@weapp-core/shared 3.4.3 → 3.5.0-dev.20261115.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.
@@ -0,0 +1,43 @@
1
+ export interface NativeDomEvent {
2
+ detail?: unknown;
3
+ stopPropagation?: () => void;
4
+ target?: unknown;
5
+ type?: string;
6
+ }
7
+ export interface NativeDomNode {
8
+ addEventListener: (type: string, listener: (event: NativeDomEvent) => void, capture?: boolean) => void;
9
+ appendChild: (node: NativeDomNode) => unknown;
10
+ insertBefore: (node: NativeDomNode, before: NativeDomNode | null) => unknown;
11
+ nodeValue?: string | null;
12
+ removeAttribute: (name: string) => void;
13
+ removeChild: (node: NativeDomNode) => unknown;
14
+ removeEventListener: (type: string, listener: (event: NativeDomEvent) => void, capture?: boolean) => void;
15
+ setAttribute: (name: string, value: unknown) => void;
16
+ }
17
+ export interface NativeDomDocument {
18
+ createElement: (type: string) => NativeDomNode;
19
+ createNativeComponent: (type: string, options: Record<string, unknown>) => NativeDomNode;
20
+ createTextNode: (value: string) => NativeDomNode;
21
+ getPageDocumentById: (webviewId: number) => NativeDomNode | undefined;
22
+ }
23
+ export interface TtRuntime {
24
+ appDocument?: NativeDomDocument;
25
+ getBuiltInComponents?: () => Set<string> | string[];
26
+ getRenderMode?: () => number;
27
+ }
28
+ export declare const DEFAULT_BUILT_IN_COMPONENTS: Set<string>;
29
+ export type NativeDomRendererMode = 'legacy' | 'auto' | 'native-dom';
30
+ export interface NativeDomSelection {
31
+ appDocument: NativeDomDocument;
32
+ container: NativeDomNode;
33
+ builtInComponents: Set<string>;
34
+ }
35
+ /** 在开始执行用户 setup 前选择后端;探针失败仅允许 auto 回退。 */
36
+ export declare function selectNativeDom(config: {
37
+ mode: NativeDomRendererMode;
38
+ platform: string;
39
+ }, adapter: {
40
+ __webviewId__?: number;
41
+ }, owner: string): NativeDomSelection | undefined;
42
+ /** 按平台内置组件清单创建节点,其他标签交给原生组件 bridge。 */
43
+ export declare function createNativeDomElement(selection: NativeDomSelection, type: string): NativeDomNode;
@@ -0,0 +1,74 @@
1
+ // src/native-dom.ts
2
+ const DEFAULT_BUILT_IN_COMPONENTS = /* @__PURE__ */ new Set([
3
+ "ad",
4
+ "audio",
5
+ "block",
6
+ "button",
7
+ "camera",
8
+ "canvas",
9
+ "checkbox",
10
+ "checkbox-group",
11
+ "cover-image",
12
+ "cover-view",
13
+ "editor",
14
+ "form",
15
+ "functional-page-navigator",
16
+ "icon",
17
+ "image",
18
+ "input",
19
+ "label",
20
+ "live-player",
21
+ "live-pusher",
22
+ "map",
23
+ "movable-area",
24
+ "movable-view",
25
+ "navigator",
26
+ "official-account",
27
+ "open-data",
28
+ "picker",
29
+ "picker-view",
30
+ "picker-view-column",
31
+ "progress",
32
+ "radio",
33
+ "radio-group",
34
+ "rich-text",
35
+ "scroll-view",
36
+ "slot",
37
+ "slider",
38
+ "swiper",
39
+ "swiper-item",
40
+ "switch",
41
+ "textarea",
42
+ "text",
43
+ "video",
44
+ "view",
45
+ "web-view"
46
+ ]);
47
+ /** 在开始执行用户 setup 前选择后端;探针失败仅允许 auto 回退。 */
48
+ function selectNativeDom(config, adapter, owner) {
49
+ if (config.mode === "legacy" || config.mode === "auto" && config.platform !== "tt") return;
50
+ if (config.platform !== "tt") throw new Error(`[${owner}] renderer: 'native-dom' 仅支持 tt 平台,当前目标为 ${config.platform || "unknown"}`);
51
+ try {
52
+ const runtime = globalThis.tt;
53
+ const appDocument = runtime?.appDocument;
54
+ if (runtime?.getRenderMode?.() !== 2 || !appDocument || typeof appDocument.createElement !== "function" || typeof appDocument.createNativeComponent !== "function" || typeof appDocument.createTextNode !== "function" || typeof appDocument.getPageDocumentById !== "function" || typeof adapter.__webviewId__ !== "number") throw new Error("Render Mode V2 API 不可用");
55
+ const container = appDocument.getPageDocumentById(adapter.__webviewId__);
56
+ if (!container) throw new Error("页面文档尚不可用");
57
+ const builtIn = runtime.getBuiltInComponents?.();
58
+ return {
59
+ appDocument,
60
+ container,
61
+ builtInComponents: builtIn instanceof Set ? builtIn : Array.isArray(builtIn) ? new Set(builtIn) : DEFAULT_BUILT_IN_COMPONENTS
62
+ };
63
+ } catch (cause) {
64
+ if (config.mode === "auto") return;
65
+ const error = /* @__PURE__ */ new Error(`[${owner}] renderer: 'native-dom' 需要抖音 Render Mode V2、tt.appDocument 与当前页面 __webviewId__ (${cause instanceof Error ? cause.message : String(cause)})`);
66
+ error.cause = cause;
67
+ throw error;
68
+ }
69
+ }
70
+ /** 按平台内置组件清单创建节点,其他标签交给原生组件 bridge。 */
71
+ function createNativeDomElement(selection, type) {
72
+ return selection.builtInComponents.has(type) ? selection.appDocument.createElement(type) : selection.appDocument.createNativeComponent(type, { __tt__inner__options__: { name: type } });
73
+ }
74
+ export { DEFAULT_BUILT_IN_COMPONENTS, createNativeDomElement, selectNativeDom };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@weapp-core/shared",
3
3
  "type": "module",
4
- "version": "3.4.3",
4
+ "version": "3.5.0-dev.20261115.1",
5
5
  "description": "Shared runtime-safe utilities and platform contracts for the weapp-vite ecosystem.",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
@@ -55,6 +55,10 @@
55
55
  "./platforms/runtime": {
56
56
  "types": "./src/platforms/runtime/index.ts",
57
57
  "default": "./src/platforms/runtime/index.ts"
58
+ },
59
+ "./native-dom": {
60
+ "types": "./src/native-dom.ts",
61
+ "default": "./src/native-dom.ts"
58
62
  }
59
63
  },
60
64
  "main": "./src/index.ts",
@@ -85,6 +89,10 @@
85
89
  "./platforms/runtime": {
86
90
  "types": "./dist/platforms/runtime/index.d.ts",
87
91
  "import": "./dist/platforms/runtime/index.js"
92
+ },
93
+ "./native-dom": {
94
+ "types": "./dist/native-dom.d.ts",
95
+ "import": "./dist/native-dom.js"
88
96
  }
89
97
  },
90
98
  "main": "./dist/index.js",
@@ -98,14 +106,22 @@
98
106
  },
99
107
  "dependencies": {
100
108
  "@types/set-value": "^4.0.3",
101
- "@weapp-vite/wxml": "0.0.1",
109
+ "@weapp-vite/wxml": "0.0.2-dev.20261115.1",
102
110
  "domhandler": "^6.0.1",
103
111
  "get-value": "^4.1.0",
104
112
  "htmlparser2": "^12.0.0"
105
113
  },
106
114
  "publishConfig": {
107
115
  "access": "public",
108
- "registry": "https://registry.npmjs.org"
116
+ "registry": "https://registry.npmjs.org/",
117
+ "tag": "snapshot-nightly"
118
+ },
119
+ "repoctlSnapshot": {
120
+ "kind": "nightly",
121
+ "commit": "f3693c09b01bae2d6805c1d621aacf2e44d64cc4",
122
+ "buildId": "43665076788-1",
123
+ "identityKey": "73d798fdc7fc7b6de9dae22159bc39f6ef7c896eac6ccd9058a2e871a5da073a",
124
+ "tag": "snapshot-nightly"
109
125
  },
110
126
  "scripts": {
111
127
  "dev": "tsdown -w --sourcemap",
@@ -120,4 +136,4 @@
120
136
  "lint:fix": "eslint . --fix",
121
137
  "sync": "repo release sync-npmmirror --package @weapp-core/shared"
122
138
  }
123
- }
139
+ }