@zeus-js/output-wc 0.1.0-beta.2 → 0.1.0-beta.4
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/capabilities.cjs.js +2 -2
- package/dist/capabilities.cjs.prod.js +2 -2
- package/dist/capabilities.js +1 -1
- package/dist/capabilities.prod.js +1 -1
- package/dist/output-wc.cjs.js +317 -23
- package/dist/output-wc.cjs.prod.js +317 -23
- package/dist/output-wc.d.ts +26 -2
- package/dist/output-wc.esm-bundler.js +318 -24
- package/package.json +13 -11
package/dist/capabilities.cjs.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* output-wc v0.1.0-beta.
|
|
2
|
+
* output-wc v0.1.0-beta.4
|
|
3
3
|
* (c) 2026 baicie
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
**/
|
|
@@ -9,7 +9,7 @@ Object.defineProperties(exports, {
|
|
|
9
9
|
});
|
|
10
10
|
const ZEUS_OUTPUT_WC_CAPABILITIES = {
|
|
11
11
|
packageName: "@zeus-js/output-wc",
|
|
12
|
-
version: "0.1.0-beta.
|
|
12
|
+
version: "0.1.0-beta.4",
|
|
13
13
|
output: {
|
|
14
14
|
webComponent: true,
|
|
15
15
|
customElements: true,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* output-wc v0.1.0-beta.
|
|
2
|
+
* output-wc v0.1.0-beta.4
|
|
3
3
|
* (c) 2026 baicie
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
**/
|
|
@@ -9,7 +9,7 @@ Object.defineProperties(exports, {
|
|
|
9
9
|
});
|
|
10
10
|
const ZEUS_OUTPUT_WC_CAPABILITIES = {
|
|
11
11
|
packageName: "@zeus-js/output-wc",
|
|
12
|
-
version: "0.1.0-beta.
|
|
12
|
+
version: "0.1.0-beta.4",
|
|
13
13
|
output: {
|
|
14
14
|
webComponent: true,
|
|
15
15
|
customElements: true,
|
package/dist/capabilities.js
CHANGED
package/dist/output-wc.cjs.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* output-wc v0.1.0-beta.
|
|
2
|
+
* output-wc v0.1.0-beta.4
|
|
3
3
|
* (c) 2026 baicie
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
**/
|
|
@@ -54,7 +54,10 @@ function generateCustomElementsJson(options) {
|
|
|
54
54
|
events: generateEvents(component),
|
|
55
55
|
slots: generateSlots(component),
|
|
56
56
|
cssParts: component.cssParts.map((name) => ({ name })),
|
|
57
|
-
cssProperties: component.
|
|
57
|
+
cssProperties: getCssVars(component).map((variable) => ({
|
|
58
|
+
name: variable.name,
|
|
59
|
+
description: variable.description
|
|
60
|
+
}))
|
|
58
61
|
}],
|
|
59
62
|
exports: [{
|
|
60
63
|
kind: "js",
|
|
@@ -84,7 +87,8 @@ function generateAttributes(component) {
|
|
|
84
87
|
return result;
|
|
85
88
|
}
|
|
86
89
|
function generateMembers(component) {
|
|
87
|
-
|
|
90
|
+
var _component$methods;
|
|
91
|
+
const fields = Object.entries(component.props).map(([name, prop]) => {
|
|
88
92
|
return {
|
|
89
93
|
kind: "field",
|
|
90
94
|
name,
|
|
@@ -93,18 +97,28 @@ function generateMembers(component) {
|
|
|
93
97
|
default: prop.default === void 0 ? void 0 : JSON.stringify(prop.default)
|
|
94
98
|
};
|
|
95
99
|
});
|
|
100
|
+
const methods = Object.keys((_component$methods = component.methods) !== null && _component$methods !== void 0 ? _component$methods : {}).map((name) => {
|
|
101
|
+
return {
|
|
102
|
+
kind: "method",
|
|
103
|
+
name
|
|
104
|
+
};
|
|
105
|
+
});
|
|
106
|
+
return [...fields, ...methods];
|
|
96
107
|
}
|
|
97
108
|
function generateEvents(component) {
|
|
98
|
-
return Object.entries(component.events).map(([
|
|
109
|
+
return Object.entries(component.events).map(([key, event]) => {
|
|
110
|
+
var _event$name, _event$key;
|
|
99
111
|
return {
|
|
100
|
-
name,
|
|
112
|
+
name: (_event$name = event.name) !== null && _event$name !== void 0 ? _event$name : toKebabCase$1((_event$key = event.key) !== null && _event$key !== void 0 ? _event$key : key),
|
|
101
113
|
description: event.description,
|
|
102
114
|
type: { text: event.detail ? `CustomEvent<${formatDetailType(event.detail)}>` : "CustomEvent" }
|
|
103
115
|
};
|
|
104
116
|
});
|
|
105
117
|
}
|
|
106
118
|
function generateSlots(component) {
|
|
107
|
-
return Object.entries(component.slots).map(([
|
|
119
|
+
return Object.entries(component.slots).map(([key, slot]) => {
|
|
120
|
+
var _slot$name;
|
|
121
|
+
const name = (_slot$name = slot.name) !== null && _slot$name !== void 0 ? _slot$name : key;
|
|
108
122
|
return {
|
|
109
123
|
name: name === "default" ? "" : name,
|
|
110
124
|
description: slot.description
|
|
@@ -114,6 +128,7 @@ function generateSlots(component) {
|
|
|
114
128
|
function getAttributeName(propName, prop) {
|
|
115
129
|
if (prop.attr === false) return false;
|
|
116
130
|
if (typeof prop.attr === "string") return prop.attr;
|
|
131
|
+
if (!isAttributeBackedType$1(prop.type)) return false;
|
|
117
132
|
return propName.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
|
|
118
133
|
}
|
|
119
134
|
function formatPropType(prop) {
|
|
@@ -125,15 +140,25 @@ function formatPropType(prop) {
|
|
|
125
140
|
case "boolean": return "boolean";
|
|
126
141
|
case "array": return "unknown[]";
|
|
127
142
|
case "object": return "Record<string, unknown>";
|
|
143
|
+
case "function": return "Function";
|
|
128
144
|
default: return "unknown";
|
|
129
145
|
}
|
|
130
146
|
}
|
|
147
|
+
function isAttributeBackedType$1(type) {
|
|
148
|
+
return type === "string" || type === "number" || type === "boolean";
|
|
149
|
+
}
|
|
131
150
|
function formatDetailType(detail) {
|
|
132
151
|
return `{ ${Object.entries(detail).map(([name, type]) => `${name}: ${type}`).join("; ")} }`;
|
|
133
152
|
}
|
|
134
153
|
function normalizeModulePath(value) {
|
|
135
154
|
return value.replace(/\\/g, "/");
|
|
136
155
|
}
|
|
156
|
+
function getCssVars(component) {
|
|
157
|
+
return Object.values(component.cssVars);
|
|
158
|
+
}
|
|
159
|
+
function toKebabCase$1(value) {
|
|
160
|
+
return value.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
|
|
161
|
+
}
|
|
137
162
|
//#endregion
|
|
138
163
|
//#region packages/web-c/output-wc/src/imports.ts
|
|
139
164
|
function toAbsoluteImportPath(root, source) {
|
|
@@ -176,6 +201,162 @@ function getVirtualIndexId() {
|
|
|
176
201
|
return "zeus:wc:index";
|
|
177
202
|
}
|
|
178
203
|
//#endregion
|
|
204
|
+
//#region packages/web-c/output-wc/src/generateLazyEntry.ts
|
|
205
|
+
function generateLazyEntry(options) {
|
|
206
|
+
const { component, outPath, sourceImport } = options;
|
|
207
|
+
const source = sourceImport !== null && sourceImport !== void 0 ? sourceImport : toRelativeImport(component.source, outPath);
|
|
208
|
+
return [
|
|
209
|
+
`import { mountElementDefinition } from "@zeus-js/runtime-dom";`,
|
|
210
|
+
`import { ${component.exportName} } from ${JSON.stringify(source)};`,
|
|
211
|
+
"",
|
|
212
|
+
`export function createComponent(hostRef) {`,
|
|
213
|
+
` let mounted;`,
|
|
214
|
+
` const mountState = {`,
|
|
215
|
+
` attributeProps: hostRef.attributeProps,`,
|
|
216
|
+
` internals: hostRef.internals,`,
|
|
217
|
+
` reflectingAttrs: hostRef.reflectingAttrs,`,
|
|
218
|
+
` };`,
|
|
219
|
+
"",
|
|
220
|
+
` return {`,
|
|
221
|
+
` connected() {`,
|
|
222
|
+
` if (mounted) return;`,
|
|
223
|
+
"",
|
|
224
|
+
` mounted = mountElementDefinition(`,
|
|
225
|
+
` ${component.exportName},`,
|
|
226
|
+
` hostRef.host,`,
|
|
227
|
+
` hostRef.values,`,
|
|
228
|
+
` mountState,`,
|
|
229
|
+
` );`,
|
|
230
|
+
` },`,
|
|
231
|
+
"",
|
|
232
|
+
` disconnected() {`,
|
|
233
|
+
` mounted?.dispose();`,
|
|
234
|
+
` mounted = undefined;`,
|
|
235
|
+
` },`,
|
|
236
|
+
"",
|
|
237
|
+
` propertyChanged(name, oldValue, newValue) {`,
|
|
238
|
+
` mounted?.propertyChanged(name, oldValue, newValue);`,
|
|
239
|
+
` },`,
|
|
240
|
+
"",
|
|
241
|
+
` formAssociated(form) {`,
|
|
242
|
+
` mounted?.formAssociated(form);`,
|
|
243
|
+
` },`,
|
|
244
|
+
"",
|
|
245
|
+
` formDisabled(disabled) {`,
|
|
246
|
+
` mounted?.formDisabled(disabled);`,
|
|
247
|
+
` },`,
|
|
248
|
+
"",
|
|
249
|
+
` formReset() {`,
|
|
250
|
+
` mounted?.formReset();`,
|
|
251
|
+
` },`,
|
|
252
|
+
"",
|
|
253
|
+
` formStateRestore(state, mode) {`,
|
|
254
|
+
` mounted?.formStateRestore(state, mode);`,
|
|
255
|
+
` },`,
|
|
256
|
+
` };`,
|
|
257
|
+
`}`,
|
|
258
|
+
"",
|
|
259
|
+
`export default { createComponent };`,
|
|
260
|
+
""
|
|
261
|
+
].join("\n");
|
|
262
|
+
}
|
|
263
|
+
function toRelativeImport(source, outPath) {
|
|
264
|
+
const sourceParts = normalizePath(source).split("/");
|
|
265
|
+
const outParts = normalizePath(outPath).split("/");
|
|
266
|
+
let common = 0;
|
|
267
|
+
for (let i = 0; i < Math.min(sourceParts.length, outParts.length); i++) if (sourceParts[i] === outParts[i]) common++;
|
|
268
|
+
else break;
|
|
269
|
+
return [...outParts.slice(common).map(() => ".."), ...sourceParts.slice(common)].join("/");
|
|
270
|
+
}
|
|
271
|
+
//#endregion
|
|
272
|
+
//#region packages/web-c/output-wc/src/generateLazyManifest.ts
|
|
273
|
+
function generateLazyManifest(options) {
|
|
274
|
+
const { components, getEntryFileName } = options;
|
|
275
|
+
return `export const components = [
|
|
276
|
+
${components.map((component) => {
|
|
277
|
+
var _component$runtimePro, _component$methods, _component$meta$shado, _component$meta, _component$meta$formA, _component$meta2;
|
|
278
|
+
const entryFile = getEntryFileName(component.tag).replace(/\\/g, "/");
|
|
279
|
+
const props = generatePropsArray((_component$runtimePro = component.runtimeProps) !== null && _component$runtimePro !== void 0 ? _component$runtimePro : component.props);
|
|
280
|
+
const methods = Object.keys((_component$methods = component.methods) !== null && _component$methods !== void 0 ? _component$methods : {});
|
|
281
|
+
const importPath = entryFile.startsWith(".") ? JSON.stringify(entryFile) : JSON.stringify(`./${entryFile}`);
|
|
282
|
+
const methodLine = methods.length ? ` methods: ${JSON.stringify(methods)},\n` : "";
|
|
283
|
+
return ` {
|
|
284
|
+
tagName: ${JSON.stringify(component.tag)},
|
|
285
|
+
shadow: ${(_component$meta$shado = (_component$meta = component.meta) === null || _component$meta === void 0 ? void 0 : _component$meta.shadow) !== null && _component$meta$shado !== void 0 ? _component$meta$shado : false},
|
|
286
|
+
formAssociated: ${(_component$meta$formA = (_component$meta2 = component.meta) === null || _component$meta2 === void 0 ? void 0 : _component$meta2.formAssociated) !== null && _component$meta$formA !== void 0 ? _component$meta$formA : false},
|
|
287
|
+
load: () => import(${importPath}),
|
|
288
|
+
props: ${props},
|
|
289
|
+
${methodLine}
|
|
290
|
+
}`;
|
|
291
|
+
}).join(",\n")}
|
|
292
|
+
];
|
|
293
|
+
`;
|
|
294
|
+
}
|
|
295
|
+
function generatePropsArray(props) {
|
|
296
|
+
const entries = Object.entries(props);
|
|
297
|
+
if (entries.length === 0) return "[]";
|
|
298
|
+
return `[\n${entries.map(([name, prop]) => {
|
|
299
|
+
const parts = [`name: ${JSON.stringify(name)}`];
|
|
300
|
+
if (!isAttributeBackedType(prop.type) && !prop.deserialize || prop.attr === false) parts.push("attrName: false");
|
|
301
|
+
else {
|
|
302
|
+
var _prop$attr;
|
|
303
|
+
const attrName = (_prop$attr = prop.attr) !== null && _prop$attr !== void 0 ? _prop$attr : toKebabCase(name);
|
|
304
|
+
if (attrName !== toKebabCase(name)) parts.push(`attrName: ${JSON.stringify(attrName)}`);
|
|
305
|
+
}
|
|
306
|
+
parts.push(`type: ${JSON.stringify(prop.type)}`);
|
|
307
|
+
if (prop.reflect && (isAttributeBackedType(prop.type) || Boolean(prop.serialize))) parts.push("reflect: true");
|
|
308
|
+
if (prop.serialize) parts.push("serialize: true");
|
|
309
|
+
if (prop.deserialize) parts.push("deserialize: true");
|
|
310
|
+
return ` { ${parts.join(", ")} }`;
|
|
311
|
+
}).join(",\n")}\n ]`;
|
|
312
|
+
}
|
|
313
|
+
function isAttributeBackedType(type) {
|
|
314
|
+
return type === "string" || type === "number" || type === "boolean";
|
|
315
|
+
}
|
|
316
|
+
function toKebabCase(value) {
|
|
317
|
+
return value.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
|
|
318
|
+
}
|
|
319
|
+
//#endregion
|
|
320
|
+
//#region packages/web-c/output-wc/src/generateLoader.ts
|
|
321
|
+
function generateLoader() {
|
|
322
|
+
return `import { bootstrapLazy } from "@zeus-js/web-c-runtime";
|
|
323
|
+
import { components } from "./components.manifest.js";
|
|
324
|
+
|
|
325
|
+
let defined = false;
|
|
326
|
+
|
|
327
|
+
export function defineCustomElements() {
|
|
328
|
+
if (defined) {
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
if (typeof customElements === "undefined") {
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
bootstrapLazy(components);
|
|
337
|
+
|
|
338
|
+
defined = true;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
export const defineLazyElements = defineCustomElements;
|
|
342
|
+
`;
|
|
343
|
+
}
|
|
344
|
+
function generateAutoEntry() {
|
|
345
|
+
return `import { defineCustomElements } from "./loader.js";
|
|
346
|
+
|
|
347
|
+
defineCustomElements();
|
|
348
|
+
|
|
349
|
+
export {};
|
|
350
|
+
`;
|
|
351
|
+
}
|
|
352
|
+
function generateLazyIndex() {
|
|
353
|
+
return `export {
|
|
354
|
+
defineCustomElements,
|
|
355
|
+
defineLazyElements,
|
|
356
|
+
} from "./loader.js";
|
|
357
|
+
`;
|
|
358
|
+
}
|
|
359
|
+
//#endregion
|
|
179
360
|
//#region packages/web-c/output-wc/src/generateManifest.ts
|
|
180
361
|
function generateZeusComponentsManifest(manifest) {
|
|
181
362
|
return `${JSON.stringify(manifest, null, 2)}\n`;
|
|
@@ -183,17 +364,21 @@ function generateZeusComponentsManifest(manifest) {
|
|
|
183
364
|
//#endregion
|
|
184
365
|
//#region packages/web-c/output-wc/src/index.ts
|
|
185
366
|
function wc(options = {}) {
|
|
186
|
-
var _options$outDir, _options$stripPrefix, _options$manifestFile, _options$customElemen, _options$dts, _options$jsxDts, _options$index, _options$warnOnFileNa;
|
|
367
|
+
var _options$register, _options$outDir, _options$stripPrefix, _options$manifestFile, _options$customElemen, _options$dts, _options$jsxDts, _options$index, _options$warnOnFileNa, _options$auto, _options$entryFileNam;
|
|
368
|
+
const registerMode = (_options$register = options.register) !== null && _options$register !== void 0 ? _options$register : "lazy";
|
|
187
369
|
const normalized = {
|
|
188
370
|
outDir: (_options$outDir = options.outDir) !== null && _options$outDir !== void 0 ? _options$outDir : "wc",
|
|
189
371
|
stripPrefix: (_options$stripPrefix = options.stripPrefix) !== null && _options$stripPrefix !== void 0 ? _options$stripPrefix : false,
|
|
190
372
|
fileName: options.fileName,
|
|
191
373
|
manifestFile: (_options$manifestFile = options.manifestFile) !== null && _options$manifestFile !== void 0 ? _options$manifestFile : "zeus.components.json",
|
|
192
374
|
customElementsFile: (_options$customElemen = options.customElementsFile) !== null && _options$customElemen !== void 0 ? _options$customElemen : "custom-elements.json",
|
|
193
|
-
dts: (_options$dts = options.dts) !== null && _options$dts !== void 0 ? _options$dts :
|
|
194
|
-
jsxDts: (_options$jsxDts = options.jsxDts) !== null && _options$jsxDts !== void 0 ? _options$jsxDts :
|
|
375
|
+
dts: (_options$dts = options.dts) !== null && _options$dts !== void 0 ? _options$dts : true,
|
|
376
|
+
jsxDts: (_options$jsxDts = options.jsxDts) !== null && _options$jsxDts !== void 0 ? _options$jsxDts : true,
|
|
195
377
|
index: (_options$index = options.index) !== null && _options$index !== void 0 ? _options$index : true,
|
|
196
|
-
warnOnFileNameCollision: (_options$warnOnFileNa = options.warnOnFileNameCollision) !== null && _options$warnOnFileNa !== void 0 ? _options$warnOnFileNa : true
|
|
378
|
+
warnOnFileNameCollision: (_options$warnOnFileNa = options.warnOnFileNameCollision) !== null && _options$warnOnFileNa !== void 0 ? _options$warnOnFileNa : true,
|
|
379
|
+
register: registerMode,
|
|
380
|
+
auto: (_options$auto = options.auto) !== null && _options$auto !== void 0 ? _options$auto : true,
|
|
381
|
+
entryFileName: (_options$entryFileNam = options.entryFileName) !== null && _options$entryFileNam !== void 0 ? _options$entryFileNam : ((tag) => `${tag}.entry`)
|
|
197
382
|
};
|
|
198
383
|
let _outDir = normalized.outDir;
|
|
199
384
|
return {
|
|
@@ -208,7 +393,32 @@ function wc(options = {}) {
|
|
|
208
393
|
},
|
|
209
394
|
buildStart(ctx) {
|
|
210
395
|
if (!ctx.manifest) return;
|
|
211
|
-
|
|
396
|
+
if (normalized.register === "lazy") for (const component of ctx.manifest.components) {
|
|
397
|
+
var _component$runtimePro, _component$runtimePro2;
|
|
398
|
+
const diagnostics = (_component$runtimePro = component.runtimePropsDiagnostics) !== null && _component$runtimePro !== void 0 ? _component$runtimePro : [];
|
|
399
|
+
if (diagnostics.length > 0) ctx.error([`[zeus-output-wc] <${component.tag}> cannot be emitted with register:"lazy" because its runtime props are not statically analyzable.`, ...diagnostics.map((message) => `- ${message}`)].join("\n"));
|
|
400
|
+
const runtimeProps = (_component$runtimePro2 = component.runtimeProps) !== null && _component$runtimePro2 !== void 0 ? _component$runtimePro2 : {};
|
|
401
|
+
for (const [name, prop] of Object.entries(runtimeProps)) {
|
|
402
|
+
if (isAttributeBackedRuntimeProp(prop.type)) continue;
|
|
403
|
+
if (prop.attr !== void 0 && prop.attr !== false && !prop.deserialize) ctx.error([
|
|
404
|
+
`[zeus-output-wc] <${component.tag}> prop "${name}" cannot use attr:${JSON.stringify(prop.attr)} with register:"lazy".`,
|
|
405
|
+
"Non-primitive lazy attributes require a custom deserialize function.",
|
|
406
|
+
"Add deserialize or use attr:false and pass the value as a property."
|
|
407
|
+
].join("\n"));
|
|
408
|
+
if (prop.reflect && !prop.serialize) ctx.error([
|
|
409
|
+
`[zeus-output-wc] <${component.tag}> prop "${name}" cannot use reflect:true with register:"lazy".`,
|
|
410
|
+
"Non-primitive lazy reflection requires a custom serialize function.",
|
|
411
|
+
"Add serialize or remove reflect:true."
|
|
412
|
+
].join("\n"));
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
checkFileNameCollisions(ctx.manifest.components, {
|
|
416
|
+
getFileName: (tag) => {
|
|
417
|
+
if (normalized.register === "lazy") return getLazyEntryFileName(normalized.entryFileName, tag);
|
|
418
|
+
return normalizeFileName(tag, normalized.stripPrefix, normalized.fileName);
|
|
419
|
+
},
|
|
420
|
+
warnOnFileNameCollision: normalized.warnOnFileNameCollision
|
|
421
|
+
}, { warn: ctx.warn });
|
|
212
422
|
},
|
|
213
423
|
virtualModules(ctx) {
|
|
214
424
|
if (!ctx.manifest) return [];
|
|
@@ -222,7 +432,55 @@ function wc(options = {}) {
|
|
|
222
432
|
if (hasOutputs) return ctx.outputs.join("wc", fileName);
|
|
223
433
|
return node_path.default.posix.join(_outDir, fileName);
|
|
224
434
|
};
|
|
225
|
-
|
|
435
|
+
const isLazy = normalized.register === "lazy";
|
|
436
|
+
if (isLazy) {
|
|
437
|
+
modules.push({
|
|
438
|
+
id: "zeus:wc:components.manifest",
|
|
439
|
+
fileName: joinPath("components.manifest.js"),
|
|
440
|
+
code: generateLazyManifest({
|
|
441
|
+
components: ctx.manifest.components,
|
|
442
|
+
getEntryFileName: (tag) => getLazyEntryFileName(normalized.entryFileName, tag)
|
|
443
|
+
})
|
|
444
|
+
});
|
|
445
|
+
modules.push({
|
|
446
|
+
id: "zeus:wc:loader",
|
|
447
|
+
fileName: joinPath("loader.js"),
|
|
448
|
+
code: generateLoader()
|
|
449
|
+
});
|
|
450
|
+
if (normalized.auto) modules.push({
|
|
451
|
+
id: "zeus:wc:auto",
|
|
452
|
+
fileName: joinPath("auto.js"),
|
|
453
|
+
code: generateAutoEntry()
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
for (const component of ctx.manifest.components) if (isLazy) {
|
|
457
|
+
/**
|
|
458
|
+
* Registration bridge module consumed by Vue / React wrappers.
|
|
459
|
+
*
|
|
460
|
+
* It only registers lazy Proxy Elements.
|
|
461
|
+
* It does not import the real component implementation.
|
|
462
|
+
*/
|
|
463
|
+
modules.push({
|
|
464
|
+
id: getVirtualComponentId(component),
|
|
465
|
+
code: `
|
|
466
|
+
import { defineCustomElements } from "zeus:wc:loader";
|
|
467
|
+
|
|
468
|
+
defineCustomElements();
|
|
469
|
+
|
|
470
|
+
export {};
|
|
471
|
+
`.trimStart()
|
|
472
|
+
});
|
|
473
|
+
const fileName = joinPath(getLazyEntryFileName(normalized.entryFileName, component.tag));
|
|
474
|
+
modules.push({
|
|
475
|
+
id: `zeus:wc:entry:${component.tag}`,
|
|
476
|
+
fileName,
|
|
477
|
+
code: generateLazyEntry({
|
|
478
|
+
component,
|
|
479
|
+
outPath: fileName,
|
|
480
|
+
sourceImport: toAbsoluteImportPath(ctx.root, component.source)
|
|
481
|
+
})
|
|
482
|
+
});
|
|
483
|
+
} else {
|
|
226
484
|
const fileName = joinPath(getFileName(component.tag));
|
|
227
485
|
modules.push({
|
|
228
486
|
id: getVirtualComponentId(component),
|
|
@@ -233,7 +491,7 @@ function wc(options = {}) {
|
|
|
233
491
|
})
|
|
234
492
|
});
|
|
235
493
|
}
|
|
236
|
-
if (normalized.index) modules.push({
|
|
494
|
+
if (normalized.index && !isLazy) modules.push({
|
|
237
495
|
id: getVirtualIndexId(),
|
|
238
496
|
fileName: joinPath("index.js"),
|
|
239
497
|
code: generateWCIndex({
|
|
@@ -241,16 +499,18 @@ function wc(options = {}) {
|
|
|
241
499
|
getFileName
|
|
242
500
|
})
|
|
243
501
|
});
|
|
502
|
+
if (isLazy && normalized.index) modules.push({
|
|
503
|
+
id: getVirtualIndexId(),
|
|
504
|
+
fileName: joinPath("index.js"),
|
|
505
|
+
code: generateLazyIndex()
|
|
506
|
+
});
|
|
244
507
|
return modules;
|
|
245
508
|
},
|
|
246
509
|
generateBundle(ctx) {
|
|
247
510
|
if (!ctx.manifest) return [];
|
|
248
511
|
const files = [];
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
fileName: normalized.manifestFile,
|
|
252
|
-
source: generateZeusComponentsManifest(ctx.manifest)
|
|
253
|
-
});
|
|
512
|
+
const dts = (0, _zeus_js_bundler_plugin.resolvePluginDts)(normalized.dts, ctx);
|
|
513
|
+
const jsxDts = (0, _zeus_js_bundler_plugin.resolvePluginDts)(normalized.jsxDts, ctx);
|
|
254
514
|
const hasOutputs = ctx.outputs.has("wc");
|
|
255
515
|
const getFileName = (tag) => {
|
|
256
516
|
if (hasOutputs) return ctx.outputs.getFileName("wc", tag);
|
|
@@ -260,17 +520,41 @@ function wc(options = {}) {
|
|
|
260
520
|
if (hasOutputs) return ctx.outputs.join("wc", fileName);
|
|
261
521
|
return node_path.default.posix.join(_outDir, fileName);
|
|
262
522
|
};
|
|
523
|
+
const isLazy = normalized.register === "lazy";
|
|
524
|
+
if (isLazy) {
|
|
525
|
+
if (dts) {
|
|
526
|
+
const loaderDts = (0, _zeus_js_component_dts.generateLoaderDts)(ctx.manifest);
|
|
527
|
+
files.push({
|
|
528
|
+
type: "asset",
|
|
529
|
+
fileName: joinPath("loader.d.ts"),
|
|
530
|
+
source: loaderDts
|
|
531
|
+
});
|
|
532
|
+
if (normalized.index) files.push({
|
|
533
|
+
type: "asset",
|
|
534
|
+
fileName: joinPath("index.d.ts"),
|
|
535
|
+
source: loaderDts
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
if (jsxDts) files.push({
|
|
539
|
+
type: "asset",
|
|
540
|
+
fileName: joinPath("types/jsx.d.ts"),
|
|
541
|
+
source: (0, _zeus_js_component_dts.generateWCJsxDts)(ctx.manifest)
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
if (normalized.manifestFile) files.push({
|
|
545
|
+
type: "asset",
|
|
546
|
+
fileName: normalized.manifestFile,
|
|
547
|
+
source: generateZeusComponentsManifest(ctx.manifest)
|
|
548
|
+
});
|
|
263
549
|
if (normalized.customElementsFile) files.push({
|
|
264
550
|
type: "asset",
|
|
265
551
|
fileName: normalized.customElementsFile,
|
|
266
552
|
source: generateCustomElementsJson({
|
|
267
553
|
manifest: ctx.manifest,
|
|
268
|
-
getModulePath: (component) => joinPath(getFileName(component.tag))
|
|
554
|
+
getModulePath: (component) => isLazy ? joinPath(getLazyEntryFileName(normalized.entryFileName, component.tag)) : joinPath(getFileName(component.tag))
|
|
269
555
|
})
|
|
270
556
|
});
|
|
271
|
-
|
|
272
|
-
const jsxDts = (0, _zeus_js_bundler_plugin.resolvePluginDts)(normalized.jsxDts, ctx);
|
|
273
|
-
if (dts || jsxDts) {
|
|
557
|
+
if (!isLazy && (dts || jsxDts)) {
|
|
274
558
|
const dtsFiles = (0, _zeus_js_component_dts.generateWCDtsFiles)(ctx.manifest, {
|
|
275
559
|
outDir: _outDir,
|
|
276
560
|
stripPrefix: normalized.stripPrefix,
|
|
@@ -299,12 +583,22 @@ function normalizeFileName(tag, stripPrefix, fileName) {
|
|
|
299
583
|
if (!name.endsWith(".js")) name = `${name}.js`;
|
|
300
584
|
return name;
|
|
301
585
|
}
|
|
586
|
+
function normalizeLazyEntryFileName(fileName) {
|
|
587
|
+
const normalized = fileName.replace(/\\/g, "/");
|
|
588
|
+
return normalized.endsWith(".js") ? normalized : `${normalized}.js`;
|
|
589
|
+
}
|
|
590
|
+
function getLazyEntryFileName(entryFileName, tag) {
|
|
591
|
+
return normalizeLazyEntryFileName(entryFileName(tag));
|
|
592
|
+
}
|
|
593
|
+
function isAttributeBackedRuntimeProp(type) {
|
|
594
|
+
return type === "string" || type === "number" || type === "boolean";
|
|
595
|
+
}
|
|
302
596
|
function checkFileNameCollisions(components, options, reporter) {
|
|
303
597
|
if (options.warnOnFileNameCollision === false) return;
|
|
304
598
|
const map = /* @__PURE__ */ new Map();
|
|
305
599
|
for (const component of components) {
|
|
306
600
|
var _map$get;
|
|
307
|
-
const fileName =
|
|
601
|
+
const fileName = options.getFileName(component.tag);
|
|
308
602
|
const list = (_map$get = map.get(fileName)) !== null && _map$get !== void 0 ? _map$get : [];
|
|
309
603
|
list.push(component);
|
|
310
604
|
map.set(fileName, list);
|