hyperscript-rxjs 1.3.23 → 1.3.24

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.
@@ -198,13 +198,16 @@ export declare function colgroup(...childNodes: any[]): HyperscriptExtensions<HT
198
198
  * `collapse` 函数通过绑定 `hidden` 属性,实现一组 HTML 元素的动态显示或隐藏。
199
199
  *
200
200
  * @param {Observable<boolean>} hidden$ - 一个可观察对象(如 BehaviorSubject),用于控制元素的 `hidden` 属性。
201
- * @param {...HTMLElement|HTMLElement[]} elements - 一个或多个 HTML 元素,或者包含 HTML 元素的数组。
201
+ * @param {...HTMLElement} elements - 一个或多个 HTML 元素,或者包含 HTML 元素的数组。
202
202
  * @returns {HTMLElement[]} - 处理后的元素数组。
203
203
  *
204
204
  * @throws {Error} 如果 `elements` 中包含非元素节点(如 TextNode)。
205
205
  *
206
206
  */
207
- export declare function collapse(hidden$: Observable<boolean>, ...elements: (HTMLElement | HTMLElement[])[]): HTMLElement[];
207
+ export declare function collapse(
208
+ hidden$: Observable<boolean>,
209
+ ...elements: HTMLElement[]
210
+ ): HTMLElement[];
208
211
 
209
212
  /**
210
213
  * 比较两个日期对象的大小。
@@ -349,10 +352,6 @@ export declare class Comparer<T> {
349
352
  isSuperset(array1: T[], array2: T[]): boolean;
350
353
  }
351
354
 
352
- export declare function compose(...fns: ((arg: any) => any)[]): (arg: any) => any;
353
-
354
- export declare function cond(branches: Array<Function | [Function, Function]>): (...args: any[]) => any;
355
-
356
355
  export declare function data(props: {
357
356
  [_: string]: any;
358
357
  }, ...childNodes: any[]): HyperscriptExtensions<HTMLDataElement>;
@@ -646,18 +645,6 @@ export declare function flat(data: any, isLeaf?: (value: any, key: string | numb
646
645
  */
647
646
  export declare function flip(yinHidden$: Observable<boolean>, yin: HTMLElement | HTMLElement[], yang: HTMLElement | HTMLElement[]): HTMLElement[];
648
647
 
649
- /**
650
- * 通用折叠(递归归约)函数。
651
- *
652
- * @public
653
- * @param {(this:any, acc: any, seed: any) => [*, *]|[any]|[]|null|undefined} fn - 处理函数,返回 [新acc, 新seed] 或 [新acc]
654
- * @param {*} acc - 初始累加值
655
- * @param {*} seed - 初始种子
656
- * @returns {*} 折叠后的结果
657
- * @this *
658
- */
659
- export declare function fold(this: any, fn: (this: any, acc: any, seed: any) => [any, any] | [any] | [] | null | undefined, acc: any, seed: any): any;
660
-
661
648
  export declare function footer(props: {
662
649
  [_: string]: any;
663
650
  }, ...childNodes: any[]): HyperscriptExtensions<HTMLElement>;
@@ -673,11 +660,11 @@ export declare function form(...childNodes: any[]): HyperscriptExtensions<HTMLFo
673
660
  /**
674
661
  * 用途:插入一组元素,不必使用循环语句,fragment 用后即弃。
675
662
  *
676
- * @param {...Node|Node[]} childNodes - 要插入的子节点,可以是单个节点、多个节点或节点数组。
663
+ * @param {...Node} childNodes - 要插入的子节点,可以是单个节点、多个节点或节点数组。
677
664
  * @returns {DocumentFragment} - 返回包含所有子节点的 DocumentFragment。
678
665
  * @throws {Error} 如果传入的子节点不是有效的 DOM 节点。
679
666
  */
680
- export declare function fragment(...childNodes: (Node | Node[])[]): DocumentFragment;
667
+ export declare function fragment(...childNodes: Node[]): DocumentFragment;
681
668
 
682
669
  /**
683
670
  * 获取 HTML 元素的默认 CSS `display` 值。
@@ -782,15 +769,73 @@ export declare function hr(props: {
782
769
 
783
770
  export declare function hr(...childNodes: any[]): HyperscriptExtensions<HTMLHRElement>;
784
771
 
772
+ export declare type HtmlTagName =
773
+ // 主根元素
774
+ | "html"
775
+
776
+ // 文档元数据
777
+ | "head" | "title" | "base" | "link" | "meta" | "style"
778
+
779
+ // 脚本
780
+ | "script" | "noscript" | "template"
781
+
782
+ // 分区根
783
+ | "body"
784
+
785
+ // 内容分区
786
+ | "article" | "aside" | "footer" | "header" | "h1" | "h2" | "h3"
787
+ | "h4" | "h5" | "h6" | "main" | "nav" | "section"
788
+
789
+ // 文本内容
790
+ | "blockquote" | "dd" | "div" | "dl" | "dt" | "figcaption"
791
+ | "figure" | "hr" | "li" | "ol" | "p" | "pre" | "ul"
792
+
793
+ // 内联文本语义
794
+ | "a" | "abbr" | "b" | "bdi" | "bdo" | "br" | "cite" | "code"
795
+ | "data" | "dfn" | "em" | "i" | "kbd" | "mark" | "q"
796
+ | "rp" | "rt" | "ruby" | "s" | "samp" | "small" | "span"
797
+ | "strong" | "sub" | "sup" | "time" | "u" | "var" | "wbr"
798
+
799
+ // 图片和多媒体
800
+ | "area" | "audio" | "img" | "map" | "track" | "video"
801
+
802
+ // 嵌入式内容
803
+ | "embed" | "iframe" | "object" | "param" | "picture" | "portal" | "source"
804
+
805
+ // SVG 和 MathML
806
+ | "svg" | "math"
807
+
808
+ // 表单
809
+ | "button" | "datalist" | "fieldset" | "form" | "input" | "label"
810
+ | "legend" | "meter" | "optgroup" | "option" | "output" | "progress"
811
+ | "select" | "textarea"
812
+
813
+ // 交互元素
814
+ | "details" | "dialog" | "menu" | "summary"
815
+
816
+ // Web Components
817
+ | "slot" | "canvas"
818
+
819
+ // 过时元素 (可选是否包含)
820
+ | "acronym" | "applet" | "basefont" | "big" | "blink" | "center"
821
+ | "content" | "dir" | "font" | "frame" | "frameset" | "isindex"
822
+ | "keygen" | "marquee" | "menuitem" | "nobr" | "noembed"
823
+ | "noframes" | "plaintext" | "rb" | "rtc" | "shadow" | "spacer"
824
+ | "strike" | "tt" | "xmp"
825
+
826
+ // 我添加的
827
+ | 'address' | 'caption' | 'col' | 'colgroup' | 'del'
828
+ | 'hgroup' | 'ins' | 'table' | 'tbody' | 'td' | 'tfoot' | 'th' | 'thead' | 'tr'
829
+
785
830
  /**
786
831
  * Creates an HTML element with extended event handling capabilities
787
832
  * @public
788
- * @param {string} elemName - The HTML element tag name
833
+ * @param {HtmlTagName} elemName - The HTML element tag name
789
834
  * @param {...any} args - Optional properties and child nodes
790
835
  * @returns {HyperscriptElement} The created element with extended methods
791
836
  * @throws {Error} If elemName is not a valid HTML element tag name
792
837
  */
793
- export declare function hyperscript(elemName: string, ...args: any[]): HyperscriptElement;
838
+ export declare function hyperscript(elemName: HtmlTagName, ...args: any[]): HyperscriptElement;
794
839
 
795
840
  export declare type HyperscriptElement = HyperscriptExtensions<HTMLElement>;
796
841
 
@@ -862,11 +907,11 @@ export declare function ins(...childNodes: any[]): HyperscriptExtensions<HTMLMod
862
907
  /**
863
908
  * Creates an object composed of the picked object properties.
864
909
  * @param {Record<string,any>} obj - Source object
865
- * @param {string[]} keys - Array of property keys to pick
910
+ * @param {Iterable<string>} keys - Iterable of property keys to pick
866
911
  * @returns {Record<string,any>} New object with picked properties
867
912
  * @throws {TypeError} If obj is not an object or keys is not an array
868
913
  */
869
- export declare function intersectObject(obj: Record<string, any>, keys: string[]): Record<string, any>;
914
+ export declare function intersectObject(obj: Record<string, any>, keys: Iterable<string>): Record<string, any>;
870
915
 
871
916
  export declare function isEmptyObject(obj: unknown): obj is Record<never, never>;
872
917
 
@@ -959,15 +1004,16 @@ export declare function meter(...childNodes: any[]): HyperscriptExtensions<HTMLM
959
1004
  * 创建一个支持多选功能的 <select> 元素,并绑定选项的选中状态。必须手动添加控件更新BehaviorSubject的事件。
960
1005
  *
961
1006
  * @param {MultiselectProps} props - 配置对象,包含 <select> 元素的属性。
962
- * @param {...HTMLOptionElement[]} options - 一个或多个 <option> 元素,必须是 HTMLOptionElement 类型。
1007
+ * @param {...HTMLOptionElement} options - 一个或多个 <option> 元素,必须是 HTMLOptionElement 类型。
963
1008
  * 每个选项需要包含一个 `selected` 属性,该属性是一个 BehaviorSubject ,用于绑定选中状态。
964
1009
  * @returns {HyperscriptSelectElement} - 创建的 <select> 元素。
965
1010
  * @throws {Error} 如果 `props` 不是对象,或者 `options` 中的选项未正确定义 `selected` 属性。
966
1011
  *
967
1012
  */
968
- export declare function multiselect(props: MultiselectProps, ...options: HTMLOptionElement[]): HyperscriptSelectElement;
969
-
970
- export declare function multiselect(props: MultiselectProps, options: HTMLOptionElement[]): HyperscriptSelectElement;
1013
+ export declare function multiselect(
1014
+ props: MultiselectProps,
1015
+ ...options: HTMLOptionElement[]
1016
+ ): HyperscriptSelectElement;
971
1017
 
972
1018
  export declare type MultiselectProps = {
973
1019
  oninput?: (e: Event) => void;
@@ -995,6 +1041,16 @@ export declare function nestedCombineLatest(model: Record<string | number, any>)
995
1041
  */
996
1042
  export declare function nestedMerge(model: Record<string | number, any>): Observable<[(string | number)[], any]>;
997
1043
 
1044
+ export declare type NestedObject<T> =
1045
+ | T
1046
+ | NestedObject<T>[]
1047
+ | { [_: string]: NestedObject<T> }
1048
+
1049
+ /**
1050
+ * 表示一个可以无限嵌套的字符串结构
1051
+ */
1052
+ export declare type NestedStringArray = string | NestedStringArray[]
1053
+
998
1054
  /**
999
1055
  * 规范化子节点,将非节点转换为文本节点。
1000
1056
  *
@@ -1136,18 +1192,24 @@ export declare function parseHyperscriptArgs(args: any[]): {
1136
1192
  export declare function parsePropName(props: string, obj: Record<string, any>): [Record<string, any>, string];
1137
1193
 
1138
1194
  /**
1139
- *
1195
+ *
1140
1196
  * 拾取对象中的BehaviorSubject值,作爲葉子節點,忽略其他值。
1141
- *
1142
- * @param {Record<string|number,any> & { pickeys?: () => string [] }} model - 输入的数据结构,可以是对象、数组或BehaviorSubject
1143
- * @returns {Record<string|number,any>} - 返回只包含BehaviorSubject当前值的结构
1197
+ * @public
1198
+ * @template T
1199
+ * @param {{[_:string]:NestedObject<T>} & { pickeys?:( () => string []) }} source - 输入的数据结构,可以是对象、数组或BehaviorSubject
1200
+ * @param {NestedStringArray[]} [paths]
1201
+ * @returns {{[_:string]:NestedObject<T>}}
1144
1202
  * @throws {Error} 当输入不包含任何BehaviorSubject或结构不符合预期时抛出错误
1145
1203
  */
1146
- export declare function pickBehaviorSubject(model: Record<string | number, any> & {
1147
- pickeys?: () => string[];
1148
- }): Record<string | number, any>;
1149
-
1150
- export declare function pipe(initialValue: any, ...fns: ((arg: any) => any)[]): any;
1204
+ export declare function pickBehaviorSubject<T>(
1205
+ source: {
1206
+ [_: string]: NestedObject<T>;
1207
+ } & {
1208
+ pickeys?: () => NestedStringArray[];
1209
+ }, paths?: NestedStringArray[]
1210
+ ): {
1211
+ [_: string]: NestedObject<T>;
1212
+ };
1151
1213
 
1152
1214
  /**
1153
1215
  * 为指定的 DOM 元素订阅事件流,并通过 pipe 对事件流进行处理。
@@ -1276,14 +1338,12 @@ export declare function section(...childNodes: any[]): HyperscriptExtensions<HTM
1276
1338
  * 创建一个支持 RxJS 数据绑定的 <select> 元素。仅单选选择框。
1277
1339
  *
1278
1340
  * @param { SelectProps } props - 配置对象,包含 <select> 元素的属性。
1279
- * @param {...HTMLOptionElement []} options - 一个或多个 <option> 元素,必须是 HTMLOptionElement 类型。
1341
+ * @param {...HTMLOptionElement} options - 一个或多个 <option> 元素,必须是 HTMLOptionElement 类型。
1280
1342
  * @returns {HyperscriptSelectElement} - 创建的 <select> 元素。
1281
1343
  * @throws {Error} 如果 `props` 不是对象,或者 `selectedIndex` 或 `value` 不是 BehaviorSubject。
1282
1344
  */
1283
1345
  export declare function select(props: SelectProps, ...options: HTMLOptionElement[]): HyperscriptSelectElement;
1284
1346
 
1285
- export declare function select(props: SelectProps, options: HTMLOptionElement[]): HyperscriptSelectElement;
1286
-
1287
1347
  export declare type SelectProps = {
1288
1348
  selectedIndex?: BehaviorSubject<number>;
1289
1349
  value?: BehaviorSubject<string>;
@@ -1482,8 +1542,9 @@ export declare function textbox(props: {
1482
1542
  }): HyperscriptInputElement;
1483
1543
 
1484
1544
  /**
1485
- * @typedef {Text & {subscription?: Subscription, unsubscribe?: ()=>void}} ObservableTextNode
1545
+ * @typedef {Text & {subscription?: Subscription, unsubscribe?: () => void}} ObservableTextNode
1486
1546
  */
1547
+
1487
1548
  /**
1488
1549
  * 创建一个文本节点。
1489
1550
  * 支持静态文本和动态更新的文本(通过 RxJS Observable)。
@@ -1492,11 +1553,11 @@ export declare function textbox(props: {
1492
1553
  * - 如果传入的是 RxJS Observable,则创建一个动态文本节点,并根据 Observable 的值实时更新文本内容。
1493
1554
  * - 动态文本节点支持通过 `unsubscribe` 方法取消订阅。
1494
1555
  *
1495
- * @param {any} text (Observable<any> | any) 任何类型数据都会被转换成string
1556
+ * @param {Observable<T>|T} text 任何类型数据都会被转换成string
1496
1557
  * @returns {ObservableTextNode}
1497
1558
  *
1498
1559
  */
1499
- export declare function textNode(text: any): ObservableTextNode;
1560
+ export declare function textNode<T>(text: Observable<T>|T): ObservableTextNode;
1500
1561
 
1501
1562
  export declare function tfoot(props: {
1502
1563
  [_: string]: any;
@@ -1564,18 +1625,6 @@ export declare function ul(props: {
1564
1625
 
1565
1626
  export declare function ul(...childNodes: any[]): HyperscriptExtensions<HTMLUListElement>;
1566
1627
 
1567
- /**
1568
- * 通过不断调用 fn 生成值,直到 fn 返回 falsy。
1569
- *
1570
- * @public
1571
- * @template T, S
1572
- * @param {(seed: S) => [T, S] | false | null | undefined} fn - 生成函数,接收当前 seed,返回 [value, nextSeed] 或 falsy。
1573
- * @param {S} seed - 初始种子值。
1574
- * @returns {Array<T>} 由 fn 生成的所有 value 组成的数组。
1575
- * @this *
1576
- */
1577
- export declare function unfold<T, S>(this: any, fn: (seed: S) => [T, S] | false | null | undefined, seed: S): Array<T>;
1578
-
1579
1628
  /**
1580
1629
  * 将任意 JS 值序列化为“无引号 JSON”字符串(仅对键名和部分字符串值去引号)。
1581
1630
  *
@@ -1585,15 +1634,6 @@ export declare function unfold<T, S>(this: any, fn: (seed: S) => [T, S] | false
1585
1634
  */
1586
1635
  export declare function unquotedJsonStringify(value: any): string;
1587
1636
 
1588
- /**
1589
- * 简易unwrap参数数组。如果子节点是单个数组,则解构为子节点,否则返回原数组。
1590
- *
1591
- * @template T
1592
- * @param {(T|T[])[]} args - 子节点数组。
1593
- * @returns {T[]} - 解构后的子节点数组。
1594
- */
1595
- export declare function unwrapArgs<T>(args: (T | T[])[]): T[];
1596
-
1597
1637
  export declare function video(props: {
1598
1638
  [_: string]: any;
1599
1639
  }, ...childNodes: any[]): HyperscriptExtensions<HTMLVideoElement>;
@@ -90,7 +90,7 @@ __webpack_require__.r(__webpack_exports__);
90
90
  __webpack_require__.d(__webpack_exports__, {
91
91
  Comparer: () => (/* reexport */ Comparer),
92
92
  Deep: () => (/* reexport */ Deep),
93
- ObservableArray: () => (/* reexport */ ObservableArray),
93
+ ObservableArray: () => (/* reexport */ ObservableArray_ObservableArray),
94
94
  a: () => (/* reexport */ a),
95
95
  abbr: () => (/* reexport */ abbr),
96
96
  address: () => (/* reexport */ address),
@@ -123,8 +123,6 @@ __webpack_require__.d(__webpack_exports__, {
123
123
  compareKey: () => (/* reexport */ compareKey),
124
124
  compareKeyPath: () => (/* reexport */ compareKeyPath),
125
125
  compareNumber: () => (/* reexport */ compareNumber),
126
- compose: () => (/* reexport */ compose),
127
- cond: () => (/* reexport */ cond),
128
126
  data: () => (/* reexport */ data),
129
127
  datalist: () => (/* reexport */ datalist),
130
128
  dd: () => (/* reexport */ dd),
@@ -146,7 +144,6 @@ __webpack_require__.d(__webpack_exports__, {
146
144
  findLastIndex: () => (/* reexport */ findLastIndex),
147
145
  flat: () => (/* reexport */ flat),
148
146
  flip: () => (/* reexport */ flip),
149
- fold: () => (/* reexport */ fold),
150
147
  footer: () => (/* reexport */ footer),
151
148
  form: () => (/* reexport */ tags_form),
152
149
  fragment: () => (/* reexport */ fragment),
@@ -198,7 +195,6 @@ __webpack_require__.d(__webpack_exports__, {
198
195
  parseHyperscriptArgs: () => (/* reexport */ parseHyperscriptArgs),
199
196
  parsePropName: () => (/* reexport */ parsePropName),
200
197
  pickBehaviorSubject: () => (/* reexport */ pickBehaviorSubject),
201
- pipe: () => (/* reexport */ pipe),
202
198
  pipeEvent: () => (/* reexport */ pipeEvent),
203
199
  pluckProperty: () => (/* reexport */ pluckProperty),
204
200
  pre: () => (/* reexport */ pre),
@@ -249,9 +245,7 @@ __webpack_require__.d(__webpack_exports__, {
249
245
  types: () => (/* reexport */ types),
250
246
  u: () => (/* reexport */ u),
251
247
  ul: () => (/* reexport */ ul),
252
- unfold: () => (/* reexport */ unfold),
253
248
  unquotedJsonStringify: () => (/* reexport */ unquotedJsonStringify),
254
- unwrapArgs: () => (/* reexport */ unwrapArgs),
255
249
  video: () => (/* reexport */ video),
256
250
  wbr: () => (/* reexport */ wbr),
257
251
  zipArray: () => (/* reexport */ zipArray)
@@ -350,17 +344,6 @@ function rangeArray(length) {
350
344
  length
351
345
  }).map((v, i) => i);
352
346
  }
353
- ;// ./src/array/unwrapArgs.js
354
- /**
355
- * 简易unwrap参数数组。如果子节点是单个数组,则解构为子节点,否则返回原数组。
356
- *
357
- * @template T
358
- * @param {(T|T[])[]} args - 子节点数组。
359
- * @returns {T[]} - 解构后的子节点数组。
360
- */
361
- function unwrapArgs(args) {
362
- return /** @type{T[]} */args.length === 1 && Array.isArray(args[0]) ? args[0] : args;
363
- }
364
347
  ;// ./src/array/zipArray.js
365
348
  /**
366
349
  * 合并两个数组为一个元组数组。
@@ -391,7 +374,7 @@ function zipArray(a, b) {
391
374
 
392
375
 
393
376
 
394
-
377
+ // export * from './unwrapArgs.js'
395
378
 
396
379
  ;// ./src/comparers/distinctArray.js
397
380
  /**
@@ -1517,7 +1500,7 @@ function isRxType(obj) {
1517
1500
  * @template T
1518
1501
  * @extends Array<T>
1519
1502
  */
1520
- class ObservableArray extends Array {
1503
+ class ObservableArray_ObservableArray extends Array {
1521
1504
  /**
1522
1505
  * @constructor 创建一个 ObservableArray 实例。禁止传参。
1523
1506
  * @param {()=>T} newItem
@@ -1590,7 +1573,7 @@ class ObservableArray extends Array {
1590
1573
  ;// ./src/deep-rxjs/0.js
1591
1574
 
1592
1575
 
1593
- ;// ./src/hyperscript-rxjs/displays/blockLevelFamily.js
1576
+ ;// ./src/hyperscripts/displays/blockLevelFamily.js
1594
1577
  /**
1595
1578
  * 一个包含所有 HTML 块级元素标签名称的集合。
1596
1579
  *
@@ -1608,7 +1591,7 @@ class ObservableArray extends Array {
1608
1591
  * @constant {Set<string>} blockLevelFamily
1609
1592
  */
1610
1593
  const blockLevelFamily = new Set(['ADDRESS', 'ARTICLE', 'ASIDE', 'BLOCKQUOTE', 'DD', 'DETAILS', 'DIALOG', 'DIV', 'DL', 'DT', 'FIELDSET', 'FIGCAPTION', 'FIGURE', 'FOOTER', 'FORM', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'HEADER', 'HGROUP', 'HR', 'LI', 'MAIN', 'NAV', 'OL', 'P', 'PRE', 'SECTION', 'TABLE', 'UL']);
1611
- ;// ./src/hyperscript-rxjs/displays/inlineFamily.js
1594
+ ;// ./src/hyperscripts/displays/inlineFamily.js
1612
1595
  /**
1613
1596
  * 一个包含所有 HTML 内联元素标签名称的集合。
1614
1597
  *
@@ -1626,7 +1609,7 @@ const blockLevelFamily = new Set(['ADDRESS', 'ARTICLE', 'ASIDE', 'BLOCKQUOTE', '
1626
1609
  const inlineFamily = new Set(['A', 'ABBR', 'ACRONYM', 'AUDIO', 'B', 'BDI', 'BDO', 'BIG', 'BR', 'BUTTON', 'CANVAS', 'CITE', 'CODE', 'DATA', 'DATALIST', 'DEL', 'DFN', 'EM', 'EMBED', 'I', 'IFRAME', 'IMG', 'INPUT', 'INS', 'KBD', 'LABEL', 'MAP', 'MARK', 'METER', 'NOSCRIPT', 'OBJECT', 'OUTPUT', 'PICTURE', 'PROGRESS', 'Q', 'RUBY', 'S', 'SAMP', 'SCRIPT', 'SELECT', 'SLOT', 'SMALL', 'SPAN', 'STRONG', 'SUB', 'SUP', 'SVG', 'TEMPLATE', 'TEXTAREA', 'TIME', 'TT', 'U', 'VAR', 'VIDEO', 'WBR']);
1627
1610
 
1628
1611
  // developer.mozilla.org/en-US/docs/Web/HTML/Inline_elements
1629
- ;// ./src/hyperscript-rxjs/displays/getDisplay.js
1612
+ ;// ./src/hyperscripts/displays/getDisplay.js
1630
1613
 
1631
1614
 
1632
1615
 
@@ -1677,7 +1660,7 @@ function getDisplay(elem) {
1677
1660
  return 'unset';
1678
1661
  }
1679
1662
  }
1680
- ;// ./src/hyperscript-rxjs/displays/0.js
1663
+ ;// ./src/hyperscripts/displays/0.js
1681
1664
 
1682
1665
 
1683
1666
 
@@ -1691,18 +1674,19 @@ function getDisplay(elem) {
1691
1674
  * @throws {Error} If parameters are invalid.
1692
1675
  */
1693
1676
  const attachSubscriptionToNode = (elem, subscription) => {
1694
- if (!(elem instanceof Node)) {
1695
- throw new Error('Valid DOM node required');
1696
- }
1697
- if (!(subscription instanceof external_commonjs_rxjs_commonjs2_rxjs_amd_rxjs_root_rxjs_.Subscription)) {
1698
- throw new Error('Valid RxJS subscription required');
1699
- }
1677
+ // if (!(elem instanceof Node)) {
1678
+ // throw new Error('Valid DOM node required');
1679
+ // }
1680
+
1681
+ // if (!(subscription instanceof Subscription)) {
1682
+ // throw new Error('Valid RxJS subscription required');
1683
+ // }
1700
1684
 
1701
1685
  //新建或附加订阅
1702
- if (!elem.subscription) {
1703
- elem.subscription = subscription;
1704
- } else {
1686
+ if ('subscription' in elem && elem.subscription instanceof external_commonjs_rxjs_commonjs2_rxjs_amd_rxjs_root_rxjs_.Subscription) {
1705
1687
  elem.subscription.add(subscription);
1688
+ } else {
1689
+ elem.subscription = subscription;
1706
1690
  }
1707
1691
  };
1708
1692
  ;// ./src/nodes/pipeEvent.js
@@ -1718,16 +1702,15 @@ const attachSubscriptionToNode = (elem, subscription) => {
1718
1702
  * @throws {Error} 如果参数无效。
1719
1703
  */
1720
1704
  function pipeEvent(elem) {
1721
- // 参数检查,确保 elem 是一个有效的 DOM 元素
1722
- if (!(elem instanceof HTMLElement)) {
1723
- throw new Error('参数 "elem" 必须是一个有效的 DOM 元素。');
1724
- }
1705
+ // // 参数检查,确保 elem 是一个有效的 DOM 元素
1706
+ // if (!(elem instanceof HTMLElement)) {
1707
+ // throw new Error('参数 "elem" 必须是一个有效的 DOM 元素。');
1708
+ // }
1709
+
1725
1710
  return (
1726
1711
  /**
1727
- *
1728
1712
  * @param {string} event
1729
1713
  * @param {(event$: Observable<Event>) => Subscription} subscriber
1730
- * @returns
1731
1714
  */
1732
1715
  function (event, subscriber) {
1733
1716
  // 参数检查,确保 event 是字符串,subscriber 是函数
@@ -1873,8 +1856,6 @@ function isProps(value) {
1873
1856
  return proto === null || proto === Object.prototype;
1874
1857
  }
1875
1858
  ;// ./src/nodes/normalizeChildNodes.js
1876
-
1877
-
1878
1859
  /**
1879
1860
  * 规范化子节点,将非节点转换为文本节点。
1880
1861
  *
@@ -1882,9 +1863,7 @@ function isProps(value) {
1882
1863
  * @returns {Node[]} - 返回规范化后的节点数组。
1883
1864
  */
1884
1865
  function normalizeChildNodes(childNodes) {
1885
- const normalizedNodes = unwrapArgs(childNodes); // 解构子节点数组
1886
-
1887
- return normalizedNodes.map(child => child instanceof Node ? child : document.createTextNode(String(child)) // 将非节点转换为文本节点
1866
+ return childNodes.map(child => child instanceof Node ? child : document.createTextNode(String(child)) // 将非节点转换为文本节点
1888
1867
  );
1889
1868
  }
1890
1869
  ;// ./src/object/splitObjectByObservable.js
@@ -2130,7 +2109,7 @@ function setProps(element, props) {
2130
2109
  // 返回元素本身,支持链式调用
2131
2110
  return element;
2132
2111
  }
2133
- ;// ./src/hyperscript-rxjs/hyperscript.js
2112
+ ;// ./src/hyperscripts/hyperscript.js
2134
2113
 
2135
2114
 
2136
2115
 
@@ -2139,7 +2118,7 @@ function setProps(element, props) {
2139
2118
 
2140
2119
 
2141
2120
  /**
2142
- * @typedef {import("./HyperscriptExtensions.d.ts").HyperscriptExtensions<HTMLElement>} HyperscriptElement
2121
+ * @typedef {import("./HyperscriptExtensions.js").HyperscriptExtensions<HTMLElement>} HyperscriptElement
2143
2122
  */
2144
2123
 
2145
2124
  /**
@@ -2200,12 +2179,12 @@ function hyperscript(elemName, ...args) {
2200
2179
  return /** @type {HyperscriptElement} */element; // 返回创建的元素
2201
2180
  }
2202
2181
  const tagNames = new Set(["a", "abbr", "address", "area", "article", "aside", "audio", "b", "bdi", "bdo", "blockquote", "br", "button", "caption", "cite", "code", "col", "colgroup", "data", "datalist", "dd", "del", "details", "dfn", "dialog", "div", "dl", "dt", "em", "fieldset", "figcaption", "figure", "footer", "form", "h1", "h2", "h3", "h4", "h5", "h6", "header", "hgroup", "hr", "i", "img", "input", "ins", "kbd", "label", "legend", "li", "main", "mark", "menu", "menuitem", "meter", "nav", "ol", "optgroup", "option", "output", "p", "pre", "progress", "q", "rb", "rp", "rt", "rtc", "ruby", "s", "samp", "section", "select", "small", "span", "strong", "sub", "summary", "sup", "table", "tbody", "td", "textarea", "tfoot", "th", "thead", "time", "tr", "track", "tt", "u", "ul", "video", "wbr"]);
2203
- ;// ./src/hyperscript-rxjs/tags.js
2182
+ ;// ./src/hyperscripts/tags.js
2204
2183
 
2205
2184
 
2206
2185
  /**
2207
2186
  * @template {HTMLElement} T
2208
- * @typedef {import("./HyperscriptExtensions.d.ts").HyperscriptExtensions<T>} HyperscriptExtensions
2187
+ * @typedef {import("./HyperscriptExtensions.js").HyperscriptExtensions<T>} HyperscriptExtensions
2209
2188
  */
2210
2189
 
2211
2190
  /**
@@ -2951,7 +2930,7 @@ const video = (props, ...childNodes) => (/** @type {HyperscriptExtensions<HTMLVi
2951
2930
  * @returns {HyperscriptExtensions<HTMLElement>}
2952
2931
  */
2953
2932
  const wbr = (props, ...childNodes) => (/** @type {HyperscriptExtensions<HTMLElement>} */hyperscript('wbr', props, ...childNodes));
2954
- ;// ./src/hyperscript-rxjs/tabControls/tabRoot.js
2933
+ ;// ./src/hyperscripts/tabControls/tabRoot.js
2955
2934
 
2956
2935
 
2957
2936
  /**
@@ -2975,7 +2954,7 @@ function tabRoot(props) {
2975
2954
  className: 'tab-content'
2976
2955
  }));
2977
2956
  }
2978
- ;// ./src/hyperscript-rxjs/tabControls/tabNavItem.js
2957
+ ;// ./src/hyperscripts/tabControls/tabNavItem.js
2979
2958
 
2980
2959
 
2981
2960
  /**
@@ -3000,7 +2979,7 @@ function tabNavItem(...source) {
3000
2979
  className: 'btn btn-link nav-link'
3001
2980
  }, ...source));
3002
2981
  }
3003
- ;// ./src/hyperscript-rxjs/tabControls/tabPanel.js
2982
+ ;// ./src/hyperscripts/tabControls/tabPanel.js
3004
2983
 
3005
2984
 
3006
2985
  /**
@@ -3020,7 +2999,7 @@ function tabPanel(...source) {
3020
2999
  className: 'tab-pane'
3021
3000
  }, ...source);
3022
3001
  }
3023
- ;// ./src/hyperscript-rxjs/tabControls/bindTabIndex.js
3002
+ ;// ./src/hyperscripts/tabControls/bindTabIndex.js
3024
3003
 
3025
3004
 
3026
3005
 
@@ -3036,7 +3015,7 @@ function tabPanel(...source) {
3036
3015
  */
3037
3016
  function bindTabIndex(tabRoot, tabIndex$) {
3038
3017
  /**
3039
- * @typedef {import("../HyperscriptExtensions.d.ts").HyperscriptExtensions<HTMLElement>} HyperscriptElement
3018
+ * @typedef {import("../HyperscriptExtensions.js").HyperscriptExtensions<HTMLElement>} HyperscriptElement
3040
3019
  */
3041
3020
 
3042
3021
  const navs = /** @type {HyperscriptElement} */tabRoot.firstChild; // 导航栏容器
@@ -3069,7 +3048,7 @@ function bindTabIndex(tabRoot, tabIndex$) {
3069
3048
  navs.pipeEvent('click', click$ => click$.pipe((0,operators_root_rxjs_.map)(e => Array.from(navs.childNodes).map(e => (/** @type {HTMLElement} */e.firstChild)).indexOf(/** @type {HTMLElement} */e.target)), (0,operators_root_rxjs_.filter)(i => i > -1) // 过滤无效索引
3070
3049
  ).subscribe(tabIndex$));
3071
3050
  }
3072
- ;// ./src/hyperscript-rxjs/tabControls/tabControl.js
3051
+ ;// ./src/hyperscripts/tabControls/tabControl.js
3073
3052
 
3074
3053
 
3075
3054
 
@@ -3107,19 +3086,19 @@ function tabControl(props, tabs, panels) {
3107
3086
  bindTabIndex(root, tabIndex);
3108
3087
  return root;
3109
3088
  }
3110
- ;// ./src/hyperscript-rxjs/tabControls/0.js
3089
+ ;// ./src/hyperscripts/tabControls/0.js
3111
3090
 
3112
3091
 
3113
3092
 
3114
3093
 
3115
3094
 
3116
- ;// ./src/hyperscript-rxjs/checkbox.js
3095
+ ;// ./src/hyperscripts/checkbox.js
3117
3096
 
3118
3097
 
3119
3098
 
3120
3099
 
3121
3100
  /**
3122
- * @typedef {import("./HyperscriptExtensions.d.ts").HyperscriptExtensions<HTMLInputElement>} HyperscriptInputElement
3101
+ * @typedef {import("./HyperscriptExtensions.js").HyperscriptExtensions<HTMLInputElement>} HyperscriptInputElement
3123
3102
  */
3124
3103
 
3125
3104
  /**
@@ -3144,9 +3123,7 @@ function checkbox_checkbox(props) {
3144
3123
  // 监听复选框的 input 事件,并将选中状态推送到 Observable/Subject
3145
3124
  let subscriber =
3146
3125
  /**
3147
- *
3148
3126
  * @param {Observable<Event>} input$
3149
- * @returns
3150
3127
  */
3151
3128
  input$ => input$.pipe((0,operators_root_rxjs_.map)(e => /** @type {HTMLInputElement} */e.target.checked) // 提取复选框的选中状态
3152
3129
  ).subscribe(props.checked); // 推送选中状态到 Observable/Subject
@@ -3157,8 +3134,7 @@ function checkbox_checkbox(props) {
3157
3134
  }
3158
3135
  return elem; // 返回复选框元素
3159
3136
  }
3160
- ;// ./src/hyperscript-rxjs/collapse.js
3161
-
3137
+ ;// ./src/hyperscripts/collapse.js
3162
3138
 
3163
3139
 
3164
3140
 
@@ -3168,16 +3144,14 @@ function checkbox_checkbox(props) {
3168
3144
  * `collapse` 函数通过绑定 `hidden` 属性,实现一组 HTML 元素的动态显示或隐藏。
3169
3145
  *
3170
3146
  * @param {Observable<boolean>} hidden$ - 一个可观察对象(如 BehaviorSubject),用于控制元素的 `hidden` 属性。
3171
- * @param {...HTMLElement|HTMLElement[]} elements - 一个或多个 HTML 元素,或者包含 HTML 元素的数组。
3147
+ * @param {...HTMLElement} elements - 一个或多个 HTML 元素,或者包含 HTML 元素的数组。
3172
3148
  * @returns {HTMLElement[]} - 处理后的元素数组。
3173
3149
  *
3174
3150
  * @throws {Error} 如果 `elements` 中包含非元素节点(如 TextNode)。
3175
3151
  *
3176
3152
  */
3177
3153
  function collapse(hidden$, ...elements) {
3178
- // 支持子元素包含在数组中:collapse([a, b, c]) 或 collapse(a, b, c)
3179
- let elems = unwrapArgs(elements);
3180
- elems.forEach(elem => {
3154
+ elements.forEach(elem => {
3181
3155
  if (!(elem instanceof HTMLElement)) {
3182
3156
  throw new Error('`collapse` only supports HTMLElement nodes.');
3183
3157
  }
@@ -3185,9 +3159,9 @@ function collapse(hidden$, ...elements) {
3185
3159
  // 绑定 hidden 属性到可观察对象
3186
3160
  subscribeProp(elem, 'hidden', hidden$);
3187
3161
  });
3188
- return elems;
3162
+ return elements;
3189
3163
  }
3190
- ;// ./src/hyperscript-rxjs/choice.js
3164
+ ;// ./src/hyperscripts/choice.js
3191
3165
 
3192
3166
 
3193
3167
 
@@ -3202,12 +3176,13 @@ function choice(chosen$, possibilities) {
3202
3176
  const elems = Object.entries(possibilities).map(([key, possibility]) => {
3203
3177
  const hidden$ = chosen$.pipe((0,operators_root_rxjs_.map)(selectedKey => selectedKey !== key) // 如果当前选中的键不是当前可能性,则隐藏
3204
3178
  );
3205
- return collapse(hidden$, possibility); // 绑定 hidden 属性
3179
+ const arr = Array.isArray(possibility) ? possibility : [possibility];
3180
+ return collapse(hidden$, ...arr); // 绑定 hidden 属性
3206
3181
  }).reduce((acc, cur) => [...acc, ...cur], []); // 扁平化数组
3207
3182
 
3208
3183
  return elems;
3209
3184
  }
3210
- ;// ./src/hyperscript-rxjs/flip.js
3185
+ ;// ./src/hyperscripts/flip.js
3211
3186
 
3212
3187
 
3213
3188
 
@@ -3230,15 +3205,15 @@ function flip(yinHidden$, yin, yang) {
3230
3205
  const yangHidden$ = yinHidden$.pipe((0,operators_root_rxjs_.map)(isHidden => !isHidden));
3231
3206
 
3232
3207
  // 阴阳交叉
3233
- return [...collapse(yangHidden$, yin), ...collapse(yinHidden$, yang)];
3208
+ return [...collapse(yangHidden$, ...(Array.isArray(yin) ? yin : [yin])), ...collapse(yinHidden$, ...(Array.isArray(yang) ? yang : [yang]))];
3234
3209
  }
3235
- ;// ./src/hyperscript-rxjs/fragment.js
3210
+ ;// ./src/hyperscripts/fragment.js
3236
3211
 
3237
3212
 
3238
3213
  /**
3239
3214
  * 用途:插入一组元素,不必使用循环语句,fragment 用后即弃。
3240
3215
  *
3241
- * @param {...Node|Node[]} childNodes - 要插入的子节点,可以是单个节点、多个节点或节点数组。
3216
+ * @param {...Node} childNodes - 要插入的子节点,可以是单个节点、多个节点或节点数组。
3242
3217
  * @returns {DocumentFragment} - 返回包含所有子节点的 DocumentFragment。
3243
3218
  * @throws {Error} 如果传入的子节点不是有效的 DOM 节点。
3244
3219
  */
@@ -3254,18 +3229,18 @@ function fragment(...childNodes) {
3254
3229
  // 返回 DocumentFragment
3255
3230
  return frag;
3256
3231
  }
3257
- ;// ./src/hyperscript-rxjs/multiselect.js
3232
+ ;// ./src/hyperscripts/multiselect.js
3258
3233
 
3259
3234
 
3260
3235
  /**
3261
- * @typedef {import("./HyperscriptExtensions.d.ts").HyperscriptExtensions<HTMLSelectElement>} HyperscriptSelectElement
3236
+ * @typedef {import("./HyperscriptExtensions.js").HyperscriptExtensions<HTMLSelectElement>} HyperscriptSelectElement
3262
3237
  */
3263
3238
 
3264
3239
  /**
3265
3240
  * 创建一个支持多选功能的 <select> 元素,并绑定选项的选中状态。必须手动添加控件更新BehaviorSubject的事件。
3266
3241
  *
3267
3242
  * @param {{oninput?: (e:Event)=>void, onchange?: (e:Event)=>void, [key: string]: any}} props - 配置对象,包含 <select> 元素的属性。
3268
- * @param {...HTMLOptionElement[]} options - 一个或多个 <option> 元素,必须是 HTMLOptionElement 类型。
3243
+ * @param {...HTMLOptionElement} options - 一个或多个 <option> 元素,必须是 HTMLOptionElement 类型。
3269
3244
  * 每个选项需要包含一个 `selected` 属性,该属性是一个 BehaviorSubject ,用于绑定选中状态。
3270
3245
  * @returns {HyperscriptSelectElement} - 创建的 <select> 元素。
3271
3246
  * @throws {Error} 如果 `props` 不是对象,或者 `options` 中的选项未正确定义 `selected` 属性。
@@ -3296,7 +3271,7 @@ function multiselect(props, ...options) {
3296
3271
  }
3297
3272
  return /** @type {HyperscriptSelectElement} */elem;
3298
3273
  }
3299
- ;// ./src/hyperscript-rxjs/numberbox.js
3274
+ ;// ./src/hyperscripts/numberbox.js
3300
3275
 
3301
3276
 
3302
3277
 
@@ -3364,7 +3339,7 @@ function numberbox(props) {
3364
3339
  elem.style.textAlign = 'right';
3365
3340
  return elem;
3366
3341
  }
3367
- ;// ./src/hyperscript-rxjs/radio.js
3342
+ ;// ./src/hyperscripts/radio.js
3368
3343
 
3369
3344
 
3370
3345
 
@@ -3374,7 +3349,7 @@ function numberbox(props) {
3374
3349
 
3375
3350
  /**
3376
3351
  * @internal
3377
- * @typedef {import("./HyperscriptExtensions.d.ts").HyperscriptInputElement} HyperscriptInputElement
3352
+ * @typedef {import("./HyperscriptExtensions.js").HyperscriptInputElement} HyperscriptInputElement
3378
3353
  */
3379
3354
 
3380
3355
  /**
@@ -3412,7 +3387,7 @@ function radio_radio(props) {
3412
3387
  }
3413
3388
  return elem;
3414
3389
  }
3415
- ;// ./src/hyperscript-rxjs/select.js
3390
+ ;// ./src/hyperscripts/select.js
3416
3391
 
3417
3392
 
3418
3393
 
@@ -3421,14 +3396,14 @@ function radio_radio(props) {
3421
3396
  // import { attachSubscriptionToNode } from '../nodes/attachSubscriptionToNode';
3422
3397
 
3423
3398
  /**
3424
- * @typedef {import("./HyperscriptExtensions.d.ts").HyperscriptSelectElement} HyperscriptSelectElement
3399
+ * @typedef {import("./HyperscriptExtensions.js").HyperscriptSelectElement} HyperscriptSelectElement
3425
3400
  */
3426
3401
 
3427
3402
  /**
3428
3403
  * 创建一个支持 RxJS 数据绑定的 <select> 元素。仅单选选择框。
3429
3404
  *
3430
3405
  * @param {{ selectedIndex?: BehaviorSubject<number>, value?: BehaviorSubject<string>, [key: string]: any }} props - 配置对象,包含 <select> 元素的属性。
3431
- * @param {...HTMLOptionElement[]} options - 一个或多个 <option> 元素,必须是 HTMLOptionElement 类型。
3406
+ * @param {...HTMLOptionElement} options - 一个或多个 <option> 元素,必须是 HTMLOptionElement 类型。
3432
3407
  * @returns {HyperscriptSelectElement} - 创建的 <select> 元素。
3433
3408
  * @throws {Error} 如果 `props` 不是对象,或者 `selectedIndex` 或 `value` 不是 BehaviorSubject。
3434
3409
  */
@@ -3488,14 +3463,14 @@ function select_select(props, ...options) {
3488
3463
  }
3489
3464
  return elem;
3490
3465
  }
3491
- ;// ./src/hyperscript-rxjs/textarea.js
3466
+ ;// ./src/hyperscripts/textarea.js
3492
3467
 
3493
3468
 
3494
3469
 
3495
3470
 
3496
3471
  /**
3497
3472
  * @internal
3498
- * @typedef {import("./HyperscriptExtensions.d.ts").HyperscriptExtensions<HTMLTextAreaElement>} HyperscriptTextAreaElement
3473
+ * @typedef {import("./HyperscriptExtensions.js").HyperscriptExtensions<HTMLTextAreaElement>} HyperscriptTextAreaElement
3499
3474
  */
3500
3475
 
3501
3476
  /**
@@ -3530,14 +3505,14 @@ function textarea_textarea(props) {
3530
3505
  elem.pipeEvent('input', subscriber);
3531
3506
  return elem;
3532
3507
  }
3533
- ;// ./src/hyperscript-rxjs/textbox.js
3508
+ ;// ./src/hyperscripts/textbox.js
3534
3509
 
3535
3510
 
3536
3511
 
3537
3512
 
3538
3513
  /**
3539
3514
  * @internal
3540
- * @typedef {import("./HyperscriptExtensions.d.ts").HyperscriptInputElement} HyperscriptInputElement
3515
+ * @typedef {import("./HyperscriptExtensions.js").HyperscriptInputElement} HyperscriptInputElement
3541
3516
  */
3542
3517
 
3543
3518
  /**
@@ -3574,7 +3549,7 @@ function textbox(props) {
3574
3549
  elem.pipeEvent('input', subscriber);
3575
3550
  return elem;
3576
3551
  }
3577
- ;// ./src/hyperscript-rxjs/textNode.js
3552
+ ;// ./src/hyperscripts/textNode.js
3578
3553
 
3579
3554
 
3580
3555
 
@@ -3589,8 +3564,8 @@ function textbox(props) {
3589
3564
  * - 如果传入的是字符串,则创建一个静态文本节点。
3590
3565
  * - 如果传入的是 RxJS Observable,则创建一个动态文本节点,并根据 Observable 的值实时更新文本内容。
3591
3566
  * - 动态文本节点支持通过 `unsubscribe` 方法取消订阅。
3592
- *
3593
- * @param {any} text Observable<any> | any 任何类型数据都会被转换成string
3567
+ * @template T
3568
+ * @param {Observable<T>|T} text 任何类型数据都会被转换成string
3594
3569
  * @returns {ObservableTextNode}
3595
3570
  *
3596
3571
  */
@@ -3625,7 +3600,7 @@ function textNode(text) {
3625
3600
  return document.createTextNode(String(text)); // 转换为字符串
3626
3601
  }
3627
3602
  }
3628
- ;// ./src/hyperscript-rxjs/0.js
3603
+ ;// ./src/hyperscripts/0.js
3629
3604
 
3630
3605
 
3631
3606
 
@@ -3652,19 +3627,32 @@ function textNode(text) {
3652
3627
  /**
3653
3628
  * Creates an object composed of the picked object properties.
3654
3629
  * @param {Record<string,any>} obj - Source object
3655
- * @param {string[]} keys - Array of property keys to pick
3630
+ * @param {Iterable<string>} keys - Iterable of property keys to pick
3656
3631
  * @returns {Record<string,any>} New object with picked properties
3657
3632
  * @throws {TypeError} If obj is not an object or keys is not an array
3658
3633
  */
3659
3634
  function intersectObject(obj, keys) {
3660
- // 类型检查
3661
3635
  if (typeof obj !== 'object' || obj === null) {
3662
3636
  throw new TypeError('First argument must be an object');
3663
3637
  }
3664
- if (!Array.isArray(keys)) {
3665
- throw new TypeError('Second argument must be an array');
3638
+ if (typeof keys?.[Symbol.iterator] !== 'function') {
3639
+ throw new TypeError('Second argument must be iterable');
3640
+ }
3641
+ return Object.fromEntries(generator(obj, keys));
3642
+ }
3643
+
3644
+ /**
3645
+ * @param {Record<string,any>} obj
3646
+ * @param {Iterable<string>} keys
3647
+ */
3648
+ function* generator(obj, keys) {
3649
+ for (const key of keys) {
3650
+ if (key in obj) {
3651
+ yield [key, obj[key]];
3652
+ } else {
3653
+ throw new Error(`key不在obj中: ${key}`);
3654
+ }
3666
3655
  }
3667
- return Object.fromEntries(keys.filter(key => key in obj).map(key => [key, obj[key]]));
3668
3656
  }
3669
3657
  ;// ./src/object/isPlainObject.js
3670
3658
  /**
@@ -3729,78 +3717,210 @@ function nestedMerge(model) {
3729
3717
 
3730
3718
 
3731
3719
 
3720
+
3721
+ /**
3722
+ * @typedef {import('./pickBehaviorSubject.js').NestedStringArray} NestedStringArray
3723
+ */
3724
+
3725
+ /**
3726
+ * @template T
3727
+ * @typedef {import('./pickBehaviorSubject.js').NestedObject<T>} NestedObject<T>
3728
+ */
3729
+
3732
3730
  /**
3733
3731
  *
3734
- * 拾取对象中的BehaviorSubject值,作爲葉子節點,忽略其他值。
3735
- * @public
3736
- * @param {Record<string|number,any> & { pickeys?: () => string [] }} model - 输入的数据结构,可以是对象、数组或BehaviorSubject
3737
- * @returns {Record<string|number,any>} - 返回只包含BehaviorSubject当前值的结构
3738
- * @throws {Error} 当输入不包含任何BehaviorSubject或结构不符合预期时抛出错误
3732
+ * @param {NestedStringArray[]} paths
3739
3733
  */
3740
- function pickBehaviorSubject(model) {
3741
- let x = loop(model, '', null);
3742
- if (x.length === 1) {
3743
- return x[0][1];
3734
+ const getMap = paths => new Map(paths.map(path => {
3735
+ if (typeof path === 'string') {
3736
+ return [path, []];
3744
3737
  } else {
3745
- throw new Error('pickBehaviorSubject');
3738
+ let [h, ...rest] = path;
3739
+ return [(/** @type {string} */h), rest];
3746
3740
  }
3747
- }
3741
+ }));
3748
3742
 
3749
3743
  /**
3750
- *
3751
- * 递归遍历数据结构收集BehaviorSubject值
3752
- *
3753
- * @param {any} value - 当前遍历的值
3754
- * @param {string|number} key - 当前键名
3755
- * @param {object|null} parent - 父级对象
3756
- * @returns {[string|number, any][]} - 返回收集到的键值对数组,每个元素是一个[key, value]元组
3757
- * @throws {Error} 当遇到不符合要求的数据结构时抛出错误
3758
- */
3759
- function loop(value, key, parent) {
3760
- if ((0,external_commonjs_rxjs_commonjs2_rxjs_amd_rxjs_root_rxjs_.isObservable)(value) && value instanceof external_commonjs_rxjs_commonjs2_rxjs_amd_rxjs_root_rxjs_.BehaviorSubject) {
3761
- return [[key, value.value]]; //保存葉節點
3762
- } else if (value === null || typeof value !== 'object' || isRxType(value)) {
3744
+ * @param {{pickeys?:()=>NestedStringArray[]}} source
3745
+ * @param {NestedStringArray[]} paths
3746
+ */
3747
+ const mergeKeys = (source, paths) => {
3748
+ if (paths && paths.length > 0) {
3749
+ return paths;
3750
+ } else if ('pickeys' in source && typeof source.pickeys === 'function') {
3751
+ return source.pickeys();
3752
+ } else {
3763
3753
  return [];
3764
- } else if (value instanceof ObservableArray) {
3765
- let v = [...value].map((e, i) => {
3766
- let pelem = loop(e, i, value);
3767
- if (pelem.length === 1) {
3768
- return pelem[0][1]; //表示元素是正常叶节点
3754
+ }
3755
+ };
3756
+
3757
+ /**
3758
+ * 数组中所有元素应该类型相同,符合同一套逻辑
3759
+ * @template T
3760
+ * @param {NestedObject<T>[]} arr
3761
+ * @param {NestedStringArray[]} paths
3762
+ * @returns {NestedObject<T>[] }}
3763
+ */
3764
+ const getArray = (arr, paths) => [...function* () {
3765
+ for (const elem of arr) {
3766
+ if (isRxType(elem)) {
3767
+ if (elem instanceof external_commonjs_rxjs_commonjs2_rxjs_amd_rxjs_root_rxjs_.BehaviorSubject) {
3768
+ yield elem.value;
3769
3769
  } else {
3770
- throw new Error('dense Array'); //非正常叶节点,有洞
3770
+ // ignore observable, subscription ...
3771
+ }
3772
+ } else if (Array.isArray(elem) || elem instanceof ObservableArray_ObservableArray) {
3773
+ if (elem.length === 0) {} else {
3774
+ yield getArray(elem, paths);
3775
+ }
3776
+ } else if (isPlainObject(elem)) {
3777
+ if (isEmptyObject(elem)) {} else {
3778
+ yield getObject(elem, paths);
3771
3779
  }
3772
- });
3773
- return [[key, v]];
3774
- } else if (value instanceof Array) {
3775
- if (value.length === 0) {
3776
- return []; //空不可变数组,将丢弃。
3777
3780
  } else {
3778
- let v = value.map((e, i) => {
3779
- let pelem = loop(e, i, value);
3780
- if (pelem.length === 1) {
3781
- return pelem[0][1];
3781
+ // ignore other number, string, null, boolean, function ...
3782
+ }
3783
+ }
3784
+ }()];
3785
+
3786
+ /**
3787
+ * @template T
3788
+ * @param {{[_:string]:NestedObject<T>}} obj
3789
+ * @param {NestedStringArray[]} paths
3790
+ * @returns {{ [_: string]: NestedObject<T> }}
3791
+ */
3792
+ const getObject = (obj, paths) => Object.fromEntries(function* () {
3793
+ let mergedPaths = mergeKeys(obj, paths);
3794
+ if (mergedPaths.length === 0) {
3795
+ for (const [key, value] of Object.entries(obj)) {
3796
+ if (isRxType(value)) {
3797
+ if (value instanceof external_commonjs_rxjs_commonjs2_rxjs_amd_rxjs_root_rxjs_.BehaviorSubject) {
3798
+ console.log('isRxType(value) && value instanceof BehaviorSubject');
3799
+ yield [key, value.value];
3782
3800
  } else {
3783
- throw new Error('dense Array');
3801
+ // ignore observable, subscription ...
3802
+ console.log('isRxType(value) && else');
3784
3803
  }
3785
- });
3786
- return [[key, v]];
3804
+ } else if (Array.isArray(value) || value instanceof ObservableArray_ObservableArray) {
3805
+ if (value.length === 0) {} else {
3806
+ yield [key, getArray(value, [])];
3807
+ }
3808
+ } else if (isPlainObject(value)) {
3809
+ if (isEmptyObject(value)) {
3810
+ console.log('isPlainObject isEmptyObject');
3811
+ } else {
3812
+ console.log('isPlainObject');
3813
+ yield [key, getObject(value, [])];
3814
+ }
3815
+ } else {
3816
+ // ignore other number, string, null, boolean, function ...
3817
+ console.log('ignore other:' + `${key}:${value}`);
3818
+ }
3787
3819
  }
3788
- } else if ('pickeys' in value) {
3789
- return loop(intersectObject(value, value.pickeys()), key, parent);
3790
3820
  } else {
3791
- let entries = Object.entries(value);
3792
- if (entries.length === 0) {
3793
- return [];
3794
- } else {
3795
- let ee = entries.map(([k, v]) => loop(v, k, parent)).reduce((acc, val) => [...acc, ...val], []);
3796
- if (ee.length === 0) {
3797
- return [];
3798
- } else {
3799
- return [[key, Object.fromEntries(ee)]];
3821
+ let mp = getMap(mergedPaths);
3822
+ for (const key of mp.keys()) {
3823
+ if (key in obj) {
3824
+ const value = obj[key];
3825
+ const newPaths = mp.get(key) ?? [];
3826
+ if (isRxType(value)) {
3827
+ if (value instanceof external_commonjs_rxjs_commonjs2_rxjs_amd_rxjs_root_rxjs_.BehaviorSubject) {
3828
+ console.log('isRxType(value) && value instanceof BehaviorSubject');
3829
+ yield [key, value.value];
3830
+ } else {
3831
+ // ignore observable, subscription ...
3832
+ console.log('isRxType(value) && else');
3833
+ }
3834
+ } else if (Array.isArray(value) || value instanceof ObservableArray_ObservableArray) {
3835
+ if (value.length === 0) {} else {
3836
+ yield [key, getArray(value, newPaths)];
3837
+ }
3838
+ } else if (isPlainObject(value)) {
3839
+ if (isEmptyObject(value)) {
3840
+ console.log('isPlainObject isEmptyObject');
3841
+ } else {
3842
+ console.log('isPlainObject');
3843
+ yield [key, getObject(value, newPaths)];
3844
+ }
3845
+ } else {
3846
+ // ignore other number, string, null, boolean, function ...
3847
+ console.log('ignore other:' + `${key}:${value}`);
3848
+ }
3800
3849
  }
3801
3850
  }
3802
3851
  }
3803
- }
3852
+ }());
3853
+
3854
+ /**
3855
+ *
3856
+ * 拾取对象中的BehaviorSubject值,作爲葉子節點,忽略其他值。
3857
+ * @public
3858
+ * @template T
3859
+ * @param {{[_:string]:NestedObject<T>} & { pickeys?: () => NestedStringArray[] }} source - 输入的数据结构,可以是对象、数组或BehaviorSubject
3860
+ * @param {NestedStringArray[]} [paths]
3861
+ * @returns {{[_:string]:NestedObject<T>}}
3862
+ * @throws {Error} 当输入不包含任何BehaviorSubject或结构不符合预期时抛出错误
3863
+ */
3864
+ const pickBehaviorSubject = (source, paths = []) => {
3865
+ if (isRxType(source)) {
3866
+ throw new Error("请将内容包装在普通对象中");
3867
+ } else if (Array.isArray(source) || source instanceof ObservableArray_ObservableArray) {
3868
+ throw new Error("请将内容包装在普通对象中");
3869
+ } else if (isPlainObject(source)) {
3870
+ if (isEmptyObject(source)) {
3871
+ throw new Error("N没有内容需要pick");
3872
+ } else {
3873
+ return getObject(source, paths);
3874
+ }
3875
+ } else {
3876
+ throw new Error("没有内容需要pick");
3877
+ }
3878
+ };
3879
+
3880
+ /**
3881
+ * 提取值判断的分类
3882
+ * @param {*} value
3883
+ * @returns
3884
+ */
3885
+ const testit = value => {
3886
+ if (typeof value === 'undefined' || value === null) {
3887
+ return {
3888
+ kind: "null"
3889
+ };
3890
+ } else if (isObservable(value)) {
3891
+ if (value instanceof BehaviorSubject) {
3892
+ return {
3893
+ kind: "BehaviorSubject"
3894
+ };
3895
+ } else {
3896
+ return {
3897
+ kind: "Observable"
3898
+ };
3899
+ }
3900
+ } else if (value instanceof ObservableArray) {
3901
+ return {
3902
+ kind: "ObservableArray"
3903
+ };
3904
+ } else if (Array.isArray(value)) {
3905
+ return {
3906
+ kind: "Array"
3907
+ };
3908
+ } else if (typeof value === 'object') {
3909
+ if (Object.keys(value).length === 0) {
3910
+ return {
3911
+ kind: "EmptyObject"
3912
+ };
3913
+ } else {
3914
+ return {
3915
+ kind: "PlainObject"
3916
+ };
3917
+ }
3918
+ } else {
3919
+ return {
3920
+ kind: "else"
3921
+ };
3922
+ }
3923
+ };
3804
3924
  ;// ./src/object/restore.js
3805
3925
 
3806
3926
 
@@ -3815,7 +3935,7 @@ function loop(value, key, parent) {
3815
3935
  * @returns
3816
3936
  */
3817
3937
  function restore(model, src) {
3818
- restore_loop(model, src);
3938
+ loop(model, src);
3819
3939
  // return model
3820
3940
  }
3821
3941
 
@@ -3824,13 +3944,13 @@ function restore(model, src) {
3824
3944
  * @param {any & {appendChild?: (c:any) => void }} o - Current model node to update
3825
3945
  * @param {any} src - Corresponding source value
3826
3946
  */
3827
- function restore_loop(o, src) {
3947
+ function loop(o, src) {
3828
3948
  if (o instanceof external_commonjs_rxjs_commonjs2_rxjs_amd_rxjs_root_rxjs_.BehaviorSubject) {
3829
3949
  // Input value
3830
3950
  o.next(src);
3831
3951
  } else if (o === null || typeof o !== 'object' || isRxType(o)) {
3832
3952
  // noop
3833
- } else if (o instanceof ObservableArray) {
3953
+ } else if (o instanceof ObservableArray_ObservableArray) {
3834
3954
  let len = o.length;
3835
3955
  let diffcount = len - src.length;
3836
3956
  if (diffcount > 0) {
@@ -3852,7 +3972,7 @@ function restore_loop(o, src) {
3852
3972
 
3853
3973
  // After alignment, update each element's value
3854
3974
  for (let i of o.keys()) {
3855
- restore_loop(o[i], src[i]);
3975
+ loop(o[i], src[i]);
3856
3976
  }
3857
3977
  } else if (o instanceof Array) {
3858
3978
  // Regular array, tuple
@@ -3860,13 +3980,13 @@ function restore_loop(o, src) {
3860
3980
  // Ignore extra src elements, noop for missing elements
3861
3981
  for (let i of indexes.keys()) {
3862
3982
  // todo: Throw error when o[i] is not settable?
3863
- restore_loop(o[i], src[i]);
3983
+ loop(o[i], src[i]);
3864
3984
  }
3865
3985
  } else if (typeof o === 'object') {
3866
3986
  // Recursively process object properties
3867
3987
  Object.entries(o).filter(([k, v]) => k in src) // Intersection
3868
3988
  .forEach(([k, v]) => {
3869
- restore_loop(v, src[k]);
3989
+ loop(v, src[k]);
3870
3990
  });
3871
3991
  }
3872
3992
  }
@@ -3886,132 +4006,6 @@ function restore_loop(o, src) {
3886
4006
 
3887
4007
 
3888
4008
 
3889
- ;// ./src/ramda/compose.js
3890
- /**
3891
- * 函数优先的管道组合工具(从右向左执行)
3892
- * @public
3893
- * @param {...((arg: any) => any)} fns - 要组合的函数列表
3894
- * @returns {(arg: any) => any} 组合后的函数(无参数时返回恒等函数 x => x)
3895
- * @throws {TypeError} 当参数包含非函数时抛出错误
3896
- */
3897
- const compose = (...fns) => {
3898
- if (!fns || fns.length === 0) {
3899
- /** @param {*} x */
3900
- return x => x;
3901
- }
3902
- const firstNonFunctionIndex = fns.findIndex(fn => typeof fn !== 'function');
3903
- if (firstNonFunctionIndex !== -1) {
3904
- const invalidFn = fns[firstNonFunctionIndex];
3905
- const errorType = invalidFn === null ? 'null' : invalidFn === undefined ? 'undefined' : typeof invalidFn;
3906
- throw new TypeError(`所有参数必须是函数,但第 ${firstNonFunctionIndex} 个参数是: ${errorType}`);
3907
- }
3908
- if (fns.length === 1) {
3909
- return fns[0];
3910
- }
3911
-
3912
- // 标注 args 类型
3913
- return fns.reduce((acc, fn) => /** @returns {*} */
3914
- (...args) => acc(fn(...args)));
3915
- };
3916
- ;// ./src/ramda/cond.js
3917
- /**
3918
- * 条件分支函数,依次判断分支并返回第一个匹配的结果。
3919
- *
3920
- * @public
3921
- * @param {Array<Function|[Function, Function]>} branches - 分支数组,每个分支可以是函数或 [谓词函数, 动作函数] 形式
3922
- * @returns {function(...*): *} 组合后的条件函数
3923
- */
3924
- const cond = function cond(branches) {
3925
- /**
3926
- * @this any
3927
- */
3928
- return function () {
3929
- for (const branch of branches) {
3930
- if (typeof branch === 'function') {
3931
- let tryAction = branch.apply(this, arguments);
3932
- if (tryAction) {
3933
- return tryAction;
3934
- }
3935
- } else if (Array.isArray(branch)) {
3936
- let predicate = branch[0].apply(this, arguments);
3937
- if (predicate) {
3938
- let args = Array.from(arguments);
3939
- args[args.length] = predicate;
3940
- return branch[1].apply(this, args);
3941
- }
3942
- }
3943
- }
3944
- };
3945
- };
3946
- ;// ./src/ramda/fold.js
3947
- /**
3948
- * 通用折叠(递归归约)函数。
3949
- *
3950
- * @public
3951
- * @param {(this:any, acc: any, seed: any) => [*, *]|[any]|[]|null|undefined} fn - 处理函数,返回 [新acc, 新seed] 或 [新acc]
3952
- * @param {*} acc - 初始累加值
3953
- * @param {*} seed - 初始种子
3954
- * @returns {*} 折叠后的结果
3955
- * @this *
3956
- */
3957
- function fold(fn, acc, seed) {
3958
- while (seed != null) {
3959
- let pair = fn.call(this, acc, seed);
3960
- if (pair == null || pair.length === 0) break;
3961
- acc = pair[0];
3962
- if (pair.length === 1) break;
3963
- seed = pair[1];
3964
- }
3965
- return acc;
3966
- }
3967
- ;// ./src/ramda/pipe.js
3968
- /**
3969
- * 数据优先的管道处理工具(从左向右执行)
3970
- * 适合一次性数据处理流程
3971
- * @public
3972
- * @param {any} initialValue - 初始值
3973
- * @param {...((arg: any) => any)} fns - 要应用的函数管道(从左向右执行)
3974
- * @throws {TypeError} 当参数包含非函数时抛出错误
3975
- */
3976
- const pipe = (initialValue, ...fns) => {
3977
- // 无函数时直接返回初始值
3978
- if (fns.length === 0) return initialValue;
3979
-
3980
- // 类型检查(遇到第一个错误就抛出)
3981
- const firstNonFunctionIndex = fns.findIndex(fn => typeof fn !== 'function');
3982
- if (firstNonFunctionIndex !== -1) {
3983
- const invalidFn = fns[firstNonFunctionIndex];
3984
- const errorType = invalidFn === null ? 'null' : invalidFn === undefined ? 'undefined' : typeof invalidFn;
3985
- throw new TypeError(`所有管道函数必须是函数,但第 ${firstNonFunctionIndex} 个参数是: ${errorType}`);
3986
- }
3987
- return fns.reduce((acc, fn) => fn(acc), initialValue);
3988
- };
3989
- ;// ./src/ramda/unfold.js
3990
- /**
3991
- * 通过不断调用 fn 生成值,直到 fn 返回 falsy。
3992
- *
3993
- * @public
3994
- * @template T, S
3995
- * @param {(seed: S) => [T, S] | false | null | undefined} fn - 生成函数,接收当前 seed,返回 [value, nextSeed] 或 falsy。
3996
- * @param {S} seed - 初始种子值。
3997
- * @returns {Array<T>} 由 fn 生成的所有 value 组成的数组。
3998
- * @this *
3999
- */
4000
- function unfold(fn, seed) {
4001
- let result = [];
4002
- let resultSeedPair = fn.call(this, seed);
4003
- while (resultSeedPair && resultSeedPair.length) {
4004
- result[result.length] = resultSeedPair[0];
4005
- resultSeedPair = fn.call(this, resultSeedPair[1]);
4006
- }
4007
- return result;
4008
- }
4009
- ;// ./src/ramda/0.js
4010
-
4011
-
4012
-
4013
-
4014
-
4015
4009
  ;// ./src/structures/erectObject.js
4016
4010
 
4017
4011
 
@@ -4157,6 +4151,8 @@ const queryStringify_escape = str => str.replace(/[\x00-\x20#%&+=\x7F]/g, c => m
4157
4151
 
4158
4152
 
4159
4153
 
4154
+ // export * from "./ramda/0.js"
4155
+
4160
4156
 
4161
4157
 
4162
4158
  /******/ return __webpack_exports__;
package/package.json CHANGED
@@ -6,14 +6,14 @@
6
6
  "rxjs": "7.8.2"
7
7
  },
8
8
  "devDependencies": {
9
- "@babel/core": "7.27.4",
10
- "@babel/preset-env": "7.27.2",
9
+ "@babel/core": "7.28.0",
10
+ "@babel/preset-env": "7.28.0",
11
11
  "@types/jest": "30.0.0",
12
12
  "@microsoft/api-extractor": "7.52.8",
13
- "babel-jest": "30.0.2",
13
+ "babel-jest": "30.0.4",
14
14
  "cross-env": "7.0.3",
15
- "jest": "30.0.3",
16
- "jest-environment-jsdom": "30.0.2",
15
+ "jest": "30.0.4",
16
+ "jest-environment-jsdom": "30.0.4",
17
17
  "jsdom": "26.1.0",
18
18
  "typescript": "5.8.3",
19
19
  "babel-loader": "10.0.0",
@@ -23,6 +23,7 @@
23
23
  "scripts": {
24
24
  "check": "tsc --noEmit",
25
25
  "types": "tsc",
26
+ "types:file": "tsc --allowJs --declaration --emitDeclarationOnly --outDir types",
26
27
  "build": "webpack --stats verbose",
27
28
  "test": "jest",
28
29
  "extract": "api-extractor run --local"
@@ -45,7 +46,7 @@
45
46
  "type": "module",
46
47
  "sideEffects": false,
47
48
  "license": "LGPL-3.0-or-later",
48
- "version": "1.3.23",
49
+ "version": "1.3.24",
49
50
  "files": [
50
51
  "dist",
51
52
  "README.md"