Compare commits
36 Commits
Author | SHA1 | Date | |
---|---|---|---|
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 |
1
license
1
license
@ -1,4 +1,5 @@
|
|||||||
Copyright (c) 2020 Lossless GmbH (hello@lossless.com)
|
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
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
19526
package-lock.json
generated
19526
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
27
package.json
27
package.json
@ -1,39 +1,40 @@
|
|||||||
{
|
{
|
||||||
"name": "@designestate/dees-domtools",
|
"name": "@designestate/dees-domtools",
|
||||||
"version": "1.0.109",
|
"version": "2.0.12",
|
||||||
"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",
|
||||||
"typings": "dist_ts/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
|
"type": "module",
|
||||||
"author": "Lossless GmbH",
|
"author": "Lossless GmbH",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/ --web)",
|
"test": "(tstest test/ --web)",
|
||||||
"build": "(tsbuild --web && tsbundle npm)",
|
"build": "(tsbuild --web --allowimplicitany --skiplibcheck && tsbundle npm)",
|
||||||
"format": "(gitzone format)"
|
"format": "(gitzone format)"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.29",
|
"@gitzone/tsbuild": "^2.1.61",
|
||||||
"@gitzone/tsbundle": "^1.0.89",
|
"@gitzone/tsbundle": "^1.0.102",
|
||||||
"@gitzone/tstest": "^1.0.60",
|
"@gitzone/tstest": "^1.0.70",
|
||||||
"@pushrocks/tapbundle": "^4.0.0",
|
"@pushrocks/tapbundle": "^5.0.3",
|
||||||
"@types/node": "^17.0.13",
|
"@types/node": "^17.0.23",
|
||||||
"tslint": "^6.1.3",
|
"tslint": "^6.1.3",
|
||||||
"tslint-config-prettier": "^1.15.0"
|
"tslint-config-prettier": "^1.15.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@apiglobal/typedrequest": "^1.0.65",
|
"@apiglobal/typedrequest": "^2.0.3",
|
||||||
"@designestate/dees-comms": "^1.0.16",
|
"@designestate/dees-comms": "^1.0.22",
|
||||||
"@pushrocks/lik": "^5.0.4",
|
"@pushrocks/lik": "^5.0.4",
|
||||||
"@pushrocks/smartdelay": "^2.0.13",
|
"@pushrocks/smartdelay": "^2.0.13",
|
||||||
"@pushrocks/smartpromise": "^3.1.6",
|
"@pushrocks/smartpromise": "^3.1.7",
|
||||||
"@pushrocks/smartrouter": "^1.0.12",
|
"@pushrocks/smartrouter": "^1.0.12",
|
||||||
"@pushrocks/smartrx": "^2.0.25",
|
"@pushrocks/smartrx": "^2.0.25",
|
||||||
"@pushrocks/smartstate": "^1.0.23",
|
"@pushrocks/smartstate": "^2.0.0",
|
||||||
"@pushrocks/webrequest": "^2.0.13",
|
"@pushrocks/webrequest": "^3.0.3",
|
||||||
"@pushrocks/websetup": "^3.0.16",
|
"@pushrocks/websetup": "^3.0.16",
|
||||||
"@pushrocks/webstore": "^1.0.18",
|
"@pushrocks/webstore": "^1.0.18",
|
||||||
"lit": "^2.1.2",
|
"lit": "^2.2.2",
|
||||||
"sweet-scroll": "^4.0.0"
|
"sweet-scroll": "^4.0.0"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
import * as plugins from './domtools.plugins';
|
import * as plugins from './domtools.plugins.js';
|
||||||
import { Stringmap } from '@pushrocks/lik/dist_ts/lik.stringmap';
|
import { Stringmap } from '@pushrocks/lik/dist_ts/lik.stringmap.js';
|
||||||
import { FastMap } from '@pushrocks/lik/dist_ts/lik.fastmap';
|
import { FastMap } from '@pushrocks/lik/dist_ts/lik.fastmap.js';
|
||||||
import { TViewport } from './domtools.css.breakpoints';
|
import { TViewport } from './domtools.css.breakpoints.js';
|
||||||
|
|
||||||
import { Scroller } from './domtools.classes.scroller';
|
import { Scroller } from './domtools.classes.scroller.js';
|
||||||
import { WebSetup } from '@pushrocks/websetup';
|
import { WebSetup } from '@pushrocks/websetup';
|
||||||
import { ThemeManager } from './domtools.classes.thememanager';
|
import { ThemeManager } from './domtools.classes.thememanager.js';
|
||||||
|
import { Keyboard, Key } from './domtools.classes.keyboard.js';
|
||||||
|
|
||||||
export interface IDomToolsState {
|
export interface IDomToolsState {
|
||||||
virtualViewport: TViewport;
|
virtualViewport: TViewport;
|
||||||
@ -91,18 +92,8 @@ export class DomTools {
|
|||||||
/* some options */
|
/* some options */
|
||||||
}); // TODO: switch to scroller class
|
}); // TODO: switch to scroller class
|
||||||
public themeManager = new ThemeManager(this);
|
public themeManager = new ThemeManager(this);
|
||||||
|
public keyboard = new Keyboard(document.body);
|
||||||
/* private actionSetVirtualViewport = this.domToolsStatePart.createAction<TViewport>(
|
|
||||||
async (statePart, payload) => {
|
|
||||||
const currentState = statePart.getState();
|
|
||||||
currentState.virtualViewport = payload;
|
|
||||||
return currentState;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
public setVirtualViewport(environmentArg: TViewport) {
|
|
||||||
this.domToolsStatePart.dispatchAction(this.actionSetVirtualViewport, environmentArg);
|
|
||||||
} */
|
|
||||||
|
|
||||||
public domToolsReady = plugins.smartpromise.defer();
|
public domToolsReady = plugins.smartpromise.defer();
|
||||||
public domReady = plugins.smartpromise.defer();
|
public domReady = plugins.smartpromise.defer();
|
||||||
|
223
ts/domtools.classes.keyboard.ts
Normal file
223
ts/domtools.classes.keyboard.ts
Normal file
@ -0,0 +1,223 @@
|
|||||||
|
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,
|
||||||
|
}
|
||||||
|
|
||||||
|
type KeyCombo = Array<Key>;
|
||||||
|
|
||||||
|
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[] | KeyCombo[]) {
|
||||||
|
const combos = this.toCombos(keys);
|
||||||
|
const subject = new plugins.smartrx.rxjs.Subject<KeyboardEvent>();
|
||||||
|
combos.forEach((combo) => {
|
||||||
|
this.registerComboCallback(combo, 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, comboArg) => {
|
||||||
|
if (this.isComboPressed(comboArg)) {
|
||||||
|
subjectArg.next(event);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
private handleKeyUp = (event: KeyboardEvent) => {
|
||||||
|
this.pressedKeys.delete(event.keyCode);
|
||||||
|
};
|
||||||
|
|
||||||
|
private isComboPressed(combo: number[]) {
|
||||||
|
let result = true;
|
||||||
|
|
||||||
|
combo.forEach((key) => {
|
||||||
|
if (!this.pressedKeys.has(key)) {
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private registerComboCallback(
|
||||||
|
comboArg: Array<Key>,
|
||||||
|
subjectArg: plugins.smartrx.rxjs.Subject<KeyboardEvent>
|
||||||
|
) {
|
||||||
|
if (!this.mapCombosToHandlers.has(comboArg)) {
|
||||||
|
this.mapCombosToHandlers.set(comboArg, subjectArg);
|
||||||
|
} else {
|
||||||
|
const subject = this.mapCombosToHandlers.get(comboArg);
|
||||||
|
return subject;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private toCombos(keys: KeyCombo[] | Key[]) {
|
||||||
|
if (keys.length === 0) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
const isKeys = !Array.isArray(keys[0]);
|
||||||
|
let combos: KeyCombo[] = [];
|
||||||
|
|
||||||
|
if (isKeys) {
|
||||||
|
combos = (keys as Key[]).map((key) => [key]);
|
||||||
|
} else {
|
||||||
|
combos = keys as KeyCombo[];
|
||||||
|
combos = combos.filter((combo) => combo.length > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return combos;
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
import * as plugins from './domtools.plugins';
|
import * as plugins from './domtools.plugins.js';
|
||||||
|
|
||||||
export class Scroller {
|
export class Scroller {
|
||||||
// TODO: move sweet scroll over to here;
|
// TODO: move sweet scroll over to here;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { DomTools } from './domtools.classes.domtools';
|
import { DomTools } from './domtools.classes.domtools.js';
|
||||||
import * as plugins from './domtools.plugins';
|
import * as plugins from './domtools.plugins.js';
|
||||||
|
|
||||||
export class ThemeManager {
|
export class ThemeManager {
|
||||||
public domtoolsRef: DomTools;
|
public domtoolsRef: DomTools;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { DomTools } from './domtools.classes.domtools';
|
import { DomTools } from './domtools.classes.domtools.js';
|
||||||
|
|
||||||
import { css, unsafeCSS } from 'lit';
|
import { css, unsafeCSS } from 'lit';
|
||||||
|
|
||||||
@ -43,10 +43,6 @@ export const globalBaseStyles: string = css`
|
|||||||
format('woff2');
|
format('woff2');
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Roboto Font */
|
|
||||||
@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');
|
|
||||||
|
|
||||||
/* global body styles */
|
/* global body styles */
|
||||||
body {
|
body {
|
||||||
margin: 0px;
|
margin: 0px;
|
||||||
|
@ -1,14 +1,37 @@
|
|||||||
import { DomTools } from './domtools.classes.domtools';
|
import { DomTools } from './domtools.classes.domtools.js';
|
||||||
|
|
||||||
import { CSSResult, unsafeCSS } from 'lit';
|
import { CSSResult, unsafeCSS } from 'lit';
|
||||||
|
|
||||||
export const desktop = 1240;
|
export const desktop = 1600;
|
||||||
|
export const notebook = 1240;
|
||||||
export const tablet = 1024;
|
export const tablet = 1024;
|
||||||
export const phablet = 600;
|
export const phablet = 600;
|
||||||
export const phone = 400;
|
export const phone = 400;
|
||||||
|
|
||||||
export type TViewport = 'native' | 'desktop' | 'tablet' | 'phablet' | 'phone';
|
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) => {
|
export const cssForTablet = (cssArg: CSSResult) => {
|
||||||
return unsafeCSS(`
|
return unsafeCSS(`
|
||||||
@container wccToolsViewport (max-width: ${tablet}px) {
|
@container wccToolsViewport (max-width: ${tablet}px) {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import * as plugins from './domtools.plugins';
|
import * as plugins from './domtools.plugins.js';
|
||||||
import { DomTools } from './domtools.classes.domtools';
|
import { DomTools } from './domtools.classes.domtools.js';
|
||||||
import { scrollBarStyles, globalBaseStyles } from './domtools.css.basestyles';
|
import { scrollBarStyles, globalBaseStyles } from './domtools.css.basestyles.js';
|
||||||
|
|
||||||
import { html, LitElement, css, unsafeCSS } from 'lit';
|
import { html, LitElement, css, unsafeCSS } from 'lit';
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ import * as websetup from '@pushrocks/websetup';
|
|||||||
import * as webstore from '@pushrocks/webstore';
|
import * as webstore from '@pushrocks/webstore';
|
||||||
|
|
||||||
// subscope lik
|
// subscope lik
|
||||||
import { ObjectMap } from '@pushrocks/lik/dist_ts/lik.objectmap';
|
import { ObjectMap } from '@pushrocks/lik/dist_ts/lik.objectmap.js';
|
||||||
const lik = {
|
const lik = {
|
||||||
ObjectMap,
|
ObjectMap,
|
||||||
};
|
};
|
||||||
|
12
ts/index.ts
12
ts/index.ts
@ -1,16 +1,16 @@
|
|||||||
export * from './domtools.colors';
|
export * from './domtools.colors.js';
|
||||||
|
|
||||||
import * as elementBasic from './domtools.elementbasic';
|
import * as elementBasic from './domtools.elementbasic.js';
|
||||||
import * as breakpoints from './domtools.css.breakpoints';
|
import * as breakpoints from './domtools.css.breakpoints.js';
|
||||||
import * as css from './domtools.css';
|
import * as css from './domtools.css.js';
|
||||||
|
|
||||||
export { css, breakpoints, elementBasic };
|
export { css, breakpoints, elementBasic };
|
||||||
export { DomTools } from './domtools.classes.domtools';
|
export { DomTools } from './domtools.classes.domtools.js';
|
||||||
export { TypedRequest } from '@apiglobal/typedrequest';
|
export { TypedRequest } from '@apiglobal/typedrequest';
|
||||||
export { IWebSetupConstructorOptions } from '@pushrocks/websetup';
|
export { IWebSetupConstructorOptions } from '@pushrocks/websetup';
|
||||||
export { rxjs } from '@pushrocks/smartrx';
|
export { rxjs } from '@pushrocks/smartrx';
|
||||||
|
|
||||||
import * as allPlugins from './domtools.plugins';
|
import * as allPlugins from './domtools.plugins.js';
|
||||||
|
|
||||||
export const plugins = {
|
export const plugins = {
|
||||||
smartdelay: allPlugins.smartdelay,
|
smartdelay: allPlugins.smartdelay,
|
||||||
|
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