Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
fb36c641a9 | |||
ae74e0b4f2 | |||
d2a330e5d9 | |||
f40287fbb6 | |||
e27bd8a53f | |||
d6fc173a5b | |||
52c245d655 | |||
c2e0c0ab19 | |||
455d68338b | |||
710e99a69a | |||
e3939865aa | |||
ba20508642 |
2003
package-lock.json
generated
2003
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
11
package.json
11
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@designestate/dees-domtools",
|
"name": "@designestate/dees-domtools",
|
||||||
"version": "1.0.12",
|
"version": "1.0.18",
|
||||||
"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,19 +9,22 @@
|
|||||||
"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": "^10.11.7",
|
"@types/node": "^14.0.5",
|
||||||
"tslint": "^5.11.0",
|
"tslint": "^6.1.2",
|
||||||
"tslint-config-prettier": "^1.15.0"
|
"tslint-config-prettier": "^1.15.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@pushrocks/lik": "^4.0.10",
|
||||||
"@pushrocks/smartpromise": "^3.0.6",
|
"@pushrocks/smartpromise": "^3.0.6",
|
||||||
|
"@pushrocks/smartstate": "^1.0.15",
|
||||||
"lit-element": "^2.3.1"
|
"lit-element": "^2.3.1"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
|
@ -1,5 +1,74 @@
|
|||||||
export class DeesDomTools {
|
import * as plugins from './domtools.plugins';
|
||||||
public static createDomTools = () => {
|
import { Stringmap } from '@pushrocks/lik/dist_ts/lik.stringmap';
|
||||||
globalThis.deesDomTools = new DeesDomTools();
|
import { FastMap } from '@pushrocks/lik/dist_ts/lik.fastmap';
|
||||||
|
|
||||||
|
export class 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public smartstate = new plugins.smartstate.Smartstate();
|
||||||
|
|
||||||
|
public domToolsReady = plugins.smartpromise.defer();
|
||||||
|
public domReady = plugins.smartpromise.defer();
|
||||||
|
public globalStylesReady = plugins.smartpromise.defer();
|
||||||
|
|
||||||
|
// elements
|
||||||
|
public elements: {
|
||||||
|
headElement: HTMLElement;
|
||||||
|
bodyElement: HTMLElement;
|
||||||
|
} = {
|
||||||
|
headElement: null,
|
||||||
|
bodyElement: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
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)) {
|
||||||
|
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);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
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';
|
47
ts/domtools.elementbasic.ts
Normal file
47
ts/domtools.elementbasic.ts
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
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');
|
||||||
|
`);
|
||||||
|
});
|
||||||
|
};
|
@ -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();
|
|
||||||
}
|
|
||||||
};
|
|
@ -1,9 +0,0 @@
|
|||||||
import { html } from 'lit-element';
|
|
||||||
export const elementBasicStyles = html`
|
|
||||||
<style>
|
|
||||||
* {
|
|
||||||
font-family: 'Roboto', sans-serif;
|
|
||||||
box-sizing: border-box;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
`;
|
|
8
ts/domtools.plugins.ts
Normal file
8
ts/domtools.plugins.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
// pushrocks scope
|
||||||
|
import * as smartpromise from '@pushrocks/smartpromise';
|
||||||
|
import * as smartstate from '@pushrocks/smartstate';
|
||||||
|
|
||||||
|
export {
|
||||||
|
smartpromise,
|
||||||
|
smartstate
|
||||||
|
};
|
@ -1,11 +1,11 @@
|
|||||||
export * from './domtools.colors';
|
export * from './domtools.colors';
|
||||||
export * from './domtools.elementbasicsetup';
|
|
||||||
export * from './domtools.elementbasicstyles';
|
|
||||||
|
|
||||||
|
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,
|
css,
|
||||||
breakpoints
|
breakpoints,
|
||||||
|
elementBasic
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user