@lingxia/elements 0.15.0 → 0.17.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 (67) hide show
  1. package/dist/index.d.ts +3 -2
  2. package/dist/index.js +1 -0
  3. package/dist/inline-native/commit.d.ts +39 -0
  4. package/dist/inline-native/commit.js +94 -0
  5. package/dist/inline-native/elements.d.ts +104 -0
  6. package/dist/inline-native/elements.js +749 -0
  7. package/dist/inline-native/errors.d.ts +8 -0
  8. package/dist/inline-native/errors.js +23 -0
  9. package/dist/inline-native/events.d.ts +10 -0
  10. package/dist/inline-native/events.js +16 -0
  11. package/dist/inline-native/geometry.d.ts +78 -0
  12. package/dist/inline-native/geometry.js +40 -0
  13. package/dist/inline-native/identity.d.ts +28 -0
  14. package/dist/inline-native/identity.js +51 -0
  15. package/dist/inline-native/index.d.ts +14 -0
  16. package/dist/inline-native/index.js +19 -0
  17. package/dist/inline-native/layout.d.ts +2 -0
  18. package/dist/inline-native/layout.js +58 -0
  19. package/dist/inline-native/lease.d.ts +13 -0
  20. package/dist/inline-native/lease.js +31 -0
  21. package/dist/inline-native/runtime.d.ts +64 -0
  22. package/dist/inline-native/runtime.js +119 -0
  23. package/dist/inline-native/schema.d.ts +111 -0
  24. package/dist/inline-native/schema.js +210 -0
  25. package/dist/inline-native/structure.d.ts +22 -0
  26. package/dist/inline-native/structure.js +706 -0
  27. package/dist/inline-native/style.d.ts +7 -0
  28. package/dist/inline-native/style.js +119 -0
  29. package/dist/inline-native/types.d.ts +82 -0
  30. package/dist/inline-native/types.js +7 -0
  31. package/dist/inline-native/unwrap.d.ts +10 -0
  32. package/dist/inline-native/unwrap.js +32 -0
  33. package/dist/inline-native/video.d.ts +65 -0
  34. package/dist/inline-native/video.js +69 -0
  35. package/dist/native_component_wrapper_shared.d.ts +3 -2
  36. package/dist/native_component_wrapper_shared.js +6 -3
  37. package/dist/nativecomponent.d.ts +1 -1
  38. package/dist/nativecomponent.js +8 -11
  39. package/dist/navigator.d.ts +2 -2
  40. package/dist/navigator.js +5 -5
  41. package/dist/video-events.d.ts +2 -0
  42. package/dist/video-events.js +18 -0
  43. package/dist/video.d.ts +98 -79
  44. package/dist/video.js +182 -757
  45. package/package.json +2 -1
  46. package/src/index.ts +58 -1
  47. package/src/inline-native/commit.ts +141 -0
  48. package/src/inline-native/elements.ts +829 -0
  49. package/src/inline-native/errors.ts +35 -0
  50. package/src/inline-native/events.ts +31 -0
  51. package/src/inline-native/geometry.ts +86 -0
  52. package/src/inline-native/identity.ts +102 -0
  53. package/src/inline-native/index.ts +103 -0
  54. package/src/inline-native/layout.ts +58 -0
  55. package/src/inline-native/lease.ts +48 -0
  56. package/src/inline-native/runtime.ts +185 -0
  57. package/src/inline-native/schema.ts +247 -0
  58. package/src/inline-native/structure.ts +823 -0
  59. package/src/inline-native/style.ts +111 -0
  60. package/src/inline-native/types.ts +105 -0
  61. package/src/inline-native/unwrap.ts +34 -0
  62. package/src/inline-native/video.ts +125 -0
  63. package/src/native_component_wrapper_shared.ts +8 -6
  64. package/src/nativecomponent.ts +8 -13
  65. package/src/navigator.ts +9 -9
  66. package/src/video-events.ts +16 -0
  67. package/src/video.ts +245 -839
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lingxia/elements",
3
- "version": "0.15.0",
3
+ "version": "0.17.0",
4
4
  "private": false,
5
5
  "description": "LingXia custom elements — native-backed web components for LxApp pages",
6
6
  "type": "module",
@@ -15,6 +15,7 @@
15
15
  },
16
16
  "scripts": {
17
17
  "build": "npm --prefix ../lingxia-bridge run build:types && tsc -p tsconfig.json",
18
+ "test:inline-native": "npm run build && node tests/inline-native-structure.mjs && node tests/inline-native-unwrap.mjs && node tests/inline-native-runtime.mjs && node tests/inline-native-events.mjs && node tests/inline-native-style.mjs && node tests/video-events.mjs && node tests/inline-native-identity.mjs && node tests/inline-native-contract.mjs",
18
19
  "clean": "rm -rf dist",
19
20
  "prepublishOnly": "npm run build"
20
21
  },
package/src/index.ts CHANGED
@@ -2,6 +2,8 @@ export {
2
2
  registerVideoComponent,
3
3
  LxVideoElement,
4
4
  type LxVideoAttributes,
5
+ type LxVideoEventPayloads,
6
+ type LxVideoEventHandlers,
5
7
  } from "./video.js";
6
8
 
7
9
  export {
@@ -38,7 +40,7 @@ export {
38
40
  LxNavigatorElement,
39
41
  type LxNavigatorAttributes,
40
42
  type LxNavigatorEvent,
41
- type NavigatorEnvVersion,
43
+ type NavigatorChannel,
42
44
  type NavigatorOpenType,
43
45
  type NavigatorQuery,
44
46
  type NavigatorQueryValue,
@@ -71,3 +73,58 @@ export {
71
73
  NativeComponentUpdateState,
72
74
  type Rect,
73
75
  } from "./component.js";
76
+
77
+ export {
78
+ INLINE_NATIVE_SCHEMA,
79
+ NATIVE_ERROR_CODES,
80
+ PUBLIC_COMPONENT_NAMES,
81
+ PUBLIC_ELEMENT_TAGS,
82
+ CORE_KINDS,
83
+ HOST_FACTORY_KINDS,
84
+ compileInlineNativeRoot,
85
+ compileInlineNativeForest,
86
+ identifyCompiledRoot,
87
+ buildRootCommit,
88
+ buildGeometrySnapshot,
89
+ publishCompiledRoot,
90
+ applyHostLeaseMessage,
91
+ createRootRuntimeState,
92
+ viewCanShowFallback,
93
+ collectVideoResourceUrls,
94
+ buildVideoCommandRequest,
95
+ collectAuthorTreeFromElement,
96
+ normalizeAuthorType,
97
+ parseBooleanAttr,
98
+ unwrapNativeEventPayload,
99
+ bindPayloadHandler,
100
+ nativeError,
101
+ registerInlineNativeComponents,
102
+ registerInlineNativeAuthorComponents,
103
+ registerNativeRootComponent,
104
+ registerNativeViewComponent,
105
+ registerNativeCoverComponent,
106
+ registerNativeTextComponent,
107
+ registerNativeButtonComponent,
108
+ LxNativeRootElement,
109
+ LxNativeViewElement,
110
+ LxNativeCoverElement,
111
+ LxNativeTextElement,
112
+ LxNativeButtonElement,
113
+ EMPTY_ROOT_REF,
114
+ type NativeErrorCode,
115
+ type PublicComponentName,
116
+ type RootRef,
117
+ type NodeRef,
118
+ type NativeError,
119
+ type AuthorNode,
120
+ type CoreNode,
121
+ type CompiledNativeRoot,
122
+ type CompileInlineNativeResult,
123
+ type PressPayload,
124
+ type ValuePayload,
125
+ type FocusPayload,
126
+ type PointerPayload,
127
+ type NativeHandler,
128
+ type NativeActionIcon,
129
+ type NativeStyleProperty,
130
+ } from "./inline-native/index.js";
@@ -0,0 +1,141 @@
1
+ import type { IdentifiedNode, IdentifiedRoot } from "./identity.js";
2
+ import type { RootRef } from "./types.js";
3
+
4
+ export interface NativeRootCommitJson {
5
+ action: "root.commit";
6
+ root: RootRef;
7
+ baseRevision: number;
8
+ revision: number;
9
+ operations: NativeRootOperationJson[];
10
+ }
11
+
12
+ export type NativeRootOperationJson =
13
+ | { op: "mount"; node: NativeNodeJson }
14
+ | { op: "update"; node: IdentifiedNode["nodeRef"]; patch: Record<string, unknown> }
15
+ | { op: "reparent"; node: IdentifiedNode["nodeRef"]; parent: IdentifiedNode["nodeRef"] | null }
16
+ | { op: "reorder"; node: IdentifiedNode["nodeRef"]; order: number }
17
+ | { op: "unmount"; node: IdentifiedNode["nodeRef"] };
18
+
19
+ export interface NativeNodeJson {
20
+ ref: IdentifiedNode["nodeRef"];
21
+ kind: string;
22
+ parent: IdentifiedNode["nodeRef"] | null;
23
+ order: number;
24
+ authorType: string;
25
+ authorId?: string;
26
+ automationId?: string;
27
+ props: Record<string, unknown>;
28
+ }
29
+
30
+ export function buildRootCommit(
31
+ next: IdentifiedRoot,
32
+ previous: IdentifiedRoot | null,
33
+ revision: number
34
+ ): NativeRootCommitJson {
35
+ const baseRevision = previous ? revision - 1 : 0;
36
+ const operations: NativeRootOperationJson[] = [];
37
+ const prevIndex = previous ? indexIdentified(previous) : new Map<string, IdentifiedNode>();
38
+ const nextIndex = indexIdentified(next);
39
+
40
+ walkMounts(next.children, prevIndex, operations);
41
+
42
+ for (const [key, current] of nextIndex) {
43
+ const prev = prevIndex.get(key);
44
+ if (!prev) continue;
45
+ if (parentKey(prev) !== parentKey(current)) {
46
+ operations.push({
47
+ op: "reparent",
48
+ node: current.nodeRef,
49
+ parent: current.parentRef,
50
+ });
51
+ }
52
+ if (prev.order !== current.order) {
53
+ operations.push({ op: "reorder", node: current.nodeRef, order: current.order });
54
+ }
55
+ const patch = propsPatch(effectiveProps(prev), effectiveProps(current));
56
+ if (patch) {
57
+ operations.push({ op: "update", node: current.nodeRef, patch });
58
+ }
59
+ }
60
+
61
+ // Retained children must leave removed parents before the host cascades unmount.
62
+ for (const [key, prev] of prevIndex) {
63
+ if (!nextIndex.has(key)) {
64
+ operations.push({ op: "unmount", node: prev.nodeRef });
65
+ }
66
+ }
67
+
68
+
69
+ return {
70
+ action: "root.commit",
71
+ root: next.rootRef,
72
+ baseRevision,
73
+ revision,
74
+ operations,
75
+ };
76
+ }
77
+
78
+ function walkMounts(
79
+ nodes: readonly IdentifiedNode[],
80
+ prevIndex: Map<string, IdentifiedNode>,
81
+ operations: NativeRootOperationJson[]
82
+ ): void {
83
+ for (const node of nodes) {
84
+ if (!prevIndex.has(node.nodeRef.nodeKey)) {
85
+ operations.push({
86
+ op: "mount",
87
+ node: {
88
+ ref: node.nodeRef,
89
+ kind: node.node.kind,
90
+ parent: node.parentRef,
91
+ order: node.order,
92
+ authorType: node.node.authorType,
93
+ authorId: node.node.authorId,
94
+ automationId: node.node.automationId,
95
+ props: effectiveProps(node),
96
+ },
97
+ });
98
+ }
99
+ walkMounts(node.children, prevIndex, operations);
100
+ }
101
+ }
102
+
103
+ function indexIdentified(root: IdentifiedRoot): Map<string, IdentifiedNode> {
104
+ const map = new Map<string, IdentifiedNode>();
105
+ const walk = (nodes: readonly IdentifiedNode[]) => {
106
+ for (const node of nodes) {
107
+ map.set(node.nodeRef.nodeKey, node);
108
+ walk(node.children);
109
+ }
110
+ };
111
+ walk(root.children);
112
+ return map;
113
+ }
114
+
115
+ function parentKey(node: IdentifiedNode): string {
116
+ return node.parentRef?.nodeKey ?? "";
117
+ }
118
+
119
+ /// `text` is a sibling of `props` on the core node, but the host reads it from
120
+ /// props. Fold it in for both the mount and the diff, or a caption that changes
121
+ /// after mount emits no update and the host keeps painting the first string.
122
+ function effectiveProps(node: IdentifiedNode): Record<string, unknown> {
123
+ return node.node.text !== undefined
124
+ ? { ...node.node.props, text: node.node.text }
125
+ : node.node.props;
126
+ }
127
+
128
+ function propsPatch(
129
+ prev: Record<string, unknown>,
130
+ next: Record<string, unknown>
131
+ ): Record<string, unknown> | null {
132
+ const patch: Record<string, unknown> = {};
133
+ let changed = false;
134
+ const keys = new Set([...Object.keys(prev), ...Object.keys(next)]);
135
+ for (const key of keys) {
136
+ if (JSON.stringify(prev[key]) === JSON.stringify(next[key])) continue;
137
+ patch[key] = next[key] === undefined ? null : next[key];
138
+ changed = true;
139
+ }
140
+ return changed ? patch : null;
141
+ }