@geastack/cli 0.1.85 → 0.1.87

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/README.md CHANGED
@@ -125,6 +125,14 @@ These commands update the app-local target definition. They do not copy native
125
125
  sources into the application; the target adapter compiles the selected drivers
126
126
  directly from the installed `@geastack/chips` package.
127
127
 
128
+ ## Wi-Fi updates for offline apps
129
+
130
+ An ESP32 app with no network API calls normally omits networking. Set
131
+ `gea.ota.wifi` to `true` in the app's `package.json` to retain Wi-Fi OTA and
132
+ remote diagnostics. Supply the usual `GEA_WIFI_SSID` and `GEA_WIFI_PASSWORD`
133
+ settings at build time. This declaration keeps networking available without
134
+ adding a network call to the app; it does not supply credentials.
135
+
128
136
  ## Development
129
137
 
130
138
  ```sh
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geastack/cli",
3
- "version": "0.1.85",
3
+ "version": "0.1.87",
4
4
  "description": "Command-line front door for GeaStack apps, targets, and local toolchains.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -37,18 +37,19 @@
37
37
  ],
38
38
  "dependencies": {
39
39
  "@clack/prompts": "^1.8.0",
40
- "@geastack/simulator": "^0.1.9",
41
- "@geastack/targets": "^0.1.82",
40
+ "@geastack/simulator": "^0.1.11",
41
+ "@geastack/targets": "^0.1.84",
42
42
  "picocolors": "^1.1.1",
43
43
  "serialport": "^13.0.0"
44
44
  },
45
45
  "starterDependencies": {
46
- "@geastack/core": "^0.1.26",
47
- "@geastack/targets": "^0.1.82",
46
+ "@geastack/core": "^0.1.30",
47
+ "@geastack/targets": "^0.1.84",
48
48
  "@geastack/apple": "^0.2.9"
49
49
  },
50
50
  "scripts": {
51
51
  "check": "node --check bin/gea.mjs && node --check bin/create-geastack.mjs && find src test packages -name '*.mjs' -print0 | xargs -0 -n1 node --check",
52
52
  "test": "node --test"
53
- }
53
+ },
54
+ "gitHead": "8be359ace7733940493c12494abb07db0c727f80"
54
55
  }
@@ -6,7 +6,7 @@ import { loadChipCatalogFromDir, writeCustomTarget } from '../boards/custom-targ
6
6
  import { CliError, ExitCode, fail } from '../errors.mjs'
7
7
  import { appCmakeMeta, appCmakeDefines, appCmakeLdFragments, appTargetConfig, appTargetPaths } from '../manifest.mjs'
8
8
  import { quietSteps, runQuiet } from '../run.mjs'
9
- import { resolveAppCapabilities } from './capabilities.mjs'
9
+ import { resolveAppCapabilities, withRendererFeatureDefines } from './capabilities.mjs'
10
10
  import { activateEspIdf, idfPyCommand } from './idf-env.mjs'
11
11
  import { Sdkconfig, prepareBuildLocalSdkconfig } from './sdkconfig.mjs'
12
12
  import { writePartitionTable } from './partitions-from-manifest.mjs'
@@ -416,7 +416,7 @@ function preparePartitions(app, config, buildDir, targetId) {
416
416
  // `set(... CACHE STRING ...)`, so a -D of the same name, which exists before
417
417
  // the board's CMakeLists runs, wins without the board knowing about apps.
418
418
  const cssDpr = cssDevicePixelRatioLiteral(app.cssDevicePixelRatio)
419
- const appDefines = [appCmakeDefines(app), cssDpr && `GEA_EMBEDDED_CSS_LAYOUT_DEVICE_PIXEL_RATIO=${cssDpr}`]
419
+ const appDefines = [withRendererFeatureDefines(appCmakeDefines(app), capabilities.features, { devicePixelRatio: cssDpr ? Number(cssDpr) : undefined }), cssDpr && `GEA_EMBEDDED_CSS_LAYOUT_DEVICE_PIXEL_RATIO=${cssDpr}`]
420
420
  .filter(Boolean)
421
421
  .join(';')
422
422
  const esp32Config = appEsp32Config
@@ -3,6 +3,7 @@ import path from 'node:path'
3
3
 
4
4
  import { ExitCode, fail } from '../errors.mjs'
5
5
  import { exists } from '../fs-utils.mjs'
6
+ import { withNativeCssFeatures } from './native-css-features.mjs'
6
7
 
7
8
  // What the firmware must link for this app. The compiler analyses the entry
8
9
  // (with the gea plugin) and reports the host bindings the program reaches;
@@ -10,6 +11,173 @@ import { exists } from '../fs-utils.mjs'
10
11
  // something actually uses them.
11
12
  const networkBindings = ['wifi', 'fetch', 'http', 'websocket', 'rtc']
12
13
 
14
+ const cssFeatureDefines = [
15
+ ['css-transforms', 'GEA_CSS_TRANSFORMS'],
16
+ ['css-grid', 'GEA_CSS_GRID'],
17
+ ['css-floats', 'GEA_CSS_FLOATS'],
18
+ ['css-writing-mode', 'GEA_CSS_WRITING_MODE'],
19
+ ['css-border-relief', 'GEA_CSS_BORDER_RELIEF']
20
+ ]
21
+
22
+ const cssV2FeatureDefines = [
23
+ ['css-blink', 'GEA_CSS_BLINK'],
24
+ ['css-order', 'GEA_CSS_ORDER'],
25
+ ['css-percent-radius', 'GEA_CSS_PERCENT_RADIUS'],
26
+ ['css-percent-gap', 'GEA_CSS_PERCENT_GAP']
27
+ ]
28
+
29
+ const cssV3FeatureDefines = [
30
+ ['css-opacity', 'GEA_CSS_OPACITY'],
31
+ ['css-text-decoration', 'GEA_CSS_TEXT_DECORATION'],
32
+ ['css-text-transform', 'GEA_CSS_TEXT_TRANSFORM'],
33
+ ['css-visibility', 'GEA_CSS_VISIBILITY'],
34
+ ['css-pointer-events', 'GEA_CSS_POINTER_EVENTS'],
35
+ ['css-mask', 'GEA_CSS_MASK'],
36
+ ['css-image-fit', 'GEA_CSS_IMAGE_FIT']
37
+ ]
38
+
39
+ const cssV4FeatureDefines = [
40
+ ['css-filters', 'GEA_CSS_FILTERS'],
41
+ ['css-box-shadow', 'GEA_CSS_BOX_SHADOW'],
42
+ ['css-flex-wrap', 'GEA_CSS_FLEX_WRAP'],
43
+ ['css-justify-items', 'GEA_CSS_JUSTIFY_ITEMS'],
44
+ ['css-align-content', 'GEA_CSS_ALIGN_CONTENT'],
45
+ ['css-align-self', 'GEA_CSS_ALIGN_SELF'],
46
+ ['css-min-width', 'GEA_CSS_MIN_WIDTH'],
47
+ ['css-height-expressions', 'GEA_CSS_HEIGHT_EXPRESSIONS']
48
+ ]
49
+
50
+ const cssV5FeatureDefines = [
51
+ ['css-z-index', 'GEA_CSS_Z_INDEX'],
52
+ ['css-aspect-ratio', 'GEA_CSS_ASPECT_RATIO'],
53
+ ['css-margin-trim', 'GEA_CSS_MARGIN_TRIM'],
54
+ ['css-containment', 'GEA_CSS_CONTAINMENT'],
55
+ ['css-justify-self', 'GEA_CSS_JUSTIFY_SELF'],
56
+ ['css-flex-line-count', 'GEA_CSS_FLEX_LINE_COUNT'],
57
+ ['css-box-expressions', 'GEA_CSS_BOX_EXPRESSIONS']
58
+ ]
59
+
60
+ const cssV6FeatureDefines = [
61
+ ['css-axis-gap', 'GEA_CSS_AXIS_GAP'],
62
+ ['css-corner-radius', 'GEA_CSS_CORNER_RADIUS']
63
+ ]
64
+
65
+ const cssV7FeatureDefines = [['css-first-line', 'GEA_CSS_FIRST_LINE']]
66
+
67
+ const cssV8FeatureDefines = [
68
+ ['css-side-borders', 'GEA_CSS_SIDE_BORDERS'],
69
+ ['css-background-layers', 'GEA_CSS_BACKGROUND_LAYERS'],
70
+ ['css-line-height-expressions', 'GEA_CSS_LINE_HEIGHT_EXPRESSIONS']
71
+ ]
72
+ const cssV9FeatureDefines = [['css-scrolling', 'GEA_CSS_SCROLLING']]
73
+ const cssV10FeatureDefines = [['css-flex-basis-expressions', 'GEA_CSS_FLEX_BASIS_EXPRESSIONS'], ['css-custom-property-lengths', 'GEA_CSS_CUSTOM_PROPERTY_LENGTHS']]
74
+ const cssV11FeatureDefines = [['css-max-height', 'GEA_CSS_MAX_HEIGHT'], ['css-flex-basis', 'GEA_CSS_FLEX_BASIS'], ['css-overflow-axes', 'GEA_CSS_OVERFLOW_AXES']]
75
+ const cssV12FeatureDefines = [['css-position-top', 'GEA_CSS_POSITION_TOP'], ['css-position-top-percent', 'GEA_CSS_POSITION_TOP_PERCENT'], ['css-position-right', 'GEA_CSS_POSITION_RIGHT'], ['css-position-right-percent', 'GEA_CSS_POSITION_RIGHT_PERCENT'], ['css-position-bottom', 'GEA_CSS_POSITION_BOTTOM'], ['css-position-bottom-percent', 'GEA_CSS_POSITION_BOTTOM_PERCENT'], ['css-position-left', 'GEA_CSS_POSITION_LEFT'], ['css-position-left-percent', 'GEA_CSS_POSITION_LEFT_PERCENT']]
76
+ const cssV13FeatureDefines = [['css-animations', 'GEA_CSS_ANIMATIONS']]
77
+ const cssV14FeatureDefines = [['css-text-alpha', 'GEA_CSS_TEXT_ALPHA'], ['css-border-alpha', 'GEA_CSS_BORDER_ALPHA']]
78
+ const cssV15FeatureDefines = [['css-pseudo-elements', 'GEA_CSS_PSEUDO_ELEMENTS']]
79
+ const cssV16FeatureDefines = [['css-flex-direction', 'GEA_CSS_FLEX_DIRECTION'], ['css-justify-content', 'GEA_CSS_JUSTIFY_CONTENT'], ['css-align-items', 'GEA_CSS_ALIGN_ITEMS'], ['css-box-sizing', 'GEA_CSS_BOX_SIZING'], ['css-margin-auto', 'GEA_CSS_MARGIN_AUTO'], ['css-line-height-multiplier', 'GEA_CSS_LINE_HEIGHT_MULTIPLIER'], ['css-width-expressions', 'GEA_CSS_WIDTH_EXPRESSIONS'], ['css-min-height', 'GEA_CSS_MIN_HEIGHT'], ['css-max-width', 'GEA_CSS_MAX_WIDTH'], ['css-active-background', 'GEA_CSS_ACTIVE_BACKGROUND']]
80
+ const cssV17FeatureDefines = [['css-margins', 'GEA_CSS_MARGINS'], ['css-padding', 'GEA_CSS_PADDING'], ['css-flex-factors', 'GEA_CSS_FLEX_FACTORS'], ['css-gap', 'GEA_CSS_GAP'], ['css-border-widths', 'GEA_CSS_BORDER_WIDTHS'], ['css-border-colors', 'GEA_CSS_BORDER_COLORS'], ['css-font-weight', 'GEA_CSS_FONT_WEIGHT'], ['css-text-align', 'GEA_CSS_TEXT_ALIGN'], ['css-white-space', 'GEA_CSS_WHITE_SPACE'], ['css-text-overflow', 'GEA_CSS_TEXT_OVERFLOW']]
81
+ const cssV18FeatureDefines = [['css-custom-properties', 'GEA_CSS_CUSTOM_PROPERTIES']]
82
+ const cssV19FeatureDefines = [['css-width-percent', 'GEA_CSS_WIDTH_PERCENT'], ['css-height-percent', 'GEA_CSS_HEIGHT_PERCENT']]
83
+ const cssFeatureVersions = [cssFeatureDefines, cssV2FeatureDefines, cssV3FeatureDefines, cssV4FeatureDefines, cssV5FeatureDefines, cssV6FeatureDefines, cssV7FeatureDefines, cssV8FeatureDefines, cssV9FeatureDefines, cssV10FeatureDefines, cssV11FeatureDefines, cssV12FeatureDefines, cssV13FeatureDefines, cssV14FeatureDefines, cssV15FeatureDefines, cssV16FeatureDefines, cssV17FeatureDefines, cssV18FeatureDefines, cssV19FeatureDefines]
84
+
85
+ const rendererFeatureDefines = [
86
+ ['renderer-circles', 'GEA_EMBEDDED_RENDERER_CIRCLES'],
87
+ ['renderer-transforms', 'GEA_EMBEDDED_RENDERER_TRANSFORMS'],
88
+ ['renderer-linear-gradients', 'GEA_EMBEDDED_RENDERER_LINEAR_GRADIENTS'],
89
+ ['renderer-radial-gradients', 'GEA_EMBEDDED_RENDERER_RADIAL_GRADIENTS']
90
+ ]
91
+
92
+ const triangleOcclusionMacro = 'GEA_EMBEDDED_RENDERER_TRIANGLE_OCCLUSION'
93
+ const circleCacheMacros = ['GEA_EMBEDDED_CANVAS_CIRCLE_RADIUS_MAX', 'GEA_EMBEDDED_CANVAS_CIRCLE_BOX_SPAN_MAX', 'GEA_EMBEDDED_CANVAS_CIRCLE_SPAN_MAX', 'GEA_EMBEDDED_CANVAS_CIRCLE_BOX_SPAN_SLOTS']
94
+ const rangeFamilies = ['padding', 'gap', 'border', 'radius', 'font', 'line-height', 'flex']
95
+ const compactStyleDefines = [['css-line-height', 'GEA_CSS_LINE_HEIGHT'], ['css-display-explicit', 'GEA_CSS_DISPLAY_EXPLICIT']]
96
+ const nodeAuxFeatureDefines = [['node-listeners', 'GEA_UI_NODE_LISTENERS'], ['node-attributes', 'GEA_UI_NODE_ATTRIBUTES'], ['node-default-styles', 'GEA_UI_DEFAULT_STYLES']]
97
+ const nodeFeatureDefines = [['node-images', 'GEA_UI_IMAGE_NODES'], ['node-inputs', 'GEA_UI_INPUT_NODES']]
98
+ const rangeMacro = family => `GEA_CSS_U8_${family.replaceAll('-', '_').toUpperCase()}`
99
+
100
+ export function withRendererFeatureDefines(defines, features, { devicePixelRatio } = {}) {
101
+ // An older plugin knows nothing about renderer features. Absence without the
102
+ // version marker is not proof of unreachability: retain engine defaults.
103
+ const generatedNames = new Set([...rendererFeatureDefines, ...cssFeatureVersions.flat(), ...nodeFeatureDefines, ...nodeAuxFeatureDefines, ...compactStyleDefines].map(([, name]) => name).concat(triangleOcclusionMacro, circleCacheMacros, rangeFamilies.map(rangeMacro), ['GEA_UI_CLASS_INLINE_TOKENS', 'GEA_UI_CLASS_OVERFLOW']))
104
+ const result = defines.split(';').filter((define) => define && !generatedNames.has(define.split('=')[0]))
105
+ if (features.includes('node-analysis-v1')) {
106
+ for (const [feature, name] of nodeFeatureDefines) result.push(`${name}=${features.includes(feature) ? 1 : 0}`)
107
+ }
108
+ const storageProofs = features.filter(feature => feature.startsWith('css-storage-'))
109
+ if (storageProofs.length && storageProofs.every(proof => proof === 'css-storage-v1')) {
110
+ for (const [feature, name] of compactStyleDefines)
111
+ result.push(`${name}=${features.includes(feature) || features.includes('node-inputs') || features.includes('node-images') ? 1 : 0}`)
112
+ }
113
+ const auxiliaryProofs = features.filter(feature => feature.startsWith('node-aux-'))
114
+ if (auxiliaryProofs.length && auxiliaryProofs.every(proof => proof === 'node-aux-v1')) {
115
+ for (const [feature, name] of nodeAuxFeatureDefines)
116
+ result.push(`${name}=${features.includes(feature) || features.includes('node-inputs') || features.includes('node-images') ? 1 : 0}`)
117
+ }
118
+ const classBounds = features.filter(feature => feature.startsWith('node-class-capacity-v1-')).map(feature => feature.slice('node-class-capacity-v1-'.length))
119
+ if (!features.includes('node-inputs') && !features.includes('node-images') && classBounds.length && classBounds.every(bound => /^[123]$/.test(bound))) {
120
+ result.push(`GEA_UI_CLASS_INLINE_TOKENS=${Math.max(...classBounds.map(Number))}`)
121
+ const storageProofs = features.filter(feature => feature.startsWith('node-class-storage-'))
122
+ const complete = classBounds.every(bound => storageProofs.includes(`node-class-storage-v1-${bound}`))
123
+ if (complete && storageProofs.every(proof => /^node-class-storage-v1-[123]$/.test(proof)) &&
124
+ storageProofs.every(proof => classBounds.includes(proof.slice('node-class-storage-v1-'.length))))
125
+ result.push('GEA_UI_CLASS_OVERFLOW=0')
126
+ }
127
+ const occlusionProofs = features.filter(feature => /^renderer-occlusion-v/.test(feature))
128
+ if (occlusionProofs.length && occlusionProofs.every(feature => feature === 'renderer-occlusion-v1'))
129
+ result.push(`${triangleOcclusionMacro}=${features.includes('renderer-occlusion-triangles') ? 1 : 0}`)
130
+ if (features.includes('renderer-analysis-v1')) {
131
+ for (const [feature, name] of rendererFeatureDefines) result.push(`${name}=${features.includes(feature) ? 1 : 0}`)
132
+ }
133
+ // Each marker proves only families known to that analyzer. Future/unknown
134
+ // markers retain defaults until this CLI explicitly understands them.
135
+ const version = cssFeatureVersions.reduce((known, _, index) => features.includes(`css-analysis-v${index + 1}`) ? index + 1 : known, 0)
136
+ const sizePercentProofs = features.filter(feature => feature.startsWith('css-analysis-'))
137
+ const completeSizePercentProof = sizePercentProofs.length > 0 && sizePercentProofs.every(feature => feature === 'css-analysis-v19')
138
+ for (const families of cssFeatureVersions.slice(0, version)) {
139
+ if (families === cssV19FeatureDefines && !completeSizePercentProof) continue
140
+ for (const [feature, name] of families) {
141
+ const nativeDefaults = /^(?:GEA_CSS_TEXT_ALPHA|GEA_CSS_BORDER_ALPHA|GEA_CSS_WIDTH_PERCENT|GEA_CSS_HEIGHT_PERCENT)$/.test(name) && (features.includes('node-inputs') || features.includes('node-images'))
142
+ result.push(`${name}=${features.includes(feature) || nativeDefaults ? 1 : 0}`)
143
+ }
144
+ }
145
+ // Width selection needs a positive whole-program range proof as well as
146
+ // the actual layout DPR. Unknown/older analyzers keep the engine's wide types.
147
+ if (features.includes('css-ranges-v1')) {
148
+ const definedRatio = result.findLast(define => define.startsWith('GEA_EMBEDDED_CSS_LAYOUT_DEVICE_PIXEL_RATIO='))?.split('=')[1]
149
+ const ratio = devicePixelRatio ?? (definedRatio === undefined ? 1 : Number(definedRatio))
150
+ const known = !features.includes('css-ranges-unknown') && Number.isFinite(ratio) && ratio > 0
151
+ for (const family of rangeFamilies) {
152
+ const bound = unit => {
153
+ const prefix = `css-range-${family}-${unit}-`
154
+ const values = features.filter(feature => feature.startsWith(prefix)).map(feature => feature.slice(prefix.length))
155
+ return values.length === 1 && /^\d+$/.test(values[0]) && Number.isSafeInteger(Number(values[0])) ? Number(values[0]) : Infinity
156
+ }
157
+ const maximum = Math.max(bound('raw'), bound('px') * ratio)
158
+ result.push(`${rangeMacro(family)}=${known && maximum <= 255 ? 1 : 0}`)
159
+ // Bound all circle paths only with the separate imperative-drawing proof.
160
+ // Effects/borders may expand a painted radius beyond its CSS border box.
161
+ const unboundedEffects = ['renderer-transforms', 'css-box-shadow', 'css-border-widths', 'css-border-relief', 'css-filters', 'css-text-decoration']
162
+ if (family === 'radius' && version >= 18 && known && Number.isFinite(maximum) &&
163
+ features.includes('renderer-analysis-v1') && features.includes('css-circle-cache-v1') &&
164
+ !features.includes('css-circle-cache-unbounded') &&
165
+ features.filter(feature => feature.startsWith('css-circle-cache-')).every(feature => feature === 'css-circle-cache-v1') && !unboundedEffects.some(feature => features.includes(feature))) {
166
+ const radius = Math.max(1, Math.ceil(maximum))
167
+ result.push(`${circleCacheMacros[0]}=${Math.min(63, radius)}`)
168
+ // roundedRectIsCircleLike accepts floor(side / 2) - 1 <= radius,
169
+ // so the largest square using the box cache is 2 * radius + 3.
170
+ result.push(`${circleCacheMacros[1]}=${Math.min(128, radius * 2 + 3)}`)
171
+ result.push(`${circleCacheMacros[2]}=${Math.min(32, radius * 2)}`)
172
+ // The box shortcut starts at side 16. Retain one slot for every
173
+ // possible cached side, up to the existing capacity of sixteen.
174
+ result.push(`${circleCacheMacros[3]}=${Math.max(1, Math.min(16, radius * 2 + 3 - 15))}`)
175
+ }
176
+ }
177
+ }
178
+ return result.join(';')
179
+ }
180
+
13
181
  export function parseAnalysis(output) {
14
182
  const bindings = output.match(/^bindings=(.*)$/m)?.[1]?.split(';').filter(Boolean) ?? []
15
183
  const features = output.match(/^features=(.*)$/m)?.[1]?.split(';').filter(Boolean) ?? []
@@ -41,10 +209,10 @@ export function analyzeApp(ctx, app, { env = ctx.env || process.env } = {}) {
41
209
  export function resolveAppCapabilities(ctx, app, options = {}) {
42
210
  const analysis = analyzeApp(ctx, app, options)
43
211
  const bindings = new Set(analysis.bindings)
44
- const features = new Set(analysis.features)
212
+ const features = new Set(withNativeCssFeatures(app, analysis.features))
45
213
  const manifestBleOta = manifestRequestsBleOta(app.packageJson)
46
214
  return {
47
- network: networkBindings.some((binding) => bindings.has(binding)) || features.has('https'),
215
+ network: networkBindings.some((binding) => bindings.has(binding)) || features.has('https') || app.packageJson?.gea?.ota?.wifi === true,
48
216
  ble: bindings.has('ble') || manifestBleOta,
49
217
  bleApi: bindings.has('ble'),
50
218
  audio: bindings.has('audio'),
@@ -0,0 +1,94 @@
1
+ import fs from 'node:fs'
2
+ import path from 'node:path'
3
+ import { resolveAppSourcePath } from '../manifest.mjs'
4
+
5
+ const families = ['css-line-height', 'css-display-explicit', 'css-width-percent', 'css-height-percent', 'css-custom-properties', 'css-margins', 'css-padding', 'css-flex-factors', 'css-gap', 'css-border-widths', 'css-border-colors', 'css-font-weight', 'css-text-align', 'css-white-space', 'css-text-overflow', 'css-flex-direction', 'css-justify-content', 'css-align-items', 'css-box-sizing', 'css-margin-auto', 'css-line-height-multiplier', 'css-width-expressions', 'css-min-height', 'css-max-width', 'css-active-background', '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']
6
+ const sourceExtension = /\.(?:c|cc|cpp|cxx|h|hh|hpp|hxx|S)$/
7
+ const ignored = new Set(['.git', '.gea', 'node_modules', 'build', 'dist', '.build', '.venv'])
8
+ const privateUiHeader = /(?:^|\/)(?:node(?:_model|_lifecycle)?|tree(?:_internal|_state)?|style(?:_values)?|document|internal|view_element|text_element)\.h$/
9
+
10
+ export function nativeCssSourceNeedsSupport(text) {
11
+ // Native code using the mutable UI API can pass computed property names or
12
+ // values at runtime. Retain all CSS automatically in that case. Read-only
13
+ // inspection has a distinct header and exposes no mutable node/style data.
14
+ if (/#\s*include\s+(?![<"])[A-Za-z_]/.test(text)) return true
15
+ for (const match of text.matchAll(/#\s*include\s*[<"]([^>"\n]+)[>"]/g)) {
16
+ const header = match[1].replaceAll('\\', '/')
17
+ if (header.endsWith('ui/tree_inspection.h')) continue
18
+ if (header.startsWith('css/') || header.startsWith('ui/') || privateUiHeader.test(header)) return true
19
+ }
20
+ return /\b(?:AnimationEngine|DeclarativeAnimations|ComputedStyle|StyleSheet|CssCompiledValue|CssDeclarationId|NodeText|NodeType|NodeClassList|ImageElement|InputElement|VirtualKeyboard)\b|\bProperty\s*::|(?:\.|->)\s*(?:style|cssText)\b|\b(?:setClassName|classList|setProperty|applyTransformComponentsFast|applyTransformSlotsFast|setDevicePixelRatio|setViewportMetrics|gea_style_set_device_pixel_ratio|gea_style_set_viewport_metrics)\s*\(/.test(text)
21
+ }
22
+
23
+ // App-supplied native drawing has no source-level CSS radius bound. Keep its
24
+ // span caches without unnecessarily retaining unrelated CSS fields.
25
+ export function nativeCircleSourceNeedsSupport(text) {
26
+ return /#\s*include\s*[<"](?:[^>"\n]*\/)?(?:canvas|display|canvas_element)\.h[>"]|\b(?:Canvas|CanvasElement|CanvasContext|CircleEntry|Display)\b|\b(?:fillCircle\w*|strokeCircle|fillRoundedRect\w*|strokeRoundedRect|drawImageCircle|drawImageRounded)\b/.test(text)
27
+ }
28
+
29
+ export function withNativeCssFeatures(app, features) {
30
+ if (!features.includes('renderer-occlusion-v1') && !features.includes('node-analysis-v1') && !features.includes('node-aux-v1') && !features.includes('css-storage-v1') && !features.some(feature => /^node-class-capacity-v1-[123]$/.test(feature)) && !features.some(feature => /^css-analysis-v(?:[1-9]|1[0123456789])$/.test(feature))) return features
31
+ const sources = app.nativeSources || []
32
+ const components = app.targetConfig?.esp32?.componentDirs || []
33
+ if (!sources.length && !components.length) return features
34
+ // The TS proof cannot bound custom native triangle producers, including
35
+ // rendering hidden behind external headers or callback registration.
36
+ features = [...new Set([...features, 'renderer-occlusion-triangles', 'node-listeners', 'node-attributes', 'node-default-styles'])]
37
+ // Opaque native CSS writes can supply gradient/transform values even when
38
+ // every source-visible custom property is a literal colour. Keep their
39
+ // renderer caches as well as semantic fields.
40
+ const retain = () => [...new Set([...features.filter(feature => !feature.startsWith('node-class-capacity-') && !feature.startsWith('node-class-storage-')), ...families, 'node-images', 'node-inputs', 'css-ranges-unknown', 'css-circle-cache-unbounded', 'renderer-circles', 'renderer-occlusion-triangles', 'renderer-transforms', 'renderer-linear-gradients', 'renderer-radial-gradients'])].sort()
41
+ const root = path.resolve(app.root)
42
+ const headers = new Map()
43
+ const seen = new Set()
44
+ const pending = []
45
+ let opaque = false
46
+ function walk(dir, collectSources = false) {
47
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
48
+ const file = path.join(dir, entry.name)
49
+ if (entry.isDirectory()) {
50
+ if (!ignored.has(entry.name)) walk(file, collectSources)
51
+ } else if (sourceExtension.test(entry.name)) {
52
+ if (/\.(?:h|hh|hpp|hxx)$/.test(entry.name)) {
53
+ const matches = headers.get(entry.name) || []
54
+ matches.push(file)
55
+ headers.set(entry.name, matches)
56
+ }
57
+ if (collectSources) pending.push(file)
58
+ } else if (collectSources && /\.(?:a|so|dylib|lib)$/.test(entry.name)) opaque = true
59
+ }
60
+ }
61
+ try {
62
+ walk(root)
63
+ for (const source of sources) {
64
+ const resolved = resolveAppSourcePath(root, source)
65
+ if (!resolved || !resolved.startsWith(root + path.sep)) return retain()
66
+ pending.push(resolved)
67
+ }
68
+ for (const component of components) {
69
+ const dir = path.resolve(root, component)
70
+ if (!dir.startsWith(root + path.sep)) return retain()
71
+ walk(dir, true)
72
+ }
73
+ while (pending.length && !opaque) {
74
+ const file = pending.pop()
75
+ if (seen.has(file)) continue
76
+ seen.add(file)
77
+ const text = fs.readFileSync(file, 'utf8')
78
+ if (nativeCircleSourceNeedsSupport(text)) features = [...new Set([...features, 'css-circle-cache-unbounded', 'renderer-circles'])]
79
+ if (nativeCssSourceNeedsSupport(text)) return retain()
80
+ // Follow app headers, including headers provided by another component's
81
+ // include directory. ESP-IDF and C/C++ platform headers do not depend on
82
+ // the UI engine. An external native package is opaque above.
83
+ for (const match of text.matchAll(/#\s*include\s*[<"]([^>"\n]+)[>"]/g)) {
84
+ const header = match[1]
85
+ const local = path.resolve(path.dirname(file), header)
86
+ if (fs.existsSync(local)) pending.push(local)
87
+ else for (const candidate of headers.get(path.basename(header)) || []) pending.push(candidate)
88
+ }
89
+ }
90
+ } catch {
91
+ return retain()
92
+ }
93
+ return opaque ? retain() : features
94
+ }