thunderous 0.5.0 → 0.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/dist/index.cjs CHANGED
@@ -1233,6 +1233,8 @@ 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();
1237
+ console.log(shadowRootOptions);
1236
1238
  const observedAttributesSet = new Set(_observedAttributes);
1237
1239
  const attributesAsPropertiesMap = /* @__PURE__ */ new Map();
1238
1240
  for (const [attrName, coerce] of attributesAsProperties) {
@@ -1372,6 +1374,7 @@ You must set an initial value before calling a property signal's getter.
1372
1374
  });
1373
1375
  fragment.host = this;
1374
1376
  setInnerHTML(root, fragment);
1377
+ root.innerHTML = root.innerHTML;
1375
1378
  }
1376
1379
  static get formAssociated() {
1377
1380
  return formAssociated;
@@ -1467,27 +1470,33 @@ You must set an initial value before calling a property signal's getter.
1467
1470
  }
1468
1471
  }
1469
1472
  }
1470
- let _tagname = null;
1473
+ let _tagName = null;
1471
1474
  let _registry = null;
1472
1475
  let _registered = false;
1473
1476
  const register = () => {
1474
- if (_tagname === null || _registry === null || _registered) return;
1475
- _registry.register(_tagname, CustomElement);
1476
- _registry.register(_tagname, elementResult);
1477
+ if (_tagName === null || _registry === null || _registered) return;
1478
+ _registry.register(_tagName, CustomElement);
1479
+ _registry.register(_tagName, elementResult);
1477
1480
  _registered = true;
1478
1481
  };
1479
1482
  const elementResult = {
1480
- define(tagname) {
1481
- if (customElements.get(tagname) !== void 0) {
1482
- console.warn(`Custom element "${tagname}" was already defined. Skipping...`);
1483
+ define(tagName) {
1484
+ const registry = _registry?.scoped ? _registry.eject() : customElements;
1485
+ console.log(tagName, registry);
1486
+ if (registry.get(tagName) !== void 0) {
1487
+ console.warn(`Custom element "${tagName}" was already defined. Skipping...`);
1483
1488
  return this;
1484
1489
  }
1485
- customElements.define(tagname, CustomElement);
1486
- _tagname = tagname;
1490
+ registry.define(tagName, CustomElement);
1491
+ _tagName = tagName;
1487
1492
  register();
1488
1493
  return this;
1489
1494
  },
1490
1495
  register(registry) {
1496
+ if (_tagName !== null && registry.scoped) {
1497
+ console.error("Must call `register()` before `define()` for scoped registries.");
1498
+ return this;
1499
+ }
1491
1500
  _registry = registry;
1492
1501
  register();
1493
1502
  return this;
@@ -1496,17 +1505,31 @@ You must set an initial value before calling a property signal's getter.
1496
1505
  };
1497
1506
  return elementResult;
1498
1507
  };
1499
- var createRegistry = () => {
1500
- const registry = /* @__PURE__ */ new Map();
1508
+ var createRegistry = (args) => {
1509
+ const { scoped = false } = args ?? {};
1510
+ const registryResult = /* @__PURE__ */ new Map();
1511
+ const registry = (() => {
1512
+ try {
1513
+ return new CustomElementRegistry();
1514
+ } catch (error) {
1515
+ if (scoped)
1516
+ console.error(
1517
+ "Scoped custom element registries are not supported in this environment. Please install `@webcomponents/scoped-custom-element-registry` to use this feature."
1518
+ );
1519
+ return customElements;
1520
+ }
1521
+ })();
1501
1522
  return {
1502
1523
  register: (tagName, element) => {
1503
- if (registry.has(element)) {
1524
+ if (registryResult.has(element)) {
1504
1525
  console.warn(`Custom element class "${element.constructor.name}" was already registered. Skipping...`);
1505
1526
  return;
1506
1527
  }
1507
- registry.set(element, tagName.toUpperCase());
1528
+ registryResult.set(element, tagName.toUpperCase());
1508
1529
  },
1509
- getTagName: (element) => registry.get(element)
1530
+ getTagName: (element) => registryResult.get(element),
1531
+ eject: () => registry,
1532
+ scoped
1510
1533
  };
1511
1534
  };
1512
1535
  // 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: Registry) => ElementResult;
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 Registry = {
101
- register: (tagName: string, element: CustomElementConstructor | ElementResult) => void;
102
- getTagName: (element: CustomElementConstructor | ElementResult) => string | undefined;
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: () => Registry;
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: Registry) => ElementResult;
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 Registry = {
101
- register: (tagName: string, element: CustomElementConstructor | ElementResult) => void;
102
- getTagName: (element: CustomElementConstructor | ElementResult) => string | undefined;
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: () => Registry;
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,8 @@ 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();
1205
+ console.log(shadowRootOptions);
1204
1206
  const observedAttributesSet = new Set(_observedAttributes);
1205
1207
  const attributesAsPropertiesMap = /* @__PURE__ */ new Map();
1206
1208
  for (const [attrName, coerce] of attributesAsProperties) {
@@ -1340,6 +1342,7 @@ You must set an initial value before calling a property signal's getter.
1340
1342
  });
1341
1343
  fragment.host = this;
1342
1344
  setInnerHTML(root, fragment);
1345
+ root.innerHTML = root.innerHTML;
1343
1346
  }
1344
1347
  static get formAssociated() {
1345
1348
  return formAssociated;
@@ -1435,27 +1438,33 @@ You must set an initial value before calling a property signal's getter.
1435
1438
  }
1436
1439
  }
1437
1440
  }
1438
- let _tagname = null;
1441
+ let _tagName = null;
1439
1442
  let _registry = null;
1440
1443
  let _registered = false;
1441
1444
  const register = () => {
1442
- if (_tagname === null || _registry === null || _registered) return;
1443
- _registry.register(_tagname, CustomElement);
1444
- _registry.register(_tagname, elementResult);
1445
+ if (_tagName === null || _registry === null || _registered) return;
1446
+ _registry.register(_tagName, CustomElement);
1447
+ _registry.register(_tagName, elementResult);
1445
1448
  _registered = true;
1446
1449
  };
1447
1450
  const elementResult = {
1448
- define(tagname) {
1449
- if (customElements.get(tagname) !== void 0) {
1450
- console.warn(`Custom element "${tagname}" was already defined. Skipping...`);
1451
+ define(tagName) {
1452
+ const registry = _registry?.scoped ? _registry.eject() : customElements;
1453
+ console.log(tagName, registry);
1454
+ if (registry.get(tagName) !== void 0) {
1455
+ console.warn(`Custom element "${tagName}" was already defined. Skipping...`);
1451
1456
  return this;
1452
1457
  }
1453
- customElements.define(tagname, CustomElement);
1454
- _tagname = tagname;
1458
+ registry.define(tagName, CustomElement);
1459
+ _tagName = tagName;
1455
1460
  register();
1456
1461
  return this;
1457
1462
  },
1458
1463
  register(registry) {
1464
+ if (_tagName !== null && registry.scoped) {
1465
+ console.error("Must call `register()` before `define()` for scoped registries.");
1466
+ return this;
1467
+ }
1459
1468
  _registry = registry;
1460
1469
  register();
1461
1470
  return this;
@@ -1464,17 +1473,31 @@ You must set an initial value before calling a property signal's getter.
1464
1473
  };
1465
1474
  return elementResult;
1466
1475
  };
1467
- var createRegistry = () => {
1468
- const registry = /* @__PURE__ */ new Map();
1476
+ var createRegistry = (args) => {
1477
+ const { scoped = false } = args ?? {};
1478
+ const registryResult = /* @__PURE__ */ new Map();
1479
+ const registry = (() => {
1480
+ try {
1481
+ return new CustomElementRegistry();
1482
+ } catch (error) {
1483
+ if (scoped)
1484
+ console.error(
1485
+ "Scoped custom element registries are not supported in this environment. Please install `@webcomponents/scoped-custom-element-registry` to use this feature."
1486
+ );
1487
+ return customElements;
1488
+ }
1489
+ })();
1469
1490
  return {
1470
1491
  register: (tagName, element) => {
1471
- if (registry.has(element)) {
1492
+ if (registryResult.has(element)) {
1472
1493
  console.warn(`Custom element class "${element.constructor.name}" was already registered. Skipping...`);
1473
1494
  return;
1474
1495
  }
1475
- registry.set(element, tagName.toUpperCase());
1496
+ registryResult.set(element, tagName.toUpperCase());
1476
1497
  },
1477
- getTagName: (element) => registry.get(element)
1498
+ getTagName: (element) => registryResult.get(element),
1499
+ eject: () => registry,
1500
+ scoped
1478
1501
  };
1479
1502
  };
1480
1503
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "thunderous",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
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
  }