@fast-china/utils 1.0.38 → 2.0.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 (286) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/CONTRIBUTING.md +87 -0
  3. package/README.md +111 -50
  4. package/README.zh.md +111 -50
  5. package/SECURITY.md +46 -0
  6. package/dist/array/index.d.mts +87 -0
  7. package/dist/array/index.d.mts.map +1 -0
  8. package/dist/array/index.mjs +161 -0
  9. package/dist/array/index.mjs.map +1 -0
  10. package/dist/async/index.d.mts +146 -0
  11. package/dist/async/index.d.mts.map +1 -0
  12. package/dist/async/index.mjs +336 -0
  13. package/dist/async/index.mjs.map +1 -0
  14. package/dist/base64/index.d.mts +105 -0
  15. package/dist/base64/index.d.mts.map +1 -0
  16. package/dist/base64/index.mjs +427 -0
  17. package/dist/base64/index.mjs.map +1 -0
  18. package/dist/color/index.d.mts +90 -0
  19. package/dist/color/index.d.mts.map +1 -0
  20. package/dist/color/index.mjs +178 -0
  21. package/dist/color/index.mjs.map +1 -0
  22. package/dist/crypto/index.d.mts +157 -0
  23. package/dist/crypto/index.d.mts.map +1 -0
  24. package/dist/crypto/index.mjs +541 -0
  25. package/dist/crypto/index.mjs.map +1 -0
  26. package/dist/date/index.d.mts +191 -0
  27. package/dist/date/index.d.mts.map +1 -0
  28. package/dist/date/index.mjs +383 -0
  29. package/dist/date/index.mjs.map +1 -0
  30. package/dist/dom/style.d.mts +30 -0
  31. package/dist/dom/style.d.mts.map +1 -0
  32. package/dist/dom/style.mjs +74 -0
  33. package/dist/dom/style.mjs.map +1 -0
  34. package/dist/env/index.d.mts +63 -0
  35. package/dist/env/index.d.mts.map +1 -0
  36. package/dist/env/index.mjs +97 -0
  37. package/dist/env/index.mjs.map +1 -0
  38. package/dist/identity/index.d.mts +78 -0
  39. package/dist/identity/index.d.mts.map +1 -0
  40. package/dist/identity/index.mjs +87 -0
  41. package/dist/identity/index.mjs.map +1 -0
  42. package/dist/index.d.mts +24 -0
  43. package/dist/index.mjs +23 -0
  44. package/dist/internal/text.mjs +36 -0
  45. package/dist/internal/text.mjs.map +1 -0
  46. package/dist/logger/index.d.mts +87 -0
  47. package/dist/logger/index.d.mts.map +1 -0
  48. package/dist/logger/index.mjs +124 -0
  49. package/dist/logger/index.mjs.map +1 -0
  50. package/dist/number/index.d.mts +89 -0
  51. package/dist/number/index.d.mts.map +1 -0
  52. package/dist/number/index.mjs +215 -0
  53. package/dist/number/index.mjs.map +1 -0
  54. package/dist/object/index.d.mts +76 -0
  55. package/dist/object/index.d.mts.map +1 -0
  56. package/dist/object/index.mjs +134 -0
  57. package/dist/object/index.mjs.map +1 -0
  58. package/dist/storage/index.d.mts +104 -0
  59. package/dist/storage/index.d.mts.map +1 -0
  60. package/dist/storage/index.mjs +324 -0
  61. package/dist/storage/index.mjs.map +1 -0
  62. package/dist/string/index.d.mts +130 -0
  63. package/dist/string/index.d.mts.map +1 -0
  64. package/dist/string/index.mjs +275 -0
  65. package/dist/string/index.mjs.map +1 -0
  66. package/dist/vue/emits.d.mts +24 -0
  67. package/dist/vue/emits.d.mts.map +1 -0
  68. package/dist/vue/emits.mjs +47 -0
  69. package/dist/vue/emits.mjs.map +1 -0
  70. package/dist/vue/expose.d.mts +12 -0
  71. package/dist/vue/expose.d.mts.map +1 -0
  72. package/dist/vue/expose.mjs +16 -0
  73. package/dist/vue/expose.mjs.map +1 -0
  74. package/dist/vue/func.d.mts +14 -0
  75. package/dist/vue/func.d.mts.map +1 -0
  76. package/dist/vue/func.mjs +16 -0
  77. package/dist/vue/func.mjs.map +1 -0
  78. package/dist/vue/index.d.mts +9 -0
  79. package/dist/vue/install.d.mts +69 -0
  80. package/dist/vue/install.d.mts.map +1 -0
  81. package/dist/vue/install.mjs +123 -0
  82. package/dist/vue/install.mjs.map +1 -0
  83. package/dist/vue/props.d.mts +23 -0
  84. package/dist/vue/props.d.mts.map +1 -0
  85. package/dist/vue/props.mjs +41 -0
  86. package/dist/vue/props.mjs.map +1 -0
  87. package/dist/vue/render.d.mts +13 -0
  88. package/dist/vue/render.d.mts.map +1 -0
  89. package/dist/vue/render.mjs +23 -0
  90. package/dist/vue/render.mjs.map +1 -0
  91. package/dist/vue/slots.d.mts +19 -0
  92. package/dist/vue/slots.d.mts.map +1 -0
  93. package/dist/vue/slots.mjs +13 -0
  94. package/dist/vue/slots.mjs.map +1 -0
  95. package/dist/vue/with.d.mts +12 -0
  96. package/dist/vue/with.d.mts.map +1 -0
  97. package/dist/vue/with.mjs +15 -0
  98. package/dist/vue/with.mjs.map +1 -0
  99. package/docs/API.md +96 -0
  100. package/docs/API.zh-CN.md +96 -0
  101. package/docs/DEVELOPMENT_RELEASE.zh-CN.md +65 -0
  102. package/docs/RUNTIME_CONTRACT.md +37 -0
  103. package/package.json +65 -73
  104. package/src/array/index.ts +173 -0
  105. package/src/async/index.ts +475 -0
  106. package/src/base64/index.ts +374 -0
  107. package/src/color/index.ts +208 -0
  108. package/src/crypto/index.ts +670 -0
  109. package/src/date/index.ts +451 -0
  110. package/src/dom/index.ts +6 -0
  111. package/src/dom/style.ts +92 -0
  112. package/src/env/index.ts +169 -0
  113. package/src/identity/index.ts +144 -0
  114. package/src/index.ts +20 -0
  115. package/src/internal/text.ts +46 -0
  116. package/src/logger/index.ts +219 -0
  117. package/src/number/index.ts +235 -0
  118. package/src/object/index.ts +160 -0
  119. package/src/storage/index.ts +524 -0
  120. package/src/string/index.ts +328 -0
  121. package/src/vue/emits.ts +71 -0
  122. package/src/vue/expose.ts +11 -0
  123. package/src/vue/func.ts +17 -0
  124. package/src/vue/index.ts +13 -0
  125. package/src/vue/install.ts +185 -0
  126. package/src/vue/props.ts +39 -0
  127. package/src/vue/render.ts +41 -0
  128. package/src/vue/slots.ts +23 -0
  129. package/src/vue/with.ts +10 -0
  130. package/Fast.png +0 -0
  131. package/dist/index.global.js +0 -14500
  132. package/dist/index.global.js.map +0 -1
  133. package/dist/index.global.min.js +0 -2
  134. package/dist/index.global.min.js.map +0 -1
  135. package/es/array/index.d.ts +0 -19
  136. package/es/array/index.mjs +0 -2
  137. package/es/array/index.mjs.map +0 -1
  138. package/es/base64/index.d.ts +0 -21
  139. package/es/base64/index.mjs +0 -2
  140. package/es/base64/index.mjs.map +0 -1
  141. package/es/click/index.d.ts +0 -33
  142. package/es/click/index.mjs +0 -2
  143. package/es/click/index.mjs.map +0 -1
  144. package/es/color/index.d.ts +0 -33
  145. package/es/color/index.mjs +0 -2
  146. package/es/color/index.mjs.map +0 -1
  147. package/es/console/index.d.ts +0 -31
  148. package/es/console/index.mjs +0 -2
  149. package/es/console/index.mjs.map +0 -1
  150. package/es/crypto/index.d.ts +0 -46
  151. package/es/crypto/index.mjs +0 -2
  152. package/es/crypto/index.mjs.map +0 -1
  153. package/es/date/index.d.ts +0 -44
  154. package/es/date/index.mjs +0 -2
  155. package/es/date/index.mjs.map +0 -1
  156. package/es/dom/index.d.ts +0 -1
  157. package/es/dom/index.mjs +0 -2
  158. package/es/dom/index.mjs.map +0 -1
  159. package/es/dom/style.d.ts +0 -12
  160. package/es/dom/style.mjs +0 -2
  161. package/es/dom/style.mjs.map +0 -1
  162. package/es/env/index.d.ts +0 -25
  163. package/es/env/index.mjs +0 -2
  164. package/es/env/index.mjs.map +0 -1
  165. package/es/error/index.d.ts +0 -3
  166. package/es/error/index.mjs +0 -2
  167. package/es/error/index.mjs.map +0 -1
  168. package/es/identity/index.d.ts +0 -14
  169. package/es/identity/index.mjs +0 -2
  170. package/es/identity/index.mjs.map +0 -1
  171. package/es/index.d.ts +0 -15
  172. package/es/index.es.d.ts +0 -2
  173. package/es/index.mjs +0 -2
  174. package/es/index.mjs.map +0 -1
  175. package/es/object/index.d.ts +0 -13
  176. package/es/object/index.mjs +0 -2
  177. package/es/object/index.mjs.map +0 -1
  178. package/es/storage/index.d.ts +0 -96
  179. package/es/storage/index.mjs +0 -2
  180. package/es/storage/index.mjs.map +0 -1
  181. package/es/string/index.d.ts +0 -114
  182. package/es/string/index.mjs +0 -2
  183. package/es/string/index.mjs.map +0 -1
  184. package/es/vue/emits.d.ts +0 -8
  185. package/es/vue/emits.mjs +0 -2
  186. package/es/vue/emits.mjs.map +0 -1
  187. package/es/vue/expose.d.ts +0 -4
  188. package/es/vue/expose.mjs +0 -2
  189. package/es/vue/expose.mjs.map +0 -1
  190. package/es/vue/func.d.ts +0 -6
  191. package/es/vue/func.mjs +0 -2
  192. package/es/vue/func.mjs.map +0 -1
  193. package/es/vue/index.d.ts +0 -8
  194. package/es/vue/index.mjs +0 -2
  195. package/es/vue/index.mjs.map +0 -1
  196. package/es/vue/install.d.ts +0 -5
  197. package/es/vue/install.mjs +0 -2
  198. package/es/vue/install.mjs.map +0 -1
  199. package/es/vue/props.d.ts +0 -9
  200. package/es/vue/props.mjs +0 -2
  201. package/es/vue/props.mjs.map +0 -1
  202. package/es/vue/slots.d.ts +0 -11
  203. package/es/vue/slots.mjs +0 -2
  204. package/es/vue/slots.mjs.map +0 -1
  205. package/es/vue/useRender.d.ts +0 -6
  206. package/es/vue/useRender.mjs +0 -2
  207. package/es/vue/useRender.mjs.map +0 -1
  208. package/es/vue/with.d.ts +0 -5
  209. package/es/vue/with.mjs +0 -2
  210. package/es/vue/with.mjs.map +0 -1
  211. package/lib/array/index.d.ts +0 -19
  212. package/lib/array/index.js +0 -2
  213. package/lib/array/index.js.map +0 -1
  214. package/lib/base64/index.d.ts +0 -21
  215. package/lib/base64/index.js +0 -2
  216. package/lib/base64/index.js.map +0 -1
  217. package/lib/click/index.d.ts +0 -33
  218. package/lib/click/index.js +0 -2
  219. package/lib/click/index.js.map +0 -1
  220. package/lib/color/index.d.ts +0 -33
  221. package/lib/color/index.js +0 -2
  222. package/lib/color/index.js.map +0 -1
  223. package/lib/console/index.d.ts +0 -31
  224. package/lib/console/index.js +0 -2
  225. package/lib/console/index.js.map +0 -1
  226. package/lib/crypto/index.d.ts +0 -46
  227. package/lib/crypto/index.js +0 -2
  228. package/lib/crypto/index.js.map +0 -1
  229. package/lib/date/index.d.ts +0 -44
  230. package/lib/date/index.js +0 -2
  231. package/lib/date/index.js.map +0 -1
  232. package/lib/dom/index.d.ts +0 -1
  233. package/lib/dom/index.js +0 -2
  234. package/lib/dom/index.js.map +0 -1
  235. package/lib/dom/style.d.ts +0 -12
  236. package/lib/dom/style.js +0 -2
  237. package/lib/dom/style.js.map +0 -1
  238. package/lib/env/index.d.ts +0 -25
  239. package/lib/env/index.js +0 -2
  240. package/lib/env/index.js.map +0 -1
  241. package/lib/error/index.d.ts +0 -3
  242. package/lib/error/index.js +0 -2
  243. package/lib/error/index.js.map +0 -1
  244. package/lib/identity/index.d.ts +0 -14
  245. package/lib/identity/index.js +0 -2
  246. package/lib/identity/index.js.map +0 -1
  247. package/lib/index.d.ts +0 -15
  248. package/lib/index.es.d.ts +0 -2
  249. package/lib/index.js +0 -2
  250. package/lib/index.js.map +0 -1
  251. package/lib/object/index.d.ts +0 -13
  252. package/lib/object/index.js +0 -2
  253. package/lib/object/index.js.map +0 -1
  254. package/lib/storage/index.d.ts +0 -96
  255. package/lib/storage/index.js +0 -2
  256. package/lib/storage/index.js.map +0 -1
  257. package/lib/string/index.d.ts +0 -114
  258. package/lib/string/index.js +0 -2
  259. package/lib/string/index.js.map +0 -1
  260. package/lib/vue/emits.d.ts +0 -8
  261. package/lib/vue/emits.js +0 -2
  262. package/lib/vue/emits.js.map +0 -1
  263. package/lib/vue/expose.d.ts +0 -4
  264. package/lib/vue/expose.js +0 -2
  265. package/lib/vue/expose.js.map +0 -1
  266. package/lib/vue/func.d.ts +0 -6
  267. package/lib/vue/func.js +0 -2
  268. package/lib/vue/func.js.map +0 -1
  269. package/lib/vue/index.d.ts +0 -8
  270. package/lib/vue/index.js +0 -2
  271. package/lib/vue/index.js.map +0 -1
  272. package/lib/vue/install.d.ts +0 -5
  273. package/lib/vue/install.js +0 -2
  274. package/lib/vue/install.js.map +0 -1
  275. package/lib/vue/props.d.ts +0 -9
  276. package/lib/vue/props.js +0 -2
  277. package/lib/vue/props.js.map +0 -1
  278. package/lib/vue/slots.d.ts +0 -11
  279. package/lib/vue/slots.js +0 -2
  280. package/lib/vue/slots.js.map +0 -1
  281. package/lib/vue/useRender.d.ts +0 -6
  282. package/lib/vue/useRender.js +0 -2
  283. package/lib/vue/useRender.js.map +0 -1
  284. package/lib/vue/with.d.ts +0 -5
  285. package/lib/vue/with.js +0 -2
  286. package/lib/vue/with.js.map +0 -1
@@ -0,0 +1,69 @@
1
+ //#region src/vue/install.d.ts
2
+ /** Vue 2.7 构造器与 Vue 3 App 共有的组件、指令注册能力。 */
3
+ interface VueRegistrationTarget {
4
+ /**
5
+ * 读取或注册全局组件。
6
+ *
7
+ * @param name - 全局组件名。
8
+ * @param component - 注册时传入的组件;省略时读取现有组件。
9
+ * @returns Vue 平台返回的现有组件、注册结果或目标自身。
10
+ */
11
+ component: (name: string, component?: unknown) => unknown;
12
+ /**
13
+ * 读取或注册全局指令。
14
+ *
15
+ * @param name - 不带 `v-` 的全局指令名。
16
+ * @param directive - 注册时传入的指令;省略时读取现有指令。
17
+ * @returns Vue 平台返回的现有指令、注册结果或目标自身。
18
+ */
19
+ directive: (name: string, directive?: unknown) => unknown;
20
+ }
21
+ /** Vue 组件对象、函数组件或指令对象可接受的最小结构类型。 */
22
+ type VueInstallValue = object | ((...arguments_: never[]) => unknown);
23
+ /** 为 Vue 组件或指令附加供 Vue 2.7 `Vue.use()` 与 Vue 3 `app.use()` 调用的安装能力。 */
24
+ type Installable<Value> = Value & {
25
+ /**
26
+ * 把当前组件或指令安装到 Vue 2.7 构造器或 Vue 3 App。
27
+ * @param target - Vue 2.7 构造器或 Vue 3 App 实例。
28
+ */
29
+ install: (target: unknown) => void;
30
+ };
31
+ /** TSX 组件安装类型;与 {@link Installable} 保持同一运行时契约。 */
32
+ type TSXWithInstall<Value> = Installable<Value>;
33
+ /**
34
+ * 为主组件附加 Vue 2.7 `Vue.use()` 与 Vue 3 `app.use()` 安装能力。
35
+ *
36
+ * @remarks 函数会直接为 `main` 定义附属组件属性和 `install`。所有组件名称、附属属性
37
+ * 冲突会在修改 `main` 前完成校验;安装到 App 时也会先预检全部全局名称,再统一注册。
38
+ * @param main - 具有非空 `name` 的组件。
39
+ * @param extras - 同时注册并以可枚举属性挂到主组件的附属组件映射。
40
+ * @returns 原始 `main` 引用,并附加类型化的 `install` 与 `extras` 属性。
41
+ * @throws `TypeError` 当组件缺少合法名称、已有 `install`、附属键或名称发生冲突。
42
+ * @throws `Error` 当安装目标中同名位置已经注册其他组件。
43
+ */
44
+ declare function withInstall<Main extends VueInstallValue, Extras extends Record<string, VueInstallValue> = Record<never, never>>(main: Main, extras?: Extras): Installable<Main> & Extras;
45
+ /**
46
+ * 为不需要单独注册的附属组件附加空安装函数。
47
+ *
48
+ * @remarks 适用于只能作为主组件附属属性使用、但仍需满足 Vue Plugin 类型的组件。
49
+ * 函数直接修改并返回传入组件,不会向 Vue 全局组件表注册内容。
50
+ * @param component - 尚未定义或继承 `install` 属性的组件。
51
+ * @returns 原组件引用及无副作用的 `install` 方法。
52
+ * @throws `TypeError` 当组件自身或原型链已经存在 `install`。
53
+ */
54
+ declare function withNoopInstall<Value extends VueInstallValue>(component: Value): TSXWithInstall<Value>;
55
+ /**
56
+ * 为 Vue 2.7/3 指令附加插件安装能力。
57
+ *
58
+ * @remarks 函数直接修改并返回指令。安装时重复注册同一引用保持幂等,不会覆盖同名的
59
+ * 其他指令。名称只传给 `directive()`,不得包含 `v-` 前缀。
60
+ * @param directive - 尚未定义或继承 `install` 属性的 Vue 指令对象。
61
+ * @param name - 非空、无空白且不以 `v-` 开头的全局指令名。
62
+ * @returns 原指令引用及 Vue Plugin `install` 方法。
63
+ * @throws `TypeError` 当名称非法、指令已有 `install`,或安装目标无效。
64
+ * @throws `Error` 当安装目标中同名位置已经注册其他指令。
65
+ */
66
+ declare function withInstallDirective<Value extends VueInstallValue>(directive: Value, name: string): Installable<Value>;
67
+ //#endregion
68
+ export { Installable, TSXWithInstall, VueInstallValue, VueRegistrationTarget, withInstall, withInstallDirective, withNoopInstall };
69
+ //# sourceMappingURL=install.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"install.d.mts","names":[],"sources":["../../src/vue/install.ts"],"mappings":";;UACiB;;;;;;;;EAQhB,YAAY,cAAc;;;;;;;;EAQ1B,YAAY,cAAc;;;KAIf,gCAAgC;;KAGhC,YAAY,SAAS;;;;;EAKhC,UAAU;;;KAIC,eAAe,SAAS,YAAY;;;;;;;;;;;;iBA0EhC,YAAY,aAAa,iBAAiB,eAAe,eAAe,mBAAmB,sBAC1G,MAAM,MACN,SAAS,SACP,YAAY,QAAQ;;;;;;;;;;iBAyCP,gBAAgB,cAAc,iBAAiB,WAAW,QAAQ,eAAe;;;;;;;;;;;;iBAkBjF,qBAAqB,cAAc,iBAAiB,WAAW,OAAO,eAAe,YAAY"}
@@ -0,0 +1,123 @@
1
+ //#region src/vue/install.ts
2
+ /**
3
+ * 校验 Vue 插件安装目标。
4
+ *
5
+ * @param value - Vue 2.7 构造器或 Vue 3 App 实例。
6
+ * @returns 只包含组件和指令注册能力的结构化目标。
7
+ * @throws `TypeError` 当目标缺少 `component` 或 `directive` 方法。
8
+ */
9
+ const assertTarget = (value) => {
10
+ if (typeof value !== "object" && typeof value !== "function" || value === null) throw new TypeError("Vue plugin installation requires a Vue constructor or App.");
11
+ const target = value;
12
+ if (typeof target.component !== "function" || typeof target.directive !== "function") throw new TypeError("Vue plugin installation requires component() and directive() registration methods.");
13
+ return target;
14
+ };
15
+ /**
16
+ * 提取组件的全局注册名称。
17
+ *
18
+ * @param component - 待注册组件。
19
+ * @returns 去除外围空白后的显式名称。
20
+ * @throws `TypeError` 当组件没有非空字符串名称。
21
+ */
22
+ const getComponentName = (component) => {
23
+ const name = component.name;
24
+ if (typeof name !== "string" || name.length === 0 || /\s/u.test(name)) throw new TypeError("Installable Vue components must expose a non-empty name without whitespace.");
25
+ return name;
26
+ };
27
+ /**
28
+ * 预检单个组件注册。
29
+ *
30
+ * @remarks 先读取同名组件并完成冲突判断,再返回延迟执行动作;调用方可以在所有组件预检通过后统一提交。
31
+ * @param target - 已校验的 Vue 注册目标。
32
+ * @param component - 待注册组件。
33
+ * @returns 已校验的组件引用、名称和目标中是否已经存在同一引用。
34
+ * @throws `Error` 当同名位置已由其他组件占用。
35
+ */
36
+ const prepareComponentRegistration = (target, component) => {
37
+ const name = getComponentName(component);
38
+ const existing = target.component(name);
39
+ if (existing !== void 0 && existing !== component) throw new Error(`Vue component name "${name}" is already registered by another component.`);
40
+ return {
41
+ component,
42
+ name,
43
+ registered: existing === component
44
+ };
45
+ };
46
+ /**
47
+ * 为主组件附加 Vue 2.7 `Vue.use()` 与 Vue 3 `app.use()` 安装能力。
48
+ *
49
+ * @remarks 函数会直接为 `main` 定义附属组件属性和 `install`。所有组件名称、附属属性
50
+ * 冲突会在修改 `main` 前完成校验;安装到 App 时也会先预检全部全局名称,再统一注册。
51
+ * @param main - 具有非空 `name` 的组件。
52
+ * @param extras - 同时注册并以可枚举属性挂到主组件的附属组件映射。
53
+ * @returns 原始 `main` 引用,并附加类型化的 `install` 与 `extras` 属性。
54
+ * @throws `TypeError` 当组件缺少合法名称、已有 `install`、附属键或名称发生冲突。
55
+ * @throws `Error` 当安装目标中同名位置已经注册其他组件。
56
+ */
57
+ function withInstall(main, extras) {
58
+ const componentNames = /* @__PURE__ */ new Set([getComponentName(main)]);
59
+ if ("install" in Object(main)) throw new TypeError("The Vue component already defines an install property.");
60
+ const extraEntries = Object.entries(extras ?? {});
61
+ if (extras !== void 0 && Object.getOwnPropertySymbols(extras).some((key) => Object.prototype.propertyIsEnumerable.call(extras, key))) throw new TypeError("Vue component extras must use string property names.");
62
+ for (const [key, component] of extraEntries) {
63
+ const componentName = getComponentName(component);
64
+ if (componentNames.has(componentName)) throw new TypeError(`Vue component name "${componentName}" is registered more than once.`);
65
+ componentNames.add(componentName);
66
+ if (key === "install" || key in Object(main)) throw new TypeError(`Vue component extra "${key}" would overwrite a property on the main component.`);
67
+ }
68
+ const installable = main;
69
+ for (const [key, component] of extraEntries) Object.defineProperty(installable, key, {
70
+ configurable: true,
71
+ enumerable: true,
72
+ value: component,
73
+ writable: true
74
+ });
75
+ installable.install = (value) => {
76
+ const target = assertTarget(value);
77
+ const registrations = [main, ...extraEntries.map(([, component]) => component)].map((component) => prepareComponentRegistration(target, component));
78
+ for (const registration of registrations) if (!registration.registered) target.component(registration.name, registration.component);
79
+ };
80
+ return installable;
81
+ }
82
+ /**
83
+ * 为不需要单独注册的附属组件附加空安装函数。
84
+ *
85
+ * @remarks 适用于只能作为主组件附属属性使用、但仍需满足 Vue Plugin 类型的组件。
86
+ * 函数直接修改并返回传入组件,不会向 Vue 全局组件表注册内容。
87
+ * @param component - 尚未定义或继承 `install` 属性的组件。
88
+ * @returns 原组件引用及无副作用的 `install` 方法。
89
+ * @throws `TypeError` 当组件自身或原型链已经存在 `install`。
90
+ */
91
+ function withNoopInstall(component) {
92
+ if ("install" in Object(component)) throw new TypeError("The Vue component already defines an install property.");
93
+ const installable = component;
94
+ installable.install = () => void 0;
95
+ return installable;
96
+ }
97
+ /**
98
+ * 为 Vue 2.7/3 指令附加插件安装能力。
99
+ *
100
+ * @remarks 函数直接修改并返回指令。安装时重复注册同一引用保持幂等,不会覆盖同名的
101
+ * 其他指令。名称只传给 `directive()`,不得包含 `v-` 前缀。
102
+ * @param directive - 尚未定义或继承 `install` 属性的 Vue 指令对象。
103
+ * @param name - 非空、无空白且不以 `v-` 开头的全局指令名。
104
+ * @returns 原指令引用及 Vue Plugin `install` 方法。
105
+ * @throws `TypeError` 当名称非法、指令已有 `install`,或安装目标无效。
106
+ * @throws `Error` 当安装目标中同名位置已经注册其他指令。
107
+ */
108
+ function withInstallDirective(directive, name) {
109
+ if (name.length === 0 || /\s/u.test(name) || name.startsWith("v-")) throw new TypeError("Installable Vue directives require a name without whitespace or a v- prefix.");
110
+ if ("install" in Object(directive)) throw new TypeError("The Vue directive already defines an install property.");
111
+ const installable = directive;
112
+ installable.install = (value) => {
113
+ const target = assertTarget(value);
114
+ const existing = target.directive(name);
115
+ if (existing !== void 0 && existing !== directive) throw new Error(`Vue directive name "${name}" is already registered by another directive.`);
116
+ if (existing !== directive) target.directive(name, directive);
117
+ };
118
+ return installable;
119
+ }
120
+ //#endregion
121
+ export { withInstall, withInstallDirective, withNoopInstall };
122
+
123
+ //# sourceMappingURL=install.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"install.mjs","names":[],"sources":["../../src/vue/install.ts"],"sourcesContent":["/** Vue 2.7 构造器与 Vue 3 App 共有的组件、指令注册能力。 */\nexport interface VueRegistrationTarget {\n\t/**\n\t * 读取或注册全局组件。\n\t *\n\t * @param name - 全局组件名。\n\t * @param component - 注册时传入的组件;省略时读取现有组件。\n\t * @returns Vue 平台返回的现有组件、注册结果或目标自身。\n\t */\n\tcomponent: (name: string, component?: unknown) => unknown;\n\t/**\n\t * 读取或注册全局指令。\n\t *\n\t * @param name - 不带 `v-` 的全局指令名。\n\t * @param directive - 注册时传入的指令;省略时读取现有指令。\n\t * @returns Vue 平台返回的现有指令、注册结果或目标自身。\n\t */\n\tdirective: (name: string, directive?: unknown) => unknown;\n}\n\n/** Vue 组件对象、函数组件或指令对象可接受的最小结构类型。 */\nexport type VueInstallValue = object | ((...arguments_: never[]) => unknown);\n\n/** 为 Vue 组件或指令附加供 Vue 2.7 `Vue.use()` 与 Vue 3 `app.use()` 调用的安装能力。 */\nexport type Installable<Value> = Value & {\n\t/**\n\t * 把当前组件或指令安装到 Vue 2.7 构造器或 Vue 3 App。\n\t * @param target - Vue 2.7 构造器或 Vue 3 App 实例。\n\t */\n\tinstall: (target: unknown) => void;\n};\n\n/** TSX 组件安装类型;与 {@link Installable} 保持同一运行时契约。 */\nexport type TSXWithInstall<Value> = Installable<Value>;\n\n/**\n * 校验 Vue 插件安装目标。\n *\n * @param value - Vue 2.7 构造器或 Vue 3 App 实例。\n * @returns 只包含组件和指令注册能力的结构化目标。\n * @throws `TypeError` 当目标缺少 `component` 或 `directive` 方法。\n */\nconst assertTarget = (value: unknown): VueRegistrationTarget => {\n\tif ((typeof value !== \"object\" && typeof value !== \"function\") || value === null) {\n\t\tthrow new TypeError(\"Vue plugin installation requires a Vue constructor or App.\");\n\t}\n\tconst target = value as Partial<VueRegistrationTarget>;\n\tif (typeof target.component !== \"function\" || typeof target.directive !== \"function\") {\n\t\tthrow new TypeError(\"Vue plugin installation requires component() and directive() registration methods.\");\n\t}\n\treturn target as VueRegistrationTarget;\n};\n\n/**\n * 提取组件的全局注册名称。\n *\n * @param component - 待注册组件。\n * @returns 去除外围空白后的显式名称。\n * @throws `TypeError` 当组件没有非空字符串名称。\n */\nconst getComponentName = (component: VueInstallValue): string => {\n\tconst name = (component as { name?: unknown }).name;\n\tif (typeof name !== \"string\" || name.length === 0 || /\\s/u.test(name)) {\n\t\tthrow new TypeError(\"Installable Vue components must expose a non-empty name without whitespace.\");\n\t}\n\treturn name;\n};\n\n/** 预检完成、可以无失败注册的组件动作。 */\ninterface ComponentRegistration {\n\t/** 已校验的组件引用。 */\n\tcomponent: VueInstallValue;\n\t/** 已校验的组件名称。 */\n\tname: string;\n\t/** 目标中是否已经注册了完全相同的组件引用。 */\n\tregistered: boolean;\n}\n\n/**\n * 预检单个组件注册。\n *\n * @remarks 先读取同名组件并完成冲突判断,再返回延迟执行动作;调用方可以在所有组件预检通过后统一提交。\n * @param target - 已校验的 Vue 注册目标。\n * @param component - 待注册组件。\n * @returns 已校验的组件引用、名称和目标中是否已经存在同一引用。\n * @throws `Error` 当同名位置已由其他组件占用。\n */\nconst prepareComponentRegistration = (target: VueRegistrationTarget, component: VueInstallValue): ComponentRegistration => {\n\tconst name = getComponentName(component);\n\tconst existing = target.component(name);\n\tif (existing !== undefined && existing !== component) {\n\t\tthrow new Error(`Vue component name \"${name}\" is already registered by another component.`);\n\t}\n\treturn { component, name, registered: existing === component };\n};\n\n/**\n * 为主组件附加 Vue 2.7 `Vue.use()` 与 Vue 3 `app.use()` 安装能力。\n *\n * @remarks 函数会直接为 `main` 定义附属组件属性和 `install`。所有组件名称、附属属性\n * 冲突会在修改 `main` 前完成校验;安装到 App 时也会先预检全部全局名称,再统一注册。\n * @param main - 具有非空 `name` 的组件。\n * @param extras - 同时注册并以可枚举属性挂到主组件的附属组件映射。\n * @returns 原始 `main` 引用,并附加类型化的 `install` 与 `extras` 属性。\n * @throws `TypeError` 当组件缺少合法名称、已有 `install`、附属键或名称发生冲突。\n * @throws `Error` 当安装目标中同名位置已经注册其他组件。\n */\nexport function withInstall<Main extends VueInstallValue, Extras extends Record<string, VueInstallValue> = Record<never, never>>(\n\tmain: Main,\n\textras?: Extras\n): Installable<Main> & Extras {\n\tconst componentNames = new Set([getComponentName(main)]);\n\tif (\"install\" in Object(main)) throw new TypeError(\"The Vue component already defines an install property.\");\n\tconst extraEntries = Object.entries(extras ?? {});\n\tif (extras !== undefined && Object.getOwnPropertySymbols(extras).some((key) => Object.prototype.propertyIsEnumerable.call(extras, key))) {\n\t\tthrow new TypeError(\"Vue component extras must use string property names.\");\n\t}\n\tfor (const [key, component] of extraEntries) {\n\t\tconst componentName = getComponentName(component);\n\t\tif (componentNames.has(componentName)) throw new TypeError(`Vue component name \"${componentName}\" is registered more than once.`);\n\t\tcomponentNames.add(componentName);\n\t\tif (key === \"install\" || key in Object(main)) {\n\t\t\tthrow new TypeError(`Vue component extra \"${key}\" would overwrite a property on the main component.`);\n\t\t}\n\t}\n\tconst installable = main as Installable<Main> & Extras;\n\tfor (const [key, component] of extraEntries) {\n\t\tObject.defineProperty(installable, key, { configurable: true, enumerable: true, value: component, writable: true });\n\t}\n\tinstallable.install = (value: unknown): void => {\n\t\tconst target = assertTarget(value);\n\t\t// 先完成全部冲突检查,再统一注册,避免安装到一半留下部分全局组件。\n\t\tconst registrations = [main, ...extraEntries.map(([, component]) => component)].map((component) =>\n\t\t\tprepareComponentRegistration(target, component)\n\t\t);\n\t\tfor (const registration of registrations) {\n\t\t\tif (!registration.registered) target.component(registration.name, registration.component);\n\t\t}\n\t};\n\treturn installable;\n}\n\n/**\n * 为不需要单独注册的附属组件附加空安装函数。\n *\n * @remarks 适用于只能作为主组件附属属性使用、但仍需满足 Vue Plugin 类型的组件。\n * 函数直接修改并返回传入组件,不会向 Vue 全局组件表注册内容。\n * @param component - 尚未定义或继承 `install` 属性的组件。\n * @returns 原组件引用及无副作用的 `install` 方法。\n * @throws `TypeError` 当组件自身或原型链已经存在 `install`。\n */\nexport function withNoopInstall<Value extends VueInstallValue>(component: Value): TSXWithInstall<Value> {\n\tif (\"install\" in Object(component)) throw new TypeError(\"The Vue component already defines an install property.\");\n\tconst installable = component as TSXWithInstall<Value>;\n\tinstallable.install = (): void => undefined;\n\treturn installable;\n}\n\n/**\n * 为 Vue 2.7/3 指令附加插件安装能力。\n *\n * @remarks 函数直接修改并返回指令。安装时重复注册同一引用保持幂等,不会覆盖同名的\n * 其他指令。名称只传给 `directive()`,不得包含 `v-` 前缀。\n * @param directive - 尚未定义或继承 `install` 属性的 Vue 指令对象。\n * @param name - 非空、无空白且不以 `v-` 开头的全局指令名。\n * @returns 原指令引用及 Vue Plugin `install` 方法。\n * @throws `TypeError` 当名称非法、指令已有 `install`,或安装目标无效。\n * @throws `Error` 当安装目标中同名位置已经注册其他指令。\n */\nexport function withInstallDirective<Value extends VueInstallValue>(directive: Value, name: string): Installable<Value> {\n\tif (name.length === 0 || /\\s/u.test(name) || name.startsWith(\"v-\")) {\n\t\tthrow new TypeError(\"Installable Vue directives require a name without whitespace or a v- prefix.\");\n\t}\n\tif (\"install\" in Object(directive)) throw new TypeError(\"The Vue directive already defines an install property.\");\n\tconst installable = directive as Installable<Value>;\n\tinstallable.install = (value: unknown): void => {\n\t\tconst target = assertTarget(value);\n\t\tconst existing = target.directive(name);\n\t\tif (existing !== undefined && existing !== directive) {\n\t\t\tthrow new Error(`Vue directive name \"${name}\" is already registered by another directive.`);\n\t\t}\n\t\tif (existing !== directive) target.directive(name, directive);\n\t};\n\treturn installable;\n}\n"],"mappings":";;;;;;;;AA0CA,MAAM,gBAAgB,UAA0C;CAC/D,IAAK,OAAO,UAAU,YAAY,OAAO,UAAU,cAAe,UAAU,MAC3E,MAAM,IAAI,UAAU,4DAA4D;CAEjF,MAAM,SAAS;CACf,IAAI,OAAO,OAAO,cAAc,cAAc,OAAO,OAAO,cAAc,YACzE,MAAM,IAAI,UAAU,oFAAoF;CAEzG,OAAO;AACR;;;;;;;;AASA,MAAM,oBAAoB,cAAuC;CAChE,MAAM,OAAQ,UAAiC;CAC/C,IAAI,OAAO,SAAS,YAAY,KAAK,WAAW,KAAK,MAAM,KAAK,IAAI,GACnE,MAAM,IAAI,UAAU,6EAA6E;CAElG,OAAO;AACR;;;;;;;;;;AAqBA,MAAM,gCAAgC,QAA+B,cAAsD;CAC1H,MAAM,OAAO,iBAAiB,SAAS;CACvC,MAAM,WAAW,OAAO,UAAU,IAAI;CACtC,IAAI,aAAa,KAAA,KAAa,aAAa,WAC1C,MAAM,IAAI,MAAM,uBAAuB,KAAK,8CAA8C;CAE3F,OAAO;EAAE;EAAW;EAAM,YAAY,aAAa;CAAU;AAC9D;;;;;;;;;;;;AAaA,SAAgB,YACf,MACA,QAC6B;CAC7B,MAAM,iCAAiB,IAAI,IAAI,CAAC,iBAAiB,IAAI,CAAC,CAAC;CACvD,IAAI,aAAa,OAAO,IAAI,GAAG,MAAM,IAAI,UAAU,wDAAwD;CAC3G,MAAM,eAAe,OAAO,QAAQ,UAAU,CAAC,CAAC;CAChD,IAAI,WAAW,KAAA,KAAa,OAAO,sBAAsB,MAAM,CAAC,CAAC,MAAM,QAAQ,OAAO,UAAU,qBAAqB,KAAK,QAAQ,GAAG,CAAC,GACrI,MAAM,IAAI,UAAU,sDAAsD;CAE3E,KAAK,MAAM,CAAC,KAAK,cAAc,cAAc;EAC5C,MAAM,gBAAgB,iBAAiB,SAAS;EAChD,IAAI,eAAe,IAAI,aAAa,GAAG,MAAM,IAAI,UAAU,uBAAuB,cAAc,gCAAgC;EAChI,eAAe,IAAI,aAAa;EAChC,IAAI,QAAQ,aAAa,OAAO,OAAO,IAAI,GAC1C,MAAM,IAAI,UAAU,wBAAwB,IAAI,oDAAoD;CAEtG;CACA,MAAM,cAAc;CACpB,KAAK,MAAM,CAAC,KAAK,cAAc,cAC9B,OAAO,eAAe,aAAa,KAAK;EAAE,cAAc;EAAM,YAAY;EAAM,OAAO;EAAW,UAAU;CAAK,CAAC;CAEnH,YAAY,WAAW,UAAyB;EAC/C,MAAM,SAAS,aAAa,KAAK;EAEjC,MAAM,gBAAgB,CAAC,MAAM,GAAG,aAAa,KAAK,GAAG,eAAe,SAAS,CAAC,CAAC,CAAC,KAAK,cACpF,6BAA6B,QAAQ,SAAS,CAC/C;EACA,KAAK,MAAM,gBAAgB,eAC1B,IAAI,CAAC,aAAa,YAAY,OAAO,UAAU,aAAa,MAAM,aAAa,SAAS;CAE1F;CACA,OAAO;AACR;;;;;;;;;;AAWA,SAAgB,gBAA+C,WAAyC;CACvG,IAAI,aAAa,OAAO,SAAS,GAAG,MAAM,IAAI,UAAU,wDAAwD;CAChH,MAAM,cAAc;CACpB,YAAY,gBAAsB,KAAA;CAClC,OAAO;AACR;;;;;;;;;;;;AAaA,SAAgB,qBAAoD,WAAkB,MAAkC;CACvH,IAAI,KAAK,WAAW,KAAK,MAAM,KAAK,IAAI,KAAK,KAAK,WAAW,IAAI,GAChE,MAAM,IAAI,UAAU,8EAA8E;CAEnG,IAAI,aAAa,OAAO,SAAS,GAAG,MAAM,IAAI,UAAU,wDAAwD;CAChH,MAAM,cAAc;CACpB,YAAY,WAAW,UAAyB;EAC/C,MAAM,SAAS,aAAa,KAAK;EACjC,MAAM,WAAW,OAAO,UAAU,IAAI;EACtC,IAAI,aAAa,KAAA,KAAa,aAAa,WAC1C,MAAM,IAAI,MAAM,uBAAuB,KAAK,8CAA8C;EAE3F,IAAI,aAAa,WAAW,OAAO,UAAU,MAAM,SAAS;CAC7D;CACA,OAAO;AACR"}
@@ -0,0 +1,23 @@
1
+ import { ComputedRef, PropType } from "vue";
2
+ //#region src/vue/props.d.ts
3
+ /**
4
+ * 为 Vue 运行时 Props 构造器附加泛型类型。
5
+ *
6
+ * @remarks 该函数只帮助 TypeScript 建模,不验证运行时值与 `Value` 一致;调用方仍应
7
+ * 传入 Vue 支持的构造器或构造器数组。
8
+ * @param runtimeType - Vue 支持的运行时构造器或构造器数组。
9
+ * @returns 同一引用,仅在类型层收窄为 `PropType<Value>`。
10
+ */
11
+ declare function definePropType<Value>(runtimeType: unknown): PropType<Value>;
12
+ /**
13
+ * 构建需要透传给子组件的响应式 Props。
14
+ *
15
+ * @param props - Vue `setup` 接收的只读响应式 Props 对象。
16
+ * @param rawProps - 子组件的运行时 Props 配置。
17
+ * @param ignoredProps - 不需要透传的 Props 名称。
18
+ * @returns 只包含 `rawProps` 声明键且随 Props 更新的 ComputedRef。
19
+ */
20
+ declare function useProps<Props extends object, RawProps extends object>(props: Props, rawProps: RawProps, ignoredProps?: readonly (keyof RawProps)[]): ComputedRef<Pick<Props, Extract<keyof Props, keyof RawProps>>>;
21
+ //#endregion
22
+ export { definePropType, useProps };
23
+ //# sourceMappingURL=props.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"props.d.mts","names":[],"sources":["../../src/vue/props.ts"],"mappings":";;;;;;;;;;iBAYgB,eAAe,OAAO,uBAAuB,SAAS;;;;;;;;;iBAYtD,SAAS,sBAAsB,yBAC9C,OAAO,OACP,UAAU,UACV,+BAA8B,cAC5B,YAAY,KAAK,OAAO,cAAc,aAAa"}
@@ -0,0 +1,41 @@
1
+ import { computed } from "vue";
2
+ //#region src/vue/props.ts
3
+ /**
4
+ * 为 Vue 运行时 Props 构造器附加泛型类型。
5
+ *
6
+ * @remarks 该函数只帮助 TypeScript 建模,不验证运行时值与 `Value` 一致;调用方仍应
7
+ * 传入 Vue 支持的构造器或构造器数组。
8
+ * @param runtimeType - Vue 支持的运行时构造器或构造器数组。
9
+ * @returns 同一引用,仅在类型层收窄为 `PropType<Value>`。
10
+ */
11
+ function definePropType(runtimeType) {
12
+ return runtimeType;
13
+ }
14
+ /**
15
+ * 构建需要透传给子组件的响应式 Props。
16
+ *
17
+ * @param props - Vue `setup` 接收的只读响应式 Props 对象。
18
+ * @param rawProps - 子组件的运行时 Props 配置。
19
+ * @param ignoredProps - 不需要透传的 Props 名称。
20
+ * @returns 只包含 `rawProps` 声明键且随 Props 更新的 ComputedRef。
21
+ */
22
+ function useProps(props, rawProps, ignoredProps = []) {
23
+ const ignored = new Set(ignoredProps);
24
+ return computed(() => {
25
+ const result = {};
26
+ for (const key of Reflect.ownKeys(rawProps)) {
27
+ if (ignored.has(key) || !Object.hasOwn(props, key)) continue;
28
+ Object.defineProperty(result, key, {
29
+ configurable: true,
30
+ enumerable: true,
31
+ value: Reflect.get(props, key),
32
+ writable: true
33
+ });
34
+ }
35
+ return result;
36
+ });
37
+ }
38
+ //#endregion
39
+ export { definePropType, useProps };
40
+
41
+ //# sourceMappingURL=props.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"props.mjs","names":[],"sources":["../../src/vue/props.ts"],"sourcesContent":["import { computed } from \"vue\";\n\nimport type { ComputedRef, PropType } from \"vue\";\n\n/**\n * 为 Vue 运行时 Props 构造器附加泛型类型。\n *\n * @remarks 该函数只帮助 TypeScript 建模,不验证运行时值与 `Value` 一致;调用方仍应\n * 传入 Vue 支持的构造器或构造器数组。\n * @param runtimeType - Vue 支持的运行时构造器或构造器数组。\n * @returns 同一引用,仅在类型层收窄为 `PropType<Value>`。\n */\nexport function definePropType<Value>(runtimeType: unknown): PropType<Value> {\n\treturn runtimeType as PropType<Value>;\n}\n\n/**\n * 构建需要透传给子组件的响应式 Props。\n *\n * @param props - Vue `setup` 接收的只读响应式 Props 对象。\n * @param rawProps - 子组件的运行时 Props 配置。\n * @param ignoredProps - 不需要透传的 Props 名称。\n * @returns 只包含 `rawProps` 声明键且随 Props 更新的 ComputedRef。\n */\nexport function useProps<Props extends object, RawProps extends object>(\n\tprops: Props,\n\trawProps: RawProps,\n\tignoredProps: readonly (keyof RawProps)[] = []\n): ComputedRef<Pick<Props, Extract<keyof Props, keyof RawProps>>> {\n\tconst ignored = new Set<PropertyKey>(ignoredProps);\n\treturn computed<Pick<Props, Extract<keyof Props, keyof RawProps>>>(() => {\n\t\tconst result = {} as Pick<Props, Extract<keyof Props, keyof RawProps>>;\n\t\tfor (const key of Reflect.ownKeys(rawProps)) {\n\t\t\tif (ignored.has(key) || !Object.hasOwn(props, key)) continue;\n\t\t\tObject.defineProperty(result, key, { configurable: true, enumerable: true, value: Reflect.get(props, key), writable: true });\n\t\t}\n\t\treturn result;\n\t});\n}\n"],"mappings":";;;;;;;;;;AAYA,SAAgB,eAAsB,aAAuC;CAC5E,OAAO;AACR;;;;;;;;;AAUA,SAAgB,SACf,OACA,UACA,eAA4C,CAAC,GACoB;CACjE,MAAM,UAAU,IAAI,IAAiB,YAAY;CACjD,OAAO,eAAkE;EACxE,MAAM,SAAS,CAAC;EAChB,KAAK,MAAM,OAAO,QAAQ,QAAQ,QAAQ,GAAG;GAC5C,IAAI,QAAQ,IAAI,GAAG,KAAK,CAAC,OAAO,OAAO,OAAO,GAAG,GAAG;GACpD,OAAO,eAAe,QAAQ,KAAK;IAAE,cAAc;IAAM,YAAY;IAAM,OAAO,QAAQ,IAAI,OAAO,GAAG;IAAG,UAAU;GAAK,CAAC;EAC5H;EACA,OAAO;CACR,CAAC;AACF"}
@@ -0,0 +1,13 @@
1
+ import { VNode } from "vue";
2
+ //#region src/vue/render.d.ts
3
+ /**
4
+ * 在当前 Vue 2.7/3 组件实例上安装 TSX 渲染函数。
5
+ *
6
+ * @remarks 组件的 `setup` 可以继续返回状态对象,因此状态能够显示在 Vue Devtools 中。
7
+ * @param render - 当前组件的渲染函数。
8
+ * @throws 不在组件 `setup` 调用栈中使用时抛出 `Error`。
9
+ */
10
+ declare function useRender(render: () => VNode): void;
11
+ //#endregion
12
+ export { useRender };
13
+ //# sourceMappingURL=render.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render.d.mts","names":[],"sources":["../../src/vue/render.ts"],"mappings":";;;;;;;;;iBA+BgB,UAAU,cAAc"}
@@ -0,0 +1,23 @@
1
+ import { getCurrentInstance } from "vue";
2
+ //#region src/vue/render.ts
3
+ /**
4
+ * 在当前 Vue 2.7/3 组件实例上安装 TSX 渲染函数。
5
+ *
6
+ * @remarks 组件的 `setup` 可以继续返回状态对象,因此状态能够显示在 Vue Devtools 中。
7
+ * @param render - 当前组件的渲染函数。
8
+ * @throws 不在组件 `setup` 调用栈中使用时抛出 `Error`。
9
+ */
10
+ function useRender(render) {
11
+ const instance = getCurrentInstance();
12
+ if (instance === null) throw new Error("useRender must be called from inside a setup function.");
13
+ const compatible = instance;
14
+ if (compatible.proxy?.$options !== void 0 && !("render" in compatible)) {
15
+ compatible.proxy.$options.render = render;
16
+ return;
17
+ }
18
+ compatible.render = render;
19
+ }
20
+ //#endregion
21
+ export { useRender };
22
+
23
+ //# sourceMappingURL=render.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render.mjs","names":[],"sources":["../../src/vue/render.ts"],"sourcesContent":["import { getCurrentInstance } from \"vue\";\n\nimport type { VNode } from \"vue\";\n\n/** Vue 2.7 与 Vue 3 组件实例中渲染函数可能出现的位置。 */\ninterface CompatibleVueInstance {\n\t/** Vue 2.7 兼容实例上的公共代理。 */\n\tproxy?: CompatibleVueProxy;\n\t/** Vue 3 内部组件实例直接持有的渲染函数。 */\n\trender?: () => VNode;\n}\n\n/** Vue 2.7 公共代理中允许写入渲染函数的最小结构。 */\ninterface CompatibleVueProxy {\n\t/** 当前组件的可变 Options API 配置。 */\n\t$options?: CompatibleVueOptions;\n}\n\n/** TSX Helper 需要写入的最小组件选项。 */\ninterface CompatibleVueOptions {\n\t/** 当前组件渲染函数;调用 {@link useRender} 后替换为传入函数。 */\n\trender?: () => VNode;\n}\n\n/**\n * 在当前 Vue 2.7/3 组件实例上安装 TSX 渲染函数。\n *\n * @remarks 组件的 `setup` 可以继续返回状态对象,因此状态能够显示在 Vue Devtools 中。\n * @param render - 当前组件的渲染函数。\n * @throws 不在组件 `setup` 调用栈中使用时抛出 `Error`。\n */\nexport function useRender(render: () => VNode): void {\n\tconst instance = getCurrentInstance();\n\tif (instance === null) throw new Error(\"useRender must be called from inside a setup function.\");\n\tconst compatible = instance as unknown as CompatibleVueInstance;\n\tif (compatible.proxy?.$options !== undefined && !(\"render\" in compatible)) {\n\t\tcompatible.proxy.$options.render = render;\n\t\treturn;\n\t}\n\tcompatible.render = render;\n}\n"],"mappings":";;;;;;;;;AA+BA,SAAgB,UAAU,QAA2B;CACpD,MAAM,WAAW,mBAAmB;CACpC,IAAI,aAAa,MAAM,MAAM,IAAI,MAAM,wDAAwD;CAC/F,MAAM,aAAa;CACnB,IAAI,WAAW,OAAO,aAAa,KAAA,KAAa,EAAE,YAAY,aAAa;EAC1E,WAAW,MAAM,SAAS,SAAS;EACnC;CACD;CACA,WAAW,SAAS;AACrB"}
@@ -0,0 +1,19 @@
1
+ import { SlotsType, VNode } from "vue";
2
+ //#region src/vue/slots.d.ts
3
+ /** Slot 名到 Props 类型的内部声明映射。 */
4
+ type RawSlots = Record<string, unknown>;
5
+ /** 根据 Slot Props 是否为 never 生成无参数或有参数的 Slot 签名。 */
6
+ type VueSlot<Properties> = [Properties] extends [never] ? () => VNode[] : (properties: Properties) => VNode[];
7
+ /** 把 Slot 名称与作用域参数映射为 Vue 3 Slot 函数。 */
8
+ type TypedSlots<Slots extends RawSlots> = { [Name in keyof Slots]: VueSlot<Slots[Name]>; };
9
+ /** Vue 3 `slots` 选项接受的运行时声明与官方静态类型标记。 */
10
+ type TypedSlotsDeclaration<Slots extends RawSlots> = SlotsType<Partial<TypedSlots<Slots>>>;
11
+ /**
12
+ * 为 Options API 的 `slots` 选项创建带作用域参数的类型声明。
13
+ *
14
+ * @returns 运行时 `Object` 构造器,并携带仅供 TypeScript 使用的 Slot 类型标记。
15
+ */
16
+ declare function makeSlots<Slots extends RawSlots>(): TypedSlotsDeclaration<Slots>;
17
+ //#endregion
18
+ export { TypedSlots, TypedSlotsDeclaration, makeSlots };
19
+ //# sourceMappingURL=slots.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slots.d.mts","names":[],"sources":["../../src/vue/slots.ts"],"mappings":";;;KAGK,WAAW;;KAEX,QAAQ,eAAe,oCAAoC,WAAW,YAAY,eAAe;;KAG1F,WAAW,cAAc,eACnC,cAAc,QAAQ,QAAQ,MAAM;;KAI1B,sBAAsB,cAAc,YAAY,UAAU,QAAQ,WAAW;;;;;;iBAOzE,UAAU,cAAc,aAAa,sBAAsB"}
@@ -0,0 +1,13 @@
1
+ //#region src/vue/slots.ts
2
+ /**
3
+ * 为 Options API 的 `slots` 选项创建带作用域参数的类型声明。
4
+ *
5
+ * @returns 运行时 `Object` 构造器,并携带仅供 TypeScript 使用的 Slot 类型标记。
6
+ */
7
+ function makeSlots() {
8
+ return Object;
9
+ }
10
+ //#endregion
11
+ export { makeSlots };
12
+
13
+ //# sourceMappingURL=slots.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slots.mjs","names":[],"sources":["../../src/vue/slots.ts"],"sourcesContent":["import type { SlotsType, VNode } from \"vue\";\n\n/** Slot 名到 Props 类型的内部声明映射。 */\ntype RawSlots = Record<string, unknown>;\n/** 根据 Slot Props 是否为 never 生成无参数或有参数的 Slot 签名。 */\ntype VueSlot<Properties> = [Properties] extends [never] ? () => VNode[] : (properties: Properties) => VNode[];\n\n/** 把 Slot 名称与作用域参数映射为 Vue 3 Slot 函数。 */\nexport type TypedSlots<Slots extends RawSlots> = {\n\t[Name in keyof Slots]: VueSlot<Slots[Name]>;\n};\n\n/** Vue 3 `slots` 选项接受的运行时声明与官方静态类型标记。 */\nexport type TypedSlotsDeclaration<Slots extends RawSlots> = SlotsType<Partial<TypedSlots<Slots>>>;\n\n/**\n * 为 Options API 的 `slots` 选项创建带作用域参数的类型声明。\n *\n * @returns 运行时 `Object` 构造器,并携带仅供 TypeScript 使用的 Slot 类型标记。\n */\nexport function makeSlots<Slots extends RawSlots>(): TypedSlotsDeclaration<Slots> {\n\treturn Object as TypedSlotsDeclaration<Slots>;\n}\n"],"mappings":";;;;;;AAoBA,SAAgB,YAAkE;CACjF,OAAO;AACR"}
@@ -0,0 +1,12 @@
1
+ //#region src/vue/with.d.ts
2
+ /**
3
+ * 保留传入值并显式指定其 TypeScript 类型。
4
+ *
5
+ * @remarks 未传值时运行时结果为 `undefined`,仅适合为 reactive 对象的初始字段提供类型。
6
+ * @param data - 可选的原始值。
7
+ * @returns 传入值本身;省略时返回类型化的 `undefined`。
8
+ */
9
+ declare function withDefineType<Value>(data?: Value): Value;
10
+ //#endregion
11
+ export { withDefineType };
12
+ //# sourceMappingURL=with.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"with.d.mts","names":[],"sources":["../../src/vue/with.ts"],"mappings":";;;;;;;;iBAOgB,eAAe,OAAO,OAAO,QAAQ"}
@@ -0,0 +1,15 @@
1
+ //#region src/vue/with.ts
2
+ /**
3
+ * 保留传入值并显式指定其 TypeScript 类型。
4
+ *
5
+ * @remarks 未传值时运行时结果为 `undefined`,仅适合为 reactive 对象的初始字段提供类型。
6
+ * @param data - 可选的原始值。
7
+ * @returns 传入值本身;省略时返回类型化的 `undefined`。
8
+ */
9
+ function withDefineType(data) {
10
+ return data;
11
+ }
12
+ //#endregion
13
+ export { withDefineType };
14
+
15
+ //# sourceMappingURL=with.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"with.mjs","names":[],"sources":["../../src/vue/with.ts"],"sourcesContent":["/**\n * 保留传入值并显式指定其 TypeScript 类型。\n *\n * @remarks 未传值时运行时结果为 `undefined`,仅适合为 reactive 对象的初始字段提供类型。\n * @param data - 可选的原始值。\n * @returns 传入值本身;省略时返回类型化的 `undefined`。\n */\nexport function withDefineType<Value>(data?: Value): Value {\n\treturn data as Value;\n}\n"],"mappings":";;;;;;;;AAOA,SAAgB,eAAsB,MAAqB;CAC1D,OAAO;AACR"}
package/docs/API.md ADDED
@@ -0,0 +1,96 @@
1
+ # Fast.Utils API
2
+
3
+ Fast.Utils is a browser-first, pure ESM utility package targeting ES2022. Its application environments are modern browsers, WebViews, Vue 2.7/3, and uni-app.
4
+
5
+ ## Imports
6
+
7
+ The package has one public root entry. Every utility, including the Vue helpers, is exposed as a named export.
8
+
9
+ ```ts
10
+ import { chunk, configureStorage, installationIdentity, Local } from "@fast-china/utils";
11
+ ```
12
+
13
+ Internal helpers are not public subpaths. Aggregate utility objects are not exported; import named functions so bundlers can remove unused code.
14
+
15
+ ## Storage
16
+
17
+ Call `configureStorage` once in the application entry, then import `Local` or `Session` directly wherever needed.
18
+
19
+ ```ts
20
+ import { configureStorage, Local, Session } from "@fast-china/utils";
21
+
22
+ configureStorage({ prefix: "admin:" });
23
+
24
+ Local.set("profile", { name: "Ada" }, { ttlMs: 3_600_000 });
25
+ Session.set("draft", { step: 2 });
26
+ ```
27
+
28
+ `Local` and `Session` provide `get`, `set`, `has`, `remove`, `removeByPrefix`, `keys`, `pruneExpired`, and namespace-scoped `clear`. Missing and expired values return `undefined`. Invalid TTL values, empty prefixes, malformed stored envelopes, unavailable platform storage, and conflicting repeated configuration throw errors. Native storage quota and privacy errors are propagated.
29
+
30
+ For uni-app, `configureStorage` automatically detects the global `uni` object and uses its synchronous Storage API. uni-app has no separate session backend, so `Session` throws when called in this mode.
31
+
32
+ ```ts
33
+ import { configureStorage, Local } from "@fast-china/utils";
34
+
35
+ configureStorage({ prefix: "mini:" });
36
+ Local.set("token", "value");
37
+ ```
38
+
39
+ Custom codecs may be supplied with `codec`. `base64StorageCodec` is reversible obfuscation, not encryption.
40
+
41
+ `encodeSecureBase64` and `decodeSecureBase64` preserve the legacy dictionary payload while using a Web Crypto random prefix. Given the same default six-character prefix, valid legacy payloads remain byte-for-byte compatible. The old dictionary references an unavailable character for Base64 lengths 101–124, so the current implementation inserts a one-character fallback that the legacy removal flow can decode. The old custom-length argument always generated six random characters; the current API correctly generates `prefixLength` characters. Custom lengths must match during encoding and decoding; `0` disables both the prefix and dictionary insertion. The format remains reversible encoding rather than encryption.
42
+
43
+ ## Identity
44
+
45
+ `installationIdentity` is the global installation identifier facade. Call `configureInstallationIdentity` in the application entry before first use to override its `identity:installation-id` cache key. `getOrCreateInstallationId(installationId?)` loads, creates, or replaces its UUID v4 value in configured `Local` storage. Call `configureStorage` first. UUID generation requires Web Crypto and never falls back to `Math.random()`.
46
+
47
+ ```ts
48
+ import { configureInstallationIdentity, configureStorage, getOrCreateInstallationId, installationIdentity } from "@fast-china/utils";
49
+
50
+ configureStorage({ prefix: "app:" });
51
+ configureInstallationIdentity({ cacheKey: "account:installation-id" });
52
+ getOrCreateInstallationId();
53
+ installationIdentity.read();
54
+ installationIdentity.clear();
55
+ ```
56
+
57
+ The identifier is an installation-scoped value, not a hardware identifier, authentication credential, secret, or anti-fraud signal.
58
+
59
+ ## Logger
60
+
61
+ Logger scope belongs to each message rather than a mutable logger or child instance:
62
+
63
+ ```ts
64
+ import { logger } from "@fast-china/utils";
65
+
66
+ logger.info("storage", "profile loaded", { userId: 1 });
67
+ logger.error("network", "request failed", error);
68
+ ```
69
+
70
+ `createLogger` configures the minimum level, brand prefix, sink, and optional uni-app App-Plus split output. Scope must be a non-empty string without surrounding whitespace.
71
+
72
+ ## Modules
73
+
74
+ - `array`: `chunk`, `removeNullishValues`, `unique`, `uniqueBy`, `groupBy`, `partition`, `difference`, `intersection`, `hasDuplicatesBy`, and `allEqualBy`.
75
+ - `async`: abort-aware `sleep`, timeout, retry, bounded concurrent mapping, debounce, and throttle primitives.
76
+ - `base64`: strict UTF-8 Base64/Base64URL byte and text functions plus the historical Latin-1 and dictionary-obfuscation functions.
77
+ - `color`: Hex parsing/formatting/mixing, explicit black/white mixing, luminance, and contrast helpers.
78
+ - `crypto`: secure randomness, hashes, AES compatibility helpers, authenticated password encryption, RSA-OAEP, ECDSA, and ECDH helpers.
79
+ - `date`: date validation and arithmetic, day ranges, relative formatting, and the seven historical date helpers as named functions.
80
+ - `dom`: CSS unit and style serialization helpers.
81
+ - `env`: capability and user-agent detection. Detection does not expand the supported runtime contract.
82
+ - `logger`: isolated configurable loggers and the default `logger`.
83
+ - `number`: ranges, rounding, aggregation, interpolation, byte formatting, and secure integer generation.
84
+ - `object`: prototype-safe selection, comparison, mapping, and query serialization. Style serialization is provided by the `dom` module.
85
+ - `string`: query parsing, casing, grapheme-aware truncation, UUID, secure random strings, escaping, and whitespace normalization.
86
+ - `vue`: Composition API, type, render, and registration helpers for Vue 2.7/3. `makeSlots` is Vue 3-only because it uses Vue's official `SlotsType`.
87
+
88
+ ## Security and limits
89
+
90
+ Use authenticated password encryption for new protected payloads. AES-CBC/ECB, MD5, SHA-1, and the historical Base64 dictionary exist for protocol compatibility and must not be presented as modern authenticated encryption. Cryptographic helpers enforce algorithm-specific parameter and payload limits and require Web Crypto where applicable.
91
+
92
+ Query and object helpers reject prototype-polluting keys. URL decoders are bounded. Storage cleanup is always restricted to the configured namespace. Browser globals are resolved only when an API is called, never during module import.
93
+
94
+ ## Errors and compatibility
95
+
96
+ Programming errors, invalid inputs, unsupported platform capabilities, and malformed protected data throw native errors unless a function explicitly documents a nullable result.
@@ -0,0 +1,96 @@
1
+ # Fast.Utils API
2
+
3
+ Fast.Utils 是面向浏览器的纯 ESM 工具包,语法目标为 ES2022,应用环境包括现代浏览器、WebView、Vue 2.7/3 和 uni-app。
4
+
5
+ ## 导入
6
+
7
+ 包只提供一个公开根入口,包含普通工具和 Vue Helper 在内的全部 API 均使用具名导出。
8
+
9
+ ```ts
10
+ import { chunk, configureStorage, installationIdentity, Local } from "@fast-china/utils";
11
+ ```
12
+
13
+ 内部 Helper 不提供公共子路径。库不再导出工具聚合对象,调用方应直接导入具名函数,以便 Tree Shaking。
14
+
15
+ ## Storage
16
+
17
+ 在程序入口调用一次 `configureStorage`,其余业务文件直接从包中导入 `Local` 或 `Session`。
18
+
19
+ ```ts
20
+ import { configureStorage, Local, Session } from "@fast-china/utils";
21
+
22
+ configureStorage({ prefix: "admin:" });
23
+
24
+ Local.set("profile", { name: "Ada" }, { ttlMs: 3_600_000 });
25
+ Session.set("draft", { step: 2 });
26
+ ```
27
+
28
+ `Local` 和 `Session` 提供 `get`、`set`、`has`、`remove`、`removeByPrefix`、`keys`、`pruneExpired` 和仅清理当前命名空间的 `clear`。键缺失或过期时返回 `undefined`。TTL 非法、Prefix 为空、存储包络损坏、平台 Storage 不可用或重复配置发生冲突时抛出错误;浏览器配额与隐私策略错误直接向上传播。
29
+
30
+ uni-app 中,`configureStorage` 会自动检测全局 `uni` 并使用其同步 Storage API。uni-app 没有独立 Session 后端,因此该模式调用 `Session` 会明确抛错。
31
+
32
+ ```ts
33
+ import { configureStorage, Local } from "@fast-china/utils";
34
+
35
+ configureStorage({ prefix: "mini:" });
36
+ Local.set("token", "value");
37
+ ```
38
+
39
+ 可以通过 `codec` 注入自定义 Codec。`base64StorageCodec` 只是可逆混淆,不是加密。
40
+
41
+ `encodeSecureBase64` 与 `decodeSecureBase64` 保留旧字典兼容载荷,并使用 Web Crypto 生成安全随机前缀。给定相同的默认 6 字符前缀时,有效旧载荷保持逐字符兼容;旧字典在 Base64 长度 101–124 时会引用越界,当前实现使用单字符回退,旧删除字典流程仍可解码。旧自定义长度参数始终生成 6 个随机字符,当前 API 已按 `prefixLength` 正确生成。自定义 `prefixLength` 必须在编码和解码时保持一致;传入 `0` 会同时关闭随机前缀与字典插入。该格式仍是可逆编码,不等同于加密。
42
+
43
+ ## Identity
44
+
45
+ `installationIdentity` 是全局安装标识门面。可在程序入口、首次使用前调用 `configureInstallationIdentity` 覆盖默认缓存键 `identity:installation-id`。`getOrCreateInstallationId(installationId?)` 会通过已配置的 `Local` 读取、生成或替换 UUID v4。必须先调用 `configureStorage`。UUID 生成依赖 Web Crypto,不会回退到 `Math.random()`。
46
+
47
+ ```ts
48
+ import { configureInstallationIdentity, configureStorage, getOrCreateInstallationId, installationIdentity } from "@fast-china/utils";
49
+
50
+ configureStorage({ prefix: "app:" });
51
+ configureInstallationIdentity({ cacheKey: "account:installation-id" });
52
+ getOrCreateInstallationId();
53
+ installationIdentity.read();
54
+ installationIdentity.clear();
55
+ ```
56
+
57
+ 这个 ID 只标识当前存储空间中的安装实例,不是硬件标识、认证凭证、秘密或反欺诈信号。
58
+
59
+ ## Logger
60
+
61
+ Logger 作用域属于每条日志,不保存在可变 Logger 或 Child 实例中:
62
+
63
+ ```ts
64
+ import { logger } from "@fast-china/utils";
65
+
66
+ logger.info("storage", "profile loaded", { userId: 1 });
67
+ logger.error("network", "request failed", error);
68
+ ```
69
+
70
+ `createLogger` 只配置最低级别、品牌前缀、Sink 和可选的 uni-app App-Plus 拆分输出。作用域必须是无外围空白的非空字符串。
71
+
72
+ ## 模块
73
+
74
+ - `array`:分块、压缩、去重、分组、分区、差集、交集和一致性判断。
75
+ - `async`:支持取消的 Sleep、超时、重试、受限并发映射、防抖和节流。
76
+ - `base64`:严格 UTF-8 Base64/Base64URL 字节与文本函数,以及 Latin-1 和 SecureBase64 兼容函数。
77
+ - `color`:颜色解析、格式化、混合、明暗、亮度和对比度。
78
+ - `crypto`:安全随机、哈希、AES 兼容函数、认证密码加密、RSA-OAEP、ECDSA 和 ECDH。
79
+ - `date`:日期校验、加减、日范围、相对时间,以及七个历史日期功能的具名函数。
80
+ - `dom`:CSS 单位和 Style 序列化。
81
+ - `env`:能力与 User-Agent 检测;检测函数不扩大运行时支持范围。
82
+ - `logger`:隔离的可配置 Logger 和默认 `logger`。
83
+ - `number`:范围、舍入、聚合、插值、字节格式化和安全随机整数。
84
+ - `object`:防原型污染的选择、比较、映射和 Query 序列化;Style 序列化由 `dom` 模块提供。
85
+ - `string`:Query 解析、大小写、字素截断、UUID、安全随机文本、转义和空白规范化。
86
+ - `vue`:Vue 2.7/3 的 Composition API、类型、Render 和注册 Helper;使用官方 `SlotsType` 的 `makeSlots` 仅供 Vue 3 使用。
87
+
88
+ ## 安全与限制
89
+
90
+ 新受保护载荷应使用认证密码加密。AES-CBC/ECB、MD5、SHA-1 和历史 Base64 字典仅用于协议兼容,不能描述为现代认证加密。Crypto API 按算法限制参数和载荷大小,并在需要时强制要求 Web Crypto。
91
+
92
+ Query 与 Object API 拒绝原型污染键,URL 解码有最大深度,Storage 清理只作用于配置的命名空间。浏览器全局对象只在调用 API 时解析,模块导入阶段不会访问。
93
+
94
+ ## 错误与兼容性
95
+
96
+ 除明确说明返回空值的函数外,编程错误、非法输入、平台能力缺失和受保护数据损坏均抛出原生错误。