@doubao-dev/taro-runtime 0.9.0 → 0.10.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 (185) hide show
  1. package/README.md +117 -0
  2. package/assets/refresh-loading.png +0 -0
  3. package/dist/api/base/can-i-use.d.ts +3 -0
  4. package/dist/api/base/can-i-use.js +12 -0
  5. package/dist/api/base/event-center.d.ts +12 -0
  6. package/dist/api/base/event-center.js +52 -0
  7. package/dist/api/base/index.d.ts +1 -1
  8. package/dist/api/base/index.js +1 -1
  9. package/dist/api/base/next-tick.d.ts +3 -0
  10. package/dist/api/base/next-tick.js +11 -0
  11. package/dist/api/canvas/index.d.ts +17 -0
  12. package/dist/api/canvas/index.js +29 -0
  13. package/dist/api/create-animation.d.ts +47 -0
  14. package/dist/api/create-animation.js +98 -0
  15. package/dist/api/create-intersection-observer/index.d.ts +7 -0
  16. package/dist/api/create-intersection-observer/index.js +126 -0
  17. package/dist/api/create-selector-query/index.js +284 -109
  18. package/dist/api/device/accelerometer.js +1 -1
  19. package/dist/api/device/accessibility.js +1 -1
  20. package/dist/api/device/battery.js +1 -1
  21. package/dist/api/device/beacon.js +1 -1
  22. package/dist/api/device/bluetooth.js +1 -1
  23. package/dist/api/device/clipboard.js +1 -1
  24. package/dist/api/device/compass.js +1 -1
  25. package/dist/api/device/crypto.js +1 -1
  26. package/dist/api/device/device-motion.js +1 -1
  27. package/dist/api/device/gyroscope.js +1 -1
  28. package/dist/api/device/keyboard.js +1 -1
  29. package/dist/api/device/scan.js +1 -1
  30. package/dist/api/device/screen.js +1 -1
  31. package/dist/api/device/sms.js +1 -1
  32. package/dist/api/device/vibration.js +1 -1
  33. package/dist/api/device/wifi.js +1 -1
  34. package/dist/api/index.d.ts +8 -1
  35. package/dist/api/index.js +8 -1
  36. package/dist/api/interaction/index.js +1 -1
  37. package/dist/api/location/index.d.ts +2 -2
  38. package/dist/api/location/index.js +1 -1
  39. package/dist/api/media/image.d.ts +9 -0
  40. package/dist/api/media/image.js +21 -1
  41. package/dist/api/media/index.d.ts +2 -0
  42. package/dist/api/media/index.js +2 -0
  43. package/dist/api/media/inner-audio.d.ts +5 -0
  44. package/dist/api/media/inner-audio.js +7 -0
  45. package/dist/api/media/media.d.ts +6 -0
  46. package/dist/api/media/media.js +9 -0
  47. package/dist/api/px-transform.d.ts +11 -0
  48. package/dist/api/px-transform.js +31 -0
  49. package/dist/api/request/index.js +1 -1
  50. package/dist/api/request/websocket.js +1 -1
  51. package/dist/api/router/current-instance.d.ts +17 -0
  52. package/dist/api/router/current-instance.js +28 -0
  53. package/dist/api/router/exit-mini-program.js +1 -1
  54. package/dist/api/router/get-current-pages.d.ts +13 -1
  55. package/dist/api/router/get-current-pages.js +5 -3
  56. package/dist/api/router/index.d.ts +1 -0
  57. package/dist/api/router/index.js +1 -0
  58. package/dist/api/router/navigate-back.js +1 -1
  59. package/dist/api/router/navigate-to.js +1 -1
  60. package/dist/api/router/re-launch.js +1 -1
  61. package/dist/api/router/redirect-to.js +1 -1
  62. package/dist/api/runtime/download.d.ts +11 -0
  63. package/dist/api/runtime/download.js +18 -0
  64. package/dist/api/runtime/resize.d.ts +7 -0
  65. package/dist/api/runtime/resize.js +26 -0
  66. package/dist/api/runtime/system.d.ts +8 -0
  67. package/dist/api/runtime/system.js +10 -0
  68. package/dist/api/show-toast/index.js +1 -1
  69. package/dist/api/storage/index.d.ts +1 -1
  70. package/dist/api/storage/index.js +1 -1
  71. package/dist/api/system/index.js +1 -1
  72. package/dist/components/Block/index.d.ts +3 -0
  73. package/dist/components/Block/index.jsx +4 -0
  74. package/dist/components/Button/index.d.ts +7 -0
  75. package/dist/components/Button/index.jsx +28 -0
  76. package/dist/components/Canvas/index.d.ts +4 -0
  77. package/dist/components/Canvas/index.jsx +25 -0
  78. package/dist/components/Checkbox/index.d.ts +3 -0
  79. package/dist/components/Checkbox/index.jsx +17 -0
  80. package/dist/components/CheckboxGroup/index.d.ts +3 -0
  81. package/dist/components/CheckboxGroup/index.jsx +13 -0
  82. package/dist/components/CoverView/index.d.ts +6 -1
  83. package/dist/components/CoverView/index.js +5 -1
  84. package/dist/components/Form/index.d.ts +4 -0
  85. package/dist/components/Form/index.jsx +39 -0
  86. package/dist/components/Form/use-form-field.d.ts +5 -0
  87. package/dist/components/Form/use-form-field.js +40 -0
  88. package/dist/components/Icon/index.d.ts +3 -0
  89. package/dist/components/Icon/index.jsx +40 -0
  90. package/dist/components/Image/index.d.ts +3 -1
  91. package/dist/components/Image/index.jsx +15 -4
  92. package/dist/components/Input/index.d.ts +1 -1
  93. package/dist/components/Input/index.jsx +9 -5
  94. package/dist/components/Input/map.d.ts +1 -1
  95. package/dist/components/Label/control.d.ts +6 -0
  96. package/dist/components/Label/control.js +29 -0
  97. package/dist/components/Label/index.d.ts +3 -0
  98. package/dist/components/Label/index.jsx +15 -0
  99. package/dist/components/LivePlayer/index.d.ts +3 -0
  100. package/dist/components/LivePlayer/index.jsx +8 -0
  101. package/dist/components/Map/bridge.d.ts +1 -1
  102. package/dist/components/Map/index.jsx +10 -6
  103. package/dist/components/Movable/index.d.ts +4 -0
  104. package/dist/components/Movable/index.jsx +26 -0
  105. package/dist/components/NavigationBar/index.d.ts +3 -0
  106. package/dist/components/NavigationBar/index.jsx +16 -0
  107. package/dist/components/Navigator/index.d.ts +3 -0
  108. package/dist/components/Navigator/index.jsx +32 -0
  109. package/dist/components/OpenData/index.d.ts +3 -0
  110. package/dist/components/OpenData/index.js +4 -0
  111. package/dist/components/Picker/index.d.ts +6 -0
  112. package/dist/components/Picker/index.jsx +155 -0
  113. package/dist/components/Picker/popup.d.ts +18 -0
  114. package/dist/components/Picker/popup.jsx +105 -0
  115. package/dist/components/PickerView/index.d.ts +1 -1
  116. package/dist/components/PickerView/index.jsx +1 -1
  117. package/dist/components/PickerView/map.d.ts +1 -1
  118. package/dist/components/Progress/index.d.ts +3 -0
  119. package/dist/components/Progress/index.jsx +14 -0
  120. package/dist/components/Radio/index.jsx +9 -5
  121. package/dist/components/Radio/shared.d.ts +1 -1
  122. package/dist/components/RadioGroup/context.js +1 -1
  123. package/dist/components/RadioGroup/index.jsx +8 -4
  124. package/dist/components/RadioGroup/map.d.ts +1 -1
  125. package/dist/components/RichText/index.d.ts +3 -0
  126. package/dist/components/RichText/index.jsx +7 -0
  127. package/dist/components/ScrollView/index.d.ts +4 -1
  128. package/dist/components/ScrollView/index.jsx +44 -14
  129. package/dist/components/ScrollView/map.d.ts +4 -2
  130. package/dist/components/ScrollView/map.js +19 -1
  131. package/dist/components/ScrollView/refresh-types.d.ts +25 -0
  132. package/dist/components/ScrollView/refresh-types.js +2 -0
  133. package/dist/components/ScrollView/refresh.d.ts +10 -0
  134. package/dist/components/ScrollView/refresh.jsx +29 -0
  135. package/dist/components/ScrollView/use-refresher.d.ts +19 -0
  136. package/dist/components/ScrollView/use-refresher.js +214 -0
  137. package/dist/components/Slider/index.d.ts +3 -0
  138. package/dist/components/Slider/index.jsx +13 -0
  139. package/dist/components/Swiper/index.d.ts +3 -0
  140. package/dist/components/Swiper/index.jsx +79 -0
  141. package/dist/components/SwiperItem/index.d.ts +3 -0
  142. package/dist/components/SwiperItem/index.jsx +18 -0
  143. package/dist/components/Switch/index.d.ts +3 -0
  144. package/dist/components/Switch/index.jsx +32 -0
  145. package/dist/components/Text/format.d.ts +5 -0
  146. package/dist/components/Text/format.js +51 -0
  147. package/dist/components/Text/index.d.ts +4 -3
  148. package/dist/components/Text/index.jsx +3 -2
  149. package/dist/components/Text/map.js +9 -4
  150. package/dist/components/Textarea/index.d.ts +3 -0
  151. package/dist/components/Textarea/index.jsx +30 -0
  152. package/dist/components/Video/index.d.ts +3 -0
  153. package/dist/components/Video/index.jsx +22 -0
  154. package/dist/components/View/index.d.ts +5 -5
  155. package/dist/components/View/index.jsx +11 -13
  156. package/dist/components/View/map.js +5 -0
  157. package/dist/components/base/change-event.d.ts +18 -0
  158. package/dist/components/base/change-event.js +13 -0
  159. package/dist/components/base/wrap-text-node.d.ts +3 -0
  160. package/dist/components/base/wrap-text-node.jsx +34 -0
  161. package/dist/components/index.d.ts +24 -1
  162. package/dist/components/index.js +24 -1
  163. package/dist/exports/app.d.ts +2 -1
  164. package/dist/exports/app.js +3 -1
  165. package/dist/exports/common.d.ts +1 -0
  166. package/dist/exports/common.js +1 -0
  167. package/dist/exports/view-core.d.ts +2 -1
  168. package/dist/exports/view-core.js +2 -1
  169. package/dist/exports/view.d.ts +2 -1
  170. package/dist/exports/view.js +3 -1
  171. package/dist/hooks/lifecycle/app.js +1 -1
  172. package/dist/hooks/use-animation.d.ts +9 -0
  173. package/dist/hooks/use-animation.js +151 -0
  174. package/dist/internal/class-components.d.ts +11 -0
  175. package/dist/internal/class-components.js +42 -0
  176. package/dist/internal/index.d.ts +1 -0
  177. package/dist/internal/index.js +1 -0
  178. package/dist/internal/map-context/index.d.ts +1 -1
  179. package/dist/internal/query-node.d.ts +9 -0
  180. package/dist/internal/query-node.js +35 -0
  181. package/dist/internal/selector-id.d.ts +6 -0
  182. package/dist/internal/selector-id.js +18 -0
  183. package/dist/react.d.ts +4 -0
  184. package/dist/react.js +4 -0
  185. package/package.json +23 -1
package/README.md CHANGED
@@ -9,3 +9,120 @@ pnpm add @doubao-dev/taro-runtime
9
9
  ```
10
10
 
11
11
  然后按 [Taro 构建接入说明](../../taro-plugin/README.md#接入-taro-项目) 配置 Kit 的 `experiments.taro`。构建插件会将 `@tarojs/taro` 和 `@tarojs/components` 映射到本包,业务代码继续使用 Taro 的导入方式。
12
+
13
+ ## React 兼容入口
14
+
15
+ `@doubao-dev/taro-runtime/react` 复用 framework 的 React 导出,并提供 Taro 迁移所需的兼容实现。
16
+ 平台导出器将业务源码中 `react` 的值引用映射到此入口,支持具名、默认、命名空间导入及重导出;
17
+ React 类型引用仍保留在原类型包。`react-dom` 继续映射到 framework 的原生 Portal 能力。
18
+
19
+ - `useTransition` 返回 `[false, startTransition]`,`startTransition` 同步执行回调,不提供时间分片、
20
+ 可中断渲染或 pending 状态。列表可以用它更新状态,需要加载提示时应自行维护明确的加载状态。
21
+ - `useLayoutEffect` 复用宿主已有的 `useEffect`,与 ReactLynx 后台线程的异步时机一致,不保证 React DOM
22
+ 在绘制前同步读取布局并重新渲染的时机。布局测量应使用平台节点查询接口并异步处理结果。
23
+ - 这些兼容实现随 taro-runtime 打入应用,不依赖宿主新增同名 framework 导出。
24
+
25
+ ## Checkbox / CheckboxGroup
26
+
27
+ 基于 SDK `checkbox` / `checkbox-group` 实现,组内选中状态由各 Checkbox 的 `checked` 决定。
28
+
29
+ - `checked` 传入时由业务在 change 回调中更新;不传时由组件维护选中状态。
30
+ - 组的 `change` 事件通过 `event.detail.value` 返回选中值数组,只在用户点击或通过 `Label` 切换时触发。
31
+ - 设置 `name` 后接入 `Form` 提交与重置,提交时读取组的当前选中值。
32
+
33
+ ## Textarea
34
+
35
+ `value` 由 Taro 适配层在初始化和属性变化时通过原生 `setValue` 同步;SDK TextArea 保持原生 ref 接口,不增加 `value/defaultValue` 属性。初始化也使用 `setValue`,不依赖较新宿主的 `default-value` 属性。
36
+
37
+ Lynx 原生 textarea 没有受控输入协议,跨线程的 `setValue` 是异步更新,不能提供 Web textarea 的同步受控保证。`onInput` 上报实际输入;将该值原样更新到 `value` 时不重复写入原生,也不会因为 `value` 未变化而强制回滚用户输入。Form 跟随实际输入更新,应用主动修改 `value` 时同步更新字段值。
38
+
39
+ ## Image 尺寸模式
40
+
41
+ 普通图片的 `widthFix` / `heightFix` 复用 SDK Image 的 `autoSize`:`widthFix` 保留宽度并将高度设为 `auto`,`heightFix` 保留高度并将宽度设为 `auto`,原生加载图片后按原图比例计算另一边。固定边的尺寸可以通过 `className` 或 `style` 设置,`style` 支持对象和字符串;自动计算的一边会覆盖样式中原先指定的宽或高。
42
+
43
+ `scaleToFill`、`aspectFit`、`aspectFill`、`center` 继续使用原生缩放模式。SVG 仍走已有的 Svg 渲染路径,不包含在此次尺寸模式兼容范围内。
44
+
45
+ Web runtime 的 `autoSize` 仍受父容器 Flex 拉伸影响;例如纵向 Flex 容器中的 `heightFix`,可设置父容器 `align-items: flex-start`,避免自动宽度被拉伸。示例页包含这一布局设置。
46
+
47
+ ## Text
48
+
49
+ `Text` 在 Taro 适配层支持以下属性:
50
+
51
+ - `userSelect` / `selectable`:开启原生文本选择,同时设置 `flatten={false}`。同时传入时以 `userSelect` 为准,包括显式传入 `false`。
52
+ - `space`:将普通空格转换为 `ensp`(半个中文字符宽度)、`emsp`(一个中文字符宽度)或 `nbsp`(不换行空格)。
53
+ - `decode`:默认关闭。开启后解码 `&`、`<`、`>`、`"`、`'`、` `、` `、` ` 和有效的十进制/十六进制数字实体;未知或无效实体保留原文。解码结果仍按文本显示。
54
+
55
+ 同时开启 `decode` 和 `space` 时,先解码,再转换普通空格。数组和 Fragment 中的文本同样处理;嵌套 `Text` 按自身的 `decode`、`space` 属性独立处理,保留样式和事件,不继承父级的转换设置。
56
+
57
+ ```tsx
58
+ import { Text } from '@tarojs/components';
59
+
60
+ <Text userSelect decode space="ensp">
61
+ {'A &amp; B'}
62
+ <Text decode>{' &lt;C&gt;'}</Text>
63
+ </Text>;
64
+ ```
65
+
66
+ 文本选择的长按交互和菜单表现由原生组件提供,需在目标版本真机验证。
67
+
68
+ ## Picker
69
+
70
+ Taro `Picker` 通过兼容层复用 SDK 已有的 `Popup`、`PickerView` 和 `PickerColumn`。业务继续从
71
+ `@tarojs/components` 导入,SDK 不新增内置 `picker` 标签。
72
+
73
+ - 支持现有 `selector`、`multiSelector`、`date`、`time` 模式及对应的值转换。
74
+ - 支持 `range/rangeKey`、`value/defaultValue`、`disabled`、`headerText`、`textProps` 和确认/取消回调。
75
+ - 多列的 `onColumnChange` 返回列下标及选项下标,业务可更新 `range/value` 实现联动。
76
+ - `value` 为受控值;未传时保留已确认选择。滚动只修改临时值,取消和遮罩关闭不提交。
77
+ - 弹层跟随 SDK 主题,空列不能确认。`region` 仍不支持,不内置行政区数据。
78
+
79
+ `examples/taro/src/pages/picker` 提供这些属性的手动演示。日期与时间的模式约定只保留在 Taro 兼容层。
80
+
81
+ ## Portal
82
+
83
+ `react-dom` 的值引用由编译插件映射到 `@doubao-dev/framework`,本包不提供 `react-dom` 入口。支持命名、默认和命名空间导入,调用表达式保持不变。`createPortal(children, container)` 只支持两个参数;参数及成员检查交给生成项目的 TypeScript 类型检查,编译插件不额外检查 JS 调用。容器必须迁移为 Lynx `NodesRef`,可通过原生节点的 ref 或 `lynx.createSelectorQuery().select(...)` 获取;编译插件不会将 DOM 元素自动转换为原生节点,也不提供 `document` 或 DOM 创建、查询能力。
84
+
85
+ Portal 仅在后台线程渲染,不参与主线程首屏渲染;事件按实际节点结构传播,不支持跨页面或跨原生容器挂载。其他 `react-dom` API 不在兼容范围内。
86
+
87
+ 需要同时更新包含 `createPortal` 导出的 framework 宿主资源;仅更新 taro-runtime 无法补齐旧宿主的能力。
88
+
89
+ ## 节点相交观察
90
+
91
+ `createIntersectionObserver` 由 Taro runtime 直接适配 Lynx 观察器:
92
+
93
+ ```ts
94
+ import { createIntersectionObserver } from '@tarojs/taro';
95
+
96
+ // 目标节点渲染后调用;使用结束时 disconnect。
97
+ const observer = createIntersectionObserver(null, { thresholds: [0, 0.5, 1] });
98
+ observer.relativeToViewport({ bottom: 100 }).observe('#target', (result) => {
99
+ console.log(result.intersectionRatio, result.boundingClientRect?.width);
100
+ });
101
+ // 页面或卡片销毁时:observer.disconnect();
102
+ ```
103
+
104
+ 适配层补齐 `boundingClientRect` 和 `intersectionRect` 的 `width`、`height`,并在 `disconnect` 后忽略晚到回调;断开后不复用该观察器。`relativeTo` / `relativeToViewport` 返回同一个适配观察器,便于链式调用。
105
+
106
+ Lynx 的 `observe()` 按 ID 查找目标。对于 `.class` 等选择器,Taro runtime 在调用 `observe()` 时通过 Lynx SelectorQuery 查询节点,再按 `unique_id` 注册观察。`observeAll: false` 取首个匹配节点,`true` 取全部匹配节点。
107
+
108
+ ### 当前兼容限制
109
+
110
+ - **观察目标**。选择器支持范围取决于 Lynx SelectorQuery。通过查询注册的目标列表在调用 `observe()` 时确定,之后新增的匹配节点需要重新注册。
111
+ - **首次通知**。Taro runtime 向 Lynx 传入 `initialRatio: 0`,并逐节点比较第一条收到的回调。比例等于调用方的 `initialRatio` 时跳过该条回调。初始比例为 0 时,Lynx 可能不发回调,适配层无法补发。此时滚动后的第一条回调也可能被当作首次回调过滤。阈值判断仍由 Lynx 执行。
112
+ - **多个参照区域**。微信可对多个参照区域取交集。豆包真机实测连续调用 `relativeTo()` 时最后一次设置生效,依赖多个区域共同限制可见性的业务可能提前或漏触发回调。
113
+ - **检测时间与节点信息**。`time` 原样转发,当前实测 Lynx 返回 0,无法用于计算检测时间差。微信实测返回的目标节点 `id`、`dataset` 当前未适配。
114
+ - **查询范围**。适配层忽略第一个 Taro 组件参数,在整个 LynxView 内查询,建议传入 `null`。`relativeToViewport()` 使用当前 LynxView 的视口,祖先裁剪遵循 Lynx。
115
+
116
+ 请在支持该 API 的视图后台脚本中调用。运行时缺少该 API 时会同步抛错。
117
+
118
+ 真机宿主的 framework API bundle 必须包含此 API;仅更新或 link taro-runtime 不会升级宿主资源。本地内网 SDK 调试可使用 `DISABLE_EXTERNAL=1` 将匹配版本的 framework/API 实现打入应用。
119
+
120
+
121
+ ## 页面路由与实例
122
+
123
+ 页面实例和路由信息来自豆包框架的 `getCurrentPage()`,需要使用提供该能力的框架版本。
124
+
125
+ - 页面组件中用 `useRouter()` 读取页面首次渲染时的 `path` 和 `params`;用 `useRouter(true)` 在宿主更新页面地址后读取最新值。`path` 和 `params` 从宿主下发的页面地址解析:`path` 以 `/` 开头,`params` 的值均为字符串。
126
+ - `getCurrentInstance()` 返回 `{ app, page, router }`。`page` 与 `getCurrentPages()` 的各项结构相同,包含 `path` 和 `options`;路由参数从 `router.params` 读取。宿主未下发页面地址时(例如在 Widget 中),`page` 和 `router` 为 `null`;App 尚未初始化时,`app` 为 `null`。
127
+ - `getCurrentPages()` 返回页面栈,各项的页面路径可通过 `path` 或 `route` 读取,查询参数可通过 `options` 或 `query` 读取。
128
+ - `getApp()` 返回当前运行环境中已初始化的豆包应用实例,初始化前调用会抛错。独立运行环境(例如 Web 的页面与 App)不共享此实例。
Binary file
@@ -0,0 +1,3 @@
1
+ /** Reports whether the runtime exports the API or component named by the schema. */
2
+ export declare function canIUse(schema: string): boolean;
3
+ //# sourceMappingURL=can-i-use.d.ts.map
@@ -0,0 +1,12 @@
1
+ import * as components from '../../components/index.js';
2
+ import * as runtime from '../../exports/common.js';
3
+ /** Reports whether the runtime exports the API or component named by the schema. */
4
+ export function canIUse(schema) {
5
+ if (typeof schema !== 'string') {
6
+ return false;
7
+ }
8
+ const name = schema.split('.', 1)[0] ?? '';
9
+ const component = name.replace(/(?:^|-)([a-z])/g, (_, letter) => letter.toUpperCase());
10
+ return (!name.startsWith('_') && Object.hasOwn(runtime, name)) || Object.hasOwn(components, component);
11
+ }
12
+ //# sourceMappingURL=can-i-use.js.map
@@ -0,0 +1,12 @@
1
+ type EventName = string | symbol;
2
+ type Listener = (...args: any[]) => void;
3
+ declare class EventCenter {
4
+ private readonly listeners;
5
+ on(events: EventName, callback: Listener, context?: unknown): this;
6
+ once(events: EventName, callback: Listener, context?: unknown): this;
7
+ off(events?: EventName, callback?: Listener, context?: unknown): this;
8
+ trigger(events: EventName, ...args: unknown[]): this;
9
+ }
10
+ export declare const eventCenter: EventCenter;
11
+ export {};
12
+ //# sourceMappingURL=event-center.d.ts.map
@@ -0,0 +1,52 @@
1
+ function splitEvents(events) {
2
+ return typeof events === 'symbol' ? [events] : events.split(',').filter(Boolean);
3
+ }
4
+ class EventCenter {
5
+ constructor() {
6
+ this.listeners = new Map();
7
+ }
8
+ on(events, callback, context) {
9
+ for (const event of splitEvents(events)) {
10
+ const listeners = this.listeners.get(event) ?? [];
11
+ this.listeners.set(event, [...listeners, { callback, context }]);
12
+ }
13
+ return this;
14
+ }
15
+ once(events, callback, context) {
16
+ let fired = false;
17
+ const listener = (...args) => {
18
+ if (fired) {
19
+ return;
20
+ }
21
+ fired = true;
22
+ this.off(events, listener, context);
23
+ callback.apply(context || this, args);
24
+ };
25
+ return this.on(events, listener, context);
26
+ }
27
+ off(events, callback, context) {
28
+ for (const event of events ? splitEvents(events) : this.listeners.keys()) {
29
+ const remaining = this.listeners
30
+ .get(event)
31
+ ?.filter((listener) => (callback !== undefined && listener.callback !== callback) ||
32
+ (context !== undefined && listener.context !== context));
33
+ if (remaining?.length) {
34
+ this.listeners.set(event, remaining);
35
+ }
36
+ else {
37
+ this.listeners.delete(event);
38
+ }
39
+ }
40
+ return this;
41
+ }
42
+ trigger(events, ...args) {
43
+ for (const event of splitEvents(events)) {
44
+ for (const { callback, context } of this.listeners.get(event) ?? []) {
45
+ callback.apply(context || this, args);
46
+ }
47
+ }
48
+ return this;
49
+ }
50
+ }
51
+ export const eventCenter = new EventCenter();
52
+ //# sourceMappingURL=event-center.js.map
@@ -1,4 +1,4 @@
1
- export declare function getPerformance(): import("@byted-doubao-apps/framework/api").Performance;
1
+ export declare function getPerformance(): import("@doubao-dev/framework/api").Performance;
2
2
  export declare function getEnv(): TaroGeneral.ENV_TYPE | 'DOUBAO';
3
3
  export declare const ENV_TYPE: {
4
4
  DOUBAO: string;
@@ -1,4 +1,4 @@
1
- import { getPerformance as appGetPerformance } from '@byted-doubao-apps/framework/api';
1
+ import { getPerformance as appGetPerformance } from '@doubao-dev/framework/api';
2
2
  export function getPerformance() {
3
3
  return appGetPerformance();
4
4
  }
@@ -0,0 +1,3 @@
1
+ /** Defers work to the next JS task in the Doubao runtime. */
2
+ export declare function nextTick(callback: () => void, context?: unknown): void;
3
+ //# sourceMappingURL=next-tick.d.ts.map
@@ -0,0 +1,11 @@
1
+ /** Defers work to the next JS task in the Doubao runtime. */
2
+ export function nextTick(callback, context) {
3
+ const run = () => callback.call(context);
4
+ const runtime = globalThis;
5
+ if (typeof runtime.setImmediate === 'function') {
6
+ runtime.setImmediate(run);
7
+ return;
8
+ }
9
+ setTimeout(run, 0);
10
+ }
11
+ //# sourceMappingURL=next-tick.js.map
@@ -0,0 +1,17 @@
1
+ import { type OffscreenCanvas as DoubaoOffscreenCanvas } from '@doubao-dev/framework/api';
2
+ import type Taro from '@tarojs/taro';
3
+ type TaroCanvasToTempFilePathOption = Parameters<typeof Taro.canvasToTempFilePath>[0];
4
+ type TaroCanvasToTempFilePathResult = Awaited<ReturnType<typeof Taro.canvasToTempFilePath>>;
5
+ /**
6
+ * Export a canvas by instance or id. For a component scope, pass the same object to
7
+ * Canvas.exportScope and the second argument; implicit wx component-tree lookup is unavailable.
8
+ */
9
+ export declare function canvasToTempFilePath(option?: TaroCanvasToTempFilePathOption, component?: TaroGeneral.IAnyObject): Promise<TaroCanvasToTempFilePathResult>;
10
+ export declare function createOffscreenCanvas(options: Taro.createOffscreenCanvas.Option): DoubaoOffscreenCanvas;
11
+ declare module '@tarojs/taro' {
12
+ interface TaroStatic {
13
+ createOffscreenCanvas(options: Taro.createOffscreenCanvas.Option): DoubaoOffscreenCanvas;
14
+ }
15
+ }
16
+ export {};
17
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,29 @@
1
+ import { createOffscreenCanvas as createCanvas, canvasToTempFilePath as exportCanvas } from '@doubao-dev/framework/api';
2
+ import { buildOkCallbackResult, runTaroApi } from '../utils.js';
3
+ /**
4
+ * Export a canvas by instance or id. For a component scope, pass the same object to
5
+ * Canvas.exportScope and the second argument; implicit wx component-tree lookup is unavailable.
6
+ */
7
+ export async function canvasToTempFilePath(option, component) {
8
+ return runTaroApi('canvasToTempFilePath', option, async () => {
9
+ if (!option) {
10
+ throw new TypeError('canvasToTempFilePath: options are required');
11
+ }
12
+ const result = await exportCanvas({
13
+ ...option,
14
+ canvas: option.canvas
15
+ }, component);
16
+ return { ...result, ...buildOkCallbackResult('canvasToTempFilePath') };
17
+ });
18
+ }
19
+ export function createOffscreenCanvas(options) {
20
+ if ((options?.type ?? 'webgl') !== '2d') {
21
+ throw new Error('createOffscreenCanvas:fail only type 2d is supported');
22
+ }
23
+ const canvas = createCanvas(options);
24
+ if (!canvas?.getContext('2d')) {
25
+ throw new Error('createOffscreenCanvas:fail offscreen 2d canvas is unavailable');
26
+ }
27
+ return canvas;
28
+ }
29
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,47 @@
1
+ interface AnimationOptions {
2
+ duration?: number;
3
+ delay?: number;
4
+ timingFunction?: string;
5
+ transformOrigin?: string;
6
+ }
7
+ export interface AnimationStep {
8
+ styles: Record<string, number | string>;
9
+ options: AnimationOptions;
10
+ }
11
+ export interface AnimationData {
12
+ steps: AnimationStep[];
13
+ }
14
+ export declare function createAnimation(options?: AnimationOptions): {
15
+ matrix: (values_0: number, values_1: number, values_2: number, values_3: number, values_4: number, values_5: number) => /*elided*/ any;
16
+ matrix3d: (values_0: number, values_1: number, values_2: number, values_3: number, values_4: number, values_5: number, values_6: number, values_7: number, values_8: number, values_9: number, values_10: number, values_11: number, values_12: number, values_13: number, values_14: number, values_15: number) => /*elided*/ any;
17
+ rotate: (value: number) => /*elided*/ any;
18
+ rotateX: (value: number) => /*elided*/ any;
19
+ rotateY: (value: number) => /*elided*/ any;
20
+ rotateZ: (value: number) => /*elided*/ any;
21
+ rotate3d(x: number, y?: number, z?: number, degrees?: number): /*elided*/ any;
22
+ scale: (x: number, y?: number) => /*elided*/ any;
23
+ scaleX: (value: number) => /*elided*/ any;
24
+ scaleY: (value: number) => /*elided*/ any;
25
+ scaleZ: (value: number) => /*elided*/ any;
26
+ scale3d: (x: number, y: number, z: number) => /*elided*/ any;
27
+ skew: (x: number, y?: number) => /*elided*/ any;
28
+ skewX: (value: number) => /*elided*/ any;
29
+ skewY: (value: number) => /*elided*/ any;
30
+ translate: (x: string | number, y?: string | number) => /*elided*/ any;
31
+ translateX: (value: string | number) => /*elided*/ any;
32
+ translateY: (value: string | number) => /*elided*/ any;
33
+ translateZ: (value: string | number) => /*elided*/ any;
34
+ translate3d: (x: string | number, y: string | number, z: string | number) => /*elided*/ any;
35
+ opacity: (value: number) => /*elided*/ any;
36
+ backgroundColor: (value: string) => /*elided*/ any;
37
+ width: (value: string | number) => /*elided*/ any;
38
+ height: (value: string | number) => /*elided*/ any;
39
+ top: (value: string | number) => /*elided*/ any;
40
+ right: (value: string | number) => /*elided*/ any;
41
+ bottom: (value: string | number) => /*elided*/ any;
42
+ left: (value: string | number) => /*elided*/ any;
43
+ step(overrides?: AnimationOptions): /*elided*/ any;
44
+ export(): AnimationData;
45
+ };
46
+ export {};
47
+ //# sourceMappingURL=create-animation.d.ts.map
@@ -0,0 +1,98 @@
1
+ export function createAnimation(options = {}) {
2
+ let steps = [];
3
+ let styles = {};
4
+ const transforms = new Map();
5
+ let hasTransformUpdate = false;
6
+ const length = (value) => (typeof value === 'number' ? `${value}px` : value);
7
+ const angle = (value) => `${value}deg`;
8
+ const setTransform = (key, name, values) => {
9
+ transforms.set(key, `${name}(${values.join(', ')})`);
10
+ hasTransformUpdate = true;
11
+ return animation;
12
+ };
13
+ const transform = (name, ...values) => setTransform(name, name, values);
14
+ const style = (name, value) => {
15
+ styles[name] = value;
16
+ return animation;
17
+ };
18
+ const animation = {
19
+ matrix: (...values) => transform('matrix', ...values),
20
+ matrix3d: (...values) => transform('matrix3d', ...values),
21
+ rotate: (value) => transform('rotate', angle(value)),
22
+ rotateX: (value) => transform('rotateX', angle(value)),
23
+ rotateY: (value) => transform('rotateY', angle(value)),
24
+ rotateZ: (value) => transform('rotateZ', angle(value)),
25
+ rotate3d(x, y = 0, z = 0, degrees = 0) {
26
+ // Lynx accepts matrix3d for arbitrary-axis rotations.
27
+ const axisLength = Math.hypot(x, y, z);
28
+ if (!axisLength) {
29
+ return animation;
30
+ }
31
+ x /= axisLength;
32
+ y /= axisLength;
33
+ z /= axisLength;
34
+ const radians = (degrees * Math.PI) / 180;
35
+ const c = Math.cos(radians);
36
+ const s = Math.sin(radians);
37
+ const t = 1 - c;
38
+ return setTransform('rotate3d', 'matrix3d', [
39
+ t * x * x + c,
40
+ t * x * y + s * z,
41
+ t * x * z - s * y,
42
+ 0,
43
+ t * x * y - s * z,
44
+ t * y * y + c,
45
+ t * y * z + s * x,
46
+ 0,
47
+ t * x * z + s * y,
48
+ t * y * z - s * x,
49
+ t * z * z + c,
50
+ 0,
51
+ 0,
52
+ 0,
53
+ 0,
54
+ 1
55
+ ]);
56
+ },
57
+ scale: (x, y = x) => transform('scale', x, y),
58
+ scaleX: (value) => transform('scaleX', value),
59
+ scaleY: (value) => transform('scaleY', value),
60
+ scaleZ: (value) => setTransform('scaleZ', 'matrix3d', [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, value, 0, 0, 0, 0, 1]),
61
+ scale3d: (x, y, z) => setTransform('scale3d', 'matrix3d', [x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1]),
62
+ skew: (x, y = 0) => transform('skew', angle(x), angle(y)),
63
+ skewX: (value) => transform('skewX', angle(value)),
64
+ skewY: (value) => transform('skewY', angle(value)),
65
+ translate: (x, y = 0) => transform('translate', length(x), length(y)),
66
+ translateX: (value) => transform('translateX', length(value)),
67
+ translateY: (value) => transform('translateY', length(value)),
68
+ translateZ: (value) => transform('translateZ', length(value)),
69
+ translate3d: (x, y, z) => transform('translate3d', length(x), length(y), length(z)),
70
+ opacity: (value) => style('opacity', value),
71
+ backgroundColor: (value) => style('backgroundColor', value),
72
+ width: (value) => style('width', length(value)),
73
+ height: (value) => style('height', length(value)),
74
+ top: (value) => style('top', length(value)),
75
+ right: (value) => style('right', length(value)),
76
+ bottom: (value) => style('bottom', length(value)),
77
+ left: (value) => style('left', length(value)),
78
+ step(overrides = {}) {
79
+ // CSS transform replaces the entire list, so include earlier steps' operations.
80
+ if (hasTransformUpdate) {
81
+ styles.transform = Array.from(transforms.values()).join(' ');
82
+ }
83
+ steps.push({ styles, options: { duration: 400, ...options, ...overrides } });
84
+ styles = {};
85
+ hasTransformUpdate = false;
86
+ return animation;
87
+ },
88
+ export() {
89
+ const data = { steps };
90
+ steps = [];
91
+ transforms.clear();
92
+ hasTransformUpdate = false;
93
+ return data;
94
+ }
95
+ };
96
+ return animation;
97
+ }
98
+ //# sourceMappingURL=create-animation.js.map
@@ -0,0 +1,7 @@
1
+ import type Taro from '@tarojs/taro';
2
+ /**
3
+ * Adapt the view-wide observer. The Taro component argument does not scope Lynx queries.
4
+ * Class selectors are resolved once when observe is called. Clipping follows Lynx.
5
+ */
6
+ export declare function createIntersectionObserver(_component?: TaroGeneral.IAnyObject | null, options?: Taro.createIntersectionObserver.Option): Taro.IntersectionObserver;
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,126 @@
1
+ function createViewIntersectionObserver(options) {
2
+ if (typeof lynx === 'undefined' || typeof lynx.createIntersectionObserver !== 'function') {
3
+ throw new Error('createIntersectionObserver is not available in this runtime.');
4
+ }
5
+ const initialRatio = options?.initialRatio ?? 0;
6
+ const observeAll = options?.observeAll === true;
7
+ // An empty component ID selects the view root.
8
+ const nativeObserver = lynx.createIntersectionObserver({ componentId: '' }, {
9
+ ...options,
10
+ initialRatio: 0
11
+ });
12
+ let disconnected = false;
13
+ function assertConnected() {
14
+ if (disconnected) {
15
+ throw new Error('createIntersectionObserver: observer has been disconnected.');
16
+ }
17
+ }
18
+ const observer = {
19
+ relativeTo(selector, margins) {
20
+ assertConnected();
21
+ nativeObserver.relativeTo(selector, margins);
22
+ return observer;
23
+ },
24
+ relativeToViewport(margins) {
25
+ assertConnected();
26
+ nativeObserver.relativeToViewport(margins);
27
+ return observer;
28
+ },
29
+ relativeToScreen(margins) {
30
+ assertConnected();
31
+ nativeObserver.relativeToScreen(margins);
32
+ return observer;
33
+ },
34
+ observe(selector, callback) {
35
+ assertConnected();
36
+ function observeTarget(target) {
37
+ if (disconnected) {
38
+ return;
39
+ }
40
+ let firstCallback = true;
41
+ nativeObserver.observe(target, (result) => {
42
+ if (disconnected) {
43
+ return;
44
+ }
45
+ if (firstCallback) {
46
+ firstCallback = false;
47
+ if (result.intersectionRatio === initialRatio) {
48
+ return;
49
+ }
50
+ }
51
+ callback(result);
52
+ });
53
+ }
54
+ if (/^#[\w-]+$|^\d+$/.test(selector)) {
55
+ observeTarget(selector);
56
+ return;
57
+ }
58
+ // Resolve class selectors to node IDs before registering targets.
59
+ const query = lynx.createSelectorQuery?.();
60
+ if (!query) {
61
+ throw new Error('createIntersectionObserver: selector queries are not available in this runtime.');
62
+ }
63
+ const ref = observeAll ? query.selectAll(selector) : query.select(selector);
64
+ ref
65
+ .fields({ unique_id: true }, (nodes) => {
66
+ const ids = new Set();
67
+ for (const node of Array.isArray(nodes) ? nodes : [nodes]) {
68
+ const id = node?.unique_id;
69
+ if (typeof id === 'number' || (typeof id === 'string' && id.length > 0)) {
70
+ ids.add(String(id));
71
+ }
72
+ }
73
+ ids.forEach(observeTarget);
74
+ })
75
+ .exec();
76
+ },
77
+ disconnect() {
78
+ if (!disconnected) {
79
+ disconnected = true;
80
+ nativeObserver.disconnect();
81
+ }
82
+ }
83
+ };
84
+ return observer;
85
+ }
86
+ function withSize(rect) {
87
+ return {
88
+ ...rect,
89
+ width: rect.right - rect.left,
90
+ height: rect.bottom - rect.top
91
+ };
92
+ }
93
+ function toTaroResult(result) {
94
+ return {
95
+ intersectionRatio: result.intersectionRatio,
96
+ intersectionRect: withSize(result.intersectionRect),
97
+ boundingClientRect: withSize(result.boundingClientRect),
98
+ relativeRect: { ...result.relativeRect },
99
+ time: result.time
100
+ };
101
+ }
102
+ /**
103
+ * Adapt the view-wide observer. The Taro component argument does not scope Lynx queries.
104
+ * Class selectors are resolved once when observe is called. Clipping follows Lynx.
105
+ */
106
+ export function createIntersectionObserver(_component, options) {
107
+ const nativeObserver = createViewIntersectionObserver(options);
108
+ const observer = {
109
+ relativeTo(selector, margins) {
110
+ nativeObserver.relativeTo(selector, margins);
111
+ return observer;
112
+ },
113
+ relativeToViewport(margins) {
114
+ nativeObserver.relativeToViewport(margins);
115
+ return observer;
116
+ },
117
+ observe(selector, callback) {
118
+ nativeObserver.observe(selector, (result) => callback(toTaroResult(result)));
119
+ },
120
+ disconnect() {
121
+ nativeObserver.disconnect();
122
+ }
123
+ };
124
+ return observer;
125
+ }
126
+ //# sourceMappingURL=index.js.map