@vizejs/vite-plugin-musea 0.502.0 → 0.503.0
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/a11y/index.d.mts +1 -1
- package/dist/cli/index.d.mts +3 -1
- package/dist/cli/index.d.mts.map +1 -1
- package/dist/cli/index.mjs +19 -2
- package/dist/cli/index.mjs.map +1 -1
- package/dist/{index-BXI8gTfW.d.mts → index-CYEDgY-M.d.mts} +3 -3
- package/dist/{index-BXI8gTfW.d.mts.map → index-CYEDgY-M.d.mts.map} +1 -1
- package/dist/{index-CPq3wpG5.d.mts → index-CbChC9Bf.d.mts} +16 -2
- package/dist/{index-CPq3wpG5.d.mts.map → index-CbChC9Bf.d.mts.map} +1 -1
- package/dist/index.d.mts +3 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +25 -51
- package/dist/index.mjs.map +1 -1
- package/dist/{options-BRid4Hkx.mjs → options-BwF3nGEB.mjs} +241 -121
- package/dist/options-BwF3nGEB.mjs.map +1 -0
- package/dist/{vrt-DdWm07iR.mjs → vrt-C7wgh92N.mjs} +5 -3
- package/dist/vrt-C7wgh92N.mjs.map +1 -0
- package/dist/{vrt-CLASQfpd.d.mts → vrt-DNoUalLH.d.mts} +2 -2
- package/dist/{vrt-CLASQfpd.d.mts.map → vrt-DNoUalLH.d.mts.map} +1 -1
- package/dist/vrt.d.mts +1 -1
- package/dist/vrt.mjs +1 -1
- package/package.json +4 -4
- package/dist/options-BRid4Hkx.mjs.map +0 -1
- package/dist/vrt-DdWm07iR.mjs.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { E as loadNative, S as resolveTrustedSourcePath, T as analyzeSfcFallback, f as parseJsonBody, g as assertComponentSourcePath, s as toPascalCase, t as escapeHtml, v as decodeUrlComponent, w as HttpError, x as resolveInsideAny, y as isVueSourcePath } from "./utils-BloA9YP9.mjs";
|
|
2
|
-
import { o as resolveSnapshotIdentity } from "./vrt-
|
|
2
|
+
import { o as resolveSnapshotIdentity } from "./vrt-C7wgh92N.mjs";
|
|
3
3
|
import fs from "node:fs";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import ts from "typescript";
|
|
@@ -142,6 +142,146 @@ function expandSelfTag(template, componentTagName) {
|
|
|
142
142
|
return template.replace(/<Self(?=[\s/>])/g, `<${componentTagName}`).replace(/<\/Self\s*>/g, `</${componentTagName}>`);
|
|
143
143
|
}
|
|
144
144
|
//#endregion
|
|
145
|
+
//#region src/art-style.ts
|
|
146
|
+
function artScopeAttribute(filePath) {
|
|
147
|
+
return `data-v-${createHash("sha256").update(filePath).digest("hex").slice(0, 8)}`;
|
|
148
|
+
}
|
|
149
|
+
const TAG_NAME_START = /[A-Za-z]/;
|
|
150
|
+
const TAG_NAME_CHAR = /[\w:.-]/;
|
|
151
|
+
const SPACE = /\s/;
|
|
152
|
+
/**
|
|
153
|
+
* Add `scopeAttr` to every start tag of a variant template.
|
|
154
|
+
*
|
|
155
|
+
* Tokenizes like Vue's template parser: quoted attribute values, comments and
|
|
156
|
+
* `{{ }}` interpolations are opaque, so `@x="() => {}"` or `{{ a<b }}` is not
|
|
157
|
+
* mistaken for tag syntax (#9752).
|
|
158
|
+
*/
|
|
159
|
+
function stampScopeAttribute(template, scopeAttr) {
|
|
160
|
+
let out = "";
|
|
161
|
+
let i = 0;
|
|
162
|
+
while (i < template.length) if (template.startsWith("{{", i)) {
|
|
163
|
+
const end = template.indexOf("}}", i + 2);
|
|
164
|
+
const stop = end === -1 ? template.length : end + 2;
|
|
165
|
+
out += template.slice(i, stop);
|
|
166
|
+
i = stop;
|
|
167
|
+
} else if (template.startsWith("<!--", i)) {
|
|
168
|
+
const end = template.indexOf("-->", i + 4);
|
|
169
|
+
const stop = end === -1 ? template.length : end + 3;
|
|
170
|
+
out += template.slice(i, stop);
|
|
171
|
+
i = stop;
|
|
172
|
+
} else if (template[i] === "<" && TAG_NAME_START.test(template[i + 1] ?? "")) {
|
|
173
|
+
const tag = scanStartTag(template, i);
|
|
174
|
+
out += tag.stamped(scopeAttr);
|
|
175
|
+
i = tag.end;
|
|
176
|
+
} else {
|
|
177
|
+
out += template[i];
|
|
178
|
+
i += 1;
|
|
179
|
+
}
|
|
180
|
+
return out;
|
|
181
|
+
}
|
|
182
|
+
function scanStartTag(source, start) {
|
|
183
|
+
let i = start + 1;
|
|
184
|
+
while (i < source.length && TAG_NAME_CHAR.test(source[i])) i += 1;
|
|
185
|
+
const nameEnd = i;
|
|
186
|
+
const names = [];
|
|
187
|
+
let attrsEnd = source.length;
|
|
188
|
+
let selfClosing = false;
|
|
189
|
+
let closed = false;
|
|
190
|
+
while (i < source.length) {
|
|
191
|
+
const ch = source[i];
|
|
192
|
+
if (SPACE.test(ch)) i += 1;
|
|
193
|
+
else if (ch === ">") {
|
|
194
|
+
attrsEnd = i;
|
|
195
|
+
i += 1;
|
|
196
|
+
closed = true;
|
|
197
|
+
break;
|
|
198
|
+
} else if (ch === "/" && source[i + 1] === ">") {
|
|
199
|
+
attrsEnd = i;
|
|
200
|
+
i += 2;
|
|
201
|
+
selfClosing = true;
|
|
202
|
+
closed = true;
|
|
203
|
+
break;
|
|
204
|
+
} else if (ch === "/") i += 1;
|
|
205
|
+
else {
|
|
206
|
+
const nameStart = i;
|
|
207
|
+
while (i < source.length && !/[\s=/>]/.test(source[i])) i += 1;
|
|
208
|
+
if (i === nameStart) i += 1;
|
|
209
|
+
names.push(source.slice(nameStart, i));
|
|
210
|
+
let j = i;
|
|
211
|
+
while (j < source.length && SPACE.test(source[j])) j += 1;
|
|
212
|
+
if (source[j] !== "=") continue;
|
|
213
|
+
j += 1;
|
|
214
|
+
while (j < source.length && SPACE.test(source[j])) j += 1;
|
|
215
|
+
const quote = source[j];
|
|
216
|
+
if (quote === "\"" || quote === "'") {
|
|
217
|
+
const close = source.indexOf(quote, j + 1);
|
|
218
|
+
i = close === -1 ? source.length : close + 1;
|
|
219
|
+
} else {
|
|
220
|
+
while (j < source.length && !/[\s>]/.test(source[j])) j += 1;
|
|
221
|
+
i = j;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
return {
|
|
226
|
+
end: i,
|
|
227
|
+
stamped(scopeAttr) {
|
|
228
|
+
const raw = source.slice(start, i);
|
|
229
|
+
if (!closed || names.includes(scopeAttr)) return raw;
|
|
230
|
+
const attrs = source.slice(nameEnd, attrsEnd).trimEnd();
|
|
231
|
+
return `${source.slice(start, nameEnd)}${attrs} ${scopeAttr}${selfClosing ? " /" : ""}>`;
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
//#endregion
|
|
236
|
+
//#region src/art-style-module.ts
|
|
237
|
+
const STYLE_MARKER = ".__musea_style_";
|
|
238
|
+
function artStyleRequestId(filePath, index, style, scopeAttr) {
|
|
239
|
+
const params = new URLSearchParams({
|
|
240
|
+
"musea-art-style": "",
|
|
241
|
+
"musea-file": filePath,
|
|
242
|
+
index: String(index),
|
|
243
|
+
lang: style.lang
|
|
244
|
+
});
|
|
245
|
+
if (style.scoped && scopeAttr) params.set("scoped", scopeAttr);
|
|
246
|
+
return `${filePath}${STYLE_MARKER}${index}.${style.lang}?${params}`;
|
|
247
|
+
}
|
|
248
|
+
function parseArtStyleRequest(id) {
|
|
249
|
+
const normalized = id.startsWith("\0") ? id.slice(1) : id;
|
|
250
|
+
const queryIndex = normalized.indexOf("?");
|
|
251
|
+
if (queryIndex < 0 || !normalized.slice(0, queryIndex).includes(STYLE_MARKER)) return null;
|
|
252
|
+
const params = new URLSearchParams(normalized.slice(queryIndex + 1));
|
|
253
|
+
if (!params.has("musea-art-style")) return null;
|
|
254
|
+
const filePath = params.get("musea-file");
|
|
255
|
+
const index = Number(params.get("index"));
|
|
256
|
+
const lang = params.get("lang");
|
|
257
|
+
if (!filePath || !Number.isInteger(index) || index < 0 || !lang) return null;
|
|
258
|
+
return {
|
|
259
|
+
filePath,
|
|
260
|
+
index,
|
|
261
|
+
lang,
|
|
262
|
+
scoped: params.get("scoped") ?? void 0
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
function loadArtStyle(art, request, scopeCss = defaultScopeCss) {
|
|
266
|
+
if (!art || !request) return null;
|
|
267
|
+
const style = art.styleBlockDetails?.[request.index] ?? (art.styleBlocks?.[request.index] ? {
|
|
268
|
+
content: art.styleBlocks[request.index],
|
|
269
|
+
lang: "css",
|
|
270
|
+
scoped: false
|
|
271
|
+
} : void 0);
|
|
272
|
+
if (!style || style.lang !== request.lang) return null;
|
|
273
|
+
if (request.scoped && style.scoped && style.lang === "css") return scopeCss(style.content, request.scoped);
|
|
274
|
+
return style.content;
|
|
275
|
+
}
|
|
276
|
+
function transformPreprocessedArtStyle(code, id, scopeCss = defaultScopeCss) {
|
|
277
|
+
const request = parseArtStyleRequest(id);
|
|
278
|
+
if (!request?.scoped || request.lang === "css") return null;
|
|
279
|
+
return scopeCss(code, request.scoped);
|
|
280
|
+
}
|
|
281
|
+
function defaultScopeCss(css, scopeId) {
|
|
282
|
+
return loadNative().scopeViteCssForPipeline?.(css, scopeId) ?? css;
|
|
283
|
+
}
|
|
284
|
+
//#endregion
|
|
145
285
|
//#region src/art-module.ts
|
|
146
286
|
/**
|
|
147
287
|
* Art module generation for Musea.
|
|
@@ -395,6 +535,13 @@ function generateArtModule(art, filePath, options = {}) {
|
|
|
395
535
|
let code = `
|
|
396
536
|
// Auto-generated module for: ${path.basename(filePath)}
|
|
397
537
|
`;
|
|
538
|
+
const styles = art.styleBlockDetails ?? art.styleBlocks?.map((content) => ({
|
|
539
|
+
content,
|
|
540
|
+
lang: "css",
|
|
541
|
+
scoped: false
|
|
542
|
+
})) ?? [];
|
|
543
|
+
const scopeAttr = styles.some((style) => style.scoped) ? artScopeAttribute(filePath) : void 0;
|
|
544
|
+
for (const [index, style] of styles.entries()) code += `import ${JSON.stringify(artStyleRequestId(filePath, index, style, scopeAttr))};\n`;
|
|
398
545
|
if (options.vueVersion === 2 && hasSetup) code += `import { defineComponent as __museaDefineComponent } from 'vue';\n`;
|
|
399
546
|
if (scriptSetup) {
|
|
400
547
|
const artDir = path.dirname(filePath);
|
|
@@ -410,7 +557,6 @@ function generateArtModule(art, filePath, options = {}) {
|
|
|
410
557
|
code += `
|
|
411
558
|
export const metadata = ${JSON.stringify(art.metadata)};
|
|
412
559
|
export const variants = ${JSON.stringify(art.variants)};
|
|
413
|
-
export const __styles__ = ${JSON.stringify(art.styleBlocks ?? [])};
|
|
414
560
|
`;
|
|
415
561
|
const setupReturn = `{ ${scriptSetup?.returnNames.join(", ") ?? ""} }`;
|
|
416
562
|
const isolatedSetup = art.scriptSetupIsolated !== false;
|
|
@@ -1898,48 +2044,117 @@ function joinUrlPath(basePath, ...segments) {
|
|
|
1898
2044
|
}
|
|
1899
2045
|
async function createStaticGalleryPayload(ctx) {
|
|
1900
2046
|
const apiCtx = createApiContext(ctx);
|
|
1901
|
-
const
|
|
2047
|
+
const sourceArts = sortedArts(ctx.artFiles.values());
|
|
2048
|
+
const arts = [];
|
|
1902
2049
|
const previews = Object.create(null);
|
|
1903
2050
|
const details = {};
|
|
1904
2051
|
const snapshotIdentities = Object.create(null);
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
2052
|
+
const identityRoot = resolveStaticIdentityRoot(ctx.config.root, sourceArts.map((art) => art.path), ctx.projectRoot);
|
|
2053
|
+
const publicPaths = /* @__PURE__ */ new Map();
|
|
2054
|
+
for (const art of sourceArts) publicPaths.set(art.path, resolveStaticArtIdentity(art.path, identityRoot));
|
|
2055
|
+
for (const sourceArt of sourceArts) {
|
|
2056
|
+
const publicPath = publicPaths.get(sourceArt.path);
|
|
2057
|
+
const art = publicArtInfo(sourceArt, publicPath, identityRoot);
|
|
2058
|
+
arts.push(art);
|
|
2059
|
+
snapshotIdentities[publicPath] = publicPath;
|
|
2060
|
+
previews[publicPath] = Object.create(null);
|
|
1908
2061
|
for (const variant of art.variants) {
|
|
1909
|
-
const id = staticPreviewId(
|
|
1910
|
-
previews[
|
|
2062
|
+
const id = staticPreviewId(publicPath, variant.name);
|
|
2063
|
+
previews[publicPath][variant.name] = joinUrlPath(ctx.basePath, "preview", `${id}.html`);
|
|
1911
2064
|
}
|
|
1912
|
-
details[
|
|
1913
|
-
source: await captureJson((sendJson, sendError) => {
|
|
1914
|
-
return handleArtSource(apiCtx, artMatch(
|
|
2065
|
+
details[publicPath] = {
|
|
2066
|
+
source: withPublicSourcePath(await captureJson((sendJson, sendError) => {
|
|
2067
|
+
return handleArtSource(apiCtx, artMatch(sourceArt.path), sendJson, sendError);
|
|
1915
2068
|
}, {
|
|
1916
2069
|
source: "",
|
|
1917
|
-
path:
|
|
1918
|
-
}),
|
|
2070
|
+
path: sourceArt.path
|
|
2071
|
+
}), publicPath),
|
|
1919
2072
|
palette: await captureJson((sendJson, sendError) => {
|
|
1920
|
-
return handleArtPalette(apiCtx, artMatch(
|
|
2073
|
+
return handleArtPalette(apiCtx, artMatch(sourceArt.path), sendJson, sendError);
|
|
1921
2074
|
}, emptyPalette(art)),
|
|
1922
2075
|
analysis: await captureJson((sendJson, sendError) => {
|
|
1923
|
-
return handleArtAnalysis(apiCtx, artMatch(
|
|
2076
|
+
return handleArtAnalysis(apiCtx, artMatch(sourceArt.path), sendJson, sendError);
|
|
1924
2077
|
}, {
|
|
1925
2078
|
props: [],
|
|
1926
2079
|
emits: []
|
|
1927
2080
|
}),
|
|
1928
2081
|
docs: await captureJson((sendJson, sendError) => {
|
|
1929
|
-
return handleArtDocs(apiCtx, artMatch(
|
|
2082
|
+
return handleArtDocs(apiCtx, artMatch(sourceArt.path), sendJson, sendError);
|
|
1930
2083
|
}, emptyDocs(art))
|
|
1931
2084
|
};
|
|
1932
2085
|
}
|
|
2086
|
+
const tokens = await captureJson((sendJson) => handleTokensGet(apiCtx, sendJson), emptyTokens());
|
|
2087
|
+
const tokenUsage = await captureJson((sendJson) => handleTokensUsage(apiCtx, sendJson), {});
|
|
1933
2088
|
return {
|
|
1934
2089
|
arts,
|
|
1935
2090
|
snapshotIdentityVersion: 1,
|
|
1936
2091
|
snapshotIdentities,
|
|
1937
2092
|
previews,
|
|
1938
2093
|
details,
|
|
1939
|
-
tokens:
|
|
1940
|
-
tokenUsage:
|
|
2094
|
+
tokens: withPublicTokenPath(tokens, identityRoot),
|
|
2095
|
+
tokenUsage: withPublicUsagePaths(tokenUsage, publicPaths)
|
|
2096
|
+
};
|
|
2097
|
+
}
|
|
2098
|
+
function resolveStaticIdentityRoot(viteRoot, artPaths, projectRoot) {
|
|
2099
|
+
if (projectRoot) return path.resolve(projectRoot);
|
|
2100
|
+
let root = path.resolve(viteRoot);
|
|
2101
|
+
for (const artPath of artPaths) {
|
|
2102
|
+
const directory = path.dirname(path.resolve(artPath));
|
|
2103
|
+
while (!isPathInside(root, directory)) {
|
|
2104
|
+
const parent = path.dirname(root);
|
|
2105
|
+
if (parent === root) throw new Error(`Art is outside the Vite root on another filesystem: ${artPath}. Configure projectRoot.`);
|
|
2106
|
+
root = parent;
|
|
2107
|
+
}
|
|
2108
|
+
}
|
|
2109
|
+
return root;
|
|
2110
|
+
}
|
|
2111
|
+
function resolveStaticArtIdentity(artPath, identityRoot) {
|
|
2112
|
+
return resolveSnapshotIdentity(artPath, identityRoot);
|
|
2113
|
+
}
|
|
2114
|
+
function publicArtInfo(art, publicPath, identityRoot) {
|
|
2115
|
+
return {
|
|
2116
|
+
...art,
|
|
2117
|
+
path: publicPath,
|
|
2118
|
+
...art.componentPath ? { componentPath: publicSourceIdentity(art.componentPath, identityRoot) } : {}
|
|
1941
2119
|
};
|
|
1942
2120
|
}
|
|
2121
|
+
function withPublicSourcePath(value, publicPath) {
|
|
2122
|
+
if (!isRecord(value) || typeof value.path !== "string") return value;
|
|
2123
|
+
return {
|
|
2124
|
+
...value,
|
|
2125
|
+
path: publicPath
|
|
2126
|
+
};
|
|
2127
|
+
}
|
|
2128
|
+
function withPublicTokenPath(value, identityRoot) {
|
|
2129
|
+
if (!isRecord(value) || !isRecord(value.meta) || typeof value.meta.filePath !== "string") return value;
|
|
2130
|
+
if (!path.isAbsolute(value.meta.filePath)) return value;
|
|
2131
|
+
return {
|
|
2132
|
+
...value,
|
|
2133
|
+
meta: {
|
|
2134
|
+
...value.meta,
|
|
2135
|
+
filePath: publicSourceIdentity(value.meta.filePath, identityRoot)
|
|
2136
|
+
}
|
|
2137
|
+
};
|
|
2138
|
+
}
|
|
2139
|
+
function withPublicUsagePaths(value, publicPaths) {
|
|
2140
|
+
if (!isRecord(value)) return value;
|
|
2141
|
+
return Object.fromEntries(Object.entries(value).map(([token, entries]) => [token, Array.isArray(entries) ? entries.map((entry) => isRecord(entry) && typeof entry.artPath === "string" ? {
|
|
2142
|
+
...entry,
|
|
2143
|
+
artPath: publicPaths.get(entry.artPath) ?? path.basename(entry.artPath)
|
|
2144
|
+
} : entry) : entries]));
|
|
2145
|
+
}
|
|
2146
|
+
function publicSourceIdentity(sourcePath, identityRoot) {
|
|
2147
|
+
const relative = path.relative(identityRoot, path.resolve(sourcePath));
|
|
2148
|
+
if (relative === "" || relative === ".." || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) return path.basename(sourcePath);
|
|
2149
|
+
return relative.split(path.sep).join("/");
|
|
2150
|
+
}
|
|
2151
|
+
function isRecord(value) {
|
|
2152
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
2153
|
+
}
|
|
2154
|
+
function isPathInside(root, candidate) {
|
|
2155
|
+
const relative = path.relative(root, candidate);
|
|
2156
|
+
return relative === "" || relative !== ".." && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative);
|
|
2157
|
+
}
|
|
1943
2158
|
function createApiContext(ctx) {
|
|
1944
2159
|
return {
|
|
1945
2160
|
config: ctx.config,
|
|
@@ -2096,97 +2311,6 @@ function attachArtReportOwner(json, target) {
|
|
|
2096
2311
|
}, null, 2);
|
|
2097
2312
|
}
|
|
2098
2313
|
//#endregion
|
|
2099
|
-
//#region src/art-style.ts
|
|
2100
|
-
function artScopeAttribute(filePath) {
|
|
2101
|
-
return `data-v-${createHash("sha256").update(filePath).digest("hex").slice(0, 8)}`;
|
|
2102
|
-
}
|
|
2103
|
-
const TAG_NAME_START = /[A-Za-z]/;
|
|
2104
|
-
const TAG_NAME_CHAR = /[\w:.-]/;
|
|
2105
|
-
const SPACE = /\s/;
|
|
2106
|
-
/**
|
|
2107
|
-
* Add `scopeAttr` to every start tag of a variant template.
|
|
2108
|
-
*
|
|
2109
|
-
* Tokenizes like Vue's template parser: quoted attribute values, comments and
|
|
2110
|
-
* `{{ }}` interpolations are opaque, so `@x="() => {}"` or `{{ a<b }}` is not
|
|
2111
|
-
* mistaken for tag syntax (#9752).
|
|
2112
|
-
*/
|
|
2113
|
-
function stampScopeAttribute(template, scopeAttr) {
|
|
2114
|
-
let out = "";
|
|
2115
|
-
let i = 0;
|
|
2116
|
-
while (i < template.length) if (template.startsWith("{{", i)) {
|
|
2117
|
-
const end = template.indexOf("}}", i + 2);
|
|
2118
|
-
const stop = end === -1 ? template.length : end + 2;
|
|
2119
|
-
out += template.slice(i, stop);
|
|
2120
|
-
i = stop;
|
|
2121
|
-
} else if (template.startsWith("<!--", i)) {
|
|
2122
|
-
const end = template.indexOf("-->", i + 4);
|
|
2123
|
-
const stop = end === -1 ? template.length : end + 3;
|
|
2124
|
-
out += template.slice(i, stop);
|
|
2125
|
-
i = stop;
|
|
2126
|
-
} else if (template[i] === "<" && TAG_NAME_START.test(template[i + 1] ?? "")) {
|
|
2127
|
-
const tag = scanStartTag(template, i);
|
|
2128
|
-
out += tag.stamped(scopeAttr);
|
|
2129
|
-
i = tag.end;
|
|
2130
|
-
} else {
|
|
2131
|
-
out += template[i];
|
|
2132
|
-
i += 1;
|
|
2133
|
-
}
|
|
2134
|
-
return out;
|
|
2135
|
-
}
|
|
2136
|
-
function scanStartTag(source, start) {
|
|
2137
|
-
let i = start + 1;
|
|
2138
|
-
while (i < source.length && TAG_NAME_CHAR.test(source[i])) i += 1;
|
|
2139
|
-
const nameEnd = i;
|
|
2140
|
-
const names = [];
|
|
2141
|
-
let attrsEnd = source.length;
|
|
2142
|
-
let selfClosing = false;
|
|
2143
|
-
let closed = false;
|
|
2144
|
-
while (i < source.length) {
|
|
2145
|
-
const ch = source[i];
|
|
2146
|
-
if (SPACE.test(ch)) i += 1;
|
|
2147
|
-
else if (ch === ">") {
|
|
2148
|
-
attrsEnd = i;
|
|
2149
|
-
i += 1;
|
|
2150
|
-
closed = true;
|
|
2151
|
-
break;
|
|
2152
|
-
} else if (ch === "/" && source[i + 1] === ">") {
|
|
2153
|
-
attrsEnd = i;
|
|
2154
|
-
i += 2;
|
|
2155
|
-
selfClosing = true;
|
|
2156
|
-
closed = true;
|
|
2157
|
-
break;
|
|
2158
|
-
} else if (ch === "/") i += 1;
|
|
2159
|
-
else {
|
|
2160
|
-
const nameStart = i;
|
|
2161
|
-
while (i < source.length && !/[\s=/>]/.test(source[i])) i += 1;
|
|
2162
|
-
if (i === nameStart) i += 1;
|
|
2163
|
-
names.push(source.slice(nameStart, i));
|
|
2164
|
-
let j = i;
|
|
2165
|
-
while (j < source.length && SPACE.test(source[j])) j += 1;
|
|
2166
|
-
if (source[j] !== "=") continue;
|
|
2167
|
-
j += 1;
|
|
2168
|
-
while (j < source.length && SPACE.test(source[j])) j += 1;
|
|
2169
|
-
const quote = source[j];
|
|
2170
|
-
if (quote === "\"" || quote === "'") {
|
|
2171
|
-
const close = source.indexOf(quote, j + 1);
|
|
2172
|
-
i = close === -1 ? source.length : close + 1;
|
|
2173
|
-
} else {
|
|
2174
|
-
while (j < source.length && !/[\s>]/.test(source[j])) j += 1;
|
|
2175
|
-
i = j;
|
|
2176
|
-
}
|
|
2177
|
-
}
|
|
2178
|
-
}
|
|
2179
|
-
return {
|
|
2180
|
-
end: i,
|
|
2181
|
-
stamped(scopeAttr) {
|
|
2182
|
-
const raw = source.slice(start, i);
|
|
2183
|
-
if (!closed || names.includes(scopeAttr)) return raw;
|
|
2184
|
-
const attrs = source.slice(nameEnd, attrsEnd).trimEnd();
|
|
2185
|
-
return `${source.slice(start, nameEnd)}${attrs} ${scopeAttr}${selfClosing ? " /" : ""}>`;
|
|
2186
|
-
}
|
|
2187
|
-
};
|
|
2188
|
-
}
|
|
2189
|
-
//#endregion
|
|
2190
2314
|
//#region src/plugin/art-processing.ts
|
|
2191
2315
|
function extractArtTagAttributes(source) {
|
|
2192
2316
|
const artTagMatch = source.match(/<art\b((?:[^>"']|"[^"]*"|'[^']*')*)>/i);
|
|
@@ -2218,21 +2342,16 @@ function extractStyleBlocks(source, filePath) {
|
|
|
2218
2342
|
const content = match[2]?.trim();
|
|
2219
2343
|
const lang = attrs.match(/\blang\s*=\s*["']([^"']+)["']/i)?.[1]?.toLowerCase();
|
|
2220
2344
|
if (!content) continue;
|
|
2221
|
-
if (lang && lang !== "css") {
|
|
2222
|
-
console.warn(`[musea] ${filePath}: <style lang="${lang}"> is not processed. Art styles are plain CSS.`);
|
|
2223
|
-
continue;
|
|
2224
|
-
}
|
|
2225
2345
|
styles.push({
|
|
2226
2346
|
content,
|
|
2347
|
+
lang: lang ?? "css",
|
|
2227
2348
|
scoped: /\bscoped\b/i.test(attrs)
|
|
2228
2349
|
});
|
|
2229
2350
|
}
|
|
2230
|
-
if (!styles.some((style) => style.scoped)) return { blocks: styles
|
|
2231
|
-
const scopeAttr = artScopeAttribute(filePath);
|
|
2232
|
-
const scope = loadNative().scopeViteCssForPipeline;
|
|
2351
|
+
if (!styles.some((style) => style.scoped)) return { blocks: styles };
|
|
2233
2352
|
return {
|
|
2234
|
-
scopeAttr,
|
|
2235
|
-
blocks: styles
|
|
2353
|
+
scopeAttr: artScopeAttribute(filePath),
|
|
2354
|
+
blocks: styles
|
|
2236
2355
|
};
|
|
2237
2356
|
}
|
|
2238
2357
|
function formatArtProcessingError(root, filePath, error) {
|
|
@@ -2286,7 +2405,8 @@ async function processMuseaArtFile(filePath, ctx) {
|
|
|
2286
2405
|
scriptSetupIsolated: !isInline && parsed.hasScriptSetup ? extractScriptSetupIsolated(source) : true,
|
|
2287
2406
|
hasScript: parsed.hasScript,
|
|
2288
2407
|
styleCount: parsed.styleCount,
|
|
2289
|
-
styleBlocks: styles.blocks,
|
|
2408
|
+
styleBlocks: styles.blocks.map((style) => style.content),
|
|
2409
|
+
styleBlockDetails: styles.blocks,
|
|
2290
2410
|
isInline,
|
|
2291
2411
|
componentPath: isInline ? filePath : void 0
|
|
2292
2412
|
};
|
|
@@ -2314,6 +2434,6 @@ function readMuseaOptions(plugin) {
|
|
|
2314
2434
|
return plugin[MUSEA_OPTIONS_KEY];
|
|
2315
2435
|
}
|
|
2316
2436
|
//#endregion
|
|
2317
|
-
export {
|
|
2437
|
+
export { buildTokenMap as A, expandSelfTag as B, handleTokensGet as C, generateTokensHtml as D, resolveTokenPreview as E, parseScriptSetupForArt as F, variantComponentNames as H, rewriteRelativeImportStatement as I, loadArtStyle as L, scanTokenUsage as M, parseTokens as N, generateTokensMarkdown as O, generateArtModule as P, parseArtStyleRequest as R, handleTokensDelete as S, handleTokensUsage as T, resolveArtComponent as V, handleArtAnalysis as _, attachArtReportOwner as a, handleArtPalette as b, rewriteDevGalleryAsset as c, createStaticGalleryPayload as d, joinUrlPath as f, sortedArts as g, staticPreviewId as h, assertArtReportOwnership as i, resolveReferences as j, processStyleDictionary as k, rewriteGalleryBase as l, resolveStaticIdentityRoot as m, readMuseaOptions as n, resolveArtReportTarget as o, resolveStaticArtIdentity as p, processMuseaArtFile as r, publicBasePathFromViteBase as s, attachMuseaOptions as t, rewriteGalleryTextAssetBase as u, handleArtDocs as v, handleTokensUpdate as w, handleTokensCreate as x, handleArtSource as y, transformPreprocessedArtStyle as z };
|
|
2318
2438
|
|
|
2319
|
-
//# sourceMappingURL=options-
|
|
2439
|
+
//# sourceMappingURL=options-BwF3nGEB.mjs.map
|