thunderous 1.0.1 → 1.0.2

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
@@ -578,8 +578,18 @@ var serverDefineFns = /* @__PURE__ */ new Set();
578
578
  var onServerDefine = (fn) => {
579
579
  serverDefineFns.add(fn);
580
580
  };
581
- var serverDefine = ({ tagName, serverRender, options, scopedRegistry, parentRegistry }) => {
581
+ var serverDefine = ({
582
+ tagName,
583
+ serverRender,
584
+ options,
585
+ elementResult,
586
+ scopedRegistry,
587
+ parentRegistry
588
+ }) => {
582
589
  if (parentRegistry !== void 0) {
590
+ if (parentRegistry.getTagName(elementResult) !== tagName.toUpperCase()) {
591
+ parentRegistry.define(tagName, elementResult);
592
+ }
583
593
  parentRegistry.__serverRenderOpts.set(tagName, { serverRender, ...options });
584
594
  if (parentRegistry.scoped) return;
585
595
  }
@@ -870,7 +880,8 @@ var customElement = (render, options) => {
870
880
  serverRender,
871
881
  options: allOptions,
872
882
  scopedRegistry,
873
- parentRegistry: _registry2
883
+ parentRegistry: _registry2,
884
+ elementResult: this
874
885
  });
875
886
  return this;
876
887
  },
@@ -1177,6 +1188,7 @@ You must set an initial value before calling a property signal's getter.
1177
1188
  var createRegistry = (args) => {
1178
1189
  const { scoped = false } = args ?? {};
1179
1190
  const customElementMap = /* @__PURE__ */ new Map();
1191
+ const elementResultMap = /* @__PURE__ */ new Map();
1180
1192
  const customElementTags = /* @__PURE__ */ new Set();
1181
1193
  const nativeRegistry = (() => {
1182
1194
  if (isServer) return;
@@ -1188,30 +1200,42 @@ var createRegistry = (args) => {
1188
1200
  __serverRenderOpts: /* @__PURE__ */ new Map(),
1189
1201
  define(tagName, ElementResult, options) {
1190
1202
  const isResult = "eject" in ElementResult;
1191
- if (isServer) {
1192
- if (isResult) ElementResult.register(this).define(tagName, options);
1203
+ const upperCaseTagName = tagName.toUpperCase();
1204
+ if (customElementTags.has(upperCaseTagName)) {
1205
+ console.warn(`Custom element tag name "${upperCaseTagName}" was already defined. Skipping...`);
1193
1206
  return this;
1194
1207
  }
1195
- const CustomElement = isResult ? ElementResult.eject() : ElementResult;
1196
- if (customElementMap.has(CustomElement)) {
1197
- console.warn(`Custom element class "${CustomElement.constructor.name}" was already defined. Skipping...`);
1198
- return this;
1208
+ if (isResult) {
1209
+ if (elementResultMap.has(ElementResult)) {
1210
+ console.warn(`${upperCaseTagName} was already defined. Skipping...`);
1211
+ return this;
1212
+ }
1199
1213
  }
1200
- if (customElementTags.has(tagName)) {
1201
- console.warn(`Custom element tag name "${tagName}" was already defined. Skipping...`);
1202
- return this;
1214
+ if (!isServer) {
1215
+ const CustomElement2 = isResult ? ElementResult.eject() : ElementResult;
1216
+ if (customElementMap.has(CustomElement2)) {
1217
+ console.warn(`Custom element class "${CustomElement2.constructor.name}" was already defined. Skipping...`);
1218
+ return this;
1219
+ }
1220
+ customElementMap.set(CustomElement2, upperCaseTagName);
1203
1221
  }
1204
- customElementMap.set(CustomElement, tagName.toUpperCase());
1205
- customElementTags.add(tagName);
1206
- if (CustomElement === void 0) {
1207
- console.error(`Custom element class for tag name "${tagName}" was not found. You must register it first.`);
1222
+ if (isResult) elementResultMap.set(ElementResult, upperCaseTagName);
1223
+ customElementTags.add(upperCaseTagName);
1224
+ if (isServer) {
1225
+ if (isResult) ElementResult.register(this).define(tagName, options);
1208
1226
  return this;
1209
1227
  }
1228
+ const CustomElement = isResult ? ElementResult.eject() : ElementResult;
1210
1229
  nativeRegistry?.define(tagName, CustomElement, options);
1211
1230
  return this;
1212
1231
  },
1213
1232
  getTagName: (ElementResult) => {
1214
- const CustomElement = "eject" in ElementResult ? ElementResult.eject() : ElementResult;
1233
+ const isResult = "eject" in ElementResult;
1234
+ if (isServer) {
1235
+ if (isResult) return elementResultMap.get(ElementResult);
1236
+ return;
1237
+ }
1238
+ const CustomElement = isResult ? ElementResult.eject() : ElementResult;
1215
1239
  return customElementMap.get(CustomElement);
1216
1240
  },
1217
1241
  getAllTagNames: () => Array.from(customElementTags),
package/dist/index.d.cts CHANGED
@@ -645,18 +645,18 @@ type ServerRenderFunction = (args: RenderArgs<CustomElementProps>) => string;
645
645
 
646
646
  type ServerRenderOptions = { serverRender: ServerRenderFunction } & RenderOptions;
647
647
 
648
- type ServerDefineFn = (tagName: string, htmlString: string) => void;
648
+ type ServerDefineFn = (tagName: TagName, htmlString: string) => void;
649
649
 
650
650
  type RegistryResult = {
651
- __serverCss: Map<string, string[]>;
652
- __serverRenderOpts: Map<string, ServerRenderOptions>;
651
+ __serverCss: Map<TagName, string[]>;
652
+ __serverRenderOpts: Map<TagName, ServerRenderOptions>;
653
653
  define: (
654
654
  tagName: TagName,
655
655
  CustomElement: CustomElementConstructor | ElementResult,
656
656
  options?: ElementDefinitionOptions,
657
657
  ) => RegistryResult;
658
- getTagName: (CustomElement: CustomElementConstructor | ElementResult) => string | undefined;
659
- getAllTagNames: () => string[];
658
+ getTagName: (CustomElement: CustomElementConstructor | ElementResult) => TagName | undefined;
659
+ getAllTagNames: () => TagName[];
660
660
  eject: () => CustomElementRegistry;
661
661
  scoped: boolean;
662
662
  };
package/dist/index.d.ts CHANGED
@@ -645,18 +645,18 @@ type ServerRenderFunction = (args: RenderArgs<CustomElementProps>) => string;
645
645
 
646
646
  type ServerRenderOptions = { serverRender: ServerRenderFunction } & RenderOptions;
647
647
 
648
- type ServerDefineFn = (tagName: string, htmlString: string) => void;
648
+ type ServerDefineFn = (tagName: TagName, htmlString: string) => void;
649
649
 
650
650
  type RegistryResult = {
651
- __serverCss: Map<string, string[]>;
652
- __serverRenderOpts: Map<string, ServerRenderOptions>;
651
+ __serverCss: Map<TagName, string[]>;
652
+ __serverRenderOpts: Map<TagName, ServerRenderOptions>;
653
653
  define: (
654
654
  tagName: TagName,
655
655
  CustomElement: CustomElementConstructor | ElementResult,
656
656
  options?: ElementDefinitionOptions,
657
657
  ) => RegistryResult;
658
- getTagName: (CustomElement: CustomElementConstructor | ElementResult) => string | undefined;
659
- getAllTagNames: () => string[];
658
+ getTagName: (CustomElement: CustomElementConstructor | ElementResult) => TagName | undefined;
659
+ getAllTagNames: () => TagName[];
660
660
  eject: () => CustomElementRegistry;
661
661
  scoped: boolean;
662
662
  };
package/dist/index.js CHANGED
@@ -543,8 +543,18 @@ var serverDefineFns = /* @__PURE__ */ new Set();
543
543
  var onServerDefine = (fn) => {
544
544
  serverDefineFns.add(fn);
545
545
  };
546
- var serverDefine = ({ tagName, serverRender, options, scopedRegistry, parentRegistry }) => {
546
+ var serverDefine = ({
547
+ tagName,
548
+ serverRender,
549
+ options,
550
+ elementResult,
551
+ scopedRegistry,
552
+ parentRegistry
553
+ }) => {
547
554
  if (parentRegistry !== void 0) {
555
+ if (parentRegistry.getTagName(elementResult) !== tagName.toUpperCase()) {
556
+ parentRegistry.define(tagName, elementResult);
557
+ }
548
558
  parentRegistry.__serverRenderOpts.set(tagName, { serverRender, ...options });
549
559
  if (parentRegistry.scoped) return;
550
560
  }
@@ -835,7 +845,8 @@ var customElement = (render, options) => {
835
845
  serverRender,
836
846
  options: allOptions,
837
847
  scopedRegistry,
838
- parentRegistry: _registry2
848
+ parentRegistry: _registry2,
849
+ elementResult: this
839
850
  });
840
851
  return this;
841
852
  },
@@ -1142,6 +1153,7 @@ You must set an initial value before calling a property signal's getter.
1142
1153
  var createRegistry = (args) => {
1143
1154
  const { scoped = false } = args ?? {};
1144
1155
  const customElementMap = /* @__PURE__ */ new Map();
1156
+ const elementResultMap = /* @__PURE__ */ new Map();
1145
1157
  const customElementTags = /* @__PURE__ */ new Set();
1146
1158
  const nativeRegistry = (() => {
1147
1159
  if (isServer) return;
@@ -1153,30 +1165,42 @@ var createRegistry = (args) => {
1153
1165
  __serverRenderOpts: /* @__PURE__ */ new Map(),
1154
1166
  define(tagName, ElementResult, options) {
1155
1167
  const isResult = "eject" in ElementResult;
1156
- if (isServer) {
1157
- if (isResult) ElementResult.register(this).define(tagName, options);
1168
+ const upperCaseTagName = tagName.toUpperCase();
1169
+ if (customElementTags.has(upperCaseTagName)) {
1170
+ console.warn(`Custom element tag name "${upperCaseTagName}" was already defined. Skipping...`);
1158
1171
  return this;
1159
1172
  }
1160
- const CustomElement = isResult ? ElementResult.eject() : ElementResult;
1161
- if (customElementMap.has(CustomElement)) {
1162
- console.warn(`Custom element class "${CustomElement.constructor.name}" was already defined. Skipping...`);
1163
- return this;
1173
+ if (isResult) {
1174
+ if (elementResultMap.has(ElementResult)) {
1175
+ console.warn(`${upperCaseTagName} was already defined. Skipping...`);
1176
+ return this;
1177
+ }
1164
1178
  }
1165
- if (customElementTags.has(tagName)) {
1166
- console.warn(`Custom element tag name "${tagName}" was already defined. Skipping...`);
1167
- return this;
1179
+ if (!isServer) {
1180
+ const CustomElement2 = isResult ? ElementResult.eject() : ElementResult;
1181
+ if (customElementMap.has(CustomElement2)) {
1182
+ console.warn(`Custom element class "${CustomElement2.constructor.name}" was already defined. Skipping...`);
1183
+ return this;
1184
+ }
1185
+ customElementMap.set(CustomElement2, upperCaseTagName);
1168
1186
  }
1169
- customElementMap.set(CustomElement, tagName.toUpperCase());
1170
- customElementTags.add(tagName);
1171
- if (CustomElement === void 0) {
1172
- console.error(`Custom element class for tag name "${tagName}" was not found. You must register it first.`);
1187
+ if (isResult) elementResultMap.set(ElementResult, upperCaseTagName);
1188
+ customElementTags.add(upperCaseTagName);
1189
+ if (isServer) {
1190
+ if (isResult) ElementResult.register(this).define(tagName, options);
1173
1191
  return this;
1174
1192
  }
1193
+ const CustomElement = isResult ? ElementResult.eject() : ElementResult;
1175
1194
  nativeRegistry?.define(tagName, CustomElement, options);
1176
1195
  return this;
1177
1196
  },
1178
1197
  getTagName: (ElementResult) => {
1179
- const CustomElement = "eject" in ElementResult ? ElementResult.eject() : ElementResult;
1198
+ const isResult = "eject" in ElementResult;
1199
+ if (isServer) {
1200
+ if (isResult) return elementResultMap.get(ElementResult);
1201
+ return;
1202
+ }
1203
+ const CustomElement = isResult ? ElementResult.eject() : ElementResult;
1180
1204
  return customElementMap.get(CustomElement);
1181
1205
  },
1182
1206
  getAllTagNames: () => Array.from(customElementTags),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "thunderous",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -34,7 +34,7 @@
34
34
  "www": "cd www && npm run dev",
35
35
  "build": "tsup src/index.ts --format cjs,esm --dts --no-clean",
36
36
  "test": "find src -name '*.test.ts' | xargs c8 node --import tsx --test",
37
- "lint": "eslint ."
37
+ "lint": "tsc && eslint ."
38
38
  },
39
39
  "devDependencies": {
40
40
  "@types/dompurify": "^3.2.0",