@zeus-js/output-wc 0.1.1-beta.12 → 0.1.1-beta.14

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.
@@ -1,14 +1,90 @@
1
1
  /**
2
- * output-wc v0.1.1-beta.12
2
+ * output-wc v0.1.1-beta.14
3
3
  * (c) 2026 baicie
4
4
  * Released under the MIT License.
5
5
  **/
6
6
  import path from "node:path";
7
+ import { fileURLToPath } from "node:url";
7
8
  import { resolvePluginDts } from "@zeus-js/bundler-plugin";
8
9
  import { generateLoaderDts, generateWCDtsFiles, generateWCJsxDts } from "@zeus-js/component-dts";
10
+ //#region packages/web-c/output-wc/src/generateManifest.ts
11
+ function generateZeusComponentsManifest(manifest) {
12
+ validateComponentManifest(manifest);
13
+ return `${JSON.stringify(manifest, null, 2)}\n`;
14
+ }
15
+ function validateComponentManifest(manifest) {
16
+ if ((manifest === null || manifest === void 0 ? void 0 : manifest.schemaVersion) !== 1) throw new Error("[ZEUS_WC_ABI_VERSION] Component manifest schemaVersion must be 1.");
17
+ if (!Array.isArray(manifest.components)) throw new Error("[ZEUS_WC_INVALID_MANIFEST] Component manifest components must be an array.");
18
+ const tags = /* @__PURE__ */ new Set();
19
+ for (const [componentIndex, component] of manifest.components.entries()) {
20
+ if (!component || typeof component.tag !== "string") throw new Error(`[ZEUS_WC_INVALID_MANIFEST] components[${componentIndex}].tag must be a string.`);
21
+ if (tags.has(component.tag)) throw new Error(`[ZEUS_WC_DUPLICATE_TAG] Component tag "${component.tag}" is declared more than once.`);
22
+ tags.add(component.tag);
23
+ }
24
+ for (const [componentIndex, component] of manifest.components.entries()) {
25
+ var _component$props, _component$events, _component$props2;
26
+ const componentPath = `components[${componentIndex}]`;
27
+ if (!component || typeof component.tag !== "string" || typeof component.exportName !== "string") throw new Error(`[ZEUS_WC_INVALID_MANIFEST] ${componentPath} requires tag and exportName strings.`);
28
+ const attributes = /* @__PURE__ */ new Map();
29
+ for (const [propName, prop] of Object.entries((_component$props = component.props) !== null && _component$props !== void 0 ? _component$props : {})) {
30
+ const attrName = prop.attr === false ? false : typeof prop.attr === "string" ? prop.attr : [
31
+ "string",
32
+ "number",
33
+ "boolean"
34
+ ].includes(prop.type) ? propName.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`) : false;
35
+ if (attrName !== false) {
36
+ const previous = attributes.get(attrName);
37
+ if (previous && previous !== propName) throw new Error(`[ZEUS_WC_ATTR_COLLISION] ${componentPath}.props.${propName} and ${previous} both use attribute "${attrName}".`);
38
+ attributes.set(attrName, propName);
39
+ }
40
+ }
41
+ for (const [eventKey, event] of Object.entries((_component$events = component.events) !== null && _component$events !== void 0 ? _component$events : {})) if (event.name !== void 0 && typeof event.name !== "string" || event.reactName !== void 0 && typeof event.reactName !== "string" || event.bubbles !== void 0 && typeof event.bubbles !== "boolean" || event.composed !== void 0 && typeof event.composed !== "boolean" || event.cancelable !== void 0 && typeof event.cancelable !== "boolean") throw new Error(`[ZEUS_WC_EVENT_ABI] ${componentPath}.events.${eventKey} contains invalid names or bubbles/composed/cancelable flags.`);
42
+ for (const [propName, prop] of Object.entries((_component$props2 = component.props) !== null && _component$props2 !== void 0 ? _component$props2 : {})) {
43
+ if (prop.hasDefault !== void 0 && typeof prop.hasDefault !== "boolean") throw new Error(`[ZEUS_WC_INVALID_DEFAULT_META] ${componentPath}.props.${propName}.hasDefault must be boolean.`);
44
+ if (prop.defaultStrategy !== void 0 && prop.defaultStrategy !== "static" && prop.defaultStrategy !== "factory") throw new Error(`[ZEUS_WC_INVALID_DEFAULT_META] ${componentPath}.props.${propName}.defaultStrategy is invalid.`);
45
+ if (prop.defaultStrategy === "factory" && prop.default !== void 0) throw new Error(`[ZEUS_WC_INVALID_DEFAULT_META] ${componentPath}.props.${propName} factory defaults cannot be serialized as values.`);
46
+ if (prop.defaultStrategy === "static" && !Object.prototype.hasOwnProperty.call(prop, "default")) throw new Error(`[ZEUS_WC_INVALID_DEFAULT_META] ${componentPath}.props.${propName} static defaults require a value.`);
47
+ if (Object.prototype.hasOwnProperty.call(prop, "default")) {
48
+ if (prop.default === void 0) throw new Error(`[ZEUS_WC_INVALID_DEFAULT_META] ${componentPath}.props.${propName}.default cannot be undefined.`);
49
+ assertJsonSafe(prop.default, `${componentPath}.props.${propName}.default`, /* @__PURE__ */ new Set(), "ZEUS_WC_INVALID_DEFAULT_META", true);
50
+ }
51
+ }
52
+ }
53
+ assertJsonSafe(manifest, "manifest");
54
+ }
55
+ function assertJsonSafe(value, path, parents = /* @__PURE__ */ new Set(), code = "ZEUS_WC_INVALID_MANIFEST", rejectUndefined = false) {
56
+ if (value === void 0) {
57
+ if (rejectUndefined) throw invalidManifest(path, "undefined values are not supported", code);
58
+ return;
59
+ }
60
+ if (value === null) return;
61
+ if (typeof value === "string" || typeof value === "boolean") return;
62
+ if (typeof value === "number") {
63
+ if (!Number.isFinite(value) || Object.is(value, -0)) throw invalidManifest(path, "numbers must be finite and cannot be -0", code);
64
+ return;
65
+ }
66
+ if (typeof value === "function" || typeof value === "symbol" || typeof value === "bigint") throw invalidManifest(path, "functions, symbols, and bigint values are not supported", code);
67
+ if (typeof value !== "object") throw invalidManifest(path, "value is not JSON-safe", code);
68
+ if (parents.has(value)) throw invalidManifest(path, "cyclic values are not supported", code);
69
+ const prototype = Object.getPrototypeOf(value);
70
+ if (!Array.isArray(value) && prototype !== Object.prototype && prototype !== null) throw invalidManifest(path, "only plain objects and arrays are supported", code);
71
+ if (Object.getOwnPropertySymbols(value).length > 0) throw invalidManifest(path, "symbol keys are not supported", code);
72
+ parents.add(value);
73
+ for (const [key, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(value))) {
74
+ if ("get" in descriptor || "set" in descriptor) throw invalidManifest(`${path}.${key}`, "accessor properties are not supported", code);
75
+ if (descriptor.value === void 0 && !rejectUndefined) continue;
76
+ assertJsonSafe(descriptor.value, Array.isArray(value) ? `${path}[${key}]` : `${path}.${key}`, parents, code, rejectUndefined);
77
+ }
78
+ parents.delete(value);
79
+ }
80
+ function invalidManifest(path, reason, code) {
81
+ return /* @__PURE__ */ new Error(`[${code}] ${path}: ${reason}.`);
82
+ }
83
+ //#endregion
9
84
  //#region packages/web-c/output-wc/src/generateCustomElementsJson.ts
10
85
  function generateCustomElementsJson(options) {
11
86
  const { manifest, getModulePath } = options;
87
+ validateComponentManifest(manifest);
12
88
  const result = {
13
89
  schemaVersion: "1.0.0",
14
90
  modules: manifest.components.map((component) => {
@@ -70,14 +146,24 @@ function generateMembers(component) {
70
146
  default: prop.default === void 0 ? void 0 : JSON.stringify(prop.default)
71
147
  };
72
148
  });
73
- const methods = Object.keys((_component$methods = component.methods) !== null && _component$methods !== void 0 ? _component$methods : {}).map((name) => {
74
- return {
75
- kind: "method",
76
- name
77
- };
78
- });
149
+ const methods = Object.entries((_component$methods = component.methods) !== null && _component$methods !== void 0 ? _component$methods : {}).map(([name, method]) => generateMethodMember(name, method));
79
150
  return [...fields, ...methods];
80
151
  }
152
+ function generateMethodMember(name, method) {
153
+ var _method$returns, _method$returns2;
154
+ const member = {
155
+ kind: "method",
156
+ name,
157
+ return: { type: { text: method.async ? `Promise<${(_method$returns = method.returns) !== null && _method$returns !== void 0 ? _method$returns : "unknown"}>` : (_method$returns2 = method.returns) !== null && _method$returns2 !== void 0 ? _method$returns2 : "unknown" } }
158
+ };
159
+ if (method.parameters) member.parameters = method.parameters.map((parameter) => ({
160
+ name: parameter.name,
161
+ type: { text: parameter.type },
162
+ optional: parameter.optional,
163
+ rest: parameter.rest
164
+ }));
165
+ return member;
166
+ }
81
167
  function generateEvents(component) {
82
168
  return Object.entries(component.events).map(([key, event]) => {
83
169
  var _event$name, _event$key;
@@ -152,6 +238,15 @@ function generateWCEntry(options) {
152
238
  `import { ${component.exportName} } from ${JSON.stringify(source)};`,
153
239
  "",
154
240
  `export { ${component.exportName} };`,
241
+ "",
242
+ `export function defineCustomElement(options = {}) {`,
243
+ ` const registry = options.registry ?? (typeof customElements === 'undefined' ? undefined : customElements);`,
244
+ ` if (!registry) return;`,
245
+ ` const existing = registry.get(${JSON.stringify(component.tag)});`,
246
+ ` if (existing === ${component.exportName}) return;`,
247
+ ` if (existing) throw new Error(${JSON.stringify(`[ZEUS_WC_DUPLICATE_TAG] <${component.tag}> is already registered with a different definition.`)});`,
248
+ ` registry.define(${JSON.stringify(component.tag)}, ${component.exportName});`,
249
+ `}`,
155
250
  ""
156
251
  ].join("\n");
157
252
  }
@@ -177,16 +272,19 @@ function getVirtualIndexId() {
177
272
  //#region packages/web-c/output-wc/src/generateLazyEntry.ts
178
273
  function generateLazyEntry(options) {
179
274
  const { component, outPath, sourceImport } = options;
180
- const source = sourceImport !== null && sourceImport !== void 0 ? sourceImport : toRelativeImport(component.source, outPath);
275
+ const source = `${sourceImport !== null && sourceImport !== void 0 ? sourceImport : toRelativeImport(component.source, outPath)}?zeus-lazy-component=${component.exportName}`;
181
276
  return [
182
- `import { createCustomElementMountLifecycle, mountElementDefinition } from "@zeus-js/runtime-dom";`,
277
+ `import { createCustomElementMountLifecycle, getElementDefinition, mountElementDefinition } from "@zeus-js/runtime-dom";`,
278
+ `import { resolveHostProperties } from "@zeus-js/web-c-runtime";`,
183
279
  `import { ${component.exportName} } from ${JSON.stringify(source)};`,
184
280
  "",
185
281
  `export function createComponent(hostRef) {`,
282
+ ` resolveHostProperties(hostRef, getElementDefinition(${component.exportName}).propDefs);`,
186
283
  ` const mountState = {`,
187
284
  ` attributeProps: hostRef.attributeProps,`,
188
285
  ` internals: hostRef.internals,`,
189
286
  ` reflectingAttrs: hostRef.reflectingAttrs,`,
287
+ ` exposedMethods: hostRef.exposedMethods,`,
190
288
  ` };`,
191
289
  ` const lifecycle = createCustomElementMountLifecycle(() =>`,
192
290
  ` mountElementDefinition(`,
@@ -206,8 +304,8 @@ function generateLazyEntry(options) {
206
304
  ` lifecycle.disconnect();`,
207
305
  ` },`,
208
306
  "",
209
- ` propertyChanged(name, oldValue, newValue) {`,
210
- ` lifecycle.current()?.propertyChanged(name, oldValue, newValue);`,
307
+ ` propertyChanged(change) {`,
308
+ ` lifecycle.current()?.propertyChanged(change);`,
211
309
  ` },`,
212
310
  "",
213
311
  ` formAssociated(form) {`,
@@ -241,6 +339,60 @@ function toRelativeImport(source, outPath) {
241
339
  return [...outParts.slice(common).map(() => ".."), ...sourceParts.slice(common)].join("/");
242
340
  }
243
341
  //#endregion
342
+ //#region packages/web-c/output-wc/src/generateLoader.ts
343
+ function generateLoader() {
344
+ return `import { bootstrapLazy } from "@zeus-js/web-c-runtime";
345
+ import { components } from "./components.manifest.js";
346
+
347
+ const componentsByTagName = new Map(
348
+ components.map(component => [component.tagName, component]),
349
+ );
350
+
351
+ function resolveRegistry(options) {
352
+ return options.registry ??
353
+ (typeof customElements === "undefined" ? undefined : customElements);
354
+ }
355
+
356
+ export function defineCustomElement(tagName, options = {}) {
357
+ const registry = resolveRegistry(options);
358
+
359
+ if (!registry) {
360
+ return;
361
+ }
362
+
363
+ const component = componentsByTagName.get(tagName);
364
+
365
+ if (!component) {
366
+ throw new Error(\`[zeus:web-c] Unknown custom element: <\${tagName}>.\`);
367
+ }
368
+
369
+ bootstrapLazy([component], { registry });
370
+ }
371
+
372
+ export function defineCustomElements(options = {}) {
373
+ for (const component of components) {
374
+ defineCustomElement(component.tagName, options);
375
+ }
376
+ }
377
+
378
+ `;
379
+ }
380
+ function generateAutoEntry() {
381
+ return `import { defineCustomElements } from "./loader.js";
382
+
383
+ defineCustomElements();
384
+
385
+ export {};
386
+ `;
387
+ }
388
+ function generateLazyIndex() {
389
+ return `export {
390
+ defineCustomElement,
391
+ defineCustomElements,
392
+ } from "./loader.js";
393
+ `;
394
+ }
395
+ //#endregion
244
396
  //#region packages/web-c/output-wc/src/generateLazyManifest.ts
245
397
  function generateLazyManifest(options) {
246
398
  const { components, getEntryFileName } = options;
@@ -276,12 +428,28 @@ function generatePropsArray(props) {
276
428
  if (attrName !== toKebabCase(name)) parts.push(`attrName: ${JSON.stringify(attrName)}`);
277
429
  }
278
430
  parts.push(`type: ${JSON.stringify(prop.type)}`);
431
+ if (isJsonSafeDefault(prop.default)) {
432
+ const encoded = JSON.stringify(prop.default);
433
+ parts.push(`default: ${typeof prop.default === "object" && prop.default !== null ? `JSON.parse(${JSON.stringify(encoded)})` : encoded}`);
434
+ }
279
435
  if (prop.reflect && (isAttributeBackedType(prop.type) || Boolean(prop.serialize))) parts.push("reflect: true");
280
436
  if (prop.serialize) parts.push("serialize: true");
281
437
  if (prop.deserialize) parts.push("deserialize: true");
282
438
  return ` { ${parts.join(", ")} }`;
283
439
  }).join(",\n")}\n ]`;
284
440
  }
441
+ function isJsonSafeDefault(value, parents = /* @__PURE__ */ new Set()) {
442
+ if (value === null || typeof value === "string" || typeof value === "boolean") return true;
443
+ if (typeof value === "number") return Number.isFinite(value) && !Object.is(value, -0);
444
+ if (typeof value !== "object" || parents.has(value)) return false;
445
+ if (!Array.isArray(value) && Object.getPrototypeOf(value) !== Object.prototype) return false;
446
+ if (Object.getOwnPropertySymbols(value).length) return false;
447
+ parents.add(value);
448
+ const descriptors = Object.getOwnPropertyDescriptors(value);
449
+ const valid = Array.isArray(value) ? Array.from({ length: value.length }, (_, index) => descriptors[index]).every((descriptor) => descriptor && "value" in descriptor && isJsonSafeDefault(descriptor.value, parents)) : Object.values(descriptors).every((descriptor) => "value" in descriptor && isJsonSafeDefault(descriptor.value, parents));
450
+ parents.delete(value);
451
+ return valid;
452
+ }
285
453
  function isAttributeBackedType(type) {
286
454
  return type === "string" || type === "number" || type === "boolean";
287
455
  }
@@ -289,92 +457,134 @@ function toKebabCase(value) {
289
457
  return value.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
290
458
  }
291
459
  //#endregion
292
- //#region packages/web-c/output-wc/src/generateLoader.ts
293
- function generateLoader() {
460
+ //#region packages/web-c/output-wc/src/generateRegistration.ts
461
+ function generateLazyRegistration(component, entryFileName) {
294
462
  return `import { bootstrapLazy } from "@zeus-js/web-c-runtime";
295
- import { components } from "./components.manifest.js";
296
-
297
- const componentsByTagName = new Map(
298
- components.map(component => [component.tagName, component]),
299
- );
300
-
301
- const definedTagsByRegistry = new WeakMap();
463
+ ${generateLazyManifest({
464
+ components: [component],
465
+ getEntryFileName: () => entryFileName
466
+ })}
467
+ export const component = components[0];
302
468
 
303
- function resolveRegistry(options) {
304
- return options.registry ??
305
- (typeof customElements === "undefined" ? undefined : customElements);
469
+ export function defineCustomElement(options = {}) {
470
+ bootstrapLazy([component], options);
306
471
  }
307
-
308
- function getDefinedTags(registry) {
309
- let definedTags = definedTagsByRegistry.get(registry);
310
-
311
- if (!definedTags) {
312
- definedTags = new Set();
313
- definedTagsByRegistry.set(registry, definedTags);
314
- }
315
-
316
- return definedTags;
472
+ `;
317
473
  }
318
-
319
- export function defineCustomElement(tagName, options = {}) {
320
- const registry = resolveRegistry(options);
321
-
322
- if (!registry) {
323
- return;
324
- }
325
-
326
- const component = componentsByTagName.get(tagName);
327
-
328
- if (!component) {
329
- throw new Error(\`[zeus:web-c] Unknown custom element: <\${tagName}>.\`);
330
- }
331
-
332
- const definedTags = getDefinedTags(registry);
333
-
334
- if (definedTags.has(tagName) || registry.get(tagName)) {
335
- definedTags.add(tagName);
336
- return;
337
- }
338
-
339
- bootstrapLazy([component], { registry });
340
-
341
- definedTags.add(tagName);
474
+ //#endregion
475
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/typeof.js
476
+ function _typeof(o) {
477
+ "@babel/helpers - typeof";
478
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
479
+ return typeof o;
480
+ } : function(o) {
481
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
482
+ }, _typeof(o);
342
483
  }
343
-
344
- export function defineCustomElements(options = {}) {
345
- for (const component of components) {
346
- defineCustomElement(component.tagName, options);
347
- }
484
+ //#endregion
485
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPrimitive.js
486
+ function toPrimitive(t, r) {
487
+ if ("object" != _typeof(t) || !t) return t;
488
+ var e = t[Symbol.toPrimitive];
489
+ if (void 0 !== e) {
490
+ var i = e.call(t, r || "default");
491
+ if ("object" != _typeof(i)) return i;
492
+ throw new TypeError("@@toPrimitive must return a primitive value.");
493
+ }
494
+ return ("string" === r ? String : Number)(t);
348
495
  }
349
-
350
- export const defineLazyElement = defineCustomElement;
351
- export const defineLazyElements = defineCustomElements;
352
- `;
496
+ //#endregion
497
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPropertyKey.js
498
+ function toPropertyKey(t) {
499
+ var i = toPrimitive(t, "string");
500
+ return "symbol" == _typeof(i) ? i : i + "";
353
501
  }
354
- function generateAutoEntry() {
355
- return `import { defineCustomElements } from "./loader.js";
356
-
357
- defineCustomElements();
358
-
359
- export {};
360
- `;
502
+ //#endregion
503
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/defineProperty.js
504
+ function _defineProperty(e, r, t) {
505
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
506
+ value: t,
507
+ enumerable: !0,
508
+ configurable: !0,
509
+ writable: !0
510
+ }) : e[r] = t, e;
361
511
  }
362
- function generateLazyIndex() {
363
- return `export {
364
- defineCustomElement,
365
- defineCustomElements,
366
- defineLazyElement,
367
- defineLazyElements,
368
- } from "./loader.js";
369
- `;
512
+ //#endregion
513
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/objectSpread2.js
514
+ function ownKeys(e, r) {
515
+ var t = Object.keys(e);
516
+ if (Object.getOwnPropertySymbols) {
517
+ var o = Object.getOwnPropertySymbols(e);
518
+ r && (o = o.filter(function(r) {
519
+ return Object.getOwnPropertyDescriptor(e, r).enumerable;
520
+ })), t.push.apply(t, o);
521
+ }
522
+ return t;
523
+ }
524
+ function _objectSpread2(e) {
525
+ for (var r = 1; r < arguments.length; r++) {
526
+ var t = null != arguments[r] ? arguments[r] : {};
527
+ r % 2 ? ownKeys(Object(t), !0).forEach(function(r) {
528
+ _defineProperty(e, r, t[r]);
529
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r) {
530
+ Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
531
+ });
532
+ }
533
+ return e;
370
534
  }
371
535
  //#endregion
372
- //#region packages/web-c/output-wc/src/generateManifest.ts
373
- function generateZeusComponentsManifest(manifest) {
374
- return `${JSON.stringify(manifest, null, 2)}\n`;
536
+ //#region packages/web-c/output-wc/src/generateVSCodeCustomData.ts
537
+ function generateVSCodeCustomData(customElementsJson) {
538
+ let manifest;
539
+ try {
540
+ manifest = JSON.parse(customElementsJson);
541
+ } catch (_unused) {
542
+ throw new Error("[ZEUS_VSCODE_CUSTOM_DATA_INVALID] CEM input is not valid JSON.");
543
+ }
544
+ if ((manifest === null || manifest === void 0 ? void 0 : manifest.schemaVersion) !== "1.0.0" || !Array.isArray(manifest.modules)) throw new Error("[ZEUS_VSCODE_CUSTOM_DATA_INVALID] CEM input must use schemaVersion 1.0.0 and contain modules.");
545
+ const tags = manifest.modules.flatMap((module) => {
546
+ var _module$declarations;
547
+ return ((_module$declarations = module.declarations) !== null && _module$declarations !== void 0 ? _module$declarations : []).filter((declaration) => declaration.kind === "class" && declaration.customElement === true && typeof declaration.tagName === "string").map((declaration) => {
548
+ var _declaration$attribut;
549
+ const tagName = declaration.tagName;
550
+ const attributes = ((_declaration$attribut = declaration.attributes) !== null && _declaration$attribut !== void 0 ? _declaration$attribut : []).map((attribute) => {
551
+ var _attribute$type;
552
+ if (typeof attribute.name !== "string") throw new Error(`[ZEUS_VSCODE_CUSTOM_DATA_INVALID] <${tagName}> contains an attribute without a name.`);
553
+ const values = parseStringLiteralUnion((_attribute$type = attribute.type) === null || _attribute$type === void 0 ? void 0 : _attribute$type.text);
554
+ return _objectSpread2(_objectSpread2({ name: attribute.name }, attribute.description ? { description: attribute.description } : {}), values ? { values: values.map((name) => ({ name })) } : {});
555
+ });
556
+ return _objectSpread2(_objectSpread2({ name: tagName }, declaration.description ? { description: declaration.description } : {}), attributes.length > 0 ? { attributes } : {});
557
+ });
558
+ });
559
+ const names = /* @__PURE__ */ new Set();
560
+ for (const tag of tags) {
561
+ if (names.has(tag.name)) throw new Error(`[ZEUS_VSCODE_CUSTOM_DATA_INVALID] CEM declares <${tag.name}> more than once.`);
562
+ names.add(tag.name);
563
+ }
564
+ return `${JSON.stringify({
565
+ version: 1.1,
566
+ tags
567
+ }, null, 2)}\n`;
568
+ }
569
+ function parseStringLiteralUnion(typeText) {
570
+ if (!typeText) return void 0;
571
+ const parts = typeText.split(/\s+\|\s+/);
572
+ const values = [];
573
+ for (const part of parts) {
574
+ if (!part.startsWith("\"") || !part.endsWith("\"")) return void 0;
575
+ try {
576
+ const value = JSON.parse(part);
577
+ if (typeof value !== "string") return void 0;
578
+ values.push(value);
579
+ } catch (_unused2) {
580
+ return;
581
+ }
582
+ }
583
+ return values.length > 0 ? values : void 0;
375
584
  }
376
585
  //#endregion
377
586
  //#region packages/web-c/output-wc/src/index.ts
587
+ const outputWcModulePath = fileURLToPath(import.meta.url);
378
588
  function wc(options = {}) {
379
589
  var _options$register, _options$outDir, _options$stripPrefix, _options$manifestFile, _options$customElemen, _options$dts, _options$jsxDts, _options$index, _options$warnOnFileNa, _options$auto, _options$entryFileNam;
380
590
  const registerMode = (_options$register = options.register) !== null && _options$register !== void 0 ? _options$register : "lazy";
@@ -449,15 +659,13 @@ function wc(options = {}) {
449
659
  modules.push({
450
660
  id: "zeus:wc:components.manifest",
451
661
  fileName: joinPath("components.manifest.js"),
452
- code: generateLazyManifest({
453
- components: ctx.manifest.components,
454
- getEntryFileName: (tag) => getLazyEntryFileName(normalized.entryFileName, tag)
455
- })
662
+ code: [...ctx.manifest.components.map((component, index) => `import { component as c${index} } from ${JSON.stringify(getVirtualComponentId(component))};`), `export const components = [${ctx.manifest.components.map((_, index) => `c${index}`).join(", ")}];`].join("\n")
456
663
  });
457
664
  modules.push({
458
665
  id: "zeus:wc:loader",
459
666
  fileName: joinPath("loader.js"),
460
- code: generateLoader()
667
+ code: generateLoader(),
668
+ resolveFrom: outputWcModulePath
461
669
  });
462
670
  if (normalized.auto) modules.push({
463
671
  id: "zeus:wc:auto",
@@ -474,13 +682,9 @@ function wc(options = {}) {
474
682
  */
475
683
  modules.push({
476
684
  id: getVirtualComponentId(component),
477
- code: `
478
- import { defineCustomElements } from "zeus:wc:loader";
479
-
480
- defineCustomElements();
481
-
482
- export {};
483
- `.trimStart()
685
+ fileName: joinPath(getFileName(component.tag)),
686
+ code: generateLazyRegistration(component, path.posix.relative(path.posix.dirname(joinPath(getFileName(component.tag))), joinPath(getLazyEntryFileName(normalized.entryFileName, component.tag)))),
687
+ resolveFrom: outputWcModulePath
484
688
  });
485
689
  const fileName = joinPath(getLazyEntryFileName(normalized.entryFileName, component.tag));
486
690
  modules.push({
@@ -490,7 +694,8 @@ export {};
490
694
  component,
491
695
  outPath: fileName,
492
696
  sourceImport: toAbsoluteImportPath(ctx.root, component.source)
493
- })
697
+ }),
698
+ resolveFrom: outputWcModulePath
494
699
  });
495
700
  } else {
496
701
  const fileName = joinPath(getFileName(component.tag));
@@ -541,6 +746,11 @@ export {};
541
746
  fileName: joinPath("loader.d.ts"),
542
747
  source: loaderDts
543
748
  });
749
+ for (const component of ctx.manifest.components) files.push({
750
+ type: "asset",
751
+ fileName: joinPath(getFileName(component.tag).replace(/\.js$/, ".d.ts")),
752
+ source: "export declare function defineCustomElement(options?: { registry?: CustomElementRegistry }): void\n"
753
+ });
544
754
  if (normalized.index) files.push({
545
755
  type: "asset",
546
756
  fileName: joinPath("index.d.ts"),
@@ -558,14 +768,22 @@ export {};
558
768
  fileName: normalized.manifestFile,
559
769
  source: generateZeusComponentsManifest(ctx.manifest)
560
770
  });
561
- if (normalized.customElementsFile) files.push({
562
- type: "asset",
563
- fileName: normalized.customElementsFile,
564
- source: generateCustomElementsJson({
771
+ if (normalized.customElementsFile) {
772
+ const customElementsJson = generateCustomElementsJson({
565
773
  manifest: ctx.manifest,
566
774
  getModulePath: (component) => isLazy ? joinPath(getLazyEntryFileName(normalized.entryFileName, component.tag)) : joinPath(getFileName(component.tag))
567
- })
568
- });
775
+ });
776
+ files.push({
777
+ type: "asset",
778
+ fileName: normalized.customElementsFile,
779
+ source: customElementsJson
780
+ });
781
+ files.push({
782
+ type: "asset",
783
+ fileName: "vscode.html-custom-data.json",
784
+ source: generateVSCodeCustomData(customElementsJson)
785
+ });
786
+ }
569
787
  if (!isLazy && (dts || jsxDts)) {
570
788
  const dtsFiles = generateWCDtsFiles(ctx.manifest, {
571
789
  outDir: _outDir,