@mono-lit/utility 0.0.0-stage → 0.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.
Files changed (54) hide show
  1. package/LICENSE.md +54 -0
  2. package/README.md +157 -3
  3. package/dist/app-roots-CvJnmXcs.js +128 -0
  4. package/dist/app-roots-DK41xMWj.d.ts +90 -0
  5. package/dist/config-node-UzJrXg0Z.js +76 -0
  6. package/dist/config-node.d.ts +923 -0
  7. package/dist/config-node.js +7 -0
  8. package/dist/config.d.ts +2 -0
  9. package/dist/config.js +3 -0
  10. package/dist/create-config-B8IhX4ht.d.ts +735 -0
  11. package/dist/create-config-DdL3Fh6T.js +357 -0
  12. package/dist/fetching.d.ts +244 -0
  13. package/dist/fetching.js +1015 -0
  14. package/dist/generate-CJ7MtcDd.js +291 -0
  15. package/dist/index-BAy6tbOG.d.ts +371 -0
  16. package/dist/index-DYlzhHq7.d.ts +514 -0
  17. package/dist/index.d.ts +25 -0
  18. package/dist/index.js +941 -0
  19. package/dist/merge-file-CLc3wxY4.d.ts +99 -0
  20. package/dist/merge-file-CtyKTu5L.js +133 -0
  21. package/dist/mock-db-4tTWrF-P.js +1282 -0
  22. package/dist/mock-db.d.ts +2 -0
  23. package/dist/mock-db.js +4 -0
  24. package/dist/mono-alias-DNDm-jB_.js +508 -0
  25. package/dist/mono-clone.mjs +958 -0
  26. package/dist/mono-db.d.ts +1 -0
  27. package/dist/mono-db.js +158 -0
  28. package/dist/mono-env.mjs +231 -0
  29. package/dist/mono-git.mjs +798 -0
  30. package/dist/mono-link-YlOQ2PVS.js +488 -0
  31. package/dist/mono-prepare.d.ts +1 -0
  32. package/dist/mono-prepare.js +28 -0
  33. package/dist/mono-skills.d.ts +1 -0
  34. package/dist/mono-skills.js +837 -0
  35. package/dist/mono-tsconfig-D2qRL9_R.js +204 -0
  36. package/dist/mono.mjs +34 -0
  37. package/dist/nuxt-layers-DP1m7f1-.js +176 -0
  38. package/dist/nuxt-layers.d.ts +36 -0
  39. package/dist/nuxt-layers.js +3 -0
  40. package/dist/nuxt-runtime.d.ts +17 -0
  41. package/dist/nuxt-runtime.js +102 -0
  42. package/dist/nuxt.d.ts +390 -0
  43. package/dist/nuxt.js +737 -0
  44. package/dist/runtime-vs7U9Ed4.js +6054 -0
  45. package/dist/runtime.d.ts +2518 -0
  46. package/dist/runtime.js +4 -0
  47. package/dist/session-Bcig-rPi.js +1721 -0
  48. package/dist/types-B6FdB7LJ.d.ts +57 -0
  49. package/dist/universal-BR0O7Qwk.d.ts +59 -0
  50. package/dist/universal-DIVEzCvN.js +600 -0
  51. package/dist/virtual-mono-apps.d.ts +16 -0
  52. package/dist/vite.d.ts +943 -0
  53. package/dist/vite.js +1132 -0
  54. package/package.json +141 -3
package/dist/index.js ADDED
@@ -0,0 +1,941 @@
1
+ import { n as mergeEcosystem, r as monoEcosystem } from "./merge-file-CtyKTu5L.js";
2
+ import fs from "node:fs";
3
+ import path, { resolve } from "node:path";
4
+ import fs$1 from "node:fs/promises";
5
+
6
+ //#region src/composables/vite-html-to-vue.ts
7
+ function normalizeScriptType(value) {
8
+ return value?.trim().toLowerCase() || void 0;
9
+ }
10
+ function normalizeScriptWarmupStrategy(value) {
11
+ const v = value?.trim().toLowerCase();
12
+ switch (v) {
13
+ case "preload":
14
+ case "prefetch":
15
+ case "preconnect":
16
+ case "dns-prefetch": return v;
17
+ case "false": return false;
18
+ default: return;
19
+ }
20
+ }
21
+ function stripJsComments(code) {
22
+ return code.replace(/\/\*[\s\S]*?\*\//g, "").replace(/^\s*\/\/.*$/gm, "");
23
+ }
24
+ function buildInlineHeadScriptKey(projectNameCamel, root, htmlAbs, index) {
25
+ return `${projectNameCamel}-${path.relative(root, htmlAbs).replace(/\\/g, "/").replace(/[^A-Za-z0-9]+/g, "-").replace(/^-+|-+$/g, "")}-inline-${index}`;
26
+ }
27
+ function normalizeExecutableBody(code) {
28
+ return stripJsComments(removeImports(code)).trim();
29
+ }
30
+ function escapeRegExp(value) {
31
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
32
+ }
33
+ function hasExecutableReference(code, ref) {
34
+ if (!code.trim() || !ref.trim()) return false;
35
+ return new RegExp(`(?<![A-Za-z0-9_$])${escapeRegExp(ref)}(?![A-Za-z0-9_$])`).test(code);
36
+ }
37
+ function isRemoteScriptActivelyUsed(item, executableBodies) {
38
+ if (!item.use) return false;
39
+ return uniq([item.use.expr, item.use.as].filter((v) => !!v)).some((ref) => executableBodies.some((body) => hasExecutableReference(body, ref)));
40
+ }
41
+ function splitImportClause(clause) {
42
+ const parts = [];
43
+ let current = "";
44
+ let depth = 0;
45
+ for (const ch of clause) {
46
+ if (ch === "{") depth++;
47
+ if (ch === "}") depth--;
48
+ if (ch === "," && depth === 0) {
49
+ if (current.trim()) parts.push(current.trim());
50
+ current = "";
51
+ continue;
52
+ }
53
+ current += ch;
54
+ }
55
+ if (current.trim()) parts.push(current.trim());
56
+ return parts;
57
+ }
58
+ function parseUseExpression(value) {
59
+ if (!value) return void 0;
60
+ const raw = value.trim();
61
+ if (!raw) return void 0;
62
+ const match = raw.match(/^(.*?)\s+as\s+([A-Za-z_$][A-Za-z0-9_$]*)$/);
63
+ if (match) {
64
+ const expr = match[1]?.trim();
65
+ const as = match[2]?.trim();
66
+ if (!expr) return void 0;
67
+ return {
68
+ expr,
69
+ as
70
+ };
71
+ }
72
+ return { expr: raw };
73
+ }
74
+ function renderUseScriptCall(item) {
75
+ if (!item.use) return `useScript(${toCode(item.input)})`;
76
+ return `useScript(${toCode(item.input)}, { use: () => ${item.use.expr} })`;
77
+ }
78
+ function extractImportBindings(clause) {
79
+ if (!clause) return [];
80
+ const out = [];
81
+ for (const part of splitImportClause(clause.trim())) {
82
+ const item = part.replace(/^type\s+/, "").trim();
83
+ if (!item) continue;
84
+ const nsMatch = item.match(/^\*\s+as\s+([A-Za-z_$][A-Za-z0-9_$]*)$/);
85
+ if (nsMatch) {
86
+ out.push(nsMatch[1]);
87
+ continue;
88
+ }
89
+ if (item.startsWith("{") && item.endsWith("}")) {
90
+ const inner = item.slice(1, -1).trim();
91
+ if (!inner) continue;
92
+ for (const raw of inner.split(",")) {
93
+ const named = raw.replace(/^type\s+/, "").trim();
94
+ if (!named) continue;
95
+ const asMatch = named.match(/^([A-Za-z_$][A-Za-z0-9_$]*)\s+as\s+([A-Za-z_$][A-Za-z0-9_$]*)$/);
96
+ if (asMatch) {
97
+ out.push(asMatch[2]);
98
+ continue;
99
+ }
100
+ const plainMatch = named.match(/^([A-Za-z_$][A-Za-z0-9_$]*)$/);
101
+ if (plainMatch) out.push(plainMatch[1]);
102
+ }
103
+ continue;
104
+ }
105
+ const defaultMatch = item.match(/^([A-Za-z_$][A-Za-z0-9_$]*)$/);
106
+ if (defaultMatch) out.push(defaultMatch[1]);
107
+ }
108
+ return uniq(out);
109
+ }
110
+ function renderWindowRunModule(globalFnName, injectedNames, body) {
111
+ return [
112
+ injectedNames.length ? `window.${globalFnName} = function ({ ${injectedNames.join(", ")} } = {}) {` : `window.${globalFnName} = function () {`,
113
+ indent(body.trim(), 2),
114
+ "}"
115
+ ].filter(Boolean).join("\n");
116
+ }
117
+ function buildGlobalRunnerName(projectNameCamel, scriptAbs) {
118
+ return `${projectNameCamel}Run${pascalCase(fileBaseStem(scriptAbs))}Fn`;
119
+ }
120
+ function fileStemFromAbs(root, abs) {
121
+ return path.relative(root, abs).replace(/\\/g, "/").replace(/\.[^.]+$/, "").split("/").filter(Boolean).join("-");
122
+ }
123
+ function normalizeVueJsOutPath(value) {
124
+ let next = value.replace(/\\/g, "/").trim();
125
+ next = next.replace(/^\.\/+/, "");
126
+ next = next.replace(/^\/+/, "");
127
+ if (!next.endsWith(".js")) next += ".js";
128
+ return next;
129
+ }
130
+ function normalizeCssOutPath(value) {
131
+ let next = value.replace(/\\/g, "/").trim();
132
+ next = next.replace(/^\.\/+/, "");
133
+ next = next.replace(/^\/+/, "");
134
+ if (!next.endsWith(".css")) next += ".css";
135
+ return next;
136
+ }
137
+ function normalizeOverridePath(value) {
138
+ if (!value) return void 0;
139
+ return value.replace(/\/+$/, "").trim();
140
+ }
141
+ function toGeneratedImportSpecifier(ctx, fromOutPath, toOutPath) {
142
+ const normalizedTo = toOutPath.replace(/\\/g, "/");
143
+ if (ctx.overridePath) return `${ctx.overridePath}/${normalizedTo}`;
144
+ return toVueRelativeImport(fromOutPath, normalizedTo);
145
+ }
146
+ function readProjectNameCamel(root) {
147
+ const pkgPath = findNearestPackageJson(root);
148
+ if (!pkgPath) return "app";
149
+ try {
150
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
151
+ return toCamelCase(String(pkg.name || path.basename(root)).split("/").pop() || "app");
152
+ } catch {
153
+ return "app";
154
+ }
155
+ }
156
+ function findNearestPackageJson(start) {
157
+ let dir = start;
158
+ while (true) {
159
+ const candidate = path.join(dir, "package.json");
160
+ if (fs.existsSync(candidate) && fs.statSync(candidate).isFile()) return candidate;
161
+ const parent = path.dirname(dir);
162
+ if (parent === dir) return null;
163
+ dir = parent;
164
+ }
165
+ }
166
+ function toCamelCase(value) {
167
+ const parts = value.replace(/^@/, "").split(/[\/\-_]+/).filter(Boolean);
168
+ if (!parts.length) return "app";
169
+ return parts.map((part, index) => index === 0 ? part.charAt(0).toLowerCase() + part.slice(1) : part.charAt(0).toUpperCase() + part.slice(1)).join("");
170
+ }
171
+ function htmlToVue(options) {
172
+ const ctx = {
173
+ root: process.cwd(),
174
+ componentRootAbs: "",
175
+ componentOutDir: "components",
176
+ overridePath: void 0,
177
+ projectNameCamel: "app",
178
+ pages: []
179
+ };
180
+ return {
181
+ name: "html-to-vue",
182
+ apply: "build",
183
+ configResolved(config) {
184
+ ctx.root = config.root;
185
+ ctx.componentRootAbs = resolveFromRoot(ctx.root, options.components?.path ?? "./components");
186
+ ctx.componentOutDir = normalizeDirPath(options.components?.outDir ?? "components");
187
+ ctx.overridePath = normalizeOverridePath(options.overridePath);
188
+ ctx.projectNameCamel = readProjectNameCamel(ctx.root);
189
+ ctx.pages = (options.pages?.list ?? []).map((page) => ({
190
+ htmlAbs: resolveFromRoot(ctx.root, page.html),
191
+ pagePath: normalizeVueOutPath(page.pagePath ?? defaultPagePath(page.html))
192
+ }));
193
+ },
194
+ async generateBundle() {
195
+ const emitted = /* @__PURE__ */ new Map();
196
+ const componentCache = /* @__PURE__ */ new Map();
197
+ const scriptCache = /* @__PURE__ */ new Map();
198
+ const plainScriptCache = /* @__PURE__ */ new Map();
199
+ const styleCache = /* @__PURE__ */ new Map();
200
+ for (const page of ctx.pages) {
201
+ const sfc = await compileHtmlFile({
202
+ ctx,
203
+ htmlAbs: page.htmlAbs,
204
+ outPath: page.pagePath,
205
+ emitted,
206
+ componentCache,
207
+ scriptCache,
208
+ plainScriptCache,
209
+ styleCache
210
+ });
211
+ emitted.set(page.pagePath, sfc);
212
+ }
213
+ for (const [outPath, source] of emitted) this.emitFile({
214
+ type: "asset",
215
+ fileName: `vue/src/${outPath}`,
216
+ source
217
+ });
218
+ }
219
+ };
220
+ }
221
+ async function compileHtmlFile(args) {
222
+ const { ctx, htmlAbs, outPath, emitted, componentCache, scriptCache, plainScriptCache, styleCache } = args;
223
+ const htmlSource = await fs$1.readFile(htmlAbs, "utf8");
224
+ const componentResult = await replaceLoadTagsWithComponents({
225
+ ctx,
226
+ template: extractTemplateRaw(htmlSource),
227
+ ownerHtmlAbs: htmlAbs,
228
+ ownerOutPath: outPath,
229
+ emitted,
230
+ componentCache,
231
+ scriptCache,
232
+ plainScriptCache,
233
+ styleCache
234
+ });
235
+ const detected = await detectAssetsFromHtmlWithSiblings(ctx, htmlAbs, htmlSource);
236
+ uniq(detected.remoteScripts.map((item) => item.use?.as).filter((value) => !!value));
237
+ const inlineScripts = analyzeInlineScripts(ctx, htmlAbs, htmlSource);
238
+ const inlineExecutableBodies = inlineScripts.mountedBodies.map((body) => stripJsComments(body).trim()).filter(Boolean);
239
+ const localScriptExecutableBodies = (await Promise.all(detected.localScripts.map(async (scriptEntry) => {
240
+ try {
241
+ const code = await fs$1.readFile(scriptEntry.sourceAbs, "utf8");
242
+ return analyzeExternalScript(ctx.root, scriptEntry.sourceAbs, code).body;
243
+ } catch {
244
+ return "";
245
+ }
246
+ }))).filter(Boolean);
247
+ const executableBodies = [...inlineExecutableBodies, ...localScriptExecutableBodies];
248
+ const activeRemoteScriptIndexes = detected.remoteScripts.map((item, index) => isRemoteScriptActivelyUsed(item, executableBodies) ? index : -1).filter((index) => index >= 0);
249
+ const activeRemoteInjectedNames = uniq(activeRemoteScriptIndexes.map((index) => detected.remoteScripts[index]?.use?.as).filter((value) => !!value));
250
+ const scriptUrlImportLines = [];
251
+ const scriptPageImportLines = [];
252
+ const scriptSetupLines = [];
253
+ const scriptLoadedLines = [];
254
+ const extraStyleFiles = [];
255
+ for (const scriptEntry of detected.localScripts) try {
256
+ const mod = await ensureScriptModule({
257
+ ctx,
258
+ root: ctx.root,
259
+ scriptEntry,
260
+ ownerOutPath: outPath,
261
+ emitted,
262
+ scriptCache,
263
+ plainScriptCache,
264
+ styleCache,
265
+ extraInjectedNames: activeRemoteInjectedNames
266
+ });
267
+ scriptPageImportLines.push(...mod.pageImportLines);
268
+ scriptUrlImportLines.push(mod.scriptUrlImportLine);
269
+ scriptSetupLines.push(mod.setupLine);
270
+ if (mod.loadedLine) scriptLoadedLines.push(mod.loadedLine);
271
+ extraStyleFiles.push(...mod.ref.localStyles);
272
+ } catch {}
273
+ const styleImportLines = [];
274
+ const allStyleFiles = uniq([...detected.localStyles, ...extraStyleFiles]);
275
+ for (const styleAbs of allStyleFiles) try {
276
+ const line = await ensureStyleAsset({
277
+ ctx,
278
+ root: ctx.root,
279
+ styleAbs,
280
+ ownerOutPath: outPath,
281
+ emitted,
282
+ styleCache
283
+ });
284
+ styleImportLines.push(line);
285
+ } catch {}
286
+ return renderVueSfc({
287
+ template: stripTemplateAssets(componentResult.template),
288
+ style: extractAllStyleBlocks(htmlSource),
289
+ scriptBody: joinNonEmpty([...inlineScripts.mountedBodies]),
290
+ importLines: uniq([
291
+ ...styleImportLines,
292
+ ...componentResult.importLines,
293
+ ...inlineScripts.importLines,
294
+ ...scriptPageImportLines,
295
+ ...scriptUrlImportLines
296
+ ]),
297
+ setupLines: uniq(scriptSetupLines),
298
+ loadedLines: uniq(scriptLoadedLines),
299
+ remoteScripts: uniqObjects(detected.remoteScripts),
300
+ activeRemoteScriptIndexes,
301
+ remoteStyleLinks: uniqObjects(detected.remoteStyleLinks),
302
+ inlineHeadScripts: uniqObjects(inlineScripts.headScripts)
303
+ });
304
+ }
305
+ async function replaceLoadTagsWithComponents(args) {
306
+ const { ctx, template, ownerHtmlAbs, ownerOutPath, emitted, componentCache, scriptCache, plainScriptCache, styleCache } = args;
307
+ const importLines = [];
308
+ return {
309
+ template: await replaceAsync(template, /<load\b([^>]*?)(?:\/>|>\s*<\/load>)/gi, async (_full, rawAttrs) => {
310
+ const src = getAttr(rawAttrs ?? "", "src");
311
+ if (!src) return "";
312
+ const childAbs = resolveHtmlAssetPath(ctx.root, path.dirname(ownerHtmlAbs), src);
313
+ if (!childAbs || !childAbs.toLowerCase().endsWith(".html")) return "";
314
+ const childRef = await ensureComponent({
315
+ ctx,
316
+ htmlAbs: childAbs,
317
+ emitted,
318
+ componentCache,
319
+ scriptCache,
320
+ plainScriptCache,
321
+ styleCache
322
+ });
323
+ const importPath = toGeneratedImportSpecifier(ctx, ownerOutPath, childRef.outPath);
324
+ importLines.push(`import ${childRef.name} from ${JSON.stringify(importPath)}`);
325
+ return `<${childRef.name} />`;
326
+ }),
327
+ importLines: uniq(importLines)
328
+ };
329
+ }
330
+ function buildWindowRunCallLine(onLoadedVar, globalFnName, injectedNames) {
331
+ return `${onLoadedVar}(() => { ${injectedNames.length ? `window.${globalFnName}?.({ ${injectedNames.join(", ")} })` : `window.${globalFnName}?.()`} })`;
332
+ }
333
+ function buildGeneratedScriptUseScriptLine(args) {
334
+ const { scriptVar, onLoadedVar, scriptEntry } = args;
335
+ const input = {
336
+ src: scriptVar,
337
+ ...scriptEntry.type ? { type: scriptEntry.type } : {}
338
+ };
339
+ const options = {
340
+ trigger: "client",
341
+ ...scriptEntry.warmupStrategy !== void 0 ? { warmupStrategy: scriptEntry.warmupStrategy } : {}
342
+ };
343
+ return `const { onLoaded: ${onLoadedVar} } = useScript(${toCode(input)}, ${toCode(options)})`;
344
+ }
345
+ async function ensureScriptModule(args) {
346
+ const { ctx, root, scriptEntry, ownerOutPath, emitted, scriptCache, plainScriptCache, styleCache, extraInjectedNames } = args;
347
+ const scriptAbs = scriptEntry.sourceAbs;
348
+ const scriptCacheKey = `${scriptAbs}::${uniq([...extraInjectedNames]).slice().sort().join(",")}`;
349
+ const cached = scriptCache.get(scriptCacheKey);
350
+ if (cached) {
351
+ const pageImportLines = [...cached.staticPageImportLines, ...cached.localPageImports.map((item) => item.clause ? `import ${item.clause} from ${JSON.stringify(toGeneratedImportSpecifier(ctx, ownerOutPath, item.outPath))}` : `import ${JSON.stringify(toGeneratedImportSpecifier(ctx, ownerOutPath, item.outPath))}`)];
352
+ const scriptVar = `__scriptUrl${pascalCase(fileBaseStem(scriptAbs))}`;
353
+ const onLoadedVar = `__onLoaded${pascalCase(fileBaseStem(scriptAbs))}`;
354
+ return {
355
+ ref: cached,
356
+ pageImportLines: uniq(pageImportLines),
357
+ scriptUrlImportLine: `import ${scriptVar} from ${JSON.stringify(`${toGeneratedImportSpecifier(ctx, ownerOutPath, cached.outPath)}?url`)}`,
358
+ setupLine: buildGeneratedScriptUseScriptLine({
359
+ scriptVar,
360
+ onLoadedVar,
361
+ scriptEntry
362
+ }),
363
+ loadedLine: cached.hasBody ? buildWindowRunCallLine(onLoadedVar, cached.globalFnName, cached.injectedNames) : ""
364
+ };
365
+ }
366
+ const analyzed = analyzeExternalScript(root, scriptAbs, await fs$1.readFile(scriptAbs, "utf8"));
367
+ const fileStem = fileStemFromAbs(root, scriptAbs);
368
+ const outPath = normalizeVueJsOutPath(`script/${fileStem}.js`);
369
+ const globalFnName = buildGlobalRunnerName(ctx.projectNameCamel, scriptAbs);
370
+ const localPageImports = [];
371
+ for (const item of analyzed.localJsImports) {
372
+ const depStem = `${fileStem}-${fileBaseStem(item.sourceAbs)}`;
373
+ const depRef = await ensurePlainScriptModule({
374
+ root,
375
+ sourceAbs: item.sourceAbs,
376
+ outStem: depStem,
377
+ emitted,
378
+ plainScriptCache,
379
+ styleCache
380
+ });
381
+ localPageImports.push({
382
+ clause: item.clause,
383
+ outPath: depRef.outPath
384
+ });
385
+ }
386
+ const finalInjectedNames = uniq([...analyzed.injectedNames, ...extraInjectedNames]);
387
+ const moduleSource = renderWindowRunModule(globalFnName, finalInjectedNames, analyzed.body);
388
+ const ref = {
389
+ sourceAbs: scriptAbs,
390
+ outPath,
391
+ globalFnName,
392
+ localStyles: analyzed.localStyles,
393
+ staticPageImportLines: analyzed.pageImportLines,
394
+ localPageImports,
395
+ injectedNames: finalInjectedNames,
396
+ hasBody: !!analyzed.body
397
+ };
398
+ scriptCache.set(scriptCacheKey, ref);
399
+ emitted.set(outPath, moduleSource);
400
+ const pageImportLines = [...ref.staticPageImportLines, ...ref.localPageImports.map((item) => item.clause ? `import ${item.clause} from ${JSON.stringify(toGeneratedImportSpecifier(ctx, ownerOutPath, item.outPath))}` : `import ${JSON.stringify(toGeneratedImportSpecifier(ctx, ownerOutPath, item.outPath))}`)];
401
+ const scriptVar = `__scriptUrl${pascalCase(fileBaseStem(scriptAbs))}`;
402
+ const onLoadedVar = `__onLoaded${pascalCase(fileBaseStem(scriptAbs))}`;
403
+ return {
404
+ ref,
405
+ pageImportLines: uniq(pageImportLines),
406
+ scriptUrlImportLine: `import ${scriptVar} from ${JSON.stringify(`${toGeneratedImportSpecifier(ctx, ownerOutPath, outPath)}?url`)}`,
407
+ setupLine: buildGeneratedScriptUseScriptLine({
408
+ scriptVar,
409
+ onLoadedVar,
410
+ scriptEntry
411
+ }),
412
+ loadedLine: ref.hasBody ? buildWindowRunCallLine(onLoadedVar, ref.globalFnName, ref.injectedNames) : ""
413
+ };
414
+ }
415
+ function fileBaseStem(abs) {
416
+ return path.basename(abs, path.extname(abs));
417
+ }
418
+ async function ensurePlainScriptModule(args) {
419
+ const { root, sourceAbs, outStem, emitted, plainScriptCache, styleCache } = args;
420
+ const cacheKey = `${sourceAbs}::${outStem}`;
421
+ const cached = plainScriptCache.get(cacheKey);
422
+ if (cached) return cached;
423
+ const outPath = normalizeVueJsOutPath(`script/${outStem}.js`);
424
+ const fileDir = path.dirname(sourceAbs);
425
+ const nextCode = await replaceAsync(await fs$1.readFile(sourceAbs, "utf8"), /^\s*import\s+(?:(.*?)\s+from\s+)?['"]([^'"]+)['"]\s*;?\s*$/gm, async (full, clauseRaw, specRaw) => {
426
+ const clause = clauseRaw?.trim();
427
+ const spec = specRaw?.trim();
428
+ if (!spec) return full.trim();
429
+ if (isRemoteUrl(spec) || isBareImport(spec)) return full.trim();
430
+ const resolved = resolveJsImportPath(root, fileDir, spec);
431
+ if (!resolved) return full.trim();
432
+ if (resolved.endsWith(".css")) {
433
+ const cssOutPath = await ensureStyleAssetOutPath({
434
+ root,
435
+ styleAbs: resolved,
436
+ emitted,
437
+ styleCache
438
+ });
439
+ return `import ${JSON.stringify(toVueRelativeImport(outPath, cssOutPath))}`;
440
+ }
441
+ const childStem = `${outStem}-${fileBaseStem(resolved)}`;
442
+ const childRef = await ensurePlainScriptModule({
443
+ root,
444
+ sourceAbs: resolved,
445
+ outStem: childStem,
446
+ emitted,
447
+ plainScriptCache,
448
+ styleCache
449
+ });
450
+ const nextSpec = toVueRelativeImport(outPath, childRef.outPath);
451
+ return clause ? `import ${clause} from ${JSON.stringify(nextSpec)}` : `import ${JSON.stringify(nextSpec)}`;
452
+ });
453
+ const ref = {
454
+ sourceAbs,
455
+ outPath
456
+ };
457
+ plainScriptCache.set(cacheKey, ref);
458
+ emitted.set(outPath, nextCode);
459
+ return ref;
460
+ }
461
+ async function ensureStyleAsset(args) {
462
+ const { ctx, root, styleAbs, ownerOutPath, emitted, styleCache } = args;
463
+ const outPath = await ensureStyleAssetOutPath({
464
+ root,
465
+ styleAbs,
466
+ emitted,
467
+ styleCache
468
+ });
469
+ return `import ${JSON.stringify(toGeneratedImportSpecifier(ctx, ownerOutPath, outPath))}`;
470
+ }
471
+ async function ensureComponent(args) {
472
+ const { ctx, htmlAbs, emitted, componentCache, scriptCache, plainScriptCache, styleCache } = args;
473
+ const cached = componentCache.get(htmlAbs);
474
+ if (cached) return cached;
475
+ const name = componentNameFromPath(ctx.componentRootAbs, ctx.root, htmlAbs);
476
+ const outPath = normalizeVueOutPath(`${ctx.componentOutDir}/${name}.vue`);
477
+ const ref = {
478
+ name,
479
+ outPath
480
+ };
481
+ componentCache.set(htmlAbs, ref);
482
+ const sfc = await compileHtmlFile({
483
+ ctx,
484
+ htmlAbs,
485
+ outPath,
486
+ emitted,
487
+ componentCache,
488
+ scriptCache,
489
+ plainScriptCache,
490
+ styleCache
491
+ });
492
+ emitted.set(outPath, sfc);
493
+ return ref;
494
+ }
495
+ async function detectAssetsFromHtmlWithSiblings(ctx, htmlAbs, htmlSource) {
496
+ const detected = detectAssetsFromHtml(ctx.root, htmlAbs, htmlSource);
497
+ const sibling = await detectSiblingAssets(htmlAbs);
498
+ return {
499
+ localScripts: uniqObjects([...detected.localScripts, ...sibling.localScripts]),
500
+ localStyles: uniq([...detected.localStyles, ...sibling.localStyles]),
501
+ remoteScripts: uniqObjects(detected.remoteScripts),
502
+ remoteStyleLinks: uniqObjects(detected.remoteStyleLinks)
503
+ };
504
+ }
505
+ function detectAssetsFromHtml(root, htmlFile, htmlSource) {
506
+ const htmlDir = path.dirname(resolveFromRoot(root, htmlFile));
507
+ const localScripts = [];
508
+ const localStyles = [];
509
+ const remoteScripts = [];
510
+ const remoteStyleLinks = [];
511
+ for (const match of htmlSource.matchAll(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi)) {
512
+ const attrs = match[1] ?? "";
513
+ const type = getAttr(attrs, "type")?.toLowerCase();
514
+ if (type === "importmap") continue;
515
+ const src = getAttr(attrs, "src");
516
+ if (!src) continue;
517
+ if (isRemoteUrl(src)) {
518
+ remoteScripts.push(scriptAttrsToRemoteScriptEntry(src, attrs));
519
+ continue;
520
+ }
521
+ if (isIgnoredHtmlAsset(src)) continue;
522
+ const resolved = resolveHtmlAssetPath(root, htmlDir, src);
523
+ if (resolved) localScripts.push({
524
+ sourceAbs: resolved,
525
+ type: normalizeScriptType(type),
526
+ warmupStrategy: normalizeScriptWarmupStrategy(getAttr(attrs, "rel"))
527
+ });
528
+ }
529
+ for (const match of htmlSource.matchAll(/<link\b([^>]*?)>/gi)) {
530
+ const attrs = match[1] ?? "";
531
+ if (getAttr(attrs, "rel")?.toLowerCase() !== "stylesheet") continue;
532
+ const href = getAttr(attrs, "href");
533
+ if (!href) continue;
534
+ if (isRemoteUrl(href)) {
535
+ remoteStyleLinks.push(linkAttrsToHeadLink(href, attrs));
536
+ continue;
537
+ }
538
+ if (isIgnoredHtmlAsset(href)) continue;
539
+ const resolved = resolveHtmlAssetPath(root, htmlDir, href);
540
+ if (resolved) localStyles.push(resolved);
541
+ }
542
+ return {
543
+ localScripts: uniqObjects(localScripts),
544
+ localStyles: uniq(localStyles),
545
+ remoteScripts,
546
+ remoteStyleLinks
547
+ };
548
+ }
549
+ async function detectSiblingAssets(htmlAbs) {
550
+ const base = htmlAbs.replace(/\.html$/i, "");
551
+ const localScripts = [];
552
+ const localStyles = [];
553
+ if (await fileExists(`${base}.js`)) localScripts.push({
554
+ sourceAbs: `${base}.js`,
555
+ type: "module",
556
+ warmupStrategy: void 0
557
+ });
558
+ if (await fileExists(`${base}.css`)) localStyles.push(`${base}.css`);
559
+ return {
560
+ localScripts,
561
+ localStyles
562
+ };
563
+ }
564
+ async function ensureStyleAssetOutPath(args) {
565
+ const { root, styleAbs, emitted, styleCache } = args;
566
+ const cached = styleCache.get(styleAbs);
567
+ if (cached) return cached.outPath;
568
+ const css = await fs$1.readFile(styleAbs, "utf8");
569
+ const outPath = normalizeCssOutPath(`style/${fileStemFromAbs(root, styleAbs)}.css`);
570
+ const ref = {
571
+ sourceAbs: styleAbs,
572
+ outPath
573
+ };
574
+ styleCache.set(styleAbs, ref);
575
+ emitted.set(outPath, css);
576
+ return outPath;
577
+ }
578
+ function analyzeExternalScript(root, filePath, code) {
579
+ const pageImportLines = [];
580
+ const injectedNames = [];
581
+ const localStyles = [];
582
+ const localJsImports = [];
583
+ const fileDir = path.dirname(filePath);
584
+ const importRe = /^\s*import\s+(?:(.*?)\s+from\s+)?['"]([^'"]+)['"]\s*;?\s*$/gm;
585
+ let match;
586
+ while (match = importRe.exec(code)) {
587
+ const clause = match[1]?.trim();
588
+ const spec = match[2]?.trim();
589
+ if (!spec) continue;
590
+ if (isRemoteUrl(spec) || isBareImport(spec)) {
591
+ pageImportLines.push(match[0].trim());
592
+ injectedNames.push(...extractImportBindings(clause));
593
+ continue;
594
+ }
595
+ const resolved = resolveJsImportPath(root, fileDir, spec);
596
+ if (!resolved) continue;
597
+ if (resolved.endsWith(".css")) {
598
+ localStyles.push(resolved);
599
+ continue;
600
+ }
601
+ localJsImports.push({
602
+ clause,
603
+ sourceAbs: resolved
604
+ });
605
+ injectedNames.push(...extractImportBindings(clause));
606
+ }
607
+ const executableBody = normalizeExecutableBody(code);
608
+ return {
609
+ pageImportLines: uniq(pageImportLines),
610
+ injectedNames: uniq(injectedNames),
611
+ localStyles: uniq(localStyles),
612
+ localJsImports,
613
+ body: executableBody
614
+ };
615
+ }
616
+ function buildScriptSetup(scriptBody, importLines, setupLines, loadedLines, remoteScripts, activeRemoteScriptIndexes, remoteStyleLinks, inlineHeadScripts) {
617
+ const activeIndexSet = new Set(activeRemoteScriptIndexes);
618
+ const scriptSetupLines = remoteScripts.map((item, index) => {
619
+ const isActive = activeIndexSet.has(index);
620
+ if (item.use && isActive) return `const { onLoaded: ${`__onLoaded${index}`} } = ${renderUseScriptCall(item)}`;
621
+ return renderUseScriptCall(item);
622
+ });
623
+ const useWrappedScripts = remoteScripts.map((item, index) => ({
624
+ item,
625
+ index
626
+ })).filter(({ item, index }) => !!item.use && activeIndexSet.has(index));
627
+ const plainBody = scriptBody.trim();
628
+ const topLevelLoadedBlocks = useWrappedScripts.map(({ item, index }) => {
629
+ const cbArg = item.use?.as ? item.use.as : "";
630
+ return [
631
+ `__onLoaded${index}(${cbArg ? `(${cbArg}) => {` : `() => {`}`,
632
+ indent(plainBody, 2),
633
+ `})`
634
+ ].join("\n");
635
+ });
636
+ const mountedBlock = plainBody && !useWrappedScripts.length ? [
637
+ "onMounted(() => {",
638
+ indent(plainBody, 2),
639
+ "})"
640
+ ].join("\n") : "";
641
+ const headConfigParts = [];
642
+ if (remoteStyleLinks.length) headConfigParts.push(`link: ${toCode(remoteStyleLinks)}`);
643
+ if (inlineHeadScripts.length) headConfigParts.push(`script: ${toCode(inlineHeadScripts)}`);
644
+ const headLine = headConfigParts.length ? `useHead({ ${headConfigParts.join(", ")} })` : "";
645
+ return [
646
+ "<script setup>",
647
+ ...mountedBlock ? [`import { onMounted } from 'vue'`] : [],
648
+ ...remoteScripts.length || setupLines.length || loadedLines.length ? [`import { useScript } from '@unhead/vue'`] : [],
649
+ ...remoteStyleLinks.length || inlineHeadScripts.length ? [`import { useHead } from '@unhead/vue'`] : [],
650
+ ...importLines,
651
+ "",
652
+ ...headLine ? [headLine, ""] : [],
653
+ ...scriptSetupLines,
654
+ ...setupLines,
655
+ ...scriptSetupLines.length || setupLines.length ? [""] : [],
656
+ ...topLevelLoadedBlocks,
657
+ ...loadedLines,
658
+ ...topLevelLoadedBlocks.length || loadedLines.length ? [""] : [],
659
+ mountedBlock,
660
+ "<\/script>"
661
+ ].filter(Boolean).join("\n");
662
+ }
663
+ function renderVueSfc(parts) {
664
+ return [
665
+ `<template>\n${parts.template}\n</template>`,
666
+ buildScriptSetup(parts.scriptBody, parts.importLines, parts.setupLines, parts.loadedLines, parts.remoteScripts, parts.activeRemoteScriptIndexes, parts.remoteStyleLinks, parts.inlineHeadScripts),
667
+ `<style>\n${parts.style}\n</style>`
668
+ ].join("\n\n");
669
+ }
670
+ function analyzeInlineModuleScript(code) {
671
+ const importLines = [];
672
+ const importRe = /^\s*import\s+(?:(.*?)\s+from\s+)?['"]([^'"]+)['"]\s*;?\s*$/gm;
673
+ let match;
674
+ while (match = importRe.exec(code)) importLines.push(match[0].trim());
675
+ return {
676
+ importLines: uniq(importLines),
677
+ body: normalizeExecutableBody(code)
678
+ };
679
+ }
680
+ function analyzeInlineScripts(ctx, htmlAbs, html) {
681
+ const importLines = [];
682
+ const mountedBodies = [];
683
+ const headScripts = [];
684
+ let inlineIndex = 0;
685
+ for (const match of html.matchAll(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi)) {
686
+ const attrs = match[1] ?? "";
687
+ const content = (match[2] ?? "").trim();
688
+ const src = getAttr(attrs, "src");
689
+ const type = getAttr(attrs, "type")?.toLowerCase();
690
+ if (src) continue;
691
+ if (type === "importmap") continue;
692
+ if (!content) continue;
693
+ const key = buildInlineHeadScriptKey(ctx.projectNameCamel, ctx.root, htmlAbs, inlineIndex++);
694
+ if (type === "module") {
695
+ const analyzed = analyzeInlineModuleScript(content);
696
+ importLines.push(...analyzed.importLines);
697
+ if (analyzed.body.trim()) mountedBodies.push(analyzed.body.trim());
698
+ continue;
699
+ }
700
+ headScripts.push({
701
+ key,
702
+ textContent: content,
703
+ tagPosition: "bodyClose"
704
+ });
705
+ }
706
+ return {
707
+ importLines: uniq(importLines),
708
+ mountedBodies,
709
+ headScripts: uniqObjects(headScripts)
710
+ };
711
+ }
712
+ function extractTemplateRaw(html) {
713
+ const bodyMatch = html.match(/<body\b[^>]*>([\s\S]*?)<\/body>/i);
714
+ if (bodyMatch) return bodyMatch[1].trim();
715
+ return html.replace(/<!doctype[\s\S]*?>/gi, "").replace(/<html\b[^>]*>/gi, "").replace(/<\/html>/gi, "").replace(/<head\b[\s\S]*?<\/head>/gi, "").trim();
716
+ }
717
+ function stripTemplateAssets(template) {
718
+ return template.replace(/<script\b[\s\S]*?<\/script>/gi, "").replace(/<link\b[^>]*rel=["']stylesheet["'][^>]*>/gi, "").replace(/<style\b[\s\S]*?<\/style>/gi, "").trim();
719
+ }
720
+ function extractAllStyleBlocks(html) {
721
+ return [...html.matchAll(/<style\b[^>]*>([\s\S]*?)<\/style>/gi)].map((m) => m[1].trim()).filter(Boolean).join("\n\n");
722
+ }
723
+ function componentNameFromPath(componentRootAbs, root, htmlAbs) {
724
+ return (isInsideDir(componentRootAbs, htmlAbs) ? path.relative(componentRootAbs, htmlAbs) : path.relative(root, htmlAbs)).replace(/\.html$/i, "").replace(/\\/g, "/").split("/").filter(Boolean).map(pascalCase).join("");
725
+ }
726
+ function scriptAttrsToRemoteScriptEntry(src, attrs) {
727
+ const crossorigin = normalizeCrossorigin(getAttr(attrs, "crossorigin"));
728
+ const referrerpolicy = normalizeReferrerPolicy(getAttr(attrs, "referrerpolicy"));
729
+ const integrity = getAttr(attrs, "integrity");
730
+ const use = parseUseExpression(getAttr(attrs, "use"));
731
+ return {
732
+ input: {
733
+ src,
734
+ ...hasBooleanAttr(attrs, "async") ? { async: true } : {},
735
+ ...hasBooleanAttr(attrs, "defer") ? { defer: true } : {},
736
+ ...crossorigin !== void 0 ? { crossorigin } : {},
737
+ ...referrerpolicy !== void 0 ? { referrerpolicy } : {},
738
+ ...integrity ? { integrity } : {}
739
+ },
740
+ ...use ? { use } : {}
741
+ };
742
+ }
743
+ function linkAttrsToHeadLink(href, attrs) {
744
+ return {
745
+ rel: "stylesheet",
746
+ href,
747
+ ...getAttr(attrs, "media") ? { media: getAttr(attrs, "media") } : {},
748
+ ...getAttr(attrs, "crossorigin") ? { crossorigin: getAttr(attrs, "crossorigin") } : {},
749
+ ...getAttr(attrs, "referrerpolicy") ? { referrerpolicy: getAttr(attrs, "referrerpolicy") } : {},
750
+ ...getAttr(attrs, "integrity") ? { integrity: getAttr(attrs, "integrity") } : {}
751
+ };
752
+ }
753
+ function getAttr(attrs, name) {
754
+ const re = new RegExp(`\\b${name}\\s*=\\s*("([^"]*)"|'([^']*)'|([^\\s>]+))`, "i");
755
+ const match = attrs.match(re);
756
+ return match?.[2] ?? match?.[3] ?? match?.[4] ?? null;
757
+ }
758
+ function hasBooleanAttr(attrs, name) {
759
+ return new RegExp(`\\b${name}(?=\\s|>|$)`, "i").test(attrs);
760
+ }
761
+ function isRemoteUrl(value) {
762
+ return /^https?:\/\//i.test(value);
763
+ }
764
+ function isBareImport(spec) {
765
+ return !spec.startsWith("/") && !spec.startsWith("./") && !spec.startsWith("../") && !isRemoteUrl(spec);
766
+ }
767
+ function isIgnoredHtmlAsset(value) {
768
+ const v = value.replace(/\\/g, "/");
769
+ return v.startsWith("/_virtual/") || v.startsWith("/@") || v.includes("/node_modules/") || v.endsWith(".html.js") || isBareImport(v);
770
+ }
771
+ function resolveHtmlAssetPath(root, htmlDir, value) {
772
+ const clean = stripQueryHash(value);
773
+ return clean.startsWith("/") ? path.resolve(root, `.${clean}`) : path.resolve(htmlDir, clean);
774
+ }
775
+ function resolveExistingModulePath(base) {
776
+ const candidates = uniq([
777
+ base,
778
+ `${base}.js`,
779
+ `${base}.mjs`,
780
+ `${base}.cjs`,
781
+ `${base}.ts`,
782
+ `${base}.mts`,
783
+ `${base}.cts`,
784
+ `${base}.jsx`,
785
+ `${base}.tsx`,
786
+ path.join(base, "index.js"),
787
+ path.join(base, "index.mjs"),
788
+ path.join(base, "index.cjs"),
789
+ path.join(base, "index.ts"),
790
+ path.join(base, "index.mts"),
791
+ path.join(base, "index.cts"),
792
+ path.join(base, "index.jsx"),
793
+ path.join(base, "index.tsx")
794
+ ]);
795
+ for (const file of candidates) if (fs.existsSync(file) && fs.statSync(file).isFile()) return file;
796
+ return null;
797
+ }
798
+ function resolveJsImportPath(root, fileDir, spec) {
799
+ const clean = stripQueryHash(spec);
800
+ let base = null;
801
+ if (clean.startsWith("/")) base = path.resolve(root, `.${clean}`);
802
+ else if (clean.startsWith("./") || clean.startsWith("../")) base = path.resolve(fileDir, clean);
803
+ if (!base) return null;
804
+ return resolveExistingModulePath(base);
805
+ }
806
+ function normalizeCrossorigin(value) {
807
+ if (value == null) return void 0;
808
+ const v = value.trim().toLowerCase();
809
+ if (v === "") return "";
810
+ if (v === "anonymous") return "anonymous";
811
+ if (v === "use-credentials") return "use-credentials";
812
+ }
813
+ function normalizeReferrerPolicy(value) {
814
+ if (value == null) return void 0;
815
+ const v = value.trim().toLowerCase();
816
+ switch (v) {
817
+ case "":
818
+ case "no-referrer":
819
+ case "no-referrer-when-downgrade":
820
+ case "origin":
821
+ case "origin-when-cross-origin":
822
+ case "same-origin":
823
+ case "strict-origin":
824
+ case "strict-origin-when-cross-origin":
825
+ case "unsafe-url": return v;
826
+ default: return;
827
+ }
828
+ }
829
+ function normalizeVueOutPath(value) {
830
+ let next = value.replace(/\\/g, "/").trim();
831
+ next = next.replace(/^\.\/+/, "");
832
+ next = next.replace(/^\/+/, "");
833
+ if (!next.endsWith(".vue")) next += ".vue";
834
+ return next;
835
+ }
836
+ function normalizeDirPath(value) {
837
+ let next = value.replace(/\\/g, "/").trim();
838
+ next = next.replace(/^\.\/+/, "");
839
+ next = next.replace(/^\/+/, "");
840
+ next = next.replace(/\/+$/, "");
841
+ return next;
842
+ }
843
+ function defaultPagePath(htmlPath) {
844
+ return `pages/${path.basename(htmlPath, path.extname(htmlPath))}.vue`;
845
+ }
846
+ function toVueRelativeImport(fromOutPath, toOutPath) {
847
+ const fromDir = path.posix.dirname(fromOutPath.replace(/\\/g, "/"));
848
+ const to = toOutPath.replace(/\\/g, "/");
849
+ let rel = path.posix.relative(fromDir, to);
850
+ if (!rel.startsWith(".")) rel = `./${rel}`;
851
+ return rel;
852
+ }
853
+ function resolveFromRoot(root, filePath) {
854
+ return path.isAbsolute(filePath) ? filePath : path.resolve(root, filePath);
855
+ }
856
+ function stripQueryHash(value) {
857
+ return value.split("?")[0].split("#")[0];
858
+ }
859
+ function pascalCase(value) {
860
+ return value.split(/[^A-Za-z0-9]+/).filter(Boolean).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
861
+ }
862
+ function removeImports(code) {
863
+ return code.replace(/^\s*import[\s\S]*?from\s+['"][^'"]+['"]\s*;?\s*$/gm, "").replace(/^\s*import\s+['"][^'"]+['"]\s*;?\s*$/gm, "").trim();
864
+ }
865
+ async function fileExists(file) {
866
+ try {
867
+ await fs$1.access(file);
868
+ return true;
869
+ } catch {
870
+ return false;
871
+ }
872
+ }
873
+ async function replaceAsync(input, re, replacer) {
874
+ const matches = [...input.matchAll(re)];
875
+ if (!matches.length) return input;
876
+ let out = "";
877
+ let lastIndex = 0;
878
+ for (const match of matches) {
879
+ const index = match.index ?? 0;
880
+ out += input.slice(lastIndex, index);
881
+ out += await replacer(...match);
882
+ lastIndex = index + match[0].length;
883
+ }
884
+ out += input.slice(lastIndex);
885
+ return out;
886
+ }
887
+ function joinNonEmpty(parts) {
888
+ return parts.filter(Boolean).join("\n\n");
889
+ }
890
+ function uniq(arr) {
891
+ return Array.from(new Set(arr));
892
+ }
893
+ function uniqObjects(arr) {
894
+ const seen = /* @__PURE__ */ new Set();
895
+ return arr.filter((item) => {
896
+ const key = JSON.stringify(item);
897
+ if (seen.has(key)) return false;
898
+ seen.add(key);
899
+ return true;
900
+ });
901
+ }
902
+ function isInsideDir(parent, child) {
903
+ const rel = path.relative(parent, child);
904
+ return !!rel && !rel.startsWith("..") && !path.isAbsolute(rel);
905
+ }
906
+ function toCode(value) {
907
+ if (value === null) return "null";
908
+ if (value === void 0) return "undefined";
909
+ const type = typeof value;
910
+ if (type === "string") return JSON.stringify(value);
911
+ if (type === "number" || type === "boolean" || type === "bigint") return String(value);
912
+ if (Array.isArray(value)) return `[${value.map((item) => toCode(item)).join(", ")}]`;
913
+ if (type === "object") return `{ ${Object.entries(value).filter(([, v]) => v !== void 0).map(([key, val]) => {
914
+ return `${isValidIdentifier(key) ? key : JSON.stringify(key)}: ${toCode(val)}`;
915
+ }).join(", ")} }`;
916
+ return JSON.stringify(value);
917
+ }
918
+ function isValidIdentifier(key) {
919
+ return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(key);
920
+ }
921
+ function indent(code, spaces) {
922
+ const pad = " ".repeat(spaces);
923
+ return code.split("\n").map((line) => line ? pad + line : line).join("\n");
924
+ }
925
+
926
+ //#endregion
927
+ //#region src/composables/html-path.ts
928
+ function htmlPath({ dir, dirname }) {
929
+ const absDir = resolve(dirname, dir);
930
+ const entries = {};
931
+ for (const name of fs.readdirSync(absDir)) {
932
+ if (!name.endsWith(".html")) continue;
933
+ const full = path.join(absDir, name);
934
+ const key = name.replace(/\.html$/, "");
935
+ entries[key] = full;
936
+ }
937
+ return entries;
938
+ }
939
+
940
+ //#endregion
941
+ export { htmlPath, htmlToVue, mergeEcosystem, monoEcosystem };