Compare commits

...

40 Commits

Author SHA1 Message Date
ad3f4b31fa 1.0.33 2020-06-28 17:40:03 +00:00
91b50ecde5 fix(core): update 2020-06-28 17:40:03 +00:00
45fecfbde8 1.0.32 2020-06-28 16:59:15 +00:00
e3e6d06969 fix(core): update 2020-06-28 16:59:14 +00:00
50ace4c236 1.0.31 2020-06-28 16:42:31 +00:00
90f68965bb fix(core): update 2020-06-28 16:42:30 +00:00
6c92a9cdf8 1.0.30 2020-06-28 15:49:47 +00:00
d4e24d615a fix(core): update 2020-06-28 15:49:46 +00:00
37b7dca212 1.0.29 2020-06-26 01:39:10 +00:00
7d9dc1ad65 fix(core): update 2020-06-26 01:39:10 +00:00
20f06e5935 1.0.28 2020-06-03 10:34:10 +00:00
d3fa33f0cc fix(core): update 2020-06-03 10:34:09 +00:00
aa91dad272 1.0.27 2020-06-03 09:07:32 +00:00
05a22599b8 fix(core): update 2020-06-03 09:07:31 +00:00
bd0b279fc2 1.0.26 2020-06-01 12:30:22 +00:00
8276a5b09b fix(core): update 2020-06-01 12:30:21 +00:00
a9200859ec 1.0.25 2020-05-27 23:53:32 +00:00
210a0ad8a1 fix(core): update 2020-05-27 23:53:32 +00:00
2756a3cb68 1.0.24 2020-05-27 22:41:09 +00:00
acf0ea3874 fix(core): update 2020-05-27 22:41:08 +00:00
284d2be0e3 1.0.23 2020-05-27 22:30:04 +00:00
dfb9175613 fix(core): update 2020-05-27 22:30:03 +00:00
16a213f536 1.0.22 2020-05-27 22:28:52 +00:00
9869b0c6aa fix(core): update 2020-05-27 22:28:52 +00:00
e63cb9669b 1.0.21 2020-05-27 22:06:06 +00:00
06766c6895 fix(core): update 2020-05-27 22:06:05 +00:00
48f1b02f0b 1.0.20 2020-05-27 21:59:28 +00:00
f41550fa22 fix(core): update 2020-05-27 21:59:28 +00:00
ac18ed0684 1.0.19 2020-05-27 21:15:39 +00:00
0ed59e850e fix(core): update 2020-05-27 21:15:38 +00:00
fb36c641a9 1.0.18 2020-05-27 18:59:45 +00:00
ae74e0b4f2 fix(core): update 2020-05-27 18:59:44 +00:00
d2a330e5d9 1.0.17 2020-05-25 22:14:38 +00:00
f40287fbb6 fix(core): update 2020-05-25 22:14:37 +00:00
e27bd8a53f 1.0.16 2020-05-25 16:22:05 +00:00
d6fc173a5b fix(core): update 2020-05-25 16:22:05 +00:00
52c245d655 1.0.15 2020-05-25 16:12:00 +00:00
c2e0c0ab19 fix(core): update 2020-05-25 16:11:59 +00:00
455d68338b 1.0.14 2020-05-25 15:57:47 +00:00
710e99a69a fix(core): update 2020-05-25 15:57:47 +00:00
13 changed files with 2334 additions and 264 deletions

2225
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{
"name": "@designestate/dees-domtools",
"version": "1.0.13",
"version": "1.0.33",
"private": false,
"description": "tools to simplify complex css structures",
"main": "dist_ts/index.js",
@ -9,20 +9,28 @@
"license": "MIT",
"scripts": {
"test": "(tstest test/ --web)",
"build": "(tsbuild --web)",
"build": "(tsbuild --web && tsbundle npm)",
"format": "(gitzone format)"
},
"devDependencies": {
"@gitzone/tsbuild": "^2.0.22",
"@gitzone/tsbundle": "^1.0.69",
"@gitzone/tstest": "^1.0.15",
"@pushrocks/tapbundle": "^3.0.7",
"@types/node": "^10.11.7",
"tslint": "^5.11.0",
"@types/node": "^14.0.5",
"tslint": "^6.1.2",
"tslint-config-prettier": "^1.15.0"
},
"dependencies": {
"@apiglobal/typedrequest": "^1.0.38",
"@pushrocks/lik": "^4.0.13",
"@pushrocks/smartpromise": "^3.0.6",
"lit-element": "^2.3.1"
"@pushrocks/smartrouter": "^1.0.2",
"@pushrocks/smartstate": "^1.0.16",
"@pushrocks/webrequest": "^2.0.9",
"@pushrocks/websetup": "^2.0.16",
"lit-element": "^2.3.1",
"sweet-scroll": "^4.0.0"
},
"files": [
"ts/**/*",

View File

@ -8,13 +8,20 @@ tools to simplify complex css structures
* [docs (typedoc)](https://designestate.gitlab.io/dees-domtools/)
## Status for master
[![pipeline status](https://gitlab.com/designestate/dees-domtools/badges/master/pipeline.svg)](https://gitlab.com/designestate/dees-domtools/commits/master)
[![coverage report](https://gitlab.com/designestate/dees-domtools/badges/master/coverage.svg)](https://gitlab.com/designestate/dees-domtools/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/@designestate/dees-domtools.svg)](https://www.npmjs.com/package/@designestate/dees-domtools)
[![Known Vulnerabilities](https://snyk.io/test/npm/@designestate/dees-domtools/badge.svg)](https://snyk.io/test/npm/@designestate/dees-domtools)
[![TypeScript](https://img.shields.io/badge/TypeScript->=%203.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-prettier-ff69b4.svg)](https://prettier.io/)
Status Category | Status Badge
-- | --
GitLab Pipelines | [![pipeline status](https://gitlab.com/designestate/dees-domtools/badges/master/pipeline.svg)](https://lossless.cloud)
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/designestate/dees-domtools/badges/master/coverage.svg)](https://lossless.cloud)
npm | [![npm downloads per month](https://badgen.net/npm/dy/@designestate/dees-domtools)](https://lossless.cloud)
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/designestate/dees-domtools)](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@designestate/dees-domtools)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@designestate/dees-domtools)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@designestate/dees-domtools)](https://lossless.cloud)
Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20Windows%2010/yes/green?icon=windows)](https://lossless.cloud) [![Supports Mac OS X](https://badgen.net/badge/supports%20Mac%20OS%20X/yes/green?icon=apple)](https://lossless.cloud)
## Usage

View File

@ -1,24 +1,35 @@
import { DomTools } from './domtools.classes.domtools';
export const desktop = 1240;
export const tablet = 700;
export const phablet = 500;
export const phone = 340;
export const tablet = 1024;
export const phablet = 600;
export const phone = 400;
export type TEnvironment = 'native' | 'desktop' | 'tablet' | 'phablet' | 'phone';
export type TViewport = 'native' | 'desktop' | 'tablet' | 'phablet' | 'phone';
let environment: TEnvironment = 'native';
export const setEnvironment = envArg => {
environment = envArg;
export const getEnvironment = (): TViewport => {
if (
globalThis.deesDomTools &&
globalThis.deesDomTools.domToolsStatePart.getState().virtualViewport
) {
return globalThis.deesDomTools.domToolsStatePart.getState().virtualViewport;
} else {
return 'native';
}
};
export const cssForTablet = (contentArg) => {
if (environment === 'native' || environment === 'desktop') {
if (getEnvironment() === 'native' || getEnvironment() === 'desktop') {
return `
@media (max-width: ${tablet}px) {
${contentArg}
}
`;
} else if (environment === 'tablet' || environment === 'phablet' || environment === 'phone') {
} else if (
getEnvironment() === 'tablet' ||
getEnvironment() === 'phablet' ||
getEnvironment() === 'phone'
) {
return `
@media (min-width: 0px) {
${contentArg}
@ -28,13 +39,13 @@ export const cssForTablet = (contentArg) => {
};
export const cssForPhablet = (contentArg) => {
if (environment === 'native' || environment === 'desktop') {
if (getEnvironment() === 'native' || getEnvironment() === 'desktop') {
return `
@media (max-width: ${phablet}px) {
${contentArg}
}
`;
} else if (environment === 'phablet' || environment === 'phone') {
} else if (getEnvironment() === 'phablet' || getEnvironment() === 'phone') {
return `
@media (min-width: 0px) {
${contentArg}
@ -44,13 +55,13 @@ export const cssForPhablet = (contentArg) => {
};
export const cssForPhone = (contentArg) => {
if (environment === 'native' || environment === 'desktop') {
if (getEnvironment() === 'native' || getEnvironment() === 'desktop') {
return `
@media (max-width: ${phone}px) {
${contentArg}
}
`;
} else if (environment === 'phone') {
} else if (getEnvironment() === 'phone') {
return `
@media (min-width: 0px) {
${contentArg}

View File

@ -1,5 +1,129 @@
export class DeesDomTools {
public static createDomTools = () => {
globalThis.deesDomTools = new DeesDomTools();
import * as plugins from './domtools.plugins';
import { Stringmap } from '@pushrocks/lik/dist_ts/lik.stringmap';
import { FastMap } from '@pushrocks/lik/dist_ts/lik.fastmap';
import { TViewport } from './domtools.breakpoints';
import { Scroller } from './domtools.classes.scroller';
export interface IDomToolsState {
virtualViewport: TViewport;
}
export class DomTools {
// ======
// STATIC
// ======
/**
* setups domtools
*/
public static async setupDomTools() {
let domToolsInstance: DomTools;
if (!globalThis.deesDomTools) {
globalThis.deesDomTools = new DomTools();
domToolsInstance = globalThis.deesDomTools;
// lets make sure the dom is ready
const readyStateChangedFunc = () => {
if (document.readyState === 'interactive' || document.readyState === 'complete') {
domToolsInstance.elements.headElement = document.querySelector('head');
domToolsInstance.elements.bodyElement = document.querySelector('body');
domToolsInstance.domReady.resolve();
}
};
document.addEventListener('readystatechange', readyStateChangedFunc);
domToolsInstance.domToolsReady.resolve();
} else {
domToolsInstance = globalThis.deesDomTools;
}
await domToolsInstance.domToolsReady.promise;
return domToolsInstance;
}
// ========
// INSTANCE
// ========
// elements
public elements: {
headElement: HTMLElement;
bodyElement: HTMLElement;
} = {
headElement: null,
bodyElement: null,
};
public smartstate = new plugins.smartstate.Smartstate();
public domToolsStatePart = this.smartstate.getStatePart<IDomToolsState>('domtools', {
virtualViewport: 'native',
});
public router = new plugins.smartrouter.SmartRouter({
debug: false,
});
public scroller: plugins.SweetScroll;
private actionSetVirtualViewport = this.domToolsStatePart.createAction<TViewport>(
async (statePart, payload) => {
const currentState = statePart.getState();
currentState.virtualViewport = payload;
return currentState;
}
);
public domToolsReady = plugins.smartpromise.defer();
public domReady = plugins.smartpromise.defer();
public globalStylesReady = plugins.smartpromise.defer();
constructor() {
// lets care about third party stuff
this.domToolsReady.promise.then(() => {
this.scroller = new plugins.SweetScroll({
/* some options */
});
});
}
private runOnceTrackerStringMap = new Stringmap();
private runOnceResultMap = new FastMap();
/**
* run a function once and always get the Promise of the first execution
* @param identifierArg the indentifier arg identifies functions. functions with the same identifier are considered equal
* @param funcArg the actual func arg to run
*/
public async runOnce<T>(identifierArg: string, funcArg: () => Promise<T>) {
const runningId = `${identifierArg}+runningCheck`;
if (!this.runOnceTrackerStringMap.checkString(identifierArg)) {
this.runOnceTrackerStringMap.addString(identifierArg);
this.runOnceTrackerStringMap.addString(runningId);
const result = await funcArg();
this.runOnceResultMap.addToMap(identifierArg, result);
this.runOnceTrackerStringMap.removeString(runningId);
}
return await this.runOnceTrackerStringMap.registerUntilTrue(
(stringMap) => {
return !stringMap.includes(runningId);
},
() => {
return this.runOnceResultMap.getByKey(identifierArg);
}
);
}
// setStuff
public async setGlobalStyles(stylesText: string) {
await this.domReady.promise;
const styleElement = document.createElement('style');
styleElement.type = 'text/css';
styleElement.appendChild(document.createTextNode(stylesText));
this.elements.headElement.appendChild(styleElement);
}
public setVirtualViewport(environmentArg: TViewport) {
this.domToolsStatePart.dispatchAction(this.actionSetVirtualViewport, environmentArg);
}
public async setWebsiteInfo(optionsArg: plugins.websetup.IWebSetupConstructorOptions) {
const websetup = new plugins.websetup.WebSetup(optionsArg);
await websetup.setup();
}
}

View File

@ -0,0 +1,5 @@
import * as plugins from './domtools.plugins';
export class Scroller {
// TODO: move sweet scroll over to here;
}

View File

@ -1,7 +1,9 @@
export const cssGridColumns = (amountOfColumnsArg: number, gapSizeArg: number) => {
let returnString = ``;
for (let i = 0; i < amountOfColumnsArg; i++) {
returnString += ` calc((100%/${amountOfColumnsArg}) - (${gapSizeArg * (amountOfColumnsArg - 1)}px/${amountOfColumnsArg}))`;
returnString += ` calc((100%/${amountOfColumnsArg}) - (${
gapSizeArg * (amountOfColumnsArg - 1)
}px/${amountOfColumnsArg}))`;
}
return returnString;
};

View File

@ -0,0 +1,45 @@
import * as plugins from './domtools.plugins';
import { DomTools } from './domtools.classes.domtools';
import { html } from 'lit-element';
export const styles = html`
<style>
* {
font-family: 'Roboto', sans-serif;
box-sizing: border-box;
}
</style>
`;
/**
* a basic setup for elements
* makes sure everything is in check
*/
export const setup = async () => {
const domTools = await DomTools.setupDomTools();
domTools.runOnce('elementBasicSetup', async () => {
// bodyStyles
domTools.setGlobalStyles(`
body {
margin: 0px;
font-family: 'Roboto', sans-serif;
box-sizing: border-box;
}
`);
// material font
domTools.setGlobalStyles(`
@font-face {
font-family: 'Material Icons';
font-style: normal;
font-weight: 400;
src: url(https://fonts.gstatic.com/s/materialicons/v42/flUhRq6tzZclQEJ-Vdg-IuiaDsNcIhQ8tQ.woff2) format('woff2');
}
`);
// Roboto Font
domTools.setGlobalStyles(`
@import url('https://fonts.googleapis.com/css?family=Roboto');
`);
});
};

View File

@ -1,69 +0,0 @@
import { defer } from '@pushrocks/smartpromise';
const createStyleElement = (headElement: HTMLElement, styleText: string) => {
const styleElement = document.createElement('style');
styleElement.type = 'text/css';
styleElement.appendChild(document.createTextNode(styleText));
headElement.appendChild(styleElement);
};
/**
* a basic setup for elements
* makes sure everything is in check
*/
export const elementBasicSetup = async () => {
if (globalThis.deesCssToolsReady) {
await globalThis.deesCssToolsReady.promise;
} else {
// lets prevent double execution
globalThis.deesCssToolsReady = defer();
// lets make sure the dom is ready
const documentReady = defer();
const readyStateChangedFunc = () => {
if (document.readyState === 'interactive' || document.readyState === 'complete') {
console.log('elementBasicSetup: element basic setup complete')
documentReady.resolve();
} else {
console.log('elementBasicSetup: document not yet ready');
}
};
document.addEventListener('readystatechange', readyStateChangedFunc);
console.log('elementBasicSetup: waiting for document to be ready');
await documentReady.promise;
console.log('elementBasicSetup: document ready!');
// lets get started
const head = document.querySelector('head');
const body = document.querySelector('body');
// bodyStyles
const bodyStyles = `
body {
margin: 0px;
font-family: 'Roboto', sans-serif;
box-sizing: border-box;
}
`;
createStyleElement(head, bodyStyles);
// material font
const materialFontStyles = `
@font-face {
font-family: 'Material Icons';
font-style: normal;
font-weight: 400;
src: url(https://fonts.gstatic.com/s/materialicons/v42/flUhRq6tzZclQEJ-Vdg-IuiaDsNcIhQ8tQ.woff2) format('woff2');
}
`;
createStyleElement(head, materialFontStyles);
// Roboto Font
const robotoFontCss = `
@import url('https://fonts.googleapis.com/css?family=Roboto');
`;
createStyleElement(head, robotoFontCss);
globalThis.deesCssToolsReady.resolve();
}
};

View File

@ -1,9 +0,0 @@
import { html } from 'lit-element';
export const elementBasicStyles = html`
<style>
* {
font-family: 'Roboto', sans-serif;
box-sizing: border-box;
}
</style>
`;

13
ts/domtools.plugins.ts Normal file
View File

@ -0,0 +1,13 @@
// pushrocks scope
import * as smartpromise from '@pushrocks/smartpromise';
import * as smartrouter from '@pushrocks/smartrouter';
import * as smartstate from '@pushrocks/smartstate';
import * as webrequest from '@pushrocks/webrequest';
import * as websetup from '@pushrocks/websetup';
export { smartpromise, smartrouter, smartstate, webrequest, websetup };
// third party scope
import SweetScroll from 'sweet-scroll';
export { SweetScroll };

View File

@ -1,17 +1,9 @@
export * from './domtools.colors';
import * as elementBasicSetup from './domtools.elementbasicsetup';
import * as elementBasicStyles from './domtools.elementbasicstyles';
import * as elementBasic from './domtools.elementbasic';
import * as breakpoints from './domtools.breakpoints';
import * as css from './domtools.css';
const elementBasic = {
setup: elementBasicSetup.elementBasicSetup,
styles: elementBasicStyles.elementBasicStyles
};
export {
css,
breakpoints,
elementBasic
};
export { css, breakpoints, elementBasic };
export { DomTools } from './domtools.classes.domtools';
export { TypedRequest } from '@apiglobal/typedrequest';