embedded-react 0.12.0 → 0.14.0
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 +222 -6
- package/aot/compile.mjs +3316 -364
- package/aot/style-map.mjs +30 -6
- package/assets/bake-font.mjs +104 -12
- package/assets/bake-svg.mjs +11 -1
- package/assets/build-builtin-font.mjs +6 -12
- package/assets/emit-c.mjs +10 -2
- package/assets/emit-container.mjs +4 -2
- package/assets/font-config.mjs +49 -0
- package/assets/font-sizes.mjs +652 -0
- package/assets/glyph-coverage.mjs +281 -0
- package/assets/index.mjs +29 -5
- package/build.mjs +11 -21
- package/cli.mjs +41 -3
- package/compile-bin.mjs +71 -0
- package/hotreload/pack-app.mjs +8 -21
- package/hotreload/pack-split.mjs +12 -27
- package/pack-container.mjs +10 -47
- package/package.json +2 -1
- package/sim/embedded-react.wasm +0 -0
- package/sim/index.html +32 -3
- package/sim-server.mjs +33 -27
- package/src/embedded-react/Animated.js +23 -9
- package/src/embedded-react/Button.js +98 -0
- package/src/embedded-react/FlatList.js +88 -0
- package/src/embedded-react/ImageBackground.js +67 -0
- package/src/embedded-react/PanResponder.js +326 -0
- package/src/embedded-react/SectionList.js +148 -0
- package/src/embedded-react/TouchableOpacity.js +152 -0
- package/src/embedded-react/components.js +4 -3
- package/src/embedded-react/index.d.ts +867 -60
- package/src/embedded-react/index.js +7 -2
- package/src/embedded-react/list-child.js +54 -0
- package/src/embedded-react/svg-ops.js +309 -77
- package/src/embedded-react/warn-props.js +80 -0
- package/src/host-config.js +103 -3
- package/src/props.js +40 -0
- package/src/renderer.js +31 -0
|
@@ -26,13 +26,12 @@ export {
|
|
|
26
26
|
Text,
|
|
27
27
|
Image,
|
|
28
28
|
ScrollView,
|
|
29
|
-
FlatList,
|
|
30
29
|
Pressable,
|
|
31
|
-
TouchableOpacity,
|
|
32
30
|
TextInput,
|
|
33
31
|
Switch,
|
|
34
32
|
ActivityIndicator,
|
|
35
33
|
Modal,
|
|
34
|
+
Dial,
|
|
36
35
|
Svg,
|
|
37
36
|
Path,
|
|
38
37
|
Circle,
|
|
@@ -42,11 +41,17 @@ export {
|
|
|
42
41
|
G,
|
|
43
42
|
Arc,
|
|
44
43
|
} from './components.js';
|
|
44
|
+
export {Button} from './Button.js';
|
|
45
|
+
export {TouchableOpacity} from './TouchableOpacity.js';
|
|
46
|
+
export {FlatList} from './FlatList.js';
|
|
47
|
+
export {ImageBackground} from './ImageBackground.js';
|
|
48
|
+
export {SectionList} from './SectionList.js';
|
|
45
49
|
export {updateVector, updateText, setKeyboardConfig} from './imperative.js';
|
|
46
50
|
export {StyleSheet} from './StyleSheet.js';
|
|
47
51
|
export {Platform} from './Platform.js';
|
|
48
52
|
export {AppRegistry} from './AppRegistry.js';
|
|
49
53
|
export {Animated, useAnimatedValue} from './Animated.js';
|
|
54
|
+
export {PanResponder} from './PanResponder.js';
|
|
50
55
|
export {usePersistentState} from './usePersistentState.js';
|
|
51
56
|
export {useHostValue} from './useHostValue.js';
|
|
52
57
|
export {Easing} from './Easing.js';
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026 Cory Lamming
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
// Shared row handling for the list wrappers (<FlatList>, <SectionList>). Both turn a render callback's
|
|
18
|
+
// result into a keyed child of one <ScrollView>, and the awkward cases are the same for both: a row
|
|
19
|
+
// that renders to nothing, and a row that isn't an element at all.
|
|
20
|
+
import {cloneElement} from 'react';
|
|
21
|
+
|
|
22
|
+
/** True for a render result that puts nothing on screen — the `{cond && <Row/>}` of a row callback. */
|
|
23
|
+
export const rendersNothing = node =>
|
|
24
|
+
node === null || node === undefined || node === false;
|
|
25
|
+
|
|
26
|
+
/** True for something cloneElement can key — a React element, as opposed to a string/number row. */
|
|
27
|
+
export const isElement = node =>
|
|
28
|
+
node !== null && typeof node === 'object' && node.$$typeof !== undefined;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Appends one rendered row to `out`, keyed, or drops it if it rendered nothing.
|
|
32
|
+
*
|
|
33
|
+
* Callers own the key because they know what makes one unique (a SectionList's rows are siblings
|
|
34
|
+
* across sections, a FlatList's are not). A row that is not an element goes in untouched: there is no
|
|
35
|
+
* key to attach to a raw string, and a plain `.map` wouldn't have attached one either.
|
|
36
|
+
*
|
|
37
|
+
* The key arrives as a FUNCTION, not a value, and that is the point: it is called only for a node that
|
|
38
|
+
* can actually carry one. `keyExtractor` is the app's code — running it for a row that rendered
|
|
39
|
+
* nothing, or for a raw string that cannot be cloned, is both wasted work on the commit path and a
|
|
40
|
+
* side effect the app never asked for. Passing the key by value invites exactly that, and did.
|
|
41
|
+
*
|
|
42
|
+
* @param {Array} out The child list being built.
|
|
43
|
+
* @param {*} node Whatever the render callback returned.
|
|
44
|
+
* @param {(element: object) => string} keyFor Builds the React key, given the keyable element.
|
|
45
|
+
*/
|
|
46
|
+
export function pushKeyedChild(out, node, keyFor) {
|
|
47
|
+
if (rendersNothing(node)) return;
|
|
48
|
+
if (!isElement(node)) {
|
|
49
|
+
out.push(node);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const key = keyFor(node);
|
|
53
|
+
out.push(node.key === key ? node : cloneElement(node, {key}));
|
|
54
|
+
}
|
|
@@ -32,6 +32,10 @@ export const VOP_CUBIC = 4;
|
|
|
32
32
|
export const VOP_ARC = 5;
|
|
33
33
|
export const VOP_CLOSE = 6;
|
|
34
34
|
|
|
35
|
+
// Control-point ratio for approximating a quarter (circular or elliptical) arc with one cubic:
|
|
36
|
+
// 4/3 * (sqrt(2) - 1). Used by rounded-rect corners.
|
|
37
|
+
export const KAPPA = 0.5522847498307936;
|
|
38
|
+
|
|
35
39
|
export const CAP = {butt: 0, round: 1, square: 2};
|
|
36
40
|
export const JOIN = {miter: 0, round: 1, bevel: 2};
|
|
37
41
|
|
|
@@ -295,8 +299,62 @@ function arcToCubics(x0, y0, rx, ry, phiDeg, largeArc, sweep, x, y) {
|
|
|
295
299
|
/**
|
|
296
300
|
* Parses an SVG `d` string into engine path ops (a flat number array, NO leading SHAPE op). Supports
|
|
297
301
|
* M/L/H/V/C/S/Q/T/A/Z and their relative (lowercase) forms; arcs are converted to cubics.
|
|
302
|
+
*
|
|
303
|
+
* Results are cached by `d` string, so the returned array is SHARED — read it, never mutate it.
|
|
298
304
|
*/
|
|
299
305
|
export function parsePath(d) {
|
|
306
|
+
return pathEntry(d).ops;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// Parsed `d` strings, keyed on the string itself. An <Svg> recompiles its whole tape whenever any
|
|
310
|
+
// part of it changes, so without this a moving needle re-runs the tokenizer and the arc->cubic
|
|
311
|
+
// conversion over every static path beside it, only for the engine to memcmp the result and throw
|
|
312
|
+
// the identical bytes away. Held to both an op budget and an entry count, and a path too big to fit
|
|
313
|
+
// the budget on its own is never stored, so nothing can push it over; an entry also holds one
|
|
314
|
+
// transformed copy (see xf), so the real footprint is ~2x the op budget. The bridge caps a single
|
|
315
|
+
// <Svg> at 1024 ops and 16 shapes, so this holds several screens' worth.
|
|
316
|
+
const PATH_CACHE = new Map();
|
|
317
|
+
const PATH_CACHE_MAX_OPS = 4096;
|
|
318
|
+
const PATH_CACHE_MAX_ENTRIES = 128;
|
|
319
|
+
let _pathCacheOps = 0;
|
|
320
|
+
|
|
321
|
+
/** Cache record for one `d` string: `ops` are the parsed path ops, `xf` the last transform applied
|
|
322
|
+
* to them (see transformCached). Coerces its key, so a non-string `d` still hits the cache instead
|
|
323
|
+
* of keying a fresh entry off object identity every call. */
|
|
324
|
+
function pathEntry(d) {
|
|
325
|
+
const key = typeof d === 'string' ? d : String(d);
|
|
326
|
+
const hit = PATH_CACHE.get(key);
|
|
327
|
+
if (hit !== undefined) {
|
|
328
|
+
// A Map iterates oldest-first, so re-inserting on a hit makes eviction LRU — which is what keeps
|
|
329
|
+
// a static face cached next to a needle whose `d` is rebuilt every frame.
|
|
330
|
+
PATH_CACHE.delete(key);
|
|
331
|
+
PATH_CACHE.set(key, hit);
|
|
332
|
+
return hit;
|
|
333
|
+
}
|
|
334
|
+
const entry = {ops: parsePathUncached(key), xf: null};
|
|
335
|
+
// A path that alone exceeds the whole budget is parsed but not stored: caching it would blow the
|
|
336
|
+
// bound it is measured against, and at that size it is already past the bridge's per-<Svg> op cap.
|
|
337
|
+
if (entry.ops.length > PATH_CACHE_MAX_OPS) return entry;
|
|
338
|
+
PATH_CACHE.set(key, entry);
|
|
339
|
+
_pathCacheOps += entry.ops.length;
|
|
340
|
+
while (
|
|
341
|
+
_pathCacheOps > PATH_CACHE_MAX_OPS ||
|
|
342
|
+
PATH_CACHE.size > PATH_CACHE_MAX_ENTRIES
|
|
343
|
+
) {
|
|
344
|
+
const oldest = PATH_CACHE.keys().next().value;
|
|
345
|
+
_pathCacheOps -= PATH_CACHE.get(oldest).ops.length;
|
|
346
|
+
PATH_CACHE.delete(oldest);
|
|
347
|
+
}
|
|
348
|
+
return entry;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/** Drops every cached path. Only for tests that measure parse work. */
|
|
352
|
+
export function clearPathCache() {
|
|
353
|
+
PATH_CACHE.clear();
|
|
354
|
+
_pathCacheOps = 0;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
function parsePathUncached(d) {
|
|
300
358
|
const ops = [];
|
|
301
359
|
const toks = tokenizePath(d);
|
|
302
360
|
let cx = 0;
|
|
@@ -448,38 +506,121 @@ function circleOps(p) {
|
|
|
448
506
|
];
|
|
449
507
|
}
|
|
450
508
|
|
|
451
|
-
|
|
452
|
-
|
|
509
|
+
/** An ellipse as a `d` string: an arc-free path of four cubic Béziers (kappa) once parsePath lowers
|
|
510
|
+
* the two `A` commands. Returned as a string so it goes through the same parse cache as <Path d>. */
|
|
511
|
+
function ellipsePathD(p) {
|
|
453
512
|
const cx = num(p.cx, 0);
|
|
454
513
|
const cy = num(p.cy, 0);
|
|
455
514
|
const rx = num(p.rx, 0);
|
|
456
515
|
const ry = num(p.ry, 0);
|
|
457
|
-
|
|
458
|
-
return parsePath(d);
|
|
516
|
+
return `M ${cx - rx} ${cy} A ${rx} ${ry} 0 1 0 ${cx + rx} ${cy} A ${rx} ${ry} 0 1 0 ${cx - rx} ${cy} Z`;
|
|
459
517
|
}
|
|
460
518
|
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
519
|
+
/**
|
|
520
|
+
* SVG <rect> corner-radius resolution. A missing radius is `auto` and falls back to the other one; a
|
|
521
|
+
* NEGATIVE radius is invalid, which also means `auto`, so it falls back too — <rect rx="-3" ry="8">
|
|
522
|
+
* rounds at 8, matching what browsers render. An explicit ZERO is a valid radius and squares the
|
|
523
|
+
* corners, and each radius is clamped to half its own side. Returns [rx, ry] — [0, 0] for a
|
|
524
|
+
* square-cornered rect. Exported so the AOT and the SVG baker apply the same rules.
|
|
525
|
+
*/
|
|
526
|
+
export function rectRadii(rxAttr, ryAttr, w, h) {
|
|
527
|
+
let rx = num(rxAttr, -1);
|
|
528
|
+
let ry = num(ryAttr, -1);
|
|
529
|
+
if (rx < 0) rx = ry; // rx omitted -> ry
|
|
530
|
+
if (ry < 0) ry = rx; // ry omitted -> rx
|
|
531
|
+
rx = Math.min(rx, w / 2);
|
|
532
|
+
ry = Math.min(ry, h / 2);
|
|
533
|
+
return rx > 0 && ry > 0 ? [rx, ry] : [0, 0];
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
/**
|
|
537
|
+
* Rect path ops, clockwise from the top-left corner. rx/ry must already be resolved by rectRadii();
|
|
538
|
+
* 0 gives the plain four-line rectangle. Corners are cubics rather than VOP_ARC so each one STARTS at
|
|
539
|
+
* exactly the preceding line's endpoint — an arc recomputes that point from cos/sin and can miss the
|
|
540
|
+
* engine's exact-equality join dedupe by a ULP, which spikes the miter join on a stroked rect.
|
|
541
|
+
*/
|
|
542
|
+
function rectOpsXY(x, y, w, h, rx, ry) {
|
|
543
|
+
if (rx <= 0 || ry <= 0)
|
|
544
|
+
return [
|
|
545
|
+
VOP_MOVE,
|
|
546
|
+
x,
|
|
547
|
+
y,
|
|
548
|
+
VOP_LINE,
|
|
549
|
+
x + w,
|
|
550
|
+
y,
|
|
551
|
+
VOP_LINE,
|
|
552
|
+
x + w,
|
|
553
|
+
y + h,
|
|
554
|
+
VOP_LINE,
|
|
555
|
+
x,
|
|
556
|
+
y + h,
|
|
557
|
+
VOP_CLOSE,
|
|
558
|
+
];
|
|
559
|
+
const kx = rx * KAPPA;
|
|
560
|
+
const ky = ry * KAPPA;
|
|
561
|
+
const x1 = x + rx; // where the top/bottom edges start, past the left corners
|
|
562
|
+
const x2 = x + w - rx; // ... and end, before the right corners
|
|
563
|
+
const y1 = y + ry;
|
|
564
|
+
const y2 = y + h - ry;
|
|
565
|
+
const r = x + w;
|
|
566
|
+
const b = y + h;
|
|
466
567
|
return [
|
|
467
568
|
VOP_MOVE,
|
|
468
|
-
|
|
569
|
+
x1,
|
|
469
570
|
y,
|
|
470
571
|
VOP_LINE,
|
|
471
|
-
|
|
572
|
+
x2,
|
|
472
573
|
y,
|
|
574
|
+
VOP_CUBIC,
|
|
575
|
+
x2 + kx,
|
|
576
|
+
y,
|
|
577
|
+
r,
|
|
578
|
+
y1 - ky,
|
|
579
|
+
r,
|
|
580
|
+
y1,
|
|
581
|
+
VOP_LINE,
|
|
582
|
+
r,
|
|
583
|
+
y2,
|
|
584
|
+
VOP_CUBIC,
|
|
585
|
+
r,
|
|
586
|
+
y2 + ky,
|
|
587
|
+
x2 + kx,
|
|
588
|
+
b,
|
|
589
|
+
x2,
|
|
590
|
+
b,
|
|
473
591
|
VOP_LINE,
|
|
474
|
-
|
|
475
|
-
|
|
592
|
+
x1,
|
|
593
|
+
b,
|
|
594
|
+
VOP_CUBIC,
|
|
595
|
+
x1 - kx,
|
|
596
|
+
b,
|
|
597
|
+
x,
|
|
598
|
+
y2 + ky,
|
|
599
|
+
x,
|
|
600
|
+
y2,
|
|
476
601
|
VOP_LINE,
|
|
477
602
|
x,
|
|
478
|
-
|
|
603
|
+
y1,
|
|
604
|
+
VOP_CUBIC,
|
|
605
|
+
x,
|
|
606
|
+
y1 - ky,
|
|
607
|
+
x1 - kx,
|
|
608
|
+
y,
|
|
609
|
+
x1,
|
|
610
|
+
y,
|
|
479
611
|
VOP_CLOSE,
|
|
480
612
|
];
|
|
481
613
|
}
|
|
482
614
|
|
|
615
|
+
function rectOps(p) {
|
|
616
|
+
const x = num(p.x, 0);
|
|
617
|
+
const y = num(p.y, 0);
|
|
618
|
+
const w = num(p.width, 0);
|
|
619
|
+
const h = num(p.height, 0);
|
|
620
|
+
const [rx, ry] = rectRadii(p.rx, p.ry, w, h);
|
|
621
|
+
return rectOpsXY(x, y, w, h, rx, ry);
|
|
622
|
+
}
|
|
623
|
+
|
|
483
624
|
function lineOps(p) {
|
|
484
625
|
return [
|
|
485
626
|
VOP_MOVE,
|
|
@@ -509,7 +650,7 @@ function arcOpsCW(cx, cy, r, a0deg, a1deg) {
|
|
|
509
650
|
* { arc: [cx, cy, r, startDeg, endDeg], stroke: '#f4a261', strokeWidth: 14, cap: 'round' }
|
|
510
651
|
* { circle: [cx, cy, r], fill: '#16202f', stroke: '#f4a261', strokeWidth: 3 }
|
|
511
652
|
* { line: [x1, y1, x2, y2], stroke, strokeWidth }
|
|
512
|
-
* { rect: [x, y, w, h], fill }
|
|
653
|
+
* { rect: [x, y, w, h], fill } // optional [x, y, w, h, rx, ry] for rounded corners
|
|
513
654
|
* { path: 'M..A..', stroke } // d-string supported but slower (regex + bezier)
|
|
514
655
|
* Arc angles are degrees, clockwise from 12 o'clock. This avoids the d-string parser entirely, so it's
|
|
515
656
|
* cheap enough to call on every pointer move (the imperative drag path).
|
|
@@ -562,21 +703,29 @@ export function shapesToVector(shapes) {
|
|
|
562
703
|
const y = s.rect[1];
|
|
563
704
|
const w = s.rect[2];
|
|
564
705
|
const h = s.rect[3];
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
706
|
+
if (s.rect.length > 4) {
|
|
707
|
+
// Rounded — the optional trailing [rx, ry]. Off the allocation-free path below, but a rounded
|
|
708
|
+
// rect is a chrome/backing shape, not something a drag rebuilds every move.
|
|
709
|
+
const [rx, ry] = rectRadii(s.rect[4], s.rect[5], w, h);
|
|
710
|
+
const ro = rectOpsXY(x, y, w, h, rx, ry);
|
|
711
|
+
for (let k = 0; k < ro.length; k++) ops.push(ro[k]);
|
|
712
|
+
} else {
|
|
713
|
+
ops.push(
|
|
714
|
+
VOP_MOVE,
|
|
715
|
+
x,
|
|
716
|
+
y,
|
|
717
|
+
VOP_LINE,
|
|
718
|
+
x + w,
|
|
719
|
+
y,
|
|
720
|
+
VOP_LINE,
|
|
721
|
+
x + w,
|
|
722
|
+
y + h,
|
|
723
|
+
VOP_LINE,
|
|
724
|
+
x,
|
|
725
|
+
y + h,
|
|
726
|
+
VOP_CLOSE,
|
|
727
|
+
);
|
|
728
|
+
}
|
|
580
729
|
} else if (s.line) {
|
|
581
730
|
ops.push(VOP_MOVE, s.line[0], s.line[1], VOP_LINE, s.line[2], s.line[3]);
|
|
582
731
|
} else if (s.path) {
|
|
@@ -698,20 +847,86 @@ function transformOps(ops, T) {
|
|
|
698
847
|
return out;
|
|
699
848
|
}
|
|
700
849
|
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
850
|
+
/**
|
|
851
|
+
* transformOps against a cached path, reusing the last result when the transform is unchanged. One
|
|
852
|
+
* slot per path: a shape's transform is the root viewBox scale composed with its <G>s, which almost
|
|
853
|
+
* never moves between commits, so an untouched shape costs a compare instead of a rebuild. The same
|
|
854
|
+
* `d` drawn under several different transforms just misses and pays the full transform.
|
|
855
|
+
*/
|
|
856
|
+
function transformCached(entry, T) {
|
|
857
|
+
const xf = entry.xf;
|
|
858
|
+
if (
|
|
859
|
+
xf &&
|
|
860
|
+
xf.sx === T.sx &&
|
|
861
|
+
xf.sy === T.sy &&
|
|
862
|
+
xf.tx === T.tx &&
|
|
863
|
+
xf.ty === T.ty
|
|
864
|
+
)
|
|
865
|
+
return xf.out;
|
|
866
|
+
const out = transformOps(entry.ops, T);
|
|
867
|
+
entry.xf = {sx: T.sx, sy: T.sy, tx: T.tx, ty: T.ty, out};
|
|
868
|
+
return out;
|
|
704
869
|
}
|
|
705
870
|
|
|
706
871
|
function isElement(c) {
|
|
707
872
|
return c && typeof c === 'object' && c.type != null && c.props != null;
|
|
708
873
|
}
|
|
709
874
|
|
|
875
|
+
// React's fragment tag. Read from the global symbol registry rather than importing React, which this
|
|
876
|
+
// module deliberately does not depend on; `Symbol.for` returns the very symbol React itself uses.
|
|
877
|
+
const REACT_FRAGMENT = Symbol.for('react.fragment');
|
|
878
|
+
|
|
879
|
+
/** Children JSX produces for "draw nothing": a bare `{cond && <Path/>}` that failed, a hole in a
|
|
880
|
+
* list, and the whitespace JSX leaves between elements. Skipped without a word. */
|
|
881
|
+
function isEmptyChild(c) {
|
|
882
|
+
return (
|
|
883
|
+
c == null ||
|
|
884
|
+
typeof c === 'boolean' ||
|
|
885
|
+
(typeof c === 'string' && c.trim() === '')
|
|
886
|
+
);
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
// Shape/grouping tags flattenSvg knows. A tag outside this set is a mistake worth reporting; a known
|
|
890
|
+
// tag that produces no geometry (a <Path> with no `d`, a zero-radius <Circle>) is not.
|
|
891
|
+
const SVG_TAGS = ['Path', 'Circle', 'Ellipse', 'Rect', 'Line', 'Arc', 'G'];
|
|
892
|
+
|
|
893
|
+
let _warnedSvgChild = false;
|
|
894
|
+
|
|
895
|
+
/**
|
|
896
|
+
* Warns ONCE about a child <Svg> cannot draw. The two common cases are a component (`<Needle/>` —
|
|
897
|
+
* <Svg> owns its subtree, so React never renders it) and a non-shape host tag; both used to vanish
|
|
898
|
+
* with no output at all. Once per app, like the other commit-path warnings: an <Svg> recompiles its
|
|
899
|
+
* tape on every update, and one bad child would otherwise print on every frame.
|
|
900
|
+
*
|
|
901
|
+
* The way out of the component case is to CALL it — `{needle()}` puts whatever it returns (an element
|
|
902
|
+
* or an array of them) straight into children, where the walk sees it. Having it return an array does
|
|
903
|
+
* nothing for `<Needle/>`: that form is never invoked at all.
|
|
904
|
+
*/
|
|
905
|
+
function warnSvgChild(c) {
|
|
906
|
+
if (_warnedSvgChild) return;
|
|
907
|
+
_warnedSvgChild = true;
|
|
908
|
+
const what = !isElement(c)
|
|
909
|
+
? typeof c === 'string'
|
|
910
|
+
? `the text ${JSON.stringify(c)}`
|
|
911
|
+
: `a ${typeof c} child`
|
|
912
|
+
: typeof c.type === 'function'
|
|
913
|
+
? `<${c.type.displayName || c.type.name || 'Component'}>, a component`
|
|
914
|
+
: `<${String(c.type)}>`;
|
|
915
|
+
console.warn(
|
|
916
|
+
`embedded-react: <Svg> can't draw ${what}, and skipped it. Children must be ${SVG_TAGS.join('/')} ` +
|
|
917
|
+
`elements (arrays and fragments around them are unwrapped). <Svg> flattens its subtree instead of ` +
|
|
918
|
+
`mounting it, so a component is never rendered — inline its shapes, or call it as a plain ` +
|
|
919
|
+
`function: {needle()}.`,
|
|
920
|
+
);
|
|
921
|
+
}
|
|
922
|
+
|
|
710
923
|
/**
|
|
711
924
|
* Flattens an <Svg> element's props into {ops, paints, gradients} flat arrays for NativeUI.setVectorOps.
|
|
712
925
|
* Handles Path/Circle/Ellipse/Rect/Line shapes, <G> grouping (inherited paint + translate/scale), and
|
|
713
|
-
* a root viewBox -> width/height scale.
|
|
714
|
-
*
|
|
926
|
+
* a root viewBox -> width/height scale. Arrays and fragments are unwrapped at any depth, so a mapped
|
|
927
|
+
* list of shapes draws like an inline one. A shape's fillGrad/strokeGrad descriptor lands in
|
|
928
|
+
* `gradients` and is referenced 1-based from its paint record. Returns empty arrays when there is
|
|
929
|
+
* nothing to draw.
|
|
715
930
|
*/
|
|
716
931
|
export function flattenSvg(props) {
|
|
717
932
|
const ops = [];
|
|
@@ -732,46 +947,63 @@ export function flattenSvg(props) {
|
|
|
732
947
|
}
|
|
733
948
|
}
|
|
734
949
|
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
const gx = num(p.x ?? p.translateX, 0);
|
|
744
|
-
const gy = num(p.y ?? p.translateY, 0);
|
|
745
|
-
const childT = {
|
|
746
|
-
sx: T.sx * s,
|
|
747
|
-
sy: T.sy * s,
|
|
748
|
-
tx: gx * T.sx + T.tx,
|
|
749
|
-
ty: gy * T.sy + T.ty,
|
|
750
|
-
};
|
|
751
|
-
walk(p.children, merged, childT);
|
|
752
|
-
continue;
|
|
753
|
-
}
|
|
754
|
-
let shapeOps = null;
|
|
755
|
-
if (c.type === 'Path' && p.d) shapeOps = parsePath(p.d);
|
|
756
|
-
else if (c.type === 'Circle') shapeOps = circleOps(p);
|
|
757
|
-
else if (c.type === 'Ellipse') shapeOps = ellipseOps(p);
|
|
758
|
-
else if (c.type === 'Rect') shapeOps = rectOps(p);
|
|
759
|
-
else if (c.type === 'Line') shapeOps = lineOps(p);
|
|
760
|
-
else if (c.type === 'Arc')
|
|
761
|
-
shapeOps = arcOpsCW(
|
|
762
|
-
num(p.cx, 0),
|
|
763
|
-
num(p.cy, 0),
|
|
764
|
-
num(p.r, 0),
|
|
765
|
-
num(p.startAngle, 0),
|
|
766
|
-
num(p.endAngle, 0),
|
|
767
|
-
);
|
|
768
|
-
if (!shapeOps || shapeOps.length === 0) continue;
|
|
769
|
-
|
|
770
|
-
const paintIndex = paints.length / PAINT_STRIDE;
|
|
771
|
-
const scale = (T.sx + T.sy) / 2; // stroke-width scale (uniform assumed)
|
|
772
|
-
paints.push(...paintRecord(merged, scale, gradients));
|
|
773
|
-
ops.push(VOP_SHAPE, paintIndex, ...transformOps(shapeOps, T));
|
|
950
|
+
// One child at a time, recursing through the wrappers, JSX inserts around shapes: an array (every
|
|
951
|
+
// `{shapes.map(...)}`, and arrays of arrays when those nest) and a fragment, either of which can
|
|
952
|
+
// sit anywhere a shape can. Both are transparent — they carry no paint and no transform.
|
|
953
|
+
const walk = (c, paint, T) => {
|
|
954
|
+
if (isEmptyChild(c)) return;
|
|
955
|
+
if (Array.isArray(c)) {
|
|
956
|
+
for (const item of c) walk(item, paint, T);
|
|
957
|
+
return;
|
|
774
958
|
}
|
|
959
|
+
if (!isElement(c)) return warnSvgChild(c);
|
|
960
|
+
const p = c.props || {};
|
|
961
|
+
if (c.type === REACT_FRAGMENT) return walk(p.children, paint, T);
|
|
962
|
+
const merged = mergePaint(paint, p);
|
|
963
|
+
if (c.type === 'G') {
|
|
964
|
+
// Compose a translate/scale for the group, then recurse.
|
|
965
|
+
const s = num(p.scale, 1);
|
|
966
|
+
const gx = num(p.x ?? p.translateX, 0);
|
|
967
|
+
const gy = num(p.y ?? p.translateY, 0);
|
|
968
|
+
const childT = {
|
|
969
|
+
sx: T.sx * s,
|
|
970
|
+
sy: T.sy * s,
|
|
971
|
+
tx: gx * T.sx + T.tx,
|
|
972
|
+
ty: gy * T.sy + T.ty,
|
|
973
|
+
};
|
|
974
|
+
return walk(p.children, merged, childT);
|
|
975
|
+
}
|
|
976
|
+
if (!SVG_TAGS.includes(c.type)) return warnSvgChild(c);
|
|
977
|
+
|
|
978
|
+
// Path/Ellipse geometry comes from a `d` string and is cached (parse + transform) by that string;
|
|
979
|
+
// the primitives build a fixed handful of numbers, which is cheaper than any cache lookup.
|
|
980
|
+
let entry = null;
|
|
981
|
+
let shapeOps = null;
|
|
982
|
+
if (c.type === 'Path' && p.d)
|
|
983
|
+
entry = pathEntry(p.d); // pathEntry coerces the key
|
|
984
|
+
else if (c.type === 'Ellipse') entry = pathEntry(ellipsePathD(p));
|
|
985
|
+
else if (c.type === 'Circle') shapeOps = circleOps(p);
|
|
986
|
+
else if (c.type === 'Rect') shapeOps = rectOps(p);
|
|
987
|
+
else if (c.type === 'Line') shapeOps = lineOps(p);
|
|
988
|
+
else if (c.type === 'Arc')
|
|
989
|
+
shapeOps = arcOpsCW(
|
|
990
|
+
num(p.cx, 0),
|
|
991
|
+
num(p.cy, 0),
|
|
992
|
+
num(p.r, 0),
|
|
993
|
+
num(p.startAngle, 0),
|
|
994
|
+
num(p.endAngle, 0),
|
|
995
|
+
);
|
|
996
|
+
const baseOps = entry ? entry.ops : shapeOps;
|
|
997
|
+
if (!baseOps || baseOps.length === 0) return;
|
|
998
|
+
|
|
999
|
+
const seg = entry ? transformCached(entry, T) : transformOps(baseOps, T);
|
|
1000
|
+
const paintIndex = paints.length / PAINT_STRIDE;
|
|
1001
|
+
const scale = (T.sx + T.sy) / 2; // stroke-width scale (uniform assumed)
|
|
1002
|
+
paints.push(...paintRecord(merged, scale, gradients));
|
|
1003
|
+
// Appended one at a time: `seg` can be a long cached tape, and spreading it into push() both
|
|
1004
|
+
// copies it into an argument list and risks the call-argument limit.
|
|
1005
|
+
ops.push(VOP_SHAPE, paintIndex);
|
|
1006
|
+
for (let k = 0; k < seg.length; k++) ops.push(seg[k]);
|
|
775
1007
|
};
|
|
776
1008
|
|
|
777
1009
|
walk(props.children, PAINT_DEFAULT, root);
|
|
@@ -877,7 +1109,7 @@ export function warnVectorCaps(
|
|
|
877
1109
|
console.warn(
|
|
878
1110
|
`embedded-react: an <Svg> op-tape is too long (${opsLen} > ${maxOps} floats) and will be truncated — ` +
|
|
879
1111
|
`the shape gets cut off. Simplify the path (fewer/coarser curves) or split it across <Svg> nodes; ` +
|
|
880
|
-
`raising the limit needs
|
|
1112
|
+
`raising the limit needs ERUI_VECTOR_TAPE_MAX.`,
|
|
881
1113
|
);
|
|
882
1114
|
}
|
|
883
1115
|
const shapes = (paintsLen / PAINT_STRIDE) | 0;
|
|
@@ -885,7 +1117,7 @@ export function warnVectorCaps(
|
|
|
885
1117
|
_warnedVecPaints = true;
|
|
886
1118
|
console.warn(
|
|
887
1119
|
`embedded-react: an <Svg> has ${shapes} shapes (> ${maxPaints}) — the extra shapes won't render. ` +
|
|
888
|
-
`Split them across multiple <Svg> nodes; raising the limit needs
|
|
1120
|
+
`Split them across multiple <Svg> nodes; raising the limit needs ERUI_VECTOR_PAINTS_MAX.`,
|
|
889
1121
|
);
|
|
890
1122
|
}
|
|
891
1123
|
if (!_warnedVecGrads && maxGrads > 0 && gradsLen > maxGrads) {
|
|
@@ -893,7 +1125,7 @@ export function warnVectorCaps(
|
|
|
893
1125
|
console.warn(
|
|
894
1126
|
`embedded-react: an <Svg> references ${gradsLen} gradients (> ${maxGrads}) — the extra gradients are ` +
|
|
895
1127
|
`dropped and shapes that use them fall back to solid fills/strokes. Reuse fewer distinct gradients across ` +
|
|
896
|
-
`shapes; raising the limit needs
|
|
1128
|
+
`shapes; raising the limit needs ERUI_VECTOR_GRADS_MAX.`,
|
|
897
1129
|
);
|
|
898
1130
|
}
|
|
899
1131
|
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026 Cory Lamming
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
// Shared "you passed a prop this component ignores" warning for the JS-only RN wrappers (Button,
|
|
18
|
+
// FlatList, ImageBackground, SectionList). Those components exist for API compatibility, so an app
|
|
19
|
+
// ported from React Native arrives carrying props that mean nothing on a panel — and a prop that is
|
|
20
|
+
// silently dropped is the worst outcome, because the UI just quietly isn't what the source says.
|
|
21
|
+
//
|
|
22
|
+
// Warns ONCE per component and then stops scanning: these render on the Flow A commit path, and a
|
|
23
|
+
// misconfigured list re-renders on every data change. One line in the device console is a hint; one
|
|
24
|
+
// line per commit is a flood that pushes everything else out of the scrollback.
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* RN props that wrap an OS service a bare panel does not have: a screen reader, a focus engine, a test
|
|
28
|
+
* runner, a click sound. They are real RN props, they cost nothing to carry, and keeping them means a
|
|
29
|
+
* component still compiles when it goes back to React Native — so a wrapper drops them without a word
|
|
30
|
+
* rather than making an app strip them to silence a warning.
|
|
31
|
+
*
|
|
32
|
+
* Note that <FlatList> deliberately does NOT quiet these: it is the one wrapper the AOT lowers, and it
|
|
33
|
+
* rejects every prop outside its supported four, so a `testID` there fails the device build. Warning
|
|
34
|
+
* about it is the point.
|
|
35
|
+
*/
|
|
36
|
+
export const RN_PLATFORM_NO_OPS = [
|
|
37
|
+
'accessible',
|
|
38
|
+
'accessibilityLabel',
|
|
39
|
+
'accessibilityHint',
|
|
40
|
+
'accessibilityLanguage',
|
|
41
|
+
'accessibilityRole',
|
|
42
|
+
'accessibilityState',
|
|
43
|
+
'accessibilityActions',
|
|
44
|
+
'onAccessibilityAction',
|
|
45
|
+
'importantForAccessibility',
|
|
46
|
+
'testID',
|
|
47
|
+
'touchSoundDisabled',
|
|
48
|
+
'hasTVPreferredFocus',
|
|
49
|
+
'nextFocusDown',
|
|
50
|
+
'nextFocusForward',
|
|
51
|
+
'nextFocusLeft',
|
|
52
|
+
'nextFocusRight',
|
|
53
|
+
'nextFocusUp',
|
|
54
|
+
];
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Builds the once-only prop warner for a component.
|
|
58
|
+
*
|
|
59
|
+
* @param {string} component Component name, as it appears in JSX (no angle brackets).
|
|
60
|
+
* @param {string[]} supported Props the component honours. Listed in the warning as the way out.
|
|
61
|
+
* @param {string} hint Why the rest are ignored / what to reach for instead. Ends the first sentence.
|
|
62
|
+
* @param {string[]} [quiet] Props to ignore silently — RN props that wrap an OS service this board
|
|
63
|
+
* doesn't have (accessibility, TV focus, test ids). They are portable no-ops, not mistakes.
|
|
64
|
+
* @returns {(props: object) => void} Call with the full prop object on every render.
|
|
65
|
+
*/
|
|
66
|
+
export function createPropWarner(component, supported, hint, quiet = []) {
|
|
67
|
+
let warned = false;
|
|
68
|
+
return props => {
|
|
69
|
+
if (warned) return;
|
|
70
|
+
const names = Object.keys(props).filter(
|
|
71
|
+
k => !supported.includes(k) && !quiet.includes(k),
|
|
72
|
+
);
|
|
73
|
+
if (names.length === 0) return;
|
|
74
|
+
warned = true;
|
|
75
|
+
console.warn(
|
|
76
|
+
`embedded-react: <${component}> ignores ${names.join(', ')} — ${hint} ` +
|
|
77
|
+
`Supported here: ${supported.join(', ')}.`,
|
|
78
|
+
);
|
|
79
|
+
};
|
|
80
|
+
}
|