@doubao-dev/framework 0.0.39 → 0.0.41

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.
@@ -328,6 +328,11 @@ export declare interface CanvasProps {
328
328
  * 元素的唯一标识
329
329
  */
330
330
  id?: string;
331
+ /**
332
+ * 原生属性透传,一般由自带画布渲染的三方库使用,业务代码请改用 `ref` 上的绘图方法。
333
+ * 传入后画布交由外部通过 `attachToCanvasView(name)` 接管,组件不再创建自己的画布实例,`ref` 上的绘图方法随之失效。
334
+ */
335
+ name?: string;
331
336
  /**
332
337
  * 手指触摸动作开始
333
338
  * @eventProperty
@@ -3032,6 +3037,47 @@ export declare interface RenderLongImageSegmentsOptions {
3032
3037
  listItemReuseIdentifierPrefix?: string;
3033
3038
  }
3034
3039
 
3040
+ /** An allowlisted HTML element in a rich-text node tree. */
3041
+ export declare interface RichTextElementNode {
3042
+ /** Optional mini-program-compatible element node discriminator. */
3043
+ type?: 'node';
3044
+ /** Name of the allowlisted HTML element to render. */
3045
+ name: string;
3046
+ /** Element attributes; unsupported attributes are removed during parsing. */
3047
+ attrs?: Record<string, string>;
3048
+ /** Nested text and element nodes rendered inside this element. */
3049
+ children?: RichTextNode[];
3050
+ }
3051
+
3052
+ /** A text or element node accepted by RichText. */
3053
+ export declare type RichTextNode = RichTextTextNode | RichTextElementNode;
3054
+
3055
+ /** Props for the mini-program-compatible RichText adapter. */
3056
+ export declare interface RichTextProps {
3057
+ /**
3058
+ * An HTML string or a structured node array to render. Unsupported nodes and
3059
+ * attributes are removed before the content is passed to Lynx UI RichText.
3060
+ */
3061
+ nodes?: string | RichTextNode[];
3062
+ /** How plain spaces in text nodes are converted. */
3063
+ space?: RichTextSpace;
3064
+ /** Class name applied to the outer Lynx container. */
3065
+ className?: string;
3066
+ /** Inline style applied to the outer Lynx container. */
3067
+ style?: CSSProperties | string;
3068
+ }
3069
+
3070
+ /** Whitespace replacement mode compatible with mini-program rich-text. */
3071
+ export declare type RichTextSpace = '' | 'nbsp' | 'ensp' | 'emsp';
3072
+
3073
+ /** Text content in a rich-text node tree. */
3074
+ export declare interface RichTextTextNode {
3075
+ /** Identifies this entry as a text node. */
3076
+ type: 'text';
3077
+ /** Plain text rendered at this position in the node tree. */
3078
+ text: string;
3079
+ }
3080
+
3035
3081
  export declare interface RouteLabel {
3036
3082
  /**
3037
3083
  * 标签 ID。
@@ -3055,6 +3101,11 @@ export declare interface RouteLabel {
3055
3101
  * @defaultValue 12
3056
3102
  */
3057
3103
  fontSize?: number;
3104
+ /**
3105
+ * 标签文字字重。
3106
+ * @defaultValue "normal"
3107
+ */
3108
+ fontWeight?: 'normal' | 'bold';
3058
3109
  /**
3059
3110
  * 标签边框颜色。
3060
3111
  * @defaultValue "#cccccc"
@@ -4626,6 +4677,86 @@ declare interface WebGLContextAttributes_2 {
4626
4677
  antialias?: boolean;
4627
4678
  }
4628
4679
 
4680
+ /**
4681
+ * 网页视图组件,用于在智能服务页面内承载 H5 页面。
4682
+ *
4683
+ * @remarks
4684
+ * ## 与 H5 双向通信
4685
+ *
4686
+ * H5 页面需要先引入 WebView JSSDK,才能收发消息。可以用 script 标签引入:
4687
+ *
4688
+ * ```html
4689
+ * <script src="https://lf3-static.bytednsdoc.com/obj/eden-cn/msvdeh7pfhpquly/doubao-jssdk-0.0.34-canary-1022d83a-20260615035129.js"></script>
4690
+ * ```
4691
+ *
4692
+ * 构建型项目也可以安装 `@doubao-dev/webview-jssdk` 后导入,导入时会同时挂载全局 `window.doubao`:
4693
+ *
4694
+ * ```js
4695
+ * import doubao from '@doubao-dev/webview-jssdk';
4696
+ * // 或按需导入:import { postMessage, onMessage } from '@doubao-dev/webview-jssdk';
4697
+ * ```
4698
+ *
4699
+ * 应用侧:`src` 指向 H5 地址,`ref` 用于拿到 `postMessage`,`onMessage` 接收 H5 消息。
4700
+ *
4701
+ * ```tsx
4702
+ * import { definePage, useRef } from '@doubao-dev/framework';
4703
+ * import type { WebViewRef } from '@doubao-dev/framework/components';
4704
+ *
4705
+ * function WebViewPage() {
4706
+ * const webViewRef = useRef<WebViewRef>(null);
4707
+ *
4708
+ * return (
4709
+ * <web-view
4710
+ * ref={webViewRef}
4711
+ * src="https://example.com/page"
4712
+ * // 网页加载完成后再发首条消息,H5 才接得住
4713
+ * onLoad={(event) => webViewRef.current?.postMessage({ type: 'ready', src: event.src })}
4714
+ * // H5 → 应用:event.data 就是 H5 传入的原始值
4715
+ * onMessage={(event) => {
4716
+ * const data = event.data as { type?: string };
4717
+ * if (data?.type === 'submit') {
4718
+ * webViewRef.current?.postMessage({ type: 'ack', timestamp: Date.now() });
4719
+ * }
4720
+ * }}
4721
+ * onError={(event) => console.error(event.errorMsg, event.errorCode)}
4722
+ * />
4723
+ * );
4724
+ * }
4725
+ *
4726
+ * export default definePage({ render: () => <WebViewPage /> });
4727
+ * ```
4728
+ *
4729
+ * H5 侧:`doubao.onMessage` 接收应用消息并返回注销函数,`doubao.postMessage` 发送消息给应用。
4730
+ *
4731
+ * ```js
4732
+ * const off = doubao.onMessage((raw) => {
4733
+ * // 应用侧发送的对象会被序列化,这里统一还原
4734
+ * const data = typeof raw === 'string' ? JSON.parse(raw) : raw;
4735
+ *
4736
+ * if (data.type === 'ready') {
4737
+ * // H5 → 应用:参数是 { data },不是直接传值
4738
+ * doubao.postMessage({ data: { type: 'submit', payload: { name: '豆包' } } });
4739
+ * }
4740
+ * });
4741
+ *
4742
+ * // 页面卸载或不再需要时注销
4743
+ * // off();
4744
+ * ```
4745
+ *
4746
+ * 三个容易踩的点:
4747
+ *
4748
+ * - 首条消息放在 `onLoad` 之后发,H5 尚未加载完成时发送的消息会丢失。
4749
+ * - 两个方向的数据形态不同:应用 → H5 时非字符串会被 `JSON.stringify`,H5 收到的是 JSON 字符串,
4750
+ * 需要自行 `JSON.parse`;H5 → 应用时 `onMessage` 的 `event.data` 保持 H5 传入的原始值。
4751
+ * - 如果两侧都写成“收到就回”,务必按消息 `type` 区分,否则会无限互相回声。
4752
+ *
4753
+ * 除消息通道外,H5 还可以调用 `doubao.setTitle({ title })` 同步应用侧 WebView 头部标题。
4754
+ *
4755
+ * Web 模拟器中的 `<web-view>` 通过本地代理承载 H5 页面,页面脚本读取到的
4756
+ * `location.origin` / `location.host` 可能是调试器本地域名,而不是真机 WebView 中的业务域名。
4757
+ * 如果 H5 依赖 `location.origin` 或 `location.host` 判断测试环境、线上环境、白名单或鉴权逻辑,
4758
+ * Web 模拟器结果可能与真机不一致,请使用真机调试确认。
4759
+ */
4629
4760
  export declare interface WebViewProps {
4630
4761
  /**
4631
4762
  * 用于获取 WebView 实例方法
package/dist/config.d.ts CHANGED
@@ -27,6 +27,10 @@ declare interface AIAppMetadata {
27
27
  * 应用版本
28
28
  */
29
29
  version?: string;
30
+ /**
31
+ * 是否声明小程序已适配深色模式
32
+ */
33
+ darkMode?: boolean;
30
34
  }
31
35
 
32
36
  declare type AIPageMetadata = Omit<PageDefinition, 'entry' | 'renderType' | 'digest' | 'web'>;
package/dist/index.d.ts CHANGED
@@ -135,6 +135,10 @@ declare interface AIAppMetadata {
135
135
  * 应用版本
136
136
  */
137
137
  version?: string;
138
+ /**
139
+ * 是否声明小程序已适配深色模式
140
+ */
141
+ darkMode?: boolean;
138
142
  }
139
143
 
140
144
  export declare type AIToolContext = MessageMeta & {
@@ -583,6 +587,13 @@ export { NamedExoticComponent }
583
587
 
584
588
  export { NewLifecycle }
585
589
 
590
+ /**
591
+ * Register the runtime error handler.
592
+ *
593
+ * Calling this again replaces the previously registered handler.
594
+ */
595
+ export declare function onError(callback: (error: Error) => void): void;
596
+
586
597
  export declare interface Page<Data extends AnyObject = AnyObject> extends DefineUIToolOptions<Data> {
587
598
  __UI__: boolean;
588
599
  __PAGE__: boolean;
package/jsx-runtime.d.ts CHANGED
@@ -26,6 +26,7 @@ export namespace JSX {
26
26
  popup: import('./components.d.ts').PopupProps;
27
27
  radio: import('./components.d.ts').RadioProps;
28
28
  'radio-group': import('./components.d.ts').RadioGroupProps;
29
+ 'rich-text': import('./components.d.ts').RichTextProps;
29
30
  slider: import('./components.d.ts').SliderProps;
30
31
  switch: import('./components.d.ts').SwitchProps;
31
32
  swiper: import('./components.d.ts').SwiperProps;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@doubao-dev/framework",
3
- "version": "0.0.39",
3
+ "version": "0.0.41",
4
4
  "type": "module",
5
5
  "types": "./dist/index.d.ts",
6
6
  "exports": {
@@ -68,7 +68,7 @@
68
68
  "types.d.ts"
69
69
  ],
70
70
  "dependencies": {
71
- "@lynx-js/types": "4.0.0",
71
+ "@lynx-js/types": "4.1.0",
72
72
  "@types/react": "18.3.27"
73
73
  },
74
74
  "publishConfig": {