@lynx-js/react 0.121.0 → 0.121.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 (167) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/package.json +2 -2
  3. package/runtime/lib/core/commit-context.d.ts +8 -0
  4. package/runtime/lib/core/commit-context.js +18 -0
  5. package/runtime/lib/core/commit-context.js.map +1 -0
  6. package/runtime/lib/core/forceRootRender.d.ts +7 -0
  7. package/runtime/lib/core/forceRootRender.js +40 -0
  8. package/runtime/lib/core/forceRootRender.js.map +1 -0
  9. package/runtime/lib/core/globalProps.d.ts +31 -0
  10. package/runtime/lib/core/globalProps.js +55 -0
  11. package/runtime/lib/core/globalProps.js.map +1 -0
  12. package/runtime/lib/core/hooks/useLynxGlobalEventListener.js +1 -1
  13. package/runtime/lib/core/hooks/useLynxGlobalEventListener.js.map +1 -1
  14. package/runtime/lib/{snapshot/compat → core}/initData.d.ts +1 -1
  15. package/runtime/lib/{snapshot/compat → core}/initData.js +4 -5
  16. package/runtime/lib/core/initData.js.map +1 -0
  17. package/runtime/lib/core/lynx-data-processors.d.ts +2 -0
  18. package/runtime/lib/core/lynx-data-processors.js +53 -0
  19. package/runtime/lib/core/lynx-data-processors.js.map +1 -0
  20. package/runtime/lib/core/lynx-page-data.d.ts +1 -0
  21. package/runtime/lib/core/lynx-page-data.js +14 -0
  22. package/runtime/lib/core/lynx-page-data.js.map +1 -0
  23. package/runtime/lib/core/lynx-update-data.d.ts +11 -0
  24. package/runtime/lib/core/lynx-update-data.js +21 -0
  25. package/runtime/lib/core/lynx-update-data.js.map +1 -0
  26. package/runtime/lib/core/ref.d.ts +37 -0
  27. package/runtime/lib/core/ref.js +108 -0
  28. package/runtime/lib/core/ref.js.map +1 -0
  29. package/runtime/lib/core/reload-version.d.ts +2 -0
  30. package/runtime/lib/{snapshot/lifecycle/pass.js → core/reload-version.js} +4 -5
  31. package/runtime/lib/core/reload-version.js.map +1 -0
  32. package/runtime/lib/element-template/background/attr-slots.d.ts +6 -1
  33. package/runtime/lib/element-template/background/attr-slots.js +35 -2
  34. package/runtime/lib/element-template/background/attr-slots.js.map +1 -1
  35. package/runtime/lib/element-template/background/commit-context.d.ts +3 -3
  36. package/runtime/lib/element-template/background/commit-context.js +15 -18
  37. package/runtime/lib/element-template/background/commit-context.js.map +1 -1
  38. package/runtime/lib/element-template/background/commit-hook.d.ts +1 -1
  39. package/runtime/lib/element-template/background/commit-hook.js +66 -41
  40. package/runtime/lib/element-template/background/commit-hook.js.map +1 -1
  41. package/runtime/lib/element-template/background/destroy.js +9 -6
  42. package/runtime/lib/element-template/background/destroy.js.map +1 -1
  43. package/runtime/lib/element-template/background/document.js +1 -7
  44. package/runtime/lib/element-template/background/document.js.map +1 -1
  45. package/runtime/lib/element-template/background/hydrate.d.ts +1 -1
  46. package/runtime/lib/element-template/background/hydrate.js +53 -36
  47. package/runtime/lib/element-template/background/hydrate.js.map +1 -1
  48. package/runtime/lib/element-template/background/hydration-listener.js +55 -9
  49. package/runtime/lib/element-template/background/hydration-listener.js.map +1 -1
  50. package/runtime/lib/element-template/background/instance.d.ts +12 -10
  51. package/runtime/lib/element-template/background/instance.js +113 -115
  52. package/runtime/lib/element-template/background/instance.js.map +1 -1
  53. package/runtime/lib/element-template/client/root.d.ts +7 -0
  54. package/runtime/lib/element-template/client/root.js +3 -6
  55. package/runtime/lib/element-template/client/root.js.map +1 -1
  56. package/runtime/lib/element-template/debug/alog.d.ts +7 -0
  57. package/runtime/lib/element-template/debug/alog.js +10 -0
  58. package/runtime/lib/element-template/debug/alog.js.map +1 -1
  59. package/runtime/lib/element-template/debug/elementPAPICall.js +4 -0
  60. package/runtime/lib/element-template/debug/elementPAPICall.js.map +1 -1
  61. package/runtime/lib/element-template/hydration-map.d.ts +5 -0
  62. package/runtime/lib/element-template/hydration-map.js +12 -0
  63. package/runtime/lib/element-template/hydration-map.js.map +1 -0
  64. package/runtime/lib/element-template/index.d.ts +22 -1
  65. package/runtime/lib/element-template/index.js +32 -2
  66. package/runtime/lib/element-template/index.js.map +1 -1
  67. package/runtime/lib/element-template/internal.d.ts +1 -1
  68. package/runtime/lib/element-template/internal.js +2 -3
  69. package/runtime/lib/element-template/internal.js.map +1 -1
  70. package/runtime/lib/element-template/lynx/env.js +5 -48
  71. package/runtime/lib/element-template/lynx/env.js.map +1 -1
  72. package/runtime/lib/element-template/native/index.d.ts +1 -1
  73. package/runtime/lib/element-template/native/index.js +28 -2
  74. package/runtime/lib/element-template/native/index.js.map +1 -1
  75. package/runtime/lib/element-template/native/main-thread-api.js +27 -5
  76. package/runtime/lib/element-template/native/main-thread-api.js.map +1 -1
  77. package/runtime/lib/element-template/native/patch-listener.js +5 -1
  78. package/runtime/lib/element-template/native/patch-listener.js.map +1 -1
  79. package/runtime/lib/element-template/native/reload.d.ts +2 -0
  80. package/runtime/lib/element-template/native/reload.js +64 -0
  81. package/runtime/lib/element-template/native/reload.js.map +1 -0
  82. package/runtime/lib/element-template/prop-adapters/event.d.ts +1 -0
  83. package/runtime/lib/element-template/prop-adapters/event.js +4 -1
  84. package/runtime/lib/element-template/prop-adapters/event.js.map +1 -1
  85. package/runtime/lib/element-template/prop-adapters/ref.d.ts +26 -0
  86. package/runtime/lib/element-template/prop-adapters/ref.js +107 -0
  87. package/runtime/lib/element-template/prop-adapters/ref.js.map +1 -0
  88. package/runtime/lib/element-template/prop-adapters/spread.js +8 -1
  89. package/runtime/lib/element-template/prop-adapters/spread.js.map +1 -1
  90. package/runtime/lib/element-template/protocol/opcodes.d.ts +1 -0
  91. package/runtime/lib/element-template/protocol/opcodes.js +1 -0
  92. package/runtime/lib/element-template/protocol/opcodes.js.map +1 -1
  93. package/runtime/lib/element-template/protocol/types.d.ts +50 -2
  94. package/runtime/lib/element-template/runtime/page/page.d.ts +5 -2
  95. package/runtime/lib/element-template/runtime/page/page.js +12 -0
  96. package/runtime/lib/element-template/runtime/page/page.js.map +1 -1
  97. package/runtime/lib/element-template/runtime/patch.js +70 -1
  98. package/runtime/lib/element-template/runtime/patch.js.map +1 -1
  99. package/runtime/lib/element-template/runtime/render/render-main-thread.d.ts +3 -1
  100. package/runtime/lib/element-template/runtime/render/render-main-thread.js +25 -7
  101. package/runtime/lib/element-template/runtime/render/render-main-thread.js.map +1 -1
  102. package/runtime/lib/element-template/runtime/render/render-to-opcodes.js +9 -3
  103. package/runtime/lib/element-template/runtime/render/render-to-opcodes.js.map +1 -1
  104. package/runtime/lib/element-template/runtime/template/attr-slot-plan.d.ts +1 -0
  105. package/runtime/lib/element-template/runtime/template/attr-slot-plan.js +4 -0
  106. package/runtime/lib/element-template/runtime/template/attr-slot-plan.js.map +1 -1
  107. package/runtime/lib/element-template/runtime/template/handle.js +0 -1
  108. package/runtime/lib/element-template/runtime/template/handle.js.map +1 -1
  109. package/runtime/lib/element-template/runtime/template/registry.js +1 -1
  110. package/runtime/lib/element-template/runtime/template/registry.js.map +1 -1
  111. package/runtime/lib/internal.d.ts +1 -1
  112. package/runtime/lib/internal.js +1 -1
  113. package/runtime/lib/internal.js.map +1 -1
  114. package/runtime/lib/lynx-api.d.ts +3 -8
  115. package/runtime/lib/lynx-api.js +8 -45
  116. package/runtime/lib/lynx-api.js.map +1 -1
  117. package/runtime/lib/snapshot/debug/vnodeSource.js +1 -1
  118. package/runtime/lib/snapshot/debug/vnodeSource.js.map +1 -1
  119. package/runtime/lib/snapshot/lifecycle/patch/commit.d.ts +0 -1
  120. package/runtime/lib/snapshot/lifecycle/patch/commit.js +3 -8
  121. package/runtime/lib/snapshot/lifecycle/patch/commit.js.map +1 -1
  122. package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js +1 -1
  123. package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js.map +1 -1
  124. package/runtime/lib/snapshot/lifecycle/ref/delay.d.ts +6 -13
  125. package/runtime/lib/snapshot/lifecycle/ref/delay.js +9 -30
  126. package/runtime/lib/snapshot/lifecycle/ref/delay.js.map +1 -1
  127. package/runtime/lib/snapshot/lifecycle/reload.js +2 -2
  128. package/runtime/lib/snapshot/lifecycle/reload.js.map +1 -1
  129. package/runtime/lib/snapshot/list/list.js +1 -1
  130. package/runtime/lib/snapshot/list/list.js.map +1 -1
  131. package/runtime/lib/snapshot/list/listUpdateInfo.js +3 -2
  132. package/runtime/lib/snapshot/list/listUpdateInfo.js.map +1 -1
  133. package/runtime/lib/snapshot/lynx/calledByNative.js +2 -8
  134. package/runtime/lib/snapshot/lynx/calledByNative.js.map +1 -1
  135. package/runtime/lib/snapshot/lynx/component.js +2 -2
  136. package/runtime/lib/snapshot/lynx/component.js.map +1 -1
  137. package/runtime/lib/snapshot/lynx/env.js +5 -51
  138. package/runtime/lib/snapshot/lynx/env.js.map +1 -1
  139. package/runtime/lib/snapshot/lynx/runWithForce.js +9 -39
  140. package/runtime/lib/snapshot/lynx/runWithForce.js.map +1 -1
  141. package/runtime/lib/snapshot/lynx/tt.js +9 -29
  142. package/runtime/lib/snapshot/lynx/tt.js.map +1 -1
  143. package/runtime/lib/snapshot/snapshot/backgroundSnapshot.js +3 -3
  144. package/runtime/lib/snapshot/snapshot/backgroundSnapshot.js.map +1 -1
  145. package/runtime/lib/snapshot/snapshot/list.js +1 -1
  146. package/runtime/lib/snapshot/snapshot/list.js.map +1 -1
  147. package/runtime/lib/snapshot/snapshot/ref.d.ts +3 -5
  148. package/runtime/lib/snapshot/snapshot/ref.js +16 -59
  149. package/runtime/lib/snapshot/snapshot/ref.js.map +1 -1
  150. package/runtime/lib/snapshot/snapshot/snapshotInstanceHydrationMap.js +1 -1
  151. package/runtime/lib/snapshot/snapshot/snapshotInstanceHydrationMap.js.map +1 -1
  152. package/runtime/lib/tsconfig.tsbuildinfo +1 -1
  153. package/runtime/lib/worklet-runtime/workletRuntime.js +1 -1
  154. package/runtime/lib/worklet-runtime/workletRuntime.js.map +1 -1
  155. package/runtime/worklet-runtime/dev.js +2 -2
  156. package/testing-library/dist/env/index.js +2 -8
  157. package/testing-library/dist/plugins/index.js +12 -1
  158. package/transform/dist/wasm.cjs +1 -1
  159. package/runtime/lib/element-template/hooks/react.d.ts +0 -14
  160. package/runtime/lib/element-template/hooks/react.js +0 -24
  161. package/runtime/lib/element-template/hooks/react.js.map +0 -1
  162. package/runtime/lib/element-template/runtime/components/slot.d.ts +0 -1
  163. package/runtime/lib/element-template/runtime/components/slot.js +0 -11
  164. package/runtime/lib/element-template/runtime/components/slot.js.map +0 -1
  165. package/runtime/lib/snapshot/compat/initData.js.map +0 -1
  166. package/runtime/lib/snapshot/lifecycle/pass.d.ts +0 -3
  167. package/runtime/lib/snapshot/lifecycle/pass.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @lynx-js/react
2
2
 
3
+ ## 0.121.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Disable vnode reuse of different slot index in preact's diff, fixing a bug that `__RemoveElement` was called with mismatched parent and child element. ([#2664](https://github.com/lynx-family/lynx-stack/pull/2664))
8
+
9
+ - Fix list update indices when existing items are updated after inserting siblings before them. ([#2518](https://github.com/lynx-family/lynx-stack/pull/2518))
10
+
3
11
  ## 0.121.0
4
12
 
5
13
  ### Minor Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/react",
3
- "version": "0.121.0",
3
+ "version": "0.121.1",
4
4
  "description": "ReactLynx is a framework for developing Lynx applications with familiar React.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -220,7 +220,7 @@
220
220
  "README.zh.md"
221
221
  ],
222
222
  "dependencies": {
223
- "preact": "npm:@lynx-js/internal-preact@10.29.1-20260424024911-12b794f"
223
+ "preact": "npm:@lynx-js/internal-preact@10.29.1-20260519060144-e6da44c"
224
224
  },
225
225
  "devDependencies": {
226
226
  "@lynx-js/types": "3.7.0",
@@ -0,0 +1,8 @@
1
+ export interface GlobalCommitContext<Ops = unknown[]> {
2
+ ops: Ops;
3
+ flushOptions: FlushOptions;
4
+ flowIds?: number[];
5
+ }
6
+ export declare const globalCommitContext: GlobalCommitContext;
7
+ export declare function resetGlobalCommitContext(): void;
8
+ export declare function takeGlobalFlushOptions(): FlushOptions;
@@ -0,0 +1,18 @@
1
+ // Copyright 2026 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+ export const globalCommitContext = {
5
+ ops: [],
6
+ flushOptions: {},
7
+ };
8
+ export function resetGlobalCommitContext() {
9
+ globalCommitContext.ops = [];
10
+ globalCommitContext.flushOptions = {};
11
+ delete globalCommitContext.flowIds;
12
+ }
13
+ export function takeGlobalFlushOptions() {
14
+ const flushOptions = globalCommitContext.flushOptions;
15
+ globalCommitContext.flushOptions = {};
16
+ return flushOptions;
17
+ }
18
+ //# sourceMappingURL=commit-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commit-context.js","sourceRoot":"","sources":["../../src/core/commit-context.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAQ1D,MAAM,CAAC,MAAM,mBAAmB,GAAwB;IACtD,GAAG,EAAE,EAAE;IACP,YAAY,EAAE,EAAE;CACjB,CAAC;AAEF,MAAM,UAAU,wBAAwB;IACtC,mBAAmB,CAAC,GAAG,GAAG,EAAE,CAAC;IAC7B,mBAAmB,CAAC,YAAY,GAAG,EAAE,CAAC;IACtC,OAAO,mBAAmB,CAAC,OAAO,CAAC;AACrC,CAAC;AAED,MAAM,UAAU,sBAAsB;IACpC,MAAM,YAAY,GAAG,mBAAmB,CAAC,YAAY,CAAC;IACtD,mBAAmB,CAAC,YAAY,GAAG,EAAE,CAAC;IACtC,OAAO,YAAY,CAAC;AACtB,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { VNode } from 'preact';
2
+ export interface ForceRootRenderOptions {
3
+ getRootVNode: () => unknown;
4
+ setRootVNode: (vnode: VNode) => void;
5
+ render: () => void;
6
+ }
7
+ export declare function runWithForceRootRender({ getRootVNode, setRootVNode, render }: ForceRootRenderOptions): void;
@@ -0,0 +1,40 @@
1
+ // Copyright 2026 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+ import { options as preactOptions } from 'preact';
5
+ import { COMPONENT, DIFF2, FORCE, ORIGINAL } from '../shared/render-constants.js';
6
+ export function runWithForceRootRender({ getRootVNode, setRootVNode, render }) {
7
+ // Preact can skip root render if `_original` is unchanged; bumping it keeps
8
+ // backend force renders aligned with Preact's own rerender path.
9
+ const rootVNode = getRootVNode();
10
+ if (rootVNode) {
11
+ const newVNode = Object.assign({}, rootVNode);
12
+ if (newVNode[ORIGINAL] != null) {
13
+ newVNode[ORIGINAL] += 1;
14
+ setRootVNode(newVNode);
15
+ }
16
+ }
17
+ const oldDiff = preactOptions[DIFF2];
18
+ preactOptions[DIFF2] = (vnode, oldVNode) => {
19
+ /* v8 ignore start */
20
+ if (oldDiff) {
21
+ oldDiff(vnode, oldVNode);
22
+ }
23
+ /* v8 ignore stop */
24
+ const c = oldVNode[COMPONENT];
25
+ if (c) {
26
+ c[FORCE] = true;
27
+ }
28
+ else {
29
+ // mount phase of a new Component
30
+ // `isNew` is true, no need to set FORCE
31
+ }
32
+ };
33
+ try {
34
+ render();
35
+ }
36
+ finally {
37
+ preactOptions[DIFF2] = oldDiff;
38
+ }
39
+ }
40
+ //# sourceMappingURL=forceRootRender.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"forceRootRender.js","sourceRoot":"","sources":["../../src/core/forceRootRender.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,QAAQ,CAAC;AAGlD,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AAQlF,MAAM,UAAU,sBAAsB,CACpC,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,EAA0B;IAE9D,4EAA4E;IAC5E,iEAAiE;IACjE,MAAM,SAAS,GAAG,YAAY,EAAE,CAAC;IACjC,IAAI,SAAS,EAAE,CAAC;QACd,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,SAAS,CAAU,CAAC;QACvD,IAAI,QAAQ,CAAC,QAAQ,CAAC,IAAI,IAAI,EAAE,CAAC;YAC/B,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YACxB,YAAY,CAAC,QAAQ,CAAC,CAAC;QACzB,CAAC;IACH,CAAC;IAED,MAAM,OAAO,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;IACrC,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,KAAY,EAAE,QAAe,EAAE,EAAE;QACvD,qBAAqB;QACrB,IAAI,OAAO,EAAE,CAAC;YACZ,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QAC3B,CAAC;QACD,oBAAoB;QAEpB,MAAM,CAAC,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC;QAC9B,IAAI,CAAC,EAAE,CAAC;YACN,CAAC,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;QAClB,CAAC;aAAM,CAAC;YACN,iCAAiC;YACjC,wCAAwC;QAC1C,CAAC;IACH,CAAC,CAAC;IAEF,IAAI,CAAC;QACH,MAAM,EAAE,CAAC;IACX,CAAC;YAAS,CAAC;QACT,aAAa,CAAC,KAAK,CAAC,GAAG,OAAkD,CAAC;IAC5E,CAAC;AACH,CAAC"}
@@ -0,0 +1,31 @@
1
+ import type { Consumer, Provider } from 'preact';
2
+ import type { useLynxGlobalEventListener } from './hooks/useLynxGlobalEventListener.js';
3
+ type Getter<T> = {
4
+ [key in keyof T]: () => T[key];
5
+ };
6
+ interface GlobalPropsRuntimeDeps {
7
+ createContext: typeof import('preact').createContext;
8
+ useState: typeof import('preact/hooks').useState;
9
+ createElement: typeof import('preact/compat').createElement;
10
+ useLynxGlobalEventListener: typeof useLynxGlobalEventListener;
11
+ }
12
+ interface GlobalPropsApi<Data> {
13
+ Provider: Provider<Data>;
14
+ Consumer: Consumer<Data>;
15
+ use: () => Data;
16
+ useChanged: (callback: (data: Data) => void) => void;
17
+ }
18
+ /**
19
+ * The interface you can extends so that the `useGlobalProps` returning value can be customized
20
+ *
21
+ * @public
22
+ */
23
+ export interface GlobalProps {
24
+ }
25
+ export interface UpdateGlobalPropsOptions {
26
+ forceRerender?: (() => void) | undefined;
27
+ }
28
+ export declare function isGlobalPropsEventMode(): boolean;
29
+ export declare function createGlobalProps<Data = GlobalProps>(deps: GlobalPropsRuntimeDeps): Getter<GlobalPropsApi<Data>>;
30
+ export declare function updateGlobalProps(newData: Record<string, any>, { forceRerender }?: UpdateGlobalPropsOptions): void;
31
+ export {};
@@ -0,0 +1,55 @@
1
+ import { factory } from './initData.js';
2
+ export function isGlobalPropsEventMode() {
3
+ return typeof __GLOBAL_PROPS_MODE__ !== 'undefined' && __GLOBAL_PROPS_MODE__ === 'event';
4
+ }
5
+ export function createGlobalProps(deps) {
6
+ return isGlobalPropsEventMode()
7
+ ? /* @__PURE__ */ factory(deps, '__globalProps', 'onGlobalPropsChanged')
8
+ : /* @__PURE__ */ createFallbackGlobalProps(deps.useLynxGlobalEventListener);
9
+ }
10
+ export function updateGlobalProps(newData, { forceRerender } = {}) {
11
+ if (isGlobalPropsEventMode()) {
12
+ // COW keeps Provider / Consumer state readers aligned in event mode.
13
+ lynx.__globalProps = Object.assign({}, lynx.__globalProps, newData);
14
+ }
15
+ else {
16
+ Object.assign(lynx.__globalProps, newData);
17
+ if (forceRerender) {
18
+ void Promise.resolve().then(forceRerender);
19
+ }
20
+ }
21
+ lynxCoreInject.tt.GlobalEventEmitter.emit('onGlobalPropsChanged', [lynx.__globalProps]);
22
+ }
23
+ function warnGlobalPropsMode() {
24
+ if (typeof __LEPUS__ !== 'undefined' && !__LEPUS__ && typeof __DEV__ !== 'undefined' && __DEV__) {
25
+ console.warn(`No need to use this API when 'globalPropsMode' is not 'event', `
26
+ + `updates will be triggered automatically by full re-render. `
27
+ + `Please set 'globalPropsMode' to 'event' to enable optimized updates.`);
28
+ }
29
+ }
30
+ function FallbackProvider({ children }) {
31
+ warnGlobalPropsMode();
32
+ return children;
33
+ }
34
+ function FallbackConsumer({ children }) {
35
+ warnGlobalPropsMode();
36
+ return children(lynx.__globalProps);
37
+ }
38
+ function useFallbackGlobalProps() {
39
+ warnGlobalPropsMode();
40
+ return lynx.__globalProps;
41
+ }
42
+ function createFallbackGlobalProps(useListener) {
43
+ const useChanged = (callback) => {
44
+ if (typeof __LEPUS__ === 'undefined' || !__LEPUS__) {
45
+ useListener('onGlobalPropsChanged', callback);
46
+ }
47
+ };
48
+ return {
49
+ Provider: () => FallbackProvider,
50
+ Consumer: () => FallbackConsumer,
51
+ use: () => useFallbackGlobalProps,
52
+ useChanged: () => useChanged,
53
+ };
54
+ }
55
+ //# sourceMappingURL=globalProps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"globalProps.js","sourceRoot":"","sources":["../../src/core/globalProps.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AA+BxC,MAAM,UAAU,sBAAsB;IACpC,OAAO,OAAO,qBAAqB,KAAK,WAAW,IAAI,qBAAqB,KAAK,OAAO,CAAC;AAC3F,CAAC;AAED,MAAM,UAAU,iBAAiB,CAC/B,IAA4B;IAE5B,OAAO,sBAAsB,EAAE;QAC7B,CAAC,CAAC,eAAe,CAAC,OAAO,CACvB,IAAI,EACJ,eAAe,EACf,sBAAsB,CACvB;QACD,CAAC,CAAC,eAAe,CAAC,yBAAyB,CAAO,IAAI,CAAC,0BAA0B,CAAC,CAAC;AACvF,CAAC;AAED,MAAM,UAAU,iBAAiB,CAC/B,OAA4B,EAC5B,EAAE,aAAa,KAA+B,EAAE;IAEhD,IAAI,sBAAsB,EAAE,EAAE,CAAC;QAC7B,qEAAqE;QAC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,CAAC;QAChD,CAAC;IACH,CAAC,CAAC;IAEF,OAAO;QACL,QAAQ,EAAE,GAAG,EAAE,CAAC,gBAAgB;QAChC,QAAQ,EAAE,GAAG,EAAE,CAAC,gBAAkC;QAClD,GAAG,EAAE,GAAG,EAAE,CAAC,sBAAoC;QAC/C,UAAU,EAAE,GAAG,EAAE,CAAC,UAAU;KAC7B,CAAC;AACJ,CAAC"}
@@ -1,7 +1,7 @@
1
1
  // Copyright 2024 The Lynx Authors. All rights reserved.
2
2
  // Licensed under the Apache License Version 2.0 that can be found in the
3
3
  // LICENSE file in the root directory of this source tree.
4
- import { useEffect, useMemo, useRef } from 'preact/hooks';
4
+ import { useEffect, useMemo, useRef } from '@lynx-js/react/hooks';
5
5
  /**
6
6
  * `useLynxGlobalEventListener` helps you `addListener` as early as possible.
7
7
  *
@@ -1 +1 @@
1
- {"version":3,"file":"useLynxGlobalEventListener.js","sourceRoot":"","sources":["../../../src/core/hooks/useLynxGlobalEventListener.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE1D;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,UAAU,0BAA0B,CACxC,SAAiB,EACjB,QAAW;IAEX,iBAAiB,CAAC;IAElB,MAAM,eAAe,GAAG,MAAM,EAAe,CAAC;IAE9C,OAAO,CAAC,GAAG,EAAE;QACX,IAAI,eAAe,CAAC,OAAO,EAAE,CAAC;YAC5B,MAAM,CAAC,SAAS,EAAE,QAAQ,CAAC,GAAG,eAAe,CAAC,OAAO,CAAC;YACtD,IAAI,CAAC,WAAW,CAAC,oBAAoB,CAAC,CAAC,cAAc,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;QAC7E,CAAC;QACD,IAAI,CAAC,WAAW,CAAC,oBAAoB,CAAC,CAAC,WAAW,CAAC,SAAS,EAAE,QAA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O,GAAG,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IAClD,CAAC,EAAE,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC;IAE1B,SAAS,CAAC,GAAG,EAAE;QACb,OAAO,GAAG,EAAE;YACV,IAAI,eAAe,CAAC,OAAO,EAAE,CAAC;gBAC5B,MAAM,CAAC,SAAS,EAAE,QAAQ,CAAC,GAAG,eAAe,CAAC,OAAO,CAAC;gBACtD,IAAI,CAAC,WAAW,CAAC,oBAAoB,CAAC,CAAC,cAAc,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;YAC7E,CAAC;QACH,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import type { Consumer, Context, Provider } from 'preact';
2
2
  import type { ComponentClass } from 'react';
3
- import { useLynxGlobalEventListener } from '../../core/hooks/useLynxGlobalEventListener.js';
3
+ import type { useLynxGlobalEventListener } from './hooks/useLynxGlobalEventListener.js';
4
4
  type Getter<T> = {
5
5
  [key in keyof T]: () => T[key];
6
6
  };
@@ -1,5 +1,4 @@
1
- import { useLynxGlobalEventListener } from '../../core/hooks/useLynxGlobalEventListener.js';
2
- import { globalFlushOptions } from '../lifecycle/patch/commit.js';
1
+ import { globalCommitContext } from './commit-context.js';
3
2
  // for better reuse if runtime is changed
4
3
  export function factory({ createContext, useState, createElement, useLynxGlobalEventListener: useListener }, prop, eventName) {
5
4
  const Context = createContext({});
@@ -7,7 +6,7 @@ export function factory({ createContext, useState, createElement, useLynxGlobalE
7
6
  const [__, set] = useState(lynx[prop]);
8
7
  const handleChange = () => {
9
8
  if (prop === '__initData') {
10
- globalFlushOptions.triggerDataUpdated = true;
9
+ globalCommitContext.flushOptions.triggerDataUpdated = true;
11
10
  }
12
11
  set(lynx[prop]);
13
12
  };
@@ -21,7 +20,7 @@ export function factory({ createContext, useState, createElement, useLynxGlobalE
21
20
  const [__, set] = useState(lynx[prop]);
22
21
  useChanged(() => {
23
22
  if (prop === '__initData') {
24
- globalFlushOptions.triggerDataUpdated = true;
23
+ globalCommitContext.flushOptions.triggerDataUpdated = true;
25
24
  }
26
25
  set(lynx[prop]);
27
26
  });
@@ -84,7 +83,7 @@ export function withInitDataInState(App) {
84
83
  if (!__LEPUS__) {
85
84
  lynx.getJSModule('GlobalEventEmitter').addListener('onDataChanged', this.h = (...args) => {
86
85
  const [newData] = args;
87
- globalFlushOptions.triggerDataUpdated = true;
86
+ globalCommitContext.flushOptions.triggerDataUpdated = true;
88
87
  this.setState(newData);
89
88
  });
90
89
  }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"initData.js","sourceRoot":"","sources":["../../src/core/initData.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAO1D,yCAAyC;AACzC,MAAM,UAAU,OAAO,CACrB,EAAE,aAAa,EAAE,QAAQ,EAAE,aAAa,EAAE,0BAA0B,EAAE,WAAW,EAKhF,EACD,IAAoC,EACpC,SAAiB;IAQjB,MAAM,OAAO,GAAG,aAAa,CAAC,EAAU,CAAC,CAAC;IAE1C,MAAM,QAAQ,GAAG,CAAC,EAAE,QAAQ,EAAoC,EAAE,EAAE;QAClE,MAAM,CAAC,EAAE,EAAE,GAAG,CAAC,GAAG,QAAQ,CAAO,IAAI,CAAC,IAAI,CAAS,CAAC,CAAC;QAErD,MAAM,YAAY,GAAG,GAAG,EAAE;YACxB,IAAI,IAAI,KAAK,YAAY,EAAE,CAAC;gBAC1B,mBAAmB,CAAC,YAAY,CAAC,kBAAkB,GAAG,IAAI,CAAC;YAC7D,CAAC;YACD,GAAG,CAAC,IAAI,CAAC,IAAI,CAAS,CAAC,CAAC;QAC1B,CAAC,CAAC;QAEF,UAAU,CAAC,YAAY,CAAC,CAAC;QAEzB,OAAO,aAAa,CAClB,OAAO,CAAC,QAAQ,EAChB;YACE,KAAK,EAAE,EAAE;SACV,EACD,QAAQ,CACT,CAAC;IACJ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,KAAK,CAAC,KAAK,CAAC,CAAC;YACb,IAAI,CAAC,KAAK,GAAG;gBACX,GAAG,IAAI,CAAC,KAAK;gBACb,GAAG,IAAI,CAAC,UAAU;aACnB,CAAC;YAEF,IAAI,CAAC,SAAS,EAAE,CAAC;gBACf,IAAI,CAAC,WAAW,CAAC,oBAAoB,CAAC,CAAC,WAAW,CAChD,eAAe,EACf,IAAI,CAAC,CAAC,GAAG,CAAC,GAAG,IAAe,EAAE,EAAE;oBAC9B,MAAM,CAAC,OAAO,CAAC,GAAG,IAAW,CAAC;oBAC9B,mBAAmB,CAAC,YAAY,CAAC,kBAAkB,GAAG,IAAI,CAAC;oBAC3D,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;gBACzB,CAAC,CACF,CAAC;YACJ,CAAC;QACH,CAAC;QAEQ,oBAAoB;YAC3B,KAAK,CAAC,oBAAoB,EAAE,EAAE,CAAC;YAC/B,IAAI,CAAC,SAAS,EAAE,CAAC;gBACf,IAAI,CAAC,WAAW,CAAC,oBAAoB,CAAC,CAAC,cAAc,CACnD,eAAe,EACf,IAAI,CAAC,CAAE,CACR,CAAC;YACJ,CAAC;QACH,CAAC;KACF;IAED,OAAO,CAAC,CAAC;AACX,CAAC"}
@@ -0,0 +1,2 @@
1
+ import type { DataProcessorDefinition, InitData, InitDataRaw } from '../lynx-api.js';
2
+ export declare function createProcessData(dataProcessorDefinition?: DataProcessorDefinition): (data: InitDataRaw, processorName?: string) => InitData | InitDataRaw;
@@ -0,0 +1,53 @@
1
+ import { profileEnd, profileStart } from '../shared/profile.js';
2
+ export function createProcessData(dataProcessorDefinition) {
3
+ let hasDefaultDataProcessorExecuted = false;
4
+ return (data, processorName) => {
5
+ if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {
6
+ profileStart('processData');
7
+ }
8
+ let result;
9
+ try {
10
+ if (processorName) {
11
+ result = dataProcessorDefinition?.dataProcessors?.[processorName]?.(data) ?? data;
12
+ }
13
+ else {
14
+ result = dataProcessorDefinition?.defaultDataProcessor?.(data) ?? data;
15
+ }
16
+ }
17
+ catch (error) {
18
+ lynx.reportError(error);
19
+ result = {};
20
+ }
21
+ if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {
22
+ profileEnd();
23
+ }
24
+ if (!hasDefaultDataProcessorExecuted) {
25
+ result = appendInitDataMetadata(result);
26
+ }
27
+ if (!processorName) {
28
+ hasDefaultDataProcessorExecuted = true;
29
+ }
30
+ return result;
31
+ };
32
+ }
33
+ function appendInitDataMetadata(result) {
34
+ // @ts-expect-error todo: add types to i18n logic
35
+ const i18nResourceTranslation = globalThis.__I18N_RESOURCE_TRANSLATION__;
36
+ if (i18nResourceTranslation) {
37
+ result = {
38
+ ...result,
39
+ __I18N_RESOURCE_TRANSLATION__: i18nResourceTranslation,
40
+ };
41
+ }
42
+ // @ts-expect-error todo: add types to __EXTRACT_STR__
43
+ if (__EXTRACT_STR__) {
44
+ // @ts-expect-error todo: add types to __EXTRACT_STR__
45
+ const extractStrIdentFlag = __EXTRACT_STR_IDENT_FLAG__;
46
+ result = {
47
+ ...result,
48
+ _EXTRACT_STR: extractStrIdentFlag,
49
+ };
50
+ }
51
+ return result;
52
+ }
53
+ //# sourceMappingURL=lynx-data-processors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lynx-data-processors.js","sourceRoot":"","sources":["../../src/core/lynx-data-processors.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEhE,MAAM,UAAU,iBAAiB,CAC/B,uBAAiD;IAEjD,IAAI,+BAA+B,GAAG,KAAK,CAAC;IAE5C,OAAO,CAAC,IAAI,EAAE,aAAa,EAAE,EAAE;QAC7B,IAAI,OAAO,WAAW,KAAK,WAAW,IAAI,WAAW,EAAE,CAAC;YACtD,YAAY,CAAC,aAAa,CAAC,CAAC;QAC9B,CAAC;QAED,IAAI,MAA8B,CAAC;QACnC,IAAI,CAAC;YACH,IAAI,aA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1,14 @@
1
+ // Copyright 2026 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+ import { isEmptyObject } from '../utils.js';
5
+ export function applyUpdatePageData(data, options) {
6
+ if (options?.resetPageData) {
7
+ lynx.__initData = {};
8
+ }
9
+ if (typeof data == 'object' && data !== null && !isEmptyObject(data)) {
10
+ lynx.__initData ??= {};
11
+ Object.assign(lynx.__initData, data);
12
+ }
13
+ }
14
+ //# sourceMappingURL=lynx-page-data.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lynx-page-data.js","sourceRoot":"","sources":["../../src/core/lynx-page-data.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,MAAM,UAAU,mBAAmB,CAAC,IAAa,EAAE,OAAiD;IAClG,IAAI,OAAO,EAAE,aAAa,EAAE,CAAC;QAC3B,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;IACvB,CAAC;IAED,IAAI,OAAO,IAAI,IAAI,QAAQ,IAAI,IAAI,KAAK,IAAI,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC;QACrE,IAAI,CAAC,UAAU,KAAK,EAAE,CAAC;QACvB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IACvC,CAAC;AACH,CAAC"}
@@ -0,0 +1,11 @@
1
+ export declare const NativeUpdateDataType: {
2
+ readonly UPDATE: 0;
3
+ readonly RESET: 1;
4
+ };
5
+ export type NativeUpdateDataType = (typeof NativeUpdateDataType)[keyof typeof NativeUpdateDataType];
6
+ export interface NativeUpdateDataOptions {
7
+ type?: NativeUpdateDataType | undefined;
8
+ }
9
+ type InitDataPatch = Record<string, any>;
10
+ export declare function updateCardData(newData: InitDataPatch, options?: NativeUpdateDataOptions): void;
11
+ export {};
@@ -0,0 +1,21 @@
1
+ // Copyright 2026 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+ export const NativeUpdateDataType = {
5
+ UPDATE: 0,
6
+ RESET: 1,
7
+ };
8
+ export function updateCardData(newData, options) {
9
+ const { ['__lynx_timing_flag']: performanceTimingFlag, ...restNewData } = newData;
10
+ if (performanceTimingFlag) {
11
+ lynx.reportError(new Error(`Received unsupported updateData with \`__lynx_timing_flag\` (value "${performanceTimingFlag}"), the timing flag is ignored`));
12
+ }
13
+ const { type = NativeUpdateDataType.UPDATE } = options ?? {};
14
+ if (type == NativeUpdateDataType.RESET) {
15
+ lynx.__initData = {};
16
+ }
17
+ // COW keeps provider/consumer readers aligned with Snapshot updateData behavior.
18
+ lynx.__initData = Object.assign({}, lynx.__initData, restNewData);
19
+ lynx.getJSModule('GlobalEventEmitter').emit('onDataChanged', [restNewData]);
20
+ }
21
+ //# sourceMappingURL=lynx-update-data.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lynx-update-data.js","sourceRoot":"","sources":["../../src/core/lynx-update-data.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,MAAM,EAAE,CAAC;IACT,KAAK,EAAE,CAAC;CACA,CAAC;AAUX,MAAM,UAAU,cAAc,CAC5B,OAAsB,EACtB,OAAiC;IAEjC,MAAM,EAAE,CAAC,oBAAoB,CAAC,EAAE,qBAAqB,EAAE,GAAG,WAAW,EAAE,GAAG,OAAO,CAAC;IAClF,IAAI,qBAAqB,EAAE,CAAC;QAC1B,IAAI,CAAC,WAAW,CACd,IAAI,KAAK,CACP,uEAAuE,qBAAqB,gCAAgC,CAC7H,CACF,CAAC;IACJ,CAAC;IAED,MAAM,EAAE,IAAI,GAAG,oBAAoB,CAAC,MAAM,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;IAC7D,IAAI,IAAI,IAAI,oBAAoB,CAAC,KAAK,EAAE,CAAC;QACvC,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;IACvB,CAAC;IAED,iFAAiF;IACjF,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;IAElE,IAAI,CAAC,WAAW,CAAC,oBAAoB,CAAC,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC;AAC9E,CAAC"}
@@ -0,0 +1,37 @@
1
+ import type { NodesRef } from '@lynx-js/types';
2
+ export type RefCleanup = (() => void) | void;
3
+ export type RefCallback<T> = ((ref: T | null) => RefCleanup) & {
4
+ _unmount?: RefCleanup;
5
+ };
6
+ export interface RefObject<T> {
7
+ current: T | null;
8
+ }
9
+ export type OrdinaryRef<T> = RefCallback<T> | RefObject<T>;
10
+ type FunctionPropertyNames<T> = {
11
+ [K in keyof T]: T[K] extends (...args: unknown[]) => unknown ? K : never;
12
+ }[keyof T];
13
+ export type ForwardableNodesRefMethod = Exclude<FunctionPropertyNames<NodesRef>, 'exec'>;
14
+ export type RefProxyForwardedMethods<TProxy> = {
15
+ [K in ForwardableNodesRefMethod]: (...args: Parameters<NodesRef[K]>) => TProxy;
16
+ };
17
+ export declare function assertValidRef<T>(value: unknown): OrdinaryRef<T>;
18
+ export declare function normalizeRefValue<T>(value: unknown): OrdinaryRef<T> | null | undefined;
19
+ export declare function applyOrdinaryRef<T>(ref: OrdinaryRef<T>, value: T | null): void;
20
+ export declare class OrdinaryRefEffectQueue<TProxy, TToken> {
21
+ private readonly refsToClear;
22
+ private readonly refsToApply;
23
+ queue(oldRef: OrdinaryRef<TProxy> | null | undefined, newRef: OrdinaryRef<TProxy> | null | undefined, token: TToken): void;
24
+ flush(createValue: (token: TToken) => TProxy): void;
25
+ clear(): void;
26
+ hasPending(): boolean;
27
+ }
28
+ export declare abstract class SelectorRefProxy<TProxy extends SelectorRefProxy<TProxy>> {
29
+ private task;
30
+ protected createProxy(): TProxy;
31
+ protected abstract createProxyTarget(): TProxy;
32
+ protected abstract runOrDelay(task: () => void): void;
33
+ abstract get selector(): string;
34
+ private setTask;
35
+ exec(): void;
36
+ }
37
+ export {};
@@ -0,0 +1,108 @@
1
+ // Copyright 2026 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+ export function assertValidRef(value) {
5
+ if (typeof value === 'function'
6
+ || (typeof value === 'object' && value !== null && 'current' in value)) {
7
+ return value;
8
+ }
9
+ throw new Error(`Elements' "ref" property should be a function, or an object created `
10
+ + `by createRef(), but got [${typeof value}] instead`);
11
+ }
12
+ export function normalizeRefValue(value) {
13
+ if (value === null || value === undefined) {
14
+ return value;
15
+ }
16
+ return assertValidRef(value);
17
+ }
18
+ export function applyOrdinaryRef(ref, value) {
19
+ try {
20
+ if (typeof ref === 'function') {
21
+ const cleanup = ref._unmount;
22
+ const hasCleanup = typeof cleanup === 'function';
23
+ if (hasCleanup) {
24
+ cleanup();
25
+ }
26
+ ref._unmount = undefined;
27
+ if (!hasCleanup || value !== null) {
28
+ const nextCleanup = ref(value);
29
+ if (typeof nextCleanup === 'function') {
30
+ ref._unmount = nextCleanup;
31
+ }
32
+ }
33
+ }
34
+ else {
35
+ ref.current = value;
36
+ }
37
+ }
38
+ catch (error) {
39
+ lynx.reportError(error);
40
+ }
41
+ }
42
+ // Keeps the Snapshot/ET ordinary ref ordering shared without owning backend
43
+ // timing: each backend decides when to queue/flush and how to build the proxy.
44
+ export class OrdinaryRefEffectQueue {
45
+ refsToClear = [];
46
+ refsToApply = [];
47
+ queue(oldRef, newRef, token) {
48
+ if (oldRef === newRef) {
49
+ return;
50
+ }
51
+ if (oldRef) {
52
+ this.refsToClear.push(oldRef);
53
+ }
54
+ if (newRef) {
55
+ this.refsToApply.push([newRef, token]);
56
+ }
57
+ }
58
+ flush(createValue) {
59
+ // Ref callbacks can synchronously trigger more work; detach this batch from
60
+ // the queue before invoking user code so later effects stay in the next batch.
61
+ const refsToClearNow = this.refsToClear.splice(0);
62
+ const refsToApplyNow = this.refsToApply.splice(0);
63
+ for (const ref of refsToClearNow) {
64
+ applyOrdinaryRef(ref, null);
65
+ }
66
+ for (const [ref, token] of refsToApplyNow) {
67
+ applyOrdinaryRef(ref, createValue(token));
68
+ }
69
+ }
70
+ clear() {
71
+ this.refsToClear.length = 0;
72
+ this.refsToApply.length = 0;
73
+ }
74
+ hasPending() {
75
+ return this.refsToClear.length > 0 || this.refsToApply.length > 0;
76
+ }
77
+ }
78
+ export class SelectorRefProxy {
79
+ task;
80
+ createProxy() {
81
+ return new Proxy(this, {
82
+ get: (target, prop, receiver) => {
83
+ if (typeof prop === 'symbol'
84
+ || prop === 'then'
85
+ || prop in target
86
+ || typeof prop !== 'string') {
87
+ return Reflect.get(target, prop, receiver);
88
+ }
89
+ return (...args) => {
90
+ return target.createProxyTarget().setTask(prop, args);
91
+ };
92
+ },
93
+ });
94
+ }
95
+ setTask(method, args) {
96
+ this.task = (nodesRef) => {
97
+ const nodesRefMethod = nodesRef[method];
98
+ return nodesRefMethod.apply(nodesRef, args);
99
+ };
100
+ return this;
101
+ }
102
+ exec() {
103
+ this.runOrDelay(() => {
104
+ this.task(lynx.createSelectorQuery().select(this.selector)).exec();
105
+ });
106
+ }
107
+ }
108
+ //# sourceMappingURL=ref.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ref.js","sourceRoot":"","sources":["../../src/core/ref.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAwB1D,MAAM,UAAU,cAAc,CAAI,KAAc;IAC9C,IACE,OAAO,KAAK,KAAK,UAAU;WACxB,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,SAAS,IAAI,KAAK,CAAC,EACtE,CAAC;QACD,OAAO,KA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B,IACE,OAAO,IAAI,KAAK,QAAQ;uBACrB,IAAI,KAAK,MAAM;uBACf,IAAI,IAAI,MAAM;uBACd,OAAO,IAAI,KAAK,QAAQ,EAC3B,CAAC;oBACD,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;gBAC7C,CAAC;gBAED,OAAO,CAAsC,GAAG,IAA6B,EAAE,EAAE;oBAC/E,OAAO,MAAM,CAAC,iBAAiB,EAAE,CAAC,OAAO,CAAC,IAAiC,EAAE,IAAI,CAAC,CAAC;gBACrF,CAAC,CAAC;YACJ,CAAC;SACF,CAAsB,CAAC;IAC1B,CAAC;IAQO,OAAO,CACb,MAAS,EACT,IAA6B;QAE7B,IAAI,CAAC,IAAI,GAAG,CAAC,QAAQ,EAAE,EAAE;YACvB,MAAM,cAAc,GAAG,QAAQ,CAAC,MAAM,CAA0D,CAAC;YACjG,OAAO,cAAc,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QAC9C,CAAC,CAAC;QACF,OAAO,IAAyB,CAAC;IACnC,CAAC;IAED,IAAI;QACF,IAAI,CAAC,UAAU,CAAC,GAAG,EAAE;YACnB,IAAI,CAAC,IAAK,CAAC,IAAI,CAAC,mBAAmB,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QACtE,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -0,0 +1,2 @@
1
+ export declare function getReloadVersion(): number;
2
+ export declare function increaseReloadVersion(): number;
@@ -1,12 +1,11 @@
1
- // Copyright 2024 The Lynx Authors. All rights reserved.
1
+ // Copyright 2026 The Lynx Authors. All rights reserved.
2
2
  // Licensed under the Apache License Version 2.0 that can be found in the
3
3
  // LICENSE file in the root directory of this source tree.
4
4
  let reloadVersion = 0;
5
- function getReloadVersion() {
5
+ export function getReloadVersion() {
6
6
  return reloadVersion;
7
7
  }
8
- function increaseReloadVersion() {
8
+ export function increaseReloadVersion() {
9
9
  return ++reloadVersion;
10
10
  }
11
- export { getReloadVersion, increaseReloadVersion };
12
- //# sourceMappingURL=pass.js.map
11
+ //# sourceMappingURL=reload-version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reload-version.js","sourceRoot":"","sources":["../../src/core/reload-version.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,IAAI,aAAa,GAAG,CAAC,CAAC;AAEtB,MAAM,UAAU,gBAAgB;IAC9B,OAAO,aAAa,CAAC;AACvB,CAAC;AAED,MAAM,UAAU,qBAAqB;IACnC,OAAO,EAAE,aAAa,CAAC;AACzB,CAAC"}
@@ -1,2 +1,7 @@
1
1
  import type { SerializableValue } from '../protocol/types.js';
2
- export declare function prepareAttributeSlots(templateKey: string, handleId: number, rawSlots: readonly unknown[]): SerializableValue[];
2
+ export interface PrepareAttributeSlotsOptions {
3
+ previousRawSlots?: readonly unknown[];
4
+ queueRefEffects?: boolean;
5
+ }
6
+ export declare function prepareAttributeSlots(templateKey: string, handleId: number, rawSlots: readonly unknown[], options?: PrepareAttributeSlotsOptions): SerializableValue[];
7
+ export declare function queueRefAttributeSlotUpdates(templateKey: string, handleId: number, previousRawSlots?: readonly unknown[], nextRawSlots?: readonly unknown[]): void;