@lynx-js/react 0.111.0 → 0.111.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. package/CHANGELOG.md +58 -0
  2. package/components/lib/DeferredListItem.d.ts +3 -1
  3. package/components/lib/DeferredListItem.jsx +4 -2
  4. package/components/lib/DeferredListItem.jsx.map +1 -1
  5. package/components/src/DeferredListItem.tsx +5 -3
  6. package/package.json +6 -1
  7. package/refresh/.turbo/turbo-build.log +7 -3
  8. package/refresh/dist/index.js +223 -284
  9. package/refresh/package.json +3 -4
  10. package/refresh/rslib.config.ts +24 -0
  11. package/runtime/debug/index.cjs +8 -0
  12. package/runtime/debug/index.d.ts +4 -0
  13. package/runtime/debug/index.js +5 -0
  14. package/runtime/lib/alog/index.d.ts +1 -0
  15. package/runtime/lib/alog/index.js +8 -0
  16. package/runtime/lib/alog/index.js.map +1 -0
  17. package/runtime/lib/alog/render.d.ts +1 -0
  18. package/runtime/lib/alog/render.js +19 -0
  19. package/runtime/lib/alog/render.js.map +1 -0
  20. package/runtime/lib/backgroundSnapshot.d.ts +1 -0
  21. package/runtime/lib/backgroundSnapshot.js +31 -17
  22. package/runtime/lib/backgroundSnapshot.js.map +1 -1
  23. package/runtime/lib/debug/component-stack.d.ts +33 -0
  24. package/runtime/lib/debug/component-stack.js +145 -0
  25. package/runtime/lib/debug/component-stack.js.map +1 -0
  26. package/runtime/lib/debug/formatPatch.d.ts +2 -0
  27. package/runtime/lib/debug/formatPatch.js +27 -0
  28. package/runtime/lib/debug/formatPatch.js.map +1 -0
  29. package/runtime/lib/debug/printSnapshot.d.ts +1 -1
  30. package/runtime/lib/debug/printSnapshot.js +0 -4
  31. package/runtime/lib/debug/printSnapshot.js.map +1 -1
  32. package/runtime/lib/debug/profile.js +1 -3
  33. package/runtime/lib/debug/profile.js.map +1 -1
  34. package/runtime/lib/hydrate.js +11 -7
  35. package/runtime/lib/hydrate.js.map +1 -1
  36. package/runtime/lib/lifecycle/patch/commit.js +1 -1
  37. package/runtime/lib/lifecycle/patch/commit.js.map +1 -1
  38. package/runtime/lib/lifecycle/patch/snapshotPatch.d.ts +4 -0
  39. package/runtime/lib/lifecycle/patch/snapshotPatch.js +28 -0
  40. package/runtime/lib/lifecycle/patch/snapshotPatch.js.map +1 -1
  41. package/runtime/lib/lynx.js +9 -0
  42. package/runtime/lib/lynx.js.map +1 -1
  43. package/runtime/lib/pendingListUpdates.d.ts +2 -1
  44. package/runtime/lib/pendingListUpdates.js +16 -4
  45. package/runtime/lib/pendingListUpdates.js.map +1 -1
  46. package/runtime/lib/renderToOpcodes/constants.d.ts +2 -0
  47. package/runtime/lib/renderToOpcodes/constants.js +2 -0
  48. package/runtime/lib/renderToOpcodes/constants.js.map +1 -1
  49. package/runtime/lib/root.d.ts +6 -0
  50. package/runtime/lib/root.js +4 -0
  51. package/runtime/lib/root.js.map +1 -1
  52. package/runtime/lib/snapshot/platformInfo.js +5 -3
  53. package/runtime/lib/snapshot/platformInfo.js.map +1 -1
  54. package/runtime/lib/snapshot/ref.d.ts +2 -2
  55. package/runtime/lib/snapshot/spread.js +3 -1
  56. package/runtime/lib/snapshot/spread.js.map +1 -1
  57. package/runtime/lib/snapshot.js +13 -7
  58. package/runtime/lib/snapshot.js.map +1 -1
  59. package/runtime/lib/utils.d.ts +2 -0
  60. package/runtime/lib/utils.js +23 -2
  61. package/runtime/lib/utils.js.map +1 -1
  62. package/testing-library/dist/env/vitest.js +18 -7
  63. package/testing-library/dist/pure.js +3 -1
  64. package/testing-library/dist/vitest-global-setup.js +2 -2
  65. package/transform/dist/wasm.cjs +1 -1
  66. package/types/react.d.ts +13 -1
  67. package/worklet-runtime/dist/dev.js +403 -506
  68. package/worklet-runtime/dist/main.js +1 -517
  69. package/worklet-runtime/lib/workletRuntime.js +5 -5
  70. package/worklet-runtime/lib/workletRuntime.js.map +1 -1
  71. package/runtime/src/backgroundSnapshot.ts +0 -501
  72. package/runtime/src/compat/componentIs.ts +0 -30
  73. package/runtime/src/compat/initData.ts +0 -150
  74. package/runtime/src/compat/lynxComponent.ts +0 -79
  75. package/runtime/src/debug/debug.ts +0 -9
  76. package/runtime/src/debug/printSnapshot.ts +0 -28
  77. package/runtime/src/debug/profile.ts +0 -55
  78. package/runtime/src/document.ts +0 -84
  79. package/runtime/src/gesture/processGesture.ts +0 -89
  80. package/runtime/src/gesture/processGestureBagkround.ts +0 -19
  81. package/runtime/src/gesture/types.ts +0 -44
  82. package/runtime/src/hooks/react.ts +0 -62
  83. package/runtime/src/hooks/useLynxGlobalEventListener.ts +0 -59
  84. package/runtime/src/hydrate.ts +0 -368
  85. package/runtime/src/index.ts +0 -94
  86. package/runtime/src/internal.ts +0 -63
  87. package/runtime/src/legacy-react-runtime/index.ts +0 -42
  88. package/runtime/src/lifecycle/destroy.ts +0 -34
  89. package/runtime/src/lifecycle/event/delayEvents.ts +0 -11
  90. package/runtime/src/lifecycle/event/delayLifecycleEvents.ts +0 -15
  91. package/runtime/src/lifecycle/event/jsReady.ts +0 -34
  92. package/runtime/src/lifecycle/pass.ts +0 -14
  93. package/runtime/src/lifecycle/patch/commit.ts +0 -214
  94. package/runtime/src/lifecycle/patch/error.ts +0 -61
  95. package/runtime/src/lifecycle/patch/isMainThreadHydrationFinished.ts +0 -13
  96. package/runtime/src/lifecycle/patch/snapshotPatch.ts +0 -65
  97. package/runtime/src/lifecycle/patch/snapshotPatchApply.ts +0 -145
  98. package/runtime/src/lifecycle/patch/updateMainThread.ts +0 -64
  99. package/runtime/src/lifecycle/ref/delay.ts +0 -99
  100. package/runtime/src/lifecycle/reload.ts +0 -97
  101. package/runtime/src/lifecycle/render.ts +0 -54
  102. package/runtime/src/lifecycleConstant.ts +0 -21
  103. package/runtime/src/list.ts +0 -307
  104. package/runtime/src/listUpdateInfo.ts +0 -221
  105. package/runtime/src/lynx/calledByNative.ts +0 -160
  106. package/runtime/src/lynx/component.ts +0 -113
  107. package/runtime/src/lynx/dynamic-js.ts +0 -36
  108. package/runtime/src/lynx/env.ts +0 -109
  109. package/runtime/src/lynx/injectLepusMethods.ts +0 -53
  110. package/runtime/src/lynx/lazy-bundle.ts +0 -175
  111. package/runtime/src/lynx/performance.ts +0 -148
  112. package/runtime/src/lynx/runWithForce.ts +0 -67
  113. package/runtime/src/lynx/tt.ts +0 -215
  114. package/runtime/src/lynx-api.ts +0 -455
  115. package/runtime/src/lynx.ts +0 -58
  116. package/runtime/src/opcodes.ts +0 -155
  117. package/runtime/src/pendingListUpdates.ts +0 -18
  118. package/runtime/src/renderToOpcodes/constants.ts +0 -24
  119. package/runtime/src/renderToOpcodes/index.ts +0 -306
  120. package/runtime/src/root.ts +0 -23
  121. package/runtime/src/snapshot/dynamicPartType.ts +0 -16
  122. package/runtime/src/snapshot/event.ts +0 -33
  123. package/runtime/src/snapshot/gesture.ts +0 -30
  124. package/runtime/src/snapshot/list.ts +0 -36
  125. package/runtime/src/snapshot/platformInfo.ts +0 -62
  126. package/runtime/src/snapshot/ref.ts +0 -139
  127. package/runtime/src/snapshot/spread.ts +0 -330
  128. package/runtime/src/snapshot/workletEvent.ts +0 -35
  129. package/runtime/src/snapshot/workletRef.ts +0 -88
  130. package/runtime/src/snapshot.ts +0 -634
  131. package/runtime/src/snapshotInstanceHydrationMap.ts +0 -17
  132. package/runtime/src/utils.ts +0 -44
  133. package/runtime/src/worklet/ctx.ts +0 -22
  134. package/runtime/src/worklet/destroy.ts +0 -16
  135. package/runtime/src/worklet/execMap.ts +0 -51
  136. package/runtime/src/worklet/functionCall.ts +0 -42
  137. package/runtime/src/worklet/functionality.ts +0 -29
  138. package/runtime/src/worklet/hmr.ts +0 -34
  139. package/runtime/src/worklet/indexMap.ts +0 -23
  140. package/runtime/src/worklet/runOnBackground.ts +0 -147
  141. package/runtime/src/worklet/runOnMainThread.ts +0 -50
  142. package/runtime/src/worklet/transformToWorklet.ts +0 -26
  143. package/runtime/src/worklet/workletRef.ts +0 -231
  144. package/runtime/src/worklet/workletRefPool.ts +0 -29
@@ -1,79 +0,0 @@
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
- import { Component } from 'preact';
5
- import type { ReactNode } from 'react';
6
-
7
- export function wrapWithLynxComponent(
8
- jsxSnapshot: (c: ReactNode, spread?: Record<string, any>) => ReactNode,
9
- jsxComponent: any,
10
- ): ReactNode {
11
- const C = jsxComponent.type;
12
- if (
13
- typeof C === 'function' && (C === ComponentFromReactRuntime || C.prototype instanceof ComponentFromReactRuntime)
14
- ) {
15
- if (jsxSnapshot.length === 1) {
16
- return jsxSnapshot(jsxComponent);
17
- } else {
18
- // spread
19
- if (!jsxComponent.props.removeComponentElement) {
20
- return jsxSnapshot(jsxComponent, takeComponentAttributes(jsxComponent));
21
- }
22
- }
23
- }
24
- return jsxComponent;
25
- }
26
-
27
- // @ts-expect-error
28
- export class ComponentFromReactRuntime extends Component {}
29
-
30
- const __COMPONENT_ATTRIBUTES__ = /* @__PURE__ */ new Set([
31
- 'name',
32
- 'style',
33
- 'class',
34
- 'flatten',
35
- 'clip-radius',
36
- 'overlap',
37
- 'user-interaction-enabled',
38
- 'native-interaction-enabled',
39
- 'block-native-event',
40
- 'enableLayoutOnly',
41
- 'cssAlignWithLegacyW3C',
42
- 'intersection-observers',
43
- 'trigger-global-event',
44
- 'exposure-scene',
45
- 'exposure-id',
46
- 'exposure-screen-margin-top',
47
- 'exposure-screen-margin-bottom',
48
- 'exposure-screen-margin-left',
49
- 'exposure-screen-margin-right',
50
- 'focusable',
51
- 'focus-index',
52
- 'accessibility-label',
53
- 'accessibility-element',
54
- 'accessibility-traits',
55
- 'enable-new-animator',
56
- ]);
57
-
58
- function takeComponentAttributes(jsxComponent: any): Record<string, any> {
59
- const attributes: Record<string, any> = {};
60
- Object.keys(jsxComponent.props).forEach((k) => {
61
- // let re1 = Regex::new(r"^(global-bind|bind|catch|capture-bind|capture-catch)([A-Za-z]+)$").unwrap();
62
- // let re2 = Regex::new(r"^data-([A-Za-z]+)$").unwrap();
63
- if (
64
- __COMPONENT_ATTRIBUTES__.has(k)
65
- || k === 'id'
66
- || k === 'className'
67
- || k === 'dataSet'
68
- || k === 'data-set'
69
- || k === 'removeComponentElement'
70
- || (/^(global-bind|bind|catch|capture-bind|capture-catch)([A-Za-z]+)$/.exec(k))
71
- || (/^data-([A-Za-z]+)$/.exec(k))
72
- ) {
73
- attributes[k] = jsxComponent.props[k];
74
- delete jsxComponent.props[k];
75
- }
76
- });
77
-
78
- return attributes;
79
- }
@@ -1,9 +0,0 @@
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
- const logDebug: (...args: any[]) => void = console.debug;
5
-
6
- /**
7
- * @internal
8
- */
9
- export { logDebug };
@@ -1,28 +0,0 @@
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
- import { BackgroundSnapshotInstance } from '../backgroundSnapshot.js';
5
- import { SnapshotInstance } from '../snapshot.js';
6
- import { logDebug } from './debug.js';
7
-
8
- export function printSnapshotInstance(
9
- instance: BackgroundSnapshotInstance | SnapshotInstance,
10
- log?: (...data: any[]) => void,
11
- ): void {
12
- const impl = (
13
- instance: BackgroundSnapshotInstance | SnapshotInstance,
14
- level: number,
15
- ) => {
16
- let msg = '';
17
- for (let i = 0; i < level; ++i) {
18
- msg += ' ';
19
- }
20
- msg += `| ${instance.__id}(${instance.type}): ${JSON.stringify(instance.__values)}`;
21
- (log ?? logDebug)(msg);
22
- for (const c of instance.childNodes) {
23
- impl(c, level + 1);
24
- }
25
- };
26
-
27
- impl(instance, 0);
28
- }
@@ -1,55 +0,0 @@
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
- import { options } from 'preact';
5
- import type { Component, ComponentClass, VNode } from 'preact';
6
-
7
- import { COMPONENT, DIFF, DIFFED, RENDER } from '../renderToOpcodes/constants.js';
8
-
9
- export function initProfileHook(): void {
10
- const oldDiff = options[DIFF];
11
- options[DIFF] = function(vnode: VNode) {
12
- // This __PROFILE__ is used for DCE testing
13
- if (__PROFILE__ && typeof vnode.type === 'function') {
14
- // We only add profiling trace for Component
15
- console.profile(`diff::${getDisplayName(vnode.type as ComponentClass)}`);
16
- }
17
- oldDiff?.(vnode);
18
- };
19
- const oldDiffed = options[DIFFED];
20
- options[DIFFED] = function(vnode) {
21
- // This __PROFILE__ is used for DCE testing
22
- if (__PROFILE__ && typeof vnode.type === 'function') {
23
- console.profileEnd(); // for options[DIFF]
24
- }
25
- oldDiffed?.(vnode);
26
- };
27
-
28
- // Profile the user-provided `render`.
29
- const oldRender = options[RENDER];
30
- options[RENDER] = function(vnode: VNode & { [COMPONENT]: Component }) {
31
- const displayName = getDisplayName(vnode.type as ComponentClass);
32
- // eslint-disable-next-line @typescript-eslint/unbound-method
33
- const originalRender = vnode[COMPONENT].render;
34
- vnode[COMPONENT].render = function render(this, props, state, context) {
35
- // This __PROFILE__ is used for DCE testing
36
- if (__PROFILE__) {
37
- console.profile(`render::${displayName}`);
38
- }
39
- try {
40
- return originalRender.call(this, props, state, context);
41
- } finally {
42
- // This __PROFILE__ is used for DCE testing
43
- if (__PROFILE__) {
44
- console.profileEnd();
45
- }
46
- vnode[COMPONENT].render = originalRender;
47
- }
48
- };
49
- oldRender?.(vnode);
50
- };
51
- }
52
-
53
- function getDisplayName(type: ComponentClass): string {
54
- return type.displayName ?? type.name;
55
- }
@@ -1,84 +0,0 @@
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
- import { BackgroundSnapshotInstance } from './backgroundSnapshot.js';
5
- import { SnapshotInstance } from './snapshot.js';
6
-
7
- /**
8
- * This module implements an Interface Adapter Pattern to integrate Preact's
9
- * rendering system with Lynx's custom Snapshot-based virtual DOM.
10
- *
11
- * It works by:
12
- * 1. Defining a minimal {@link Document}-like interface that Preact expects
13
- * 2. Implementing this interface to return our {@link Snapshot} instances
14
- * 3. Maintaining the same method signatures as the standard DOM API
15
- *
16
- * This allows Preact to build its virtual tree using our Snapshot system
17
- * without knowing it's not working with a real DOM.
18
- */
19
-
20
- /**
21
- * Defines the minimal document interface that Preact expects, depending on
22
- * which thread is running.
23
- */
24
- interface SnapshotDocumentAdapter {
25
- createElement(type: string): BackgroundSnapshotInstance | SnapshotInstance;
26
- createElementNS(ns: string | null, type: string): BackgroundSnapshotInstance | SnapshotInstance;
27
- createTextNode(text: string): BackgroundSnapshotInstance | SnapshotInstance;
28
- }
29
-
30
- const document: SnapshotDocumentAdapter = {} as SnapshotDocumentAdapter;
31
-
32
- /**
33
- * Sets up the document interface for the background thread.
34
- * All DOM operations are intercepted to create {@link BackgroundSnapshotInstance}.
35
- */
36
- function setupBackgroundDocument(): void {
37
- document.createElement = function(type: string) {
38
- return new BackgroundSnapshotInstance(type);
39
- };
40
- document.createElementNS = function(_ns: string, type: string) {
41
- return new BackgroundSnapshotInstance(type);
42
- };
43
- document.createTextNode = function(text: string) {
44
- const i = new BackgroundSnapshotInstance(null as unknown as string);
45
- i.setAttribute(0, text);
46
- Object.defineProperty(i, 'data', {
47
- set(v) {
48
- i.setAttribute(0, v);
49
- },
50
- });
51
- return i;
52
- };
53
- }
54
-
55
- /**
56
- * Sets up the document interface for the main thread.
57
- * All DOM operations are intercepted to create {@link SnapshotInstance}.
58
- */
59
- function setupDocument(): void {
60
- document.createElement = function(type: string) {
61
- return new SnapshotInstance(type);
62
- };
63
- document.createElementNS = function(_ns: string, type: string) {
64
- return new SnapshotInstance(type);
65
- };
66
- document.createTextNode = function(text: string) {
67
- const i = new SnapshotInstance(null as unknown as string);
68
- i.setAttribute(0, text);
69
- Object.defineProperty(i, 'data', {
70
- set(v) {
71
- i.setAttribute(0, v);
72
- },
73
- });
74
- return i;
75
- };
76
- }
77
-
78
- // if (__JS__) {
79
- // setupBackgroundDocument();
80
- // } else if (__LEPUS__) {
81
- // setupDocument();
82
- // }
83
-
84
- export { document, setupBackgroundDocument, setupDocument };
@@ -1,89 +0,0 @@
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
- import { onWorkletCtxUpdate } from '@lynx-js/react/worklet-runtime/bindings';
5
-
6
- import { GestureTypeInner } from './types.js';
7
- import type { BaseGesture, ComposedGesture, GestureConfig, GestureKind } from './types.js';
8
-
9
- function isSerializedGesture(gesture: GestureKind): boolean {
10
- return gesture.__isSerialized ?? false;
11
- }
12
-
13
- function getGestureInfo(
14
- gesture: BaseGesture,
15
- oldGesture: BaseGesture | undefined,
16
- isFirstScreen: boolean,
17
- dom: FiberElement,
18
- ) {
19
- const config = {
20
- callbacks: [],
21
- } as GestureConfig;
22
- const baseGesture = gesture;
23
-
24
- if (baseGesture.config) {
25
- config.config = baseGesture.config;
26
- }
27
-
28
- for (
29
- const key of Object.keys(baseGesture.callbacks)
30
- ) {
31
- const callback = baseGesture.callbacks[key]!;
32
- const oldCallback = oldGesture?.callbacks[key];
33
- onWorkletCtxUpdate(callback, oldCallback, isFirstScreen, dom);
34
- config.callbacks.push({
35
- name: key,
36
- callback: callback,
37
- });
38
- }
39
-
40
- const relationMap = {
41
- waitFor: baseGesture?.waitFor?.map(subGesture => subGesture.id) ?? [],
42
- simultaneous: baseGesture?.simultaneousWith?.map(subGesture => subGesture.id) ?? [],
43
- continueWith: baseGesture?.continueWith?.map(subGesture => subGesture.id) ?? [],
44
- };
45
-
46
- return {
47
- config,
48
- relationMap,
49
- };
50
- }
51
-
52
- export function processGesture(
53
- dom: FiberElement,
54
- gesture: GestureKind,
55
- oldGesture: GestureKind | undefined,
56
- isFirstScreen: boolean,
57
- gestureOptions?: {
58
- domSet: boolean;
59
- },
60
- ): void {
61
- if (!gesture || !isSerializedGesture(gesture)) {
62
- return;
63
- }
64
-
65
- if (!(gestureOptions && gestureOptions.domSet)) {
66
- __SetAttribute(dom, 'has-react-gesture', true);
67
- __SetAttribute(dom, 'flatten', false);
68
- }
69
-
70
- if (gesture.type === GestureTypeInner.COMPOSED) {
71
- for (const [index, subGesture] of (gesture as ComposedGesture).gestures.entries()) {
72
- processGesture(dom, subGesture, (oldGesture as ComposedGesture)?.gestures[index], isFirstScreen, {
73
- domSet: true,
74
- });
75
- }
76
- } else {
77
- const baseGesture = gesture as BaseGesture;
78
- const oldBaseGesture = oldGesture as BaseGesture | undefined;
79
-
80
- const { config, relationMap } = getGestureInfo(baseGesture, oldBaseGesture, isFirstScreen, dom);
81
- __SetGestureDetector(
82
- dom,
83
- baseGesture.id,
84
- baseGesture.type,
85
- config,
86
- relationMap,
87
- );
88
- }
89
- }
@@ -1,19 +0,0 @@
1
- // Copyright 2025 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 { GestureTypeInner } from './types.js';
5
- import type { BaseGesture, ComposedGesture, GestureKind } from './types.js';
6
- import { onPostWorkletCtx } from '../worklet/ctx.js';
7
-
8
- export function processGestureBackground(gesture: GestureKind): void {
9
- if (gesture.type === GestureTypeInner.COMPOSED) {
10
- for (const subGesture of (gesture as ComposedGesture).gestures) {
11
- processGestureBackground(subGesture);
12
- }
13
- } else {
14
- const baseGesture = gesture as BaseGesture;
15
- for (const [name, value] of Object.entries(baseGesture.callbacks)) {
16
- baseGesture.callbacks[name] = onPostWorkletCtx(value)!;
17
- }
18
- }
19
- }
@@ -1,44 +0,0 @@
1
- // Copyright 2025 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 type { Worklet } from '@lynx-js/react/worklet-runtime/bindings';
5
-
6
- export enum GestureTypeInner {
7
- COMPOSED = -1,
8
- PAN = 0,
9
- FLING = 1,
10
- DEFAULT = 2,
11
- TAP = 3,
12
- LONGPRESS = 4,
13
- ROTATION = 5,
14
- PINCH = 6,
15
- NATIVE = 7,
16
- }
17
-
18
- export interface GestureKind {
19
- type: GestureTypeInner;
20
- __isSerialized?: boolean;
21
- __isGesture?: boolean;
22
- }
23
-
24
- export interface ComposedGesture extends GestureKind {
25
- type: GestureTypeInner.COMPOSED;
26
- gestures: GestureKind[];
27
- }
28
-
29
- export interface BaseGesture extends GestureKind {
30
- id: number;
31
- callbacks: Record<string, Worklet>;
32
- waitFor: BaseGesture[];
33
- simultaneousWith: BaseGesture[];
34
- continueWith: BaseGesture[];
35
- config?: Record<string, unknown>;
36
- }
37
-
38
- export interface GestureConfig {
39
- callbacks: {
40
- name: string;
41
- callback: Worklet;
42
- }[];
43
- config?: Record<string, unknown>;
44
- }
@@ -1,62 +0,0 @@
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
- import {
5
- useCallback,
6
- useContext,
7
- useDebugValue,
8
- useErrorBoundary,
9
- useId,
10
- useImperativeHandle,
11
- useMemo,
12
- useEffect as usePreactEffect,
13
- useReducer,
14
- useRef,
15
- useState,
16
- } from 'preact/hooks';
17
- import type { DependencyList, EffectCallback } from 'react';
18
-
19
- /**
20
- * `useLayoutEffect` is now an alias of `useEffect`. Use `useEffect` instead.
21
- *
22
- * Accepts a function that contains imperative, possibly effectful code. The effects run after main thread dom update without blocking it.
23
- *
24
- * @param effect - Imperative function that can return a cleanup function
25
- * @param deps - If present, effect will only activate if the values in the list change (using ===).
26
- *
27
- * @public
28
- *
29
- * @deprecated `useLayoutEffect` in the background thread cannot offer the precise timing for reading layout information and synchronously re-render, which is different from React.
30
- */
31
- function useLayoutEffect(effect: EffectCallback, deps?: DependencyList): void {
32
- return usePreactEffect(effect, deps);
33
- }
34
-
35
- /**
36
- * Accepts a function that contains imperative, possibly effectful code.
37
- * The effects run after main thread dom update without blocking it.
38
- *
39
- * @param effect - Imperative function that can return a cleanup function
40
- * @param deps - If present, effect will only activate if the values in the list change (using ===).
41
- *
42
- * @public
43
- */
44
- function useEffect(effect: EffectCallback, deps?: DependencyList): void {
45
- return usePreactEffect(effect, deps);
46
- }
47
-
48
- export {
49
- // preact
50
- useState,
51
- useReducer,
52
- useRef,
53
- useImperativeHandle,
54
- useLayoutEffect,
55
- useEffect,
56
- useCallback,
57
- useMemo,
58
- useContext,
59
- useDebugValue,
60
- useErrorBoundary,
61
- useId,
62
- };
@@ -1,59 +0,0 @@
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
- import { useEffect, useMemo, useRef } from 'preact/hooks';
5
-
6
- /**
7
- * `useLynxGlobalEventListener` help you `addListener` as early as possible.
8
- *
9
- * @example
10
- *
11
- * Use this hooks to listen to event 'exposure' and event 'disexposure'
12
- *
13
- * ```jsx
14
- * function App() {
15
- * useLynxGlobalEventListener('exposure', (e) => {
16
- * console.log("exposure", e)
17
- * })
18
- * useLynxGlobalEventListener('disexposure', (e) => {
19
- * console.log("disexposure", e)
20
- * })
21
- * return (
22
- * <view
23
- * style='width: 100px; height: 100px; background-color: red;'
24
- * exposure-id='a'
25
- * />
26
- * )
27
- * }
28
- * ```
29
- *
30
- * @param eventName - Event name to listen
31
- * @param listener - Event handler
32
- * @public
33
- */
34
- export function useLynxGlobalEventListener<T extends (...args: any[]) => void>(
35
- eventName: string,
36
- listener: T,
37
- ): void {
38
- 'background only';
39
-
40
- const previousArgsRef = useRef<[string, T]>();
41
-
42
- useMemo(() => {
43
- if (previousArgsRef.current) {
44
- const [eventName, listener] = previousArgsRef.current;
45
- lynx.getJSModule('GlobalEventEmitter').removeListener(eventName, listener);
46
- }
47
- lynx.getJSModule('GlobalEventEmitter').addListener(eventName, listener);
48
- previousArgsRef.current = [eventName, listener];
49
- }, [eventName, listener]);
50
-
51
- useEffect(() => {
52
- return () => {
53
- if (previousArgsRef.current) {
54
- const [eventName, listener] = previousArgsRef.current;
55
- lynx.getJSModule('GlobalEventEmitter').removeListener(eventName, listener);
56
- }
57
- };
58
- }, []);
59
- }