@geastack/geatsc-plugin-gea 0.1.6 → 0.1.8

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.
@@ -0,0 +1,5 @@
1
+ import type ts from 'typescript';
2
+ export declare function colorAlphaObserver(features: Set<string>, resolve?: (node: ts.Expression) => string[] | undefined): {
3
+ property(name: string | undefined, value: string | undefined, expression?: ts.Expression): void;
4
+ finish(): void;
5
+ };
@@ -0,0 +1,76 @@
1
+ // These two fields start at 255. Only a complete opaque-colour proof removes
2
+ // them; background alpha has a transparent default and remains independently live.
3
+ export function colorAlphaObserver(features, resolve) {
4
+ const variables = new Map();
5
+ const text = [], border = [];
6
+ const values = (value, expression) => value !== undefined ? [value] : expression ? resolve?.(expression) : undefined;
7
+ const strip = (value) => value.trim().replace(/\s*!important\s*$/i, '').trim();
8
+ const wide = /^(?:initial|inherit|unset|revert|revert-layer)$/i;
9
+ const opaqueHex = /^(?:#[\da-f]{3}|#[\da-f]{6}|#[\da-f]{3}f|#[\da-f]{6}ff)$/i;
10
+ const opaque = (value, allowCurrent, seen = new Set()) => {
11
+ value = strip(value);
12
+ if (wide.test(value) || opaqueHex.test(value))
13
+ return true;
14
+ if (/^currentcolor$/i.test(value))
15
+ return allowCurrent;
16
+ const variable = value.match(/^var\(\s*(--[\w-]+)\s*(?:,\s*([^()]+))?\)$/i);
17
+ if (!variable || seen.has(variable[1]))
18
+ return false;
19
+ seen.add(variable[1]);
20
+ const definitions = variables.get(variable[1]);
21
+ if (!definitions?.length)
22
+ return variable[2] !== undefined && opaque(variable[2], allowCurrent, new Set(seen));
23
+ return definitions.every(group => group !== undefined && group.every(item => opaque(item, allowCurrent, new Set(seen)))) &&
24
+ (variable[2] === undefined || opaque(variable[2], allowCurrent, new Set(seen)));
25
+ };
26
+ const all = (groups, allowCurrent) => groups.every(group => group !== undefined && group.every(value => opaque(value, allowCurrent)));
27
+ return {
28
+ property(name, value, expression) {
29
+ if (!name) {
30
+ features.add('css-text-alpha');
31
+ features.add('css-border-alpha');
32
+ return;
33
+ }
34
+ const candidates = values(value, expression);
35
+ if (name.startsWith('--')) {
36
+ const definitions = variables.get(name) ?? [];
37
+ definitions.push(candidates);
38
+ variables.set(name, definitions);
39
+ return;
40
+ }
41
+ name = name.replace(/[A-Z]/g, c => `-${c.toLowerCase()}`).toLowerCase();
42
+ if (name === 'color')
43
+ text.push(candidates);
44
+ if (/^border(?:-(?:top|right|bottom|left|block|inline)(?:-start|-end)?)?-color$/.test(name)) {
45
+ border.push(candidates?.flatMap(value => /var\(/i.test(value) ? [value] : strip(value).split(/\s+/)));
46
+ }
47
+ if (/^border(?:-(?:top|right|bottom|left|block|inline)(?:-start|-end)?)?$/.test(name)) {
48
+ border.push(candidates?.flatMap(value => {
49
+ value = strip(value);
50
+ if (wide.test(value))
51
+ return [value];
52
+ // A fully known simple shorthand can omit its width/style tokens.
53
+ // Functions/variables expanding an entire shorthand remain opaque.
54
+ if (/[()]/.test(value))
55
+ return [value];
56
+ const colors = value.split(/\s+/).filter(part => !/^(?:none|hidden|solid|dotted|dashed|double|groove|ridge|inset|outset|thin|medium|thick|[+]?(?:\d+(?:\.\d*)?|\.\d+)(?:px|em|rem|vw|vh|vmin|vmax|%)?)$/i.test(part));
57
+ return colors.length ? colors : ['currentcolor'];
58
+ }));
59
+ }
60
+ // Native-style spellings and arbitrary CSS-wide mutation are conservative.
61
+ if (name === 'color-alpha')
62
+ features.add('css-text-alpha');
63
+ if (name === 'border-alpha' || name === 'all')
64
+ features.add('css-border-alpha');
65
+ if (name === 'all')
66
+ features.add('css-text-alpha');
67
+ },
68
+ finish() {
69
+ const textOpaque = !features.has('css-text-alpha') && all(text, true);
70
+ if (!textOpaque)
71
+ features.add('css-text-alpha');
72
+ if (!all(border, textOpaque))
73
+ features.add('css-border-alpha');
74
+ },
75
+ };
76
+ }
@@ -0,0 +1 @@
1
+ export declare function analyzeClassCapacity(files: Map<string, string>, opaque: boolean): number | undefined;
@@ -0,0 +1,157 @@
1
+ import ts from 'typescript';
2
+ import path from 'node:path';
3
+ const atom = { count: 1, start: true, end: true, empty: false };
4
+ const space = /[\x00-\x20]/;
5
+ function literal(value) {
6
+ const parts = value.split(/[\x00-\x20]+/).filter(Boolean);
7
+ return { count: Math.min(4, parts.length), start: !!value && !space.test(value[0]), end: !!value && !space.test(value.at(-1)), empty: !value };
8
+ }
9
+ function unique(shapes) {
10
+ return [...new Map(shapes.map(s => [`${s.count}/${s.start}/${s.end}/${s.empty}`, s])).values()];
11
+ }
12
+ function join(left, right) {
13
+ return unique(left.flatMap(a => right.map(b => ({
14
+ count: Math.min(4, a.count + b.count - (a.end && b.start ? 1 : 0)),
15
+ start: a.empty ? b.start : a.start,
16
+ end: b.empty ? a.end : b.end,
17
+ empty: a.empty && b.empty,
18
+ }))));
19
+ }
20
+ // A positive proof selects inline capacity; no proof keeps the existing four
21
+ // slots. Overflow remains supported, so capacity never truncates class names.
22
+ export function analyzeClassCapacity(files, opaque) {
23
+ if (opaque)
24
+ return undefined;
25
+ const sources = new Map([...files].filter(([file]) => !/\.css$/i.test(file)).map(([file, text]) => [file, ts.createSourceFile(file, text, ts.ScriptTarget.Latest, true, /\.[jt]sx$/i.test(file) ? ts.ScriptKind.TSX : ts.ScriptKind.TS)]));
26
+ let checker;
27
+ const getChecker = () => {
28
+ if (checker)
29
+ return checker;
30
+ // Use the already-discovered graph only. External packages cannot provide
31
+ // a numeric proof here, and this pass neither loads libraries nor emits.
32
+ const host = {
33
+ getSourceFile: file => sources.get(path.resolve(file)),
34
+ getDefaultLibFileName: () => '', writeFile: () => { },
35
+ getCurrentDirectory: () => '/', getDirectories: () => [],
36
+ getCanonicalFileName: file => file, useCaseSensitiveFileNames: () => true,
37
+ getNewLine: () => '\n', fileExists: file => sources.has(path.resolve(file)),
38
+ readFile: file => files.get(path.resolve(file)),
39
+ resolveModuleNames: (names, containingFile) => names.map(name => {
40
+ if (!name.startsWith('.'))
41
+ return undefined;
42
+ const base = path.resolve(path.dirname(containingFile), name);
43
+ const candidates = [base, ...['.ts', '.tsx', '.js', '.jsx', '.mjs'].map(ext => base + ext),
44
+ ...['index.ts', 'index.tsx', 'index.js', 'index.jsx'].map(file => path.join(base, file))];
45
+ const resolved = candidates.find(file => sources.has(file));
46
+ if (!resolved)
47
+ return undefined;
48
+ return { resolvedFileName: resolved, extension: /\.tsx$/i.test(resolved) ? ts.Extension.Tsx : /\.jsx$/i.test(resolved) ? ts.Extension.Jsx : /\.[cm]?js$/i.test(resolved) ? ts.Extension.Js : ts.Extension.Ts };
49
+ }),
50
+ };
51
+ checker = ts.createProgram([...sources.keys()], { noLib: true, target: ts.ScriptTarget.ESNext, module: ts.ModuleKind.ESNext, moduleResolution: ts.ModuleResolutionKind.Bundler, jsx: ts.JsxEmit.Preserve, strict: true, allowJs: true }, host).getTypeChecker();
52
+ return checker;
53
+ };
54
+ const scalarShapes = (node) => {
55
+ if (ts.isParenthesizedExpression(node))
56
+ return scalarShapes(node.expression);
57
+ // Assertions are not a source proof. Unknown values must not acquire a
58
+ // smaller class capacity merely because a caller asserted a type.
59
+ if (ts.isAsExpression(node) || ts.isTypeAssertionExpression(node) || ts.isNonNullExpression(node))
60
+ return undefined;
61
+ if (ts.isStringLiteralLike(node))
62
+ return [literal(node.text)];
63
+ if (ts.isNumericLiteral(node) || ts.isBigIntLiteral(node))
64
+ return [atom];
65
+ if (ts.isConditionalExpression(node)) {
66
+ const a = scalarShapes(node.whenTrue), b = scalarShapes(node.whenFalse);
67
+ return a && b ? unique([...a, ...b]) : undefined;
68
+ }
69
+ if (ts.isTemplateExpression(node)) {
70
+ let result = [literal(node.head.text)];
71
+ for (const part of node.templateSpans) {
72
+ const value = scalarShapes(part.expression);
73
+ if (!value)
74
+ return undefined;
75
+ result = join(join(result, value), [literal(part.literal.text)]);
76
+ }
77
+ return result;
78
+ }
79
+ if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.PlusToken) {
80
+ const a = scalarShapes(node.left), b = scalarShapes(node.right);
81
+ return a && b ? join(a, b) : undefined;
82
+ }
83
+ const type = getChecker().getTypeAtLocation(node);
84
+ const parts = type.isUnion() ? type.types : [type];
85
+ if (parts.every(t => !!(t.flags & (ts.TypeFlags.NumberLike | ts.TypeFlags.BigIntLike | ts.TypeFlags.BooleanLike))))
86
+ return [atom];
87
+ return undefined;
88
+ };
89
+ const classCount = (node) => {
90
+ if (ts.isParenthesizedExpression(node))
91
+ return classCount(node.expression);
92
+ if (ts.isObjectLiteralExpression(node)) {
93
+ let count = 0;
94
+ for (const property of node.properties) {
95
+ if (!ts.isPropertyAssignment(property) && !ts.isShorthandPropertyAssignment(property))
96
+ return undefined;
97
+ if (ts.isComputedPropertyName(property.name))
98
+ return undefined;
99
+ const name = property.name;
100
+ if (!ts.isIdentifier(name) && !ts.isStringLiteralLike(name) && !ts.isNumericLiteral(name))
101
+ return undefined;
102
+ count += literal(name.text).count;
103
+ }
104
+ return count;
105
+ }
106
+ if (ts.isConditionalExpression(node)) {
107
+ const a = classCount(node.whenTrue), b = classCount(node.whenFalse);
108
+ return a !== undefined && b !== undefined ? Math.max(a, b) : undefined;
109
+ }
110
+ const shapes = scalarShapes(node);
111
+ return shapes && Math.max(...shapes.map(s => s.count));
112
+ };
113
+ let maximum = 0, unknown = false;
114
+ const dangerous = /^(?:className|classList|attributes|getAttributeNode|setAttributeNode|setAttribute|setAttributeNS|setClassName|innerHTML|outerHTML|insertAdjacentHTML|DOMParser|eval|Function|Proxy|Reflect|Object|VirtualList|VirtualListElement|createList|createVirtualList)$/;
115
+ const visit = (node) => {
116
+ if (unknown)
117
+ return;
118
+ // Casts can hide arbitrary class strings through aliases in another file.
119
+ if (ts.isAsExpression(node) || ts.isTypeAssertionExpression(node) || ts.isNonNullExpression(node))
120
+ unknown = true;
121
+ if (ts.isIdentifier(node) && dangerous.test(node.text) && !(ts.isJsxAttribute(node.parent) && node.parent.name === node))
122
+ unknown = true;
123
+ if (ts.isStringLiteralLike(node) && (dangerous.test(node.text) || /^(?:class|list|virtual-list)$/.test(node.text)) && !ts.isJsxAttribute(node.parent))
124
+ unknown = true;
125
+ if (ts.isJsxSpreadAttribute(node))
126
+ unknown = true;
127
+ if (ts.isJsxAttribute(node) && (ts.isJsxNamespacedName(node.name) || node.name.getText() === 'classList'))
128
+ unknown = true;
129
+ if (ts.isJsxOpeningElement(node) || ts.isJsxSelfClosingElement(node)) {
130
+ if (/^(?:list|virtual-list|input|textarea|select)$/i.test(node.tagName.getText()))
131
+ unknown = true;
132
+ }
133
+ if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === 'Object' && /^(?:assign|defineProperty|defineProperties|setPrototypeOf)$/.test(node.name.text))
134
+ unknown = true;
135
+ // A computed DOM member may name className/classList or a mutation method.
136
+ // Numeric indexes cannot name those members; ordinary array access is safe.
137
+ if (ts.isElementAccessExpression(node) && (!node.argumentExpression ||
138
+ (!ts.isStringLiteralLike(node.argumentExpression) && !(getChecker().getTypeAtLocation(node.argumentExpression).flags & ts.TypeFlags.NumberLike))))
139
+ unknown = true;
140
+ if (ts.isJsxAttribute(node) && /^(?:class|className)$/.test(node.name.getText())) {
141
+ const init = node.initializer;
142
+ const count = !init ? 0 : ts.isStringLiteral(init) ? literal(init.text).count
143
+ : ts.isJsxExpression(init) && init.expression ? classCount(init.expression) : undefined;
144
+ if (count === undefined)
145
+ unknown = true;
146
+ else
147
+ maximum = Math.max(maximum, count);
148
+ }
149
+ ts.forEachChild(node, visit);
150
+ };
151
+ for (const source of sources.values()) {
152
+ if (source.parseDiagnostics?.length)
153
+ return undefined;
154
+ visit(source);
155
+ }
156
+ return unknown || maximum >= 4 ? undefined : Math.max(1, maximum);
157
+ }
@@ -0,0 +1,4 @@
1
+ import type { StyleUsageObserver } from './analyze-renderer.js';
2
+ export declare function cssRangeObserver(features: Set<string>): StyleUsageObserver & {
3
+ finish(): void;
4
+ };
@@ -0,0 +1,115 @@
1
+ // Bounds are build facts. Keep the unit separate: numeric/native-style values
2
+ // are raw pixels, whereas authored px lengths scale with the target CSS DPR.
3
+ const families = ['padding', 'gap', 'border', 'radius', 'font', 'line-height', 'flex'];
4
+ const defaults = /^(?:initial|inherit|unset|revert|revert-layer)$/;
5
+ const number = /^[+]?(?:\d+(?:\.\d*)?|\.\d+)$/;
6
+ export function cssRangeObserver(features) {
7
+ const bounds = new Map(families.map(name => [name, { raw: name === 'flex' ? 1 : 0, px: name === 'font' ? 16 : 0, unknown: false }]));
8
+ let opaque = false;
9
+ let lineMultiplier = 0;
10
+ const unknown = (...names) => { for (const name of names)
11
+ bounds.get(name).unknown = true; };
12
+ const length = (name, value, count = 1) => {
13
+ if (value !== undefined && defaults.test(value))
14
+ return;
15
+ const parts = value?.split(/\s+/);
16
+ if (!parts?.length || parts.length > count) {
17
+ unknown(name);
18
+ return;
19
+ }
20
+ for (const part of parts) {
21
+ const match = part.match(/^([+]?(?:\d+(?:\.\d*)?|\.\d+))(px)?$/);
22
+ if (!match || !Number.isFinite(Number(match[1]))) {
23
+ unknown(name);
24
+ continue;
25
+ }
26
+ const unit = match[2] ? 'px' : 'raw';
27
+ bounds.get(name)[unit] = Math.max(bounds.get(name)[unit], Math.ceil(Number(match[1])));
28
+ }
29
+ };
30
+ return {
31
+ unknown() { opaque = true; },
32
+ selector(css) { if (/@(?:-webkit-)?keyframes\b|@property\b/i.test(css))
33
+ opaque = true; },
34
+ property(name, value) {
35
+ if (!name) {
36
+ opaque = true;
37
+ return;
38
+ }
39
+ name = name.replace(/[A-Z]/g, letter => `-${letter.toLowerCase()}`).toLowerCase();
40
+ value = value?.trim().toLowerCase().replace(/\s*!important$/, '');
41
+ if (name === 'all' || /^(?:-webkit-)?(?:animation|transition)(?:-|$)/.test(name)) {
42
+ opaque = true;
43
+ return;
44
+ }
45
+ if (/^padding(?:-|$)/.test(name))
46
+ length('padding', value, 4);
47
+ if (/^(?:grid-)?(?:(?:row|column)-)?gap$/.test(name))
48
+ length('gap', value === 'normal' ? '0' : value, 2);
49
+ if (/^border(?:-(?:top-left|top-right|bottom-left|bottom-right|start-start|start-end|end-start|end-end))?-radius$/.test(name))
50
+ length('radius', value, 4);
51
+ if (/^border(?:-(?:top|right|bottom|left|block|inline)(?:-(?:start|end))?)?-width$/.test(name)) {
52
+ length('border', value?.replace(/\bthin\b/g, '1px').replace(/\bmedium\b/g, '3px').replace(/\bthick\b/g, '5px'), 4);
53
+ }
54
+ if (/^border(?:-(?:top|right|bottom|left|block|inline)(?:-(?:start|end))?)?$/.test(name)) {
55
+ if (value === undefined || /[()]/.test(value))
56
+ unknown('border');
57
+ else if (!defaults.test(value)) {
58
+ const tokens = value.split(/\s+/);
59
+ const widths = tokens.filter(token => /^(?:[+.-]?\d|thin$|medium$|thick$)/.test(token));
60
+ if (widths.length > 1)
61
+ unknown('border');
62
+ else
63
+ length('border', widths[0]?.replace(/^thin$/, '1px').replace(/^medium$/, '3px').replace(/^thick$/, '5px') ?? (tokens.some(t => /^(?:none|hidden)$/.test(t)) ? '0' : '3px'));
64
+ }
65
+ }
66
+ if (name === 'font-size')
67
+ length('font', value);
68
+ if (name === 'font' && (value === undefined || !defaults.test(value)))
69
+ unknown('font', 'line-height');
70
+ if (name === 'line-height' && value !== 'normal' && !(value !== undefined && defaults.test(value))) {
71
+ if (value !== undefined && number.test(value))
72
+ lineMultiplier = Math.max(lineMultiplier, Math.ceil(Number(value)));
73
+ else
74
+ length('line-height', value);
75
+ }
76
+ if (name === 'flex-grow' || name === 'flex-shrink') {
77
+ if (value === undefined || (!defaults.test(value) && !number.test(value)))
78
+ unknown('flex');
79
+ else if (!defaults.test(value))
80
+ length('flex', value);
81
+ }
82
+ if (name === 'flex' && !/^(?:none|auto|initial|inherit|unset|revert|revert-layer)$/.test(value ?? '')) {
83
+ const parts = value?.split(/\s+/);
84
+ if (!parts?.length || parts.length > 3 || !number.test(parts[0]))
85
+ unknown('flex');
86
+ else {
87
+ length('flex', parts[0]);
88
+ if (parts.length > 1 && number.test(parts[1]))
89
+ length('flex', parts[1]);
90
+ else if (parts.length > 2 || (parts.length === 2 && !/^(?:auto|content|[+]?(?:\d+(?:\.\d*)?|\.\d+)(?:px|%))$/.test(parts[1])))
91
+ unknown('flex');
92
+ }
93
+ }
94
+ },
95
+ finish() {
96
+ features.add('css-ranges-v1');
97
+ if (opaque) {
98
+ features.add('css-ranges-unknown');
99
+ return;
100
+ }
101
+ const font = bounds.get('font'), line = bounds.get('line-height');
102
+ if (lineMultiplier) {
103
+ line.unknown ||= font.unknown || !Number.isFinite(lineMultiplier);
104
+ line.raw = Math.max(line.raw, font.raw * lineMultiplier);
105
+ line.px = Math.max(line.px, font.px * lineMultiplier);
106
+ }
107
+ for (const [name, bound] of bounds)
108
+ if (!bound.unknown) {
109
+ for (const unit of ['raw', 'px'])
110
+ if (Number.isSafeInteger(bound[unit]))
111
+ features.add(`css-range-${name}-${unit}-${bound[unit]}`);
112
+ }
113
+ },
114
+ };
115
+ }
@@ -0,0 +1,8 @@
1
+ import type ts from 'typescript';
2
+ import { type StyleUsageObserver } from './analyze-renderer.js';
3
+ export declare const cssAnalysisVersion = "css-analysis-v15";
4
+ export declare const cssFeatures: readonly ["css-pseudo-elements", "css-text-alpha", "css-border-alpha", "css-animations", "css-transforms", "css-grid", "css-floats", "css-writing-mode", "css-border-relief", "css-blink", "css-order", "css-percent-radius", "css-percent-gap", "css-opacity", "css-text-decoration", "css-text-transform", "css-visibility", "css-pointer-events", "css-mask", "css-image-fit", "css-filters", "css-box-shadow", "css-flex-wrap", "css-justify-items", "css-align-content", "css-align-self", "css-min-width", "css-height-expressions", "css-z-index", "css-aspect-ratio", "css-margin-trim", "css-containment", "css-justify-self", "css-flex-line-count", "css-box-expressions", "css-axis-gap", "css-corner-radius", "css-first-line", "css-side-borders", "css-background-layers", "css-line-height-expressions", "css-scrolling", "css-flex-basis-expressions", "css-custom-property-lengths", "css-max-height", "css-flex-basis", "css-overflow-axes", "css-position-top", "css-position-top-percent", "css-position-right", "css-position-right-percent", "css-position-bottom", "css-position-bottom-percent", "css-position-left", "css-position-left-percent"];
5
+ export declare function addUnknownCssFeatures(features: Set<string>): void;
6
+ export declare function cssUsageObserver(features: Set<string>, resolve?: (node: ts.Expression) => string[] | undefined): StyleUsageObserver & {
7
+ finish(): void;
8
+ };
@@ -0,0 +1,205 @@
1
+ import { colorAlphaObserver } from './analyze-alpha.js';
2
+ import { colorVariableAnalysis } from './analyze-renderer.js';
3
+ export const cssAnalysisVersion = 'css-analysis-v15';
4
+ export const cssFeatures = ['css-pseudo-elements', 'css-text-alpha', 'css-border-alpha', 'css-animations', 'css-transforms', 'css-grid', 'css-floats', 'css-writing-mode', 'css-border-relief', 'css-blink', 'css-order', 'css-percent-radius', 'css-percent-gap', 'css-opacity', 'css-text-decoration', 'css-text-transform', 'css-visibility', 'css-pointer-events', 'css-mask', 'css-image-fit', 'css-filters', 'css-box-shadow', 'css-flex-wrap', 'css-justify-items', 'css-align-content', 'css-align-self', 'css-min-width', 'css-height-expressions', 'css-z-index', 'css-aspect-ratio', 'css-margin-trim', 'css-containment', 'css-justify-self', 'css-flex-line-count', 'css-box-expressions', 'css-axis-gap', 'css-corner-radius', 'css-first-line', 'css-side-borders', 'css-background-layers', 'css-line-height-expressions', 'css-scrolling', 'css-flex-basis-expressions', 'css-custom-property-lengths', 'css-max-height', 'css-flex-basis', 'css-overflow-axes', 'css-position-top', 'css-position-top-percent', 'css-position-right', 'css-position-right-percent', 'css-position-bottom', 'css-position-bottom-percent', 'css-position-left', 'css-position-left-percent'];
5
+ export function addUnknownCssFeatures(features) {
6
+ for (const feature of cssFeatures)
7
+ features.add(feature);
8
+ }
9
+ // These are build facts, not application options. Unknown values retain the
10
+ // entire affected family; unknown property names retain all CSS semantics.
11
+ // In particular, a dynamic width does not enable transforms or grid layout.
12
+ export function cssUsageObserver(features, resolve) {
13
+ const colors = colorVariableAnalysis();
14
+ const alpha = colorAlphaObserver(features, resolve);
15
+ const deferredColors = [];
16
+ return {
17
+ unknown: () => { colors.unknown(); addUnknownCssFeatures(features); },
18
+ finish() {
19
+ alpha.finish();
20
+ for (const [feature, value] of deferredColors)
21
+ if (!colors.isColor(value))
22
+ features.add(feature);
23
+ },
24
+ selector: css => {
25
+ if (/::?(?:before|after)\b/i.test(css))
26
+ features.add('css-pseudo-elements');
27
+ if (/::?first-line\b/i.test(css))
28
+ features.add('css-first-line');
29
+ if (/@(?:-webkit-)?keyframes\b/i.test(css))
30
+ features.add('css-animations');
31
+ },
32
+ property(name, value, expression) {
33
+ alpha.property(name, value, expression);
34
+ colors.property(name, value);
35
+ if (!name) {
36
+ addUnknownCssFeatures(features);
37
+ return;
38
+ }
39
+ if (name === 'content')
40
+ features.add('css-pseudo-elements');
41
+ if (name.startsWith('--')) {
42
+ // Quoted CSS strings remain raw text; the length parser never unquotes
43
+ // them. Unknown values still keep the length cache automatically.
44
+ const quoted = value !== undefined && /^(?:"(?:[^"\\\r\n]|\\[^\r\n])*"|'(?:[^'\\\r\n]|\\[^\r\n])*')(?:\s*!important)?$/i.test(value.trim());
45
+ if (!quoted)
46
+ deferredColors.push(['css-custom-property-lengths', value]);
47
+ return;
48
+ }
49
+ const originalValue = value;
50
+ name = name.replace(/[A-Z]/g, c => `-${c.toLowerCase()}`).toLowerCase();
51
+ value = value?.trim().toLowerCase();
52
+ // Only a proven literal without percentages or functions can omit these
53
+ // alternate representations. var/calc and dynamic values retain them.
54
+ // Equal literal edges need one stored value. Unknown functions/variables
55
+ // may expand to multiple values, and longhands can mutate just one edge.
56
+ const parts = value?.replace(/\s*!important$/, '').split(/\s+/);
57
+ // Preserve each authored physical edge. Logical insets may map to any
58
+ // edge; functions, percentages and unknown values retain percent storage.
59
+ const positionSides = /^(?:top|right|bottom|left)$/.test(name) ? [name]
60
+ : /^inset(?:-|$)/.test(name) ? ['top', 'right', 'bottom', 'left'] : [];
61
+ const fixedPosition = !!parts?.length && parts.length <= 4 && parts.every(part => /^(?:(?:auto|initial|inherit|unset|revert|revert-layer)|[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:px)?)$/.test(part));
62
+ for (const side of positionSides) {
63
+ features.add(`css-position-${side}`);
64
+ if (!fixedPosition)
65
+ features.add(`css-position-${side}-percent`);
66
+ }
67
+ const uniformLength = !!parts?.length && parts.length <= 4 &&
68
+ parts.every(part => part === parts[0]) &&
69
+ /^(?:(?:normal|initial|inherit|unset|revert|revert-layer)|[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:px|em|rem|vw|vh|vmin|vmax|%)?)$/.test(parts[0]);
70
+ if (/^(?:grid-)?(?:row|column)-gap$/.test(name) ||
71
+ (/^(?:grid-)?gap$/.test(name) && (!uniformLength || parts.length > 2)))
72
+ features.add('css-axis-gap');
73
+ if ((name === 'border-radius' && !uniformLength) ||
74
+ /^border-(?:top-left|top-right|bottom-left|bottom-right|start-start|start-end|end-start|end-end)-radius$/.test(name))
75
+ features.add('css-corner-radius');
76
+ const mayUsePercent = value === undefined || /[%()]/.test(value);
77
+ if (/^border(?:-(?:top-left|top-right|bottom-left|bottom-right))?-radius$/.test(name) && mayUsePercent)
78
+ features.add('css-percent-radius');
79
+ if (/^(?:grid-)?(?:(?:row|column)-)?gap$/.test(name) && mayUsePercent)
80
+ features.add('css-percent-gap');
81
+ if (/^(?:-webkit-)?(?:animation|transition)(?:-|$)/.test(name))
82
+ features.add('css-animations');
83
+ if (name === 'blink-interval')
84
+ features.add('css-blink');
85
+ if (name === 'order')
86
+ features.add('css-order');
87
+ if (name === 'opacity')
88
+ features.add('css-opacity');
89
+ if (name === 'text-decoration' || name === 'text-decoration-line')
90
+ features.add('css-text-decoration');
91
+ if (name === 'text-transform')
92
+ features.add('css-text-transform');
93
+ if (name === 'visibility')
94
+ features.add('css-visibility');
95
+ if (name === 'pointer-events')
96
+ features.add('css-pointer-events');
97
+ if (name === 'mask' || name === 'mask-image' || name === '-webkit-mask' || name === '-webkit-mask-image')
98
+ features.add('css-mask');
99
+ if (name === 'object-fit')
100
+ features.add('css-image-fit');
101
+ if (name === 'filter' || name === '-webkit-filter')
102
+ features.add('css-filters');
103
+ if (name === 'box-shadow' || name === '-webkit-box-shadow')
104
+ features.add('css-box-shadow');
105
+ if (name === 'flex-wrap' || name === 'flex-flow')
106
+ features.add('css-flex-wrap');
107
+ if (name === 'justify-items' || name === 'place-items')
108
+ features.add('css-justify-items');
109
+ if (name === 'align-content' || name === 'place-content')
110
+ features.add('css-align-content');
111
+ if (name === 'align-self' || name === 'place-self')
112
+ features.add('css-align-self');
113
+ if (/^min-(?:width|inline-size|block-size)$/.test(name))
114
+ features.add('css-min-width');
115
+ // Only simple literal heights prove that no deferred expression is needed.
116
+ // Intrinsic keywords, functions, unknown values and logical sizes retain it.
117
+ if (name === 'block-size' || name === 'inline-size' ||
118
+ (name === 'height' && (value === undefined || !/^(?:(?:auto|initial|inherit|unset|revert|revert-layer)|[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:px|%)?)(?:\s*!important)?$/.test(value))))
119
+ features.add('css-height-expressions');
120
+ if (/^max-(?:height|block-size|inline-size)$/.test(name))
121
+ features.add('css-max-height');
122
+ if (name === 'z-index')
123
+ features.add('css-z-index');
124
+ if (name === 'aspect-ratio')
125
+ features.add('css-aspect-ratio');
126
+ if (name === 'margin-trim')
127
+ features.add('css-margin-trim');
128
+ if (name === 'contain' || name === 'content-visibility')
129
+ features.add('css-containment');
130
+ if (name === 'justify-self' || name === 'place-self')
131
+ features.add('css-justify-self');
132
+ if (name === 'flex-line-count')
133
+ features.add('css-flex-line-count');
134
+ // Only fixed pixel/zero edges and CSS-wide defaults can omit deferred
135
+ // lengths. Percentages, relative units, functions and dynamic values keep
136
+ // their storage. Include logical shorthands and longhands conservatively.
137
+ if (/^(?:margin|padding)(?:-|$)/.test(name) && name !== 'margin-trim') {
138
+ const fixed = value?.replace(/\s*!important$/, '').split(/\s+/).every(part => /^(?:(?:auto|initial|inherit|unset|revert|revert-layer)|[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:px)?)$/.test(part));
139
+ if (!fixed)
140
+ features.add('css-box-expressions');
141
+ }
142
+ // CSS couples the axes: visible computes to auto next to hidden.
143
+ // Longhands can combine through the cascade, so retain them unless a
144
+ // whole-axis proof is available. A literal shorthand controls both axes.
145
+ if (/^overflow(?:-[xy]|-inline|-block)$/.test(name)) {
146
+ features.add('css-scrolling');
147
+ features.add('css-overflow-axes');
148
+ }
149
+ if (name === 'overflow') {
150
+ const axes = value?.replace(/\s*!important$/, '').split(/\s+/);
151
+ if (!axes?.length || axes.length > 2 || !axes.every(axis => axis === axes[0]) || !/^(?:visible|hidden|clip|auto|scroll|initial|inherit|unset|revert|revert-layer)$/.test(axes[0]))
152
+ features.add('css-overflow-axes');
153
+ const known = !!axes?.length && axes.length <= 2 && axes.every(axis => /^(?:visible|hidden|clip|initial|inherit|unset|revert|revert-layer)$/.test(axis));
154
+ if (!known || (axes.includes('visible') && axes.includes('hidden')))
155
+ features.add('css-scrolling');
156
+ }
157
+ // Local background attachment can observe overflowing content even
158
+ // without a scroll control, so preserve its geometry as well.
159
+ if (/^(?:scroll|overscroll)-/.test(name) || name === 'background-attachment')
160
+ features.add('css-scrolling');
161
+ if (name === 'background' && !/^(?:none|initial|inherit|unset|revert|revert-layer)(?:\s*!important)?$/.test(value ?? ''))
162
+ deferredColors.push(['css-scrolling', originalValue]);
163
+ const cssWide = value !== undefined && /^(?:initial|inherit|unset|revert|revert-layer)(?:\s*!important)?$/.test(value);
164
+ if (/^border-(?:top|right|bottom|left|block|inline)(?:-|$)/.test(name) && !name.endsWith('-radius'))
165
+ features.add('css-side-borders');
166
+ if (name === 'border-width' && !cssWide && !(parts?.length && parts.length <= 4 && parts.every(part => part === parts[0]) && /^(?:thin|medium|thick|[+]?(?:\d+(?:\.\d*)?|\.\d+)(?:px|em|rem|vw|vh|vmin|vmax)?)$/.test(parts[0])))
167
+ features.add('css-side-borders');
168
+ if (name === 'border-style' && !cssWide && !(parts?.length && parts.length <= 4 && parts.every(part => part === parts[0]) && /^(?:none|hidden|solid|dotted|dashed|double|groove|ridge|inset|outset)$/.test(parts[0])))
169
+ features.add('css-side-borders');
170
+ if (name === 'border-color' && !cssWide)
171
+ deferredColors.push(['css-side-borders', originalValue]);
172
+ if (/^background-(?:image|clip|size|position|repeat|attachment|origin)(?:-|$)/.test(name))
173
+ features.add('css-background-layers');
174
+ if (name === 'background' && !cssWide && !/^none(?:\s*!important)?$/.test(value ?? ''))
175
+ deferredColors.push(['css-background-layers', originalValue]);
176
+ if ((name === 'line-height' && !cssWide && (value === undefined || !/^(?:normal|[+]?(?:\d+(?:\.\d*)?|\.\d+)(?:px)?)(?:\s*!important)?$/.test(value))) || (name === 'font' && !cssWide))
177
+ features.add('css-line-height-expressions');
178
+ // Numeric one/two-factor shorthands and defaults use the implicit auto
179
+ // scalar basis. Any explicit basis or unknown shorthand keeps the field.
180
+ if (name === 'flex-basis' || (name === 'flex' && (value === undefined || !/^(?:(?:none|auto|initial|inherit|unset|revert|revert-layer)|[+]?(?:\d+(?:\.\d*)?|\.\d+)(?:\s+[+]?(?:\d+(?:\.\d*)?|\.\d+))?)(?:\s*!important)?$/.test(value))))
181
+ features.add('css-flex-basis');
182
+ // Fixed pixel bases and numeric flex shorthand need no deferred value.
183
+ // Functions, percentages, relative units and dynamic values retain it.
184
+ if (name === 'flex-basis' && (value === undefined || !/^(?:(?:auto|content|initial|inherit|unset|revert|revert-layer)|[+]?(?:\d+(?:\.\d*)?|\.\d+)(?:px)?)(?:\s*!important)?$/.test(value)))
185
+ features.add('css-flex-basis-expressions');
186
+ if (name === 'flex' && !cssWide && (value === undefined || !/^(?:none|auto|(?:[+]?(?:\d+(?:\.\d*)?|\.\d+)\s+){0,2}(?:[+]?(?:\d+(?:\.\d*)?|\.\d+)(?:px)?|auto|content))(?:\s*!important)?$/.test(value)))
187
+ features.add('css-flex-basis-expressions');
188
+ if (name === 'all') {
189
+ addUnknownCssFeatures(features);
190
+ return;
191
+ }
192
+ if (/^(?:-webkit-)?(?:transform(?:-origin|-style)?|perspective(?:-origin)?|translate|rotate|scale|backface-visibility)$/.test(name))
193
+ features.add('css-transforms');
194
+ if (/^grid(?:-|$)/.test(name) || (name === 'display' && (value === undefined || /(?:grid|var\s*\()/i.test(value))))
195
+ features.add('css-grid');
196
+ if (name === 'float' || name === 'clear')
197
+ features.add('css-floats');
198
+ if (name === 'writing-mode' || name === 'direction')
199
+ features.add('css-writing-mode');
200
+ if (/^border(?:-(?:top|right|bottom|left))?(?:-style)?$/.test(name) &&
201
+ (value === undefined || /(?:inset|outset|groove|ridge|var\s*\()/i.test(value)))
202
+ features.add('css-border-relief');
203
+ },
204
+ };
205
+ }
@@ -0,0 +1,2 @@
1
+ import ts from 'typescript';
2
+ export declare function sourceLiteralResolver(files: Map<string, string>, initiallyOpaque: boolean): (node: ts.Expression) => string[] | undefined;