@geastack/geatsc-plugin-gea 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +37 -0
- package/dist/analyze.d.ts +4 -0
- package/dist/analyze.js +195 -0
- package/dist/cpp-canvas-colors.d.ts +4 -0
- package/dist/cpp-canvas-colors.js +226 -0
- package/dist/cpp-field-access.d.ts +49 -0
- package/dist/cpp-field-access.js +144 -0
- package/dist/cpp-ir-dom-style.d.ts +1 -0
- package/dist/cpp-ir-dom-style.js +49 -0
- package/dist/cpp-ir.d.ts +30 -0
- package/dist/cpp-ir.js +2426 -0
- package/dist/cpp-keyed-component-diagnostics.d.ts +8 -0
- package/dist/cpp-keyed-component-diagnostics.js +74 -0
- package/dist/cpp-keyed-list-diagnostics.d.ts +17 -0
- package/dist/cpp-keyed-list-diagnostics.js +84 -0
- package/dist/cpp-mounted-lowering.d.ts +81 -0
- package/dist/cpp-mounted-lowering.js +2235 -0
- package/dist/cpp-mounted.d.ts +25 -0
- package/dist/cpp-mounted.js +1376 -0
- package/dist/cpp-reactive-component-diagnostics.d.ts +2 -0
- package/dist/cpp-reactive-component-diagnostics.js +76 -0
- package/dist/cpp-reactive-component.d.ts +14 -0
- package/dist/cpp-reactive-component.js +349 -0
- package/dist/cpp-replacements.d.ts +14 -0
- package/dist/cpp-replacements.js +787 -0
- package/dist/cpp-source-replacements.d.ts +11 -0
- package/dist/cpp-source-replacements.js +257 -0
- package/dist/cpp-store-hub.d.ts +7 -0
- package/dist/cpp-store-hub.js +160 -0
- package/dist/cpp-store-method-body-parser.d.ts +2 -0
- package/dist/cpp-store-method-body-parser.js +392 -0
- package/dist/cpp-store-method-context.d.ts +48 -0
- package/dist/cpp-store-method-context.js +114 -0
- package/dist/cpp-store-method-expressions.d.ts +12 -0
- package/dist/cpp-store-method-expressions.js +1263 -0
- package/dist/cpp-store-method-replacements.d.ts +5 -0
- package/dist/cpp-store-method-replacements.js +1521 -0
- package/dist/cpp-store-method-targets.d.ts +19 -0
- package/dist/cpp-store-method-targets.js +296 -0
- package/dist/cpp-store-typed-arrays.d.ts +2 -0
- package/dist/cpp-store-typed-arrays.js +655 -0
- package/dist/cpp-stores.d.ts +73 -0
- package/dist/cpp-stores.js +1739 -0
- package/dist/cpp-template-renderer.d.ts +23 -0
- package/dist/cpp-template-renderer.js +3530 -0
- package/dist/css-style-declaration-shims.d.ts +3 -0
- package/dist/css-style-declaration-shims.js +47 -0
- package/dist/host-declarations.d.ts +11 -0
- package/dist/host-declarations.js +320 -0
- package/dist/host-shims.d.ts +3 -0
- package/dist/host-shims.js +3217 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +1239 -0
- package/dist/load-ir.d.ts +7 -0
- package/dist/load-ir.js +40 -0
- package/dist/types.d.ts +604 -0
- package/dist/types.js +1 -0
- package/dist/utils.d.ts +26 -0
- package/dist/utils.js +723 -0
- package/dist/validate.d.ts +3 -0
- package/dist/validate.js +226 -0
- package/package.json +57 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# @geastack/geatsc-plugin-gea
|
|
2
|
+
|
|
3
|
+
The Gea backend plugin for `geatsc`, the GeaStack TypeScript-to-C++ compiler.
|
|
4
|
+
It teaches the compiler the Gea framework: which globals are host functions,
|
|
5
|
+
how reactive stores and components lower, and how the app's Gea IR becomes C++.
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install @geastack/geatsc-plugin-gea
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## What it does
|
|
12
|
+
|
|
13
|
+
- Declares the Gea host surface so calls into the framework compile to the
|
|
14
|
+
runtime's C++ entry points instead of being refused as unknown globals.
|
|
15
|
+
- Lowers the Gea IR that the Vite build emits into the C++ that mounts the
|
|
16
|
+
element tree, wires stores and reactive components, and applies styles.
|
|
17
|
+
- Analyzes the app source for the host bindings it actually uses so the target
|
|
18
|
+
compiles only what the app needs.
|
|
19
|
+
|
|
20
|
+
## How it is loaded
|
|
21
|
+
|
|
22
|
+
`@geastack/core`'s build driver resolves this package and passes it to the
|
|
23
|
+
compiler; an app never references it directly. The same can be done by hand:
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
geatsc compile-module-graph gea-module-graph.json --entry src/index.tsx \
|
|
27
|
+
--plugin @geastack/geatsc-plugin-gea
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
The module's default export is the plugin factory, as described in the
|
|
31
|
+
compiler's `docs/CLI-PLUGINS.md`. `@geastack/geatsc-plugin-gea/host-shims` and
|
|
32
|
+
`@geastack/geatsc-plugin-gea/cpp-ir` are exported for tools that need the
|
|
33
|
+
tables without the plugin.
|
|
34
|
+
|
|
35
|
+
## License
|
|
36
|
+
|
|
37
|
+
Apache-2.0. See `LICENSE`.
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { HostBindingAnalysisPatch } from './types.js';
|
|
2
|
+
export declare function capabilitiesToAnalyzePatch(capabilities: string[]): HostBindingAnalysisPatch;
|
|
3
|
+
export declare function analyzeSourceHostBindings(entry: string): HostBindingAnalysisPatch;
|
|
4
|
+
export declare function mergeAnalyzePatches(...patches: HostBindingAnalysisPatch[]): HostBindingAnalysisPatch;
|
package/dist/analyze.js
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
export function capabilitiesToAnalyzePatch(capabilities) {
|
|
4
|
+
const features = [];
|
|
5
|
+
const bindings = [];
|
|
6
|
+
for (const capability of capabilities) {
|
|
7
|
+
if (capability === 'https')
|
|
8
|
+
features.push(capability);
|
|
9
|
+
else
|
|
10
|
+
bindings.push(capability);
|
|
11
|
+
}
|
|
12
|
+
return { bindings, features };
|
|
13
|
+
}
|
|
14
|
+
// The source scan runs at CMake configure time, before any bundle or IR
|
|
15
|
+
// exists, so it is the only authority the board build has for what the
|
|
16
|
+
// firmware must link. It therefore has to answer the IR's `hostCapabilities`
|
|
17
|
+
// questions from text alone: which host bindings are imported, which host
|
|
18
|
+
// globals are called, and whether any URL needs TLS. A miss is silent and
|
|
19
|
+
// expensive -- an app whose `https://` literal is not seen is built without
|
|
20
|
+
// the certificate bundle, and ESP-IDF 6's esp-tls then refuses every
|
|
21
|
+
// connection with "No server verification option set".
|
|
22
|
+
export function analyzeSourceHostBindings(entry) {
|
|
23
|
+
const bindings = new Set();
|
|
24
|
+
const features = new Set();
|
|
25
|
+
for (const file of discoverSourceFiles(entry)) {
|
|
26
|
+
if (!fs.existsSync(file))
|
|
27
|
+
continue;
|
|
28
|
+
const text = fs.readFileSync(file, 'utf8');
|
|
29
|
+
addBindingsForGeaEmbeddedImports(text, bindings);
|
|
30
|
+
addBindingsForEmbeddedHostNames(text, bindings);
|
|
31
|
+
addBindingsForHostGlobals(text, bindings);
|
|
32
|
+
addFeaturesForUrlSchemes(text, features);
|
|
33
|
+
}
|
|
34
|
+
return { bindings: [...bindings].sort(), features: [...features].sort() };
|
|
35
|
+
}
|
|
36
|
+
export function mergeAnalyzePatches(...patches) {
|
|
37
|
+
const bindings = new Set();
|
|
38
|
+
const features = new Set();
|
|
39
|
+
for (const patch of patches) {
|
|
40
|
+
for (const binding of patch.bindings ?? [])
|
|
41
|
+
bindings.add(binding);
|
|
42
|
+
for (const feature of patch.features ?? [])
|
|
43
|
+
features.add(feature);
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
bindings: [...bindings].sort(),
|
|
47
|
+
features: [...features].sort(),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
const importBindingNames = new Map([
|
|
51
|
+
['Apps', 'apps'],
|
|
52
|
+
['BLE', 'ble'],
|
|
53
|
+
['BLEServer', 'ble'],
|
|
54
|
+
['WiFi', 'wifi'],
|
|
55
|
+
// The device HTTP server runs on lwip; importing `http` pulls in the same
|
|
56
|
+
// WiFi/network bring-up binding so the TCP/IP stack is initialized.
|
|
57
|
+
['http', 'wifi'],
|
|
58
|
+
['Accelerometer', 'imu'],
|
|
59
|
+
['Audio', 'audio'],
|
|
60
|
+
['Display', 'display'],
|
|
61
|
+
['Memory', 'memory'],
|
|
62
|
+
['Input', 'input'],
|
|
63
|
+
['audioContext', 'audio'],
|
|
64
|
+
['loadImage', 'image'],
|
|
65
|
+
['Camera', 'camera'],
|
|
66
|
+
['CameraView', 'camera'],
|
|
67
|
+
]);
|
|
68
|
+
const embeddedHostNamePrefixes = [
|
|
69
|
+
['__gea_Accelerometer', 'imu'],
|
|
70
|
+
['__gea_audioContext', 'audio'],
|
|
71
|
+
['__gea_Audio', 'audio'],
|
|
72
|
+
['__gea_Display', 'display'],
|
|
73
|
+
['__gea_Memory', 'memory'],
|
|
74
|
+
['__gea_Camera', 'camera'],
|
|
75
|
+
];
|
|
76
|
+
const namespaceImportBindings = ['apps', 'audio', 'ble', 'camera', 'display', 'image', 'imu', 'memory', 'wifi'];
|
|
77
|
+
// Property access (`document.` / `document[`), plus VALUE positions: an
|
|
78
|
+
// interface cast (`document as unknown as EventSourceLike` — sky-hop-canvas
|
|
79
|
+
// bindInput's whole DOM usage) and argument/assignment positions. Without the
|
|
80
|
+
// value forms the document runtime include is dropped and every facade
|
|
81
|
+
// capability silently returns missing at runtime.
|
|
82
|
+
const documentHostRegex = /(?:\bdocument\s*(?:\.|\[)|\bwindow\s*\.\s*document\b|\bdocument\s+as\b|[=(,]\s*document\s*[),;])/;
|
|
83
|
+
function addBindingsForGeaEmbeddedImports(text, bindings) {
|
|
84
|
+
const importRegex = /\bimport\s+([\s\S]*?)\s+from\s+['"](?:gea-embedded|@geastack\/core|@geajs\/core)['"]/g;
|
|
85
|
+
let match;
|
|
86
|
+
while ((match = importRegex.exec(text)) !== null) {
|
|
87
|
+
const clause = match[1];
|
|
88
|
+
if (/\*\s+as\s+/.test(clause)) {
|
|
89
|
+
for (const binding of namespaceImportBindings)
|
|
90
|
+
bindings.add(binding);
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
const named = clause.match(/\{([\s\S]*?)\}/);
|
|
94
|
+
if (!named)
|
|
95
|
+
continue;
|
|
96
|
+
for (const specifier of named[1].split(',')) {
|
|
97
|
+
const importedName = specifier.trim().split(/\s+as\s+/)[0]?.trim();
|
|
98
|
+
if (!importedName)
|
|
99
|
+
continue;
|
|
100
|
+
const binding = importBindingNames.get(importedName);
|
|
101
|
+
if (binding)
|
|
102
|
+
bindings.add(binding);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// `fetch(...)` and `new WebSocket(...)` are globals, never imports, so the
|
|
107
|
+
// import scan cannot see them; both need the network stack. A member call
|
|
108
|
+
// (`this.fetch(`, `store.fetch(`) is an app method, not the host global.
|
|
109
|
+
const hostGlobalCalls = [
|
|
110
|
+
[/(?<![.\w$])fetch\s*\(/, 'fetch'],
|
|
111
|
+
[/(?<![.\w$])new\s+WebSocket\s*\(/, 'websocket'],
|
|
112
|
+
];
|
|
113
|
+
// A file that declares its own `fetch` (a class method, or a wrapper such as
|
|
114
|
+
// image-demo's runtime.ts) calls that one; its network use, if any, shows up
|
|
115
|
+
// through the URL scheme scan instead. A declaration is the only `fetch(`
|
|
116
|
+
// whose parameter list is followed by a body.
|
|
117
|
+
const fetchDeclarationRegex = /\bfunction\s+fetch\b|\bfetch\s*\([^()]*\)\s*(?::[^{;]*)?\{/;
|
|
118
|
+
function addBindingsForHostGlobals(text, bindings) {
|
|
119
|
+
const shadowed = fetchDeclarationRegex.test(text);
|
|
120
|
+
for (const [pattern, binding] of hostGlobalCalls) {
|
|
121
|
+
if (binding === 'fetch' && shadowed)
|
|
122
|
+
continue;
|
|
123
|
+
if (pattern.test(text))
|
|
124
|
+
bindings.add(binding);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
// Only a quoted `https://` counts: a bare one is almost always a comment
|
|
128
|
+
// citing a source, and linking mbedtls for a comment would cost every app
|
|
129
|
+
// that documents itself ~100 KB of flash and the TLS heap at first use.
|
|
130
|
+
const httpsLiteralRegex = /['"`]https:\/\//;
|
|
131
|
+
const wssLiteralRegex = /['"`]wss:\/\//;
|
|
132
|
+
function addFeaturesForUrlSchemes(text, features) {
|
|
133
|
+
if (httpsLiteralRegex.test(text) || wssLiteralRegex.test(text))
|
|
134
|
+
features.add('https');
|
|
135
|
+
}
|
|
136
|
+
function addBindingsForEmbeddedHostNames(text, bindings) {
|
|
137
|
+
for (const [prefix, binding] of embeddedHostNamePrefixes) {
|
|
138
|
+
if (text.includes(prefix))
|
|
139
|
+
bindings.add(binding);
|
|
140
|
+
}
|
|
141
|
+
if (documentHostRegex.test(text))
|
|
142
|
+
bindings.add('dom');
|
|
143
|
+
}
|
|
144
|
+
function discoverSourceFiles(entry) {
|
|
145
|
+
const visited = new Set();
|
|
146
|
+
const files = [];
|
|
147
|
+
function visit(file) {
|
|
148
|
+
const resolved = path.resolve(file);
|
|
149
|
+
// An entry that is a directory (a configure run without app metadata)
|
|
150
|
+
// is not a program; reading it would throw EISDIR out of the analyzer.
|
|
151
|
+
if (visited.has(resolved) || !fs.existsSync(resolved) || !fs.statSync(resolved).isFile())
|
|
152
|
+
return;
|
|
153
|
+
visited.add(resolved);
|
|
154
|
+
const text = fs.readFileSync(resolved, 'utf8');
|
|
155
|
+
for (const specifier of relativeModuleSpecifiers(text)) {
|
|
156
|
+
const dependency = resolveRelativeModule(resolved, specifier);
|
|
157
|
+
if (dependency)
|
|
158
|
+
visit(dependency);
|
|
159
|
+
}
|
|
160
|
+
files.push(resolved);
|
|
161
|
+
}
|
|
162
|
+
visit(entry);
|
|
163
|
+
return files;
|
|
164
|
+
}
|
|
165
|
+
function relativeModuleSpecifiers(text) {
|
|
166
|
+
const specifiers = [];
|
|
167
|
+
const staticImportRegex = /\b(?:import|export)\s+(?:[\s\S]*?\s+from\s+)?['"]([^'"]+)['"]/g;
|
|
168
|
+
const dynamicImportRegex = /\bimport\s*\(\s*['"]([^'"]+)['"]\s*\)/g;
|
|
169
|
+
collectRelativeSpecifiers(text, staticImportRegex, specifiers);
|
|
170
|
+
collectRelativeSpecifiers(text, dynamicImportRegex, specifiers);
|
|
171
|
+
return specifiers;
|
|
172
|
+
}
|
|
173
|
+
function collectRelativeSpecifiers(text, regex, specifiers) {
|
|
174
|
+
let match;
|
|
175
|
+
while ((match = regex.exec(text)) !== null) {
|
|
176
|
+
const specifier = match[1];
|
|
177
|
+
if (specifier?.startsWith('.'))
|
|
178
|
+
specifiers.push(specifier);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
function resolveRelativeModule(importer, specifier) {
|
|
182
|
+
const base = path.resolve(path.dirname(importer), specifier);
|
|
183
|
+
for (const candidate of moduleCandidates(base)) {
|
|
184
|
+
if (fs.existsSync(candidate) && fs.statSync(candidate).isFile())
|
|
185
|
+
return candidate;
|
|
186
|
+
}
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
function moduleCandidates(base) {
|
|
190
|
+
const extensions = ['', '.ts', '.tsx', '.js', '.jsx', '.mjs', '.cjs'];
|
|
191
|
+
return [
|
|
192
|
+
...extensions.map((extension) => `${base}${extension}`),
|
|
193
|
+
...extensions.filter(Boolean).map((extension) => path.join(base, `index${extension}`)),
|
|
194
|
+
];
|
|
195
|
+
}
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
const canvasCallRules = [
|
|
2
|
+
{ name: 'gea_ir::canvasSetFillStyle', replacement: 'gea_ir::canvasSetFillStyleRgb565', colorArg: 1 },
|
|
3
|
+
{ name: 'gea_ir::canvasFillCircle', replacement: 'gea_ir::canvasFillCircleRgb565', colorArg: 4 },
|
|
4
|
+
{ name: 'gea_ir::canvasFillCircleRgb565', replacement: 'gea_ir::canvasFillCircleRgb565', colorArg: 4 },
|
|
5
|
+
{ name: 'gea_ir::canvasFillTriangleRgb565', replacement: 'gea_ir::canvasFillTriangleRgb565', colorArg: 7 },
|
|
6
|
+
{ name: 'gea_ir::canvasFillCirclesRgb565Uniform', replacement: 'gea_ir::canvasFillCirclesRgb565Uniform', colorArg: 4 },
|
|
7
|
+
].sort((a, b) => b.name.length - a.name.length);
|
|
8
|
+
export function foldCanvasColorLiteralsInCpp(source, options = {}) {
|
|
9
|
+
let out = '';
|
|
10
|
+
let index = 0;
|
|
11
|
+
while (index < source.length) {
|
|
12
|
+
const rule = canvasCallRules.find((candidate) => source.startsWith(candidate.name, index) && source[index + candidate.name.length] === '(');
|
|
13
|
+
if (!rule) {
|
|
14
|
+
out += source[index];
|
|
15
|
+
index += 1;
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
const rewritten = rewriteCanvasCall(source, index, rule, options);
|
|
19
|
+
if (!rewritten) {
|
|
20
|
+
out += source[index];
|
|
21
|
+
index += 1;
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
out += rewritten.text;
|
|
25
|
+
index = rewritten.end;
|
|
26
|
+
}
|
|
27
|
+
return out;
|
|
28
|
+
}
|
|
29
|
+
function rewriteCanvasCall(source, start, rule, options) {
|
|
30
|
+
const open = start + rule.name.length;
|
|
31
|
+
const close = findMatching(source, open, '(', ')');
|
|
32
|
+
if (close < 0)
|
|
33
|
+
return null;
|
|
34
|
+
const args = splitTopLevelArgs(source.slice(open + 1, close));
|
|
35
|
+
const colorExpression = args[rule.colorArg];
|
|
36
|
+
if (colorExpression === undefined)
|
|
37
|
+
return null;
|
|
38
|
+
const packed = parseKnownColorExpression(colorExpression, options);
|
|
39
|
+
if (packed === null)
|
|
40
|
+
return null;
|
|
41
|
+
args[rule.colorArg] = formatPackedColor(packed);
|
|
42
|
+
return {
|
|
43
|
+
text: `${rule.replacement}(${args.join(', ')})`,
|
|
44
|
+
end: close + 1,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function parseKnownColorExpression(expression, options) {
|
|
48
|
+
void options;
|
|
49
|
+
const trimmed = expression.trim();
|
|
50
|
+
const css = parseCppStringLiteral(trimmed);
|
|
51
|
+
if (css !== null)
|
|
52
|
+
return parseCssColor(css, options);
|
|
53
|
+
const rgbArgs = parseRgbCallArgs(trimmed);
|
|
54
|
+
if (rgbArgs) {
|
|
55
|
+
const channels = rgbArgs.map(parseStaticNumber);
|
|
56
|
+
if (channels.every((value) => value !== null)) {
|
|
57
|
+
return packRgba8888(channels[0], channels[1], channels[2], 255);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
function parseCppStringLiteral(expression) {
|
|
63
|
+
const direct = expression.match(/^("(?:\\.|[^"\\])*")$/);
|
|
64
|
+
if (direct)
|
|
65
|
+
return decodeCppStringLiteral(direct[1]);
|
|
66
|
+
const constructed = expression.match(/^std::string\(\s*("(?:\\.|[^"\\])*")\s*(?:,\s*\d+\s*)?\)$/);
|
|
67
|
+
if (constructed)
|
|
68
|
+
return decodeCppStringLiteral(constructed[1]);
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
function decodeCppStringLiteral(literal) {
|
|
72
|
+
try {
|
|
73
|
+
return JSON.parse(literal);
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function parseRgbCallArgs(expression) {
|
|
80
|
+
const call = expression.match(/^(?:__gea_global_)?(?:color|rgb)\s*(?:\(\))?\s*\(([\s\S]*)\)$/);
|
|
81
|
+
if (!call)
|
|
82
|
+
return null;
|
|
83
|
+
const args = splitTopLevelArgs(call[1]);
|
|
84
|
+
return args.length === 3 ? args : null;
|
|
85
|
+
}
|
|
86
|
+
function parseStaticNumber(expression) {
|
|
87
|
+
const trimmed = expression.trim();
|
|
88
|
+
const literal = trimmed.match(/^-?\d+(?:\.\d+)?$/);
|
|
89
|
+
if (literal)
|
|
90
|
+
return Number(literal[0]);
|
|
91
|
+
const cast = trimmed.match(/^static_cast<[^>]+>\(\s*(-?\d+(?:\.\d+)?)\s*\)$/);
|
|
92
|
+
if (cast)
|
|
93
|
+
return Number(cast[1]);
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
function parseCssColor(value, options) {
|
|
97
|
+
void options;
|
|
98
|
+
const text = value.trim();
|
|
99
|
+
// rgb()/rgba() — alpha is a 0..1 float in CSS.
|
|
100
|
+
const rgb = text.match(/^rgba?\(\s*(-?\d+(?:\.\d+)?)\s*,\s*(-?\d+(?:\.\d+)?)\s*,\s*(-?\d+(?:\.\d+)?)\s*(?:,\s*(-?\d+(?:\.\d+)?)\s*)?\)$/i);
|
|
101
|
+
if (rgb) {
|
|
102
|
+
const a = rgb[4] === undefined ? 255 : clampByte(Number(rgb[4]) * 255);
|
|
103
|
+
return packRgba8888(Number(rgb[1]), Number(rgb[2]), Number(rgb[3]), a);
|
|
104
|
+
}
|
|
105
|
+
// #rrggbbaa (full RGBA8888 authoring)
|
|
106
|
+
const hex8 = text.match(/^#([0-9a-f]{8})$/i);
|
|
107
|
+
if (hex8) {
|
|
108
|
+
const raw = Number.parseInt(hex8[1], 16);
|
|
109
|
+
return packRgba8888((raw >>> 24) & 0xff, (raw >> 16) & 0xff, (raw >> 8) & 0xff, raw & 0xff);
|
|
110
|
+
}
|
|
111
|
+
const longHex = text.match(/^#([0-9a-f]{6})$/i);
|
|
112
|
+
if (longHex) {
|
|
113
|
+
const raw = Number.parseInt(longHex[1], 16);
|
|
114
|
+
return packRgba8888((raw >> 16) & 0xff, (raw >> 8) & 0xff, raw & 0xff, 255);
|
|
115
|
+
}
|
|
116
|
+
// #rgba (short, with alpha nibble)
|
|
117
|
+
const shortHexA = text.match(/^#([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])$/i);
|
|
118
|
+
if (shortHexA) {
|
|
119
|
+
const r = Number.parseInt(shortHexA[1], 16);
|
|
120
|
+
const g = Number.parseInt(shortHexA[2], 16);
|
|
121
|
+
const b = Number.parseInt(shortHexA[3], 16);
|
|
122
|
+
const a = Number.parseInt(shortHexA[4], 16);
|
|
123
|
+
return packRgba8888((r << 4) | r, (g << 4) | g, (b << 4) | b, (a << 4) | a);
|
|
124
|
+
}
|
|
125
|
+
const shortHex = text.match(/^#([0-9a-f])([0-9a-f])([0-9a-f])$/i);
|
|
126
|
+
if (shortHex) {
|
|
127
|
+
const r = Number.parseInt(shortHex[1], 16);
|
|
128
|
+
const g = Number.parseInt(shortHex[2], 16);
|
|
129
|
+
const b = Number.parseInt(shortHex[3], 16);
|
|
130
|
+
return packRgba8888((r << 4) | r, (g << 4) | g, (b << 4) | b, 255);
|
|
131
|
+
}
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
// RGBA8888 packed as the C++ pixel::packRgba8888 layout: R | G<<8 | B<<16 | A<<24.
|
|
135
|
+
function packRgba8888(r, g, b, a) {
|
|
136
|
+
return ((clampByte(r) | (clampByte(g) << 8) | (clampByte(b) << 16) | (clampByte(a) << 24)) >>> 0);
|
|
137
|
+
}
|
|
138
|
+
function clampByte(value) {
|
|
139
|
+
if (!Number.isFinite(value))
|
|
140
|
+
return 0;
|
|
141
|
+
const integer = Math.trunc(value);
|
|
142
|
+
if (integer < 0)
|
|
143
|
+
return 0;
|
|
144
|
+
if (integer > 255)
|
|
145
|
+
return 255;
|
|
146
|
+
return integer;
|
|
147
|
+
}
|
|
148
|
+
// Emit the ONE colour conversion as a constexpr call: the per-target C++ build
|
|
149
|
+
// folds it to RGB565 (esp32) or RGBA8888 (iOS) at compile time — no runtime cost.
|
|
150
|
+
function formatPackedColor(value) {
|
|
151
|
+
return `gea::framework::graphics::pixel::nativeColorFromRgba8888(0x${(value >>> 0).toString(16).padStart(8, '0')}u)`;
|
|
152
|
+
}
|
|
153
|
+
function splitTopLevelArgs(args) {
|
|
154
|
+
const result = [];
|
|
155
|
+
let start = 0;
|
|
156
|
+
let parens = 0;
|
|
157
|
+
let brackets = 0;
|
|
158
|
+
let braces = 0;
|
|
159
|
+
let quote = null;
|
|
160
|
+
let escaped = false;
|
|
161
|
+
for (let index = 0; index < args.length; index++) {
|
|
162
|
+
const char = args[index];
|
|
163
|
+
if (quote) {
|
|
164
|
+
if (escaped)
|
|
165
|
+
escaped = false;
|
|
166
|
+
else if (char === '\\')
|
|
167
|
+
escaped = true;
|
|
168
|
+
else if (char === quote)
|
|
169
|
+
quote = null;
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
if (char === '"' || char === "'") {
|
|
173
|
+
quote = char;
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
if (char === '(')
|
|
177
|
+
parens += 1;
|
|
178
|
+
else if (char === ')')
|
|
179
|
+
parens -= 1;
|
|
180
|
+
else if (char === '[')
|
|
181
|
+
brackets += 1;
|
|
182
|
+
else if (char === ']')
|
|
183
|
+
brackets -= 1;
|
|
184
|
+
else if (char === '{')
|
|
185
|
+
braces += 1;
|
|
186
|
+
else if (char === '}')
|
|
187
|
+
braces -= 1;
|
|
188
|
+
else if (char === ',' && parens === 0 && brackets === 0 && braces === 0) {
|
|
189
|
+
result.push(args.slice(start, index).trim());
|
|
190
|
+
start = index + 1;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
const tail = args.slice(start).trim();
|
|
194
|
+
if (tail.length > 0 || args.length > 0)
|
|
195
|
+
result.push(tail);
|
|
196
|
+
return result;
|
|
197
|
+
}
|
|
198
|
+
function findMatching(source, open, openChar, closeChar) {
|
|
199
|
+
let depth = 0;
|
|
200
|
+
let quote = null;
|
|
201
|
+
let escaped = false;
|
|
202
|
+
for (let index = open; index < source.length; index++) {
|
|
203
|
+
const char = source[index];
|
|
204
|
+
if (quote) {
|
|
205
|
+
if (escaped)
|
|
206
|
+
escaped = false;
|
|
207
|
+
else if (char === '\\')
|
|
208
|
+
escaped = true;
|
|
209
|
+
else if (char === quote)
|
|
210
|
+
quote = null;
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
if (char === '"' || char === "'") {
|
|
214
|
+
quote = char;
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
if (char === openChar)
|
|
218
|
+
depth += 1;
|
|
219
|
+
else if (char === closeChar) {
|
|
220
|
+
depth -= 1;
|
|
221
|
+
if (depth === 0)
|
|
222
|
+
return index;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
return -1;
|
|
226
|
+
}
|