Compare commits
14 Commits
Author | SHA1 | Date | |
---|---|---|---|
16a213f536 | |||
9869b0c6aa | |||
e63cb9669b | |||
06766c6895 | |||
48f1b02f0b | |||
f41550fa22 | |||
ac18ed0684 | |||
0ed59e850e | |||
fb36c641a9 | |||
ae74e0b4f2 | |||
d2a330e5d9 | |||
f40287fbb6 | |||
e27bd8a53f | |||
d6fc173a5b |
1952
package-lock.json
generated
1952
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@designestate/dees-domtools",
|
||||
"version": "1.0.15",
|
||||
"version": "1.0.22",
|
||||
"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": [
|
||||
|
@ -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 = async (): Promise<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}
|
||||
|
@ -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() {
|
||||
@ -25,6 +31,15 @@ export class DomTools {
|
||||
}
|
||||
|
||||
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();
|
||||
@ -36,9 +51,13 @@ export class DomTools {
|
||||
bodyElement: HTMLElement;
|
||||
} = {
|
||||
headElement: null,
|
||||
bodyElement: null,
|
||||
bodyElement: null
|
||||
};
|
||||
|
||||
constructor() {
|
||||
|
||||
}
|
||||
|
||||
public async setGlobalStyles(stylesText: string) {
|
||||
await this.domReady.promise;
|
||||
const styleElement = document.createElement('style');
|
||||
@ -49,20 +68,31 @@ export class DomTools {
|
||||
|
||||
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)) {
|
||||
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);
|
||||
});
|
||||
return await this.runOnceTrackerStringMap.registerUntilTrue(
|
||||
stringMap => {
|
||||
return !stringMap.includes(runningId);
|
||||
},
|
||||
() => {
|
||||
return this.runOnceResultMap.getByKey(identifierArg);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
setVirtualViewport(environmentArg: TViewport) {
|
||||
this.domToolsStatePart.dispatchAction(this.actionSetVirtualViewport, environmentArg);
|
||||
}
|
||||
}
|
||||
|
1
ts/domtools.classes.router.ts
Normal file
1
ts/domtools.classes.router.ts
Normal file
@ -0,0 +1 @@
|
||||
import * as plugins from './domtools.plugins';
|
@ -3,4 +3,4 @@ export interface IDeesColorSet {
|
||||
secondaryAccent: string;
|
||||
primaryBackground: string;
|
||||
secondaryBackground: string;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
};
|
||||
|
@ -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
|
||||
|
@ -2,7 +2,4 @@
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
import * as smartstate from '@pushrocks/smartstate';
|
||||
|
||||
export {
|
||||
smartpromise,
|
||||
smartstate
|
||||
};
|
||||
export { smartpromise, smartstate };
|
||||
|
@ -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';
|
||||
|
Reference in New Issue
Block a user