@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.
- package/dist/analyze-alpha.d.ts +5 -0
- package/dist/analyze-alpha.js +76 -0
- package/dist/analyze-classes.d.ts +1 -0
- package/dist/analyze-classes.js +157 -0
- package/dist/analyze-css-ranges.d.ts +4 -0
- package/dist/analyze-css-ranges.js +115 -0
- package/dist/analyze-css.d.ts +8 -0
- package/dist/analyze-css.js +205 -0
- package/dist/analyze-literals.d.ts +2 -0
- package/dist/analyze-literals.js +267 -0
- package/dist/analyze-nodes.d.ts +4 -0
- package/dist/analyze-nodes.js +68 -0
- package/dist/analyze-renderer.d.ts +23 -0
- package/dist/analyze-renderer.js +403 -0
- package/dist/analyze.js +96 -16
- package/dist/cpp-mounted-lowering.js +24 -6
- package/dist/cpp-template-renderer.js +21 -7
- package/dist/host-shims.js +17 -0
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +43 -16
- package/package.json +1 -1
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
export const rendererAnalysisVersion = 'renderer-analysis-v1';
|
|
3
|
+
const rendererFeatures = ['renderer-circles', 'renderer-transforms', 'renderer-linear-gradients', 'renderer-radial-gradients'];
|
|
4
|
+
export function addUnknownRendererFeatures(features) {
|
|
5
|
+
for (const feature of rendererFeatures)
|
|
6
|
+
features.add(feature);
|
|
7
|
+
}
|
|
8
|
+
// Proof shared by CSS storage and renderer cache selection. Custom-property
|
|
9
|
+
// identifiers are case-sensitive; missing/aliased/opaque definitions retain
|
|
10
|
+
// support. The atom-like proof is intentionally limited to literal colors.
|
|
11
|
+
export function colorVariableAnalysis() {
|
|
12
|
+
const colors = new Map();
|
|
13
|
+
let opaque = false;
|
|
14
|
+
const color = (value) => value !== undefined && /^(?:#(?:[\da-f]{3}|[\da-f]{4}|[\da-f]{6}|[\da-f]{8})|transparent|currentcolor)$/i.test(value.trim().replace(/\s*!important\s*$/i, ''));
|
|
15
|
+
return {
|
|
16
|
+
property(name, value) {
|
|
17
|
+
if (!name) {
|
|
18
|
+
opaque = true;
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (name.startsWith('--'))
|
|
22
|
+
colors.set(name, (colors.get(name) ?? true) && color(value));
|
|
23
|
+
},
|
|
24
|
+
unknown() { opaque = true; },
|
|
25
|
+
isColor(value) {
|
|
26
|
+
if (color(value))
|
|
27
|
+
return true;
|
|
28
|
+
const match = value?.trim().replace(/\s*!important\s*$/i, '').match(/^var\(\s*(--[\w-]+)\s*(?:,\s*([^()]+))?\)$/i);
|
|
29
|
+
return !opaque && !!match && colors.get(match[1]) === true && (match[2] === undefined || color(match[2]));
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export function rendererVariableAnalysis(features) {
|
|
34
|
+
const colors = colorVariableAnalysis();
|
|
35
|
+
const backgrounds = [];
|
|
36
|
+
return {
|
|
37
|
+
property: colors.property,
|
|
38
|
+
unknown: colors.unknown,
|
|
39
|
+
background(value) { backgrounds.push(value); },
|
|
40
|
+
finish() {
|
|
41
|
+
if (backgrounds.some(value => !colors.isColor(value))) {
|
|
42
|
+
features.add('renderer-linear-gradients');
|
|
43
|
+
features.add('renderer-radial-gradients');
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
export function addRendererFeatures(file, text, features, observer, variables) {
|
|
49
|
+
const allStyles = () => {
|
|
50
|
+
observer?.unknown();
|
|
51
|
+
for (const feature of rendererFeatures.slice(1))
|
|
52
|
+
features.add(feature);
|
|
53
|
+
};
|
|
54
|
+
const gradients = (value, unknown = false) => {
|
|
55
|
+
if (unknown || /(?:^|[^\w-])(?:repeating-)?linear-gradient\s*\(/i.test(value))
|
|
56
|
+
features.add('renderer-linear-gradients');
|
|
57
|
+
if (unknown || /(?:^|[^\w-])(?:repeating-)?radial-gradient\s*\(/i.test(value))
|
|
58
|
+
features.add('renderer-radial-gradients');
|
|
59
|
+
};
|
|
60
|
+
const property = (name, value, expression) => {
|
|
61
|
+
observer?.property(name, value, expression);
|
|
62
|
+
if (!name) {
|
|
63
|
+
allStyles();
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const cssName = name.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`).toLowerCase();
|
|
67
|
+
if (/^(?:-webkit-)?(?:transform|perspective|translate|rotate|scale)$/.test(cssName)) {
|
|
68
|
+
if (value?.trim().toLowerCase() !== 'none')
|
|
69
|
+
features.add('renderer-transforms');
|
|
70
|
+
}
|
|
71
|
+
if (/^(?:background(?:-image)?|border-image(?:-source)?|mask(?:-image)?)$/.test(cssName)) {
|
|
72
|
+
if (value !== undefined && /var\s*\(/i.test(value) && variables)
|
|
73
|
+
variables.background(value);
|
|
74
|
+
else
|
|
75
|
+
gradients(value ?? '', value === undefined || /var\s*\(/i.test(value));
|
|
76
|
+
}
|
|
77
|
+
// Custom properties can later supply a background or transform value.
|
|
78
|
+
if (cssName.startsWith('--') && value !== undefined)
|
|
79
|
+
gradients(value);
|
|
80
|
+
};
|
|
81
|
+
const css = (value) => {
|
|
82
|
+
value = value.replace(/\/\*[\s\S]*?\*\//g, '');
|
|
83
|
+
// CSS escapes can occur in property names and values as well as glyph
|
|
84
|
+
// content. Decode them so an icon escape doesn't force every CSS family.
|
|
85
|
+
value = value.replace(/\\(?:([0-9a-f]{1,6})\s?|([^\r\n]))/gi, (_match, hex, character) => {
|
|
86
|
+
if (!hex)
|
|
87
|
+
return character ?? '';
|
|
88
|
+
const code = Number.parseInt(hex, 16);
|
|
89
|
+
return String.fromCodePoint(code > 0 && code <= 0x10ffff ? code : 0xfffd);
|
|
90
|
+
});
|
|
91
|
+
observer?.selector?.(value);
|
|
92
|
+
gradients(value);
|
|
93
|
+
for (const match of value.matchAll(/(?:^|[;{])\s*([\w-]+)\s*:\s*([^;{}]*)/g))
|
|
94
|
+
property(match[1].startsWith('--') ? match[1] : match[1].toLowerCase(), match[2]);
|
|
95
|
+
};
|
|
96
|
+
if (/\.css$/i.test(file)) {
|
|
97
|
+
css(text);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
const source = ts.createSourceFile(file, text, ts.ScriptTarget.Latest, true, /\.[jt]sx$/i.test(file) ? ts.ScriptKind.TSX : ts.ScriptKind.TS);
|
|
101
|
+
const constants = new Map();
|
|
102
|
+
const ambiguousConstants = new Set();
|
|
103
|
+
const bindingCounts = new Map();
|
|
104
|
+
const bind = (name) => {
|
|
105
|
+
if (ts.isIdentifier(name)) {
|
|
106
|
+
const count = (bindingCounts.get(name.text) ?? 0) + 1;
|
|
107
|
+
bindingCounts.set(name.text, count);
|
|
108
|
+
if (count > 1)
|
|
109
|
+
ambiguousConstants.add(name.text);
|
|
110
|
+
}
|
|
111
|
+
else
|
|
112
|
+
for (const part of name.elements)
|
|
113
|
+
if (ts.isBindingElement(part))
|
|
114
|
+
bind(part.name);
|
|
115
|
+
};
|
|
116
|
+
const collect = (node) => {
|
|
117
|
+
if (ts.isVariableDeclaration(node) || ts.isParameter(node))
|
|
118
|
+
bind(node.name);
|
|
119
|
+
else if ((ts.isImportClause(node) || ts.isImportSpecifier(node) || ts.isNamespaceImport(node) ||
|
|
120
|
+
ts.isFunctionDeclaration(node) || ts.isClassDeclaration(node)) && node.name)
|
|
121
|
+
bind(node.name);
|
|
122
|
+
if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name) && node.initializer &&
|
|
123
|
+
ts.isVariableDeclarationList(node.parent) && (node.parent.flags & ts.NodeFlags.Const)) {
|
|
124
|
+
constants.set(node.name.text, node.initializer);
|
|
125
|
+
}
|
|
126
|
+
ts.forEachChild(node, collect);
|
|
127
|
+
};
|
|
128
|
+
collect(source);
|
|
129
|
+
const unwrap = (node) => {
|
|
130
|
+
while (ts.isParenthesizedExpression(node) || ts.isAsExpression(node) || ts.isTypeAssertionExpression(node) || ts.isSatisfiesExpression(node))
|
|
131
|
+
node = node.expression;
|
|
132
|
+
return node;
|
|
133
|
+
};
|
|
134
|
+
const literal = (node, seen = new Set()) => {
|
|
135
|
+
if (!node)
|
|
136
|
+
return undefined;
|
|
137
|
+
node = unwrap(node);
|
|
138
|
+
if (ts.isStringLiteralLike(node) || ts.isNumericLiteral(node))
|
|
139
|
+
return node.text;
|
|
140
|
+
if (ts.isIdentifier(node) && !ambiguousConstants.has(node.text) && !seen.has(node.text)) {
|
|
141
|
+
seen.add(node.text);
|
|
142
|
+
return literal(constants.get(node.text), seen);
|
|
143
|
+
}
|
|
144
|
+
if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.PlusToken) {
|
|
145
|
+
const left = literal(node.left, new Set(seen)), right = literal(node.right, new Set(seen));
|
|
146
|
+
if (left !== undefined && right !== undefined)
|
|
147
|
+
return left + right;
|
|
148
|
+
}
|
|
149
|
+
return undefined;
|
|
150
|
+
};
|
|
151
|
+
const member = (node) => {
|
|
152
|
+
if (ts.isPropertyAccessExpression(node))
|
|
153
|
+
return node.name.text;
|
|
154
|
+
if (ts.isElementAccessExpression(node))
|
|
155
|
+
return literal(node.argumentExpression);
|
|
156
|
+
return undefined;
|
|
157
|
+
};
|
|
158
|
+
const isStyleTarget = (node, seen = new Set()) => {
|
|
159
|
+
node = unwrap(node);
|
|
160
|
+
if (member(node) === 'style')
|
|
161
|
+
return true;
|
|
162
|
+
if (ts.isIdentifier(node) && constants.has(node.text) && !ambiguousConstants.has(node.text) && !seen.has(node.text)) {
|
|
163
|
+
seen.add(node.text);
|
|
164
|
+
return isStyleTarget(constants.get(node.text), seen);
|
|
165
|
+
}
|
|
166
|
+
return false;
|
|
167
|
+
};
|
|
168
|
+
const styleObjectBindings = new Set();
|
|
169
|
+
const styleObject = (expression, seen = new Set()) => {
|
|
170
|
+
expression = unwrap(expression);
|
|
171
|
+
if (ts.isIdentifier(expression))
|
|
172
|
+
styleObjectBindings.add(expression.text);
|
|
173
|
+
if (ts.isIdentifier(expression) && constants.has(expression.text) && !ambiguousConstants.has(expression.text) && !seen.has(expression.text)) {
|
|
174
|
+
seen.add(expression.text);
|
|
175
|
+
styleObject(constants.get(expression.text), seen);
|
|
176
|
+
}
|
|
177
|
+
else if (ts.isObjectLiteralExpression(expression)) {
|
|
178
|
+
for (const item of expression.properties) {
|
|
179
|
+
if (ts.isSpreadAssignment(item)) {
|
|
180
|
+
styleObject(item.expression, new Set(seen));
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
if (!ts.isPropertyAssignment(item) && !ts.isShorthandPropertyAssignment(item)) {
|
|
184
|
+
allStyles();
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
const name = ts.isComputedPropertyName(item.name) ? literal(item.name.expression) : item.name.text;
|
|
188
|
+
property(name, literal(ts.isPropertyAssignment(item) ? item.initializer : item.name), ts.isPropertyAssignment(item) ? item.initializer : item.name);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
else if (ts.isConditionalExpression(expression)) {
|
|
192
|
+
styleObject(expression.whenTrue, new Set(seen));
|
|
193
|
+
styleObject(expression.whenFalse, new Set(seen));
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
const value = literal(expression);
|
|
197
|
+
if (value === undefined)
|
|
198
|
+
allStyles();
|
|
199
|
+
else
|
|
200
|
+
css(value);
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
const isStyleObjectReference = (expression, seen = new Set()) => {
|
|
204
|
+
expression = unwrap(expression);
|
|
205
|
+
if (!ts.isIdentifier(expression) || seen.has(expression.text))
|
|
206
|
+
return false;
|
|
207
|
+
if (styleObjectBindings.has(expression.text))
|
|
208
|
+
return true;
|
|
209
|
+
seen.add(expression.text);
|
|
210
|
+
const initializer = constants.get(expression.text);
|
|
211
|
+
return !!initializer && isStyleObjectReference(initializer, seen);
|
|
212
|
+
};
|
|
213
|
+
const argumentContainsStyle = (expression) => {
|
|
214
|
+
if (ts.isExpression(expression) && isStyleObjectReference(expression))
|
|
215
|
+
return true;
|
|
216
|
+
let found = false;
|
|
217
|
+
ts.forEachChild(expression, child => { if (argumentContainsStyle(child))
|
|
218
|
+
found = true; });
|
|
219
|
+
return found;
|
|
220
|
+
};
|
|
221
|
+
const opaqueCallable = (node, seen = new Set()) => {
|
|
222
|
+
node = unwrap(node);
|
|
223
|
+
if (ts.isIdentifier(node) && !seen.has(node.text) && constants.has(node.text)) {
|
|
224
|
+
seen.add(node.text);
|
|
225
|
+
return opaqueCallable(constants.get(node.text), seen);
|
|
226
|
+
}
|
|
227
|
+
if (ts.isElementAccessExpression(node) && member(node) === undefined)
|
|
228
|
+
return true;
|
|
229
|
+
if (ts.isPropertyAccessExpression(node) || ts.isElementAccessExpression(node))
|
|
230
|
+
return opaqueCallable(node.expression, seen);
|
|
231
|
+
return false;
|
|
232
|
+
};
|
|
233
|
+
const circleMethods = new Set(['arc', 'arcTo', 'ellipse', 'roundRect', 'fillCircle', 'fillCircles', 'fillCirclesRgb565', 'fillCirclesRgb565Uniform', 'fillCirclesRgb565WorldYSorted', 'fillCircleBox', 'fillEllipse', 'fillEllipseBatch', 'fillRoundedRectBoxesRgb565']);
|
|
234
|
+
const visit = (node) => {
|
|
235
|
+
if (ts.isIdentifier(node) && /^__gea_/.test(node.text) && node.text !== '__gea_Display')
|
|
236
|
+
observer?.unknownRanges?.();
|
|
237
|
+
// These factories/hosts can inject native defaults or change length scaling
|
|
238
|
+
// outside the authored CSS range proof. Type-only imports cannot do so.
|
|
239
|
+
if (ts.isImportDeclaration(node) && ts.isStringLiteral(node.moduleSpecifier) &&
|
|
240
|
+
/^(?:gea-embedded|@geastack\/(?:core|engine)|@geajs\/core)(?:\/|$)/.test(node.moduleSpecifier.text) &&
|
|
241
|
+
node.importClause && !node.importClause.isTypeOnly) {
|
|
242
|
+
const bindings = node.importClause.namedBindings;
|
|
243
|
+
if (node.importClause.name || !bindings || !ts.isNamedImports(bindings) ||
|
|
244
|
+
bindings.elements.some(item => !item.isTypeOnly && !/^(?:Component|Store|mount)$/.test((item.propertyName ?? item.name).text)))
|
|
245
|
+
observer?.unknownRanges?.();
|
|
246
|
+
}
|
|
247
|
+
if (ts.isIdentifier(node) && /^(?:setDevicePixelRatio|setViewportMetrics|devicePixelRatio|__gea_StyleSheet|createVirtualList|createInput|createTextInput|VirtualList|VirtualListElement|TextInput|VirtualKeyboard)$/.test(node.text))
|
|
248
|
+
observer?.unknownRanges?.();
|
|
249
|
+
if ((ts.isStringLiteralLike(node) && /^(?:virtual-list|input|textarea|select)$/i.test(node.text)) ||
|
|
250
|
+
((ts.isJsxOpeningElement(node) || ts.isJsxSelfClosingElement(node)) && /^(?:virtual-list|input|textarea|select)$/i.test(node.tagName.getText(source))))
|
|
251
|
+
observer?.unknownRanges?.();
|
|
252
|
+
// Native controls can introduce scrollable descendants without authored
|
|
253
|
+
// overflow CSS. Literal tag/factory use retains state; dynamic factories
|
|
254
|
+
// and computed calls are opaque and keep all families below.
|
|
255
|
+
if ((ts.isIdentifier(node) && /^(?:createVirtualList|createInput|createTextInput|VirtualList|VirtualListElement|TextInput|VirtualKeyboard)$/.test(node.text)) ||
|
|
256
|
+
(ts.isStringLiteralLike(node) && /^(?:virtual-list|input|textarea|select)$/i.test(node.text)) ||
|
|
257
|
+
((ts.isJsxOpeningElement(node) || ts.isJsxSelfClosingElement(node)) && /^(?:virtual-list|input|textarea|select)$/i.test(node.tagName.getText(source)))) {
|
|
258
|
+
features.add('css-scrolling');
|
|
259
|
+
features.add('css-overflow-axes');
|
|
260
|
+
observer?.property('inset', undefined);
|
|
261
|
+
}
|
|
262
|
+
// Imperative animation APIs can mutate arbitrary style fields. Observe
|
|
263
|
+
// references as well as calls so aliases cannot bypass the proof. Frame
|
|
264
|
+
// scheduling (requestAnimationFrame) is independent and stays available.
|
|
265
|
+
if (ts.isIdentifier(node) && /^(?:animate|KeyframeEffect|Animation|AnimationEngine|DeclarativeAnimations|Reflect)$/.test(node.text))
|
|
266
|
+
allStyles();
|
|
267
|
+
if (ts.isBindingElement(node) && /^(?:createElement|createElementNS|animate|setAttribute|insertRule|replaceSync)$/.test(node.propertyName?.getText(source).replace(/^['"]|['"]$/g, '') ?? node.name.getText(source)))
|
|
268
|
+
allStyles();
|
|
269
|
+
if (ts.isBindingElement(node) && node.propertyName && ts.isComputedPropertyName(node.propertyName) && literal(node.propertyName.expression) === undefined)
|
|
270
|
+
allStyles();
|
|
271
|
+
if (ts.isTaggedTemplateExpression(node) && ts.isTemplateExpression(node.template))
|
|
272
|
+
allStyles();
|
|
273
|
+
// Literal CSS also covers CSS templates, DOM setters and imported helpers.
|
|
274
|
+
if (ts.isStringLiteralLike(node))
|
|
275
|
+
css(node.text);
|
|
276
|
+
if (ts.isPropertyAccessExpression(node) || ts.isElementAccessExpression(node)) {
|
|
277
|
+
const name = member(node);
|
|
278
|
+
if (name && /^(?:setDevicePixelRatio|setViewportMetrics|devicePixelRatio)$/.test(name))
|
|
279
|
+
observer?.unknownRanges?.();
|
|
280
|
+
if (name && circleMethods.has(name))
|
|
281
|
+
features.add('renderer-circles');
|
|
282
|
+
if (name === 'dataset' || name === 'animate')
|
|
283
|
+
allStyles();
|
|
284
|
+
if (name && /^(?:setAttribute|insertRule|replaceSync)$/.test(name) && !(ts.isCallExpression(node.parent) && node.parent.expression === node))
|
|
285
|
+
allStyles();
|
|
286
|
+
if (name && /^(?:getOwnPropertyDescriptor|getOwnPropertyDescriptors|getPrototypeOf|setPrototypeOf|defineProperty|defineProperties)$/.test(name))
|
|
287
|
+
allStyles();
|
|
288
|
+
if ((name === 'createElement' || name === 'createElementNS') && !(ts.isCallExpression(node.parent) && node.parent.expression === node))
|
|
289
|
+
allStyles();
|
|
290
|
+
if (name === 'style') {
|
|
291
|
+
const parent = node.parent;
|
|
292
|
+
const knownMember = (ts.isPropertyAccessExpression(parent) || ts.isElementAccessExpression(parent)) && parent.expression === node;
|
|
293
|
+
const knownAssignment = ts.isBinaryExpression(parent) && parent.left === node;
|
|
294
|
+
if (!knownMember && !knownAssignment)
|
|
295
|
+
observer?.unknown();
|
|
296
|
+
}
|
|
297
|
+
if (name === 'setProperty' && !(ts.isCallExpression(node.parent) && node.parent.expression === node))
|
|
298
|
+
observer?.unknown();
|
|
299
|
+
}
|
|
300
|
+
// Native declarative animations can write style fields through data-anim.
|
|
301
|
+
if (ts.isJsxAttribute(node) && node.name.getText(source) === 'data-anim')
|
|
302
|
+
allStyles();
|
|
303
|
+
if (ts.isJsxAttribute(node) && node.name.getText(source) === 'dir')
|
|
304
|
+
observer?.property('direction', undefined);
|
|
305
|
+
if (ts.isJsxAttribute(node) && node.name.getText(source) === 'style' && node.initializer) {
|
|
306
|
+
if (ts.isJsxExpression(node.initializer) && node.initializer.expression)
|
|
307
|
+
styleObject(node.initializer.expression);
|
|
308
|
+
}
|
|
309
|
+
if (ts.isJsxSpreadAttribute(node)) {
|
|
310
|
+
const value = unwrap(node.expression);
|
|
311
|
+
if (ts.isObjectLiteralExpression(value)) {
|
|
312
|
+
for (const item of value.properties)
|
|
313
|
+
if (ts.isPropertyAssignment(item) && item.name.getText(source) === 'style')
|
|
314
|
+
styleObject(item.initializer);
|
|
315
|
+
}
|
|
316
|
+
else
|
|
317
|
+
allStyles();
|
|
318
|
+
}
|
|
319
|
+
// Property names are relevant even for aliases of el.style. This deliberately
|
|
320
|
+
// errs toward keeping a cache when an unrelated object has a style key.
|
|
321
|
+
if (ts.isPropertyAssignment(node)) {
|
|
322
|
+
const name = ts.isComputedPropertyName(node.name) ? literal(node.name.expression) : node.name.getText(source).replace(/^['"]|['"]$/g, '');
|
|
323
|
+
if (name === 'data-anim')
|
|
324
|
+
allStyles();
|
|
325
|
+
if (name !== undefined)
|
|
326
|
+
property(name, literal(node.initializer), node.initializer);
|
|
327
|
+
if (name === 'style')
|
|
328
|
+
styleObject(node.initializer);
|
|
329
|
+
}
|
|
330
|
+
if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.EqualsToken) {
|
|
331
|
+
const name = member(node.left);
|
|
332
|
+
if (name === 'dir')
|
|
333
|
+
observer?.property('direction', undefined);
|
|
334
|
+
if (name === 'innerHTML' || name === 'outerHTML' || name === 'adoptedStyleSheets')
|
|
335
|
+
allStyles();
|
|
336
|
+
if (name === 'style' || name === 'cssText')
|
|
337
|
+
styleObject(node.right);
|
|
338
|
+
else if (ts.isPropertyAccessExpression(node.left) || ts.isElementAccessExpression(node.left)) {
|
|
339
|
+
if (name !== undefined || isStyleTarget(node.left.expression))
|
|
340
|
+
property(name, literal(node.right), node.right);
|
|
341
|
+
else if (isStyleObjectReference(node.left.expression))
|
|
342
|
+
observer?.unknown();
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
if (ts.isCallExpression(node)) {
|
|
346
|
+
if (opaqueCallable(node.expression))
|
|
347
|
+
allStyles();
|
|
348
|
+
// A helper receiving a style object can mutate it through aliases,
|
|
349
|
+
// Object.assign or computed keys that this source scan cannot resolve.
|
|
350
|
+
if (node.arguments.some(argumentContainsStyle))
|
|
351
|
+
observer?.unknown();
|
|
352
|
+
const name = member(node.expression);
|
|
353
|
+
if ((ts.isPropertyAccessExpression(node.expression) || ts.isElementAccessExpression(node.expression)) && isStyleTarget(node.expression.expression) && name !== 'setProperty' && name !== 'removeProperty')
|
|
354
|
+
observer?.unknownRanges?.();
|
|
355
|
+
if (node.expression.kind === ts.SyntaxKind.ImportKeyword && literal(node.arguments[0]) === undefined) {
|
|
356
|
+
addUnknownRendererFeatures(features);
|
|
357
|
+
observer?.unknown();
|
|
358
|
+
}
|
|
359
|
+
if (name && circleMethods.has(name))
|
|
360
|
+
features.add('renderer-circles');
|
|
361
|
+
if (name === 'createLinearGradient')
|
|
362
|
+
features.add('renderer-linear-gradients');
|
|
363
|
+
if (name === 'createRadialGradient')
|
|
364
|
+
features.add('renderer-radial-gradients');
|
|
365
|
+
if (name === 'registerProperty')
|
|
366
|
+
allStyles();
|
|
367
|
+
if ((name === 'createElement' || name === 'createElementNS') && literal(node.arguments[name === 'createElementNS' ? 1 : 0]) === undefined)
|
|
368
|
+
allStyles();
|
|
369
|
+
if (name === 'createElement' && literal(node.arguments[0]) === 'style')
|
|
370
|
+
allStyles();
|
|
371
|
+
if (name === 'setAttribute' && literal(node.arguments[0]) === 'dir')
|
|
372
|
+
observer?.property('direction', undefined);
|
|
373
|
+
if (name === 'setProperty')
|
|
374
|
+
property(literal(node.arguments[0]), literal(node.arguments[1]), node.arguments[1]);
|
|
375
|
+
if (name === 'setAttribute' && (!literal(node.arguments[0]) || literal(node.arguments[0]) === 'data-anim'))
|
|
376
|
+
allStyles();
|
|
377
|
+
if (name === 'setAttribute' && literal(node.arguments[0]) === 'style') {
|
|
378
|
+
if (node.arguments[1])
|
|
379
|
+
styleObject(node.arguments[1]);
|
|
380
|
+
else
|
|
381
|
+
allStyles();
|
|
382
|
+
}
|
|
383
|
+
if (name === 'assign' && node.arguments[0] && isStyleTarget(node.arguments[0])) {
|
|
384
|
+
for (const arg of node.arguments.slice(1))
|
|
385
|
+
styleObject(arg);
|
|
386
|
+
}
|
|
387
|
+
if (name === 'insertRule' || name === 'replaceSync' || name === 'replace') {
|
|
388
|
+
if (node.arguments[0])
|
|
389
|
+
styleObject(node.arguments[0]);
|
|
390
|
+
}
|
|
391
|
+
// Unknown computed method dispatch may be a canvas operation or style API.
|
|
392
|
+
if (ts.isElementAccessExpression(node.expression) && name === undefined) {
|
|
393
|
+
addUnknownRendererFeatures(features);
|
|
394
|
+
observer?.unknown();
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
ts.forEachChild(node, visit);
|
|
398
|
+
};
|
|
399
|
+
// Style object declarations can precede their JSX use. The first pass
|
|
400
|
+
// discovers those bindings; the second also sees earlier mutations.
|
|
401
|
+
visit(source);
|
|
402
|
+
visit(source);
|
|
403
|
+
}
|
package/dist/analyze.js
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
|
+
import { sourceLiteralResolver } from './analyze-literals.js';
|
|
1
2
|
import fs from 'node:fs';
|
|
3
|
+
import { analyzeClassCapacity } from './analyze-classes.js';
|
|
4
|
+
import ts from 'typescript';
|
|
2
5
|
import path from 'node:path';
|
|
6
|
+
import { createRequire } from 'node:module';
|
|
7
|
+
import { nodeAnalysisVersion, addNodeFeatures, addUnknownNodeFeatures } from './analyze-nodes.js';
|
|
8
|
+
import { cssRangeObserver } from './analyze-css-ranges.js';
|
|
9
|
+
import { cssAnalysisVersion, cssUsageObserver, addUnknownCssFeatures } from './analyze-css.js';
|
|
10
|
+
import { addRendererFeatures, addUnknownRendererFeatures, rendererAnalysisVersion, rendererVariableAnalysis } from './analyze-renderer.js';
|
|
3
11
|
export function capabilitiesToAnalyzePatch(capabilities) {
|
|
4
12
|
const features = [];
|
|
5
13
|
const bindings = [];
|
|
@@ -21,16 +29,47 @@ export function capabilitiesToAnalyzePatch(capabilities) {
|
|
|
21
29
|
// connection with "No server verification option set".
|
|
22
30
|
export function analyzeSourceHostBindings(entry) {
|
|
23
31
|
const bindings = new Set();
|
|
24
|
-
const features = new Set();
|
|
25
|
-
|
|
32
|
+
const features = new Set([rendererAnalysisVersion, cssAnalysisVersion, nodeAnalysisVersion]);
|
|
33
|
+
const discovery = discoverSourceFiles(entry);
|
|
34
|
+
const classSources = new Map();
|
|
35
|
+
let classUnknown = discovery.unknown;
|
|
36
|
+
const variables = rendererVariableAnalysis(features);
|
|
37
|
+
const literalSources = new Map([...discovery.files].filter(file => fs.existsSync(file)).map(file => [file, fs.readFileSync(file, 'utf8')]));
|
|
38
|
+
const css = cssUsageObserver(features, sourceLiteralResolver(literalSources, discovery.unknown));
|
|
39
|
+
const ranges = cssRangeObserver(features);
|
|
40
|
+
const observer = {
|
|
41
|
+
selector(value) { css.selector?.(value); ranges.selector?.(value); },
|
|
42
|
+
property(name, value, expression) { css.property(name, value, expression); ranges.property(name, value); variables.property(name, value); },
|
|
43
|
+
unknown() { classUnknown = true; css.unknown(); ranges.unknown(); variables.unknown(); addUnknownNodeFeatures(features); },
|
|
44
|
+
unknownRanges() { ranges.unknown(); },
|
|
45
|
+
};
|
|
46
|
+
if (discovery.unknown) {
|
|
47
|
+
variables.unknown();
|
|
48
|
+
ranges.unknown();
|
|
49
|
+
addUnknownNodeFeatures(features);
|
|
50
|
+
}
|
|
51
|
+
if (discovery.unknown) {
|
|
52
|
+
addUnknownRendererFeatures(features);
|
|
53
|
+
addUnknownCssFeatures(features);
|
|
54
|
+
}
|
|
55
|
+
for (const file of discovery.files) {
|
|
26
56
|
if (!fs.existsSync(file))
|
|
27
57
|
continue;
|
|
28
58
|
const text = fs.readFileSync(file, 'utf8');
|
|
59
|
+
classSources.set(file, text);
|
|
29
60
|
addBindingsForGeaEmbeddedImports(text, bindings);
|
|
30
61
|
addBindingsForEmbeddedHostNames(text, bindings);
|
|
31
62
|
addBindingsForHostGlobals(text, bindings);
|
|
32
63
|
addFeaturesForUrlSchemes(text, features);
|
|
64
|
+
addRendererFeatures(file, text, features, observer, variables);
|
|
65
|
+
addNodeFeatures(file, text, features);
|
|
33
66
|
}
|
|
67
|
+
const classCapacity = analyzeClassCapacity(classSources, classUnknown || features.has('node-inputs') || features.has('node-images'));
|
|
68
|
+
if (classCapacity !== undefined)
|
|
69
|
+
features.add(`node-class-capacity-v1-${classCapacity}`);
|
|
70
|
+
variables.finish();
|
|
71
|
+
css.finish();
|
|
72
|
+
ranges.finish();
|
|
34
73
|
return { bindings: [...bindings].sort(), features: [...features].sort() };
|
|
35
74
|
}
|
|
36
75
|
export function mergeAnalyzePatches(...patches) {
|
|
@@ -144,6 +183,7 @@ function addBindingsForEmbeddedHostNames(text, bindings) {
|
|
|
144
183
|
function discoverSourceFiles(entry) {
|
|
145
184
|
const visited = new Set();
|
|
146
185
|
const files = [];
|
|
186
|
+
let unknown = false;
|
|
147
187
|
function visit(file) {
|
|
148
188
|
const resolved = path.resolve(file);
|
|
149
189
|
// An entry that is a directory (a configure run without app metadata)
|
|
@@ -152,30 +192,68 @@ function discoverSourceFiles(entry) {
|
|
|
152
192
|
return;
|
|
153
193
|
visited.add(resolved);
|
|
154
194
|
const text = fs.readFileSync(resolved, 'utf8');
|
|
155
|
-
for (const specifier of
|
|
156
|
-
|
|
195
|
+
for (const specifier of /\.css$/i.test(resolved) ? [] : moduleSpecifiers(resolved, text)) {
|
|
196
|
+
// Framework host imports do not inject renderer instructions. Other
|
|
197
|
+
// external code may supply styles/components we cannot inspect here.
|
|
198
|
+
if (/^(?:gea-embedded|@geastack\/(?:core|engine)|@geajs\/core)(?:\/|$)/.test(specifier))
|
|
199
|
+
continue;
|
|
200
|
+
const dependency = specifier.startsWith('.') ? resolveRelativeModule(resolved, specifier) : resolvePackageModule(resolved, specifier);
|
|
157
201
|
if (dependency)
|
|
158
202
|
visit(dependency);
|
|
203
|
+
else
|
|
204
|
+
unknown = true;
|
|
205
|
+
}
|
|
206
|
+
if (/\.css$/i.test(resolved)) {
|
|
207
|
+
for (const match of text.replace(/\/\*[\s\S]*?\*\//g, '').matchAll(/@import\s+(?:url\(\s*(?:['"]([^'"]+)['"]|([^\s)]+))\s*\)|['"]([^'"]+)['"])/g)) {
|
|
208
|
+
const specifier = match[1] ?? match[2] ?? match[3];
|
|
209
|
+
const dependency = !/^(?:[a-z]+:|\/)/i.test(specifier) && resolveRelativeModule(resolved, specifier);
|
|
210
|
+
if (dependency)
|
|
211
|
+
visit(dependency);
|
|
212
|
+
else
|
|
213
|
+
unknown = true;
|
|
214
|
+
}
|
|
159
215
|
}
|
|
160
216
|
files.push(resolved);
|
|
161
217
|
}
|
|
162
218
|
visit(entry);
|
|
163
|
-
|
|
219
|
+
if (!files.length)
|
|
220
|
+
unknown = true;
|
|
221
|
+
return { files, unknown };
|
|
164
222
|
}
|
|
165
|
-
function
|
|
223
|
+
function moduleSpecifiers(file, text) {
|
|
224
|
+
const source = ts.createSourceFile(file, text, ts.ScriptTarget.Latest, true, /\.[jt]sx$/i.test(file) ? ts.ScriptKind.TSX : ts.ScriptKind.TS);
|
|
166
225
|
const specifiers = [];
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
226
|
+
// An empty specifier deliberately fails resolution, retaining all features.
|
|
227
|
+
// A malformed or computed module boundary cannot establish absence of CSS.
|
|
228
|
+
if (source.parseDiagnostics?.length)
|
|
229
|
+
specifiers.push('');
|
|
230
|
+
const add = (expression) => {
|
|
231
|
+
specifiers.push(expression && ts.isStringLiteralLike(expression) ? expression.text : '');
|
|
232
|
+
};
|
|
233
|
+
const visit = (node) => {
|
|
234
|
+
if ((ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) && node.moduleSpecifier)
|
|
235
|
+
add(node.moduleSpecifier);
|
|
236
|
+
if (ts.isImportEqualsDeclaration(node) && ts.isExternalModuleReference(node.moduleReference))
|
|
237
|
+
add(node.moduleReference.expression);
|
|
238
|
+
if (ts.isCallExpression(node) && (node.expression.kind === ts.SyntaxKind.ImportKeyword ||
|
|
239
|
+
(ts.isIdentifier(node.expression) && node.expression.text === 'require')))
|
|
240
|
+
add(node.arguments[0]);
|
|
241
|
+
ts.forEachChild(node, visit);
|
|
242
|
+
};
|
|
243
|
+
visit(source);
|
|
171
244
|
return specifiers;
|
|
172
245
|
}
|
|
173
|
-
function
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
246
|
+
function resolvePackageModule(importer, specifier) {
|
|
247
|
+
// CSS package imports must be traversed just like relative stylesheets. For
|
|
248
|
+
// opaque JS packages keep the conservative feature set instead of assuming
|
|
249
|
+
// their exports cannot render anything.
|
|
250
|
+
if (!/\.css$/i.test(specifier))
|
|
251
|
+
return null;
|
|
252
|
+
try {
|
|
253
|
+
return createRequire(importer).resolve(specifier);
|
|
254
|
+
}
|
|
255
|
+
catch {
|
|
256
|
+
return null;
|
|
179
257
|
}
|
|
180
258
|
}
|
|
181
259
|
function resolveRelativeModule(importer, specifier) {
|
|
@@ -189,6 +267,8 @@ function resolveRelativeModule(importer, specifier) {
|
|
|
189
267
|
function moduleCandidates(base) {
|
|
190
268
|
const extensions = ['', '.ts', '.tsx', '.js', '.jsx', '.mjs', '.cjs'];
|
|
191
269
|
return [
|
|
270
|
+
// TypeScript's NodeNext imports commonly spell the emitted .js extension.
|
|
271
|
+
...(/\.[cm]?jsx?$/.test(base) ? [base.replace(/\.js$/, '.ts'), base.replace(/\.jsx?$/, '.tsx'), base.replace(/\.mjs$/, '.mts'), base.replace(/\.cjs$/, '.cts')] : []),
|
|
192
272
|
...extensions.map((extension) => `${base}${extension}`),
|
|
193
273
|
...extensions.filter(Boolean).map((extension) => path.join(base, `index${extension}`)),
|
|
194
274
|
];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
|
-
import { cppString, cssPropertyName, isPxLengthStylePropertyName, isRecord, isRuntimeNumericConstantIdentifier, nativeStyleColorExpression, opaqueCssHexColor, sanitizeCppIdentifier, styleDeclarationEnumForPropertyName, styleKeywordPropertiesForPropertyName, styleKeywordPropertyValuesForPropertyName, styleOpaqueColorTargetForPropertyName, stylePercentPropertyEnumForPropertyName, styleRawNumberPropertyEnumsForPropertyName, } from './utils.js';
|
|
2
|
+
import { cppString, cssPropertyName, isPxLengthStylePropertyName, isBorderWidthStylePropertyName, isRecord, isRuntimeNumericConstantIdentifier, nativeStyleColorExpression, opaqueCssHexColor, sanitizeCppIdentifier, styleDeclarationEnumForPropertyName, styleKeywordPropertiesForPropertyName, styleKeywordPropertyValuesForPropertyName, styleOpaqueColorTargetForPropertyName, stylePercentPropertyEnumForPropertyName, styleRawNumberPropertyEnumsForPropertyName, } from './utils.js';
|
|
3
3
|
// Whether the global store cell for `globalName` is the TYPED shared_ptr.
|
|
4
4
|
// geatsc core emits store singleton accessors as `std::shared_ptr<Class>&`
|
|
5
5
|
// for regular Store subclasses regardless of whether their runtime base is
|
|
@@ -591,6 +591,7 @@ function lowerRowPxLengthStyleExpression(expr, propertyName, itemName, field, co
|
|
|
591
591
|
return {
|
|
592
592
|
expr: loweredRowAsNumber(lowered),
|
|
593
593
|
shape: { kind: 'literal', valueType: 'number' },
|
|
594
|
+
styleUnit: 'px',
|
|
594
595
|
itemFields: lowered.itemFields,
|
|
595
596
|
storeFields: lowered.storeFields,
|
|
596
597
|
};
|
|
@@ -1701,7 +1702,7 @@ function lowerStorePxLengthStyleExpression(field, propertyName, storeFields) {
|
|
|
1701
1702
|
if (!ts.isPropertyAccessExpression(expr))
|
|
1702
1703
|
return null;
|
|
1703
1704
|
const lowered = lowerStoreFieldByName(expr.name.text, storeFieldLocalName(expr.name.text), storeFields);
|
|
1704
|
-
return lowered ? { ...lowered, shape: { kind: 'literal', valueType: 'number' } } : null;
|
|
1705
|
+
return lowered ? { ...lowered, shape: { kind: 'literal', valueType: 'number' }, styleUnit: 'px' } : null;
|
|
1705
1706
|
}
|
|
1706
1707
|
function lowerStorePercentLengthStyleExpression(field, propertyName, storeFields) {
|
|
1707
1708
|
if (!stylePercentPropertyEnumForPropertyName(propertyName) || !field.expr)
|
|
@@ -1857,6 +1858,10 @@ function storeFieldAsBoolean(store, expr) {
|
|
|
1857
1858
|
return `gea::runtime::coerce::to_boolean(gea_cpp_key(${expr}))`;
|
|
1858
1859
|
}
|
|
1859
1860
|
function directNumberStyleApplyLine(node, propertyName, value) {
|
|
1861
|
+
if (isBorderWidthStylePropertyName(propertyName)) {
|
|
1862
|
+
const declaration = styleDeclarationEnumForPropertyName(propertyName);
|
|
1863
|
+
return `gea::embedded::ui::StyleSheet::instance().applyNumberProperty(${node}, gea::embedded::ui::StyleDeclaration::${declaration}, static_cast<double>(${value}));`;
|
|
1864
|
+
}
|
|
1860
1865
|
const rawNumber = rawNumberExpression(value);
|
|
1861
1866
|
const properties = styleRawNumberPropertyEnumsForPropertyName(propertyName);
|
|
1862
1867
|
if (properties) {
|
|
@@ -1872,8 +1877,10 @@ function directNumberStyleApplyLine(node, propertyName, value) {
|
|
|
1872
1877
|
if (propertyName === 'translate-y')
|
|
1873
1878
|
return `${node}.style().translateY(${rawNumber});`;
|
|
1874
1879
|
if (propertyName === 'scale')
|
|
1875
|
-
return `${node}.style().
|
|
1876
|
-
if (propertyName === '
|
|
1880
|
+
return `${node}.style().cssScale(static_cast<double>(${value}));`;
|
|
1881
|
+
if (propertyName === 'rotate')
|
|
1882
|
+
return `${node}.style().cssRotateDegrees(static_cast<double>(${value}));`;
|
|
1883
|
+
if (propertyName === 'transform')
|
|
1877
1884
|
return `${node}.style().rotateDegrees(static_cast<double>(${value}));`;
|
|
1878
1885
|
return null;
|
|
1879
1886
|
}
|
|
@@ -1920,8 +1927,10 @@ function keywordCommonValue(entries) {
|
|
|
1920
1927
|
}
|
|
1921
1928
|
function directColorStyleApplyLine(node, propertyName, value) {
|
|
1922
1929
|
const target = styleOpaqueColorTargetForPropertyName(propertyName);
|
|
1923
|
-
if (target === 'background')
|
|
1924
|
-
|
|
1930
|
+
if (target === 'background') {
|
|
1931
|
+
const resetImage = propertyName === 'background' ? `${node}.style().set(gea::embedded::ui::Property::BackgroundImage, -1); ${node}.style().set(gea::embedded::ui::Property::BackgroundClip, 0); ` : '';
|
|
1932
|
+
return `${resetImage}${node}.style().backgroundColor(static_cast<int>(${value}));`;
|
|
1933
|
+
}
|
|
1925
1934
|
if (target === 'color')
|
|
1926
1935
|
return `${node}.style().color(static_cast<int>(${value}));`;
|
|
1927
1936
|
if (target === 'active-background') {
|
|
@@ -1951,6 +1960,15 @@ function stylePropertyArgument(propertyName) {
|
|
|
1951
1960
|
}
|
|
1952
1961
|
function styleApplyLines(node, propertyName, value, shape, styleUnit) {
|
|
1953
1962
|
const property = stylePropertyArgument(propertyName);
|
|
1963
|
+
if (styleUnit === 'px') {
|
|
1964
|
+
const declaration = styleDeclarationEnumForPropertyName(propertyName);
|
|
1965
|
+
if (declaration)
|
|
1966
|
+
return [`gea::embedded::ui::StyleSheet::instance().applyPixelLengthProperty(${node}, ${property}, static_cast<double>(${value}));`];
|
|
1967
|
+
const translated = directNumberStyleApplyLine(node, propertyName, `(${value}) * gea::embedded::ui::devicePixelRatio()`);
|
|
1968
|
+
if (!translated)
|
|
1969
|
+
throw new Error(`No CSS pixel style apply for ${propertyName}`);
|
|
1970
|
+
return [translated];
|
|
1971
|
+
}
|
|
1954
1972
|
if (shape?.kind === 'literal' && shape.valueType === 'number') {
|
|
1955
1973
|
const direct = styleUnit === 'percent'
|
|
1956
1974
|
? directPercentStyleApplyLine(node, propertyName, value)
|