thunderous 0.5.0 → 0.6.1
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/dist/index.cjs +34 -14
- package/dist/index.d.cts +14 -6
- package/dist/index.d.ts +14 -6
- package/dist/index.js +34 -14
- package/package.json +9 -1
package/dist/index.cjs
CHANGED
@@ -1233,6 +1233,7 @@ var customElement = (render, options) => {
|
|
1233
1233
|
shadowRootOptions: _shadowRootOptions
|
1234
1234
|
} = { ...DEFAULT_RENDER_OPTIONS, ...options };
|
1235
1235
|
const shadowRootOptions = { ...DEFAULT_RENDER_OPTIONS.shadowRootOptions, ..._shadowRootOptions };
|
1236
|
+
shadowRootOptions.registry = shadowRootOptions.customElements = shadowRootOptions.registry instanceof CustomElementRegistry ? shadowRootOptions.registry : shadowRootOptions.registry?.eject();
|
1236
1237
|
const observedAttributesSet = new Set(_observedAttributes);
|
1237
1238
|
const attributesAsPropertiesMap = /* @__PURE__ */ new Map();
|
1238
1239
|
for (const [attrName, coerce] of attributesAsProperties) {
|
@@ -1467,27 +1468,32 @@ You must set an initial value before calling a property signal's getter.
|
|
1467
1468
|
}
|
1468
1469
|
}
|
1469
1470
|
}
|
1470
|
-
let
|
1471
|
+
let _tagName = null;
|
1471
1472
|
let _registry = null;
|
1472
1473
|
let _registered = false;
|
1473
1474
|
const register = () => {
|
1474
|
-
if (
|
1475
|
-
_registry.register(
|
1476
|
-
_registry.register(
|
1475
|
+
if (_tagName === null || _registry === null || _registered) return;
|
1476
|
+
_registry.register(_tagName, CustomElement);
|
1477
|
+
_registry.register(_tagName, elementResult);
|
1477
1478
|
_registered = true;
|
1478
1479
|
};
|
1479
1480
|
const elementResult = {
|
1480
|
-
define(
|
1481
|
-
|
1482
|
-
|
1481
|
+
define(tagName) {
|
1482
|
+
const registry = _registry?.scoped ? _registry.eject() : customElements;
|
1483
|
+
if (registry.get(tagName) !== void 0) {
|
1484
|
+
console.warn(`Custom element "${tagName}" was already defined. Skipping...`);
|
1483
1485
|
return this;
|
1484
1486
|
}
|
1485
|
-
|
1486
|
-
|
1487
|
+
registry.define(tagName, CustomElement);
|
1488
|
+
_tagName = tagName;
|
1487
1489
|
register();
|
1488
1490
|
return this;
|
1489
1491
|
},
|
1490
1492
|
register(registry) {
|
1493
|
+
if (_tagName !== null && registry.scoped) {
|
1494
|
+
console.error("Must call `register()` before `define()` for scoped registries.");
|
1495
|
+
return this;
|
1496
|
+
}
|
1491
1497
|
_registry = registry;
|
1492
1498
|
register();
|
1493
1499
|
return this;
|
@@ -1496,17 +1502,31 @@ You must set an initial value before calling a property signal's getter.
|
|
1496
1502
|
};
|
1497
1503
|
return elementResult;
|
1498
1504
|
};
|
1499
|
-
var createRegistry = () => {
|
1500
|
-
const
|
1505
|
+
var createRegistry = (args) => {
|
1506
|
+
const { scoped = false } = args ?? {};
|
1507
|
+
const registryResult = /* @__PURE__ */ new Map();
|
1508
|
+
const registry = (() => {
|
1509
|
+
try {
|
1510
|
+
return new CustomElementRegistry();
|
1511
|
+
} catch (error) {
|
1512
|
+
if (scoped)
|
1513
|
+
console.error(
|
1514
|
+
"Scoped custom element registries are not supported in this environment. Please install `@webcomponents/scoped-custom-element-registry` to use this feature."
|
1515
|
+
);
|
1516
|
+
return customElements;
|
1517
|
+
}
|
1518
|
+
})();
|
1501
1519
|
return {
|
1502
1520
|
register: (tagName, element) => {
|
1503
|
-
if (
|
1521
|
+
if (registryResult.has(element)) {
|
1504
1522
|
console.warn(`Custom element class "${element.constructor.name}" was already registered. Skipping...`);
|
1505
1523
|
return;
|
1506
1524
|
}
|
1507
|
-
|
1525
|
+
registryResult.set(element, tagName.toUpperCase());
|
1508
1526
|
},
|
1509
|
-
getTagName: (element) =>
|
1527
|
+
getTagName: (element) => registryResult.get(element),
|
1528
|
+
eject: () => registry,
|
1529
|
+
scoped
|
1510
1530
|
};
|
1511
1531
|
};
|
1512
1532
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/index.d.cts
CHANGED
@@ -52,7 +52,7 @@ declare global {
|
|
52
52
|
}
|
53
53
|
type ElementResult = {
|
54
54
|
define: (tagname: `${string}-${string}`) => ElementResult;
|
55
|
-
register: (registry:
|
55
|
+
register: (registry: RegistryResult) => ElementResult;
|
56
56
|
eject: () => CustomElementConstructor;
|
57
57
|
};
|
58
58
|
type AttributeChangedCallback = (name: string, oldValue: string | null, newValue: string | null) => void;
|
@@ -83,7 +83,10 @@ type RenderOptions = {
|
|
83
83
|
observedAttributes: string[];
|
84
84
|
attributesAsProperties: [string, Coerce][];
|
85
85
|
attachShadow: boolean;
|
86
|
-
shadowRootOptions: ShadowRootInit
|
86
|
+
shadowRootOptions: Partial<ShadowRootInit> & {
|
87
|
+
customElements?: CustomElementRegistry;
|
88
|
+
registry?: CustomElementRegistry | RegistryResult;
|
89
|
+
};
|
87
90
|
};
|
88
91
|
type RenderFunction<Props extends CustomElementProps> = (args: RenderArgs<Props>) => DocumentFragment;
|
89
92
|
/**
|
@@ -97,9 +100,14 @@ type RenderFunction<Props extends CustomElementProps> = (args: RenderArgs<Props>
|
|
97
100
|
* ```
|
98
101
|
*/
|
99
102
|
declare const customElement: <Props extends CustomElementProps>(render: RenderFunction<Props>, options?: Partial<RenderOptions>) => ElementResult;
|
100
|
-
type
|
101
|
-
register: (tagName: string,
|
102
|
-
getTagName: (
|
103
|
+
type RegistryResult = {
|
104
|
+
register: (tagName: string, CustomElement: CustomElementConstructor | ElementResult) => void;
|
105
|
+
getTagName: (CustomElement: CustomElementConstructor | ElementResult) => string | undefined;
|
106
|
+
eject: () => CustomElementRegistry;
|
107
|
+
scoped: boolean;
|
108
|
+
};
|
109
|
+
type RegistryArgs = {
|
110
|
+
scoped: boolean;
|
103
111
|
};
|
104
112
|
/**
|
105
113
|
* Create a registry for custom elements.
|
@@ -116,6 +124,6 @@ type Registry = {
|
|
116
124
|
* console.log(tagName); // 'MY-ELEMENT'
|
117
125
|
* ```
|
118
126
|
*/
|
119
|
-
declare const createRegistry: () =>
|
127
|
+
declare const createRegistry: (args?: RegistryArgs) => RegistryResult;
|
120
128
|
|
121
129
|
export { type RenderArgs, type RenderFunction, type RenderArgs as RenderProps, type Signal, type SignalGetter, type SignalSetter, createEffect, createRegistry, createSignal, css, customElement, derived, html };
|
package/dist/index.d.ts
CHANGED
@@ -52,7 +52,7 @@ declare global {
|
|
52
52
|
}
|
53
53
|
type ElementResult = {
|
54
54
|
define: (tagname: `${string}-${string}`) => ElementResult;
|
55
|
-
register: (registry:
|
55
|
+
register: (registry: RegistryResult) => ElementResult;
|
56
56
|
eject: () => CustomElementConstructor;
|
57
57
|
};
|
58
58
|
type AttributeChangedCallback = (name: string, oldValue: string | null, newValue: string | null) => void;
|
@@ -83,7 +83,10 @@ type RenderOptions = {
|
|
83
83
|
observedAttributes: string[];
|
84
84
|
attributesAsProperties: [string, Coerce][];
|
85
85
|
attachShadow: boolean;
|
86
|
-
shadowRootOptions: ShadowRootInit
|
86
|
+
shadowRootOptions: Partial<ShadowRootInit> & {
|
87
|
+
customElements?: CustomElementRegistry;
|
88
|
+
registry?: CustomElementRegistry | RegistryResult;
|
89
|
+
};
|
87
90
|
};
|
88
91
|
type RenderFunction<Props extends CustomElementProps> = (args: RenderArgs<Props>) => DocumentFragment;
|
89
92
|
/**
|
@@ -97,9 +100,14 @@ type RenderFunction<Props extends CustomElementProps> = (args: RenderArgs<Props>
|
|
97
100
|
* ```
|
98
101
|
*/
|
99
102
|
declare const customElement: <Props extends CustomElementProps>(render: RenderFunction<Props>, options?: Partial<RenderOptions>) => ElementResult;
|
100
|
-
type
|
101
|
-
register: (tagName: string,
|
102
|
-
getTagName: (
|
103
|
+
type RegistryResult = {
|
104
|
+
register: (tagName: string, CustomElement: CustomElementConstructor | ElementResult) => void;
|
105
|
+
getTagName: (CustomElement: CustomElementConstructor | ElementResult) => string | undefined;
|
106
|
+
eject: () => CustomElementRegistry;
|
107
|
+
scoped: boolean;
|
108
|
+
};
|
109
|
+
type RegistryArgs = {
|
110
|
+
scoped: boolean;
|
103
111
|
};
|
104
112
|
/**
|
105
113
|
* Create a registry for custom elements.
|
@@ -116,6 +124,6 @@ type Registry = {
|
|
116
124
|
* console.log(tagName); // 'MY-ELEMENT'
|
117
125
|
* ```
|
118
126
|
*/
|
119
|
-
declare const createRegistry: () =>
|
127
|
+
declare const createRegistry: (args?: RegistryArgs) => RegistryResult;
|
120
128
|
|
121
129
|
export { type RenderArgs, type RenderFunction, type RenderArgs as RenderProps, type Signal, type SignalGetter, type SignalSetter, createEffect, createRegistry, createSignal, css, customElement, derived, html };
|
package/dist/index.js
CHANGED
@@ -1201,6 +1201,7 @@ var customElement = (render, options) => {
|
|
1201
1201
|
shadowRootOptions: _shadowRootOptions
|
1202
1202
|
} = { ...DEFAULT_RENDER_OPTIONS, ...options };
|
1203
1203
|
const shadowRootOptions = { ...DEFAULT_RENDER_OPTIONS.shadowRootOptions, ..._shadowRootOptions };
|
1204
|
+
shadowRootOptions.registry = shadowRootOptions.customElements = shadowRootOptions.registry instanceof CustomElementRegistry ? shadowRootOptions.registry : shadowRootOptions.registry?.eject();
|
1204
1205
|
const observedAttributesSet = new Set(_observedAttributes);
|
1205
1206
|
const attributesAsPropertiesMap = /* @__PURE__ */ new Map();
|
1206
1207
|
for (const [attrName, coerce] of attributesAsProperties) {
|
@@ -1435,27 +1436,32 @@ You must set an initial value before calling a property signal's getter.
|
|
1435
1436
|
}
|
1436
1437
|
}
|
1437
1438
|
}
|
1438
|
-
let
|
1439
|
+
let _tagName = null;
|
1439
1440
|
let _registry = null;
|
1440
1441
|
let _registered = false;
|
1441
1442
|
const register = () => {
|
1442
|
-
if (
|
1443
|
-
_registry.register(
|
1444
|
-
_registry.register(
|
1443
|
+
if (_tagName === null || _registry === null || _registered) return;
|
1444
|
+
_registry.register(_tagName, CustomElement);
|
1445
|
+
_registry.register(_tagName, elementResult);
|
1445
1446
|
_registered = true;
|
1446
1447
|
};
|
1447
1448
|
const elementResult = {
|
1448
|
-
define(
|
1449
|
-
|
1450
|
-
|
1449
|
+
define(tagName) {
|
1450
|
+
const registry = _registry?.scoped ? _registry.eject() : customElements;
|
1451
|
+
if (registry.get(tagName) !== void 0) {
|
1452
|
+
console.warn(`Custom element "${tagName}" was already defined. Skipping...`);
|
1451
1453
|
return this;
|
1452
1454
|
}
|
1453
|
-
|
1454
|
-
|
1455
|
+
registry.define(tagName, CustomElement);
|
1456
|
+
_tagName = tagName;
|
1455
1457
|
register();
|
1456
1458
|
return this;
|
1457
1459
|
},
|
1458
1460
|
register(registry) {
|
1461
|
+
if (_tagName !== null && registry.scoped) {
|
1462
|
+
console.error("Must call `register()` before `define()` for scoped registries.");
|
1463
|
+
return this;
|
1464
|
+
}
|
1459
1465
|
_registry = registry;
|
1460
1466
|
register();
|
1461
1467
|
return this;
|
@@ -1464,17 +1470,31 @@ You must set an initial value before calling a property signal's getter.
|
|
1464
1470
|
};
|
1465
1471
|
return elementResult;
|
1466
1472
|
};
|
1467
|
-
var createRegistry = () => {
|
1468
|
-
const
|
1473
|
+
var createRegistry = (args) => {
|
1474
|
+
const { scoped = false } = args ?? {};
|
1475
|
+
const registryResult = /* @__PURE__ */ new Map();
|
1476
|
+
const registry = (() => {
|
1477
|
+
try {
|
1478
|
+
return new CustomElementRegistry();
|
1479
|
+
} catch (error) {
|
1480
|
+
if (scoped)
|
1481
|
+
console.error(
|
1482
|
+
"Scoped custom element registries are not supported in this environment. Please install `@webcomponents/scoped-custom-element-registry` to use this feature."
|
1483
|
+
);
|
1484
|
+
return customElements;
|
1485
|
+
}
|
1486
|
+
})();
|
1469
1487
|
return {
|
1470
1488
|
register: (tagName, element) => {
|
1471
|
-
if (
|
1489
|
+
if (registryResult.has(element)) {
|
1472
1490
|
console.warn(`Custom element class "${element.constructor.name}" was already registered. Skipping...`);
|
1473
1491
|
return;
|
1474
1492
|
}
|
1475
|
-
|
1493
|
+
registryResult.set(element, tagName.toUpperCase());
|
1476
1494
|
},
|
1477
|
-
getTagName: (element) =>
|
1495
|
+
getTagName: (element) => registryResult.get(element),
|
1496
|
+
eject: () => registry,
|
1497
|
+
scoped
|
1478
1498
|
};
|
1479
1499
|
};
|
1480
1500
|
export {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "thunderous",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.6.1",
|
4
4
|
"description": "",
|
5
5
|
"type": "module",
|
6
6
|
"main": "./dist/index.cjs",
|
@@ -50,5 +50,13 @@
|
|
50
50
|
},
|
51
51
|
"dependencies": {
|
52
52
|
"dompurify": "^3.2.1"
|
53
|
+
},
|
54
|
+
"peerDependenciesMeta": {
|
55
|
+
"@webcomponents/scoped-custom-element-registry": {
|
56
|
+
"optional": true
|
57
|
+
}
|
58
|
+
},
|
59
|
+
"peerDependencies": {
|
60
|
+
"@webcomponents/scoped-custom-element-registry": "^0.0.9"
|
53
61
|
}
|
54
62
|
}
|