@tenphi/tasty 0.0.0-snapshot.05c1c22
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 +629 -0
- package/dist/_virtual/_rolldown/runtime.js +7 -0
- package/dist/chunks/cacheKey.d.ts +1 -0
- package/dist/chunks/cacheKey.js +77 -0
- package/dist/chunks/cacheKey.js.map +1 -0
- package/dist/chunks/definitions.d.ts +37 -0
- package/dist/chunks/definitions.js +258 -0
- package/dist/chunks/definitions.js.map +1 -0
- package/dist/chunks/index.d.ts +1 -0
- package/dist/chunks/renderChunk.d.ts +1 -0
- package/dist/chunks/renderChunk.js +59 -0
- package/dist/chunks/renderChunk.js.map +1 -0
- package/dist/config.d.ts +366 -0
- package/dist/config.js +503 -0
- package/dist/config.js.map +1 -0
- package/dist/core/index.d.ts +33 -0
- package/dist/core/index.js +26 -0
- package/dist/counter-style/index.js +51 -0
- package/dist/counter-style/index.js.map +1 -0
- package/dist/debug.d.ts +89 -0
- package/dist/debug.js +453 -0
- package/dist/debug.js.map +1 -0
- package/dist/font-face/index.js +63 -0
- package/dist/font-face/index.js.map +1 -0
- package/dist/hooks/index.d.ts +7 -0
- package/dist/hooks/resolve-ssr-collector.js +14 -0
- package/dist/hooks/resolve-ssr-collector.js.map +1 -0
- package/dist/hooks/useCounterStyle.d.ts +50 -0
- package/dist/hooks/useCounterStyle.js +46 -0
- package/dist/hooks/useCounterStyle.js.map +1 -0
- package/dist/hooks/useFontFace.d.ts +43 -0
- package/dist/hooks/useFontFace.js +70 -0
- package/dist/hooks/useFontFace.js.map +1 -0
- package/dist/hooks/useGlobalStyles.d.ts +30 -0
- package/dist/hooks/useGlobalStyles.js +78 -0
- package/dist/hooks/useGlobalStyles.js.map +1 -0
- package/dist/hooks/useKeyframes.d.ts +56 -0
- package/dist/hooks/useKeyframes.js +64 -0
- package/dist/hooks/useKeyframes.js.map +1 -0
- package/dist/hooks/useProperty.d.ts +79 -0
- package/dist/hooks/useProperty.js +109 -0
- package/dist/hooks/useProperty.js.map +1 -0
- package/dist/hooks/useRawCSS.d.ts +53 -0
- package/dist/hooks/useRawCSS.js +35 -0
- package/dist/hooks/useRawCSS.js.map +1 -0
- package/dist/hooks/useStyles.d.ts +45 -0
- package/dist/hooks/useStyles.js +237 -0
- package/dist/hooks/useStyles.js.map +1 -0
- package/dist/index.d.ts +50 -0
- package/dist/index.js +35 -0
- package/dist/injector/index.d.ts +183 -0
- package/dist/injector/index.js +179 -0
- package/dist/injector/index.js.map +1 -0
- package/dist/injector/injector.d.ts +166 -0
- package/dist/injector/injector.js +464 -0
- package/dist/injector/injector.js.map +1 -0
- package/dist/injector/sheet-manager.d.ts +136 -0
- package/dist/injector/sheet-manager.js +733 -0
- package/dist/injector/sheet-manager.js.map +1 -0
- package/dist/injector/types.d.ts +204 -0
- package/dist/keyframes/index.js +206 -0
- package/dist/keyframes/index.js.map +1 -0
- package/dist/parser/classify.js +319 -0
- package/dist/parser/classify.js.map +1 -0
- package/dist/parser/const.js +49 -0
- package/dist/parser/const.js.map +1 -0
- package/dist/parser/lru.js +109 -0
- package/dist/parser/lru.js.map +1 -0
- package/dist/parser/parser.d.ts +25 -0
- package/dist/parser/parser.js +115 -0
- package/dist/parser/parser.js.map +1 -0
- package/dist/parser/tokenizer.js +69 -0
- package/dist/parser/tokenizer.js.map +1 -0
- package/dist/parser/types.d.ts +51 -0
- package/dist/parser/types.js +46 -0
- package/dist/parser/types.js.map +1 -0
- package/dist/pipeline/conditions.d.ts +134 -0
- package/dist/pipeline/conditions.js +406 -0
- package/dist/pipeline/conditions.js.map +1 -0
- package/dist/pipeline/exclusive.js +230 -0
- package/dist/pipeline/exclusive.js.map +1 -0
- package/dist/pipeline/index.d.ts +55 -0
- package/dist/pipeline/index.js +708 -0
- package/dist/pipeline/index.js.map +1 -0
- package/dist/pipeline/materialize.js +1103 -0
- package/dist/pipeline/materialize.js.map +1 -0
- package/dist/pipeline/parseStateKey.d.ts +15 -0
- package/dist/pipeline/parseStateKey.js +446 -0
- package/dist/pipeline/parseStateKey.js.map +1 -0
- package/dist/pipeline/simplify.js +515 -0
- package/dist/pipeline/simplify.js.map +1 -0
- package/dist/pipeline/warnings.js +18 -0
- package/dist/pipeline/warnings.js.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 +97 -0
- package/dist/plugins/okhsl-plugin.js.map +1 -0
- package/dist/plugins/types.d.ts +76 -0
- package/dist/properties/index.js +222 -0
- package/dist/properties/index.js.map +1 -0
- package/dist/properties/property-type-resolver.d.ts +24 -0
- package/dist/properties/property-type-resolver.js +90 -0
- package/dist/properties/property-type-resolver.js.map +1 -0
- package/dist/ssr/astro.d.ts +29 -0
- package/dist/ssr/astro.js +64 -0
- package/dist/ssr/astro.js.map +1 -0
- package/dist/ssr/async-storage.d.ts +17 -0
- package/dist/ssr/async-storage.js +34 -0
- package/dist/ssr/async-storage.js.map +1 -0
- package/dist/ssr/collect-auto-properties.js +39 -0
- package/dist/ssr/collect-auto-properties.js.map +1 -0
- package/dist/ssr/collector.d.ts +102 -0
- package/dist/ssr/collector.js +226 -0
- package/dist/ssr/collector.js.map +1 -0
- package/dist/ssr/context.d.ts +8 -0
- package/dist/ssr/context.js +13 -0
- package/dist/ssr/context.js.map +1 -0
- package/dist/ssr/format-global-rules.js +22 -0
- package/dist/ssr/format-global-rules.js.map +1 -0
- package/dist/ssr/format-keyframes.js +69 -0
- package/dist/ssr/format-keyframes.js.map +1 -0
- package/dist/ssr/format-property.js +49 -0
- package/dist/ssr/format-property.js.map +1 -0
- package/dist/ssr/format-rules.js +73 -0
- package/dist/ssr/format-rules.js.map +1 -0
- package/dist/ssr/hydrate.d.ts +22 -0
- package/dist/ssr/hydrate.js +49 -0
- package/dist/ssr/hydrate.js.map +1 -0
- package/dist/ssr/index.d.ts +5 -0
- package/dist/ssr/index.js +11 -0
- package/dist/ssr/index.js.map +1 -0
- package/dist/ssr/next.d.ts +45 -0
- package/dist/ssr/next.js +69 -0
- package/dist/ssr/next.js.map +1 -0
- package/dist/ssr/ssr-collector-ref.js +12 -0
- package/dist/ssr/ssr-collector-ref.js.map +1 -0
- package/dist/states/index.d.ts +49 -0
- package/dist/states/index.js +170 -0
- package/dist/states/index.js.map +1 -0
- package/dist/static/index.d.ts +5 -0
- package/dist/static/index.js +4 -0
- package/dist/static/inject.d.ts +5 -0
- package/dist/static/inject.js +17 -0
- package/dist/static/inject.js.map +1 -0
- package/dist/static/tastyStatic.d.ts +46 -0
- package/dist/static/tastyStatic.js +30 -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/border.d.ts +25 -0
- package/dist/styles/border.js +113 -0
- package/dist/styles/border.js.map +1 -0
- package/dist/styles/color.d.ts +14 -0
- package/dist/styles/color.js +26 -0
- package/dist/styles/color.js.map +1 -0
- package/dist/styles/createStyle.js +79 -0
- package/dist/styles/createStyle.js.map +1 -0
- package/dist/styles/dimension.js +96 -0
- package/dist/styles/dimension.js.map +1 -0
- package/dist/styles/display.d.ts +37 -0
- package/dist/styles/display.js +66 -0
- package/dist/styles/display.js.map +1 -0
- package/dist/styles/fade.d.ts +15 -0
- package/dist/styles/fade.js +57 -0
- package/dist/styles/fade.js.map +1 -0
- package/dist/styles/fill.d.ts +42 -0
- package/dist/styles/fill.js +51 -0
- package/dist/styles/fill.js.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/gap.d.ts +31 -0
- package/dist/styles/gap.js +36 -0
- package/dist/styles/gap.js.map +1 -0
- package/dist/styles/height.d.ts +17 -0
- package/dist/styles/height.js +19 -0
- package/dist/styles/height.js.map +1 -0
- package/dist/styles/index.d.ts +1 -0
- package/dist/styles/index.js +8 -0
- package/dist/styles/index.js.map +1 -0
- package/dist/styles/inset.d.ts +52 -0
- package/dist/styles/inset.js +149 -0
- package/dist/styles/inset.js.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/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 +24 -0
- package/dist/styles/margin.js +103 -0
- package/dist/styles/margin.js.map +1 -0
- package/dist/styles/outline.d.ts +29 -0
- package/dist/styles/outline.js +64 -0
- package/dist/styles/outline.js.map +1 -0
- package/dist/styles/padding.d.ts +24 -0
- package/dist/styles/padding.js +103 -0
- package/dist/styles/padding.js.map +1 -0
- package/dist/styles/predefined.d.ts +71 -0
- package/dist/styles/predefined.js +237 -0
- package/dist/styles/predefined.js.map +1 -0
- package/dist/styles/preset.d.ts +52 -0
- package/dist/styles/preset.js +126 -0
- package/dist/styles/preset.js.map +1 -0
- package/dist/styles/radius.d.ts +12 -0
- package/dist/styles/radius.js +71 -0
- package/dist/styles/radius.js.map +1 -0
- package/dist/styles/scrollbar.d.ts +25 -0
- package/dist/styles/scrollbar.js +46 -0
- package/dist/styles/scrollbar.js.map +1 -0
- package/dist/styles/shadow.d.ts +14 -0
- package/dist/styles/shadow.js +23 -0
- package/dist/styles/shadow.js.map +1 -0
- package/dist/styles/transition.d.ts +14 -0
- package/dist/styles/transition.js +157 -0
- package/dist/styles/transition.js.map +1 -0
- package/dist/styles/types.d.ts +549 -0
- package/dist/styles/width.d.ts +17 -0
- package/dist/styles/width.js +19 -0
- package/dist/styles/width.js.map +1 -0
- package/dist/tasty.d.ts +119 -0
- package/dist/tasty.js +231 -0
- package/dist/tasty.js.map +1 -0
- package/dist/types.d.ts +184 -0
- package/dist/utils/cache-wrapper.js +21 -0
- package/dist/utils/cache-wrapper.js.map +1 -0
- package/dist/utils/case-converter.js +8 -0
- package/dist/utils/case-converter.js.map +1 -0
- package/dist/utils/color-math.d.ts +46 -0
- package/dist/utils/color-math.js +749 -0
- package/dist/utils/color-math.js.map +1 -0
- package/dist/utils/color-space.d.ts +5 -0
- package/dist/utils/color-space.js +228 -0
- package/dist/utils/color-space.js.map +1 -0
- package/dist/utils/colors.d.ts +5 -0
- package/dist/utils/colors.js +10 -0
- package/dist/utils/colors.js.map +1 -0
- package/dist/utils/css-types.d.ts +7 -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/has-keys.js +13 -0
- package/dist/utils/has-keys.js.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-valid-element-type.js +15 -0
- package/dist/utils/is-valid-element-type.js.map +1 -0
- package/dist/utils/merge-styles.d.ts +7 -0
- package/dist/utils/merge-styles.js +145 -0
- package/dist/utils/merge-styles.js.map +1 -0
- package/dist/utils/mod-attrs.d.ts +6 -0
- package/dist/utils/mod-attrs.js +20 -0
- package/dist/utils/mod-attrs.js.map +1 -0
- package/dist/utils/process-tokens.d.ts +21 -0
- package/dist/utils/process-tokens.js +90 -0
- package/dist/utils/process-tokens.js.map +1 -0
- package/dist/utils/resolve-recipes.d.ts +17 -0
- package/dist/utils/resolve-recipes.js +146 -0
- package/dist/utils/resolve-recipes.js.map +1 -0
- package/dist/utils/selector-transform.js +32 -0
- package/dist/utils/selector-transform.js.map +1 -0
- package/dist/utils/string.js +8 -0
- package/dist/utils/string.js.map +1 -0
- package/dist/utils/styles.d.ts +99 -0
- package/dist/utils/styles.js +220 -0
- package/dist/utils/styles.js.map +1 -0
- package/dist/utils/typography.d.ts +47 -0
- package/dist/utils/typography.js +51 -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.ts +182 -0
- package/dist/zero/babel.js +438 -0
- package/dist/zero/babel.js.map +1 -0
- package/dist/zero/css-writer.d.ts +45 -0
- package/dist/zero/css-writer.js +73 -0
- package/dist/zero/css-writer.js.map +1 -0
- package/dist/zero/extractor.d.ts +24 -0
- package/dist/zero/extractor.js +266 -0
- package/dist/zero/extractor.js.map +1 -0
- package/dist/zero/index.d.ts +3 -0
- package/dist/zero/index.js +3 -0
- package/dist/zero/next.d.ts +86 -0
- package/dist/zero/next.js +143 -0
- package/dist/zero/next.js.map +1 -0
- package/docs/PIPELINE.md +519 -0
- package/docs/README.md +31 -0
- package/docs/adoption.md +296 -0
- package/docs/comparison.md +420 -0
- package/docs/configuration.md +326 -0
- package/docs/debug.md +318 -0
- package/docs/design-system.md +424 -0
- package/docs/dsl.md +673 -0
- package/docs/getting-started.md +217 -0
- package/docs/injector.md +528 -0
- package/docs/methodology.md +567 -0
- package/docs/runtime.md +485 -0
- package/docs/ssr.md +384 -0
- package/docs/styles.md +582 -0
- package/docs/tasty-static.md +520 -0
- package/package.json +215 -0
- package/tasty.config.ts +14 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { getNamedColorHex, getRgbValuesFromRgbaString, hexToRgb, hslToRgbValues, strToRgb } from "../utils/color-math.js";
|
|
2
|
+
import { Bucket } from "../parser/types.js";
|
|
3
|
+
import { StyleParser } from "../parser/parser.js";
|
|
4
|
+
import { okhslFunc, okhslPlugin } from "../plugins/okhsl-plugin.js";
|
|
5
|
+
import { CUSTOM_UNITS, DIRECTIONS, customFunc, filterMods, getGlobalFuncs, getGlobalParser, getGlobalPredefinedTokens, normalizeColorTokenValue, parseColor, parseStyle, resetGlobalPredefinedTokens, setGlobalPredefinedTokens, stringifyStyles } from "../utils/styles.js";
|
|
6
|
+
import { deprecationWarning, warn } from "../utils/warnings.js";
|
|
7
|
+
import { styleHandlers } from "../styles/predefined.js";
|
|
8
|
+
import { SheetManager } from "../injector/sheet-manager.js";
|
|
9
|
+
import { StyleInjector } from "../injector/injector.js";
|
|
10
|
+
import { createStateParserContext, getGlobalPredefinedStates, setGlobalPredefinedStates } from "../states/index.js";
|
|
11
|
+
import { parseStateKey } from "../pipeline/parseStateKey.js";
|
|
12
|
+
import { isSelector, renderStyles } from "../pipeline/index.js";
|
|
13
|
+
import { configure, getConfig, getGlobalCounterStyle, getGlobalFontFace, getGlobalKeyframes, getGlobalRecipes, hasGlobalKeyframes, hasGlobalRecipes, hasStylesGenerated, isConfigLocked, isTestEnvironment, resetConfig } from "../config.js";
|
|
14
|
+
import { CHUNK_NAMES, STYLE_TO_CHUNK, categorizeStyleKeys } from "../chunks/definitions.js";
|
|
15
|
+
import { BASE_STYLES, BLOCK_INNER_STYLES, BLOCK_OUTER_STYLES, BLOCK_STYLES, COLOR_STYLES, CONTAINER_STYLES, DIMENSION_STYLES, FLOW_STYLES, INNER_STYLES, OUTER_STYLES, POSITION_STYLES, TEXT_STYLES } from "../styles/list.js";
|
|
16
|
+
import { allocateClassName, cleanup, counterStyle, createInjector, destroy, fontFace, getCssText, getCssTextForNode, getIsTestEnvironment, getRawCSSText, inject, injectGlobal, injectRawCSS, injector, isPropertyDefined, keyframes, property, trackRef } from "../injector/index.js";
|
|
17
|
+
import { filterBaseProps } from "../utils/filter-base-props.js";
|
|
18
|
+
import { color } from "../utils/colors.js";
|
|
19
|
+
import { _modAttrs } from "../utils/mod-attrs.js";
|
|
20
|
+
import { dotize } from "../utils/dotize.js";
|
|
21
|
+
import { mergeStyles } from "../utils/merge-styles.js";
|
|
22
|
+
import { resolveRecipes } from "../utils/resolve-recipes.js";
|
|
23
|
+
import { processTokens, stringifyTokens } from "../utils/process-tokens.js";
|
|
24
|
+
import { generateTypographyTokens } from "../utils/typography.js";
|
|
25
|
+
import { tastyDebug } from "../debug.js";
|
|
26
|
+
export { BASE_STYLES, BLOCK_INNER_STYLES, BLOCK_OUTER_STYLES, BLOCK_STYLES, Bucket, CHUNK_NAMES, COLOR_STYLES, CONTAINER_STYLES, CUSTOM_UNITS, DIMENSION_STYLES, DIRECTIONS, FLOW_STYLES, INNER_STYLES, OUTER_STYLES, POSITION_STYLES, STYLE_TO_CHUNK, SheetManager, StyleInjector, StyleParser, TEXT_STYLES, allocateClassName, categorizeStyleKeys, cleanup, color, configure, counterStyle, createInjector, createStateParserContext, customFunc, deprecationWarning, destroy, dotize, filterBaseProps, filterMods, fontFace, generateTypographyTokens, getConfig, getCssText, getCssTextForNode, getGlobalCounterStyle, getGlobalFontFace, getGlobalFuncs, getGlobalKeyframes, getGlobalParser, getGlobalPredefinedStates, getGlobalPredefinedTokens, getGlobalRecipes, getIsTestEnvironment, getNamedColorHex, getRawCSSText, getRgbValuesFromRgbaString, hasGlobalKeyframes, hasGlobalRecipes, hasStylesGenerated, hexToRgb, hslToRgbValues, inject, injectGlobal, injectRawCSS, injector, isConfigLocked, isPropertyDefined, isSelector, isTestEnvironment, keyframes, mergeStyles, _modAttrs as modAttrs, normalizeColorTokenValue, okhslFunc, okhslPlugin, parseColor, parseStateKey, parseStyle, processTokens, property, renderStyles, resetConfig, resetGlobalPredefinedTokens, resolveRecipes, setGlobalPredefinedStates, setGlobalPredefinedTokens, strToRgb, stringifyStyles, stringifyTokens, styleHandlers, tastyDebug, trackRef, warn };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
//#region src/counter-style/index.ts
|
|
2
|
+
const COUNTER_STYLE_KEY = "@counterStyle";
|
|
3
|
+
/**
|
|
4
|
+
* Check if styles object has local @counterStyle definition.
|
|
5
|
+
*/
|
|
6
|
+
function hasLocalCounterStyle(styles) {
|
|
7
|
+
return COUNTER_STYLE_KEY in styles;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Extract local @counterStyle from styles object.
|
|
11
|
+
* Returns null if no local counter styles (fast path).
|
|
12
|
+
*/
|
|
13
|
+
function extractLocalCounterStyle(styles) {
|
|
14
|
+
const counterStyle = styles[COUNTER_STYLE_KEY];
|
|
15
|
+
if (!counterStyle || typeof counterStyle !== "object") return null;
|
|
16
|
+
return counterStyle;
|
|
17
|
+
}
|
|
18
|
+
const COUNTER_STYLE_DESCRIPTOR_MAP = {
|
|
19
|
+
system: "system",
|
|
20
|
+
symbols: "symbols",
|
|
21
|
+
additiveSymbols: "additive-symbols",
|
|
22
|
+
prefix: "prefix",
|
|
23
|
+
suffix: "suffix",
|
|
24
|
+
negative: "negative",
|
|
25
|
+
range: "range",
|
|
26
|
+
pad: "pad",
|
|
27
|
+
fallback: "fallback",
|
|
28
|
+
speakAs: "speak-as"
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Format the inner declarations of a @counter-style rule (no wrapper).
|
|
32
|
+
* Used by the injector which needs selector and declarations separately.
|
|
33
|
+
*/
|
|
34
|
+
function formatCounterStyleDeclarations(descriptors) {
|
|
35
|
+
const parts = [];
|
|
36
|
+
for (const [key, cssName] of Object.entries(COUNTER_STYLE_DESCRIPTOR_MAP)) {
|
|
37
|
+
const value = descriptors[key];
|
|
38
|
+
if (value !== void 0) parts.push(`${cssName}: ${value};`);
|
|
39
|
+
}
|
|
40
|
+
return parts.join(" ");
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Format a @counter-style rule as CSS.
|
|
44
|
+
*/
|
|
45
|
+
function formatCounterStyleRule(name, descriptors) {
|
|
46
|
+
return `@counter-style ${name} { ${formatCounterStyleDeclarations(descriptors)} }`;
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
49
|
+
export { extractLocalCounterStyle, formatCounterStyleDeclarations, formatCounterStyleRule, hasLocalCounterStyle };
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/counter-style/index.ts"],"sourcesContent":["/**\n * Counter Style Utilities\n *\n * Utilities for extracting and processing CSS @counter-style definitions in styles.\n * Counter-style rules are permanent once injected and do not need cleanup.\n */\n\nimport type { CounterStyleDescriptors } from '../injector/types';\nimport type { Styles } from '../styles/types';\n\n// ============================================================================\n// Constants\n// ============================================================================\n\nconst COUNTER_STYLE_KEY = '@counterStyle';\n\n// ============================================================================\n// Extraction Functions\n// ============================================================================\n\n/**\n * Check if styles object has local @counterStyle definition.\n */\nexport function hasLocalCounterStyle(styles: Styles): boolean {\n return COUNTER_STYLE_KEY in styles;\n}\n\n/**\n * Extract local @counterStyle from styles object.\n * Returns null if no local counter styles (fast path).\n */\nexport function extractLocalCounterStyle(\n styles: Styles,\n): Record<string, CounterStyleDescriptors> | null {\n const counterStyle = styles[COUNTER_STYLE_KEY];\n if (!counterStyle || typeof counterStyle !== 'object') {\n return null;\n }\n return counterStyle as Record<string, CounterStyleDescriptors>;\n}\n\n// ============================================================================\n// CSS Formatting\n// ============================================================================\n\nconst COUNTER_STYLE_DESCRIPTOR_MAP: Record<string, string> = {\n system: 'system',\n symbols: 'symbols',\n additiveSymbols: 'additive-symbols',\n prefix: 'prefix',\n suffix: 'suffix',\n negative: 'negative',\n range: 'range',\n pad: 'pad',\n fallback: 'fallback',\n speakAs: 'speak-as',\n};\n\n/**\n * Format the inner declarations of a @counter-style rule (no wrapper).\n * Used by the injector which needs selector and declarations separately.\n */\nexport function formatCounterStyleDeclarations(\n descriptors: CounterStyleDescriptors,\n): string {\n const parts: string[] = [];\n\n for (const [key, cssName] of Object.entries(COUNTER_STYLE_DESCRIPTOR_MAP)) {\n const value = descriptors[key as keyof CounterStyleDescriptors];\n if (value !== undefined) {\n parts.push(`${cssName}: ${value};`);\n }\n }\n\n return parts.join(' ');\n}\n\n/**\n * Format a @counter-style rule as CSS.\n */\nexport function formatCounterStyleRule(\n name: string,\n descriptors: CounterStyleDescriptors,\n): string {\n return `@counter-style ${name} { ${formatCounterStyleDeclarations(descriptors)} }`;\n}\n"],"mappings":";AAcA,MAAM,oBAAoB;;;;AAS1B,SAAgB,qBAAqB,QAAyB;AAC5D,QAAO,qBAAqB;;;;;;AAO9B,SAAgB,yBACd,QACgD;CAChD,MAAM,eAAe,OAAO;AAC5B,KAAI,CAAC,gBAAgB,OAAO,iBAAiB,SAC3C,QAAO;AAET,QAAO;;AAOT,MAAM,+BAAuD;CAC3D,QAAQ;CACR,SAAS;CACT,iBAAiB;CACjB,QAAQ;CACR,QAAQ;CACR,UAAU;CACV,OAAO;CACP,KAAK;CACL,UAAU;CACV,SAAS;CACV;;;;;AAMD,SAAgB,+BACd,aACQ;CACR,MAAM,QAAkB,EAAE;AAE1B,MAAK,MAAM,CAAC,KAAK,YAAY,OAAO,QAAQ,6BAA6B,EAAE;EACzE,MAAM,QAAQ,YAAY;AAC1B,MAAI,UAAU,KAAA,EACZ,OAAM,KAAK,GAAG,QAAQ,IAAI,MAAM,GAAG;;AAIvC,QAAO,MAAM,KAAK,IAAI;;;;;AAMxB,SAAgB,uBACd,MACA,aACQ;AACR,QAAO,kBAAkB,KAAK,KAAK,+BAA+B,YAAY,CAAC"}
|
package/dist/debug.d.ts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { CacheMetrics } from "./injector/types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/debug.d.ts
|
|
4
|
+
declare global {
|
|
5
|
+
interface Window {
|
|
6
|
+
tastyDebug?: typeof tastyDebug;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
type CSSTarget = 'all' | 'global' | 'active' | 'unused' | 'page' | string | string[] | Element;
|
|
10
|
+
interface DebugOptions {
|
|
11
|
+
root?: Document | ShadowRoot;
|
|
12
|
+
/** Suppress console logging and return data only (default: false) */
|
|
13
|
+
raw?: boolean;
|
|
14
|
+
}
|
|
15
|
+
interface CssOptions extends DebugOptions {
|
|
16
|
+
prettify?: boolean;
|
|
17
|
+
/** Read from stored source CSS (dev-mode only) instead of live CSSOM */
|
|
18
|
+
source?: boolean;
|
|
19
|
+
}
|
|
20
|
+
interface ChunkInfo {
|
|
21
|
+
className: string;
|
|
22
|
+
chunkName: string | null;
|
|
23
|
+
}
|
|
24
|
+
interface InspectResult {
|
|
25
|
+
element?: Element | null;
|
|
26
|
+
classes: string[];
|
|
27
|
+
chunks: ChunkInfo[];
|
|
28
|
+
css: string;
|
|
29
|
+
size: number;
|
|
30
|
+
rules: number;
|
|
31
|
+
}
|
|
32
|
+
interface CacheStatus {
|
|
33
|
+
classes: {
|
|
34
|
+
active: string[];
|
|
35
|
+
unused: string[];
|
|
36
|
+
all: string[];
|
|
37
|
+
};
|
|
38
|
+
metrics: CacheMetrics | null;
|
|
39
|
+
}
|
|
40
|
+
interface ChunkBreakdown {
|
|
41
|
+
byChunk: Record<string, {
|
|
42
|
+
classes: string[];
|
|
43
|
+
cssSize: number;
|
|
44
|
+
ruleCount: number;
|
|
45
|
+
}>;
|
|
46
|
+
totalChunkTypes: number;
|
|
47
|
+
totalClasses: number;
|
|
48
|
+
}
|
|
49
|
+
interface Summary {
|
|
50
|
+
activeClasses: string[];
|
|
51
|
+
unusedClasses: string[];
|
|
52
|
+
totalStyledClasses: string[];
|
|
53
|
+
activeCSSSize: number;
|
|
54
|
+
unusedCSSSize: number;
|
|
55
|
+
globalCSSSize: number;
|
|
56
|
+
rawCSSSize: number;
|
|
57
|
+
keyframesCSSSize: number;
|
|
58
|
+
propertyCSSSize: number;
|
|
59
|
+
totalCSSSize: number;
|
|
60
|
+
activeRuleCount: number;
|
|
61
|
+
unusedRuleCount: number;
|
|
62
|
+
globalRuleCount: number;
|
|
63
|
+
rawRuleCount: number;
|
|
64
|
+
keyframesRuleCount: number;
|
|
65
|
+
propertyRuleCount: number;
|
|
66
|
+
totalRuleCount: number;
|
|
67
|
+
metrics: CacheMetrics | null;
|
|
68
|
+
definedProperties: string[];
|
|
69
|
+
definedKeyframes: {
|
|
70
|
+
name: string;
|
|
71
|
+
refCount: number;
|
|
72
|
+
}[];
|
|
73
|
+
chunkBreakdown: ChunkBreakdown;
|
|
74
|
+
}
|
|
75
|
+
declare const tastyDebug: {
|
|
76
|
+
css(target: CSSTarget, opts?: CssOptions): string;
|
|
77
|
+
inspect(target: string | Element, opts?: DebugOptions): InspectResult;
|
|
78
|
+
summary(opts?: DebugOptions): Summary;
|
|
79
|
+
chunks(opts?: DebugOptions): ChunkBreakdown;
|
|
80
|
+
cache(opts?: DebugOptions): CacheStatus;
|
|
81
|
+
cleanup(opts?: {
|
|
82
|
+
root?: Document | ShadowRoot;
|
|
83
|
+
}): void;
|
|
84
|
+
help(): void;
|
|
85
|
+
install(): void;
|
|
86
|
+
};
|
|
87
|
+
//#endregion
|
|
88
|
+
export { tastyDebug };
|
|
89
|
+
//# sourceMappingURL=debug.d.ts.map
|
package/dist/debug.js
ADDED
|
@@ -0,0 +1,453 @@
|
|
|
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
|
+
//#region src/debug.ts
|
|
5
|
+
function fmtSize(bytes) {
|
|
6
|
+
return bytes > 1024 ? `${(bytes / 1024).toFixed(1)}KB` : `${bytes}B`;
|
|
7
|
+
}
|
|
8
|
+
function countRules(css) {
|
|
9
|
+
return (css.match(/\{[^}]*\}/g) || []).length;
|
|
10
|
+
}
|
|
11
|
+
function sortTastyClasses(classes) {
|
|
12
|
+
return Array.from(classes).sort((a, b) => parseInt(a.slice(1)) - parseInt(b.slice(1)));
|
|
13
|
+
}
|
|
14
|
+
function getRegistry(root = document) {
|
|
15
|
+
return injector.instance._sheetManager?.getRegistry(root);
|
|
16
|
+
}
|
|
17
|
+
function getUnusedClasses(root = document) {
|
|
18
|
+
const registry = getRegistry(root);
|
|
19
|
+
if (!registry) return [];
|
|
20
|
+
const result = [];
|
|
21
|
+
for (const [cls, rc] of registry.refCounts) if (rc === 0) result.push(cls);
|
|
22
|
+
return sortTastyClasses(result);
|
|
23
|
+
}
|
|
24
|
+
function findDomTastyClasses(root = document) {
|
|
25
|
+
const classes = /* @__PURE__ */ new Set();
|
|
26
|
+
(root.querySelectorAll?.("[class]") || []).forEach((el) => {
|
|
27
|
+
const attr = el.getAttribute("class");
|
|
28
|
+
if (attr) {
|
|
29
|
+
for (const cls of attr.split(/\s+/)) if (/^t\d+$/.test(cls)) classes.add(cls);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
return sortTastyClasses(classes);
|
|
33
|
+
}
|
|
34
|
+
function prettifyCSS(css) {
|
|
35
|
+
if (!css || !css.trim()) return "";
|
|
36
|
+
const out = [];
|
|
37
|
+
let depth = 0;
|
|
38
|
+
const indent = () => " ".repeat(depth);
|
|
39
|
+
let normalized = css.replace(/\s+/g, " ").trim();
|
|
40
|
+
normalized = normalized.replace(/\s*\{\s*/g, " { ");
|
|
41
|
+
normalized = normalized.replace(/\s*\}\s*/g, " } ");
|
|
42
|
+
normalized = normalized.replace(/;\s*/g, "; ");
|
|
43
|
+
const tokens = normalized.split(/\s+/);
|
|
44
|
+
let buf = "";
|
|
45
|
+
for (const t of tokens) if (t === "{") {
|
|
46
|
+
const header = buf.trim();
|
|
47
|
+
if (header) {
|
|
48
|
+
const parts = splitOutsideParens(header, ",");
|
|
49
|
+
if (parts.length > 1) out.push(parts.map((p, idx) => idx === 0 ? `${indent()}${p.trim()},` : `${indent()}${p.trim()}${idx < parts.length - 1 ? "," : ""}`).join("\n") + " {");
|
|
50
|
+
else out.push(`${indent()}${header} {`);
|
|
51
|
+
} else out.push(`${indent()}{`);
|
|
52
|
+
depth++;
|
|
53
|
+
buf = "";
|
|
54
|
+
} else if (t === "}") {
|
|
55
|
+
if (buf.trim()) {
|
|
56
|
+
for (const decl of buf.split(";").filter((s) => s.trim())) out.push(`${indent()}${decl.trim()};`);
|
|
57
|
+
buf = "";
|
|
58
|
+
}
|
|
59
|
+
depth = Math.max(0, depth - 1);
|
|
60
|
+
out.push(`${indent()}}`);
|
|
61
|
+
} else if (t.endsWith(";")) {
|
|
62
|
+
buf += ` ${t}`;
|
|
63
|
+
const full = buf.trim();
|
|
64
|
+
if (full) out.push(`${indent()}${full}`);
|
|
65
|
+
buf = "";
|
|
66
|
+
} else buf += ` ${t}`;
|
|
67
|
+
if (buf.trim()) out.push(buf.trim());
|
|
68
|
+
return out.filter((l) => l.trim()).join("\n").replace(/\n{3,}/g, "\n\n").trim();
|
|
69
|
+
}
|
|
70
|
+
/** Split `str` by `sep` only when not inside parentheses */
|
|
71
|
+
function splitOutsideParens(str, sep) {
|
|
72
|
+
const parts = [];
|
|
73
|
+
let depth = 0;
|
|
74
|
+
let start = 0;
|
|
75
|
+
for (let i = 0; i < str.length; i++) {
|
|
76
|
+
const ch = str[i];
|
|
77
|
+
if (ch === "(") depth++;
|
|
78
|
+
else if (ch === ")") depth--;
|
|
79
|
+
else if (depth === 0 && str.startsWith(sep, i)) {
|
|
80
|
+
parts.push(str.slice(start, i));
|
|
81
|
+
start = i + sep.length;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
parts.push(str.slice(start));
|
|
85
|
+
return parts;
|
|
86
|
+
}
|
|
87
|
+
function extractChunkName(cacheKey) {
|
|
88
|
+
for (const part of cacheKey.split("\0")) {
|
|
89
|
+
if (part.startsWith("[states:")) continue;
|
|
90
|
+
if (!part.includes(":") && part.length > 0) return part;
|
|
91
|
+
}
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
function getChunkForClass(className, root = document) {
|
|
95
|
+
const registry = getRegistry(root);
|
|
96
|
+
if (!registry) return null;
|
|
97
|
+
for (const [key, cn] of registry.cacheKeyToClassName) if (cn === className) return extractChunkName(key);
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
function buildChunkBreakdown(root = document) {
|
|
101
|
+
const registry = getRegistry(root);
|
|
102
|
+
if (!registry) return {
|
|
103
|
+
byChunk: {},
|
|
104
|
+
totalChunkTypes: 0,
|
|
105
|
+
totalClasses: 0
|
|
106
|
+
};
|
|
107
|
+
const byChunk = {};
|
|
108
|
+
for (const [cacheKey, className] of registry.cacheKeyToClassName) {
|
|
109
|
+
const chunk = extractChunkName(cacheKey) || "unknown";
|
|
110
|
+
if (!byChunk[chunk]) byChunk[chunk] = {
|
|
111
|
+
classes: [],
|
|
112
|
+
cssSize: 0,
|
|
113
|
+
ruleCount: 0
|
|
114
|
+
};
|
|
115
|
+
byChunk[chunk].classes.push(className);
|
|
116
|
+
const css = injector.instance.getCssTextForClasses([className], { root });
|
|
117
|
+
byChunk[chunk].cssSize += css.length;
|
|
118
|
+
byChunk[chunk].ruleCount += countRules(css);
|
|
119
|
+
}
|
|
120
|
+
for (const entry of Object.values(byChunk)) entry.classes = sortTastyClasses(entry.classes);
|
|
121
|
+
const totalClasses = Object.values(byChunk).reduce((s, e) => s + e.classes.length, 0);
|
|
122
|
+
return {
|
|
123
|
+
byChunk,
|
|
124
|
+
totalChunkTypes: Object.keys(byChunk).length,
|
|
125
|
+
totalClasses
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
function getGlobalTypeCSS(type, root = document) {
|
|
129
|
+
const registry = getRegistry(root);
|
|
130
|
+
if (!registry) return {
|
|
131
|
+
css: "",
|
|
132
|
+
ruleCount: 0,
|
|
133
|
+
size: 0
|
|
134
|
+
};
|
|
135
|
+
const chunks = [];
|
|
136
|
+
let rc = 0;
|
|
137
|
+
if (type === "keyframes") for (const [, entry] of registry.keyframesCache) {
|
|
138
|
+
const info = entry.info;
|
|
139
|
+
const ss = registry.sheets[info.sheetIndex]?.sheet?.sheet;
|
|
140
|
+
if (ss && info.ruleIndex < ss.cssRules.length) {
|
|
141
|
+
const rule = ss.cssRules[info.ruleIndex];
|
|
142
|
+
if (rule) {
|
|
143
|
+
chunks.push(rule.cssText);
|
|
144
|
+
rc++;
|
|
145
|
+
}
|
|
146
|
+
} else if (info.cssText) {
|
|
147
|
+
chunks.push(info.cssText);
|
|
148
|
+
rc++;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
const prefix = type === "global" ? "global:" : type === "raw" ? "raw:" : "property:";
|
|
153
|
+
for (const [key, ri] of registry.globalRules) {
|
|
154
|
+
if (!key.startsWith(prefix)) continue;
|
|
155
|
+
const ss = registry.sheets[ri.sheetIndex]?.sheet?.sheet;
|
|
156
|
+
if (ss) {
|
|
157
|
+
const start = Math.max(0, ri.ruleIndex);
|
|
158
|
+
const end = Math.min(ss.cssRules.length - 1, ri.endRuleIndex ?? ri.ruleIndex);
|
|
159
|
+
if (start >= 0 && end >= start && start < ss.cssRules.length) for (let i = start; i <= end; i++) {
|
|
160
|
+
const rule = ss.cssRules[i];
|
|
161
|
+
if (rule) {
|
|
162
|
+
chunks.push(rule.cssText);
|
|
163
|
+
rc++;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
} else if (ri.cssText?.length) {
|
|
167
|
+
chunks.push(...ri.cssText);
|
|
168
|
+
rc += ri.cssText.length;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
const raw = chunks.join("\n");
|
|
173
|
+
return {
|
|
174
|
+
css: prettifyCSS(raw),
|
|
175
|
+
ruleCount: rc,
|
|
176
|
+
size: raw.length
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
function getSourceCssForClasses(classNames, root = document) {
|
|
180
|
+
const registry = getRegistry(root);
|
|
181
|
+
if (!registry) return null;
|
|
182
|
+
const chunks = [];
|
|
183
|
+
let found = false;
|
|
184
|
+
for (const cls of classNames) {
|
|
185
|
+
const info = registry.rules.get(cls);
|
|
186
|
+
if (info?.cssText?.length) {
|
|
187
|
+
chunks.push(...info.cssText);
|
|
188
|
+
found = true;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return found ? chunks.join("\n") : null;
|
|
192
|
+
}
|
|
193
|
+
function getDefs(root = document) {
|
|
194
|
+
const registry = getRegistry(root);
|
|
195
|
+
let properties = [];
|
|
196
|
+
if (registry?.injectedProperties) properties = Array.from(registry.injectedProperties.keys()).sort();
|
|
197
|
+
const keyframes = [];
|
|
198
|
+
if (registry) {
|
|
199
|
+
for (const entry of registry.keyframesCache.values()) keyframes.push({
|
|
200
|
+
name: entry.name,
|
|
201
|
+
refCount: entry.refCount
|
|
202
|
+
});
|
|
203
|
+
keyframes.sort((a, b) => a.name.localeCompare(b.name));
|
|
204
|
+
}
|
|
205
|
+
return {
|
|
206
|
+
properties,
|
|
207
|
+
keyframes
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
const CHUNK_ORDER = [
|
|
211
|
+
CHUNK_NAMES.COMBINED,
|
|
212
|
+
CHUNK_NAMES.APPEARANCE,
|
|
213
|
+
CHUNK_NAMES.FONT,
|
|
214
|
+
CHUNK_NAMES.DIMENSION,
|
|
215
|
+
CHUNK_NAMES.DISPLAY,
|
|
216
|
+
CHUNK_NAMES.LAYOUT,
|
|
217
|
+
CHUNK_NAMES.POSITION,
|
|
218
|
+
CHUNK_NAMES.MISC,
|
|
219
|
+
CHUNK_NAMES.SUBCOMPONENTS
|
|
220
|
+
];
|
|
221
|
+
const tastyDebug = {
|
|
222
|
+
css(target, opts) {
|
|
223
|
+
const { root = document, prettify = true, raw = false, source = false } = opts || {};
|
|
224
|
+
let css = "";
|
|
225
|
+
if (source && typeof target === "string" && /^t\d+$/.test(target)) {
|
|
226
|
+
const src = getSourceCssForClasses([target], root);
|
|
227
|
+
if (src) css = src;
|
|
228
|
+
else {
|
|
229
|
+
if (!raw) console.warn("tastyDebug: source CSS not available (requires dev mode or TASTY_DEBUG=true). Falling back to live CSSOM.");
|
|
230
|
+
css = injector.instance.getCssTextForClasses([target], { root });
|
|
231
|
+
}
|
|
232
|
+
} else if (source && Array.isArray(target)) {
|
|
233
|
+
const src = getSourceCssForClasses(target, root);
|
|
234
|
+
if (src) css = src;
|
|
235
|
+
else {
|
|
236
|
+
if (!raw) console.warn("tastyDebug: source CSS not available. Falling back to live CSSOM.");
|
|
237
|
+
css = injector.instance.getCssTextForClasses(target, { root });
|
|
238
|
+
}
|
|
239
|
+
} else if (typeof target === "string") if (target === "all") css = injector.instance.getCssText({ root });
|
|
240
|
+
else if (target === "global") {
|
|
241
|
+
css = getGlobalTypeCSS("global", root).css;
|
|
242
|
+
return css;
|
|
243
|
+
} else if (target === "active") {
|
|
244
|
+
const active = findDomTastyClasses(root);
|
|
245
|
+
css = injector.instance.getCssTextForClasses(active, { root });
|
|
246
|
+
} else if (target === "unused") {
|
|
247
|
+
const unused = getUnusedClasses(root);
|
|
248
|
+
css = injector.instance.getCssTextForClasses(unused, { root });
|
|
249
|
+
} else if (target === "page") css = getPageCSS(root);
|
|
250
|
+
else if (/^t\d+$/.test(target)) css = injector.instance.getCssTextForClasses([target], { root });
|
|
251
|
+
else {
|
|
252
|
+
const el = root.querySelector?.(target);
|
|
253
|
+
if (el) css = getCssTextForNode(el, { root });
|
|
254
|
+
}
|
|
255
|
+
else if (Array.isArray(target)) css = injector.instance.getCssTextForClasses(target, { root });
|
|
256
|
+
else if (target instanceof Element) css = getCssTextForNode(target, { root });
|
|
257
|
+
const result = prettify ? prettifyCSS(css) : css;
|
|
258
|
+
if (!raw) {
|
|
259
|
+
const label = Array.isArray(target) ? `[${target.join(", ")}]` : target;
|
|
260
|
+
const rc = countRules(css);
|
|
261
|
+
console.group(`CSS for ${label} (${rc} rules, ${fmtSize(css.length)})`);
|
|
262
|
+
console.log(result || "(empty)");
|
|
263
|
+
console.groupEnd();
|
|
264
|
+
}
|
|
265
|
+
return result;
|
|
266
|
+
},
|
|
267
|
+
inspect(target, opts) {
|
|
268
|
+
const { root = document, raw = false } = opts || {};
|
|
269
|
+
const element = typeof target === "string" ? root.querySelector?.(target) : target;
|
|
270
|
+
if (!element) {
|
|
271
|
+
const empty = {
|
|
272
|
+
element: null,
|
|
273
|
+
classes: [],
|
|
274
|
+
chunks: [],
|
|
275
|
+
css: "",
|
|
276
|
+
size: 0,
|
|
277
|
+
rules: 0
|
|
278
|
+
};
|
|
279
|
+
if (!raw) console.warn("tastyDebug.inspect: element not found");
|
|
280
|
+
return empty;
|
|
281
|
+
}
|
|
282
|
+
const tastyClasses = (element.getAttribute("class") || "").split(/\s+/).filter((cls) => /^t\d+$/.test(cls));
|
|
283
|
+
const chunks = tastyClasses.map((className) => ({
|
|
284
|
+
className,
|
|
285
|
+
chunkName: getChunkForClass(className, root)
|
|
286
|
+
}));
|
|
287
|
+
const css = getCssTextForNode(element, { root });
|
|
288
|
+
const rules = countRules(css);
|
|
289
|
+
const result = {
|
|
290
|
+
element,
|
|
291
|
+
classes: tastyClasses,
|
|
292
|
+
chunks,
|
|
293
|
+
css: prettifyCSS(css),
|
|
294
|
+
size: css.length,
|
|
295
|
+
rules
|
|
296
|
+
};
|
|
297
|
+
if (!raw) {
|
|
298
|
+
const tag = element.tagName.toLowerCase();
|
|
299
|
+
const id = element.id ? `#${element.id}` : "";
|
|
300
|
+
console.group(`inspect ${tag}${id} — ${tastyClasses.length} classes, ${rules} rules, ${fmtSize(css.length)}`);
|
|
301
|
+
if (chunks.length) console.log("Chunks:", chunks.map((c) => `${c.className}→${c.chunkName || "?"}`).join(", "));
|
|
302
|
+
console.groupCollapsed("CSS");
|
|
303
|
+
console.log(result.css || "(empty)");
|
|
304
|
+
console.groupEnd();
|
|
305
|
+
console.groupEnd();
|
|
306
|
+
}
|
|
307
|
+
return result;
|
|
308
|
+
},
|
|
309
|
+
summary(opts) {
|
|
310
|
+
const { root = document, raw = false } = opts || {};
|
|
311
|
+
const activeClasses = findDomTastyClasses(root);
|
|
312
|
+
const unusedClasses = getUnusedClasses(root);
|
|
313
|
+
const totalStyledClasses = [...activeClasses, ...unusedClasses];
|
|
314
|
+
const activeCSS = injector.instance.getCssTextForClasses(activeClasses, { root });
|
|
315
|
+
const unusedCSS = injector.instance.getCssTextForClasses(unusedClasses, { root });
|
|
316
|
+
const allCSS = injector.instance.getCssText({ root });
|
|
317
|
+
const activeRuleCount = countRules(activeCSS);
|
|
318
|
+
const unusedRuleCount = countRules(unusedCSS);
|
|
319
|
+
const globalData = getGlobalTypeCSS("global", root);
|
|
320
|
+
const rawData = getGlobalTypeCSS("raw", root);
|
|
321
|
+
const kfData = getGlobalTypeCSS("keyframes", root);
|
|
322
|
+
const propData = getGlobalTypeCSS("property", root);
|
|
323
|
+
const totalRuleCount = activeRuleCount + unusedRuleCount + globalData.ruleCount + rawData.ruleCount + kfData.ruleCount + propData.ruleCount;
|
|
324
|
+
const metrics = injector.instance.getMetrics({ root });
|
|
325
|
+
const defs = getDefs(root);
|
|
326
|
+
const chunkBreakdown = buildChunkBreakdown(root);
|
|
327
|
+
const summary = {
|
|
328
|
+
activeClasses,
|
|
329
|
+
unusedClasses,
|
|
330
|
+
totalStyledClasses,
|
|
331
|
+
activeCSSSize: activeCSS.length,
|
|
332
|
+
unusedCSSSize: unusedCSS.length,
|
|
333
|
+
globalCSSSize: globalData.size,
|
|
334
|
+
rawCSSSize: rawData.size,
|
|
335
|
+
keyframesCSSSize: kfData.size,
|
|
336
|
+
propertyCSSSize: propData.size,
|
|
337
|
+
totalCSSSize: allCSS.length,
|
|
338
|
+
activeRuleCount,
|
|
339
|
+
unusedRuleCount,
|
|
340
|
+
globalRuleCount: globalData.ruleCount,
|
|
341
|
+
rawRuleCount: rawData.ruleCount,
|
|
342
|
+
keyframesRuleCount: kfData.ruleCount,
|
|
343
|
+
propertyRuleCount: propData.ruleCount,
|
|
344
|
+
totalRuleCount,
|
|
345
|
+
metrics,
|
|
346
|
+
definedProperties: defs.properties,
|
|
347
|
+
definedKeyframes: defs.keyframes,
|
|
348
|
+
chunkBreakdown
|
|
349
|
+
};
|
|
350
|
+
if (!raw) {
|
|
351
|
+
console.group("Tasty Summary");
|
|
352
|
+
console.log(`Active: ${activeClasses.length} classes, ${activeRuleCount} rules, ${fmtSize(activeCSS.length)}`);
|
|
353
|
+
console.log(`Unused: ${unusedClasses.length} classes, ${unusedRuleCount} rules, ${fmtSize(unusedCSS.length)}`);
|
|
354
|
+
console.log(`Global: ${globalData.ruleCount} rules, ${fmtSize(globalData.size)}`);
|
|
355
|
+
if (rawData.ruleCount) console.log(`Raw: ${rawData.ruleCount} rules, ${fmtSize(rawData.size)}`);
|
|
356
|
+
if (kfData.ruleCount) console.log(`Keyframes: ${kfData.ruleCount} rules, ${fmtSize(kfData.size)}`);
|
|
357
|
+
if (propData.ruleCount) console.log(`@property: ${propData.ruleCount} rules, ${fmtSize(propData.size)}`);
|
|
358
|
+
console.log(`Total: ${totalStyledClasses.length} classes, ${totalRuleCount} rules, ${fmtSize(allCSS.length)}`);
|
|
359
|
+
if (metrics) {
|
|
360
|
+
const total = metrics.hits + metrics.misses;
|
|
361
|
+
const rate = total > 0 ? (metrics.hits / total * 100).toFixed(1) : 0;
|
|
362
|
+
console.log(`Cache: ${rate}% hit rate (${total} lookups)`);
|
|
363
|
+
}
|
|
364
|
+
if (chunkBreakdown.totalChunkTypes > 0) {
|
|
365
|
+
console.groupCollapsed(`Chunks (${chunkBreakdown.totalChunkTypes} types, ${chunkBreakdown.totalClasses} classes)`);
|
|
366
|
+
for (const name of CHUNK_ORDER) {
|
|
367
|
+
const d = chunkBreakdown.byChunk[name];
|
|
368
|
+
if (d) console.log(` ${name}: ${d.classes.length} cls, ${d.ruleCount} rules, ${fmtSize(d.cssSize)}`);
|
|
369
|
+
}
|
|
370
|
+
for (const [name, d] of Object.entries(chunkBreakdown.byChunk)) if (!CHUNK_ORDER.includes(name)) console.log(` ${name}: ${d.classes.length} cls, ${d.ruleCount} rules, ${fmtSize(d.cssSize)}`);
|
|
371
|
+
console.groupEnd();
|
|
372
|
+
}
|
|
373
|
+
if (defs.properties.length || defs.keyframes.length) console.log(`Defs: ${defs.properties.length} @property, ${defs.keyframes.length} @keyframes`);
|
|
374
|
+
console.groupEnd();
|
|
375
|
+
}
|
|
376
|
+
return summary;
|
|
377
|
+
},
|
|
378
|
+
chunks(opts) {
|
|
379
|
+
const { root = document, raw = false } = opts || {};
|
|
380
|
+
const breakdown = buildChunkBreakdown(root);
|
|
381
|
+
if (!raw) {
|
|
382
|
+
console.group(`Chunks (${breakdown.totalChunkTypes} types, ${breakdown.totalClasses} classes)`);
|
|
383
|
+
for (const name of CHUNK_ORDER) {
|
|
384
|
+
const d = breakdown.byChunk[name];
|
|
385
|
+
if (d) console.log(` ${name}: ${d.classes.length} cls, ${d.ruleCount} rules, ${fmtSize(d.cssSize)}`);
|
|
386
|
+
}
|
|
387
|
+
for (const [name, d] of Object.entries(breakdown.byChunk)) if (!CHUNK_ORDER.includes(name)) console.log(` ${name}: ${d.classes.length} cls, ${d.ruleCount} rules, ${fmtSize(d.cssSize)}`);
|
|
388
|
+
console.groupEnd();
|
|
389
|
+
}
|
|
390
|
+
return breakdown;
|
|
391
|
+
},
|
|
392
|
+
cache(opts) {
|
|
393
|
+
const { root = document, raw = false } = opts || {};
|
|
394
|
+
const active = findDomTastyClasses(root);
|
|
395
|
+
const unused = getUnusedClasses(root);
|
|
396
|
+
const metrics = injector.instance.getMetrics({ root });
|
|
397
|
+
const status = {
|
|
398
|
+
classes: {
|
|
399
|
+
active,
|
|
400
|
+
unused,
|
|
401
|
+
all: [...active, ...unused]
|
|
402
|
+
},
|
|
403
|
+
metrics
|
|
404
|
+
};
|
|
405
|
+
if (!raw) {
|
|
406
|
+
console.group("Cache");
|
|
407
|
+
console.log(`Active: ${active.length}, Unused: ${unused.length}`);
|
|
408
|
+
if (metrics) {
|
|
409
|
+
const total = metrics.hits + metrics.misses;
|
|
410
|
+
const rate = total > 0 ? (metrics.hits / total * 100).toFixed(1) : 0;
|
|
411
|
+
console.log(`Hits: ${metrics.hits}, Misses: ${metrics.misses}, Rate: ${rate}%`);
|
|
412
|
+
}
|
|
413
|
+
console.groupEnd();
|
|
414
|
+
}
|
|
415
|
+
return status;
|
|
416
|
+
},
|
|
417
|
+
cleanup(opts) {
|
|
418
|
+
injector.instance.cleanup(opts?.root);
|
|
419
|
+
},
|
|
420
|
+
help() {
|
|
421
|
+
console.log(`tastyDebug API:
|
|
422
|
+
.summary() — overview (classes, rules, sizes)
|
|
423
|
+
.css("active") — CSS for classes in DOM
|
|
424
|
+
.css("t42") — CSS for a specific class
|
|
425
|
+
.css("t42",{source:1})— original CSS before browser parsing (dev only)
|
|
426
|
+
.css(".selector") — CSS for a DOM element
|
|
427
|
+
.inspect(".selector") — element details (classes, chunks, rules)
|
|
428
|
+
.chunks() — style chunk breakdown
|
|
429
|
+
.cache() — cache status and metrics
|
|
430
|
+
.cleanup() — force unused style cleanup
|
|
431
|
+
Options: { raw: true } suppresses logging, { root: shadowRoot } targets Shadow DOM`);
|
|
432
|
+
},
|
|
433
|
+
install() {
|
|
434
|
+
if (typeof window !== "undefined" && window.tastyDebug !== tastyDebug) {
|
|
435
|
+
window.tastyDebug = tastyDebug;
|
|
436
|
+
console.log("tastyDebug installed. Run tastyDebug.help() for commands.");
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
};
|
|
440
|
+
function getPageCSS(root = document) {
|
|
441
|
+
const chunks = [];
|
|
442
|
+
try {
|
|
443
|
+
if ("styleSheets" in root) for (const sheet of Array.from(root.styleSheets)) try {
|
|
444
|
+
if (sheet.cssRules) chunks.push(Array.from(sheet.cssRules).map((r) => r.cssText).join("\n"));
|
|
445
|
+
} catch {}
|
|
446
|
+
} catch {}
|
|
447
|
+
return chunks.join("\n");
|
|
448
|
+
}
|
|
449
|
+
if (typeof window !== "undefined" && isDevEnv()) tastyDebug.install();
|
|
450
|
+
//#endregion
|
|
451
|
+
export { tastyDebug };
|
|
452
|
+
|
|
453
|
+
//# sourceMappingURL=debug.js.map
|