jj 2.4.0 → 2.6.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.
- package/README.md +37 -48
- package/SKILL.md +671 -0
- package/lib/bundle.cjs +2031 -0
- package/lib/bundle.cjs.map +1 -0
- package/lib/bundle.d.cts +1782 -0
- package/lib/bundle.d.ts +1782 -1
- package/lib/bundle.global.js +1953 -0
- package/lib/bundle.global.js.map +1 -0
- package/lib/bundle.js +864 -848
- package/lib/bundle.js.map +1 -7
- package/lib/bundle.min.cjs +2 -0
- package/lib/bundle.min.cjs.map +1 -0
- package/lib/bundle.min.d.cts +1782 -0
- package/lib/bundle.min.d.ts +1782 -1
- package/lib/bundle.min.global.js +2 -0
- package/lib/bundle.min.global.js.map +1 -0
- package/lib/bundle.min.js +2 -2
- package/lib/bundle.min.js.map +1 -0
- package/package.json +14 -6
- package/lib/JJD.d.ts +0 -76
- package/lib/JJD.js +0 -91
- package/lib/JJD.js.map +0 -1
- package/lib/JJDF.d.ts +0 -60
- package/lib/JJDF.js +0 -68
- package/lib/JJDF.js.map +0 -1
- package/lib/JJE.d.ts +0 -313
- package/lib/JJE.js +0 -412
- package/lib/JJE.js.map +0 -1
- package/lib/JJHE.d.ts +0 -120
- package/lib/JJHE.js +0 -164
- package/lib/JJHE.js.map +0 -1
- package/lib/JJN.d.ts +0 -234
- package/lib/JJN.js +0 -323
- package/lib/JJN.js.map +0 -1
- package/lib/JJSE.d.ts +0 -148
- package/lib/JJSE.js +0 -190
- package/lib/JJSE.js.map +0 -1
- package/lib/JJSR.d.ts +0 -67
- package/lib/JJSR.js +0 -85
- package/lib/JJSR.js.map +0 -1
- package/lib/JJT.d.ts +0 -79
- package/lib/JJT.js +0 -108
- package/lib/JJT.js.map +0 -1
- package/lib/case.d.ts +0 -60
- package/lib/case.js +0 -92
- package/lib/case.js.map +0 -1
- package/lib/case.test.d.ts +0 -1
- package/lib/case.test.js +0 -79
- package/lib/case.test.js.map +0 -1
- package/lib/components.d.ts +0 -147
- package/lib/components.js +0 -286
- package/lib/components.js.map +0 -1
- package/lib/helpers.d.ts +0 -158
- package/lib/helpers.js +0 -231
- package/lib/helpers.js.map +0 -1
- package/lib/index.d.ts +0 -15
- package/lib/index.js +0 -16
- package/lib/index.js.map +0 -1
- package/lib/mixin-types.d.ts +0 -143
- package/lib/mixin-types.js +0 -2
- package/lib/mixin-types.js.map +0 -1
- package/lib/mixins.d.ts +0 -77
- package/lib/mixins.js +0 -336
- package/lib/mixins.js.map +0 -1
- package/lib/types.d.ts +0 -77
- package/lib/types.js +0 -2
- package/lib/types.js.map +0 -1
- package/lib/util.d.ts +0 -96
- package/lib/util.js +0 -122
- package/lib/util.js.map +0 -1
- package/lib/util.test.d.ts +0 -1
- package/lib/util.test.js +0 -46
- package/lib/util.test.js.map +0 -1
package/lib/components.d.ts
DELETED
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import { JJStyleConfig, JJTemplateConfig, ShadowConfig } from './types.js';
|
|
2
|
-
/**
|
|
3
|
-
* Manages the resolution of Shadow DOM configuration (template and styles).
|
|
4
|
-
*
|
|
5
|
-
* Allows building up the configuration and resolving it lazily.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```ts
|
|
9
|
-
* const sm = ShadowMaster.create()
|
|
10
|
-
* .setTemplate('<div>Hello World</div>')
|
|
11
|
-
* .addStyles('div { color: red; }')
|
|
12
|
-
*
|
|
13
|
-
* class MyComponent extends HTMLElement {
|
|
14
|
-
* async connectedCallback() {
|
|
15
|
-
* // Resolves the config once and caches it
|
|
16
|
-
* const shadowConfig = await sm.getResolved()
|
|
17
|
-
* // ... init shadow root with shadowConfig
|
|
18
|
-
* }
|
|
19
|
-
* }
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
export declare class ShadowMaster {
|
|
23
|
-
#private;
|
|
24
|
-
/**
|
|
25
|
-
* Creates a new instance of ShadowMaster.
|
|
26
|
-
*
|
|
27
|
-
* @returns A new ShadowMaster instance.
|
|
28
|
-
*/
|
|
29
|
-
static create(): ShadowMaster;
|
|
30
|
-
constructor();
|
|
31
|
-
/**
|
|
32
|
-
* Sets the template configuration.
|
|
33
|
-
*
|
|
34
|
-
* @param templateConfig - The template configuration.
|
|
35
|
-
* @returns The instance for chaining.
|
|
36
|
-
*
|
|
37
|
-
* @example
|
|
38
|
-
* ```ts
|
|
39
|
-
* // Accepts string, promise, or fetchHtml result
|
|
40
|
-
* sm.setTemplate(fetchHtml('./template.html'))
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
|
-
setTemplate(templateConfig?: JJTemplateConfig): this;
|
|
44
|
-
/**
|
|
45
|
-
* Adds one or more style configurations.
|
|
46
|
-
*
|
|
47
|
-
* @param stylesConfig - Variable number of style configurations.
|
|
48
|
-
* @returns The instance for chaining.
|
|
49
|
-
*
|
|
50
|
-
* @example
|
|
51
|
-
* ```ts
|
|
52
|
-
* sm.addStyles(
|
|
53
|
-
* 'p { color: red; }',
|
|
54
|
-
* fetchCss('./styles.css'),
|
|
55
|
-
* () => fetchCss('../lazy-loaded-styles.css'),
|
|
56
|
-
* )
|
|
57
|
-
* ```
|
|
58
|
-
*/
|
|
59
|
-
addStyles(...stylesConfig: JJStyleConfig[]): this;
|
|
60
|
-
/**
|
|
61
|
-
* Resolves the configuration to something that can be fed to `JJHE.initShadow()` function
|
|
62
|
-
*
|
|
63
|
-
* The result is cached, so subsequent calls return the same promise.
|
|
64
|
-
* Note: Any changes made to the ShadowMaster instance (via setTemplate/addStyles)
|
|
65
|
-
* after the first call to getResolved() will be ignored.
|
|
66
|
-
*
|
|
67
|
-
* @returns A promise resolving to the ShadowConfig.
|
|
68
|
-
*/
|
|
69
|
-
getResolved(): Promise<ShadowConfig>;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* A helper to bridge the attribute world (kebab-case) to the property world (camelCase).
|
|
73
|
-
* It works in tandem with browser's `observedAttributes` feature which triggers
|
|
74
|
-
* `attributeChangedCallback`.
|
|
75
|
-
*
|
|
76
|
-
* @remarks
|
|
77
|
-
* Your custom component class MUST define `static observedAttributes[]` otherwise `attributeChangedCallback` won't trigger.
|
|
78
|
-
* `observedAttributes` should contain kebab-based attribute names.
|
|
79
|
-
*
|
|
80
|
-
* @example
|
|
81
|
-
* ```ts
|
|
82
|
-
* class MyComponent extends HTMLElement {
|
|
83
|
-
* static observedAttributes = ['user-name', 'counter']
|
|
84
|
-
* userName = '' // Property MUST exist on the instance (or prototype setter)
|
|
85
|
-
* #counter = 0 // You can also use private properties together with getter/setters
|
|
86
|
-
*
|
|
87
|
-
* attributeChangedCallback(name, oldValue, newValue) {
|
|
88
|
-
* attr2prop(this, name, oldValue, newValue)
|
|
89
|
-
* }
|
|
90
|
-
|
|
91
|
-
* get counter() {
|
|
92
|
-
* return this.#counter
|
|
93
|
-
* }
|
|
94
|
-
*
|
|
95
|
-
* set counter(value) {
|
|
96
|
-
* this.#counter = value
|
|
97
|
-
* this.#render() // You can call your render function to update the DOM
|
|
98
|
-
* }
|
|
99
|
-
*
|
|
100
|
-
* #render() {
|
|
101
|
-
* const shadow = JJHE.from(this).shadow
|
|
102
|
-
* if (shadow) {
|
|
103
|
-
* shadow.byId('user').setText(this.userName)
|
|
104
|
-
* shadow.byId('counter').setText(this.counter)
|
|
105
|
-
* }
|
|
106
|
-
* }
|
|
107
|
-
* }
|
|
108
|
-
* ```
|
|
109
|
-
*
|
|
110
|
-
* @param instance - A reference to the common component instance
|
|
111
|
-
* @param name - kebab-case and in lower case exactly as it appears in `observedAttributes`.
|
|
112
|
-
* @param oldValue - The previous value of the attribute.
|
|
113
|
-
* @param newValue - The new value of the attribute.
|
|
114
|
-
* @returns `true` if it tried to set the attribute; otherwise `false`.
|
|
115
|
-
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_custom_elements#responding_to_attribute_changes | Responding to attribute changes}
|
|
116
|
-
*/
|
|
117
|
-
export declare function attr2prop(instance: HTMLElement, name: string, oldValue: any, newValue: any): boolean;
|
|
118
|
-
/**
|
|
119
|
-
* Registers the custom element with the browser and waits till it is defined.
|
|
120
|
-
*
|
|
121
|
-
* @example
|
|
122
|
-
* ```ts
|
|
123
|
-
* class MyComponent extends HTMLElement {}
|
|
124
|
-
* await registerComponent('my-component', MyComponent)
|
|
125
|
-
* ```
|
|
126
|
-
* Another convention is to have a `static async register()` function in the Custom Component.
|
|
127
|
-
* ```ts
|
|
128
|
-
* export class MyComponent extends HTMLElement {
|
|
129
|
-
* static async register() {
|
|
130
|
-
* return registerComponent('my-component', MyComponent)
|
|
131
|
-
* }
|
|
132
|
-
* }
|
|
133
|
-
* ```
|
|
134
|
-
* That way, you can import multiple components and do a `Promise.all()` on all their `.register()`s.
|
|
135
|
-
* ```ts
|
|
136
|
-
* import { MyComponent, YourComponent, TheirComponent } ...
|
|
137
|
-
* await Promise.all([
|
|
138
|
-
* MyComponent.register(),
|
|
139
|
-
* YourComponent.register(),
|
|
140
|
-
* TheirComponent.register(),
|
|
141
|
-
* ])
|
|
142
|
-
*
|
|
143
|
-
* @throws {TypeError} If name is not a string or constructor is not a function
|
|
144
|
-
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry/define | customElements.define}
|
|
145
|
-
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry/whenDefined | customElements.whenDefined}
|
|
146
|
-
*/
|
|
147
|
-
export declare function registerComponent(name: string, constructor: CustomElementConstructor, options?: ElementDefinitionOptions): Promise<void>;
|
package/lib/components.js
DELETED
|
@@ -1,286 +0,0 @@
|
|
|
1
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
-
};
|
|
7
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
-
};
|
|
12
|
-
var _ShadowMaster_templateConfig, _ShadowMaster_stylesConfig, _ShadowMaster_normalizedConfig;
|
|
13
|
-
import { hasProp, isA, isArr, isDef, isFn, isStr } from 'jty';
|
|
14
|
-
import { JJHE } from './JJHE.js';
|
|
15
|
-
import { cssToStyle } from './util.js';
|
|
16
|
-
import { keb2cam } from './case.js';
|
|
17
|
-
/**
|
|
18
|
-
* Resolves a template configuration into a string suitable for Shadow DOM.
|
|
19
|
-
*
|
|
20
|
-
* Handles functions (sync/async), promises, strings, JJHE instances, and HTMLElements.
|
|
21
|
-
*
|
|
22
|
-
* @param templateConfig - The configuration to resolve.
|
|
23
|
-
* @returns A promise resolving to the HTML string or undefined.
|
|
24
|
-
* @throws {TypeError} If the resolved value is not a string, JJHE, or HTMLElement.
|
|
25
|
-
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/outerHTML | Element.outerHTML}
|
|
26
|
-
*/
|
|
27
|
-
async function templatePromise(templateConfig) {
|
|
28
|
-
if (!isDef(templateConfig)) {
|
|
29
|
-
return undefined;
|
|
30
|
-
}
|
|
31
|
-
if (isFn(templateConfig)) {
|
|
32
|
-
templateConfig = await templateConfig();
|
|
33
|
-
}
|
|
34
|
-
templateConfig = await templateConfig;
|
|
35
|
-
if (isStr(templateConfig)) {
|
|
36
|
-
return templateConfig;
|
|
37
|
-
}
|
|
38
|
-
if (isA(templateConfig, JJHE)) {
|
|
39
|
-
return templateConfig.getHTML();
|
|
40
|
-
}
|
|
41
|
-
if (isA(templateConfig, HTMLElement)) {
|
|
42
|
-
return templateConfig.outerHTML;
|
|
43
|
-
}
|
|
44
|
-
throw new TypeError(`Expected a string, JJHE or HTMLElement. Got ${templateConfig} (${typeof templateConfig})`);
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Resolves a style configuration into a CSSStyleSheet.
|
|
48
|
-
*
|
|
49
|
-
* Handles functions (sync/async), promises, CSSStyleSheet instances, and strings.
|
|
50
|
-
* Strings are converted to CSSStyleSheet using `cssToStyle`.
|
|
51
|
-
*
|
|
52
|
-
* @param styleConfig - The configuration to resolve.
|
|
53
|
-
* @returns A promise resolving to a CSSStyleSheet.
|
|
54
|
-
* @throws {TypeError} If the resolved value is not a string or CSSStyleSheet.
|
|
55
|
-
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet | CSSStyleSheet}
|
|
56
|
-
*/
|
|
57
|
-
async function stylePromise(styleConfig) {
|
|
58
|
-
if (isFn(styleConfig)) {
|
|
59
|
-
styleConfig = await styleConfig();
|
|
60
|
-
}
|
|
61
|
-
styleConfig = await styleConfig;
|
|
62
|
-
if (isA(styleConfig, CSSStyleSheet)) {
|
|
63
|
-
return styleConfig;
|
|
64
|
-
}
|
|
65
|
-
if (isStr(styleConfig)) {
|
|
66
|
-
return await cssToStyle(styleConfig);
|
|
67
|
-
}
|
|
68
|
-
throw new TypeError(`Expected a css string or CSSStyleSheet. Got ${styleConfig} (${typeof styleConfig})`);
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Maps an array of style configurations to an array of promises resolving to CSSStyleSheets.
|
|
72
|
-
*
|
|
73
|
-
* @param styleConfigs - Array of style configurations.
|
|
74
|
-
* @returns Array of promises.
|
|
75
|
-
*/
|
|
76
|
-
function stylePromises(styleConfigs) {
|
|
77
|
-
if (!isArr(styleConfigs)) {
|
|
78
|
-
return [];
|
|
79
|
-
}
|
|
80
|
-
return styleConfigs.map(stylePromise);
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Resolves both template and style configurations.
|
|
84
|
-
*
|
|
85
|
-
* @param templateConfig - The template configuration.
|
|
86
|
-
* @param styleConfigs - The style configurations.
|
|
87
|
-
* @returns A promise resolving to the final ShadowConfig.
|
|
88
|
-
*/
|
|
89
|
-
async function resolveConfig(templateConfig, styleConfigs) {
|
|
90
|
-
const [template, ...styles] = await Promise.all([templatePromise(templateConfig), ...stylePromises(styleConfigs)]);
|
|
91
|
-
return { template, styles };
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Manages the resolution of Shadow DOM configuration (template and styles).
|
|
95
|
-
*
|
|
96
|
-
* Allows building up the configuration and resolving it lazily.
|
|
97
|
-
*
|
|
98
|
-
* @example
|
|
99
|
-
* ```ts
|
|
100
|
-
* const sm = ShadowMaster.create()
|
|
101
|
-
* .setTemplate('<div>Hello World</div>')
|
|
102
|
-
* .addStyles('div { color: red; }')
|
|
103
|
-
*
|
|
104
|
-
* class MyComponent extends HTMLElement {
|
|
105
|
-
* async connectedCallback() {
|
|
106
|
-
* // Resolves the config once and caches it
|
|
107
|
-
* const shadowConfig = await sm.getResolved()
|
|
108
|
-
* // ... init shadow root with shadowConfig
|
|
109
|
-
* }
|
|
110
|
-
* }
|
|
111
|
-
* ```
|
|
112
|
-
*/
|
|
113
|
-
export class ShadowMaster {
|
|
114
|
-
/**
|
|
115
|
-
* Creates a new instance of ShadowMaster.
|
|
116
|
-
*
|
|
117
|
-
* @returns A new ShadowMaster instance.
|
|
118
|
-
*/
|
|
119
|
-
static create() {
|
|
120
|
-
return new ShadowMaster();
|
|
121
|
-
}
|
|
122
|
-
constructor() {
|
|
123
|
-
_ShadowMaster_templateConfig.set(this, undefined);
|
|
124
|
-
_ShadowMaster_stylesConfig.set(this, []);
|
|
125
|
-
_ShadowMaster_normalizedConfig.set(this, undefined
|
|
126
|
-
/**
|
|
127
|
-
* Creates a new instance of ShadowMaster.
|
|
128
|
-
*
|
|
129
|
-
* @returns A new ShadowMaster instance.
|
|
130
|
-
*/
|
|
131
|
-
);
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Sets the template configuration.
|
|
135
|
-
*
|
|
136
|
-
* @param templateConfig - The template configuration.
|
|
137
|
-
* @returns The instance for chaining.
|
|
138
|
-
*
|
|
139
|
-
* @example
|
|
140
|
-
* ```ts
|
|
141
|
-
* // Accepts string, promise, or fetchHtml result
|
|
142
|
-
* sm.setTemplate(fetchHtml('./template.html'))
|
|
143
|
-
* ```
|
|
144
|
-
*/
|
|
145
|
-
setTemplate(templateConfig) {
|
|
146
|
-
__classPrivateFieldSet(this, _ShadowMaster_templateConfig, templateConfig, "f");
|
|
147
|
-
return this;
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* Adds one or more style configurations.
|
|
151
|
-
*
|
|
152
|
-
* @param stylesConfig - Variable number of style configurations.
|
|
153
|
-
* @returns The instance for chaining.
|
|
154
|
-
*
|
|
155
|
-
* @example
|
|
156
|
-
* ```ts
|
|
157
|
-
* sm.addStyles(
|
|
158
|
-
* 'p { color: red; }',
|
|
159
|
-
* fetchCss('./styles.css'),
|
|
160
|
-
* () => fetchCss('../lazy-loaded-styles.css'),
|
|
161
|
-
* )
|
|
162
|
-
* ```
|
|
163
|
-
*/
|
|
164
|
-
addStyles(...stylesConfig) {
|
|
165
|
-
__classPrivateFieldGet(this, _ShadowMaster_stylesConfig, "f").push(...stylesConfig);
|
|
166
|
-
return this;
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Resolves the configuration to something that can be fed to `JJHE.initShadow()` function
|
|
170
|
-
*
|
|
171
|
-
* The result is cached, so subsequent calls return the same promise.
|
|
172
|
-
* Note: Any changes made to the ShadowMaster instance (via setTemplate/addStyles)
|
|
173
|
-
* after the first call to getResolved() will be ignored.
|
|
174
|
-
*
|
|
175
|
-
* @returns A promise resolving to the ShadowConfig.
|
|
176
|
-
*/
|
|
177
|
-
async getResolved() {
|
|
178
|
-
if (!__classPrivateFieldGet(this, _ShadowMaster_normalizedConfig, "f")) {
|
|
179
|
-
__classPrivateFieldSet(this, _ShadowMaster_normalizedConfig, resolveConfig(__classPrivateFieldGet(this, _ShadowMaster_templateConfig, "f"), __classPrivateFieldGet(this, _ShadowMaster_stylesConfig, "f")), "f");
|
|
180
|
-
}
|
|
181
|
-
return await __classPrivateFieldGet(this, _ShadowMaster_normalizedConfig, "f");
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
_ShadowMaster_templateConfig = new WeakMap(), _ShadowMaster_stylesConfig = new WeakMap(), _ShadowMaster_normalizedConfig = new WeakMap();
|
|
185
|
-
/**
|
|
186
|
-
* A helper to bridge the attribute world (kebab-case) to the property world (camelCase).
|
|
187
|
-
* It works in tandem with browser's `observedAttributes` feature which triggers
|
|
188
|
-
* `attributeChangedCallback`.
|
|
189
|
-
*
|
|
190
|
-
* @remarks
|
|
191
|
-
* Your custom component class MUST define `static observedAttributes[]` otherwise `attributeChangedCallback` won't trigger.
|
|
192
|
-
* `observedAttributes` should contain kebab-based attribute names.
|
|
193
|
-
*
|
|
194
|
-
* @example
|
|
195
|
-
* ```ts
|
|
196
|
-
* class MyComponent extends HTMLElement {
|
|
197
|
-
* static observedAttributes = ['user-name', 'counter']
|
|
198
|
-
* userName = '' // Property MUST exist on the instance (or prototype setter)
|
|
199
|
-
* #counter = 0 // You can also use private properties together with getter/setters
|
|
200
|
-
*
|
|
201
|
-
* attributeChangedCallback(name, oldValue, newValue) {
|
|
202
|
-
* attr2prop(this, name, oldValue, newValue)
|
|
203
|
-
* }
|
|
204
|
-
|
|
205
|
-
* get counter() {
|
|
206
|
-
* return this.#counter
|
|
207
|
-
* }
|
|
208
|
-
*
|
|
209
|
-
* set counter(value) {
|
|
210
|
-
* this.#counter = value
|
|
211
|
-
* this.#render() // You can call your render function to update the DOM
|
|
212
|
-
* }
|
|
213
|
-
*
|
|
214
|
-
* #render() {
|
|
215
|
-
* const shadow = JJHE.from(this).shadow
|
|
216
|
-
* if (shadow) {
|
|
217
|
-
* shadow.byId('user').setText(this.userName)
|
|
218
|
-
* shadow.byId('counter').setText(this.counter)
|
|
219
|
-
* }
|
|
220
|
-
* }
|
|
221
|
-
* }
|
|
222
|
-
* ```
|
|
223
|
-
*
|
|
224
|
-
* @param instance - A reference to the common component instance
|
|
225
|
-
* @param name - kebab-case and in lower case exactly as it appears in `observedAttributes`.
|
|
226
|
-
* @param oldValue - The previous value of the attribute.
|
|
227
|
-
* @param newValue - The new value of the attribute.
|
|
228
|
-
* @returns `true` if it tried to set the attribute; otherwise `false`.
|
|
229
|
-
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_custom_elements#responding_to_attribute_changes | Responding to attribute changes}
|
|
230
|
-
*/
|
|
231
|
-
export function attr2prop(instance, name, oldValue, newValue) {
|
|
232
|
-
if (!isA(instance, HTMLElement)) {
|
|
233
|
-
throw new TypeError(`Expected an HTMLElement or a custom element instance. Got ${instance} (${typeof instance})`);
|
|
234
|
-
}
|
|
235
|
-
// Called when observed attributes change.
|
|
236
|
-
if (oldValue !== newValue) {
|
|
237
|
-
const propName = keb2cam(name);
|
|
238
|
-
if (hasProp(instance, propName)) {
|
|
239
|
-
instance[propName] = newValue;
|
|
240
|
-
return true;
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
return false;
|
|
244
|
-
}
|
|
245
|
-
/**
|
|
246
|
-
* Registers the custom element with the browser and waits till it is defined.
|
|
247
|
-
*
|
|
248
|
-
* @example
|
|
249
|
-
* ```ts
|
|
250
|
-
* class MyComponent extends HTMLElement {}
|
|
251
|
-
* await registerComponent('my-component', MyComponent)
|
|
252
|
-
* ```
|
|
253
|
-
* Another convention is to have a `static async register()` function in the Custom Component.
|
|
254
|
-
* ```ts
|
|
255
|
-
* export class MyComponent extends HTMLElement {
|
|
256
|
-
* static async register() {
|
|
257
|
-
* return registerComponent('my-component', MyComponent)
|
|
258
|
-
* }
|
|
259
|
-
* }
|
|
260
|
-
* ```
|
|
261
|
-
* That way, you can import multiple components and do a `Promise.all()` on all their `.register()`s.
|
|
262
|
-
* ```ts
|
|
263
|
-
* import { MyComponent, YourComponent, TheirComponent } ...
|
|
264
|
-
* await Promise.all([
|
|
265
|
-
* MyComponent.register(),
|
|
266
|
-
* YourComponent.register(),
|
|
267
|
-
* TheirComponent.register(),
|
|
268
|
-
* ])
|
|
269
|
-
*
|
|
270
|
-
* @throws {TypeError} If name is not a string or constructor is not a function
|
|
271
|
-
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry/define | customElements.define}
|
|
272
|
-
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry/whenDefined | customElements.whenDefined}
|
|
273
|
-
*/
|
|
274
|
-
export async function registerComponent(name, constructor, options) {
|
|
275
|
-
if (!isStr(name)) {
|
|
276
|
-
throw new TypeError(`Expected a string name. Got ${name} (${typeof name})`);
|
|
277
|
-
}
|
|
278
|
-
if (!isFn(constructor)) {
|
|
279
|
-
throw new TypeError(`Expected a constructor function. Got ${constructor} (${typeof constructor})`);
|
|
280
|
-
}
|
|
281
|
-
if (!customElements.get(name)) {
|
|
282
|
-
customElements.define(name, constructor, options);
|
|
283
|
-
await customElements.whenDefined(name);
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
//# sourceMappingURL=components.js.map
|
package/lib/components.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"components.js","sourceRoot":"","sources":["../src/components.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,KAAK,CAAA;AAE7D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AACtC,OAAO,EAAE,OAAO,EAA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AAc,CAAC,WAAW,CAAC,IAAI,CAAC,CAAA;IAC1C,CAAC;AACL,CAAC"}
|
package/lib/helpers.d.ts
DELETED
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import { JJHE } from './JJHE.js';
|
|
2
|
-
import { Wrappable } from './types.js';
|
|
3
|
-
/**
|
|
4
|
-
* Hyperscript helper to create JJHE instances.
|
|
5
|
-
* The `h` function provides a concise way to create DOM wrappers with attributes and children,
|
|
6
|
-
* similar to hyperscript helpers found in other libraries.
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* @remarks
|
|
10
|
-
* It returns a `JJHE` instance which wraps the native HTMLElement.
|
|
11
|
-
*
|
|
12
|
-
* You may recognize it from other libraries:
|
|
13
|
-
* - [React](https://react.dev/reference/react/createElement)
|
|
14
|
-
* - [Vue](https://vuejs.org/guide/extras/render-function)
|
|
15
|
-
* - [Hyperscript](https://github.com/hyperhype/hyperscript)
|
|
16
|
-
* - [Angular](https://angular.dev/guide/components/programmatic-rendering)
|
|
17
|
-
* - [Lit](https://lit.dev/docs/components/rendering/)
|
|
18
|
-
*
|
|
19
|
-
* This is not exactly a replacement, but it roughly follows the same idea.
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```ts
|
|
23
|
-
* // Create a simple div
|
|
24
|
-
* h('div', { id: 'app' }, 'Hello World')
|
|
25
|
-
*
|
|
26
|
-
* // Create a nested structure
|
|
27
|
-
* h('ul', { class: 'list' },
|
|
28
|
-
* h('li', null, 'Item 1'),
|
|
29
|
-
* h('li', null, 'Item 2')
|
|
30
|
-
* )
|
|
31
|
-
* ```
|
|
32
|
-
*
|
|
33
|
-
* @param tagName - The HTML tag name.
|
|
34
|
-
* @param attributes - Attributes to set on the element. Can be null or undefined.
|
|
35
|
-
* @param children - Children to append (strings, nodes, or other JJHE instances).
|
|
36
|
-
* @returns The created JJHE instance.
|
|
37
|
-
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Document/createElement | document.createElement}
|
|
38
|
-
*/
|
|
39
|
-
export declare function h(tagName: string, attributes?: Record<string, string> | null, ...children: Wrappable[]): JJHE;
|
|
40
|
-
/**
|
|
41
|
-
* Creates a `<link>` element for prefetching or preloading resources.
|
|
42
|
-
*
|
|
43
|
-
* @remarks
|
|
44
|
-
* This function validates the input arguments and returns a wrapped `JJHE` instance.
|
|
45
|
-
* It does not append the element to the document.
|
|
46
|
-
*
|
|
47
|
-
* @param rel - The relationship of the linked resource ('prefetch' or 'preload').
|
|
48
|
-
* @param href - The URL of the resource.
|
|
49
|
-
* @param as - The type of content being loaded ('fetch' for HTML, 'style' for CSS, or 'script' for JavaScript files).
|
|
50
|
-
* If it's not provided or set to a falsy value, it runs heuristics to find the best match from the href parameter.
|
|
51
|
-
*
|
|
52
|
-
* @returns The JJHE instance representing the link element. The `<link>` is accessible via `.ref`
|
|
53
|
-
* @throws {TypeError} If `href` is not a string or URL.
|
|
54
|
-
* @throws {RangeError} If `rel` or `as` are not valid values.
|
|
55
|
-
* @see {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel/preload | Link types: preload}
|
|
56
|
-
* @see {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel/prefetch | Link types: prefetch}
|
|
57
|
-
*/
|
|
58
|
-
export declare function createLinkPre(rel: 'prefetch' | 'preload', href: string | URL, as?: 'fetch' | 'style' | 'script'): JJHE;
|
|
59
|
-
/**
|
|
60
|
-
* Adds a `<link>` tag to the document head for prefetching or preloading resources.
|
|
61
|
-
*
|
|
62
|
-
* @remarks
|
|
63
|
-
* This function helps in optimizing performance by telling the browser to fetch resources
|
|
64
|
-
* that might be needed later (prefetch) or are needed immediately (preload).
|
|
65
|
-
*
|
|
66
|
-
* Please refer to {@link createLinkPre} for more details.
|
|
67
|
-
*
|
|
68
|
-
* @example
|
|
69
|
-
* ```ts
|
|
70
|
-
* // Preload a script
|
|
71
|
-
* addLinkPre('https://example.com/script.js', 'preload', 'script')
|
|
72
|
-
*
|
|
73
|
-
* // Prefetch a future page's CSS
|
|
74
|
-
* addLinkPre('/next-page.css', 'prefetch', 'style')
|
|
75
|
-
* ```
|
|
76
|
-
*
|
|
77
|
-
* @returns The JJHE instance representing the link element.
|
|
78
|
-
* @throws {TypeError} If `href` is not a string or URL.
|
|
79
|
-
* @throws {RangeError} If `rel` or `as` are not valid values.
|
|
80
|
-
* @see {@link createLinkPre}
|
|
81
|
-
* @see {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel/preload | Link types: preload}
|
|
82
|
-
* @see {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel/prefetch | Link types: prefetch}
|
|
83
|
-
*/
|
|
84
|
-
export declare function addLinkPre(...args: Parameters<typeof createLinkPre>): JJHE<HTMLElement>;
|
|
85
|
-
/**
|
|
86
|
-
* Fetches a file and returns its contents as string.
|
|
87
|
-
*
|
|
88
|
-
* @remarks
|
|
89
|
-
* This is a wrapper around the native `fetch` API that handles the response status check
|
|
90
|
-
* and text extraction. It sets the `Accept` header based on the provided mime type.
|
|
91
|
-
*
|
|
92
|
-
* @example
|
|
93
|
-
* ```ts
|
|
94
|
-
* const text = await fetchText('https://example.com/data.txt')
|
|
95
|
-
* ```
|
|
96
|
-
*
|
|
97
|
-
* @param url - The file location.
|
|
98
|
-
* @param mime - The HTTP Request Accept header. Defaults to 'text/*'.
|
|
99
|
-
* @returns The file contents as a string.
|
|
100
|
-
* @throws {TypeError} If `mime` is not a string.
|
|
101
|
-
* @throws {Error} If the fetch fails or the response status is not OK (200-299).
|
|
102
|
-
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API | Fetch API}
|
|
103
|
-
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Response/text | Response.text()}
|
|
104
|
-
*/
|
|
105
|
-
export declare function fetchText(url: URL | string, mime?: string): Promise<string>;
|
|
106
|
-
/**
|
|
107
|
-
* Fetches the contents of a HTML file as string.
|
|
108
|
-
*
|
|
109
|
-
* @remarks
|
|
110
|
-
* Useful for loading HTML templates dynamically.
|
|
111
|
-
* You can use `import.meta.resolve('./relative-path-to.html')` to resolve paths relative to the current module.
|
|
112
|
-
*
|
|
113
|
-
* @example
|
|
114
|
-
* ```ts
|
|
115
|
-
* const template = await fetchHtml('./template.html')
|
|
116
|
-
* ```
|
|
117
|
-
*
|
|
118
|
-
* @param url - The HTML file location.
|
|
119
|
-
* @returns The file content as a string.
|
|
120
|
-
* @throws {Error} If the response is not ok.
|
|
121
|
-
* @see {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types | MIME types}
|
|
122
|
-
*/
|
|
123
|
-
export declare function fetchHtml(url: URL | string): Promise<string>;
|
|
124
|
-
/**
|
|
125
|
-
* Fetches the contents of a CSS file as string.
|
|
126
|
-
*
|
|
127
|
-
* @remarks
|
|
128
|
-
* You can use `import.meta.resolve('./relative-path-to.css')` inside components to resolve relative paths.
|
|
129
|
-
*
|
|
130
|
-
* @example
|
|
131
|
-
* ```ts
|
|
132
|
-
* const css = await fetchCss('./style.css')
|
|
133
|
-
* ```
|
|
134
|
-
*
|
|
135
|
-
* @param url - The CSS file location.
|
|
136
|
-
* @returns The file content as a string.
|
|
137
|
-
* @throws {Error} If the response is not ok.
|
|
138
|
-
*/
|
|
139
|
-
export declare function fetchCss(url: URL | string): Promise<string>;
|
|
140
|
-
/**
|
|
141
|
-
* Fetches a CSS file and constructs a CSSStyleSheet.
|
|
142
|
-
*
|
|
143
|
-
* @remarks
|
|
144
|
-
* This is particularly useful for Constructable Stylesheets, which can be shared across Shadow DOM boundaries.
|
|
145
|
-
*
|
|
146
|
-
* @example
|
|
147
|
-
* ```ts
|
|
148
|
-
* const sheet = await fetchStyle('./component.css')
|
|
149
|
-
* shadowRoot.adoptedStyleSheets = [sheet]
|
|
150
|
-
* ```
|
|
151
|
-
*
|
|
152
|
-
* @param url - The CSS file location.
|
|
153
|
-
* @returns The CSSStyleSheet object constructed from the CSS contents.
|
|
154
|
-
* @throws {Error} If the fetch fails.
|
|
155
|
-
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet | CSSStyleSheet}
|
|
156
|
-
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/ShadowRoot/adoptedStyleSheets | adoptedStyleSheets}
|
|
157
|
-
*/
|
|
158
|
-
export declare function fetchStyle(url: URL | string): Promise<CSSStyleSheet>;
|