jj 0.1.1 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +36 -7
  3. package/lib/WC.d.ts +45 -0
  4. package/lib/WC.js +118 -0
  5. package/lib/WC.js.map +1 -0
  6. package/lib/WDF.d.ts +11 -0
  7. package/lib/WDF.js +31 -0
  8. package/lib/WDF.js.map +1 -0
  9. package/lib/WE.d.ts +43 -0
  10. package/lib/WE.js +133 -0
  11. package/lib/WE.js.map +1 -0
  12. package/lib/WHE.d.ts +21 -0
  13. package/lib/WHE.js +75 -0
  14. package/lib/WHE.js.map +1 -0
  15. package/lib/WN-mixin.d.ts +9 -0
  16. package/lib/WN-mixin.js +59 -0
  17. package/lib/WN-mixin.js.map +1 -0
  18. package/lib/WN.d.ts +34 -0
  19. package/lib/WN.js +145 -0
  20. package/lib/WN.js.map +1 -0
  21. package/lib/WSH.d.ts +11 -0
  22. package/lib/WSH.js +29 -0
  23. package/lib/WSH.js.map +1 -0
  24. package/lib/WT.d.ts +12 -0
  25. package/lib/WT.js +39 -0
  26. package/lib/WT.js.map +1 -0
  27. package/lib/bundle.js +706 -0
  28. package/lib/bundle.js.map +7 -0
  29. package/lib/bundle.min.js +2 -0
  30. package/lib/case.d.ts +3 -0
  31. package/lib/case.js +34 -0
  32. package/lib/case.js.map +1 -0
  33. package/lib/case.test.d.ts +1 -0
  34. package/lib/case.test.js +79 -0
  35. package/lib/case.test.js.map +1 -0
  36. package/lib/h.d.ts +3 -0
  37. package/lib/h.js +9 -0
  38. package/lib/h.js.map +1 -0
  39. package/lib/index.d.ts +11 -0
  40. package/lib/index.js +12 -0
  41. package/lib/index.js.map +1 -0
  42. package/lib/util.d.ts +4 -0
  43. package/lib/util.js +11 -0
  44. package/lib/util.js.map +1 -0
  45. package/package.json +56 -26
  46. package/CSS.js +0 -145
  47. package/Router.js +0 -89
  48. package/Selector.js +0 -175
  49. package/Tag.js +0 -827
  50. package/control.js +0 -74
  51. package/dist/jj.js +0 -1580
  52. package/dist/jj.js.gz +0 -0
  53. package/dist/jj.min.js +0 -1
  54. package/dist/jj.min.js.gz +0 -0
  55. package/dist/jj.min.js.map +0 -1
  56. package/events.js +0 -16
  57. package/index.js +0 -26
  58. package/observer.js +0 -27
  59. package/rollup.config.js +0 -25
  60. package/unit.js +0 -78
  61. package/util.js +0 -153
  62. package/win.js +0 -11
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Alex Ewerlöf
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md CHANGED
@@ -1,20 +1,46 @@
1
1
  # Just JavaScript!
2
2
 
3
+ **Do you know what runs faster than VDOM? No VDOM!**
4
+ **Do you know what's faster than transpilation? No transpilation!**
5
+
3
6
  **JJ** A human readable WYWIWIR (what you write is what is run) DSL for creating and manipulating HTML and CSS for modern browsers.
4
7
 
5
- > Do you know what is faster than VDOM? No VDOM!
8
+ Modern browsers are very powerful out of the box and get you pretty far without having to "compile" (transpile) an interpreted language (`.jsx`, `.vue`, etc.) to an earlier version of it (ES5). This is a proof of concept to show how far we can go without having to compile the code.
9
+
10
+ ## Install
6
11
 
7
- Modern browsers are pretty awesome out of the box and get you pretty far without having to "compile" (transpile) an interpreted language (JavaScript) to an earlier version of it (ES5). This is a proof of concept to show how far we can go without having to compile the code.
12
+ ```bash
13
+ npm i jj
14
+ ```
15
+
16
+ # Usage
17
+
18
+ CDN:
19
+
20
+ ```js
21
+ import { nextAnimationFrame, on } from 'https://unpkg.com/browse/jj/dist/bundle.js'
22
+ ```
23
+
24
+ From NPM:
25
+
26
+ ```js
27
+ import { nextAnimationFrame, on } from 'jj'
28
+ ```
8
29
 
9
30
  ## Design principals
10
31
 
11
- * Modern: take full advantage of ever-green browser features. No support for legacy browsers
12
- * Sugar but not magic: it'll let you write shorter code but it won't do much logic behind the scene
13
- * Excplicit: make the code more readable and easier to follow
14
- * Basic: use plain old javascript objects (POJOs) for describing HTML and CSS
32
+ - Modern: take full advantage of ever-green browser features. No support for legacy browsers
33
+ - Sugar but not magic: it'll let you write shorter code but it won't do much logic behind the scene
34
+ - Excplicit: make the code more readable and easier to follow
35
+ - Basic: use plain old javascript objects (POJOs) for describing HTML and CSS
15
36
 
16
37
  # Install
17
38
 
39
+ One of the main points of using this library is to avoid compiling your code.
40
+ You can directly import it from UNPKG at https://unpkg.com/browse/jj/dist/jj.js
41
+
42
+ But if you prefer to install it via NPM:
43
+
18
44
  ```
19
45
  npm i jj
20
46
  ```
@@ -30,7 +56,10 @@ npm i jj
30
56
  ```
31
57
 
32
58
  ```javascript
59
+ // If you installed via NPM
33
60
  import { ready, html } from '/node_modules/jj/dist/jj.js'
61
+ // Is you want to directly use it via UNPKG
62
+ import { ready, html } from 'https://unpkg.com/browse/jj/dist/jj.js'
34
63
 
35
64
  ready(() => {
36
65
  html.div('Hello world!').appendToBody()
@@ -45,4 +74,4 @@ _Will be written when we reach a stable API._
45
74
 
46
75
  MIT
47
76
 
48
- _Made in Sweden 🇸🇪 by [@alexewerlof](https://mobile.twitter.com/alexewerlof)_
77
+ _Made in Sweden 🇸🇪 by [@alexewerlof](https://mobile.twitter.com/alexewerlof)_
package/lib/WC.d.ts ADDED
@@ -0,0 +1,45 @@
1
+ import { WHE } from './WHE.js';
2
+ export declare function fetchText(url: URL | string, mime?: string): Promise<string>;
3
+ export declare function fetchHtml(url: URL | string): Promise<string>;
4
+ export declare function fetchCss(url: URL | string): Promise<string>;
5
+ export declare function cssToStyle(css: string): Promise<CSSStyleSheet>;
6
+ export declare function fetchStyle(url: URL | string): Promise<CSSStyleSheet>;
7
+ export declare function addLinkPre(href: string, rel: 'prefetch' | 'preload', as?: 'fetch' | 'style' | 'script'): WHE<HTMLElement>;
8
+ export type JJResource<T> = T | Promise<T> | (() => T | Promise<T>);
9
+ export type JJTemplateConfig = JJResource<string>;
10
+ export type JJStylesConfig = JJResource<string | CSSStyleSheet> | JJResource<string | CSSStyleSheet>[];
11
+ export interface JJConfig {
12
+ name: string;
13
+ template?: JJTemplateConfig;
14
+ styles?: JJStylesConfig;
15
+ templateMode?: 'open' | 'closed';
16
+ }
17
+ interface JJProcessedConfig {
18
+ template?: string;
19
+ styles: CSSStyleSheet[];
20
+ }
21
+ /**
22
+ * Parent class for custom components.
23
+ * It adds a few pragmatic functionalities
24
+ * - `setTemplate` sets the template for the custom component body
25
+ * - `addStyle` adds a stylesheet to be used by the shadowRoot
26
+ * - `connectedCallback` assigns the templates to shadowRoot and attaches any styles
27
+ * - `attributeChangedCallback` sets any props that corresponds to attributes defined in `static observedAttributes`
28
+ */
29
+ export declare class WC extends HTMLElement {
30
+ static _jjCache: Promise<JJProcessedConfig> | JJProcessedConfig | undefined;
31
+ static jj: JJConfig;
32
+ static observedAttributes?: string[];
33
+ static register(): Promise<void>;
34
+ connectedCallback(): Promise<void>;
35
+ /**
36
+ * The class that extends this one should define
37
+ * `static observedAttributes[]` containing kebab-based attribute names (all lower case)
38
+ * @param name kebab-case and in lower case exactly as it appears in `observedAttributes`
39
+ * @param oldValue
40
+ * @param newValue
41
+ * @returns true if it tried to set the attribute; otherwise false
42
+ */
43
+ attributeChangedCallback(name: string, oldValue: any, newValue: any): boolean;
44
+ }
45
+ export {};
package/lib/WC.js ADDED
@@ -0,0 +1,118 @@
1
+ import { keb2cam } from './case.js';
2
+ import { WHE } from './WHE.js';
3
+ import { hasProp, isArr, isStr, isObj, isFn, isA, isDef } from 'jty';
4
+ export async function fetchText(url, mime = 'text/*') {
5
+ if (!isStr(mime)) {
6
+ throw new TypeError(`Expected a string mime like 'text/html' or 'text/css'. Got ${mime} (${typeof mime})`);
7
+ }
8
+ const response = await fetch(url, { headers: { Accept: mime } });
9
+ if (!response.ok) {
10
+ throw new Error(`GET ${url} failed: ${response.status} ${response.statusText}`);
11
+ }
12
+ return response.text();
13
+ }
14
+ export async function fetchHtml(url) {
15
+ return await fetchText(url, 'text/html');
16
+ }
17
+ export async function fetchCss(url) {
18
+ return await fetchText(url, 'text/css');
19
+ }
20
+ export async function cssToStyle(css) {
21
+ const sheet = new CSSStyleSheet();
22
+ return await sheet.replace(css);
23
+ }
24
+ export async function fetchStyle(url) {
25
+ return await cssToStyle(await fetchCss(url));
26
+ }
27
+ export function addLinkPre(href, rel, as = 'fetch') {
28
+ const link = WHE.fromTag('link').setAttrs({
29
+ rel,
30
+ href,
31
+ as,
32
+ });
33
+ document.head.append(link.ref);
34
+ return link;
35
+ }
36
+ async function processStyleConfig(style) {
37
+ if (isFn(style)) {
38
+ style = await style();
39
+ }
40
+ style = await style;
41
+ if (isA(style, CSSStyleSheet)) {
42
+ return style;
43
+ }
44
+ if (isStr(style)) {
45
+ return await cssToStyle(style);
46
+ }
47
+ throw new TypeError(`Expected a css string or CSSStyleSheet. Got ${style} (${typeof style})`);
48
+ }
49
+ async function processConfig(templateResource, styleResources) {
50
+ const templatePromise = isFn(templateResource) ? templateResource() : Promise.resolve(templateResource);
51
+ if (!isDef(styleResources)) {
52
+ styleResources = [];
53
+ }
54
+ if (!isArr(styleResources)) {
55
+ styleResources = [styleResources];
56
+ }
57
+ const [template, ...styles] = await Promise.all([templatePromise, ...styleResources.map(processStyleConfig)]);
58
+ return { template, styles };
59
+ }
60
+ /**
61
+ * Parent class for custom components.
62
+ * It adds a few pragmatic functionalities
63
+ * - `setTemplate` sets the template for the custom component body
64
+ * - `addStyle` adds a stylesheet to be used by the shadowRoot
65
+ * - `connectedCallback` assigns the templates to shadowRoot and attaches any styles
66
+ * - `attributeChangedCallback` sets any props that corresponds to attributes defined in `static observedAttributes`
67
+ */
68
+ export class WC extends HTMLElement {
69
+ static async register() {
70
+ if (!isObj(this.jj)) {
71
+ throw new Error(`static jj object is missing from the extending class. Got ${this.jj} (${typeof this.jj})`);
72
+ }
73
+ const { name } = this.jj;
74
+ if (!isStr(name)) {
75
+ throw new TypeError(`Expected a string name. Got ${name} (${typeof name})`);
76
+ }
77
+ if (!customElements.get(name)) {
78
+ customElements.define(name, this);
79
+ await customElements.whenDefined(name);
80
+ }
81
+ }
82
+ async connectedCallback() {
83
+ const classRef = this.constructor;
84
+ const jj = classRef.jj;
85
+ if (!isObj(jj)) {
86
+ throw new TypeError(`static jj object is missing from the extending class. Got ${jj} (${typeof jj})`);
87
+ }
88
+ if (!classRef._jjCache) {
89
+ classRef._jjCache = processConfig(classRef.jj.template, classRef.jj.styles);
90
+ }
91
+ const { template, styles } = await classRef._jjCache;
92
+ const { templateMode } = jj;
93
+ WHE.from(this).setShadow(templateMode, template, ...styles);
94
+ }
95
+ /**
96
+ * The class that extends this one should define
97
+ * `static observedAttributes[]` containing kebab-based attribute names (all lower case)
98
+ * @param name kebab-case and in lower case exactly as it appears in `observedAttributes`
99
+ * @param oldValue
100
+ * @param newValue
101
+ * @returns true if it tried to set the attribute; otherwise false
102
+ */
103
+ attributeChangedCallback(name, oldValue, newValue) {
104
+ // Called when observed attributes change.
105
+ if (oldValue !== newValue) {
106
+ const observedAttributes = this.constructor.observedAttributes;
107
+ if (isArr(observedAttributes) && observedAttributes.includes(name)) {
108
+ const kebabName = keb2cam(name);
109
+ if (hasProp(this, kebabName)) {
110
+ this[kebabName] = newValue;
111
+ return true;
112
+ }
113
+ }
114
+ }
115
+ return false;
116
+ }
117
+ }
118
+ //# sourceMappingURL=WC.js.map
package/lib/WC.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WC.js","sourceRoot":"","sources":["../src/WC.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,KAAK,CAAA;AAEpE,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,GAAiB,EAAE,OAAe,QAAQ;IACtE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;QACf,MAAM,IAAI,SAAS,CAAC,8DAA8D,IAAI,KAAK,OAAO,IAAI,GAAG,CAAC,CAAA;IAC9G,CAAC;IACD,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC,CAAA;IAChE,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,OAAO,GAAG,YAAY,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAA;IACnF,CAAC;IACD,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAA;AAC1B,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,GAAiB;IAC7C,OAAO,MAAM,SAAS,CAAC,GAAG,EAAE,WAAW,CAAC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AC,GAAG,QAAQ,CAAA;oBACxC,OAAO,IAAI,CAAA;gBACf,CAAC;YACL,CAAC;QACL,CAAC;QACD,OAAO,KAAK,CAAA;IAChB,CAAC;CACJ"}
package/lib/WDF.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ import { WN } from './WN.js';
2
+ import { Wrapped } from './WN-mixin.js';
3
+ /**
4
+ * Wraps a DocumentFragment (which is a descendant of Node)
5
+ */
6
+ export declare class WDF<T extends DocumentFragment = DocumentFragment> extends WN<T> {
7
+ static from(ref: DocumentFragment): WDF;
8
+ constructor(ref: T);
9
+ byId(id: string, throwIfNotFound?: boolean): Wrapped | null;
10
+ empty(): this;
11
+ }
package/lib/WDF.js ADDED
@@ -0,0 +1,31 @@
1
+ import { isA } from 'jty';
2
+ import { WN } from './WN.js';
3
+ /**
4
+ * Wraps a DocumentFragment (which is a descendant of Node)
5
+ */
6
+ export class WDF extends WN {
7
+ static from(ref) {
8
+ return new WDF(ref);
9
+ }
10
+ constructor(ref) {
11
+ if (!isA(ref, DocumentFragment)) {
12
+ throw new TypeError(`Expected a DocumentFragment. Got ${ref} (${typeof ref})`);
13
+ }
14
+ super(ref);
15
+ }
16
+ byId(id, throwIfNotFound = true) {
17
+ const el = this.ref.getElementById(id);
18
+ if (el) {
19
+ return WN.wrap(el);
20
+ }
21
+ if (throwIfNotFound) {
22
+ throw new TypeError(`Element with id ${id} not found`);
23
+ }
24
+ return null;
25
+ }
26
+ empty() {
27
+ this.ref.replaceChildren();
28
+ return this;
29
+ }
30
+ }
31
+ //# sourceMappingURL=WDF.js.map
package/lib/WDF.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WDF.js","sourceRoot":"","sources":["../src/WDF.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAA;AACzB,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAG5B;;GAEG;AACH,MAAM,OAAO,GAAmD,SAAQ,EAAK;IACzE,MAAM,CAAC,IAAI,CAAC,GAAqB;QAC7B,OAAO,IAAI,GAAG,CAAC,GAAG,CAAC,CAAA;IACvB,CAAC;IAED,YAAY,GAAM;QACd,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,gBAAgB,CAAC,EAAE,CAAC;YAC9B,MAAM,IAAI,SAAS,CAAC,oCAAoC,GAAG,KAAK,OAAO,GAAG,GAAG,CAAC,CAAA;QAClF,CAAC;QACD,KAAK,CAAC,GAAG,CAAC,CAAA;IACd,CAAC;IAED,IAAI,CAAC,EAAU,EAAE,eAAe,GAAG,IAAI;QACnC,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE,CAAC,CAAA;QACtC,IAAI,EAAE,EAAE,CAAC;YACL,OAAO,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;QACtB,CAAC;QACD,IAAI,eAAe,EAAE,CAAC;YAClB,MAAM,IAAI,SAAS,CAAC,mBAAmB,EAAE,YAAY,CAAC,CAAA;QAC1D,CAAC;QACD,OAAO,IAAI,CAAA;IACf,CAAC;IAED,KAAK;QACD,IAAI,CAAC,GAAG,CAAC,eAAe,EAAE,CAAA;QAC1B,OAAO,IAAI,CAAA;IACf,CAAC;CACJ"}
package/lib/WE.d.ts ADDED
@@ -0,0 +1,43 @@
1
+ import { WN } from './WN.js';
2
+ import { WSH } from './WSH.js';
3
+ /**
4
+ * Wraps a DOM Element (which is a descendant of Node)
5
+ */
6
+ export declare class WE<T extends Element = Element> extends WN<T> {
7
+ static from(ref: Element): WE;
8
+ constructor(ref: T);
9
+ getAttr(name: string): string | null;
10
+ hasAttr(name: string): boolean;
11
+ setAttr(name: string, value: string): this;
12
+ setAttrs(obj: Record<string, string>): this;
13
+ rmAttr(name: string): this;
14
+ rmAttrs(...names: string[]): this;
15
+ getAria(name: string): string | null;
16
+ hasAria(name: string): boolean;
17
+ setAria(name: string, value: string): this;
18
+ rmAria(name: string): this;
19
+ addClass(...classNames: string[]): this;
20
+ rmClasses(...classNames: string[]): this;
21
+ rmClass(className: string): this;
22
+ hasClass(className: string): boolean;
23
+ toggleClass(className: string): this;
24
+ onClick(handler: EventListenerOrEventListenerObject): this;
25
+ hide(): this;
26
+ show(): this;
27
+ disable(): this;
28
+ enable(): this;
29
+ getTitle(): string | null;
30
+ setTitle(title: string): this;
31
+ setId(id: string): this;
32
+ getId(): string | null;
33
+ getHtml(): string;
34
+ setHtml(html: string): this;
35
+ /**
36
+ * We prevent FOUC by assigning the template and CSS in one go
37
+ * @remarks
38
+ * **Note:** You can't attach a shadow root to every type of element. There are some that can't have a
39
+ * shadow DOM for security reasons (for example `<a>`).
40
+ */
41
+ setShadow(mode?: ShadowRootMode, html?: string, ...styleSheets: CSSStyleSheet[]): this;
42
+ getShadow(): WSH;
43
+ }
package/lib/WE.js ADDED
@@ -0,0 +1,133 @@
1
+ import { isA, isObj } from 'jty';
2
+ import { WN } from './WN.js';
3
+ import { WSH } from './WSH.js';
4
+ /**
5
+ * Wraps a DOM Element (which is a descendant of Node)
6
+ */
7
+ export class WE extends WN {
8
+ static from(ref) {
9
+ return new WE(ref);
10
+ }
11
+ constructor(ref) {
12
+ if (!isA(ref, Element)) {
13
+ throw new TypeError(`Expected a Element. Got: ${ref} (${typeof ref})`);
14
+ }
15
+ super(ref);
16
+ }
17
+ getAttr(name) {
18
+ return this.ref.getAttribute(name);
19
+ }
20
+ hasAttr(name) {
21
+ return this.ref.hasAttribute(name);
22
+ }
23
+ setAttr(name, value) {
24
+ this.ref.setAttribute(name, value);
25
+ return this;
26
+ }
27
+ setAttrs(obj) {
28
+ if (!isObj(obj)) {
29
+ throw new TypeError(`Expected an object. Got: ${obj} (${typeof obj})`);
30
+ }
31
+ for (const [name, value] of Object.entries(obj)) {
32
+ this.setAttr(name, value);
33
+ }
34
+ return this;
35
+ }
36
+ rmAttr(name) {
37
+ return this.rmAttrs(name);
38
+ }
39
+ rmAttrs(...names) {
40
+ for (const name of names) {
41
+ this.ref.removeAttribute(name);
42
+ }
43
+ return this;
44
+ }
45
+ getAria(name) {
46
+ return this.ref.getAttribute(`aria-${name}`);
47
+ }
48
+ hasAria(name) {
49
+ return this.ref.hasAttribute(`aria-${name}`);
50
+ }
51
+ setAria(name, value) {
52
+ this.ref.setAttribute(`aria-${name}`, value);
53
+ return this;
54
+ }
55
+ rmAria(name) {
56
+ this.ref.removeAttribute(`aria-${name}`);
57
+ return this;
58
+ }
59
+ addClass(...classNames) {
60
+ this.ref.classList.add(...classNames);
61
+ return this;
62
+ }
63
+ rmClasses(...classNames) {
64
+ this.ref.classList.remove(...classNames);
65
+ return this;
66
+ }
67
+ rmClass(className) {
68
+ return this.rmClasses(className);
69
+ }
70
+ hasClass(className) {
71
+ return this.ref.classList.contains(className);
72
+ }
73
+ toggleClass(className) {
74
+ this.ref.classList.toggle(className);
75
+ return this;
76
+ }
77
+ onClick(handler) {
78
+ return this.on('click', handler);
79
+ }
80
+ hide() {
81
+ return this.setAttr('hidden', '').setAttr('aria-hidden', 'true');
82
+ }
83
+ show() {
84
+ return this.rmAttrs('hidden', 'aria-hidden');
85
+ }
86
+ disable() {
87
+ return this.setAttr('disabled', '').setAttr('aria-disabled', 'true');
88
+ }
89
+ enable() {
90
+ return this.rmAttrs('disabled', 'aria-disabled');
91
+ }
92
+ getTitle() {
93
+ return this.getAttr('title');
94
+ }
95
+ setTitle(title) {
96
+ return this.setAttr('title', title);
97
+ }
98
+ setId(id) {
99
+ return this.setAttr('id', id);
100
+ }
101
+ getId() {
102
+ return this.getAttr('id');
103
+ }
104
+ getHtml() {
105
+ return this.ref.innerHTML;
106
+ }
107
+ setHtml(html) {
108
+ this.ref.innerHTML = html;
109
+ return this;
110
+ }
111
+ /**
112
+ * We prevent FOUC by assigning the template and CSS in one go
113
+ * @remarks
114
+ * **Note:** You can't attach a shadow root to every type of element. There are some that can't have a
115
+ * shadow DOM for security reasons (for example `<a>`).
116
+ */
117
+ setShadow(mode = 'open', html, ...styleSheets) {
118
+ const shadowRoot = this.ref.shadowRoot ?? this.ref.attachShadow({ mode });
119
+ if (html) {
120
+ shadowRoot.innerHTML = html;
121
+ }
122
+ if (styleSheets.length) {
123
+ shadowRoot.adoptedStyleSheets.push(...styleSheets);
124
+ }
125
+ return this;
126
+ }
127
+ getShadow() {
128
+ if (!this.ref.shadowRoot)
129
+ throw new Error('No shadow root');
130
+ return new WSH(this.ref.shadowRoot);
131
+ }
132
+ }
133
+ //# sourceMappingURL=WE.js.map
package/lib/WE.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WE.js","sourceRoot":"","sources":["../src/WE.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,KAAK,CAAA;AAChC,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAC5B,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAE9B;;GAEG;AACH,MAAM,OAAO,EAAgC,SAAQ,EAAK;IACtD,MAAM,CAAC,IAAI,CAAC,GAAY;QACpB,OAAO,IAAI,EAAE,CAAC,GAAG,CAAC,CAAA;IACtB,CAAC;IAED,YAAY,GAAM;QACd,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,EAAE,CAAC;YACrB,MAAM,IAAI,SAAS,CAAC,4BAA4B,GAAG,KAAK,OAAO,GAAG,GAAG,CAAC,CAAA;QAC1E,CAAC;QACD,KAAK,CAAC,GAAG,CAAC,CAAA;IACd,CAAC;IAED,OAAO,CAAC,IAAY;QAChB,OAAO,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,CAAC,CAAA;IACtC,CAAC;IAED,OAAO,CAAC,IAAY;QAChB,OAAO,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,CAAC,CAAA;IACtC,CAAC;IAED,OAAO,CAAC,IAAY,EAAE,KAAa;QAC/B,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;QAClC,OAA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a;QAClB,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;IACvC,CAAC;IAED,KAAK,CAAC,EAAU;QACZ,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAA;IACjC,CAAC;IAED,KAAK;QACD,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;IAC7B,CAAC;IAED,OAAO;QACH,OAAO,IAAI,CAAC,GAAG,CAAC,SAAS,CAAA;IAC7B,CAAC;IAED,OAAO,CAAC,IAAY;QAChB,IAAI,CAAC,GAAG,CAAC,SAAS,GAAG,IAAI,CAAA;QACzB,OAAO,IAAI,CAAA;IACf,CAAC;IAED;;;;;OAKG;IACH,SAAS,CAAC,OAAuB,MAAM,EAAE,IAAa,EAAE,GAAG,WAA4B;QACnF,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,UAAU,IAAI,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,CAAC,CAAA;QACzE,IAAI,IAAI,EAAE,CAAC;YACP,UAAU,CAAC,SAAS,GAAG,IAAI,CAAA;QAC/B,CAAC;QACD,IAAI,WAAW,CAAC,MAAM,EAAE,CAAC;YACrB,UAAU,CAAC,kBAAkB,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC,CAAA;QACtD,CAAC;QACD,OAAO,IAAI,CAAA;IACf,CAAC;IAED,SAAS;QACL,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,UAAU;YAAE,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAA;QAC3D,OAAO,IAAI,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;IACvC,CAAC;CACJ"}
package/lib/WHE.d.ts ADDED
@@ -0,0 +1,21 @@
1
+ import { WE } from './WE.js';
2
+ /**
3
+ * Wraps a DOM HTMLElement (which is a descendant of Element)
4
+ */
5
+ export declare class WHE<T extends HTMLElement = HTMLElement> extends WE<T> {
6
+ static from(ref: HTMLElement): WHE;
7
+ static fromTag(tagName: string, options?: ElementCreationOptions): WHE;
8
+ constructor(ref: T);
9
+ getValue(): unknown;
10
+ setValue(value: string): this;
11
+ getData(name: string): string | undefined;
12
+ hasData(name: string): boolean;
13
+ setData(name: string, value: string): this;
14
+ setDataObj(obj: Record<string, string>): this;
15
+ rmData(name: string): this;
16
+ focus(): this;
17
+ click(): this;
18
+ empty(): this;
19
+ getText(): string;
20
+ setText(text: string): this;
21
+ }
package/lib/WHE.js ADDED
@@ -0,0 +1,75 @@
1
+ import { hasProp, isA, isStr } from 'jty';
2
+ import { WE } from './WE.js';
3
+ /**
4
+ * Wraps a DOM HTMLElement (which is a descendant of Element)
5
+ */
6
+ export class WHE extends WE {
7
+ static from(ref) {
8
+ return new WHE(ref);
9
+ }
10
+ static fromTag(tagName, options) {
11
+ if (!isStr(tagName)) {
12
+ throw new TypeError(`Expected a string for tagName. Got: ${tagName} (${typeof tagName})`);
13
+ }
14
+ return new WHE(document.createElement(tagName, options));
15
+ }
16
+ constructor(ref) {
17
+ if (!isA(ref, HTMLElement)) {
18
+ throw new TypeError(`Expected a HTMLElement. Got ${ref} (${typeof ref})`);
19
+ }
20
+ super(ref);
21
+ }
22
+ getValue() {
23
+ if (!hasProp(this.ref, 'value')) {
24
+ throw new Error('Element does not have a value property');
25
+ }
26
+ return this.ref.value;
27
+ }
28
+ setValue(value) {
29
+ if (!hasProp(this.ref, 'value')) {
30
+ throw new Error('Element does not have a value property');
31
+ }
32
+ this.ref.value = value;
33
+ return this;
34
+ }
35
+ getData(name) {
36
+ return this.ref.dataset[name];
37
+ }
38
+ hasData(name) {
39
+ return hasProp(this.ref.dataset, name);
40
+ }
41
+ setData(name, value) {
42
+ this.ref.dataset[name] = value;
43
+ return this;
44
+ }
45
+ setDataObj(obj) {
46
+ for (const [name, value] of Object.entries(obj)) {
47
+ this.setData(name, value);
48
+ }
49
+ return this;
50
+ }
51
+ rmData(name) {
52
+ delete this.ref.dataset[name];
53
+ return this;
54
+ }
55
+ focus() {
56
+ this.ref.focus();
57
+ return this;
58
+ }
59
+ click() {
60
+ this.ref.click();
61
+ return this;
62
+ }
63
+ empty() {
64
+ this.ref.innerText = '';
65
+ return this;
66
+ }
67
+ getText() {
68
+ return this.ref.innerText;
69
+ }
70
+ setText(text) {
71
+ this.ref.innerText = text;
72
+ return this;
73
+ }
74
+ }
75
+ //# sourceMappingURL=WHE.js.map
package/lib/WHE.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WHE.js","sourceRoot":"","sources":["../src/WHE.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,KAAK,CAAA;AACzC,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAE5B;;GAEG;AACH,MAAM,OAAO,GAAyC,SAAQ,EAAK;IAC/D,MAAM,CAAC,IAAI,CAAC,GAAgB;QACxB,OAAO,IAAI,GAAG,CAAC,GAAG,CAAC,CAAA;IACvB,CAAC;IAED,MAAM,CAAC,OAAO,CAAC,OAAe,EAAE,OAAgC;QAC5D,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;YAClB,MAAM,IAAI,SAAS,CAAC,uCAAuC,OAAO,KAAK,OAAO,OAAO,GAAG,CAAC,CAAA;QAC7F,CAAC;QACD,OAAO,IAAI,GAAG,CAAC,QAAQ,CAAC,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAA;IAC5D,CAAC;IAED,YAAY,GAAM;QACd,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,WAAW,CAAC,EAAE,CAAC;YACzB,MAAM,IAAI,SAAS,CAAC,+BAA+B,GAAG,KAAK,OAAO,GAAG,GAAG,CAAC,CAAA;QAC7E,CAAC;QACD,KAAK,CAAC,GAAG,CAAC,CAAA;IACd,CAAC;IAED,QAAQ;QACJ,IAAI,CAAC,OAAO,CAAC,IAAI,CA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ED,KAAK;QACD,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAA;QAChB,OAAO,IAAI,CAAA;IACf,CAAC;IAED,KAAK;QACD,IAAI,CAAC,GAAG,CAAC,SAAS,GAAG,EAAE,CAAA;QACvB,OAAO,IAAI,CAAA;IACf,CAAC;IAED,OAAO;QACH,OAAO,IAAI,CAAC,GAAG,CAAC,SAAS,CAAA;IAC7B,CAAC;IAED,OAAO,CAAC,IAAY;QAChB,IAAI,CAAC,GAAG,CAAC,SAAS,GAAG,IAAI,CAAA;QACzB,OAAO,IAAI,CAAA;IACf,CAAC;CACJ"}
@@ -0,0 +1,9 @@
1
+ import { WHE } from './WHE.js';
2
+ import { WE } from './WE.js';
3
+ import { WDF } from './WDF.js';
4
+ import { WSH } from './WSH.js';
5
+ import { WT } from './WT.js';
6
+ import { WN } from './WN.js';
7
+ export type Wrappable = WN | Node | string;
8
+ export type Wrapped = WHE | WE | WDF | WSH | WDF | WT | WN;
9
+ export type Unwrapped = HTMLElement | Element | ShadowRoot | DocumentFragment | Text | Node;
@@ -0,0 +1,59 @@
1
+ import { isA, isObj, isStr } from 'jty';
2
+ import { WHE } from './WHE.js';
3
+ import { WE } from './WE.js';
4
+ import { WDF } from './WDF.js';
5
+ import { WSH } from './WSH.js';
6
+ import { WT } from './WT.js';
7
+ import { WN } from './WN.js';
8
+ /**
9
+ * @returns the most granual Wrapped subclass.
10
+ */
11
+ WN.wrap = (raw) => {
12
+ if (isStr(raw)) {
13
+ return WT.from(document.createTextNode(raw));
14
+ }
15
+ if (!isObj(raw)) {
16
+ throw new TypeError(`Expected an object to wrap. Got ${raw} (${typeof raw})`);
17
+ }
18
+ if (isA(raw, WN)) {
19
+ return raw;
20
+ }
21
+ if (isA(raw, HTMLElement)) {
22
+ return WHE.from(raw);
23
+ }
24
+ if (isA(raw, Element)) {
25
+ return WE.from(raw);
26
+ }
27
+ if (isA(raw, ShadowRoot)) {
28
+ return WSH.from(raw);
29
+ }
30
+ if (isA(raw, DocumentFragment)) {
31
+ return WDF.from(raw);
32
+ }
33
+ if (isA(raw, Text)) {
34
+ return WT.from(raw);
35
+ }
36
+ if (isA(raw, Node)) {
37
+ return WN.from(raw);
38
+ }
39
+ throw new TypeError(`Only Frag or DocumentFragment can be wrapped. Got ${raw} (${typeof raw})`);
40
+ };
41
+ /**
42
+ * @returns the original DOM node wrapped in the appropriate class
43
+ */
44
+ WN.unwrap = (obj) => {
45
+ if (isStr(obj)) {
46
+ return document.createTextNode(obj);
47
+ }
48
+ if (!isObj(obj)) {
49
+ throw new TypeError(`Expected an object. Got ${obj} (${typeof obj})`);
50
+ }
51
+ if (isA(obj, Node)) {
52
+ return obj;
53
+ }
54
+ if (isA(obj, WN)) {
55
+ return obj.ref;
56
+ }
57
+ throw new TypeError(`Could not unwrap ${obj} (${typeof obj})`);
58
+ };
59
+ //# sourceMappingURL=WN-mixin.js.map