Compare commits

...

123 Commits

Author SHA1 Message Date
94127227a6 1.0.79 2020-12-01 21:06:54 +00:00
b5af1b1226 fix(core): update 2020-12-01 21:06:53 +00:00
a6f382dd7f 1.0.78 2020-12-01 17:31:38 +00:00
0de00cb2c1 fix(core): update 2020-12-01 17:31:37 +00:00
570a026cf8 1.0.77 2020-11-30 20:03:05 +00:00
48b5cc770c fix(core): update 2020-11-30 20:03:05 +00:00
7ae2de5843 1.0.76 2020-11-30 10:25:00 +00:00
e4d87ae882 fix(core): update 2020-11-30 10:25:00 +00:00
259a669e24 1.0.75 2020-11-29 23:56:20 +00:00
bf461dd1a0 fix(core): update 2020-11-29 23:56:19 +00:00
63c9ae97d4 1.0.74 2020-11-25 15:42:56 +00:00
a83239e0d9 fix(core): update 2020-11-25 15:42:55 +00:00
8da64f1b50 1.0.73 2020-11-25 15:14:48 +00:00
2d4c0e4e49 fix(core): update 2020-11-25 15:14:48 +00:00
1c8f7fa59e 1.0.72 2020-11-25 14:56:09 +00:00
a613c0aca2 fix(core): update 2020-11-25 14:56:08 +00:00
127564cd71 1.0.71 2020-11-25 14:43:23 +00:00
e077bf5b25 fix(core): update 2020-11-25 14:43:23 +00:00
64a3f57813 1.0.70 2020-11-24 20:57:42 +00:00
1315e8c3f6 fix(core): update 2020-11-24 20:57:41 +00:00
d059862841 1.0.69 2020-11-24 19:48:14 +00:00
ad34affb9e fix(core): update 2020-11-24 19:48:14 +00:00
011b3fb76a 1.0.68 2020-11-24 19:23:07 +00:00
47099d02b5 fix(core): update 2020-11-24 19:23:06 +00:00
f4029ed008 1.0.67 2020-11-24 19:19:00 +00:00
d5732822e4 fix(core): update 2020-11-24 19:18:59 +00:00
c467a92e7c 1.0.66 2020-11-24 16:55:58 +00:00
746c1148e3 fix(core): update 2020-11-24 16:55:57 +00:00
d75e66ba78 1.0.65 2020-11-23 20:41:27 +00:00
7c805a075e fix(core): update 2020-11-23 20:41:26 +00:00
5e1a44ad88 1.0.64 2020-11-21 16:50:14 +00:00
093eae2c97 fix(core): update 2020-11-21 16:50:13 +00:00
991d318de6 1.0.63 2020-11-06 01:27:47 +00:00
c7c3650fe9 fix(core): update 2020-11-06 01:27:46 +00:00
8d355f234f 1.0.62 2020-11-05 20:08:07 +00:00
a5c22ec1db fix(core): update 2020-11-05 20:08:07 +00:00
f5263a0cc4 1.0.61 2020-11-05 18:50:28 +00:00
4a022a7d1d fix(core): update 2020-11-05 18:50:28 +00:00
bd6ba6d6db 1.0.60 2020-11-05 18:08:42 +00:00
317bc63bc7 fix(core): update 2020-11-05 18:08:42 +00:00
22eeb7809b 1.0.59 2020-11-05 17:37:45 +00:00
fdd550ec21 fix(core): update 2020-11-05 17:37:45 +00:00
9db1f92ba3 1.0.58 2020-11-05 17:20:01 +00:00
772d0b0b97 fix(core): update 2020-11-05 17:20:01 +00:00
a68e9e1bf9 1.0.57 2020-11-05 15:40:35 +00:00
f9507b0dbd fix(core): update 2020-11-05 15:40:35 +00:00
f8c1a0135a 1.0.56 2020-11-04 18:35:46 +00:00
7d884f6556 fix(core): update 2020-11-04 18:35:45 +00:00
8a8ee5cd7b 1.0.55 2020-10-07 13:13:22 +00:00
1660381be6 fix(core): update 2020-10-07 13:13:21 +00:00
f0ad441415 1.0.54 2020-10-06 22:08:27 +00:00
27c087b693 fix(core): update 2020-10-06 22:08:26 +00:00
63463a751c 1.0.53 2020-09-16 15:10:53 +00:00
a01f5a5b8a fix(core): update 2020-09-16 15:10:52 +00:00
bb1ad4e037 1.0.52 2020-09-16 13:57:16 +00:00
eb871161f9 fix(core): update 2020-09-16 13:57:16 +00:00
090e5b4d42 1.0.51 2020-09-16 11:29:27 +00:00
8168dd1a0c fix(core): update 2020-09-16 11:29:26 +00:00
de15bc0d1c 1.0.50 2020-09-16 10:06:23 +00:00
13fa3d655e fix(core): update 2020-09-16 10:06:22 +00:00
18b93b860d 1.0.49 2020-09-15 20:56:34 +00:00
e8e6416b6f fix(core): update 2020-09-15 20:56:33 +00:00
fbe2f381c9 1.0.48 2020-09-15 20:24:12 +00:00
3cb0aceaad fix(core): update 2020-09-15 20:24:11 +00:00
6d6c92eee4 1.0.47 2020-09-13 15:53:31 +00:00
4385909677 fix(core): update 2020-09-13 15:53:30 +00:00
2dc36d8170 1.0.46 2020-09-13 14:58:27 +00:00
ffbde62744 fix(core): update 2020-09-13 14:58:26 +00:00
7bde843e43 1.0.45 2020-09-13 14:57:31 +00:00
faa7adcffe fix(core): update 2020-09-13 14:57:30 +00:00
7977538c05 1.0.44 2020-09-12 14:00:12 +00:00
afaa88047c 1.0.43 2020-09-12 13:14:17 +00:00
8aabe2820e fix(core): update 2020-09-12 13:14:17 +00:00
570d370c97 1.0.42 2020-09-12 13:11:11 +00:00
73552ad80f fix(core): update 2020-09-12 13:11:10 +00:00
537902aa53 1.0.41 2020-07-29 17:32:28 +00:00
e033bfa5b3 fix(core): update 2020-07-29 17:32:28 +00:00
4983e1ed90 1.0.40 2020-07-27 18:23:48 +00:00
899775b050 fix(core): update 2020-07-27 18:23:47 +00:00
7655fc0348 1.0.39 2020-07-27 17:11:01 +00:00
8aa5576318 fix(core): update 2020-07-27 17:11:00 +00:00
1ff54b0fcd 1.0.38 2020-07-15 18:58:40 +00:00
3901258272 fix(core): update 2020-07-15 18:58:40 +00:00
27380d1483 1.0.37 2020-07-15 18:12:27 +00:00
e2f9991f96 fix(core): update 2020-07-15 18:12:27 +00:00
133ce80b0a 1.0.36 2020-06-30 14:08:35 +00:00
cf12f45c9b fix(core): update 2020-06-30 14:08:35 +00:00
6cc5ec315e 1.0.35 2020-06-28 21:26:57 +00:00
88810bae2c fix(core): update 2020-06-28 21:26:57 +00:00
21369d8da5 1.0.34 2020-06-28 18:03:23 +00:00
a5973944ee fix(core): update 2020-06-28 18:03:22 +00:00
ad3f4b31fa 1.0.33 2020-06-28 17:40:03 +00:00
91b50ecde5 fix(core): update 2020-06-28 17:40:03 +00:00
45fecfbde8 1.0.32 2020-06-28 16:59:15 +00:00
e3e6d06969 fix(core): update 2020-06-28 16:59:14 +00:00
50ace4c236 1.0.31 2020-06-28 16:42:31 +00:00
90f68965bb fix(core): update 2020-06-28 16:42:30 +00:00
6c92a9cdf8 1.0.30 2020-06-28 15:49:47 +00:00
d4e24d615a fix(core): update 2020-06-28 15:49:46 +00:00
37b7dca212 1.0.29 2020-06-26 01:39:10 +00:00
7d9dc1ad65 fix(core): update 2020-06-26 01:39:10 +00:00
20f06e5935 1.0.28 2020-06-03 10:34:10 +00:00
d3fa33f0cc fix(core): update 2020-06-03 10:34:09 +00:00
aa91dad272 1.0.27 2020-06-03 09:07:32 +00:00
05a22599b8 fix(core): update 2020-06-03 09:07:31 +00:00
bd0b279fc2 1.0.26 2020-06-01 12:30:22 +00:00
8276a5b09b fix(core): update 2020-06-01 12:30:21 +00:00
a9200859ec 1.0.25 2020-05-27 23:53:32 +00:00
210a0ad8a1 fix(core): update 2020-05-27 23:53:32 +00:00
2756a3cb68 1.0.24 2020-05-27 22:41:09 +00:00
acf0ea3874 fix(core): update 2020-05-27 22:41:08 +00:00
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
19 changed files with 9384 additions and 1056 deletions

View File

@ -19,23 +19,35 @@ mirror:
stage: security stage: security
script: script:
- npmci git mirror - npmci git mirror
only:
- tags
tags: tags:
- lossless - lossless
- docker - docker
- notpriv - 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
auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security stage: security
script: script:
- npmci npm prepare - npmci npm prepare
- npmci command npm install --ignore-scripts - npmci command npm install --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org - 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: tags:
- lossless
- docker - docker
- notpriv allow_failure: true
# ==================== # ====================
# test stage # test stage
@ -50,9 +62,7 @@ testStable:
- npmci npm test - npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/ coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- lossless
- docker - docker
- priv
testBuild: testBuild:
stage: test stage: test
@ -63,9 +73,7 @@ testBuild:
- npmci command npm run build - npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/ coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- lossless
- docker - docker
- notpriv
release: release:
stage: release stage: release
@ -85,6 +93,8 @@ release:
codequality: codequality:
stage: metadata stage: metadata
allow_failure: true allow_failure: true
only:
- tags
script: script:
- npmci command npm install -g tslint typescript - npmci command npm install -g tslint typescript
- npmci npm prepare - npmci npm prepare

View File

@ -15,7 +15,7 @@
"properties": { "properties": {
"projectType": { "projectType": {
"type": "string", "type": "string",
"enum": ["website", "element", "service", "npm"] "enum": ["website", "element", "service", "npm", "wcc"]
} }
} }
} }

9963
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.17", "version": "1.0.79",
"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",
@ -13,19 +13,27 @@
"format": "(gitzone format)" "format": "(gitzone format)"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.0.22", "@gitzone/tsbuild": "^2.1.25",
"@gitzone/tsbundle": "^1.0.69", "@gitzone/tsbundle": "^1.0.78",
"@gitzone/tstest": "^1.0.15", "@gitzone/tstest": "^1.0.52",
"@pushrocks/tapbundle": "^3.0.7", "@pushrocks/tapbundle": "^3.2.9",
"@types/node": "^14.0.5", "@types/node": "^14.14.10",
"tslint": "^6.1.2", "tslint": "^6.1.3",
"tslint-config-prettier": "^1.15.0" "tslint-config-prettier": "^1.15.0"
}, },
"dependencies": { "dependencies": {
"@pushrocks/lik": "^4.0.4", "@apiglobal/typedrequest": "^1.0.54",
"@pushrocks/smartpromise": "^3.0.6", "@designestate/dees-comms": "^1.0.7",
"@pushrocks/smartstate": "^1.0.15", "@pushrocks/lik": "^4.0.20",
"lit-element": "^2.3.1" "@pushrocks/smartdelay": "^2.0.10",
"@pushrocks/smartpromise": "^3.1.3",
"@pushrocks/smartrouter": "^1.0.6",
"@pushrocks/smartstate": "^1.0.21",
"@pushrocks/webrequest": "^2.0.13",
"@pushrocks/websetup": "^3.0.11",
"@pushrocks/webstore": "^1.0.16",
"lit-element": "^2.4.0",
"sweet-scroll": "^4.0.0"
}, },
"files": [ "files": [
"ts/**/*", "ts/**/*",
@ -38,5 +46,8 @@
"cli.js", "cli.js",
"npmextra.json", "npmextra.json",
"readme.md" "readme.md"
],
"browserslist": [
"last 1 chrome versions"
] ]
} }

View File

@ -8,13 +8,20 @@ tools to simplify complex css structures
* [docs (typedoc)](https://designestate.gitlab.io/dees-domtools/) * [docs (typedoc)](https://designestate.gitlab.io/dees-domtools/)
## Status for master ## Status for master
[![pipeline status](https://gitlab.com/designestate/dees-domtools/badges/master/pipeline.svg)](https://gitlab.com/designestate/dees-domtools/commits/master)
[![coverage report](https://gitlab.com/designestate/dees-domtools/badges/master/coverage.svg)](https://gitlab.com/designestate/dees-domtools/commits/master) Status Category | Status Badge
[![npm downloads per month](https://img.shields.io/npm/dm/@designestate/dees-domtools.svg)](https://www.npmjs.com/package/@designestate/dees-domtools) -- | --
[![Known Vulnerabilities](https://snyk.io/test/npm/@designestate/dees-domtools/badge.svg)](https://snyk.io/test/npm/@designestate/dees-domtools) GitLab Pipelines | [![pipeline status](https://gitlab.com/designestate/dees-domtools/badges/master/pipeline.svg)](https://lossless.cloud)
[![TypeScript](https://img.shields.io/badge/TypeScript->=%203.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/) GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/designestate/dees-domtools/badges/master/coverage.svg)](https://lossless.cloud)
[![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/) npm | [![npm downloads per month](https://badgen.net/npm/dy/@designestate/dees-domtools)](https://lossless.cloud)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-prettier-ff69b4.svg)](https://prettier.io/) Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/designestate/dees-domtools)](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@designestate/dees-domtools)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@designestate/dees-domtools)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@designestate/dees-domtools)](https://lossless.cloud)
Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20Windows%2010/yes/green?icon=windows)](https://lossless.cloud) [![Supports Mac OS X](https://badgen.net/badge/supports%20Mac%20OS%20X/yes/green?icon=apple)](https://lossless.cloud)
## Usage ## Usage

9
test/test.browser.ts Normal file
View 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).to.be.instanceof(domtools.DomTools);
});
tap.start();

View File

@ -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();

View File

@ -1,24 +1,35 @@
import { DomTools } from './domtools.classes.domtools';
export const desktop = 1240; export const desktop = 1240;
export const tablet = 700; export const tablet = 1024;
export const phablet = 500; export const phablet = 600;
export const phone = 340; export const phone = 400;
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 (
export const setEnvironment = envArg => { globalThis.deesDomTools &&
environment = envArg; globalThis.deesDomTools.domToolsStatePart.getState().virtualViewport
) {
return globalThis.deesDomTools.domToolsStatePart.getState().virtualViewport;
} else {
return 'native';
}
}; };
export const cssForTablet = (contentArg) => { export const cssForTablet = (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}
@ -28,13 +39,13 @@ export const cssForTablet = (contentArg) => {
}; };
export const cssForPhablet = (contentArg) => { export const cssForPhablet = (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}
@ -44,13 +55,13 @@ export const cssForPhablet = (contentArg) => {
}; };
export const cssForPhone = (contentArg) => { export const cssForPhone = (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,13 +1,31 @@
import * as plugins from './domtools.plugins'; import * as plugins from './domtools.plugins';
import { Stringmap } from '@pushrocks/lik/dist_ts/lik.stringmap'; import { Stringmap } from '@pushrocks/lik/dist_ts/lik.stringmap';
import { FastMap } from '@pushrocks/lik/dist_ts/lik.fastmap'; import { FastMap } from '@pushrocks/lik/dist_ts/lik.fastmap';
import { TViewport } from './domtools.breakpoints';
import { Scroller } from './domtools.classes.scroller';
import { delayForRandom } from '@pushrocks/smartdelay';
import { WebSetup } from '@pushrocks/websetup';
import { ElementInstrumenter } from './domtools.classes.elementinstrumenter';
import { ThemeManager } from './domtools.classes.thememanager';
export interface IDomToolsState {
virtualViewport: TViewport;
}
export class DomTools { export class DomTools {
// ======
// STATIC
// ======
/**
* setups domtools
*/
public static async setupDomTools() { public static async setupDomTools() {
let domToolsInstance: DomTools; let domToolsInstance: DomTools;
if (!globalThis.deesDomTools) { if (!globalThis.deesDomTools) {
globalThis.deesDomTools = new DomTools(); globalThis.deesDomTools = new DomTools();
domToolsInstance = globalThis.deesDomTools; domToolsInstance = globalThis.deesDomTools;
// lets make sure the dom is ready // lets make sure the dom is ready
const readyStateChangedFunc = () => { const readyStateChangedFunc = () => {
if (document.readyState === 'interactive' || document.readyState === 'complete') { if (document.readyState === 'interactive' || document.readyState === 'complete') {
@ -25,12 +43,20 @@ export class DomTools {
return domToolsInstance; return domToolsInstance;
} }
public smartstate = new plugins.smartstate.Smartstate(); /**
* if you can, use the static asysnc .setupDomTools() function instead since it is safer to use.
public domToolsReady = plugins.smartpromise.defer(); */
public domReady = plugins.smartpromise.defer(); public static getGlobalDomToolsSync(): DomTools {
public globalStylesReady = plugins.smartpromise.defer(); const globalDomTools: DomTools = globalThis.deesDomTools;
if (!globalDomTools) {
throw new Error('You tried to access domtools synchronously too early');
}
return globalThis.deesDomTools;
}
// ========
// INSTANCE
// ========
// elements // elements
public elements: { public elements: {
headElement: HTMLElement; headElement: HTMLElement;
@ -40,6 +66,75 @@ export class DomTools {
bodyElement: 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',
});
public router = new plugins.smartrouter.SmartRouter({
debug: false,
});
public convenience = {
smartdelay: plugins.smartdelay,
};
public elementInstrumenter = new ElementInstrumenter();
public deesComms = new plugins.deesComms.DeesComms();
public scroller = new plugins.SweetScroll({
/* some options */
}); // TODO: switch to scroller class
public themeManager = new ThemeManager(this);
private 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();
constructor() {}
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
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');
@ -48,27 +143,20 @@ export class DomTools {
this.elements.headElement.appendChild(styleElement); this.elements.headElement.appendChild(styleElement);
} }
private runOnceTrackerStringMap = new Stringmap(); public async setExternalCss(cssLinkArg: string) {
private runOnceResultMap = new FastMap(); const cssTag = document.createElement('link');
/** cssTag.rel = 'stylesheet';
* run a function once and always get the Promise of the first execution cssTag.crossOrigin = 'anonymous';
* @param identifierArg cssTag.href = cssLinkArg;
* @param funcArg document.head.append(cssTag);
*/
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);
});
} }
} public setVirtualViewport(environmentArg: TViewport) {
this.domToolsStatePart.dispatchAction(this.actionSetVirtualViewport, environmentArg);
}
public async setWebsiteInfo(optionsArg: plugins.websetup.IWebSetupConstructorOptions) {
await this.websetup.setup(optionsArg);
await this.websetup.readyPromise;
}
}

View File

@ -0,0 +1,29 @@
import * as plugins from './domtools.plugins';
import { LitElement } from 'lit-element';
export class ElementInstrumenter {
connectedElements = new plugins.lik.ObjectMap<LitElement>();
public instrumentElement(elementArg: LitElement) {
const addToConnectedElementsFunc = (eventArg: CustomEvent) => {
this.connectedElements.add(elementArg);
};
const removeFromConnectedElementsFunc = eventArg => {
this.connectedElements.remove(elementArg);
elementArg.removeEventListener('domtools-connected', addToConnectedElementsFunc);
elementArg.removeEventListener('domtools-disconnected', removeFromConnectedElementsFunc);
};
elementArg.addEventListener('domtools-connected', addToConnectedElementsFunc);
elementArg.addEventListener('domtools-disconnected', removeFromConnectedElementsFunc);
if (elementArg.parentElement) {
this.connectedElements.add(elementArg);
}
}
public async forEachelement(eachFuncArg: (elementArg: LitElement) => Promise<void>) {
for (const elementArg of this.connectedElements.getArray()) {
await eachFuncArg(elementArg);
}
}
}

View File

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

View File

@ -0,0 +1,5 @@
import * as plugins from './domtools.plugins';
export class Scroller {
// TODO: move sweet scroll over to here;
}

View File

@ -0,0 +1,55 @@
import { LitElement } from 'lit-element';
import { DomTools } from './domtools.classes.domtools';
import * as plugins from './domtools.plugins';
export class ThemeManager {
public domtoolsRef: DomTools;
public goBrightBoolean = false;
public preferredColorSchemeMediaMatch = window.matchMedia('(prefers-color-scheme: light)');
constructor(domtoolsRefArg: DomTools) {
this.domtoolsRef = domtoolsRefArg;
// lets take care of elements being added that need to know of the current theme
this.domtoolsRef.elementInstrumenter.connectedElements.eventSubject.subscribe(async eventData => {
await this.setThemeStatusForElement(eventData.payload, this.goBrightBoolean);
});
// lets care
this.goBrightBoolean = this.preferredColorSchemeMediaMatch.matches;
this.preferredColorSchemeMediaMatch.addEventListener('change', eventArg => {
this.goBrightBoolean = eventArg.matches;
this.updateAllConnectedElements();
});
}
private async setThemeStatusForElement (elementArg: LitElement, goBrightBool: boolean) {
const goBright = (elementArg as any).goBright;
if (typeof goBright === 'boolean') {
(elementArg as any).goBright = goBrightBool;
}
}
private async updateAllConnectedElements() {
document.body.style.background = this.goBrightBoolean ? '#fff' : '#000';
this.domtoolsRef.elementInstrumenter.forEachelement(async elementArg => {
await this.setThemeStatusForElement(elementArg, this.goBrightBoolean);
});
}
public goBright() {
this.goBrightBoolean = true;
this.updateAllConnectedElements();
}
public goDark() {
this.goBrightBoolean = false;
this.updateAllConnectedElements();
}
public toggleDarkBright() {
this.goBrightBoolean = !this.goBrightBoolean;
this.updateAllConnectedElements();
}
}

View File

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

28
ts/domtools.css.theme.ts Normal file
View File

@ -0,0 +1,28 @@
import { DomTools } from './domtools.classes.domtools';
/**
* changes scrollbar styles to be consistent across OS borders
*/
export const scrollBarStyles = (() => {
const returnStyles = navigator.userAgent.indexOf("Windows") !== -1 ? `
/* width */
::-webkit-scrollbar {
width: 8px;
}
/* Track */
::-webkit-scrollbar-track {
background: #111;
}
/* Handle */
::-webkit-scrollbar-thumb {
background: #666;
}
/* Handle on hover */
::-webkit-scrollbar-thumb:hover {
background: #777;
}
` : ``;
})();

View File

@ -1,7 +1,9 @@
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,24 +1,35 @@
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 { scrollBarStyles } from './domtools.css.theme';
import { html, LitElement } from 'lit-element';
import { html } from 'lit-element'; /**
* styles to be included in every webcomponent
*/
export const styles = html` export const styles = html`
<style> <style>
* { * {
transition: background 0.1s, color 0.1s;
font-family: 'Roboto', sans-serif; font-family: 'Roboto', sans-serif;
box-sizing: border-box; box-sizing: border-box;
} }
${scrollBarStyles}
</style> </style>
`; `;
/** /**
* a basic setup for elements * a basic setup for elements
* makes sure everything is in check * makes sure everything is in check
*/ */
export const setup = async () => { export const setup = async (elementArg?: LitElement): Promise<DomTools> => {
const domTools = await DomTools.setupDomTools(); const domTools = await DomTools.setupDomTools();
if (elementArg) {
domTools.elementInstrumenter.instrumentElement(elementArg);
}
domTools.runOnce('elementBasicSetup', async () => { domTools.runOnce('elementBasicSetup', async () => {
// bodyStyles // bodyStyles
domTools.setGlobalStyles(` domTools.setGlobalStyles(`
@ -41,7 +52,14 @@ export const setup = async () => {
// Roboto Font // Roboto Font
domTools.setGlobalStyles(` domTools.setGlobalStyles(`
@import url('https://fonts.googleapis.com/css?family=Roboto'); @import url('https://fonts.googleapis.com/css2?family=Roboto:wght@100;300;400');
@import url('https://fonts.googleapis.com/css2?family=Roboto+Mono:wght@100;300;400');
`);
// scrollbars
domTools.setGlobalStyles(`
${scrollBarStyles}
`); `);
}); });
return domTools;
}; };

View File

@ -1,8 +1,33 @@
// pushrocks scope // designestate scope
import * as smartpromise from '@pushrocks/smartpromise'; import * as deesComms from '@designestate/dees-comms';
import * as smartstate from '@pushrocks/smartstate';
export { export {
smartpromise, deesComms
smartstate
}; };
// 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 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';
const lik = {
ObjectMap
};
export { lik, smartdelay, smartpromise, smartrouter, smartstate, webrequest, websetup, webstore };
// third party scope
import SweetScroll from 'sweet-scroll';
export { SweetScroll };

View File

@ -4,8 +4,12 @@ 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, export { TypedRequest } from '@apiglobal/typedrequest';
elementBasic
import * as allPlugins from './domtools.plugins';
export const plugins = {
smartpromise: allPlugins.smartpromise,
}; };