@lynx-js/react 0.129.1 → 0.129.2

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.
Files changed (121) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/components/tsconfig.tsbuildinfo +1 -1
  3. package/package.json +1 -1
  4. package/refresh/.turbo/turbo-build.log +1 -1
  5. package/runtime/__test__/core/globalProps.test.ts +27 -6
  6. package/runtime/__test__/element-template/fixtures/gesture/direct/index.tsx +33 -0
  7. package/runtime/__test__/element-template/fixtures/spread/mts/index.tsx +197 -0
  8. package/runtime/__test__/element-template/native/callDestroyLifetimeFun.test.ts +89 -3
  9. package/runtime/__test__/element-template/native/mts-destroy.test.ts +8 -3
  10. package/runtime/__test__/element-template/native/reload.test.ts +87 -0
  11. package/runtime/__test__/element-template/runtime/background/global-props/compiled-fixtures.test.tsx +5 -5
  12. package/runtime/__test__/element-template/runtime/background/global-props.test.tsx +1 -1
  13. package/runtime/__test__/element-template/runtime/background/hydrate.test.ts +70 -0
  14. package/runtime/__test__/element-template/runtime/background/ref/compiled-fixtures.test.tsx +3 -4
  15. package/runtime/__test__/element-template/runtime/background/reload.test.ts +74 -0
  16. package/runtime/__test__/element-template/runtime/patch/element-template-patch.test.tsx +15 -0
  17. package/runtime/__test__/element-template/runtime/prop-adapters/gesture-compiled.test.ts +200 -0
  18. package/runtime/__test__/element-template/runtime/prop-adapters/gesture.test.ts +420 -0
  19. package/runtime/__test__/element-template/runtime/prop-adapters/spread-mts-compiled.test.ts +527 -0
  20. package/runtime/__test__/element-template/runtime/prop-adapters/spread.test.ts +185 -6
  21. package/runtime/__test__/element-template/runtime/render/render-direct-native.test.tsx +21 -1
  22. package/runtime/__test__/element-template/runtime/template/main-thread-dynamic-attr-state.test.ts +188 -0
  23. package/runtime/__test__/snapshot/lifecycle/updateGlobalProps.event.test.jsx +2 -2
  24. package/runtime/__test__/snapshot/lifecycle/updateGlobalProps.test.jsx +3 -3
  25. package/runtime/__test__/snapshot/ref.test.jsx +30 -0
  26. package/runtime/lazy/element-template-internal.js +1 -0
  27. package/runtime/lib/core/globalProps.js +1 -1
  28. package/runtime/lib/core/globalProps.js.map +1 -1
  29. package/runtime/lib/element-template/background/attr-slots.js +5 -2
  30. package/runtime/lib/element-template/background/attr-slots.js.map +1 -1
  31. package/runtime/lib/element-template/background/destroy.js +16 -11
  32. package/runtime/lib/element-template/background/destroy.js.map +1 -1
  33. package/runtime/lib/element-template/background/hydrate.js +23 -0
  34. package/runtime/lib/element-template/background/hydrate.js.map +1 -1
  35. package/runtime/lib/element-template/debug/alog.d.ts +1 -1
  36. package/runtime/lib/element-template/debug/alog.js +4 -1
  37. package/runtime/lib/element-template/debug/alog.js.map +1 -1
  38. package/runtime/lib/element-template/internal.d.ts +1 -1
  39. package/runtime/lib/element-template/internal.js +1 -1
  40. package/runtime/lib/element-template/internal.js.map +1 -1
  41. package/runtime/lib/element-template/native/callDestroyLifetimeFun.js +6 -1
  42. package/runtime/lib/element-template/native/callDestroyLifetimeFun.js.map +1 -1
  43. package/runtime/lib/element-template/native/patch-listener.js +1 -1
  44. package/runtime/lib/element-template/native/patch-listener.js.map +1 -1
  45. package/runtime/lib/element-template/native/reload-background.js +1 -1
  46. package/runtime/lib/element-template/native/reload-background.js.map +1 -1
  47. package/runtime/lib/element-template/native/reload-main-thread.js +33 -9
  48. package/runtime/lib/element-template/native/reload-main-thread.js.map +1 -1
  49. package/runtime/lib/element-template/prop-adapters/gesture.d.ts +23 -0
  50. package/runtime/lib/element-template/prop-adapters/gesture.js +97 -0
  51. package/runtime/lib/element-template/prop-adapters/gesture.js.map +1 -0
  52. package/runtime/lib/element-template/prop-adapters/spread.d.ts +6 -1
  53. package/runtime/lib/element-template/prop-adapters/spread.js +72 -2
  54. package/runtime/lib/element-template/prop-adapters/spread.js.map +1 -1
  55. package/runtime/lib/element-template/protocol/opcodes.d.ts +1 -0
  56. package/runtime/lib/element-template/protocol/opcodes.js +1 -0
  57. package/runtime/lib/element-template/protocol/opcodes.js.map +1 -1
  58. package/runtime/lib/element-template/protocol/types.d.ts +7 -1
  59. package/runtime/lib/element-template/protocol/types.js.map +1 -1
  60. package/runtime/lib/element-template/runtime/patch.js +27 -2
  61. package/runtime/lib/element-template/runtime/patch.js.map +1 -1
  62. package/runtime/lib/element-template/runtime/template/attr-slot-plan.d.ts +4 -2
  63. package/runtime/lib/element-template/runtime/template/attr-slot-plan.js +17 -4
  64. package/runtime/lib/element-template/runtime/template/attr-slot-plan.js.map +1 -1
  65. package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.d.ts +7 -2
  66. package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js +368 -58
  67. package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js.map +1 -1
  68. package/runtime/lib/element-template/runtime/template/main-thread-ref-ctx.d.ts +2 -1
  69. package/runtime/lib/element-template/runtime/template/main-thread-ref-ctx.js +10 -1
  70. package/runtime/lib/element-template/runtime/template/main-thread-ref-ctx.js.map +1 -1
  71. package/runtime/lib/element-template/runtime/template/typed-attributes.js +3 -3
  72. package/runtime/lib/element-template/runtime/template/typed-attributes.js.map +1 -1
  73. package/runtime/lib/snapshot/lifecycle/destroy.js +23 -17
  74. package/runtime/lib/snapshot/lifecycle/destroy.js.map +1 -1
  75. package/runtime/lib/snapshot/lifecycle/ref/delay.d.ts +5 -0
  76. package/runtime/lib/snapshot/lifecycle/ref/delay.js +1 -1
  77. package/runtime/lib/snapshot/lifecycle/ref/delay.js.map +1 -1
  78. package/runtime/lib/tsconfig.tsbuildinfo +1 -1
  79. package/runtime/src/core/globalProps.ts +1 -1
  80. package/runtime/src/element-template/background/attr-slots.ts +5 -1
  81. package/runtime/src/element-template/background/destroy.ts +16 -13
  82. package/runtime/src/element-template/background/hydrate.ts +23 -0
  83. package/runtime/src/element-template/debug/alog.ts +5 -2
  84. package/runtime/src/element-template/internal.ts +1 -0
  85. package/runtime/src/element-template/native/callDestroyLifetimeFun.ts +5 -1
  86. package/runtime/src/element-template/native/patch-listener.ts +1 -1
  87. package/runtime/src/element-template/native/reload-background.ts +1 -1
  88. package/runtime/src/element-template/native/reload-main-thread.ts +30 -10
  89. package/runtime/src/element-template/prop-adapters/gesture.ts +144 -0
  90. package/runtime/src/element-template/prop-adapters/spread.ts +110 -2
  91. package/runtime/src/element-template/protocol/opcodes.ts +1 -0
  92. package/runtime/src/element-template/protocol/types.ts +8 -0
  93. package/runtime/src/element-template/runtime/patch.ts +33 -0
  94. package/runtime/src/element-template/runtime/template/attr-slot-plan.ts +31 -4
  95. package/runtime/src/element-template/runtime/template/main-thread-dynamic-attr-state.ts +441 -65
  96. package/runtime/src/element-template/runtime/template/main-thread-ref-ctx.ts +12 -2
  97. package/runtime/src/element-template/runtime/template/typed-attributes.ts +3 -3
  98. package/runtime/src/snapshot/lifecycle/destroy.ts +23 -18
  99. package/runtime/src/snapshot/lifecycle/ref/delay.ts +1 -1
  100. package/runtime/types/types.d.ts +2 -1
  101. package/testing-library/.turbo/turbo-build.log +7 -7
  102. package/transform/.turbo/turbo-build$colon$wasm.log +205 -91
  103. package/transform/__test__/fixture.spec.js +11 -11
  104. package/transform/__test__/main-thread-object-compat.spec.js +111 -0
  105. package/transform/crates/swc_plugin_element_template/lib.rs +11 -0
  106. package/transform/crates/swc_plugin_element_template/tests/element_template_contract.rs +113 -0
  107. package/transform/crates/swc_plugin_worklet/gen_stmt.rs +7 -9
  108. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_capture_env_js.js +3 -3
  109. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_capture_env_lepus.js +3 -3
  110. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_js.js +7 -7
  111. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_lepus.js +7 -7
  112. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_js.js +8 -8
  113. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_lepus.js +8 -8
  114. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_js.js +5 -5
  115. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_lepus.js +5 -5
  116. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_js.js +1 -1
  117. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_lepus.js +1 -1
  118. package/transform/dist/wasm.cjs +1 -1
  119. package/transform/swc-plugin-reactlynx/.turbo/turbo-build.log +160 -133
  120. package/transform/swc-plugin-reactlynx/swc_plugin_reactlynx.wasm +0 -0
  121. package/transform/swc-plugin-reactlynx-compat/.turbo/turbo-build.log +180 -293
@@ -1 +1 @@
1
- {"version":3,"file":"reload-main-thread.js","sourceRoot":"","sources":["../../../src/element-template/native/reload-main-thread.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EACL,wBAAwB,EACxB,gCAAgC,EAChC,qBAAqB,GACtB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,qCAAqC,EAAE,MAAM,qBAAqB,CAAC;AAE5E,OAAO,EAAE,mCAAmC,EAAE,MAAM,yBAAyB,CAAC;AAC9E,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,yBAA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AAC,OAAO,EAAE,YAAY,CAAC;IACzG,KAAK,MAAM,KAAK,IAAI,YAAY,IAAI,EAAE,EAAE,CAAC;QACvC,iCAAiC,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;IACtD,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { flushElementTemplate } from './flush.js';\nimport { onMtsDestruction } from './mts-destroy.js';\nimport {\n canReEvalMainThreadEntry,\n installMainThreadReloadCompleter,\n reEvalMainThreadEntry,\n} from '../../core/entry-reload.js';\nimport { applyUpdatePageData } from '../../core/lynx-page-data.js';\nimport { increaseReloadVersion } from '../../core/reload-version.js';\nimport { profileEnd, profileStart } from '../debug/profile.js';\nimport { ELEMENT_TEMPLATE_PAGE_ROOT_SLOT_INDEX } from '../protocol/page.js';\nimport type { SerializedEtNode, SerializedPageRoot } from '../protocol/types.js';\nimport { destroyAllElementTemplateListStates } from '../runtime/list/list.js';\nimport { __page, setupPage } from '../runtime/page/page.js';\nimport { __root, setRoot } from '../runtime/page/root-instance.js';\nimport { renderMainThread } from '../runtime/render/render-main-thread.js';\nimport { resetTemplateId } from '../runtime/template/handle.js';\nimport { resetElementTemplateMainThreadBackgroundFunctionRuntime } from '../runtime/template/main-thread-background-function.js';\nimport {\n clearMainThreadDynamicAttrState,\n deleteMainThreadDynamicAttrStateForSubtree,\n} from '../runtime/template/main-thread-dynamic-attr-state.js';\nimport { elementTemplateRegistry } from '../runtime/template/registry.js';\n\nexport function reloadMainThread(data: unknown, options: UpdatePageOption): void {\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileStart('ReactLynx::reloadMainThread');\n }\n\n try {\n applyUpdatePageData(data, options);\n\n destroyAllElementTemplateListStates();\n // TODO: Replace this cleanup-only serialization with a direct page-children\n // or clear-slot PAPI once native exposes one.\n const page = __SerializeElementTemplate(__page) as SerializedPageRoot;\n for (const root of page.childSlots?.[ELEMENT_TEMPLATE_PAGE_ROOT_SLOT_INDEX] ?? []) {\n const rootRef = elementTemplateRegistry.get(root.uid)!;\n __RemoveNodeFromElementTemplate(__page, ELEMENT_TEMPLATE_PAGE_ROOT_SLOT_INDEX, rootRef);\n const removedHandleIds: number[] = [];\n collectSerializedSubtreeHandleIds(root, removedHandleIds);\n for (const handleId of removedHandleIds) {\n elementTemplateRegistry.delete(handleId);\n }\n deleteMainThreadDynamicAttrStateForSubtree(removedHandleIds);\n }\n if (canReEvalMainThreadEntry()) {\n onMtsDestruction();\n increaseReloadVersion();\n reEvalMainThreadEntry<MainThreadReloadHandoff>({ page: __page, options });\n return;\n }\n elementTemplateRegistry.clear();\n clearMainThreadDynamicAttrState();\n resetElementTemplateMainThreadBackgroundFunctionRuntime();\n resetTemplateId();\n\n // Ref cleanup still belongs to the old page. Advance only before rendering\n // the new tree so calls queued by old ref/unmount callbacks remain stale.\n increaseReloadVersion();\n\n const oldRoot = __root;\n setRoot({ __jsx: oldRoot.__jsx });\n renderMainThread();\n\n flushElementTemplate(options);\n } finally {\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileEnd();\n }\n }\n}\n\ninterface MainThreadReloadHandoff {\n page: ElementTemplateHandle;\n options: UpdatePageOption;\n}\n\nexport function completeMainThreadReload({ page, options }: MainThreadReloadHandoff): void {\n setupPage(page);\n renderMainThread();\n __FlushElementTree(undefined, options);\n}\n\ninstallMainThreadReloadCompleter(completeMainThreadReload);\n\nfunction collectSerializedSubtreeHandleIds(\n node: SerializedEtNode,\n handleIds: number[],\n): void {\n handleIds.push(node.uid as number);\n for (const slot of node.childSlots ?? []) {\n for (const child of slot ?? []) {\n collectSerializedSubtreeHandleIds(child, handleIds);\n }\n }\n const listChildren = (node as { options?: { listChildren?: SerializedEtNode[] } }).options?.listChildren;\n for (const child of listChildren ?? []) {\n collectSerializedSubtreeHandleIds(child, handleIds);\n }\n}\n"]}
1
+ {"version":3,"file":"reload-main-thread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CAAC,CAAC;IACtD,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { flushElementTemplate } from './flush.js';\nimport { onMtsDestruction } from './mts-destroy.js';\nimport {\n canReEvalMainThreadEntry,\n installMainThreadReloadCompleter,\n reEvalMainThreadEntry,\n} from '../../core/entry-reload.js';\nimport { applyUpdatePageData } from '../../core/lynx-page-data.js';\nimport { increaseReloadVersion } from '../../core/reload-version.js';\nimport { profileEnd, profileStart } from '../debug/profile.js';\nimport { ELEMENT_TEMPLATE_PAGE_ROOT_SLOT_INDEX } from '../protocol/page.js';\nimport type { SerializedEtNode, SerializedPageRoot } from '../protocol/types.js';\nimport { destroyAllElementTemplateListStates } from '../runtime/list/list.js';\nimport { __page, setupPage } from '../runtime/page/page.js';\nimport { __root, setRoot } from '../runtime/page/root-instance.js';\nimport { renderMainThread } from '../runtime/render/render-main-thread.js';\nimport { resetTemplateId } from '../runtime/template/handle.js';\nimport { resetElementTemplateMainThreadBackgroundFunctionRuntime } from '../runtime/template/main-thread-background-function.js';\nimport {\n clearMainThreadDynamicAttrState,\n deleteMainThreadDynamicAttrStateForSubtree,\n} from '../runtime/template/main-thread-dynamic-attr-state.js';\nimport { elementTemplateRegistry } from '../runtime/template/registry.js';\n\nexport function reloadMainThread(data: unknown, options: UpdatePageOption): void {\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileStart('ReactLynx::reloadMainThread');\n }\n\n try {\n applyUpdatePageData(data, options);\n\n destroyAllElementTemplateListStates();\n // TODO: Replace this cleanup-only serialization with a direct page-children\n // or clear-slot PAPI once native exposes one.\n const page = __SerializeElementTemplate(__page) as SerializedPageRoot;\n let cleanupError: unknown;\n let didCleanupThrow = false;\n for (const root of page.childSlots?.[ELEMENT_TEMPLATE_PAGE_ROOT_SLOT_INDEX] ?? []) {\n const rootRef = elementTemplateRegistry.get(root.uid)!;\n __RemoveNodeFromElementTemplate(__page, ELEMENT_TEMPLATE_PAGE_ROOT_SLOT_INDEX, rootRef);\n const removedHandleIds: number[] = [];\n collectSerializedSubtreeHandleIds(root, removedHandleIds);\n for (const handleId of removedHandleIds) {\n elementTemplateRegistry.delete(handleId);\n }\n try {\n deleteMainThreadDynamicAttrStateForSubtree(removedHandleIds);\n } catch (error) {\n if (!didCleanupThrow) {\n cleanupError = error;\n didCleanupThrow = true;\n }\n }\n }\n if (canReEvalMainThreadEntry()) {\n try {\n onMtsDestruction();\n } finally {\n increaseReloadVersion();\n }\n if (didCleanupThrow) {\n throw cleanupError;\n }\n reEvalMainThreadEntry<MainThreadReloadHandoff>({ page: __page, options });\n return;\n }\n elementTemplateRegistry.clear();\n try {\n clearMainThreadDynamicAttrState();\n } finally {\n resetElementTemplateMainThreadBackgroundFunctionRuntime();\n resetTemplateId();\n // Ref cleanup still belongs to the old page. Advance only before rendering\n // the new tree so calls queued by old ref/unmount callbacks remain stale.\n increaseReloadVersion();\n }\n if (didCleanupThrow) {\n throw cleanupError;\n }\n\n const oldRoot = __root;\n setRoot({ __jsx: oldRoot.__jsx });\n renderMainThread();\n\n flushElementTemplate(options);\n } finally {\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileEnd();\n }\n }\n}\n\ninterface MainThreadReloadHandoff {\n page: ElementTemplateHandle;\n options: UpdatePageOption;\n}\n\nexport function completeMainThreadReload({ page, options }: MainThreadReloadHandoff): void {\n setupPage(page);\n renderMainThread();\n __FlushElementTree(undefined, options);\n}\n\ninstallMainThreadReloadCompleter(completeMainThreadReload);\n\nfunction collectSerializedSubtreeHandleIds(\n node: SerializedEtNode,\n handleIds: number[],\n): void {\n handleIds.push(node.uid as number);\n for (const slot of node.childSlots ?? []) {\n for (const child of slot ?? []) {\n collectSerializedSubtreeHandleIds(child, handleIds);\n }\n }\n const listChildren = (node as { options?: { listChildren?: SerializedEtNode[] } }).options?.listChildren;\n for (const child of listChildren ?? []) {\n collectSerializedSubtreeHandleIds(child, handleIds);\n }\n}\n"]}
@@ -0,0 +1,23 @@
1
+ import type { MTEventCtx } from '../runtime/template/main-thread-event-ctx.js';
2
+ export interface GestureDescriptor {
3
+ id: number;
4
+ type: number;
5
+ config: Record<string, unknown>;
6
+ callbacks: {
7
+ name: string;
8
+ callback: MTEventCtx;
9
+ }[];
10
+ relationMap: {
11
+ waitFor: number[];
12
+ simultaneous: number[];
13
+ continueWith: number[];
14
+ };
15
+ }
16
+ export interface GestureSlotValue {
17
+ type: 'gesture';
18
+ value: GestureDescriptor[];
19
+ }
20
+ export declare function isGestureSlotValue(value: unknown): value is GestureSlotValue;
21
+ export declare function prepareGestureForNative(value: unknown, previous?: GestureSlotValue | null): GestureSlotValue | null;
22
+ export declare function retainGestureCallbacks(value: GestureSlotValue): void;
23
+ export declare function hydrateGestureCallbacks(value: GestureSlotValue, previous: GestureSlotValue): void;
@@ -0,0 +1,97 @@
1
+ // Copyright 2026 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+ import { hydrateWorkletCtx } from '@lynx-js/react/worklet-runtime/bindings';
5
+ import { isMainThreadFunction } from '../../core/main-thread-function.js';
6
+ import { registerMainThreadBackgroundFunctionCtx, retainMainThreadBackgroundFunctionCtx, } from '../runtime/template/main-thread-background-function.js';
7
+ export function isGestureSlotValue(value) {
8
+ return value !== null
9
+ && typeof value === 'object'
10
+ && !Array.isArray(value)
11
+ && value.type === 'gesture'
12
+ && Array.isArray(value.value);
13
+ }
14
+ // Provenance stays outside the wire value. A repeated prepare before native
15
+ // delivery must reuse its registered ctx, while mutable Gesture config is copied.
16
+ const callbackSources = new WeakMap();
17
+ export function prepareGestureForNative(value, previous) {
18
+ if (value == null || value === false) {
19
+ return null;
20
+ }
21
+ if (typeof value !== 'object'
22
+ || !(value.__isGesture === true || value.__isSerialized === true)) {
23
+ throw new Error('ElementTemplate main-thread:gesture expects a Gesture object.');
24
+ }
25
+ const descriptors = [];
26
+ const seen = new Set();
27
+ function append(gesture) {
28
+ if (gesture.type === -1) {
29
+ for (const child of gesture.gestures) {
30
+ append(child);
31
+ }
32
+ return;
33
+ }
34
+ if (seen.has(gesture.id)) {
35
+ return;
36
+ }
37
+ seen.add(gesture.id);
38
+ const callbacks = [];
39
+ const previousGesture = previous?.value.find(item => item.id === gesture.id);
40
+ for (const name of Object.keys(gesture.callbacks)) {
41
+ const rawCallback = gesture.callbacks[name];
42
+ if (rawCallback == null) {
43
+ continue;
44
+ }
45
+ if (!isMainThreadFunction(rawCallback)) {
46
+ throw new Error(`Gesture callback '${name}' must be a main-thread function.`);
47
+ }
48
+ const previousCallback = previousGesture?.callbacks.find(item => item.name === name)?.callback;
49
+ let callback = previousCallback;
50
+ if (!callback || callbackSources.get(callback) !== rawCallback) {
51
+ callback = { ...rawCallback };
52
+ callbackSources.set(callback, rawCallback);
53
+ registerMainThreadBackgroundFunctionCtx(callback);
54
+ }
55
+ callbacks.push({ name, callback });
56
+ }
57
+ descriptors.push({
58
+ id: gesture.id,
59
+ type: gesture.type,
60
+ config: { ...gesture.config },
61
+ callbacks,
62
+ relationMap: {
63
+ waitFor: gesture.waitFor?.map(item => item.id) ?? [],
64
+ simultaneous: gesture.simultaneousWith?.map(item => item.id) ?? [],
65
+ continueWith: gesture.continueWith?.map(item => item.id) ?? [],
66
+ },
67
+ });
68
+ }
69
+ append(value);
70
+ return { type: 'gesture', value: descriptors };
71
+ }
72
+ export function retainGestureCallbacks(value) {
73
+ for (const gesture of value.value) {
74
+ for (const { callback } of gesture.callbacks) {
75
+ retainMainThreadBackgroundFunctionCtx(callback);
76
+ }
77
+ }
78
+ }
79
+ export function hydrateGestureCallbacks(value, previous) {
80
+ // IDs belong to independent thread-local allocators. Pair each type in
81
+ // declaration order; the worklet hydrator also checks callback source identity.
82
+ const remaining = previous.value.slice();
83
+ for (const gesture of value.value) {
84
+ const index = remaining.findIndex(old => old.type === gesture.type);
85
+ if (index === -1) {
86
+ continue;
87
+ }
88
+ const oldGesture = remaining.splice(index, 1)[0];
89
+ for (const { name, callback } of gesture.callbacks) {
90
+ const oldCallback = oldGesture.callbacks.find(item => item.name === name)?.callback;
91
+ if (oldCallback) {
92
+ hydrateWorkletCtx(callback, oldCallback);
93
+ }
94
+ }
95
+ }
96
+ }
97
+ //# sourceMappingURL=gesture.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gesture.js","sourceRoot":"","sources":["../../../src/element-template/prop-adapters/gesture.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,yCAAyC,CAAC;AAG5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EACL,uCAAuC,EACvC,qCAAqC,GACtC,MAAM,wDAAwD,CAAC;AAiChE,MAAM,UAAU,kBAAkB,CAAC,KAAc;IAC/C,OAAO,KAAK,KAAK,IAAI;WAChB,OAAO,KAAK,KAAK,QAAQ;WACzB,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;WACpB,KAA4B,CAAC,IAAI,KAAK,SAAS;WAChD,KAAK,CAAC,OAAO,CAAE,KAA6B,CAAC,KAAK,CAAC,CAAC;AAC3D,CAAC;AAED,4EAA4E;AAC5E,kFAAkF;AAClF,MAAM,eAAe,GAAG,IAAI,OAAO,EAA0B,CAAC;AAE9D,MAAM,UAAU,uBAAuB,CACrC,KAAc,EACd,QAAkC;IAElC,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,KAAK,KAAK,EAAE,CAAC;QACrC,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IACE,OAAO,KAAK,KAAK,QAAQ;WACtB,CAAC,CAAE,KAAsB,CAAC,WAAW,KAAK,IAAI,IAAK,KAAsB,CAAC,cAAc,KAAK,IAAI,CAAC,EACrG,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,+DAA+D,CAAC,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AC;AACH,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,KAAuB,EAAE,QAA0B;IACzF,uEAAuE;IACvE,gFAAgF;IAChF,MAAM,SAAS,GAAG,QAAQ,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IACzC,KAAK,MAAM,OAAO,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;QAClC,MAAM,KAAK,GAAG,SAAS,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;QACpE,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE,CAAC;YACjB,SAAS;QACX,CAAC;QACD,MAAM,UAAU,GAAG,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAE,CAAC;QAClD,KAAK,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;YACnD,MAAM,WAAW,GAAG,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,EAAE,QAAQ,CAAC;YACpF,IAAI,WAAW,EAAE,CAAC;gBAChB,iBAAiB,CAAC,QAAmB,EAAE,WAAsB,CAAC,CAAC;YACjE,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { hydrateWorkletCtx } from '@lynx-js/react/worklet-runtime/bindings';\nimport type { Worklet } from '@lynx-js/react/worklet-runtime/bindings';\n\nimport { isMainThreadFunction } from '../../core/main-thread-function.js';\nimport {\n registerMainThreadBackgroundFunctionCtx,\n retainMainThreadBackgroundFunctionCtx,\n} from '../runtime/template/main-thread-background-function.js';\nimport type { MTEventCtx } from '../runtime/template/main-thread-event-ctx.js';\n\ninterface GestureInput {\n type: number;\n id: number;\n __isGesture?: boolean;\n __isSerialized?: boolean;\n gestures?: GestureInput[];\n config?: Record<string, unknown>;\n callbacks: Record<string, MTEventCtx | null | undefined>;\n waitFor?: { id: number }[];\n simultaneousWith?: { id: number }[];\n continueWith?: { id: number }[];\n}\n\nexport interface GestureDescriptor {\n id: number;\n type: number;\n config: Record<string, unknown>;\n callbacks: { name: string; callback: MTEventCtx }[];\n relationMap: {\n waitFor: number[];\n simultaneous: number[];\n continueWith: number[];\n };\n}\n\nexport interface GestureSlotValue {\n type: 'gesture';\n value: GestureDescriptor[];\n}\n\nexport function isGestureSlotValue(value: unknown): value is GestureSlotValue {\n return value !== null\n && typeof value === 'object'\n && !Array.isArray(value)\n && (value as { type?: unknown }).type === 'gesture'\n && Array.isArray((value as { value?: unknown }).value);\n}\n\n// Provenance stays outside the wire value. A repeated prepare before native\n// delivery must reuse its registered ctx, while mutable Gesture config is copied.\nconst callbackSources = new WeakMap<MTEventCtx, MTEventCtx>();\n\nexport function prepareGestureForNative(\n value: unknown,\n previous?: GestureSlotValue | null,\n): GestureSlotValue | null {\n if (value == null || value === false) {\n return null;\n }\n if (\n typeof value !== 'object'\n || !((value as GestureInput).__isGesture === true || (value as GestureInput).__isSerialized === true)\n ) {\n throw new Error('ElementTemplate main-thread:gesture expects a Gesture object.');\n }\n\n const descriptors: GestureDescriptor[] = [];\n const seen = new Set<number>();\n function append(gesture: GestureInput): void {\n if (gesture.type === -1) {\n for (const child of gesture.gestures!) {\n append(child);\n }\n return;\n }\n if (seen.has(gesture.id)) {\n return;\n }\n seen.add(gesture.id);\n const callbacks: GestureDescriptor['callbacks'] = [];\n const previousGesture = previous?.value.find(item => item.id === gesture.id);\n for (const name of Object.keys(gesture.callbacks)) {\n const rawCallback = gesture.callbacks[name];\n if (rawCallback == null) {\n continue;\n }\n if (!isMainThreadFunction(rawCallback)) {\n throw new Error(`Gesture callback '${name}' must be a main-thread function.`);\n }\n const previousCallback = previousGesture?.callbacks.find(item => item.name === name)?.callback;\n let callback = previousCallback;\n if (!callback || callbackSources.get(callback) !== rawCallback) {\n callback = { ...rawCallback };\n callbackSources.set(callback, rawCallback);\n registerMainThreadBackgroundFunctionCtx(callback);\n }\n callbacks.push({ name, callback });\n }\n descriptors.push({\n id: gesture.id,\n type: gesture.type,\n config: { ...gesture.config },\n callbacks,\n relationMap: {\n waitFor: gesture.waitFor?.map(item => item.id) ?? [],\n simultaneous: gesture.simultaneousWith?.map(item => item.id) ?? [],\n continueWith: gesture.continueWith?.map(item => item.id) ?? [],\n },\n });\n }\n append(value as GestureInput);\n return { type: 'gesture', value: descriptors };\n}\n\nexport function retainGestureCallbacks(value: GestureSlotValue): void {\n for (const gesture of value.value) {\n for (const { callback } of gesture.callbacks) {\n retainMainThreadBackgroundFunctionCtx(callback);\n }\n }\n}\n\nexport function hydrateGestureCallbacks(value: GestureSlotValue, previous: GestureSlotValue): void {\n // IDs belong to independent thread-local allocators. Pair each type in\n // declaration order; the worklet hydrator also checks callback source identity.\n const remaining = previous.value.slice();\n for (const gesture of value.value) {\n const index = remaining.findIndex(old => old.type === gesture.type);\n if (index === -1) {\n continue;\n }\n const oldGesture = remaining.splice(index, 1)[0]!;\n for (const { name, callback } of gesture.callbacks) {\n const oldCallback = oldGesture.callbacks.find(item => item.name === name)?.callback;\n if (oldCallback) {\n hydrateWorkletCtx(callback as Worklet, oldCallback as Worklet);\n }\n }\n }\n}\n"]}
@@ -1,2 +1,7 @@
1
1
  import type { SerializableValue } from '../protocol/types.js';
2
- export declare function prepareSpreadAttrSlot(handleId: number, attrSlotIndex: number, value: unknown): SerializableValue | null;
2
+ import type { EtAttrAdapterContext } from '../runtime/template/attr-slot-plan.js';
3
+ export declare function isSpreadRecord(value: unknown): value is Record<string, unknown>;
4
+ export declare function hasOwnSpreadKey(record: Record<string, unknown>, key: string): boolean;
5
+ export declare function isMainThreadEventPropKey(key: string): boolean;
6
+ export declare function prepareSpreadAttrSlot(handleId: number, attrSlotIndex: number, value: unknown, context?: EtAttrAdapterContext): SerializableValue | null;
7
+ export declare function prepareTypedSpreadAttrSlot(handleId: number, attrSlotIndex: number, value: unknown): SerializableValue | null;
@@ -2,16 +2,35 @@
2
2
  // Licensed under the Apache License Version 2.0 that can be found in the
3
3
  // LICENSE file in the root directory of this source tree.
4
4
  import { getEventValue } from './event-value.js';
5
+ import { isGestureSlotValue, prepareGestureForNative } from './gesture.js';
5
6
  import { prepareSpreadRefAttrValue } from './ref.js';
7
+ import { isMainThreadFunction } from '../../core/main-thread-function.js';
6
8
  import { isEventPropKey, isNamespacedEventPropKey, transformAttrName } from '../../shared/attribute-name.js';
7
- function isSpreadRecord(value) {
9
+ import { prepareMTEventCtxForNative } from '../runtime/template/main-thread-event-ctx.js';
10
+ import { prepareMTRefForNative } from '../runtime/template/main-thread-ref-ctx.js';
11
+ const MAIN_THREAD_NAMESPACE_PREFIX = 'main-thread:';
12
+ // Keep per-key raw callback/ref provenance outside the wire value so in-place
13
+ // mutation of a caller-reused spread object cannot alias historical raw values.
14
+ const spreadRawSources = new WeakMap();
15
+ export function isSpreadRecord(value) {
8
16
  return value !== null && typeof value === 'object' && !Array.isArray(value);
9
17
  }
10
- export function prepareSpreadAttrSlot(handleId, attrSlotIndex, value) {
18
+ export function hasOwnSpreadKey(record, key) {
19
+ return Object.prototype.hasOwnProperty.call(record, key);
20
+ }
21
+ export function isMainThreadEventPropKey(key) {
22
+ return key.startsWith(MAIN_THREAD_NAMESPACE_PREFIX)
23
+ && isEventPropKey(key.slice(MAIN_THREAD_NAMESPACE_PREFIX.length));
24
+ }
25
+ function prepareSpreadAttrSlotImpl(handleId, attrSlotIndex, value, allowMainThreadCapabilities, context) {
11
26
  if (value === false || !isSpreadRecord(value)) {
12
27
  return null;
13
28
  }
29
+ const prevPreparedSlot = context?.previousPreparedSlots?.[attrSlotIndex];
30
+ const prevPreparedRecord = isSpreadRecord(prevPreparedSlot) ? prevPreparedSlot : undefined;
31
+ const prevRawSources = prevPreparedRecord ? spreadRawSources.get(prevPreparedRecord) : undefined;
14
32
  const prepared = {};
33
+ let rawSources;
15
34
  for (const key in value) {
16
35
  const spreadValue = value[key];
17
36
  if (key === '__spread' || key === '__self' || key === '__source') {
@@ -28,6 +47,48 @@ export function prepareSpreadAttrSlot(handleId, attrSlotIndex, value) {
28
47
  }
29
48
  continue;
30
49
  }
50
+ if (allowMainThreadCapabilities) {
51
+ if (key === 'main-thread:ref') {
52
+ if (!hasOwnSpreadKey(value, key)) {
53
+ continue;
54
+ }
55
+ const preparedRef = prepareMTRefForNative(spreadValue, prevPreparedRecord?.[key], prevRawSources?.[key]);
56
+ prepared[key] = preparedRef;
57
+ if (preparedRef !== null) {
58
+ (rawSources ??= Object.create(null))[key] = spreadValue;
59
+ }
60
+ continue;
61
+ }
62
+ if (key === 'main-thread:gesture') {
63
+ if (!hasOwnSpreadKey(value, key)) {
64
+ continue;
65
+ }
66
+ const prevGesture = prevPreparedRecord && hasOwnSpreadKey(prevPreparedRecord, key)
67
+ ? prevPreparedRecord[key]
68
+ : undefined;
69
+ prepared[key] = prepareGestureForNative(spreadValue, isGestureSlotValue(prevGesture) ? prevGesture : undefined);
70
+ continue;
71
+ }
72
+ if (isMainThreadEventPropKey(key)) {
73
+ if (!hasOwnSpreadKey(value, key)) {
74
+ continue;
75
+ }
76
+ if (spreadValue === null || spreadValue === undefined || spreadValue === false) {
77
+ prepared[key] = null;
78
+ continue;
79
+ }
80
+ if (!isMainThreadFunction(spreadValue)) {
81
+ if (__DEV__) {
82
+ lynx.reportError(new Error(`ElementTemplate main-thread event slot ${handleId}:${attrSlotIndex} (${key}) expects a worklet ctx object.`));
83
+ }
84
+ prepared[key] = null;
85
+ continue;
86
+ }
87
+ prepared[key] = prepareMTEventCtxForNative(spreadValue, prevPreparedRecord?.[key], prevRawSources?.[key]);
88
+ (rawSources ??= Object.create(null))[key] = spreadValue;
89
+ continue;
90
+ }
91
+ }
31
92
  const transformedKey = transformAttrName(key);
32
93
  if (isEventPropKey(transformedKey)) {
33
94
  prepared[transformedKey] = spreadValue === null || spreadValue === undefined || spreadValue === false
@@ -44,6 +105,15 @@ export function prepareSpreadAttrSlot(handleId, attrSlotIndex, value) {
44
105
  }
45
106
  prepared[transformedKey] = spreadValue;
46
107
  }
108
+ if (rawSources) {
109
+ spreadRawSources.set(prepared, rawSources);
110
+ }
47
111
  return prepared;
48
112
  }
113
+ export function prepareSpreadAttrSlot(handleId, attrSlotIndex, value, context) {
114
+ return prepareSpreadAttrSlotImpl(handleId, attrSlotIndex, value, true, context);
115
+ }
116
+ export function prepareTypedSpreadAttrSlot(handleId, attrSlotIndex, value) {
117
+ return prepareSpreadAttrSlotImpl(handleId, attrSlotIndex, value, false);
118
+ }
49
119
  //# sourceMappingURL=spread.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"spread.js","sourceRoot":"","sources":["../../../src/element-template/prop-adapters/spread.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,wBAAwB,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAG7G,SAAS,cAAc,CAAC,KAAc;IACpC,OAAO,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC;AAED,MAAM,UAAU,qBAAqB,CACnC,QAAgB,EAChB,aAAqB,EACrB,KAAc;IAEd,IAAI,KAAK,KAAK,KAAK,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE,CAAC;QAC9C,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,QAAQ,GAAsC,EAAE,CAAC;IAEvD,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE,CAAC;QACxB,MAAM,WAAW,GA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The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { getEventValue } from './event-value.js';\nimport { prepareSpreadRefAttrValue } from './ref.js';\nimport { isEventPropKey, isNamespacedEventPropKey, transformAttrName } from '../../shared/attribute-name.js';\nimport type { SerializableValue } from '../protocol/types.js';\n\nfunction isSpreadRecord(value: unknown): value is Record<string, unknown> {\n return value !== null && typeof value === 'object' && !Array.isArray(value);\n}\n\nexport function prepareSpreadAttrSlot(\n handleId: number,\n attrSlotIndex: number,\n value: unknown,\n): SerializableValue | null {\n if (value === false || !isSpreadRecord(value)) {\n return null;\n }\n\n const prepared: Record<string, SerializableValue> = {};\n\n for (const key in value) {\n const spreadValue = value[key];\n if (key === '__spread' || key === '__self' || key === '__source') {\n continue;\n }\n\n if (key === 'class' || key === 'className') {\n prepared['class'] = (spreadValue ?? '') as SerializableValue;\n continue;\n }\n\n if (key === 'ref') {\n const refValue = prepareSpreadRefAttrValue(handleId, attrSlotIndex, value);\n if (refValue !== undefined) {\n prepared['ref'] = refValue;\n }\n continue;\n }\n\n const transformedKey = transformAttrName(key);\n if (isEventPropKey(transformedKey)) {\n prepared[transformedKey] = spreadValue === null || spreadValue === undefined || spreadValue === false\n ? null\n : getEventValue(handleId, attrSlotIndex, key);\n continue;\n }\n\n if (\n spreadValue === undefined\n || transformedKey.endsWith(':ref')\n || transformedKey.endsWith(':gesture')\n || isNamespacedEventPropKey(key)\n || typeof spreadValue === 'function'\n ) {\n continue;\n }\n\n prepared[transformedKey] = spreadValue as SerializableValue;\n }\n\n return prepared;\n}\n"]}
1
+ {"version":3,"file":"spread.js","sourceRoot":"","sources":["../../../src/element-template/prop-adapters/spread.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,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AC,CAAC;AAClF,CAAC;AAED,MAAM,UAAU,0BAA0B,CACxC,QAAgB,EAChB,aAAqB,EACrB,KAAc;IAEd,OAAO,yBAAyB,CAAC,QAAQ,EAAE,aAAa,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;AAC1E,CAAC","sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { getEventValue } from './event-value.js';\nimport { isGestureSlotValue, prepareGestureForNative } from './gesture.js';\nimport { prepareSpreadRefAttrValue } from './ref.js';\nimport { isMainThreadFunction } from '../../core/main-thread-function.js';\nimport { isEventPropKey, isNamespacedEventPropKey, transformAttrName } from '../../shared/attribute-name.js';\nimport type { SerializableValue } from '../protocol/types.js';\nimport type { EtAttrAdapterContext } from '../runtime/template/attr-slot-plan.js';\nimport { prepareMTEventCtxForNative } from '../runtime/template/main-thread-event-ctx.js';\nimport { prepareMTRefForNative } from '../runtime/template/main-thread-ref-ctx.js';\n\nconst MAIN_THREAD_NAMESPACE_PREFIX = 'main-thread:';\n\n// Keep per-key raw callback/ref provenance outside the wire value so in-place\n// mutation of a caller-reused spread object cannot alias historical raw values.\nconst spreadRawSources = new WeakMap<Record<string, unknown>, Record<string, unknown>>();\n\nexport function isSpreadRecord(value: unknown): value is Record<string, unknown> {\n return value !== null && typeof value === 'object' && !Array.isArray(value);\n}\n\nexport function hasOwnSpreadKey(record: Record<string, unknown>, key: string): boolean {\n return Object.prototype.hasOwnProperty.call(record, key);\n}\n\nexport function isMainThreadEventPropKey(key: string): boolean {\n return key.startsWith(MAIN_THREAD_NAMESPACE_PREFIX)\n && isEventPropKey(key.slice(MAIN_THREAD_NAMESPACE_PREFIX.length));\n}\n\nfunction prepareSpreadAttrSlotImpl(\n handleId: number,\n attrSlotIndex: number,\n value: unknown,\n allowMainThreadCapabilities: boolean,\n context?: EtAttrAdapterContext,\n): SerializableValue | null {\n if (value === false || !isSpreadRecord(value)) {\n return null;\n }\n\n const prevPreparedSlot = context?.previousPreparedSlots?.[attrSlotIndex];\n const prevPreparedRecord = isSpreadRecord(prevPreparedSlot) ? prevPreparedSlot : undefined;\n const prevRawSources = prevPreparedRecord ? spreadRawSources.get(prevPreparedRecord) : undefined;\n\n const prepared: Record<string, SerializableValue> = {};\n let rawSources: Record<string, unknown> | undefined;\n\n for (const key in value) {\n const spreadValue = value[key];\n if (key === '__spread' || key === '__self' || key === '__source') {\n continue;\n }\n\n if (key === 'class' || key === 'className') {\n prepared['class'] = (spreadValue ?? '') as SerializableValue;\n continue;\n }\n\n if (key === 'ref') {\n const refValue = prepareSpreadRefAttrValue(handleId, attrSlotIndex, value);\n if (refValue !== undefined) {\n prepared['ref'] = refValue;\n }\n continue;\n }\n\n if (allowMainThreadCapabilities) {\n if (key === 'main-thread:ref') {\n if (!hasOwnSpreadKey(value, key)) {\n continue;\n }\n const preparedRef = prepareMTRefForNative(\n spreadValue,\n prevPreparedRecord?.[key],\n prevRawSources?.[key],\n );\n prepared[key] = preparedRef;\n if (preparedRef !== null) {\n (rawSources ??= Object.create(null) as Record<string, unknown>)[key] = spreadValue;\n }\n continue;\n }\n\n if (key === 'main-thread:gesture') {\n if (!hasOwnSpreadKey(value, key)) {\n continue;\n }\n const prevGesture = prevPreparedRecord && hasOwnSpreadKey(prevPreparedRecord, key)\n ? prevPreparedRecord[key]\n : undefined;\n prepared[key] = prepareGestureForNative(\n spreadValue,\n isGestureSlotValue(prevGesture) ? prevGesture : undefined,\n ) as unknown as SerializableValue;\n continue;\n }\n\n if (isMainThreadEventPropKey(key)) {\n if (!hasOwnSpreadKey(value, key)) {\n continue;\n }\n if (spreadValue === null || spreadValue === undefined || spreadValue === false) {\n prepared[key] = null;\n continue;\n }\n if (!isMainThreadFunction(spreadValue)) {\n if (__DEV__) {\n lynx.reportError(\n new Error(\n `ElementTemplate main-thread event slot ${handleId}:${attrSlotIndex} (${key}) expects a worklet ctx object.`,\n ),\n );\n }\n prepared[key] = null;\n continue;\n }\n prepared[key] = prepareMTEventCtxForNative(\n spreadValue,\n prevPreparedRecord?.[key],\n prevRawSources?.[key],\n );\n (rawSources ??= Object.create(null) as Record<string, unknown>)[key] = spreadValue;\n continue;\n }\n }\n\n const transformedKey = transformAttrName(key);\n if (isEventPropKey(transformedKey)) {\n prepared[transformedKey] = spreadValue === null || spreadValue === undefined || spreadValue === false\n ? null\n : getEventValue(handleId, attrSlotIndex, key);\n continue;\n }\n\n if (\n spreadValue === undefined\n || transformedKey.endsWith(':ref')\n || transformedKey.endsWith(':gesture')\n || isNamespacedEventPropKey(key)\n || typeof spreadValue === 'function'\n ) {\n continue;\n }\n\n prepared[transformedKey] = spreadValue as SerializableValue;\n }\n\n if (rawSources) {\n spreadRawSources.set(prepared, rawSources);\n }\n\n return prepared;\n}\n\nexport function prepareSpreadAttrSlot(\n handleId: number,\n attrSlotIndex: number,\n value: unknown,\n context?: EtAttrAdapterContext,\n): SerializableValue | null {\n return prepareSpreadAttrSlotImpl(handleId, attrSlotIndex, value, true, context);\n}\n\nexport function prepareTypedSpreadAttrSlot(\n handleId: number,\n attrSlotIndex: number,\n value: unknown,\n): SerializableValue | null {\n return prepareSpreadAttrSlotImpl(handleId, attrSlotIndex, value, false);\n}\n"]}
@@ -9,5 +9,6 @@ export declare const ElementTemplateUpdateOps: {
9
9
  readonly updateTypedListItem: 8;
10
10
  readonly setMainThreadEvent: 9;
11
11
  readonly setMainThreadRef: 10;
12
+ readonly setGesture: 11;
12
13
  };
13
14
  export type ElementTemplateUpdateOp = typeof ElementTemplateUpdateOps[keyof typeof ElementTemplateUpdateOps];
@@ -12,5 +12,6 @@ export const ElementTemplateUpdateOps = {
12
12
  updateTypedListItem: 8,
13
13
  setMainThreadEvent: 9,
14
14
  setMainThreadRef: 10,
15
+ setGesture: 11,
15
16
  };
16
17
  //# sourceMappingURL=opcodes.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"opcodes.js","sourceRoot":"","sources":["../../../src/element-template/protocol/opcodes.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,MAAM,CAAC,MAAM,wBAAwB,GAAG;IACtC,cAAc,EAAE,CAAC;IACjB,YAAY,EAAE,CAAC;IACf,UAAU,EAAE,CAAC;IACb,UAAU,EAAE,CAAC;IACb,kBAAkB,EAAE,CAAC;IACrB,mBAAmB,EAAE,CAAC;IACtB,mBAAmB,EAAE,CAAC;IACtB,mBAAmB,EAAE,CAAC;IACtB,kBAAkB,EAAE,CAAC;IACrB,gBAAgB,EAAE,EAAE;CACZ,CAAC","sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nexport const ElementTemplateUpdateOps = {\n createTemplate: 1,\n setAttribute: 2,\n insertNode: 3,\n removeNode: 4,\n createTypedElement: 5,\n insertTypedListItem: 6,\n removeTypedListItem: 7,\n updateTypedListItem: 8,\n setMainThreadEvent: 9,\n setMainThreadRef: 10,\n} as const;\n\nexport type ElementTemplateUpdateOp = typeof ElementTemplateUpdateOps[keyof typeof ElementTemplateUpdateOps];\n"]}
1
+ {"version":3,"file":"opcodes.js","sourceRoot":"","sources":["../../../src/element-template/protocol/opcodes.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,MAAM,CAAC,MAAM,wBAAwB,GAAG;IACtC,cAAc,EAAE,CAAC;IACjB,YAAY,EAAE,CAAC;IACf,UAAU,EAAE,CAAC;IACb,UAAU,EAAE,CAAC;IACb,kBAAkB,EAAE,CAAC;IACrB,mBAAmB,EAAE,CAAC;IACtB,mBAAmB,EAAE,CAAC;IACtB,mBAAmB,EAAE,CAAC;IACtB,kBAAkB,EAAE,CAAC;IACrB,gBAAgB,EAAE,EAAE;IACpB,UAAU,EAAE,EAAE;CACN,CAAC","sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nexport const ElementTemplateUpdateOps = {\n createTemplate: 1,\n setAttribute: 2,\n insertNode: 3,\n removeNode: 4,\n createTypedElement: 5,\n insertTypedListItem: 6,\n removeTypedListItem: 7,\n updateTypedListItem: 8,\n setMainThreadEvent: 9,\n setMainThreadRef: 10,\n setGesture: 11,\n} as const;\n\nexport type ElementTemplateUpdateOp = typeof ElementTemplateUpdateOps[keyof typeof ElementTemplateUpdateOps];\n"]}
@@ -85,6 +85,12 @@ export type SetMainThreadEventCommand = [
85
85
  attrSlotIndex: number,
86
86
  value: SerializableValue | null
87
87
  ];
88
+ export type SetGestureCommand = [
89
+ typeof ElementTemplateUpdateOps.setGesture,
90
+ targetHandleId: number,
91
+ attrSlotIndex: number,
92
+ value: SerializableValue | null
93
+ ];
88
94
  export type SetMainThreadRefCommand = [
89
95
  typeof ElementTemplateUpdateOps.setMainThreadRef,
90
96
  targetHandleId: number,
@@ -131,7 +137,7 @@ export type UpdateTypedListItemInfoCommand = [
131
137
  listHandleId: number,
132
138
  item: UpdateTypedListItemCommand
133
139
  ];
134
- export type ElementTemplateUpdateCommand = CreateTemplateCommand | SetAttributeCommand | SetMainThreadEventCommand | SetMainThreadRefCommand | InsertNodeCommand | RemoveNodeCommand | CreateTypedElementCommand | InsertTypedListItemCommand | RemoveTypedListItemCommand | UpdateTypedListItemInfoCommand;
140
+ export type ElementTemplateUpdateCommand = CreateTemplateCommand | SetAttributeCommand | SetMainThreadEventCommand | SetMainThreadRefCommand | SetGestureCommand | InsertNodeCommand | RemoveNodeCommand | CreateTypedElementCommand | InsertTypedListItemCommand | RemoveTypedListItemCommand | UpdateTypedListItemInfoCommand;
135
141
  export type ElementTemplateUpdateCommandStream = ElementTemplateUpdateCommand[number][];
136
142
  export interface ElementTemplateFlushOptions {
137
143
  pipelineOptions?: PipelineOptions;
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/element-template/protocol/types.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAI1D,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,+BAA+B,EAAE,0BAA0B,EAAE,MAAM,WAAW,CAAC","sourcesContent":["// Copyright 2025 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport type { RunWorkletCtxData } from '@lynx-js/react/worklet-runtime/bindings';\n\nimport { ElementTemplateUpdateOps } from './opcodes.js';\nimport { ELEMENT_TEMPLATE_PAGE_HANDLE_ID, ELEMENT_TEMPLATE_PAGE_TYPE } from './page.js';\n\nexport type SerializableValue =\n | string\n | number\n | boolean\n | null\n | SerializableValue[]\n | { [key: string]: SerializableValue };\n\nexport type RuntimeOptionValue =\n | SerializableValue\n | FiberElement\n | RuntimeOptionValue[]\n | { [key: string]: RuntimeOptionValue };\n\nexport type RuntimeOptions = Record<string, RuntimeOptionValue>;\n\nexport type RuntimeAttributeSlotValue =\n | SerializableValue\n | ((...args: unknown[]) => unknown)\n | RuntimeAttributeSlotValue[]\n | { [key: string]: RuntimeAttributeSlotValue };\n\nexport type RuntimeTypedElementAttributes = Record<string, RuntimeAttributeSlotValue>;\n\nexport type TypedElementAttributesCommand = Record<string, SerializableValue>;\n\nexport type RuntimeChildSlots = Array<ElementTemplateHandle[] | null | undefined>;\n\nexport type ElementTemplateHandleSlotsCommand = Array<number[] | null | undefined>;\n\nexport type SerializedEtNodeChildSlots = Array<SerializedEtNode[] | null | undefined>;\n\nexport interface ElementTemplateHandleRefCommandValue {\n __etHandleRef: number;\n [key: string]: SerializableValue;\n}\n\nexport interface UpdateTypedListItemCommand extends ElementTemplateHandleRefCommandValue {\n type: string;\n platformInfo: Record<string, SerializableValue>;\n subtreeHandleIds: number[];\n}\n\nexport type RuntimeOptionsCommand = Record<string, SerializableValue>;\n\n// Deferred typed-list create carries logical item records here. Its future\n// main-thread consumer resolves these refs into the list-specific runtime carrier.\nexport interface TypedListOptionsCommand extends RuntimeOptionsCommand {\n listChildren: UpdateTypedListItemCommand[];\n}\n\nexport interface RuntimeTypedListOptions {\n listChildren: ElementTemplateHandle[];\n}\n\nexport type SerializedRuntimeOptions = Record<string, SerializableValue>;\n\nexport interface SerializedTypedListOptions {\n listChildren: SerializedEtNode[];\n}\n\nexport interface SerializedEtNodeBase {\n attributeSlots?: SerializableValue[] | null;\n childSlots?: SerializedEtNodeChildSlots | null;\n uid: number;\n options?: SerializedRuntimeOptions | null;\n}\n\nexport interface SerializedCompiledNode extends SerializedEtNodeBase {\n templateKey: string;\n bundleUrl?: string;\n attributeSlots?: SerializableValue[] | null;\n}\n\nexport interface SerializedTypedNode extends SerializedEtNodeBase {\n // Native __SerializeElementTemplate returns typed hosts as { tag, attributes }.\n tag: string;\n attributes?: TypedElementAttributesCommand | null;\n}\n\nexport interface SerializedTypedListNode extends Omit<SerializedEtNodeBase, 'options'> {\n tag: 'list';\n attributes?: TypedElementAttributesCommand | null;\n options?: SerializedTypedListOptions | null;\n}\n\nexport type SerializedEtNode = SerializedCompiledNode | SerializedTypedNode | SerializedTypedListNode;\n\nexport interface SerializedPageRoot extends SerializedTypedNode {\n tag: typeof ELEMENT_TEMPLATE_PAGE_TYPE;\n uid: typeof ELEMENT_TEMPLATE_PAGE_HANDLE_ID;\n}\n\nexport interface ElementTemplateHydrateCommitContext {\n page: SerializedPageRoot;\n reloadVersion: number;\n}\n\nexport type CreateTemplateCommand = [\n typeof ElementTemplateUpdateOps.createTemplate,\n handleId: number,\n templateKey: string,\n bundleUrl: string | null | undefined,\n attributeSlots: SerializableValue[] | null | undefined,\n childSlots: ElementTemplateHandleSlotsCommand | null | undefined,\n];\n\nexport type SetAttributeCommand = [\n typeof ElementTemplateUpdateOps.setAttribute,\n targetHandleId: number,\n attrSlotIndex: number,\n value: SerializableValue | null,\n];\n\nexport type SetMainThreadEventCommand = [\n typeof ElementTemplateUpdateOps.setMainThreadEvent,\n targetHandleId: number,\n attrSlotIndex: number,\n value: SerializableValue | null,\n];\n\nexport type SetMainThreadRefCommand = [\n typeof ElementTemplateUpdateOps.setMainThreadRef,\n targetHandleId: number,\n attrSlotIndex: number,\n value: SerializableValue | null,\n];\n\nexport type InsertNodeCommand = [\n typeof ElementTemplateUpdateOps.insertNode,\n targetHandleId: number,\n childSlotIndex: number,\n childHandleId: number,\n referenceHandleId: number,\n attachedSubtreeHandleIds: number[] | null,\n];\n\nexport type RemoveNodeCommand = [\n typeof ElementTemplateUpdateOps.removeNode,\n targetHandleId: number,\n childSlotIndex: number,\n childHandleId: number,\n removedSubtreeHandleIds: number[],\n];\n\nexport type CreateTypedElementCommand = [\n typeof ElementTemplateUpdateOps.createTypedElement,\n handleId: number,\n type: string,\n attributes: TypedElementAttributesCommand | null | undefined,\n childSlots: ElementTemplateHandleSlotsCommand | null | undefined,\n options: RuntimeOptionsCommand | TypedListOptionsCommand | null | undefined,\n];\n\nexport type InsertTypedListItemCommand = [\n typeof ElementTemplateUpdateOps.insertTypedListItem,\n listHandleId: number,\n item: UpdateTypedListItemCommand,\n beforeHandleId: number,\n];\n\nexport type RemoveTypedListItemCommand = [\n typeof ElementTemplateUpdateOps.removeTypedListItem,\n listHandleId: number,\n itemHandleId: number,\n removedSubtreeHandleIds: number[],\n];\n\nexport type UpdateTypedListItemInfoCommand = [\n typeof ElementTemplateUpdateOps.updateTypedListItem,\n listHandleId: number,\n item: UpdateTypedListItemCommand,\n];\n\nexport type ElementTemplateUpdateCommand =\n | CreateTemplateCommand\n | SetAttributeCommand\n | SetMainThreadEventCommand\n | SetMainThreadRefCommand\n | InsertNodeCommand\n | RemoveNodeCommand\n | CreateTypedElementCommand\n | InsertTypedListItemCommand\n | RemoveTypedListItemCommand\n | UpdateTypedListItemInfoCommand;\n\n// Commands are transported as a flat stream to match the native update payload.\n// Tuple aliases above define each opcode's shape; this item union preserves the\n// existing flat buffer ergonomics while making command contracts explicit.\nexport type ElementTemplateUpdateCommandStream = ElementTemplateUpdateCommand[number][];\n\nexport interface ElementTemplateFlushOptions {\n pipelineOptions?: PipelineOptions;\n triggerDataUpdated?: boolean;\n emptyPatch?: boolean;\n}\n\nexport interface ElementTemplateUpdateCommitContext {\n ops: ElementTemplateUpdateCommandStream;\n flushOptions: ElementTemplateFlushOptions;\n flowIds?: number[] | undefined;\n isHydration?: boolean | undefined;\n reloadVersion?: number | undefined;\n delayedRunOnMainThreadData?: RunWorkletCtxData[] | undefined;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/element-template/protocol/types.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAI1D,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,+BAA+B,EAAE,0BAA0B,EAAE,MAAM,WAAW,CAAC","sourcesContent":["// Copyright 2025 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport type { RunWorkletCtxData } from '@lynx-js/react/worklet-runtime/bindings';\n\nimport { ElementTemplateUpdateOps } from './opcodes.js';\nimport { ELEMENT_TEMPLATE_PAGE_HANDLE_ID, ELEMENT_TEMPLATE_PAGE_TYPE } from './page.js';\n\nexport type SerializableValue =\n | string\n | number\n | boolean\n | null\n | SerializableValue[]\n | { [key: string]: SerializableValue };\n\nexport type RuntimeOptionValue =\n | SerializableValue\n | FiberElement\n | RuntimeOptionValue[]\n | { [key: string]: RuntimeOptionValue };\n\nexport type RuntimeOptions = Record<string, RuntimeOptionValue>;\n\nexport type RuntimeAttributeSlotValue =\n | SerializableValue\n | ((...args: unknown[]) => unknown)\n | RuntimeAttributeSlotValue[]\n | { [key: string]: RuntimeAttributeSlotValue };\n\nexport type RuntimeTypedElementAttributes = Record<string, RuntimeAttributeSlotValue>;\n\nexport type TypedElementAttributesCommand = Record<string, SerializableValue>;\n\nexport type RuntimeChildSlots = Array<ElementTemplateHandle[] | null | undefined>;\n\nexport type ElementTemplateHandleSlotsCommand = Array<number[] | null | undefined>;\n\nexport type SerializedEtNodeChildSlots = Array<SerializedEtNode[] | null | undefined>;\n\nexport interface ElementTemplateHandleRefCommandValue {\n __etHandleRef: number;\n [key: string]: SerializableValue;\n}\n\nexport interface UpdateTypedListItemCommand extends ElementTemplateHandleRefCommandValue {\n type: string;\n platformInfo: Record<string, SerializableValue>;\n subtreeHandleIds: number[];\n}\n\nexport type RuntimeOptionsCommand = Record<string, SerializableValue>;\n\n// Deferred typed-list create carries logical item records here. Its future\n// main-thread consumer resolves these refs into the list-specific runtime carrier.\nexport interface TypedListOptionsCommand extends RuntimeOptionsCommand {\n listChildren: UpdateTypedListItemCommand[];\n}\n\nexport interface RuntimeTypedListOptions {\n listChildren: ElementTemplateHandle[];\n}\n\nexport type SerializedRuntimeOptions = Record<string, SerializableValue>;\n\nexport interface SerializedTypedListOptions {\n listChildren: SerializedEtNode[];\n}\n\nexport interface SerializedEtNodeBase {\n attributeSlots?: SerializableValue[] | null;\n childSlots?: SerializedEtNodeChildSlots | null;\n uid: number;\n options?: SerializedRuntimeOptions | null;\n}\n\nexport interface SerializedCompiledNode extends SerializedEtNodeBase {\n templateKey: string;\n bundleUrl?: string;\n attributeSlots?: SerializableValue[] | null;\n}\n\nexport interface SerializedTypedNode extends SerializedEtNodeBase {\n // Native __SerializeElementTemplate returns typed hosts as { tag, attributes }.\n tag: string;\n attributes?: TypedElementAttributesCommand | null;\n}\n\nexport interface SerializedTypedListNode extends Omit<SerializedEtNodeBase, 'options'> {\n tag: 'list';\n attributes?: TypedElementAttributesCommand | null;\n options?: SerializedTypedListOptions | null;\n}\n\nexport type SerializedEtNode = SerializedCompiledNode | SerializedTypedNode | SerializedTypedListNode;\n\nexport interface SerializedPageRoot extends SerializedTypedNode {\n tag: typeof ELEMENT_TEMPLATE_PAGE_TYPE;\n uid: typeof ELEMENT_TEMPLATE_PAGE_HANDLE_ID;\n}\n\nexport interface ElementTemplateHydrateCommitContext {\n page: SerializedPageRoot;\n reloadVersion: number;\n}\n\nexport type CreateTemplateCommand = [\n typeof ElementTemplateUpdateOps.createTemplate,\n handleId: number,\n templateKey: string,\n bundleUrl: string | null | undefined,\n attributeSlots: SerializableValue[] | null | undefined,\n childSlots: ElementTemplateHandleSlotsCommand | null | undefined,\n];\n\nexport type SetAttributeCommand = [\n typeof ElementTemplateUpdateOps.setAttribute,\n targetHandleId: number,\n attrSlotIndex: number,\n value: SerializableValue | null,\n];\n\nexport type SetMainThreadEventCommand = [\n typeof ElementTemplateUpdateOps.setMainThreadEvent,\n targetHandleId: number,\n attrSlotIndex: number,\n value: SerializableValue | null,\n];\n\nexport type SetGestureCommand = [\n typeof ElementTemplateUpdateOps.setGesture,\n targetHandleId: number,\n attrSlotIndex: number,\n value: SerializableValue | null,\n];\n\nexport type SetMainThreadRefCommand = [\n typeof ElementTemplateUpdateOps.setMainThreadRef,\n targetHandleId: number,\n attrSlotIndex: number,\n value: SerializableValue | null,\n];\n\nexport type InsertNodeCommand = [\n typeof ElementTemplateUpdateOps.insertNode,\n targetHandleId: number,\n childSlotIndex: number,\n childHandleId: number,\n referenceHandleId: number,\n attachedSubtreeHandleIds: number[] | null,\n];\n\nexport type RemoveNodeCommand = [\n typeof ElementTemplateUpdateOps.removeNode,\n targetHandleId: number,\n childSlotIndex: number,\n childHandleId: number,\n removedSubtreeHandleIds: number[],\n];\n\nexport type CreateTypedElementCommand = [\n typeof ElementTemplateUpdateOps.createTypedElement,\n handleId: number,\n type: string,\n attributes: TypedElementAttributesCommand | null | undefined,\n childSlots: ElementTemplateHandleSlotsCommand | null | undefined,\n options: RuntimeOptionsCommand | TypedListOptionsCommand | null | undefined,\n];\n\nexport type InsertTypedListItemCommand = [\n typeof ElementTemplateUpdateOps.insertTypedListItem,\n listHandleId: number,\n item: UpdateTypedListItemCommand,\n beforeHandleId: number,\n];\n\nexport type RemoveTypedListItemCommand = [\n typeof ElementTemplateUpdateOps.removeTypedListItem,\n listHandleId: number,\n itemHandleId: number,\n removedSubtreeHandleIds: number[],\n];\n\nexport type UpdateTypedListItemInfoCommand = [\n typeof ElementTemplateUpdateOps.updateTypedListItem,\n listHandleId: number,\n item: UpdateTypedListItemCommand,\n];\n\nexport type ElementTemplateUpdateCommand =\n | CreateTemplateCommand\n | SetAttributeCommand\n | SetMainThreadEventCommand\n | SetMainThreadRefCommand\n | SetGestureCommand\n | InsertNodeCommand\n | RemoveNodeCommand\n | CreateTypedElementCommand\n | InsertTypedListItemCommand\n | RemoveTypedListItemCommand\n | UpdateTypedListItemInfoCommand;\n\n// Commands are transported as a flat stream to match the native update payload.\n// Tuple aliases above define each opcode's shape; this item union preserves the\n// existing flat buffer ergonomics while making command contracts explicit.\nexport type ElementTemplateUpdateCommandStream = ElementTemplateUpdateCommand[number][];\n\nexport interface ElementTemplateFlushOptions {\n pipelineOptions?: PipelineOptions;\n triggerDataUpdated?: boolean;\n emptyPatch?: boolean;\n}\n\nexport interface ElementTemplateUpdateCommitContext {\n ops: ElementTemplateUpdateCommandStream;\n flushOptions: ElementTemplateFlushOptions;\n flowIds?: number[] | undefined;\n isHydration?: boolean | undefined;\n reloadVersion?: number | undefined;\n delayedRunOnMainThreadData?: RunWorkletCtxData[] | undefined;\n}\n"]}
@@ -9,7 +9,8 @@ import { TYPED_ELEMENT_ATTRIBUTES_SLOT_INDEX } from './template/typed-attributes
9
9
  import { ElementTemplateUpdateOps } from '../protocol/opcodes.js';
10
10
  import { ELEMENT_TEMPLATE_PAGE_HANDLE_ID } from '../protocol/page.js';
11
11
  import { elementTemplateIdentityKey, elementTemplateTypeTag, parseElementTemplateType, } from '../protocol/template-type.js';
12
- import { deleteMainThreadDynamicAttrStateForSubtree, initializeMainThreadDynamicAttrSlots, prepareMainThreadDynamicAttrSlotsForNative, updateMainThreadEventAttrSlot, updateMainThreadRefAttrSlot, } from './template/main-thread-dynamic-attr-state.js';
12
+ import { deleteMainThreadDynamicAttrStateForSubtree, initializeMainThreadDynamicAttrSlots, isSpreadDynamicAttrSlot, prepareMainThreadDynamicAttrSlotsForNative, prepareSpreadAttrSlotForNative, reconcileUnhydratedSpreadMTRefSlots, updateGestureAttrSlot, updateMainThreadEventAttrSlot, updateMainThreadRefAttrSlot, updateSpreadAttrSlot, } from './template/main-thread-dynamic-attr-state.js';
13
+ import { retainGestureCallbacks } from '../prop-adapters/gesture.js';
13
14
  // The update event's JSON transport already normalizes array holes and undefined
14
15
  // entries to null. Consume those wire values without copying each attr array.
15
16
  export function applyElementTemplateUpdateCommands(stream, isHydration = false) {
@@ -39,7 +40,7 @@ export function applyElementTemplateUpdateCommands(stream, isHydration = false)
39
40
  const nativeRef = __CreateElementTemplate(templateKey, bundleUrl, nativeAttributeSlots, resolvedChildSlots, handleId);
40
41
  if (nativeRef) {
41
42
  elementTemplateRegistry.set(handleId, nativeRef);
42
- initializeMainThreadDynamicAttrSlots(handleId, templateType, attributeSlots);
43
+ initializeMainThreadDynamicAttrSlots(handleId, templateType, attributeSlots, true);
43
44
  }
44
45
  break;
45
46
  }
@@ -58,7 +59,28 @@ export function applyElementTemplateUpdateCommands(stream, isHydration = false)
58
59
  break;
59
60
  }
60
61
  }
62
+ if (isSpreadDynamicAttrSlot(targetId, attrSlotIndex)) {
63
+ const nativeValue = prepareSpreadAttrSlotForNative(value);
64
+ __SetAttributeOfElementTemplate(nativeRef, attrSlotIndex, nativeValue);
65
+ updateSpreadAttrSlot(targetId, attrSlotIndex, value, nativeRef, isHydration);
66
+ break;
67
+ }
68
+ __SetAttributeOfElementTemplate(nativeRef, attrSlotIndex, value);
69
+ break;
70
+ }
71
+ case ElementTemplateUpdateOps.setGesture: {
72
+ const targetId = stream[i++];
73
+ const attrSlotIndex = stream[i++];
74
+ const value = stream[i++];
75
+ const nativeRef = resolveTargetHandle(targetId, 'target');
76
+ if (!nativeRef) {
77
+ continue;
78
+ }
79
+ if (value != null) {
80
+ retainGestureCallbacks(value);
81
+ }
61
82
  __SetAttributeOfElementTemplate(nativeRef, attrSlotIndex, value);
83
+ updateGestureAttrSlot(targetId, attrSlotIndex, value, isHydration);
62
84
  break;
63
85
  }
64
86
  case ElementTemplateUpdateOps.setMainThreadEvent: {
@@ -219,6 +241,9 @@ export function applyElementTemplateUpdateCommands(stream, isHydration = false)
219
241
  }
220
242
  }
221
243
  }
244
+ if (isHydration) {
245
+ reconcileUnhydratedSpreadMTRefSlots();
246
+ }
222
247
  flushPendingListUpdates();
223
248
  }
224
249
  function flushPendingListUpdates() {