UNPKG

weapp-tailwindcss

Version:

把 tailwindcss 原子化样式思想,带给小程序开发者们! bring tailwindcss to miniprogram developers!

1,256 lines 508 kB
const require_rolldown_runtime = require("./rolldown-runtime-CVvi-lCc.cjs"); const require_framework = require("./framework.cjs"); const require_generator = require("./generator-BE34PYSC.cjs"); const require_object = require("./object-C_Vr6_S5.cjs"); const require_options = require("./options-hVsoTfwL.cjs"); require("./utils-CuKLf1Zv.cjs"); const require_v4_generation_core = require("./v4-generation-core-CDI6ChiH.cjs"); const require_wxml = require("./wxml-DSMNuUaP.cjs"); const require_hmr_timing = require("./hmr-timing-Cye_A4mI.cjs"); const require_context = require("./context-OqD_eBxQ.cjs"); const require_tailwindcss = require("./tailwindcss-DcpiKvmJ.cjs"); const require_style_options = require("./style-options-B_ppaVIg.cjs"); const require_source_candidate_scan_signature = require("./source-candidate-scan-signature-D4X_VprL.cjs"); require("./logger-TlKT3xmR.cjs"); const require_css_imports = require("./css-imports-DfNC3e6a.cjs"); let node_fs = require("node:fs"); node_fs = require_rolldown_runtime.__toESM(node_fs, 1); let node_path = require("node:path"); node_path = require_rolldown_runtime.__toESM(node_path, 1); let node_process = require("node:process"); node_process = require_rolldown_runtime.__toESM(node_process, 1); let _tailwindcss_mangle_engine = require("@tailwindcss-mangle/engine"); let _weapp_tailwindcss_postcss = require("@weapp-tailwindcss/postcss"); let lru_cache = require("lru-cache"); let node_fs_promises = require("node:fs/promises"); let micromatch = require("micromatch"); micromatch = require_rolldown_runtime.__toESM(micromatch, 1); let _weapp_tailwindcss_shared = require("@weapp-tailwindcss/shared"); let _weapp_tailwindcss_logger = require("@weapp-tailwindcss/logger"); let node_buffer = require("node:buffer"); let node_async_hooks = require("node:async_hooks"); let comment_json = require("comment-json"); //#region src/bundlers/vite/source-output-relations.ts const activeRelationOwnerStorage = new node_async_hooks.AsyncLocalStorage(); function normalizeSourceFile$1(sourceFile) { return require_source_candidate_scan_signature.normalizeOutputPathKey(sourceFile.replace(/[?#].*$/, "")); } function normalizeOutputFile(outputFile) { return require_source_candidate_scan_signature.normalizeOutputPathKey(outputFile); } function collectOwnedSources(output) { if (output.type === "chunk") { if (output.facadeModuleId) return [output.facadeModuleId]; const moduleIds = Array.isArray(output.moduleIds) ? output.moduleIds : []; return moduleIds.length === 1 ? moduleIds : []; } return [output.originalFileName, ...Array.isArray(output.originalFileNames) ? output.originalFileNames : []].filter((sourceFile) => typeof sourceFile === "string" && sourceFile.length > 0); } function createViteSourceOutputRelationOwner() { const outputsBySource = /* @__PURE__ */ new Map(); const sourcesByOutput = /* @__PURE__ */ new Map(); const deletedSources = /* @__PURE__ */ new Set(); const dirtySources = /* @__PURE__ */ new Set(); const consumers = /* @__PURE__ */ new Set(); let disposed = false; const unlinkSourceFromOutput = (sourceFile, outputFile) => { const outputs = outputsBySource.get(sourceFile); outputs?.delete(outputFile); if (outputs?.size === 0) outputsBySource.delete(sourceFile); const sources = sourcesByOutput.get(outputFile); sources?.delete(sourceFile); if (sources?.size === 0) sourcesByOutput.delete(outputFile); }; const unlinkSource = (sourceFile) => { const outputs = [...outputsBySource.get(sourceFile) ?? []]; for (const outputFile of outputs) unlinkSourceFromOutput(sourceFile, outputFile); return outputs; }; const queueRemovedOutputs = (outputFiles) => { for (const outputFile of outputFiles) { if (sourcesByOutput.has(outputFile)) continue; for (const consumer of consumers) consumer.pending.add(outputFile); } }; const recordOwnedOutput = (sourceFile, outputFile) => { if (disposed) return; const sourceKey = normalizeSourceFile$1(sourceFile); const outputKey = normalizeOutputFile(outputFile); if (!sourceKey || !outputKey || deletedSources.has(sourceKey)) return; if (dirtySources.delete(sourceKey)) queueRemovedOutputs(unlinkSource(sourceKey)); const outputs = outputsBySource.get(sourceKey) ?? /* @__PURE__ */ new Set(); outputs.add(outputKey); outputsBySource.set(sourceKey, outputs); const sources = sourcesByOutput.get(outputKey) ?? /* @__PURE__ */ new Set(); sources.add(sourceKey); sourcesByOutput.set(outputKey, sources); }; const replaceOutputOwners = (outputFile, sourceFiles) => { const outputKey = normalizeOutputFile(outputFile); for (const sourceFile of [...sourcesByOutput.get(outputKey) ?? []]) unlinkSourceFromOutput(sourceFile, outputKey); for (const sourceFile of sourceFiles) { deletedSources.delete(normalizeSourceFile$1(sourceFile)); recordOwnedOutput(sourceFile, outputKey); } }; return { createRemovalConsumer() { const state = { pending: /* @__PURE__ */ new Set() }; consumers.add(state); return { consume(currentBundleFiles) { if (disposed || state.pending.size === 0) return []; const currentFiles = new Set([...currentBundleFiles].map(normalizeOutputFile)); const removedFiles = [...state.pending].filter((file) => !currentFiles.has(file)); state.pending.clear(); return removedFiles; } }; }, dispose() { disposed = true; outputsBySource.clear(); sourcesByOutput.clear(); deletedSources.clear(); dirtySources.clear(); consumers.clear(); }, getStats() { return { consumers: consumers.size, dirtySources: dirtySources.size, outputs: sourcesByOutput.size, pendingOutputs: new Set([...consumers].flatMap((consumer) => [...consumer.pending])).size, sources: outputsBySource.size }; }, getOutputSources(outputFile) { return new Set(sourcesByOutput.get(normalizeOutputFile(outputFile)) ?? []); }, getOwnedOutputs(sourceFile) { return new Set(outputsBySource.get(normalizeSourceFile$1(sourceFile)) ?? []); }, observeSource(sourceFile) { if (!disposed) { const sourceKey = normalizeSourceFile$1(sourceFile); deletedSources.delete(sourceKey); if (outputsBySource.has(sourceKey)) dirtySources.add(sourceKey); } }, recordBundle(bundle) { if (disposed) return; for (const [bundleFile, output] of Object.entries(bundle)) { const ownedSources = collectOwnedSources(output); if (ownedSources.length > 0) replaceOutputOwners(output.fileName || bundleFile, ownedSources); } }, recordOwnedOutput, removeSource(sourceFile) { if (disposed) return /* @__PURE__ */ new Set(); const sourceKey = normalizeSourceFile$1(sourceFile); deletedSources.add(sourceKey); dirtySources.delete(sourceKey); const removedOutputs = /* @__PURE__ */ new Set(); for (const outputFile of unlinkSource(sourceKey)) if (!sourcesByOutput.has(outputFile)) removedOutputs.add(outputFile); queueRemovedOutputs(removedOutputs); return removedOutputs; } }; } function getActiveViteSourceOutputRelationOwner() { return activeRelationOwnerStorage.getStore(); } function withViteSourceOutputRelationOwner(owner, run) { return activeRelationOwnerStorage.run(owner, run); } //#endregion //#region src/bundlers/vite/css-asset-identity.ts function createViteCssAssetIdentityResolver(options) { const identityByAsset = /* @__PURE__ */ new WeakMap(); const placeholderFile = require_source_candidate_scan_signature.normalizeOutputPathKey(node_path.default.resolve(options.generatorPlaceholderFile)); return (asset, file) => { const cached = identityByAsset.get(asset); if (cached) return cached; const candidates = [ file, asset.originalFileName, ...asset.originalFileNames ?? [] ].filter((candidate) => typeof candidate === "string" && candidate.length > 0); const placeholderSourceFile = candidates.find((candidate) => require_source_candidate_scan_signature.normalizeOutputPathKey(node_path.default.resolve(candidate.replace(/[?#].*$/, ""))) === placeholderFile); let identity; if (placeholderSourceFile) identity = { kind: "generator-placeholder", sourceFile: placeholderSourceFile }; else identity = candidates.some(options.isKnownProcessedSource) ? { kind: "bundler-generated" } : { kind: "user" }; identityByAsset.set(asset, identity); return identity; }; } //#endregion //#region src/uni-app-x/style-asset/harmony-apply.ts const SFC_STYLE_BLOCK_RE$3 = /(<style\b[^>]*>)([\s\S]*?)(<\/style>)/gi; function createGeneratedRuleMap(css) { let root; try { root = _weapp_tailwindcss_postcss.postcss.parse(css); } catch { return; } const rules = /* @__PURE__ */ new Map(); root.walkRules((rule) => { if (rule.nodes && rule.nodes.length > 0) rules.set(rule.selector.trim(), rule.nodes.map((node) => node.clone())); }); return rules.size > 0 ? rules : void 0; } function expandUniAppXHarmonyApplyStyles(source, generatedCss) { if (!source.includes("@apply")) return source; const generatedRules = createGeneratedRuleMap(generatedCss); if (!generatedRules) return source; return source.replace(SFC_STYLE_BLOCK_RE$3, (block, open, styleSource, close) => { if (!styleSource.includes("@apply")) return block; let root; try { root = _weapp_tailwindcss_postcss.postcss.parse(styleSource); } catch { return block; } let changed = false; root.walkRules((rule) => { if (!(rule.nodes?.some((node) => node.type === "atrule" && node.name === "apply") === true)) return; const generatedNodes = generatedRules.get(rule.selector.trim()); if (!generatedNodes) return; rule.removeAll(); rule.append(generatedNodes.map((node) => node.clone())); changed = true; }); if (!changed) return block; if (!root.toString().includes("@apply")) root.walkAtRules("reference", (rule) => rule.remove()); return `${open}${root.toString()}${close}`; }); } //#endregion //#region src/uni-app-x/style-asset/style-value.ts const GEN_APP_STYLES_RE = /const\s+GenAppStyles\s*=\s*\[_uM\(\[([\s\S]*?)\]\)\]/; const STYLE_ENTRY_RE = /\[\s*("((?:\\.|[^"\\])+)")\s*,\s*(_pS\(_uM\(\[[\s\S]*?\]\)\))\s*\]/g; const STRING_LITERAL_RE = /(['"`])((?:\\.|(?!\1)[\s\S])*?)\1/g; const SFC_STYLE_BLOCK_RE$2 = /<style\b[^>]*>([\s\S]*?)<\/style>/gi; const STYLE_EXPORT_PREFIX_RE = /^\s*export\s+default\s+/; const CLASS_SELECTOR_PREFIX_RE = /^\.((?:\\[^\n\r\f]|[\w-])+)(?=$|[.:#[])/; function toCamelCase(prop) { return prop.replace(/-([a-z])/g, (_, char) => char.toUpperCase()); } function normalizeValue(value) { const trimmed = value.trim(); if (/^-?\d+(?:\.\d+)?px$/.test(trimmed)) return Number(trimmed.slice(0, -2)); return trimmed.replace(/\s*,\s*/g, ","); } function normalizeStyleValue(value) { if (typeof value === "number") return value; return normalizeValue(value); } function unescapeCssClassSelector(className) { return className.replace(/\\([^\n\r\f0-9a-f])/gi, "$1"); } function parseStyleExport(source) { const json = source.replace(STYLE_EXPORT_PREFIX_RE, "").trim(); if (!json) return; try { return JSON.parse(json); } catch {} } function parseStyleObject(source) { try { return JSON.parse(source); } catch {} } function parseSourceMapSourcesContent(source) { try { const map = JSON.parse(source); return Array.isArray(map.sourcesContent) ? map.sourcesContent.filter((item) => typeof item === "string") : []; } catch { return []; } } function collectChunkMapSourcesContent(chunk) { const map = chunk.map; return Array.isArray(map?.sourcesContent) ? map.sourcesContent.filter((item) => typeof item === "string") : []; } function styleExportToUtsMap(styleExport) { const classEntries = []; for (const [className, styleStates] of Object.entries(styleExport)) { const declarations = styleStates[""]; if (!declarations || Object.keys(declarations).length === 0) continue; const declarationEntries = Object.entries(declarations).map(([prop, value]) => { return `[${JSON.stringify(toCamelCase(prop))}, ${JSON.stringify(normalizeStyleValue(value))}]`; }); if (declarationEntries.length === 0) continue; classEntries.push(`[${JSON.stringify(className)}, _pS(_uM([${declarationEntries.join(", ")}]))]`); } if (classEntries.length === 0) return "[]"; return `[_uM([${classEntries.join(", ")}])]`; } function createUtsStyleArray(entries) { if (entries.length === 0) return "[]"; return `[_uM([${entries.join(", ")}])]`; } function extractAppStyleEntries(source) { const match = source.match(GEN_APP_STYLES_RE); if (!match?.[1]) return; const entries = /* @__PURE__ */ new Map(); for (const entry of match[1].matchAll(STYLE_ENTRY_RE)) { const rawClassName = entry[1]; const className = entry[2]; const styleValue = entry[3]; if (!rawClassName || !className || !styleValue) continue; entries.set(JSON.parse(rawClassName), `[${rawClassName}, ${styleValue}]`); } return entries.size > 0 ? entries : void 0; } function collectUsedClassNames(code, entries) { const used = /* @__PURE__ */ new Set(); for (const literalMatch of code.matchAll(STRING_LITERAL_RE)) { const literal = literalMatch[2]; if (!literal) continue; for (const candidate of (0, _tailwindcss_mangle_engine.splitCandidateTokens)(literal)) if (entries.has(candidate)) used.add(candidate); } return used; } function collectUsedStyleKeys(code, styleValue) { return collectUsedClassNames(code, new Map(Object.keys(styleValue).map((className) => [className, className]))); } function createUtsStyleArrayFromAppStyles(code, appSource) { if (!appSource) return; const entries = extractAppStyleEntries(appSource); if (!entries) return; const used = collectUsedClassNames(code, entries); if (used.size === 0) return; return createUtsStyleArray([...used].map((className) => entries.get(className)).filter(Boolean)); } function cssToStyleExport(source) { let root; try { root = _weapp_tailwindcss_postcss.postcss.parse(source); } catch { return; } const result = {}; root.walkRules((rule) => { const selectors = rule.selectors ?? []; for (const selector of selectors) { const match = selector.trim().match(CLASS_SELECTOR_PREFIX_RE); if (!match?.[1]) continue; const declarations = {}; rule.walkDecls((decl) => { declarations[toCamelCase(decl.prop)] = normalizeValue(decl.value); }); if (Object.keys(declarations).length > 0) { result[match[1]] = { "": declarations }; const className = unescapeCssClassSelector(match[1]); result[className] = { "": declarations }; result[require_wxml.replaceWxml(className)] = { "": declarations }; } } }); return Object.keys(result).length > 0 ? result : void 0; } function cssSourceToStyleValue(source) { return STYLE_EXPORT_PREFIX_RE.test(source) ? parseStyleExport(source) : cssToStyleExport(source); } function mergeStyleValues(...items) { const result = {}; for (const item of items) { if (!item) continue; for (const [className, states] of Object.entries(item)) if (!result[className]) result[className] = states; } return Object.keys(result).length > 0 ? result : void 0; } function createStyleValueFromApplySources(sources, utilityStyles) { if (!utilityStyles) return; const result = {}; for (const source of sources) { const styleSources = source.includes("<style") ? [...source.matchAll(SFC_STYLE_BLOCK_RE$2)].map((styleBlock) => styleBlock[1] ?? "") : [source]; for (const styleSource of styleSources) { let root; try { root = _weapp_tailwindcss_postcss.postcss.parse(styleSource); } catch { continue; } root.walkRules((rule) => { const applyRules = rule.nodes?.filter((node) => node.type === "atrule" && node.name === "apply") ?? []; if (applyRules.length === 0) return; const selectors = rule.selectors ?? [rule.selector]; for (const selector of selectors) { const className = selector.trim().match(CLASS_SELECTOR_PREFIX_RE)?.[1]; if (!className) continue; const declarations = {}; for (const applyRule of applyRules) for (const utility of (0, _tailwindcss_mangle_engine.splitCandidateTokens)(applyRule.params)) { const utilityDeclarations = utilityStyles[utility]?.[""] ?? utilityStyles[require_wxml.replaceWxml(utility)]?.[""]; if (utilityDeclarations) Object.assign(declarations, utilityDeclarations); } if (Object.keys(declarations).length > 0) { const unescapedClassName = unescapeCssClassSelector(className); result[className] = { "": declarations }; result[unescapedClassName] = { "": declarations }; result[require_wxml.replaceWxml(unescapedClassName)] = { "": declarations }; } } }); } } return Object.keys(result).length > 0 ? result : void 0; } function resolveReferencePaths(styleSource, sourceId) { if (!sourceId || !styleSource.includes("@reference")) return styleSource; let root; try { root = _weapp_tailwindcss_postcss.postcss.parse(styleSource); } catch { return styleSource; } const cleanSourceId = sourceId.replace(/\?.*$/, ""); root.walkAtRules("reference", (rule) => { const quote = rule.params[0]; if (quote !== "\"" && quote !== "'") return; const closingQuoteIndex = rule.params.indexOf(quote, 1); if (closingQuoteIndex <= 1) return; const referencePath = rule.params.slice(1, closingQuoteIndex); if (!referencePath.startsWith(".")) return; rule.params = `${quote}${node_path.default.resolve(node_path.default.dirname(cleanSourceId), referencePath)}${quote}${rule.params.slice(closingQuoteIndex + 1)}`; }); return root.toString(); } function collectUniAppXHarmonyApplyStyleSourcesFromSource(source, sourceId) { return (source.includes("<style") ? [...source.matchAll(SFC_STYLE_BLOCK_RE$2)].map((styleBlock) => styleBlock[1] ?? "") : [source]).map((styleSource) => resolveReferencePaths(styleSource.trim(), sourceId)).filter((styleSource) => styleSource.length > 0 && styleSource.includes("@apply")); } function collectUniAppXHarmonyApplyUtilitiesFromSources(sources) { const utilities = /* @__PURE__ */ new Set(); for (const source of sources) for (const styleSource of collectUniAppXHarmonyApplyStyleSourcesFromSource(source)) { let root; try { root = _weapp_tailwindcss_postcss.postcss.parse(styleSource); } catch { continue; } root.walkAtRules("apply", (rule) => { for (const utility of (0, _tailwindcss_mangle_engine.splitCandidateTokens)(rule.params)) utilities.add(utility); }); } return utilities; } function createMergedStyleValue(code, localStyle, appStyle) { const used = collectUsedStyleKeys(code, appStyle); if (used.size === 0) return; const merged = { ...localStyle ?? {} }; let changed = false; for (const className of used) { if (merged[className] || !appStyle[className]) continue; merged[className] = appStyle[className]; changed = true; } return changed ? merged : void 0; } function createMergedStyleValues(code, localStyles, appStyle) { if (localStyles.length === 0) return; const used = collectUsedStyleKeys(code, appStyle); if (used.size === 0) return; const merged = localStyles.map((style) => ({ ...style })); let changed = false; for (const className of used) { const generatedStyle = appStyle[className]; if (!generatedStyle) continue; const indexes = merged.flatMap((style, index) => style[className] ? [index] : []); if (indexes.length === 0) { merged[0][className] = generatedStyle; changed = true; continue; } for (const index of indexes) { if (JSON.stringify(merged[index][className]) === JSON.stringify(generatedStyle)) continue; merged[index][className] = generatedStyle; changed = true; } } return changed ? merged : void 0; } //#endregion //#region src/uni-app-x/style-asset.ts const GEN_STYLES_PLACEHOLDER_RE = /\/\*(Gen[A-Za-z0-9]+Styles)\*\/|const\s+(Gen[A-Za-z0-9]+Styles)\s*=\s*\[\]/; const UVUE_TS_RE = /\.uvue\.ts$/; const JS_RE = /\.js$/; const APP_JS_RE = /(?:^|\/)App\.js$/; const COMPONENT_JS_RE = /(?:^|\/)components\/.+\.js$/; const HARMONY_BUNDLE_MARKER_FILES = /* @__PURE__ */ new Set([ "import/app-service.ets", "import/dynamic.ets", "uni_modules/oh-package.json5" ]); const STYLE_DECL_RE = /const\s+(_style_\d+)\s*=\s*\{/g; const EXPORT_SFC_RE = /_export_sfc\(_sfc_main\s*,\s*\[/; const UNI_APP_X_STYLE_PLACEHOLDER_VERSION = "uni-app-x-style-placeholder-v3"; function createUniAppXHarmonyApplyGeneratorSource(applyStyleSources, _applyUtilities) { return applyStyleSources.map((source) => { let root; try { root = _weapp_tailwindcss_postcss.postcss.parse(source); } catch { return source; } root.walkAtRules("reference", (rule) => { if (rule.params.match(/^(['"])(.+?)\1/)?.[2]?.startsWith(".")) rule.remove(); }); return root.toString(); }).join("\n"); } function collectUniAppXHarmonyApplyUtilities(bundle) { const utilities = /* @__PURE__ */ new Set(); const getBundleSource = createUniAppXBundleAssetSourceGetter(bundle); for (const [file, item] of Object.entries(bundle)) { if (item.type !== "chunk" || !file.endsWith(".js") || APP_JS_RE.test(file)) continue; const mapSources = collectChunkMapSourcesContent(item).concat(resolveSourceMapFiles(file).flatMap((mapFile) => { const source = getBundleSource(mapFile); return source ? parseSourceMapSourcesContent(source) : []; })); for (const source of mapSources) for (const utility of collectUniAppXHarmonyApplyUtilitiesFromSources([source])) utilities.add(utility); } return utilities; } function collectUniAppXHarmonyApplyStyleSources(bundle) { const sources = /* @__PURE__ */ new Set(); const getBundleSource = createUniAppXBundleAssetSourceGetter(bundle); const addSource = (source) => { for (const styleSource of collectUniAppXHarmonyApplyStyleSourcesFromSource(source)) sources.add(styleSource); }; for (const [file, item] of Object.entries(bundle)) { if (item.type === "asset" && file.endsWith(".uvue")) { addSource(String(item.source)); continue; } if (item.type !== "chunk" || !file.endsWith(".js") || APP_JS_RE.test(file)) continue; for (const sourceContent of collectChunkMapSourcesContent(item)) addSource(sourceContent); for (const mapFile of resolveSourceMapFiles(file)) { const source = getBundleSource(mapFile); if (!source) continue; for (const sourceContent of parseSourceMapSourcesContent(source)) addSource(sourceContent); } } return [...sources]; } function resolveStyleAssetFile(file) { if (!UVUE_TS_RE.test(file)) return; return file.replace(/\.uvue\.ts$/, ".uvue"); } function resolveStylePlaceholderFallbackFiles(file) { const styleAssetFile = resolveStyleAssetFile(file); if (!styleAssetFile) return []; const base = styleAssetFile.replace(/\.uvue$/, ""); return [ styleAssetFile, `${base}.wxss`, `${base}.css` ]; } function findBalancedObjectEnd(source, start) { let depth = 0; let quote; let escaped = false; for (let index = start; index < source.length; index++) { const char = source[index]; if (quote) { if (escaped) escaped = false; else if (char === "\\") escaped = true; else if (char === quote) quote = void 0; continue; } if (char === "\"" || char === "'" || char === "`") { quote = char; continue; } if (char === "{") { depth++; continue; } if (char === "}") { depth--; if (depth === 0) return index + 1; } } } function findStyleObjectDecls(source) { STYLE_DECL_RE.lastIndex = 0; const declarations = []; for (const match of source.matchAll(STYLE_DECL_RE)) { const varName = match[1]; if (!varName || match.index === void 0) continue; const objectStart = source.indexOf("{", match.index); if (objectStart < 0) continue; const objectEnd = findBalancedObjectEnd(source, objectStart); if (!objectEnd) continue; const semicolonEnd = source[objectEnd] === ";" ? objectEnd + 1 : objectEnd; declarations.push({ end: semicolonEnd, objectEnd, objectStart, objectText: source.slice(objectStart, objectEnd), start: match.index, varName }); } return declarations; } function resolveCssFallbackFiles(styleAssetFiles = []) { const files = /* @__PURE__ */ new Set(); for (const assetFile of styleAssetFiles) if (assetFile) files.add(assetFile); return [...files]; } function resolveStyleAssetFilesForChunk(file, styleAssetFiles) { return typeof styleAssetFiles === "function" ? styleAssetFiles(file) : styleAssetFiles; } function resolveSourceMapFiles(file) { return [ `${file}.map`, file.startsWith("assets/") ? `${file.slice(7)}.map` : void 0, file.startsWith("assets/") ? void 0 : `assets/${file}.map` ].filter((item) => typeof item === "string"); } function createStyleValueFromBundleSources(file, _code, getBundleSource, options = {}) { const cssStyles = mergeStyleValues(...[...options.cssSources ?? []].map((source) => source ? cssSourceToStyleValue(source) : void 0), ...resolveCssFallbackFiles(resolveStyleAssetFilesForChunk(file, options.styleAssetFiles)).map((cssFile) => { const source = getBundleSource?.(cssFile); return source ? cssSourceToStyleValue(source) : void 0; })); return mergeStyleValues(cssStyles, createStyleValueFromApplySources([...options.mapSources ?? [], ...resolveSourceMapFiles(file).flatMap((mapFile) => { const source = getBundleSource?.(mapFile); return source ? parseSourceMapSourcesContent(source) : []; })].filter((source) => typeof source === "string"), cssStyles)); } function injectStyleOption(code, styleVarName) { const styleOptionMatch = code.match(/(\["styles"\s*,\s*\[)([^\]]*)(\]\])/); if (styleOptionMatch?.index !== void 0) { const styleVars = styleOptionMatch[2]?.trim(); if (styleVars?.split(",").map((item) => item.trim()).includes(styleVarName)) return code; const replacement = `${styleOptionMatch[1]}${styleVars ? `${styleVars}, ` : ""}${styleVarName}${styleOptionMatch[3]}`; return `${code.slice(0, styleOptionMatch.index)}${replacement}${code.slice(styleOptionMatch.index + styleOptionMatch[0].length)}`; } const exportMatch = code.match(EXPORT_SFC_RE); if (!exportMatch || exportMatch.index === void 0) return code; const fileOptionIndex = code.indexOf("[\"__file\"", exportMatch.index); if (fileOptionIndex < 0) return code; return `${code.slice(0, fileOptionIndex)}["styles", [${styleVarName}]], ${code.slice(fileOptionIndex)}`; } function injectUniAppXStylePlaceholder(file, code, getAssetSource, cssSources = []) { const match = code.match(GEN_STYLES_PLACEHOLDER_RE); const stylesName = match?.[1] ?? match?.[2]; if (!stylesName) return code; if (!resolveStyleAssetFile(file)) return code; const appStyleArray = createUtsStyleArrayFromAppStyles(code, getAssetSource?.("App.uvue.ts")); const fallbackStyleSources = resolveStylePlaceholderFallbackFiles(file).map((candidate) => getAssetSource?.(candidate)); const styleExport = mergeStyleValues(...[...cssSources, ...fallbackStyleSources].map((source) => source ? cssSourceToStyleValue(source) : void 0)); const styleArrays = [appStyleArray, styleExport ? styleExportToUtsMap(styleExport) : void 0].filter((item) => Boolean(item)); if (styleArrays.length === 0) return code; const mergedStyleArray = styleArrays.length === 1 ? styleArrays[0] : `[${styleArrays.map((item) => item.slice(1, -1)).filter(Boolean).join(", ")}]`; return code.replace(GEN_STYLES_PLACEHOLDER_RE, `const ${stylesName} = ${mergedStyleArray}`); } function injectUniAppXHarmonyGlobalStyles(file, code, getBundleSource, options = {}) { if (!JS_RE.test(file) || APP_JS_RE.test(file)) return code; if (options.excludeComponents && COMPONENT_JS_RE.test(file)) return code; const appSource = getBundleSource?.("assets/App.js") ?? getBundleSource?.("App.js"); const appStyle = appSource ? mergeStyleValues(...findStyleObjectDecls(appSource).map((decl) => parseStyleObject(decl.objectText))) : void 0; const parseableLocalStyles = findStyleObjectDecls(code).flatMap((decl) => { const style = parseStyleObject(decl.objectText); return style ? [{ decl, style }] : []; }); const styleSource = mergeStyleValues(createStyleValueFromBundleSources(file, code, getBundleSource, options), appStyle); if (!styleSource) return code; const mergedStyles = createMergedStyleValues(code, parseableLocalStyles.map((item) => item.style), styleSource); if (mergedStyles) { let nextCode = code; for (let index = parseableLocalStyles.length - 1; index >= 0; index--) { const decl = parseableLocalStyles[index].decl; nextCode = `${nextCode.slice(0, decl.objectStart)}${JSON.stringify(mergedStyles[index])}${nextCode.slice(decl.objectEnd)}`; } return nextCode; } if (parseableLocalStyles.length > 0) return code; const newStyle = createMergedStyleValue(code, void 0, styleSource); if (!newStyle) return code; const exportMatch = code.match(EXPORT_SFC_RE); if (!exportMatch || exportMatch.index === void 0) return code; const styleVarName = "_style_wt"; return injectStyleOption(`${code.slice(0, exportMatch.index)}const ${styleVarName} = ${JSON.stringify(newStyle)};\n${code.slice(exportMatch.index)}`, styleVarName); } function injectUniAppXHarmonyBundleStyles(bundle, options = {}) { const getBundleSource = createUniAppXBundleAssetSourceGetter(bundle); const styleAssetFilesByChunk = collectUniAppXBundleStyleAssetFilesByChunk(bundle); const resolveStyleAssetFiles = typeof options.styleAssetFiles === "function" ? options.styleAssetFiles : (file) => [...options.styleAssetFiles ?? [], ...styleAssetFilesByChunk.get(file) ?? []]; let changed = false; for (const [file, item] of Object.entries(bundle)) { if (item.type !== "chunk" || !file.endsWith(".js")) continue; const currentSource = item.code; const nextSource = injectUniAppXHarmonyGlobalStyles(file, currentSource, getBundleSource, { ...options, styleAssetFiles: resolveStyleAssetFiles, mapSources: collectChunkMapSourcesContent(item) }); if (nextSource !== currentSource) { item.code = nextSource; changed = true; } } return changed; } function collectUniAppXBundleStyleAssetFilesByChunk(bundle) { const styleAssetFilesByChunk = /* @__PURE__ */ new Map(); const appStyleAssetFiles = /* @__PURE__ */ new Set(); const assetFiles = new Set(Object.entries(bundle).filter(([, item]) => item.type === "asset").map(([file]) => file).filter(isStyleAssetFile)); for (const [chunkFile, item] of Object.entries(bundle)) { if (item.type !== "chunk") continue; const chunk = item; for (const cssFile of chunk.viteMetadata?.importedCss ?? []) { if (!assetFiles.has(cssFile)) continue; if (APP_JS_RE.test(chunk.fileName ?? chunkFile) || APP_JS_RE.test(chunkFile)) { appStyleAssetFiles.add(cssFile); continue; } let styleAssetFiles = styleAssetFilesByChunk.get(chunkFile); if (!styleAssetFiles) { styleAssetFiles = /* @__PURE__ */ new Set(); styleAssetFilesByChunk.set(chunkFile, styleAssetFiles); } styleAssetFiles.add(cssFile); } } if (appStyleAssetFiles.size > 0) for (const [file, item] of Object.entries(bundle)) { if (item.type !== "chunk" || !file.endsWith(".js") || APP_JS_RE.test(file)) continue; let styleAssetFiles = styleAssetFilesByChunk.get(file); if (!styleAssetFiles) { styleAssetFiles = /* @__PURE__ */ new Set(); styleAssetFilesByChunk.set(file, styleAssetFiles); } for (const appStyleAssetFile of appStyleAssetFiles) styleAssetFiles.add(appStyleAssetFile); } return styleAssetFilesByChunk; } function isStyleAssetFile(file) { return /\.(?:acss|css|jxss|qss|ttss|wxss)$/i.test(file); } function isUniAppXHarmonyBundle(bundle) { for (const file of Object.keys(bundle)) if (HARMONY_BUNDLE_MARKER_FILES.has(file)) return true; return false; } function createUniAppXBundleAssetSourceGetter(bundle) { return (file) => { const item = bundle[file] ?? Object.entries(bundle).find(([key, value]) => { if (value.type !== "asset" && value.type !== "chunk") return false; const outputFile = value.fileName || key; return key === file || key.endsWith(`/${file}`) || outputFile === file || outputFile.endsWith(`/${file}`); })?.[1]; if (!item) return; if (item.type === "asset") return String(item.source); if (item.type === "chunk") return String(item.code); }; } //#endregion //#region src/bundlers/vite/bundle-entries.ts function readOutputEntry(entry) { if (entry.output.type === "chunk") return entry.output.code; const source = entry.output.source; if (typeof source === "string") return source; if (source instanceof Uint8Array) return node_buffer.Buffer.from(source).toString(); const fallbackSource = source; if (fallbackSource == null) return; if (typeof fallbackSource.toString === "function") return fallbackSource.toString(); } function isJavaScriptEntry(entry) { if (entry.output.type === "chunk") return true; return entry.fileName.endsWith(".js"); } function createBundleModuleGraphOptions(outputDir, entries) { const normalizedEntries = /* @__PURE__ */ new Map(); for (const [id, entry] of entries) normalizedEntries.set(require_source_candidate_scan_signature.normalizeOutputPathKey(id), entry); const getEntry = (id) => entries.get(id) ?? normalizedEntries.get(require_source_candidate_scan_signature.normalizeOutputPathKey(id)); return { resolve(specifier, importer) { return require_source_candidate_scan_signature.resolveOutputSpecifier(specifier, importer, outputDir, (candidate) => Boolean(getEntry(candidate))); }, load(id) { const entry = getEntry(id); if (!entry) return; return readOutputEntry(entry); }, filter(id) { return Boolean(getEntry(id)); } }; } function applyLinkedResults(linked, entries, onLinkedUpdate, onApplied) { if (!linked) return; const normalizedEntries = /* @__PURE__ */ new Map(); for (const [entryId, entry] of entries) normalizedEntries.set(require_source_candidate_scan_signature.normalizeOutputPathKey(entryId), entry); for (const [id, { code }] of Object.entries(linked)) { const entry = entries.get(id) ?? normalizedEntries.get(require_source_candidate_scan_signature.normalizeOutputPathKey(id)); if (!entry) continue; const previous = readOutputEntry(entry); if (previous == null || previous === code) continue; if (entry.output.type === "chunk") entry.output.code = code; else entry.output.source = code; onApplied?.(entry, code); onLinkedUpdate(entry.fileName, previous, code); } } //#endregion //#region src/bundlers/vite/runtime-candidate-entry.ts const VENDOR_CHUNK_BASENAME_RE = /^(?:vendor|vendors|chunk-vendors|common_vendor)(?:[.-]|$)/i; const COMMON_VENDOR_CHUNK_RE = /^(?:common|static|assets|chunks?)\/(?:vendor|vendors|chunk-vendors|common_vendor|runtime)(?:[.-]|$)/i; function toPosixPath(value) { return value.split("\\").join("/"); } function isDependencyModuleId(id) { const normalized = toPosixPath(id); return normalized.includes("/node_modules/") || normalized.includes("/.pnpm/") || normalized.includes("/node_modules_"); } function collectChunkModuleIds$3(output) { return [...output.moduleIds ?? [], ...Object.keys(output.modules ?? {})].filter((id, index, ids) => ids.indexOf(id) === index); } function isKnownVendorChunkFile(file) { const normalized = toPosixPath(file).replace(/^\.\//, ""); const basename = normalized.slice(normalized.lastIndexOf("/") + 1); return VENDOR_CHUNK_BASENAME_RE.test(basename) || COMMON_VENDOR_CHUNK_RE.test(normalized) || normalized.includes("/node_modules/") || normalized.includes("/node_modules_"); } function isDependencyOnlyChunk(output) { if (output.isEntry || output.isDynamicEntry || output.isImplicitEntry) return false; const moduleIds = collectChunkModuleIds$3(output); return moduleIds.length > 0 && moduleIds.every(isDependencyModuleId); } function isRuntimeCandidateBundleEntry(entry) { if (entry.type === "html") return true; if (entry.type !== "js") return false; if (entry.output.type === "chunk" && isDependencyOnlyChunk(entry.output)) return false; if (!isKnownVendorChunkFile(entry.file)) return true; if (entry.output.type !== "chunk") return false; if (entry.output.facadeModuleId && !isDependencyModuleId(entry.output.facadeModuleId)) return true; return collectChunkModuleIds$3(entry.output).some((id) => !isDependencyModuleId(id)); } //#endregion //#region src/bundlers/vite/bundle-state.ts const removedBundleFilesStorage = new node_async_hooks.AsyncLocalStorage(); function runWithRemovedBundleFiles(removedFiles, run) { return removedBundleFilesStorage.run(removedFiles, run); } function createBundleBuildState() { return require_hmr_timing.createRuntimeCompilationBuildState(); } function readEntrySource(output) { if (output.type === "chunk") return output.code; return typeof output.source === "string" ? output.source : node_buffer.Buffer.from(output.source).toString(); } function classifyBundleEntry(file, opts) { return require_source_candidate_scan_signature.classifyRuntimeEntry(file, opts); } function collectJsEntry(fileName, output, outDir, store) { const entry = { fileName, output }; if (!isJavaScriptEntry(entry)) return; const absolute = require_source_candidate_scan_signature.toAbsoluteOutputPath(fileName, outDir); store.set(absolute, entry); } function collectBundleEntries(bundle, opts, outDir) { const jsEntries = /* @__PURE__ */ new Map(); const entries = []; for (const [file, output] of Object.entries(bundle)) { const type = classifyBundleEntry(file, opts); const entry = { file, output, source: readEntrySource(output), type }; entry.runtimeCandidate = isRuntimeCandidateBundleEntry(entry); collectJsEntry(file, output, outDir, jsEntries); entries.push(entry); } return { entries, jsEntries }; } function buildBundleSnapshot(bundle, opts, outDir, state, forceAll = false, options = {}) { const { entries, jsEntries } = collectBundleEntries(bundle, opts, outDir); return { ...require_hmr_timing.buildRuntimeCompilationSnapshot(entries, state, { computeHash: (source) => opts.cache.computeHash(source), createRuntimeAffectingSignature: require_v4_generation_core.createRuntimeAffectingSourceSignature, forceAll, hasOmittedKnownFiles: options.hasOmittedKnownFiles, removedFiles: options.removedFiles ?? removedBundleFilesStorage.getStore() }), jsEntries }; } function updateBundleBuildState(state, snapshot, linkedByEntry, options = {}) { require_hmr_timing.updateRuntimeCompilationBuildState(state, snapshot, linkedByEntry, options); } //#endregion //#region ../../node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs let _lazyMatch = () => { var __lib__ = (() => { var m = Object.defineProperty, V = Object.getOwnPropertyDescriptor, G = Object.getOwnPropertyNames, T = Object.prototype.hasOwnProperty, q = (r, e) => { for (var n in e) m(r, n, { get: e[n], enumerable: true }); }, H = (r, e, n, a) => { if (e && typeof e == "object" || typeof e == "function") for (let t of G(e)) !T.call(r, t) && t !== n && m(r, t, { get: () => e[t], enumerable: !(a = V(e, t)) || a.enumerable }); return r; }, J = (r) => H(m({}, "__esModule", { value: true }), r), w = {}; q(w, { default: () => re }); var A = (r) => Array.isArray(r), d = (r) => typeof r == "function", Q = (r) => r.length === 0, W = (r) => typeof r == "number", K = (r) => typeof r == "object" && r !== null, X = (r) => r instanceof RegExp, b = (r) => typeof r == "string", h = (r) => r === void 0, Y = (r) => { const e = /* @__PURE__ */ new Map(); return (n) => { const a = e.get(n); if (a) return a; const t = r(n); return e.set(n, t), t; }; }, rr = (r, e, n = {}) => { const a = { cache: {}, input: r, index: 0, indexMax: 0, options: n, output: [] }; if (v(e)(a) && a.index === r.length) return a.output; throw new Error(`Failed to parse at index ${a.indexMax}`); }, i = (r, e) => A(r) ? er(r, e) : b(r) ? ar(r, e) : nr(r, e), er = (r, e) => { const n = {}; for (const a of r) { if (a.length !== 1) throw new Error(`Invalid character: "${a}"`); const t = a.charCodeAt(0); n[t] = true; } return (a) => { const t = a.index, o = a.input; for (; a.index < o.length && o.charCodeAt(a.index) in n;) a.index += 1; const u = a.index; if (u > t) { if (!h(e) && !a.options.silent) { const s = a.input.slice(t, u), c = d(e) ? e(s, o, String(t)) : e; h(c) || a.output.push(c); } a.indexMax = Math.max(a.indexMax, a.index); } return true; }; }, nr = (r, e) => { const n = r.source, a = r.flags.replace(/y|$/, "y"), t = new RegExp(n, a); return g((o) => { t.lastIndex = o.index; const u = t.exec(o.input); if (u) { if (!h(e) && !o.options.silent) { const s = d(e) ? e(...u, o.input, String(o.index)) : e; h(s) || o.output.push(s); } return o.index += u[0].length, o.indexMax = Math.max(o.indexMax, o.index), true; } else return false; }); }, ar = (r, e) => (n) => { if (n.input.startsWith(r, n.index)) { if (!h(e) && !n.options.silent) { const t = d(e) ? e(r, n.input, String(n.index)) : e; h(t) || n.output.push(t); } return n.index += r.length, n.indexMax = Math.max(n.indexMax, n.index), true; } else return false; }, C = (r, e, n, a) => { const t = v(r); return g(_(M((o) => { let u = 0; for (; u < n;) { const s = o.index; if (!t(o) || (u += 1, o.index === s)) break; } return u >= e; }))); }, tr = (r, e) => C(r, 0, 1), f = (r, e) => C(r, 0, Infinity), x = (r, e) => { const n = r.map(v); return g(_(M((a) => { for (let t = 0, o = n.length; t < o; t++) if (!n[t](a)) return false; return true; }))); }, l = (r, e) => { const n = r.map(v); return g(_((a) => { for (let t = 0, o = n.length; t < o; t++) if (n[t](a)) return true; return false; })); }, M = (r, e = false) => { const n = v(r); return (a) => { const t = a.index, o = a.output.length, u = n(a); return (!u || e) && (a.index = t, a.output.length !== o && (a.output.length = o)), u; }; }, _ = (r, e) => { return v(r); }, g = (() => { let r = 0; return (e) => { const n = v(e), a = r += 1; return (t) => { var o; if (t.options.memoization === false) return n(t); const u = t.index, s = (o = t.cache)[a] || (o[a] = /* @__PURE__ */ new Map()), c = s.get(u); if (c === false) return false; if (W(c)) return t.index = c, true; if (c) return t.index = c.index, c.output?.length && t.output.push(...c.output), true; { const Z = t.output.length; if (n(t)) { const D = t.index, U = t.output.length; if (U > Z) { const ee = t.output.slice(Z, U); s.set(u, { index: D, output: ee }); } else s.set(u, D); return true; } else return s.set(u, false), false; } }; }; })(), E = (r) => { let e; return (n) => (e || (e = v(r())), e(n)); }, v = Y((r) => { if (d(r)) return Q(r) ? E(r) : r; if (b(r) || X(r)) return i(r); if (A(r)) return x(r); if (K(r)) return l(Object.values(r)); throw new Error("Invalid rule"); }), P = "abcdefghijklmnopqrstuvwxyz", ir = (r) => { let e = ""; for (; r > 0;) e = P[(r - 1) % 26] + e, r = Math.floor((r - 1) / 26); return e; }, O = (r) => { let e = 0; for (let n = 0, a = r.length; n < a; n++) e = e * 26 + P.indexOf(r[n]) + 1; return e; }, S = (r, e) => { if (e < r) return S(e, r); const n = []; for (; r <= e;) n.push(r++); return n; }, or = (r, e, n) => S(r, e).map((a) => String(a).padStart(n, "0")), R = (r, e) => S(O(r), O(e)).map(ir), p = (r) => r, z = (r) => ur((e) => rr(e, r, { memoization: false }).join("")), ur = (r) => { const e = {}; return (n) => e[n] ?? (e[n] = r(n)); }, sr = i(/^\*\*\/\*$/, ".*"), cr = i(/^\*\*\/(\*)?([ a-zA-Z0-9._-]+)$/, (r, e, n) => `.*${e ? "" : "(?:^|/)"}${n.replaceAll(".", "\\.")}`), lr = i(/^\*\*\/(\*)?([ a-zA-Z0-9._-]*)\{([ a-zA-Z0-9._-]+(?:,[ a-zA-Z0-9._-]+)*)\}$/, (r, e, n, a) => `.*${e ? "" : "(?:^|/)"}${n.replaceAll(".", "\\.")}(?:${a.replaceAll(",", "|").replaceAll(".", "\\.")})`), y = i(/\\./, p), pr = i(/[$.*+?^(){}[\]\|]/, (r) => `\\${r}`), vr = i(/./, p), fr = l([i(/^(?:!!)*!(.*)$/, (r, e) => `(?!^${L(e)}$).*?`), i(/^(!!)+/, "")]), j = l([ i(/\/(\*\*\/)+/, "(?:/.+/|/)"), i(/^(\*\*\/)+/, "(?:^|.*/)"), i(/\/(\*\*)$/, "(?:/.*|$)"), i(/\*\*/, ".*") ]), N = l([i(/\*\/(?!\*\*\/)/, "[^/]*/"), i(/\*/, "[^/]*")]), k = i("?", "[^/]"), $r = i("[", p), wr = i("]", p), Ar = i(/[!^]/, "^/"), br = i(/[a-z]-[a-z]|[0-9]-[0-9]/i, p), Er = l([ y, i(/[$.*+?^(){}[\|]/, (r) => `\\${r}`), br, i(/[^\]]/, p) ]), B = x([ $r, tr(Ar), f(Er), wr ]), Pr = i("{", "(?:"), Or = i("}", ")"), I = x([ Pr, l([ i(/(\d+)\.\.(\d+)/, (r, e, n) => or(+e, +n, Math.min(e.length, n.length)).join("|")), i(/([a-z]+)\.\.([a-z]+)/, (r, e, n) => R(e, n).join("|")), i(/([A-Z]+)\.\.([A-Z]+)/, (r, e, n) => R(e.toLowerCase(), n.toLowerCase()).join("|").toUpperCase()) ]), Or ]), kr = i("{", "(?:"), Br = i("}", ")"), Ir = i(",", "|"), Fr = i(/[$.*+?^(){[\]\|]/, (r) => `\\${r}`), Lr = i(/[^}]/, p), F = x([ kr, f(l([ j, N, k, B, I, E(() => F), y, Fr, Ir, Lr ])), Br ]), L = z(f(l([ sr, cr, lr, fr, j, N, k, B, I, F, y, pr, vr ]))), Tr = i(/\\./, p), qr = i(/./, p), Yr = z(f(l([ Tr, i(/\*\*\*+/, "*"), i(/([^/{[(!])\*\*/, (r, e) => `${e}*`), i(/(^|.)\*\*(?=[^*/)\]}])/, (r, e) => `${e}*`), qr ]))), $ = (r, e) => { const n = Array.isArray(r) ? r : [r]; if (!n.length) return false; const a = n.map($.compile), t = n.every((s) => /(\/(?:\*\*)?|\[\/\])$/.test(s)), o = e.replace(/[\\\/]+/g, "/").replace(/\/$/, t ? "/" : ""); return a.some((s) => s.test(o)); }; $.compile = (r) => new RegExp(`^${L(Yr(r))}$`, "s"); var re = $; return J(w); })(); return __lib__.default || __lib__; }; let _match; const zeptomatch = (path, pattern) => { if (!_match) { _match = _lazyMatch(); _lazyMatch = null; } return _match(path, pattern); }; const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//; function normalizeWindowsPath(input = "") { if (!input) return input; return input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase()); } const _UNC_REGEX = /^[/\\]{2}/; const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/; const _DRIVE_LETTER_RE = /^[A-Za-z]:$/; const _ROOT_FOLDER_RE = /^\/([A-Za-z]:)?$/; const _EXTNAME_RE = /.(\.[^./]+|\.)$/; const _PATH_ROOT_RE = /^[/\\]|^[a-zA-Z]:[/\\]/; const normalize = function(path) { if (path.length === 0) return "."; path = normalizeWindowsPath(path); const isUNCPath = path.match(_UNC_REGEX); const isPathAbsolute = isAbsolute(path); const trailingSeparator = path[path.length - 1] === "/"; path = normalizeString(path, !isPathAbsolute); if (path.length === 0) { if (isPathAbsolute) return "/"; return trailingSeparator ? "./" : "."; } if (trailingSeparator) path += "/"; if (_DRIVE_LETTER_RE.test(path)) path += "/"; if (isUNCPath) { if (!isPathAbsolute) return `//./${path}`; return `//${path}`; } return isPathAbsolute && !isAbsolute(path) ? `/${path}` : path; }; const join = function(...segments) { let path = ""; for (const seg of segments) { if (!seg) continue; if (path.length > 0) { const pathTrailing = path[path.length - 1] === "/"; const segLeading = seg[0] === "/"; if (pathTrailing && segLeading) path += seg.slice(1); else path += pathTrailing || segLeading ? seg : `/${seg}`; } else path += seg; } return normalize(path); }; function cwd() { if (typeof process !== "undefined" && typeof process.cwd === "function") return process.cwd().replace(/\\/g, "/"); return "/"; } const resolve = function(...arguments_) { arguments_ = arguments_.map((argument) => normalizeWindowsPath(argument)); let resolvedPath = ""; let resolvedAbsolute = false; for (let index = arguments_.length - 1; index >= -1 && !resolvedAbsolute; index--) { const path = index >= 0 ? arguments_[index] : cwd(); if (!path || path.length === 0) continue; resolvedPath = `${path}/${resolvedPath}`; resolvedAbsolute = isAbsolute(path); } resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute); if (resolvedAbsolute && !isAbsolute(resolvedPath)) return `/${resolvedPath}`; return resolvedPath.length > 0 ? resolvedPath : "."; }; function normalizeString(path, allowAboveRoot) { let res = ""; let lastSegmentLength = 0; let lastSlash = -1; let dots = 0; let char = null; for (let index = 0; index <= path.length; ++index) { if (index < path.length) char = path[index]; else if (char === "/") break; else char = "/"; if (char === "/") { if (lastSlash === index - 1 || dots === 1); else if (dots === 2) { if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") { if (res.length > 2) { const lastSlashIndex = res.lastIndexOf("/"); if (lastSlashIndex === -1) { res = ""; lastSegmentLength = 0; } else { res = res.slice(0, lastSlashIndex); lastSegmentLength = res.length - 1 - res.lastIndexOf("/"); } lastSlash = index; dots = 0; continue; } else if (res.length > 0) { res = ""; lastSegmentLength = 0; lastSlash = index; dots = 0; continue; } } if (allowAboveRoot) { res += res.length > 0 ? "/.." : ".."; lastSegmentLength = 2; } } else { if (res.length > 0) res += `/${path.slice(lastSlash + 1, index)}`; else res = path.slice(lastSlash + 1, index); lastSegmentLength = index - lastSlash - 1; } lastSlash = index; dots = 0; } else if (char === "." && dots !== -1) ++dots; else dots = -1; } return res; } const isAbsolute = function(p) { return _IS_ABSOLUTE_RE.test(p); }; const toNamespacedPath = function(p) { return normalizeWindowsPath(p); }; const extname = function(p) { if (p === "..") return ""; const match = _EXTNAME_RE.exec(normalizeWindowsPath(p)); return match && match[1] || ""; }; const relative = function(from, to) { cons