Compare commits

..

16 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
10 changed files with 1977 additions and 88 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", "name": "@designestate/dees-domtools",
"version": "1.0.15", "version": "1.0.23",
"private": false, "private": false,
"description": "tools to simplify complex css structures", "description": "tools to simplify complex css structures",
"main": "dist_ts/index.js", "main": "dist_ts/index.js",
@ -9,11 +9,12 @@
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"test": "(tstest test/ --web)", "test": "(tstest test/ --web)",
"build": "(tsbuild --web)", "build": "(tsbuild --web && tsbundle npm)",
"format": "(gitzone format)" "format": "(gitzone format)"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.0.22", "@gitzone/tsbuild": "^2.0.22",
"@gitzone/tsbundle": "^1.0.69",
"@gitzone/tstest": "^1.0.15", "@gitzone/tstest": "^1.0.15",
"@pushrocks/tapbundle": "^3.0.7", "@pushrocks/tapbundle": "^3.0.7",
"@types/node": "^14.0.5", "@types/node": "^14.0.5",
@ -21,9 +22,9 @@
"tslint-config-prettier": "^1.15.0" "tslint-config-prettier": "^1.15.0"
}, },
"dependencies": { "dependencies": {
"@pushrocks/lik": "^4.0.2", "@pushrocks/lik": "^4.0.12",
"@pushrocks/smartpromise": "^3.0.6", "@pushrocks/smartpromise": "^3.0.6",
"@pushrocks/smartstate": "^1.0.15", "@pushrocks/smartstate": "^1.0.16",
"lit-element": "^2.3.1" "lit-element": "^2.3.1"
}, },
"files": [ "files": [

View File

@ -1,24 +1,32 @@
import { DomTools } from './domtools.classes.domtools';
export const desktop = 1240; export const desktop = 1240;
export const tablet = 700; export const tablet = 700;
export const phablet = 500; export const phablet = 500;
export const phone = 340; 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 getEnvironment = (): TViewport => {
if (globalThis.deesDomTools && globalThis.deesDomTools.domToolsStatePart.getState().virtualViewport) {
export const setEnvironment = envArg => { return globalThis.deesDomTools.domToolsStatePart.getState().virtualViewport;
environment = envArg; } else {
return 'native';
}
}; };
export const cssForTablet = (contentArg) => { export const cssForTablet = async (contentArg) => {
if (environment === 'native' || environment === 'desktop') { if (getEnvironment() === 'native' || getEnvironment() === 'desktop') {
return ` return `
@media (max-width: ${tablet}px) { @media (max-width: ${tablet}px) {
${contentArg} ${contentArg}
} }
`; `;
} else if (environment === 'tablet' || environment === 'phablet' || environment === 'phone') { } else if (
getEnvironment() === 'tablet' ||
getEnvironment() === 'phablet' ||
getEnvironment() === 'phone'
) {
return ` return `
@media (min-width: 0px) { @media (min-width: 0px) {
${contentArg} ${contentArg}
@ -27,14 +35,14 @@ export const cssForTablet = (contentArg) => {
} }
}; };
export const cssForPhablet = (contentArg) => { export const cssForPhablet = async (contentArg) => {
if (environment === 'native' || environment === 'desktop') { if (getEnvironment() === 'native' || getEnvironment() === 'desktop') {
return ` return `
@media (max-width: ${phablet}px) { @media (max-width: ${phablet}px) {
${contentArg} ${contentArg}
} }
`; `;
} else if (environment === 'phablet' || environment === 'phone') { } else if (getEnvironment() === 'phablet' || getEnvironment() === 'phone') {
return ` return `
@media (min-width: 0px) { @media (min-width: 0px) {
${contentArg} ${contentArg}
@ -43,14 +51,14 @@ export const cssForPhablet = (contentArg) => {
} }
}; };
export const cssForPhone = (contentArg) => { export const cssForPhone = async (contentArg) => {
if (environment === 'native' || environment === 'desktop') { if (getEnvironment() === 'native' || getEnvironment() === 'desktop') {
return ` return `
@media (max-width: ${phone}px) { @media (max-width: ${phone}px) {
${contentArg} ${contentArg}
} }
`; `;
} else if (environment === 'phone') { } else if (getEnvironment() === 'phone') {
return ` return `
@media (min-width: 0px) { @media (min-width: 0px) {
${contentArg} ${contentArg}

View File

@ -1,5 +1,11 @@
import * as plugins from './domtools.plugins'; 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 { export class DomTools {
public static async setupDomTools() { public static async setupDomTools() {
@ -25,6 +31,15 @@ export class DomTools {
} }
public smartstate = new plugins.smartstate.Smartstate(); 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 domToolsReady = plugins.smartpromise.defer();
public domReady = plugins.smartpromise.defer(); public domReady = plugins.smartpromise.defer();
@ -36,9 +51,13 @@ export class DomTools {
bodyElement: HTMLElement; bodyElement: HTMLElement;
} = { } = {
headElement: null, headElement: null,
bodyElement: null, bodyElement: null
}; };
constructor() {
}
public async setGlobalStyles(stylesText: string) { public async setGlobalStyles(stylesText: string) {
await this.domReady.promise; await this.domReady.promise;
const styleElement = document.createElement('style'); const styleElement = document.createElement('style');
@ -49,20 +68,31 @@ export class DomTools {
private runOnceTrackerStringMap = new Stringmap(); private runOnceTrackerStringMap = new Stringmap();
private runOnceResultMap = new FastMap(); 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>) { public async runOnce<T>(identifierArg: string, funcArg: () => Promise<T>) {
const runningId = `${identifierArg}+runningCheck`; const runningId = `${identifierArg}+runningCheck`;
if(!this.runOnceTrackerStringMap.checkString(identifierArg)) { if (!this.runOnceTrackerStringMap.checkString(identifierArg)) {
this.runOnceTrackerStringMap.addString(identifierArg); this.runOnceTrackerStringMap.addString(identifierArg);
this.runOnceTrackerStringMap.addString(runningId); this.runOnceTrackerStringMap.addString(runningId);
const result = await funcArg(); const result = await funcArg();
this.runOnceResultMap.addToMap(identifierArg, result); this.runOnceResultMap.addToMap(identifierArg, result);
this.runOnceTrackerStringMap.removeString(runningId); this.runOnceTrackerStringMap.removeString(runningId);
} }
return await this.runOnceTrackerStringMap.registerUntilTrue(stringMap => { return await this.runOnceTrackerStringMap.registerUntilTrue(
return !stringMap.includes(runningId); stringMap => {
}, () => { return !stringMap.includes(runningId);
return this.runOnceResultMap.getByKey(identifierArg); },
}); () => {
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

@ -3,4 +3,4 @@ export interface IDeesColorSet {
secondaryAccent: string; secondaryAccent: string;
primaryBackground: string; primaryBackground: string;
secondaryBackground: string; secondaryBackground: string;
} }

View File

@ -1,7 +1,8 @@
export const cssGridColumns = (amountOfColumnsArg: number, gapSizeArg: number) => { export const cssGridColumns = (amountOfColumnsArg: number, gapSizeArg: number) => {
let returnString = ``; let returnString = ``;
for (let i = 0; i < amountOfColumnsArg; i++) { 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; return returnString;
}; };

View File

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

View File

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

View File

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