@tenphi/tasty 0.0.0-snapshot.b2ad8a7 → 0.0.0-snapshot.b358071
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/astro-C_by9qPq.js +307 -0
- package/dist/astro-C_by9qPq.js.map +1 -0
- package/dist/{babel-B_P8t-f0.d.ts → babel-BUQGeOXA.d.ts} +2 -2
- package/dist/{collector-DCI2yzwx.js → collector-BevHh16N.js} +36 -13
- package/dist/collector-BevHh16N.js.map +1 -0
- package/dist/{collector-CQDeU7WS.d.ts → collector-CLVr5_p3.d.ts} +21 -3
- package/dist/{config-B97n_EIv.js → config-NcdqU9PC.js} +139 -482
- package/dist/config-NcdqU9PC.js.map +1 -0
- package/dist/{config-CwRr6-fG.d.ts → config-YsxGv4tq.d.ts} +32 -104
- package/dist/core/index.d.ts +5 -5
- package/dist/core/index.js +6 -6
- package/dist/{core-DWrUWxog.js → core-D7s7u-k1.js} +32 -111
- package/dist/core-D7s7u-k1.js.map +1 -0
- package/dist/{css-writer-Cq0fg5v8.js → css-writer-BDPmetHV.js} +3 -3
- package/dist/{css-writer-Cq0fg5v8.js.map → css-writer-BDPmetHV.js.map} +1 -1
- package/dist/{format-rules-Wb7dJOoL.js → format-rules-BQCn7JZH.js} +2 -2
- package/dist/{format-rules-Wb7dJOoL.js.map → format-rules-BQCn7JZH.js.map} +1 -1
- package/dist/{hydrate-gFTLBDK9.js → hydrate-C3cfqlaQ.js} +3 -3
- package/dist/{hydrate-gFTLBDK9.js.map → hydrate-C3cfqlaQ.js.map} +1 -1
- package/dist/{index-C0W21Qcb.d.ts → index-CBK778ne.d.ts} +17 -64
- package/dist/{index-DpykQKO8.d.ts → index-Cd45t5NM.d.ts} +26 -58
- package/dist/index.d.ts +5 -5
- package/dist/index.js +41 -117
- package/dist/index.js.map +1 -1
- package/dist/{renderChunk-COXABoQz.js → keyframes-ByhOtsXB.js} +206 -3
- package/dist/keyframes-ByhOtsXB.js.map +1 -0
- package/dist/{merge-styles-CzVxdtav.js → merge-styles-BKfagXfV.js} +2 -2
- package/dist/{merge-styles-CzVxdtav.js.map → merge-styles-BKfagXfV.js.map} +1 -1
- package/dist/{merge-styles-Bpwfy1CS.d.ts → merge-styles-CU7JbEwg.d.ts} +2 -2
- package/dist/{resolve-recipes-BnrUEjWV.js → resolve-recipes-vvygrWLw.js} +3 -3
- package/dist/{resolve-recipes-BnrUEjWV.js.map → resolve-recipes-vvygrWLw.js.map} +1 -1
- package/dist/ssr/astro-client.js +1 -1
- package/dist/ssr/astro-middleware-extract-static.d.ts +11 -0
- package/dist/ssr/astro-middleware-extract-static.js +9 -0
- package/dist/ssr/astro-middleware-extract-static.js.map +1 -0
- package/dist/ssr/astro-middleware-extract.d.ts +11 -0
- package/dist/ssr/astro-middleware-extract.js +9 -0
- package/dist/ssr/astro-middleware-extract.js.map +1 -0
- package/dist/ssr/astro-middleware-static.d.ts +3 -1
- package/dist/ssr/astro-middleware-static.js +1 -1
- package/dist/ssr/astro-middleware.d.ts +3 -1
- package/dist/ssr/astro-middleware.js +1 -1
- package/dist/ssr/astro.d.ts +37 -3
- package/dist/ssr/astro.js +1 -156
- package/dist/ssr/index.d.ts +2 -2
- package/dist/ssr/index.js +3 -3
- package/dist/ssr/index.js.map +1 -1
- package/dist/ssr/next.d.ts +1 -1
- package/dist/ssr/next.js +4 -4
- package/dist/static/index.d.ts +2 -2
- package/dist/static/index.js +1 -1
- package/dist/zero/babel.d.ts +1 -1
- package/dist/zero/babel.js +4 -4
- package/dist/zero/index.d.ts +1 -1
- package/dist/zero/index.js +1 -1
- package/dist/zero/next.d.ts +1 -1
- package/docs/debug.md +2 -4
- package/docs/injector.md +25 -48
- package/docs/ssr.md +48 -9
- package/package.json +20 -6
- package/dist/collector-DCI2yzwx.js.map +0 -1
- package/dist/config-B97n_EIv.js.map +0 -1
- package/dist/core-DWrUWxog.js.map +0 -1
- package/dist/renderChunk-COXABoQz.js.map +0 -1
- package/dist/ssr/astro.js.map +0 -1
|
@@ -5040,7 +5040,7 @@ var SheetManager = class {
|
|
|
5040
5040
|
} : void 0;
|
|
5041
5041
|
registry = {
|
|
5042
5042
|
sheets: [],
|
|
5043
|
-
|
|
5043
|
+
refCounts: /* @__PURE__ */ new Map(),
|
|
5044
5044
|
rules: /* @__PURE__ */ new Map(),
|
|
5045
5045
|
cacheKeyToClassName: /* @__PURE__ */ new Map(),
|
|
5046
5046
|
ruleTextSet: /* @__PURE__ */ new Set(),
|
|
@@ -5054,9 +5054,10 @@ var SheetManager = class {
|
|
|
5054
5054
|
injectedFunctions: /* @__PURE__ */ new Map(),
|
|
5055
5055
|
globalRules: /* @__PURE__ */ new Map(),
|
|
5056
5056
|
propertyTypeResolver: new PropertyTypeResolver(),
|
|
5057
|
-
|
|
5058
|
-
|
|
5059
|
-
|
|
5057
|
+
usageMap: /* @__PURE__ */ new Map(),
|
|
5058
|
+
touchCount: 0,
|
|
5059
|
+
touchTick: -1,
|
|
5060
|
+
touchedTick: /* @__PURE__ */ new Set(),
|
|
5060
5061
|
serverClassSyncIndex: 0,
|
|
5061
5062
|
rscStylesScanned: false,
|
|
5062
5063
|
injectionMode: this.detectInjectionMode(root)
|
|
@@ -5438,26 +5439,25 @@ var SheetManager = class {
|
|
|
5438
5439
|
return registry.atPropertySupported;
|
|
5439
5440
|
}
|
|
5440
5441
|
/**
|
|
5441
|
-
*
|
|
5442
|
-
|
|
5443
|
-
|
|
5444
|
-
|
|
5445
|
-
|
|
5446
|
-
|
|
5447
|
-
*
|
|
5448
|
-
* @returns Number of classes actually deleted.
|
|
5442
|
+
* Force cleanup of unused styles
|
|
5443
|
+
*/
|
|
5444
|
+
forceCleanup(registry) {
|
|
5445
|
+
this.performBulkCleanup(registry);
|
|
5446
|
+
}
|
|
5447
|
+
/**
|
|
5448
|
+
* Perform bulk cleanup of all unused styles (refCount = 0).
|
|
5449
5449
|
*/
|
|
5450
|
-
|
|
5450
|
+
performBulkCleanup(registry) {
|
|
5451
5451
|
const cleanupStartTime = Date.now();
|
|
5452
|
-
const
|
|
5452
|
+
const unusedClassNames = Array.from(registry.refCounts.entries()).filter(([className, refCount]) => refCount === 0 && !registry.usageMap.has(className)).map(([className]) => className);
|
|
5453
|
+
if (unusedClassNames.length === 0) return;
|
|
5454
|
+
const selected = unusedClassNames.map((className) => {
|
|
5453
5455
|
const ruleInfo = registry.rules.get(className);
|
|
5454
5456
|
return ruleInfo ? {
|
|
5455
5457
|
className,
|
|
5456
5458
|
ruleInfo
|
|
5457
5459
|
} : null;
|
|
5458
5460
|
}).filter((entry) => entry != null);
|
|
5459
|
-
if (selected.length === 0) return 0;
|
|
5460
|
-
const deleted = /* @__PURE__ */ new Set();
|
|
5461
5461
|
let cleanedUpCount = 0;
|
|
5462
5462
|
let totalCssSize = 0;
|
|
5463
5463
|
let totalRulesDeleted = 0;
|
|
@@ -5478,7 +5478,7 @@ var SheetManager = class {
|
|
|
5478
5478
|
for (const [_sheetIndex, rulesInSheet] of rulesBySheet) {
|
|
5479
5479
|
rulesInSheet.sort((a, b) => b.ruleInfo.ruleIndex - a.ruleInfo.ruleIndex);
|
|
5480
5480
|
for (const { className, ruleInfo } of rulesInSheet) {
|
|
5481
|
-
if ((registry.
|
|
5481
|
+
if ((registry.refCounts.get(className) || 0) > 0) continue;
|
|
5482
5482
|
if (registry.rules.get(className) !== ruleInfo) continue;
|
|
5483
5483
|
const sheetInfo = registry.sheets[ruleInfo.sheetIndex];
|
|
5484
5484
|
if (!sheetInfo || !sheetInfo.sheet && !sheetInfo.constructableSheet) continue;
|
|
@@ -5489,21 +5489,14 @@ var SheetManager = class {
|
|
|
5489
5489
|
const endIdx = ruleInfo.endRuleIndex ?? ruleInfo.ruleIndex;
|
|
5490
5490
|
if (startIdx < 0 || endIdx > maxRuleIndex || startIdx > endIdx) continue;
|
|
5491
5491
|
this.deleteRule(registry, ruleInfo);
|
|
5492
|
-
const keyframeHandles = registry.keyframeHandles.get(className);
|
|
5493
|
-
if (keyframeHandles) {
|
|
5494
|
-
for (const dispose of keyframeHandles) dispose();
|
|
5495
|
-
registry.keyframeHandles.delete(className);
|
|
5496
|
-
}
|
|
5497
5492
|
registry.rules.delete(className);
|
|
5498
|
-
registry.
|
|
5499
|
-
|
|
5500
|
-
|
|
5493
|
+
registry.refCounts.delete(className);
|
|
5494
|
+
const keysToDelete = [];
|
|
5495
|
+
for (const [key, mappedClassName] of registry.cacheKeyToClassName.entries()) if (mappedClassName === className) keysToDelete.push(key);
|
|
5496
|
+
for (const key of keysToDelete) registry.cacheKeyToClassName.delete(key);
|
|
5501
5497
|
cleanedUpCount++;
|
|
5502
5498
|
}
|
|
5503
5499
|
}
|
|
5504
|
-
if (deleted.size > 0) {
|
|
5505
|
-
for (const [key, mappedClassName] of registry.cacheKeyToClassName) if (deleted.has(mappedClassName)) registry.cacheKeyToClassName.delete(key);
|
|
5506
|
-
}
|
|
5507
5500
|
if (registry.metrics) {
|
|
5508
5501
|
registry.metrics.bulkCleanups++;
|
|
5509
5502
|
registry.metrics.stylesCleanedUp += cleanedUpCount;
|
|
@@ -5514,7 +5507,6 @@ var SheetManager = class {
|
|
|
5514
5507
|
rulesDeleted: totalRulesDeleted
|
|
5515
5508
|
});
|
|
5516
5509
|
}
|
|
5517
|
-
return cleanedUpCount;
|
|
5518
5510
|
}
|
|
5519
5511
|
/**
|
|
5520
5512
|
* Get total number of rules across all sheets
|
|
@@ -5549,9 +5541,10 @@ var SheetManager = class {
|
|
|
5549
5541
|
*/
|
|
5550
5542
|
getMetrics(registry) {
|
|
5551
5543
|
if (!registry.metrics) return null;
|
|
5544
|
+
const unusedRulesCount = Array.from(registry.refCounts.values()).filter((count) => count === 0).length;
|
|
5552
5545
|
return {
|
|
5553
5546
|
...registry.metrics,
|
|
5554
|
-
unusedHits:
|
|
5547
|
+
unusedHits: unusedRulesCount
|
|
5555
5548
|
};
|
|
5556
5549
|
}
|
|
5557
5550
|
/**
|
|
@@ -5925,209 +5918,6 @@ function fontFaceContentHash(family, descriptors) {
|
|
|
5925
5918
|
});
|
|
5926
5919
|
}
|
|
5927
5920
|
//#endregion
|
|
5928
|
-
//#region src/keyframes/index.ts
|
|
5929
|
-
const KEYFRAMES_KEY = "@keyframes";
|
|
5930
|
-
/**
|
|
5931
|
-
* Pattern to extract animation names from CSS animation property values.
|
|
5932
|
-
* Animation name is typically the first identifier in the shorthand.
|
|
5933
|
-
* Handles: "fadeIn 300ms ease-in", "pulse 1s infinite", etc.
|
|
5934
|
-
*
|
|
5935
|
-
* CSS animation shorthand order (all optional except name):
|
|
5936
|
-
* animation: name | duration | timing | delay | iteration | direction | fill-mode | play-state
|
|
5937
|
-
*
|
|
5938
|
-
* Animation names must:
|
|
5939
|
-
* - Start with a letter, underscore, or hyphen (but not a digit or CSS keyword)
|
|
5940
|
-
* - Not be CSS keywords: none, initial, inherit, unset, revert
|
|
5941
|
-
*/
|
|
5942
|
-
const CSS_KEYWORDS = new Set([
|
|
5943
|
-
"none",
|
|
5944
|
-
"initial",
|
|
5945
|
-
"inherit",
|
|
5946
|
-
"unset",
|
|
5947
|
-
"revert",
|
|
5948
|
-
"auto",
|
|
5949
|
-
"normal",
|
|
5950
|
-
"running",
|
|
5951
|
-
"paused"
|
|
5952
|
-
]);
|
|
5953
|
-
/**
|
|
5954
|
-
* Pattern to match animation name at the start of an animation value.
|
|
5955
|
-
* Must start with letter, underscore, or hyphen (not digit).
|
|
5956
|
-
*/
|
|
5957
|
-
const ANIMATION_NAME_PATTERN = /^([a-zA-Z_-][a-zA-Z0-9_-]*)/;
|
|
5958
|
-
/**
|
|
5959
|
-
* Check if styles object has local @keyframes definition.
|
|
5960
|
-
* Fast path: single property lookup.
|
|
5961
|
-
*/
|
|
5962
|
-
function hasLocalKeyframes(styles) {
|
|
5963
|
-
return KEYFRAMES_KEY in styles;
|
|
5964
|
-
}
|
|
5965
|
-
/**
|
|
5966
|
-
* Extract local @keyframes from styles object.
|
|
5967
|
-
* Returns null if no local keyframes (fast path).
|
|
5968
|
-
*/
|
|
5969
|
-
function extractLocalKeyframes(styles) {
|
|
5970
|
-
const keyframes = styles[KEYFRAMES_KEY];
|
|
5971
|
-
if (!keyframes || typeof keyframes !== "object") return null;
|
|
5972
|
-
return keyframes;
|
|
5973
|
-
}
|
|
5974
|
-
/**
|
|
5975
|
-
* Merge local and global keyframes.
|
|
5976
|
-
* Local keyframes take priority over global.
|
|
5977
|
-
* Returns null if no keyframes exist (fast path).
|
|
5978
|
-
*/
|
|
5979
|
-
function mergeKeyframes(local, global) {
|
|
5980
|
-
if (!local && !global) return null;
|
|
5981
|
-
if (!local) return global;
|
|
5982
|
-
if (!global) return local;
|
|
5983
|
-
return {
|
|
5984
|
-
...global,
|
|
5985
|
-
...local
|
|
5986
|
-
};
|
|
5987
|
-
}
|
|
5988
|
-
/**
|
|
5989
|
-
* Extract animation name from a single animation value.
|
|
5990
|
-
* Returns null if no valid name found.
|
|
5991
|
-
*
|
|
5992
|
-
* Examples:
|
|
5993
|
-
* - "fadeIn 300ms ease-in" → "fadeIn"
|
|
5994
|
-
* - "1s pulse infinite" → "pulse" (name can be anywhere)
|
|
5995
|
-
* - "none" → null (CSS keyword)
|
|
5996
|
-
* - "300ms ease-in" → null (no name, just duration/timing)
|
|
5997
|
-
*/
|
|
5998
|
-
function extractAnimationNameFromValue(value) {
|
|
5999
|
-
const trimmed = value.trim();
|
|
6000
|
-
if (!trimmed) return null;
|
|
6001
|
-
const parts = trimmed.split(/\s+/);
|
|
6002
|
-
for (const part of parts) {
|
|
6003
|
-
if (CSS_KEYWORDS.has(part.toLowerCase())) continue;
|
|
6004
|
-
if (/^-?[\d.]+m?s$/i.test(part)) continue;
|
|
6005
|
-
if (part === "infinite" || /^\d+$/.test(part)) continue;
|
|
6006
|
-
if ([
|
|
6007
|
-
"normal",
|
|
6008
|
-
"reverse",
|
|
6009
|
-
"alternate",
|
|
6010
|
-
"alternate-reverse"
|
|
6011
|
-
].includes(part.toLowerCase())) continue;
|
|
6012
|
-
if ([
|
|
6013
|
-
"forwards",
|
|
6014
|
-
"backwards",
|
|
6015
|
-
"both"
|
|
6016
|
-
].includes(part.toLowerCase())) continue;
|
|
6017
|
-
if (["running", "paused"].includes(part.toLowerCase())) continue;
|
|
6018
|
-
if (/^(ease|linear|ease-in|ease-out|ease-in-out|step-start|step-end)$/i.test(part)) continue;
|
|
6019
|
-
if (/^(cubic-bezier|steps)\(/i.test(part)) continue;
|
|
6020
|
-
const match = ANIMATION_NAME_PATTERN.exec(part);
|
|
6021
|
-
if (match) return match[1];
|
|
6022
|
-
}
|
|
6023
|
-
return null;
|
|
6024
|
-
}
|
|
6025
|
-
/**
|
|
6026
|
-
* Extract all animation names from an animation property value.
|
|
6027
|
-
* Handles multiple animations separated by commas.
|
|
6028
|
-
*
|
|
6029
|
-
* Example: "fadeIn 300ms, slideIn 500ms ease-out" → ["fadeIn", "slideIn"]
|
|
6030
|
-
*/
|
|
6031
|
-
function extractAnimationNamesFromAnimationValue(value) {
|
|
6032
|
-
const names = [];
|
|
6033
|
-
const animations = value.split(",");
|
|
6034
|
-
for (const animation of animations) {
|
|
6035
|
-
const name = extractAnimationNameFromValue(animation);
|
|
6036
|
-
if (name && !names.includes(name)) names.push(name);
|
|
6037
|
-
}
|
|
6038
|
-
return names;
|
|
6039
|
-
}
|
|
6040
|
-
/**
|
|
6041
|
-
* Extract animation names from a style value (handles mappings and arrays).
|
|
6042
|
-
*/
|
|
6043
|
-
function extractAnimationNamesFromStyleValue(value, names) {
|
|
6044
|
-
if (typeof value === "string") for (const name of extractAnimationNamesFromAnimationValue(value)) names.add(name);
|
|
6045
|
-
else if (Array.isArray(value)) for (const v of value) extractAnimationNamesFromStyleValue(v, names);
|
|
6046
|
-
else if (value && typeof value === "object") for (const v of Object.values(value)) extractAnimationNamesFromStyleValue(v, names);
|
|
6047
|
-
}
|
|
6048
|
-
/**
|
|
6049
|
-
* Extract all animation names referenced in styles.
|
|
6050
|
-
* Scans 'animation' and 'animationName' properties including in state mappings.
|
|
6051
|
-
* Returns empty set if no animation properties found (fast path).
|
|
6052
|
-
*/
|
|
6053
|
-
function extractAnimationNamesFromStyles(styles) {
|
|
6054
|
-
const names = /* @__PURE__ */ new Set();
|
|
6055
|
-
if ("animation" in styles) extractAnimationNamesFromStyleValue(styles.animation, names);
|
|
6056
|
-
if ("animationName" in styles) extractAnimationNamesFromStyleValue(styles.animationName, names);
|
|
6057
|
-
for (const [key, value] of Object.entries(styles)) {
|
|
6058
|
-
if (key === "$" || key === KEYFRAMES_KEY) continue;
|
|
6059
|
-
if ((key.startsWith("&") || key.startsWith(".") || /^[A-Z]/.test(key)) && value && typeof value === "object") {
|
|
6060
|
-
const nestedNames = extractAnimationNamesFromStyles(value);
|
|
6061
|
-
for (const name of nestedNames) names.add(name);
|
|
6062
|
-
}
|
|
6063
|
-
}
|
|
6064
|
-
return names;
|
|
6065
|
-
}
|
|
6066
|
-
/**
|
|
6067
|
-
* Replace animation names in CSS declarations with injected names.
|
|
6068
|
-
* Optimized to avoid regex creation - uses simple string replacement.
|
|
6069
|
-
*
|
|
6070
|
-
* @param declarations CSS declarations string
|
|
6071
|
-
* @param nameMap Map from original name to injected name (only contains names that differ)
|
|
6072
|
-
* @returns Updated declarations string
|
|
6073
|
-
*/
|
|
6074
|
-
function replaceAnimationNames(declarations, nameMap) {
|
|
6075
|
-
if (!declarations.includes("animation")) return declarations;
|
|
6076
|
-
const parts = declarations.split(";");
|
|
6077
|
-
let modified = false;
|
|
6078
|
-
for (let i = 0; i < parts.length; i++) {
|
|
6079
|
-
const part = parts[i];
|
|
6080
|
-
const colonIdx = part.indexOf(":");
|
|
6081
|
-
if (colonIdx === -1) continue;
|
|
6082
|
-
const prop = part.slice(0, colonIdx).trim().toLowerCase();
|
|
6083
|
-
if (prop === "animation" || prop === "animation-name") {
|
|
6084
|
-
const prefix = part.slice(0, colonIdx + 1);
|
|
6085
|
-
let value = part.slice(colonIdx + 1);
|
|
6086
|
-
for (const [original, injected] of nameMap) {
|
|
6087
|
-
const newValue = replaceWord(value, original, injected);
|
|
6088
|
-
if (newValue !== value) {
|
|
6089
|
-
value = newValue;
|
|
6090
|
-
modified = true;
|
|
6091
|
-
}
|
|
6092
|
-
}
|
|
6093
|
-
parts[i] = prefix + value;
|
|
6094
|
-
}
|
|
6095
|
-
}
|
|
6096
|
-
return modified ? parts.join(";") : declarations;
|
|
6097
|
-
}
|
|
6098
|
-
/**
|
|
6099
|
-
* Replace a word in a string (word boundary aware, no regex).
|
|
6100
|
-
*/
|
|
6101
|
-
function replaceWord(str, word, replacement) {
|
|
6102
|
-
let result = str;
|
|
6103
|
-
let idx = 0;
|
|
6104
|
-
while ((idx = result.indexOf(word, idx)) !== -1) {
|
|
6105
|
-
const before = idx === 0 ? " " : result[idx - 1];
|
|
6106
|
-
const after = idx + word.length >= result.length ? " " : result[idx + word.length];
|
|
6107
|
-
const isWordBoundaryBefore = !/[a-zA-Z0-9_-]/.test(before);
|
|
6108
|
-
const isWordBoundaryAfter = !/[a-zA-Z0-9_-]/.test(after);
|
|
6109
|
-
if (isWordBoundaryBefore && isWordBoundaryAfter) {
|
|
6110
|
-
result = result.slice(0, idx) + replacement + result.slice(idx + word.length);
|
|
6111
|
-
idx += replacement.length;
|
|
6112
|
-
} else idx += word.length;
|
|
6113
|
-
}
|
|
6114
|
-
return result;
|
|
6115
|
-
}
|
|
6116
|
-
/**
|
|
6117
|
-
* Filter keyframes to only those that are actually used.
|
|
6118
|
-
* Returns null if no keyframes are used (fast path).
|
|
6119
|
-
*/
|
|
6120
|
-
function filterUsedKeyframes(keyframes, usedNames) {
|
|
6121
|
-
if (!keyframes || usedNames.size === 0) return null;
|
|
6122
|
-
const used = {};
|
|
6123
|
-
let hasAny = false;
|
|
6124
|
-
for (const name of usedNames) if (keyframes[name]) {
|
|
6125
|
-
used[name] = keyframes[name];
|
|
6126
|
-
hasAny = true;
|
|
6127
|
-
}
|
|
6128
|
-
return hasAny ? used : null;
|
|
6129
|
-
}
|
|
6130
|
-
//#endregion
|
|
6131
5921
|
//#region src/counter-style/index.ts
|
|
6132
5922
|
const COUNTER_STYLE_KEY = "@counter-style";
|
|
6133
5923
|
/**
|
|
@@ -6177,8 +5967,6 @@ function formatCounterStyleRule(name, descriptors) {
|
|
|
6177
5967
|
}
|
|
6178
5968
|
//#endregion
|
|
6179
5969
|
//#region src/injector/injector.ts
|
|
6180
|
-
/** Dispose handle handed back for injections that took no pin. */
|
|
6181
|
-
const noop = () => {};
|
|
6182
5970
|
/**
|
|
6183
5971
|
* Placeholder `KeyframesInfo` for a cache entry reserved by a batched write and
|
|
6184
5972
|
* not yet backed by a real rule. Only ever read through `entry.pending`, which
|
|
@@ -6236,25 +6024,13 @@ function registerHydratedClass(registry, className) {
|
|
|
6236
6024
|
ruleIndex: -2,
|
|
6237
6025
|
sheetIndex: -2
|
|
6238
6026
|
});
|
|
6239
|
-
registry.
|
|
6027
|
+
registry.refCounts.set(className, 0);
|
|
6240
6028
|
}
|
|
6241
6029
|
var StyleInjector = class {
|
|
6242
6030
|
sheetManager;
|
|
6243
6031
|
config;
|
|
6244
6032
|
globalRuleCounter = 0;
|
|
6245
|
-
|
|
6246
|
-
cancelPendingGC = null;
|
|
6247
|
-
/** className -> the CSS it stands for, so a collected class can come back. */
|
|
6248
|
-
recipes = /* @__PURE__ */ new Map();
|
|
6249
|
-
/**
|
|
6250
|
-
* cacheKey -> the class name it resolves to, and whether its CSS has been
|
|
6251
|
-
* described yet. A managed render is then one lookup rather than a hash plus
|
|
6252
|
-
* a second lookup, which matters because it runs for every chunk of every
|
|
6253
|
-
* component on every render.
|
|
6254
|
-
*/
|
|
6255
|
-
classNames = /* @__PURE__ */ new Map();
|
|
6256
|
-
/** Releases since the last scheduled pass. */
|
|
6257
|
-
releaseCount = 0;
|
|
6033
|
+
pendingGCHandle = null;
|
|
6258
6034
|
namePrefix;
|
|
6259
6035
|
classRegex;
|
|
6260
6036
|
rscClassRegex;
|
|
@@ -6383,7 +6159,6 @@ var StyleInjector = class {
|
|
|
6383
6159
|
inject(rules, options) {
|
|
6384
6160
|
const root = options?.root || document;
|
|
6385
6161
|
const registry = this.sheetManager.getRegistry(root);
|
|
6386
|
-
const pin = options?.pin ?? true;
|
|
6387
6162
|
if (rules.length === 0) return {
|
|
6388
6163
|
className: "",
|
|
6389
6164
|
dispose: () => {}
|
|
@@ -6394,32 +6169,30 @@ var StyleInjector = class {
|
|
|
6394
6169
|
className = registry.cacheKeyToClassName.get(cacheKey);
|
|
6395
6170
|
const existingRuleInfo = registry.rules.get(className);
|
|
6396
6171
|
if (existingRuleInfo.ruleIndex === -3) {
|
|
6397
|
-
|
|
6172
|
+
registry.refCounts.set(className, (registry.refCounts.get(className) || 0) + 1);
|
|
6398
6173
|
if (registry.metrics) registry.metrics.hits++;
|
|
6399
6174
|
return {
|
|
6400
6175
|
className,
|
|
6401
|
-
dispose:
|
|
6176
|
+
dispose: () => this.dispose(className, registry)
|
|
6402
6177
|
};
|
|
6403
6178
|
}
|
|
6404
6179
|
if (!(existingRuleInfo.ruleIndex === -1 && existingRuleInfo.sheetIndex === -1)) {
|
|
6405
|
-
|
|
6406
|
-
|
|
6407
|
-
registry.pinCounts.set(className, pins + 1);
|
|
6408
|
-
}
|
|
6180
|
+
const currentRefCount = registry.refCounts.get(className) || 0;
|
|
6181
|
+
registry.refCounts.set(className, currentRefCount + 1);
|
|
6409
6182
|
if (registry.metrics) registry.metrics.hits++;
|
|
6410
6183
|
return {
|
|
6411
6184
|
className,
|
|
6412
|
-
dispose:
|
|
6185
|
+
dispose: () => this.dispose(className, registry)
|
|
6413
6186
|
};
|
|
6414
6187
|
}
|
|
6415
6188
|
} else if (cacheKey) {
|
|
6416
6189
|
className = this.generateClassName(cacheKey);
|
|
6417
6190
|
if (this.tryHydratedHit(registry, cacheKey, className)) {
|
|
6418
|
-
|
|
6191
|
+
registry.refCounts.set(className, (registry.refCounts.get(className) || 0) + 1);
|
|
6419
6192
|
if (registry.metrics) registry.metrics.hits++;
|
|
6420
6193
|
return {
|
|
6421
6194
|
className,
|
|
6422
|
-
dispose:
|
|
6195
|
+
dispose: () => this.dispose(className, registry)
|
|
6423
6196
|
};
|
|
6424
6197
|
}
|
|
6425
6198
|
} else {
|
|
@@ -6480,7 +6253,7 @@ var StyleInjector = class {
|
|
|
6480
6253
|
sheetIndex: -3
|
|
6481
6254
|
});
|
|
6482
6255
|
if (cacheKey) registry.cacheKeyToClassName.set(cacheKey, className);
|
|
6483
|
-
|
|
6256
|
+
registry.refCounts.set(className, 1);
|
|
6484
6257
|
const queued = enqueueStyleWrite(() => {
|
|
6485
6258
|
if (applySheetWrite()) return;
|
|
6486
6259
|
registry.rules.set(className, {
|
|
@@ -6491,26 +6264,26 @@ var StyleInjector = class {
|
|
|
6491
6264
|
});
|
|
6492
6265
|
return {
|
|
6493
6266
|
className,
|
|
6494
|
-
dispose:
|
|
6495
|
-
if (!queued.done && registry.
|
|
6267
|
+
dispose: () => {
|
|
6268
|
+
if (!queued.done && registry.refCounts.get(className) === 1 && registry.rules.get(className)?.ruleIndex === -3) {
|
|
6496
6269
|
queued.cancelled = true;
|
|
6497
6270
|
registry.rules.delete(className);
|
|
6498
6271
|
if (cacheKey) registry.cacheKeyToClassName.delete(cacheKey);
|
|
6499
|
-
registry.
|
|
6272
|
+
registry.refCounts.set(className, 0);
|
|
6500
6273
|
return;
|
|
6501
6274
|
}
|
|
6502
|
-
this.
|
|
6503
|
-
}
|
|
6275
|
+
this.dispose(className, registry);
|
|
6276
|
+
}
|
|
6504
6277
|
};
|
|
6505
6278
|
}
|
|
6506
6279
|
if (!applySheetWrite()) return {
|
|
6507
6280
|
className,
|
|
6508
6281
|
dispose: () => {}
|
|
6509
6282
|
};
|
|
6510
|
-
|
|
6283
|
+
registry.refCounts.set(className, 1);
|
|
6511
6284
|
return {
|
|
6512
6285
|
className,
|
|
6513
|
-
dispose:
|
|
6286
|
+
dispose: () => this.dispose(className, registry)
|
|
6514
6287
|
};
|
|
6515
6288
|
}
|
|
6516
6289
|
/**
|
|
@@ -6590,43 +6363,41 @@ var StyleInjector = class {
|
|
|
6590
6363
|
return this.sheetManager.getRawCSSText(root);
|
|
6591
6364
|
}
|
|
6592
6365
|
/**
|
|
6593
|
-
*
|
|
6594
|
-
*
|
|
6595
|
-
*
|
|
6366
|
+
* Increment refCount for an already-injected cacheKey and return a dispose.
|
|
6367
|
+
* Used by useStyles on cache hits (hydration or runtime reuse) where
|
|
6368
|
+
* the pipeline was skipped but refCount tracking is still needed.
|
|
6369
|
+
* Returns null if the cacheKey is not found.
|
|
6596
6370
|
*/
|
|
6597
6371
|
trackRef(cacheKey, options) {
|
|
6598
6372
|
const root = options?.root || document;
|
|
6599
6373
|
const registry = this.sheetManager.getRegistry(root);
|
|
6600
6374
|
if (!registry.cacheKeyToClassName.has(cacheKey)) return null;
|
|
6601
6375
|
const className = registry.cacheKeyToClassName.get(cacheKey);
|
|
6602
|
-
const
|
|
6603
|
-
registry.
|
|
6376
|
+
const currentRefCount = registry.refCounts.get(className) || 0;
|
|
6377
|
+
registry.refCounts.set(className, currentRefCount + 1);
|
|
6604
6378
|
if (registry.metrics) registry.metrics.hits++;
|
|
6605
6379
|
return {
|
|
6606
6380
|
className,
|
|
6607
|
-
dispose: () => this.
|
|
6381
|
+
dispose: () => this.dispose(className, registry)
|
|
6608
6382
|
};
|
|
6609
6383
|
}
|
|
6610
6384
|
/**
|
|
6611
|
-
*
|
|
6612
|
-
* stays cached and collectible, and `gc()` decides when it actually goes.
|
|
6385
|
+
* Dispose of a className (decrements refCount only).
|
|
6613
6386
|
*/
|
|
6614
|
-
|
|
6615
|
-
const
|
|
6616
|
-
if (
|
|
6617
|
-
const
|
|
6618
|
-
registry.
|
|
6619
|
-
if (
|
|
6387
|
+
dispose(className, registry) {
|
|
6388
|
+
const currentRefCount = registry.refCounts.get(className);
|
|
6389
|
+
if (currentRefCount == null || currentRefCount <= 0) return;
|
|
6390
|
+
const newRefCount = currentRefCount - 1;
|
|
6391
|
+
registry.refCounts.set(className, newRefCount);
|
|
6392
|
+
if (newRefCount === 0 && registry.metrics) registry.metrics.totalUnused++;
|
|
6620
6393
|
}
|
|
6621
6394
|
/**
|
|
6622
|
-
*
|
|
6623
|
-
* outstanding `inject()` handle, ignoring the GC capacity threshold.
|
|
6395
|
+
* Force bulk cleanup of unused styles
|
|
6624
6396
|
*/
|
|
6625
6397
|
cleanup(root) {
|
|
6626
|
-
|
|
6627
|
-
|
|
6628
|
-
|
|
6629
|
-
});
|
|
6398
|
+
flushStyles();
|
|
6399
|
+
const registry = this.sheetManager.getRegistry(root || document);
|
|
6400
|
+
this.sheetManager.forceCleanup(registry);
|
|
6630
6401
|
}
|
|
6631
6402
|
/**
|
|
6632
6403
|
* Get CSS text from all sheets (for SSR)
|
|
@@ -6669,9 +6440,7 @@ var StyleInjector = class {
|
|
|
6669
6440
|
flushStyles();
|
|
6670
6441
|
const root = options?.root || document;
|
|
6671
6442
|
const registry = this.sheetManager.getRegistry(root);
|
|
6672
|
-
|
|
6673
|
-
if (metrics && typeof document !== "undefined") metrics.unusedHits = this.collectUnused(registry).length;
|
|
6674
|
-
return metrics;
|
|
6443
|
+
return this.sheetManager.getMetrics(registry);
|
|
6675
6444
|
}
|
|
6676
6445
|
/**
|
|
6677
6446
|
* Reset cache performance metrics
|
|
@@ -6943,210 +6712,108 @@ var StyleInjector = class {
|
|
|
6943
6712
|
}
|
|
6944
6713
|
}
|
|
6945
6714
|
/**
|
|
6946
|
-
*
|
|
6947
|
-
*
|
|
6948
|
-
*
|
|
6949
|
-
|
|
6950
|
-
|
|
6951
|
-
* The class name a cache key resolves to, and whether its CSS is already
|
|
6952
|
-
* described. Pure: no allocation beyond the memo, nothing written — safe
|
|
6953
|
-
* during render, and stable because the name is a hash of the key.
|
|
6954
|
-
*/
|
|
6955
|
-
resolveChunk(cacheKey) {
|
|
6956
|
-
let entry = this.classNames.get(cacheKey);
|
|
6957
|
-
if (entry === void 0) {
|
|
6958
|
-
entry = {
|
|
6959
|
-
name: this.generateClassName(cacheKey),
|
|
6960
|
-
described: false
|
|
6961
|
-
};
|
|
6962
|
-
this.classNames.set(cacheKey, entry);
|
|
6963
|
-
}
|
|
6964
|
-
return entry;
|
|
6965
|
-
}
|
|
6966
|
-
/** Whether this class has already been described, so its CSS need not be re-rendered. */
|
|
6967
|
-
hasRecipe(className) {
|
|
6968
|
-
return this.recipes.has(className);
|
|
6969
|
-
}
|
|
6970
|
-
/**
|
|
6971
|
-
* Record the CSS a class name stands for without writing it to a sheet.
|
|
6972
|
-
*
|
|
6973
|
-
* Called during render. Nothing is inserted yet: the component that will
|
|
6974
|
-
* carry the class inserts it from here when it commits, so a render that is
|
|
6975
|
-
* discarded leaves no rule behind, and a rule collected between render and
|
|
6976
|
-
* commit comes back.
|
|
6977
|
-
*/
|
|
6978
|
-
defineRecipe(className, recipe) {
|
|
6979
|
-
if (this.recipes.has(className)) return;
|
|
6980
|
-
this.recipes.set(className, recipe);
|
|
6981
|
-
if (recipe.cacheKey) {
|
|
6982
|
-
const entry = this.classNames.get(recipe.cacheKey);
|
|
6983
|
-
if (entry) entry.described = true;
|
|
6984
|
-
}
|
|
6985
|
-
}
|
|
6986
|
-
/**
|
|
6987
|
-
* Take up a class on commit: insert its rules if they are not in the sheet,
|
|
6988
|
-
* and count one more mounted holder.
|
|
6989
|
-
*
|
|
6990
|
-
* `className` may be several space-separated chunk classes; they are acquired
|
|
6991
|
-
* together, which is what lets a component pay one insertion effect.
|
|
6992
|
-
*/
|
|
6993
|
-
acquire(className, options) {
|
|
6994
|
-
if (!className) return;
|
|
6995
|
-
const root = options?.root || document;
|
|
6996
|
-
const registry = this.sheetManager.getRegistry(root);
|
|
6997
|
-
const parts = className.indexOf(" ") === -1 ? [className] : className.split(" ");
|
|
6998
|
-
for (const cls of parts) {
|
|
6999
|
-
const held = registry.committed.get(cls) ?? 0;
|
|
7000
|
-
registry.committed.set(cls, held + 1);
|
|
7001
|
-
registry.candidates.delete(cls);
|
|
7002
|
-
if (held > 0) continue;
|
|
7003
|
-
const existing = registry.rules.get(cls);
|
|
7004
|
-
if (existing && existing.sheetIndex !== -1) continue;
|
|
7005
|
-
const recipe = this.recipes.get(cls);
|
|
7006
|
-
if (!recipe) continue;
|
|
7007
|
-
let rules = recipe.rules;
|
|
7008
|
-
if (recipe.keyframes) {
|
|
7009
|
-
const handles = [];
|
|
7010
|
-
let nameMap = null;
|
|
7011
|
-
for (const [name, steps] of Object.entries(recipe.keyframes)) {
|
|
7012
|
-
const injected = this.keyframes(steps, {
|
|
7013
|
-
name,
|
|
7014
|
-
root
|
|
7015
|
-
});
|
|
7016
|
-
handles.push(injected.dispose);
|
|
7017
|
-
const injectedName = injected.toString();
|
|
7018
|
-
if (injectedName !== name) {
|
|
7019
|
-
if (!nameMap) nameMap = /* @__PURE__ */ new Map();
|
|
7020
|
-
nameMap.set(name, injectedName);
|
|
7021
|
-
}
|
|
7022
|
-
}
|
|
7023
|
-
registry.keyframeHandles.set(cls, handles);
|
|
7024
|
-
if (nameMap) rules = rules.map((rule) => ({
|
|
7025
|
-
...rule,
|
|
7026
|
-
declarations: replaceAnimationNames(rule.declarations, nameMap)
|
|
7027
|
-
}));
|
|
7028
|
-
}
|
|
7029
|
-
this.inject(rules, {
|
|
7030
|
-
root,
|
|
7031
|
-
cacheKey: recipe.cacheKey,
|
|
7032
|
-
pin: false
|
|
7033
|
-
});
|
|
7034
|
-
}
|
|
7035
|
-
}
|
|
7036
|
-
/**
|
|
7037
|
-
* Give up a class on unmount. At zero holders it becomes a candidate, but is
|
|
7038
|
-
* not deleted here: insertion-effect cleanups and setups interleave component
|
|
7039
|
-
* by component, so a sibling mounting the same class must get to say so
|
|
7040
|
-
* first. The scheduled pass re-checks before deleting anything.
|
|
6715
|
+
* Record a render-time usage hit for one or more classNames.
|
|
6716
|
+
* Handles space-separated multi-chunk classNames.
|
|
6717
|
+
* When the global touch counter reaches `touchInterval`, schedules a GC
|
|
6718
|
+
* via `requestIdleCallback`.
|
|
6719
|
+
* No-op on the server.
|
|
7041
6720
|
*/
|
|
7042
|
-
|
|
7043
|
-
if (
|
|
6721
|
+
touch(className, options) {
|
|
6722
|
+
if (typeof document === "undefined") return;
|
|
6723
|
+
if (!this.config.gc) return;
|
|
7044
6724
|
const root = options?.root || document;
|
|
7045
6725
|
const registry = this.sheetManager.getRegistry(root);
|
|
7046
|
-
const parts = className.indexOf(" ") === -1 ? [className] : className.split(" ");
|
|
7047
6726
|
const now = Date.now();
|
|
6727
|
+
if (registry.touchTick !== now) {
|
|
6728
|
+
registry.touchTick = now;
|
|
6729
|
+
registry.touchedTick.clear();
|
|
6730
|
+
} else if (registry.touchedTick.has(className)) return;
|
|
6731
|
+
registry.touchedTick.add(className);
|
|
6732
|
+
const parts = className.indexOf(" ") === -1 ? [className] : className.split(" ");
|
|
7048
6733
|
for (const cls of parts) {
|
|
7049
|
-
|
|
7050
|
-
if (
|
|
7051
|
-
|
|
7052
|
-
|
|
7053
|
-
|
|
7054
|
-
|
|
7055
|
-
}
|
|
7056
|
-
|
|
7057
|
-
|
|
7058
|
-
|
|
7059
|
-
this.releaseCount = 0;
|
|
6734
|
+
if (!this.classRegex.test(cls)) continue;
|
|
6735
|
+
if (!registry.rules.has(cls)) continue;
|
|
6736
|
+
const entry = registry.usageMap.get(cls);
|
|
6737
|
+
if (entry) entry.lastTouchedAt = now;
|
|
6738
|
+
else registry.usageMap.set(cls, { lastTouchedAt: now });
|
|
6739
|
+
registry.touchCount++;
|
|
6740
|
+
}
|
|
6741
|
+
const touchInterval = this.config.gc.touchInterval ?? 1e3;
|
|
6742
|
+
if (registry.touchCount >= touchInterval) {
|
|
6743
|
+
registry.touchCount = 0;
|
|
7060
6744
|
this.scheduleGC();
|
|
7061
6745
|
}
|
|
7062
6746
|
}
|
|
7063
6747
|
/**
|
|
7064
|
-
* Schedule a
|
|
7065
|
-
* double-scheduling
|
|
7066
|
-
*
|
|
7067
|
-
* Deliberately deferred rather than run inside `release()`: insertion-effect
|
|
7068
|
-
* cleanups and setups interleave component by component, so a class one
|
|
7069
|
-
* component just dropped may be picked straight back up by the next one.
|
|
7070
|
-
* Deleting on the way past would race that; the pass re-checks instead.
|
|
6748
|
+
* Schedule a GC via `requestIdleCallback` (or synchronously as fallback).
|
|
6749
|
+
* Runs GC on all active roots. Avoids double-scheduling via `pendingGCHandle`.
|
|
7071
6750
|
*/
|
|
7072
6751
|
scheduleGC() {
|
|
7073
|
-
if (this.
|
|
6752
|
+
if (this.pendingGCHandle != null) return;
|
|
7074
6753
|
const runGC = () => {
|
|
7075
|
-
this.
|
|
6754
|
+
this.pendingGCHandle = null;
|
|
7076
6755
|
this.sheetManager.pruneDisconnectedRoots();
|
|
7077
6756
|
for (const root of this.sheetManager.getActiveRoots()) this.gc({ root });
|
|
7078
6757
|
};
|
|
7079
|
-
if (typeof requestIdleCallback !== "undefined")
|
|
7080
|
-
|
|
7081
|
-
this.cancelPendingGC = () => cancelIdleCallback(handle);
|
|
7082
|
-
} else {
|
|
7083
|
-
const handle = setTimeout(runGC, 0);
|
|
7084
|
-
this.cancelPendingGC = () => clearTimeout(handle);
|
|
7085
|
-
}
|
|
7086
|
-
}
|
|
7087
|
-
/**
|
|
7088
|
-
* The one definition of "unused": a class that mounted components released
|
|
7089
|
-
* and nobody pinned. `gc()` deletes from this set, `getMetrics()` counts it,
|
|
7090
|
-
* and `tastyDebug` reports it — all through here, so the three can never
|
|
7091
|
-
* disagree about what "unused" means.
|
|
7092
|
-
*
|
|
7093
|
-
* Only a class that was committed and then released can be here. A class
|
|
7094
|
-
* that was never mounted — a bare `computeStyles()` call, a pinned
|
|
7095
|
-
* `inject()` — is never collectible, because nothing would re-create it.
|
|
7096
|
-
*/
|
|
7097
|
-
collectUnused(registry) {
|
|
7098
|
-
const unused = [];
|
|
7099
|
-
for (const className of registry.candidates.keys()) {
|
|
7100
|
-
if ((registry.committed.get(className) ?? 0) > 0) continue;
|
|
7101
|
-
if ((registry.pinCounts.get(className) ?? 0) > 0) continue;
|
|
7102
|
-
const ruleInfo = registry.rules.get(className);
|
|
7103
|
-
if (!ruleInfo || ruleInfo.sheetIndex < 0) continue;
|
|
7104
|
-
unused.push(className);
|
|
7105
|
-
}
|
|
7106
|
-
return unused;
|
|
7107
|
-
}
|
|
7108
|
-
/**
|
|
7109
|
-
* Class names this injector holds CSS for that nothing renders and nobody
|
|
7110
|
-
* pinned — exactly what `gc({ force: true })` would delete. Unordered.
|
|
7111
|
-
*/
|
|
7112
|
-
getUnusedClasses(options) {
|
|
7113
|
-
flushStyles();
|
|
7114
|
-
if (typeof document === "undefined") return [];
|
|
7115
|
-
const registry = this.sheetManager.getRegistry(options?.root || document);
|
|
7116
|
-
return this.collectUnused(registry);
|
|
6758
|
+
if (typeof requestIdleCallback !== "undefined") this.pendingGCHandle = requestIdleCallback(() => runGC());
|
|
6759
|
+
else runGC();
|
|
7117
6760
|
}
|
|
7118
6761
|
/**
|
|
7119
6762
|
* Synchronous garbage collection.
|
|
7120
6763
|
*
|
|
7121
|
-
* 1. Quick upper-bound check: skip if
|
|
7122
|
-
* 2. Scans the DOM for live tasty classNames
|
|
7123
|
-
*
|
|
7124
|
-
*
|
|
7125
|
-
* Without `force`: keeps the `capacity` most recently touched and deletes
|
|
7126
|
-
* the rest, oldest first.
|
|
6764
|
+
* 1. Quick upper-bound check: skip if unused count can't exceed capacity.
|
|
6765
|
+
* 2. Scans the DOM for live tasty classNames (safety guard).
|
|
6766
|
+
* 3. With `force: true`: deletes all unused entries inline.
|
|
6767
|
+
* Without `force`: collects unused, sorts oldest-first, evicts over capacity.
|
|
7127
6768
|
*
|
|
7128
6769
|
* @returns Number of styles evicted.
|
|
7129
6770
|
*/
|
|
7130
6771
|
gc(options) {
|
|
7131
6772
|
flushStyles();
|
|
7132
6773
|
if (typeof document === "undefined") return 0;
|
|
7133
|
-
this.
|
|
7134
|
-
|
|
6774
|
+
if (this.pendingGCHandle != null) {
|
|
6775
|
+
if (typeof cancelIdleCallback !== "undefined") cancelIdleCallback(this.pendingGCHandle);
|
|
6776
|
+
this.pendingGCHandle = null;
|
|
6777
|
+
}
|
|
7135
6778
|
const root = options?.root || document;
|
|
7136
|
-
const force = options?.force;
|
|
6779
|
+
const force = options?.force ?? false;
|
|
7137
6780
|
const registry = this.sheetManager.getRegistry(root);
|
|
7138
6781
|
const capacity = this.config.gc?.capacity ?? 1e3;
|
|
7139
|
-
if (!force
|
|
7140
|
-
|
|
7141
|
-
|
|
7142
|
-
|
|
7143
|
-
|
|
7144
|
-
|
|
7145
|
-
|
|
7146
|
-
|
|
7147
|
-
|
|
7148
|
-
|
|
7149
|
-
|
|
6782
|
+
if (!force) {
|
|
6783
|
+
let activeCount = 0;
|
|
6784
|
+
for (const refCount of registry.refCounts.values()) if (refCount > 0) activeCount++;
|
|
6785
|
+
if (registry.usageMap.size - activeCount <= capacity) return 0;
|
|
6786
|
+
}
|
|
6787
|
+
const liveClasses = /* @__PURE__ */ new Set();
|
|
6788
|
+
for (const el of root.querySelectorAll("[class]")) for (const token of el.classList) if (this.classRegex.test(token)) liveClasses.add(token);
|
|
6789
|
+
let swept = 0;
|
|
6790
|
+
if (force) for (const [className] of registry.usageMap) {
|
|
6791
|
+
if (liveClasses.has(className)) continue;
|
|
6792
|
+
if ((registry.refCounts.get(className) ?? 0) > 0) continue;
|
|
6793
|
+
registry.usageMap.delete(className);
|
|
6794
|
+
swept++;
|
|
6795
|
+
}
|
|
6796
|
+
else {
|
|
6797
|
+
const unused = [];
|
|
6798
|
+
for (const [className, usage] of registry.usageMap) {
|
|
6799
|
+
if (liveClasses.has(className)) continue;
|
|
6800
|
+
if ((registry.refCounts.get(className) ?? 0) > 0) continue;
|
|
6801
|
+
unused.push({
|
|
6802
|
+
className,
|
|
6803
|
+
lastTouchedAt: usage.lastTouchedAt
|
|
6804
|
+
});
|
|
6805
|
+
}
|
|
6806
|
+
if (unused.length > capacity) {
|
|
6807
|
+
unused.sort((a, b) => a.lastTouchedAt - b.lastTouchedAt);
|
|
6808
|
+
const toEvict = unused.length - capacity;
|
|
6809
|
+
for (let i = 0; i < toEvict; i++) {
|
|
6810
|
+
registry.usageMap.delete(unused[i].className);
|
|
6811
|
+
swept++;
|
|
6812
|
+
}
|
|
6813
|
+
}
|
|
6814
|
+
}
|
|
6815
|
+
if (swept > 0) this.sheetManager.forceCleanup(registry);
|
|
6816
|
+
return swept;
|
|
7150
6817
|
}
|
|
7151
6818
|
/**
|
|
7152
6819
|
* Destroy all resources for a root
|
|
@@ -7155,9 +6822,9 @@ var StyleInjector = class {
|
|
|
7155
6822
|
flushStyles();
|
|
7156
6823
|
const targetRoot = root || document;
|
|
7157
6824
|
this.sheetManager.cleanup(targetRoot);
|
|
7158
|
-
if (this.
|
|
7159
|
-
this.
|
|
7160
|
-
this.
|
|
6825
|
+
if (this.pendingGCHandle != null && !this.sheetManager.hasActiveRoots()) {
|
|
6826
|
+
if (typeof cancelIdleCallback !== "undefined") cancelIdleCallback(this.pendingGCHandle);
|
|
6827
|
+
this.pendingGCHandle = null;
|
|
7161
6828
|
}
|
|
7162
6829
|
}
|
|
7163
6830
|
};
|
|
@@ -12027,19 +11694,10 @@ function createDefaultConfig(isTest) {
|
|
|
12027
11694
|
* This locks the configuration - no further changes allowed.
|
|
12028
11695
|
* Also injects internal and global properties.
|
|
12029
11696
|
*/
|
|
12030
|
-
/**
|
|
12031
|
-
* Bumped whenever the global injector is replaced. Caches that hold class names
|
|
12032
|
-
* across renders compare it to notice that the injector which knew what those
|
|
12033
|
-
* names stand for is gone.
|
|
12034
|
-
*/
|
|
12035
|
-
let styleEpoch = 0;
|
|
12036
|
-
function getStyleEpoch() {
|
|
12037
|
-
return styleEpoch;
|
|
12038
|
-
}
|
|
12039
11697
|
function markStylesGenerated() {
|
|
12040
11698
|
if (stylesGenerated) return;
|
|
12041
11699
|
stylesGenerated = true;
|
|
12042
|
-
if (typeof document !== "undefined" && document.querySelector("
|
|
11700
|
+
if (typeof document !== "undefined" && document.querySelector("[data-tasty-ssr]")) {
|
|
12043
11701
|
warnOnce("ssr-globals-skip", "[Tasty] SSR styles detected — skipping client-side global CSS injection to avoid duplicates.");
|
|
12044
11702
|
return;
|
|
12045
11703
|
}
|
|
@@ -12604,9 +12262,8 @@ function resetConfig() {
|
|
|
12604
12262
|
resetStyleWarnings();
|
|
12605
12263
|
const storage = typeof window !== "undefined" ? window : globalThis;
|
|
12606
12264
|
delete storage[GLOBAL_INJECTOR_KEY];
|
|
12607
|
-
styleEpoch++;
|
|
12608
12265
|
}
|
|
12609
12266
|
//#endregion
|
|
12610
|
-
export {
|
|
12267
|
+
export { SheetManager as $, StyleParser as $t, FLOW_STYLES as A, STYLE_TO_CHUNK as At, createStateParserContext as B, getGlobalParseFunctions as Bt, BASE_STYLES as C, APPEARANCE_CHUNK_STYLES as Ct, COLOR_STYLES as D, FONT_CHUNK_STYLES as Dt, BLOCK_STYLES as E, DISPLAY_CHUNK_STYLES as Et, hasPipelineCacheEntry as F, registerFunctionPolyfill as Ft, StyleInjector as G, parseStyle as Gt, extractPredefinedStateRefs as H, getGlobalPredefinedTokens as Ht, isSelector as I, registerLocalFunctionPolyfills as It, hasLocalCounterStyle as J, okhstPlugin as Jt, extractLocalCounterStyle as K, stringifyStyles as Kt, renderStyles as L, CUSTOM_UNITS as Lt, OUTER_STYLES as M, formatFunctionRule as Mt, POSITION_STYLES as N, hasLocalFunctions as Nt, CONTAINER_STYLES as O, LAYOUT_CHUNK_STYLES as Ot, TEXT_STYLES as P, parseFunctionName as Pt, hasLocalFontFace as Q, isDevEnv as Qt, parseStateKey as R, DIRECTIONS as Rt, baseStylePropsRegistry as S, propHandlerRegistry as St, BLOCK_OUTER_STYLES as T, DIMENSION_CHUNK_STYLES as Tt, getGlobalPredefinedStates as U, normalizeColorTokenValue as Ut, extractLocalPredefinedStates as V, getGlobalParser as Vt, setGlobalPredefinedStates as W, parseColor as Wt, fontFaceContentHash as X, okhslPlugin as Xt, extractLocalFontFace as Y, okhslFunction as Yt, formatFontFaceRule as Z, createColorFunc as Zt, isFunctionsPolyfillEnabled as _, hashString as _t, getGlobalCounterStyles as a, hslToRgbValues as an, closeBatchWindow as at, resetConfig as b, hasLocalProperties as bt, getGlobalInjector as c, openBatchWindow as ct, getGlobalStyles as d, DEFAULT_ZERO_NAME_PREFIX as dt, Lru as en, STYLE_HANDLER_MAP as et, getNamePrefix as f, makeClassName as ft, isConfigLocked as g, validateNamePrefix as gt, hasStylesGenerated as h, tastyClassRegex as ht, getGlobalConfigTokens as i, hexToRgb as in, PropertyTypeResolver as it, INNER_STYLES as j, extractLocalFunctions as jt, DIMENSION_STYLES as k, POSITION_CHUNK_STYLES as kt, getGlobalKeyframes as l, resetStyleBatch as lt, hasGlobalRecipes as m, makeKeyframeName as mt, getConfig as n, getNamedColorHex as nn, styleHandlers as nt, getGlobalFontFaces as o, strToRgb as on, flushStyles as ot, hasGlobalKeyframes as p, makeCounterStyleName as pt, formatCounterStyleRule as q, okhstFunction as qt, getEffectiveProperties as r, getRgbValuesFromRgbaString as rn, createStyle as rt, getGlobalFunctions as s, normalizeDslName as sn, hasPendingStyleWrites as st, configure as t, overrideColorAlpha as tn, defineHandler as tt, getGlobalRecipes as u, DEFAULT_NAME_PREFIX as ut, isTestEnvironment as v, extractLocalProperties as vt, BLOCK_INNER_STYLES as w, CHUNK_NAMES as wt, generateTypographyTokens as x, parsePropertyToken as xt, markStylesGenerated as y, getEffectiveDefinition as yt, camelToKebab as z, filterMods as zt };
|
|
12611
12268
|
|
|
12612
|
-
//# sourceMappingURL=config-
|
|
12269
|
+
//# sourceMappingURL=config-NcdqU9PC.js.map
|