@tenphi/tasty 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +236 -0
- package/dist/_virtual/_rolldown/runtime.mjs +7 -0
- package/dist/chunks/cacheKey.d.ts +1 -0
- package/dist/chunks/cacheKey.js +70 -0
- package/dist/chunks/cacheKey.js.map +1 -0
- package/dist/chunks/cacheKey.mjs +70 -0
- package/dist/chunks/cacheKey.mjs.map +1 -0
- package/dist/chunks/definitions.d.ts +37 -0
- package/dist/chunks/definitions.js +260 -0
- package/dist/chunks/definitions.js.map +1 -0
- package/dist/chunks/definitions.mjs +260 -0
- package/dist/chunks/definitions.mjs.map +1 -0
- package/dist/chunks/index.d.ts +3 -0
- package/dist/chunks/renderChunk.d.ts +2 -0
- package/dist/chunks/renderChunk.js +61 -0
- package/dist/chunks/renderChunk.js.map +1 -0
- package/dist/chunks/renderChunk.mjs +61 -0
- package/dist/chunks/renderChunk.mjs.map +1 -0
- package/dist/config.d.ts +279 -0
- package/dist/config.js +400 -0
- package/dist/config.js.map +1 -0
- package/dist/config.mjs +231 -0
- package/dist/config.mjs.map +1 -0
- package/dist/css-writer.d.mts +45 -0
- package/dist/css-writer.mjs +74 -0
- package/dist/css-writer.mjs.map +1 -0
- package/dist/debug.d.ts +204 -0
- package/dist/debug.js +733 -0
- package/dist/debug.js.map +1 -0
- package/dist/extractor.d.mts +24 -0
- package/dist/extractor.mjs +150 -0
- package/dist/extractor.mjs.map +1 -0
- package/dist/hooks/index.d.ts +5 -0
- package/dist/hooks/useGlobalStyles.d.ts +27 -0
- package/dist/hooks/useGlobalStyles.js +56 -0
- package/dist/hooks/useGlobalStyles.js.map +1 -0
- package/dist/hooks/useKeyframes.d.ts +56 -0
- package/dist/hooks/useKeyframes.js +54 -0
- package/dist/hooks/useKeyframes.js.map +1 -0
- package/dist/hooks/useProperty.d.ts +79 -0
- package/dist/hooks/useProperty.js +91 -0
- package/dist/hooks/useProperty.js.map +1 -0
- package/dist/hooks/useRawCSS.d.ts +53 -0
- package/dist/hooks/useRawCSS.js +28 -0
- package/dist/hooks/useRawCSS.js.map +1 -0
- package/dist/hooks/useStyles.d.ts +40 -0
- package/dist/hooks/useStyles.js +169 -0
- package/dist/hooks/useStyles.js.map +1 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.js +30 -0
- package/dist/injector/index.d.ts +157 -0
- package/dist/injector/index.js +154 -0
- package/dist/injector/index.js.map +1 -0
- package/dist/injector/injector.d.ts +139 -0
- package/dist/injector/injector.js +404 -0
- package/dist/injector/injector.js.map +1 -0
- package/dist/injector/injector.mjs +404 -0
- package/dist/injector/injector.mjs.map +1 -0
- package/dist/injector/sheet-manager.d.ts +127 -0
- package/dist/injector/sheet-manager.js +714 -0
- package/dist/injector/sheet-manager.js.map +1 -0
- package/dist/injector/sheet-manager.mjs +714 -0
- package/dist/injector/sheet-manager.mjs.map +1 -0
- package/dist/injector/types.d.mts +18 -0
- package/dist/injector/types.d.ts +135 -0
- package/dist/keyframes/index.js +206 -0
- package/dist/keyframes/index.js.map +1 -0
- package/dist/keyframes/index.mjs +156 -0
- package/dist/keyframes/index.mjs.map +1 -0
- package/dist/parser/classify.js +319 -0
- package/dist/parser/classify.js.map +1 -0
- package/dist/parser/classify.mjs +319 -0
- package/dist/parser/classify.mjs.map +1 -0
- package/dist/parser/const.js +33 -0
- package/dist/parser/const.js.map +1 -0
- package/dist/parser/const.mjs +33 -0
- package/dist/parser/const.mjs.map +1 -0
- package/dist/parser/lru.js +109 -0
- package/dist/parser/lru.js.map +1 -0
- package/dist/parser/lru.mjs +109 -0
- package/dist/parser/lru.mjs.map +1 -0
- package/dist/parser/parser.d.ts +25 -0
- package/dist/parser/parser.js +116 -0
- package/dist/parser/parser.js.map +1 -0
- package/dist/parser/parser.mjs +116 -0
- package/dist/parser/parser.mjs.map +1 -0
- package/dist/parser/tokenizer.js +69 -0
- package/dist/parser/tokenizer.js.map +1 -0
- package/dist/parser/tokenizer.mjs +69 -0
- package/dist/parser/tokenizer.mjs.map +1 -0
- package/dist/parser/types.d.mts +37 -0
- package/dist/parser/types.d.ts +46 -0
- package/dist/parser/types.js +46 -0
- package/dist/parser/types.js.map +1 -0
- package/dist/parser/types.mjs +46 -0
- package/dist/parser/types.mjs.map +1 -0
- package/dist/pipeline/conditions.js +377 -0
- package/dist/pipeline/conditions.js.map +1 -0
- package/dist/pipeline/conditions.mjs +377 -0
- package/dist/pipeline/conditions.mjs.map +1 -0
- package/dist/pipeline/exclusive.d.ts +1 -0
- package/dist/pipeline/exclusive.js +231 -0
- package/dist/pipeline/exclusive.js.map +1 -0
- package/dist/pipeline/exclusive.mjs +231 -0
- package/dist/pipeline/exclusive.mjs.map +1 -0
- package/dist/pipeline/index.d.ts +53 -0
- package/dist/pipeline/index.js +641 -0
- package/dist/pipeline/index.js.map +1 -0
- package/dist/pipeline/index.mjs +635 -0
- package/dist/pipeline/index.mjs.map +1 -0
- package/dist/pipeline/materialize.js +821 -0
- package/dist/pipeline/materialize.js.map +1 -0
- package/dist/pipeline/materialize.mjs +821 -0
- package/dist/pipeline/materialize.mjs.map +1 -0
- package/dist/pipeline/parseStateKey.d.ts +1 -0
- package/dist/pipeline/parseStateKey.js +418 -0
- package/dist/pipeline/parseStateKey.js.map +1 -0
- package/dist/pipeline/parseStateKey.mjs +418 -0
- package/dist/pipeline/parseStateKey.mjs.map +1 -0
- package/dist/pipeline/simplify.js +557 -0
- package/dist/pipeline/simplify.js.map +1 -0
- package/dist/pipeline/simplify.mjs +557 -0
- package/dist/pipeline/simplify.mjs.map +1 -0
- package/dist/plugins/index.d.ts +2 -0
- package/dist/plugins/okhsl-plugin.d.ts +35 -0
- package/dist/plugins/okhsl-plugin.js +371 -0
- package/dist/plugins/okhsl-plugin.js.map +1 -0
- package/dist/plugins/okhsl-plugin.mjs +345 -0
- package/dist/plugins/okhsl-plugin.mjs.map +1 -0
- package/dist/plugins/types.d.mts +49 -0
- package/dist/plugins/types.d.ts +69 -0
- package/dist/properties/index.js +158 -0
- package/dist/properties/index.js.map +1 -0
- package/dist/properties/index.mjs +141 -0
- package/dist/properties/index.mjs.map +1 -0
- package/dist/states/index.d.ts +45 -0
- package/dist/states/index.js +389 -0
- package/dist/states/index.js.map +1 -0
- package/dist/states/index.mjs +161 -0
- package/dist/states/index.mjs.map +1 -0
- package/dist/static/index.d.ts +5 -0
- package/dist/static/index.js +5 -0
- package/dist/static/tastyStatic.d.ts +46 -0
- package/dist/static/tastyStatic.js +31 -0
- package/dist/static/tastyStatic.js.map +1 -0
- package/dist/static/types.d.ts +49 -0
- package/dist/static/types.js +24 -0
- package/dist/static/types.js.map +1 -0
- package/dist/styles/align.d.ts +15 -0
- package/dist/styles/align.js +14 -0
- package/dist/styles/align.js.map +1 -0
- package/dist/styles/align.mjs +14 -0
- package/dist/styles/align.mjs.map +1 -0
- package/dist/styles/border.d.ts +25 -0
- package/dist/styles/border.js +114 -0
- package/dist/styles/border.js.map +1 -0
- package/dist/styles/border.mjs +114 -0
- package/dist/styles/border.mjs.map +1 -0
- package/dist/styles/color.d.ts +14 -0
- package/dist/styles/color.js +23 -0
- package/dist/styles/color.js.map +1 -0
- package/dist/styles/color.mjs +23 -0
- package/dist/styles/color.mjs.map +1 -0
- package/dist/styles/createStyle.js +77 -0
- package/dist/styles/createStyle.js.map +1 -0
- package/dist/styles/createStyle.mjs +77 -0
- package/dist/styles/createStyle.mjs.map +1 -0
- package/dist/styles/dimension.js +97 -0
- package/dist/styles/dimension.js.map +1 -0
- package/dist/styles/dimension.mjs +97 -0
- package/dist/styles/dimension.mjs.map +1 -0
- package/dist/styles/display.d.ts +37 -0
- package/dist/styles/display.js +67 -0
- package/dist/styles/display.js.map +1 -0
- package/dist/styles/display.mjs +67 -0
- package/dist/styles/display.mjs.map +1 -0
- package/dist/styles/fade.d.ts +15 -0
- package/dist/styles/fade.js +58 -0
- package/dist/styles/fade.js.map +1 -0
- package/dist/styles/fade.mjs +58 -0
- package/dist/styles/fade.mjs.map +1 -0
- package/dist/styles/fill.d.ts +44 -0
- package/dist/styles/fill.js +51 -0
- package/dist/styles/fill.js.map +1 -0
- package/dist/styles/fill.mjs +51 -0
- package/dist/styles/fill.mjs.map +1 -0
- package/dist/styles/flow.d.ts +16 -0
- package/dist/styles/flow.js +12 -0
- package/dist/styles/flow.js.map +1 -0
- package/dist/styles/flow.mjs +12 -0
- package/dist/styles/flow.mjs.map +1 -0
- package/dist/styles/gap.d.ts +31 -0
- package/dist/styles/gap.js +37 -0
- package/dist/styles/gap.js.map +1 -0
- package/dist/styles/gap.mjs +37 -0
- package/dist/styles/gap.mjs.map +1 -0
- package/dist/styles/height.d.ts +17 -0
- package/dist/styles/height.js +20 -0
- package/dist/styles/height.js.map +1 -0
- package/dist/styles/height.mjs +20 -0
- package/dist/styles/height.mjs.map +1 -0
- package/dist/styles/index.d.ts +2 -0
- package/dist/styles/index.js +9 -0
- package/dist/styles/index.js.map +1 -0
- package/dist/styles/index.mjs +9 -0
- package/dist/styles/index.mjs.map +1 -0
- package/dist/styles/inset.d.ts +50 -0
- package/dist/styles/inset.js +142 -0
- package/dist/styles/inset.js.map +1 -0
- package/dist/styles/inset.mjs +142 -0
- package/dist/styles/inset.mjs.map +1 -0
- package/dist/styles/justify.d.ts +15 -0
- package/dist/styles/justify.js +14 -0
- package/dist/styles/justify.js.map +1 -0
- package/dist/styles/justify.mjs +14 -0
- package/dist/styles/justify.mjs.map +1 -0
- package/dist/styles/list.d.ts +16 -0
- package/dist/styles/list.js +98 -0
- package/dist/styles/list.js.map +1 -0
- package/dist/styles/margin.d.ts +28 -0
- package/dist/styles/margin.js +96 -0
- package/dist/styles/margin.js.map +1 -0
- package/dist/styles/margin.mjs +96 -0
- package/dist/styles/margin.mjs.map +1 -0
- package/dist/styles/outline.d.ts +29 -0
- package/dist/styles/outline.js +65 -0
- package/dist/styles/outline.js.map +1 -0
- package/dist/styles/outline.mjs +65 -0
- package/dist/styles/outline.mjs.map +1 -0
- package/dist/styles/padding.d.ts +28 -0
- package/dist/styles/padding.js +96 -0
- package/dist/styles/padding.js.map +1 -0
- package/dist/styles/padding.mjs +96 -0
- package/dist/styles/padding.mjs.map +1 -0
- package/dist/styles/predefined.d.ts +74 -0
- package/dist/styles/predefined.js +241 -0
- package/dist/styles/predefined.js.map +1 -0
- package/dist/styles/predefined.mjs +232 -0
- package/dist/styles/predefined.mjs.map +1 -0
- package/dist/styles/preset.d.ts +47 -0
- package/dist/styles/preset.js +126 -0
- package/dist/styles/preset.js.map +1 -0
- package/dist/styles/preset.mjs +126 -0
- package/dist/styles/preset.mjs.map +1 -0
- package/dist/styles/radius.d.ts +14 -0
- package/dist/styles/radius.js +51 -0
- package/dist/styles/radius.js.map +1 -0
- package/dist/styles/radius.mjs +51 -0
- package/dist/styles/radius.mjs.map +1 -0
- package/dist/styles/scrollbar.d.ts +21 -0
- package/dist/styles/scrollbar.js +105 -0
- package/dist/styles/scrollbar.js.map +1 -0
- package/dist/styles/scrollbar.mjs +105 -0
- package/dist/styles/scrollbar.mjs.map +1 -0
- package/dist/styles/shadow.d.ts +14 -0
- package/dist/styles/shadow.js +24 -0
- package/dist/styles/shadow.js.map +1 -0
- package/dist/styles/shadow.mjs +24 -0
- package/dist/styles/shadow.mjs.map +1 -0
- package/dist/styles/styledScrollbar.d.ts +47 -0
- package/dist/styles/styledScrollbar.js +38 -0
- package/dist/styles/styledScrollbar.js.map +1 -0
- package/dist/styles/styledScrollbar.mjs +38 -0
- package/dist/styles/styledScrollbar.mjs.map +1 -0
- package/dist/styles/transition.d.ts +14 -0
- package/dist/styles/transition.js +138 -0
- package/dist/styles/transition.js.map +1 -0
- package/dist/styles/transition.mjs +138 -0
- package/dist/styles/transition.mjs.map +1 -0
- package/dist/styles/types.d.mts +492 -0
- package/dist/styles/types.d.ts +496 -0
- package/dist/styles/width.d.ts +17 -0
- package/dist/styles/width.js +20 -0
- package/dist/styles/width.js.map +1 -0
- package/dist/styles/width.mjs +20 -0
- package/dist/styles/width.mjs.map +1 -0
- package/dist/tasty.d.ts +983 -0
- package/dist/tasty.js +191 -0
- package/dist/tasty.js.map +1 -0
- package/dist/tokens/typography.d.ts +19 -0
- package/dist/tokens/typography.js +237 -0
- package/dist/tokens/typography.js.map +1 -0
- package/dist/types.d.ts +182 -0
- package/dist/utils/cache-wrapper.js +26 -0
- package/dist/utils/cache-wrapper.js.map +1 -0
- package/dist/utils/cache-wrapper.mjs +26 -0
- package/dist/utils/cache-wrapper.mjs.map +1 -0
- package/dist/utils/case-converter.js +8 -0
- package/dist/utils/case-converter.js.map +1 -0
- package/dist/utils/case-converter.mjs +8 -0
- package/dist/utils/case-converter.mjs.map +1 -0
- package/dist/utils/colors.d.ts +5 -0
- package/dist/utils/colors.js +9 -0
- package/dist/utils/colors.js.map +1 -0
- package/dist/utils/dotize.d.ts +26 -0
- package/dist/utils/dotize.js +122 -0
- package/dist/utils/dotize.js.map +1 -0
- package/dist/utils/filter-base-props.d.ts +15 -0
- package/dist/utils/filter-base-props.js +45 -0
- package/dist/utils/filter-base-props.js.map +1 -0
- package/dist/utils/get-display-name.d.ts +7 -0
- package/dist/utils/get-display-name.js +10 -0
- package/dist/utils/get-display-name.js.map +1 -0
- package/dist/utils/hsl-to-rgb.js +38 -0
- package/dist/utils/hsl-to-rgb.js.map +1 -0
- package/dist/utils/hsl-to-rgb.mjs +38 -0
- package/dist/utils/hsl-to-rgb.mjs.map +1 -0
- package/dist/utils/is-dev-env.js +19 -0
- package/dist/utils/is-dev-env.js.map +1 -0
- package/dist/utils/is-dev-env.mjs +19 -0
- package/dist/utils/is-dev-env.mjs.map +1 -0
- package/dist/utils/merge-styles.d.ts +7 -0
- package/dist/utils/merge-styles.js +146 -0
- package/dist/utils/merge-styles.js.map +1 -0
- package/dist/utils/merge-styles.mjs +146 -0
- package/dist/utils/merge-styles.mjs.map +1 -0
- package/dist/utils/mod-attrs.d.ts +8 -0
- package/dist/utils/mod-attrs.js +21 -0
- package/dist/utils/mod-attrs.js.map +1 -0
- package/dist/utils/okhsl-to-rgb.js +296 -0
- package/dist/utils/okhsl-to-rgb.js.map +1 -0
- package/dist/utils/okhsl-to-rgb.mjs +296 -0
- package/dist/utils/okhsl-to-rgb.mjs.map +1 -0
- package/dist/utils/process-tokens.d.ts +31 -0
- package/dist/utils/process-tokens.js +171 -0
- package/dist/utils/process-tokens.js.map +1 -0
- package/dist/utils/process-tokens.mjs +28 -0
- package/dist/utils/process-tokens.mjs.map +1 -0
- package/dist/utils/resolve-recipes.d.ts +17 -0
- package/dist/utils/resolve-recipes.js +143 -0
- package/dist/utils/resolve-recipes.js.map +1 -0
- package/dist/utils/resolve-recipes.mjs +143 -0
- package/dist/utils/resolve-recipes.mjs.map +1 -0
- package/dist/utils/string.js +8 -0
- package/dist/utils/string.js.map +1 -0
- package/dist/utils/string.mjs +8 -0
- package/dist/utils/string.mjs.map +1 -0
- package/dist/utils/styles.d.mts +18 -0
- package/dist/utils/styles.d.ts +183 -0
- package/dist/utils/styles.js +585 -0
- package/dist/utils/styles.js.map +1 -0
- package/dist/utils/styles.mjs +346 -0
- package/dist/utils/styles.mjs.map +1 -0
- package/dist/utils/typography.d.ts +36 -0
- package/dist/utils/typography.js +53 -0
- package/dist/utils/typography.js.map +1 -0
- package/dist/utils/warnings.d.ts +16 -0
- package/dist/utils/warnings.js +16 -0
- package/dist/utils/warnings.js.map +1 -0
- package/dist/zero/babel.d.mts +108 -0
- package/dist/zero/babel.mjs +282 -0
- package/dist/zero/babel.mjs.map +1 -0
- package/dist/zero/index.d.mts +3 -0
- package/dist/zero/index.mjs +4 -0
- package/dist/zero/next.d.mts +60 -0
- package/dist/zero/next.mjs +78 -0
- package/dist/zero/next.mjs.map +1 -0
- package/package.json +127 -0
package/dist/debug.js
ADDED
|
@@ -0,0 +1,733 @@
|
|
|
1
|
+
import { isDevEnv } from "./utils/is-dev-env.js";
|
|
2
|
+
import { CHUNK_NAMES } from "./chunks/definitions.js";
|
|
3
|
+
import { getCssTextForNode, injector } from "./injector/index.js";
|
|
4
|
+
|
|
5
|
+
//#region src/debug.ts
|
|
6
|
+
/**
|
|
7
|
+
* Debug utilities for inspecting tasty-generated CSS at runtime
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Pretty-print CSS with proper indentation and formatting
|
|
11
|
+
*/
|
|
12
|
+
function prettifyCSS(css) {
|
|
13
|
+
if (!css || css.trim() === "") return "";
|
|
14
|
+
let formatted = css.replace(/\s+/g, " ").trim();
|
|
15
|
+
formatted = formatted.replace(/\s*\{\s*/g, " {\n");
|
|
16
|
+
formatted = formatted.replace(/;(?![^"']*["'][^"']*$)(?![^()]*\))/g, ";\n");
|
|
17
|
+
formatted = formatted.replace(/\s*\}\s*/g, "\n}\n");
|
|
18
|
+
formatted = formatted.replace(/,(?![^"']*["'][^"']*$)(?![^()]*\))(?=.*:.*\{|.*\{)/g, ",\n");
|
|
19
|
+
const lines = formatted.split("\n");
|
|
20
|
+
let indentLevel = 0;
|
|
21
|
+
const indentSize = 2;
|
|
22
|
+
let result = lines.map((line) => {
|
|
23
|
+
const trimmed = line.trim();
|
|
24
|
+
if (!trimmed) return "";
|
|
25
|
+
if (trimmed === "}") {
|
|
26
|
+
indentLevel = Math.max(0, indentLevel - 1);
|
|
27
|
+
return " ".repeat(indentLevel * indentSize) + trimmed;
|
|
28
|
+
}
|
|
29
|
+
const result = " ".repeat(indentLevel * indentSize) + trimmed;
|
|
30
|
+
if (trimmed.endsWith("{")) indentLevel++;
|
|
31
|
+
return result;
|
|
32
|
+
}).filter((line) => line.trim()).join("\n").replace(/\n{3,}/g, "\n\n").trim();
|
|
33
|
+
result = result.replace(/,\s+/g, ", ");
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
function findAllTastyClasses(root = document) {
|
|
37
|
+
const classes = /* @__PURE__ */ new Set();
|
|
38
|
+
(root.querySelectorAll?.("[class]") || []).forEach((element) => {
|
|
39
|
+
const classList = element.getAttribute("class");
|
|
40
|
+
if (classList) classList.split(/\s+/).filter((cls) => /^t\d+$/.test(cls)).forEach((cls) => classes.add(cls));
|
|
41
|
+
});
|
|
42
|
+
return Array.from(classes).sort((a, b) => {
|
|
43
|
+
return parseInt(a.slice(1)) - parseInt(b.slice(1));
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
function findAllStyledClasses(root = document) {
|
|
47
|
+
const allCSS = injector.instance.getCssText({ root });
|
|
48
|
+
const classes = /* @__PURE__ */ new Set();
|
|
49
|
+
const classRegex = /\.t(\d+)/g;
|
|
50
|
+
let match;
|
|
51
|
+
while ((match = classRegex.exec(allCSS)) !== null) classes.add(`t${match[1]}`);
|
|
52
|
+
return Array.from(classes).sort((a, b) => {
|
|
53
|
+
return parseInt(a.slice(1)) - parseInt(b.slice(1));
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
function extractCSSRules(css) {
|
|
57
|
+
const rules = [];
|
|
58
|
+
const cleanCSS = css.replace(/\/\*[\s\S]*?\*\//g, "");
|
|
59
|
+
let i = 0;
|
|
60
|
+
while (i < cleanCSS.length) {
|
|
61
|
+
while (i < cleanCSS.length && /\s/.test(cleanCSS[i])) i++;
|
|
62
|
+
if (i >= cleanCSS.length) break;
|
|
63
|
+
const selectorStart = i;
|
|
64
|
+
let braceDepth = 0;
|
|
65
|
+
let inString = false;
|
|
66
|
+
let stringChar = "";
|
|
67
|
+
while (i < cleanCSS.length) {
|
|
68
|
+
const char = cleanCSS[i];
|
|
69
|
+
if (inString) {
|
|
70
|
+
if (char === stringChar && cleanCSS[i - 1] !== "\\") inString = false;
|
|
71
|
+
} else if (char === "\"" || char === "'") {
|
|
72
|
+
inString = true;
|
|
73
|
+
stringChar = char;
|
|
74
|
+
} else if (char === "{") {
|
|
75
|
+
braceDepth++;
|
|
76
|
+
if (braceDepth === 1) break;
|
|
77
|
+
}
|
|
78
|
+
i++;
|
|
79
|
+
}
|
|
80
|
+
if (i >= cleanCSS.length) break;
|
|
81
|
+
const selector = cleanCSS.substring(selectorStart, i).trim();
|
|
82
|
+
i++;
|
|
83
|
+
const contentStart = i;
|
|
84
|
+
braceDepth = 1;
|
|
85
|
+
inString = false;
|
|
86
|
+
while (i < cleanCSS.length && braceDepth > 0) {
|
|
87
|
+
const char = cleanCSS[i];
|
|
88
|
+
if (inString) {
|
|
89
|
+
if (char === stringChar && cleanCSS[i - 1] !== "\\") inString = false;
|
|
90
|
+
} else if (char === "\"" || char === "'") {
|
|
91
|
+
inString = true;
|
|
92
|
+
stringChar = char;
|
|
93
|
+
} else if (char === "{") braceDepth++;
|
|
94
|
+
else if (char === "}") braceDepth--;
|
|
95
|
+
i++;
|
|
96
|
+
}
|
|
97
|
+
const content = cleanCSS.substring(contentStart, i - 1).trim();
|
|
98
|
+
if (content && selector) rules.push({
|
|
99
|
+
selector,
|
|
100
|
+
declarations: content
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
return rules;
|
|
104
|
+
}
|
|
105
|
+
function getGlobalCSS(root = document) {
|
|
106
|
+
return prettifyCSS(extractCSSRules(injector.instance.getCssText({ root })).filter((rule) => {
|
|
107
|
+
return !rule.selector.split(",").map((s) => s.trim()).every((selector) => {
|
|
108
|
+
const parts = selector.replace(/[.#:\s>+~[\]()]/g, " ").split(/\s+/).filter(Boolean);
|
|
109
|
+
return parts.length > 0 && parts.every((part) => /^t\d+$/.test(part));
|
|
110
|
+
});
|
|
111
|
+
}).map((rule) => `${rule.selector} { ${rule.declarations} }`).join("\n"));
|
|
112
|
+
}
|
|
113
|
+
function getPageCSS(options) {
|
|
114
|
+
const root = options?.root || document;
|
|
115
|
+
const includeCrossOrigin = options?.includeCrossOrigin ?? false;
|
|
116
|
+
const cssChunks = [];
|
|
117
|
+
try {
|
|
118
|
+
if ("styleSheets" in root) {
|
|
119
|
+
const styleSheets = Array.from(root.styleSheets);
|
|
120
|
+
for (const sheet of styleSheets) try {
|
|
121
|
+
if (sheet.cssRules) {
|
|
122
|
+
const rules = Array.from(sheet.cssRules);
|
|
123
|
+
cssChunks.push(rules.map((rule) => rule.cssText).join("\n"));
|
|
124
|
+
}
|
|
125
|
+
} catch {
|
|
126
|
+
if (includeCrossOrigin) cssChunks.push(`/* Cross-origin stylesheet: ${sheet.href || "inline"} */`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
} catch {}
|
|
130
|
+
return cssChunks.join("\n");
|
|
131
|
+
}
|
|
132
|
+
function getPageStats(options) {
|
|
133
|
+
const root = options?.root || document;
|
|
134
|
+
options?.includeCrossOrigin;
|
|
135
|
+
let cssSize = 0;
|
|
136
|
+
let ruleCount = 0;
|
|
137
|
+
let stylesheetCount = 0;
|
|
138
|
+
let skippedStylesheets = 0;
|
|
139
|
+
try {
|
|
140
|
+
if ("styleSheets" in root) {
|
|
141
|
+
const styleSheets = Array.from(root.styleSheets);
|
|
142
|
+
stylesheetCount = styleSheets.length;
|
|
143
|
+
for (const sheet of styleSheets) try {
|
|
144
|
+
if (sheet.cssRules) {
|
|
145
|
+
const rules = Array.from(sheet.cssRules);
|
|
146
|
+
ruleCount += rules.length;
|
|
147
|
+
cssSize += rules.reduce((sum, rule) => sum + rule.cssText.length, 0);
|
|
148
|
+
}
|
|
149
|
+
} catch {
|
|
150
|
+
skippedStylesheets++;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
} catch {}
|
|
154
|
+
return {
|
|
155
|
+
cssSize,
|
|
156
|
+
ruleCount,
|
|
157
|
+
stylesheetCount,
|
|
158
|
+
skippedStylesheets
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Extract chunk name from a cache key.
|
|
163
|
+
*
|
|
164
|
+
* Cache keys have the format: "chunkName\0key:value\0key:value..."
|
|
165
|
+
* or "[states:...]\0chunkName\0..." for predefined states.
|
|
166
|
+
*
|
|
167
|
+
* @param cacheKey - The cache key to parse
|
|
168
|
+
* @returns The chunk name, or null if not found
|
|
169
|
+
*/
|
|
170
|
+
function extractChunkNameFromCacheKey(cacheKey) {
|
|
171
|
+
const parts = cacheKey.split("\0");
|
|
172
|
+
for (const part of parts) {
|
|
173
|
+
if (part.startsWith("[states:")) continue;
|
|
174
|
+
if (!part.includes(":") && part.length > 0) return part;
|
|
175
|
+
}
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Get chunk info for a className by reverse-looking up its cache key.
|
|
180
|
+
*
|
|
181
|
+
* @param className - The tasty class name (e.g., "t0", "t123")
|
|
182
|
+
* @param root - The document or shadow root to search in
|
|
183
|
+
* @returns Object with chunk name and cache key, or nulls if not found
|
|
184
|
+
*/
|
|
185
|
+
function getChunkForClassName(className, root = document) {
|
|
186
|
+
const registry = injector.instance._sheetManager?.getRegistry(root);
|
|
187
|
+
if (!registry) return {
|
|
188
|
+
chunkName: null,
|
|
189
|
+
cacheKey: null
|
|
190
|
+
};
|
|
191
|
+
for (const [cacheKey, cn] of registry.cacheKeyToClassName) if (cn === className) return {
|
|
192
|
+
chunkName: extractChunkNameFromCacheKey(cacheKey),
|
|
193
|
+
cacheKey
|
|
194
|
+
};
|
|
195
|
+
return {
|
|
196
|
+
chunkName: null,
|
|
197
|
+
cacheKey: null
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Get chunk breakdown statistics for all styles.
|
|
202
|
+
*
|
|
203
|
+
* @param root - The document or shadow root to search in
|
|
204
|
+
* @returns Object with breakdown by chunk type and totals
|
|
205
|
+
*/
|
|
206
|
+
function getChunkBreakdown(root = document) {
|
|
207
|
+
const registry = injector.instance._sheetManager?.getRegistry(root);
|
|
208
|
+
if (!registry) return {
|
|
209
|
+
byChunk: {},
|
|
210
|
+
totalChunkTypes: 0
|
|
211
|
+
};
|
|
212
|
+
const byChunk = {};
|
|
213
|
+
for (const [cacheKey, className] of registry.cacheKeyToClassName) {
|
|
214
|
+
const chunkName = extractChunkNameFromCacheKey(cacheKey) || "unknown";
|
|
215
|
+
if (!byChunk[chunkName]) byChunk[chunkName] = {
|
|
216
|
+
classes: [],
|
|
217
|
+
cssSize: 0,
|
|
218
|
+
ruleCount: 0
|
|
219
|
+
};
|
|
220
|
+
byChunk[chunkName].classes.push(className);
|
|
221
|
+
const css = injector.instance.getCssTextForClasses([className], { root });
|
|
222
|
+
byChunk[chunkName].cssSize += css.length;
|
|
223
|
+
byChunk[chunkName].ruleCount += (css.match(/\{[^}]*\}/g) || []).length;
|
|
224
|
+
}
|
|
225
|
+
for (const entry of Object.values(byChunk)) entry.classes.sort((a, b) => {
|
|
226
|
+
return parseInt(a.slice(1)) - parseInt(b.slice(1));
|
|
227
|
+
});
|
|
228
|
+
return {
|
|
229
|
+
byChunk,
|
|
230
|
+
totalChunkTypes: Object.keys(byChunk).length
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Concise tastyDebug API for inspecting styles at runtime
|
|
235
|
+
*/
|
|
236
|
+
const tastyDebug = {
|
|
237
|
+
css(target, opts) {
|
|
238
|
+
const { root = document, prettify = true, log = false } = opts || {};
|
|
239
|
+
let css = "";
|
|
240
|
+
if (typeof target === "string") if (target === "all") css = injector.instance.getCssText({ root });
|
|
241
|
+
else if (target === "global") css = getGlobalCSS(root);
|
|
242
|
+
else if (target === "active") {
|
|
243
|
+
const activeClasses = findAllTastyClasses(root);
|
|
244
|
+
css = injector.instance.getCssTextForClasses(activeClasses, { root });
|
|
245
|
+
} else if (target === "unused") {
|
|
246
|
+
const registry = injector.instance._sheetManager?.getRegistry(root);
|
|
247
|
+
const unusedClasses = registry ? Array.from(registry.refCounts.entries()).filter(([, refCount]) => refCount === 0).map(([className]) => className) : [];
|
|
248
|
+
css = injector.instance.getCssTextForClasses(unusedClasses, { root });
|
|
249
|
+
} else if (target === "page") css = getPageCSS({
|
|
250
|
+
root,
|
|
251
|
+
includeCrossOrigin: true
|
|
252
|
+
});
|
|
253
|
+
else if (/^t\d+$/.test(target)) css = injector.instance.getCssTextForClasses([target], { root });
|
|
254
|
+
else {
|
|
255
|
+
const element = root.querySelector?.(target);
|
|
256
|
+
if (element) css = getCssTextForNode(element, { root });
|
|
257
|
+
}
|
|
258
|
+
else if (Array.isArray(target)) css = injector.instance.getCssTextForClasses(target, { root });
|
|
259
|
+
else if (target instanceof Element) css = getCssTextForNode(target, { root });
|
|
260
|
+
const result = prettify ? prettifyCSS(css) : css;
|
|
261
|
+
if (log) {
|
|
262
|
+
console.group(`🎨 CSS for ${Array.isArray(target) ? `[${target.join(", ")}]` : target}`);
|
|
263
|
+
console.log(result || "(empty)");
|
|
264
|
+
console.groupEnd();
|
|
265
|
+
}
|
|
266
|
+
return result;
|
|
267
|
+
},
|
|
268
|
+
inspect(target, opts) {
|
|
269
|
+
const { root = document } = opts || {};
|
|
270
|
+
const element = typeof target === "string" ? root.querySelector?.(target) : target;
|
|
271
|
+
if (!element) return {
|
|
272
|
+
element: null,
|
|
273
|
+
classes: [],
|
|
274
|
+
chunks: [],
|
|
275
|
+
css: "",
|
|
276
|
+
size: 0,
|
|
277
|
+
rules: 0
|
|
278
|
+
};
|
|
279
|
+
const tastyClasses = (element.getAttribute("class") || "").split(/\s+/).filter((cls) => /^t\d+$/.test(cls));
|
|
280
|
+
const chunks = tastyClasses.map((className) => ({
|
|
281
|
+
className,
|
|
282
|
+
chunkName: getChunkForClassName(className, root).chunkName
|
|
283
|
+
}));
|
|
284
|
+
const css = getCssTextForNode(element, { root });
|
|
285
|
+
const prettifiedCSS = prettifyCSS(css);
|
|
286
|
+
const ruleCount = (css.match(/\{[^}]*\}/g) || []).length;
|
|
287
|
+
return {
|
|
288
|
+
element,
|
|
289
|
+
classes: tastyClasses,
|
|
290
|
+
chunks,
|
|
291
|
+
css: prettifiedCSS,
|
|
292
|
+
size: css.length,
|
|
293
|
+
rules: ruleCount
|
|
294
|
+
};
|
|
295
|
+
},
|
|
296
|
+
cache(opts) {
|
|
297
|
+
const { root = document } = opts || {};
|
|
298
|
+
const activeClasses = findAllTastyClasses(root);
|
|
299
|
+
findAllStyledClasses(root);
|
|
300
|
+
const registry = injector.instance._sheetManager?.getRegistry(root);
|
|
301
|
+
const unusedClasses = registry ? Array.from(registry.refCounts.entries()).filter(([, refCount]) => refCount === 0).map(([className]) => className) : [];
|
|
302
|
+
return {
|
|
303
|
+
classes: {
|
|
304
|
+
active: activeClasses,
|
|
305
|
+
unused: unusedClasses,
|
|
306
|
+
all: [...activeClasses, ...unusedClasses]
|
|
307
|
+
},
|
|
308
|
+
metrics: injector.instance.getMetrics({ root })
|
|
309
|
+
};
|
|
310
|
+
},
|
|
311
|
+
cleanup(opts) {
|
|
312
|
+
const { root } = opts || {};
|
|
313
|
+
injector.instance.cleanup(root);
|
|
314
|
+
},
|
|
315
|
+
metrics(opts) {
|
|
316
|
+
const { root } = opts || {};
|
|
317
|
+
return injector.instance.getMetrics({ root });
|
|
318
|
+
},
|
|
319
|
+
resetMetrics(opts) {
|
|
320
|
+
const { root } = opts || {};
|
|
321
|
+
injector.instance.resetMetrics({ root });
|
|
322
|
+
},
|
|
323
|
+
chunks(opts) {
|
|
324
|
+
const { root = document, log = false } = opts || {};
|
|
325
|
+
const breakdown = getChunkBreakdown(root);
|
|
326
|
+
const totalClasses = Object.values(breakdown.byChunk).reduce((sum, entry) => sum + entry.classes.length, 0);
|
|
327
|
+
if (log) {
|
|
328
|
+
console.group("🧩 Style Chunk Breakdown");
|
|
329
|
+
const displayOrder = [
|
|
330
|
+
CHUNK_NAMES.COMBINED,
|
|
331
|
+
CHUNK_NAMES.APPEARANCE,
|
|
332
|
+
CHUNK_NAMES.FONT,
|
|
333
|
+
CHUNK_NAMES.DIMENSION,
|
|
334
|
+
CHUNK_NAMES.DISPLAY,
|
|
335
|
+
CHUNK_NAMES.LAYOUT,
|
|
336
|
+
CHUNK_NAMES.POSITION,
|
|
337
|
+
CHUNK_NAMES.MISC,
|
|
338
|
+
CHUNK_NAMES.SUBCOMPONENTS
|
|
339
|
+
];
|
|
340
|
+
for (const chunkName of displayOrder) {
|
|
341
|
+
const data = breakdown.byChunk[chunkName];
|
|
342
|
+
if (data) {
|
|
343
|
+
const sizeStr = data.cssSize > 1024 ? `${(data.cssSize / 1024).toFixed(1)}KB` : `${data.cssSize}B`;
|
|
344
|
+
console.log(` • ${chunkName}: ${data.classes.length} classes, ${sizeStr}, ${data.ruleCount} rules`);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
for (const [chunkName, data] of Object.entries(breakdown.byChunk)) if (!displayOrder.includes(chunkName)) {
|
|
348
|
+
const sizeStr = data.cssSize > 1024 ? `${(data.cssSize / 1024).toFixed(1)}KB` : `${data.cssSize}B`;
|
|
349
|
+
console.log(` • ${chunkName}: ${data.classes.length} classes, ${sizeStr}, ${data.ruleCount} rules`);
|
|
350
|
+
}
|
|
351
|
+
console.log(`📊 Total: ${totalClasses} classes across ${breakdown.totalChunkTypes} chunk types`);
|
|
352
|
+
console.groupEnd();
|
|
353
|
+
}
|
|
354
|
+
return {
|
|
355
|
+
...breakdown,
|
|
356
|
+
totalClasses
|
|
357
|
+
};
|
|
358
|
+
},
|
|
359
|
+
getGlobalTypeCSS(type, opts) {
|
|
360
|
+
const { root = document } = opts || {};
|
|
361
|
+
const registry = injector.instance._sheetManager?.getRegistry(root);
|
|
362
|
+
if (!registry) return {
|
|
363
|
+
css: "",
|
|
364
|
+
ruleCount: 0,
|
|
365
|
+
size: 0
|
|
366
|
+
};
|
|
367
|
+
const cssChunks = [];
|
|
368
|
+
let ruleCount = 0;
|
|
369
|
+
if (type === "keyframes") for (const [, entry] of registry.keyframesCache) {
|
|
370
|
+
const info = entry.info;
|
|
371
|
+
const styleSheet = registry.sheets[info.sheetIndex]?.sheet?.sheet;
|
|
372
|
+
if (styleSheet && info.ruleIndex < styleSheet.cssRules.length) {
|
|
373
|
+
const rule = styleSheet.cssRules[info.ruleIndex];
|
|
374
|
+
if (rule) {
|
|
375
|
+
cssChunks.push(rule.cssText);
|
|
376
|
+
ruleCount++;
|
|
377
|
+
}
|
|
378
|
+
} else if (info.cssText) {
|
|
379
|
+
cssChunks.push(info.cssText);
|
|
380
|
+
ruleCount++;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
else {
|
|
384
|
+
const prefix = type === "global" ? "global:" : type === "raw" ? "raw:" : "property:";
|
|
385
|
+
for (const [key, ruleInfo] of registry.globalRules) if (key.startsWith(prefix)) {
|
|
386
|
+
const styleSheet = registry.sheets[ruleInfo.sheetIndex]?.sheet?.sheet;
|
|
387
|
+
if (styleSheet) {
|
|
388
|
+
const start = Math.max(0, ruleInfo.ruleIndex);
|
|
389
|
+
const end = Math.min(styleSheet.cssRules.length - 1, ruleInfo.endRuleIndex ?? ruleInfo.ruleIndex);
|
|
390
|
+
if (start >= 0 && end >= start && start < styleSheet.cssRules.length) for (let i = start; i <= end; i++) {
|
|
391
|
+
const rule = styleSheet.cssRules[i];
|
|
392
|
+
if (rule) {
|
|
393
|
+
cssChunks.push(rule.cssText);
|
|
394
|
+
ruleCount++;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
} else if (ruleInfo.cssText && ruleInfo.cssText.length) {
|
|
398
|
+
cssChunks.push(...ruleInfo.cssText);
|
|
399
|
+
ruleCount += ruleInfo.cssText.length;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
const rawCSS = cssChunks.join("\n");
|
|
404
|
+
return {
|
|
405
|
+
css: prettifyCSS(rawCSS),
|
|
406
|
+
ruleCount,
|
|
407
|
+
size: rawCSS.length
|
|
408
|
+
};
|
|
409
|
+
},
|
|
410
|
+
defs(opts) {
|
|
411
|
+
const { root = document } = opts || {};
|
|
412
|
+
let properties = [];
|
|
413
|
+
try {
|
|
414
|
+
const registry = injector.instance._sheetManager?.getRegistry(root);
|
|
415
|
+
if (registry?.injectedProperties) properties = Array.from(registry.injectedProperties.keys()).sort();
|
|
416
|
+
} catch {
|
|
417
|
+
const allCSS = injector.instance.getCssText({ root });
|
|
418
|
+
const propRegex = /@property\s+(--[a-z0-9-]+)/gi;
|
|
419
|
+
const propSet = /* @__PURE__ */ new Set();
|
|
420
|
+
let match;
|
|
421
|
+
while ((match = propRegex.exec(allCSS)) !== null) propSet.add(match[1]);
|
|
422
|
+
properties = Array.from(propSet).sort();
|
|
423
|
+
}
|
|
424
|
+
let keyframes = [];
|
|
425
|
+
try {
|
|
426
|
+
const registry = injector.instance._sheetManager?.getRegistry(root);
|
|
427
|
+
if (registry) {
|
|
428
|
+
for (const entry of registry.keyframesCache.values()) keyframes.push({
|
|
429
|
+
name: entry.name,
|
|
430
|
+
refCount: entry.refCount
|
|
431
|
+
});
|
|
432
|
+
keyframes.sort((a, b) => a.name.localeCompare(b.name));
|
|
433
|
+
}
|
|
434
|
+
} catch {
|
|
435
|
+
const allCSS = injector.instance.getCssText({ root });
|
|
436
|
+
const keyframesRegex = /@keyframes\s+([a-zA-Z0-9_-]+)/gi;
|
|
437
|
+
const keyframesSet = /* @__PURE__ */ new Set();
|
|
438
|
+
let match;
|
|
439
|
+
while ((match = keyframesRegex.exec(allCSS)) !== null) keyframesSet.add(match[1]);
|
|
440
|
+
keyframes = Array.from(keyframesSet).sort().map((name) => ({
|
|
441
|
+
name,
|
|
442
|
+
refCount: 1
|
|
443
|
+
}));
|
|
444
|
+
}
|
|
445
|
+
return {
|
|
446
|
+
properties,
|
|
447
|
+
keyframes
|
|
448
|
+
};
|
|
449
|
+
},
|
|
450
|
+
summary(opts) {
|
|
451
|
+
const { root = document, log = false, includePageCSS = false } = opts || {};
|
|
452
|
+
const cacheStatus = this.cache({ root });
|
|
453
|
+
const definitions = this.defs({ root });
|
|
454
|
+
const metrics = this.metrics({ root });
|
|
455
|
+
const activeCSS = this.css("active", {
|
|
456
|
+
root,
|
|
457
|
+
prettify: false
|
|
458
|
+
});
|
|
459
|
+
const unusedCSS = this.css("unused", {
|
|
460
|
+
root,
|
|
461
|
+
prettify: false
|
|
462
|
+
});
|
|
463
|
+
const allCSS = this.css("all", {
|
|
464
|
+
root,
|
|
465
|
+
prettify: false
|
|
466
|
+
});
|
|
467
|
+
const classCSSSize = activeCSS.length + unusedCSS.length;
|
|
468
|
+
const totalGlobalCSSSize = allCSS.length - classCSSSize;
|
|
469
|
+
const globalData = this.getGlobalTypeCSS("global", { root });
|
|
470
|
+
const rawData = this.getGlobalTypeCSS("raw", { root });
|
|
471
|
+
const keyframesData = this.getGlobalTypeCSS("keyframes", { root });
|
|
472
|
+
const propertyData = this.getGlobalTypeCSS("property", { root });
|
|
473
|
+
const globalTypesTotalSize = globalData.size + rawData.size + keyframesData.size + propertyData.size;
|
|
474
|
+
const cleanupSummary = {
|
|
475
|
+
enabled: !!metrics,
|
|
476
|
+
totalCleanups: metrics?.cleanupHistory?.length || 0,
|
|
477
|
+
totalClassesDeleted: metrics?.cleanupHistory?.reduce((sum, c) => sum + c.classesDeleted, 0) || 0,
|
|
478
|
+
totalCssDeleted: metrics?.cleanupHistory?.reduce((sum, c) => sum + c.cssSize, 0) || 0,
|
|
479
|
+
totalRulesDeleted: metrics?.cleanupHistory?.reduce((sum, c) => sum + c.rulesDeleted, 0) || 0,
|
|
480
|
+
averageClassesPerCleanup: 0,
|
|
481
|
+
averageCssPerCleanup: 0,
|
|
482
|
+
averageRulesPerCleanup: 0,
|
|
483
|
+
lastCleanup: void 0
|
|
484
|
+
};
|
|
485
|
+
if (cleanupSummary.totalCleanups > 0) {
|
|
486
|
+
cleanupSummary.averageClassesPerCleanup = cleanupSummary.totalClassesDeleted / cleanupSummary.totalCleanups;
|
|
487
|
+
cleanupSummary.averageCssPerCleanup = cleanupSummary.totalCssDeleted / cleanupSummary.totalCleanups;
|
|
488
|
+
cleanupSummary.averageRulesPerCleanup = cleanupSummary.totalRulesDeleted / cleanupSummary.totalCleanups;
|
|
489
|
+
const lastCleanup = metrics?.cleanupHistory?.[metrics.cleanupHistory.length - 1];
|
|
490
|
+
if (lastCleanup) cleanupSummary.lastCleanup = {
|
|
491
|
+
...lastCleanup,
|
|
492
|
+
date: new Date(lastCleanup.timestamp).toISOString()
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
let page;
|
|
496
|
+
if (includePageCSS) page = {
|
|
497
|
+
...getPageStats({
|
|
498
|
+
root,
|
|
499
|
+
includeCrossOrigin: true
|
|
500
|
+
}),
|
|
501
|
+
css: includePageCSS === "all" ? getPageCSS({
|
|
502
|
+
root,
|
|
503
|
+
includeCrossOrigin: true
|
|
504
|
+
}) : void 0
|
|
505
|
+
};
|
|
506
|
+
const useIndividualSizes = Math.abs(globalTypesTotalSize - totalGlobalCSSSize) < 100;
|
|
507
|
+
let adjustedGlobalSizes;
|
|
508
|
+
if (useIndividualSizes) adjustedGlobalSizes = {
|
|
509
|
+
globalCSSSize: globalData.size,
|
|
510
|
+
rawCSSSize: rawData.size,
|
|
511
|
+
keyframesCSSSize: keyframesData.size,
|
|
512
|
+
propertyCSSSize: propertyData.size
|
|
513
|
+
};
|
|
514
|
+
else {
|
|
515
|
+
const scaleFactor = totalGlobalCSSSize / globalTypesTotalSize;
|
|
516
|
+
adjustedGlobalSizes = {
|
|
517
|
+
globalCSSSize: Math.round(globalData.size * scaleFactor),
|
|
518
|
+
rawCSSSize: Math.round(rawData.size * scaleFactor),
|
|
519
|
+
keyframesCSSSize: Math.round(keyframesData.size * scaleFactor),
|
|
520
|
+
propertyCSSSize: Math.round(propertyData.size * scaleFactor)
|
|
521
|
+
};
|
|
522
|
+
}
|
|
523
|
+
const chunkBreakdown = getChunkBreakdown(root);
|
|
524
|
+
const summary = {
|
|
525
|
+
activeClasses: cacheStatus.classes.active,
|
|
526
|
+
unusedClasses: cacheStatus.classes.unused,
|
|
527
|
+
totalStyledClasses: cacheStatus.classes.all,
|
|
528
|
+
activeCSSSize: activeCSS.length,
|
|
529
|
+
unusedCSSSize: unusedCSS.length,
|
|
530
|
+
...adjustedGlobalSizes,
|
|
531
|
+
totalCSSSize: allCSS.length,
|
|
532
|
+
activeCSS: prettifyCSS(activeCSS),
|
|
533
|
+
unusedCSS: prettifyCSS(unusedCSS),
|
|
534
|
+
globalCSS: globalData.css,
|
|
535
|
+
rawCSS: rawData.css,
|
|
536
|
+
keyframesCSS: keyframesData.css,
|
|
537
|
+
propertyCSS: propertyData.css,
|
|
538
|
+
allCSS: prettifyCSS(allCSS),
|
|
539
|
+
globalRuleCount: globalData.ruleCount,
|
|
540
|
+
rawRuleCount: rawData.ruleCount,
|
|
541
|
+
keyframesRuleCount: keyframesData.ruleCount,
|
|
542
|
+
propertyRuleCount: propertyData.ruleCount,
|
|
543
|
+
page,
|
|
544
|
+
metrics,
|
|
545
|
+
definedProperties: definitions.properties,
|
|
546
|
+
definedKeyframes: definitions.keyframes,
|
|
547
|
+
propertyCount: definitions.properties.length,
|
|
548
|
+
keyframeCount: definitions.keyframes.length,
|
|
549
|
+
cleanupSummary,
|
|
550
|
+
chunkBreakdown
|
|
551
|
+
};
|
|
552
|
+
if (log) {
|
|
553
|
+
console.group("🎨 Comprehensive Tasty Debug Summary");
|
|
554
|
+
console.log(`📊 Style Cache Status:`);
|
|
555
|
+
console.log(` • Active classes (in DOM): ${summary.activeClasses.length}`);
|
|
556
|
+
console.log(` • Unused classes (refCount = 0): ${summary.unusedClasses.length}`);
|
|
557
|
+
console.log(` • Total styled classes: ${summary.totalStyledClasses.length}`);
|
|
558
|
+
console.log(`💾 CSS Size:`);
|
|
559
|
+
console.log(` • Active CSS: ${summary.activeCSSSize} characters`);
|
|
560
|
+
console.log(` • Unused CSS: ${summary.unusedCSSSize} characters`);
|
|
561
|
+
console.log(` • Global CSS (injectGlobal): ${summary.globalCSSSize} characters (${summary.globalRuleCount} rules)`);
|
|
562
|
+
console.log(` • Raw CSS (injectRawCSS/useRawCSS): ${summary.rawCSSSize} characters (${summary.rawRuleCount} rules)`);
|
|
563
|
+
console.log(` • Keyframes CSS: ${summary.keyframesCSSSize} characters (${summary.keyframesRuleCount} rules)`);
|
|
564
|
+
console.log(` • Property CSS: ${summary.propertyCSSSize} characters (${summary.propertyRuleCount} rules)`);
|
|
565
|
+
const calculatedTotal = summary.activeCSSSize + summary.unusedCSSSize + summary.globalCSSSize + summary.rawCSSSize + summary.keyframesCSSSize + summary.propertyCSSSize;
|
|
566
|
+
console.log(` • Calculated Total: ${calculatedTotal} characters`);
|
|
567
|
+
console.log(` • Actual Total: ${summary.totalCSSSize} characters`);
|
|
568
|
+
const difference = Math.abs(calculatedTotal - summary.totalCSSSize);
|
|
569
|
+
if (difference > 100) {
|
|
570
|
+
console.warn(` ⚠️ Size mismatch: ${difference} characters difference`);
|
|
571
|
+
console.group("🔍 Debugging size mismatch:");
|
|
572
|
+
console.log(`Active + Unused = ${summary.activeCSSSize + summary.unusedCSSSize}`);
|
|
573
|
+
console.log(`All Global Types = ${summary.globalCSSSize + summary.rawCSSSize + summary.keyframesCSSSize + summary.propertyCSSSize}`);
|
|
574
|
+
console.log(`Class-based vs Total difference = ${summary.totalCSSSize - (summary.activeCSSSize + summary.unusedCSSSize)}`);
|
|
575
|
+
console.log(`Raw global extraction total: ${globalTypesTotalSize}`);
|
|
576
|
+
console.log(`Calculated global size: ${totalGlobalCSSSize}`);
|
|
577
|
+
console.log(`Used individual sizes: ${useIndividualSizes}`);
|
|
578
|
+
if (!useIndividualSizes) console.log(`Scale factor applied: ${(totalGlobalCSSSize / globalTypesTotalSize).toFixed(3)}`);
|
|
579
|
+
console.groupEnd();
|
|
580
|
+
}
|
|
581
|
+
if (page) {
|
|
582
|
+
console.log(`📄 Page CSS:`);
|
|
583
|
+
console.log(` • Total page CSS: ${page.cssSize} characters`);
|
|
584
|
+
console.log(` • Total page rules: ${page.ruleCount}`);
|
|
585
|
+
console.log(` • Stylesheets: ${page.stylesheetCount} (${page.skippedStylesheets} skipped)`);
|
|
586
|
+
}
|
|
587
|
+
console.log("🏷️ Properties & Keyframes:");
|
|
588
|
+
console.log(` • Defined @property: ${summary.propertyCount}`);
|
|
589
|
+
console.log(` • Defined @keyframes: ${summary.keyframeCount}`);
|
|
590
|
+
if (metrics) {
|
|
591
|
+
console.log(`⚡ Performance Metrics:`);
|
|
592
|
+
console.log(` • Cache hits: ${metrics.hits}`);
|
|
593
|
+
console.log(` • Cache misses: ${metrics.misses}`);
|
|
594
|
+
console.log(` • Cached style reuses: ${metrics.unusedHits}`);
|
|
595
|
+
const hitRate = metrics.hits + metrics.misses > 0 ? ((metrics.hits + (metrics.unusedHits || 0)) / (metrics.hits + metrics.misses) * 100).toFixed(1) : "0";
|
|
596
|
+
console.log(` • Overall cache hit rate: ${hitRate}%`);
|
|
597
|
+
}
|
|
598
|
+
if (summary.chunkBreakdown.totalChunkTypes > 0) {
|
|
599
|
+
console.log("🧩 Style Chunk Breakdown:");
|
|
600
|
+
const displayOrder = [
|
|
601
|
+
CHUNK_NAMES.COMBINED,
|
|
602
|
+
CHUNK_NAMES.APPEARANCE,
|
|
603
|
+
CHUNK_NAMES.FONT,
|
|
604
|
+
CHUNK_NAMES.DIMENSION,
|
|
605
|
+
CHUNK_NAMES.DISPLAY,
|
|
606
|
+
CHUNK_NAMES.LAYOUT,
|
|
607
|
+
CHUNK_NAMES.POSITION,
|
|
608
|
+
CHUNK_NAMES.MISC,
|
|
609
|
+
CHUNK_NAMES.SUBCOMPONENTS
|
|
610
|
+
];
|
|
611
|
+
for (const chunkName of displayOrder) {
|
|
612
|
+
const data = summary.chunkBreakdown.byChunk[chunkName];
|
|
613
|
+
if (data) {
|
|
614
|
+
const sizeStr = data.cssSize > 1024 ? `${(data.cssSize / 1024).toFixed(1)}KB` : `${data.cssSize}B`;
|
|
615
|
+
console.log(` • ${chunkName}: ${data.classes.length} classes, ${sizeStr}, ${data.ruleCount} rules`);
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
console.log("🔍 Details:");
|
|
620
|
+
console.log(" • Active classes:", summary.activeClasses);
|
|
621
|
+
console.log(" • Unused classes:", summary.unusedClasses);
|
|
622
|
+
console.groupEnd();
|
|
623
|
+
}
|
|
624
|
+
return summary;
|
|
625
|
+
},
|
|
626
|
+
pageCSS(opts) {
|
|
627
|
+
const { root = document, prettify = true, log = false, includeCrossOrigin = true } = opts || {};
|
|
628
|
+
const css = getPageCSS({
|
|
629
|
+
root,
|
|
630
|
+
includeCrossOrigin
|
|
631
|
+
});
|
|
632
|
+
const result = prettify ? prettifyCSS(css) : css;
|
|
633
|
+
if (log) {
|
|
634
|
+
console.group("📄 Page CSS (All Stylesheets)");
|
|
635
|
+
console.log(result || "(empty)");
|
|
636
|
+
console.groupEnd();
|
|
637
|
+
}
|
|
638
|
+
return result;
|
|
639
|
+
},
|
|
640
|
+
pageStats(opts) {
|
|
641
|
+
const { root = document, includeCrossOrigin = true } = opts || {};
|
|
642
|
+
return getPageStats({
|
|
643
|
+
root,
|
|
644
|
+
includeCrossOrigin
|
|
645
|
+
});
|
|
646
|
+
},
|
|
647
|
+
install() {
|
|
648
|
+
if (typeof window !== "undefined" && window.tastyDebug !== tastyDebug) {
|
|
649
|
+
window.tastyDebug = tastyDebug;
|
|
650
|
+
console.log("🎨 tastyDebug installed on window. Run tastyDebug.help() for quick start guide.");
|
|
651
|
+
}
|
|
652
|
+
},
|
|
653
|
+
log(target, opts) {
|
|
654
|
+
const { title, ...cssOpts } = opts || {};
|
|
655
|
+
const css = tastyDebug.css(target, cssOpts);
|
|
656
|
+
if (!css.trim()) {
|
|
657
|
+
console.warn(`🎨 No CSS found for target: ${String(target)}`);
|
|
658
|
+
return;
|
|
659
|
+
}
|
|
660
|
+
const targetStr = Array.isArray(target) ? target.join(", ") : String(target);
|
|
661
|
+
const displayTitle = title || `CSS for "${targetStr}"`;
|
|
662
|
+
const lines = css.split("\n").length;
|
|
663
|
+
const size = new Blob([css]).size;
|
|
664
|
+
const sizeStr = size > 1024 ? `${(size / 1024).toFixed(1)}KB` : `${size}B`;
|
|
665
|
+
const ruleCount = (css.match(/\{/g) || []).length;
|
|
666
|
+
console.group(`🎨 ${displayTitle} (${ruleCount} rules, ${lines} lines, ${sizeStr})`);
|
|
667
|
+
const subElementMatches = css.match(/\[data-element="([^"]+)"\]/g) || [];
|
|
668
|
+
const subElements = [...new Set(subElementMatches.map((match) => match.match(/\[data-element="([^"]+)"\]/)?.[1]).filter(Boolean))];
|
|
669
|
+
if (subElements.length > 0) {
|
|
670
|
+
console.log(`🧩 Sub-elements found: ${subElements.join(", ")}`);
|
|
671
|
+
subElements.forEach((element) => {
|
|
672
|
+
`${element}`;
|
|
673
|
+
const elementRegex = new RegExp(`[^}]*\\[data-element="${element.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}"\\][^{]*\\{[^}]*\\}`, "gm");
|
|
674
|
+
const elementCSS = (css.match(elementRegex) || []).join("\n");
|
|
675
|
+
if (elementCSS) {
|
|
676
|
+
const elementRules = (elementCSS.match(/\{/g) || []).length;
|
|
677
|
+
const elementLines = elementCSS.split("\n").length;
|
|
678
|
+
const elementSize = new Blob([elementCSS]).size;
|
|
679
|
+
const elementSizeStr = elementSize > 1024 ? `${(elementSize / 1024).toFixed(1)}KB` : `${elementSize}B`;
|
|
680
|
+
console.groupCollapsed(`🧩 ${element} (${elementRules} rules, ${elementLines} lines, ${elementSizeStr})`);
|
|
681
|
+
console.log(`%c${elementCSS}`, "color: #666; font-family: monospace; font-size: 12px; white-space: pre;");
|
|
682
|
+
console.groupEnd();
|
|
683
|
+
}
|
|
684
|
+
});
|
|
685
|
+
}
|
|
686
|
+
console.groupCollapsed("📄 Full CSS (click to expand)");
|
|
687
|
+
console.log(`%c${css}`, "color: #666; font-family: monospace; font-size: 12px; white-space: pre;");
|
|
688
|
+
console.groupEnd();
|
|
689
|
+
console.groupEnd();
|
|
690
|
+
},
|
|
691
|
+
help() {
|
|
692
|
+
console.group("🎨 tastyDebug - Quick Start Guide");
|
|
693
|
+
console.log("💡 Essential commands:");
|
|
694
|
+
console.log(" • tastyDebug.summary({ log: true }) - comprehensive overview");
|
|
695
|
+
console.log(" • tastyDebug.chunks({ log: true }) - style chunk breakdown");
|
|
696
|
+
console.log(" • tastyDebug.log(\"active\") - beautiful CSS display");
|
|
697
|
+
console.log(" • tastyDebug.css(\"active\") - get active CSS");
|
|
698
|
+
console.log(" • tastyDebug.inspect(\".my-element\") - element inspection with chunk info");
|
|
699
|
+
console.log(" • tastyDebug.cache() - cache status");
|
|
700
|
+
console.log(" • tastyDebug.defs() - defined properties & keyframes");
|
|
701
|
+
console.log(" • tastyDebug.pageCSS({ log: true }) - all page CSS");
|
|
702
|
+
console.log("");
|
|
703
|
+
console.log("📖 Common targets for css()/log():");
|
|
704
|
+
console.log(" • \"all\" - all tasty CSS + global CSS");
|
|
705
|
+
console.log(" • \"active\" - CSS for classes in DOM");
|
|
706
|
+
console.log(" • \"unused\" - CSS for classes with refCount = 0");
|
|
707
|
+
console.log(" • \"global\" - only global CSS (injectGlobal)");
|
|
708
|
+
console.log(" • \"page\" - ALL page CSS (including non-tasty)");
|
|
709
|
+
console.log(" • \"t123\" - specific tasty class");
|
|
710
|
+
console.log(" • [\".my-selector\"] - CSS selector");
|
|
711
|
+
console.log("");
|
|
712
|
+
console.log("🔧 Available options:");
|
|
713
|
+
console.log(" • { log: true } - auto-log results to console");
|
|
714
|
+
console.log(" • { title: \"Custom\" } - custom title for log()");
|
|
715
|
+
console.log(" • { root: shadowRoot } - target Shadow DOM");
|
|
716
|
+
console.log(" • { prettify: false } - skip CSS formatting");
|
|
717
|
+
console.log("");
|
|
718
|
+
console.log("🧩 Style Chunking:");
|
|
719
|
+
console.log(" Elements have multiple classes (one per chunk: appearance, font, dimension, etc.)");
|
|
720
|
+
console.log(" • tastyDebug.chunks({ log: true }) - breakdown by chunk type");
|
|
721
|
+
console.log(" • tastyDebug.inspect() - shows which chunk each class belongs to");
|
|
722
|
+
console.log(" Chunk types: combined (non-chunked), appearance, font, dimension, container, scrollbar, position, misc, subcomponents");
|
|
723
|
+
console.groupEnd();
|
|
724
|
+
}
|
|
725
|
+
};
|
|
726
|
+
/**
|
|
727
|
+
* Auto-install in development
|
|
728
|
+
*/
|
|
729
|
+
if (typeof window !== "undefined" && isDevEnv()) tastyDebug.install();
|
|
730
|
+
|
|
731
|
+
//#endregion
|
|
732
|
+
export { tastyDebug };
|
|
733
|
+
//# sourceMappingURL=debug.js.map
|