hyperscript-rxjs 1.3.23 → 1.3.25
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.
- package/dist/hyperscript-rxjs.d.ts +285 -265
- package/dist/hyperscript-rxjs.js +370 -423
- package/package.json +7 -6
package/dist/hyperscript-rxjs.js
CHANGED
@@ -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 */
|
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
|
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/
|
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/
|
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/
|
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/
|
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
|
-
|
1696
|
-
}
|
1697
|
-
|
1698
|
-
|
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 (
|
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
|
-
|
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 是函数
|
@@ -1809,7 +1792,28 @@ function subscribeEvent(elem) {
|
|
1809
1792
|
}
|
1810
1793
|
);
|
1811
1794
|
}
|
1795
|
+
;// ./src/object/isPlainObject.js
|
1796
|
+
/**
|
1797
|
+
* 检查一个值是否是普通对象(Plain Object)
|
1798
|
+
* @param {unknown} value - 要检查的值
|
1799
|
+
* @returns {value is object} - 返回是否是普通对象的类型谓词
|
1800
|
+
*/
|
1801
|
+
function isPlainObject(value) {
|
1802
|
+
// 基本检查:非对象或为null的直接返回false
|
1803
|
+
if (typeof value !== 'object' || value === null) {
|
1804
|
+
return false;
|
1805
|
+
}
|
1806
|
+
|
1807
|
+
// 检查原型链
|
1808
|
+
const proto = Object.getPrototypeOf(value);
|
1809
|
+
|
1810
|
+
// 1. 原型为null(如Object.create(null)创建的对象)
|
1811
|
+
// 2. 原型等于Object.prototype(普通对象)
|
1812
|
+
return proto === null || proto === Object.prototype;
|
1813
|
+
}
|
1812
1814
|
;// ./src/nodes/parseHyperscriptArgs.js
|
1815
|
+
|
1816
|
+
|
1813
1817
|
/**
|
1814
1818
|
* 解析 hyperscript 风格的参数,返回 props 和 childNodes。
|
1815
1819
|
*
|
@@ -1817,12 +1821,7 @@ function subscribeEvent(elem) {
|
|
1817
1821
|
* @returns {{ props: Record<string, any>, childNodes: any[] }} 包含 props(对象)和 childNodes(数组)的对象。
|
1818
1822
|
* @throws 如果参数不是数组会抛出错误。
|
1819
1823
|
*/
|
1820
|
-
|
1821
1824
|
function parseHyperscriptArgs(args) {
|
1822
|
-
// 参数验证,确保 args 是一个数组
|
1823
|
-
if (!Array.isArray(args)) {
|
1824
|
-
throw new Error('参数 "args" 必须是一个数组。');
|
1825
|
-
}
|
1826
1825
|
if (args.length === 0) {
|
1827
1826
|
return {
|
1828
1827
|
props: {},
|
@@ -1830,9 +1829,7 @@ function parseHyperscriptArgs(args) {
|
|
1830
1829
|
};
|
1831
1830
|
} else {
|
1832
1831
|
let [first, ...rest] = args;
|
1833
|
-
|
1834
|
-
//
|
1835
|
-
if (isProps(first)) {
|
1832
|
+
if (isPlainObject(first)) {
|
1836
1833
|
return {
|
1837
1834
|
props: first ? first : {},
|
1838
1835
|
childNodes: rest
|
@@ -1846,45 +1843,15 @@ function parseHyperscriptArgs(args) {
|
|
1846
1843
|
}
|
1847
1844
|
}
|
1848
1845
|
}
|
1849
|
-
|
1850
|
-
/**
|
1851
|
-
* 如果第一个参数是 undefined、null 或普通对象(非数组),则返回 true。
|
1852
|
-
* 否则返回 false。
|
1853
|
-
* @param {unknown} value - 要检查的值
|
1854
|
-
* @returns {boolean}
|
1855
|
-
*
|
1856
|
-
*/
|
1857
|
-
function isProps(value) {
|
1858
|
-
//// 基本检查: 空作为props的占位符(不建议,作为兼容)
|
1859
|
-
if (value === undefined || value === null) {
|
1860
|
-
return true;
|
1861
|
-
}
|
1862
|
-
|
1863
|
-
// 基本检查:非对象直接返回false
|
1864
|
-
if (typeof value !== 'object') {
|
1865
|
-
return false;
|
1866
|
-
}
|
1867
|
-
|
1868
|
-
// 检查原型链
|
1869
|
-
const proto = Object.getPrototypeOf(value);
|
1870
|
-
|
1871
|
-
// 1. 原型为null(如Object.create(null)创建的对象)
|
1872
|
-
// 2. 原型等于Object.prototype(普通对象)
|
1873
|
-
return proto === null || proto === Object.prototype;
|
1874
|
-
}
|
1875
1846
|
;// ./src/nodes/normalizeChildNodes.js
|
1876
|
-
|
1877
|
-
|
1878
1847
|
/**
|
1879
1848
|
* 规范化子节点,将非节点转换为文本节点。
|
1880
1849
|
*
|
1881
|
-
* @param {
|
1850
|
+
* @param {import("./normalizeChildNodes.d.ts").NodeInput[]} childNodes - 子节点数组。
|
1882
1851
|
* @returns {Node[]} - 返回规范化后的节点数组。
|
1883
1852
|
*/
|
1884
1853
|
function normalizeChildNodes(childNodes) {
|
1885
|
-
|
1886
|
-
|
1887
|
-
return normalizedNodes.map(child => child instanceof Node ? child : document.createTextNode(String(child)) // 将非节点转换为文本节点
|
1854
|
+
return childNodes.map(child => child instanceof Node ? child : document.createTextNode(String(child)) // 将非节点转换为文本节点
|
1888
1855
|
);
|
1889
1856
|
}
|
1890
1857
|
;// ./src/object/splitObjectByObservable.js
|
@@ -2130,7 +2097,7 @@ function setProps(element, props) {
|
|
2130
2097
|
// 返回元素本身,支持链式调用
|
2131
2098
|
return element;
|
2132
2099
|
}
|
2133
|
-
;// ./src/
|
2100
|
+
;// ./src/hyperscripts/hyperscript.js
|
2134
2101
|
|
2135
2102
|
|
2136
2103
|
|
@@ -2139,43 +2106,29 @@ function setProps(element, props) {
|
|
2139
2106
|
|
2140
2107
|
|
2141
2108
|
/**
|
2142
|
-
* @typedef {import("./HyperscriptExtensions.
|
2109
|
+
* @typedef {import("./HyperscriptExtensions.js").HyperscriptExtensions<HTMLElement>} HyperscriptElement
|
2143
2110
|
*/
|
2144
2111
|
|
2145
2112
|
/**
|
2146
2113
|
* Creates an HTML element with extended event handling capabilities
|
2147
2114
|
* @public
|
2148
|
-
* @param {
|
2115
|
+
* @param {import("./hyperscript.d.ts").HtmlTagName} elemName - The HTML element tag name
|
2149
2116
|
* @param {...any} args - Optional properties and child nodes
|
2150
2117
|
* @returns {HyperscriptElement} The created element with extended methods
|
2151
2118
|
* @throws {Error} If elemName is not a valid HTML element tag name
|
2152
2119
|
*/
|
2153
2120
|
function hyperscript(elemName, ...args) {
|
2154
|
-
// 参数验证,确保 elemName 是一个有效的字符串
|
2155
|
-
if (typeof elemName !== 'string' || !tagNames.has(elemName)) {
|
2156
|
-
throw new Error(`参数 elemName 不是一个有效的 HTML 元素标签名。`);
|
2157
|
-
}
|
2158
|
-
|
2159
|
-
// 创建 HTML 元素
|
2160
|
-
|
2161
2121
|
let element = document.createElement(elemName);
|
2162
|
-
|
2163
|
-
// 解析传入的参数
|
2164
2122
|
const {
|
2165
2123
|
props,
|
2166
2124
|
childNodes
|
2167
2125
|
} = parseHyperscriptArgs(args);
|
2168
|
-
|
2169
|
-
// 设置元素属性
|
2170
2126
|
setProps(element, props);
|
2171
|
-
|
2172
|
-
// 添加子节点
|
2173
2127
|
normalizeChildNodes(childNodes).forEach(child => {
|
2174
|
-
element.appendChild(child);
|
2128
|
+
element.appendChild(child);
|
2175
2129
|
});
|
2176
2130
|
Object.assign(element, {
|
2177
2131
|
/**
|
2178
|
-
*
|
2179
2132
|
* @param {string} event
|
2180
2133
|
* @param {(event$: Observable<Event>) => Subscription} subscriber
|
2181
2134
|
*/
|
@@ -2183,7 +2136,6 @@ function hyperscript(elemName, ...args) {
|
|
2183
2136
|
return pipeEvent(element)(event, subscriber);
|
2184
2137
|
},
|
2185
2138
|
/**
|
2186
|
-
*
|
2187
2139
|
* @param {string} event
|
2188
2140
|
* @param {((value: Event) => void) | import('rxjs').Observer<Event>} observer
|
2189
2141
|
*/
|
@@ -2192,21 +2144,90 @@ function hyperscript(elemName, ...args) {
|
|
2192
2144
|
},
|
2193
2145
|
unsubscribe() {
|
2194
2146
|
if ('subscription' in element && element.subscription instanceof external_commonjs_rxjs_commonjs2_rxjs_amd_rxjs_root_rxjs_.Subscription) {
|
2195
|
-
element.subscription.unsubscribe();
|
2196
|
-
delete element.subscription;
|
2147
|
+
element.subscription.unsubscribe();
|
2148
|
+
delete element.subscription;
|
2197
2149
|
}
|
2198
2150
|
}
|
2199
2151
|
});
|
2200
|
-
return /** @type {HyperscriptElement} */element;
|
2152
|
+
return /** @type {HyperscriptElement} */element;
|
2201
2153
|
}
|
2154
|
+
|
2155
|
+
/**
|
2156
|
+
* @type {Set<import("./hyperscript.d.ts").HtmlTagName>}
|
2157
|
+
*/
|
2202
2158
|
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/
|
2159
|
+
;// ./src/hyperscripts/tags.js
|
2204
2160
|
|
2205
2161
|
|
2206
2162
|
/**
|
2207
2163
|
* @template {HTMLElement} T
|
2208
|
-
* @typedef {import("./HyperscriptExtensions.
|
2164
|
+
* @typedef {import("./HyperscriptExtensions.js").HyperscriptExtensions<T>} HyperscriptExtensions
|
2165
|
+
*/
|
2166
|
+
|
2167
|
+
/// void elements
|
2168
|
+
|
2169
|
+
/**
|
2170
|
+
* 创建 <br> 元素
|
2171
|
+
* @returns {HyperscriptExtensions<HTMLBRElement>}
|
2172
|
+
*/
|
2173
|
+
const br = () => (/** @type {HyperscriptExtensions<HTMLBRElement>} */hyperscript('br'));
|
2174
|
+
|
2175
|
+
/**
|
2176
|
+
* 创建 <hr> 元素
|
2177
|
+
* @returns {HyperscriptExtensions<HTMLHRElement>}
|
2178
|
+
*/
|
2179
|
+
const hr = () => (/** @type {HyperscriptExtensions<HTMLHRElement>} */hyperscript('hr'));
|
2180
|
+
|
2181
|
+
/**
|
2182
|
+
* 创建 <wbr> 元素
|
2183
|
+
* @returns {HyperscriptExtensions<HTMLElement>}
|
2184
|
+
*/
|
2185
|
+
const wbr = () => (/** @type {HyperscriptExtensions<HTMLElement>} */hyperscript('wbr'));
|
2186
|
+
|
2187
|
+
/// 有属性,无子元素的html
|
2188
|
+
|
2189
|
+
/**
|
2190
|
+
* 创建 <area> 元素
|
2191
|
+
* @param {{ [_: string]: any }} [props] - 元素属性
|
2192
|
+
* @returns {HyperscriptExtensions<HTMLAreaElement>}
|
2193
|
+
*/
|
2194
|
+
const tags_area = props => (/** @type {HyperscriptExtensions<HTMLAreaElement>} */hyperscript('area', props));
|
2195
|
+
|
2196
|
+
/**
|
2197
|
+
* 创建 <col> 元素
|
2198
|
+
* @param {{ [_: string]: any }} [props] - 元素属性
|
2199
|
+
* @returns {HyperscriptExtensions<HTMLTableColElement>}
|
2209
2200
|
*/
|
2201
|
+
const col = props => (/** @type {HyperscriptExtensions<HTMLTableColElement>} */hyperscript('col', props));
|
2202
|
+
|
2203
|
+
/**
|
2204
|
+
* 创建 <img> 元素
|
2205
|
+
* @param {{ [_: string]: any }} [props] - 元素属性
|
2206
|
+
* @returns {HyperscriptExtensions<HTMLImageElement>}
|
2207
|
+
*/
|
2208
|
+
const img = props => (/** @type {HyperscriptExtensions<HTMLImageElement>} */hyperscript('img', props));
|
2209
|
+
|
2210
|
+
/**
|
2211
|
+
* 创建 <input> 元素
|
2212
|
+
* @param {{ [_: string]: any }} [props] - 元素属性
|
2213
|
+
* @returns {HyperscriptExtensions<HTMLInputElement>}
|
2214
|
+
*/
|
2215
|
+
const input = props => (/** @type {HyperscriptExtensions<HTMLInputElement>} */hyperscript('input', props));
|
2216
|
+
|
2217
|
+
/**
|
2218
|
+
* 创建 <track> 元素
|
2219
|
+
* @param {{ [_: string]: any }} [props] - 元素属性
|
2220
|
+
* @returns {HyperscriptExtensions<HTMLTrackElement>}
|
2221
|
+
*/
|
2222
|
+
const track = props => (/** @type {HyperscriptExtensions<HTMLTrackElement>} */hyperscript('track', props));
|
2223
|
+
|
2224
|
+
/**
|
2225
|
+
* 创建 <option> 元素
|
2226
|
+
* @param {{ [_: string]: any }} [props] - 元素属性
|
2227
|
+
* @param {...(Text|string)} childNodes - 子节点
|
2228
|
+
* @returns {HyperscriptExtensions<HTMLOptionElement>}
|
2229
|
+
*/
|
2230
|
+
const tags_option = (props, ...childNodes) => (/** @type {HyperscriptExtensions<HTMLOptionElement>} */hyperscript('option', props, ...childNodes));
|
2210
2231
|
|
2211
2232
|
/**
|
2212
2233
|
* 创建 <a> 元素
|
@@ -2232,14 +2253,6 @@ const abbr = (props, ...childNodes) => (/** @type {HyperscriptExtensions<HTMLEle
|
|
2232
2253
|
*/
|
2233
2254
|
const address = (props, ...childNodes) => (/** @type {HyperscriptExtensions<HTMLElement>} */hyperscript('address', props, ...childNodes));
|
2234
2255
|
|
2235
|
-
/**
|
2236
|
-
* 创建 <area> 元素
|
2237
|
-
* @param {{ [_: string]: any }} [props] - 元素属性
|
2238
|
-
* @param {...any} childNodes - 子节点
|
2239
|
-
* @returns {HyperscriptExtensions<HTMLAreaElement>}
|
2240
|
-
*/
|
2241
|
-
const tags_area = (props, ...childNodes) => (/** @type {HyperscriptExtensions<HTMLAreaElement>} */hyperscript('area', props, ...childNodes));
|
2242
|
-
|
2243
2256
|
/**
|
2244
2257
|
* 创建 <article> 元素
|
2245
2258
|
* @param {{ [_: string]: any }} [props] - 元素属性
|
@@ -2296,14 +2309,6 @@ const bdo = (props, ...childNodes) => (/** @type {HyperscriptExtensions<HTMLElem
|
|
2296
2309
|
*/
|
2297
2310
|
const blockquote = (props, ...childNodes) => (/** @type {HyperscriptExtensions<HTMLQuoteElement>} */hyperscript('blockquote', props, ...childNodes));
|
2298
2311
|
|
2299
|
-
/**
|
2300
|
-
* 创建 <br> 元素
|
2301
|
-
* @param {{ [_: string]: any }} [props] - 元素属性
|
2302
|
-
* @param {...any} childNodes - 子节点
|
2303
|
-
* @returns {HyperscriptExtensions<HTMLBRElement>}
|
2304
|
-
*/
|
2305
|
-
const br = (props, ...childNodes) => (/** @type {HyperscriptExtensions<HTMLBRElement>} */hyperscript('br', props, ...childNodes));
|
2306
|
-
|
2307
2312
|
/**
|
2308
2313
|
* 创建 <button> 元素
|
2309
2314
|
* @param {{ [_: string]: any }} [props] - 元素属性
|
@@ -2336,14 +2341,6 @@ const cite = (props, ...childNodes) => (/** @type {HyperscriptExtensions<HTMLEle
|
|
2336
2341
|
*/
|
2337
2342
|
const code = (props, ...childNodes) => (/** @type {HyperscriptExtensions<HTMLElement>} */hyperscript('code', props, ...childNodes));
|
2338
2343
|
|
2339
|
-
/**
|
2340
|
-
* 创建 <col> 元素
|
2341
|
-
* @param {{ [_: string]: any }} [props] - 元素属性
|
2342
|
-
* @param {...any} childNodes - 子节点
|
2343
|
-
* @returns {HyperscriptExtensions<HTMLTableColElement>}
|
2344
|
-
*/
|
2345
|
-
const col = (props, ...childNodes) => (/** @type {HyperscriptExtensions<HTMLTableColElement>} */hyperscript('col', props, ...childNodes));
|
2346
|
-
|
2347
2344
|
/**
|
2348
2345
|
* 创建 <colgroup> 元素
|
2349
2346
|
* @param {{ [_: string]: any }} [props] - 元素属性
|
@@ -2544,14 +2541,6 @@ const header = (props, ...childNodes) => (/** @type {HyperscriptExtensions<HTMLE
|
|
2544
2541
|
*/
|
2545
2542
|
const hgroup = (props, ...childNodes) => (/** @type {HyperscriptExtensions<HTMLElement>} */hyperscript('hgroup', props, ...childNodes));
|
2546
2543
|
|
2547
|
-
/**
|
2548
|
-
* 创建 <hr> 元素
|
2549
|
-
* @param {{ [_: string]: any }} [props] - 元素属性
|
2550
|
-
* @param {...any} childNodes - 子节点
|
2551
|
-
* @returns {HyperscriptExtensions<HTMLHRElement>}
|
2552
|
-
*/
|
2553
|
-
const hr = (props, ...childNodes) => (/** @type {HyperscriptExtensions<HTMLHRElement>} */hyperscript('hr', props, ...childNodes));
|
2554
|
-
|
2555
2544
|
/**
|
2556
2545
|
* 创建 <i> 元素
|
2557
2546
|
* @param {{ [_: string]: any }} [props] - 元素属性
|
@@ -2560,22 +2549,6 @@ const hr = (props, ...childNodes) => (/** @type {HyperscriptExtensions<HTMLHREle
|
|
2560
2549
|
*/
|
2561
2550
|
const i = (props, ...childNodes) => (/** @type {HyperscriptExtensions<HTMLElement>} */hyperscript('i', props, ...childNodes));
|
2562
2551
|
|
2563
|
-
/**
|
2564
|
-
* 创建 <img> 元素
|
2565
|
-
* @param {{ [_: string]: any }} [props] - 元素属性
|
2566
|
-
* @param {...any} childNodes - 子节点
|
2567
|
-
* @returns {HyperscriptExtensions<HTMLImageElement>}
|
2568
|
-
*/
|
2569
|
-
const img = (props, ...childNodes) => (/** @type {HyperscriptExtensions<HTMLImageElement>} */hyperscript('img', props, ...childNodes));
|
2570
|
-
|
2571
|
-
/**
|
2572
|
-
* 创建 <input> 元素
|
2573
|
-
* @param {{ [_: string]: any }} [props] - 元素属性
|
2574
|
-
* @param {...any} childNodes - 子节点
|
2575
|
-
* @returns {HyperscriptExtensions<HTMLInputElement>}
|
2576
|
-
*/
|
2577
|
-
const input = (props, ...childNodes) => (/** @type {HyperscriptExtensions<HTMLInputElement>} */hyperscript('input', props, ...childNodes));
|
2578
|
-
|
2579
2552
|
/**
|
2580
2553
|
* 创建 <ins> 元素
|
2581
2554
|
* @param {{ [_: string]: any }} [props] - 元素属性
|
@@ -2680,14 +2653,6 @@ const ol = (props, ...childNodes) => (/** @type {HyperscriptExtensions<HTMLOList
|
|
2680
2653
|
*/
|
2681
2654
|
const optgroup = (props, ...childNodes) => (/** @type {HyperscriptExtensions<HTMLOptGroupElement>} */hyperscript('optgroup', props, ...childNodes));
|
2682
2655
|
|
2683
|
-
/**
|
2684
|
-
* 创建 <option> 元素
|
2685
|
-
* @param {{ [_: string]: any }} [props] - 元素属性
|
2686
|
-
* @param {...any} childNodes - 子节点
|
2687
|
-
* @returns {HyperscriptExtensions<HTMLOptionElement>}
|
2688
|
-
*/
|
2689
|
-
const tags_option = (props, ...childNodes) => (/** @type {HyperscriptExtensions<HTMLOptionElement>} */hyperscript('option', props, ...childNodes));
|
2690
|
-
|
2691
2656
|
/**
|
2692
2657
|
* 创建 <output> 元素
|
2693
2658
|
* @param {{ [_: string]: any }} [props] - 元素属性
|
@@ -2904,14 +2869,6 @@ const time = (props, ...childNodes) => (/** @type {HyperscriptExtensions<HTMLTim
|
|
2904
2869
|
*/
|
2905
2870
|
const tr = (props, ...childNodes) => (/** @type {HyperscriptExtensions<HTMLTableRowElement>} */hyperscript('tr', props, ...childNodes));
|
2906
2871
|
|
2907
|
-
/**
|
2908
|
-
* 创建 <track> 元素
|
2909
|
-
* @param {{ [_: string]: any }} [props] - 元素属性
|
2910
|
-
* @param {...any} childNodes - 子节点
|
2911
|
-
* @returns {HyperscriptExtensions<HTMLTrackElement>}
|
2912
|
-
*/
|
2913
|
-
const track = (props, ...childNodes) => (/** @type {HyperscriptExtensions<HTMLTrackElement>} */hyperscript('track', props, ...childNodes));
|
2914
|
-
|
2915
2872
|
/**
|
2916
2873
|
* 创建 <tt> 元素
|
2917
2874
|
* @param {{ [_: string]: any }} [props] - 元素属性
|
@@ -2943,15 +2900,7 @@ const ul = (props, ...childNodes) => (/** @type {HyperscriptExtensions<HTMLUList
|
|
2943
2900
|
* @returns {HyperscriptExtensions<HTMLVideoElement>}
|
2944
2901
|
*/
|
2945
2902
|
const video = (props, ...childNodes) => (/** @type {HyperscriptExtensions<HTMLVideoElement>} */hyperscript('video', props, ...childNodes));
|
2946
|
-
|
2947
|
-
/**
|
2948
|
-
* 创建 <wbr> 元素
|
2949
|
-
* @param {{ [_: string]: any }} [props] - 元素属性
|
2950
|
-
* @param {...any} childNodes - 子节点
|
2951
|
-
* @returns {HyperscriptExtensions<HTMLElement>}
|
2952
|
-
*/
|
2953
|
-
const wbr = (props, ...childNodes) => (/** @type {HyperscriptExtensions<HTMLElement>} */hyperscript('wbr', props, ...childNodes));
|
2954
|
-
;// ./src/hyperscript-rxjs/tabControls/tabRoot.js
|
2903
|
+
;// ./src/hyperscripts/tabControls/tabRoot.js
|
2955
2904
|
|
2956
2905
|
|
2957
2906
|
/**
|
@@ -2975,7 +2924,7 @@ function tabRoot(props) {
|
|
2975
2924
|
className: 'tab-content'
|
2976
2925
|
}));
|
2977
2926
|
}
|
2978
|
-
;// ./src/
|
2927
|
+
;// ./src/hyperscripts/tabControls/tabNavItem.js
|
2979
2928
|
|
2980
2929
|
|
2981
2930
|
/**
|
@@ -3000,7 +2949,7 @@ function tabNavItem(...source) {
|
|
3000
2949
|
className: 'btn btn-link nav-link'
|
3001
2950
|
}, ...source));
|
3002
2951
|
}
|
3003
|
-
;// ./src/
|
2952
|
+
;// ./src/hyperscripts/tabControls/tabPanel.js
|
3004
2953
|
|
3005
2954
|
|
3006
2955
|
/**
|
@@ -3020,7 +2969,7 @@ function tabPanel(...source) {
|
|
3020
2969
|
className: 'tab-pane'
|
3021
2970
|
}, ...source);
|
3022
2971
|
}
|
3023
|
-
;// ./src/
|
2972
|
+
;// ./src/hyperscripts/tabControls/bindTabIndex.js
|
3024
2973
|
|
3025
2974
|
|
3026
2975
|
|
@@ -3036,7 +2985,7 @@ function tabPanel(...source) {
|
|
3036
2985
|
*/
|
3037
2986
|
function bindTabIndex(tabRoot, tabIndex$) {
|
3038
2987
|
/**
|
3039
|
-
* @typedef {import("../HyperscriptExtensions.
|
2988
|
+
* @typedef {import("../HyperscriptExtensions.js").HyperscriptExtensions<HTMLElement>} HyperscriptElement
|
3040
2989
|
*/
|
3041
2990
|
|
3042
2991
|
const navs = /** @type {HyperscriptElement} */tabRoot.firstChild; // 导航栏容器
|
@@ -3069,7 +3018,7 @@ function bindTabIndex(tabRoot, tabIndex$) {
|
|
3069
3018
|
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
3019
|
).subscribe(tabIndex$));
|
3071
3020
|
}
|
3072
|
-
;// ./src/
|
3021
|
+
;// ./src/hyperscripts/tabControls/tabControl.js
|
3073
3022
|
|
3074
3023
|
|
3075
3024
|
|
@@ -3107,19 +3056,19 @@ function tabControl(props, tabs, panels) {
|
|
3107
3056
|
bindTabIndex(root, tabIndex);
|
3108
3057
|
return root;
|
3109
3058
|
}
|
3110
|
-
;// ./src/
|
3059
|
+
;// ./src/hyperscripts/tabControls/0.js
|
3111
3060
|
|
3112
3061
|
|
3113
3062
|
|
3114
3063
|
|
3115
3064
|
|
3116
|
-
;// ./src/
|
3065
|
+
;// ./src/hyperscripts/checkbox.js
|
3117
3066
|
|
3118
3067
|
|
3119
3068
|
|
3120
3069
|
|
3121
3070
|
/**
|
3122
|
-
* @typedef {import("./HyperscriptExtensions.
|
3071
|
+
* @typedef {import("./HyperscriptExtensions.js").HyperscriptExtensions<HTMLInputElement>} HyperscriptInputElement
|
3123
3072
|
*/
|
3124
3073
|
|
3125
3074
|
/**
|
@@ -3144,9 +3093,7 @@ function checkbox_checkbox(props) {
|
|
3144
3093
|
// 监听复选框的 input 事件,并将选中状态推送到 Observable/Subject
|
3145
3094
|
let subscriber =
|
3146
3095
|
/**
|
3147
|
-
*
|
3148
3096
|
* @param {Observable<Event>} input$
|
3149
|
-
* @returns
|
3150
3097
|
*/
|
3151
3098
|
input$ => input$.pipe((0,operators_root_rxjs_.map)(e => /** @type {HTMLInputElement} */e.target.checked) // 提取复选框的选中状态
|
3152
3099
|
).subscribe(props.checked); // 推送选中状态到 Observable/Subject
|
@@ -3157,8 +3104,7 @@ function checkbox_checkbox(props) {
|
|
3157
3104
|
}
|
3158
3105
|
return elem; // 返回复选框元素
|
3159
3106
|
}
|
3160
|
-
;// ./src/
|
3161
|
-
|
3107
|
+
;// ./src/hyperscripts/collapse.js
|
3162
3108
|
|
3163
3109
|
|
3164
3110
|
|
@@ -3168,16 +3114,14 @@ function checkbox_checkbox(props) {
|
|
3168
3114
|
* `collapse` 函数通过绑定 `hidden` 属性,实现一组 HTML 元素的动态显示或隐藏。
|
3169
3115
|
*
|
3170
3116
|
* @param {Observable<boolean>} hidden$ - 一个可观察对象(如 BehaviorSubject),用于控制元素的 `hidden` 属性。
|
3171
|
-
* @param {...HTMLElement
|
3117
|
+
* @param {...HTMLElement} elements - 一个或多个 HTML 元素,或者包含 HTML 元素的数组。
|
3172
3118
|
* @returns {HTMLElement[]} - 处理后的元素数组。
|
3173
3119
|
*
|
3174
3120
|
* @throws {Error} 如果 `elements` 中包含非元素节点(如 TextNode)。
|
3175
3121
|
*
|
3176
3122
|
*/
|
3177
3123
|
function collapse(hidden$, ...elements) {
|
3178
|
-
|
3179
|
-
let elems = unwrapArgs(elements);
|
3180
|
-
elems.forEach(elem => {
|
3124
|
+
elements.forEach(elem => {
|
3181
3125
|
if (!(elem instanceof HTMLElement)) {
|
3182
3126
|
throw new Error('`collapse` only supports HTMLElement nodes.');
|
3183
3127
|
}
|
@@ -3185,9 +3129,9 @@ function collapse(hidden$, ...elements) {
|
|
3185
3129
|
// 绑定 hidden 属性到可观察对象
|
3186
3130
|
subscribeProp(elem, 'hidden', hidden$);
|
3187
3131
|
});
|
3188
|
-
return
|
3132
|
+
return elements;
|
3189
3133
|
}
|
3190
|
-
;// ./src/
|
3134
|
+
;// ./src/hyperscripts/choice.js
|
3191
3135
|
|
3192
3136
|
|
3193
3137
|
|
@@ -3202,12 +3146,13 @@ function choice(chosen$, possibilities) {
|
|
3202
3146
|
const elems = Object.entries(possibilities).map(([key, possibility]) => {
|
3203
3147
|
const hidden$ = chosen$.pipe((0,operators_root_rxjs_.map)(selectedKey => selectedKey !== key) // 如果当前选中的键不是当前可能性,则隐藏
|
3204
3148
|
);
|
3205
|
-
|
3149
|
+
const arr = Array.isArray(possibility) ? possibility : [possibility];
|
3150
|
+
return collapse(hidden$, ...arr); // 绑定 hidden 属性
|
3206
3151
|
}).reduce((acc, cur) => [...acc, ...cur], []); // 扁平化数组
|
3207
3152
|
|
3208
3153
|
return elems;
|
3209
3154
|
}
|
3210
|
-
;// ./src/
|
3155
|
+
;// ./src/hyperscripts/flip.js
|
3211
3156
|
|
3212
3157
|
|
3213
3158
|
|
@@ -3230,15 +3175,15 @@ function flip(yinHidden$, yin, yang) {
|
|
3230
3175
|
const yangHidden$ = yinHidden$.pipe((0,operators_root_rxjs_.map)(isHidden => !isHidden));
|
3231
3176
|
|
3232
3177
|
// 阴阳交叉
|
3233
|
-
return [...collapse(yangHidden$, yin), ...collapse(yinHidden$, yang)];
|
3178
|
+
return [...collapse(yangHidden$, ...(Array.isArray(yin) ? yin : [yin])), ...collapse(yinHidden$, ...(Array.isArray(yang) ? yang : [yang]))];
|
3234
3179
|
}
|
3235
|
-
;// ./src/
|
3180
|
+
;// ./src/hyperscripts/fragment.js
|
3236
3181
|
|
3237
3182
|
|
3238
3183
|
/**
|
3239
3184
|
* 用途:插入一组元素,不必使用循环语句,fragment 用后即弃。
|
3240
3185
|
*
|
3241
|
-
* @param {...Node
|
3186
|
+
* @param {...Node} childNodes - 要插入的子节点,可以是单个节点、多个节点或节点数组。
|
3242
3187
|
* @returns {DocumentFragment} - 返回包含所有子节点的 DocumentFragment。
|
3243
3188
|
* @throws {Error} 如果传入的子节点不是有效的 DOM 节点。
|
3244
3189
|
*/
|
@@ -3254,18 +3199,18 @@ function fragment(...childNodes) {
|
|
3254
3199
|
// 返回 DocumentFragment
|
3255
3200
|
return frag;
|
3256
3201
|
}
|
3257
|
-
;// ./src/
|
3202
|
+
;// ./src/hyperscripts/multiselect.js
|
3258
3203
|
|
3259
3204
|
|
3260
3205
|
/**
|
3261
|
-
* @typedef {import("./HyperscriptExtensions.
|
3206
|
+
* @typedef {import("./HyperscriptExtensions.js").HyperscriptExtensions<HTMLSelectElement>} HyperscriptSelectElement
|
3262
3207
|
*/
|
3263
3208
|
|
3264
3209
|
/**
|
3265
3210
|
* 创建一个支持多选功能的 <select> 元素,并绑定选项的选中状态。必须手动添加控件更新BehaviorSubject的事件。
|
3266
3211
|
*
|
3267
3212
|
* @param {{oninput?: (e:Event)=>void, onchange?: (e:Event)=>void, [key: string]: any}} props - 配置对象,包含 <select> 元素的属性。
|
3268
|
-
* @param {...HTMLOptionElement
|
3213
|
+
* @param {...HTMLOptionElement} options - 一个或多个 <option> 元素,必须是 HTMLOptionElement 类型。
|
3269
3214
|
* 每个选项需要包含一个 `selected` 属性,该属性是一个 BehaviorSubject ,用于绑定选中状态。
|
3270
3215
|
* @returns {HyperscriptSelectElement} - 创建的 <select> 元素。
|
3271
3216
|
* @throws {Error} 如果 `props` 不是对象,或者 `options` 中的选项未正确定义 `selected` 属性。
|
@@ -3296,7 +3241,7 @@ function multiselect(props, ...options) {
|
|
3296
3241
|
}
|
3297
3242
|
return /** @type {HyperscriptSelectElement} */elem;
|
3298
3243
|
}
|
3299
|
-
;// ./src/
|
3244
|
+
;// ./src/hyperscripts/numberbox.js
|
3300
3245
|
|
3301
3246
|
|
3302
3247
|
|
@@ -3364,7 +3309,7 @@ function numberbox(props) {
|
|
3364
3309
|
elem.style.textAlign = 'right';
|
3365
3310
|
return elem;
|
3366
3311
|
}
|
3367
|
-
;// ./src/
|
3312
|
+
;// ./src/hyperscripts/radio.js
|
3368
3313
|
|
3369
3314
|
|
3370
3315
|
|
@@ -3374,7 +3319,7 @@ function numberbox(props) {
|
|
3374
3319
|
|
3375
3320
|
/**
|
3376
3321
|
* @internal
|
3377
|
-
* @typedef {import("./HyperscriptExtensions.
|
3322
|
+
* @typedef {import("./HyperscriptExtensions.js").HyperscriptInputElement} HyperscriptInputElement
|
3378
3323
|
*/
|
3379
3324
|
|
3380
3325
|
/**
|
@@ -3412,7 +3357,7 @@ function radio_radio(props) {
|
|
3412
3357
|
}
|
3413
3358
|
return elem;
|
3414
3359
|
}
|
3415
|
-
;// ./src/
|
3360
|
+
;// ./src/hyperscripts/select.js
|
3416
3361
|
|
3417
3362
|
|
3418
3363
|
|
@@ -3421,14 +3366,14 @@ function radio_radio(props) {
|
|
3421
3366
|
// import { attachSubscriptionToNode } from '../nodes/attachSubscriptionToNode';
|
3422
3367
|
|
3423
3368
|
/**
|
3424
|
-
* @typedef {import("./HyperscriptExtensions.
|
3369
|
+
* @typedef {import("./HyperscriptExtensions.js").HyperscriptSelectElement} HyperscriptSelectElement
|
3425
3370
|
*/
|
3426
3371
|
|
3427
3372
|
/**
|
3428
3373
|
* 创建一个支持 RxJS 数据绑定的 <select> 元素。仅单选选择框。
|
3429
3374
|
*
|
3430
3375
|
* @param {{ selectedIndex?: BehaviorSubject<number>, value?: BehaviorSubject<string>, [key: string]: any }} props - 配置对象,包含 <select> 元素的属性。
|
3431
|
-
* @param {...HTMLOptionElement
|
3376
|
+
* @param {...HTMLOptionElement} options - 一个或多个 <option> 元素,必须是 HTMLOptionElement 类型。
|
3432
3377
|
* @returns {HyperscriptSelectElement} - 创建的 <select> 元素。
|
3433
3378
|
* @throws {Error} 如果 `props` 不是对象,或者 `selectedIndex` 或 `value` 不是 BehaviorSubject。
|
3434
3379
|
*/
|
@@ -3488,14 +3433,14 @@ function select_select(props, ...options) {
|
|
3488
3433
|
}
|
3489
3434
|
return elem;
|
3490
3435
|
}
|
3491
|
-
;// ./src/
|
3436
|
+
;// ./src/hyperscripts/textarea.js
|
3492
3437
|
|
3493
3438
|
|
3494
3439
|
|
3495
3440
|
|
3496
3441
|
/**
|
3497
3442
|
* @internal
|
3498
|
-
* @typedef {import("./HyperscriptExtensions.
|
3443
|
+
* @typedef {import("./HyperscriptExtensions.js").HyperscriptExtensions<HTMLTextAreaElement>} HyperscriptTextAreaElement
|
3499
3444
|
*/
|
3500
3445
|
|
3501
3446
|
/**
|
@@ -3530,14 +3475,14 @@ function textarea_textarea(props) {
|
|
3530
3475
|
elem.pipeEvent('input', subscriber);
|
3531
3476
|
return elem;
|
3532
3477
|
}
|
3533
|
-
;// ./src/
|
3478
|
+
;// ./src/hyperscripts/textbox.js
|
3534
3479
|
|
3535
3480
|
|
3536
3481
|
|
3537
3482
|
|
3538
3483
|
/**
|
3539
3484
|
* @internal
|
3540
|
-
* @typedef {import("./HyperscriptExtensions.
|
3485
|
+
* @typedef {import("./HyperscriptExtensions.js").HyperscriptInputElement} HyperscriptInputElement
|
3541
3486
|
*/
|
3542
3487
|
|
3543
3488
|
/**
|
@@ -3574,7 +3519,7 @@ function textbox(props) {
|
|
3574
3519
|
elem.pipeEvent('input', subscriber);
|
3575
3520
|
return elem;
|
3576
3521
|
}
|
3577
|
-
;// ./src/
|
3522
|
+
;// ./src/hyperscripts/textNode.js
|
3578
3523
|
|
3579
3524
|
|
3580
3525
|
|
@@ -3589,8 +3534,8 @@ function textbox(props) {
|
|
3589
3534
|
* - 如果传入的是字符串,则创建一个静态文本节点。
|
3590
3535
|
* - 如果传入的是 RxJS Observable,则创建一个动态文本节点,并根据 Observable 的值实时更新文本内容。
|
3591
3536
|
* - 动态文本节点支持通过 `unsubscribe` 方法取消订阅。
|
3592
|
-
*
|
3593
|
-
* @param {
|
3537
|
+
* @template T
|
3538
|
+
* @param {Observable<T>|T} text 任何类型数据都会被转换成string
|
3594
3539
|
* @returns {ObservableTextNode}
|
3595
3540
|
*
|
3596
3541
|
*/
|
@@ -3622,10 +3567,10 @@ function textNode(text) {
|
|
3622
3567
|
}
|
3623
3568
|
});
|
3624
3569
|
} else {
|
3625
|
-
return document.createTextNode(String(text)); // 转换为字符串
|
3570
|
+
return document.createTextNode(typeof text === 'string' ? text : String(text)); // 转换为字符串
|
3626
3571
|
}
|
3627
3572
|
}
|
3628
|
-
;// ./src/
|
3573
|
+
;// ./src/hyperscripts/0.js
|
3629
3574
|
|
3630
3575
|
|
3631
3576
|
|
@@ -3652,38 +3597,32 @@ function textNode(text) {
|
|
3652
3597
|
/**
|
3653
3598
|
* Creates an object composed of the picked object properties.
|
3654
3599
|
* @param {Record<string,any>} obj - Source object
|
3655
|
-
* @param {string
|
3600
|
+
* @param {Iterable<string>} keys - Iterable of property keys to pick
|
3656
3601
|
* @returns {Record<string,any>} New object with picked properties
|
3657
3602
|
* @throws {TypeError} If obj is not an object or keys is not an array
|
3658
3603
|
*/
|
3659
3604
|
function intersectObject(obj, keys) {
|
3660
|
-
// 类型检查
|
3661
3605
|
if (typeof obj !== 'object' || obj === null) {
|
3662
3606
|
throw new TypeError('First argument must be an object');
|
3663
3607
|
}
|
3664
|
-
if (
|
3665
|
-
throw new TypeError('Second argument must be
|
3608
|
+
if (typeof keys?.[Symbol.iterator] !== 'function') {
|
3609
|
+
throw new TypeError('Second argument must be iterable');
|
3666
3610
|
}
|
3667
|
-
return Object.fromEntries(
|
3611
|
+
return Object.fromEntries(generator(obj, keys));
|
3668
3612
|
}
|
3669
|
-
|
3613
|
+
|
3670
3614
|
/**
|
3671
|
-
*
|
3672
|
-
* @param {
|
3673
|
-
* @returns {value is object} - 返回是否是普通对象的类型谓词
|
3615
|
+
* @param {Record<string,any>} obj
|
3616
|
+
* @param {Iterable<string>} keys
|
3674
3617
|
*/
|
3675
|
-
function
|
3676
|
-
|
3677
|
-
|
3678
|
-
|
3618
|
+
function* generator(obj, keys) {
|
3619
|
+
for (const key of keys) {
|
3620
|
+
if (key in obj) {
|
3621
|
+
yield [key, obj[key]];
|
3622
|
+
} else {
|
3623
|
+
throw new Error(`key不在obj中: ${key}`);
|
3624
|
+
}
|
3679
3625
|
}
|
3680
|
-
|
3681
|
-
// 检查原型链
|
3682
|
-
const proto = Object.getPrototypeOf(value);
|
3683
|
-
|
3684
|
-
// 1. 原型为null(如Object.create(null)创建的对象)
|
3685
|
-
// 2. 原型等于Object.prototype(普通对象)
|
3686
|
-
return proto === null || proto === Object.prototype;
|
3687
3626
|
}
|
3688
3627
|
;// ./src/object/isEmptyObject.js
|
3689
3628
|
|
@@ -3729,78 +3668,210 @@ function nestedMerge(model) {
|
|
3729
3668
|
|
3730
3669
|
|
3731
3670
|
|
3671
|
+
|
3672
|
+
/**
|
3673
|
+
* @typedef {import('./pickBehaviorSubject.js').NestedStringArray} NestedStringArray
|
3674
|
+
*/
|
3675
|
+
|
3676
|
+
/**
|
3677
|
+
* @template T
|
3678
|
+
* @typedef {import('./pickBehaviorSubject.js').NestedObject<T>} NestedObject<T>
|
3679
|
+
*/
|
3680
|
+
|
3732
3681
|
/**
|
3733
3682
|
*
|
3734
|
-
*
|
3735
|
-
* @public
|
3736
|
-
* @param {Record<string|number,any> & { pickeys?: () => string [] }} model - 输入的数据结构,可以是对象、数组或BehaviorSubject
|
3737
|
-
* @returns {Record<string|number,any>} - 返回只包含BehaviorSubject当前值的结构
|
3738
|
-
* @throws {Error} 当输入不包含任何BehaviorSubject或结构不符合预期时抛出错误
|
3683
|
+
* @param {NestedStringArray[]} paths
|
3739
3684
|
*/
|
3740
|
-
|
3741
|
-
|
3742
|
-
|
3743
|
-
return x[0][1];
|
3685
|
+
const getMap = paths => new Map(paths.map(path => {
|
3686
|
+
if (typeof path === 'string') {
|
3687
|
+
return [path, []];
|
3744
3688
|
} else {
|
3745
|
-
|
3689
|
+
let [h, ...rest] = path;
|
3690
|
+
return [(/** @type {string} */h), rest];
|
3746
3691
|
}
|
3747
|
-
}
|
3692
|
+
}));
|
3748
3693
|
|
3749
3694
|
/**
|
3750
|
-
*
|
3751
|
-
*
|
3752
|
-
|
3753
|
-
|
3754
|
-
|
3755
|
-
|
3756
|
-
|
3757
|
-
|
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)) {
|
3695
|
+
* @param {{pickeys?:()=>NestedStringArray[]}} source
|
3696
|
+
* @param {NestedStringArray[]} paths
|
3697
|
+
*/
|
3698
|
+
const mergeKeys = (source, paths) => {
|
3699
|
+
if (paths && paths.length > 0) {
|
3700
|
+
return paths;
|
3701
|
+
} else if ('pickeys' in source && typeof source.pickeys === 'function') {
|
3702
|
+
return source.pickeys();
|
3703
|
+
} else {
|
3763
3704
|
return [];
|
3764
|
-
}
|
3765
|
-
|
3766
|
-
|
3767
|
-
|
3768
|
-
|
3705
|
+
}
|
3706
|
+
};
|
3707
|
+
|
3708
|
+
/**
|
3709
|
+
* 数组中所有元素应该类型相同,符合同一套逻辑
|
3710
|
+
* @template T
|
3711
|
+
* @param {NestedObject<T>[]} arr
|
3712
|
+
* @param {NestedStringArray[]} paths
|
3713
|
+
* @returns {NestedObject<T>[] }}
|
3714
|
+
*/
|
3715
|
+
const getArray = (arr, paths) => [...function* () {
|
3716
|
+
for (const elem of arr) {
|
3717
|
+
if (isRxType(elem)) {
|
3718
|
+
if (elem instanceof external_commonjs_rxjs_commonjs2_rxjs_amd_rxjs_root_rxjs_.BehaviorSubject) {
|
3719
|
+
yield elem.value;
|
3769
3720
|
} else {
|
3770
|
-
|
3721
|
+
// ignore observable, subscription ...
|
3722
|
+
}
|
3723
|
+
} else if (Array.isArray(elem) || elem instanceof ObservableArray_ObservableArray) {
|
3724
|
+
if (elem.length === 0) {} else {
|
3725
|
+
yield getArray(elem, paths);
|
3726
|
+
}
|
3727
|
+
} else if (isPlainObject(elem)) {
|
3728
|
+
if (isEmptyObject(elem)) {} else {
|
3729
|
+
yield getObject(elem, paths);
|
3771
3730
|
}
|
3772
|
-
});
|
3773
|
-
return [[key, v]];
|
3774
|
-
} else if (value instanceof Array) {
|
3775
|
-
if (value.length === 0) {
|
3776
|
-
return []; //空不可变数组,将丢弃。
|
3777
3731
|
} else {
|
3778
|
-
|
3779
|
-
|
3780
|
-
|
3781
|
-
|
3732
|
+
// ignore other number, string, null, boolean, function ...
|
3733
|
+
}
|
3734
|
+
}
|
3735
|
+
}()];
|
3736
|
+
|
3737
|
+
/**
|
3738
|
+
* @template T
|
3739
|
+
* @param {{[_:string]:NestedObject<T>}} obj
|
3740
|
+
* @param {NestedStringArray[]} paths
|
3741
|
+
* @returns {{ [_: string]: NestedObject<T> }}
|
3742
|
+
*/
|
3743
|
+
const getObject = (obj, paths) => Object.fromEntries(function* () {
|
3744
|
+
let mergedPaths = mergeKeys(obj, paths);
|
3745
|
+
if (mergedPaths.length === 0) {
|
3746
|
+
for (const [key, value] of Object.entries(obj)) {
|
3747
|
+
if (isRxType(value)) {
|
3748
|
+
if (value instanceof external_commonjs_rxjs_commonjs2_rxjs_amd_rxjs_root_rxjs_.BehaviorSubject) {
|
3749
|
+
console.log('isRxType(value) && value instanceof BehaviorSubject');
|
3750
|
+
yield [key, value.value];
|
3782
3751
|
} else {
|
3783
|
-
|
3752
|
+
// ignore observable, subscription ...
|
3753
|
+
console.log('isRxType(value) && else');
|
3784
3754
|
}
|
3785
|
-
})
|
3786
|
-
|
3755
|
+
} else if (Array.isArray(value) || value instanceof ObservableArray_ObservableArray) {
|
3756
|
+
if (value.length === 0) {} else {
|
3757
|
+
yield [key, getArray(value, [])];
|
3758
|
+
}
|
3759
|
+
} else if (isPlainObject(value)) {
|
3760
|
+
if (isEmptyObject(value)) {
|
3761
|
+
console.log('isPlainObject isEmptyObject');
|
3762
|
+
} else {
|
3763
|
+
console.log('isPlainObject');
|
3764
|
+
yield [key, getObject(value, [])];
|
3765
|
+
}
|
3766
|
+
} else {
|
3767
|
+
// ignore other number, string, null, boolean, function ...
|
3768
|
+
console.log('ignore other:' + `${key}:${value}`);
|
3769
|
+
}
|
3787
3770
|
}
|
3788
|
-
} else if ('pickeys' in value) {
|
3789
|
-
return loop(intersectObject(value, value.pickeys()), key, parent);
|
3790
3771
|
} else {
|
3791
|
-
let
|
3792
|
-
|
3793
|
-
|
3794
|
-
|
3795
|
-
|
3796
|
-
|
3797
|
-
|
3798
|
-
|
3799
|
-
|
3772
|
+
let mp = getMap(mergedPaths);
|
3773
|
+
for (const key of mp.keys()) {
|
3774
|
+
if (key in obj) {
|
3775
|
+
const value = obj[key];
|
3776
|
+
const newPaths = mp.get(key) ?? [];
|
3777
|
+
if (isRxType(value)) {
|
3778
|
+
if (value instanceof external_commonjs_rxjs_commonjs2_rxjs_amd_rxjs_root_rxjs_.BehaviorSubject) {
|
3779
|
+
console.log('isRxType(value) && value instanceof BehaviorSubject');
|
3780
|
+
yield [key, value.value];
|
3781
|
+
} else {
|
3782
|
+
// ignore observable, subscription ...
|
3783
|
+
console.log('isRxType(value) && else');
|
3784
|
+
}
|
3785
|
+
} else if (Array.isArray(value) || value instanceof ObservableArray_ObservableArray) {
|
3786
|
+
if (value.length === 0) {} else {
|
3787
|
+
yield [key, getArray(value, newPaths)];
|
3788
|
+
}
|
3789
|
+
} else if (isPlainObject(value)) {
|
3790
|
+
if (isEmptyObject(value)) {
|
3791
|
+
console.log('isPlainObject isEmptyObject');
|
3792
|
+
} else {
|
3793
|
+
console.log('isPlainObject');
|
3794
|
+
yield [key, getObject(value, newPaths)];
|
3795
|
+
}
|
3796
|
+
} else {
|
3797
|
+
// ignore other number, string, null, boolean, function ...
|
3798
|
+
console.log('ignore other:' + `${key}:${value}`);
|
3799
|
+
}
|
3800
3800
|
}
|
3801
3801
|
}
|
3802
3802
|
}
|
3803
|
-
}
|
3803
|
+
}());
|
3804
|
+
|
3805
|
+
/**
|
3806
|
+
*
|
3807
|
+
* 拾取对象中的BehaviorSubject值,作爲葉子節點,忽略其他值。
|
3808
|
+
* @public
|
3809
|
+
* @template T
|
3810
|
+
* @param {{[_:string]:NestedObject<T>} & { pickeys?: () => NestedStringArray[] }} source - 输入的数据结构,可以是对象、数组或BehaviorSubject
|
3811
|
+
* @param {NestedStringArray[]} [paths]
|
3812
|
+
* @returns {{[_:string]:NestedObject<T>}}
|
3813
|
+
* @throws {Error} 当输入不包含任何BehaviorSubject或结构不符合预期时抛出错误
|
3814
|
+
*/
|
3815
|
+
const pickBehaviorSubject = (source, paths = []) => {
|
3816
|
+
if (isRxType(source)) {
|
3817
|
+
throw new Error("请将内容包装在普通对象中");
|
3818
|
+
} else if (Array.isArray(source) || source instanceof ObservableArray_ObservableArray) {
|
3819
|
+
throw new Error("请将内容包装在普通对象中");
|
3820
|
+
} else if (isPlainObject(source)) {
|
3821
|
+
if (isEmptyObject(source)) {
|
3822
|
+
throw new Error("N没有内容需要pick");
|
3823
|
+
} else {
|
3824
|
+
return getObject(source, paths);
|
3825
|
+
}
|
3826
|
+
} else {
|
3827
|
+
throw new Error("没有内容需要pick");
|
3828
|
+
}
|
3829
|
+
};
|
3830
|
+
|
3831
|
+
/**
|
3832
|
+
* 提取值判断的分类
|
3833
|
+
* @param {*} value
|
3834
|
+
* @returns
|
3835
|
+
*/
|
3836
|
+
const testit = value => {
|
3837
|
+
if (typeof value === 'undefined' || value === null) {
|
3838
|
+
return {
|
3839
|
+
kind: "null"
|
3840
|
+
};
|
3841
|
+
} else if (isObservable(value)) {
|
3842
|
+
if (value instanceof BehaviorSubject) {
|
3843
|
+
return {
|
3844
|
+
kind: "BehaviorSubject"
|
3845
|
+
};
|
3846
|
+
} else {
|
3847
|
+
return {
|
3848
|
+
kind: "Observable"
|
3849
|
+
};
|
3850
|
+
}
|
3851
|
+
} else if (value instanceof ObservableArray) {
|
3852
|
+
return {
|
3853
|
+
kind: "ObservableArray"
|
3854
|
+
};
|
3855
|
+
} else if (Array.isArray(value)) {
|
3856
|
+
return {
|
3857
|
+
kind: "Array"
|
3858
|
+
};
|
3859
|
+
} else if (typeof value === 'object') {
|
3860
|
+
if (Object.keys(value).length === 0) {
|
3861
|
+
return {
|
3862
|
+
kind: "EmptyObject"
|
3863
|
+
};
|
3864
|
+
} else {
|
3865
|
+
return {
|
3866
|
+
kind: "PlainObject"
|
3867
|
+
};
|
3868
|
+
}
|
3869
|
+
} else {
|
3870
|
+
return {
|
3871
|
+
kind: "else"
|
3872
|
+
};
|
3873
|
+
}
|
3874
|
+
};
|
3804
3875
|
;// ./src/object/restore.js
|
3805
3876
|
|
3806
3877
|
|
@@ -3815,7 +3886,7 @@ function loop(value, key, parent) {
|
|
3815
3886
|
* @returns
|
3816
3887
|
*/
|
3817
3888
|
function restore(model, src) {
|
3818
|
-
|
3889
|
+
loop(model, src);
|
3819
3890
|
// return model
|
3820
3891
|
}
|
3821
3892
|
|
@@ -3824,13 +3895,13 @@ function restore(model, src) {
|
|
3824
3895
|
* @param {any & {appendChild?: (c:any) => void }} o - Current model node to update
|
3825
3896
|
* @param {any} src - Corresponding source value
|
3826
3897
|
*/
|
3827
|
-
function
|
3898
|
+
function loop(o, src) {
|
3828
3899
|
if (o instanceof external_commonjs_rxjs_commonjs2_rxjs_amd_rxjs_root_rxjs_.BehaviorSubject) {
|
3829
3900
|
// Input value
|
3830
3901
|
o.next(src);
|
3831
3902
|
} else if (o === null || typeof o !== 'object' || isRxType(o)) {
|
3832
3903
|
// noop
|
3833
|
-
} else if (o instanceof
|
3904
|
+
} else if (o instanceof ObservableArray_ObservableArray) {
|
3834
3905
|
let len = o.length;
|
3835
3906
|
let diffcount = len - src.length;
|
3836
3907
|
if (diffcount > 0) {
|
@@ -3852,7 +3923,7 @@ function restore_loop(o, src) {
|
|
3852
3923
|
|
3853
3924
|
// After alignment, update each element's value
|
3854
3925
|
for (let i of o.keys()) {
|
3855
|
-
|
3926
|
+
loop(o[i], src[i]);
|
3856
3927
|
}
|
3857
3928
|
} else if (o instanceof Array) {
|
3858
3929
|
// Regular array, tuple
|
@@ -3860,13 +3931,13 @@ function restore_loop(o, src) {
|
|
3860
3931
|
// Ignore extra src elements, noop for missing elements
|
3861
3932
|
for (let i of indexes.keys()) {
|
3862
3933
|
// todo: Throw error when o[i] is not settable?
|
3863
|
-
|
3934
|
+
loop(o[i], src[i]);
|
3864
3935
|
}
|
3865
3936
|
} else if (typeof o === 'object') {
|
3866
3937
|
// Recursively process object properties
|
3867
3938
|
Object.entries(o).filter(([k, v]) => k in src) // Intersection
|
3868
3939
|
.forEach(([k, v]) => {
|
3869
|
-
|
3940
|
+
loop(v, src[k]);
|
3870
3941
|
});
|
3871
3942
|
}
|
3872
3943
|
}
|
@@ -3886,132 +3957,6 @@ function restore_loop(o, src) {
|
|
3886
3957
|
|
3887
3958
|
|
3888
3959
|
|
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
3960
|
;// ./src/structures/erectObject.js
|
4016
3961
|
|
4017
3962
|
|
@@ -4157,6 +4102,8 @@ const queryStringify_escape = str => str.replace(/[\x00-\x20#%&+=\x7F]/g, c => m
|
|
4157
4102
|
|
4158
4103
|
|
4159
4104
|
|
4105
|
+
// export * from "./ramda/0.js"
|
4106
|
+
|
4160
4107
|
|
4161
4108
|
|
4162
4109
|
/******/ return __webpack_exports__;
|