Compare commits

...

18 Commits

Author SHA1 Message Date
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
10 changed files with 1988 additions and 92 deletions

1952
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.14",
"version": "1.0.23",
"private": false,
"description": "tools to simplify complex css structures",
"main": "dist_ts/index.js",
@ -9,11 +9,12 @@
"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": "^14.0.5",
@ -21,9 +22,9 @@
"tslint-config-prettier": "^1.15.0"
},
"dependencies": {
"@pushrocks/lik": "^4.0.2",
"@pushrocks/lik": "^4.0.12",
"@pushrocks/smartpromise": "^3.0.6",
"@pushrocks/smartstate": "^1.0.15",
"@pushrocks/smartstate": "^1.0.16",
"lit-element": "^2.3.1"
},
"files": [

View File

@ -1,24 +1,32 @@
import { DomTools } from './domtools.classes.domtools';
export const desktop = 1240;
export const tablet = 700;
export const phablet = 500;
export const phone = 340;
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') {
export const cssForTablet = async (contentArg) => {
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}
@ -27,14 +35,14 @@ export const cssForTablet = (contentArg) => {
}
};
export const cssForPhablet = (contentArg) => {
if (environment === 'native' || environment === 'desktop') {
export const cssForPhablet = async (contentArg) => {
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}
@ -43,14 +51,14 @@ export const cssForPhablet = (contentArg) => {
}
};
export const cssForPhone = (contentArg) => {
if (environment === 'native' || environment === 'desktop') {
export const cssForPhone = async (contentArg) => {
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,11 @@
import * as plugins from './domtools.plugins';
import { Stringmap, FastMap } from '@pushrocks/lik';
import { Stringmap } from '@pushrocks/lik/dist_ts/lik.stringmap';
import { FastMap } from '@pushrocks/lik/dist_ts/lik.fastmap';
import { TViewport } from './domtools.breakpoints';
export interface IDomToolsState {
virtualViewport: TViewport;
}
export class DomTools {
public static async setupDomTools() {
@ -10,8 +16,8 @@ export class DomTools {
// lets make sure the dom is ready
const readyStateChangedFunc = () => {
if (document.readyState === 'interactive' || document.readyState === 'complete') {
domToolsInstance.headElement = document.querySelector('head');
domToolsInstance.bodyElement = document.querySelector('body');
domToolsInstance.elements.headElement = document.querySelector('head');
domToolsInstance.elements.bodyElement = document.querySelector('body');
domToolsInstance.domReady.resolve();
}
};
@ -24,24 +30,49 @@ export class DomTools {
return domToolsInstance;
}
public smartstate = new plugins.smartstate.Smartstate();
public domToolsStatePart = this.smartstate.getStatePart<IDomToolsState>('domtools', {
virtualViewport: 'native'
});
public 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();
// elements
public headElement: HTMLElement;
public bodyElement: HTMLElement;
public elements: {
headElement: HTMLElement;
bodyElement: HTMLElement;
} = {
headElement: null,
bodyElement: null
};
constructor() {
}
public async setGlobalStyles(stylesText: string) {
await this.domReady.promise;
const styleElement = document.createElement('style');
styleElement.type = 'text/css';
styleElement.appendChild(document.createTextNode(stylesText));
this.headElement.appendChild(styleElement);
this.elements.headElement.appendChild(styleElement);
}
private runOnceTrackerStringMap = new Stringmap();
private runOnceResultMap = new FastMap();
/**
* run a function once and always get the Promise of the first execution
* @param identifierArg
* @param funcArg
*/
public async runOnce<T>(identifierArg: string, funcArg: () => Promise<T>) {
const runningId = `${identifierArg}+runningCheck`;
if (!this.runOnceTrackerStringMap.checkString(identifierArg)) {
@ -51,11 +82,17 @@ export class DomTools {
this.runOnceResultMap.addToMap(identifierArg, result);
this.runOnceTrackerStringMap.removeString(runningId);
}
return await this.runOnceTrackerStringMap.registerUntilTrue(stringMap => {
return await this.runOnceTrackerStringMap.registerUntilTrue(
stringMap => {
return !stringMap.includes(runningId);
}, () => {
},
() => {
return this.runOnceResultMap.getByKey(identifierArg);
});
}
);
}
setVirtualViewport(environmentArg: TViewport) {
this.domToolsStatePart.dispatchAction(this.actionSetVirtualViewport, environmentArg);
}
}

View File

@ -0,0 +1 @@
import * as plugins from './domtools.plugins';

View File

@ -1,7 +1,8 @@
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

@ -1,7 +1,6 @@
import * as plugins from './domtools.plugins';
import { DomTools } from './domtools.classes.domtools';
import { html } from 'lit-element';
export const styles = html`
<style>
@ -12,7 +11,6 @@ export const styles = html`
</style>
`;
/**
* a basic setup for elements
* makes sure everything is in check

View File

@ -2,7 +2,4 @@
import * as smartpromise from '@pushrocks/smartpromise';
import * as smartstate from '@pushrocks/smartstate';
export {
smartpromise,
smartstate
};
export { smartpromise, smartstate };

View File

@ -4,8 +4,5 @@ import * as elementBasic from './domtools.elementbasic';
import * as breakpoints from './domtools.breakpoints';
import * as css from './domtools.css';
export {
css,
breakpoints,
elementBasic
};
export { css, breakpoints, elementBasic };
export { DomTools } from './domtools.classes.domtools';