@lynx-js/react 0.117.1 → 0.119.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (217) hide show
  1. package/CHANGELOG.md +62 -0
  2. package/package.json +37 -15
  3. package/refresh/.turbo/turbo-build.log +1 -1
  4. package/runtime/lib/alog/elementPAPICall.js +1 -0
  5. package/runtime/lib/alog/elementPAPICall.js.map +1 -1
  6. package/runtime/lib/debug/component-stack.d.ts +0 -6
  7. package/runtime/lib/debug/component-stack.js.map +1 -1
  8. package/runtime/lib/debug/profile.js +1 -2
  9. package/runtime/lib/debug/profile.js.map +1 -1
  10. package/runtime/lib/gesture/processGesture.js +103 -11
  11. package/runtime/lib/gesture/processGesture.js.map +1 -1
  12. package/runtime/lib/hooks/mainThread.d.ts +17 -0
  13. package/runtime/lib/hooks/mainThread.js +152 -0
  14. package/runtime/lib/hooks/mainThread.js.map +1 -0
  15. package/runtime/lib/hooks/react.js +3 -3
  16. package/runtime/lib/hooks/react.js.map +1 -1
  17. package/runtime/lib/{lifecycleConstant.js → lifecycle/constant.js} +1 -1
  18. package/runtime/lib/lifecycle/constant.js.map +1 -0
  19. package/runtime/lib/lifecycle/event/delayLifecycleEvents.d.ts +1 -1
  20. package/runtime/lib/lifecycle/event/jsReady.js +4 -2
  21. package/runtime/lib/lifecycle/event/jsReady.js.map +1 -1
  22. package/runtime/lib/lifecycle/patch/commit.js +1 -1
  23. package/runtime/lib/lifecycle/patch/commit.js.map +1 -1
  24. package/runtime/lib/lifecycle/patch/updateMainThread.js +2 -2
  25. package/runtime/lib/lifecycle/patch/updateMainThread.js.map +1 -1
  26. package/runtime/lib/lifecycle/reload.js +8 -8
  27. package/runtime/lib/lifecycle/reload.js.map +1 -1
  28. package/runtime/lib/lifecycle/render.js +2 -20
  29. package/runtime/lib/lifecycle/render.js.map +1 -1
  30. package/runtime/lib/{list.d.ts → list/list.d.ts} +1 -1
  31. package/runtime/lib/{list.js → list/list.js} +3 -3
  32. package/runtime/lib/list/list.js.map +1 -0
  33. package/runtime/lib/{listUpdateInfo.d.ts → list/listUpdateInfo.d.ts} +1 -1
  34. package/runtime/lib/{listUpdateInfo.js → list/listUpdateInfo.js} +2 -2
  35. package/runtime/lib/list/listUpdateInfo.js.map +1 -0
  36. package/runtime/lib/list/pendingListUpdates.js.map +1 -0
  37. package/runtime/lib/lynx/calledByNative.js +5 -5
  38. package/runtime/lib/lynx/calledByNative.js.map +1 -1
  39. package/runtime/lib/lynx/suspense.js +2 -2
  40. package/runtime/lib/lynx/suspense.js.map +1 -1
  41. package/runtime/lib/lynx/tt.js +1 -1
  42. package/runtime/lib/lynx/tt.js.map +1 -1
  43. package/runtime/lib/lynx-api.js +1 -1
  44. package/runtime/lib/lynx-api.js.map +1 -1
  45. package/runtime/lib/renderToOpcodes/constants.d.ts +1 -0
  46. package/runtime/lib/renderToOpcodes/constants.js +1 -0
  47. package/runtime/lib/renderToOpcodes/constants.js.map +1 -1
  48. package/runtime/lib/{hydrate.d.ts → renderToOpcodes/hydrate.d.ts} +2 -2
  49. package/runtime/lib/{hydrate.js → renderToOpcodes/hydrate.js} +6 -6
  50. package/runtime/lib/renderToOpcodes/hydrate.js.map +1 -0
  51. package/runtime/lib/renderToOpcodes/index.d.ts +2 -1
  52. package/runtime/lib/renderToOpcodes/index.js +82 -25
  53. package/runtime/lib/renderToOpcodes/index.js.map +1 -1
  54. package/runtime/lib/{opcodes.d.ts → renderToOpcodes/opcodes.d.ts} +1 -2
  55. package/runtime/lib/{opcodes.js → renderToOpcodes/opcodes.js} +54 -54
  56. package/runtime/lib/renderToOpcodes/opcodes.js.map +1 -0
  57. package/runtime/lib/snapshot/backgroundSnapshot.js +4 -4
  58. package/runtime/lib/snapshot/backgroundSnapshot.js.map +1 -1
  59. package/runtime/lib/snapshot/list.js +2 -2
  60. package/runtime/lib/snapshot/list.js.map +1 -1
  61. package/runtime/lib/snapshot/platformInfo.js +2 -2
  62. package/runtime/lib/snapshot/platformInfo.js.map +1 -1
  63. package/runtime/lib/snapshot/snapshot.d.ts +1 -0
  64. package/runtime/lib/snapshot/snapshot.js +17 -4
  65. package/runtime/lib/snapshot/snapshot.js.map +1 -1
  66. package/runtime/lib/snapshot/spread.js +2 -2
  67. package/runtime/lib/snapshot/spread.js.map +1 -1
  68. package/runtime/lib/tsconfig.tsbuildinfo +1 -0
  69. package/runtime/lib/utils.d.ts +1 -0
  70. package/runtime/lib/utils.js +3 -0
  71. package/runtime/lib/utils.js.map +1 -1
  72. package/runtime/lib/worklet/ref/updateInitValue.js +1 -1
  73. package/runtime/lib/worklet/ref/updateInitValue.js.map +1 -1
  74. package/runtime/lib/worklet-runtime/api/animation/animation.js.map +1 -0
  75. package/runtime/lib/worklet-runtime/api/animation/effect.js.map +1 -0
  76. package/runtime/lib/worklet-runtime/api/element.js.map +1 -0
  77. package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/api/lepusQuerySelector.js +10 -2
  78. package/runtime/lib/worklet-runtime/api/lepusQuerySelector.js.map +1 -0
  79. package/runtime/lib/worklet-runtime/api/lynxApi.js.map +1 -0
  80. package/runtime/lib/worklet-runtime/bindings/bindings.js.map +1 -0
  81. package/runtime/lib/worklet-runtime/bindings/events.js.map +1 -0
  82. package/runtime/lib/worklet-runtime/bindings/index.js.map +1 -0
  83. package/runtime/lib/worklet-runtime/bindings/loadRuntime.js.map +1 -0
  84. package/runtime/lib/worklet-runtime/bindings/observers.js.map +1 -0
  85. package/runtime/lib/worklet-runtime/bindings/types.js.map +1 -0
  86. package/runtime/lib/worklet-runtime/delayRunOnBackground.js.map +1 -0
  87. package/runtime/lib/worklet-runtime/delayWorkletEvent.js.map +1 -0
  88. package/runtime/lib/worklet-runtime/eomImpl.js.map +1 -0
  89. package/runtime/lib/worklet-runtime/eventPropagation.js.map +1 -0
  90. package/runtime/lib/worklet-runtime/global.js.map +1 -0
  91. package/runtime/lib/worklet-runtime/hydrate.js.map +1 -0
  92. package/runtime/lib/worklet-runtime/index.js.map +1 -0
  93. package/runtime/lib/worklet-runtime/jsFunctionLifecycle.js.map +1 -0
  94. package/runtime/lib/worklet-runtime/listeners.js.map +1 -0
  95. package/runtime/lib/worklet-runtime/runOnMainThread.js.map +1 -0
  96. package/runtime/lib/worklet-runtime/utils/mainThreadFlushLoopGuard.js.map +1 -0
  97. package/runtime/lib/worklet-runtime/utils/profile.js.map +1 -0
  98. package/runtime/lib/worklet-runtime/utils/version.js.map +1 -0
  99. package/runtime/lib/worklet-runtime/workletRef.js.map +1 -0
  100. package/runtime/lib/worklet-runtime/workletRuntime.js.map +1 -0
  101. package/{worklet-runtime/dist → runtime/worklet-runtime}/dev.js +7 -3
  102. package/{worklet-runtime/dist → runtime/worklet-runtime}/main.js +1 -1
  103. package/testing-library/README.md +48 -9
  104. package/testing-library/dist/0~123.js +43 -0
  105. package/testing-library/dist/881.js +1 -0
  106. package/testing-library/dist/entry.d.ts +1 -0
  107. package/testing-library/dist/env/index.d.ts +2 -0
  108. package/testing-library/dist/env/index.js +661 -0
  109. package/testing-library/dist/env/rstest.d.ts +1 -0
  110. package/testing-library/dist/env/rstest.js +6 -0
  111. package/testing-library/dist/env/vitest.d.ts +3 -0
  112. package/testing-library/dist/env/vitest.js +8 -662
  113. package/testing-library/dist/fire-event.d.ts +111 -0
  114. package/testing-library/dist/index.d.ts +18 -6
  115. package/testing-library/dist/plugins/index.d.ts +2 -0
  116. package/testing-library/dist/plugins/index.js +282 -0
  117. package/testing-library/dist/plugins/vitest.d.ts +26 -0
  118. package/testing-library/dist/pure.js +2 -2
  119. package/testing-library/dist/rstest-config.d.ts +25 -0
  120. package/testing-library/dist/rstest-config.js +61 -0
  121. package/testing-library/dist/setupFiles/common/bootstrap.js +2 -0
  122. package/testing-library/dist/{vitest-global-setup.js → setupFiles/common/runtime-setup.js} +25 -39
  123. package/testing-library/dist/setupFiles/inner/rstest.js +7 -0
  124. package/testing-library/dist/setupFiles/inner/vitest.js +11 -0
  125. package/testing-library/dist/setupFiles/rstest.js +21 -0
  126. package/testing-library/dist/setupFiles/vitest.js +20 -0
  127. package/testing-library/dist/vitest.config.d.ts +6 -0
  128. package/testing-library/dist/vitest.config.js +4 -257
  129. package/transform/dist/wasm.cjs +1 -1
  130. package/transform/index.d.ts +37 -1
  131. package/runtime/lib/hydrate.js.map +0 -1
  132. package/runtime/lib/lifecycleConstant.js.map +0 -1
  133. package/runtime/lib/list.js.map +0 -1
  134. package/runtime/lib/listUpdateInfo.js.map +0 -1
  135. package/runtime/lib/opcodes.js.map +0 -1
  136. package/runtime/lib/pendingListUpdates.js.map +0 -1
  137. package/testing-library/types/vitest-config.d.ts +0 -20
  138. package/worklet-runtime/lib/api/animation/animation.js.map +0 -1
  139. package/worklet-runtime/lib/api/animation/effect.js.map +0 -1
  140. package/worklet-runtime/lib/api/element.js.map +0 -1
  141. package/worklet-runtime/lib/api/lepusQuerySelector.js.map +0 -1
  142. package/worklet-runtime/lib/api/lynxApi.js.map +0 -1
  143. package/worklet-runtime/lib/bindings/bindings.js.map +0 -1
  144. package/worklet-runtime/lib/bindings/events.js.map +0 -1
  145. package/worklet-runtime/lib/bindings/index.js.map +0 -1
  146. package/worklet-runtime/lib/bindings/loadRuntime.js.map +0 -1
  147. package/worklet-runtime/lib/bindings/observers.js.map +0 -1
  148. package/worklet-runtime/lib/bindings/types.js.map +0 -1
  149. package/worklet-runtime/lib/delayRunOnBackground.js.map +0 -1
  150. package/worklet-runtime/lib/delayWorkletEvent.js.map +0 -1
  151. package/worklet-runtime/lib/eomImpl.js.map +0 -1
  152. package/worklet-runtime/lib/eventPropagation.js.map +0 -1
  153. package/worklet-runtime/lib/global.js.map +0 -1
  154. package/worklet-runtime/lib/hydrate.js.map +0 -1
  155. package/worklet-runtime/lib/index.js.map +0 -1
  156. package/worklet-runtime/lib/jsFunctionLifecycle.js.map +0 -1
  157. package/worklet-runtime/lib/listeners.js.map +0 -1
  158. package/worklet-runtime/lib/runOnMainThread.js.map +0 -1
  159. package/worklet-runtime/lib/utils/mainThreadFlushLoopGuard.js.map +0 -1
  160. package/worklet-runtime/lib/utils/profile.js.map +0 -1
  161. package/worklet-runtime/lib/utils/version.js.map +0 -1
  162. package/worklet-runtime/lib/workletRef.js.map +0 -1
  163. package/worklet-runtime/lib/workletRuntime.js.map +0 -1
  164. /package/runtime/lib/{lifecycleConstant.d.ts → lifecycle/constant.d.ts} +0 -0
  165. /package/runtime/lib/{pendingListUpdates.d.ts → list/pendingListUpdates.d.ts} +0 -0
  166. /package/runtime/lib/{pendingListUpdates.js → list/pendingListUpdates.js} +0 -0
  167. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/api/animation/animation.d.ts +0 -0
  168. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/api/animation/animation.js +0 -0
  169. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/api/animation/effect.d.ts +0 -0
  170. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/api/animation/effect.js +0 -0
  171. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/api/element.d.ts +0 -0
  172. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/api/element.js +0 -0
  173. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/api/lepusQuerySelector.d.ts +0 -0
  174. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/api/lynxApi.d.ts +0 -0
  175. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/api/lynxApi.js +0 -0
  176. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/bindings/bindings.d.ts +0 -0
  177. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/bindings/bindings.js +0 -0
  178. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/bindings/events.d.ts +0 -0
  179. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/bindings/events.js +0 -0
  180. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/bindings/index.d.ts +0 -0
  181. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/bindings/index.js +0 -0
  182. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/bindings/loadRuntime.d.ts +0 -0
  183. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/bindings/loadRuntime.js +0 -0
  184. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/bindings/observers.d.ts +0 -0
  185. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/bindings/observers.js +0 -0
  186. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/bindings/types.d.ts +0 -0
  187. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/bindings/types.js +0 -0
  188. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/delayRunOnBackground.d.ts +0 -0
  189. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/delayRunOnBackground.js +0 -0
  190. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/delayWorkletEvent.d.ts +0 -0
  191. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/delayWorkletEvent.js +0 -0
  192. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/eomImpl.d.ts +0 -0
  193. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/eomImpl.js +0 -0
  194. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/eventPropagation.d.ts +0 -0
  195. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/eventPropagation.js +0 -0
  196. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/global.d.ts +0 -0
  197. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/global.js +0 -0
  198. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/hydrate.d.ts +0 -0
  199. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/hydrate.js +0 -0
  200. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/index.d.ts +0 -0
  201. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/index.js +0 -0
  202. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/jsFunctionLifecycle.d.ts +0 -0
  203. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/jsFunctionLifecycle.js +0 -0
  204. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/listeners.d.ts +0 -0
  205. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/listeners.js +0 -0
  206. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/runOnMainThread.d.ts +0 -0
  207. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/runOnMainThread.js +0 -0
  208. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/utils/mainThreadFlushLoopGuard.d.ts +0 -0
  209. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/utils/mainThreadFlushLoopGuard.js +0 -0
  210. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/utils/profile.d.ts +0 -0
  211. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/utils/profile.js +0 -0
  212. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/utils/version.d.ts +0 -0
  213. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/utils/version.js +0 -0
  214. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/workletRef.d.ts +0 -0
  215. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/workletRef.js +0 -0
  216. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/workletRuntime.d.ts +0 -0
  217. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/workletRuntime.js +0 -0
@@ -0,0 +1,661 @@
1
+ import node_events from "node:events";
2
+ function util_define(object, properties) {
3
+ for (const name of Object.getOwnPropertyNames(properties)){
4
+ const propDesc = Object.getOwnPropertyDescriptor(properties, name);
5
+ Object.defineProperty(object, name, propDesc);
6
+ }
7
+ }
8
+ function installOwnProperties(globalThis1) {
9
+ util_define(globalThis1, {
10
+ get globalThis () {
11
+ return globalThis1._globalProxy;
12
+ }
13
+ });
14
+ }
15
+ const createGlobalThis = ()=>{
16
+ const globalThis1 = {};
17
+ globalThis1._globalObject = globalThis1._globalProxy = globalThis1;
18
+ installOwnProperties(globalThis1);
19
+ return globalThis1;
20
+ };
21
+ function _define_property(obj, key, value) {
22
+ if (key in obj) Object.defineProperty(obj, key, {
23
+ value: value,
24
+ enumerable: true,
25
+ configurable: true,
26
+ writable: true
27
+ });
28
+ else obj[key] = value;
29
+ return obj;
30
+ }
31
+ const initElementTree = ()=>{
32
+ let uiSignNext = 0;
33
+ return new class {
34
+ countElement(element, parentComponentUniqueId) {
35
+ element.$$uiSign = uiSignNext++;
36
+ this.uniqueId2Element.set(element.$$uiSign, element);
37
+ element.parentComponentUniqueId = parentComponentUniqueId;
38
+ }
39
+ __CreatePage(_tag, parentComponentUniqueId) {
40
+ const page = this.__CreateElement('page', parentComponentUniqueId);
41
+ this.root = page;
42
+ document.body.innerHTML = '';
43
+ lynxTestingEnv.env.window.document.body.appendChild(page);
44
+ return page;
45
+ }
46
+ __CreateRawText(text) {
47
+ const element = lynxTestingEnv.env.window.document.createTextNode(text);
48
+ this.countElement(element, 0);
49
+ return element;
50
+ }
51
+ __GetElementUniqueID(e) {
52
+ return e.$$uiSign;
53
+ }
54
+ __SetClasses(e, cls) {
55
+ e.className = cls;
56
+ }
57
+ __CreateElement(tag, parentComponentUniqueId) {
58
+ if ('raw-text' === tag) return this.__CreateRawText('');
59
+ const element = lynxTestingEnv.env.window.document.createElement(tag);
60
+ this.countElement(element, parentComponentUniqueId);
61
+ return element;
62
+ }
63
+ __CreateView(parentComponentUniqueId) {
64
+ return this.__CreateElement('view', parentComponentUniqueId);
65
+ }
66
+ __CreateScrollView(parentComponentUniqueId) {
67
+ return this.__CreateElement('scroll-view', parentComponentUniqueId);
68
+ }
69
+ __FirstElement(e) {
70
+ return e.firstChild;
71
+ }
72
+ __CreateText(parentComponentUniqueId) {
73
+ return this.__CreateElement('text', parentComponentUniqueId);
74
+ }
75
+ __CreateImage(parentComponentUniqueId) {
76
+ return this.__CreateElement('image', parentComponentUniqueId);
77
+ }
78
+ __CreateWrapperElement(parentComponentUniqueId) {
79
+ return this.__CreateElement('wrapper', parentComponentUniqueId);
80
+ }
81
+ __AddInlineStyle(e, key, value) {
82
+ e.style[key] = value;
83
+ }
84
+ __AppendElement(parent, child) {
85
+ parent.appendChild(child);
86
+ }
87
+ __SetCSSId(e, id, entryName) {
88
+ const cssId = `${entryName ?? '__Card__'}:${id}`;
89
+ if (Array.isArray(e)) e.forEach((item)=>{
90
+ item.cssId = cssId;
91
+ });
92
+ else e.cssId = cssId;
93
+ }
94
+ __SetAttribute(e, key, value) {
95
+ if ('style' === key || 'class' === key || 'className' === key || 'key' === key || 'id' === key || 'ref' === key || /^data-/.exec(key) || /^(bind|catch|global-bind|capture-bind|capture-catch)[A-Za-z]/.exec(key)) throw new Error(`Cannot use __SetAttribute for "${key}"`);
96
+ if ('update-list-info' === key) {
97
+ let listInfoStr = e.getAttribute(key);
98
+ let listInfo = listInfoStr ? JSON.parse(listInfoStr) : [];
99
+ listInfo.push(value);
100
+ e.setAttribute(key, JSON.stringify(listInfo));
101
+ return;
102
+ }
103
+ if ('text' === key) {
104
+ e.textContent = value;
105
+ return;
106
+ }
107
+ if (null === value) return void e.removeAttribute(key);
108
+ if ('string' == typeof value) return void e.setAttribute(key, value);
109
+ e.setAttribute(key, JSON.stringify(value));
110
+ }
111
+ __AddEvent(e, eventType, eventName, eventHandler) {
112
+ if (e.eventMap?.[`${eventType}:${eventName}`]) {
113
+ e.removeEventListener(`${eventType}:${eventName}`, e.eventMap[`${eventType}:${eventName}`]);
114
+ delete e.eventMap[`${eventType}:${eventName}`];
115
+ }
116
+ if (void 0 === eventHandler) return;
117
+ if ('string' != typeof eventHandler && void 0 === eventHandler['type']) throw new Error(`event must be string, but got ${typeof eventHandler}`);
118
+ const listener = (evt)=>{
119
+ if ('object' == typeof eventHandler && 'worklet' === eventHandler['type']) {
120
+ const isBackground = !__MAIN_THREAD__;
121
+ globalThis.lynxTestingEnv.switchToMainThread();
122
+ runWorklet(eventHandler.value, [
123
+ Object.assign({}, evt)
124
+ ]);
125
+ if (isBackground) globalThis.lynxTestingEnv.switchToBackgroundThread();
126
+ } else {
127
+ if ('catchEvent' === eventType || 'capture-catch' === eventType) evt.stopPropagation();
128
+ globalThis.lynxCoreInject.tt.publishEvent(eventHandler, evt);
129
+ }
130
+ };
131
+ e.eventMap = e.eventMap ?? {};
132
+ e.eventMap[`${eventType}:${eventName}`] = listener;
133
+ e.addEventListener(`${eventType}:${eventName}`, listener, {
134
+ capture: 'capture-bind' === eventType || 'capture-catch' === eventType
135
+ });
136
+ }
137
+ __GetEvent(e, eventType, eventName) {
138
+ const jsFunction = e.eventMap?.[`${eventType}:${eventName}`];
139
+ if (void 0 !== jsFunction) return {
140
+ type: eventType,
141
+ name: eventName,
142
+ jsFunction
143
+ };
144
+ }
145
+ __SetID(e, id) {
146
+ e.id = id;
147
+ }
148
+ __SetInlineStyles(e, styles) {
149
+ if ('string' == typeof styles) e.setAttributeNS(null, 'style', styles);
150
+ else Object.assign(e.style, styles);
151
+ }
152
+ __AddDataset(e, key, value) {
153
+ e.dataset[key] = value;
154
+ }
155
+ __SetDataset(e, dataset) {
156
+ Object.assign(e.dataset, dataset);
157
+ }
158
+ __SetGestureDetector(e, id, type, config, relationMap) {
159
+ e.gesture = {
160
+ id,
161
+ type,
162
+ config,
163
+ relationMap
164
+ };
165
+ }
166
+ __RemoveGestureDetector(e, id) {
167
+ if (e.gesture?.['id'] === id) delete e.gesture;
168
+ }
169
+ __GetDataset(e) {
170
+ return e.dataset;
171
+ }
172
+ __RemoveElement(parent, child) {
173
+ let ch = parent.firstChild;
174
+ while(ch){
175
+ if (ch === child) {
176
+ parent.removeChild(ch);
177
+ break;
178
+ }
179
+ ch = ch.nextSibling;
180
+ }
181
+ }
182
+ __InsertElementBefore(parent, child, ref) {
183
+ if (void 0 === ref) parent.appendChild(child);
184
+ else parent.insertBefore(child, ref);
185
+ }
186
+ __ReplaceElement(newElement, oldElement) {
187
+ const parent = oldElement.parentNode;
188
+ if (!parent) throw new Error('unreachable');
189
+ parent.replaceChild(newElement, oldElement);
190
+ }
191
+ __FlushElementTree() {}
192
+ __UpdateListComponents(_list, _components) {}
193
+ __UpdateListCallbacks(list, componentAtIndex, enqueueComponent) {
194
+ Object.defineProperties(list, {
195
+ componentAtIndex: {
196
+ enumerable: false,
197
+ configurable: true,
198
+ value: componentAtIndex
199
+ },
200
+ enqueueComponent: {
201
+ enumerable: false,
202
+ configurable: true,
203
+ value: enqueueComponent
204
+ }
205
+ });
206
+ }
207
+ __CreateList(parentComponentUniqueId, componentAtIndex, enqueueComponent) {
208
+ const e = this.__CreateElement('list', parentComponentUniqueId);
209
+ Object.defineProperties(e, {
210
+ componentAtIndex: {
211
+ enumerable: false,
212
+ configurable: true,
213
+ value: componentAtIndex
214
+ },
215
+ enqueueComponent: {
216
+ enumerable: false,
217
+ configurable: true,
218
+ value: enqueueComponent
219
+ }
220
+ });
221
+ return e;
222
+ }
223
+ __GetTag(ele) {
224
+ return ele.nodeName;
225
+ }
226
+ __GetAttributeByName(ele, name) {
227
+ return ele.getAttribute(name);
228
+ }
229
+ __ElementAnimate(element, args) {
230
+ const [operation, name] = args;
231
+ switch(operation){
232
+ case 0:
233
+ {
234
+ const keyframes = args[2];
235
+ const options = args[3];
236
+ this.animationMap.set(name, {
237
+ element,
238
+ state: 'running',
239
+ keyframes,
240
+ options
241
+ });
242
+ break;
243
+ }
244
+ case 1:
245
+ {
246
+ const anim = this.animationMap.get(name);
247
+ if (anim) anim.state = 'running';
248
+ break;
249
+ }
250
+ case 2:
251
+ {
252
+ const anim = this.animationMap.get(name);
253
+ if (anim) anim.state = 'paused';
254
+ break;
255
+ }
256
+ case 3:
257
+ this.animationMap.delete(name);
258
+ break;
259
+ case 4:
260
+ {
261
+ const anim = this.animationMap.get(name);
262
+ if (anim) anim.state = 'finished';
263
+ break;
264
+ }
265
+ }
266
+ }
267
+ clear() {
268
+ this.root = void 0;
269
+ }
270
+ toTree() {
271
+ return this.root;
272
+ }
273
+ enterListItemAtIndex(e, index, ...args) {
274
+ const { componentAtIndex, $$uiSign } = e;
275
+ return componentAtIndex(e, $$uiSign, index, ...args);
276
+ }
277
+ leaveListItem(e, uiSign) {
278
+ const { enqueueComponent, $$uiSign } = e;
279
+ enqueueComponent(e, $$uiSign, uiSign);
280
+ }
281
+ toJSON() {
282
+ return this.toTree();
283
+ }
284
+ __GetElementByUniqueId(uniqueId) {
285
+ return this.uniqueId2Element.get(uniqueId);
286
+ }
287
+ constructor(){
288
+ _define_property(this, "uniqueId2Element", new Map());
289
+ _define_property(this, "root", void 0);
290
+ _define_property(this, "animationMap", new Map());
291
+ }
292
+ }();
293
+ };
294
+ function GlobalEventEmitter_define_property(obj, key, value) {
295
+ if (key in obj) Object.defineProperty(obj, key, {
296
+ value: value,
297
+ enumerable: true,
298
+ configurable: true,
299
+ writable: true
300
+ });
301
+ else obj[key] = value;
302
+ return obj;
303
+ }
304
+ class GlobalEventEmitter {
305
+ addListener(eventName, listener) {
306
+ this.listeners[eventName] ??= [];
307
+ this.listeners[eventName].push(listener);
308
+ }
309
+ removeListener(eventName, listener) {
310
+ if (!this.listeners[eventName]) return;
311
+ this.listeners[eventName] = this.listeners[eventName].filter((l)=>l !== listener);
312
+ }
313
+ emit(eventName, args) {
314
+ if (!this.listeners[eventName]) return;
315
+ this.listeners[eventName].forEach((listener)=>args ? listener(...args) : listener());
316
+ }
317
+ clear() {
318
+ this.listeners = {};
319
+ }
320
+ removeAllListeners(eventName) {
321
+ if (eventName) delete this.listeners[eventName];
322
+ else this.clear();
323
+ }
324
+ trigger(eventName, params) {
325
+ this.emit(eventName, [
326
+ params
327
+ ]);
328
+ }
329
+ toggle(eventName, ...data) {
330
+ this.emit(eventName, data);
331
+ }
332
+ constructor(){
333
+ GlobalEventEmitter_define_property(this, "listeners", {});
334
+ }
335
+ }
336
+ function dist_define_property(obj, key, value) {
337
+ if (key in obj) Object.defineProperty(obj, key, {
338
+ value: value,
339
+ enumerable: true,
340
+ configurable: true,
341
+ writable: true
342
+ });
343
+ else obj[key] = value;
344
+ return obj;
345
+ }
346
+ function installLynxTestingEnv(target, env) {
347
+ target.lynxEnv = env;
348
+ target.lynxTestingEnv = new LynxTestingEnv(env);
349
+ target.Node = env.window.Node;
350
+ }
351
+ function uninstallLynxTestingEnv(target) {
352
+ delete target.lynxTestingEnv;
353
+ delete target.lynxEnv;
354
+ delete target.Node;
355
+ }
356
+ function __injectElementApi(target) {
357
+ const elementTree1 = initElementTree();
358
+ target.elementTree = elementTree1;
359
+ if (void 0 === target) target = globalThis;
360
+ for (const k of Object.getOwnPropertyNames(elementTree1.constructor.prototype))if (k.startsWith('__')) target[k] = elementTree1[k].bind(elementTree1);
361
+ target.$kTemplateAssembler = {};
362
+ target.registerDataProcessor = ()=>{
363
+ console.error('registerDataProcessor is not implemented');
364
+ };
365
+ target.__OnLifecycleEvent = (...args)=>{
366
+ const isMainThread = __MAIN_THREAD__;
367
+ globalThis.lynxTestingEnv.switchToBackgroundThread();
368
+ globalThis.lynxCoreInject.tt.OnLifecycleEvent(...args);
369
+ if (isMainThread) globalThis.lynxTestingEnv.switchToMainThread();
370
+ };
371
+ target._ReportError = ()=>{};
372
+ }
373
+ function createPolyfills() {
374
+ const app = {
375
+ callLepusMethod: (...rLynxChange)=>{
376
+ const isBackground = !__MAIN_THREAD__;
377
+ globalThis.lynxTestingEnv.switchToMainThread();
378
+ globalThis[rLynxChange[0]](rLynxChange[1]);
379
+ globalThis.lynxTestingEnv.switchToBackgroundThread();
380
+ rLynxChange[2]?.();
381
+ globalThis.lynxTestingEnv.switchToMainThread();
382
+ if (isBackground) globalThis.lynxTestingEnv.switchToBackgroundThread();
383
+ },
384
+ markTiming: ()=>{},
385
+ createJSObjectDestructionObserver: ()=>({})
386
+ };
387
+ const performance = {
388
+ __functionCallHistory: [],
389
+ _generatePipelineOptions: ()=>{
390
+ performance.__functionCallHistory.push([
391
+ '_generatePipelineOptions'
392
+ ]);
393
+ return {
394
+ pipelineID: 'pipelineID',
395
+ needTimestamps: false
396
+ };
397
+ },
398
+ _onPipelineStart: (id)=>{
399
+ performance.__functionCallHistory.push([
400
+ '_onPipelineStart',
401
+ id
402
+ ]);
403
+ },
404
+ _markTiming: (id, key)=>{
405
+ performance.__functionCallHistory.push([
406
+ '_markTiming',
407
+ id,
408
+ key
409
+ ]);
410
+ },
411
+ _bindPipelineIdWithTimingFlag: (id, flag)=>{
412
+ performance.__functionCallHistory.push([
413
+ '_bindPipelineIdWithTimingFlag',
414
+ id,
415
+ flag
416
+ ]);
417
+ }
418
+ };
419
+ const ee = new node_events();
420
+ ee.dispatchEvent = ({ type, data })=>{
421
+ if (!globalThis.lynxTestingEnv) return;
422
+ const origin = __MAIN_THREAD__ ? 'CoreContext' : 'JSContext';
423
+ if ('CoreContext' === origin) lynxTestingEnv.switchToBackgroundThread();
424
+ else lynxTestingEnv.switchToMainThread();
425
+ ee.emit(type, {
426
+ data: data,
427
+ origin
428
+ });
429
+ if ('CoreContext' === origin) lynxTestingEnv.switchToMainThread();
430
+ else lynxTestingEnv.switchToBackgroundThread();
431
+ };
432
+ ee.addEventListener = ee.addListener;
433
+ ee.removeEventListener = ee.removeListener;
434
+ const CoreContext = ee;
435
+ const JsContext = ee;
436
+ function __LoadLepusChunk(chunkName, _options) {
437
+ const isBackground = !__MAIN_THREAD__;
438
+ globalThis.lynxTestingEnv.switchToMainThread();
439
+ let ans;
440
+ if ('worklet-runtime' === chunkName) ans = globalThis.onInitWorkletRuntime?.();
441
+ else throw new Error(`__LoadLepusChunk: Unknown chunk name: ${chunkName}`);
442
+ if (isBackground) globalThis.lynxTestingEnv.switchToBackgroundThread();
443
+ return ans;
444
+ }
445
+ return {
446
+ app,
447
+ performance,
448
+ CoreContext,
449
+ JsContext,
450
+ __LoadLepusChunk
451
+ };
452
+ }
453
+ function injectMainThreadGlobals(target, polyfills) {
454
+ __injectElementApi(target);
455
+ const { performance, CoreContext, JsContext, __LoadLepusChunk } = polyfills || {};
456
+ if (void 0 === target) target = globalThis;
457
+ target.__DEV__ = true;
458
+ target.__PROFILE__ = true;
459
+ target.__ALOG__ = true;
460
+ target.__ALOG_ELEMENT_API__ = true;
461
+ target.__JS__ = false;
462
+ target.__LEPUS__ = true;
463
+ target.__BACKGROUND__ = false;
464
+ target.__MAIN_THREAD__ = true;
465
+ target.__REF_FIRE_IMMEDIATELY__ = false;
466
+ target.__FIRST_SCREEN_SYNC_TIMING__ = 'immediately';
467
+ target.__TESTING_FORCE_RENDER_TO_OPCODE__ = false;
468
+ target.__ENABLE_SSR__ = false;
469
+ target.globDynamicComponentEntry = '__Card__';
470
+ const native = {
471
+ _listeners: {},
472
+ onTriggerEvent: void 0,
473
+ postMessage: (_message)=>{},
474
+ addEventListener: (type, listener)=>{
475
+ if (!native._listeners[type]) native._listeners[type] = [];
476
+ native._listeners[type].push(listener);
477
+ },
478
+ removeEventListener: (type, listener)=>{
479
+ if (native._listeners[type]) native._listeners[type] = native._listeners[type].filter((l)=>l !== listener);
480
+ },
481
+ dispatchEvent: (event)=>{
482
+ const listeners = native._listeners[event.type];
483
+ if (listeners) listeners.forEach((listener)=>listener(event));
484
+ return {
485
+ canceled: false
486
+ };
487
+ }
488
+ };
489
+ target.lynx = {
490
+ performance,
491
+ getNative: ()=>native,
492
+ getCoreContext: ()=>CoreContext,
493
+ getJSContext: ()=>JsContext,
494
+ reportError: (e)=>{
495
+ throw e;
496
+ }
497
+ };
498
+ target.requestAnimationFrame = setTimeout;
499
+ target.cancelAnimationFrame = clearTimeout;
500
+ target.console.profile = console.profile = ()=>{};
501
+ target.console.profileEnd = console.profileEnd = ()=>{};
502
+ target.console.alog = console.alog = ()=>{};
503
+ target.__LoadLepusChunk = __LoadLepusChunk;
504
+ globalThis.onInjectMainThreadGlobals?.(target);
505
+ }
506
+ const IGNORE_LIST_GLOBALS = [
507
+ 'globalThis',
508
+ 'global'
509
+ ];
510
+ class NodesRef {
511
+ invoke() {
512
+ throw new Error('not implemented');
513
+ }
514
+ path() {
515
+ throw new Error('not implemented');
516
+ }
517
+ fields() {
518
+ throw new Error('not implemented');
519
+ }
520
+ setNativeProps(props) {
521
+ return {
522
+ exec: ()=>{
523
+ const element = elementTree.uniqueId2Element.get(Number(this._nodeSelectToken.identifier));
524
+ if (!element) throw new Error(`[NodesRef.setNativeProps] Element not found for identifier=${this._nodeSelectToken.identifier}`);
525
+ if (element) for(const key in props)element.setAttributeNS(null, key, props[key]);
526
+ }
527
+ };
528
+ }
529
+ constructor(selectorQuery, nodeSelectToken){
530
+ dist_define_property(this, "_nodeSelectToken", void 0);
531
+ dist_define_property(this, "_selectorQuery", void 0);
532
+ this._nodeSelectToken = nodeSelectToken;
533
+ this._selectorQuery = selectorQuery;
534
+ }
535
+ }
536
+ function injectBackgroundThreadGlobals(target, polyfills) {
537
+ const { app, performance, CoreContext, JsContext, __LoadLepusChunk } = polyfills || {};
538
+ if (void 0 === target) target = globalThis;
539
+ target.__DEV__ = true;
540
+ target.__PROFILE__ = true;
541
+ target.__ALOG__ = true;
542
+ target.__ALOG_ELEMENT_API__ = true;
543
+ target.__JS__ = true;
544
+ target.__LEPUS__ = false;
545
+ target.__BACKGROUND__ = true;
546
+ target.__MAIN_THREAD__ = false;
547
+ target.__ENABLE_SSR__ = false;
548
+ target.globDynamicComponentEntry = '__Card__';
549
+ target.lynxCoreInject = {};
550
+ target.lynxCoreInject.tt = {
551
+ _params: {
552
+ initData: {},
553
+ updateData: {}
554
+ }
555
+ };
556
+ const globalEventEmitter = new GlobalEventEmitter();
557
+ target.lynx = {
558
+ getNativeApp: ()=>app,
559
+ performance,
560
+ createSelectorQuery: ()=>({
561
+ selectUniqueID: function(uniqueId) {
562
+ return new NodesRef({}, {
563
+ type: 2,
564
+ identifier: uniqueId.toString()
565
+ });
566
+ },
567
+ select: function(selector) {
568
+ const el = lynxTestingEnv.env.window.document.querySelector(selector);
569
+ if (!el) throw new Error(`[createSelectorQuery.select] No element matches selector: ${selector}`);
570
+ return new NodesRef({}, {
571
+ type: 0,
572
+ identifier: el.$$uiSign.toString()
573
+ });
574
+ }
575
+ }),
576
+ getCoreContext: ()=>CoreContext,
577
+ getJSContext: ()=>JsContext,
578
+ getJSModule: (moduleName)=>{
579
+ if ('GlobalEventEmitter' === moduleName) return globalEventEmitter;
580
+ throw new Error(`getJSModule(${moduleName}) not implemented`);
581
+ },
582
+ reportError: (e)=>{
583
+ throw e;
584
+ }
585
+ };
586
+ target.requestAnimationFrame = setTimeout;
587
+ target.cancelAnimationFrame = clearTimeout;
588
+ target.console.profile = console.profile = ()=>{};
589
+ target.console.profileEnd = console.profileEnd = ()=>{};
590
+ target.console.alog = console.alog = ()=>{};
591
+ target.SystemInfo = {
592
+ platform: 'iOS',
593
+ pixelRatio: 3,
594
+ pixelWidth: 1170,
595
+ pixelHeight: 2532,
596
+ osVersion: '17.0.2',
597
+ enableKrypton: true,
598
+ runtimeType: 'quickjs',
599
+ lynxSdkVersion: '3.0'
600
+ };
601
+ target.__LoadLepusChunk = __LoadLepusChunk;
602
+ globalThis.onInjectBackgroundThreadGlobals?.(target);
603
+ }
604
+ class LynxTestingEnv {
605
+ injectGlobals() {
606
+ const polyfills = createPolyfills();
607
+ injectBackgroundThreadGlobals(this.backgroundThread.globalThis, polyfills);
608
+ injectMainThreadGlobals(this.mainThread.globalThis, polyfills);
609
+ }
610
+ switchToBackgroundThread() {
611
+ this.originals = new Map();
612
+ Object.getOwnPropertyNames(this.backgroundThread.globalThis).forEach((key)=>{
613
+ if (IGNORE_LIST_GLOBALS.includes(key)) return;
614
+ this.originals.set(key, global[key]);
615
+ global[key] = this.backgroundThread.globalThis[key];
616
+ });
617
+ globalThis?.onSwitchedToBackgroundThread?.();
618
+ }
619
+ switchToMainThread() {
620
+ this.originals = new Map();
621
+ Object.getOwnPropertyNames(this.mainThread.globalThis).forEach((key)=>{
622
+ if (IGNORE_LIST_GLOBALS.includes(key)) return;
623
+ this.originals.set(key, global[key]);
624
+ global[key] = this.mainThread.globalThis[key];
625
+ });
626
+ globalThis?.onSwitchedToMainThread?.();
627
+ }
628
+ clearGlobal() {
629
+ this.originals?.forEach((v, k)=>{
630
+ global[k] = v;
631
+ });
632
+ this.originals?.clear();
633
+ }
634
+ reset() {
635
+ this.injectGlobals();
636
+ this.switchToMainThread();
637
+ this.switchToBackgroundThread();
638
+ globalThis.onResetLynxTestingEnv?.();
639
+ }
640
+ constructor(env){
641
+ dist_define_property(this, "originals", new Map());
642
+ dist_define_property(this, "backgroundThread", void 0);
643
+ dist_define_property(this, "mainThread", void 0);
644
+ dist_define_property(this, "env", void 0);
645
+ this.env = env ?? global.lynxEnv;
646
+ if (!this.env) throw new Error("LynxTestingEnv requires an object with a jsdom-like `window`. Pass `{ window }` to the constructor, or ensure your test runner sets global.lynxEnv to that shape (e.g., via a setup file).");
647
+ this.backgroundThread = createGlobalThis();
648
+ this.mainThread = createGlobalThis();
649
+ const globalPolyfills = {
650
+ console: this.env.window['console'],
651
+ Event: this.env.window.Event,
652
+ window: this.env.window,
653
+ document: this.env.window.document
654
+ };
655
+ Object.assign(this.mainThread.globalThis, globalPolyfills);
656
+ Object.assign(this.backgroundThread.globalThis, globalPolyfills);
657
+ this.injectGlobals();
658
+ this.switchToBackgroundThread();
659
+ }
660
+ }
661
+ export { LynxTestingEnv, installLynxTestingEnv, uninstallLynxTestingEnv };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ import { LynxTestingEnv } from "./index.js";
2
+ global.lynxEnv = {
3
+ window
4
+ };
5
+ const lynxTestingEnv = new LynxTestingEnv();
6
+ global.lynxTestingEnv = lynxTestingEnv;
@@ -0,0 +1,3 @@
1
+ import { type Environment } from 'vitest/environments';
2
+ declare const env: Environment;
3
+ export default env;