@fluentic/style 0.1.0-beta.18 → 0.1.0-beta.19
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/CHANGELOG.md +8 -0
- package/atomic/utils/types.ts +4 -2
- package/dist/{combine-BpOQWCtM.js → combine-B5AnX0Gb.js} +2 -2
- package/dist/{combine-BpOQWCtM.js.map → combine-B5AnX0Gb.js.map} +1 -1
- package/dist/compiler-Dpd41bCS.mjs.map +1 -1
- package/dist/{config-B70LIQhi.js → config-VS1lyh3Z.js} +2 -2
- package/dist/{config-B70LIQhi.js.map → config-VS1lyh3Z.js.map} +1 -1
- package/dist/{css-C7tcD3IO.js → css-CMuUcsWb.js} +99 -21
- package/dist/css-CMuUcsWb.js.map +1 -0
- package/dist/{css-Cdxkur4h.js → css-ivddFxoH.js} +6 -6
- package/dist/{css-Cdxkur4h.js.map → css-ivddFxoH.js.map} +1 -1
- package/dist/{css-BkNqUfLD.js → css-tUcQKLko.js} +5 -5
- package/dist/{css-BkNqUfLD.js.map → css-tUcQKLko.js.map} +1 -1
- package/dist/css.js +1 -1
- package/dist/{css_extra-BC1Z_hDy.js → css_extra-FjU7uCIO.js} +2 -2
- package/dist/{css_extra-BC1Z_hDy.js.map → css_extra-FjU7uCIO.js.map} +1 -1
- package/dist/dev/rsc.js +5 -5
- package/dist/{dev-BoEgFs_x.js → dev-CZUGQ_Ps.js} +3 -3
- package/dist/{dev-BoEgFs_x.js.map → dev-CZUGQ_Ps.js.map} +1 -1
- package/dist/dev.js +1 -1
- package/dist/{elementMarker-nYeJnJPQ.js → elementMarker-BCL0sycL.js} +99 -21
- package/dist/elementMarker-BCL0sycL.js.map +1 -0
- package/dist/entry/dev/adapter/preact.js +1 -1
- package/dist/entry/dev/adapter/react.js +1 -1
- package/dist/entry/dev/adapter/solid.js +1 -1
- package/dist/entry/dev/css.js +1 -1
- package/dist/entry/dev/jsx-dev-runtime.js +1 -1
- package/dist/entry/dev/jsx-runtime.js +1 -1
- package/dist/entry/dev.js +5 -5
- package/dist/entry/prod/css.js +2 -2
- package/dist/entry/prod.js +2 -2
- package/dist/entry/rsc-dev/adapter/preact.js +1 -1
- package/dist/entry/rsc-dev/adapter/react.js +1 -1
- package/dist/entry/rsc-dev/adapter/solid.js +1 -1
- package/dist/entry/rsc-dev/css.js +3 -3
- package/dist/entry/rsc-dev/dev.js +4 -4
- package/dist/entry/rsc-dev/jsx-dev-runtime.js +3 -3
- package/dist/entry/rsc-dev/jsx-runtime.js +2 -2
- package/dist/entry/rsc-dev.js +6 -6
- package/dist/entry/rsc-prod/css.js +2 -2
- package/dist/entry/rsc-prod.js +2 -2
- package/dist/{env-BcNl1tsJ.js → env-CljhzScj.js} +2 -2
- package/dist/{env-BcNl1tsJ.js.map → env-CljhzScj.js.map} +1 -1
- package/dist/{getClassName-B3azD1TO.js → getClassName-DKk03IJU.js} +3 -3
- package/dist/{getClassName-B3azD1TO.js.map → getClassName-DKk03IJU.js.map} +1 -1
- package/dist/{getClassName-CkTq92nR.js → getClassName-a1SH7I2q.js} +3 -3
- package/dist/{getClassName-CkTq92nR.js.map → getClassName-a1SH7I2q.js.map} +1 -1
- package/dist/{globalSheet-CdgVpvCb.js → globalSheet-CjX0Df0w.js} +3 -3
- package/dist/globalSheet-CjX0Df0w.js.map +1 -0
- package/dist/index.js +4 -4
- package/dist/jsx/jsx-dev-runtime.js +1 -1
- package/dist/jsx/jsx-dev-runtime.server.js +1 -1
- package/dist/jsx/jsx-runtime.js +1 -1
- package/dist/jsx/jsx-runtime.server.js +1 -1
- package/dist/{jsx-DA1LD8nU.js → jsx-Gs5YwesA.js} +3 -3
- package/dist/{jsx-DA1LD8nU.js.map → jsx-Gs5YwesA.js.map} +1 -1
- package/dist/{jsx_runtime-pt7DOZOE.js → jsx_runtime-D3Dc1XfC.js} +3 -3
- package/dist/{jsx_runtime-pt7DOZOE.js.map → jsx_runtime-D3Dc1XfC.js.map} +1 -1
- package/dist/{resolveClassNameRuntime-B6vKNL5y.js → resolveClassNameRuntime-BBI9nYtq.js} +2 -2
- package/dist/{resolveClassNameRuntime-B6vKNL5y.js.map → resolveClassNameRuntime-BBI9nYtq.js.map} +1 -1
- package/dist/server.js +7 -7
- package/dist/shared-CcB1KDFI.cjs.map +1 -1
- package/dist/sheet-AV0Sl7e2.js +1 -0
- package/dist/sheet-Bf09AL2O.js +7 -0
- package/dist/{sheet-D_grHnaJ.js.map → sheet-Bf09AL2O.js.map} +1 -1
- package/dist/{sheet-C6ymGhKV.js → sheet-CcwxBK3r.js} +2 -2
- package/dist/{sheet-C6ymGhKV.js.map → sheet-CcwxBK3r.js.map} +1 -1
- package/dist/{style-CRs-vfY1.js → style-DY3v7k9y.js} +3 -3
- package/dist/{style-CRs-vfY1.js.map → style-DY3v7k9y.js.map} +1 -1
- package/dist/{styleStore-D1IEmq1v.js → styleStore-BpkbvtBI.js} +99 -21
- package/dist/styleStore-BpkbvtBI.js.map +1 -0
- package/dist/{styleStore-HI4V2puu.js → styleStore-DWEAtd8z.js} +3 -3
- package/dist/{styleStore-HI4V2puu.js.map → styleStore-DWEAtd8z.js.map} +1 -1
- package/dist/{trace-DdFJPELS.js → trace-BxvaCfGx.js} +2 -2
- package/dist/{trace-DdFJPELS.js.map → trace-BxvaCfGx.js.map} +1 -1
- package/dist/{trace-uHVvnYiw.js → trace-Db5et6nx.js} +2 -2
- package/dist/{trace-uHVvnYiw.js.map → trace-Db5et6nx.js.map} +1 -1
- package/dist/transform-BZ4jPwy3.js.map +1 -1
- package/dist/types/atomic/utils/types.d.ts +3 -2
- package/dist/types/builder/utils.d.ts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/style/transform.d.ts +4 -3
- package/dist/{utils-CB70kIh6.js → utils-B3O2b3Ly.js} +3 -3
- package/dist/{utils-CB70kIh6.js.map → utils-B3O2b3Ly.js.map} +1 -1
- package/dist/{utils-sG7IWYP6.js → utils-BeJmRz7x.js} +99 -21
- package/dist/utils-BeJmRz7x.js.map +1 -0
- package/index.ts +1 -0
- package/package.json +2 -2
- package/sheet/dev/dev_layer.ts +55 -11
- package/sheet/dev/dev_sort.ts +16 -9
- package/sheet/ordered.ts +43 -6
- package/style/transform.ts +4 -3
- package/dist/css-C7tcD3IO.js.map +0 -1
- package/dist/elementMarker-nYeJnJPQ.js.map +0 -1
- package/dist/globalSheet-CdgVpvCb.js.map +0 -1
- package/dist/sheet-Biw_rI4_.js +0 -1
- package/dist/sheet-D_grHnaJ.js +0 -7
- package/dist/styleStore-D1IEmq1v.js.map +0 -1
- package/dist/utils-sG7IWYP6.js.map +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { n as getGlobalData, r as globalData } from "./global-DGcWZODV.js";
|
|
2
2
|
import { a as RUNTIME_CONFIG, c as CSS_CONFIG } from "./debug-Bo43rBKc.js";
|
|
3
3
|
import { y as DEV_CONFIG } from "./hash-CjTP-uES.js";
|
|
4
|
-
import { _ as serializeOrderedRules } from "./elementMarker-
|
|
5
|
-
import { t as IS_SERVER_RUNTIME } from "./env-
|
|
4
|
+
import { _ as serializeOrderedRules } from "./elementMarker-BCL0sycL.js";
|
|
5
|
+
import { t as IS_SERVER_RUNTIME } from "./env-CljhzScj.js";
|
|
6
6
|
//#region runtime/rsc/constants.ts
|
|
7
7
|
const GLOBAL_SEED_ATTR = "data-css-global-seed-dev";
|
|
8
8
|
const GLOBAL_RULES_ATTR = "data-css-global-rules-dev";
|
|
@@ -42,4 +42,4 @@ function getRscStyleStore() {
|
|
|
42
42
|
//#endregion
|
|
43
43
|
export { GLOBAL_RULES_ATTR as a, SEED_STYLE_TAG_ATTR as c, ELEMENT_CSS_DATA_ATTR as i, SEED_STYLE_TAG_HREF as l, getRscStyleRules as n, GLOBAL_SEED_ATTR as o, serializeRscRules as r, PRECOLLECT_LINK_TAG_ATTR as s, addRscStyleRules as t };
|
|
44
44
|
|
|
45
|
-
//# sourceMappingURL=styleStore-
|
|
45
|
+
//# sourceMappingURL=styleStore-DWEAtd8z.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"styleStore-
|
|
1
|
+
{"version":3,"file":"styleStore-DWEAtd8z.js","names":[],"sources":["../runtime/rsc/constants.ts","../runtime/rsc/styleStore.ts"],"sourcesContent":["export const GLOBAL_SEED_ATTR = 'data-css-global-seed-dev';\nexport const GLOBAL_RULES_ATTR = 'data-css-global-rules-dev';\n\nexport const ELEMENT_CSS_DATA_ATTR = 'data-css-dev';\n\nexport const PRECOLLECT_LINK_TAG_ATTR = 'data-fluentic-style-rsc-dev-link';\n\nexport const SEED_STYLE_TAG_ATTR = 'data-fluentic-style-rsc-dev-style';\nexport const SEED_STYLE_TAG_HREF = 'href-fluentic-style-rsc-dev-style';\n","import { CSS_CONFIG } from '../../config/config/css';\nimport { DEV_CONFIG } from '../../config/config/dev';\nimport { RUNTIME_CONFIG } from '../../config/config/runtime';\nimport type { SheetRule } from '../../sheet';\nimport { serializeOrderedRules } from '../../sheet/ordering';\nimport { clearGlobalData, getGlobalData, globalData } from '../../utils/global';\nimport { IS_SERVER_RUNTIME } from '../env';\n\nconst GLOBAL_KEY = 'runtime.rsc.styleStore';\n\ntype RscStyleStore = {\n rules: SheetRule[];\n keys: Set<string>;\n //\n counter: number;\n lastCounter: number;\n};\n\nexport function addRscStyleRules(rules: SheetRule[]): void {\n if (!RUNTIME_CONFIG.isRSC) return;\n if (!IS_SERVER_RUNTIME) return;\n\n const store = getRscStyleStore();\n\n for (let i = 0, len = rules.length; i < len; i++) {\n const rule = rules[i];\n if (!rule.key || !rule.css || store.keys.has(rule.key)) continue;\n\n store.keys.add(rule.key);\n store.rules.push(rule);\n }\n\n store.counter += 1;\n}\n\nexport function getRscStyleCssIfChanged() {\n const store = getGlobalData<RscStyleStore>(GLOBAL_KEY);\n if (!store) return null;\n\n if (store.counter === store.lastCounter) return null;\n\n store.lastCounter = store.counter;\n\n return getRscStyleCss();\n}\n\nexport function getRscStyleCss(): string {\n if (!RUNTIME_CONFIG.isRSC) return '';\n if (!IS_SERVER_RUNTIME) return '';\n\n return serializeRscRules(getRscStyleRules());\n}\n\nexport function getRscStyleRules(): readonly SheetRule[] {\n return getGlobalData<RscStyleStore>(GLOBAL_KEY)?.rules ?? [];\n}\n\nexport function serializeRscRules(rules: readonly SheetRule[]): string {\n return serializeOrderedRules(rules, CSS_CONFIG, DEV_CONFIG.stylePriorityMode);\n}\n\nfunction getRscStyleStore(): RscStyleStore {\n return globalData(GLOBAL_KEY, () => ({\n counter: 0,\n lastCounter: 0,\n rules: [],\n keys: new Set(),\n }));\n}\n\nexport function clearRscStyleStore(): void {\n clearGlobalData(GLOBAL_KEY);\n}\n"],"mappings":";;;;;;AAAA,MAAa,mBAAmB;AAChC,MAAa,oBAAoB;AAEjC,MAAa,wBAAwB;AAErC,MAAa,2BAA2B;AAExC,MAAa,sBAAsB;AACnC,MAAa,sBAAsB;;;ACAnC,MAAM,aAAa;AAUnB,SAAgB,iBAAiB,OAA0B;CACzD,IAAI,CAAC,eAAe,OAAO;CAC3B,IAAI,CAAC,mBAAmB;CAExB,MAAM,QAAQ,iBAAiB;CAE/B,KAAK,IAAI,IAAI,GAAG,MAAM,MAAM,QAAQ,IAAI,KAAK,KAAK;EAChD,MAAM,OAAO,MAAM;EACnB,IAAI,CAAC,KAAK,OAAO,CAAC,KAAK,OAAO,MAAM,KAAK,IAAI,KAAK,GAAG,GAAG;EAExD,MAAM,KAAK,IAAI,KAAK,GAAG;EACvB,MAAM,MAAM,KAAK,IAAI;CACvB;CAEA,MAAM,WAAW;AACnB;AAoBA,SAAgB,mBAAyC;CACvD,OAAO,cAA6B,UAAU,GAAG,SAAS,CAAC;AAC7D;AAEA,SAAgB,kBAAkB,OAAqC;CACrE,OAAO,sBAAsB,OAAO,YAAY,WAAW,iBAAiB;AAC9E;AAEA,SAAS,mBAAkC;CACzC,OAAO,WAAW,mBAAmB;EACnC,SAAS;EACT,aAAa;EACb,OAAO,CAAC;EACR,sBAAM,IAAI,IAAI;CAChB,EAAE;AACJ"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { h as normalizeCallsiteSourceUrl } from "./hash-CjTP-uES.js";
|
|
2
|
-
import { f as getDevSourcemapTags, h as getSourcemapRuleCallsite, m as createSourceMapComment } from "./elementMarker-
|
|
2
|
+
import { f as getDevSourcemapTags, h as getSourcemapRuleCallsite, m as createSourceMapComment } from "./elementMarker-BCL0sycL.js";
|
|
3
3
|
import { TraceMap, originalPositionFor, sourceContentFor } from "@jridgewell/trace-mapping";
|
|
4
4
|
//#region dev/trace.ts
|
|
5
5
|
const SOURCE_MAPPING_URL_REGEX = /(?:\/\/|\/\*)[#@]\s*sourceMappingURL=([^\s*]+)(?:\s*\*\/)?/g;
|
|
@@ -242,4 +242,4 @@ function isAbsoluteSource(source) {
|
|
|
242
242
|
//#endregion
|
|
243
243
|
export { traceDevSourcemaps };
|
|
244
244
|
|
|
245
|
-
//# sourceMappingURL=trace-
|
|
245
|
+
//# sourceMappingURL=trace-BxvaCfGx.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trace-DdFJPELS.js","names":[],"sources":["../dev/trace.ts"],"sourcesContent":["import { type EncodedSourceMap, originalPositionFor, sourceContentFor, TraceMap } from '@jridgewell/trace-mapping';\nimport { getDevSourcemapTags } from '../sheet/dev';\nimport { createSourceMapComment, getSourcemapRuleCallsite } from '../sheet/sourcemap';\nimport type { SheetCallsite } from '../sheet/types';\nimport { normalizeCallsiteSourceUrl } from '../utils/trace';\n\nexport type TraceSourcemapResult = {\n tags: number;\n rules: number;\n remapped: number;\n unresolved: number;\n sourcemaps: string[];\n};\n\ntype SourceMapData = {\n url: string;\n sourceBaseUrl: string;\n rawMap: EncodedSourceMap;\n map: TraceMap;\n sourceRoot?: string;\n};\n\nconst SOURCE_MAPPING_URL_REGEX = /(?:\\/\\/|\\/\\*)[#@]\\s*sourceMappingURL=([^\\s*]+)(?:\\s*\\*\\/)?/g;\n\nexport async function traceDevSourcemaps(): Promise<TraceSourcemapResult> {\n const activeTags = getDevSourcemapTags().filter((item) =>\n item.sourceMapNode && item.sourceMapNode.parentNode === item.tag\n );\n const browserWindow = getBrowserWindow();\n const fetcher = browserWindow?.fetch?.bind(browserWindow);\n const sourceMapCache = new Map<string, Promise<SourceMapData | null>>();\n const sourcemaps = new Set<string>();\n let rules = 0;\n let remapped = 0;\n let unresolved = 0;\n\n for (let i = 0, len = activeTags.length; i < len; i++) {\n const item = activeTags[i];\n let touched = false;\n\n for (let j = 0, ruleLen = item.rules.length; j < ruleLen; j++) {\n const rule = item.rules[j];\n const callsite = getSourcemapRuleCallsite(rule);\n\n if (!callsite) continue;\n if (isDisplaySourceUrl(callsite.sourceUrl || callsite.filePath)) continue;\n\n rules++;\n\n const nextCallsite = await traceCallsiteSourcemap(\n callsite,\n fetcher,\n sourceMapCache,\n );\n\n if (nextCallsite) {\n if (nextCallsite.sourceMapUrl) sourcemaps.add(nextCallsite.sourceMapUrl);\n rule.callsite = nextCallsite.callsite;\n rule.debug = null;\n rule.debugField = null;\n remapped++;\n } else {\n rule.callsite = createDisplayCallsite(callsite);\n rule.debug = null;\n rule.debugField = null;\n unresolved++;\n }\n\n touched = true;\n }\n\n if (touched) {\n rewriteDevSourcemapTag(item);\n }\n }\n\n return {\n tags: activeTags.length,\n rules,\n remapped,\n unresolved,\n sourcemaps: [...sourcemaps],\n };\n}\n\nasync function traceCallsiteSourcemap(\n callsite: SheetCallsite,\n fetcher: typeof fetch | undefined,\n sourceMapCache: Map<string, Promise<SourceMapData | null>>,\n): Promise<{ callsite: SheetCallsite; sourceMapUrl: string; } | null> {\n if (!fetcher) return null;\n\n const generatedUrl = getFetchableGeneratedUrl(\n callsite.sourceUrl || callsite.filePath,\n );\n\n if (!generatedUrl) return null;\n\n let sourceMapPromise = sourceMapCache.get(generatedUrl);\n\n if (!sourceMapPromise) {\n sourceMapPromise = fetchSourceMap(getGeneratedUrlFetchCandidates(generatedUrl), fetcher);\n sourceMapCache.set(generatedUrl, sourceMapPromise);\n }\n\n const sourceMap = await sourceMapPromise;\n\n if (!sourceMap) return null;\n\n const original = originalPositionFor(sourceMap.map, {\n line: callsite.line,\n column: Math.max(callsite.column - 1, 0),\n });\n\n if (!original.source || original.line == null || original.column == null) {\n return null;\n }\n\n const sourceUrl = resolveOriginalSourceUrl(\n original.source,\n sourceMap.sourceBaseUrl,\n sourceMap.sourceRoot,\n );\n const sourceContent = getSourceContent(sourceMap, original.source, sourceUrl);\n const displaySourceUrl = getDisplaySourceUrl(sourceUrl);\n\n return {\n sourceMapUrl: sourceMap.url,\n callsite: {\n filePath: displaySourceUrl,\n sourceUrl: displaySourceUrl,\n sourceContent,\n line: original.line,\n column: original.column + 1,\n },\n };\n}\n\nfunction rewriteDevSourcemapTag(item: ReturnType<typeof getDevSourcemapTags>[number]) {\n const document = item.tag.ownerDocument;\n\n item.tag.textContent = '';\n\n for (let i = 0, len = item.rules.length; i < len; i++) {\n item.tag.appendChild(document.createTextNode(item.rules[i].css + '\\n'));\n }\n\n item.sourceMapNode = document.createTextNode('\\n' + createSourceMapComment(item.rules));\n item.tag.appendChild(item.sourceMapNode);\n}\n\nfunction createDisplayCallsite(callsite: SheetCallsite): SheetCallsite {\n const displaySourceUrl = getDisplaySourceUrl(callsite.sourceUrl || callsite.filePath);\n\n return {\n ...callsite,\n filePath: displaySourceUrl,\n sourceUrl: displaySourceUrl,\n };\n}\n\nfunction isDisplaySourceUrl(sourceUrl: string) {\n return sourceUrl.match(SOURCE_MAPPING_URL_REGEX);\n}\n\nasync function fetchSourceMap(\n generatedUrls: string[],\n fetcher: typeof fetch,\n): Promise<SourceMapData | null> {\n for (const generatedUrl of generatedUrls) {\n try {\n const response = await fetcher(generatedUrl);\n\n if (!response.ok) continue;\n\n const source = await response.text();\n const sourceMapUrl = findSourceMapUrl(source, generatedUrl);\n\n if (!sourceMapUrl) continue;\n\n const rawMap = await loadSourceMap(sourceMapUrl, fetcher);\n\n if (!rawMap) continue;\n\n const sourceBaseUrl = sourceMapUrl.startsWith('data:')\n ? normalizeGeneratedUrl(generatedUrl)\n : sourceMapUrl;\n\n return {\n url: sourceMapUrl,\n sourceBaseUrl,\n rawMap,\n map: new TraceMap(rawMap, sourceBaseUrl),\n sourceRoot: typeof rawMap.sourceRoot === 'string' ? rawMap.sourceRoot : undefined,\n };\n } catch {\n // Try the next generated URL variant.\n }\n }\n\n return null;\n}\n\nasync function loadSourceMap(sourceMapUrl: string, fetcher: typeof fetch) {\n try {\n if (sourceMapUrl.startsWith('data:')) {\n return parseDataUrlSourceMap(sourceMapUrl);\n }\n\n const response = await fetcher(sourceMapUrl);\n\n if (!response.ok) return null;\n\n return JSON.parse(await response.text()) as EncodedSourceMap;\n } catch {\n return null;\n }\n}\n\nfunction findSourceMapUrl(source: string, generatedUrl: string) {\n let match: RegExpExecArray | null = null;\n let sourceMapUrl: string | null = null;\n\n SOURCE_MAPPING_URL_REGEX.lastIndex = 0;\n\n while ((match = SOURCE_MAPPING_URL_REGEX.exec(source))) {\n sourceMapUrl = match[1];\n }\n\n if (!sourceMapUrl) return null;\n if (sourceMapUrl.startsWith('data:')) return sourceMapUrl;\n\n try {\n return new URL(sourceMapUrl, generatedUrl).href;\n } catch {\n return null;\n }\n}\n\nfunction parseDataUrlSourceMap(sourceMapUrl: string) {\n const commaIndex = sourceMapUrl.indexOf(',');\n\n if (commaIndex === -1) return null;\n\n const meta = sourceMapUrl.slice(0, commaIndex);\n const data = sourceMapUrl.slice(commaIndex + 1);\n const json = meta.endsWith(';base64') ? atob(data) : decodeURIComponent(data);\n\n return JSON.parse(json) as EncodedSourceMap;\n}\n\nfunction getFetchableGeneratedUrl(\n source: string,\n): string | null {\n source = normalizeCallsiteSourceUrl(source);\n\n if (source.startsWith('webpack://') || source.startsWith('node:')) {\n return null;\n }\n\n try {\n return new URL(source).href;\n } catch {\n // Continue with a browser-relative resolution below.\n }\n\n const base = getBrowserLocationHref();\n\n if (!base) return null;\n\n try {\n return new URL(source, base).href;\n } catch {\n return null;\n }\n}\n\nfunction getGeneratedUrlFetchCandidates(url: string) {\n const normalized = normalizeGeneratedUrl(url);\n\n return url === normalized ? [url] : [url, normalized];\n}\n\nfunction getDisplaySourceUrl(sourceUrl: string) {\n sourceUrl = normalizeCallsiteSourceUrl(sourceUrl);\n const normalized = normalizeGeneratedUrl(sourceUrl);\n\n try {\n const url = new URL(normalized);\n return 'source:///' + url.pathname.replace(/^\\/+/, '');\n } catch {\n return 'source:///' + normalized.replace(/^\\/+/, '');\n }\n}\n\nfunction getSourceContent(\n sourceMap: SourceMapData,\n originalSource: string,\n resolvedSourceUrl: string,\n) {\n const tracedContent = sourceContentFor(sourceMap.map, originalSource);\n\n if (tracedContent != null) return tracedContent;\n\n const rawSources = sourceMap.rawMap.sources;\n const rawSourcesContent = sourceMap.rawMap.sourcesContent;\n\n if (!rawSources || !rawSourcesContent) return undefined;\n\n const sourceKeys = getSourceMatchKeys(originalSource, resolvedSourceUrl);\n\n for (let i = 0, len = rawSources.length; i < len; i++) {\n const rawSource = rawSources[i];\n const rawContent = rawSourcesContent[i];\n\n if (typeof rawSource !== 'string') continue;\n if (typeof rawContent !== 'string') continue;\n\n const rawSourceUrl = resolveOriginalSourceUrl(\n rawSource,\n sourceMap.sourceBaseUrl,\n sourceMap.sourceRoot,\n );\n const rawKeys = getSourceMatchKeys(rawSource, rawSourceUrl);\n\n for (const key of rawKeys) {\n if (sourceKeys.has(key)) return rawContent;\n }\n }\n\n return undefined;\n}\n\nfunction getSourceMatchKeys(...sources: string[]) {\n const keys = new Set<string>();\n\n for (const source of sources) {\n if (!source) continue;\n\n keys.add(source);\n keys.add(normalizeGeneratedUrl(source));\n\n try {\n const url = new URL(source);\n keys.add(url.pathname);\n keys.add(normalizeGeneratedUrl(url.pathname));\n } catch {\n // Non-URL sources are still useful as exact keys.\n }\n }\n\n return keys;\n}\n\nfunction normalizeGeneratedUrl(source: string) {\n try {\n const url = new URL(source);\n\n url.search = '';\n url.hash = '';\n\n return url.href;\n } catch {\n const queryIndex = findFirstIndex(source, ['?', '#']);\n\n return queryIndex === -1 ? source : source.slice(0, queryIndex);\n }\n}\n\nfunction findFirstIndex(text: string, needles: string[]) {\n let index = -1;\n\n for (const needle of needles) {\n const next = text.indexOf(needle);\n if (next !== -1 && (index === -1 || next < index)) index = next;\n }\n\n return index;\n}\n\nfunction getBrowserLocationHref() {\n return getBrowserWindow()?.location.href;\n}\n\nfunction getBrowserWindow() {\n return typeof window === 'undefined' ? null : window;\n}\n\nfunction resolveOriginalSourceUrl(\n source: string,\n sourceMapUrl: string,\n sourceRoot?: string,\n) {\n if (isAbsoluteSource(source)) return source;\n\n try {\n if (sourceRoot && !isAbsoluteSource(sourceRoot)) {\n return new URL(sourceRoot.replace(/\\/?$/, '/') + source, sourceMapUrl).href;\n }\n\n if (sourceRoot) {\n return new URL(source, sourceRoot).href;\n }\n\n return new URL(source, sourceMapUrl).href;\n } catch {\n return sourceRoot ? sourceRoot.replace(/\\/?$/, '/') + source : source;\n }\n}\n\nfunction isAbsoluteSource(source: string) {\n return /^[a-zA-Z][a-zA-Z\\d+.-]*:/.test(source) || source.startsWith('/');\n}\n"],"mappings":";;;;AAsBA,MAAM,2BAA2B;AAEjC,eAAsB,qBAAoD;CACxE,MAAM,aAAa,oBAAoB,EAAE,QAAQ,SAC/C,KAAK,iBAAiB,KAAK,cAAc,eAAe,KAAK,GAC/D;CACA,MAAM,gBAAgB,iBAAiB;CACvC,MAAM,UAAU,eAAe,OAAO,KAAK,aAAa;CACxD,MAAM,iCAAiB,IAAI,IAA2C;CACtE,MAAM,6BAAa,IAAI,IAAY;CACnC,IAAI,QAAQ;CACZ,IAAI,WAAW;CACf,IAAI,aAAa;CAEjB,KAAK,IAAI,IAAI,GAAG,MAAM,WAAW,QAAQ,IAAI,KAAK,KAAK;EACrD,MAAM,OAAO,WAAW;EACxB,IAAI,UAAU;EAEd,KAAK,IAAI,IAAI,GAAG,UAAU,KAAK,MAAM,QAAQ,IAAI,SAAS,KAAK;GAC7D,MAAM,O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AO;AACT;AAEA,SAAS,sBAAsB,QAAgB;CAC7C,IAAI;EACF,MAAM,MAAM,IAAI,IAAI,MAAM;EAE1B,IAAI,SAAS;EACb,IAAI,OAAO;EAEX,OAAO,IAAI;CACb,QAAQ;EACN,MAAM,aAAa,eAAe,QAAQ,CAAC,KAAK,GAAG,CAAC;EAEpD,OAAO,eAAe,KAAK,SAAS,OAAO,MAAM,GAAG,UAAU;CAChE;AACF;AAEA,SAAS,eAAe,MAAc,SAAmB;CACvD,IAAI,QAAQ;CAEZ,KAAK,MAAM,UAAU,SAAS;EAC5B,MAAM,OAAO,KAAK,QAAQ,MAAM;EAChC,IAAI,SAAS,OAAO,UAAU,MAAM,OAAO,QAAQ,QAAQ;CAC7D;CAEA,OAAO;AACT;AAEA,SAAS,yBAAyB;CAChC,OAAO,iBAAiB,GAAG,SAAS;AACtC;AAEA,SAAS,mBAAmB;CAC1B,OAAO,OAAO,WAAW,cAAc,OAAO;AAChD;AAEA,SAAS,yBACP,QACA,cACA,YACA;CACA,IAAI,iBAAiB,MAAM,GAAG,OAAO;CAErC,IAAI;EACF,IAAI,cAAc,CAAC,iBAAiB,UAAU,GAC5C,OAAO,IAAI,IAAI,WAAW,QAAQ,QAAQ,GAAG,IAAI,QAAQ,YAAY,EAAE;EAGzE,IAAI,YACF,OAAO,IAAI,IAAI,QAAQ,UAAU,EAAE;EAGrC,OAAO,IAAI,IAAI,QAAQ,YAAY,EAAE;CACvC,QAAQ;EACN,OAAO,aAAa,WAAW,QAAQ,QAAQ,GAAG,IAAI,SAAS;CACjE;AACF;AAEA,SAAS,iBAAiB,QAAgB;CACxC,OAAO,2BAA2B,KAAK,MAAM,KAAK,OAAO,WAAW,GAAG;AACzE"}
|
|
1
|
+
{"version":3,"file":"trace-BxvaCfGx.js","names":[],"sources":["../dev/trace.ts"],"sourcesContent":["import { type EncodedSourceMap, originalPositionFor, sourceContentFor, TraceMap } from '@jridgewell/trace-mapping';\nimport { getDevSourcemapTags } from '../sheet/dev';\nimport { createSourceMapComment, getSourcemapRuleCallsite } from '../sheet/sourcemap';\nimport type { SheetCallsite } from '../sheet/types';\nimport { normalizeCallsiteSourceUrl } from '../utils/trace';\n\nexport type TraceSourcemapResult = {\n tags: number;\n rules: number;\n remapped: number;\n unresolved: number;\n sourcemaps: string[];\n};\n\ntype SourceMapData = {\n url: string;\n sourceBaseUrl: string;\n rawMap: EncodedSourceMap;\n map: TraceMap;\n sourceRoot?: string;\n};\n\nconst SOURCE_MAPPING_URL_REGEX = /(?:\\/\\/|\\/\\*)[#@]\\s*sourceMappingURL=([^\\s*]+)(?:\\s*\\*\\/)?/g;\n\nexport async function traceDevSourcemaps(): Promise<TraceSourcemapResult> {\n const activeTags = getDevSourcemapTags().filter((item) =>\n item.sourceMapNode && item.sourceMapNode.parentNode === item.tag\n );\n const browserWindow = getBrowserWindow();\n const fetcher = browserWindow?.fetch?.bind(browserWindow);\n const sourceMapCache = new Map<string, Promise<SourceMapData | null>>();\n const sourcemaps = new Set<string>();\n let rules = 0;\n let remapped = 0;\n let unresolved = 0;\n\n for (let i = 0, len = activeTags.length; i < len; i++) {\n const item = activeTags[i];\n let touched = false;\n\n for (let j = 0, ruleLen = item.rules.length; j < ruleLen; j++) {\n const rule = item.rules[j];\n const callsite = getSourcemapRuleCallsite(rule);\n\n if (!callsite) continue;\n if (isDisplaySourceUrl(callsite.sourceUrl || callsite.filePath)) continue;\n\n rules++;\n\n const nextCallsite = await traceCallsiteSourcemap(\n callsite,\n fetcher,\n sourceMapCache,\n );\n\n if (nextCallsite) {\n if (nextCallsite.sourceMapUrl) sourcemaps.add(nextCallsite.sourceMapUrl);\n rule.callsite = nextCallsite.callsite;\n rule.debug = null;\n rule.debugField = null;\n remapped++;\n } else {\n rule.callsite = createDisplayCallsite(callsite);\n rule.debug = null;\n rule.debugField = null;\n unresolved++;\n }\n\n touched = true;\n }\n\n if (touched) {\n rewriteDevSourcemapTag(item);\n }\n }\n\n return {\n tags: activeTags.length,\n rules,\n remapped,\n unresolved,\n sourcemaps: [...sourcemaps],\n };\n}\n\nasync function traceCallsiteSourcemap(\n callsite: SheetCallsite,\n fetcher: typeof fetch | undefined,\n sourceMapCache: Map<string, Promise<SourceMapData | null>>,\n): Promise<{ callsite: SheetCallsite; sourceMapUrl: string; } | null> {\n if (!fetcher) return null;\n\n const generatedUrl = getFetchableGeneratedUrl(\n callsite.sourceUrl || callsite.filePath,\n );\n\n if (!generatedUrl) return null;\n\n let sourceMapPromise = sourceMapCache.get(generatedUrl);\n\n if (!sourceMapPromise) {\n sourceMapPromise = fetchSourceMap(getGeneratedUrlFetchCandidates(generatedUrl), fetcher);\n sourceMapCache.set(generatedUrl, sourceMapPromise);\n }\n\n const sourceMap = await sourceMapPromise;\n\n if (!sourceMap) return null;\n\n const original = originalPositionFor(sourceMap.map, {\n line: callsite.line,\n column: Math.max(callsite.column - 1, 0),\n });\n\n if (!original.source || original.line == null || original.column == null) {\n return null;\n }\n\n const sourceUrl = resolveOriginalSourceUrl(\n original.source,\n sourceMap.sourceBaseUrl,\n sourceMap.sourceRoot,\n );\n const sourceContent = getSourceContent(sourceMap, original.source, sourceUrl);\n const displaySourceUrl = getDisplaySourceUrl(sourceUrl);\n\n return {\n sourceMapUrl: sourceMap.url,\n callsite: {\n filePath: displaySourceUrl,\n sourceUrl: displaySourceUrl,\n sourceContent,\n line: original.line,\n column: original.column + 1,\n },\n };\n}\n\nfunction rewriteDevSourcemapTag(item: ReturnType<typeof getDevSourcemapTags>[number]) {\n const document = item.tag.ownerDocument;\n\n item.tag.textContent = '';\n\n for (let i = 0, len = item.rules.length; i < len; i++) {\n item.tag.appendChild(document.createTextNode(item.rules[i].css + '\\n'));\n }\n\n item.sourceMapNode = document.createTextNode('\\n' + createSourceMapComment(item.rules));\n item.tag.appendChild(item.sourceMapNode);\n}\n\nfunction createDisplayCallsite(callsite: SheetCallsite): SheetCallsite {\n const displaySourceUrl = getDisplaySourceUrl(callsite.sourceUrl || callsite.filePath);\n\n return {\n ...callsite,\n filePath: displaySourceUrl,\n sourceUrl: displaySourceUrl,\n };\n}\n\nfunction isDisplaySourceUrl(sourceUrl: string) {\n return sourceUrl.match(SOURCE_MAPPING_URL_REGEX);\n}\n\nasync function fetchSourceMap(\n generatedUrls: string[],\n fetcher: typeof fetch,\n): Promise<SourceMapData | null> {\n for (const generatedUrl of generatedUrls) {\n try {\n const response = await fetcher(generatedUrl);\n\n if (!response.ok) continue;\n\n const source = await response.text();\n const sourceMapUrl = findSourceMapUrl(source, generatedUrl);\n\n if (!sourceMapUrl) continue;\n\n const rawMap = await loadSourceMap(sourceMapUrl, fetcher);\n\n if (!rawMap) continue;\n\n const sourceBaseUrl = sourceMapUrl.startsWith('data:')\n ? normalizeGeneratedUrl(generatedUrl)\n : sourceMapUrl;\n\n return {\n url: sourceMapUrl,\n sourceBaseUrl,\n rawMap,\n map: new TraceMap(rawMap, sourceBaseUrl),\n sourceRoot: typeof rawMap.sourceRoot === 'string' ? rawMap.sourceRoot : undefined,\n };\n } catch {\n // Try the next generated URL variant.\n }\n }\n\n return null;\n}\n\nasync function loadSourceMap(sourceMapUrl: string, fetcher: typeof fetch) {\n try {\n if (sourceMapUrl.startsWith('data:')) {\n return parseDataUrlSourceMap(sourceMapUrl);\n }\n\n const response = await fetcher(sourceMapUrl);\n\n if (!response.ok) return null;\n\n return JSON.parse(await response.text()) as EncodedSourceMap;\n } catch {\n return null;\n }\n}\n\nfunction findSourceMapUrl(source: string, generatedUrl: string) {\n let match: RegExpExecArray | null = null;\n let sourceMapUrl: string | null = null;\n\n SOURCE_MAPPING_URL_REGEX.lastIndex = 0;\n\n while ((match = SOURCE_MAPPING_URL_REGEX.exec(source))) {\n sourceMapUrl = match[1];\n }\n\n if (!sourceMapUrl) return null;\n if (sourceMapUrl.startsWith('data:')) return sourceMapUrl;\n\n try {\n return new URL(sourceMapUrl, generatedUrl).href;\n } catch {\n return null;\n }\n}\n\nfunction parseDataUrlSourceMap(sourceMapUrl: string) {\n const commaIndex = sourceMapUrl.indexOf(',');\n\n if (commaIndex === -1) return null;\n\n const meta = sourceMapUrl.slice(0, commaIndex);\n const data = sourceMapUrl.slice(commaIndex + 1);\n const json = meta.endsWith(';base64') ? atob(data) : decodeURIComponent(data);\n\n return JSON.parse(json) as EncodedSourceMap;\n}\n\nfunction getFetchableGeneratedUrl(\n source: string,\n): string | null {\n source = normalizeCallsiteSourceUrl(source);\n\n if (source.startsWith('webpack://') || source.startsWith('node:')) {\n return null;\n }\n\n try {\n return new URL(source).href;\n } catch {\n // Continue with a browser-relative resolution below.\n }\n\n const base = getBrowserLocationHref();\n\n if (!base) return null;\n\n try {\n return new URL(source, base).href;\n } catch {\n return null;\n }\n}\n\nfunction getGeneratedUrlFetchCandidates(url: string) {\n const normalized = normalizeGeneratedUrl(url);\n\n return url === normalized ? [url] : [url, normalized];\n}\n\nfunction getDisplaySourceUrl(sourceUrl: string) {\n sourceUrl = normalizeCallsiteSourceUrl(sourceUrl);\n const normalized = normalizeGeneratedUrl(sourceUrl);\n\n try {\n const url = new URL(normalized);\n return 'source:///' + url.pathname.replace(/^\\/+/, '');\n } catch {\n return 'source:///' + normalized.replace(/^\\/+/, '');\n }\n}\n\nfunction getSourceContent(\n sourceMap: SourceMapData,\n originalSource: string,\n resolvedSourceUrl: string,\n) {\n const tracedContent = sourceContentFor(sourceMap.map, originalSource);\n\n if (tracedContent != null) return tracedContent;\n\n const rawSources = sourceMap.rawMap.sources;\n const rawSourcesContent = sourceMap.rawMap.sourcesContent;\n\n if (!rawSources || !rawSourcesContent) return undefined;\n\n const sourceKeys = getSourceMatchKeys(originalSource, resolvedSourceUrl);\n\n for (let i = 0, len = rawSources.length; i < len; i++) {\n const rawSource = rawSources[i];\n const rawContent = rawSourcesContent[i];\n\n if (typeof rawSource !== 'string') continue;\n if (typeof rawContent !== 'string') continue;\n\n const rawSourceUrl = resolveOriginalSourceUrl(\n rawSource,\n sourceMap.sourceBaseUrl,\n sourceMap.sourceRoot,\n );\n const rawKeys = getSourceMatchKeys(rawSource, rawSourceUrl);\n\n for (const key of rawKeys) {\n if (sourceKeys.has(key)) return rawContent;\n }\n }\n\n return undefined;\n}\n\nfunction getSourceMatchKeys(...sources: string[]) {\n const keys = new Set<string>();\n\n for (const source of sources) {\n if (!source) continue;\n\n keys.add(source);\n keys.add(normalizeGeneratedUrl(source));\n\n try {\n const url = new URL(source);\n keys.add(url.pathname);\n keys.add(normalizeGeneratedUrl(url.pathname));\n } catch {\n // Non-URL sources are still useful as exact keys.\n }\n }\n\n return keys;\n}\n\nfunction normalizeGeneratedUrl(source: string) {\n try {\n const url = new URL(source);\n\n url.search = '';\n url.hash = '';\n\n return url.href;\n } catch {\n const queryIndex = findFirstIndex(source, ['?', '#']);\n\n return queryIndex === -1 ? source : source.slice(0, queryIndex);\n }\n}\n\nfunction findFirstIndex(text: string, needles: string[]) {\n let index = -1;\n\n for (const needle of needles) {\n const next = text.indexOf(needle);\n if (next !== -1 && (index === -1 || next < index)) index = next;\n }\n\n return index;\n}\n\nfunction getBrowserLocationHref() {\n return getBrowserWindow()?.location.href;\n}\n\nfunction getBrowserWindow() {\n return typeof window === 'undefined' ? null : window;\n}\n\nfunction resolveOriginalSourceUrl(\n source: string,\n sourceMapUrl: string,\n sourceRoot?: string,\n) {\n if (isAbsoluteSource(source)) return source;\n\n try {\n if (sourceRoot && !isAbsoluteSource(sourceRoot)) {\n return new URL(sourceRoot.replace(/\\/?$/, '/') + source, sourceMapUrl).href;\n }\n\n if (sourceRoot) {\n return new URL(source, sourceRoot).href;\n }\n\n return new URL(source, sourceMapUrl).href;\n } catch {\n return sourceRoot ? sourceRoot.replace(/\\/?$/, '/') + source : source;\n }\n}\n\nfunction isAbsoluteSource(source: string) {\n return /^[a-zA-Z][a-zA-Z\\d+.-]*:/.test(source) || source.startsWith('/');\n}\n"],"mappings":";;;;AAsBA,MAAM,2BAA2B;AAEjC,eAAsB,qBAAoD;CACxE,MAAM,aAAa,oBAAoB,EAAE,QAAQ,SAC/C,KAAK,iBAAiB,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,IAAI,IAAI,QAAQ,UAAU,EAAE;EAGrC,OAAO,IAAI,IAAI,QAAQ,YAAY,EAAE;CACvC,QAAQ;EACN,OAAO,aAAa,WAAW,QAAQ,QAAQ,GAAG,IAAI,SAAS;CACjE;AACF;AAEA,SAAS,iBAAiB,QAAgB;CACxC,OAAO,2BAA2B,KAAK,MAAM,KAAK,OAAO,WAAW,GAAG;AACzE"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { It as createSourceMapComment, Lt as getSourcemapRuleCallsite, Pt as getDevSourcemapTags, Wt as normalizeCallsiteSourceUrl } from "./styleStore-
|
|
1
|
+
import { It as createSourceMapComment, Lt as getSourcemapRuleCallsite, Pt as getDevSourcemapTags, Wt as normalizeCallsiteSourceUrl } from "./styleStore-BpkbvtBI.js";
|
|
2
2
|
import { TraceMap, originalPositionFor, sourceContentFor } from "@jridgewell/trace-mapping";
|
|
3
3
|
//#region dev/trace.ts
|
|
4
4
|
const SOURCE_MAPPING_URL_REGEX = /(?:\/\/|\/\*)[#@]\s*sourceMappingURL=([^\s*]+)(?:\s*\*\/)?/g;
|
|
@@ -241,4 +241,4 @@ function isAbsoluteSource(source) {
|
|
|
241
241
|
//#endregion
|
|
242
242
|
export { traceDevSourcemaps };
|
|
243
243
|
|
|
244
|
-
//# sourceMappingURL=trace-
|
|
244
|
+
//# sourceMappingURL=trace-Db5et6nx.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trace-uHVvnYiw.js","names":[],"sources":["../dev/trace.ts"],"sourcesContent":["import { type EncodedSourceMap, originalPositionFor, sourceContentFor, TraceMap } from '@jridgewell/trace-mapping';\nimport { getDevSourcemapTags } from '../sheet/dev';\nimport { createSourceMapComment, getSourcemapRuleCallsite } from '../sheet/sourcemap';\nimport type { SheetCallsite } from '../sheet/types';\nimport { normalizeCallsiteSourceUrl } from '../utils/trace';\n\nexport type TraceSourcemapResult = {\n tags: number;\n rules: number;\n remapped: number;\n unresolved: number;\n sourcemaps: string[];\n};\n\ntype SourceMapData = {\n url: string;\n sourceBaseUrl: string;\n rawMap: EncodedSourceMap;\n map: TraceMap;\n sourceRoot?: string;\n};\n\nconst SOURCE_MAPPING_URL_REGEX = /(?:\\/\\/|\\/\\*)[#@]\\s*sourceMappingURL=([^\\s*]+)(?:\\s*\\*\\/)?/g;\n\nexport async function traceDevSourcemaps(): Promise<TraceSourcemapResult> {\n const activeTags = getDevSourcemapTags().filter((item) =>\n item.sourceMapNode && item.sourceMapNode.parentNode === item.tag\n );\n const browserWindow = getBrowserWindow();\n const fetcher = browserWindow?.fetch?.bind(browserWindow);\n const sourceMapCache = new Map<string, Promise<SourceMapData | null>>();\n const sourcemaps = new Set<string>();\n let rules = 0;\n let remapped = 0;\n let unresolved = 0;\n\n for (let i = 0, len = activeTags.length; i < len; i++) {\n const item = activeTags[i];\n let touched = false;\n\n for (let j = 0, ruleLen = item.rules.length; j < ruleLen; j++) {\n const rule = item.rules[j];\n const callsite = getSourcemapRuleCallsite(rule);\n\n if (!callsite) continue;\n if (isDisplaySourceUrl(callsite.sourceUrl || callsite.filePath)) continue;\n\n rules++;\n\n const nextCallsite = await traceCallsiteSourcemap(\n callsite,\n fetcher,\n sourceMapCache,\n );\n\n if (nextCallsite) {\n if (nextCallsite.sourceMapUrl) sourcemaps.add(nextCallsite.sourceMapUrl);\n rule.callsite = nextCallsite.callsite;\n rule.debug = null;\n rule.debugField = null;\n remapped++;\n } else {\n rule.callsite = createDisplayCallsite(callsite);\n rule.debug = null;\n rule.debugField = null;\n unresolved++;\n }\n\n touched = true;\n }\n\n if (touched) {\n rewriteDevSourcemapTag(item);\n }\n }\n\n return {\n tags: activeTags.length,\n rules,\n remapped,\n unresolved,\n sourcemaps: [...sourcemaps],\n };\n}\n\nasync function traceCallsiteSourcemap(\n callsite: SheetCallsite,\n fetcher: typeof fetch | undefined,\n sourceMapCache: Map<string, Promise<SourceMapData | null>>,\n): Promise<{ callsite: SheetCallsite; sourceMapUrl: string; } | null> {\n if (!fetcher) return null;\n\n const generatedUrl = getFetchableGeneratedUrl(\n callsite.sourceUrl || callsite.filePath,\n );\n\n if (!generatedUrl) return null;\n\n let sourceMapPromise = sourceMapCache.get(generatedUrl);\n\n if (!sourceMapPromise) {\n sourceMapPromise = fetchSourceMap(getGeneratedUrlFetchCandidates(generatedUrl), fetcher);\n sourceMapCache.set(generatedUrl, sourceMapPromise);\n }\n\n const sourceMap = await sourceMapPromise;\n\n if (!sourceMap) return null;\n\n const original = originalPositionFor(sourceMap.map, {\n line: callsite.line,\n column: Math.max(callsite.column - 1, 0),\n });\n\n if (!original.source || original.line == null || original.column == null) {\n return null;\n }\n\n const sourceUrl = resolveOriginalSourceUrl(\n original.source,\n sourceMap.sourceBaseUrl,\n sourceMap.sourceRoot,\n );\n const sourceContent = getSourceContent(sourceMap, original.source, sourceUrl);\n const displaySourceUrl = getDisplaySourceUrl(sourceUrl);\n\n return {\n sourceMapUrl: sourceMap.url,\n callsite: {\n filePath: displaySourceUrl,\n sourceUrl: displaySourceUrl,\n sourceContent,\n line: original.line,\n column: original.column + 1,\n },\n };\n}\n\nfunction rewriteDevSourcemapTag(item: ReturnType<typeof getDevSourcemapTags>[number]) {\n const document = item.tag.ownerDocument;\n\n item.tag.textContent = '';\n\n for (let i = 0, len = item.rules.length; i < len; i++) {\n item.tag.appendChild(document.createTextNode(item.rules[i].css + '\\n'));\n }\n\n item.sourceMapNode = document.createTextNode('\\n' + createSourceMapComment(item.rules));\n item.tag.appendChild(item.sourceMapNode);\n}\n\nfunction createDisplayCallsite(callsite: SheetCallsite): SheetCallsite {\n const displaySourceUrl = getDisplaySourceUrl(callsite.sourceUrl || callsite.filePath);\n\n return {\n ...callsite,\n filePath: displaySourceUrl,\n sourceUrl: displaySourceUrl,\n };\n}\n\nfunction isDisplaySourceUrl(sourceUrl: string) {\n return sourceUrl.match(SOURCE_MAPPING_URL_REGEX);\n}\n\nasync function fetchSourceMap(\n generatedUrls: string[],\n fetcher: typeof fetch,\n): Promise<SourceMapData | null> {\n for (const generatedUrl of generatedUrls) {\n try {\n const response = await fetcher(generatedUrl);\n\n if (!response.ok) continue;\n\n const source = await response.text();\n const sourceMapUrl = findSourceMapUrl(source, generatedUrl);\n\n if (!sourceMapUrl) continue;\n\n const rawMap = await loadSourceMap(sourceMapUrl, fetcher);\n\n if (!rawMap) continue;\n\n const sourceBaseUrl = sourceMapUrl.startsWith('data:')\n ? normalizeGeneratedUrl(generatedUrl)\n : sourceMapUrl;\n\n return {\n url: sourceMapUrl,\n sourceBaseUrl,\n rawMap,\n map: new TraceMap(rawMap, sourceBaseUrl),\n sourceRoot: typeof rawMap.sourceRoot === 'string' ? rawMap.sourceRoot : undefined,\n };\n } catch {\n // Try the next generated URL variant.\n }\n }\n\n return null;\n}\n\nasync function loadSourceMap(sourceMapUrl: string, fetcher: typeof fetch) {\n try {\n if (sourceMapUrl.startsWith('data:')) {\n return parseDataUrlSourceMap(sourceMapUrl);\n }\n\n const response = await fetcher(sourceMapUrl);\n\n if (!response.ok) return null;\n\n return JSON.parse(await response.text()) as EncodedSourceMap;\n } catch {\n return null;\n }\n}\n\nfunction findSourceMapUrl(source: string, generatedUrl: string) {\n let match: RegExpExecArray | null = null;\n let sourceMapUrl: string | null = null;\n\n SOURCE_MAPPING_URL_REGEX.lastIndex = 0;\n\n while ((match = SOURCE_MAPPING_URL_REGEX.exec(source))) {\n sourceMapUrl = match[1];\n }\n\n if (!sourceMapUrl) return null;\n if (sourceMapUrl.startsWith('data:')) return sourceMapUrl;\n\n try {\n return new URL(sourceMapUrl, generatedUrl).href;\n } catch {\n return null;\n }\n}\n\nfunction parseDataUrlSourceMap(sourceMapUrl: string) {\n const commaIndex = sourceMapUrl.indexOf(',');\n\n if (commaIndex === -1) return null;\n\n const meta = sourceMapUrl.slice(0, commaIndex);\n const data = sourceMapUrl.slice(commaIndex + 1);\n const json = meta.endsWith(';base64') ? atob(data) : decodeURIComponent(data);\n\n return JSON.parse(json) as EncodedSourceMap;\n}\n\nfunction getFetchableGeneratedUrl(\n source: string,\n): string | null {\n source = normalizeCallsiteSourceUrl(source);\n\n if (source.startsWith('webpack://') || source.startsWith('node:')) {\n return null;\n }\n\n try {\n return new URL(source).href;\n } catch {\n // Continue with a browser-relative resolution below.\n }\n\n const base = getBrowserLocationHref();\n\n if (!base) return null;\n\n try {\n return new URL(source, base).href;\n } catch {\n return null;\n }\n}\n\nfunction getGeneratedUrlFetchCandidates(url: string) {\n const normalized = normalizeGeneratedUrl(url);\n\n return url === normalized ? [url] : [url, normalized];\n}\n\nfunction getDisplaySourceUrl(sourceUrl: string) {\n sourceUrl = normalizeCallsiteSourceUrl(sourceUrl);\n const normalized = normalizeGeneratedUrl(sourceUrl);\n\n try {\n const url = new URL(normalized);\n return 'source:///' + url.pathname.replace(/^\\/+/, '');\n } catch {\n return 'source:///' + normalized.replace(/^\\/+/, '');\n }\n}\n\nfunction getSourceContent(\n sourceMap: SourceMapData,\n originalSource: string,\n resolvedSourceUrl: string,\n) {\n const tracedContent = sourceContentFor(sourceMap.map, originalSource);\n\n if (tracedContent != null) return tracedContent;\n\n const rawSources = sourceMap.rawMap.sources;\n const rawSourcesContent = sourceMap.rawMap.sourcesContent;\n\n if (!rawSources || !rawSourcesContent) return undefined;\n\n const sourceKeys = getSourceMatchKeys(originalSource, resolvedSourceUrl);\n\n for (let i = 0, len = rawSources.length; i < len; i++) {\n const rawSource = rawSources[i];\n const rawContent = rawSourcesContent[i];\n\n if (typeof rawSource !== 'string') continue;\n if (typeof rawContent !== 'string') continue;\n\n const rawSourceUrl = resolveOriginalSourceUrl(\n rawSource,\n sourceMap.sourceBaseUrl,\n sourceMap.sourceRoot,\n );\n const rawKeys = getSourceMatchKeys(rawSource, rawSourceUrl);\n\n for (const key of rawKeys) {\n if (sourceKeys.has(key)) return rawContent;\n }\n }\n\n return undefined;\n}\n\nfunction getSourceMatchKeys(...sources: string[]) {\n const keys = new Set<string>();\n\n for (const source of sources) {\n if (!source) continue;\n\n keys.add(source);\n keys.add(normalizeGeneratedUrl(source));\n\n try {\n const url = new URL(source);\n keys.add(url.pathname);\n keys.add(normalizeGeneratedUrl(url.pathname));\n } catch {\n // Non-URL sources are still useful as exact keys.\n }\n }\n\n return keys;\n}\n\nfunction normalizeGeneratedUrl(source: string) {\n try {\n const url = new URL(source);\n\n url.search = '';\n url.hash = '';\n\n return url.href;\n } catch {\n const queryIndex = findFirstIndex(source, ['?', '#']);\n\n return queryIndex === -1 ? source : source.slice(0, queryIndex);\n }\n}\n\nfunction findFirstIndex(text: string, needles: string[]) {\n let index = -1;\n\n for (const needle of needles) {\n const next = text.indexOf(needle);\n if (next !== -1 && (index === -1 || next < index)) index = next;\n }\n\n return index;\n}\n\nfunction getBrowserLocationHref() {\n return getBrowserWindow()?.location.href;\n}\n\nfunction getBrowserWindow() {\n return typeof window === 'undefined' ? null : window;\n}\n\nfunction resolveOriginalSourceUrl(\n source: string,\n sourceMapUrl: string,\n sourceRoot?: string,\n) {\n if (isAbsoluteSource(source)) return source;\n\n try {\n if (sourceRoot && !isAbsoluteSource(sourceRoot)) {\n return new URL(sourceRoot.replace(/\\/?$/, '/') + source, sourceMapUrl).href;\n }\n\n if (sourceRoot) {\n return new URL(source, sourceRoot).href;\n }\n\n return new URL(source, sourceMapUrl).href;\n } catch {\n return sourceRoot ? sourceRoot.replace(/\\/?$/, '/') + source : source;\n }\n}\n\nfunction isAbsoluteSource(source: string) {\n return /^[a-zA-Z][a-zA-Z\\d+.-]*:/.test(source) || source.startsWith('/');\n}\n"],"mappings":";;;AAsBA,MAAM,2BAA2B;AAEjC,eAAsB,qBAAoD;CACxE,MAAM,aAAa,oBAAoB,EAAE,QAAQ,SAC/C,KAAK,iBAAiB,KAAK,cAAc,eAAe,KAAK,GAC/D;CACA,MAAM,gBAAgB,iBAAiB;CACvC,MAAM,UAAU,eAAe,OAAO,KAAK,aAAa;CACxD,MAAM,iCAAiB,IAAI,IAA2C;CACtE,MAAM,6BAAa,IAAI,IAAY;CACnC,IAAI,QA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gB;CACxC,OAAO,2BAA2B,KAAK,MAAM,KAAK,OAAO,WAAW,GAAG;AACzE"}
|
|
1
|
+
{"version":3,"file":"trace-Db5et6nx.js","names":[],"sources":["../dev/trace.ts"],"sourcesContent":["import { type EncodedSourceMap, originalPositionFor, sourceContentFor, TraceMap } from '@jridgewell/trace-mapping';\nimport { getDevSourcemapTags } from '../sheet/dev';\nimport { createSourceMapComment, getSourcemapRuleCallsite } from '../sheet/sourcemap';\nimport type { SheetCallsite } from '../sheet/types';\nimport { normalizeCallsiteSourceUrl } from '../utils/trace';\n\nexport type TraceSourcemapResult = {\n tags: number;\n rules: number;\n remapped: number;\n unresolved: number;\n sourcemaps: string[];\n};\n\ntype SourceMapData = {\n url: string;\n sourceBaseUrl: string;\n rawMap: EncodedSourceMap;\n map: TraceMap;\n sourceRoot?: string;\n};\n\nconst SOURCE_MAPPING_URL_REGEX = /(?:\\/\\/|\\/\\*)[#@]\\s*sourceMappingURL=([^\\s*]+)(?:\\s*\\*\\/)?/g;\n\nexport async function traceDevSourcemaps(): Promise<TraceSourcemapResult> {\n const activeTags = getDevSourcemapTags().filter((item) =>\n item.sourceMapNode && item.sourceMapNode.parentNode === item.tag\n );\n const browserWindow = getBrowserWindow();\n const fetcher = browserWindow?.fetch?.bind(browserWindow);\n const sourceMapCache = new Map<string, Promise<SourceMapData | null>>();\n const sourcemaps = new Set<string>();\n let rules = 0;\n let remapped = 0;\n let unresolved = 0;\n\n for (let i = 0, len = activeTags.length; i < len; i++) {\n const item = activeTags[i];\n let touched = false;\n\n for (let j = 0, ruleLen = item.rules.length; j < ruleLen; j++) {\n const rule = item.rules[j];\n const callsite = getSourcemapRuleCallsite(rule);\n\n if (!callsite) continue;\n if (isDisplaySourceUrl(callsite.sourceUrl || callsite.filePath)) continue;\n\n rules++;\n\n const nextCallsite = await traceCallsiteSourcemap(\n callsite,\n fetcher,\n sourceMapCache,\n );\n\n if (nextCallsite) {\n if (nextCallsite.sourceMapUrl) sourcemaps.add(nextCallsite.sourceMapUrl);\n rule.callsite = nextCallsite.callsite;\n rule.debug = null;\n rule.debugField = null;\n remapped++;\n } else {\n rule.callsite = createDisplayCallsite(callsite);\n rule.debug = null;\n rule.debugField = null;\n unresolved++;\n }\n\n touched = true;\n }\n\n if (touched) {\n rewriteDevSourcemapTag(item);\n }\n }\n\n return {\n tags: activeTags.length,\n rules,\n remapped,\n unresolved,\n sourcemaps: [...sourcemaps],\n };\n}\n\nasync function traceCallsiteSourcemap(\n callsite: SheetCallsite,\n fetcher: typeof fetch | undefined,\n sourceMapCache: Map<string, Promise<SourceMapData | null>>,\n): Promise<{ callsite: SheetCallsite; sourceMapUrl: string; } | null> {\n if (!fetcher) return null;\n\n const generatedUrl = getFetchableGeneratedUrl(\n callsite.sourceUrl || callsite.filePath,\n );\n\n if (!generatedUrl) return null;\n\n let sourceMapPromise = sourceMapCache.get(generatedUrl);\n\n if (!sourceMapPromise) {\n sourceMapPromise = fetchSourceMap(getGeneratedUrlFetchCandidates(generatedUrl), fetcher);\n sourceMapCache.set(generatedUrl, sourceMapPromise);\n }\n\n const sourceMap = await sourceMapPromise;\n\n if (!sourceMap) return null;\n\n const original = originalPositionFor(sourceMap.map, {\n line: callsite.line,\n column: Math.max(callsite.column - 1, 0),\n });\n\n if (!original.source || original.line == null || original.column == null) {\n return null;\n }\n\n const sourceUrl = resolveOriginalSourceUrl(\n original.source,\n sourceMap.sourceBaseUrl,\n sourceMap.sourceRoot,\n );\n const sourceContent = getSourceContent(sourceMap, original.source, sourceUrl);\n const displaySourceUrl = getDisplaySourceUrl(sourceUrl);\n\n return {\n sourceMapUrl: sourceMap.url,\n callsite: {\n filePath: displaySourceUrl,\n sourceUrl: displaySourceUrl,\n sourceContent,\n line: original.line,\n column: original.column + 1,\n },\n };\n}\n\nfunction rewriteDevSourcemapTag(item: ReturnType<typeof getDevSourcemapTags>[number]) {\n const document = item.tag.ownerDocument;\n\n item.tag.textContent = '';\n\n for (let i = 0, len = item.rules.length; i < len; i++) {\n item.tag.appendChild(document.createTextNode(item.rules[i].css + '\\n'));\n }\n\n item.sourceMapNode = document.createTextNode('\\n' + createSourceMapComment(item.rules));\n item.tag.appendChild(item.sourceMapNode);\n}\n\nfunction createDisplayCallsite(callsite: SheetCallsite): SheetCallsite {\n const displaySourceUrl = getDisplaySourceUrl(callsite.sourceUrl || callsite.filePath);\n\n return {\n ...callsite,\n filePath: displaySourceUrl,\n sourceUrl: displaySourceUrl,\n };\n}\n\nfunction isDisplaySourceUrl(sourceUrl: string) {\n return sourceUrl.match(SOURCE_MAPPING_URL_REGEX);\n}\n\nasync function fetchSourceMap(\n generatedUrls: string[],\n fetcher: typeof fetch,\n): Promise<SourceMapData | null> {\n for (const generatedUrl of generatedUrls) {\n try {\n const response = await fetcher(generatedUrl);\n\n if (!response.ok) continue;\n\n const source = await response.text();\n const sourceMapUrl = findSourceMapUrl(source, generatedUrl);\n\n if (!sourceMapUrl) continue;\n\n const rawMap = await loadSourceMap(sourceMapUrl, fetcher);\n\n if (!rawMap) continue;\n\n const sourceBaseUrl = sourceMapUrl.startsWith('data:')\n ? normalizeGeneratedUrl(generatedUrl)\n : sourceMapUrl;\n\n return {\n url: sourceMapUrl,\n sourceBaseUrl,\n rawMap,\n map: new TraceMap(rawMap, sourceBaseUrl),\n sourceRoot: typeof rawMap.sourceRoot === 'string' ? rawMap.sourceRoot : undefined,\n };\n } catch {\n // Try the next generated URL variant.\n }\n }\n\n return null;\n}\n\nasync function loadSourceMap(sourceMapUrl: string, fetcher: typeof fetch) {\n try {\n if (sourceMapUrl.startsWith('data:')) {\n return parseDataUrlSourceMap(sourceMapUrl);\n }\n\n const response = await fetcher(sourceMapUrl);\n\n if (!response.ok) return null;\n\n return JSON.parse(await response.text()) as EncodedSourceMap;\n } catch {\n return null;\n }\n}\n\nfunction findSourceMapUrl(source: string, generatedUrl: string) {\n let match: RegExpExecArray | null = null;\n let sourceMapUrl: string | null = null;\n\n SOURCE_MAPPING_URL_REGEX.lastIndex = 0;\n\n while ((match = SOURCE_MAPPING_URL_REGEX.exec(source))) {\n sourceMapUrl = match[1];\n }\n\n if (!sourceMapUrl) return null;\n if (sourceMapUrl.startsWith('data:')) return sourceMapUrl;\n\n try {\n return new URL(sourceMapUrl, generatedUrl).href;\n } catch {\n return null;\n }\n}\n\nfunction parseDataUrlSourceMap(sourceMapUrl: string) {\n const commaIndex = sourceMapUrl.indexOf(',');\n\n if (commaIndex === -1) return null;\n\n const meta = sourceMapUrl.slice(0, commaIndex);\n const data = sourceMapUrl.slice(commaIndex + 1);\n const json = meta.endsWith(';base64') ? atob(data) : decodeURIComponent(data);\n\n return JSON.parse(json) as EncodedSourceMap;\n}\n\nfunction getFetchableGeneratedUrl(\n source: string,\n): string | null {\n source = normalizeCallsiteSourceUrl(source);\n\n if (source.startsWith('webpack://') || source.startsWith('node:')) {\n return null;\n }\n\n try {\n return new URL(source).href;\n } catch {\n // Continue with a browser-relative resolution below.\n }\n\n const base = getBrowserLocationHref();\n\n if (!base) return null;\n\n try {\n return new URL(source, base).href;\n } catch {\n return null;\n }\n}\n\nfunction getGeneratedUrlFetchCandidates(url: string) {\n const normalized = normalizeGeneratedUrl(url);\n\n return url === normalized ? [url] : [url, normalized];\n}\n\nfunction getDisplaySourceUrl(sourceUrl: string) {\n sourceUrl = normalizeCallsiteSourceUrl(sourceUrl);\n const normalized = normalizeGeneratedUrl(sourceUrl);\n\n try {\n const url = new URL(normalized);\n return 'source:///' + url.pathname.replace(/^\\/+/, '');\n } catch {\n return 'source:///' + normalized.replace(/^\\/+/, '');\n }\n}\n\nfunction getSourceContent(\n sourceMap: SourceMapData,\n originalSource: string,\n resolvedSourceUrl: string,\n) {\n const tracedContent = sourceContentFor(sourceMap.map, originalSource);\n\n if (tracedContent != null) return tracedContent;\n\n const rawSources = sourceMap.rawMap.sources;\n const rawSourcesContent = sourceMap.rawMap.sourcesContent;\n\n if (!rawSources || !rawSourcesContent) return undefined;\n\n const sourceKeys = getSourceMatchKeys(originalSource, resolvedSourceUrl);\n\n for (let i = 0, len = rawSources.length; i < len; i++) {\n const rawSource = rawSources[i];\n const rawContent = rawSourcesContent[i];\n\n if (typeof rawSource !== 'string') continue;\n if (typeof rawContent !== 'string') continue;\n\n const rawSourceUrl = resolveOriginalSourceUrl(\n rawSource,\n sourceMap.sourceBaseUrl,\n sourceMap.sourceRoot,\n );\n const rawKeys = getSourceMatchKeys(rawSource, rawSourceUrl);\n\n for (const key of rawKeys) {\n if (sourceKeys.has(key)) return rawContent;\n }\n }\n\n return undefined;\n}\n\nfunction getSourceMatchKeys(...sources: string[]) {\n const keys = new Set<string>();\n\n for (const source of sources) {\n if (!source) continue;\n\n keys.add(source);\n keys.add(normalizeGeneratedUrl(source));\n\n try {\n const url = new URL(source);\n keys.add(url.pathname);\n keys.add(normalizeGeneratedUrl(url.pathname));\n } catch {\n // Non-URL sources are still useful as exact keys.\n }\n }\n\n return keys;\n}\n\nfunction normalizeGeneratedUrl(source: string) {\n try {\n const url = new URL(source);\n\n url.search = '';\n url.hash = '';\n\n return url.href;\n } catch {\n const queryIndex = findFirstIndex(source, ['?', '#']);\n\n return queryIndex === -1 ? source : source.slice(0, queryIndex);\n }\n}\n\nfunction findFirstIndex(text: string, needles: string[]) {\n let index = -1;\n\n for (const needle of needles) {\n const next = text.indexOf(needle);\n if (next !== -1 && (index === -1 || next < index)) index = next;\n }\n\n return index;\n}\n\nfunction getBrowserLocationHref() {\n return getBrowserWindow()?.location.href;\n}\n\nfunction getBrowserWindow() {\n return typeof window === 'undefined' ? null : window;\n}\n\nfunction resolveOriginalSourceUrl(\n source: string,\n sourceMapUrl: string,\n sourceRoot?: string,\n) {\n if (isAbsoluteSource(source)) return source;\n\n try {\n if (sourceRoot && !isAbsoluteSource(sourceRoot)) {\n return new URL(sourceRoot.replace(/\\/?$/, '/') + source, sourceMapUrl).href;\n }\n\n if (sourceRoot) {\n return new URL(source, sourceRoot).href;\n }\n\n return new URL(source, sourceMapUrl).href;\n } catch {\n return sourceRoot ? sourceRoot.replace(/\\/?$/, '/') + source : source;\n }\n}\n\nfunction isAbsoluteSource(source: string) {\n return /^[a-zA-Z][a-zA-Z\\d+.-]*:/.test(source) || source.startsWith('/');\n}\n"],"mappings":";;;AAsBA,MAAM,2BAA2B;AAEjC,eAAsB,qBAAoD;CACxE,MAAM,aAAa,oBAAoB,EAAE,QAAQ,SAC/C,KAAK,iBAAiB,KAAK,cAAc,eAAe,KAAK,GAC/D;CACA,MAAM,gBAAgB,iBAAiB;CACvC,MAAM,UAAU,eAAe,OAAO,KAAK,aAAa;CACxD,MAAM,iCAAiB,IAAI,IAA2C;CACtE,MAAM,6BAAa,IAAI,IAAY;CACnC,IAAI,QAAQ;CACZ,IAAI,WAAW;CACf,IAAI,aAAa;CAEjB,KAAK,IAAI,IAAI,GAAG,MAAM,WAAW,QAAQ,IAAI,KAAK,KAAK;EACrD,MAAM,OAAO,WAAW;EACxB,IAAI,UAAU;EAEd,KAAK,IAAI,IAAI,GAAG,UAAU,KAAK,MAAM,QAAQ,IAAI,SAAS,KAAK;GAC7D,MAAM,OAAO,KAAK,MAAM;GACxB,MAAM,WAAW,yBAAyB,IAAI;GAE9C,IAAI,CAAC,UAAU;GACf,IAAI,mBAAmB,SAAS,aAAa,SAAS,QAAQ,GAAG;GAEjE;GAEA,MAAM,eAAe,MAAM,uBACzB,UACA,SACA,cACF;GAEA,IAAI,cAAc;IAChB,IAAI,aAAa,cAAc,WAAW,IAAI,aAAa,YAAY;IACvE,KAAK,WAAW,aAAa;IAC7B,KAAK,QAAQ;IACb,KAAK,aAAa;IAClB;GACF,OAAO;IACL,KAAK,WAAW,sBAAsB,QAAQ;IAC9C,KAAK,QAAQ;IACb,KAAK,aAAa;IAClB;GACF;GAEA,UAAU;EACZ;EAEA,IAAI,SACF,uBAAuB,IAAI;CAE/B;CAEA,OAAO;EACL,MAAM,WAAW;EACjB;EACA;EACA;EACA,YAAY,CAAC,GAAG,UAAU;CAC5B;AACF;AAEA,eAAe,uBACb,UACA,SACA,gBACo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AAc,OAAO;AAChD;AAEA,SAAS,yBACP,QACA,cACA,YACA;CACA,IAAI,iBAAiB,MAAM,GAAG,OAAO;CAErC,IAAI;EACF,IAAI,cAAc,CAAC,iBAAiB,UAAU,GAC5C,OAAO,IAAI,IAAI,WAAW,QAAQ,QAAQ,GAAG,IAAI,QAAQ,YAAY,EAAE;EAGzE,IAAI,YACF,OAAO,IAAI,IAAI,QAAQ,UAAU,EAAE;EAGrC,OAAO,IAAI,IAAI,QAAQ,YAAY,EAAE;CACvC,QAAQ;EACN,OAAO,aAAa,WAAW,QAAQ,QAAQ,GAAG,IAAI,SAAS;CACjE;AACF;AAEA,SAAS,iBAAiB,QAAgB;CACxC,OAAO,2BAA2B,KAAK,MAAM,KAAK,OAAO,WAAW,GAAG;AACzE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform-BZ4jPwy3.js","names":[],"sources":["../style/transform.ts"],"sourcesContent":["import { symbol } from '../utils/symbol';\nimport type {
|
|
1
|
+
{"version":3,"file":"transform-BZ4jPwy3.js","names":[],"sources":["../style/transform.ts"],"sourcesContent":["import type { CSSPropertiesRaw } from '../atomic/utils/types';\nimport { symbol } from '../utils/symbol';\nimport type { StyleObject, StyleValue } from './types';\n\nconst CLASS_NAME_VALUE: unique symbol = symbol('transform.classNameValue');\n\nexport type ClassNameValue<Value = unknown> = {\n readonly [CLASS_NAME_VALUE]: true;\n readonly value: Value;\n readonly className: string;\n};\n\nexport type TransformStyleObject<Style = unknown> = {\n [P in keyof Style]: StyleValue<Style[P] | ClassNameValue<Style[P]>>;\n};\n\nexport type StyleTransform<Style = unknown> = {\n transform(style: StyleObject<Style>): TransformStyleObject<CSSPropertiesRaw>;\n};\n\nexport type ClassNameTransform<ClassName extends string = string> = {\n transform(className: ClassName): TransformStyleObject<CSSPropertiesRaw>;\n};\n\nexport function classNameValue<const Value>(\n value: Value,\n className: string,\n): ClassNameValue<Value> {\n return {\n [CLASS_NAME_VALUE]: true,\n value,\n className,\n };\n}\n\nexport function isClassNameValue(value: unknown): value is ClassNameValue {\n return !!value &&\n typeof value === 'object' &&\n (value as ClassNameValue)[CLASS_NAME_VALUE] === true &&\n typeof (value as ClassNameValue).className === 'string';\n}\n\nexport function styleTransform<Style>(options: StyleTransform<Style>) {\n return options;\n}\n\nexport function classNameTransform<ClassName extends string>(options: ClassNameTransform<ClassName>) {\n return options;\n}\n"],"mappings":";;AAIA,MAAM,mBAAkC,OAAO,0BAA0B;AAoBzE,SAAgB,eACd,OACA,WACuB;CACvB,OAAO;GACJ,mBAAmB;EACpB;EACA;CACF;AACF;AAEA,SAAgB,iBAAiB,OAAyC;CACxE,OAAO,CAAC,CAAC,SACP,OAAO,UAAU,YAChB,MAAyB,sBAAsB,QAChD,OAAQ,MAAyB,cAAc;AACnD;AAEA,SAAgB,eAAsB,SAAgC;CACpE,OAAO;AACT;AAEA,SAAgB,mBAA6C,SAAwC;CACnG,OAAO;AACT"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type * as CSS from 'csstype';
|
|
2
2
|
export type * as CSS from 'csstype';
|
|
3
3
|
export type CSSValueExclude = '-moz-initial';
|
|
4
|
+
export type CSSPropertiesRaw = CSS.Properties<string | number>;
|
|
4
5
|
export type CSSProperties = {
|
|
5
|
-
[P in keyof
|
|
6
|
+
[P in keyof CSSPropertiesRaw]: Exclude<CSSPropertiesRaw[P], CSSValueExclude>;
|
|
6
7
|
};
|
|
7
|
-
export type CSSPropertyName = keyof
|
|
8
|
+
export type CSSPropertyName = keyof CSSPropertiesRaw;
|
|
@@ -6,4 +6,4 @@ export declare const FnPrefixScope = "scope.";
|
|
|
6
6
|
export declare const FnPrefixSelector = "selector.";
|
|
7
7
|
export declare function runtimeCallsite(): import("../utils/trace.js").TraceCallsite | null;
|
|
8
8
|
export declare function resolveCallsite(debug: DebugData | null | undefined): import("../utils/trace.js").TraceCallsite | null;
|
|
9
|
-
export declare function transformStyle<Style>(style: StyleObject<Style>, transform: StyleTransform<Style> | null): StyleObject<Style> | import("../index.js").TransformStyleObject<import("../index.js").
|
|
9
|
+
export declare function transformStyle<Style>(style: StyleObject<Style>, transform: StyleTransform<Style> | null): StyleObject<Style> | import("../index.js").TransformStyleObject<import("../index.js").CSSPropertiesRaw>;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -4,6 +4,6 @@ export { type } from "./utils/type.js";
|
|
|
4
4
|
export { type ClassNameProps, type ClassNameResult, type CombinedStyle, getClassName, getToken, transformElement, } from "./runtime/core/index.js";
|
|
5
5
|
export { bindScope, type CombinedStyleFor, combineScope, combineStyle, } from "./runtime/style/index.js";
|
|
6
6
|
export type { StyleProp, StyleTheme, StyleTokenInput, } from "./runtime/types.js";
|
|
7
|
-
export type { CSS, CSSProperties, CSSPropertyName, CSSValueExclude, } from "./atomic/utils/types.js";
|
|
7
|
+
export type { CSS, CSSProperties, CSSPropertiesRaw, CSSPropertyName, CSSValueExclude, } from "./atomic/utils/types.js";
|
|
8
8
|
export { createElement } from "./jsx/runtime/jsx_runtime.js";
|
|
9
9
|
export * from "./jsx/types/index.js";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { CSSPropertiesRaw } from "../atomic/utils/types.js";
|
|
2
|
+
import type { StyleObject, StyleValue } from "./types.js";
|
|
2
3
|
declare const CLASS_NAME_VALUE: unique symbol;
|
|
3
4
|
export type ClassNameValue<Value = unknown> = {
|
|
4
5
|
readonly [CLASS_NAME_VALUE]: true;
|
|
@@ -9,10 +10,10 @@ export type TransformStyleObject<Style = unknown> = {
|
|
|
9
10
|
[P in keyof Style]: StyleValue<Style[P] | ClassNameValue<Style[P]>>;
|
|
10
11
|
};
|
|
11
12
|
export type StyleTransform<Style = unknown> = {
|
|
12
|
-
transform(style: StyleObject<Style>): TransformStyleObject<
|
|
13
|
+
transform(style: StyleObject<Style>): TransformStyleObject<CSSPropertiesRaw>;
|
|
13
14
|
};
|
|
14
15
|
export type ClassNameTransform<ClassName extends string = string> = {
|
|
15
|
-
transform(className: ClassName): TransformStyleObject<
|
|
16
|
+
transform(className: ClassName): TransformStyleObject<CSSPropertiesRaw>;
|
|
16
17
|
};
|
|
17
18
|
export declare function classNameValue<const Value>(value: Value, className: string): ClassNameValue<Value>;
|
|
18
19
|
export declare function isClassNameValue(value: unknown): value is ClassNameValue;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as getClassName } from "./getClassName-
|
|
2
|
-
import { a as createTransformElement } from "./globalSheet-
|
|
1
|
+
import { t as getClassName } from "./getClassName-DKk03IJU.js";
|
|
2
|
+
import { a as createTransformElement } from "./globalSheet-CjX0Df0w.js";
|
|
3
3
|
//#region runtime/rsc/jsx.ts
|
|
4
4
|
const transformElement = createTransformElement(getClassName);
|
|
5
5
|
//#endregion
|
|
@@ -39,4 +39,4 @@ function createJsx(fn, transformElement) {
|
|
|
39
39
|
//#endregion
|
|
40
40
|
export { transformElement as a, wrapFragment as i, createJsxDEV as n, wrapCreateElement as r, createJsx as t };
|
|
41
41
|
|
|
42
|
-
//# sourceMappingURL=utils-
|
|
42
|
+
//# sourceMappingURL=utils-B3O2b3Ly.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils-
|
|
1
|
+
{"version":3,"file":"utils-B3O2b3Ly.js","names":[],"sources":["../runtime/rsc/jsx.ts","../jsx/utils.ts"],"sourcesContent":["import { createTransformElement } from '../core/createTransformElement';\nimport { getClassName } from './getClassName';\n\nexport const transformElement = createTransformElement(getClassName);\n","import type { createElement, ElementType, Fragment } from 'react';\nimport type { jsxDEV } from 'react/jsx-dev-runtime';\nimport type { jsx, jsxs } from 'react/jsx-runtime';\n\nexport type FnJsxDEV = typeof jsxDEV;\nexport type FnJsx = typeof jsx;\nexport type FnJsxs = typeof jsxs;\nexport type FnCreateElement = typeof createElement;\n\nexport type TransformElementArgs = {\n type: ElementType;\n props: unknown;\n source?: unknown;\n};\n\nexport type TransformElement = {\n (args: TransformElementArgs): TransformElementArgs;\n};\n\nexport function wrapCreateElement(\n createElement: FnCreateElement,\n transformElement: TransformElement,\n): FnCreateElement {\n const fn = (type: ElementType, props: unknown, ...children: []) => {\n const result = transformElement({ type, props });\n\n return createElement(result.type, result.props, ...children);\n };\n\n return fn as FnCreateElement;\n}\n\nexport function wrapFragment(\n fragment: typeof Fragment,\n) {\n return fragment;\n}\n\nexport function createJsxDEV(\n fn: FnJsxDEV,\n transformElement: TransformElement,\n): FnJsxDEV {\n return (type, props, key, isStatic, source, self) => {\n const result = transformElement({ type, props, source });\n\n return fn(result.type, result.props, key, isStatic, source, self);\n };\n}\n\nexport function createJsx(\n fn: FnJsx,\n transformElement: TransformElement,\n): FnJsx {\n return (type, props, key) => {\n const result = transformElement({ type, props });\n\n return fn(result.type, result.props, key);\n };\n}\n"],"mappings":";;;AAGA,MAAa,mBAAmB,uBAAuB,YAAY;;;ACgBnE,SAAgB,kBACd,eACA,kBACiB;CACjB,MAAM,MAAM,MAAmB,OAAgB,GAAG,aAAiB;EACjE,MAAM,SAAS,iBAAiB;GAAE;GAAM;EAAM,CAAC;EAE/C,OAAO,cAAc,OAAO,MAAM,OAAO,OAAO,GAAG,QAAQ;CAC7D;CAEA,OAAO;AACT;AAEA,SAAgB,aACd,UACA;CACA,OAAO;AACT;AAEA,SAAgB,aACd,IACA,kBACU;CACV,QAAQ,MAAM,OAAO,KAAK,UAAU,QAAQ,SAAS;EACnD,MAAM,SAAS,iBAAiB;GAAE;GAAM;GAAO;EAAO,CAAC;EAEvD,OAAO,GAAG,OAAO,MAAM,OAAO,OAAO,KAAK,UAAU,QAAQ,IAAI;CAClE;AACF;AAEA,SAAgB,UACd,IACA,kBACO;CACP,QAAQ,MAAM,OAAO,QAAQ;EAC3B,MAAM,SAAS,iBAAiB;GAAE;GAAM;EAAM,CAAC;EAE/C,OAAO,GAAG,OAAO,MAAM,OAAO,OAAO,GAAG;CAC1C;AACF"}
|
|
@@ -813,11 +813,14 @@ function createOrderedSheet(create, options, dev) {
|
|
|
813
813
|
let header = null;
|
|
814
814
|
let serial = 0;
|
|
815
815
|
let dirty = false;
|
|
816
|
+
let orderingDirty = true;
|
|
817
|
+
let order = "";
|
|
816
818
|
let mode = DEV_CONFIG.stylePriorityMode;
|
|
817
819
|
const pending = /* @__PURE__ */ new Set();
|
|
818
820
|
const regular = getGroup("regular");
|
|
819
821
|
const refresh = () => {
|
|
820
822
|
dirty = true;
|
|
823
|
+
orderingDirty = true;
|
|
821
824
|
flush();
|
|
822
825
|
};
|
|
823
826
|
if (dev) refreshers.add(refresh);
|
|
@@ -829,6 +832,7 @@ function createOrderedSheet(create, options, dev) {
|
|
|
829
832
|
name,
|
|
830
833
|
tagName,
|
|
831
834
|
rules: [],
|
|
835
|
+
ordering: /* @__PURE__ */ new Map(),
|
|
832
836
|
sheet: create({
|
|
833
837
|
...options,
|
|
834
838
|
tagName
|
|
@@ -857,10 +861,32 @@ function createOrderedSheet(create, options, dev) {
|
|
|
857
861
|
const group = getGroup(sheetRuleGroup(item));
|
|
858
862
|
const previous = group.rules[group.rules.length - 1];
|
|
859
863
|
group.rules.push(item);
|
|
860
|
-
|
|
864
|
+
trackOrdering(group, item);
|
|
865
|
+
if (!dev && enabled && previous && compareSheetRules(previous, item) > 0) pending.add(group);
|
|
861
866
|
if (!pending.has(group)) group.sheet.insert(route(item));
|
|
862
867
|
dirty = true;
|
|
863
868
|
}
|
|
869
|
+
function trackOrdering(group, rule) {
|
|
870
|
+
const key = JSON.stringify([
|
|
871
|
+
rule.layer ?? "style",
|
|
872
|
+
rule.priority ?? [
|
|
873
|
+
0,
|
|
874
|
+
0,
|
|
875
|
+
0,
|
|
876
|
+
0,
|
|
877
|
+
0,
|
|
878
|
+
0,
|
|
879
|
+
0
|
|
880
|
+
],
|
|
881
|
+
!!rule.sheet,
|
|
882
|
+
!!rule.important,
|
|
883
|
+
!!rule.importantNative,
|
|
884
|
+
rule.globalSheet?.order
|
|
885
|
+
]);
|
|
886
|
+
if (group.ordering.has(key)) return;
|
|
887
|
+
group.ordering.set(key, rule);
|
|
888
|
+
orderingDirty = true;
|
|
889
|
+
}
|
|
864
890
|
function rebuild(group) {
|
|
865
891
|
pending.delete(group);
|
|
866
892
|
group.sheet.destroy?.();
|
|
@@ -870,6 +896,9 @@ function createOrderedSheet(create, options, dev) {
|
|
|
870
896
|
});
|
|
871
897
|
group.sheet.updateLayers(activeLayers ?? []);
|
|
872
898
|
group.rules.sort((a, b) => compareSheetRules(a, b));
|
|
899
|
+
group.ordering.clear();
|
|
900
|
+
orderingDirty = true;
|
|
901
|
+
for (const rule of group.rules) trackOrdering(group, rule);
|
|
873
902
|
for (const rule of group.rules) group.sheet.insert(route(rule));
|
|
874
903
|
group.sheet.flush();
|
|
875
904
|
dirty = true;
|
|
@@ -893,16 +922,22 @@ function createOrderedSheet(create, options, dev) {
|
|
|
893
922
|
if (dev && mode !== DEV_CONFIG.stylePriorityMode) {
|
|
894
923
|
mode = DEV_CONFIG.stylePriorityMode;
|
|
895
924
|
dirty = true;
|
|
925
|
+
orderingDirty = true;
|
|
896
926
|
}
|
|
897
927
|
for (const group of pending) rebuild(group);
|
|
898
928
|
pending.clear();
|
|
899
929
|
for (const group of groups.values()) group.sheet.flush();
|
|
900
930
|
if (!enabled || !dirty) return;
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
931
|
+
if (orderingDirty) {
|
|
932
|
+
const config = {
|
|
933
|
+
...CSS_CONFIG,
|
|
934
|
+
layers: activeLayers ? [...activeLayers] : void 0
|
|
935
|
+
};
|
|
936
|
+
const all = [];
|
|
937
|
+
for (const group of groups.values()) for (const rule of group.ordering.values()) all.push(rule);
|
|
938
|
+
order = sheetOrderingPreamble(all, config, dev ? DEV_CONFIG.stylePriorityMode : "layer");
|
|
939
|
+
orderingDirty = false;
|
|
940
|
+
}
|
|
906
941
|
const head = document.head || document.documentElement;
|
|
907
942
|
const groupTags = collectTags();
|
|
908
943
|
if (!header) {
|
|
@@ -935,6 +970,7 @@ function createOrderedSheet(create, options, dev) {
|
|
|
935
970
|
updateLayers(layers) {
|
|
936
971
|
if (activeLayers?.length === layers.length && layers.every((name, index) => activeLayers[index] === name)) return;
|
|
937
972
|
activeLayers = [...layers];
|
|
973
|
+
orderingDirty = true;
|
|
938
974
|
for (const group of groups.values()) group.sheet.updateLayers(layers);
|
|
939
975
|
dirty = true;
|
|
940
976
|
},
|
|
@@ -1195,8 +1231,8 @@ function createDevLayerSheet(options = {}) {
|
|
|
1195
1231
|
const queued = [];
|
|
1196
1232
|
let layerText = "";
|
|
1197
1233
|
let activeLayers = CSS_CONFIG.layers ?? CSS_CONFIG_DEFAULT.layers ?? [];
|
|
1198
|
-
|
|
1199
|
-
|
|
1234
|
+
const groups = [];
|
|
1235
|
+
const groupLookup = /* @__PURE__ */ new Map();
|
|
1200
1236
|
let hasSheetLayer = false;
|
|
1201
1237
|
const namedLayers = /* @__PURE__ */ new Set();
|
|
1202
1238
|
if (options.top) insertStyleTagAtTop(document, layerTag);
|
|
@@ -1229,12 +1265,13 @@ function createDevLayerSheet(options = {}) {
|
|
|
1229
1265
|
if (key) inserted.add(key);
|
|
1230
1266
|
queued.push({
|
|
1231
1267
|
css,
|
|
1232
|
-
rule: typeof rule === "string" ? null : rule
|
|
1268
|
+
rule: typeof rule === "string" ? null : rule,
|
|
1269
|
+
group: getGroup(typeof rule === "string" ? { css: rule } : rule)
|
|
1233
1270
|
});
|
|
1234
1271
|
},
|
|
1235
1272
|
flush() {
|
|
1236
1273
|
if (!queued.length) return;
|
|
1237
|
-
const touched =
|
|
1274
|
+
const touched = /* @__PURE__ */ new Set();
|
|
1238
1275
|
let fragment = null;
|
|
1239
1276
|
let fragmentTag = null;
|
|
1240
1277
|
const flushFragment = () => {
|
|
@@ -1246,15 +1283,32 @@ function createDevLayerSheet(options = {}) {
|
|
|
1246
1283
|
};
|
|
1247
1284
|
for (let i = 0, len = queued.length; i < len; i++) {
|
|
1248
1285
|
const item = queued[i];
|
|
1286
|
+
const group = item.group;
|
|
1287
|
+
let active = group.tags[group.tags.length - 1];
|
|
1249
1288
|
if (!active || active.count >= maxRules) {
|
|
1250
1289
|
flushFragment();
|
|
1251
|
-
|
|
1290
|
+
const index = groups.indexOf(group);
|
|
1291
|
+
let before;
|
|
1292
|
+
let previous = layerTag;
|
|
1293
|
+
for (let i = index + 1; i < groups.length; i++) if (groups[i].tags.length) {
|
|
1294
|
+
before = groups[i].tags[0].tag;
|
|
1295
|
+
break;
|
|
1296
|
+
}
|
|
1297
|
+
for (let i = index; i >= 0; i--) {
|
|
1298
|
+
const tags = groups[i].tags;
|
|
1299
|
+
if (tags.length) {
|
|
1300
|
+
previous = tags[tags.length - 1].tag;
|
|
1301
|
+
break;
|
|
1302
|
+
}
|
|
1303
|
+
}
|
|
1304
|
+
active = createDevTag(document, previous, {
|
|
1305
|
+
before,
|
|
1252
1306
|
sourcemap,
|
|
1253
1307
|
nonce: options.nonce,
|
|
1254
1308
|
className: tagPrefix + "rules",
|
|
1255
1309
|
top: options.top
|
|
1256
1310
|
});
|
|
1257
|
-
|
|
1311
|
+
group.tags.push(active);
|
|
1258
1312
|
}
|
|
1259
1313
|
if (fragmentTag !== active) {
|
|
1260
1314
|
flushFragment();
|
|
@@ -1262,14 +1316,29 @@ function createDevLayerSheet(options = {}) {
|
|
|
1262
1316
|
fragment = document.createDocumentFragment();
|
|
1263
1317
|
}
|
|
1264
1318
|
insertDevRule(document, active, fragment, item.css, item.rule);
|
|
1265
|
-
|
|
1319
|
+
touched.add(active);
|
|
1266
1320
|
}
|
|
1267
1321
|
flushFragment();
|
|
1268
1322
|
queued.length = 0;
|
|
1269
1323
|
if (!sourcemap) return;
|
|
1270
|
-
for (
|
|
1324
|
+
for (const tag of touched) tag.updateSourceMap();
|
|
1271
1325
|
}
|
|
1272
1326
|
};
|
|
1327
|
+
function getGroup(rule) {
|
|
1328
|
+
const layer = rule.layer ?? "style";
|
|
1329
|
+
const key = (layer === false || layer === "style" && !isStyleLayerEnabled() ? 2 : layer === "style" || typeof layer === "object" && layer.name === getStyleLayerName() ? 0 : 1) + ":" + getSheetRulePriority(rule.priority).join(",");
|
|
1330
|
+
const cached = groupLookup.get(key);
|
|
1331
|
+
if (cached) return cached;
|
|
1332
|
+
const group = {
|
|
1333
|
+
rule,
|
|
1334
|
+
tags: []
|
|
1335
|
+
};
|
|
1336
|
+
const index = groups.findIndex((existing) => compareSheetRules(rule, existing.rule) < 0);
|
|
1337
|
+
if (index < 0) groups.push(group);
|
|
1338
|
+
else groups.splice(index, 0, group);
|
|
1339
|
+
groupLookup.set(key, group);
|
|
1340
|
+
return group;
|
|
1341
|
+
}
|
|
1273
1342
|
}
|
|
1274
1343
|
//#endregion
|
|
1275
1344
|
//#region sheet/dev/dev_sort.ts
|
|
@@ -1281,6 +1350,7 @@ function createDevSortSheet(options = {}) {
|
|
|
1281
1350
|
const inserted = /* @__PURE__ */ new Set();
|
|
1282
1351
|
const queued = [];
|
|
1283
1352
|
const groups = [];
|
|
1353
|
+
const groupLookup = /* @__PURE__ */ new Map();
|
|
1284
1354
|
const shouldLayer = isStyleLayerEnabled();
|
|
1285
1355
|
const layerName = getStyleLayerName();
|
|
1286
1356
|
const tagPrefix = options.tagName ? options.tagName + " " : "";
|
|
@@ -1320,7 +1390,7 @@ function createDevSortSheet(options = {}) {
|
|
|
1320
1390
|
},
|
|
1321
1391
|
flush() {
|
|
1322
1392
|
if (!queued.length) return;
|
|
1323
|
-
const touched =
|
|
1393
|
+
const touched = /* @__PURE__ */ new Set();
|
|
1324
1394
|
let fragment = null;
|
|
1325
1395
|
let fragmentTag = null;
|
|
1326
1396
|
const flushFragment = () => {
|
|
@@ -1333,7 +1403,7 @@ function createDevSortSheet(options = {}) {
|
|
|
1333
1403
|
queued.sort((a, b) => compareLayerPriority(a.priority, b.priority));
|
|
1334
1404
|
for (let i = 0, len = queued.length; i < len; i++) {
|
|
1335
1405
|
const item = queued[i];
|
|
1336
|
-
const group = ensureGroup(groups, item.priority, item.layer);
|
|
1406
|
+
const group = ensureGroup(groups, groupLookup, item.priority, item.layer);
|
|
1337
1407
|
let active = group.tags[group.tags.length - 1] ?? null;
|
|
1338
1408
|
if (!active || active.count >= maxRules) {
|
|
1339
1409
|
flushFragment();
|
|
@@ -1352,12 +1422,12 @@ function createDevSortSheet(options = {}) {
|
|
|
1352
1422
|
fragment = document.createDocumentFragment();
|
|
1353
1423
|
}
|
|
1354
1424
|
insertDevRule(document, active, fragment, item.css, item.rule);
|
|
1355
|
-
|
|
1425
|
+
touched.add(active);
|
|
1356
1426
|
}
|
|
1357
1427
|
flushFragment();
|
|
1358
1428
|
queued.length = 0;
|
|
1359
1429
|
if (!sourcemap) return;
|
|
1360
|
-
for (
|
|
1430
|
+
for (const tag of touched) tag.updateSourceMap();
|
|
1361
1431
|
}
|
|
1362
1432
|
};
|
|
1363
1433
|
function updateLayerText() {
|
|
@@ -1379,12 +1449,18 @@ function createDevSortSheet(options = {}) {
|
|
|
1379
1449
|
else insertStyleTagAfter(document, layerTag, null);
|
|
1380
1450
|
}
|
|
1381
1451
|
}
|
|
1382
|
-
function ensureGroup(groups, priority, layer) {
|
|
1452
|
+
function ensureGroup(groups, lookup, priority, layer) {
|
|
1383
1453
|
const key = (typeof layer === "object" ? "named-" + layer.name + "-" : layer === "sheet" ? "sheet-" : "") + getPriorityKey(priority);
|
|
1454
|
+
const lookupKey = JSON.stringify([layer, priority]);
|
|
1455
|
+
const cached = lookup.get(lookupKey);
|
|
1456
|
+
if (cached) return cached;
|
|
1384
1457
|
for (let i = 0, len = groups.length; i < len; i++) {
|
|
1385
1458
|
const group = groups[i];
|
|
1386
1459
|
const order = getLayerRank(layer) - getLayerRank(group.layer) || compareLayerPriority(priority, group.priority);
|
|
1387
|
-
if (order === 0 && key === group.key && layer === false === (group.layer === false))
|
|
1460
|
+
if (order === 0 && key === group.key && layer === false === (group.layer === false)) {
|
|
1461
|
+
lookup.set(lookupKey, group);
|
|
1462
|
+
return group;
|
|
1463
|
+
}
|
|
1388
1464
|
if (order < 0) {
|
|
1389
1465
|
const next = {
|
|
1390
1466
|
key,
|
|
@@ -1393,6 +1469,7 @@ function ensureGroup(groups, priority, layer) {
|
|
|
1393
1469
|
layer
|
|
1394
1470
|
};
|
|
1395
1471
|
groups.splice(i, 0, next);
|
|
1472
|
+
lookup.set(lookupKey, next);
|
|
1396
1473
|
return next;
|
|
1397
1474
|
}
|
|
1398
1475
|
}
|
|
@@ -1403,6 +1480,7 @@ function ensureGroup(groups, priority, layer) {
|
|
|
1403
1480
|
layer
|
|
1404
1481
|
};
|
|
1405
1482
|
groups.push(group);
|
|
1483
|
+
lookup.set(lookupKey, group);
|
|
1406
1484
|
return group;
|
|
1407
1485
|
}
|
|
1408
1486
|
function getLayerRank(layer) {
|
|
@@ -3049,4 +3127,4 @@ function createJsx(fn, transformElement) {
|
|
|
3049
3127
|
//#endregion
|
|
3050
3128
|
export { transformElement as a, wrapFragment as i, createJsxDEV as n, withGlobalSheetPayload as o, wrapCreateElement as r, createJsx as t };
|
|
3051
3129
|
|
|
3052
|
-
//# sourceMappingURL=utils-
|
|
3130
|
+
//# sourceMappingURL=utils-BeJmRz7x.js.map
|