Compare commits
254 Commits
Author | SHA1 | Date | |
---|---|---|---|
3bc5e1d0e2 | |||
96a88112dc | |||
6c0c1e165f | |||
653a4138a9 | |||
d776843494 | |||
79e64c4cc2 | |||
7192d3fbf7 | |||
42bcb8243d | |||
52fb046fa8 | |||
b83d3e1aed | |||
4ec8707596 | |||
69e1b52e72 | |||
a5ff175913 | |||
f84e7c48ae | |||
185d9ff957 | |||
6145bd66dc | |||
d58272a604 | |||
68ca1e8906 | |||
7023888f38 | |||
1356666700 | |||
b436fe77b0 | |||
3de788bb75 | |||
d50e320f17 | |||
a7532c8816 | |||
2d5944cdd7 | |||
5a8527068a | |||
ffd0bb925a | |||
4a5fb3ef4b | |||
a059c268af | |||
714aa77839 | |||
2527e6e586 | |||
88f7f20b6f | |||
8e23b7ebec | |||
b3d12c39bf | |||
d102d5a7e6 | |||
8be31958b4 | |||
e21f6c3920 | |||
356a756962 | |||
0bb66e8221 | |||
b70077c43f | |||
9c5f024e5f | |||
5eea208924 | |||
f21fdb2eb8 | |||
d6ea74cb71 | |||
10375576a7 | |||
367be854ff | |||
0933c1d83b | |||
af1eb73028 | |||
4bff0091c9 | |||
7bae4585f3 | |||
d9cdff2897 | |||
189060f11d | |||
fc2dfa8018 | |||
be44cb7a78 | |||
de6aba4289 | |||
3babbce2c5 | |||
707956b7ee | |||
c71a6170d5 | |||
3f98f2867c | |||
7c86f5a8f6 | |||
472ec3158e | |||
9a0d09d9de | |||
5975ca7320 | |||
97583c650d | |||
f5fd0662d3 | |||
14c91ed81f | |||
1aabacdf87 | |||
1747afe04a | |||
a1bd7f74a7 | |||
6ff89390b7 | |||
2ad8d0a9fd | |||
ae01670361 | |||
5657b0be1d | |||
781ae3c3b1 | |||
da79e623cc | |||
3ca6b5e34e | |||
98f0bc013d | |||
d32a544de2 | |||
070221d6c9 | |||
19714854ba | |||
50ebea1b5f | |||
df0527f3c1 | |||
b620b7393e | |||
ab5b9511fd | |||
da86e64056 | |||
effc331a67 | |||
fa24708a47 | |||
31126e30eb | |||
ef0a4eae80 | |||
e711302c28 | |||
1cfc07fe8e | |||
7f221c1a8c | |||
09f927c0d4 | |||
1042e79625 | |||
fced2efcbd | |||
83fe1d62e7 | |||
78bce9600c | |||
2860b5b6e0 | |||
b802935d27 | |||
b73a702b74 | |||
b3deb31ab5 | |||
6ea5482e3d | |||
0ead7215ff | |||
286bb0887a | |||
4456f00816 | |||
b60a1bebe0 | |||
94127227a6 | |||
b5af1b1226 | |||
a6f382dd7f | |||
0de00cb2c1 | |||
570a026cf8 | |||
48b5cc770c | |||
7ae2de5843 | |||
e4d87ae882 | |||
259a669e24 | |||
bf461dd1a0 | |||
63c9ae97d4 | |||
a83239e0d9 | |||
8da64f1b50 | |||
2d4c0e4e49 | |||
1c8f7fa59e | |||
a613c0aca2 | |||
127564cd71 | |||
e077bf5b25 | |||
64a3f57813 | |||
1315e8c3f6 | |||
d059862841 | |||
ad34affb9e | |||
011b3fb76a | |||
47099d02b5 | |||
f4029ed008 | |||
d5732822e4 | |||
c467a92e7c | |||
746c1148e3 | |||
d75e66ba78 | |||
7c805a075e | |||
5e1a44ad88 | |||
093eae2c97 | |||
991d318de6 | |||
c7c3650fe9 | |||
8d355f234f | |||
a5c22ec1db | |||
f5263a0cc4 | |||
4a022a7d1d | |||
bd6ba6d6db | |||
317bc63bc7 | |||
22eeb7809b | |||
fdd550ec21 | |||
9db1f92ba3 | |||
772d0b0b97 | |||
a68e9e1bf9 | |||
f9507b0dbd | |||
f8c1a0135a | |||
7d884f6556 | |||
8a8ee5cd7b | |||
1660381be6 | |||
f0ad441415 | |||
27c087b693 | |||
63463a751c | |||
a01f5a5b8a | |||
bb1ad4e037 | |||
eb871161f9 | |||
090e5b4d42 | |||
8168dd1a0c | |||
de15bc0d1c | |||
13fa3d655e | |||
18b93b860d | |||
e8e6416b6f | |||
fbe2f381c9 | |||
3cb0aceaad | |||
6d6c92eee4 | |||
4385909677 | |||
2dc36d8170 | |||
ffbde62744 | |||
7bde843e43 | |||
faa7adcffe | |||
7977538c05 | |||
afaa88047c | |||
8aabe2820e | |||
570d370c97 | |||
73552ad80f | |||
537902aa53 | |||
e033bfa5b3 | |||
4983e1ed90 | |||
899775b050 | |||
7655fc0348 | |||
8aa5576318 | |||
1ff54b0fcd | |||
3901258272 | |||
27380d1483 | |||
e2f9991f96 | |||
133ce80b0a | |||
cf12f45c9b | |||
6cc5ec315e | |||
88810bae2c | |||
21369d8da5 | |||
a5973944ee | |||
ad3f4b31fa | |||
91b50ecde5 | |||
45fecfbde8 | |||
e3e6d06969 | |||
50ace4c236 | |||
90f68965bb | |||
6c92a9cdf8 | |||
d4e24d615a | |||
37b7dca212 | |||
7d9dc1ad65 | |||
20f06e5935 | |||
d3fa33f0cc | |||
aa91dad272 | |||
05a22599b8 | |||
bd0b279fc2 | |||
8276a5b09b | |||
a9200859ec | |||
210a0ad8a1 | |||
2756a3cb68 | |||
acf0ea3874 | |||
284d2be0e3 | |||
dfb9175613 | |||
16a213f536 | |||
9869b0c6aa | |||
e63cb9669b | |||
06766c6895 | |||
48f1b02f0b | |||
f41550fa22 | |||
ac18ed0684 | |||
0ed59e850e | |||
fb36c641a9 | |||
ae74e0b4f2 | |||
d2a330e5d9 | |||
f40287fbb6 | |||
e27bd8a53f | |||
d6fc173a5b | |||
52c245d655 | |||
c2e0c0ab19 | |||
455d68338b | |||
710e99a69a | |||
e3939865aa | |||
ba20508642 | |||
bef4ea7bed | |||
17a8151b2f | |||
5aee15a23b | |||
38d78b4e12 | |||
ec36a516c0 | |||
1c844d35ca | |||
ecb387f59e | |||
9b3c92fef5 | |||
74cf94a69e | |||
9f76d4e920 | |||
082ef21078 | |||
4db0e6f5fc | |||
40b8c5010d | |||
16297dc630 | |||
7c3d131b46 |
@ -19,23 +19,36 @@ mirror:
|
||||
stage: security
|
||||
script:
|
||||
- npmci git mirror
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
audit:
|
||||
auditProductionDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install --production --ignore-scripts
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- npmci command npm audit --audit-level=high --only=prod --production
|
||||
tags:
|
||||
- docker
|
||||
allow_failure: true
|
||||
|
||||
auditDevDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install --ignore-scripts
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- npmci command npm audit --audit-level=high
|
||||
- npmci command npm audit --audit-level=high --only=dev
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
allow_failure: true
|
||||
|
||||
# ====================
|
||||
# test stage
|
||||
@ -50,9 +63,7 @@ testStable:
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- priv
|
||||
|
||||
testBuild:
|
||||
stage: test
|
||||
@ -63,9 +74,7 @@ testBuild:
|
||||
- npmci command npm run build
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
release:
|
||||
stage: release
|
||||
@ -85,6 +94,8 @@ release:
|
||||
codequality:
|
||||
stage: metadata
|
||||
allow_failure: true
|
||||
only:
|
||||
- tags
|
||||
script:
|
||||
- npmci command npm install -g tslint typescript
|
||||
- npmci npm prepare
|
||||
|
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@ -15,7 +15,7 @@
|
||||
"properties": {
|
||||
"projectType": {
|
||||
"type": "string",
|
||||
"enum": ["website", "element", "service", "npm"]
|
||||
"enum": ["website", "element", "service", "npm", "wcc"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
1
license
1
license
@ -1,4 +1,5 @@
|
||||
Copyright (c) 2020 Lossless GmbH (hello@lossless.com)
|
||||
Copyright (c) 2017 Nathan Friend (ts-keycode-enum)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -4,9 +4,9 @@
|
||||
"module": {
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "designestate",
|
||||
"gitrepo": "dees-csstools",
|
||||
"gitrepo": "dees-domtools",
|
||||
"shortDescription": "tools to simplify complex css structures",
|
||||
"npmPackagename": "@designestate/dees-csstools",
|
||||
"npmPackagename": "@designestate/dees-domtools",
|
||||
"license": "MIT",
|
||||
"projectDomain": "design.estate"
|
||||
}
|
||||
|
19279
package-lock.json
generated
19279
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
36
package.json
36
package.json
@ -1,28 +1,41 @@
|
||||
{
|
||||
"name": "@designestate/dees-csstools",
|
||||
"version": "1.0.4",
|
||||
"name": "@designestate/dees-domtools",
|
||||
"version": "2.0.17",
|
||||
"private": false,
|
||||
"description": "tools to simplify complex css structures",
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"type": "module",
|
||||
"author": "Lossless GmbH",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"test": "(tstest test/ --web)",
|
||||
"build": "(tsbuild --web)",
|
||||
"build": "(tsbuild --web --allowimplicitany --skiplibcheck && tsbundle npm)",
|
||||
"format": "(gitzone format)"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.0.22",
|
||||
"@gitzone/tstest": "^1.0.15",
|
||||
"@pushrocks/tapbundle": "^3.0.7",
|
||||
"@types/node": "^10.11.7",
|
||||
"tslint": "^5.11.0",
|
||||
"@gitzone/tsbuild": "^2.1.61",
|
||||
"@gitzone/tsbundle": "^1.0.102",
|
||||
"@gitzone/tstest": "^1.0.70",
|
||||
"@pushrocks/tapbundle": "^5.0.3",
|
||||
"@types/node": "^17.0.23",
|
||||
"tslint": "^6.1.3",
|
||||
"tslint-config-prettier": "^1.15.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@pushrocks/smartpromise": "^3.0.6",
|
||||
"lit-element": "^2.3.1"
|
||||
"@apiglobal/typedrequest": "^2.0.3",
|
||||
"@designestate/dees-comms": "^1.0.22",
|
||||
"@pushrocks/lik": "^5.0.4",
|
||||
"@pushrocks/smartdelay": "^2.0.13",
|
||||
"@pushrocks/smartpromise": "^3.1.7",
|
||||
"@pushrocks/smartrouter": "^1.0.12",
|
||||
"@pushrocks/smartrx": "^2.0.25",
|
||||
"@pushrocks/smartstate": "^2.0.0",
|
||||
"@pushrocks/webrequest": "^3.0.3",
|
||||
"@pushrocks/websetup": "^3.0.16",
|
||||
"@pushrocks/webstore": "^1.0.18",
|
||||
"lit": "^2.2.2",
|
||||
"sweet-scroll": "^4.0.0"
|
||||
},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
@ -35,5 +48,8 @@
|
||||
"cli.js",
|
||||
"npmextra.json",
|
||||
"readme.md"
|
||||
],
|
||||
"browserslist": [
|
||||
"last 1 chrome versions"
|
||||
]
|
||||
}
|
||||
|
31
readme.md
31
readme.md
@ -1,20 +1,27 @@
|
||||
# @designestate/dees-csstools
|
||||
# @designestate/dees-domtools
|
||||
tools to simplify complex css structures
|
||||
|
||||
## Availabililty and Links
|
||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@designestate/dees-csstools)
|
||||
* [gitlab.com (source)](https://gitlab.com/designestate/dees-csstools)
|
||||
* [github.com (source mirror)](https://github.com/designestate/dees-csstools)
|
||||
* [docs (typedoc)](https://designestate.gitlab.io/dees-csstools/)
|
||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@designestate/dees-domtools)
|
||||
* [gitlab.com (source)](https://gitlab.com/designestate/dees-domtools)
|
||||
* [github.com (source mirror)](https://github.com/designestate/dees-domtools)
|
||||
* [docs (typedoc)](https://designestate.gitlab.io/dees-domtools/)
|
||||
|
||||
## Status for master
|
||||
[](https://gitlab.com/designestate/dees-csstools/commits/master)
|
||||
[](https://gitlab.com/designestate/dees-csstools/commits/master)
|
||||
[](https://www.npmjs.com/package/@designestate/dees-csstools)
|
||||
[](https://snyk.io/test/npm/@designestate/dees-csstools)
|
||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
[](https://prettier.io/)
|
||||
|
||||
Status Category | Status Badge
|
||||
-- | --
|
||||
GitLab Pipelines | [](https://lossless.cloud)
|
||||
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||
npm | [](https://lossless.cloud)
|
||||
Snyk | [](https://lossless.cloud)
|
||||
TypeScript Support | [](https://lossless.cloud)
|
||||
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
Code Style | [](https://lossless.cloud)
|
||||
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
||||
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
||||
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
||||
Platform support | [](https://lossless.cloud) [](https://lossless.cloud)
|
||||
|
||||
## Usage
|
||||
|
||||
|
9
test/test.browser.ts
Normal file
9
test/test.browser.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { expect, tap } from '@pushrocks/tapbundle';
|
||||
import * as domtools from '../ts/index';
|
||||
|
||||
tap.test('first test', async () => {
|
||||
const domtoolsInstance = await domtools.DomTools.setupDomTools();
|
||||
expect(domtoolsInstance).toBeInstanceOf(domtools.DomTools);
|
||||
});
|
||||
|
||||
tap.start();
|
@ -1,8 +0,0 @@
|
||||
import { expect, tap } from '@pushrocks/tapbundle';
|
||||
import * as deesCsstools from '../ts/index';
|
||||
|
||||
tap.test('first test', async () => {
|
||||
console.log('hi');
|
||||
});
|
||||
|
||||
tap.start();
|
@ -1,60 +0,0 @@
|
||||
export const desktop = 1240;
|
||||
export const tablet = 700;
|
||||
export const phablet = 500;
|
||||
export const phone = 340;
|
||||
|
||||
export type TEnvironment = 'native' | 'desktop' | 'tablet' | 'phablet' | 'phone';
|
||||
|
||||
let environment: TEnvironment = 'native';
|
||||
|
||||
export const setEnvironment = envArg => {
|
||||
environment = envArg;
|
||||
};
|
||||
|
||||
export const cssForTablet = (contentArg) => {
|
||||
if (environment === 'native' || environment === 'desktop') {
|
||||
return `
|
||||
@media (max-width: ${tablet}px) {
|
||||
${contentArg}
|
||||
}
|
||||
`;
|
||||
} else if (environment === 'tablet' || environment === 'phablet' || environment === 'phone') {
|
||||
return `
|
||||
@media (min-width: 0px) {
|
||||
${contentArg}
|
||||
}
|
||||
`;
|
||||
}
|
||||
};
|
||||
|
||||
export const cssForPhablet = (contentArg) => {
|
||||
if (environment === 'native' || environment === 'desktop') {
|
||||
return `
|
||||
@media (max-width: ${phablet}px) {
|
||||
${contentArg}
|
||||
}
|
||||
`;
|
||||
} else if (environment === 'phablet' || environment === 'phone') {
|
||||
return `
|
||||
@media (min-width: 0px) {
|
||||
${contentArg}
|
||||
}
|
||||
`;
|
||||
}
|
||||
};
|
||||
|
||||
export const cssForPhone = (contentArg) => {
|
||||
if (environment === 'native' || environment === 'desktop') {
|
||||
return `
|
||||
@media (max-width: ${phone}px) {
|
||||
${contentArg}
|
||||
}
|
||||
`;
|
||||
} else if (environment === 'phone') {
|
||||
return `
|
||||
@media (min-width: 0px) {
|
||||
${contentArg}
|
||||
}
|
||||
`;
|
||||
}
|
||||
};
|
@ -1,14 +0,0 @@
|
||||
import { defer } from '@pushrocks/smartpromise';
|
||||
|
||||
/**
|
||||
* a basic setup for elements
|
||||
* makes sure everything is in check
|
||||
*/
|
||||
export const elementBasicSetup = async () => {
|
||||
if (globalThis.deesCssToolsReady) {
|
||||
await globalThis.deesCssToolsReady.promise;
|
||||
} else {
|
||||
globalThis.deesCssToolsReady = defer();
|
||||
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>
|
||||
`;
|
184
ts/domtools.classes.domtools.ts
Normal file
184
ts/domtools.classes.domtools.ts
Normal file
@ -0,0 +1,184 @@
|
||||
import * as plugins from './domtools.plugins.js';
|
||||
import { Stringmap } from '@pushrocks/lik/dist_ts/lik.stringmap.js';
|
||||
import { FastMap } from '@pushrocks/lik/dist_ts/lik.fastmap.js';
|
||||
import { TViewport } from './domtools.css.breakpoints.js';
|
||||
|
||||
import { Scroller } from './domtools.classes.scroller.js';
|
||||
import { WebSetup } from '@pushrocks/websetup';
|
||||
import { ThemeManager } from './domtools.classes.thememanager.js';
|
||||
import { Keyboard } from './domtools.classes.keyboard.js';
|
||||
|
||||
export interface IDomToolsState {
|
||||
virtualViewport: TViewport;
|
||||
jwt: string;
|
||||
}
|
||||
|
||||
export interface IDomToolsContructorOptions {
|
||||
ignoreGlobal?: boolean;
|
||||
}
|
||||
|
||||
export class DomTools {
|
||||
// ======
|
||||
// STATIC
|
||||
// ======
|
||||
/**
|
||||
* setups domtools
|
||||
*/
|
||||
public static async setupDomTools(optionsArg: IDomToolsContructorOptions = {}) {
|
||||
let domToolsInstance: DomTools;
|
||||
if (!globalThis.deesDomTools && !optionsArg.ignoreGlobal) {
|
||||
globalThis.deesDomTools = new DomTools(optionsArg);
|
||||
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 if (optionsArg.ignoreGlobal) {
|
||||
domToolsInstance = new DomTools(optionsArg);
|
||||
} else {
|
||||
domToolsInstance = globalThis.deesDomTools;
|
||||
}
|
||||
await domToolsInstance.domToolsReady.promise;
|
||||
return domToolsInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* if you can, use the static asysnc .setupDomTools() function instead since it is safer to use.
|
||||
*/
|
||||
public static getGlobalDomToolsSync(): DomTools {
|
||||
const globalDomTools: DomTools = globalThis.deesDomTools;
|
||||
if (!globalDomTools) {
|
||||
throw new Error('You tried to access domtools synchronously too early');
|
||||
}
|
||||
return globalThis.deesDomTools;
|
||||
}
|
||||
|
||||
// ========
|
||||
// INSTANCE
|
||||
// ========
|
||||
// elements
|
||||
public elements: {
|
||||
headElement: HTMLElement;
|
||||
bodyElement: HTMLElement;
|
||||
} = {
|
||||
headElement: null,
|
||||
bodyElement: null,
|
||||
};
|
||||
|
||||
public websetup: WebSetup = new WebSetup({
|
||||
metaObject: {
|
||||
title: 'loading...',
|
||||
},
|
||||
});
|
||||
|
||||
public smartstate = new plugins.smartstate.Smartstate();
|
||||
public domToolsStatePart = this.smartstate.getStatePart<IDomToolsState>('domtools', {
|
||||
virtualViewport: 'native',
|
||||
jwt: null,
|
||||
});
|
||||
|
||||
public router = new plugins.smartrouter.SmartRouter({
|
||||
debug: false,
|
||||
});
|
||||
|
||||
public convenience = {
|
||||
typedrequest: plugins.typedrequest,
|
||||
smartdelay: plugins.smartdelay,
|
||||
};
|
||||
|
||||
public deesComms = new plugins.deesComms.DeesComms();
|
||||
public scroller = new plugins.SweetScroll({
|
||||
/* some options */
|
||||
}); // TODO: switch to scroller class
|
||||
public themeManager = new ThemeManager(this);
|
||||
public keyboard = new Keyboard(document.body);
|
||||
|
||||
public domToolsReady = plugins.smartpromise.defer();
|
||||
public domReady = plugins.smartpromise.defer();
|
||||
public globalStylesReady = plugins.smartpromise.defer();
|
||||
|
||||
constructor(optionsArg: IDomToolsContructorOptions) {}
|
||||
|
||||
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
|
||||
/**
|
||||
* allows to set global styles
|
||||
* @param stylesText the css text you want to set
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* allows to set global styles
|
||||
* @param stylesText the css text you want to set
|
||||
*/
|
||||
public async setExternalScript(scriptLinkArg: string) {
|
||||
await this.domReady.promise;
|
||||
const done = plugins.smartpromise.defer();
|
||||
const script = document.createElement('script')
|
||||
script.src = scriptLinkArg;
|
||||
script.addEventListener('load', function() {
|
||||
done.resolve();
|
||||
});
|
||||
await done.promise;
|
||||
}
|
||||
|
||||
/**
|
||||
* allows setting external css files
|
||||
* @param cssLinkArg a url to an external stylesheet
|
||||
*/
|
||||
public async setExternalCss(cssLinkArg: string) {
|
||||
const cssTag = document.createElement('link');
|
||||
cssTag.rel = 'stylesheet';
|
||||
cssTag.crossOrigin = 'anonymous';
|
||||
cssTag.href = cssLinkArg;
|
||||
document.head.append(cssTag);
|
||||
}
|
||||
|
||||
/**
|
||||
* allows setting of website infos
|
||||
* @param optionsArg the website info
|
||||
*/
|
||||
public async setWebsiteInfo(optionsArg: plugins.websetup.IWebSetupConstructorOptions) {
|
||||
await this.websetup.setup(optionsArg);
|
||||
await this.websetup.readyPromise;
|
||||
}
|
||||
}
|
200
ts/domtools.classes.keyboard.ts
Normal file
200
ts/domtools.classes.keyboard.ts
Normal file
@ -0,0 +1,200 @@
|
||||
import * as plugins from './domtools.plugins.js';
|
||||
|
||||
export enum Key {
|
||||
Backspace = 8,
|
||||
Tab = 9,
|
||||
Enter = 13,
|
||||
Shift = 16,
|
||||
Ctrl = 17,
|
||||
Alt = 18,
|
||||
PauseBreak = 19,
|
||||
CapsLock = 20,
|
||||
Escape = 27,
|
||||
Space = 32,
|
||||
PageUp = 33,
|
||||
PageDown = 34,
|
||||
End = 35,
|
||||
Home = 36,
|
||||
|
||||
LeftArrow = 37,
|
||||
UpArrow = 38,
|
||||
RightArrow = 39,
|
||||
DownArrow = 40,
|
||||
|
||||
Insert = 45,
|
||||
Delete = 46,
|
||||
|
||||
Zero = 48,
|
||||
ClosedParen = Zero,
|
||||
One = 49,
|
||||
ExclamationMark = One,
|
||||
Two = 50,
|
||||
AtSign = Two,
|
||||
Three = 51,
|
||||
PoundSign = Three,
|
||||
Hash = PoundSign,
|
||||
Four = 52,
|
||||
DollarSign = Four,
|
||||
Five = 53,
|
||||
PercentSign = Five,
|
||||
Six = 54,
|
||||
Caret = Six,
|
||||
Hat = Caret,
|
||||
Seven = 55,
|
||||
Ampersand = Seven,
|
||||
Eight = 56,
|
||||
Star = Eight,
|
||||
Asterik = Star,
|
||||
Nine = 57,
|
||||
OpenParen = Nine,
|
||||
|
||||
A = 65,
|
||||
B = 66,
|
||||
C = 67,
|
||||
D = 68,
|
||||
E = 69,
|
||||
F = 70,
|
||||
G = 71,
|
||||
H = 72,
|
||||
I = 73,
|
||||
J = 74,
|
||||
K = 75,
|
||||
L = 76,
|
||||
M = 77,
|
||||
N = 78,
|
||||
O = 79,
|
||||
P = 80,
|
||||
Q = 81,
|
||||
R = 82,
|
||||
S = 83,
|
||||
T = 84,
|
||||
U = 85,
|
||||
V = 86,
|
||||
W = 87,
|
||||
X = 88,
|
||||
Y = 89,
|
||||
Z = 90,
|
||||
|
||||
LeftWindowKey = 91,
|
||||
RightWindowKey = 92,
|
||||
SelectKey = 93,
|
||||
|
||||
Numpad0 = 96,
|
||||
Numpad1 = 97,
|
||||
Numpad2 = 98,
|
||||
Numpad3 = 99,
|
||||
Numpad4 = 100,
|
||||
Numpad5 = 101,
|
||||
Numpad6 = 102,
|
||||
Numpad7 = 103,
|
||||
Numpad8 = 104,
|
||||
Numpad9 = 105,
|
||||
|
||||
Multiply = 106,
|
||||
Add = 107,
|
||||
Subtract = 109,
|
||||
DecimalPoint = 110,
|
||||
Divide = 111,
|
||||
|
||||
F1 = 112,
|
||||
F2 = 113,
|
||||
F3 = 114,
|
||||
F4 = 115,
|
||||
F5 = 116,
|
||||
F6 = 117,
|
||||
F7 = 118,
|
||||
F8 = 119,
|
||||
F9 = 120,
|
||||
F10 = 121,
|
||||
F11 = 122,
|
||||
F12 = 123,
|
||||
|
||||
NumLock = 144,
|
||||
ScrollLock = 145,
|
||||
|
||||
SemiColon = 186,
|
||||
Equals = 187,
|
||||
Comma = 188,
|
||||
Dash = 189,
|
||||
Period = 190,
|
||||
UnderScore = Dash,
|
||||
PlusSign = Equals,
|
||||
ForwardSlash = 191,
|
||||
Tilde = 192,
|
||||
GraveAccent = Tilde,
|
||||
|
||||
OpenBracket = 219,
|
||||
ClosedBracket = 221,
|
||||
Quote = 222,
|
||||
}
|
||||
|
||||
export class Keyboard {
|
||||
private mapCombosToHandlers = new Map<number[], plugins.smartrx.rxjs.Subject<KeyboardEvent>>();
|
||||
private pressedKeys = new Set<Key>();
|
||||
|
||||
constructor(private domNode: Element | Document) {
|
||||
this.startListening();
|
||||
}
|
||||
|
||||
public keyEnum = Key;
|
||||
|
||||
public on(keys: Key[]) {
|
||||
const subject = new plugins.smartrx.rxjs.Subject<KeyboardEvent>();
|
||||
this.registerKeys(keys, subject);
|
||||
return subject;
|
||||
}
|
||||
|
||||
public startListening() {
|
||||
this.domNode.addEventListener('keydown', this.handleKeyDown);
|
||||
this.domNode.addEventListener('keyup', this.handleKeyUp);
|
||||
}
|
||||
|
||||
public stopListening() {
|
||||
this.domNode.removeEventListener('keydown', this.handleKeyDown);
|
||||
this.domNode.removeEventListener('keyup', this.handleKeyUp);
|
||||
}
|
||||
|
||||
public clear() {
|
||||
this.stopListening();
|
||||
this.mapCombosToHandlers.clear();
|
||||
this.pressedKeys.clear();
|
||||
}
|
||||
|
||||
private handleKeyDown = (event: KeyboardEvent) => {
|
||||
this.pressedKeys.add(event.keyCode);
|
||||
|
||||
this.mapCombosToHandlers.forEach((subjectArg, keysArg) => {
|
||||
if (this.areAllKeysPressed(keysArg)) {
|
||||
subjectArg.next(event);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
private handleKeyUp = (event: KeyboardEvent) => {
|
||||
this.pressedKeys.delete(event.keyCode);
|
||||
};
|
||||
|
||||
private areAllKeysPressed(keysArg: Key[]) {
|
||||
let result = true;
|
||||
|
||||
keysArg.forEach((key) => {
|
||||
if (!this.pressedKeys.has(key)) {
|
||||
result = false;
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private registerKeys(
|
||||
keysArg: Array<Key>,
|
||||
subjectArg: plugins.smartrx.rxjs.Subject<KeyboardEvent>
|
||||
) {
|
||||
if (!this.mapCombosToHandlers.has(keysArg)) {
|
||||
this.mapCombosToHandlers.set(keysArg, subjectArg);
|
||||
} else {
|
||||
const subject = this.mapCombosToHandlers.get(keysArg);
|
||||
return subject;
|
||||
}
|
||||
}
|
||||
}
|
5
ts/domtools.classes.scroller.ts
Normal file
5
ts/domtools.classes.scroller.ts
Normal file
@ -0,0 +1,5 @@
|
||||
import * as plugins from './domtools.plugins.js';
|
||||
|
||||
export class Scroller {
|
||||
// TODO: move sweet scroll over to here;
|
||||
}
|
54
ts/domtools.classes.thememanager.ts
Normal file
54
ts/domtools.classes.thememanager.ts
Normal file
@ -0,0 +1,54 @@
|
||||
import { DomTools } from './domtools.classes.domtools.js';
|
||||
import * as plugins from './domtools.plugins.js';
|
||||
|
||||
export class ThemeManager {
|
||||
public domtoolsRef: DomTools;
|
||||
|
||||
public goBrightBoolean = false;
|
||||
public preferredColorSchemeMediaMatch = window.matchMedia('(prefers-color-scheme: light)');
|
||||
|
||||
public themeObservable = new plugins.smartrx.rxjs.ReplaySubject<boolean>(1);
|
||||
|
||||
constructor(domtoolsRefArg: DomTools) {
|
||||
this.domtoolsRef = domtoolsRefArg;
|
||||
|
||||
// lets care
|
||||
this.goBrightBoolean = this.preferredColorSchemeMediaMatch.matches;
|
||||
this.preferredColorSchemeMediaMatch.addEventListener('change', (eventArg) => {
|
||||
this.goBrightBoolean = eventArg.matches;
|
||||
this.updateAllConnectedElements();
|
||||
});
|
||||
this.updateAllConnectedElements();
|
||||
}
|
||||
|
||||
private async updateAllConnectedElements() {
|
||||
if (document.body && document.body.style) {
|
||||
document.body.style.background = this.goBrightBoolean ? '#fff' : '#000';
|
||||
}
|
||||
this.themeObservable.next(this.goBrightBoolean);
|
||||
}
|
||||
|
||||
/**
|
||||
* set the theme of the website to bright
|
||||
*/
|
||||
public goBright() {
|
||||
this.goBrightBoolean = true;
|
||||
this.updateAllConnectedElements();
|
||||
}
|
||||
|
||||
/**
|
||||
* set the theme of the website to dark
|
||||
*/
|
||||
public goDark() {
|
||||
this.goBrightBoolean = false;
|
||||
this.updateAllConnectedElements();
|
||||
}
|
||||
|
||||
/**
|
||||
* simply toggle between bright and dark
|
||||
*/
|
||||
public toggleDarkBright() {
|
||||
this.goBrightBoolean = !this.goBrightBoolean;
|
||||
this.updateAllConnectedElements();
|
||||
}
|
||||
}
|
6
ts/domtools.colors.ts
Normal file
6
ts/domtools.colors.ts
Normal file
@ -0,0 +1,6 @@
|
||||
export interface IDeesColorSet {
|
||||
primaryAccent: string;
|
||||
secondaryAccent: string;
|
||||
primaryBackground: string;
|
||||
secondaryBackground: string;
|
||||
}
|
55
ts/domtools.css.basestyles.ts
Normal file
55
ts/domtools.css.basestyles.ts
Normal file
@ -0,0 +1,55 @@
|
||||
import { DomTools } from './domtools.classes.domtools.js';
|
||||
|
||||
import { css, unsafeCSS } from 'lit';
|
||||
|
||||
/**
|
||||
* changes scrollbar styles to be consistent across OS borders
|
||||
*/
|
||||
export const scrollBarStyles: string = (() => {
|
||||
const returnStyles =
|
||||
navigator.userAgent.indexOf('Mac OS X') === -1
|
||||
? css`
|
||||
/* width */
|
||||
::-webkit-scrollbar {
|
||||
width: 6px;
|
||||
}
|
||||
|
||||
/* Track */
|
||||
::-webkit-scrollbar-track {
|
||||
background: #111;
|
||||
}
|
||||
|
||||
/* Handle */
|
||||
::-webkit-scrollbar-thumb {
|
||||
background: #666;
|
||||
}
|
||||
|
||||
/* Handle on hover */
|
||||
::-webkit-scrollbar-thumb:hover {
|
||||
background: #777;
|
||||
}
|
||||
`.cssText
|
||||
: ``;
|
||||
return returnStyles;
|
||||
})();
|
||||
|
||||
export const globalBaseStyles: string = css`
|
||||
/* global material font */
|
||||
@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');
|
||||
}
|
||||
|
||||
/* global body styles */
|
||||
body {
|
||||
margin: 0px;
|
||||
font-family: 'Roboto', sans-serif;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
/* scroll bar styles */
|
||||
${unsafeCSS(scrollBarStyles)}
|
||||
`.cssText;
|
66
ts/domtools.css.breakpoints.ts
Normal file
66
ts/domtools.css.breakpoints.ts
Normal file
@ -0,0 +1,66 @@
|
||||
import { DomTools } from './domtools.classes.domtools.js';
|
||||
|
||||
import { CSSResult, unsafeCSS } from 'lit';
|
||||
|
||||
export const desktop = 1600;
|
||||
export const notebook = 1240;
|
||||
export const tablet = 1024;
|
||||
export const phablet = 600;
|
||||
export const phone = 400;
|
||||
|
||||
export type TViewport = 'native' | 'desktop' | 'tablet' | 'phablet' | 'phone';
|
||||
|
||||
export const cssForDesktop = (cssArg: CSSResult) => {
|
||||
return unsafeCSS(`
|
||||
@container wccToolsViewport (min-width: ${desktop}px) {
|
||||
${cssArg.cssText}
|
||||
}
|
||||
@media (min-width: ${desktop}px) {
|
||||
${cssArg.cssText}
|
||||
}
|
||||
`);
|
||||
};
|
||||
|
||||
export const cssForNotebook = (cssArg: CSSResult) => {
|
||||
return unsafeCSS(`
|
||||
@container wccToolsViewport (max-width: ${notebook}px) {
|
||||
${cssArg.cssText}
|
||||
}
|
||||
@media (max-width: ${notebook}px) {
|
||||
${cssArg.cssText}
|
||||
}
|
||||
`);
|
||||
};
|
||||
|
||||
export const cssForTablet = (cssArg: CSSResult) => {
|
||||
return unsafeCSS(`
|
||||
@container wccToolsViewport (max-width: ${tablet}px) {
|
||||
${cssArg.cssText}
|
||||
}
|
||||
@media (max-width: ${tablet}px) {
|
||||
${cssArg.cssText}
|
||||
}
|
||||
`);
|
||||
};
|
||||
|
||||
export const cssForPhablet = (cssArg: CSSResult) => {
|
||||
return unsafeCSS(`
|
||||
@container wccToolsViewport (max-width: ${phablet}px) {
|
||||
${cssArg.cssText}
|
||||
}
|
||||
@media (max-width: ${phablet}px) {
|
||||
${cssArg.cssText}
|
||||
}
|
||||
`);
|
||||
};
|
||||
|
||||
export const cssForPhone = (cssArg: CSSResult) => {
|
||||
return unsafeCSS(`
|
||||
@container wccToolsViewport (max-width: ${phone}px) {
|
||||
${cssArg.cssText}
|
||||
}
|
||||
@media (max-width: ${phone}px) {
|
||||
${cssArg.cssText}
|
||||
}
|
||||
`);
|
||||
};
|
9
ts/domtools.css.ts
Normal file
9
ts/domtools.css.ts
Normal file
@ -0,0 +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}))`;
|
||||
}
|
||||
return returnString;
|
||||
};
|
56
ts/domtools.elementbasic.ts
Normal file
56
ts/domtools.elementbasic.ts
Normal file
@ -0,0 +1,56 @@
|
||||
import * as plugins from './domtools.plugins.js';
|
||||
import { DomTools, IDomToolsContructorOptions } from './domtools.classes.domtools.js';
|
||||
import { scrollBarStyles, globalBaseStyles } from './domtools.css.basestyles.js';
|
||||
|
||||
import { html, LitElement, css, unsafeCSS } from 'lit';
|
||||
|
||||
export const staticStyles = css`
|
||||
* {
|
||||
transition: background 0.1s, color 0.1s;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
:host {
|
||||
box-sizing: border-box;
|
||||
font-family: 'Roboto', sans-serif;
|
||||
}
|
||||
|
||||
${unsafeCSS(scrollBarStyles)}
|
||||
`;
|
||||
|
||||
/**
|
||||
* styles to be included in every webcomponent
|
||||
*/
|
||||
export const styles = html`
|
||||
<style>
|
||||
* {
|
||||
transition: background 0.1s, color 0.1s;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
:host {
|
||||
font-family: 'Roboto', sans-serif;
|
||||
}
|
||||
|
||||
${scrollBarStyles}
|
||||
</style>
|
||||
`;
|
||||
|
||||
/**
|
||||
* a basic setup for elements
|
||||
* makes sure everything is in check
|
||||
*/
|
||||
export const setup = async (elementArg?: LitElement, optionsArg: IDomToolsContructorOptions = {}): Promise<DomTools> => {
|
||||
const domTools = await DomTools.setupDomTools(optionsArg);
|
||||
|
||||
if (elementArg) {
|
||||
// lets do something with the element
|
||||
// not used right now
|
||||
}
|
||||
|
||||
domTools.runOnce('elementBasicSetup', async () => {
|
||||
// bodyStyles
|
||||
domTools.setGlobalStyles(globalBaseStyles);
|
||||
});
|
||||
return domTools;
|
||||
};
|
42
ts/domtools.plugins.ts
Normal file
42
ts/domtools.plugins.ts
Normal file
@ -0,0 +1,42 @@
|
||||
// designestate scope
|
||||
import * as deesComms from '@designestate/dees-comms';
|
||||
|
||||
export { deesComms };
|
||||
|
||||
// apiglobal scope
|
||||
import * as typedrequest from '@apiglobal/typedrequest';
|
||||
|
||||
export { typedrequest };
|
||||
|
||||
// pushrocks scope
|
||||
import * as smartdelay from '@pushrocks/smartdelay';
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
import * as smartrouter from '@pushrocks/smartrouter';
|
||||
import * as smartrx from '@pushrocks/smartrx';
|
||||
import * as smartstate from '@pushrocks/smartstate';
|
||||
import * as webrequest from '@pushrocks/webrequest';
|
||||
import * as websetup from '@pushrocks/websetup';
|
||||
import * as webstore from '@pushrocks/webstore';
|
||||
|
||||
// subscope lik
|
||||
import { ObjectMap } from '@pushrocks/lik/dist_ts/lik.objectmap.js';
|
||||
const lik = {
|
||||
ObjectMap,
|
||||
};
|
||||
|
||||
export {
|
||||
lik,
|
||||
smartdelay,
|
||||
smartpromise,
|
||||
smartrouter,
|
||||
smartrx,
|
||||
smartstate,
|
||||
webrequest,
|
||||
websetup,
|
||||
webstore,
|
||||
};
|
||||
|
||||
// third party scope
|
||||
import SweetScroll from 'sweet-scroll';
|
||||
|
||||
export { SweetScroll };
|
22
ts/index.ts
22
ts/index.ts
@ -1,8 +1,20 @@
|
||||
export * from './csstools.elementbasicsetup';
|
||||
export * from './csstools.elementbasicstyles';
|
||||
export * from './domtools.colors.js';
|
||||
|
||||
import * as breakpoints from './csstools.breakpoints';
|
||||
import * as elementBasic from './domtools.elementbasic.js';
|
||||
import * as breakpoints from './domtools.css.breakpoints.js';
|
||||
import * as css from './domtools.css.js';
|
||||
|
||||
export {
|
||||
breakpoints
|
||||
export { css, breakpoints, elementBasic };
|
||||
export { DomTools, IDomToolsContructorOptions } from './domtools.classes.domtools.js';
|
||||
export { TypedRequest } from '@apiglobal/typedrequest';
|
||||
export { IWebSetupConstructorOptions } from '@pushrocks/websetup';
|
||||
export { rxjs } from '@pushrocks/smartrx';
|
||||
|
||||
import * as allPlugins from './domtools.plugins.js';
|
||||
|
||||
export const plugins = {
|
||||
smartdelay: allPlugins.smartdelay,
|
||||
smartpromise: allPlugins.smartpromise,
|
||||
SweetScroll: allPlugins.SweetScroll,
|
||||
smartstate: allPlugins.smartstate
|
||||
};
|
||||
|
6
tsconfig.json
Normal file
6
tsconfig.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2020",
|
||||
"module": "Node12"
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user