@symbiote-native/angular 2.0.0 → 3.0.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 +5 -4
- package/babel-register-composed.cjs +0 -8
- package/build/angular/callback-host.d.ts +25 -0
- package/build/angular/callback-host.js +211 -0
- package/build/angular/callback-host.js.map +1 -0
- package/build/angular/change-detection-flush.d.ts +14 -2
- package/build/angular/change-detection-flush.js +54 -6
- package/build/angular/change-detection-flush.js.map +1 -1
- package/build/angular/components/flat-list/index.js +39 -86
- package/build/angular/components/flat-list/index.js.map +1 -1
- package/build/angular/components/image-shared.js +49 -110
- package/build/angular/components/image-shared.js.map +1 -1
- package/build/angular/components/keyboard-avoiding-view/index.js +33 -72
- package/build/angular/components/keyboard-avoiding-view/index.js.map +1 -1
- package/build/angular/components/modal/index.js +58 -103
- package/build/angular/components/modal/index.js.map +1 -1
- package/build/angular/components/pressable-props.d.ts +2 -0
- package/build/angular/components/section-list/index.js +20 -103
- package/build/angular/components/section-list/index.js.map +1 -1
- package/build/angular/components/touchable-props.d.ts +1 -0
- package/build/angular/components/virtualized-list/directives.js +32 -22
- package/build/angular/components/virtualized-list/directives.js.map +1 -1
- package/build/angular/components/virtualized-list/index.d.ts +7 -1
- package/build/angular/components/virtualized-list/index.js +350 -359
- package/build/angular/components/virtualized-list/index.js.map +1 -1
- package/build/angular/components/virtualized-section-list/directives.js +20 -12
- package/build/angular/components/virtualized-section-list/directives.js.map +1 -1
- package/build/angular/components/virtualized-section-list/index.js +36 -142
- package/build/angular/components/virtualized-section-list/index.js.map +1 -1
- package/build/angular/components.d.ts +1 -1
- package/build/angular/components.js +1 -1
- package/build/angular/components.js.map +1 -1
- package/build/angular/create-portal/index.js +9 -8
- package/build/angular/create-portal/index.js.map +1 -1
- package/build/angular/create-tunnel/index.js +13 -12
- package/build/angular/create-tunnel/index.js.map +1 -1
- package/build/angular/descriptor-to-angular/index.js +6 -6
- package/build/angular/descriptor-to-angular/index.js.map +1 -1
- package/build/angular/diagnostics.d.ts +13 -0
- package/build/angular/diagnostics.js +18 -0
- package/build/angular/diagnostics.js.map +1 -1
- package/build/angular/element-props.d.ts +1 -3
- package/build/angular/elements.d.ts +46 -32
- package/build/angular/elements.js +217 -434
- package/build/angular/elements.js.map +1 -1
- package/build/angular/index.d.ts +3 -1
- package/build/angular/index.js +44 -13
- package/build/angular/index.js.map +1 -1
- package/build/angular/modules/animated/animated-leaf-binder.js +0 -2
- package/build/angular/modules/animated/animated-leaf-binder.js.map +1 -1
- package/build/angular/modules/animated/create-animated-component.js +69 -74
- package/build/angular/modules/animated/create-animated-component.js.map +1 -1
- package/build/angular/modules/animated/index.d.ts +30 -19
- package/build/angular/modules/status-bar/index.js +2 -8
- package/build/angular/modules/status-bar/index.js.map +1 -1
- package/build/angular/primitives/index.d.ts +14 -28
- package/build/angular/primitives/index.js +44 -107
- package/build/angular/primitives/index.js.map +1 -1
- package/build/angular/primitives/shared.d.ts +1 -0
- package/build/angular/primitives/shared.js +47 -32
- package/build/angular/primitives/shared.js.map +1 -1
- package/build/angular/render/index.js +34 -1
- package/build/angular/render/index.js.map +1 -1
- package/build/angular/renderer/index.d.ts +56 -0
- package/build/angular/renderer/index.js +295 -114
- package/build/angular/renderer/index.js.map +1 -1
- package/build/angular/runtime-matching.d.ts +9 -0
- package/build/angular/runtime-matching.js +82 -0
- package/build/angular/runtime-matching.js.map +1 -0
- package/build/angular/services/color-scheme.service.js +4 -4
- package/build/angular/services/color-scheme.service.js.map +1 -1
- package/build/angular/services/window-dimensions.service.js +4 -4
- package/build/angular/services/window-dimensions.service.js.map +1 -1
- package/build/angular/style-host.d.ts +11 -0
- package/build/angular/style-host.js +86 -0
- package/build/angular/style-host.js.map +1 -0
- package/metro-config.cjs +32 -16
- package/package.json +5 -5
- package/src/callback-host.ts +229 -0
- package/src/change-detection-flush.ts +62 -9
- package/src/components/flat-list/index.ts +2 -1
- package/src/components/keyboard-avoiding-view/index.ts +8 -0
- package/src/components/pressable-props.ts +8 -0
- package/src/components/touchable-props.ts +4 -0
- package/src/components/virtualized-list/index.ts +98 -45
- package/src/components.ts +0 -2
- package/src/diagnostics.ts +18 -0
- package/src/element-props.ts +1 -5
- package/src/elements.ts +159 -38
- package/src/index.ts +47 -14
- package/src/primitives/index.ts +14 -70
- package/src/primitives/shared.ts +21 -6
- package/src/render/index.ts +44 -0
- package/src/renderer/index.ts +347 -104
- package/src/runtime-matching.ts +80 -0
- package/src/style-host.ts +94 -0
- package/tsconfig.angular.base.json +11 -0
package/src/renderer/index.ts
CHANGED
|
@@ -10,19 +10,26 @@ import {
|
|
|
10
10
|
createAnchor,
|
|
11
11
|
createElement,
|
|
12
12
|
createRawText,
|
|
13
|
+
componentOf,
|
|
13
14
|
dlog,
|
|
14
15
|
getExplicitStyle,
|
|
15
16
|
insertBefore,
|
|
16
17
|
isDebug,
|
|
18
|
+
isRawTextNode,
|
|
17
19
|
isSymbioteEvent,
|
|
18
20
|
isSymbioteNode,
|
|
21
|
+
isTextContainer,
|
|
22
|
+
isSameShallowStyle,
|
|
23
|
+
nextSiblingOf,
|
|
24
|
+
parentOf,
|
|
25
|
+
propOf,
|
|
26
|
+
registerBeforeFlush,
|
|
19
27
|
removeChild,
|
|
20
28
|
routeProp,
|
|
21
29
|
setEventListener,
|
|
22
|
-
setProp,
|
|
23
30
|
setText,
|
|
31
|
+
textOf,
|
|
24
32
|
toPublicInstance,
|
|
25
|
-
RAW_TEXT_COMPONENT,
|
|
26
33
|
SymbioteSurface,
|
|
27
34
|
type ISymbioteNode,
|
|
28
35
|
} from '@symbiote-native/engine';
|
|
@@ -30,12 +37,12 @@ import {
|
|
|
30
37
|
COMPONENT_DESCRIPTORS,
|
|
31
38
|
descriptorFor,
|
|
32
39
|
} from '@symbiote-native/components';
|
|
33
|
-
import { foldHostBag } from '@symbiote-native/components/fold-host-bag';
|
|
34
40
|
import type { Renderer2, RendererFactory2, RendererType2 } from '@angular/core';
|
|
35
41
|
import { isAnchorHostComponent } from '../anchor-host-registry';
|
|
36
42
|
import {
|
|
37
43
|
countAngular,
|
|
38
44
|
noteAngularCreate,
|
|
45
|
+
noteAngularStyleWrite,
|
|
39
46
|
noteAngularWrite,
|
|
40
47
|
} from '../diagnostics';
|
|
41
48
|
// Angular host nodes are all SymbioteNode (elements, raw text, anchors). The mount
|
|
@@ -48,71 +55,34 @@ function isSurface(parent: IHostElement): parent is SymbioteSurface {
|
|
|
48
55
|
}
|
|
49
56
|
|
|
50
57
|
function isRawText(node: ISymbioteNode): boolean {
|
|
51
|
-
return node
|
|
58
|
+
return isRawTextNode(node);
|
|
52
59
|
}
|
|
53
60
|
|
|
54
61
|
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
55
62
|
return typeof value === 'object' && value !== null;
|
|
56
63
|
}
|
|
57
64
|
|
|
58
|
-
// RN's
|
|
59
|
-
//
|
|
60
|
-
//
|
|
61
|
-
//
|
|
62
|
-
// doesn't have this split" reasoning elsewhere in this file), so createElement runs for its INNER
|
|
63
|
-
// text node too; seeding here therefore covers both the composed Text and any bare
|
|
64
|
-
// `text` a future lowering emits, uniformly. Found missing 2026-08-31 (a cross-adapter
|
|
65
|
-
// key-count diff against Vue's real BenchmarkRow.vue) — without this a lowered Text's
|
|
66
|
-
// `numberOfLines` clips with no ellipsis, silently, on device only. Vue's renderer already does
|
|
67
|
-
// this (`adapters/vue/src/renderer/index.ts`'s `seedTextDefaults`); Angular's simply never did.
|
|
65
|
+
// RN's TWO TEXT DEFAULTS LEFT THIS RENDERER ENTIRELY ON 2026-09-18, in two steps a fortnight apart.
|
|
66
|
+
// The SEED went first, to the payload builder — writing them as props cost a crossing every time an
|
|
67
|
+
// app authored the same value (6 000 per 1 000-row create, `writesOfUnchanged`). What stayed was a
|
|
68
|
+
// resolver for the clear-back path: a write of `undefined` looked up the default instead of clearing.
|
|
68
69
|
//
|
|
69
|
-
//
|
|
70
|
-
// `
|
|
71
|
-
//
|
|
72
|
-
//
|
|
73
|
-
// `
|
|
74
|
-
//
|
|
75
|
-
// exactly the seed this function needs.
|
|
76
|
-
function seedTextDefaults(node: ISymbioteNode): void {
|
|
77
|
-
const seeded = foldHostBag('text', {});
|
|
78
|
-
for (const [key, value] of Object.entries(seeded)) setProp(node, key, value);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// An explicit `undefined` must NOT clear one of those defaults — RN treats a missing prop and an
|
|
82
|
-
// explicit undefined alike, and only a literal `false` opts allowFontScaling out. Reached only
|
|
83
|
-
// when a later write clears a key back to undefined, so it costs nothing on the common path.
|
|
84
|
-
// `foldHostBag` folds every Text default when called this way (not just `key`), because its
|
|
85
|
-
// contract is "fold a whole bag" — the extra key computed alongside `key` is simply unread here.
|
|
86
|
-
function textDefaultFor(el: IHostElement, key: string): unknown {
|
|
87
|
-
if (isSurface(el) || !el.isText) return undefined;
|
|
88
|
-
return foldHostBag('text', { [key]: undefined })[key];
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// RN's `id` is the modern W3C-named alias for `nativeID` (core/components/host-primitives.cjs's
|
|
92
|
-
// `ID_ALIAS`) — View.js/Text.js copy it over unconditionally, so the two name ONE native prop.
|
|
93
|
-
// React/Solid/Svelte fold it in a wrapper or transform; Angular had it nowhere, so `<view
|
|
94
|
-
// id="x">`/`[id]="x"` reached Fabric with an unknown `id` key and no `nativeID` — silently, on
|
|
95
|
-
// device only. Lives in the renderer (mirroring Vue's `PROP_ALIASES`) so it covers every path
|
|
96
|
-
// that can set a prop — `setAttribute`, `setProperty`, and (should a future lowering emit one) a
|
|
97
|
-
// hand-built call — not just the composed component's own `id` @Input.
|
|
98
|
-
// `symbioteStyle` is what the lowering transform emits in place of `[style]`: Angular routes a
|
|
99
|
-
// `style` binding to its own CSS styling engine, which cannot represent an RN StyleProp (an array
|
|
100
|
-
// throws inside change detection). Under any other name it is an ordinary property binding and
|
|
101
|
-
// arrives here.
|
|
70
|
+
// That is gone too, and for the reason the seed was: `applyTextDefaults` (and its C++ twin) runs on
|
|
71
|
+
// EVERY commit of every `RCTText`, so a cleared key is absent for exactly as long as it takes the
|
|
72
|
+
// payload builder to supply the default again. The resolver was answering a question nothing asks.
|
|
73
|
+
//
|
|
74
|
+
// `PROP_ALIASES` (`id` -> `nativeID`) left this renderer on 2026-09-18 — `routeProp` resolves it
|
|
75
|
+
// for every adapter now, so every path that can set a prop still reaches it.
|
|
102
76
|
// Angular's two-way sugar `[(value)]` compiles to a `(valueChange)` binding; the engine knows the
|
|
103
77
|
// same fold as the function prop `onValueChange`. See `listen()`. The two names live in a leaf
|
|
104
78
|
// module so `elements.ts`'s ControlValueAccessor can name them without importing this cyclic file.
|
|
105
79
|
import { VALUE_CHANGE_EVENT, VALUE_CHANGE_PROP } from './value-change';
|
|
106
|
-
import {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
function aliasedPropName(name: string): string {
|
|
114
|
-
return PROP_ALIASES.get(name) ?? name;
|
|
115
|
-
}
|
|
80
|
+
import {
|
|
81
|
+
createCallbackWrapper,
|
|
82
|
+
flushViewFor,
|
|
83
|
+
isWrappableCallback,
|
|
84
|
+
type ICallbackWrapper,
|
|
85
|
+
} from '../change-detection-flush';
|
|
116
86
|
|
|
117
87
|
// The app callbacks an engine behavior READS BACK inside the same microtask turn, as an Angular
|
|
118
88
|
// `(event)` binding — `valueChange` is handled in `listen` on its own, since it also needs the field
|
|
@@ -125,8 +95,53 @@ function aliasedPropName(name: string): string {
|
|
|
125
95
|
// and adds the `markForCheck` a prop callback needs and an event binding gets from Angular.
|
|
126
96
|
const READ_BACK_EVENTS: ReadonlySet<string> = new Set(['refresh']);
|
|
127
97
|
|
|
98
|
+
// How many distinct style objects the renderer keeps to hand back by identity. A screen's styles are
|
|
99
|
+
// a handful; the bench row has four. See `publishedStyles`.
|
|
100
|
+
const STYLE_CACHE = 16;
|
|
101
|
+
|
|
128
102
|
type IReadBackListener = (event: unknown) => unknown;
|
|
129
103
|
|
|
104
|
+
// `listen(VALUE_CHANGE_EVENT)` can be called TWICE for the SAME logical `(valueChange)`/`[(value)]`
|
|
105
|
+
// binding on a MATCHED element — Angular's own compiled output-binding codegen wires one listener,
|
|
106
|
+
// `ValueChangeElement.ngOnInit`'s manual bridge wires a second (`lowered-two-way-value.test.ts`,
|
|
107
|
+
// "delivers a bound handler exactly once per change"). Those two must DEDUPE (last one replaces,
|
|
108
|
+
// not composes — firing both double-delivers the identical value). A genuinely different explicit
|
|
109
|
+
// `[onValueChange]` app-level handler (routed here via `ngOnChanges`'s generic per-input loop) must
|
|
110
|
+
// instead be PRESERVED and called alongside the bridge, or it silently stops firing the moment
|
|
111
|
+
// `[(value)]`/`(valueChange)` is also bound. This set is what tells the two cases apart.
|
|
112
|
+
const bridgedValueChangeHandlers = new WeakSet<IReadBackListener>();
|
|
113
|
+
|
|
114
|
+
// The genuinely explicit `[onValueChange]` app handler for a node, if one is bound — read LIVE by
|
|
115
|
+
// the composed forward function on every event rather than captured once at compose time. That is
|
|
116
|
+
// what makes handler installation order-independent: `ngOnChanges` (the explicit handler) and the
|
|
117
|
+
// two `listen(VALUE_CHANGE_EVENT)` calls (the bridge, see below) can happen in any interleaving —
|
|
118
|
+
// at initial mount OR on a later `[onValueChange]` rebind (`ngOnChanges` again, same code path,
|
|
119
|
+
// routed through `setProperty`) — without one silently overwriting the other's closure.
|
|
120
|
+
const explicitValueChangeHandlers = new WeakMap<
|
|
121
|
+
ISymbioteNode,
|
|
122
|
+
IReadBackListener
|
|
123
|
+
>();
|
|
124
|
+
|
|
125
|
+
function composeValueChangeHandler(
|
|
126
|
+
target: ISymbioteNode,
|
|
127
|
+
bridgeCallback: (event: unknown) => boolean | void,
|
|
128
|
+
): IReadBackListener {
|
|
129
|
+
const forwardValue = withChangeDetection(target, (event: unknown) => {
|
|
130
|
+
explicitValueChangeHandlers.get(target)?.(event);
|
|
131
|
+
if (isSymbioteEvent(event)) {
|
|
132
|
+
if ('text' in event) return bridgeCallback(event.text);
|
|
133
|
+
if ('value' in event) return bridgeCallback(event.value);
|
|
134
|
+
}
|
|
135
|
+
return bridgeCallback(event);
|
|
136
|
+
});
|
|
137
|
+
bridgedValueChangeHandlers.add(forwardValue);
|
|
138
|
+
return forwardValue;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function isReadBackListener(value: unknown): value is IReadBackListener {
|
|
142
|
+
return typeof value === 'function';
|
|
143
|
+
}
|
|
144
|
+
|
|
130
145
|
function withChangeDetection(
|
|
131
146
|
node: IHostElement,
|
|
132
147
|
listener: IReadBackListener,
|
|
@@ -158,8 +173,8 @@ function describeHost(node: IHostElement | null | undefined): string {
|
|
|
158
173
|
if (isSurface(node)) return 'surface';
|
|
159
174
|
const anchorId = anchorDebugIds.get(node);
|
|
160
175
|
return anchorId !== undefined
|
|
161
|
-
? `${node
|
|
162
|
-
: node
|
|
176
|
+
? `${componentOf(node)}#${anchorId}`
|
|
177
|
+
: componentOf(node);
|
|
163
178
|
}
|
|
164
179
|
|
|
165
180
|
// A hand-written tag ngtsc accepts must contain a HYPHEN, so the six dashless intrinsics
|
|
@@ -204,9 +219,9 @@ const PRIMITIVE_SELECTOR_ALIAS: Record<string, string> = {
|
|
|
204
219
|
// stray RCTRawText would paint). Angular's ɵɵtext only ever lands text inside a <text>,
|
|
205
220
|
// but guard anyway for parity with the Vue adapter and to fail loudly on a bad template.
|
|
206
221
|
function assertTextPlacement(child: ISymbioteNode, parent: IHostElement): void {
|
|
207
|
-
if (isRawText(child) && (isSurface(parent) || !parent
|
|
222
|
+
if (isRawText(child) && (isSurface(parent) || !isTextContainer(parent))) {
|
|
208
223
|
throw new Error(
|
|
209
|
-
`Text string "${
|
|
224
|
+
`Text string "${textOf(child) ?? ''}" must be rendered inside a <text>`,
|
|
210
225
|
);
|
|
211
226
|
}
|
|
212
227
|
}
|
|
@@ -220,9 +235,144 @@ export class SymbioteRenderer implements Renderer2 {
|
|
|
220
235
|
// render.ts (unmount), so per-node cleanup is a no-op.
|
|
221
236
|
destroyNode: ((node: ISymbioteNode) => void) | null = null;
|
|
222
237
|
|
|
223
|
-
|
|
238
|
+
// THE STYLING RUN, and why it is held rather than published key by key.
|
|
239
|
+
//
|
|
240
|
+
// Angular has no whole-value styling call: `ɵɵstyleMap` / `ɵɵclassMap` walk the key-value array
|
|
241
|
+
// and call `setStyle` / `addClass` once PER KEY (`updateStyling` -> `applyStyling`, upstream
|
|
242
|
+
// `@angular/core`). RN wants one `style` prop, so publishing on each call rebuilt the whole object
|
|
243
|
+
// every time — N writes for an N-key style, the k-th carrying k keys, and N DISTINCT values where
|
|
244
|
+
// the app authored one. Measured on the headless bench arm: `values` 10 001 against Vue's 3 004
|
|
245
|
+
// for the identical tree, and `convert` 30.0 ms against 0.6.
|
|
246
|
+
//
|
|
247
|
+
// The run is safe to hold because it is CONTIGUOUS: `updateStyling` takes its node from
|
|
248
|
+
// `getSelectedIndex()` and the loop never changes element mid-way, so the calls for one node
|
|
249
|
+
// arrive with nothing between them. Anything else — a different node, any other renderer call, a
|
|
250
|
+
// host read, the commit — closes it first.
|
|
251
|
+
// `ISymbioteNode`, not `IHostElement`: a surface is turned away by `isSurface` at every entry
|
|
252
|
+
// point, so a run can only ever be open on a real node, and saying so keeps the publish below
|
|
253
|
+
// free of a second guard.
|
|
254
|
+
private pendingStyleNode: ISymbioteNode | undefined;
|
|
255
|
+
private pendingStyle: Record<string, unknown> = {};
|
|
256
|
+
private pendingClassNode: ISymbioteNode | undefined;
|
|
257
|
+
private readonly releaseBeforeFlush: () => void;
|
|
258
|
+
|
|
259
|
+
constructor(private readonly surface: SymbioteSurface) {
|
|
260
|
+
// A READ AND A COMMIT BOTH ARRIVE FROM ELSEWHERE, so the renderer cannot close the run on its
|
|
261
|
+
// own: a turn whose last act is a style change has no next call to close it, and the commit
|
|
262
|
+
// would paint the node without it. `flushOps` is the one door in front of every drain.
|
|
263
|
+
this.releaseBeforeFlush = registerBeforeFlush(() => this.flushStyling());
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
destroy(): void {
|
|
267
|
+
this.flushStyling();
|
|
268
|
+
this.releaseBeforeFlush();
|
|
269
|
+
}
|
|
224
270
|
|
|
225
|
-
|
|
271
|
+
/**
|
|
272
|
+
* Publish whatever the styling run is holding. Idempotent, and free when it holds nothing.
|
|
273
|
+
*
|
|
274
|
+
* IT DOES NOT REQUEST A COMMIT, and that is not an omission — the request is made when the style
|
|
275
|
+
* is ACCUMULATED, exactly where it was made before the run existed. This runs from inside
|
|
276
|
+
* `flushOps`, which the commit itself calls first, so asking there schedules a SECOND commit whose
|
|
277
|
+
* tree is already current: a full `completeRoot` plus a Yoga pass for nothing.
|
|
278
|
+
*
|
|
279
|
+
* Measured, because it did not look like a cost. The bench arm's `select` fell 17.1 -> 3.8 ms and
|
|
280
|
+
* its `remove` rose 7.1 -> 18.2 in the same runs — the extra commit lands in whichever step's
|
|
281
|
+
* microtask happens to run it, so the work had MOVED between steps rather than gone. Two rows
|
|
282
|
+
* moving by the same amount in opposite directions is what that always looks like.
|
|
283
|
+
*/
|
|
284
|
+
private flushStyling(): void {
|
|
285
|
+
const styled = this.pendingStyleNode;
|
|
286
|
+
if (styled !== undefined) {
|
|
287
|
+
const style = this.pendingStyle;
|
|
288
|
+
this.pendingStyleNode = undefined;
|
|
289
|
+
this.pendingStyle = {};
|
|
290
|
+
routeProp(styled, 'style', this.canonicalStyle(style));
|
|
291
|
+
}
|
|
292
|
+
const classed = this.pendingClassNode;
|
|
293
|
+
if (classed !== undefined) {
|
|
294
|
+
this.pendingClassNode = undefined;
|
|
295
|
+
routeProp(classed, 'class', this.classStringFor(classed));
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* The union of a node's two class sources, or `undefined` when it has none.
|
|
301
|
+
*
|
|
302
|
+
* A node can be told its classes BOTH ways in one pass: Ivy compiles `[class.foo]`, `[ngClass]`
|
|
303
|
+
* and a static `class=` down to per-token `addClass`/`removeClass`, while a whole-string `class`
|
|
304
|
+
* arrives at `setProperty` — which is the shape Angular uses when a directive declares `class` as
|
|
305
|
+
* an input and the styling binding is shadowed into it (`setShadowStylingInputFlags`,
|
|
306
|
+
* `view/directives.ts`). Publishing either one alone erases the other, and the DOM renderer this
|
|
307
|
+
* mirrors has no such problem because `classList` accumulates for it.
|
|
308
|
+
*/
|
|
309
|
+
private classStringFor(el: ISymbioteNode): string | undefined {
|
|
310
|
+
const tokens = this.classTokens.get(el);
|
|
311
|
+
const whole = this.classStrings.get(el);
|
|
312
|
+
if (whole === undefined) {
|
|
313
|
+
return tokens !== undefined && tokens.size > 0
|
|
314
|
+
? [...tokens].join(' ')
|
|
315
|
+
: undefined;
|
|
316
|
+
}
|
|
317
|
+
if (tokens === undefined || tokens.size === 0) {
|
|
318
|
+
return whole.length > 0 ? whole : undefined;
|
|
319
|
+
}
|
|
320
|
+
const union = new Set(
|
|
321
|
+
whole.split(/\s+/u).filter(token => token.length > 0),
|
|
322
|
+
);
|
|
323
|
+
for (const token of tokens) union.add(token);
|
|
324
|
+
return union.size > 0 ? [...union].join(' ') : undefined;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* Style objects this renderer has already published, so a list of identical rows sends ONE.
|
|
329
|
+
*
|
|
330
|
+
* The intern table keys by IDENTITY, so a fresh object per node is a fresh entry per node and the
|
|
331
|
+
* host converts every entry across JSI. Measured on the bench arm: `values` 7 001 against Vue's
|
|
332
|
+
* 3 004 for the identical tree, with `convert` 19.5 ms against 0.6 — and the gap is the KIND
|
|
333
|
+
* rather than the count, ~4 000 of Angular's being objects that convert recursively where Vue's
|
|
334
|
+
* are scalars plus four hoisted styles every row shares.
|
|
335
|
+
*
|
|
336
|
+
* Angular cannot share them on its own: `ɵɵstyleMap` hands over KEYS, so the object is this
|
|
337
|
+
* renderer's own construction. Recognising one it has already built is what puts an Angular app
|
|
338
|
+
* back on the footing of a framework whose author hoisted the constant.
|
|
339
|
+
*
|
|
340
|
+
* SMALL AND MRU. A screen has a handful of distinct styles and re-publishes them thousands of
|
|
341
|
+
* times, so a hit is almost always at the front; a miss costs at most `STYLE_CACHE` shallow
|
|
342
|
+
* compares, which is nothing beside the conversion it saves. An app with more distinct styles than
|
|
343
|
+
* this simply stops sharing — it never stops being correct.
|
|
344
|
+
*/
|
|
345
|
+
private readonly publishedStyles: Record<string, unknown>[] = [];
|
|
346
|
+
|
|
347
|
+
/** A published object equal to this one, or this one — which then becomes the published copy. */
|
|
348
|
+
private canonicalStyle(
|
|
349
|
+
style: Record<string, unknown>,
|
|
350
|
+
): Record<string, unknown> {
|
|
351
|
+
for (let at = 0; at < this.publishedStyles.length; at += 1) {
|
|
352
|
+
const known = this.publishedStyles[at];
|
|
353
|
+
if (!isSameShallowStyle(style, known)) continue;
|
|
354
|
+
if (at > 0) {
|
|
355
|
+
this.publishedStyles.splice(at, 1);
|
|
356
|
+
this.publishedStyles.unshift(known);
|
|
357
|
+
}
|
|
358
|
+
return known;
|
|
359
|
+
}
|
|
360
|
+
this.publishedStyles.unshift(style);
|
|
361
|
+
if (this.publishedStyles.length > STYLE_CACHE) this.publishedStyles.pop();
|
|
362
|
+
return style;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/** The accumulator for this node's style run, opening one (and closing any other) if needed. */
|
|
366
|
+
private openStyleRun(el: ISymbioteNode): Record<string, unknown> {
|
|
367
|
+
if (this.pendingStyleNode === el) return this.pendingStyle;
|
|
368
|
+
this.flushStyling();
|
|
369
|
+
// Seeded from what is STANDING, because Angular sends only the keys that changed — an update
|
|
370
|
+
// that moves one key must not drop the rest.
|
|
371
|
+
const current = getExplicitStyle(el);
|
|
372
|
+
this.pendingStyle = isRecord(current) ? { ...current } : {};
|
|
373
|
+
this.pendingStyleNode = el;
|
|
374
|
+
return this.pendingStyle;
|
|
375
|
+
}
|
|
226
376
|
|
|
227
377
|
createElement(name: string): IHostNode {
|
|
228
378
|
// `name` is the component's host tag — a symbiote intrinsic (`view`,
|
|
@@ -270,7 +420,6 @@ export class SymbioteRenderer implements Renderer2 {
|
|
|
270
420
|
descriptor.isText,
|
|
271
421
|
engineName,
|
|
272
422
|
);
|
|
273
|
-
if (descriptor.isText) seedTextDefaults(node);
|
|
274
423
|
if (isDebug()) {
|
|
275
424
|
dlog(`angular createElement ${name} -> ${descriptor.component}`);
|
|
276
425
|
}
|
|
@@ -354,16 +503,23 @@ export class SymbioteRenderer implements Renderer2 {
|
|
|
354
503
|
// Detach from the child's own retained parent (a top-level node lives in
|
|
355
504
|
// surface.children with no parent). Angular's `parent` arg is ignored in favor of the
|
|
356
505
|
// authoritative link, mirroring the Vue adapter's remove.
|
|
506
|
+
// Angular tears down a root view by removing its HOST, which here is the surface itself. There
|
|
507
|
+
// is nothing above it to detach from — the old retained tree absorbed the call (`indexOf` of a
|
|
508
|
+
// node that is not in the list is -1), and the mutation buffer cannot: it would record a remove
|
|
509
|
+
// naming the surface as a child of its own node.
|
|
510
|
+
if (isSurface(oldChild)) return;
|
|
357
511
|
countAngular('nodesRemoved');
|
|
358
512
|
if (isDebug()) {
|
|
359
513
|
const angularParent = _parent !== null ? describeHost(_parent) : 'null';
|
|
360
514
|
const retainedParent =
|
|
361
|
-
oldChild
|
|
515
|
+
parentOf(oldChild) !== undefined
|
|
516
|
+
? describeHost(parentOf(oldChild))
|
|
517
|
+
: 'none';
|
|
362
518
|
dlog(
|
|
363
519
|
`Angular renderer removeChild angularParent=${angularParent} retainedParent=${retainedParent} child=${describeHost(oldChild)}`,
|
|
364
520
|
);
|
|
365
521
|
}
|
|
366
|
-
const parent = oldChild
|
|
522
|
+
const parent = parentOf(oldChild);
|
|
367
523
|
if (parent !== undefined) removeChild(parent, oldChild);
|
|
368
524
|
else this.surface.removeChild(oldChild);
|
|
369
525
|
this.surface.requestCommit();
|
|
@@ -383,14 +539,13 @@ export class SymbioteRenderer implements Renderer2 {
|
|
|
383
539
|
// does `inject(ViewContainerRef)`, e.g. VListOutletDirective) forwards this null straight into
|
|
384
540
|
// insertBefore without checking it; without that guard it crashed on-device.
|
|
385
541
|
parentNode(node: IHostNode): IHostElement | null {
|
|
386
|
-
return node
|
|
542
|
+
return parentOf(node) ?? null;
|
|
387
543
|
}
|
|
388
544
|
|
|
389
545
|
nextSibling(node: IHostNode): IHostNode | null {
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
return index >= 0 ? (siblings[index + 1] ?? null) : null;
|
|
546
|
+
// `?? null` because Renderer2 types the miss as null; the engine answers undefined
|
|
547
|
+
// uniformly and owns the top-level fallback through the surface it is handed.
|
|
548
|
+
return nextSiblingOf(node, this.surface) ?? null;
|
|
394
549
|
}
|
|
395
550
|
|
|
396
551
|
// locateHostElement always routes createComponent's `hostElement` THROUGH here as
|
|
@@ -401,20 +556,24 @@ export class SymbioteRenderer implements Renderer2 {
|
|
|
401
556
|
return typeof selectorOrNode === 'string' ? this.surface : selectorOrNode;
|
|
402
557
|
}
|
|
403
558
|
|
|
559
|
+
// The three prop writers below close the styling run FIRST. A read or a commit would do it through
|
|
560
|
+
// `registerBeforeFlush`, but neither happens here: this is one prop write landing on the same node
|
|
561
|
+
// whose `style` or `class` is still held, and a run published afterwards would overwrite it.
|
|
404
562
|
setAttribute(el: IHostElement, name: string, value: string): void {
|
|
405
563
|
if (isSurface(el)) return;
|
|
564
|
+
this.flushStyling();
|
|
406
565
|
countAngular('rendererWrites');
|
|
407
566
|
noteAngularWrite(name);
|
|
408
|
-
routeProp(el,
|
|
567
|
+
routeProp(el, name, value);
|
|
409
568
|
this.surface.requestCommit();
|
|
410
569
|
}
|
|
411
570
|
|
|
412
571
|
removeAttribute(el: IHostElement, name: string): void {
|
|
413
572
|
if (isSurface(el)) return;
|
|
573
|
+
this.flushStyling();
|
|
414
574
|
countAngular('rendererWrites');
|
|
415
575
|
noteAngularWrite(name);
|
|
416
|
-
|
|
417
|
-
routeProp(el, aliased, textDefaultFor(el, aliased));
|
|
576
|
+
routeProp(el, name, undefined);
|
|
418
577
|
this.surface.requestCommit();
|
|
419
578
|
}
|
|
420
579
|
|
|
@@ -427,6 +586,15 @@ export class SymbioteRenderer implements Renderer2 {
|
|
|
427
586
|
// resolves identically regardless of adapter.
|
|
428
587
|
private readonly classTokens = new WeakMap<IHostNode, Set<string>>();
|
|
429
588
|
|
|
589
|
+
// The OTHER class source: a whole string written as a prop. Kept apart from the token set rather
|
|
590
|
+
// than merged into it, because the two are replaced independently — a new `[class]` value
|
|
591
|
+
// replaces this string entirely while leaving every `[class.foo]` token standing.
|
|
592
|
+
private readonly classStrings = new WeakMap<IHostNode, string>();
|
|
593
|
+
private readonly callbackWrappers = new WeakMap<
|
|
594
|
+
IHostNode,
|
|
595
|
+
ICallbackWrapper
|
|
596
|
+
>();
|
|
597
|
+
|
|
430
598
|
addClass(el: IHostElement, name: string): void {
|
|
431
599
|
if (isSurface(el)) return;
|
|
432
600
|
countAngular('rendererWrites');
|
|
@@ -434,7 +602,7 @@ export class SymbioteRenderer implements Renderer2 {
|
|
|
434
602
|
const tokens = this.classTokens.get(el) ?? new Set<string>();
|
|
435
603
|
tokens.add(name);
|
|
436
604
|
this.classTokens.set(el, tokens);
|
|
437
|
-
|
|
605
|
+
this.openClassRun(el);
|
|
438
606
|
this.surface.requestCommit();
|
|
439
607
|
}
|
|
440
608
|
|
|
@@ -445,10 +613,18 @@ export class SymbioteRenderer implements Renderer2 {
|
|
|
445
613
|
countAngular('rendererWrites');
|
|
446
614
|
noteAngularWrite('class');
|
|
447
615
|
tokens.delete(name);
|
|
448
|
-
|
|
616
|
+
this.openClassRun(el);
|
|
449
617
|
this.surface.requestCommit();
|
|
450
618
|
}
|
|
451
619
|
|
|
620
|
+
// The token SET is the accumulator here — `addClass` has already put the token in it — so this
|
|
621
|
+
// only has to remember whose run is open. Closing it re-joins the set once.
|
|
622
|
+
private openClassRun(el: ISymbioteNode): void {
|
|
623
|
+
if (this.pendingClassNode === el) return;
|
|
624
|
+
this.flushStyling();
|
|
625
|
+
this.pendingClassNode = el;
|
|
626
|
+
}
|
|
627
|
+
|
|
452
628
|
// Angular decomposes a [style] binding into per-key setStyle calls (ɵɵstyleMap). RN wants
|
|
453
629
|
// the whole style object as one `style` prop, so merge each key into it — onto the explicit
|
|
454
630
|
// style half tracked by routeProp's centralized class+style merge (core/engine/src/node.ts),
|
|
@@ -457,21 +633,23 @@ export class SymbioteRenderer implements Renderer2 {
|
|
|
457
633
|
setStyle(el: IHostElement, style: string, value: unknown): void {
|
|
458
634
|
if (isSurface(el)) return;
|
|
459
635
|
countAngular('rendererWrites');
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
const base = isRecord(current) ? current : {};
|
|
463
|
-
routeProp(el, 'style', { ...base, [style]: value });
|
|
636
|
+
noteAngularStyleWrite(style);
|
|
637
|
+
this.openStyleRun(el)[style] = value;
|
|
464
638
|
this.surface.requestCommit();
|
|
465
639
|
}
|
|
466
640
|
|
|
467
641
|
removeStyle(el: IHostElement, style: string): void {
|
|
468
642
|
if (isSurface(el)) return;
|
|
469
|
-
|
|
470
|
-
|
|
643
|
+
// A remove on a node with no style at all is Angular clearing a binding it never set. Opening a
|
|
644
|
+
// run for it would publish an empty style onto a node that had none, which the old early return
|
|
645
|
+
// was there to avoid.
|
|
646
|
+
if (this.pendingStyleNode !== el && !isRecord(getExplicitStyle(el))) return;
|
|
471
647
|
countAngular('rendererWrites');
|
|
472
|
-
|
|
473
|
-
const
|
|
474
|
-
|
|
648
|
+
noteAngularStyleWrite(style);
|
|
649
|
+
const run = this.openStyleRun(el);
|
|
650
|
+
// The accumulator is this renderer's own object, never the node's — see `openStyleRun`.
|
|
651
|
+
|
|
652
|
+
delete run[style];
|
|
475
653
|
this.surface.requestCommit();
|
|
476
654
|
}
|
|
477
655
|
|
|
@@ -481,15 +659,64 @@ export class SymbioteRenderer implements Renderer2 {
|
|
|
481
659
|
if (isSurface(el)) return;
|
|
482
660
|
countAngular('rendererWrites');
|
|
483
661
|
noteAngularWrite(name);
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
662
|
+
// A WHOLE CLASS STRING IS NOT AN ORDINARY PROP: it is one of two sources the node's class list
|
|
663
|
+
// is built from, and writing it straight through would erase every `[class.foo]` token the
|
|
664
|
+
// other one put there. It joins the class run instead, exactly as `addClass` does.
|
|
665
|
+
if (name === 'class') {
|
|
666
|
+
this.openClassRun(el);
|
|
667
|
+
this.classStrings.set(el, typeof value === 'string' ? value : '');
|
|
668
|
+
this.surface.requestCommit();
|
|
669
|
+
return;
|
|
670
|
+
}
|
|
671
|
+
// `ngOnChanges` routes every `[onValueChange]` write here (both the initial bind and any
|
|
672
|
+
// later rebind to a new function reference) — never through `listen()`. When the write is a
|
|
673
|
+
// genuinely explicit app handler (not a prior bridge's own forward function), update the live
|
|
674
|
+
// slot `composeValueChangeHandler`'s forward function reads on every event; when a bridge is
|
|
675
|
+
// already installed on this node, that's ALL that's needed — the installed forward function
|
|
676
|
+
// picks the new handler up on its own, no re-route. Without this, a rebind after mount would
|
|
677
|
+
// silently kill the `[(value)]` two-way sync the moment it overwrote the composed prop raw.
|
|
678
|
+
if (name === VALUE_CHANGE_PROP) {
|
|
679
|
+
if (isReadBackListener(value) && !bridgedValueChangeHandlers.has(value)) {
|
|
680
|
+
explicitValueChangeHandlers.set(el, value);
|
|
681
|
+
} else {
|
|
682
|
+
explicitValueChangeHandlers.delete(el);
|
|
683
|
+
}
|
|
684
|
+
const current = propOf(el, VALUE_CHANGE_PROP);
|
|
685
|
+
const bridgeActive =
|
|
686
|
+
isReadBackListener(current) && bridgedValueChangeHandlers.has(current);
|
|
687
|
+
if (bridgeActive) {
|
|
688
|
+
this.surface.requestCommit();
|
|
689
|
+
return;
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
this.flushStyling();
|
|
693
|
+
routeProp(el, name, this.wrapCallback(el, name, value));
|
|
490
694
|
this.surface.requestCommit();
|
|
491
695
|
}
|
|
492
696
|
|
|
697
|
+
// AN `on*` PROP IS CALLED BY THE ENGINE, so Angular is told nothing and a plain field mutation
|
|
698
|
+
// inside the app's handler dirties no view — the "pan readout stuck at dx 0" bug
|
|
699
|
+
// `change-detection-flush.ts` records. It used to be wrapped by `SymbioteElement.ngOnChanges`,
|
|
700
|
+
// which is the wrong place now that most element directives are withheld from runtime matching
|
|
701
|
+
// (`../runtime-matching`): a withheld tag's binding reaches the renderer DIRECTLY through
|
|
702
|
+
// `ɵɵproperty` and never passes through a directive at all.
|
|
703
|
+
//
|
|
704
|
+
// Here it is reached by both paths and by every adapter surface — an element binding, a composed
|
|
705
|
+
// component's flat bag, an imperative write — which is a better home than the one it left.
|
|
706
|
+
//
|
|
707
|
+
// The cache is per NODE rather than per caller, because a node is what both paths agree on, and the
|
|
708
|
+
// wrapper is built on the first callback a node receives: the overwhelming majority of tags carry
|
|
709
|
+
// no `on*` prop, and an eager one would be a closure and a `WeakMap` per element for nothing.
|
|
710
|
+
private wrapCallback(node: IHostNode, name: string, value: unknown): unknown {
|
|
711
|
+
if (!isWrappableCallback(name, value)) return value;
|
|
712
|
+
let wrapper = this.callbackWrappers.get(node);
|
|
713
|
+
if (wrapper === undefined) {
|
|
714
|
+
wrapper = createCallbackWrapper(node);
|
|
715
|
+
this.callbackWrappers.set(node, wrapper);
|
|
716
|
+
}
|
|
717
|
+
return wrapper(name, value);
|
|
718
|
+
}
|
|
719
|
+
|
|
493
720
|
setValue(node: IHostNode, value: string): void {
|
|
494
721
|
countAngular('rendererWrites');
|
|
495
722
|
noteAngularWrite('#text');
|
|
@@ -513,11 +740,11 @@ export class SymbioteRenderer implements Renderer2 {
|
|
|
513
740
|
): () => void {
|
|
514
741
|
if (!isSymbioteNode(target)) return () => {};
|
|
515
742
|
// `[(value)]` desugars to `(valueChange)`, which is the spelling every Angular template writes
|
|
516
|
-
// for a Switch or a TextInput.
|
|
517
|
-
//
|
|
518
|
-
//
|
|
743
|
+
// for a Switch or a TextInput. It used to be an `@Output()` a wrapper derived from the raw
|
|
744
|
+
// `change` payload; a tag has no component, and registering `valueChange` as an engine event
|
|
745
|
+
// would wait forever for a Fabric event of that name.
|
|
519
746
|
//
|
|
520
|
-
// The
|
|
747
|
+
// The same fold already exists under RN's own spelling: both behaviors call
|
|
521
748
|
// `node.props.onValueChange(event)` — a plain function PROP, not an event
|
|
522
749
|
// (`behaviors/switch.ts`, `behaviors/text-input.ts`), with `text`/`value` carried as a FIELD on
|
|
523
750
|
// the event object rather than a second argument (Svelte forces every individual `on*` prop
|
|
@@ -526,15 +753,31 @@ export class SymbioteRenderer implements Renderer2 {
|
|
|
526
753
|
// unwrap that field back to a bare value before handing it to Angular's callback, or `text =
|
|
527
754
|
// $event` would assign the whole event object instead of the typed string/boolean.
|
|
528
755
|
if (eventName === VALUE_CHANGE_EVENT) {
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
756
|
+
// `ngOnChanges` may already have written an explicit `[onValueChange]` binding onto this
|
|
757
|
+
// same prop key via `routeProp` (`setProperty`'s generic reflect loop) — seed the live
|
|
758
|
+
// explicit-handler slot from it, unless what's there is a PRIOR bridge's own forward
|
|
759
|
+
// function (the Angular-vs-manual-bridge double-registration this branch already dedupes,
|
|
760
|
+
// `listen(VALUE_CHANGE_EVENT)` fires twice per element — see `bridgedValueChangeHandlers`).
|
|
761
|
+
// Composing with the explicit handler (never replacing it) is the RN-parity behavior: RN's
|
|
762
|
+
// `onChange` always fires regardless of whether `value` is controlled.
|
|
763
|
+
const currentOnValueChange = propOf(target, VALUE_CHANGE_PROP);
|
|
764
|
+
if (
|
|
765
|
+
isReadBackListener(currentOnValueChange) &&
|
|
766
|
+
!bridgedValueChangeHandlers.has(currentOnValueChange)
|
|
767
|
+
) {
|
|
768
|
+
explicitValueChangeHandlers.set(target, currentOnValueChange);
|
|
769
|
+
}
|
|
770
|
+
routeProp(
|
|
771
|
+
target,
|
|
772
|
+
VALUE_CHANGE_PROP,
|
|
773
|
+
composeValueChangeHandler(target, callback),
|
|
774
|
+
);
|
|
775
|
+
return () =>
|
|
776
|
+
routeProp(
|
|
777
|
+
target,
|
|
778
|
+
VALUE_CHANGE_PROP,
|
|
779
|
+
explicitValueChangeHandlers.get(target),
|
|
780
|
+
);
|
|
538
781
|
}
|
|
539
782
|
const listener = READ_BACK_EVENTS.has(eventName)
|
|
540
783
|
? withChangeDetection(target, callback)
|