@lynx-js/react 0.125.0 → 0.126.1

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 (1316) hide show
  1. package/CHANGELOG.md +63 -0
  2. package/LICENSE +202 -0
  3. package/components/.gitignore +3 -0
  4. package/components/.npmignore +5 -0
  5. package/components/lib/Page.js +4 -2
  6. package/components/lib/Page.js.map +1 -1
  7. package/components/src/Page.ts +4 -2
  8. package/components/tsconfig.json +17 -0
  9. package/components/tsconfig.tsbuildinfo +1 -0
  10. package/package.json +6 -2
  11. package/refresh/.gitignore +1 -0
  12. package/refresh/.npmignore +3 -0
  13. package/refresh/.turbo/turbo-build.log +9 -0
  14. package/refresh/package.json +21 -0
  15. package/refresh/rslib.config.ts +24 -0
  16. package/refresh/tsconfig.json +4 -0
  17. package/refresh/turbo.json +16 -0
  18. package/runtime/.gitignore +4 -0
  19. package/runtime/.npmignore +15 -0
  20. package/runtime/.prettierrc +6 -0
  21. package/runtime/.turbo/turbo-build.log +1 -0
  22. package/runtime/CHANGELOG.md +7 -0
  23. package/runtime/__test__/core/background-function.test.ts +133 -0
  24. package/runtime/__test__/core/commit-context.test.ts +37 -0
  25. package/runtime/__test__/core/forceRootRender.test.ts +65 -0
  26. package/runtime/__test__/core/globalProps.test.ts +141 -0
  27. package/runtime/__test__/core/hooks/mainThread.test.tsx +279 -0
  28. package/runtime/__test__/core/hooks/useLynxGlobalEventListener.test.jsx +168 -0
  29. package/runtime/__test__/core/lynx-data-processors.test.ts +131 -0
  30. package/runtime/__test__/core/lynx-page-data.test.ts +62 -0
  31. package/runtime/__test__/core/lynx-update-data.test.ts +97 -0
  32. package/runtime/__test__/core/main-thread-function.test.ts +13 -0
  33. package/runtime/__test__/core/main-thread-ref.test.ts +102 -0
  34. package/runtime/__test__/core/ref.test.ts +261 -0
  35. package/runtime/__test__/core/reload-version.test.ts +14 -0
  36. package/runtime/__test__/core/thread-function-call.test.ts +182 -0
  37. package/runtime/__test__/element-template/debug/alog.test.ts +214 -0
  38. package/runtime/__test__/element-template/debug/elementPAPICall.test.ts +157 -0
  39. package/runtime/__test__/element-template/debug/profile-hook.test.tsx +67 -0
  40. package/runtime/__test__/element-template/debug/profile-installation.test.tsx +49 -0
  41. package/runtime/__test__/element-template/fixtures/background/event/conditional-direct-event/index.tsx +8 -0
  42. package/runtime/__test__/element-template/fixtures/background/event/direct-event/index.tsx +7 -0
  43. package/runtime/__test__/element-template/fixtures/background/event/main-thread-direct-event/index.tsx +11 -0
  44. package/runtime/__test__/element-template/fixtures/background/event/main-thread-run-on-background-event/index.tsx +14 -0
  45. package/runtime/__test__/element-template/fixtures/background/event/spread-event/index.tsx +20 -0
  46. package/runtime/__test__/element-template/fixtures/background/global-props/direct-read/index.tsx +7 -0
  47. package/runtime/__test__/element-template/fixtures/background/global-props/event-hook/index.tsx +34 -0
  48. package/runtime/__test__/element-template/fixtures/background/hydrate/_shared.tsx +584 -0
  49. package/runtime/__test__/element-template/fixtures/background/hydrate/attrs.adds-background-only/case.tsx +5 -0
  50. package/runtime/__test__/element-template/fixtures/background/hydrate/attrs.adds-background-only/output.txt +11 -0
  51. package/runtime/__test__/element-template/fixtures/background/hydrate/attrs.aligns-ids-and-patches/case.tsx +5 -0
  52. package/runtime/__test__/element-template/fixtures/background/hydrate/attrs.aligns-ids-and-patches/output.txt +12 -0
  53. package/runtime/__test__/element-template/fixtures/background/hydrate/attrs.array-diff/case.tsx +5 -0
  54. package/runtime/__test__/element-template/fixtures/background/hydrate/attrs.array-diff/output.txt +13 -0
  55. package/runtime/__test__/element-template/fixtures/background/hydrate/attrs.batch-multiple-patches/case.tsx +5 -0
  56. package/runtime/__test__/element-template/fixtures/background/hydrate/attrs.batch-multiple-patches/output.txt +12 -0
  57. package/runtime/__test__/element-template/fixtures/background/hydrate/attrs.nullish-values/case.tsx +5 -0
  58. package/runtime/__test__/element-template/fixtures/background/hydrate/attrs.nullish-values/output.txt +10 -0
  59. package/runtime/__test__/element-template/fixtures/background/hydrate/attrs.object-value-updates/case.tsx +5 -0
  60. package/runtime/__test__/element-template/fixtures/background/hydrate/attrs.object-value-updates/output.txt +13 -0
  61. package/runtime/__test__/element-template/fixtures/background/hydrate/attrs.patches-nested-component/case.tsx +5 -0
  62. package/runtime/__test__/element-template/fixtures/background/hydrate/attrs.patches-nested-component/output.txt +13 -0
  63. package/runtime/__test__/element-template/fixtures/background/hydrate/attrs.removes-missing/case.tsx +5 -0
  64. package/runtime/__test__/element-template/fixtures/background/hydrate/attrs.removes-missing/output.txt +10 -0
  65. package/runtime/__test__/element-template/fixtures/background/hydrate/attrs.skips-identical/case.tsx +5 -0
  66. package/runtime/__test__/element-template/fixtures/background/hydrate/attrs.skips-identical/output.txt +3 -0
  67. package/runtime/__test__/element-template/fixtures/background/hydrate/attrs.style-object-updates/case.tsx +5 -0
  68. package/runtime/__test__/element-template/fixtures/background/hydrate/attrs.style-object-updates/output.txt +13 -0
  69. package/runtime/__test__/element-template/fixtures/background/hydrate/attrs.type-diff/case.tsx +5 -0
  70. package/runtime/__test__/element-template/fixtures/background/hydrate/attrs.type-diff/output.txt +10 -0
  71. package/runtime/__test__/element-template/fixtures/background/hydrate/children.creates-missing-nodes-recursively/case.tsx +5 -0
  72. package/runtime/__test__/element-template/fixtures/background/hydrate/children.creates-missing-nodes-recursively/output.txt +39 -0
  73. package/runtime/__test__/element-template/fixtures/background/hydrate/children.iterates-existing-slots/case.tsx +5 -0
  74. package/runtime/__test__/element-template/fixtures/background/hydrate/children.iterates-existing-slots/output.txt +16 -0
  75. package/runtime/__test__/element-template/fixtures/background/hydrate/children.missing-attrs-element/case.tsx +5 -0
  76. package/runtime/__test__/element-template/fixtures/background/hydrate/children.missing-attrs-element/output.txt +3 -0
  77. package/runtime/__test__/element-template/fixtures/background/hydrate/children.missing-slot-record-on-background/case.tsx +5 -0
  78. package/runtime/__test__/element-template/fixtures/background/hydrate/children.missing-slot-record-on-background/output.txt +11 -0
  79. package/runtime/__test__/element-template/fixtures/background/hydrate/children.missing-slot-record-on-main/case.tsx +5 -0
  80. package/runtime/__test__/element-template/fixtures/background/hydrate/children.missing-slot-record-on-main/output.txt +16 -0
  81. package/runtime/__test__/element-template/fixtures/background/hydrate/children.raw-text-instance-empty-text/case.tsx +5 -0
  82. package/runtime/__test__/element-template/fixtures/background/hydrate/children.raw-text-instance-empty-text/output.txt +4 -0
  83. package/runtime/__test__/element-template/fixtures/background/hydrate/coverage.emit-create-raw-text/case.tsx +5 -0
  84. package/runtime/__test__/element-template/fixtures/background/hydrate/coverage.emit-create-raw-text/output.txt +12 -0
  85. package/runtime/__test__/element-template/fixtures/background/hydrate/coverage.emit-create-raw-text-non-text/case.tsx +5 -0
  86. package/runtime/__test__/element-template/fixtures/background/hydrate/coverage.emit-create-raw-text-non-text/output.txt +10 -0
  87. package/runtime/__test__/element-template/fixtures/background/hydrate/coverage.move-before-child/case.tsx +5 -0
  88. package/runtime/__test__/element-template/fixtures/background/hydrate/coverage.move-before-child/output.txt +10 -0
  89. package/runtime/__test__/element-template/fixtures/background/hydrate/coverage.raw-text-key-branches/case.tsx +5 -0
  90. package/runtime/__test__/element-template/fixtures/background/hydrate/coverage.raw-text-key-branches/output.txt +22 -0
  91. package/runtime/__test__/element-template/fixtures/background/hydrate/full-flow.dispatches-update-event/case.tsx +5 -0
  92. package/runtime/__test__/element-template/fixtures/background/hydrate/full-flow.dispatches-update-event/output.txt +5 -0
  93. package/runtime/__test__/element-template/fixtures/background/hydrate/root-key-mismatch-reconciles/case.tsx +5 -0
  94. package/runtime/__test__/element-template/fixtures/background/hydrate/root-key-mismatch-reconciles/output.txt +24 -0
  95. package/runtime/__test__/element-template/fixtures/background/hydrate/updates-raw-text-instance-id/case.tsx +5 -0
  96. package/runtime/__test__/element-template/fixtures/background/hydrate/updates-raw-text-instance-id/output.txt +5 -0
  97. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.creates-and-inserts-new/index.tsx +14 -0
  98. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.creates-and-inserts-new/output.txt +20 -0
  99. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.inserts-before-existing-sibling/index.tsx +39 -0
  100. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.inserts-before-existing-sibling/output.txt +20 -0
  101. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.mixed-operations/index.tsx +38 -0
  102. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.mixed-operations/output.txt +29 -0
  103. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.moves-before-existing-sibling/index.tsx +40 -0
  104. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.moves-before-existing-sibling/output.txt +12 -0
  105. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.non-string-raw-text-key-on-main/index.tsx +14 -0
  106. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.non-string-raw-text-key-on-main/output.txt +22 -0
  107. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.removes-missing/index.tsx +14 -0
  108. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.removes-missing/output.txt +13 -0
  109. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.reorders-when-order-differs/index.tsx +34 -0
  110. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.reorders-when-order-differs/output.txt +12 -0
  111. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.reuses-by-type-ignoring-keys/index.tsx +18 -0
  112. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.reuses-by-type-ignoring-keys/output.txt +16 -0
  113. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/complex-trees.deeply-nested-dynamic-content/index.tsx +33 -0
  114. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/complex-trees.deeply-nested-dynamic-content/output.txt +26 -0
  115. package/runtime/__test__/element-template/fixtures/background/init-data/update/index.tsx +11 -0
  116. package/runtime/__test__/element-template/fixtures/background/instance/_shared.ts +30 -0
  117. package/runtime/__test__/element-template/fixtures/background/instance/ops/does-not-emit-patch-when-attrs-reference-reused/case.ts +24 -0
  118. package/runtime/__test__/element-template/fixtures/background/instance/ops/does-not-emit-patch-when-attrs-reference-reused/output.txt +1 -0
  119. package/runtime/__test__/element-template/fixtures/background/instance/ops/emits-bundle-url-in-create-template/case.ts +11 -0
  120. package/runtime/__test__/element-template/fixtures/background/instance/ops/emits-bundle-url-in-create-template/output.txt +8 -0
  121. package/runtime/__test__/element-template/fixtures/background/instance/ops/supports-silent-insert-before/case.ts +11 -0
  122. package/runtime/__test__/element-template/fixtures/background/instance/ops/supports-silent-insert-before/output.txt +1 -0
  123. package/runtime/__test__/element-template/fixtures/background/instance/ops/treats-non-object-attrs-entry-as-empty-object/case.ts +23 -0
  124. package/runtime/__test__/element-template/fixtures/background/instance/ops/treats-non-object-attrs-entry-as-empty-object/output.txt +6 -0
  125. package/runtime/__test__/element-template/fixtures/background/instance/ops/treats-nullish-attrs-as-empty-object/case.ts +23 -0
  126. package/runtime/__test__/element-template/fixtures/background/instance/ops/treats-nullish-attrs-as-empty-object/output.txt +6 -0
  127. package/runtime/__test__/element-template/fixtures/background/main-thread-function/run-on-main-thread/index.tsx +24 -0
  128. package/runtime/__test__/element-template/fixtures/background/ref/direct-ref/index.tsx +7 -0
  129. package/runtime/__test__/element-template/fixtures/background/ref/multi-ref/index.tsx +20 -0
  130. package/runtime/__test__/element-template/fixtures/background/ref/spread-ref/index.tsx +14 -0
  131. package/runtime/__test__/element-template/fixtures/background/ref/unsupported-ref/index.tsx +12 -0
  132. package/runtime/__test__/element-template/fixtures/background/render/_shared.tsx +85 -0
  133. package/runtime/__test__/element-template/fixtures/background/render/constructs-shadow-tree/case.tsx +5 -0
  134. package/runtime/__test__/element-template/fixtures/background/render/constructs-shadow-tree/output.txt +7 -0
  135. package/runtime/__test__/element-template/fixtures/background/render/supports-slot-component-materiality/case.tsx +5 -0
  136. package/runtime/__test__/element-template/fixtures/background/render/supports-slot-component-materiality/output.txt +13 -0
  137. package/runtime/__test__/element-template/fixtures/background/update/keyed/compiled-keyed-list/index.tsx +15 -0
  138. package/runtime/__test__/element-template/fixtures/background/update/keyed/compiled-keyed-subtree-list/index.tsx +19 -0
  139. package/runtime/__test__/element-template/fixtures/background/update/sparse/compiled-element-slot/index.tsx +26 -0
  140. package/runtime/__test__/element-template/fixtures/hydration/hydration-data/_shared.tsx +169 -0
  141. package/runtime/__test__/element-template/fixtures/hydration/hydration-data/multiple-root-instances/case.tsx +5 -0
  142. package/runtime/__test__/element-template/fixtures/hydration/hydration-data/multiple-root-instances/output.txt +14 -0
  143. package/runtime/__test__/element-template/fixtures/hydration/hydration-data/nested-instances/case.tsx +5 -0
  144. package/runtime/__test__/element-template/fixtures/hydration/hydration-data/nested-instances/output.txt +8 -0
  145. package/runtime/__test__/element-template/fixtures/hydration/hydration-data/simple-element/case.tsx +5 -0
  146. package/runtime/__test__/element-template/fixtures/hydration/hydration-data/simple-element/output.txt +10 -0
  147. package/runtime/__test__/element-template/fixtures/hydration/hydration-data/sub-components/case.tsx +5 -0
  148. package/runtime/__test__/element-template/fixtures/hydration/hydration-data/sub-components/output.txt +28 -0
  149. package/runtime/__test__/element-template/fixtures/hydration/hydration-data/sub-components/source.tsx +15 -0
  150. package/runtime/__test__/element-template/fixtures/hydration/hydration-data/text-children/case.tsx +5 -0
  151. package/runtime/__test__/element-template/fixtures/hydration/hydration-data/text-children/output.txt +19 -0
  152. package/runtime/__test__/element-template/fixtures/hydration/hydration-data/text-children/source.tsx +8 -0
  153. package/runtime/__test__/element-template/fixtures/page/render-page/case.tsx +41 -0
  154. package/runtime/__test__/element-template/fixtures/page/render-page/native-log.txt +31 -0
  155. package/runtime/__test__/element-template/fixtures/page/render-page/output.txt +5 -0
  156. package/runtime/__test__/element-template/fixtures/page-compiled/authored-page/index.tsx +67 -0
  157. package/runtime/__test__/element-template/fixtures/patch/_shared.tsx +270 -0
  158. package/runtime/__test__/element-template/fixtures/patch/detaches-node-when-moving-between-slots/after-jsx.txt +7 -0
  159. package/runtime/__test__/element-template/fixtures/patch/detaches-node-when-moving-between-slots/before-jsx.txt +8 -0
  160. package/runtime/__test__/element-template/fixtures/patch/detaches-node-when-moving-between-slots/case.tsx +100 -0
  161. package/runtime/__test__/element-template/fixtures/patch/props-update/after-jsx.txt +3 -0
  162. package/runtime/__test__/element-template/fixtures/patch/props-update/before-jsx.txt +3 -0
  163. package/runtime/__test__/element-template/fixtures/patch/props-update/case.tsx +42 -0
  164. package/runtime/__test__/element-template/fixtures/patch/props-update/ops.txt +8 -0
  165. package/runtime/__test__/element-template/fixtures/patch/state-update/after-jsx.txt +3 -0
  166. package/runtime/__test__/element-template/fixtures/patch/state-update/before-jsx.txt +3 -0
  167. package/runtime/__test__/element-template/fixtures/patch/state-update/case.tsx +64 -0
  168. package/runtime/__test__/element-template/fixtures/patch/state-update/ops.txt +8 -0
  169. package/runtime/__test__/element-template/fixtures/patch-compiled/applies-insert-before-with-reference/after-jsx.txt +7 -0
  170. package/runtime/__test__/element-template/fixtures/patch-compiled/applies-insert-before-with-reference/before-jsx.txt +6 -0
  171. package/runtime/__test__/element-template/fixtures/patch-compiled/applies-insert-before-with-reference/index.tsx +39 -0
  172. package/runtime/__test__/element-template/fixtures/patch-compiled/applies-insert-before-with-reference/ops.txt +14 -0
  173. package/runtime/__test__/element-template/fixtures/patch-compiled/apply-hydration-ops/after-jsx.txt +10 -0
  174. package/runtime/__test__/element-template/fixtures/patch-compiled/apply-hydration-ops/before-jsx.txt +9 -0
  175. package/runtime/__test__/element-template/fixtures/patch-compiled/apply-hydration-ops/index.tsx +47 -0
  176. package/runtime/__test__/element-template/fixtures/patch-compiled/apply-hydration-ops/ops.txt +34 -0
  177. package/runtime/__test__/element-template/fixtures/render/child-siblings/index.js.txt +21 -0
  178. package/runtime/__test__/element-template/fixtures/render/child-siblings/index.tsx +16 -0
  179. package/runtime/__test__/element-template/fixtures/render/child-siblings/output.txt +8 -0
  180. package/runtime/__test__/element-template/fixtures/render/child-siblings/papi.txt +128 -0
  181. package/runtime/__test__/element-template/fixtures/render/child-siblings/templates.json.txt +66 -0
  182. package/runtime/__test__/element-template/fixtures/render/component/index.js.txt +12 -0
  183. package/runtime/__test__/element-template/fixtures/render/component/index.tsx +17 -0
  184. package/runtime/__test__/element-template/fixtures/render/component/output.txt +7 -0
  185. package/runtime/__test__/element-template/fixtures/render/component/papi.txt +67 -0
  186. package/runtime/__test__/element-template/fixtures/render/component/templates.json.txt +68 -0
  187. package/runtime/__test__/element-template/fixtures/render/component-slot-content/index.js.txt +16 -0
  188. package/runtime/__test__/element-template/fixtures/render/component-slot-content/index.tsx +18 -0
  189. package/runtime/__test__/element-template/fixtures/render/component-slot-content/output.txt +6 -0
  190. package/runtime/__test__/element-template/fixtures/render/component-slot-content/papi.txt +85 -0
  191. package/runtime/__test__/element-template/fixtures/render/component-slot-content/templates.json.txt +78 -0
  192. package/runtime/__test__/element-template/fixtures/render/css-scope-dynamic-bundle-url/fixture.config.json +5 -0
  193. package/runtime/__test__/element-template/fixtures/render/css-scope-dynamic-bundle-url/index.js.txt +6 -0
  194. package/runtime/__test__/element-template/fixtures/render/css-scope-dynamic-bundle-url/index.tsx +9 -0
  195. package/runtime/__test__/element-template/fixtures/render/css-scope-dynamic-bundle-url/output.txt +3 -0
  196. package/runtime/__test__/element-template/fixtures/render/css-scope-dynamic-bundle-url/papi.txt +25 -0
  197. package/runtime/__test__/element-template/fixtures/render/css-scope-dynamic-bundle-url/templates.json.txt +57 -0
  198. package/runtime/__test__/element-template/fixtures/render/mapped-view-children/index.js.txt +18 -0
  199. package/runtime/__test__/element-template/fixtures/render/mapped-view-children/index.tsx +13 -0
  200. package/runtime/__test__/element-template/fixtures/render/mapped-view-children/output.txt +17 -0
  201. package/runtime/__test__/element-template/fixtures/render/mapped-view-children/papi.txt +214 -0
  202. package/runtime/__test__/element-template/fixtures/render/mapped-view-children/templates.json.txt +63 -0
  203. package/runtime/__test__/element-template/fixtures/render/mixed-children/index.js.txt +15 -0
  204. package/runtime/__test__/element-template/fixtures/render/mixed-children/index.tsx +15 -0
  205. package/runtime/__test__/element-template/fixtures/render/mixed-children/output.txt +7 -0
  206. package/runtime/__test__/element-template/fixtures/render/mixed-children/papi.txt +86 -0
  207. package/runtime/__test__/element-template/fixtures/render/mixed-children/templates.json.txt +51 -0
  208. package/runtime/__test__/element-template/fixtures/render/multiple-text/index.js.txt +23 -0
  209. package/runtime/__test__/element-template/fixtures/render/multiple-text/index.tsx +22 -0
  210. package/runtime/__test__/element-template/fixtures/render/multiple-text/output.txt +38 -0
  211. package/runtime/__test__/element-template/fixtures/render/multiple-text/papi.txt +454 -0
  212. package/runtime/__test__/element-template/fixtures/render/multiple-text/templates.json.txt +131 -0
  213. package/runtime/__test__/element-template/fixtures/render/nested-templates/index.js.txt +19 -0
  214. package/runtime/__test__/element-template/fixtures/render/nested-templates/index.tsx +19 -0
  215. package/runtime/__test__/element-template/fixtures/render/nested-templates/output.txt +5 -0
  216. package/runtime/__test__/element-template/fixtures/render/nested-templates/papi.txt +80 -0
  217. package/runtime/__test__/element-template/fixtures/render/nested-templates/templates.json.txt +34 -0
  218. package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/_shared.ts +131 -0
  219. package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/appends-root-text-via-append-element/case.ts +19 -0
  220. package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/appends-root-text-via-append-element/native-log.txt +27 -0
  221. package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/appends-root-text-via-append-element/output.txt +12 -0
  222. package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/creates-template-from-attrs-and-slot-text/case.ts +39 -0
  223. package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/creates-template-from-attrs-and-slot-text/native-log.txt +49 -0
  224. package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/creates-template-from-attrs-and-slot-text/output.txt +34 -0
  225. package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/handles-multiple-template-children-in-the-same-slot/case.ts +34 -0
  226. package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/handles-multiple-template-children-in-the-same-slot/native-log.txt +56 -0
  227. package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/handles-multiple-template-children-in-the-same-slot/output.txt +11 -0
  228. package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/handles-multiple-text-nodes-in-the-same-slot/case.ts +29 -0
  229. package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/handles-multiple-text-nodes-in-the-same-slot/native-log.txt +64 -0
  230. package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/handles-multiple-text-nodes-in-the-same-slot/output.txt +20 -0
  231. package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/inserts-nested-templates-into-parent-slots/case.ts +42 -0
  232. package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/inserts-nested-templates-into-parent-slots/native-log.txt +84 -0
  233. package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/inserts-nested-templates-into-parent-slots/output.txt +42 -0
  234. package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/keeps-slot-children-separated-and-ordered/case.ts +31 -0
  235. package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/keeps-slot-children-separated-and-ordered/native-log.txt +66 -0
  236. package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/keeps-slot-children-separated-and-ordered/output.txt +41 -0
  237. package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/passes-bundle-url-to-native-create/case.ts +20 -0
  238. package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/passes-bundle-url-to-native-create/native-log.txt +25 -0
  239. package/runtime/__test__/element-template/fixtures/render/react-example/index.js.txt +39 -0
  240. package/runtime/__test__/element-template/fixtures/render/react-example/index.tsx +51 -0
  241. package/runtime/__test__/element-template/fixtures/render/react-example/output.txt +24 -0
  242. package/runtime/__test__/element-template/fixtures/render/react-example/papi.txt +70 -0
  243. package/runtime/__test__/element-template/fixtures/render/react-example/templates.json.txt +280 -0
  244. package/runtime/__test__/element-template/fixtures/render/sparse-element-slot/index.js.txt +14 -0
  245. package/runtime/__test__/element-template/fixtures/render/sparse-element-slot/index.tsx +17 -0
  246. package/runtime/__test__/element-template/fixtures/render/sparse-element-slot/output.txt +10 -0
  247. package/runtime/__test__/element-template/fixtures/render/sparse-element-slot/papi.txt +81 -0
  248. package/runtime/__test__/element-template/fixtures/render/sparse-element-slot/templates.json.txt +97 -0
  249. package/runtime/__test__/element-template/fixtures/render/template-dedupe/index.js.txt +28 -0
  250. package/runtime/__test__/element-template/fixtures/render/template-dedupe/index.tsx +28 -0
  251. package/runtime/__test__/element-template/fixtures/render/template-dedupe/output.txt +12 -0
  252. package/runtime/__test__/element-template/fixtures/render/template-dedupe/papi.txt +144 -0
  253. package/runtime/__test__/element-template/fixtures/render/template-dedupe/templates.json.txt +57 -0
  254. package/runtime/__test__/element-template/imports/global-props-api.test.ts +23 -0
  255. package/runtime/__test__/element-template/imports/init-data-api.test.ts +19 -0
  256. package/runtime/__test__/element-template/imports/jsx-runtime.test.ts +76 -0
  257. package/runtime/__test__/element-template/imports/legacy-react-runtime.test.ts +100 -0
  258. package/runtime/__test__/element-template/imports/main-thread-ref-api.test.ts +10 -0
  259. package/runtime/__test__/element-template/imports/no-legacy-imports.test.ts +415 -0
  260. package/runtime/__test__/element-template/imports/register-data-processors.test.ts +34 -0
  261. package/runtime/__test__/element-template/imports/suspense-lazy.test.ts +295 -0
  262. package/runtime/__test__/element-template/internal/legacy-internal-guardrail.test.ts +35 -0
  263. package/runtime/__test__/element-template/lynx/env.test.ts +242 -0
  264. package/runtime/__test__/element-template/lynx/lazy-bundle.test.ts +294 -0
  265. package/runtime/__test__/element-template/lynx/performance.test.ts +161 -0
  266. package/runtime/__test__/element-template/native/callDestroyLifetimeFun.test.ts +107 -0
  267. package/runtime/__test__/element-template/native/index.test.ts +224 -0
  268. package/runtime/__test__/element-template/native/init-timing-api.test.ts +29 -0
  269. package/runtime/__test__/element-template/native/main-thread-api.test.ts +202 -0
  270. package/runtime/__test__/element-template/native/mts-destroy.test.ts +226 -0
  271. package/runtime/__test__/element-template/native/reload.test.ts +588 -0
  272. package/runtime/__test__/element-template/runtime/background/adapter/background-adapter.et.test.tsx +65 -0
  273. package/runtime/__test__/element-template/runtime/background/commit-context.test.ts +91 -0
  274. package/runtime/__test__/element-template/runtime/background/commit-hook.test.ts +800 -0
  275. package/runtime/__test__/element-template/runtime/background/event/compiled-fixtures.test.tsx +867 -0
  276. package/runtime/__test__/element-template/runtime/background/global-props/compiled-fixtures.test.tsx +220 -0
  277. package/runtime/__test__/element-template/runtime/background/global-props.test.tsx +173 -0
  278. package/runtime/__test__/element-template/runtime/background/hydrate/compiled-fixtures.test.ts +43 -0
  279. package/runtime/__test__/element-template/runtime/background/hydrate/fixtures.test.ts +16 -0
  280. package/runtime/__test__/element-template/runtime/background/hydrate.test.ts +2179 -0
  281. package/runtime/__test__/element-template/runtime/background/init-data/compiled-fixtures.test.tsx +129 -0
  282. package/runtime/__test__/element-template/runtime/background/instance/fixtures.test.ts +16 -0
  283. package/runtime/__test__/element-template/runtime/background/instance.test.ts +2751 -0
  284. package/runtime/__test__/element-template/runtime/background/main-thread-function/compiled-fixtures.test.tsx +287 -0
  285. package/runtime/__test__/element-template/runtime/background/manager.test.ts +142 -0
  286. package/runtime/__test__/element-template/runtime/background/page-root-hydrate.test.ts +75 -0
  287. package/runtime/__test__/element-template/runtime/background/ref/compiled-fixtures.test.tsx +339 -0
  288. package/runtime/__test__/element-template/runtime/background/reload.test.ts +79 -0
  289. package/runtime/__test__/element-template/runtime/background/render/fixtures.test.ts +16 -0
  290. package/runtime/__test__/element-template/runtime/background/render/preact.test.tsx +268 -0
  291. package/runtime/__test__/element-template/runtime/background/root-render.test.tsx +265 -0
  292. package/runtime/__test__/element-template/runtime/background/suspense.test.tsx +940 -0
  293. package/runtime/__test__/element-template/runtime/background/update/compiled-fixtures.test.tsx +277 -0
  294. package/runtime/__test__/element-template/runtime/background/update/sparse-fixtures.test.tsx +163 -0
  295. package/runtime/__test__/element-template/runtime/background/update-timing.test.ts +127 -0
  296. package/runtime/__test__/element-template/runtime/hydration/fixtures.test.ts +16 -0
  297. package/runtime/__test__/element-template/runtime/hydration/hydration-listener.test.ts +1249 -0
  298. package/runtime/__test__/element-template/runtime/page/authored-page.test.ts +35 -0
  299. package/runtime/__test__/element-template/runtime/page/compiled-fixtures.test.tsx +560 -0
  300. package/runtime/__test__/element-template/runtime/page/fixtures.test.ts +16 -0
  301. package/runtime/__test__/element-template/runtime/page/page.test.ts +25 -0
  302. package/runtime/__test__/element-template/runtime/page/root-instance.test.ts +25 -0
  303. package/runtime/__test__/element-template/runtime/patch/compiled-fixtures.test.ts +40 -0
  304. package/runtime/__test__/element-template/runtime/patch/element-template-patch.test.tsx +3704 -0
  305. package/runtime/__test__/element-template/runtime/patch/fixtures.test.ts +16 -0
  306. package/runtime/__test__/element-template/runtime/patch/patch-listener-alog.test.ts +80 -0
  307. package/runtime/__test__/element-template/runtime/patch/update-fixture-helper.test.tsx +40 -0
  308. package/runtime/__test__/element-template/runtime/patch/update-timing.test.ts +203 -0
  309. package/runtime/__test__/element-template/runtime/prop-adapters/event.test.ts +183 -0
  310. package/runtime/__test__/element-template/runtime/prop-adapters/hydrate.test.ts +246 -0
  311. package/runtime/__test__/element-template/runtime/prop-adapters/ref.test.ts +155 -0
  312. package/runtime/__test__/element-template/runtime/prop-adapters/spread.test.ts +160 -0
  313. package/runtime/__test__/element-template/runtime/protocol/template-type.test.ts +40 -0
  314. package/runtime/__test__/element-template/runtime/render/fixtures.test.ts +18 -0
  315. package/runtime/__test__/element-template/runtime/render/render-main-thread.contract.test.ts +143 -0
  316. package/runtime/__test__/element-template/runtime/render/render-main-thread.test.ts +377 -0
  317. package/runtime/__test__/element-template/runtime/render/render-opcodes-into-element-template.et.test.tsx +791 -0
  318. package/runtime/__test__/element-template/runtime/render/render-to-opcodes.et.test.jsx +522 -0
  319. package/runtime/__test__/element-template/runtime/render/render-transform.contract.test.ts +564 -0
  320. package/runtime/__test__/element-template/runtime/template/element-template-attr-slot-plan.test.ts +373 -0
  321. package/runtime/__test__/element-template/runtime/template/element-template-handle.test.ts +228 -0
  322. package/runtime/__test__/element-template/runtime/template/element-template-registry.test.ts +65 -0
  323. package/runtime/__test__/element-template/runtime/template/main-thread-dynamic-attr-state.test.ts +567 -0
  324. package/runtime/__test__/element-template/runtime/template/main-thread-function.test.ts +280 -0
  325. package/runtime/__test__/element-template/test-utils/debug/compiledFixtureApp.ts +26 -0
  326. package/runtime/__test__/element-template/test-utils/debug/compiledFixtureCompiler.ts +76 -0
  327. package/runtime/__test__/element-template/test-utils/debug/compiledFixtureModule.ts +74 -0
  328. package/runtime/__test__/element-template/test-utils/debug/compiledFixtureRegistry.ts +22 -0
  329. package/runtime/__test__/element-template/test-utils/debug/compiledHydrationScenario.ts +82 -0
  330. package/runtime/__test__/element-template/test-utils/debug/compiledThreadRunner.ts +70 -0
  331. package/runtime/__test__/element-template/test-utils/debug/envManager.ts +96 -0
  332. package/runtime/__test__/element-template/test-utils/debug/fixtureRunner.ts +284 -0
  333. package/runtime/__test__/element-template/test-utils/debug/hydrate.ts +23 -0
  334. package/runtime/__test__/element-template/test-utils/debug/registry.ts +43 -0
  335. package/runtime/__test__/element-template/test-utils/debug/renderFixtureRunner.ts +337 -0
  336. package/runtime/__test__/element-template/test-utils/debug/serializer.ts +79 -0
  337. package/runtime/__test__/element-template/test-utils/debug/updateRunner.test.tsx +148 -0
  338. package/runtime/__test__/element-template/test-utils/debug/updateRunner.ts +303 -0
  339. package/runtime/__test__/element-template/test-utils/mock/globals.js +35 -0
  340. package/runtime/__test__/element-template/test-utils/mock/jscontext-mock.test.ts +142 -0
  341. package/runtime/__test__/element-template/test-utils/mock/mockNativePapi/context.ts +305 -0
  342. package/runtime/__test__/element-template/test-utils/mock/mockNativePapi/templateTree.test.ts +187 -0
  343. package/runtime/__test__/element-template/test-utils/mock/mockNativePapi/templateTree.ts +745 -0
  344. package/runtime/__test__/element-template/test-utils/mock/mockNativePapi.ts +432 -0
  345. package/runtime/__test__/element-template/test-utils/mock/performance.js +68 -0
  346. package/runtime/__test__/element-template/test-utils/setup.js +100 -0
  347. package/runtime/__test__/element-template/vitest.config.ts +128 -0
  348. package/runtime/__test__/guardrails/snapshot-containment.test.ts +198 -0
  349. package/runtime/__test__/shared/profile.test.ts +88 -0
  350. package/runtime/__test__/snapshot/alog/elementPAPICall.test.js +50 -0
  351. package/runtime/__test__/snapshot/attribute-name.test.ts +78 -0
  352. package/runtime/__test__/snapshot/basic.test.jsx +718 -0
  353. package/runtime/__test__/snapshot/children.test.jsx +476 -0
  354. package/runtime/__test__/snapshot/clone.test.jsx +959 -0
  355. package/runtime/__test__/snapshot/commit-context.test.ts +29 -0
  356. package/runtime/__test__/snapshot/compat/export.test.jsx +42 -0
  357. package/runtime/__test__/snapshot/compat/hooks.test.jsx +45 -0
  358. package/runtime/__test__/snapshot/compat/initData.test.jsx +195 -0
  359. package/runtime/__test__/snapshot/compat/use-insertion-effect.test.jsx +128 -0
  360. package/runtime/__test__/snapshot/compat/use.test.jsx +111 -0
  361. package/runtime/__test__/snapshot/compat.test.jsx +199 -0
  362. package/runtime/__test__/snapshot/createElement.test.jsx +1352 -0
  363. package/runtime/__test__/snapshot/createSuspender.jsx +26 -0
  364. package/runtime/__test__/snapshot/css/compat.test.jsx +164 -0
  365. package/runtime/__test__/snapshot/css/remove-scoped-lazy-bundle.test.jsx +40 -0
  366. package/runtime/__test__/snapshot/css/remove-scoped-main-bundle.test.jsx +27 -0
  367. package/runtime/__test__/snapshot/css/scoped-lazy-bundle.test.jsx +45 -0
  368. package/runtime/__test__/snapshot/css/scoped-main-bundle.test.jsx +36 -0
  369. package/runtime/__test__/snapshot/debug/backgroundSnapshot-profile.test.jsx +366 -0
  370. package/runtime/__test__/snapshot/debug/children-with-same-key.test.jsx +43 -0
  371. package/runtime/__test__/snapshot/debug/describeInvalidValue.test.ts +32 -0
  372. package/runtime/__test__/snapshot/debug/formatPatch.test.ts +89 -0
  373. package/runtime/__test__/snapshot/debug/hooks-in-render.test.jsx +13 -0
  374. package/runtime/__test__/snapshot/debug/hooks-invalid-args.test.jsx +42 -0
  375. package/runtime/__test__/snapshot/debug/jsx-twice.test.jsx +55 -0
  376. package/runtime/__test__/snapshot/debug/missing-suspense.test.jsx +35 -0
  377. package/runtime/__test__/snapshot/debug/object-as-child.test.jsx +35 -0
  378. package/runtime/__test__/snapshot/debug/printSnapshot.test.jsx +155 -0
  379. package/runtime/__test__/snapshot/debug/profile.test.jsx +348 -0
  380. package/runtime/__test__/snapshot/debug/react-hooks-profile.test.jsx +285 -0
  381. package/runtime/__test__/snapshot/debug/set-state-in-ctor.test.jsx +40 -0
  382. package/runtime/__test__/snapshot/debug/too-many-rerenders.test.jsx +33 -0
  383. package/runtime/__test__/snapshot/debug/undefined-component.test.jsx +40 -0
  384. package/runtime/__test__/snapshot/debug/vnodeSource.test.ts +120 -0
  385. package/runtime/__test__/snapshot/delayed-lifecycle-events.test.jsx +62 -0
  386. package/runtime/__test__/snapshot/dynamicPartType.test.jsx +690 -0
  387. package/runtime/__test__/snapshot/element.test.jsx +46 -0
  388. package/runtime/__test__/snapshot/event.test.jsx +1294 -0
  389. package/runtime/__test__/snapshot/gesture/prepareGestureForCommit.test.js +86 -0
  390. package/runtime/__test__/snapshot/gesture/processGesture.test.ts +326 -0
  391. package/runtime/__test__/snapshot/gesture.test.jsx +1446 -0
  392. package/runtime/__test__/snapshot/hydrate.test.jsx +372 -0
  393. package/runtime/__test__/snapshot/jsx-runtime-lepus.test.jsx +89 -0
  394. package/runtime/__test__/snapshot/lazy.test.js +203 -0
  395. package/runtime/__test__/snapshot/legacySlot.legacy-slot.test.jsx +437 -0
  396. package/runtime/__test__/snapshot/lifecycle/commitHook.test.jsx +112 -0
  397. package/runtime/__test__/snapshot/lifecycle/destroy.test.jsx +47 -0
  398. package/runtime/__test__/snapshot/lifecycle/emptyPatch.test.jsx +104 -0
  399. package/runtime/__test__/snapshot/lifecycle/isRendering.test.jsx +114 -0
  400. package/runtime/__test__/snapshot/lifecycle/reload.test.jsx +1908 -0
  401. package/runtime/__test__/snapshot/lifecycle/reloadBG.jsx +79 -0
  402. package/runtime/__test__/snapshot/lifecycle/reloadMT.jsx +76 -0
  403. package/runtime/__test__/snapshot/lifecycle/resetPageDataError.test.jsx +79 -0
  404. package/runtime/__test__/snapshot/lifecycle/updateData.test.jsx +1688 -0
  405. package/runtime/__test__/snapshot/lifecycle/updateGlobalProps.event.test.jsx +226 -0
  406. package/runtime/__test__/snapshot/lifecycle/updateGlobalProps.test.jsx +382 -0
  407. package/runtime/__test__/snapshot/lifecycle.test.jsx +675 -0
  408. package/runtime/__test__/snapshot/list.test.jsx +4956 -0
  409. package/runtime/__test__/snapshot/lynx/component-compat.test.ts +188 -0
  410. package/runtime/__test__/snapshot/lynx/dynamic-import.test.ts +111 -0
  411. package/runtime/__test__/snapshot/lynx/injectLepusMethods.test.jsx +81 -0
  412. package/runtime/__test__/snapshot/lynx/lazy-bundle-fetchbundle.test.js +659 -0
  413. package/runtime/__test__/snapshot/lynx/lazy-bundle.test.js +576 -0
  414. package/runtime/__test__/snapshot/lynx/portals.test.jsx +677 -0
  415. package/runtime/__test__/snapshot/lynx/prepareLazyBundleMTS.test.js +212 -0
  416. package/runtime/__test__/snapshot/lynx/processEvalResult.test.js +23 -0
  417. package/runtime/__test__/snapshot/lynx/runtime-backend.test.ts +81 -0
  418. package/runtime/__test__/snapshot/lynx/suspense.test.jsx +1641 -0
  419. package/runtime/__test__/snapshot/lynx/timing.test.jsx +1011 -0
  420. package/runtime/__test__/snapshot/lynx-data-processors.test.ts +3 -0
  421. package/runtime/__test__/snapshot/lynxQueueMicrotask.test.jsx +38 -0
  422. package/runtime/__test__/snapshot/mtf-execid-churn.test.jsx +216 -0
  423. package/runtime/__test__/snapshot/page.test.jsx +417 -0
  424. package/runtime/__test__/snapshot/preact.test.jsx +930 -0
  425. package/runtime/__test__/snapshot/ref-parity.test.jsx +78 -0
  426. package/runtime/__test__/snapshot/ref.test.jsx +2368 -0
  427. package/runtime/__test__/snapshot/render.test.jsx +148 -0
  428. package/runtime/__test__/snapshot/renderToOpcodes.test.jsx +1618 -0
  429. package/runtime/__test__/snapshot/snapshotPatch.test.jsx +1798 -0
  430. package/runtime/__test__/snapshot/spread.test.jsx +771 -0
  431. package/runtime/__test__/snapshot/ssr.test.jsx +574 -0
  432. package/runtime/__test__/snapshot/use-main-thread.test.jsx +141 -0
  433. package/runtime/__test__/snapshot/utils/debug.js +41 -0
  434. package/runtime/__test__/snapshot/utils/envManager.ts +109 -0
  435. package/runtime/__test__/snapshot/utils/globals.js +224 -0
  436. package/runtime/__test__/snapshot/utils/inject.ts +31 -0
  437. package/runtime/__test__/snapshot/utils/jsModule.ts +49 -0
  438. package/runtime/__test__/snapshot/utils/nativeMethod.ts +498 -0
  439. package/runtime/__test__/snapshot/utils/runtimeProxy.test.js +36 -0
  440. package/runtime/__test__/snapshot/utils/runtimeProxy.ts +73 -0
  441. package/runtime/__test__/snapshot/utils/setup.js +72 -0
  442. package/runtime/__test__/snapshot/worklet/onPost.test.js +30 -0
  443. package/runtime/__test__/snapshot/worklet/runOnBackground.test.js +234 -0
  444. package/runtime/__test__/snapshot/worklet/runOnMainThread.test.jsx +402 -0
  445. package/runtime/__test__/snapshot/worklet/transform.test.js +35 -0
  446. package/runtime/__test__/snapshot/worklet/workletRef.test.jsx +292 -0
  447. package/runtime/__test__/snapshot/workletEvent.test.jsx +1286 -0
  448. package/runtime/__test__/snapshot/workletLifecycle.test.ts +198 -0
  449. package/runtime/__test__/snapshot/workletRef.test.jsx +831 -0
  450. package/runtime/__test__/snapshot/workletRefBG.jsx +95 -0
  451. package/runtime/__test__/snapshot/workletRefMT.jsx +99 -0
  452. package/runtime/__test__/test-utils/lynx-event-emitter.ts +63 -0
  453. package/runtime/__test__/tsconfig.json +9 -0
  454. package/runtime/__test__/worklet-runtime/api/element.test.js +274 -0
  455. package/runtime/__test__/worklet-runtime/delayWorkletEvent.test.js +89 -0
  456. package/runtime/__test__/worklet-runtime/eventPropagation.test.js +89 -0
  457. package/runtime/__test__/worklet-runtime/jsFunctionLifecycle.test.js +89 -0
  458. package/runtime/__test__/worklet-runtime/mainThreadFlushLoopGuard.test.js +235 -0
  459. package/runtime/__test__/worklet-runtime/observers.test.js +119 -0
  460. package/runtime/__test__/worklet-runtime/profile.test.js +27 -0
  461. package/runtime/__test__/worklet-runtime/runOnBackground.test.js +186 -0
  462. package/runtime/__test__/worklet-runtime/runOnMainThread.test.js +66 -0
  463. package/runtime/__test__/worklet-runtime/workletRef.test.js +328 -0
  464. package/runtime/__test__/worklet-runtime/workletRuntime.test.js +534 -0
  465. package/runtime/compat/index.d.ts +48 -1
  466. package/runtime/compat/index.js +7 -3
  467. package/runtime/lazy/compat.js +2 -0
  468. package/runtime/lazy/element-template-internal.js +35 -0
  469. package/runtime/lazy/element-template-jsx-dev-runtime.js +19 -0
  470. package/runtime/lazy/element-template-jsx-runtime.js +14 -0
  471. package/runtime/lazy/element-template.js +53 -0
  472. package/runtime/lazy/internal.js +2 -1
  473. package/runtime/lepus/index.js +2 -2
  474. package/runtime/lepus/jsx-runtime/index.js +3 -8
  475. package/runtime/lib/core/component.js +3 -3
  476. package/runtime/lib/core/component.js.map +1 -1
  477. package/runtime/lib/core/forceRootRender.js +3 -2
  478. package/runtime/lib/core/forceRootRender.js.map +1 -1
  479. package/runtime/lib/core/globalProps.js +1 -1
  480. package/runtime/lib/core/globalProps.js.map +1 -1
  481. package/runtime/lib/core/hooks/mainThreadImpl.js +2 -0
  482. package/runtime/lib/core/hooks/mainThreadImpl.js.map +1 -1
  483. package/runtime/lib/core/hooks/useLynxGlobalEventListener.js +1 -1
  484. package/runtime/lib/core/hooks/useLynxGlobalEventListener.js.map +1 -1
  485. package/runtime/lib/core/lynx/lazy-bundle.js +1 -1
  486. package/runtime/lib/core/lynx/lazy-bundle.js.map +1 -1
  487. package/runtime/lib/core/main-thread-ref.js +1 -1
  488. package/runtime/lib/core/main-thread-ref.js.map +1 -1
  489. package/runtime/lib/core/ref.d.ts +7 -5
  490. package/runtime/lib/core/ref.js +22 -11
  491. package/runtime/lib/core/ref.js.map +1 -1
  492. package/runtime/lib/element-template/background/attr-slots.d.ts +5 -1
  493. package/runtime/lib/element-template/background/attr-slots.js +17 -6
  494. package/runtime/lib/element-template/background/attr-slots.js.map +1 -1
  495. package/runtime/lib/element-template/background/commit-context.d.ts +1 -1
  496. package/runtime/lib/element-template/background/commit-context.js +8 -9
  497. package/runtime/lib/element-template/background/commit-context.js.map +1 -1
  498. package/runtime/lib/element-template/background/commit-hook.js +60 -51
  499. package/runtime/lib/element-template/background/commit-hook.js.map +1 -1
  500. package/runtime/lib/element-template/background/destroy.js +4 -1
  501. package/runtime/lib/element-template/background/destroy.js.map +1 -1
  502. package/runtime/lib/element-template/background/hydrate.js +34 -38
  503. package/runtime/lib/element-template/background/hydrate.js.map +1 -1
  504. package/runtime/lib/element-template/background/hydration-listener.js +18 -10
  505. package/runtime/lib/element-template/background/hydration-listener.js.map +1 -1
  506. package/runtime/lib/element-template/background/instance.d.ts +7 -5
  507. package/runtime/lib/element-template/background/instance.js +79 -38
  508. package/runtime/lib/element-template/background/instance.js.map +1 -1
  509. package/runtime/lib/element-template/background/page-root-hydrate.js +1 -1
  510. package/runtime/lib/element-template/background/page-root-hydrate.js.map +1 -1
  511. package/runtime/lib/element-template/debug/alog.d.ts +10 -4
  512. package/runtime/lib/element-template/debug/alog.js +22 -9
  513. package/runtime/lib/element-template/debug/alog.js.map +1 -1
  514. package/runtime/lib/element-template/debug/profile.js +2 -2
  515. package/runtime/lib/element-template/debug/profile.js.map +1 -1
  516. package/runtime/lib/element-template/internal.d.ts +1 -0
  517. package/runtime/lib/element-template/internal.js +1 -0
  518. package/runtime/lib/element-template/internal.js.map +1 -1
  519. package/runtime/lib/element-template/jsx-runtime/index.d.ts +3 -1
  520. package/runtime/lib/element-template/jsx-runtime/index.js +2 -4
  521. package/runtime/lib/element-template/jsx-runtime/index.js.map +1 -1
  522. package/runtime/lib/element-template/lynx/env.js +1 -2
  523. package/runtime/lib/element-template/lynx/env.js.map +1 -1
  524. package/runtime/lib/element-template/native/callDestroyLifetimeFun.js +2 -0
  525. package/runtime/lib/element-template/native/callDestroyLifetimeFun.js.map +1 -1
  526. package/runtime/lib/element-template/native/index.js +9 -7
  527. package/runtime/lib/element-template/native/index.js.map +1 -1
  528. package/runtime/lib/element-template/native/main-thread-api.js +3 -3
  529. package/runtime/lib/element-template/native/main-thread-api.js.map +1 -1
  530. package/runtime/lib/element-template/native/patch-listener.js +15 -7
  531. package/runtime/lib/element-template/native/patch-listener.js.map +1 -1
  532. package/runtime/lib/element-template/native/reload-main-thread.js +21 -3
  533. package/runtime/lib/element-template/native/reload-main-thread.js.map +1 -1
  534. package/runtime/lib/element-template/prop-adapters/ref.d.ts +3 -1
  535. package/runtime/lib/element-template/prop-adapters/ref.js +2 -2
  536. package/runtime/lib/element-template/prop-adapters/ref.js.map +1 -1
  537. package/runtime/lib/element-template/prop-adapters/spread.js +1 -4
  538. package/runtime/lib/element-template/prop-adapters/spread.js.map +1 -1
  539. package/runtime/lib/element-template/protocol/opcodes.d.ts +2 -0
  540. package/runtime/lib/element-template/protocol/opcodes.js +2 -0
  541. package/runtime/lib/element-template/protocol/opcodes.js.map +1 -1
  542. package/runtime/lib/element-template/protocol/types.d.ts +45 -22
  543. package/runtime/lib/element-template/runtime/list/list.d.ts +5 -5
  544. package/runtime/lib/element-template/runtime/list/list.js +8 -7
  545. package/runtime/lib/element-template/runtime/list/list.js.map +1 -1
  546. package/runtime/lib/element-template/runtime/page/authored-page.js +17 -2
  547. package/runtime/lib/element-template/runtime/page/authored-page.js.map +1 -1
  548. package/runtime/lib/element-template/runtime/page/page.d.ts +3 -3
  549. package/runtime/lib/element-template/runtime/page/page.js +1 -1
  550. package/runtime/lib/element-template/runtime/page/page.js.map +1 -1
  551. package/runtime/lib/element-template/runtime/patch.js +78 -50
  552. package/runtime/lib/element-template/runtime/patch.js.map +1 -1
  553. package/runtime/lib/element-template/runtime/render/render-main-thread.js +7 -5
  554. package/runtime/lib/element-template/runtime/render/render-main-thread.js.map +1 -1
  555. package/runtime/lib/element-template/runtime/render/render-opcodes.d.ts +3 -1
  556. package/runtime/lib/element-template/runtime/render/render-opcodes.js +47 -38
  557. package/runtime/lib/element-template/runtime/render/render-opcodes.js.map +1 -1
  558. package/runtime/lib/element-template/runtime/render/render-to-opcodes.js +19 -17
  559. package/runtime/lib/element-template/runtime/render/render-to-opcodes.js.map +1 -1
  560. package/runtime/lib/element-template/runtime/template/attr-slot-plan.d.ts +3 -0
  561. package/runtime/lib/element-template/runtime/template/attr-slot-plan.js +39 -0
  562. package/runtime/lib/element-template/runtime/template/attr-slot-plan.js.map +1 -1
  563. package/runtime/lib/element-template/runtime/template/handle.d.ts +5 -3
  564. package/runtime/lib/element-template/runtime/template/handle.js +14 -6
  565. package/runtime/lib/element-template/runtime/template/handle.js.map +1 -1
  566. package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.d.ts +16 -7
  567. package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js +133 -55
  568. package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js.map +1 -1
  569. package/runtime/lib/element-template/runtime/template/main-thread-ref-ctx.d.ts +4 -0
  570. package/runtime/lib/element-template/runtime/template/main-thread-ref-ctx.js +30 -1
  571. package/runtime/lib/element-template/runtime/template/main-thread-ref-ctx.js.map +1 -1
  572. package/runtime/lib/element-template/runtime/template/registry.d.ts +6 -6
  573. package/runtime/lib/element-template/runtime/template/registry.js.map +1 -1
  574. package/runtime/lib/internal.d.ts +1 -1
  575. package/runtime/lib/internal.js +1 -1
  576. package/runtime/lib/internal.js.map +1 -1
  577. package/runtime/lib/shared/attribute-name.js +1 -2
  578. package/runtime/lib/shared/attribute-name.js.map +1 -1
  579. package/runtime/lib/shared/component-stack.js +2 -1
  580. package/runtime/lib/shared/component-stack.js.map +1 -1
  581. package/runtime/lib/shared/render-constants.d.ts +4 -2
  582. package/runtime/lib/shared/render-constants.js +6 -2
  583. package/runtime/lib/shared/render-constants.js.map +1 -1
  584. package/runtime/lib/snapshot/alog/render.js +1 -0
  585. package/runtime/lib/snapshot/alog/render.js.map +1 -1
  586. package/runtime/lib/snapshot/debug/profileHooks.js +2 -2
  587. package/runtime/lib/snapshot/debug/profileHooks.js.map +1 -1
  588. package/runtime/lib/snapshot/debug/vnodeSource.js +1 -0
  589. package/runtime/lib/snapshot/debug/vnodeSource.js.map +1 -1
  590. package/runtime/lib/snapshot/lifecycle/destroy.js +5 -2
  591. package/runtime/lib/snapshot/lifecycle/destroy.js.map +1 -1
  592. package/runtime/lib/snapshot/lifecycle/patch/commit.js +1 -0
  593. package/runtime/lib/snapshot/lifecycle/patch/commit.js.map +1 -1
  594. package/runtime/lib/snapshot/lynx/children.js +1 -2
  595. package/runtime/lib/snapshot/lynx/children.js.map +1 -1
  596. package/runtime/lib/snapshot/lynx/env.js +1 -1
  597. package/runtime/lib/snapshot/lynx/env.js.map +1 -1
  598. package/runtime/lib/snapshot/lynx/suspense.js +1 -1
  599. package/runtime/lib/snapshot/lynx/suspense.js.map +1 -1
  600. package/runtime/lib/snapshot/lynx/tt.js +5 -5
  601. package/runtime/lib/snapshot/lynx/tt.js.map +1 -1
  602. package/runtime/lib/snapshot/renderToOpcodes/index.js +12 -13
  603. package/runtime/lib/snapshot/renderToOpcodes/index.js.map +1 -1
  604. package/runtime/lib/snapshot/snapshot/backgroundSnapshot.d.ts +1 -0
  605. package/runtime/lib/snapshot/snapshot/backgroundSnapshot.js +23 -25
  606. package/runtime/lib/snapshot/snapshot/backgroundSnapshot.js.map +1 -1
  607. package/runtime/lib/snapshot/snapshot/platformInfo.js +1 -3
  608. package/runtime/lib/snapshot/snapshot/platformInfo.js.map +1 -1
  609. package/runtime/lib/snapshot/snapshot/ref.d.ts +3 -2
  610. package/runtime/lib/snapshot/snapshot/ref.js +4 -7
  611. package/runtime/lib/snapshot/snapshot/ref.js.map +1 -1
  612. package/runtime/lib/snapshot/snapshot/snapshot.d.ts +1 -0
  613. package/runtime/lib/snapshot/snapshot/snapshot.js +5 -0
  614. package/runtime/lib/snapshot/snapshot/snapshot.js.map +1 -1
  615. package/runtime/lib/snapshot/snapshot/spread.js +2 -8
  616. package/runtime/lib/snapshot/snapshot/spread.js.map +1 -1
  617. package/runtime/lib/tsconfig.tsbuildinfo +1 -1
  618. package/runtime/lib/utils.d.ts +9 -0
  619. package/runtime/lib/utils.js +27 -0
  620. package/runtime/lib/utils.js.map +1 -1
  621. package/runtime/lib/worklet-runtime/bindings/bindings.d.ts +5 -1
  622. package/runtime/lib/worklet-runtime/bindings/bindings.js +7 -1
  623. package/runtime/lib/worklet-runtime/bindings/bindings.js.map +1 -1
  624. package/runtime/lib/worklet-runtime/bindings/observers.js +2 -1
  625. package/runtime/lib/worklet-runtime/bindings/observers.js.map +1 -1
  626. package/runtime/package.json +37 -0
  627. package/runtime/src/core/background-function/exec-map.ts +44 -0
  628. package/runtime/src/core/background-function/handle.ts +31 -0
  629. package/runtime/src/core/background-function/run-on-background.ts +151 -0
  630. package/runtime/src/core/commit-context.ts +26 -0
  631. package/runtime/src/core/compat/legacy-react-runtime.ts +39 -0
  632. package/runtime/src/core/compat/lynxComponent.ts +91 -0
  633. package/runtime/src/core/component.ts +152 -0
  634. package/runtime/src/core/forceRootRender.ts +52 -0
  635. package/runtime/src/core/globalProps.ts +111 -0
  636. package/runtime/src/core/hooks/mainThread.ts +9 -0
  637. package/runtime/src/core/hooks/mainThreadImpl.ts +226 -0
  638. package/runtime/src/core/hooks/react.ts +172 -0
  639. package/runtime/src/core/hooks/useLynxGlobalEventListener.ts +59 -0
  640. package/runtime/src/core/initData.ts +191 -0
  641. package/runtime/src/core/lynx/dynamic-import.ts +37 -0
  642. package/runtime/src/core/lynx/lazy-bundle.ts +352 -0
  643. package/runtime/src/core/lynx/runtime-backend.ts +30 -0
  644. package/runtime/src/core/lynx-data-processors.ts +85 -0
  645. package/runtime/src/core/lynx-page-data.ts +22 -0
  646. package/runtime/src/core/lynx-update-data.ts +47 -0
  647. package/runtime/src/core/main-thread-function.ts +12 -0
  648. package/runtime/src/core/main-thread-ref-init-value.ts +29 -0
  649. package/runtime/src/core/main-thread-ref.ts +225 -0
  650. package/runtime/src/core/mts-capability.ts +21 -0
  651. package/runtime/src/core/performance.ts +186 -0
  652. package/runtime/src/core/ref.ts +181 -0
  653. package/runtime/src/core/reload-version.ts +13 -0
  654. package/runtime/src/core/runtime-destroy.ts +22 -0
  655. package/runtime/src/core/thread-function-call/main-thread.ts +81 -0
  656. package/runtime/src/core/thread-function-call/return-value.ts +77 -0
  657. package/runtime/src/document.ts +86 -0
  658. package/runtime/src/element-template/background/attr-slots.ts +132 -0
  659. package/runtime/src/element-template/background/commit-context.ts +47 -0
  660. package/runtime/src/element-template/background/commit-hook.ts +211 -0
  661. package/runtime/src/element-template/background/destroy.ts +34 -0
  662. package/runtime/src/element-template/background/document.ts +41 -0
  663. package/runtime/src/element-template/background/hydrate.ts +605 -0
  664. package/runtime/src/element-template/background/hydration-listener.ts +198 -0
  665. package/runtime/src/element-template/background/instance.ts +820 -0
  666. package/runtime/src/element-template/background/manager.ts +89 -0
  667. package/runtime/src/element-template/background/page-root-hydrate.ts +23 -0
  668. package/runtime/src/element-template/background/render-scope.ts +52 -0
  669. package/runtime/src/element-template/client/root.ts +71 -0
  670. package/runtime/src/element-template/debug/alog.ts +238 -0
  671. package/runtime/src/element-template/debug/elementPAPICall.ts +89 -0
  672. package/runtime/src/element-template/debug/profile.ts +194 -0
  673. package/runtime/src/element-template/hydration-map.ts +13 -0
  674. package/runtime/src/element-template/index.ts +138 -0
  675. package/runtime/src/element-template/internal.ts +69 -0
  676. package/runtime/src/element-template/jsx-dev-runtime/index.ts +4 -0
  677. package/runtime/src/element-template/jsx-runtime/index.ts +86 -0
  678. package/runtime/src/element-template/lynx/env.ts +59 -0
  679. package/runtime/src/element-template/lynx/performance.ts +20 -0
  680. package/runtime/src/element-template/native/callDestroyLifetimeFun.ts +10 -0
  681. package/runtime/src/element-template/native/index.ts +92 -0
  682. package/runtime/src/element-template/native/main-thread-api.ts +55 -0
  683. package/runtime/src/element-template/native/mts-destroy.ts +46 -0
  684. package/runtime/src/element-template/native/patch-listener.ts +136 -0
  685. package/runtime/src/element-template/native/reload-background.ts +43 -0
  686. package/runtime/src/element-template/native/reload-main-thread.ts +76 -0
  687. package/runtime/src/element-template/prop-adapters/event-value.ts +11 -0
  688. package/runtime/src/element-template/prop-adapters/event.ts +87 -0
  689. package/runtime/src/element-template/prop-adapters/ref.ts +148 -0
  690. package/runtime/src/element-template/prop-adapters/spread.ts +66 -0
  691. package/runtime/src/element-template/protocol/lifecycle-constant.ts +8 -0
  692. package/runtime/src/element-template/protocol/opcodes.ts +18 -0
  693. package/runtime/src/element-template/protocol/page.ts +7 -0
  694. package/runtime/src/element-template/protocol/template-type.ts +56 -0
  695. package/runtime/src/element-template/protocol/types.ts +229 -0
  696. package/runtime/src/element-template/protocol/update-event.ts +46 -0
  697. package/runtime/src/element-template/runtime/list/list.ts +829 -0
  698. package/runtime/src/element-template/runtime/page/authored-page.ts +53 -0
  699. package/runtime/src/element-template/runtime/page/page.ts +21 -0
  700. package/runtime/src/element-template/runtime/page/root-instance.ts +25 -0
  701. package/runtime/src/element-template/runtime/patch.ts +517 -0
  702. package/runtime/src/element-template/runtime/render/render-main-thread.ts +81 -0
  703. package/runtime/src/element-template/runtime/render/render-opcodes.ts +313 -0
  704. package/runtime/src/element-template/runtime/render/render-to-opcodes.ts +411 -0
  705. package/runtime/src/element-template/runtime/template/attr-slot-plan.ts +153 -0
  706. package/runtime/src/element-template/runtime/template/handle.ts +95 -0
  707. package/runtime/src/element-template/runtime/template/main-thread-background-function.ts +48 -0
  708. package/runtime/src/element-template/runtime/template/main-thread-dynamic-attr-state.ts +242 -0
  709. package/runtime/src/element-template/runtime/template/main-thread-event-ctx.ts +46 -0
  710. package/runtime/src/element-template/runtime/template/main-thread-function.ts +32 -0
  711. package/runtime/src/element-template/runtime/template/main-thread-ref-ctx.ts +95 -0
  712. package/runtime/src/element-template/runtime/template/registry.ts +72 -0
  713. package/runtime/src/element-template/runtime/template/typed-attributes.ts +25 -0
  714. package/runtime/src/element-template/runtime-backend-marker.ts +7 -0
  715. package/runtime/src/element-template/types.d.ts +128 -0
  716. package/runtime/src/index.ts +95 -0
  717. package/runtime/src/internal.ts +102 -0
  718. package/runtime/src/lynx-api.ts +563 -0
  719. package/runtime/src/lynx.ts +93 -0
  720. package/runtime/src/root.ts +38 -0
  721. package/runtime/src/runtime-backend-marker.ts +7 -0
  722. package/runtime/src/shared/attribute-name.ts +109 -0
  723. package/runtime/src/shared/component-stack.ts +168 -0
  724. package/runtime/src/shared/index-map.ts +26 -0
  725. package/runtime/src/shared/profile.ts +36 -0
  726. package/runtime/src/shared/render-constants.ts +42 -0
  727. package/runtime/src/snapshot/alog/elementPAPICall.ts +132 -0
  728. package/runtime/src/snapshot/alog/index.ts +8 -0
  729. package/runtime/src/snapshot/alog/render.ts +33 -0
  730. package/runtime/src/snapshot/compat/componentIs.ts +30 -0
  731. package/runtime/src/snapshot/debug/debug.ts +9 -0
  732. package/runtime/src/snapshot/debug/describeInvalidValue.ts +25 -0
  733. package/runtime/src/snapshot/debug/formatPatch.ts +28 -0
  734. package/runtime/src/snapshot/debug/printSnapshot.ts +63 -0
  735. package/runtime/src/snapshot/debug/profileHooks.ts +271 -0
  736. package/runtime/src/snapshot/debug/vnodeSource.ts +82 -0
  737. package/runtime/src/snapshot/gesture/processGesture.ts +274 -0
  738. package/runtime/src/snapshot/gesture/processGestureBagkround.ts +94 -0
  739. package/runtime/src/snapshot/gesture/types.ts +46 -0
  740. package/runtime/src/snapshot/index.ts +5 -0
  741. package/runtime/src/snapshot/lifecycle/constant.ts +29 -0
  742. package/runtime/src/snapshot/lifecycle/destroy.ts +38 -0
  743. package/runtime/src/snapshot/lifecycle/event/delayEvents.ts +11 -0
  744. package/runtime/src/snapshot/lifecycle/event/delayLifecycleEvents.ts +15 -0
  745. package/runtime/src/snapshot/lifecycle/event/firstScreenSync.ts +97 -0
  746. package/runtime/src/snapshot/lifecycle/isRendering.ts +27 -0
  747. package/runtime/src/snapshot/lifecycle/patch/commit.ts +278 -0
  748. package/runtime/src/snapshot/lifecycle/patch/error.ts +66 -0
  749. package/runtime/src/snapshot/lifecycle/patch/globalState.ts +16 -0
  750. package/runtime/src/snapshot/lifecycle/patch/isMainThreadHydrating.ts +13 -0
  751. package/runtime/src/snapshot/lifecycle/patch/nodesRefApply.ts +119 -0
  752. package/runtime/src/snapshot/lifecycle/patch/snapshotPatch.ts +97 -0
  753. package/runtime/src/snapshot/lifecycle/patch/snapshotPatchApply.ts +170 -0
  754. package/runtime/src/snapshot/lifecycle/patch/updateMainThread.ts +115 -0
  755. package/runtime/src/snapshot/lifecycle/ref/delay.ts +82 -0
  756. package/runtime/src/snapshot/lifecycle/reload.ts +95 -0
  757. package/runtime/src/snapshot/lifecycle/render.ts +36 -0
  758. package/runtime/src/snapshot/list/list.ts +320 -0
  759. package/runtime/src/snapshot/list/listUpdateInfo.ts +265 -0
  760. package/runtime/src/snapshot/list/pendingListUpdates.ts +44 -0
  761. package/runtime/src/snapshot/lynx/calledByNative.ts +180 -0
  762. package/runtime/src/snapshot/lynx/children.ts +40 -0
  763. package/runtime/src/snapshot/lynx/element.ts +217 -0
  764. package/runtime/src/snapshot/lynx/env.ts +58 -0
  765. package/runtime/src/snapshot/lynx/injectLepusMethods.ts +53 -0
  766. package/runtime/src/snapshot/lynx/lazyBundleConstants.ts +9 -0
  767. package/runtime/src/snapshot/lynx/nodesRef.ts +47 -0
  768. package/runtime/src/snapshot/lynx/performance.ts +20 -0
  769. package/runtime/src/snapshot/lynx/portals.ts +203 -0
  770. package/runtime/src/snapshot/lynx/portalsPending.ts +62 -0
  771. package/runtime/src/snapshot/lynx/prepareLazyBundleMTS.ts +68 -0
  772. package/runtime/src/snapshot/lynx/runWithForce.ts +18 -0
  773. package/runtime/src/snapshot/lynx/suspense.ts +58 -0
  774. package/runtime/src/snapshot/lynx/tt.ts +281 -0
  775. package/runtime/src/snapshot/renderToOpcodes/hydrate.ts +465 -0
  776. package/runtime/src/snapshot/renderToOpcodes/index.ts +445 -0
  777. package/runtime/src/snapshot/renderToOpcodes/opcodes.ts +155 -0
  778. package/runtime/src/snapshot/snapshot/backgroundSnapshot.ts +822 -0
  779. package/runtime/src/snapshot/snapshot/constants.ts +27 -0
  780. package/runtime/src/snapshot/snapshot/definition.ts +258 -0
  781. package/runtime/src/snapshot/snapshot/dynamicPartType.ts +40 -0
  782. package/runtime/src/snapshot/snapshot/event.ts +33 -0
  783. package/runtime/src/snapshot/snapshot/gesture.ts +31 -0
  784. package/runtime/src/snapshot/snapshot/index.ts +8 -0
  785. package/runtime/src/snapshot/snapshot/list.ts +66 -0
  786. package/runtime/src/snapshot/snapshot/platformInfo.ts +109 -0
  787. package/runtime/src/snapshot/snapshot/reconstructInstanceTree.ts +46 -0
  788. package/runtime/src/snapshot/snapshot/ref.ts +116 -0
  789. package/runtime/src/snapshot/snapshot/snapshot.ts +627 -0
  790. package/runtime/src/snapshot/snapshot/snapshotCreatorMap.ts +33 -0
  791. package/runtime/src/snapshot/snapshot/snapshotInstanceHydrationMap.ts +17 -0
  792. package/runtime/src/snapshot/snapshot/snapshotInstanceManager.ts +22 -0
  793. package/runtime/src/snapshot/snapshot/spread.ts +378 -0
  794. package/runtime/src/snapshot/snapshot/types.ts +29 -0
  795. package/runtime/src/snapshot/snapshot/utils.ts +59 -0
  796. package/runtime/src/snapshot/snapshot/workletEvent.ts +73 -0
  797. package/runtime/src/snapshot/snapshot/workletRef.ts +97 -0
  798. package/runtime/src/snapshot/worklet/call/runOnMainThread.ts +37 -0
  799. package/runtime/src/snapshot/worklet/ctx.ts +22 -0
  800. package/runtime/src/snapshot/worklet/destroy.ts +14 -0
  801. package/runtime/src/snapshot/worklet/functionality.ts +22 -0
  802. package/runtime/src/snapshot/worklet/hmr.ts +34 -0
  803. package/runtime/src/snapshot/worklet/ref/updateInitValue.ts +30 -0
  804. package/runtime/src/utils.ts +134 -0
  805. package/runtime/src/worklet-runtime/api/animation/animation.ts +48 -0
  806. package/runtime/src/worklet-runtime/api/animation/effect.ts +20 -0
  807. package/runtime/src/worklet-runtime/api/element.ts +152 -0
  808. package/runtime/src/worklet-runtime/api/lepusQuerySelector.ts +34 -0
  809. package/runtime/src/worklet-runtime/api/lynxApi.ts +42 -0
  810. package/runtime/src/worklet-runtime/bindings/bindings.ts +91 -0
  811. package/runtime/src/worklet-runtime/bindings/events.ts +29 -0
  812. package/runtime/src/worklet-runtime/bindings/index.ts +12 -0
  813. package/runtime/src/worklet-runtime/bindings/loadRuntime.ts +25 -0
  814. package/runtime/src/worklet-runtime/bindings/observers.ts +61 -0
  815. package/runtime/src/worklet-runtime/bindings/types.ts +84 -0
  816. package/runtime/src/worklet-runtime/delayRunOnBackground.ts +51 -0
  817. package/runtime/src/worklet-runtime/delayWorkletEvent.ts +70 -0
  818. package/runtime/src/worklet-runtime/eomImpl.ts +14 -0
  819. package/runtime/src/worklet-runtime/eventPropagation.ts +56 -0
  820. package/runtime/src/worklet-runtime/global.ts +28 -0
  821. package/runtime/src/worklet-runtime/hydrate.ts +113 -0
  822. package/runtime/src/worklet-runtime/index.ts +12 -0
  823. package/runtime/src/worklet-runtime/jsFunctionLifecycle.ts +69 -0
  824. package/runtime/src/worklet-runtime/listeners.ts +28 -0
  825. package/runtime/src/worklet-runtime/runOnMainThread.ts +21 -0
  826. package/runtime/src/worklet-runtime/types/dev.d.ts +4 -0
  827. package/runtime/src/worklet-runtime/types/elementApi.d.ts +97 -0
  828. package/runtime/src/worklet-runtime/types/runtimeProxy.d.ts +32 -0
  829. package/runtime/src/worklet-runtime/types/systeminfo.d.ts +19 -0
  830. package/runtime/src/worklet-runtime/utils/mainThreadFlushLoopGuard.ts +87 -0
  831. package/runtime/src/worklet-runtime/utils/profile.ts +20 -0
  832. package/runtime/src/worklet-runtime/utils/version.ts +11 -0
  833. package/runtime/src/worklet-runtime/workletRef.ts +119 -0
  834. package/runtime/src/worklet-runtime/workletRuntime.ts +215 -0
  835. package/runtime/tsconfig.json +30 -0
  836. package/runtime/turbo.json +21 -0
  837. package/runtime/types/internal-preact.d.ts +67 -0
  838. package/runtime/types/types.d.ts +339 -0
  839. package/runtime/vitest.config.ts +181 -0
  840. package/runtime/worklet-runtime/dev.js +1 -1
  841. package/testing-library/.npmignore +6 -0
  842. package/testing-library/.turbo/turbo-build.log +28 -0
  843. package/testing-library/README.md +109 -0
  844. package/testing-library/dist/env/index.js +1 -2
  845. package/testing-library/dist/index.d.ts +1 -1
  846. package/testing-library/dist/rstest-config.d.ts +15 -1
  847. package/testing-library/dist/rstest-config.js +38 -5
  848. package/testing-library/dist/setupFiles/common/runtime-setup.js +3 -3
  849. package/testing-library/etc/react-lynx-testing-library.api.md +71 -0
  850. package/testing-library/loaders/jsx-loader.js +49 -0
  851. package/testing-library/node_modules/.bin/rsbuild +55 -0
  852. package/testing-library/node_modules/.bin/rspeedy +55 -0
  853. package/testing-library/node_modules/.bin/rstest +55 -0
  854. package/testing-library/package.json +28 -0
  855. package/testing-library/rslib.config.ts +97 -0
  856. package/testing-library/rstest.config.ts +44 -0
  857. package/testing-library/src/__tests__/3.1/text.test.jsx +109 -0
  858. package/testing-library/src/__tests__/act.test.jsx +348 -0
  859. package/testing-library/src/__tests__/alog.test.jsx +813 -0
  860. package/testing-library/src/__tests__/auto-cleanup-skip.test.jsx +25 -0
  861. package/testing-library/src/__tests__/auto-cleanup.test.jsx +12 -0
  862. package/testing-library/src/__tests__/background-only.test.jsx +45 -0
  863. package/testing-library/src/__tests__/button.test.jsx +25 -0
  864. package/testing-library/src/__tests__/cleanup.test.jsx +29 -0
  865. package/testing-library/src/__tests__/css/index.test.jsx +47 -0
  866. package/testing-library/src/__tests__/css/style1.css +3 -0
  867. package/testing-library/src/__tests__/css/style2.css +3 -0
  868. package/testing-library/src/__tests__/css/style3.module.css +3 -0
  869. package/testing-library/src/__tests__/dom-reuse.test.jsx +1515 -0
  870. package/testing-library/src/__tests__/end-to-end.test.jsx +212 -0
  871. package/testing-library/src/__tests__/events.test.jsx +368 -0
  872. package/testing-library/src/__tests__/lazy-bundle/LazyComponent.jsx +4 -0
  873. package/testing-library/src/__tests__/lazy-bundle/index.test.jsx +598 -0
  874. package/testing-library/src/__tests__/list.test.jsx +1015 -0
  875. package/testing-library/src/__tests__/lynx.test.jsx +85 -0
  876. package/testing-library/src/__tests__/portals.test.jsx +1303 -0
  877. package/testing-library/src/__tests__/preact-signals.test.jsx +190 -0
  878. package/testing-library/src/__tests__/raw-text.test.jsx +59 -0
  879. package/testing-library/src/__tests__/ref.test.jsx +573 -0
  880. package/testing-library/src/__tests__/remove-element.test.jsx +68 -0
  881. package/testing-library/src/__tests__/render.test.jsx +296 -0
  882. package/testing-library/src/__tests__/renderComponent.test.jsx +344 -0
  883. package/testing-library/src/__tests__/renderHook.test.jsx +61 -0
  884. package/testing-library/src/__tests__/rerender.test.jsx +62 -0
  885. package/testing-library/src/__tests__/rstest-config.test.js +31 -0
  886. package/testing-library/src/__tests__/slot-jsx.test.jsx +965 -0
  887. package/testing-library/src/__tests__/spread.test.jsx +212 -0
  888. package/testing-library/src/__tests__/stopwatch.test.jsx +80 -0
  889. package/testing-library/src/__tests__/text.test.jsx +130 -0
  890. package/testing-library/src/__tests__/worklet.test.jsx +618 -0
  891. package/testing-library/src/entry.ts +2 -0
  892. package/testing-library/src/env/index.ts +2 -0
  893. package/testing-library/src/env/rstest.ts +7 -0
  894. package/testing-library/src/env/vitest.ts +27 -0
  895. package/testing-library/src/fire-event.ts +199 -0
  896. package/testing-library/src/index.jsx +25 -0
  897. package/testing-library/src/plugins/index.ts +2 -0
  898. package/testing-library/src/plugins/vitest.ts +387 -0
  899. package/testing-library/src/pure.jsx +159 -0
  900. package/testing-library/src/rstest-config.ts +173 -0
  901. package/testing-library/src/setupFiles/common/bootstrap.js +6 -0
  902. package/testing-library/src/setupFiles/common/runtime-setup.js +142 -0
  903. package/testing-library/src/setupFiles/inner/rstest.js +13 -0
  904. package/testing-library/src/setupFiles/inner/vitest.js +17 -0
  905. package/testing-library/src/setupFiles/rstest.js +30 -0
  906. package/testing-library/src/setupFiles/vitest.js +29 -0
  907. package/testing-library/src/vitest.config.ts +14 -0
  908. package/testing-library/tsconfig.json +16 -0
  909. package/testing-library/turbo.json +21 -0
  910. package/testing-library/types/entry.d.ts +1 -1
  911. package/testing-library/vitest-polyfill.cjs +6 -0
  912. package/testing-library/vitest.3.1.config.ts +17 -0
  913. package/testing-library/vitest.config.ts +14 -0
  914. package/transform/.cargo/config.toml +2 -0
  915. package/transform/.gitignore +6 -0
  916. package/transform/.npmignore +8 -0
  917. package/transform/.turbo/turbo-build$colon$wasm.log +252 -0
  918. package/transform/Cargo.toml +45 -0
  919. package/transform/__test__/background-only.spec.js +222 -0
  920. package/transform/__test__/basic.bench.js +80 -0
  921. package/transform/__test__/css/__snapshots__/transform-all-css-scoped-all.js +18 -0
  922. package/transform/__test__/css/__snapshots__/transform-all-css-scoped-modules.js +18 -0
  923. package/transform/__test__/css/__snapshots__/transform-all-css-scoped-none.js +18 -0
  924. package/transform/__test__/css/__snapshots__/transform-imports-css-scoped-all.js +24 -0
  925. package/transform/__test__/css/__snapshots__/transform-imports-css-scoped-modules.js +24 -0
  926. package/transform/__test__/css/__snapshots__/transform-imports-css-scoped-none.js +24 -0
  927. package/transform/__test__/css/__snapshots__/transform-imports-defaults.js +5 -0
  928. package/transform/__test__/css/__snapshots__/transform-imports-without-jsx-css-scoped-all.js +5 -0
  929. package/transform/__test__/css/__snapshots__/transform-imports-without-jsx-css-scoped-modules.js +5 -0
  930. package/transform/__test__/css/__snapshots__/transform-imports-without-jsx-css-scoped-none.js +5 -0
  931. package/transform/__test__/css/__snapshots__/transform-jsx-css-scoped-all-lazy-bundle.js +50 -0
  932. package/transform/__test__/css/__snapshots__/transform-jsx-css-scoped-all.js +50 -0
  933. package/transform/__test__/css/__snapshots__/transform-jsx-css-scoped-modules-lazy-bundle.js +50 -0
  934. package/transform/__test__/css/__snapshots__/transform-jsx-css-scoped-modules.js +50 -0
  935. package/transform/__test__/css/__snapshots__/transform-jsx-css-scoped-none-lazy-bundle.js +50 -0
  936. package/transform/__test__/css/__snapshots__/transform-jsx-css-scoped-none.js +50 -0
  937. package/transform/__test__/css/__snapshots__/transform-jsx-defaults.js +50 -0
  938. package/transform/__test__/css/css-scope.spec.js +209 -0
  939. package/transform/__test__/css/inline-style.spec.js +53 -0
  940. package/transform/__test__/css/object-lit-style.spec.js +293 -0
  941. package/transform/__test__/defines.spec.js +321 -0
  942. package/transform/__test__/fixture.spec.js +2496 -0
  943. package/transform/__test__/typescript.spec.js +97 -0
  944. package/transform/build.rs +11 -0
  945. package/transform/crates/swc_plugin_background_only/Cargo.toml +13 -0
  946. package/transform/crates/swc_plugin_background_only/lib.rs +326 -0
  947. package/transform/crates/swc_plugin_background_only/tests/__swc_snapshots__/lib.rs/defaults_to_null_without_fallback.js +5 -0
  948. package/transform/crates/swc_plugin_background_only/tests/__swc_snapshots__/lib.rs/desugars_nested_background_only.js +5 -0
  949. package/transform/crates/swc_plugin_background_only/tests/__swc_snapshots__/lib.rs/desugars_to_thread_conditional_in_child_position.js +8 -0
  950. package/transform/crates/swc_plugin_background_only/tests/__swc_snapshots__/lib.rs/desugars_to_thread_conditional_in_expression_position.js +3 -0
  951. package/transform/crates/swc_plugin_background_only/tests/__swc_snapshots__/lib.rs/keeps_the_fragment_for_a_lone_text_child.js +3 -0
  952. package/transform/crates/swc_plugin_background_only/tests/__swc_snapshots__/lib.rs/renders_nothing_for_empty_children.js +5 -0
  953. package/transform/crates/swc_plugin_background_only/tests/__swc_snapshots__/lib.rs/unwraps_a_lone_child_past_layout_and_comments.js +3 -0
  954. package/transform/crates/swc_plugin_compat/Cargo.toml +24 -0
  955. package/transform/crates/swc_plugin_compat/is_component_class.rs +51 -0
  956. package/transform/crates/swc_plugin_compat/lib.rs +1885 -0
  957. package/transform/crates/swc_plugin_compat/napi.rs +526 -0
  958. package/transform/crates/swc_plugin_compat/simplify_ctor_like_react_lynx_2.rs +172 -0
  959. package/transform/crates/swc_plugin_compat/tests/__swc_snapshots__/lib.rs/should_add_component_element.js +17 -0
  960. package/transform/crates/swc_plugin_compat/tests/__swc_snapshots__/lib.rs/should_add_component_element_compiler_only.js +16 -0
  961. package/transform/crates/swc_plugin_compat/tests/__swc_snapshots__/lib.rs/should_add_component_element_embedded.js +2 -0
  962. package/transform/crates/swc_plugin_compat/tests/__swc_snapshots__/lib.rs/should_add_component_element_embedded_compiler_only.js +1 -0
  963. package/transform/crates/swc_plugin_compat/tests/__swc_snapshots__/lib.rs/should_add_component_is_import.js +3 -0
  964. package/transform/crates/swc_plugin_compat/tests/__swc_snapshots__/lib.rs/should_change_runtime_pkg.js +1 -0
  965. package/transform/crates/swc_plugin_compat/tests/__swc_snapshots__/lib.rs/should_handle_recursive.js +4 -0
  966. package/transform/crates/swc_plugin_compat/tests/__swc_snapshots__/lib.rs/should_left_no_remove_component_element_attr.js +1 -0
  967. package/transform/crates/swc_plugin_compat/tests/__swc_snapshots__/lib.rs/should_not_handle_jsx_member_expression.js +1 -0
  968. package/transform/crates/swc_plugin_compat/tests/__swc_snapshots__/lib.rs/should_not_rename_view_in_scope.js +6 -0
  969. package/transform/crates/swc_plugin_compat/tests/__swc_snapshots__/lib.rs/should_not_rename_view_redeclaration.js +4 -0
  970. package/transform/crates/swc_plugin_compat/tests/__swc_snapshots__/lib.rs/should_not_transform_event_props_when_disabled.js +1 -0
  971. package/transform/crates/swc_plugin_compat/tests/__swc_snapshots__/lib.rs/should_remove_component_attr_regex.js +8 -0
  972. package/transform/crates/swc_plugin_compat/tests/__swc_snapshots__/lib.rs/should_rename_view.js +1 -0
  973. package/transform/crates/swc_plugin_compat/tests/__swc_snapshots__/lib.rs/should_simplify_ctor.js +9 -0
  974. package/transform/crates/swc_plugin_compat/tests/__swc_snapshots__/lib.rs/should_simplify_ctor_correct_order.js +10 -0
  975. package/transform/crates/swc_plugin_compat/tests/__swc_snapshots__/lib.rs/should_simplify_ctor_not_remain_local_decls.js +9 -0
  976. package/transform/crates/swc_plugin_compat/tests/__swc_snapshots__/lib.rs/should_simplify_ctor_not_remain_local_decls_with_macro.js +19 -0
  977. package/transform/crates/swc_plugin_compat/tests/__swc_snapshots__/lib.rs/should_simplify_ctor_not_remain_local_decls_with_spread.js +12 -0
  978. package/transform/crates/swc_plugin_compat/tests/__swc_snapshots__/lib.rs/should_transform_event_props_1.js +1 -0
  979. package/transform/crates/swc_plugin_compat/tests/__swc_snapshots__/lib.rs/should_transform_event_props_2.js +1 -0
  980. package/transform/crates/swc_plugin_css_scope/Cargo.toml +18 -0
  981. package/transform/crates/swc_plugin_css_scope/lib.rs +327 -0
  982. package/transform/crates/swc_plugin_css_scope/napi.rs +144 -0
  983. package/transform/crates/swc_plugin_css_scope/tests/__swc_snapshots__/lib.rs/scoped_all_transform_imports.js +5 -0
  984. package/transform/crates/swc_plugin_css_scope/tests/__swc_snapshots__/lib.rs/scoped_all_transform_imports_without_jsx.js +4 -0
  985. package/transform/crates/swc_plugin_css_scope/tests/__swc_snapshots__/lib.rs/scoped_modules_transform_imports.js +5 -0
  986. package/transform/crates/swc_plugin_css_scope/tests/__swc_snapshots__/lib.rs/scoped_modules_transform_imports_without_jsx.js +4 -0
  987. package/transform/crates/swc_plugin_css_scope/tests/__swc_snapshots__/lib.rs/scoped_none_transform_imports.js +5 -0
  988. package/transform/crates/swc_plugin_css_scope/tests/__swc_snapshots__/lib.rs/scoped_none_transform_imports_without_jsx.js +4 -0
  989. package/transform/crates/swc_plugin_define_dce/Cargo.toml +15 -0
  990. package/transform/crates/swc_plugin_define_dce/lib.rs +21 -0
  991. package/transform/crates/swc_plugin_define_dce/napi.rs +79 -0
  992. package/transform/crates/swc_plugin_directive_dce/Cargo.toml +18 -0
  993. package/transform/crates/swc_plugin_directive_dce/lib.rs +489 -0
  994. package/transform/crates/swc_plugin_directive_dce/napi.rs +65 -0
  995. package/transform/crates/swc_plugin_directive_dce/tests/__swc_snapshots__/lib.rs/should_do_nothing_in_mixed_target.js +6 -0
  996. package/transform/crates/swc_plugin_directive_dce/tests/__swc_snapshots__/lib.rs/should_do_nothing_when_arrow_function_return_directive.js +1 -0
  997. package/transform/crates/swc_plugin_directive_dce/tests/__swc_snapshots__/lib.rs/should_eliminate_async_arrow_with_background_only_directive.js +1 -0
  998. package/transform/crates/swc_plugin_directive_dce/tests/__swc_snapshots__/lib.rs/should_eliminate_background_only_generator_forms.js +7 -0
  999. package/transform/crates/swc_plugin_directive_dce/tests/__swc_snapshots__/lib.rs/should_eliminate_fn_body_in_component_props.js +1 -0
  1000. package/transform/crates/swc_plugin_directive_dce/tests/__swc_snapshots__/lib.rs/should_eliminate_fn_decl.js +1 -0
  1001. package/transform/crates/swc_plugin_directive_dce/tests/__swc_snapshots__/lib.rs/should_eliminate_js_only_but_keep_constructor.js +6 -0
  1002. package/transform/crates/swc_plugin_directive_dce/tests/__swc_snapshots__/lib.rs/should_eliminate_js_only_class_method.js +4 -0
  1003. package/transform/crates/swc_plugin_directive_dce/tests/__swc_snapshots__/lib.rs/should_eliminate_js_only_class_property.js +4 -0
  1004. package/transform/crates/swc_plugin_directive_dce/tests/__swc_snapshots__/lib.rs/should_eliminate_js_only_embedded.js +5 -0
  1005. package/transform/crates/swc_plugin_directive_dce/tests/__swc_snapshots__/lib.rs/should_eliminate_native_modules_in_default_params.js +1 -0
  1006. package/transform/crates/swc_plugin_directive_dce/tests/__swc_snapshots__/lib.rs/should_eliminate_transpiled_async_arrow_with_background_only_generator.js +1 -0
  1007. package/transform/crates/swc_plugin_dynamic_import/Cargo.toml +18 -0
  1008. package/transform/crates/swc_plugin_dynamic_import/lib.rs +408 -0
  1009. package/transform/crates/swc_plugin_dynamic_import/napi.rs +89 -0
  1010. package/transform/crates/swc_plugin_dynamic_import/tests/__swc_snapshots__/lib.rs/should_import_lazy_bundle.js +4 -0
  1011. package/transform/crates/swc_plugin_dynamic_import/tests/__swc_snapshots__/lib.rs/should_import_lazy_import.js +9 -0
  1012. package/transform/crates/swc_plugin_dynamic_import/tests/__swc_snapshots__/lib.rs/should_not_import_lazy.js +3 -0
  1013. package/transform/crates/swc_plugin_dynamic_import/tests/__swc_snapshots__/lib.rs/should_transform_import_call.js +61 -0
  1014. package/transform/crates/swc_plugin_element_template/Cargo.toml +29 -0
  1015. package/transform/crates/swc_plugin_element_template/asset.rs +64 -0
  1016. package/transform/crates/swc_plugin_element_template/attr_name.rs +77 -0
  1017. package/transform/crates/swc_plugin_element_template/extractor.rs +484 -0
  1018. package/transform/crates/swc_plugin_element_template/lib.rs +734 -0
  1019. package/transform/crates/swc_plugin_element_template/lowering.rs +125 -0
  1020. package/transform/crates/swc_plugin_element_template/napi.rs +168 -0
  1021. package/transform/crates/swc_plugin_element_template/template_attribute.rs +31 -0
  1022. package/transform/crates/swc_plugin_element_template/template_definition.rs +375 -0
  1023. package/transform/crates/swc_plugin_element_template/template_identity.rs +160 -0
  1024. package/transform/crates/swc_plugin_element_template/template_slot.rs +81 -0
  1025. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_generate_attribute_slots_for_dynamic_attributes.snap +81 -0
  1026. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_background_conditional_attributes.snap +44 -0
  1027. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_boolean_and_number_attributes.snap +62 -0
  1028. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_complex_text_structure.snap +120 -0
  1029. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_dataset_attributes.snap +62 -0
  1030. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_deeply_nested_user_components.snap +54 -0
  1031. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_dynamic_class_attributes.snap +57 -0
  1032. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_events_js.snap +57 -0
  1033. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_events_lepus.snap +57 -0
  1034. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_id_attributes.snap +57 -0
  1035. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_inline_styles.snap +82 -0
  1036. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_interpolated_text_with_siblings_js.snap +85 -0
  1037. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_interpolated_text_with_siblings_lepus.snap +85 -0
  1038. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_mixed_content.snap +82 -0
  1039. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_nested_structure_and_dynamic_content.snap +143 -0
  1040. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_refs_js.snap +52 -0
  1041. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_refs_lepus.snap +52 -0
  1042. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_sibling_user_components.snap +69 -0
  1043. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_spread_attributes.snap +56 -0
  1044. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_user_component.snap +54 -0
  1045. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_isolate_arrays_with_child_slot_placeholder.snap +56 -0
  1046. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_keep_code_and_template_attribute_slots_in_sync_for_spread.snap +66 -0
  1047. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_output_element_template_simple_lepus.snap +52 -0
  1048. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_output_template_with_static_attributes.snap +62 -0
  1049. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_verify_template_structure_complex.snap +69 -0
  1050. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_verify_text_attribute_and_child_text_slots.snap +70 -0
  1051. package/transform/crates/swc_plugin_element_template/tests/element_template.rs +1207 -0
  1052. package/transform/crates/swc_plugin_element_template/tests/element_template_contract.rs +930 -0
  1053. package/transform/crates/swc_plugin_inject/Cargo.toml +18 -0
  1054. package/transform/crates/swc_plugin_inject/lib.rs +344 -0
  1055. package/transform/crates/swc_plugin_inject/napi.rs +150 -0
  1056. package/transform/crates/swc_plugin_inject/tests/__swc_snapshots__/lib.rs/should_inject.js +8 -0
  1057. package/transform/crates/swc_plugin_inject/tests/__swc_snapshots__/lib.rs/should_inject_callee.js +1 -0
  1058. package/transform/crates/swc_plugin_list/Cargo.toml +15 -0
  1059. package/transform/crates/swc_plugin_list/legacy_slot.rs +410 -0
  1060. package/transform/crates/swc_plugin_list/lib.rs +631 -0
  1061. package/transform/crates/swc_plugin_list/tests/__swc_snapshots__/legacy_slot.rs/basic_list_legacy_slot.js +61 -0
  1062. package/transform/crates/swc_plugin_list/tests/__swc_snapshots__/legacy_slot.rs/basic_list_toplevel_legacy_slot.js +40 -0
  1063. package/transform/crates/swc_plugin_list/tests/__swc_snapshots__/legacy_slot.rs/basic_list_with_fragment_legacy_slot.js +65 -0
  1064. package/transform/crates/swc_plugin_list/tests/__swc_snapshots__/legacy_slot.rs/should_transform_list_in_view_legacy_slot.js +6 -0
  1065. package/transform/crates/swc_plugin_list/tests/__swc_snapshots__/legacy_slot.rs/should_transform_list_in_view_with_snapshot_legacy_slot.js +49 -0
  1066. package/transform/crates/swc_plugin_list/tests/__swc_snapshots__/legacy_slot.rs/should_transform_list_item_deferred_in_list_legacy_slot.js +5 -0
  1067. package/transform/crates/swc_plugin_list/tests/__swc_snapshots__/legacy_slot.rs/should_transform_list_item_deferred_with_children_with_snapshot_legacy_slot.js +95 -0
  1068. package/transform/crates/swc_plugin_list/tests/__swc_snapshots__/lib.rs/basic_list.js +53 -0
  1069. package/transform/crates/swc_plugin_list/tests/__swc_snapshots__/lib.rs/basic_list_toplevel.js +40 -0
  1070. package/transform/crates/swc_plugin_list/tests/__swc_snapshots__/lib.rs/basic_list_with_fragment.js +57 -0
  1071. package/transform/crates/swc_plugin_list/tests/__swc_snapshots__/lib.rs/should_not_transform_list_item_with_defer_false.js +1 -0
  1072. package/transform/crates/swc_plugin_list/tests/__swc_snapshots__/lib.rs/should_transform_list_in_view.js +6 -0
  1073. package/transform/crates/swc_plugin_list/tests/__swc_snapshots__/lib.rs/should_transform_list_in_view_with_snapshot.js +54 -0
  1074. package/transform/crates/swc_plugin_list/tests/__swc_snapshots__/lib.rs/should_transform_list_in_view_with_static_sibling.js +7 -0
  1075. package/transform/crates/swc_plugin_list/tests/__swc_snapshots__/lib.rs/should_transform_list_in_view_with_static_sibling_nested.js +16 -0
  1076. package/transform/crates/swc_plugin_list/tests/__swc_snapshots__/lib.rs/should_transform_list_in_view_with_static_sibling_with_snapshot.js +65 -0
  1077. package/transform/crates/swc_plugin_list/tests/__swc_snapshots__/lib.rs/should_transform_list_in_view_with_static_sibling_with_snapshot_nested.js +138 -0
  1078. package/transform/crates/swc_plugin_list/tests/__swc_snapshots__/lib.rs/should_transform_list_item_deferred_basic.js +2 -0
  1079. package/transform/crates/swc_plugin_list/tests/__swc_snapshots__/lib.rs/should_transform_list_item_deferred_in_list.js +5 -0
  1080. package/transform/crates/swc_plugin_list/tests/__swc_snapshots__/lib.rs/should_transform_list_item_deferred_with_children.js +6 -0
  1081. package/transform/crates/swc_plugin_list/tests/__swc_snapshots__/lib.rs/should_transform_list_item_deferred_with_children_with_snapshot.js +95 -0
  1082. package/transform/crates/swc_plugin_list/tests/__swc_snapshots__/lib.rs/should_transform_list_item_not_deferred.js +1 -0
  1083. package/transform/crates/swc_plugin_list/tests/__swc_snapshots__/lib.rs/should_transform_list_item_when_defer_is_expr.js +4 -0
  1084. package/transform/crates/swc_plugin_list/tests/__swc_snapshots__/lib.rs/should_transform_list_item_with_spread_deferred.js +2 -0
  1085. package/transform/crates/swc_plugin_shake/Cargo.toml +20 -0
  1086. package/transform/crates/swc_plugin_shake/is_component_class.rs +66 -0
  1087. package/transform/crates/swc_plugin_shake/lib.rs +908 -0
  1088. package/transform/crates/swc_plugin_shake/napi.rs +220 -0
  1089. package/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/only_shake_class_like_react_component_class.js +10 -0
  1090. package/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_keep_access_inside_class_property_iife.js +11 -0
  1091. package/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_keep_constructor_and_used.js +12 -0
  1092. package/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_keep_indirect.js +12 -0
  1093. package/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_keep_render_and_used.js +11 -0
  1094. package/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_keep_state_and_remove_other.js +8 -0
  1095. package/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_keep_use_effect_call_from_custom_runtime.js +6 -0
  1096. package/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_keep_with_nested_class.js +11 -0
  1097. package/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_not_remove_call_in_scope_id.js +5 -0
  1098. package/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_not_remove_in_scope_id.js +5 -0
  1099. package/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_not_remove_test_with_other_runtime.js +3 -0
  1100. package/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_remove_aliased_use_effect_call.js +4 -0
  1101. package/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_remove_aliased_use_effect_call_by_local_name.js +4 -0
  1102. package/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_remove_aliased_use_effect_param.js +4 -0
  1103. package/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_remove_aliased_use_effect_param_by_local_name.js +4 -0
  1104. package/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_remove_default_and_namespace_runtime_import_calls.js +6 -0
  1105. package/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_remove_default_and_namespace_runtime_import_params.js +6 -0
  1106. package/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_remove_test.js +5 -0
  1107. package/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_remove_unused_indirect.js +5 -0
  1108. package/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_remove_use_effect_call.js +8 -0
  1109. package/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_remove_use_effect_param.js +8 -0
  1110. package/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_replace_use_effect_call_with_undefined.js +2 -0
  1111. package/transform/crates/swc_plugin_snapshot/Cargo.toml +25 -0
  1112. package/transform/crates/swc_plugin_snapshot/attr_name.rs +84 -0
  1113. package/transform/crates/swc_plugin_snapshot/legacy_slot.rs +2201 -0
  1114. package/transform/crates/swc_plugin_snapshot/lib.rs +3495 -0
  1115. package/transform/crates/swc_plugin_snapshot/napi.rs +184 -0
  1116. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/legacy_slot.rs/basic_component_legacy_slot.js +10 -0
  1117. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/legacy_slot.rs/basic_component_with_static_sibling_jsx_dev_legacy_slot.js +35 -0
  1118. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/legacy_slot.rs/basic_component_with_static_sibling_jsx_legacy_slot.js +27 -0
  1119. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/legacy_slot.rs/basic_component_with_static_sibling_legacy_slot.js +24 -0
  1120. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/legacy_slot.rs/basic_expr_container_legacy_slot.js +10 -0
  1121. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/legacy_slot.rs/basic_expr_container_with_static_sibling_legacy_slot.js +24 -0
  1122. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/legacy_slot.rs/basic_spread_list_item_legacy_slot.js +42 -0
  1123. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/legacy_slot.rs/full_static_children_map_jsx_legacy_slot.js +44 -0
  1124. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/legacy_slot.rs/page_component_legacy_slot.js +15 -0
  1125. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/legacy_slot.rs/page_element_dev_legacy_slot.js +16 -0
  1126. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/legacy_slot.rs/page_element_legacy_slot.js +16 -0
  1127. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/legacy_slot.rs/should_create_raw_text_node_for_text_node_legacy_slot.js +55 -0
  1128. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/legacy_slot.rs/should_emit_list_item_platform_info_marker_for_spread_props_legacy_slot.js +32 -0
  1129. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/legacy_slot.rs/should_inject_implicit_flatten_legacy_slot.js +67 -0
  1130. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/legacy_slot.rs/should_not_wrap_dynamic_part.js +29 -0
  1131. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/legacy_slot.rs/should_wrap_dynamic_key_legacy_slot.js +54 -0
  1132. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/legacy_slot.rs/should_wrap_dynamic_part.js +34 -0
  1133. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/basic_component.js +10 -0
  1134. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/basic_component_with_static_sibling.js +24 -0
  1135. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/basic_component_with_static_sibling_jsx.js +27 -0
  1136. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/basic_component_with_static_sibling_jsx_dev.js +35 -0
  1137. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/basic_event.js +26 -0
  1138. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/basic_expr_container.js +10 -0
  1139. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/basic_expr_container_with_static_sibling.js +24 -0
  1140. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/basic_full_static.js +25 -0
  1141. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/basic_full_static_snapshot_extract.js +16 -0
  1142. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/basic_full_static_snapshot_extract_it.js +21 -0
  1143. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/basic_ref.js +45 -0
  1144. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/basic_spread.js +30 -0
  1145. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/basic_spread_list_item.js +30 -0
  1146. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/basic_timing_flag.js +31 -0
  1147. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/empty_module.js +1 -0
  1148. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/external_bundle_uses_card_entry_name.js +16 -0
  1149. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/full_static_children_comments.js +19 -0
  1150. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/full_static_children_map_jsx.js +28 -0
  1151. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/full_static_children_new_line.js +25 -0
  1152. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/full_static_children_self_close.js +25 -0
  1153. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/gesture.js +26 -0
  1154. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/inline_style_literal.js +11 -0
  1155. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/inline_style_literal_unknown_property.js +11 -0
  1156. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/mode_development_spread.js +24 -0
  1157. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/page_component.js +15 -0
  1158. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/page_element.js +16 -0
  1159. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/page_element_dev.js +16 -0
  1160. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/should_create_raw_text_node_for_text_node.js +47 -0
  1161. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/should_emit_list_item_platform_info_marker_for_non_zero_value_index.js +25 -0
  1162. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/should_emit_list_item_platform_info_marker_for_spread_props.js +22 -0
  1163. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/should_escape_newline_character.js +55 -0
  1164. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/should_extract_css_id.js +71 -0
  1165. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/should_extract_css_id_dynamic_component.js +71 -0
  1166. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/should_extract_css_id_dynamic_component_without_css_id.js +69 -0
  1167. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/should_extract_css_id_without_css_id.js +69 -0
  1168. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/should_inject_implicit_flatten.js +59 -0
  1169. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/should_set_attribute_for_text_node.js +44 -0
  1170. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/should_static_extract_dynamic_inline_style.js +69 -0
  1171. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/should_static_extract_inline_style.js +21 -0
  1172. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/should_wrap_dynamic_key.js +46 -0
  1173. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/worklet.js +35 -0
  1174. package/transform/crates/swc_plugin_text/Cargo.toml +14 -0
  1175. package/transform/crates/swc_plugin_text/lib.rs +93 -0
  1176. package/transform/crates/swc_plugin_text/tests/__swc_snapshots__/lib.rs/should_keep_children_for_dynamic_or_multiple_text.js +9 -0
  1177. package/transform/crates/swc_plugin_text/tests/__swc_snapshots__/lib.rs/should_transform_single_static_text_to_text_attr.js +8 -0
  1178. package/transform/crates/swc_plugin_worklet/Cargo.toml +24 -0
  1179. package/transform/crates/swc_plugin_worklet/decl_collect.rs +226 -0
  1180. package/transform/crates/swc_plugin_worklet/extract_ident.rs +460 -0
  1181. package/transform/crates/swc_plugin_worklet/gen_stmt.rs +326 -0
  1182. package/transform/crates/swc_plugin_worklet/globals.rs +104 -0
  1183. package/transform/crates/swc_plugin_worklet/hash.rs +29 -0
  1184. package/transform/crates/swc_plugin_worklet/lib.rs +2869 -0
  1185. package/transform/crates/swc_plugin_worklet/napi.rs +116 -0
  1186. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/class_in_worklet_1.js +3 -0
  1187. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_add_worklet_runtime_ident_with_inner_ident.js +13 -0
  1188. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_add_worklet_runtime_ident_with_outer_ident.js +13 -0
  1189. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_capture_env_js.js +12 -0
  1190. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_capture_env_lepus.js +35 -0
  1191. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_ident_from_this_js.js +6 -0
  1192. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_ident_from_this_lepus.js +15 -0
  1193. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_idents_outside_of_ctx.js +9 -0
  1194. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_js.js +29 -0
  1195. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_lepus.js +54 -0
  1196. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_3_js.js +12 -0
  1197. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_3_lepus.js +89 -0
  1198. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_4_js.js +3 -0
  1199. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_4_lepus.js +13 -0
  1200. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_js.js +23 -0
  1201. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_lepus.js +46 -0
  1202. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_handle_renamed_import_shadowing_js.js +16 -0
  1203. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_capture_globals.js +15 -0
  1204. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_capture_type_annotations.js +22 -0
  1205. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_destructure_from_closure.js +12 -0
  1206. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_extract_catch_clause_params.js +17 -0
  1207. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_extract_ident_from_this.js +9 -0
  1208. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_extract_idents_inside_of_ctx.js +24 -0
  1209. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_transform_constructor.js +7 -0
  1210. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_transform_getter_and_setter.js +13 -0
  1211. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_transform_recursively.js +23 -0
  1212. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_transform_when_wrong_directives.js +14 -0
  1213. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_skip_shared_identifiers_default_import_js.js +12 -0
  1214. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_skip_shared_identifiers_js.js +12 -0
  1215. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_skip_shared_identifiers_lepus.js +23 -0
  1216. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_skip_shared_identifiers_namespace_import_js.js +12 -0
  1217. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_skip_shared_identifiers_string_key_js.js +12 -0
  1218. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_arrow_function.js +15 -0
  1219. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_fn_decl_js.js +6 -0
  1220. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_fn_decl_lepus.js +16 -0
  1221. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_function_expr.js +15 -0
  1222. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_in_class_js.js +11 -0
  1223. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_in_class_js_capture_values.js +11 -0
  1224. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_in_class_lepus.js +17 -0
  1225. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_in_class_property_js.js +14 -0
  1226. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_in_class_property_js_capture_values.js +11 -0
  1227. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_in_class_property_lepus.js +21 -0
  1228. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_in_class_static_js.js +9 -0
  1229. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_in_class_static_lepus.js +18 -0
  1230. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_in_class_static_property_js.js +9 -0
  1231. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_in_class_static_property_lepus.js +17 -0
  1232. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_js.js +15 -0
  1233. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_js_fn_in_run_on_js_js.js +10 -0
  1234. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_js_fn_in_run_on_js_lepus.js +25 -0
  1235. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_js_general.js +9 -0
  1236. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_lepus.js +34 -0
  1237. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_lepus_alias.js +20 -0
  1238. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_lepus_general.js +20 -0
  1239. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_lepus_general_mixed.js +20 -0
  1240. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_multiple_worklets.js +29 -0
  1241. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_multiple_worklets_in_func.js +31 -0
  1242. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_ui_worklet_js.js +6 -0
  1243. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_ui_worklet_lepus.js +15 -0
  1244. package/transform/crates/swc_plugin_worklet/worklet_type.rs +24 -0
  1245. package/transform/crates/swc_plugins_shared/Cargo.toml +27 -0
  1246. package/transform/crates/swc_plugins_shared/css.rs +64 -0
  1247. package/transform/crates/swc_plugins_shared/defines.rs +51 -0
  1248. package/transform/crates/swc_plugins_shared/engine_version.rs +50 -0
  1249. package/transform/crates/swc_plugins_shared/jsx_helpers.rs +451 -0
  1250. package/transform/crates/swc_plugins_shared/lib.rs +12 -0
  1251. package/transform/crates/swc_plugins_shared/lynx_event.rs +159 -0
  1252. package/transform/crates/swc_plugins_shared/target.rs +66 -0
  1253. package/transform/crates/swc_plugins_shared/target_napi.rs +69 -0
  1254. package/transform/crates/swc_plugins_shared/transform_mode.rs +61 -0
  1255. package/transform/crates/swc_plugins_shared/transform_mode_napi.rs +72 -0
  1256. package/transform/crates/swc_plugins_shared/utils.rs +149 -0
  1257. package/transform/dist/wasm.cjs +1 -1
  1258. package/transform/node_modules/.bin/esbuild +46 -0
  1259. package/transform/node_modules/.bin/napi +55 -0
  1260. package/transform/package.json +42 -0
  1261. package/transform/rspack-napi/lib/index.d.ts +32 -0
  1262. package/transform/rspack-napi/lib/index.js +96 -0
  1263. package/transform/rspack-napi/lib/index.js.map +1 -0
  1264. package/transform/rspack-napi/package.json +25 -0
  1265. package/transform/rspack-napi/src/index.ts +161 -0
  1266. package/transform/rspack-napi/tsconfig.json +17 -0
  1267. package/transform/rspack-napi/tsconfig.tsbuildinfo +1 -0
  1268. package/transform/scripts/build_wasm.js +55 -0
  1269. package/transform/src/bundle.rs +249 -0
  1270. package/transform/src/esbuild.rs +201 -0
  1271. package/transform/src/lib.rs +1197 -0
  1272. package/transform/src/swc_plugin_compat_post/mod.rs +143 -0
  1273. package/transform/src/swc_plugin_extract_str/mod.rs +382 -0
  1274. package/transform/src/swc_plugin_refresh/mod.rs +546 -0
  1275. package/transform/src/swc_plugin_transform_builtin_attribute_names/mod.rs +286 -0
  1276. package/transform/src/swc_plugin_worklet_post_process/mod.rs +100 -0
  1277. package/transform/src/wasm.js +39 -0
  1278. package/transform/swc-plugin-reactlynx/.cargo/config.toml +9 -0
  1279. package/transform/swc-plugin-reactlynx/.gitignore +2 -0
  1280. package/transform/swc-plugin-reactlynx/.turbo/turbo-build.log +346 -0
  1281. package/transform/swc-plugin-reactlynx/Cargo.toml +30 -0
  1282. package/transform/swc-plugin-reactlynx/build.js +27 -0
  1283. package/transform/swc-plugin-reactlynx/index.d.ts +273 -0
  1284. package/transform/swc-plugin-reactlynx/package.json +22 -0
  1285. package/transform/swc-plugin-reactlynx/src/lib.rs +606 -0
  1286. package/transform/swc-plugin-reactlynx/swc_plugin_reactlynx.wasm +0 -0
  1287. package/transform/swc-plugin-reactlynx/turbo.json +18 -0
  1288. package/transform/swc-plugin-reactlynx-compat/.cargo/config.toml +9 -0
  1289. package/transform/swc-plugin-reactlynx-compat/.gitignore +2 -0
  1290. package/transform/swc-plugin-reactlynx-compat/.turbo/turbo-build.log +256 -0
  1291. package/transform/swc-plugin-reactlynx-compat/Cargo.toml +17 -0
  1292. package/transform/swc-plugin-reactlynx-compat/build.js +27 -0
  1293. package/transform/swc-plugin-reactlynx-compat/index.d.ts +326 -0
  1294. package/transform/swc-plugin-reactlynx-compat/package.json +22 -0
  1295. package/transform/swc-plugin-reactlynx-compat/src/lib.rs +15 -0
  1296. package/transform/swc-plugin-reactlynx-compat/swc_plugin_reactlynx_compat.wasm +0 -0
  1297. package/transform/swc-plugin-reactlynx-compat/turbo.json +18 -0
  1298. package/transform/tests/__swc_snapshots__/src/swc_plugin_compat_post/mod.rs/should_compat_dark_mode.js +3 -0
  1299. package/transform/tests/__swc_snapshots__/src/swc_plugin_compat_post/mod.rs/should_compat_dark_mode_custom_theme_expr.js +3 -0
  1300. package/transform/tests/__swc_snapshots__/src/swc_plugin_extract_str/mod.rs/should_extract_str.js +21 -0
  1301. package/transform/tests/__swc_snapshots__/src/swc_plugin_extract_str/mod.rs/should_extract_str_with_arr.js +20 -0
  1302. package/transform/tests/__swc_snapshots__/src/swc_plugin_extract_str/mod.rs/should_extract_tpl_str.js +9 -0
  1303. package/transform/tests/__swc_snapshots__/src/swc_plugin_refresh/mod.rs/should_handle_basic.js +4 -0
  1304. package/transform/tests/__swc_snapshots__/src/swc_plugin_refresh/mod.rs/should_handle_custom_library.js +4 -0
  1305. package/transform/tests/__swc_snapshots__/src/swc_plugin_refresh/mod.rs/should_handle_function_parameter.js +4 -0
  1306. package/transform/tests/__swc_snapshots__/src/swc_plugin_refresh/mod.rs/should_handle_import_computed.js +4 -0
  1307. package/transform/tests/__swc_snapshots__/src/swc_plugin_refresh/mod.rs/should_handle_import_default.js +4 -0
  1308. package/transform/tests/__swc_snapshots__/src/swc_plugin_refresh/mod.rs/should_handle_import_named_computed.js +4 -0
  1309. package/transform/tests/__swc_snapshots__/src/swc_plugin_refresh/mod.rs/should_handle_import_namespace_computed.js +4 -0
  1310. package/transform/tests/__swc_snapshots__/src/swc_plugin_refresh/mod.rs/should_handle_init_value.js +10 -0
  1311. package/transform/tests/__swc_snapshots__/src/swc_plugin_refresh/mod.rs/should_handle_local_ident.js +8 -0
  1312. package/transform/tests/__swc_snapshots__/src/swc_plugin_refresh/mod.rs/should_handle_multiple_index.js +21 -0
  1313. package/transform/tests/__swc_snapshots__/src/swc_plugin_worklet_post_process/mod.rs/should_transform_worklet.js +12 -0
  1314. package/transform/tests/__swc_snapshots__/src/swc_plugin_worklet_post_process/mod.rs/should_transform_worklet_2.js +14 -0
  1315. package/transform/turbo.json +38 -0
  1316. package/transform/vitest.config.ts +19 -0
@@ -0,0 +1,2751 @@
1
+ // Copyright 2024 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
+
5
+ import { beforeEach, describe, expect, it, vi } from 'vitest';
6
+
7
+ import { globalCommitContext } from '../../../../src/element-template/background/commit-context.js';
8
+ import {
9
+ markElementTemplateHydrated,
10
+ resetElementTemplateCommitState,
11
+ } from '../../../../src/element-template/background/commit-hook.js';
12
+ import { destroyElementTemplateBackgroundRuntime } from '../../../../src/element-template/background/destroy.js';
13
+ import { setupBackgroundElementTemplateDocument } from '../../../../src/element-template/background/document.js';
14
+ import {
15
+ BackgroundElementTemplateInstance,
16
+ BackgroundListElementTemplateInstance,
17
+ BackgroundPageRootInstance,
18
+ BackgroundTypedElementTemplateInstance,
19
+ BUILTIN_RAW_TEXT_TEMPLATE_KEY,
20
+ } from '../../../../src/element-template/background/instance.js';
21
+ import { backgroundElementTemplateInstanceManager } from '../../../../src/element-template/background/manager.js';
22
+ import { clearEventState, getEventHandlerForEventValue } from '../../../../src/element-template/prop-adapters/event.js';
23
+ import { ElementTemplateUpdateOps } from '../../../../src/element-template/protocol/opcodes.js';
24
+ import {
25
+ __etAttrPlanMap,
26
+ adaptEventAttrSlot,
27
+ adaptMTEventAttrSlot,
28
+ adaptMTRefAttrSlot,
29
+ adaptRefAttrSlot,
30
+ adaptSpreadAttrSlot,
31
+ clearEtAttrPlanMap,
32
+ } from '../../../../src/element-template/runtime/template/attr-slot-plan.js';
33
+ import { clearRefState, flushPendingRefs } from '../../../../src/element-template/prop-adapters/ref.js';
34
+ import { hydrateBackground } from '../../test-utils/debug/hydrate.js';
35
+
36
+ function createTextNode(text: string): BackgroundElementTemplateInstance {
37
+ return new BackgroundElementTemplateInstance(BUILTIN_RAW_TEXT_TEMPLATE_KEY, [text]);
38
+ }
39
+
40
+ describe('BackgroundElementTemplateInstance', () => {
41
+ beforeEach(() => {
42
+ globalThis.__MAIN_THREAD__ = false;
43
+ globalThis.__BACKGROUND__ = true;
44
+ backgroundElementTemplateInstanceManager.clear();
45
+ backgroundElementTemplateInstanceManager.nextId = 0;
46
+ clearEtAttrPlanMap();
47
+ clearEventState();
48
+ clearRefState();
49
+ resetElementTemplateCommitState();
50
+ });
51
+
52
+ it('should create an instance with correct type and id', () => {
53
+ const instance = new BackgroundElementTemplateInstance('view');
54
+ expect(instance.type).toBe('view');
55
+ expect(instance.instanceId).toBe(1);
56
+ });
57
+
58
+ it('should increment id for new instances', () => {
59
+ const instance1 = new BackgroundElementTemplateInstance('view');
60
+ const instance2 = new BackgroundElementTemplateInstance('text');
61
+ expect(instance1.instanceId).toBe(1);
62
+ expect(instance2.instanceId).toBe(2);
63
+ });
64
+
65
+ it('does not emit create before hydration', () => {
66
+ globalCommitContext.ops = [];
67
+
68
+ new BackgroundElementTemplateInstance('image', ['logo.png']);
69
+
70
+ expect(globalCommitContext.ops).toEqual([]);
71
+ });
72
+
73
+ it('routes hydrated logical root child patches through the native page handle', () => {
74
+ const root = new BackgroundPageRootInstance();
75
+ expect(root).toBeInstanceOf(BackgroundTypedElementTemplateInstance);
76
+ expect(root.type).toBe('page');
77
+ expect(root.instanceId).toBe(0);
78
+ expect(backgroundElementTemplateInstanceManager.get(0)).toBe(root);
79
+ const child = new BackgroundElementTemplateInstance('_et_child');
80
+ markElementTemplateHydrated();
81
+ globalCommitContext.ops = [];
82
+
83
+ root.appendChild(child);
84
+
85
+ expect(globalCommitContext.ops).toEqual([
86
+ ElementTemplateUpdateOps.createTemplate,
87
+ child.instanceId,
88
+ '_et_child',
89
+ null,
90
+ [],
91
+ [],
92
+ ElementTemplateUpdateOps.insertNode,
93
+ 0,
94
+ 0,
95
+ child.instanceId,
96
+ 0,
97
+ null,
98
+ ]);
99
+
100
+ globalCommitContext.ops = [];
101
+ root.removeChild(child);
102
+
103
+ expect(globalCommitContext.ops).toEqual([
104
+ ElementTemplateUpdateOps.removeNode,
105
+ 0,
106
+ 0,
107
+ child.instanceId,
108
+ [child.instanceId],
109
+ ]);
110
+ });
111
+
112
+ it('keeps authored page attrs on the root and ignores stale helper cleanup', () => {
113
+ const root = new BackgroundPageRootInstance();
114
+ const firstLifetime = {};
115
+ const replacementLifetime = {};
116
+
117
+ root.setAuthoredPageAttributes(firstLifetime, { id: 'first' });
118
+ root.setAuthoredPageAttributes(replacementLifetime, { id: 'replacement' });
119
+ root.clearAuthoredPageAttributes(firstLifetime);
120
+
121
+ expect(root.getRawAttributeSlot(0)).toEqual({ id: 'replacement' });
122
+ expect(root.getRawAttributeSlot(1)).toBeUndefined();
123
+
124
+ markElementTemplateHydrated();
125
+ globalCommitContext.ops = [];
126
+ root.clearAuthoredPageAttributes(replacementLifetime);
127
+
128
+ expect(root.getRawAttributeSlot(0)).toBeNull();
129
+ expect(globalCommitContext.ops).toEqual([
130
+ ElementTemplateUpdateOps.setAttribute,
131
+ 0,
132
+ 0,
133
+ null,
134
+ ]);
135
+ });
136
+
137
+ it('reconciles authored page attrs after hydration', () => {
138
+ const root = new BackgroundPageRootInstance();
139
+ root.setAuthoredPageAttributes({}, { id: 'background' });
140
+ globalCommitContext.ops = [];
141
+
142
+ root.reconcileAuthoredPageAttributesOnHydration({ id: 'main-thread' });
143
+
144
+ expect(globalCommitContext.ops).toEqual([
145
+ ElementTemplateUpdateOps.setAttribute,
146
+ 0,
147
+ 0,
148
+ { id: 'background' },
149
+ ]);
150
+
151
+ globalCommitContext.ops = [];
152
+ root.reconcileAuthoredPageAttributesOnHydration({ id: 'background' });
153
+
154
+ expect(globalCommitContext.ops).toEqual([]);
155
+ });
156
+
157
+ it('emits dedicated update commands for MTEvent and MTRef slots', () => {
158
+ const instance = new BackgroundElementTemplateInstance('_et_mts_attrs');
159
+ const event = { _wkltId: 'tap' };
160
+ const ref = { _wvid: 7 };
161
+ __etAttrPlanMap._et_mts_attrs = [
162
+ 0,
163
+ adaptMTEventAttrSlot,
164
+ 1,
165
+ adaptMTRefAttrSlot,
166
+ ];
167
+ instance.markMaterializedByHydration();
168
+ markElementTemplateHydrated();
169
+ globalCommitContext.ops = [];
170
+
171
+ instance.setAttribute('attributeSlots', [event, ref, 'ordinary']);
172
+
173
+ expect(globalCommitContext.ops).toEqual([
174
+ ElementTemplateUpdateOps.setMainThreadEvent,
175
+ instance.instanceId,
176
+ 0,
177
+ { type: 'worklet', value: event },
178
+ ElementTemplateUpdateOps.setMainThreadRef,
179
+ instance.instanceId,
180
+ 1,
181
+ { type: 'main-thread-ref', value: ref },
182
+ ElementTemplateUpdateOps.setAttribute,
183
+ instance.instanceId,
184
+ 2,
185
+ 'ordinary',
186
+ ]);
187
+ });
188
+
189
+ it('removes the reserved page root registration on teardown', () => {
190
+ const root = new BackgroundPageRootInstance();
191
+
192
+ root.tearDown();
193
+
194
+ expect(backgroundElementTemplateInstanceManager.get(0)).toBeUndefined();
195
+ });
196
+
197
+ it('creates exact list hosts through the list-specific background instance', () => {
198
+ const doc = setupBackgroundElementTemplateDocument();
199
+
200
+ expect(doc.createElement('list')).toBeInstanceOf(BackgroundListElementTemplateInstance);
201
+ expect(doc.createElement('list')).toBeInstanceOf(BackgroundTypedElementTemplateInstance);
202
+ expect(doc.createElement('_et_item')).toBeInstanceOf(BackgroundElementTemplateInstance);
203
+ expect(doc.createElement('_et_item')).not.toBeInstanceOf(BackgroundTypedElementTemplateInstance);
204
+ });
205
+
206
+ it('emits exact list create as typed holder with logical children in command options', () => {
207
+ const list = new BackgroundListElementTemplateInstance();
208
+ const item = new BackgroundElementTemplateInstance('_et_list_item');
209
+ list.setAttribute('attributes', { id: 'feed' });
210
+ list.appendChild(item);
211
+ globalCommitContext.ops = [];
212
+
213
+ list.emitCreate();
214
+
215
+ expect(globalCommitContext.ops).toEqual([
216
+ ElementTemplateUpdateOps.createTypedElement,
217
+ list.instanceId,
218
+ 'list',
219
+ { id: 'feed' },
220
+ null,
221
+ {
222
+ listChildren: [{
223
+ __etHandleRef: item.instanceId,
224
+ type: '_et_list_item',
225
+ platformInfo: {},
226
+ subtreeHandleIds: [],
227
+ }],
228
+ },
229
+ ]);
230
+ });
231
+
232
+ it('owns empty attributes in the generic typed attribute slot', () => {
233
+ const typed = new BackgroundTypedElementTemplateInstance('x-host');
234
+ globalCommitContext.ops = [];
235
+
236
+ expect(typed.attributeSlots).toEqual([null]);
237
+
238
+ typed.emitCreate();
239
+
240
+ expect(globalCommitContext.ops).toEqual([
241
+ ElementTemplateUpdateOps.createTypedElement,
242
+ typed.instanceId,
243
+ 'x-host',
244
+ null,
245
+ null,
246
+ null,
247
+ ]);
248
+ });
249
+
250
+ it('prepares generic typed attributes through the slot-0 spread plan', () => {
251
+ const handler = vi.fn();
252
+ const ref = vi.fn();
253
+ const typed = new BackgroundTypedElementTemplateInstance('x-host');
254
+ typed.setAttribute('attributes', {
255
+ bindtap: handler,
256
+ className: 'card',
257
+ ref,
258
+ });
259
+ flushPendingRefs();
260
+ globalCommitContext.ops = [];
261
+
262
+ typed.emitCreate();
263
+
264
+ expect(typed.attributeSlots).toEqual([{
265
+ bindtap: `${typed.instanceId}:0:bindtap`,
266
+ class: 'card',
267
+ ref: `${typed.instanceId}-0`,
268
+ }]);
269
+ expect(backgroundElementTemplateInstanceManager.getRawAttributeValueByEventValue(
270
+ `${typed.instanceId}:0:bindtap`,
271
+ )).toBe(handler);
272
+ expect(ref).toHaveBeenCalledWith(expect.objectContaining({
273
+ selector: `[ref=${typed.instanceId}-0]`,
274
+ }));
275
+ expect(globalCommitContext.ops).toEqual([
276
+ ElementTemplateUpdateOps.createTypedElement,
277
+ typed.instanceId,
278
+ 'x-host',
279
+ {
280
+ bindtap: `${typed.instanceId}:0:bindtap`,
281
+ class: 'card',
282
+ ref: `${typed.instanceId}-0`,
283
+ },
284
+ null,
285
+ null,
286
+ ]);
287
+
288
+ globalCommitContext.ops = [];
289
+ typed.emitCreate();
290
+
291
+ expect(globalCommitContext.ops).toEqual([]);
292
+ });
293
+
294
+ it('retains inherited instance metadata on typed hosts', () => {
295
+ const typed = new BackgroundTypedElementTemplateInstance('x-host');
296
+
297
+ typed.setAttribute('__listItemPlatformInfo', { 'item-key': 'typed' });
298
+
299
+ expect(typed.getListItemPlatformInfo()).toEqual({ 'item-key': 'typed' });
300
+ });
301
+
302
+ it('reports illegal typed element handle ids on create', () => {
303
+ const oldReportError = lynx.reportError;
304
+ const reportError = vi.fn();
305
+ lynx.reportError = reportError;
306
+
307
+ try {
308
+ const typed = new BackgroundTypedElementTemplateInstance('x-host');
309
+ typed.instanceId = 0;
310
+ globalCommitContext.ops = [];
311
+
312
+ typed.emitCreate();
313
+
314
+ expect(globalCommitContext.ops).toEqual([]);
315
+ expect(String(reportError.mock.calls[0]?.[0]?.message ?? '')).toContain('illegal handleId 0');
316
+ } finally {
317
+ lynx.reportError = oldReportError;
318
+ (globalThis as { __LYNX_REPORT_ERROR_CALLS?: Error[] }).__LYNX_REPORT_ERROR_CALLS = [];
319
+ }
320
+ });
321
+
322
+ it('patches hydrated typed attributes through slot 0', () => {
323
+ const list = new BackgroundListElementTemplateInstance();
324
+ const oldListId = list.instanceId;
325
+ backgroundElementTemplateInstanceManager.updateId(oldListId, -10);
326
+ list.markMaterializedByHydration();
327
+ markElementTemplateHydrated();
328
+ globalCommitContext.ops = [];
329
+
330
+ list.setAttribute('attributes', { id: 'next' });
331
+
332
+ expect(globalCommitContext.ops).toEqual([
333
+ ElementTemplateUpdateOps.setAttribute,
334
+ -10,
335
+ 0,
336
+ { id: 'next' },
337
+ ]);
338
+ });
339
+
340
+ it('emits logical list insertions as incremental typed list item patches', () => {
341
+ const list = new BackgroundListElementTemplateInstance();
342
+ const oldListId = list.instanceId;
343
+ backgroundElementTemplateInstanceManager.updateId(oldListId, -10);
344
+ list.markMaterializedByHydration();
345
+ const first = new BackgroundElementTemplateInstance('_et_item_a');
346
+ first.setAttribute('__listItemPlatformInfo', { 'item-key': 'a' });
347
+ list.appendChild(first);
348
+ const oldFirstId = first.instanceId;
349
+ backgroundElementTemplateInstanceManager.updateId(oldFirstId, -11);
350
+ first.markMaterializedByHydration();
351
+ const second = new BackgroundElementTemplateInstance('_et_item_b');
352
+ second.setAttribute('__listItemPlatformInfo', { 'item-key': 'b' });
353
+ markElementTemplateHydrated();
354
+ globalCommitContext.ops = [];
355
+
356
+ list.insertBefore(second, first);
357
+
358
+ expect(globalCommitContext.ops).toEqual([
359
+ ElementTemplateUpdateOps.createTemplate,
360
+ second.instanceId,
361
+ '_et_item_b',
362
+ null,
363
+ [],
364
+ [],
365
+ ElementTemplateUpdateOps.insertTypedListItem,
366
+ -10,
367
+ {
368
+ __etHandleRef: second.instanceId,
369
+ type: '_et_item_b',
370
+ platformInfo: { 'item-key': 'b' },
371
+ subtreeHandleIds: [],
372
+ },
373
+ -11,
374
+ ]);
375
+ });
376
+
377
+ it('emits logical list updates when list item platform info changes', () => {
378
+ const list = new BackgroundListElementTemplateInstance();
379
+ const oldListId = list.instanceId;
380
+ backgroundElementTemplateInstanceManager.updateId(oldListId, -10);
381
+ list.markMaterializedByHydration();
382
+ const item = new BackgroundElementTemplateInstance('_et_item_a');
383
+ item.setAttribute('__listItemPlatformInfo', { 'item-key': 'a' });
384
+ list.appendChild(item);
385
+ const oldItemId = item.instanceId;
386
+ backgroundElementTemplateInstanceManager.updateId(oldItemId, -11);
387
+ item.markMaterializedByHydration();
388
+ markElementTemplateHydrated();
389
+ globalCommitContext.ops = [];
390
+
391
+ item.setAttribute('__listItemPlatformInfo', { 'item-key': 'a', 'estimated-height': 42 });
392
+
393
+ expect(globalCommitContext.ops).toEqual([
394
+ ElementTemplateUpdateOps.updateTypedListItem,
395
+ -10,
396
+ {
397
+ __etHandleRef: -11,
398
+ type: '_et_item_a',
399
+ platformInfo: { 'item-key': 'a', 'estimated-height': 42 },
400
+ subtreeHandleIds: [],
401
+ },
402
+ ]);
403
+ });
404
+
405
+ it('does not refresh list membership when adding a subtree without MTRefs', () => {
406
+ const list = new BackgroundListElementTemplateInstance();
407
+ backgroundElementTemplateInstanceManager.updateId(list.instanceId, -10);
408
+ list.markMaterializedByHydration();
409
+ const item = new BackgroundElementTemplateInstance('_et_item_a');
410
+ item.setAttribute('__listItemPlatformInfo', { 'item-key': 'a' });
411
+ list.appendChild(item);
412
+ backgroundElementTemplateInstanceManager.updateId(item.instanceId, -11);
413
+ item.markMaterializedByHydration();
414
+ const child = new BackgroundElementTemplateInstance('_et_ref_child');
415
+ markElementTemplateHydrated();
416
+ globalCommitContext.ops = [];
417
+
418
+ item.appendChild(child);
419
+
420
+ expect(globalCommitContext.ops).toEqual([
421
+ ElementTemplateUpdateOps.createTemplate,
422
+ child.instanceId,
423
+ '_et_ref_child',
424
+ null,
425
+ [],
426
+ [],
427
+ ElementTemplateUpdateOps.insertNode,
428
+ -11,
429
+ 0,
430
+ child.instanceId,
431
+ 0,
432
+ null,
433
+ ]);
434
+ });
435
+
436
+ it('keeps typed list item remove and update silent before hydration', () => {
437
+ const list = new BackgroundListElementTemplateInstance();
438
+ backgroundElementTemplateInstanceManager.updateId(list.instanceId, -10);
439
+ list.markMaterializedByHydration();
440
+ const item = new BackgroundElementTemplateInstance('_et_item_a');
441
+ list.appendChild(item);
442
+ backgroundElementTemplateInstanceManager.updateId(item.instanceId, -11);
443
+ item.markMaterializedByHydration();
444
+ globalCommitContext.ops = [];
445
+
446
+ item.setAttribute('__listItemPlatformInfo', { 'item-key': 'a' });
447
+ list.removeChild(item);
448
+
449
+ expect(globalCommitContext.ops).toEqual([]);
450
+ });
451
+
452
+ it('keeps hydrated list removal silent while the list holder is not materialized', () => {
453
+ const list = new BackgroundListElementTemplateInstance();
454
+ const item = new BackgroundElementTemplateInstance('_et_item_a');
455
+ list.appendChild(item);
456
+ markElementTemplateHydrated();
457
+ globalCommitContext.ops = [];
458
+
459
+ list.removeChild(item);
460
+
461
+ expect(globalCommitContext.ops).toEqual([]);
462
+ expect(item.parent).toBeNull();
463
+ expect(backgroundElementTemplateInstanceManager.get(item.instanceId)).toBeUndefined();
464
+ });
465
+
466
+ it('keeps hydrated cross-list moves silent until list holders are materialized', () => {
467
+ const source = new BackgroundListElementTemplateInstance();
468
+ const destination = new BackgroundListElementTemplateInstance();
469
+ const item = new BackgroundElementTemplateInstance('_et_item_a');
470
+ source.appendChild(item);
471
+ markElementTemplateHydrated();
472
+ globalCommitContext.ops = [];
473
+
474
+ destination.appendChild(item);
475
+
476
+ expect(globalCommitContext.ops).toEqual([]);
477
+ expect(source.childNodes).toEqual([]);
478
+ expect(destination.childNodes).toEqual([item]);
479
+ expect(backgroundElementTemplateInstanceManager.get(item.instanceId)).toBe(item);
480
+ });
481
+
482
+ it('queues lifetime cleanup when logically removing a hydrated list item', () => {
483
+ const cleanup = vi.fn();
484
+ const ref = vi.fn(() => cleanup);
485
+ __etAttrPlanMap._et_item_a = [0, adaptRefAttrSlot];
486
+ const list = new BackgroundListElementTemplateInstance();
487
+ backgroundElementTemplateInstanceManager.updateId(list.instanceId, -10);
488
+ list.markMaterializedByHydration();
489
+ const item = new BackgroundElementTemplateInstance('_et_item_a');
490
+ list.appendChild(item);
491
+ backgroundElementTemplateInstanceManager.updateId(item.instanceId, -11);
492
+ item.markMaterializedByHydration();
493
+ markElementTemplateHydrated();
494
+ item.setAttribute('attributeSlots', [ref]);
495
+ flushPendingRefs();
496
+ ref.mockClear();
497
+ globalCommitContext.ops = [];
498
+
499
+ list.removeChild(item);
500
+ flushPendingRefs();
501
+
502
+ expect(globalCommitContext.ops).toEqual([
503
+ ElementTemplateUpdateOps.removeTypedListItem,
504
+ -10,
505
+ -11,
506
+ [-11],
507
+ ]);
508
+ expect([...globalCommitContext.nonPayload.removedSubtreesAwaitingTeardown]).toEqual([item]);
509
+ expect(cleanup).toHaveBeenCalledTimes(1);
510
+ expect(ref).not.toHaveBeenCalled();
511
+ });
512
+
513
+ it('keeps silent list removals out of lifetime cleanup', () => {
514
+ const list = new BackgroundListElementTemplateInstance();
515
+ backgroundElementTemplateInstanceManager.updateId(list.instanceId, -10);
516
+ list.markMaterializedByHydration();
517
+ const item = new BackgroundElementTemplateInstance('_et_item_a');
518
+ list.appendChild(item);
519
+ backgroundElementTemplateInstanceManager.updateId(item.instanceId, -11);
520
+ item.markMaterializedByHydration();
521
+ markElementTemplateHydrated();
522
+ globalCommitContext.ops = [];
523
+
524
+ list.removeChild(item, true);
525
+
526
+ expect(globalCommitContext.ops).toEqual([]);
527
+ expect([...globalCommitContext.nonPayload.removedSubtreesAwaitingTeardown]).toEqual([]);
528
+ });
529
+
530
+ it('emits logical updates for both lists when an item moves across typed lists', () => {
531
+ const oldList = new BackgroundListElementTemplateInstance();
532
+ const newList = new BackgroundListElementTemplateInstance();
533
+ backgroundElementTemplateInstanceManager.updateId(oldList.instanceId, -10);
534
+ backgroundElementTemplateInstanceManager.updateId(newList.instanceId, -20);
535
+ oldList.markMaterializedByHydration();
536
+ newList.markMaterializedByHydration();
537
+ const item = new BackgroundElementTemplateInstance('_et_item_a');
538
+ item.setAttribute('__listItemPlatformInfo', { 'item-key': 'a' });
539
+ oldList.appendChild(item);
540
+ backgroundElementTemplateInstanceManager.updateId(item.instanceId, -11);
541
+ item.markMaterializedByHydration();
542
+ markElementTemplateHydrated();
543
+ globalCommitContext.ops = [];
544
+
545
+ newList.appendChild(item);
546
+
547
+ expect(globalCommitContext.ops).toEqual([
548
+ ElementTemplateUpdateOps.removeTypedListItem,
549
+ -10,
550
+ -11,
551
+ [],
552
+ ElementTemplateUpdateOps.insertTypedListItem,
553
+ -20,
554
+ {
555
+ __etHandleRef: -11,
556
+ type: '_et_item_a',
557
+ platformInfo: { 'item-key': 'a' },
558
+ subtreeHandleIds: [],
559
+ },
560
+ 0,
561
+ ]);
562
+ });
563
+
564
+ it('refreshes list item subtree membership when Suspense restores a descendant', () => {
565
+ __etAttrPlanMap._et_child = [0, adaptMTRefAttrSlot];
566
+ const list = new BackgroundListElementTemplateInstance();
567
+ const item = new BackgroundElementTemplateInstance('_et_item');
568
+ const detachedParent = new BackgroundElementTemplateInstance('div');
569
+ const child = new BackgroundElementTemplateInstance('_et_child');
570
+ list.appendChild(item);
571
+ detachedParent.appendChild(child);
572
+ markElementTemplateHydrated();
573
+ list.markMaterializedByHydration();
574
+ item.markMaterializedByHydration();
575
+ detachedParent.markMaterializedByHydration();
576
+ child.markMaterializedByHydration();
577
+ globalCommitContext.ops = [];
578
+
579
+ item.appendChild(child);
580
+
581
+ expect(detachedParent.childNodes).toEqual([]);
582
+ expect(globalCommitContext.ops).toEqual([
583
+ ElementTemplateUpdateOps.insertNode,
584
+ item.instanceId,
585
+ 0,
586
+ child.instanceId,
587
+ 0,
588
+ null,
589
+ ElementTemplateUpdateOps.updateTypedListItem,
590
+ list.instanceId,
591
+ {
592
+ __etHandleRef: item.instanceId,
593
+ type: '_et_item',
594
+ platformInfo: {},
595
+ subtreeHandleIds: [child.instanceId],
596
+ },
597
+ ]);
598
+ });
599
+
600
+ it('refreshes list item subtree membership when a descendant is removed', () => {
601
+ __etAttrPlanMap._et_child = [0, adaptMTRefAttrSlot];
602
+ const list = new BackgroundListElementTemplateInstance();
603
+ const item = new BackgroundElementTemplateInstance('_et_item');
604
+ const child = new BackgroundElementTemplateInstance('_et_child');
605
+ list.appendChild(item);
606
+ item.appendChild(child);
607
+ markElementTemplateHydrated();
608
+ list.markMaterializedByHydration();
609
+ item.markMaterializedByHydration();
610
+ child.markMaterializedByHydration();
611
+ globalCommitContext.ops = [];
612
+
613
+ item.removeChild(child);
614
+
615
+ expect(globalCommitContext.ops).toEqual([
616
+ ElementTemplateUpdateOps.removeNode,
617
+ item.instanceId,
618
+ 0,
619
+ child.instanceId,
620
+ [child.instanceId],
621
+ ElementTemplateUpdateOps.updateTypedListItem,
622
+ list.instanceId,
623
+ {
624
+ __etHandleRef: item.instanceId,
625
+ type: '_et_item',
626
+ platformInfo: {},
627
+ subtreeHandleIds: [],
628
+ },
629
+ ]);
630
+ });
631
+
632
+ it('emits incremental list mutations instead of full children snapshots during one render', () => {
633
+ const list = new BackgroundListElementTemplateInstance();
634
+ backgroundElementTemplateInstanceManager.updateId(list.instanceId, -10);
635
+ list.markMaterializedByHydration();
636
+ const first = new BackgroundElementTemplateInstance('_et_item_a');
637
+ const second = new BackgroundElementTemplateInstance('_et_item_b');
638
+ const third = new BackgroundElementTemplateInstance('_et_item_c');
639
+ list.appendChild(first);
640
+ list.appendChild(second);
641
+ backgroundElementTemplateInstanceManager.updateId(first.instanceId, -11);
642
+ backgroundElementTemplateInstanceManager.updateId(second.instanceId, -12);
643
+ first.markMaterializedByHydration();
644
+ second.markMaterializedByHydration();
645
+ markElementTemplateHydrated();
646
+ globalCommitContext.ops = [];
647
+
648
+ list.insertBefore(third, second);
649
+ list.removeChild(first);
650
+ second.setAttribute('__listItemPlatformInfo', { 'item-key': 'b', 'full-span': true });
651
+
652
+ expect(globalCommitContext.ops).toEqual([
653
+ ElementTemplateUpdateOps.createTemplate,
654
+ third.instanceId,
655
+ '_et_item_c',
656
+ null,
657
+ [],
658
+ [],
659
+ ElementTemplateUpdateOps.insertTypedListItem,
660
+ -10,
661
+ {
662
+ __etHandleRef: third.instanceId,
663
+ type: '_et_item_c',
664
+ platformInfo: {},
665
+ subtreeHandleIds: [],
666
+ },
667
+ -12,
668
+ ElementTemplateUpdateOps.removeTypedListItem,
669
+ -10,
670
+ -11,
671
+ [-11],
672
+ ElementTemplateUpdateOps.updateTypedListItem,
673
+ -10,
674
+ {
675
+ __etHandleRef: -12,
676
+ type: '_et_item_b',
677
+ platformInfo: { 'item-key': 'b', 'full-span': true },
678
+ subtreeHandleIds: [],
679
+ },
680
+ ]);
681
+ });
682
+
683
+ it('exposes DOM-compatible tree accessors for Preact removal paths', () => {
684
+ const parent = new BackgroundElementTemplateInstance('view');
685
+ const child = new BackgroundElementTemplateInstance('image');
686
+ parent.appendChild(child);
687
+
688
+ expect(parent.childNodes).toEqual([child]);
689
+
690
+ markElementTemplateHydrated();
691
+ parent.markMaterializedByHydration();
692
+ child.markMaterializedByHydration();
693
+ globalCommitContext.ops = [];
694
+ child.parentNode?.removeChild(child);
695
+
696
+ expect(parent.childNodes).toEqual([]);
697
+ expect(child.parentNode).toBeNull();
698
+ expect(parent.childSlots[0]).toBeUndefined();
699
+ expect(globalCommitContext.ops).toEqual([
700
+ 4,
701
+ parent.instanceId,
702
+ 0,
703
+ child.instanceId,
704
+ [child.instanceId],
705
+ ]);
706
+ });
707
+
708
+ describe('appendChild', () => {
709
+ it('should append child correctly', () => {
710
+ const parent = new BackgroundElementTemplateInstance('view');
711
+ const child = new BackgroundElementTemplateInstance('text');
712
+ parent.appendChild(child);
713
+
714
+ expect(parent.firstChild).toBe(child);
715
+ expect(parent.lastChild).toBe(child);
716
+ expect(child.parent).toBe(parent);
717
+ });
718
+
719
+ it('should append multiple children correctly', () => {
720
+ const parent = new BackgroundElementTemplateInstance('view');
721
+ const child1 = new BackgroundElementTemplateInstance('text');
722
+ const child2 = new BackgroundElementTemplateInstance('image');
723
+
724
+ parent.appendChild(child1);
725
+ parent.appendChild(child2);
726
+
727
+ expect(parent.firstChild).toBe(child1);
728
+ expect(parent.lastChild).toBe(child2);
729
+ expect(child1.nextSibling).toBe(child2);
730
+ expect(child2.previousSibling).toBe(child1);
731
+ });
732
+
733
+ it('should reparent child from old parent', () => {
734
+ const parent1 = new BackgroundElementTemplateInstance('view');
735
+ const parent2 = new BackgroundElementTemplateInstance('view');
736
+ const child = new BackgroundElementTemplateInstance('text');
737
+
738
+ parent1.appendChild(child);
739
+ parent2.appendChild(child);
740
+
741
+ expect(parent1.firstChild).toBeNull();
742
+ expect(parent1.lastChild).toBeNull();
743
+ expect(parent2.firstChild).toBe(child);
744
+ expect(parent2.lastChild).toBe(child);
745
+ expect(child.parent).toBe(parent2);
746
+ });
747
+ });
748
+
749
+ describe('insertBefore', () => {
750
+ it('should insert before existing child', () => {
751
+ const parent = new BackgroundElementTemplateInstance('view');
752
+ const child1 = new BackgroundElementTemplateInstance('text');
753
+ const child2 = new BackgroundElementTemplateInstance('image');
754
+
755
+ parent.appendChild(child1);
756
+ parent.insertBefore(child2, child1);
757
+
758
+ expect(parent.firstChild).toBe(child2);
759
+ expect(parent.lastChild).toBe(child1);
760
+ expect(child2.nextSibling).toBe(child1);
761
+ expect(child1.previousSibling).toBe(child2);
762
+ });
763
+
764
+ it('should append if beforeChild is null', () => {
765
+ const parent = new BackgroundElementTemplateInstance('view');
766
+ const child = new BackgroundElementTemplateInstance('text');
767
+ parent.insertBefore(child, null);
768
+
769
+ expect(parent.firstChild).toBe(child);
770
+ expect(parent.lastChild).toBe(child);
771
+ });
772
+
773
+ it('supports silent append on regular parents', () => {
774
+ const parent = new BackgroundElementTemplateInstance('view');
775
+ const child = new BackgroundElementTemplateInstance('text');
776
+ globalCommitContext.ops = [];
777
+
778
+ parent.insertBefore(child, null, true);
779
+
780
+ expect(parent.firstChild).toBe(child);
781
+ expect(globalCommitContext.ops).toEqual([]);
782
+ });
783
+
784
+ it('emits create with initialized attrs before inserting a post-hydration template', () => {
785
+ const parent = new BackgroundElementTemplateInstance('view');
786
+ parent.emitCreate();
787
+
788
+ markElementTemplateHydrated();
789
+ globalCommitContext.ops = [];
790
+
791
+ const child = new BackgroundElementTemplateInstance('image');
792
+ child.setAttribute('attributeSlots', ['logo.png']);
793
+
794
+ expect(globalCommitContext.ops).toEqual([]);
795
+
796
+ parent.appendChild(child);
797
+
798
+ expect(globalCommitContext.ops).toEqual([
799
+ 1,
800
+ child.instanceId,
801
+ 'image',
802
+ null,
803
+ ['logo.png'],
804
+ [],
805
+ 3,
806
+ parent.instanceId,
807
+ 0,
808
+ child.instanceId,
809
+ 0,
810
+ null,
811
+ ]);
812
+ });
813
+
814
+ it('queues direct ref attach when inserting a post-hydration template', () => {
815
+ const ref = vi.fn();
816
+ __etAttrPlanMap.view = [0, adaptRefAttrSlot];
817
+ const parent = new BackgroundElementTemplateInstance('view');
818
+ parent.emitCreate();
819
+
820
+ markElementTemplateHydrated();
821
+ globalCommitContext.ops = [];
822
+
823
+ const child = new BackgroundElementTemplateInstance('view');
824
+ child.setAttribute('attributeSlots', [ref]);
825
+ parent.appendChild(child);
826
+ flushPendingRefs();
827
+
828
+ expect(globalCommitContext.ops).toEqual([
829
+ 1,
830
+ child.instanceId,
831
+ 'view',
832
+ null,
833
+ [`${child.instanceId}-0`],
834
+ [],
835
+ 3,
836
+ parent.instanceId,
837
+ 0,
838
+ child.instanceId,
839
+ 0,
840
+ null,
841
+ ]);
842
+ expect(ref).toHaveBeenCalledWith(expect.objectContaining({
843
+ selector: `[ref=${child.instanceId}-0]`,
844
+ }));
845
+ });
846
+
847
+ it('sends only MTRef-capable handles with a structural insert', () => {
848
+ __etAttrPlanMap.child = [0, adaptMTRefAttrSlot];
849
+ const parent = new BackgroundElementTemplateInstance('parent');
850
+ parent.emitCreate();
851
+ markElementTemplateHydrated();
852
+ globalCommitContext.ops = [];
853
+
854
+ const child = new BackgroundElementTemplateInstance('child');
855
+ const ordinaryDescendant = new BackgroundElementTemplateInstance('ordinary');
856
+ child.appendChild(ordinaryDescendant);
857
+ parent.appendChild(child);
858
+
859
+ expect(globalCommitContext.ops[12]).toBe(ElementTemplateUpdateOps.insertNode);
860
+ expect(globalCommitContext.ops.at(-1)).toEqual([child.instanceId]);
861
+ });
862
+
863
+ it('does not detach refs that never attached on a post-hydration unmaterialized subtree', () => {
864
+ // Regression: post-hydration `setAttribute` runs with
865
+ // ref publishing disabled on unmaterialized children (attach is deferred
866
+ // to `emitCreate`). If `removeChild` unconditionally queues a cleanup,
867
+ // the ref observes a spurious detach for an attach that never fired.
868
+ const ref = vi.fn();
869
+ __etAttrPlanMap.view = [0, adaptRefAttrSlot];
870
+ markElementTemplateHydrated();
871
+ const parent = new BackgroundElementTemplateInstance('view');
872
+ const child = new BackgroundElementTemplateInstance('view');
873
+ child.setAttribute('attributeSlots', [ref]);
874
+ parent.appendChild(child);
875
+ flushPendingRefs();
876
+ expect(ref).not.toHaveBeenCalled();
877
+
878
+ parent.removeChild(child);
879
+ flushPendingRefs();
880
+
881
+ expect(ref).not.toHaveBeenCalled();
882
+ });
883
+
884
+ it('does not re-attach stable direct refs when moving an existing hydrated child', () => {
885
+ const ref = vi.fn();
886
+ __etAttrPlanMap.view = [0, adaptRefAttrSlot];
887
+ const parent = new BackgroundElementTemplateInstance('view');
888
+ const before = new BackgroundElementTemplateInstance('view');
889
+ const child = new BackgroundElementTemplateInstance('view');
890
+ child.setAttribute('attributeSlots', [ref]);
891
+ parent.appendChild(before);
892
+ parent.appendChild(child);
893
+
894
+ markElementTemplateHydrated();
895
+ parent.markMaterializedByHydration();
896
+ before.markMaterializedByHydration();
897
+ child.markMaterializedByHydration();
898
+ child.prepareAttributeSlotsForNative();
899
+ flushPendingRefs();
900
+ ref.mockClear();
901
+ globalCommitContext.ops = [];
902
+
903
+ parent.insertBefore(child, before);
904
+ flushPendingRefs();
905
+
906
+ expect(globalCommitContext.ops).toEqual([
907
+ 3,
908
+ parent.instanceId,
909
+ 0,
910
+ child.instanceId,
911
+ before.instanceId,
912
+ null,
913
+ ]);
914
+ expect(ref).not.toHaveBeenCalled();
915
+ });
916
+
917
+ it.each(['compiled', 'list'])('checks only the moved subtree root for creation under a %s parent', (parentKind) => {
918
+ __etAttrPlanMap._et_leaf = [0, adaptMTRefAttrSlot];
919
+ const root = new BackgroundPageRootInstance();
920
+ const parent = parentKind === 'list'
921
+ ? new BackgroundListElementTemplateInstance()
922
+ : new BackgroundElementTemplateInstance('_et_parent');
923
+ const anchor = new BackgroundElementTemplateInstance('_et_anchor');
924
+ const owner = new BackgroundElementTemplateInstance('_et_owner');
925
+ const nested = new BackgroundElementTemplateInstance('_et_nested');
926
+ const leaf = new BackgroundElementTemplateInstance('_et_leaf');
927
+ nested.appendChild(leaf);
928
+ owner.appendChild(nested);
929
+ markElementTemplateHydrated();
930
+ root.appendChild(parent);
931
+ parent.appendChild(anchor);
932
+ parent.appendChild(owner);
933
+ globalCommitContext.ops = [];
934
+
935
+ const createCheck = vi.spyOn(BackgroundElementTemplateInstance.prototype, 'emitMainThreadCreateIfNeeded');
936
+ try {
937
+ parent.insertBefore(owner, anchor);
938
+
939
+ expect(createCheck).toHaveBeenCalledTimes(1);
940
+ } finally {
941
+ createCheck.mockRestore();
942
+ }
943
+ expect(parent.childNodes).toEqual([owner, anchor]);
944
+ expect(owner.firstChild).toBe(nested);
945
+ expect(nested.firstChild).toBe(leaf);
946
+ expect(globalCommitContext.ops).toEqual(
947
+ parentKind === 'list'
948
+ ? [
949
+ ElementTemplateUpdateOps.removeTypedListItem,
950
+ parent.instanceId,
951
+ owner.instanceId,
952
+ [],
953
+ ElementTemplateUpdateOps.insertTypedListItem,
954
+ parent.instanceId,
955
+ {
956
+ __etHandleRef: owner.instanceId,
957
+ type: '_et_owner',
958
+ platformInfo: {},
959
+ subtreeHandleIds: [leaf.instanceId],
960
+ },
961
+ anchor.instanceId,
962
+ ]
963
+ : [
964
+ ElementTemplateUpdateOps.insertNode,
965
+ parent.instanceId,
966
+ 0,
967
+ owner.instanceId,
968
+ anchor.instanceId,
969
+ [leaf.instanceId],
970
+ ],
971
+ );
972
+ });
973
+
974
+ it('creates new descendants once when moving their materialized owner', () => {
975
+ const ref = vi.fn();
976
+ __etAttrPlanMap._et_ref_leaf = [0, adaptRefAttrSlot];
977
+ const root = new BackgroundPageRootInstance();
978
+ const parent = new BackgroundElementTemplateInstance('_et_parent');
979
+ const anchor = new BackgroundElementTemplateInstance('_et_anchor');
980
+ const owner = new BackgroundElementTemplateInstance('_et_owner');
981
+ markElementTemplateHydrated();
982
+ root.appendChild(parent);
983
+ parent.appendChild(anchor);
984
+ parent.appendChild(owner);
985
+ globalCommitContext.ops = [];
986
+
987
+ const nested = new BackgroundElementTemplateInstance('_et_nested');
988
+ const leaf = new BackgroundElementTemplateInstance('_et_ref_leaf');
989
+ leaf.setAttribute('attributeSlots', [ref]);
990
+ nested.appendChild(leaf);
991
+ flushPendingRefs();
992
+ expect(ref).not.toHaveBeenCalled();
993
+ expect(globalCommitContext.ops).toEqual([]);
994
+
995
+ owner.appendChild(nested);
996
+ parent.insertBefore(owner, anchor);
997
+ flushPendingRefs();
998
+
999
+ expect(globalCommitContext.ops).toEqual([
1000
+ ElementTemplateUpdateOps.createTemplate,
1001
+ leaf.instanceId,
1002
+ '_et_ref_leaf',
1003
+ null,
1004
+ [`${leaf.instanceId}-0`],
1005
+ [],
1006
+ ElementTemplateUpdateOps.createTemplate,
1007
+ nested.instanceId,
1008
+ '_et_nested',
1009
+ null,
1010
+ [],
1011
+ [[leaf.instanceId]],
1012
+ ElementTemplateUpdateOps.insertNode,
1013
+ owner.instanceId,
1014
+ 0,
1015
+ nested.instanceId,
1016
+ 0,
1017
+ null,
1018
+ ElementTemplateUpdateOps.insertNode,
1019
+ parent.instanceId,
1020
+ 0,
1021
+ owner.instanceId,
1022
+ anchor.instanceId,
1023
+ null,
1024
+ ]);
1025
+ expect(ref).toHaveBeenCalledTimes(1);
1026
+ expect(ref).toHaveBeenCalledWith(expect.objectContaining({
1027
+ selector: `[ref=${leaf.instanceId}-0]`,
1028
+ }));
1029
+ expect(parent.childNodes).toEqual([owner, anchor]);
1030
+ expect(owner.firstChild).toBe(nested);
1031
+ expect(nested.firstChild).toBe(leaf);
1032
+ });
1033
+
1034
+ it('defers nested slot inserts until the owner template is created', () => {
1035
+ const parent = new BackgroundElementTemplateInstance('view');
1036
+ parent.emitCreate();
1037
+
1038
+ markElementTemplateHydrated();
1039
+ globalCommitContext.ops = [];
1040
+
1041
+ const owner = new BackgroundElementTemplateInstance('view');
1042
+ const nested = createTextNode('nested');
1043
+ owner.appendChild(nested);
1044
+
1045
+ expect(globalCommitContext.ops).toEqual([]);
1046
+
1047
+ parent.appendChild(owner);
1048
+
1049
+ expect(globalCommitContext.ops).toEqual([
1050
+ 1,
1051
+ nested.instanceId,
1052
+ BUILTIN_RAW_TEXT_TEMPLATE_KEY,
1053
+ null,
1054
+ ['nested'],
1055
+ [],
1056
+ 1,
1057
+ owner.instanceId,
1058
+ 'view',
1059
+ null,
1060
+ [],
1061
+ [[nested.instanceId]],
1062
+ 3,
1063
+ parent.instanceId,
1064
+ 0,
1065
+ owner.instanceId,
1066
+ 0,
1067
+ null,
1068
+ ]);
1069
+ });
1070
+
1071
+ it('skips sparse child slots when creating a post-hydration template recursively', () => {
1072
+ const parent = new BackgroundElementTemplateInstance('view');
1073
+ parent.emitCreate();
1074
+
1075
+ markElementTemplateHydrated();
1076
+ globalCommitContext.ops = [];
1077
+
1078
+ const grandchild = new BackgroundElementTemplateInstance('view');
1079
+ grandchild.__slotIndex = 1;
1080
+ const child = new BackgroundElementTemplateInstance('view');
1081
+ child.appendChild(grandchild);
1082
+
1083
+ parent.appendChild(child);
1084
+
1085
+ const serializedSlots = globalCommitContext.ops[11] as unknown[];
1086
+ expect(globalCommitContext.ops[6]).toBe(1);
1087
+ expect(globalCommitContext.ops[7]).toBe(child.instanceId);
1088
+ expect(serializedSlots).toHaveLength(2);
1089
+ expect(0 in serializedSlots).toBe(false);
1090
+ expect(1 in serializedSlots).toBe(true);
1091
+ expect(serializedSlots[1]).toEqual([grandchild.instanceId]);
1092
+ expect(globalCommitContext.ops.slice(12)).toEqual([
1093
+ 3,
1094
+ parent.instanceId,
1095
+ 0,
1096
+ child.instanceId,
1097
+ 0,
1098
+ null,
1099
+ ]);
1100
+ });
1101
+
1102
+ it('creates nested list item subtrees before inserting a post-hydration list', () => {
1103
+ const parent = new BackgroundElementTemplateInstance('view');
1104
+ parent.emitCreate();
1105
+
1106
+ markElementTemplateHydrated();
1107
+ globalCommitContext.ops = [];
1108
+
1109
+ const list = new BackgroundListElementTemplateInstance();
1110
+ const item = new BackgroundElementTemplateInstance('_et_item');
1111
+ const nested = new BackgroundElementTemplateInstance('_et_nested');
1112
+ item.appendChild(nested);
1113
+ list.appendChild(item);
1114
+
1115
+ parent.appendChild(list);
1116
+
1117
+ expect(globalCommitContext.ops).toEqual([
1118
+ ElementTemplateUpdateOps.createTemplate,
1119
+ nested.instanceId,
1120
+ '_et_nested',
1121
+ null,
1122
+ [],
1123
+ [],
1124
+ ElementTemplateUpdateOps.createTemplate,
1125
+ item.instanceId,
1126
+ '_et_item',
1127
+ null,
1128
+ [],
1129
+ [[nested.instanceId]],
1130
+ ElementTemplateUpdateOps.createTypedElement,
1131
+ list.instanceId,
1132
+ 'list',
1133
+ null,
1134
+ null,
1135
+ {
1136
+ listChildren: [{
1137
+ __etHandleRef: item.instanceId,
1138
+ type: '_et_item',
1139
+ platformInfo: {},
1140
+ subtreeHandleIds: [],
1141
+ }],
1142
+ },
1143
+ ElementTemplateUpdateOps.insertNode,
1144
+ parent.instanceId,
1145
+ 0,
1146
+ list.instanceId,
1147
+ 0,
1148
+ null,
1149
+ ]);
1150
+ });
1151
+
1152
+ it('should move existing child if re-inserted', () => {
1153
+ const parent = new BackgroundElementTemplateInstance('view');
1154
+ const child1 = new BackgroundElementTemplateInstance('text');
1155
+ const child2 = new BackgroundElementTemplateInstance('image');
1156
+
1157
+ parent.appendChild(child1);
1158
+ parent.appendChild(child2);
1159
+ // Move child2 before child1
1160
+ parent.insertBefore(child2, child1);
1161
+
1162
+ expect(parent.firstChild).toBe(child2);
1163
+ expect(parent.lastChild).toBe(child1);
1164
+ expect(child2.nextSibling).toBe(child1);
1165
+ });
1166
+
1167
+ it('should insert between two nodes', () => {
1168
+ const parent = new BackgroundElementTemplateInstance('view');
1169
+ const child1 = new BackgroundElementTemplateInstance('text');
1170
+ const child2 = new BackgroundElementTemplateInstance('image');
1171
+ const child3 = new BackgroundElementTemplateInstance('view');
1172
+
1173
+ parent.appendChild(child1);
1174
+ parent.appendChild(child2);
1175
+
1176
+ // Insert child3 before child2. child2 has previousSibling child1.
1177
+ parent.insertBefore(child3, child2);
1178
+
1179
+ expect(parent.firstChild).toBe(child1);
1180
+ expect(parent.lastChild).toBe(child2);
1181
+ expect(child1.nextSibling).toBe(child3);
1182
+ expect(child3.nextSibling).toBe(child2);
1183
+ expect(child3.previousSibling).toBe(child1);
1184
+ expect(child2.previousSibling).toBe(child3);
1185
+ });
1186
+
1187
+ it('should reparent child before target in new parent', () => {
1188
+ const parent1 = new BackgroundElementTemplateInstance('view');
1189
+ const parent2 = new BackgroundElementTemplateInstance('view');
1190
+ const child1 = new BackgroundElementTemplateInstance('text');
1191
+ const child2 = new BackgroundElementTemplateInstance('image');
1192
+ const mover = new BackgroundElementTemplateInstance('view');
1193
+
1194
+ parent1.appendChild(mover);
1195
+ parent2.appendChild(child1);
1196
+ parent2.appendChild(child2);
1197
+
1198
+ parent2.insertBefore(mover, child2);
1199
+
1200
+ expect(parent1.firstChild).toBeNull();
1201
+ expect(parent1.lastChild).toBeNull();
1202
+ expect(parent2.firstChild).toBe(child1);
1203
+ expect(child1.nextSibling).toBe(mover);
1204
+ expect(mover.nextSibling).toBe(child2);
1205
+ expect(child2.previousSibling).toBe(mover);
1206
+ expect(mover.parent).toBe(parent2);
1207
+ });
1208
+
1209
+ it('should reject a reference node from another parent', () => {
1210
+ const parent1 = new BackgroundElementTemplateInstance('view');
1211
+ const parent2 = new BackgroundElementTemplateInstance('view');
1212
+ const child = new BackgroundElementTemplateInstance('text');
1213
+ const foreign = new BackgroundElementTemplateInstance('image');
1214
+
1215
+ parent1.appendChild(child);
1216
+ parent2.appendChild(foreign);
1217
+
1218
+ expect(() => parent1.insertBefore(child, foreign)).toThrow(
1219
+ 'Reference node is not a child of this parent',
1220
+ );
1221
+ });
1222
+
1223
+ it('should reject inserting a node before itself', () => {
1224
+ const parent = new BackgroundElementTemplateInstance('view');
1225
+ const child = new BackgroundElementTemplateInstance('text');
1226
+ parent.appendChild(child);
1227
+
1228
+ expect(() => parent.insertBefore(child, child)).toThrow(
1229
+ 'Cannot insert a node before itself',
1230
+ );
1231
+ });
1232
+
1233
+ it('emits beforeId=0 when the reference child lives in a different slot', () => {
1234
+ // Slot ordering is per-slot, so a beforeChild from another slot has no
1235
+ // meaning for the new child's position. Falling back to 0 keeps the
1236
+ // main-thread insert as an append within the destination slot.
1237
+ const parent = new BackgroundElementTemplateInstance('view');
1238
+ const slot0Anchor = new BackgroundElementTemplateInstance('view');
1239
+ slot0Anchor.__slotIndex = 0;
1240
+ parent.appendChild(slot0Anchor);
1241
+
1242
+ markElementTemplateHydrated();
1243
+ parent.markMaterializedByHydration();
1244
+ slot0Anchor.markMaterializedByHydration();
1245
+ globalCommitContext.ops = [];
1246
+
1247
+ const newChild = new BackgroundElementTemplateInstance('text');
1248
+ newChild.__slotIndex = 1;
1249
+
1250
+ parent.insertBefore(newChild, slot0Anchor);
1251
+
1252
+ expect(globalCommitContext.ops).toEqual([
1253
+ ElementTemplateUpdateOps.createTemplate,
1254
+ newChild.instanceId,
1255
+ 'text',
1256
+ null,
1257
+ [],
1258
+ [],
1259
+ ElementTemplateUpdateOps.insertNode,
1260
+ parent.instanceId,
1261
+ 1,
1262
+ newChild.instanceId,
1263
+ 0,
1264
+ null,
1265
+ ]);
1266
+ });
1267
+
1268
+ it('keeps beforeId pointing at the reference child when slots match', () => {
1269
+ const parent = new BackgroundElementTemplateInstance('view');
1270
+ const anchor = new BackgroundElementTemplateInstance('view');
1271
+ anchor.__slotIndex = 1;
1272
+ parent.appendChild(anchor);
1273
+
1274
+ markElementTemplateHydrated();
1275
+ parent.markMaterializedByHydration();
1276
+ anchor.markMaterializedByHydration();
1277
+ globalCommitContext.ops = [];
1278
+
1279
+ const newChild = new BackgroundElementTemplateInstance('text');
1280
+ newChild.__slotIndex = 1;
1281
+
1282
+ parent.insertBefore(newChild, anchor);
1283
+
1284
+ expect(globalCommitContext.ops).toEqual([
1285
+ ElementTemplateUpdateOps.createTemplate,
1286
+ newChild.instanceId,
1287
+ 'text',
1288
+ null,
1289
+ [],
1290
+ [],
1291
+ ElementTemplateUpdateOps.insertNode,
1292
+ parent.instanceId,
1293
+ 1,
1294
+ newChild.instanceId,
1295
+ anchor.instanceId,
1296
+ null,
1297
+ ]);
1298
+ });
1299
+
1300
+ it('emits only the destination insert when moving a hydrated child across parents', () => {
1301
+ const source = new BackgroundElementTemplateInstance('view');
1302
+ const destination = new BackgroundElementTemplateInstance('view');
1303
+ const child = new BackgroundElementTemplateInstance('text');
1304
+ source.appendChild(child);
1305
+ markElementTemplateHydrated();
1306
+ source.markMaterializedByHydration();
1307
+ destination.markMaterializedByHydration();
1308
+ child.markMaterializedByHydration();
1309
+ globalCommitContext.ops = [];
1310
+
1311
+ destination.appendChild(child);
1312
+
1313
+ expect(globalCommitContext.ops).toEqual([
1314
+ ElementTemplateUpdateOps.insertNode,
1315
+ destination.instanceId,
1316
+ 0,
1317
+ child.instanceId,
1318
+ 0,
1319
+ null,
1320
+ ]);
1321
+ expect(source.childNodes).toEqual([]);
1322
+ expect(destination.childNodes).toEqual([child]);
1323
+ });
1324
+
1325
+ it('does not emit create for a root-handle child inserted after hydration', () => {
1326
+ const parent = new BackgroundElementTemplateInstance('view');
1327
+ parent.emitCreate();
1328
+ markElementTemplateHydrated();
1329
+
1330
+ const child = new BackgroundElementTemplateInstance('root');
1331
+ backgroundElementTemplateInstanceManager.values.delete(child.instanceId);
1332
+ child.instanceId = 0;
1333
+ globalCommitContext.ops = [];
1334
+
1335
+ parent.appendChild(child);
1336
+
1337
+ expect(globalCommitContext.ops).toHaveLength(6);
1338
+ expect(globalCommitContext.ops[0]).toBe(ElementTemplateUpdateOps.insertNode);
1339
+ expect(backgroundElementTemplateInstanceManager.get(0)).toBeUndefined();
1340
+ });
1341
+
1342
+ it('recreates a detached materialized subtree before reattaching it', () => {
1343
+ const parent = new BackgroundElementTemplateInstance('view');
1344
+ const child = new BackgroundElementTemplateInstance('view');
1345
+ const grandchild = createTextNode('inside');
1346
+ child.appendChild(grandchild);
1347
+ parent.appendChild(child);
1348
+
1349
+ markElementTemplateHydrated();
1350
+ parent.markMaterializedByHydration();
1351
+ child.markMaterializedByHydration();
1352
+ grandchild.markMaterializedByHydration();
1353
+ globalCommitContext.ops = [];
1354
+
1355
+ parent.removeChild(child);
1356
+ expect(globalCommitContext.ops).toEqual([
1357
+ ElementTemplateUpdateOps.removeNode,
1358
+ parent.instanceId,
1359
+ 0,
1360
+ child.instanceId,
1361
+ [child.instanceId, grandchild.instanceId],
1362
+ ]);
1363
+
1364
+ globalCommitContext.ops = [];
1365
+ parent.appendChild(child);
1366
+
1367
+ expect(globalCommitContext.ops).toEqual([
1368
+ ElementTemplateUpdateOps.createTemplate,
1369
+ grandchild.instanceId,
1370
+ BUILTIN_RAW_TEXT_TEMPLATE_KEY,
1371
+ null,
1372
+ ['inside'],
1373
+ [],
1374
+ ElementTemplateUpdateOps.createTemplate,
1375
+ child.instanceId,
1376
+ 'view',
1377
+ null,
1378
+ [],
1379
+ [[grandchild.instanceId]],
1380
+ ElementTemplateUpdateOps.insertNode,
1381
+ parent.instanceId,
1382
+ 0,
1383
+ child.instanceId,
1384
+ 0,
1385
+ null,
1386
+ ]);
1387
+ });
1388
+
1389
+ it('recreates detached hydrated subtrees with native negative handles', () => {
1390
+ const parent = new BackgroundElementTemplateInstance('view');
1391
+ const child = new BackgroundElementTemplateInstance('view');
1392
+ const grandchild = createTextNode('inside');
1393
+ child.appendChild(grandchild);
1394
+ parent.appendChild(child);
1395
+ backgroundElementTemplateInstanceManager.updateId(child.instanceId, -2);
1396
+ backgroundElementTemplateInstanceManager.updateId(grandchild.instanceId, -3);
1397
+
1398
+ markElementTemplateHydrated();
1399
+ parent.markMaterializedByHydration();
1400
+ child.markMaterializedByHydration();
1401
+ grandchild.markMaterializedByHydration();
1402
+
1403
+ parent.removeChild(child);
1404
+ globalCommitContext.ops = [];
1405
+ parent.appendChild(child);
1406
+
1407
+ expect(globalCommitContext.ops).toEqual([
1408
+ ElementTemplateUpdateOps.createTemplate,
1409
+ -3,
1410
+ BUILTIN_RAW_TEXT_TEMPLATE_KEY,
1411
+ null,
1412
+ ['inside'],
1413
+ [],
1414
+ ElementTemplateUpdateOps.createTemplate,
1415
+ -2,
1416
+ 'view',
1417
+ null,
1418
+ [],
1419
+ [[-3]],
1420
+ ElementTemplateUpdateOps.insertNode,
1421
+ parent.instanceId,
1422
+ 0,
1423
+ -2,
1424
+ 0,
1425
+ null,
1426
+ ]);
1427
+ });
1428
+ });
1429
+
1430
+ describe('removeChild', () => {
1431
+ it('should remove child correctly', () => {
1432
+ const parent = new BackgroundElementTemplateInstance('view');
1433
+ const child = new BackgroundElementTemplateInstance('text');
1434
+ parent.appendChild(child);
1435
+ parent.removeChild(child);
1436
+
1437
+ expect(parent.firstChild).toBeNull();
1438
+ expect(parent.lastChild).toBeNull();
1439
+ expect(child.parent).toBeNull();
1440
+ });
1441
+
1442
+ it('should update siblings when removing middle child', () => {
1443
+ const parent = new BackgroundElementTemplateInstance('view');
1444
+ const child1 = new BackgroundElementTemplateInstance('text');
1445
+ const child2 = new BackgroundElementTemplateInstance('image');
1446
+ const child3 = new BackgroundElementTemplateInstance('view');
1447
+
1448
+ parent.appendChild(child1);
1449
+ parent.appendChild(child2);
1450
+ parent.appendChild(child3);
1451
+
1452
+ parent.removeChild(child2);
1453
+
1454
+ expect(child1.nextSibling).toBe(child3);
1455
+ expect(child3.previousSibling).toBe(child1);
1456
+ expect(parent.firstChild).toBe(child1);
1457
+ expect(parent.lastChild).toBe(child3);
1458
+ });
1459
+
1460
+ it('should update head when removing first child', () => {
1461
+ const parent = new BackgroundElementTemplateInstance('view');
1462
+ const child1 = new BackgroundElementTemplateInstance('text');
1463
+ const child2 = new BackgroundElementTemplateInstance('image');
1464
+
1465
+ parent.appendChild(child1);
1466
+ parent.appendChild(child2);
1467
+
1468
+ parent.removeChild(child1);
1469
+
1470
+ expect(parent.firstChild).toBe(child2);
1471
+ expect(parent.lastChild).toBe(child2);
1472
+ expect(child2.previousSibling).toBeNull();
1473
+ });
1474
+
1475
+ it('should update tail when removing last child', () => {
1476
+ const parent = new BackgroundElementTemplateInstance('view');
1477
+ const child1 = new BackgroundElementTemplateInstance('text');
1478
+ const child2 = new BackgroundElementTemplateInstance('image');
1479
+
1480
+ parent.appendChild(child1);
1481
+ parent.appendChild(child2);
1482
+
1483
+ parent.removeChild(child2);
1484
+
1485
+ expect(parent.firstChild).toBe(child1);
1486
+ expect(parent.lastChild).toBe(child1);
1487
+ expect(child1.nextSibling).toBeNull();
1488
+ });
1489
+
1490
+ it('should throw error if removing non-child', () => {
1491
+ const parent = new BackgroundElementTemplateInstance('view');
1492
+ const other = new BackgroundElementTemplateInstance('text');
1493
+ expect(() => parent.removeChild(other)).toThrow('Node is not a child of this parent');
1494
+ });
1495
+
1496
+ it('emits remove ops when removing from a slot container', () => {
1497
+ const parent = new BackgroundElementTemplateInstance('view');
1498
+ const child = new BackgroundElementTemplateInstance('text');
1499
+ const grandchild = new BackgroundElementTemplateInstance('text');
1500
+ child.appendChild(grandchild);
1501
+ parent.appendChild(child);
1502
+
1503
+ markElementTemplateHydrated();
1504
+ parent.markMaterializedByHydration();
1505
+ child.markMaterializedByHydration();
1506
+ grandchild.markMaterializedByHydration();
1507
+ globalCommitContext.ops = [];
1508
+ parent.removeChild(child);
1509
+
1510
+ expect(parent.childSlots[0]).toBeUndefined();
1511
+ expect(globalCommitContext.ops).toEqual([
1512
+ 4,
1513
+ parent.instanceId,
1514
+ 0,
1515
+ child.instanceId,
1516
+ [child.instanceId, grandchild.instanceId],
1517
+ ]);
1518
+ expect([...globalCommitContext.nonPayload.removedSubtreesAwaitingTeardown]).toEqual([child]);
1519
+ });
1520
+
1521
+ it('queues direct ref cleanup when removing a hydrated subtree', () => {
1522
+ const cleanup = vi.fn();
1523
+ const ref = vi.fn(() => cleanup);
1524
+ __etAttrPlanMap.view = [0, adaptRefAttrSlot];
1525
+ const parent = new BackgroundElementTemplateInstance('view');
1526
+ const child = new BackgroundElementTemplateInstance('view');
1527
+ parent.appendChild(child);
1528
+
1529
+ markElementTemplateHydrated();
1530
+ parent.markMaterializedByHydration();
1531
+ child.markMaterializedByHydration();
1532
+ child.setAttribute('attributeSlots', [ref]);
1533
+ flushPendingRefs();
1534
+ ref.mockClear();
1535
+ globalCommitContext.ops = [];
1536
+
1537
+ parent.removeChild(child);
1538
+ flushPendingRefs();
1539
+
1540
+ expect(globalCommitContext.ops).toEqual([
1541
+ 4,
1542
+ parent.instanceId,
1543
+ 0,
1544
+ child.instanceId,
1545
+ [child.instanceId],
1546
+ ]);
1547
+ expect(cleanup).toHaveBeenCalledTimes(1);
1548
+ expect(ref).not.toHaveBeenCalled();
1549
+ });
1550
+
1551
+ it('queues direct object ref cleanup when removing a hydrated subtree', () => {
1552
+ const ref = { current: null };
1553
+ __etAttrPlanMap.view = [0, adaptRefAttrSlot];
1554
+ const parent = new BackgroundElementTemplateInstance('view');
1555
+ const child = new BackgroundElementTemplateInstance('view');
1556
+ parent.appendChild(child);
1557
+
1558
+ markElementTemplateHydrated();
1559
+ parent.markMaterializedByHydration();
1560
+ child.markMaterializedByHydration();
1561
+ child.setAttribute('attributeSlots', [ref]);
1562
+ flushPendingRefs();
1563
+ expect(ref.current).toMatchObject({ selector: `[ref=${child.instanceId}-0]` });
1564
+ globalCommitContext.ops = [];
1565
+
1566
+ parent.removeChild(child);
1567
+ flushPendingRefs();
1568
+
1569
+ expect(ref.current).toBeNull();
1570
+ });
1571
+
1572
+ it('queues all direct and spread ref cleanups when removing a hydrated subtree', () => {
1573
+ const directRef = vi.fn();
1574
+ const cleanup = vi.fn();
1575
+ const spreadRef = vi.fn(() => cleanup);
1576
+ __etAttrPlanMap.view = [0, adaptRefAttrSlot, 1, adaptSpreadAttrSlot];
1577
+ const parent = new BackgroundElementTemplateInstance('view');
1578
+ const child = new BackgroundElementTemplateInstance('view');
1579
+ parent.appendChild(child);
1580
+
1581
+ markElementTemplateHydrated();
1582
+ parent.markMaterializedByHydration();
1583
+ child.markMaterializedByHydration();
1584
+ child.setAttribute('attributeSlots', [directRef, { ref: spreadRef }]);
1585
+ flushPendingRefs();
1586
+ expect(directRef).toHaveBeenCalledTimes(1);
1587
+ expect(spreadRef).toHaveBeenCalledTimes(1);
1588
+ directRef.mockClear();
1589
+ spreadRef.mockClear();
1590
+
1591
+ parent.removeChild(child);
1592
+ flushPendingRefs();
1593
+
1594
+ expect(cleanup).toHaveBeenCalledTimes(1);
1595
+ expect(spreadRef).not.toHaveBeenCalled();
1596
+ expect(directRef).toHaveBeenCalledWith(null);
1597
+ });
1598
+
1599
+ it('queues nested direct and spread ref cleanup when removing a hydrated subtree', () => {
1600
+ const childCleanup = vi.fn();
1601
+ const childRef = vi.fn(() => childCleanup);
1602
+ const directGrandchildRef = vi.fn();
1603
+ const grandchildCleanup = vi.fn();
1604
+ const grandchildSpreadRef = vi.fn(() => grandchildCleanup);
1605
+ __etAttrPlanMap.view = [0, adaptRefAttrSlot, 1, adaptSpreadAttrSlot];
1606
+ const parent = new BackgroundElementTemplateInstance('view');
1607
+ const child = new BackgroundElementTemplateInstance('view');
1608
+ const grandchild = new BackgroundElementTemplateInstance('view');
1609
+ child.appendChild(grandchild);
1610
+ parent.appendChild(child);
1611
+
1612
+ markElementTemplateHydrated();
1613
+ parent.markMaterializedByHydration();
1614
+ child.markMaterializedByHydration();
1615
+ grandchild.markMaterializedByHydration();
1616
+ child.setAttribute('attributeSlots', [childRef]);
1617
+ grandchild.setAttribute('attributeSlots', [
1618
+ directGrandchildRef,
1619
+ { ref: grandchildSpreadRef },
1620
+ ]);
1621
+ flushPendingRefs();
1622
+ expect(childRef).toHaveBeenCalledTimes(1);
1623
+ expect(directGrandchildRef).toHaveBeenCalledTimes(1);
1624
+ expect(grandchildSpreadRef).toHaveBeenCalledTimes(1);
1625
+ childRef.mockClear();
1626
+ directGrandchildRef.mockClear();
1627
+ grandchildSpreadRef.mockClear();
1628
+ globalCommitContext.ops = [];
1629
+
1630
+ parent.removeChild(child);
1631
+ flushPendingRefs();
1632
+
1633
+ expect(globalCommitContext.ops).toEqual([
1634
+ 4,
1635
+ parent.instanceId,
1636
+ 0,
1637
+ child.instanceId,
1638
+ [child.instanceId, grandchild.instanceId],
1639
+ ]);
1640
+ expect(childCleanup).toHaveBeenCalledTimes(1);
1641
+ expect(grandchildCleanup).toHaveBeenCalledTimes(1);
1642
+ expect(childRef).not.toHaveBeenCalled();
1643
+ expect(grandchildSpreadRef).not.toHaveBeenCalled();
1644
+ expect(directGrandchildRef).toHaveBeenCalledWith(null);
1645
+ });
1646
+
1647
+ it('does not repeat direct function ref cleanup for detached subtrees on destroy', () => {
1648
+ const cleanup = vi.fn();
1649
+ const ref = vi.fn(() => cleanup);
1650
+ __etAttrPlanMap.view = [0, adaptRefAttrSlot];
1651
+ const parent = new BackgroundElementTemplateInstance('view');
1652
+ const child = new BackgroundElementTemplateInstance('view');
1653
+ parent.appendChild(child);
1654
+
1655
+ markElementTemplateHydrated();
1656
+ parent.markMaterializedByHydration();
1657
+ child.markMaterializedByHydration();
1658
+ child.setAttribute('attributeSlots', [ref]);
1659
+ flushPendingRefs();
1660
+ expect(ref).toHaveBeenCalledTimes(1);
1661
+
1662
+ parent.removeChild(child);
1663
+ flushPendingRefs();
1664
+ expect(cleanup).toHaveBeenCalledTimes(1);
1665
+
1666
+ destroyElementTemplateBackgroundRuntime();
1667
+
1668
+ expect(cleanup).toHaveBeenCalledTimes(1);
1669
+ expect(ref).toHaveBeenCalledTimes(1);
1670
+ });
1671
+
1672
+ it('does not emit patches for pre-hydration slot mutations', () => {
1673
+ const parent = new BackgroundElementTemplateInstance('view');
1674
+ const child = new BackgroundElementTemplateInstance('text');
1675
+ const childId = child.instanceId;
1676
+
1677
+ globalCommitContext.ops = [];
1678
+ child.setAttribute('attributeSlots', ['pending']);
1679
+ parent.appendChild(child);
1680
+ parent.removeChild(child);
1681
+
1682
+ expect(parent.childSlots[0]).toBeUndefined();
1683
+ expect(globalCommitContext.ops).toEqual([]);
1684
+ expect([...globalCommitContext.nonPayload.removedSubtreesAwaitingTeardown]).toEqual([]);
1685
+ expect(backgroundElementTemplateInstanceManager.get(childId)).toBeUndefined();
1686
+ });
1687
+
1688
+ it('cleans pre-hydration direct refs when removing a slot child before hydrate', () => {
1689
+ const ref = { current: null };
1690
+ __etAttrPlanMap.view = [0, adaptRefAttrSlot];
1691
+ const parent = new BackgroundElementTemplateInstance('view');
1692
+ const child = new BackgroundElementTemplateInstance('view');
1693
+ const childId = child.instanceId;
1694
+
1695
+ parent.appendChild(child);
1696
+ child.setAttribute('attributeSlots', [ref]);
1697
+ flushPendingRefs();
1698
+ expect(ref.current).toMatchObject({ selector: `[ref=${child.instanceId}-0]` });
1699
+
1700
+ globalCommitContext.ops = [];
1701
+ parent.removeChild(child);
1702
+ flushPendingRefs();
1703
+
1704
+ expect(ref.current).toBeNull();
1705
+ expect(parent.childSlots[0]).toBeUndefined();
1706
+ expect(globalCommitContext.ops).toEqual([]);
1707
+ expect(backgroundElementTemplateInstanceManager.get(childId)).toBeUndefined();
1708
+ });
1709
+
1710
+ it('invokes a callback ref cleanup exactly once on pre-hydration removal', () => {
1711
+ // Regression: an earlier rewrite left a redundant `queueRefCleanupForSubtree`
1712
+ // inside the pre-hydration branch in addition to the unconditional one
1713
+ // emitted at the end of `removeChild`, so callback ref cleanups fired twice.
1714
+ const cleanup = vi.fn();
1715
+ const ref = vi.fn(() => cleanup);
1716
+ __etAttrPlanMap.view = [0, adaptRefAttrSlot];
1717
+ const parent = new BackgroundElementTemplateInstance('view');
1718
+ const child = new BackgroundElementTemplateInstance('view');
1719
+ parent.appendChild(child);
1720
+ child.setAttribute('attributeSlots', [ref]);
1721
+ flushPendingRefs();
1722
+ ref.mockClear();
1723
+
1724
+ parent.removeChild(child);
1725
+ flushPendingRefs();
1726
+
1727
+ expect(cleanup).toHaveBeenCalledTimes(1);
1728
+ expect(ref).not.toHaveBeenCalled();
1729
+ });
1730
+
1731
+ it('supports silent removal from a slot container', () => {
1732
+ const parent = new BackgroundElementTemplateInstance('view');
1733
+ const child = new BackgroundElementTemplateInstance('text');
1734
+ parent.appendChild(child);
1735
+
1736
+ globalCommitContext.ops = [];
1737
+ parent.removeChild(child, true);
1738
+
1739
+ expect(parent.childSlots[0]).toBeUndefined();
1740
+ expect(globalCommitContext.ops).toEqual([]);
1741
+ expect([...globalCommitContext.nonPayload.removedSubtreesAwaitingTeardown]).toEqual([]);
1742
+ });
1743
+ });
1744
+
1745
+ it('should be registered with manager upon creation', () => {
1746
+ const instance = new BackgroundElementTemplateInstance('view');
1747
+ expect(backgroundElementTemplateInstanceManager.get(instance.instanceId)).toBe(instance);
1748
+ });
1749
+
1750
+ it('should tear down correctly', () => {
1751
+ const parent = new BackgroundElementTemplateInstance('view');
1752
+ const child = new BackgroundElementTemplateInstance('text');
1753
+ parent.appendChild(child);
1754
+
1755
+ const parentId = parent.instanceId;
1756
+ const childId = child.instanceId;
1757
+
1758
+ expect(backgroundElementTemplateInstanceManager.get(parentId)).toBe(parent);
1759
+ expect(backgroundElementTemplateInstanceManager.get(childId)).toBe(child);
1760
+
1761
+ parent.tearDown();
1762
+
1763
+ // Check manager clean up
1764
+ expect(backgroundElementTemplateInstanceManager.get(parentId)).toBeUndefined();
1765
+ expect(backgroundElementTemplateInstanceManager.get(childId)).toBeUndefined();
1766
+
1767
+ // Check reference clean up
1768
+ expect(parent.firstChild).toBeNull();
1769
+ expect(child.parent).toBeNull();
1770
+ });
1771
+
1772
+ it('clears direct object refs when removing from the root container', () => {
1773
+ const ref = { current: null };
1774
+ __etAttrPlanMap.view = [0, adaptRefAttrSlot];
1775
+ const root = new BackgroundElementTemplateInstance('root');
1776
+ const instance = new BackgroundElementTemplateInstance('view');
1777
+ backgroundElementTemplateInstanceManager.updateId(instance.instanceId, -2);
1778
+ root.appendChild(instance);
1779
+ instance.markMaterializedByHydration();
1780
+ markElementTemplateHydrated();
1781
+ instance.setAttribute('attributeSlots', [ref]);
1782
+ flushPendingRefs();
1783
+ expect(ref.current).toMatchObject({ selector: '[ref=-2-0]' });
1784
+
1785
+ root.removeChild(instance);
1786
+ flushPendingRefs();
1787
+
1788
+ expect(ref.current).toBeNull();
1789
+ });
1790
+
1791
+ it('reports error for emitCreate with illegal handleId 0 in dev', () => {
1792
+ const lynxObj = globalThis.lynx as typeof lynx & { reportError?: (error: Error) => void };
1793
+ const oldReportError = lynxObj.reportError;
1794
+ const reportErrorSpy = vi.fn();
1795
+ lynxObj.reportError = reportErrorSpy;
1796
+
1797
+ const instance = new BackgroundElementTemplateInstance('view');
1798
+ instance.instanceId = 0;
1799
+ instance.emitCreate();
1800
+
1801
+ expect(reportErrorSpy).toHaveBeenCalledTimes(1);
1802
+
1803
+ lynxObj.reportError = oldReportError;
1804
+ });
1805
+
1806
+ it('does not register the root handle when hydration marks it materialized', () => {
1807
+ const instance = new BackgroundElementTemplateInstance('root');
1808
+ const originalId = instance.instanceId;
1809
+ backgroundElementTemplateInstanceManager.values.delete(originalId);
1810
+ instance.instanceId = 0;
1811
+
1812
+ instance.markMaterializedByHydration();
1813
+
1814
+ expect(backgroundElementTemplateInstanceManager.get(0)).toBeUndefined();
1815
+ expect(backgroundElementTemplateInstanceManager.get(originalId)).toBeUndefined();
1816
+ });
1817
+
1818
+ it('normalizes undefined attributeSlots before emitting create', () => {
1819
+ const instance = new BackgroundElementTemplateInstance('view');
1820
+ instance.setAttribute('attributeSlots', [undefined]);
1821
+ globalCommitContext.ops = [];
1822
+
1823
+ instance.emitCreate();
1824
+
1825
+ expect(globalCommitContext.ops).toEqual([
1826
+ 1,
1827
+ instance.instanceId,
1828
+ 'view',
1829
+ null,
1830
+ [null],
1831
+ [],
1832
+ ]);
1833
+ });
1834
+
1835
+ it('queues direct ref attach when preparing hydrated attribute slots', () => {
1836
+ const ref = vi.fn();
1837
+ __etAttrPlanMap.view = [0, adaptRefAttrSlot];
1838
+ const instance = new BackgroundElementTemplateInstance('view', [ref]);
1839
+ backgroundElementTemplateInstanceManager.updateId(instance.instanceId, -2);
1840
+
1841
+ instance.prepareAttributeSlotsForNative();
1842
+ flushPendingRefs();
1843
+
1844
+ expect(instance.attributeSlots).toEqual(['-2-0']);
1845
+ expect(ref).toHaveBeenCalledWith(expect.objectContaining({
1846
+ selector: '[ref=-2-0]',
1847
+ }));
1848
+ });
1849
+
1850
+ it('queues direct ref changes without emitting native ops when marker is unchanged', () => {
1851
+ const oldRef = vi.fn();
1852
+ const newRef = vi.fn();
1853
+ __etAttrPlanMap.view = [0, adaptRefAttrSlot];
1854
+ const instance = new BackgroundElementTemplateInstance('view');
1855
+ backgroundElementTemplateInstanceManager.updateId(instance.instanceId, -2);
1856
+ instance.markMaterializedByHydration();
1857
+ markElementTemplateHydrated();
1858
+
1859
+ instance.setAttribute('attributeSlots', [oldRef]);
1860
+ flushPendingRefs();
1861
+ oldRef.mockClear();
1862
+ globalCommitContext.ops = [];
1863
+
1864
+ instance.setAttribute('attributeSlots', [newRef]);
1865
+ flushPendingRefs();
1866
+
1867
+ expect(globalCommitContext.ops).toEqual([]);
1868
+ expect(oldRef).toHaveBeenCalledWith(null);
1869
+ expect(newRef).toHaveBeenCalledWith(expect.objectContaining({
1870
+ selector: '[ref=-2-0]',
1871
+ }));
1872
+ });
1873
+
1874
+ it('queues spread ref attach/update/detach from raw ref identity', () => {
1875
+ const oldRef = vi.fn();
1876
+ const newRef = vi.fn();
1877
+ __etAttrPlanMap.view = [0, adaptSpreadAttrSlot];
1878
+ const instance = new BackgroundElementTemplateInstance('view');
1879
+ backgroundElementTemplateInstanceManager.updateId(instance.instanceId, -2);
1880
+ instance.markMaterializedByHydration();
1881
+ markElementTemplateHydrated();
1882
+
1883
+ instance.setAttribute('attributeSlots', [{ id: 'cta', ref: oldRef }]);
1884
+ flushPendingRefs();
1885
+ expect(instance.attributeSlots).toEqual([{ id: 'cta', ref: '-2-0' }]);
1886
+ expect(oldRef).toHaveBeenCalledWith(expect.objectContaining({
1887
+ selector: '[ref=-2-0]',
1888
+ }));
1889
+ oldRef.mockClear();
1890
+ globalCommitContext.ops = [];
1891
+
1892
+ instance.setAttribute('attributeSlots', [{ id: 'cta-next', ref: oldRef }]);
1893
+ flushPendingRefs();
1894
+
1895
+ expect(globalCommitContext.ops).toEqual([
1896
+ ElementTemplateUpdateOps.setAttribute,
1897
+ -2,
1898
+ 0,
1899
+ { id: 'cta-next', ref: '-2-0' },
1900
+ ]);
1901
+ expect(oldRef).not.toHaveBeenCalled();
1902
+ globalCommitContext.ops = [];
1903
+
1904
+ instance.setAttribute('attributeSlots', [{ id: 'cta-next', ref: newRef }]);
1905
+ flushPendingRefs();
1906
+
1907
+ expect(globalCommitContext.ops).toEqual([]);
1908
+ expect(oldRef).toHaveBeenCalledWith(null);
1909
+ expect(newRef).toHaveBeenCalledWith(expect.objectContaining({
1910
+ selector: '[ref=-2-0]',
1911
+ }));
1912
+ newRef.mockClear();
1913
+
1914
+ instance.setAttribute('attributeSlots', [{ id: 'cta-next' }]);
1915
+ flushPendingRefs();
1916
+
1917
+ expect(newRef).toHaveBeenCalledWith(null);
1918
+ });
1919
+
1920
+ it('queues direct and spread refs independently in descriptor order', () => {
1921
+ const directRef = vi.fn();
1922
+ const spreadRef = vi.fn();
1923
+ __etAttrPlanMap.view = [0, adaptRefAttrSlot, 1, adaptSpreadAttrSlot];
1924
+ const instance = new BackgroundElementTemplateInstance('view');
1925
+ backgroundElementTemplateInstanceManager.updateId(instance.instanceId, -2);
1926
+ instance.markMaterializedByHydration();
1927
+ markElementTemplateHydrated();
1928
+
1929
+ instance.setAttribute('attributeSlots', [directRef, { ref: spreadRef }]);
1930
+ flushPendingRefs();
1931
+
1932
+ expect(instance.attributeSlots).toEqual(['-2-0', { ref: '-2-1' }]);
1933
+ expect(directRef).toHaveBeenCalledWith(expect.objectContaining({
1934
+ selector: '[ref=-2-0]',
1935
+ }));
1936
+ expect(spreadRef).toHaveBeenCalledWith(expect.objectContaining({
1937
+ selector: '[ref=-2-1]',
1938
+ }));
1939
+
1940
+ directRef.mockClear();
1941
+ spreadRef.mockClear();
1942
+ instance.setAttribute('attributeSlots', [directRef, {}]);
1943
+ flushPendingRefs();
1944
+
1945
+ expect(spreadRef).toHaveBeenCalledWith(null);
1946
+ expect(directRef).not.toHaveBeenCalled();
1947
+ });
1948
+
1949
+ it.each(['direct', 'spread'])(
1950
+ 'keeps shared %s ref cleanups isolated through hydration, moves and replacement',
1951
+ (kind) => {
1952
+ const cleanupA = vi.fn();
1953
+ const cleanupB = vi.fn();
1954
+ const replacementCleanup = vi.fn();
1955
+ const ref = vi.fn<(value: { selector: string } | null) => () => void>()
1956
+ .mockReturnValueOnce(cleanupA)
1957
+ .mockReturnValueOnce(cleanupB);
1958
+ const replacement = vi.fn(() => replacementCleanup);
1959
+ const slots = (value: unknown) => [kind === 'spread' ? { ref: value } : value];
1960
+ __etAttrPlanMap.view = [0, kind === 'spread' ? adaptSpreadAttrSlot : adaptRefAttrSlot];
1961
+ const parent = new BackgroundElementTemplateInstance('root');
1962
+ const childA = new BackgroundElementTemplateInstance('view');
1963
+ const childB = new BackgroundElementTemplateInstance('view');
1964
+ childA.setAttribute('attributeSlots', slots(ref));
1965
+ childB.setAttribute('attributeSlots', slots(ref));
1966
+ parent.appendChild(childA);
1967
+ parent.appendChild(childB);
1968
+ flushPendingRefs();
1969
+
1970
+ expect(ref).toHaveBeenCalledTimes(2);
1971
+ expect(ref).toHaveBeenNthCalledWith(
1972
+ 1,
1973
+ expect.objectContaining({
1974
+ selector: `[ref=${childA.instanceId}-0]`,
1975
+ }),
1976
+ );
1977
+ expect(ref).toHaveBeenNthCalledWith(
1978
+ 2,
1979
+ expect.objectContaining({
1980
+ selector: `[ref=${childB.instanceId}-0]`,
1981
+ }),
1982
+ );
1983
+ expect(cleanupA).not.toHaveBeenCalled();
1984
+ expect(cleanupB).not.toHaveBeenCalled();
1985
+ const proxyA = ref.mock.calls[0]![0];
1986
+ const proxyB = ref.mock.calls[1]![0];
1987
+
1988
+ hydrateBackground({
1989
+ templateKey: 'root',
1990
+ uid: -1,
1991
+ childSlots: [[
1992
+ {
1993
+ templateKey: 'view',
1994
+ uid: -2,
1995
+ attributeSlots: [kind === 'spread' ? { ref: '-2-0' } : '-2-0'],
1996
+ },
1997
+ {
1998
+ templateKey: 'view',
1999
+ uid: -3,
2000
+ attributeSlots: [kind === 'spread' ? { ref: '-3-0' } : '-3-0'],
2001
+ },
2002
+ ]],
2003
+ }, parent);
2004
+ markElementTemplateHydrated();
2005
+ flushPendingRefs();
2006
+
2007
+ expect(childA.instanceId).toBe(-2);
2008
+ expect(childB.instanceId).toBe(-3);
2009
+ expect(proxyA).toMatchObject({ selector: '[ref=-2-0]' });
2010
+ expect(proxyB).toMatchObject({ selector: '[ref=-3-0]' });
2011
+ expect(ref).toHaveBeenCalledTimes(2);
2012
+ expect(cleanupA).not.toHaveBeenCalled();
2013
+ expect(cleanupB).not.toHaveBeenCalled();
2014
+
2015
+ parent.insertBefore(childB, childA);
2016
+ childA.setAttribute('attributeSlots', slots(ref));
2017
+ childB.setAttribute('attributeSlots', slots(ref));
2018
+ flushPendingRefs();
2019
+
2020
+ expect(ref).toHaveBeenCalledTimes(2);
2021
+ expect(cleanupA).not.toHaveBeenCalled();
2022
+ expect(cleanupB).not.toHaveBeenCalled();
2023
+
2024
+ childA.setAttribute('attributeSlots', slots(replacement));
2025
+ flushPendingRefs();
2026
+
2027
+ expect(cleanupA).toHaveBeenCalledTimes(1);
2028
+ expect(cleanupB).not.toHaveBeenCalled();
2029
+ expect(replacement).toHaveBeenCalledTimes(1);
2030
+ expect(replacement).toHaveBeenCalledWith(expect.objectContaining({ selector: '[ref=-2-0]' }));
2031
+ expect(ref).toHaveBeenCalledTimes(2);
2032
+
2033
+ parent.removeChild(childA);
2034
+ flushPendingRefs();
2035
+
2036
+ expect(replacementCleanup).toHaveBeenCalledTimes(1);
2037
+ expect(cleanupA).toHaveBeenCalledTimes(1);
2038
+ expect(cleanupB).not.toHaveBeenCalled();
2039
+
2040
+ parent.removeChild(childB);
2041
+ flushPendingRefs();
2042
+
2043
+ expect(cleanupB).toHaveBeenCalledTimes(1);
2044
+ expect(cleanupA).toHaveBeenCalledTimes(1);
2045
+ expect(replacementCleanup).toHaveBeenCalledTimes(1);
2046
+ expect(ref).toHaveBeenCalledTimes(2);
2047
+ expect(replacement).toHaveBeenCalledTimes(1);
2048
+ },
2049
+ );
2050
+
2051
+ it('keeps a shared callback cleanup separate for direct and spread slots on the same instance', () => {
2052
+ const directCleanup = vi.fn();
2053
+ const spreadCleanup = vi.fn();
2054
+ const ref = vi.fn()
2055
+ .mockReturnValueOnce(directCleanup)
2056
+ .mockReturnValueOnce(spreadCleanup);
2057
+ __etAttrPlanMap.view = [0, adaptRefAttrSlot, 1, adaptSpreadAttrSlot];
2058
+ const instance = new BackgroundElementTemplateInstance('view');
2059
+ backgroundElementTemplateInstanceManager.updateId(instance.instanceId, -2);
2060
+ instance.markMaterializedByHydration();
2061
+ markElementTemplateHydrated();
2062
+
2063
+ instance.setAttribute('attributeSlots', [ref, { ref }]);
2064
+ flushPendingRefs();
2065
+
2066
+ expect(ref).toHaveBeenCalledTimes(2);
2067
+ expect(ref).toHaveBeenNthCalledWith(1, expect.objectContaining({ selector: '[ref=-2-0]' }));
2068
+ expect(ref).toHaveBeenNthCalledWith(2, expect.objectContaining({ selector: '[ref=-2-1]' }));
2069
+ expect(directCleanup).not.toHaveBeenCalled();
2070
+ expect(spreadCleanup).not.toHaveBeenCalled();
2071
+
2072
+ instance.setAttribute('attributeSlots', [null, { ref }]);
2073
+ flushPendingRefs();
2074
+
2075
+ expect(directCleanup).toHaveBeenCalledTimes(1);
2076
+ expect(spreadCleanup).not.toHaveBeenCalled();
2077
+ expect(ref).toHaveBeenCalledTimes(2);
2078
+
2079
+ instance.setAttribute('attributeSlots', [null, {}]);
2080
+ flushPendingRefs();
2081
+
2082
+ expect(directCleanup).toHaveBeenCalledTimes(1);
2083
+ expect(spreadCleanup).toHaveBeenCalledTimes(1);
2084
+ expect(ref).toHaveBeenCalledTimes(2);
2085
+ });
2086
+
2087
+ it('does not let explicit undefined spread refs detach sibling direct refs', () => {
2088
+ const directRef = vi.fn();
2089
+ __etAttrPlanMap.view = [0, adaptRefAttrSlot, 1, adaptSpreadAttrSlot];
2090
+ const instance = new BackgroundElementTemplateInstance('view');
2091
+ backgroundElementTemplateInstanceManager.updateId(instance.instanceId, -2);
2092
+ instance.markMaterializedByHydration();
2093
+ markElementTemplateHydrated();
2094
+
2095
+ instance.setAttribute('attributeSlots', [directRef, { ref: undefined }]);
2096
+ flushPendingRefs();
2097
+
2098
+ expect(instance.attributeSlots).toEqual(['-2-0', { ref: null }]);
2099
+ expect(directRef).toHaveBeenCalledWith(expect.objectContaining({
2100
+ selector: '[ref=-2-0]',
2101
+ }));
2102
+ });
2103
+
2104
+ it('keeps a stable direct ref attached while spread ref presence changes', () => {
2105
+ const ref = vi.fn();
2106
+ __etAttrPlanMap.view = [0, adaptRefAttrSlot, 1, adaptSpreadAttrSlot];
2107
+ const instance = new BackgroundElementTemplateInstance('view');
2108
+ backgroundElementTemplateInstanceManager.updateId(instance.instanceId, -2);
2109
+ instance.markMaterializedByHydration();
2110
+ markElementTemplateHydrated();
2111
+
2112
+ instance.setAttribute('attributeSlots', [ref, {}]);
2113
+ flushPendingRefs();
2114
+ expect(ref).toHaveBeenCalledWith(expect.objectContaining({
2115
+ selector: '[ref=-2-0]',
2116
+ }));
2117
+ ref.mockClear();
2118
+
2119
+ instance.setAttribute('attributeSlots', [ref, { ref: undefined }]);
2120
+ flushPendingRefs();
2121
+ expect(ref).not.toHaveBeenCalled();
2122
+ ref.mockClear();
2123
+
2124
+ instance.setAttribute('attributeSlots', [ref, {}]);
2125
+ flushPendingRefs();
2126
+
2127
+ expect(instance.attributeSlots).toEqual(['-2-0', {}]);
2128
+ expect(ref).not.toHaveBeenCalled();
2129
+ });
2130
+
2131
+ it('queues spread and later direct refs independently', () => {
2132
+ const spreadRef = vi.fn();
2133
+ const directRef = vi.fn();
2134
+ __etAttrPlanMap.view = [0, adaptSpreadAttrSlot, 1, adaptRefAttrSlot];
2135
+ const instance = new BackgroundElementTemplateInstance('view');
2136
+ backgroundElementTemplateInstanceManager.updateId(instance.instanceId, -2);
2137
+ instance.markMaterializedByHydration();
2138
+ markElementTemplateHydrated();
2139
+
2140
+ instance.setAttribute('attributeSlots', [{ ref: spreadRef }, directRef]);
2141
+ flushPendingRefs();
2142
+
2143
+ expect(instance.attributeSlots).toEqual([{ ref: '-2-0' }, '-2-1']);
2144
+ expect(spreadRef).toHaveBeenCalledWith(expect.objectContaining({
2145
+ selector: '[ref=-2-0]',
2146
+ }));
2147
+ expect(directRef).toHaveBeenCalledWith(expect.objectContaining({
2148
+ selector: '[ref=-2-1]',
2149
+ }));
2150
+ });
2151
+
2152
+ it('ignores legacy create options metadata props', () => {
2153
+ const instance = new BackgroundElementTemplateInstance('view');
2154
+ instance.setAttribute('options', {
2155
+ cssId: 100,
2156
+ entryName: 'lazy-entry',
2157
+ preserveMe: 'kept',
2158
+ });
2159
+ globalCommitContext.ops = [];
2160
+
2161
+ instance.emitCreate();
2162
+
2163
+ expect(globalCommitContext.ops).toEqual([
2164
+ 1,
2165
+ instance.instanceId,
2166
+ 'view',
2167
+ null,
2168
+ [],
2169
+ [],
2170
+ ]);
2171
+ });
2172
+
2173
+ it('does not emit duplicate create ops for the same instance', () => {
2174
+ const instance = new BackgroundElementTemplateInstance('view');
2175
+ globalCommitContext.ops = [];
2176
+
2177
+ instance.emitCreate();
2178
+ instance.emitCreate();
2179
+
2180
+ expect(globalCommitContext.ops).toEqual([
2181
+ 1,
2182
+ instance.instanceId,
2183
+ 'view',
2184
+ null,
2185
+ [],
2186
+ [],
2187
+ ]);
2188
+ });
2189
+
2190
+ it('ignores text writes for non-raw-text instances', () => {
2191
+ const instance = new BackgroundElementTemplateInstance('view');
2192
+ globalCommitContext.ops = [];
2193
+
2194
+ instance.text = 'ignored';
2195
+
2196
+ expect(instance.attributeSlots).toEqual([]);
2197
+ expect(globalCommitContext.ops).toEqual([]);
2198
+ });
2199
+
2200
+ it('defers raw-text patches until inserting a post-hydration text node', () => {
2201
+ const parent = new BackgroundElementTemplateInstance('view');
2202
+ parent.emitCreate();
2203
+
2204
+ markElementTemplateHydrated();
2205
+ globalCommitContext.ops = [];
2206
+
2207
+ const textNode = createTextNode('');
2208
+ textNode.text = 'deferred';
2209
+
2210
+ expect(globalCommitContext.ops).toEqual([]);
2211
+
2212
+ parent.appendChild(textNode);
2213
+
2214
+ expect(globalCommitContext.ops).toEqual([
2215
+ 1,
2216
+ textNode.instanceId,
2217
+ BUILTIN_RAW_TEXT_TEMPLATE_KEY,
2218
+ null,
2219
+ ['deferred'],
2220
+ [],
2221
+ 3,
2222
+ parent.instanceId,
2223
+ 0,
2224
+ textNode.instanceId,
2225
+ 0,
2226
+ null,
2227
+ ]);
2228
+ });
2229
+
2230
+ it('ignores spread-like shadow keys', () => {
2231
+ const instance = new BackgroundElementTemplateInstance('view');
2232
+ instance.setAttribute('__spread', { id: 'ignored' });
2233
+ instance.setAttribute('childSlots', []);
2234
+ instance.setAttribute('children', []);
2235
+
2236
+ expect(instance.attributeSlots).toEqual([]);
2237
+ expect(instance.childSlots).toEqual([]);
2238
+ });
2239
+ });
2240
+
2241
+ describe('Background raw-text instance', () => {
2242
+ it('should have correct type and text', () => {
2243
+ const textNode = createTextNode('hello');
2244
+ expect(textNode.type).toBe(BUILTIN_RAW_TEXT_TEMPLATE_KEY);
2245
+ expect(textNode.text).toBe('hello');
2246
+ expect(textNode.nodeType).toBe(3);
2247
+ expect(textNode.attributeSlots).toEqual(['hello']);
2248
+ });
2249
+
2250
+ it('should update text via setAttribute', () => {
2251
+ const textNode = createTextNode('');
2252
+ textNode.setAttribute('0', 'world');
2253
+ expect(textNode.text).toBe('world');
2254
+ expect(textNode.attributeSlots).toEqual(['world']);
2255
+
2256
+ textNode.setAttribute('data', 'demo');
2257
+ expect(textNode.text).toBe('demo');
2258
+ expect(textNode.attributeSlots).toEqual(['demo']);
2259
+ });
2260
+
2261
+ it('should update text via data property', () => {
2262
+ const textNode = createTextNode('');
2263
+ textNode.data = 'world';
2264
+ expect(textNode.text).toBe('world');
2265
+ expect(textNode.data).toBe('world');
2266
+ });
2267
+
2268
+ it('emits setAttribute when existing raw-text data changes after hydration', () => {
2269
+ const textNode = createTextNode('old');
2270
+ textNode.emitCreate();
2271
+ markElementTemplateHydrated();
2272
+ globalCommitContext.ops = [];
2273
+
2274
+ textNode.data = 'new';
2275
+
2276
+ expect(textNode.attributeSlots).toEqual(['new']);
2277
+ expect(globalCommitContext.ops).toEqual([
2278
+ ElementTemplateUpdateOps.setAttribute,
2279
+ textNode.instanceId,
2280
+ 0,
2281
+ 'new',
2282
+ ]);
2283
+ });
2284
+
2285
+ it('stringifies numeric raw-text slot values', () => {
2286
+ const textNode = new BackgroundElementTemplateInstance(
2287
+ BUILTIN_RAW_TEXT_TEMPLATE_KEY,
2288
+ [1 as unknown as string],
2289
+ );
2290
+ expect(textNode.text).toBe('1');
2291
+ });
2292
+
2293
+ it('does not emit a patch when setting the same text value', () => {
2294
+ const textNode = createTextNode('same');
2295
+ globalCommitContext.ops = [];
2296
+
2297
+ textNode.text = 'same';
2298
+
2299
+ expect(textNode.attributeSlots).toEqual(['same']);
2300
+ expect(globalCommitContext.ops).toEqual([]);
2301
+ });
2302
+
2303
+ it('should ignore non-slot attribute writes on raw-text nodes', () => {
2304
+ const textNode = createTextNode('');
2305
+ textNode.setAttribute('style', { color: 'red' });
2306
+ expect(textNode.attributeSlots).toEqual(['']);
2307
+ });
2308
+ });
2309
+
2310
+ describe('BackgroundElementTemplateInstance Shadow State', () => {
2311
+ beforeEach(() => {
2312
+ globalThis.__MAIN_THREAD__ = false;
2313
+ globalThis.__BACKGROUND__ = true;
2314
+ backgroundElementTemplateInstanceManager.clear();
2315
+ backgroundElementTemplateInstanceManager.nextId = 0;
2316
+ clearEtAttrPlanMap();
2317
+ clearEventState();
2318
+ resetElementTemplateCommitState();
2319
+ });
2320
+
2321
+ it('should cache attributeSlots without decoding compiled template attrs', () => {
2322
+ const instance = new BackgroundElementTemplateInstance('view');
2323
+ const slots = ['logo.png', { id: 'ignored' }] as const;
2324
+
2325
+ instance.setAttribute('attributeSlots', [...slots]);
2326
+
2327
+ expect(instance.attributeSlots).toEqual(slots);
2328
+ });
2329
+
2330
+ it('should update attributeSlots when setAttribute("attributeSlots", ...) is called', () => {
2331
+ const instance = new BackgroundElementTemplateInstance('view');
2332
+ const slots = [{ id: 'a' }, { class: 'foo' }] as const;
2333
+ instance.setAttribute('attributeSlots', [...slots]);
2334
+
2335
+ expect(instance.attributeSlots).toEqual(slots);
2336
+ });
2337
+
2338
+ it.each([false, true])('does not serialize attributes before materialization (hydrated=%s)', (isHydrated) => {
2339
+ const instance = new BackgroundElementTemplateInstance('view', [{ id: 'before' }]);
2340
+ if (isHydrated) {
2341
+ markElementTemplateHydrated();
2342
+ }
2343
+ const nextSlots = [{ id: 'after' }];
2344
+ const stringify = vi.spyOn(JSON, 'stringify');
2345
+ try {
2346
+ instance.setAttribute('attributeSlots', nextSlots);
2347
+
2348
+ expect(stringify).not.toHaveBeenCalled();
2349
+ } finally {
2350
+ stringify.mockRestore();
2351
+ }
2352
+ expect(instance.attributeSlots).toEqual(nextSlots);
2353
+ expect(globalCommitContext.ops).toEqual([]);
2354
+
2355
+ const root = new BackgroundPageRootInstance();
2356
+ markElementTemplateHydrated();
2357
+ root.appendChild(instance);
2358
+
2359
+ expect(globalCommitContext.ops).toEqual([
2360
+ ElementTemplateUpdateOps.createTemplate,
2361
+ instance.instanceId,
2362
+ 'view',
2363
+ null,
2364
+ nextSlots,
2365
+ [],
2366
+ ElementTemplateUpdateOps.insertNode,
2367
+ root.instanceId,
2368
+ 0,
2369
+ instance.instanceId,
2370
+ 0,
2371
+ null,
2372
+ ]);
2373
+ });
2374
+
2375
+ it('keeps raw initial planned attribute slots for later native prepare', () => {
2376
+ __etAttrPlanMap.view = [0, adaptEventAttrSlot];
2377
+ const instance = new BackgroundElementTemplateInstance('view', [true]);
2378
+ instance.instanceId = -10;
2379
+
2380
+ instance.prepareAttributeSlotsForNative();
2381
+
2382
+ expect(instance.attributeSlots).toEqual(['-10:0:']);
2383
+ });
2384
+
2385
+ it('emits null when an existing attribute slot is removed after hydration', () => {
2386
+ const instance = new BackgroundElementTemplateInstance('view', ['old']);
2387
+ instance.emitCreate();
2388
+ markElementTemplateHydrated();
2389
+ globalCommitContext.ops = [];
2390
+
2391
+ instance.setAttribute('attributeSlots', []);
2392
+
2393
+ expect(instance.attributeSlots).toEqual([]);
2394
+ expect(globalCommitContext.ops).toEqual([
2395
+ ElementTemplateUpdateOps.setAttribute,
2396
+ instance.instanceId,
2397
+ 0,
2398
+ null,
2399
+ ]);
2400
+ });
2401
+
2402
+ it('does not patch equivalent null and undefined attribute slots after hydration', () => {
2403
+ const instance = new BackgroundElementTemplateInstance('view', [null]);
2404
+ instance.emitCreate();
2405
+ markElementTemplateHydrated();
2406
+ globalCommitContext.ops = [];
2407
+
2408
+ instance.setAttribute('attributeSlots', [undefined]);
2409
+
2410
+ expect(instance.attributeSlots).toEqual([null]);
2411
+ expect(globalCommitContext.ops).toEqual([]);
2412
+ });
2413
+
2414
+ it('prepares event attribute slots after hydration and resolves the handler by event value', () => {
2415
+ __etAttrPlanMap.view = [0, adaptEventAttrSlot];
2416
+ const instance = new BackgroundElementTemplateInstance('view');
2417
+ instance.emitCreate();
2418
+ markElementTemplateHydrated();
2419
+ globalCommitContext.ops = [];
2420
+
2421
+ const handler = vi.fn();
2422
+ instance.setAttribute('attributeSlots', [handler]);
2423
+
2424
+ const eventValue = `${instance.instanceId}:0:`;
2425
+ expect(instance.attributeSlots).toEqual([eventValue]);
2426
+ expect(getEventHandlerForEventValue(eventValue)).toBe(handler);
2427
+ expect(globalCommitContext.ops).toEqual([
2428
+ ElementTemplateUpdateOps.setAttribute,
2429
+ instance.instanceId,
2430
+ 0,
2431
+ eventValue,
2432
+ ]);
2433
+ });
2434
+
2435
+ it('uses the latest raw event handler without patching native when the event value is unchanged', () => {
2436
+ __etAttrPlanMap.view = [0, adaptEventAttrSlot];
2437
+ const instance = new BackgroundElementTemplateInstance('view');
2438
+ instance.emitCreate();
2439
+ markElementTemplateHydrated();
2440
+
2441
+ const firstHandler = vi.fn();
2442
+ const secondHandler = vi.fn();
2443
+ instance.setAttribute('attributeSlots', [firstHandler]);
2444
+ globalCommitContext.ops = [];
2445
+
2446
+ instance.setAttribute('attributeSlots', [secondHandler]);
2447
+
2448
+ const eventValue = `${instance.instanceId}:0:`;
2449
+ expect(instance.attributeSlots).toEqual([eventValue]);
2450
+ expect(getEventHandlerForEventValue(eventValue)).toBe(secondHandler);
2451
+ expect(globalCommitContext.ops).toEqual([]);
2452
+ });
2453
+
2454
+ it('drops a stale handler when an event slot becomes a non-function marker', () => {
2455
+ __etAttrPlanMap.view = [0, adaptEventAttrSlot];
2456
+ const instance = new BackgroundElementTemplateInstance('view');
2457
+ instance.emitCreate();
2458
+ markElementTemplateHydrated();
2459
+
2460
+ const handler = vi.fn();
2461
+ instance.setAttribute('attributeSlots', [handler]);
2462
+ const eventValue = `${instance.instanceId}:0:`;
2463
+ globalCommitContext.ops = [];
2464
+
2465
+ instance.setAttribute('attributeSlots', [true]);
2466
+
2467
+ expect(instance.attributeSlots).toEqual([eventValue]);
2468
+ expect(getEventHandlerForEventValue(eventValue)).toBeUndefined();
2469
+ expect(globalCommitContext.ops).toEqual([]);
2470
+ });
2471
+
2472
+ it('removes the raw event handler and patches null when the event slot is cleared', () => {
2473
+ __etAttrPlanMap.view = [0, adaptEventAttrSlot];
2474
+ const instance = new BackgroundElementTemplateInstance('view');
2475
+ instance.emitCreate();
2476
+ markElementTemplateHydrated();
2477
+
2478
+ const handler = vi.fn();
2479
+ instance.setAttribute('attributeSlots', [handler]);
2480
+ const eventValue = `${instance.instanceId}:0:`;
2481
+ globalCommitContext.ops = [];
2482
+
2483
+ instance.setAttribute('attributeSlots', [false]);
2484
+
2485
+ expect(instance.attributeSlots).toEqual([null]);
2486
+ expect(getEventHandlerForEventValue(eventValue)).toBeUndefined();
2487
+ expect(globalCommitContext.ops).toEqual([
2488
+ ElementTemplateUpdateOps.setAttribute,
2489
+ instance.instanceId,
2490
+ 0,
2491
+ null,
2492
+ ]);
2493
+ });
2494
+
2495
+ it('emits prepared event values instead of handler functions in create payloads', () => {
2496
+ __etAttrPlanMap.view = [0, adaptEventAttrSlot];
2497
+ markElementTemplateHydrated();
2498
+ const instance = new BackgroundElementTemplateInstance('view');
2499
+ const handler = vi.fn();
2500
+ instance.setAttribute('attributeSlots', [handler]);
2501
+ globalCommitContext.ops = [];
2502
+
2503
+ instance.emitCreate();
2504
+
2505
+ const eventValue = `${instance.instanceId}:0:`;
2506
+ expect(getEventHandlerForEventValue(eventValue)).toBe(handler);
2507
+ expect(globalCommitContext.ops).toEqual([
2508
+ ElementTemplateUpdateOps.createTemplate,
2509
+ instance.instanceId,
2510
+ 'view',
2511
+ null,
2512
+ [eventValue],
2513
+ [],
2514
+ ]);
2515
+ });
2516
+
2517
+ it('clears event handlers owned by an instance when it is torn down', () => {
2518
+ __etAttrPlanMap.view = [0, adaptEventAttrSlot];
2519
+ markElementTemplateHydrated();
2520
+ const instance = new BackgroundElementTemplateInstance('view');
2521
+ const handler = vi.fn();
2522
+ instance.setAttribute('attributeSlots', [handler]);
2523
+ const eventValue = `${instance.instanceId}:0:`;
2524
+
2525
+ instance.tearDown();
2526
+
2527
+ expect(getEventHandlerForEventValue(eventValue)).toBeUndefined();
2528
+ });
2529
+
2530
+ it('clears event handlers when the background runtime is destroyed', () => {
2531
+ __etAttrPlanMap.view = [0, adaptEventAttrSlot];
2532
+ markElementTemplateHydrated();
2533
+ const instance = new BackgroundElementTemplateInstance('view');
2534
+ const handler = vi.fn();
2535
+ instance.setAttribute('attributeSlots', [handler]);
2536
+ const eventValue = `${instance.instanceId}:0:`;
2537
+
2538
+ destroyElementTemplateBackgroundRuntime();
2539
+
2540
+ expect(getEventHandlerForEventValue(eventValue)).toBeUndefined();
2541
+ });
2542
+
2543
+ it('prepares spread event keys after hydration and registers handlers by event value', () => {
2544
+ __etAttrPlanMap.view = [0, adaptSpreadAttrSlot];
2545
+ const instance = new BackgroundElementTemplateInstance('view');
2546
+ instance.emitCreate();
2547
+ markElementTemplateHydrated();
2548
+ globalCommitContext.ops = [];
2549
+
2550
+ const handleTap = vi.fn();
2551
+ const handleTouch = vi.fn();
2552
+ instance.setAttribute('attributeSlots', [{
2553
+ id: 'cta',
2554
+ bindtap: handleTap,
2555
+ catchtouchstart: handleTouch,
2556
+ }]);
2557
+
2558
+ const bindtapValue = `${instance.instanceId}:0:bindtap`;
2559
+ const catchTouchValue = `${instance.instanceId}:0:catchtouchstart`;
2560
+ const preparedSpread = {
2561
+ id: 'cta',
2562
+ bindtap: bindtapValue,
2563
+ catchtouchstart: catchTouchValue,
2564
+ };
2565
+ expect(instance.attributeSlots).toEqual([preparedSpread]);
2566
+ expect(getEventHandlerForEventValue(bindtapValue)).toBe(handleTap);
2567
+ expect(getEventHandlerForEventValue(catchTouchValue)).toBe(handleTouch);
2568
+ expect(globalCommitContext.ops).toEqual([
2569
+ ElementTemplateUpdateOps.setAttribute,
2570
+ instance.instanceId,
2571
+ 0,
2572
+ preparedSpread,
2573
+ ]);
2574
+ });
2575
+
2576
+ it('updates spread event handlers without patching native when the prepared spread value is unchanged', () => {
2577
+ __etAttrPlanMap.view = [0, adaptSpreadAttrSlot];
2578
+ const instance = new BackgroundElementTemplateInstance('view');
2579
+ instance.emitCreate();
2580
+ markElementTemplateHydrated();
2581
+
2582
+ const firstHandler = vi.fn();
2583
+ const secondHandler = vi.fn();
2584
+ instance.setAttribute('attributeSlots', [{ id: 'cta', bindtap: firstHandler }]);
2585
+ globalCommitContext.ops = [];
2586
+
2587
+ instance.setAttribute('attributeSlots', [{ id: 'cta', bindtap: secondHandler }]);
2588
+
2589
+ const eventValue = `${instance.instanceId}:0:bindtap`;
2590
+ expect(instance.attributeSlots).toEqual([{ id: 'cta', bindtap: eventValue }]);
2591
+ expect(getEventHandlerForEventValue(eventValue)).toBe(secondHandler);
2592
+ expect(globalCommitContext.ops).toEqual([]);
2593
+ });
2594
+
2595
+ it('patches the whole spread slot when event keys change and cleans removed handlers', () => {
2596
+ __etAttrPlanMap.view = [0, adaptSpreadAttrSlot];
2597
+ const instance = new BackgroundElementTemplateInstance('view');
2598
+ instance.emitCreate();
2599
+ markElementTemplateHydrated();
2600
+
2601
+ const handleTap = vi.fn();
2602
+ const handleTouch = vi.fn();
2603
+ instance.setAttribute('attributeSlots', [{ id: 'cta', bindtap: handleTap }]);
2604
+ const removedEventValue = `${instance.instanceId}:0:bindtap`;
2605
+ globalCommitContext.ops = [];
2606
+
2607
+ instance.setAttribute('attributeSlots', [{ id: 'cta', catchtouchstart: handleTouch }]);
2608
+
2609
+ const nextEventValue = `${instance.instanceId}:0:catchtouchstart`;
2610
+ const preparedSpread = { id: 'cta', catchtouchstart: nextEventValue };
2611
+ expect(instance.attributeSlots).toEqual([preparedSpread]);
2612
+ expect(getEventHandlerForEventValue(removedEventValue)).toBeUndefined();
2613
+ expect(getEventHandlerForEventValue(nextEventValue)).toBe(handleTouch);
2614
+ expect(globalCommitContext.ops).toEqual([
2615
+ ElementTemplateUpdateOps.setAttribute,
2616
+ instance.instanceId,
2617
+ 0,
2618
+ preparedSpread,
2619
+ ]);
2620
+ });
2621
+
2622
+ it('emits prepared spread values instead of handler functions in create payloads', () => {
2623
+ __etAttrPlanMap.view = [0, adaptSpreadAttrSlot];
2624
+ markElementTemplateHydrated();
2625
+ const instance = new BackgroundElementTemplateInstance('view');
2626
+ const handleTap = vi.fn();
2627
+ instance.setAttribute('attributeSlots', [{ id: 'cta', bindtap: handleTap }]);
2628
+ globalCommitContext.ops = [];
2629
+
2630
+ instance.emitCreate();
2631
+
2632
+ const eventValue = `${instance.instanceId}:0:bindtap`;
2633
+ const preparedSpread = { id: 'cta', bindtap: eventValue };
2634
+ expect(getEventHandlerForEventValue(eventValue)).toBe(handleTap);
2635
+ expect(globalCommitContext.ops).toEqual([
2636
+ ElementTemplateUpdateOps.createTemplate,
2637
+ instance.instanceId,
2638
+ 'view',
2639
+ null,
2640
+ [preparedSpread],
2641
+ [],
2642
+ ]);
2643
+ });
2644
+
2645
+ it('clears spread event handlers owned by an instance when it is torn down', () => {
2646
+ __etAttrPlanMap.view = [0, adaptSpreadAttrSlot];
2647
+ markElementTemplateHydrated();
2648
+ const instance = new BackgroundElementTemplateInstance('view');
2649
+ const handleTap = vi.fn();
2650
+ instance.setAttribute('attributeSlots', [{ bindtap: handleTap }]);
2651
+ const eventValue = `${instance.instanceId}:0:bindtap`;
2652
+
2653
+ instance.tearDown();
2654
+
2655
+ expect(getEventHandlerForEventValue(eventValue)).toBeUndefined();
2656
+ });
2657
+
2658
+ it('clears spread event handlers when the background runtime is destroyed', () => {
2659
+ __etAttrPlanMap.view = [0, adaptSpreadAttrSlot];
2660
+ markElementTemplateHydrated();
2661
+ const instance = new BackgroundElementTemplateInstance('view');
2662
+ const handleTap = vi.fn();
2663
+ instance.setAttribute('attributeSlots', [{ bindtap: handleTap }]);
2664
+ const eventValue = `${instance.instanceId}:0:bindtap`;
2665
+
2666
+ destroyElementTemplateBackgroundRuntime();
2667
+
2668
+ expect(getEventHandlerForEventValue(eventValue)).toBeUndefined();
2669
+ });
2670
+ });
2671
+
2672
+ describe('BackgroundElementTemplateInstance slot-index children', () => {
2673
+ it('should clear the previous slot index when partId changes after attachment', () => {
2674
+ const root = new BackgroundElementTemplateInstance('element-template-view');
2675
+ const text = createTextNode('move');
2676
+
2677
+ root.appendChild(text);
2678
+
2679
+ text.__slotIndex = 1;
2680
+
2681
+ expect(root.childSlots[0]).toBeUndefined();
2682
+ expect(root.childSlots[1]).toEqual([text]);
2683
+ });
2684
+
2685
+ it('should keep childSlots in sync when slot is attached after children exist', () => {
2686
+ const root = new BackgroundElementTemplateInstance('element-template-view');
2687
+ const text = createTextNode('late');
2688
+
2689
+ text.__slotIndex = 2;
2690
+ root.appendChild(text);
2691
+
2692
+ expect(root.childSlots[2]).toEqual([text]);
2693
+ });
2694
+
2695
+ it('should move slot children to the new slot index when partId changes', () => {
2696
+ const root = new BackgroundElementTemplateInstance('element-template-view');
2697
+ const text = createTextNode('move');
2698
+
2699
+ text.__slotIndex = 0;
2700
+ root.appendChild(text);
2701
+ text.__slotIndex = 3;
2702
+
2703
+ expect(root.childSlots[0]).toBeUndefined();
2704
+ expect(root.childSlots[3]).toEqual([text]);
2705
+ });
2706
+
2707
+ it('should detach a moved child from the old slot shadow state when silent reparenting', () => {
2708
+ const root = new BackgroundElementTemplateInstance('element-template-view');
2709
+ const text = createTextNode('move');
2710
+
2711
+ root.appendChild(text);
2712
+
2713
+ text.__slotIndex = 1;
2714
+ root.insertBefore(text, null, true);
2715
+
2716
+ expect(root.childSlots[0]).toBeUndefined();
2717
+ expect(root.childSlots[1]).toEqual([text]);
2718
+ expect(root.firstChild).toBe(text);
2719
+ });
2720
+
2721
+ it('should detach a moved child from the old parent slot shadow state', () => {
2722
+ const rootA = new BackgroundElementTemplateInstance('element-template-view');
2723
+ const rootB = new BackgroundElementTemplateInstance('element-template-view');
2724
+ const text = createTextNode('move');
2725
+
2726
+ rootA.appendChild(text);
2727
+
2728
+ rootB.insertBefore(text, null, true);
2729
+
2730
+ expect(rootA.childSlots).toEqual([]);
2731
+ expect(rootB.firstChild).toBe(text);
2732
+ });
2733
+
2734
+ it('should append to childSlots', () => {
2735
+ const root = new BackgroundElementTemplateInstance('element-template-view');
2736
+ const view = new BackgroundElementTemplateInstance('view');
2737
+ root.appendChild(view);
2738
+
2739
+ expect(root.childSlots[0]).toEqual([view]);
2740
+ });
2741
+
2742
+ it('should append to childSlots with custom slot index', () => {
2743
+ const root = new BackgroundElementTemplateInstance('element-template-view');
2744
+ const text = createTextNode('Hello');
2745
+ text.__slotIndex = 1;
2746
+ root.appendChild(text);
2747
+
2748
+ expect(root.childSlots[0]).toBeUndefined();
2749
+ expect(root.childSlots[1]).toEqual([text]);
2750
+ });
2751
+ });