sygnal 5.4.0 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +646 -0
- package/README.md +24 -9
- package/dist/astro/client.cjs.js +16 -9
- package/dist/astro/client.cjs.js.map +1 -1
- package/dist/astro/client.mjs +16 -9
- package/dist/astro/client.mjs.map +1 -1
- package/dist/astro/index.cjs.js +362 -91
- package/dist/astro/index.cjs.js.map +1 -1
- package/dist/astro/index.mjs +362 -92
- package/dist/astro/index.mjs.map +1 -1
- package/dist/astro/server.cjs.js +3396 -165
- package/dist/astro/server.cjs.js.map +1 -1
- package/dist/astro/server.mjs +3396 -165
- package/dist/astro/server.mjs.map +1 -1
- package/dist/devtools.cjs.js +1431 -0
- package/dist/devtools.cjs.js.map +1 -0
- package/dist/devtools.esm.js +1419 -0
- package/dist/devtools.esm.js.map +1 -0
- package/dist/diagnostics.cjs.js +3032 -296
- package/dist/diagnostics.cjs.js.map +1 -1
- package/dist/diagnostics.esm.js +3032 -296
- package/dist/diagnostics.esm.js.map +1 -1
- package/dist/element.cjs.js +230 -0
- package/dist/element.cjs.js.map +1 -0
- package/dist/element.esm.js +228 -0
- package/dist/element.esm.js.map +1 -0
- package/dist/guide/accessibility.md +257 -0
- package/dist/guide/adapters.md +221 -0
- package/dist/guide/behaviors.md +312 -0
- package/dist/guide/browser-sources.md +203 -0
- package/dist/guide/drag-and-drop.md +342 -0
- package/dist/guide/element-commands.md +306 -0
- package/dist/guide/error-boundaries.md +169 -0
- package/dist/guide/forms-reference.md +381 -0
- package/dist/guide/forms.md +250 -0
- package/dist/guide/http.md +299 -0
- package/dist/guide/inputs.md +173 -0
- package/dist/guide/persistence.md +245 -0
- package/dist/guide/recipes/carousel.md +155 -0
- package/dist/guide/recipes/charts.md +177 -0
- package/dist/guide/recipes/code-editor.md +135 -0
- package/dist/guide/recipes/data-grid.md +155 -0
- package/dist/guide/recipes/data-table.md +196 -0
- package/dist/guide/recipes/i18n.md +222 -0
- package/dist/guide/recipes/icons.md +115 -0
- package/dist/guide/recipes/overview.md +33 -0
- package/dist/guide/recipes/rich-text.md +154 -0
- package/dist/guide/resources.md +471 -0
- package/dist/guide/ssr.md +255 -0
- package/dist/guide/timers.md +178 -0
- package/dist/guide/ui/accordion.md +93 -0
- package/dist/guide/ui/combobox.md +144 -0
- package/dist/guide/ui/dialog.md +124 -0
- package/dist/guide/ui/disclosure.md +60 -0
- package/dist/guide/ui/menu.md +125 -0
- package/dist/guide/ui/overview.md +166 -0
- package/dist/guide/ui/popover.md +101 -0
- package/dist/guide/ui/select.md +114 -0
- package/dist/guide/ui/tabs.md +161 -0
- package/dist/guide/ui/toaster.md +152 -0
- package/dist/guide/ui/tooltip.md +103 -0
- package/dist/guide/undo.md +178 -0
- package/dist/guide/virtual-collections.md +183 -0
- package/dist/guide/web-components.md +179 -0
- package/dist/guide/widgets.md +217 -0
- package/dist/index.cjs.js +13178 -5769
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +2908 -276
- package/dist/index.esm.js +13149 -5779
- package/dist/index.esm.js.map +1 -1
- package/dist/jsx-dev-runtime.cjs.js +26 -334
- package/dist/jsx-dev-runtime.cjs.js.map +1 -1
- package/dist/jsx-dev-runtime.esm.js +19 -327
- package/dist/jsx-dev-runtime.esm.js.map +1 -1
- package/dist/jsx-runtime.cjs.js +26 -334
- package/dist/jsx-runtime.cjs.js.map +1 -1
- package/dist/jsx-runtime.esm.js +19 -327
- package/dist/jsx-runtime.esm.js.map +1 -1
- package/dist/jsx.cjs.js +10 -314
- package/dist/jsx.cjs.js.map +1 -1
- package/dist/jsx.esm.js +8 -315
- package/dist/jsx.esm.js.map +1 -1
- package/dist/react.cjs.js +117 -0
- package/dist/react.cjs.js.map +1 -0
- package/dist/react.esm.js +115 -0
- package/dist/react.esm.js.map +1 -0
- package/dist/shims/globalthis.cjs +20 -0
- package/dist/sygnal.min.js +1 -1
- package/dist/sygnal.min.js.map +1 -1
- package/dist/ui-combobox.cjs.js +169 -0
- package/dist/ui-combobox.cjs.js.map +1 -0
- package/dist/ui-combobox.esm.js +148 -0
- package/dist/ui-combobox.esm.js.map +1 -0
- package/dist/ui-menu.cjs.js +87 -0
- package/dist/ui-menu.cjs.js.map +1 -0
- package/dist/ui-menu.esm.js +66 -0
- package/dist/ui-menu.esm.js.map +1 -0
- package/dist/ui-select.cjs.js +104 -0
- package/dist/ui-select.cjs.js.map +1 -0
- package/dist/ui-select.esm.js +83 -0
- package/dist/ui-select.esm.js.map +1 -0
- package/dist/ui.cjs.js +738 -0
- package/dist/ui.cjs.js.map +1 -0
- package/dist/ui.esm.js +727 -0
- package/dist/ui.esm.js.map +1 -0
- package/dist/vike/ClientOnly.cjs.js +4 -14
- package/dist/vike/ClientOnly.cjs.js.map +1 -1
- package/dist/vike/ClientOnly.mjs +4 -14
- package/dist/vike/ClientOnly.mjs.map +1 -1
- package/dist/vike/{+config.js → config/+config.js} +9 -1
- package/dist/vike/config/+config.js.map +1 -0
- package/dist/vike/config/package.json +6 -0
- package/dist/vike/onRenderClient.cjs.js +165 -95
- package/dist/vike/onRenderClient.cjs.js.map +1 -1
- package/dist/vike/onRenderClient.mjs +165 -95
- package/dist/vike/onRenderClient.mjs.map +1 -1
- package/dist/vike/onRenderHtml.cjs.js +59 -24
- package/dist/vike/onRenderHtml.cjs.js.map +1 -1
- package/dist/vike/onRenderHtml.mjs +60 -25
- package/dist/vike/onRenderHtml.mjs.map +1 -1
- package/dist/vite/plugin.cjs.js +323 -88
- package/dist/vite/plugin.cjs.js.map +1 -1
- package/dist/vite/plugin.mjs +323 -89
- package/dist/vite/plugin.mjs.map +1 -1
- package/dist/zag.cjs.js +408 -0
- package/dist/zag.cjs.js.map +1 -0
- package/dist/zag.esm.js +405 -0
- package/dist/zag.esm.js.map +1 -0
- package/llms.txt +166 -103
- package/package.json +98 -14
- package/src/astro/client.ts +27 -16
- package/src/astro/index.d.ts +24 -0
- package/src/astro/index.ts +69 -3
- package/src/astro/server.ts +8 -2
- package/src/collection.ts +6 -93
- package/src/core/actions.ts +134 -0
- package/src/core/cell.ts +202 -0
- package/src/core/debug.ts +23 -0
- package/src/core/define.ts +242 -0
- package/src/core/hooks.ts +314 -0
- package/src/core/hosts/collection.ts +325 -0
- package/src/core/hosts/switchable.ts +146 -0
- package/src/core/instance.ts +592 -0
- package/src/core/markers/clientonly.ts +13 -0
- package/src/core/markers/lazy.ts +40 -0
- package/src/core/markers/portal.ts +96 -0
- package/src/core/markers/suspense.ts +41 -0
- package/src/core/markers/transition.ts +70 -0
- package/src/core/registry.ts +25 -0
- package/src/core/runtime.ts +573 -0
- package/src/core/statics.ts +104 -0
- package/src/core/teardown.ts +60 -0
- package/src/core/view.ts +37 -0
- package/src/cycle/dom/DocumentDOMSource.ts +13 -8
- package/src/cycle/dom/ElementFinder.ts +7 -9
- package/src/cycle/dom/EventDelegator.ts +174 -223
- package/src/cycle/dom/IsolateModule.ts +65 -35
- package/src/cycle/dom/MainDOMSource.ts +9 -2
- package/src/cycle/dom/PriorityQueue.ts +4 -2
- package/src/cycle/dom/SymbolTree.ts +18 -47
- package/src/cycle/dom/classNameModule.ts +9 -7
- package/src/cycle/dom/controlledInputModule.ts +23 -6
- package/src/cycle/dom/enrichEventStream.ts +25 -47
- package/src/cycle/dom/fragment.ts +7 -0
- package/src/cycle/dom/isolate.ts +30 -27
- package/src/cycle/dom/makeDOMDriver.ts +115 -56
- package/src/cycle/dom/mockDOMSource.ts +21 -1
- package/src/cycle/dom/modules.ts +16 -3
- package/src/cycle/dom/propsModule.ts +65 -0
- package/src/cycle/dom/selectModule.ts +22 -17
- package/src/cycle/dom/snabbdom.ts +1 -6
- package/src/cycle/dom/thunk.ts +3 -0
- package/src/cycle/dom/utils.ts +98 -0
- package/src/cycle/dom/viewTransition.ts +43 -0
- package/src/cycle/state/StateSource.ts +19 -3
- package/src/cycle/state/objIsEqual.ts +50 -0
- package/src/cycle/state/types.ts +0 -10
- package/src/defineComponent.ts +34 -0
- package/src/devtools.d.ts +151 -0
- package/src/devtools.ts +34 -0
- package/src/element.d.ts +59 -0
- package/src/element.ts +235 -0
- package/src/extra/backoff.ts +9 -0
- package/src/extra/behaviors.ts +169 -0
- package/src/extra/browserSignals.ts +23 -0
- package/src/extra/browserSources.ts +326 -0
- package/src/extra/command.ts +3 -3
- package/src/extra/controls.ts +47 -0
- package/src/extra/copyAsTest.ts +286 -0
- package/src/extra/devtools.ts +101 -31
- package/src/extra/devtoolsActions.ts +379 -0
- package/src/extra/devtoolsHook.ts +9 -0
- package/src/extra/devtoolsNext.ts +83 -0
- package/src/extra/diagnostics/checks/actionLog.ts +108 -0
- package/src/extra/diagnostics/checks/behaviors.ts +49 -0
- package/src/extra/diagnostics/checks/browserSources.ts +96 -0
- package/src/extra/diagnostics/checks/collections.ts +1 -1
- package/src/extra/diagnostics/checks/controls.ts +148 -0
- package/src/extra/diagnostics/checks/dataset.ts +57 -0
- package/src/extra/diagnostics/checks/dom.ts +20 -11
- package/src/extra/diagnostics/checks/elementCommands.ts +175 -0
- package/src/extra/diagnostics/checks/events.ts +17 -2
- package/src/extra/diagnostics/checks/fetch.ts +135 -0
- package/src/extra/diagnostics/checks/forms.ts +163 -0
- package/src/extra/diagnostics/checks/index.ts +97 -4
- package/src/extra/diagnostics/checks/inspect.ts +140 -32
- package/src/extra/diagnostics/checks/next.ts +417 -0
- package/src/extra/diagnostics/checks/persist.ts +54 -0
- package/src/extra/diagnostics/checks/props.ts +10 -5
- package/src/extra/diagnostics/checks/public.d.ts +98 -7
- package/src/extra/diagnostics/checks/replies.ts +128 -0
- package/src/extra/diagnostics/checks/router.ts +100 -0
- package/src/extra/diagnostics/checks/rxjsHints.ts +1 -1
- package/src/extra/diagnostics/checks/shared.ts +86 -2
- package/src/extra/diagnostics/checks/shorthand.ts +115 -0
- package/src/extra/diagnostics/checks/sortable.ts +129 -0
- package/src/extra/diagnostics/checks/state.ts +100 -7
- package/src/extra/diagnostics/checks/statics.ts +48 -0
- package/src/extra/diagnostics/checks/strict.ts +10 -67
- package/src/extra/diagnostics/checks/timers.ts +80 -0
- package/src/extra/diagnostics/checks/viewTransitions.ts +47 -0
- package/src/extra/diagnostics/checks/virtual.ts +73 -0
- package/src/extra/diagnostics/checks/widgets.ts +109 -0
- package/src/extra/diagnostics/checks/wiring.ts +66 -10
- package/src/extra/diagnostics/codes.ts +268 -23
- package/src/extra/diagnostics/index.ts +34 -9
- package/src/extra/diagnostics/legacy.ts +17 -0
- package/src/extra/driverFactories.ts +83 -19
- package/src/extra/elementCommands.ts +53 -0
- package/src/extra/fetchDriver.ts +519 -0
- package/src/extra/focusWithin.ts +27 -0
- package/src/extra/form.ts +268 -0
- package/src/extra/formHelpers.ts +139 -0
- package/src/extra/head.ts +106 -0
- package/src/extra/hmr.ts +2 -3
- package/src/extra/owned.ts +24 -0
- package/src/extra/pager.ts +50 -0
- package/src/extra/persist.ts +133 -0
- package/src/extra/pwa.ts +1 -1
- package/src/extra/queryCache.ts +107 -0
- package/src/extra/reducers.ts +1 -1
- package/src/extra/reduxDevtools.ts +92 -0
- package/src/extra/replies.ts +54 -0
- package/src/extra/router.ts +323 -0
- package/src/extra/run.ts +90 -217
- package/src/extra/selection.ts +76 -0
- package/src/extra/socketDriver.ts +265 -0
- package/src/extra/sortable.ts +377 -0
- package/src/extra/ssr.ts +427 -160
- package/src/extra/standardSchema.ts +27 -0
- package/src/extra/testing.ts +2433 -175
- package/src/extra/timers.ts +95 -0
- package/src/extra/undo.ts +261 -0
- package/src/extra/viewTransitions.ts +38 -0
- package/src/extra/virtual.ts +513 -0
- package/src/extra/widget.ts +201 -0
- package/src/index.d.ts +2631 -117
- package/src/index.ts +25 -4
- package/src/jsx-runtime.ts +15 -1
- package/src/jsx.ts +2 -1
- package/src/lazy.ts +50 -7
- package/src/portal.ts +3 -1
- package/src/pragma/index.ts +256 -133
- package/src/react-peers.d.ts +5 -0
- package/src/react.d.ts +43 -0
- package/src/react.ts +110 -0
- package/src/shared.ts +48 -0
- package/src/slot.ts +1 -1
- package/src/suspense.ts +3 -1
- package/src/switchable.ts +6 -121
- package/src/transition.ts +3 -1
- package/src/ui/accordion.ts +64 -0
- package/src/ui/dialog.ts +129 -0
- package/src/ui/disclosure.ts +35 -0
- package/src/ui/popover.ts +45 -0
- package/src/ui/shared.ts +94 -0
- package/src/ui/tabs.ts +82 -0
- package/src/ui/toaster.ts +198 -0
- package/src/ui/tooltip.ts +70 -0
- package/src/ui/zag/combobox.ts +115 -0
- package/src/ui/zag/menu.ts +40 -0
- package/src/ui/zag/select.ts +54 -0
- package/src/ui/zag/shared.ts +43 -0
- package/src/ui-combobox.d.ts +20 -0
- package/src/ui-combobox.ts +6 -0
- package/src/ui-menu.d.ts +30 -0
- package/src/ui-menu.ts +6 -0
- package/src/ui-select.d.ts +17 -0
- package/src/ui-select.ts +6 -0
- package/src/ui-zag-types.d.ts +42 -0
- package/src/ui.d.ts +208 -0
- package/src/ui.ts +15 -0
- package/src/vike/+config.ts +9 -1
- package/src/vike/ClientOnly.ts +1 -1
- package/src/vike/onRenderClient.ts +144 -96
- package/src/vike/onRenderHtml.ts +69 -26
- package/src/vike/types.ts +7 -1
- package/src/vite/globalthis-shim.ts +18 -0
- package/src/vite/globalthis.ts +56 -0
- package/src/vite/plugin.d.ts +22 -3
- package/src/vite/plugin.ts +222 -24
- package/src/zag.d.ts +64 -0
- package/src/zag.ts +238 -0
- package/dist/vike/+config.cjs.js +0 -66
- package/dist/vike/+config.cjs.js.map +0 -1
- package/dist/vike/+config.js.map +0 -1
- package/src/component.ts +0 -2301
- package/src/cycle/isolate/index.ts +0 -196
- package/src/cycle/run/index.ts +0 -151
- package/src/cycle/run/internals.ts +0 -143
- package/src/cycle/state/Collection.ts +0 -184
- package/src/cycle/state/index.ts +0 -5
- package/src/cycle/state/pickCombine.ts +0 -201
- package/src/cycle/state/pickMerge.ts +0 -122
- package/src/cycle/state/withState.ts +0 -47
- package/src/pragma/fn.ts +0 -55
package/dist/astro/server.cjs.js
CHANGED
|
@@ -2,6 +2,2968 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
var onError = require('virtual:sygnal/astro-on-error');
|
|
6
|
+
|
|
7
|
+
function _mergeNamespaces(n, m) {
|
|
8
|
+
m.forEach(function (e) {
|
|
9
|
+
e && typeof e !== 'string' && !Array.isArray(e) && Object.keys(e).forEach(function (k) {
|
|
10
|
+
if (k !== 'default' && !(k in n)) {
|
|
11
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
12
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () { return e[k]; }
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
return Object.freeze(n);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/*
|
|
23
|
+
* Tiny helpers shared by the core and the helper modules (behaviors, undo, the dev entry), kept
|
|
24
|
+
* out of the core so importing them never pulls it in.
|
|
25
|
+
*/
|
|
26
|
+
/** The "no change / send nothing" sentinel (a registered symbol: the same in every copy) */
|
|
27
|
+
/**
|
|
28
|
+
* PLAN-4 GS-9 / G-214: one part of a uid() path (a child's path or `id` prop, a Collection item
|
|
29
|
+
* key, a Switchable page name), encoded injectively into [A-Za-z0-9_]: letters and digits stay,
|
|
30
|
+
* anything else (including '_' and '-') becomes '_<UTF-16 code>_' ('0.2' → '0_46_2', 'a_b' →
|
|
31
|
+
* 'a_95_b'), so the '-' between parts is unambiguous too. renderToString encodes the same way
|
|
32
|
+
* (ssr.ts).
|
|
33
|
+
*/
|
|
34
|
+
const uidPart = (s) => (s + '').replace(/\W|_/g, c => '_' + c.charCodeAt(0) + '_');
|
|
35
|
+
/**
|
|
36
|
+
* PLAN-5 A-1: a Collection item's style with its view-transition name and class
|
|
37
|
+
* (`viewTransitionName="card"`): `card-<id>`, the id escaped as uidPart does (a valid CSS
|
|
38
|
+
* identifier, unique per id), and the class `card`; the item's own style wins, except its
|
|
39
|
+
* `undefined` values (G-418: no value is no override; snabbdom would leave the old one). The
|
|
40
|
+
* core's Collection host and SSR share it
|
|
41
|
+
*/
|
|
42
|
+
const vtStyle = (p, id, style) => {
|
|
43
|
+
const o = { viewTransitionName: p + '-' + uidPart(id), viewTransitionClass: p };
|
|
44
|
+
for (const k in style)
|
|
45
|
+
if (style[k] !== undefined)
|
|
46
|
+
o[k] = style[k];
|
|
47
|
+
return o;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
51
|
+
|
|
52
|
+
var xstream = {};
|
|
53
|
+
|
|
54
|
+
var ponyfill$1 = {};
|
|
55
|
+
|
|
56
|
+
(function (exports) {
|
|
57
|
+
|
|
58
|
+
Object.defineProperty(exports, "__esModule", {
|
|
59
|
+
value: true
|
|
60
|
+
});
|
|
61
|
+
exports['default'] = symbolObservablePonyfill;
|
|
62
|
+
function symbolObservablePonyfill(root) {
|
|
63
|
+
var result;
|
|
64
|
+
var _Symbol = root.Symbol;
|
|
65
|
+
|
|
66
|
+
if (typeof _Symbol === 'function') {
|
|
67
|
+
if (_Symbol.observable) {
|
|
68
|
+
result = _Symbol.observable;
|
|
69
|
+
} else {
|
|
70
|
+
|
|
71
|
+
// This just needs to be something that won't trample other user's Symbol.for use
|
|
72
|
+
// It also will guide people to the source of their issues, if this is problematic.
|
|
73
|
+
// META: It's a resource locator!
|
|
74
|
+
result = _Symbol['for']('https://github.com/benlesh/symbol-observable');
|
|
75
|
+
try {
|
|
76
|
+
_Symbol.observable = result;
|
|
77
|
+
} catch (err) {
|
|
78
|
+
// Do nothing. In some environments, users have frozen `Symbol` for security reasons,
|
|
79
|
+
// if it is frozen assigning to it will throw. In this case, we don't care, because
|
|
80
|
+
// they will need to use the returned value from the ponyfill.
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
} else {
|
|
84
|
+
result = '@@observable';
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return result;
|
|
88
|
+
}} (ponyfill$1));
|
|
89
|
+
|
|
90
|
+
var ponyfill = ponyfill$1;
|
|
91
|
+
|
|
92
|
+
var toStr$2 = Object.prototype.toString;
|
|
93
|
+
|
|
94
|
+
var isArguments = function isArguments(value) {
|
|
95
|
+
var str = toStr$2.call(value);
|
|
96
|
+
var isArgs = str === '[object Arguments]';
|
|
97
|
+
if (!isArgs) {
|
|
98
|
+
isArgs = str !== '[object Array]' &&
|
|
99
|
+
value !== null &&
|
|
100
|
+
typeof value === 'object' &&
|
|
101
|
+
typeof value.length === 'number' &&
|
|
102
|
+
value.length >= 0 &&
|
|
103
|
+
toStr$2.call(value.callee) === '[object Function]';
|
|
104
|
+
}
|
|
105
|
+
return isArgs;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
var implementation$5;
|
|
109
|
+
var hasRequiredImplementation;
|
|
110
|
+
|
|
111
|
+
function requireImplementation () {
|
|
112
|
+
if (hasRequiredImplementation) return implementation$5;
|
|
113
|
+
hasRequiredImplementation = 1;
|
|
114
|
+
|
|
115
|
+
var keysShim;
|
|
116
|
+
if (!Object.keys) {
|
|
117
|
+
// modified from https://github.com/es-shims/es5-shim
|
|
118
|
+
var has = Object.prototype.hasOwnProperty;
|
|
119
|
+
var toStr = Object.prototype.toString;
|
|
120
|
+
var isArgs = isArguments; // eslint-disable-line global-require
|
|
121
|
+
var isEnumerable = Object.prototype.propertyIsEnumerable;
|
|
122
|
+
var hasDontEnumBug = !isEnumerable.call({ toString: null }, 'toString');
|
|
123
|
+
var hasProtoEnumBug = isEnumerable.call(function () {}, 'prototype');
|
|
124
|
+
var dontEnums = [
|
|
125
|
+
'toString',
|
|
126
|
+
'toLocaleString',
|
|
127
|
+
'valueOf',
|
|
128
|
+
'hasOwnProperty',
|
|
129
|
+
'isPrototypeOf',
|
|
130
|
+
'propertyIsEnumerable',
|
|
131
|
+
'constructor'
|
|
132
|
+
];
|
|
133
|
+
var equalsConstructorPrototype = function (o) {
|
|
134
|
+
var ctor = o.constructor;
|
|
135
|
+
return ctor && ctor.prototype === o;
|
|
136
|
+
};
|
|
137
|
+
var excludedKeys = {
|
|
138
|
+
$applicationCache: true,
|
|
139
|
+
$console: true,
|
|
140
|
+
$external: true,
|
|
141
|
+
$frame: true,
|
|
142
|
+
$frameElement: true,
|
|
143
|
+
$frames: true,
|
|
144
|
+
$innerHeight: true,
|
|
145
|
+
$innerWidth: true,
|
|
146
|
+
$onmozfullscreenchange: true,
|
|
147
|
+
$onmozfullscreenerror: true,
|
|
148
|
+
$outerHeight: true,
|
|
149
|
+
$outerWidth: true,
|
|
150
|
+
$pageXOffset: true,
|
|
151
|
+
$pageYOffset: true,
|
|
152
|
+
$parent: true,
|
|
153
|
+
$scrollLeft: true,
|
|
154
|
+
$scrollTop: true,
|
|
155
|
+
$scrollX: true,
|
|
156
|
+
$scrollY: true,
|
|
157
|
+
$self: true,
|
|
158
|
+
$webkitIndexedDB: true,
|
|
159
|
+
$webkitStorageInfo: true,
|
|
160
|
+
$window: true
|
|
161
|
+
};
|
|
162
|
+
var hasAutomationEqualityBug = (function () {
|
|
163
|
+
/* global window */
|
|
164
|
+
if (typeof window === 'undefined') { return false; }
|
|
165
|
+
for (var k in window) {
|
|
166
|
+
try {
|
|
167
|
+
if (!excludedKeys['$' + k] && has.call(window, k) && window[k] !== null && typeof window[k] === 'object') {
|
|
168
|
+
try {
|
|
169
|
+
equalsConstructorPrototype(window[k]);
|
|
170
|
+
} catch (e) {
|
|
171
|
+
return true;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
} catch (e) {
|
|
175
|
+
return true;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return false;
|
|
179
|
+
}());
|
|
180
|
+
var equalsConstructorPrototypeIfNotBuggy = function (o) {
|
|
181
|
+
/* global window */
|
|
182
|
+
if (typeof window === 'undefined' || !hasAutomationEqualityBug) {
|
|
183
|
+
return equalsConstructorPrototype(o);
|
|
184
|
+
}
|
|
185
|
+
try {
|
|
186
|
+
return equalsConstructorPrototype(o);
|
|
187
|
+
} catch (e) {
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
keysShim = function keys(object) {
|
|
193
|
+
var isObject = object !== null && typeof object === 'object';
|
|
194
|
+
var isFunction = toStr.call(object) === '[object Function]';
|
|
195
|
+
var isArguments = isArgs(object);
|
|
196
|
+
var isString = isObject && toStr.call(object) === '[object String]';
|
|
197
|
+
var theKeys = [];
|
|
198
|
+
|
|
199
|
+
if (!isObject && !isFunction && !isArguments) {
|
|
200
|
+
throw new TypeError('Object.keys called on a non-object');
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
var skipProto = hasProtoEnumBug && isFunction;
|
|
204
|
+
if (isString && object.length > 0 && !has.call(object, 0)) {
|
|
205
|
+
for (var i = 0; i < object.length; ++i) {
|
|
206
|
+
theKeys.push(String(i));
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (isArguments && object.length > 0) {
|
|
211
|
+
for (var j = 0; j < object.length; ++j) {
|
|
212
|
+
theKeys.push(String(j));
|
|
213
|
+
}
|
|
214
|
+
} else {
|
|
215
|
+
for (var name in object) {
|
|
216
|
+
if (!(skipProto && name === 'prototype') && has.call(object, name)) {
|
|
217
|
+
theKeys.push(String(name));
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if (hasDontEnumBug) {
|
|
223
|
+
var skipConstructor = equalsConstructorPrototypeIfNotBuggy(object);
|
|
224
|
+
|
|
225
|
+
for (var k = 0; k < dontEnums.length; ++k) {
|
|
226
|
+
if (!(skipConstructor && dontEnums[k] === 'constructor') && has.call(object, dontEnums[k])) {
|
|
227
|
+
theKeys.push(dontEnums[k]);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return theKeys;
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
implementation$5 = keysShim;
|
|
235
|
+
return implementation$5;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
var slice$1 = Array.prototype.slice;
|
|
239
|
+
var isArgs = isArguments;
|
|
240
|
+
|
|
241
|
+
var origKeys = Object.keys;
|
|
242
|
+
var keysShim = origKeys ? function keys(o) { return origKeys(o); } : requireImplementation();
|
|
243
|
+
|
|
244
|
+
var originalKeys = Object.keys;
|
|
245
|
+
|
|
246
|
+
keysShim.shim = function shimObjectKeys() {
|
|
247
|
+
if (Object.keys) {
|
|
248
|
+
var keysWorksWithArguments = (function () {
|
|
249
|
+
// Safari 5.0 bug
|
|
250
|
+
var args = Object.keys(arguments);
|
|
251
|
+
return args && args.length === arguments.length;
|
|
252
|
+
}(1, 2));
|
|
253
|
+
if (!keysWorksWithArguments) {
|
|
254
|
+
Object.keys = function keys(object) { // eslint-disable-line func-name-matching
|
|
255
|
+
if (isArgs(object)) {
|
|
256
|
+
return originalKeys(slice$1.call(object));
|
|
257
|
+
}
|
|
258
|
+
return originalKeys(object);
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
} else {
|
|
262
|
+
Object.keys = keysShim;
|
|
263
|
+
}
|
|
264
|
+
return Object.keys || keysShim;
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
var objectKeys = keysShim;
|
|
268
|
+
|
|
269
|
+
/* eslint complexity: [2, 18], max-statements: [2, 33] */
|
|
270
|
+
var shams = function hasSymbols() {
|
|
271
|
+
if (typeof Symbol !== 'function' || typeof Object.getOwnPropertySymbols !== 'function') { return false; }
|
|
272
|
+
if (typeof Symbol.iterator === 'symbol') { return true; }
|
|
273
|
+
|
|
274
|
+
var obj = {};
|
|
275
|
+
var sym = Symbol('test');
|
|
276
|
+
var symObj = Object(sym);
|
|
277
|
+
if (typeof sym === 'string') { return false; }
|
|
278
|
+
|
|
279
|
+
if (Object.prototype.toString.call(sym) !== '[object Symbol]') { return false; }
|
|
280
|
+
if (Object.prototype.toString.call(symObj) !== '[object Symbol]') { return false; }
|
|
281
|
+
|
|
282
|
+
// temp disabled per https://github.com/ljharb/object.assign/issues/17
|
|
283
|
+
// if (sym instanceof Symbol) { return false; }
|
|
284
|
+
// temp disabled per https://github.com/WebReflection/get-own-property-symbols/issues/4
|
|
285
|
+
// if (!(symObj instanceof Symbol)) { return false; }
|
|
286
|
+
|
|
287
|
+
// if (typeof Symbol.prototype.toString !== 'function') { return false; }
|
|
288
|
+
// if (String(sym) !== Symbol.prototype.toString.call(sym)) { return false; }
|
|
289
|
+
|
|
290
|
+
var symVal = 42;
|
|
291
|
+
obj[sym] = symVal;
|
|
292
|
+
for (sym in obj) { return false; } // eslint-disable-line no-restricted-syntax, no-unreachable-loop
|
|
293
|
+
if (typeof Object.keys === 'function' && Object.keys(obj).length !== 0) { return false; }
|
|
294
|
+
|
|
295
|
+
if (typeof Object.getOwnPropertyNames === 'function' && Object.getOwnPropertyNames(obj).length !== 0) { return false; }
|
|
296
|
+
|
|
297
|
+
var syms = Object.getOwnPropertySymbols(obj);
|
|
298
|
+
if (syms.length !== 1 || syms[0] !== sym) { return false; }
|
|
299
|
+
|
|
300
|
+
if (!Object.prototype.propertyIsEnumerable.call(obj, sym)) { return false; }
|
|
301
|
+
|
|
302
|
+
if (typeof Object.getOwnPropertyDescriptor === 'function') {
|
|
303
|
+
var descriptor = Object.getOwnPropertyDescriptor(obj, sym);
|
|
304
|
+
if (descriptor.value !== symVal || descriptor.enumerable !== true) { return false; }
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
return true;
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
var origSymbol = typeof Symbol !== 'undefined' && Symbol;
|
|
311
|
+
var hasSymbolSham = shams;
|
|
312
|
+
|
|
313
|
+
var hasSymbols$2 = function hasNativeSymbols() {
|
|
314
|
+
if (typeof origSymbol !== 'function') { return false; }
|
|
315
|
+
if (typeof Symbol !== 'function') { return false; }
|
|
316
|
+
if (typeof origSymbol('foo') !== 'symbol') { return false; }
|
|
317
|
+
if (typeof Symbol('bar') !== 'symbol') { return false; }
|
|
318
|
+
|
|
319
|
+
return hasSymbolSham();
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
var test = {
|
|
323
|
+
foo: {}
|
|
324
|
+
};
|
|
325
|
+
|
|
326
|
+
var $Object = Object;
|
|
327
|
+
|
|
328
|
+
var hasProto$1 = function hasProto() {
|
|
329
|
+
return { __proto__: test }.foo === test.foo && !({ __proto__: null } instanceof $Object);
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
/* eslint no-invalid-this: 1 */
|
|
333
|
+
|
|
334
|
+
var ERROR_MESSAGE = 'Function.prototype.bind called on incompatible ';
|
|
335
|
+
var slice = Array.prototype.slice;
|
|
336
|
+
var toStr$1 = Object.prototype.toString;
|
|
337
|
+
var funcType = '[object Function]';
|
|
338
|
+
|
|
339
|
+
var implementation$4 = function bind(that) {
|
|
340
|
+
var target = this;
|
|
341
|
+
if (typeof target !== 'function' || toStr$1.call(target) !== funcType) {
|
|
342
|
+
throw new TypeError(ERROR_MESSAGE + target);
|
|
343
|
+
}
|
|
344
|
+
var args = slice.call(arguments, 1);
|
|
345
|
+
|
|
346
|
+
var bound;
|
|
347
|
+
var binder = function () {
|
|
348
|
+
if (this instanceof bound) {
|
|
349
|
+
var result = target.apply(
|
|
350
|
+
this,
|
|
351
|
+
args.concat(slice.call(arguments))
|
|
352
|
+
);
|
|
353
|
+
if (Object(result) === result) {
|
|
354
|
+
return result;
|
|
355
|
+
}
|
|
356
|
+
return this;
|
|
357
|
+
} else {
|
|
358
|
+
return target.apply(
|
|
359
|
+
that,
|
|
360
|
+
args.concat(slice.call(arguments))
|
|
361
|
+
);
|
|
362
|
+
}
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
var boundLength = Math.max(0, target.length - args.length);
|
|
366
|
+
var boundArgs = [];
|
|
367
|
+
for (var i = 0; i < boundLength; i++) {
|
|
368
|
+
boundArgs.push('$' + i);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
bound = Function('binder', 'return function (' + boundArgs.join(',') + '){ return binder.apply(this,arguments); }')(binder);
|
|
372
|
+
|
|
373
|
+
if (target.prototype) {
|
|
374
|
+
var Empty = function Empty() {};
|
|
375
|
+
Empty.prototype = target.prototype;
|
|
376
|
+
bound.prototype = new Empty();
|
|
377
|
+
Empty.prototype = null;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
return bound;
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
var implementation$3 = implementation$4;
|
|
384
|
+
|
|
385
|
+
var functionBind = Function.prototype.bind || implementation$3;
|
|
386
|
+
|
|
387
|
+
var bind$1 = functionBind;
|
|
388
|
+
|
|
389
|
+
var src = bind$1.call(Function.call, Object.prototype.hasOwnProperty);
|
|
390
|
+
|
|
391
|
+
var undefined$1;
|
|
392
|
+
|
|
393
|
+
var $SyntaxError = SyntaxError;
|
|
394
|
+
var $Function = Function;
|
|
395
|
+
var $TypeError = TypeError;
|
|
396
|
+
|
|
397
|
+
// eslint-disable-next-line consistent-return
|
|
398
|
+
var getEvalledConstructor = function (expressionSyntax) {
|
|
399
|
+
try {
|
|
400
|
+
return $Function('"use strict"; return (' + expressionSyntax + ').constructor;')();
|
|
401
|
+
} catch (e) {}
|
|
402
|
+
};
|
|
403
|
+
|
|
404
|
+
var $gOPD = Object.getOwnPropertyDescriptor;
|
|
405
|
+
if ($gOPD) {
|
|
406
|
+
try {
|
|
407
|
+
$gOPD({}, '');
|
|
408
|
+
} catch (e) {
|
|
409
|
+
$gOPD = null; // this is IE 8, which has a broken gOPD
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
var throwTypeError = function () {
|
|
414
|
+
throw new $TypeError();
|
|
415
|
+
};
|
|
416
|
+
var ThrowTypeError = $gOPD
|
|
417
|
+
? (function () {
|
|
418
|
+
try {
|
|
419
|
+
// eslint-disable-next-line no-unused-expressions, no-caller, no-restricted-properties
|
|
420
|
+
arguments.callee; // IE 8 does not throw here
|
|
421
|
+
return throwTypeError;
|
|
422
|
+
} catch (calleeThrows) {
|
|
423
|
+
try {
|
|
424
|
+
// IE 8 throws on Object.getOwnPropertyDescriptor(arguments, '')
|
|
425
|
+
return $gOPD(arguments, 'callee').get;
|
|
426
|
+
} catch (gOPDthrows) {
|
|
427
|
+
return throwTypeError;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
}())
|
|
431
|
+
: throwTypeError;
|
|
432
|
+
|
|
433
|
+
var hasSymbols$1 = hasSymbols$2();
|
|
434
|
+
var hasProto = hasProto$1();
|
|
435
|
+
|
|
436
|
+
var getProto = Object.getPrototypeOf || (
|
|
437
|
+
hasProto
|
|
438
|
+
? function (x) { return x.__proto__; } // eslint-disable-line no-proto
|
|
439
|
+
: null
|
|
440
|
+
);
|
|
441
|
+
|
|
442
|
+
var needsEval = {};
|
|
443
|
+
|
|
444
|
+
var TypedArray = typeof Uint8Array === 'undefined' || !getProto ? undefined$1 : getProto(Uint8Array);
|
|
445
|
+
|
|
446
|
+
var INTRINSICS = {
|
|
447
|
+
'%AggregateError%': typeof AggregateError === 'undefined' ? undefined$1 : AggregateError,
|
|
448
|
+
'%Array%': Array,
|
|
449
|
+
'%ArrayBuffer%': typeof ArrayBuffer === 'undefined' ? undefined$1 : ArrayBuffer,
|
|
450
|
+
'%ArrayIteratorPrototype%': hasSymbols$1 && getProto ? getProto([][Symbol.iterator]()) : undefined$1,
|
|
451
|
+
'%AsyncFromSyncIteratorPrototype%': undefined$1,
|
|
452
|
+
'%AsyncFunction%': needsEval,
|
|
453
|
+
'%AsyncGenerator%': needsEval,
|
|
454
|
+
'%AsyncGeneratorFunction%': needsEval,
|
|
455
|
+
'%AsyncIteratorPrototype%': needsEval,
|
|
456
|
+
'%Atomics%': typeof Atomics === 'undefined' ? undefined$1 : Atomics,
|
|
457
|
+
'%BigInt%': typeof BigInt === 'undefined' ? undefined$1 : BigInt,
|
|
458
|
+
'%BigInt64Array%': typeof BigInt64Array === 'undefined' ? undefined$1 : BigInt64Array,
|
|
459
|
+
'%BigUint64Array%': typeof BigUint64Array === 'undefined' ? undefined$1 : BigUint64Array,
|
|
460
|
+
'%Boolean%': Boolean,
|
|
461
|
+
'%DataView%': typeof DataView === 'undefined' ? undefined$1 : DataView,
|
|
462
|
+
'%Date%': Date,
|
|
463
|
+
'%decodeURI%': decodeURI,
|
|
464
|
+
'%decodeURIComponent%': decodeURIComponent,
|
|
465
|
+
'%encodeURI%': encodeURI,
|
|
466
|
+
'%encodeURIComponent%': encodeURIComponent,
|
|
467
|
+
'%Error%': Error,
|
|
468
|
+
'%eval%': eval, // eslint-disable-line no-eval
|
|
469
|
+
'%EvalError%': EvalError,
|
|
470
|
+
'%Float32Array%': typeof Float32Array === 'undefined' ? undefined$1 : Float32Array,
|
|
471
|
+
'%Float64Array%': typeof Float64Array === 'undefined' ? undefined$1 : Float64Array,
|
|
472
|
+
'%FinalizationRegistry%': typeof FinalizationRegistry === 'undefined' ? undefined$1 : FinalizationRegistry,
|
|
473
|
+
'%Function%': $Function,
|
|
474
|
+
'%GeneratorFunction%': needsEval,
|
|
475
|
+
'%Int8Array%': typeof Int8Array === 'undefined' ? undefined$1 : Int8Array,
|
|
476
|
+
'%Int16Array%': typeof Int16Array === 'undefined' ? undefined$1 : Int16Array,
|
|
477
|
+
'%Int32Array%': typeof Int32Array === 'undefined' ? undefined$1 : Int32Array,
|
|
478
|
+
'%isFinite%': isFinite,
|
|
479
|
+
'%isNaN%': isNaN,
|
|
480
|
+
'%IteratorPrototype%': hasSymbols$1 && getProto ? getProto(getProto([][Symbol.iterator]())) : undefined$1,
|
|
481
|
+
'%JSON%': typeof JSON === 'object' ? JSON : undefined$1,
|
|
482
|
+
'%Map%': typeof Map === 'undefined' ? undefined$1 : Map,
|
|
483
|
+
'%MapIteratorPrototype%': typeof Map === 'undefined' || !hasSymbols$1 || !getProto ? undefined$1 : getProto(new Map()[Symbol.iterator]()),
|
|
484
|
+
'%Math%': Math,
|
|
485
|
+
'%Number%': Number,
|
|
486
|
+
'%Object%': Object,
|
|
487
|
+
'%parseFloat%': parseFloat,
|
|
488
|
+
'%parseInt%': parseInt,
|
|
489
|
+
'%Promise%': typeof Promise === 'undefined' ? undefined$1 : Promise,
|
|
490
|
+
'%Proxy%': typeof Proxy === 'undefined' ? undefined$1 : Proxy,
|
|
491
|
+
'%RangeError%': RangeError,
|
|
492
|
+
'%ReferenceError%': ReferenceError,
|
|
493
|
+
'%Reflect%': typeof Reflect === 'undefined' ? undefined$1 : Reflect,
|
|
494
|
+
'%RegExp%': RegExp,
|
|
495
|
+
'%Set%': typeof Set === 'undefined' ? undefined$1 : Set,
|
|
496
|
+
'%SetIteratorPrototype%': typeof Set === 'undefined' || !hasSymbols$1 || !getProto ? undefined$1 : getProto(new Set()[Symbol.iterator]()),
|
|
497
|
+
'%SharedArrayBuffer%': typeof SharedArrayBuffer === 'undefined' ? undefined$1 : SharedArrayBuffer,
|
|
498
|
+
'%String%': String,
|
|
499
|
+
'%StringIteratorPrototype%': hasSymbols$1 && getProto ? getProto(''[Symbol.iterator]()) : undefined$1,
|
|
500
|
+
'%Symbol%': hasSymbols$1 ? Symbol : undefined$1,
|
|
501
|
+
'%SyntaxError%': $SyntaxError,
|
|
502
|
+
'%ThrowTypeError%': ThrowTypeError,
|
|
503
|
+
'%TypedArray%': TypedArray,
|
|
504
|
+
'%TypeError%': $TypeError,
|
|
505
|
+
'%Uint8Array%': typeof Uint8Array === 'undefined' ? undefined$1 : Uint8Array,
|
|
506
|
+
'%Uint8ClampedArray%': typeof Uint8ClampedArray === 'undefined' ? undefined$1 : Uint8ClampedArray,
|
|
507
|
+
'%Uint16Array%': typeof Uint16Array === 'undefined' ? undefined$1 : Uint16Array,
|
|
508
|
+
'%Uint32Array%': typeof Uint32Array === 'undefined' ? undefined$1 : Uint32Array,
|
|
509
|
+
'%URIError%': URIError,
|
|
510
|
+
'%WeakMap%': typeof WeakMap === 'undefined' ? undefined$1 : WeakMap,
|
|
511
|
+
'%WeakRef%': typeof WeakRef === 'undefined' ? undefined$1 : WeakRef,
|
|
512
|
+
'%WeakSet%': typeof WeakSet === 'undefined' ? undefined$1 : WeakSet
|
|
513
|
+
};
|
|
514
|
+
|
|
515
|
+
if (getProto) {
|
|
516
|
+
try {
|
|
517
|
+
null.error; // eslint-disable-line no-unused-expressions
|
|
518
|
+
} catch (e) {
|
|
519
|
+
// https://github.com/tc39/proposal-shadowrealm/pull/384#issuecomment-1364264229
|
|
520
|
+
var errorProto = getProto(getProto(e));
|
|
521
|
+
INTRINSICS['%Error.prototype%'] = errorProto;
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
var doEval = function doEval(name) {
|
|
526
|
+
var value;
|
|
527
|
+
if (name === '%AsyncFunction%') {
|
|
528
|
+
value = getEvalledConstructor('async function () {}');
|
|
529
|
+
} else if (name === '%GeneratorFunction%') {
|
|
530
|
+
value = getEvalledConstructor('function* () {}');
|
|
531
|
+
} else if (name === '%AsyncGeneratorFunction%') {
|
|
532
|
+
value = getEvalledConstructor('async function* () {}');
|
|
533
|
+
} else if (name === '%AsyncGenerator%') {
|
|
534
|
+
var fn = doEval('%AsyncGeneratorFunction%');
|
|
535
|
+
if (fn) {
|
|
536
|
+
value = fn.prototype;
|
|
537
|
+
}
|
|
538
|
+
} else if (name === '%AsyncIteratorPrototype%') {
|
|
539
|
+
var gen = doEval('%AsyncGenerator%');
|
|
540
|
+
if (gen && getProto) {
|
|
541
|
+
value = getProto(gen.prototype);
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
INTRINSICS[name] = value;
|
|
546
|
+
|
|
547
|
+
return value;
|
|
548
|
+
};
|
|
549
|
+
|
|
550
|
+
var LEGACY_ALIASES = {
|
|
551
|
+
'%ArrayBufferPrototype%': ['ArrayBuffer', 'prototype'],
|
|
552
|
+
'%ArrayPrototype%': ['Array', 'prototype'],
|
|
553
|
+
'%ArrayProto_entries%': ['Array', 'prototype', 'entries'],
|
|
554
|
+
'%ArrayProto_forEach%': ['Array', 'prototype', 'forEach'],
|
|
555
|
+
'%ArrayProto_keys%': ['Array', 'prototype', 'keys'],
|
|
556
|
+
'%ArrayProto_values%': ['Array', 'prototype', 'values'],
|
|
557
|
+
'%AsyncFunctionPrototype%': ['AsyncFunction', 'prototype'],
|
|
558
|
+
'%AsyncGenerator%': ['AsyncGeneratorFunction', 'prototype'],
|
|
559
|
+
'%AsyncGeneratorPrototype%': ['AsyncGeneratorFunction', 'prototype', 'prototype'],
|
|
560
|
+
'%BooleanPrototype%': ['Boolean', 'prototype'],
|
|
561
|
+
'%DataViewPrototype%': ['DataView', 'prototype'],
|
|
562
|
+
'%DatePrototype%': ['Date', 'prototype'],
|
|
563
|
+
'%ErrorPrototype%': ['Error', 'prototype'],
|
|
564
|
+
'%EvalErrorPrototype%': ['EvalError', 'prototype'],
|
|
565
|
+
'%Float32ArrayPrototype%': ['Float32Array', 'prototype'],
|
|
566
|
+
'%Float64ArrayPrototype%': ['Float64Array', 'prototype'],
|
|
567
|
+
'%FunctionPrototype%': ['Function', 'prototype'],
|
|
568
|
+
'%Generator%': ['GeneratorFunction', 'prototype'],
|
|
569
|
+
'%GeneratorPrototype%': ['GeneratorFunction', 'prototype', 'prototype'],
|
|
570
|
+
'%Int8ArrayPrototype%': ['Int8Array', 'prototype'],
|
|
571
|
+
'%Int16ArrayPrototype%': ['Int16Array', 'prototype'],
|
|
572
|
+
'%Int32ArrayPrototype%': ['Int32Array', 'prototype'],
|
|
573
|
+
'%JSONParse%': ['JSON', 'parse'],
|
|
574
|
+
'%JSONStringify%': ['JSON', 'stringify'],
|
|
575
|
+
'%MapPrototype%': ['Map', 'prototype'],
|
|
576
|
+
'%NumberPrototype%': ['Number', 'prototype'],
|
|
577
|
+
'%ObjectPrototype%': ['Object', 'prototype'],
|
|
578
|
+
'%ObjProto_toString%': ['Object', 'prototype', 'toString'],
|
|
579
|
+
'%ObjProto_valueOf%': ['Object', 'prototype', 'valueOf'],
|
|
580
|
+
'%PromisePrototype%': ['Promise', 'prototype'],
|
|
581
|
+
'%PromiseProto_then%': ['Promise', 'prototype', 'then'],
|
|
582
|
+
'%Promise_all%': ['Promise', 'all'],
|
|
583
|
+
'%Promise_reject%': ['Promise', 'reject'],
|
|
584
|
+
'%Promise_resolve%': ['Promise', 'resolve'],
|
|
585
|
+
'%RangeErrorPrototype%': ['RangeError', 'prototype'],
|
|
586
|
+
'%ReferenceErrorPrototype%': ['ReferenceError', 'prototype'],
|
|
587
|
+
'%RegExpPrototype%': ['RegExp', 'prototype'],
|
|
588
|
+
'%SetPrototype%': ['Set', 'prototype'],
|
|
589
|
+
'%SharedArrayBufferPrototype%': ['SharedArrayBuffer', 'prototype'],
|
|
590
|
+
'%StringPrototype%': ['String', 'prototype'],
|
|
591
|
+
'%SymbolPrototype%': ['Symbol', 'prototype'],
|
|
592
|
+
'%SyntaxErrorPrototype%': ['SyntaxError', 'prototype'],
|
|
593
|
+
'%TypedArrayPrototype%': ['TypedArray', 'prototype'],
|
|
594
|
+
'%TypeErrorPrototype%': ['TypeError', 'prototype'],
|
|
595
|
+
'%Uint8ArrayPrototype%': ['Uint8Array', 'prototype'],
|
|
596
|
+
'%Uint8ClampedArrayPrototype%': ['Uint8ClampedArray', 'prototype'],
|
|
597
|
+
'%Uint16ArrayPrototype%': ['Uint16Array', 'prototype'],
|
|
598
|
+
'%Uint32ArrayPrototype%': ['Uint32Array', 'prototype'],
|
|
599
|
+
'%URIErrorPrototype%': ['URIError', 'prototype'],
|
|
600
|
+
'%WeakMapPrototype%': ['WeakMap', 'prototype'],
|
|
601
|
+
'%WeakSetPrototype%': ['WeakSet', 'prototype']
|
|
602
|
+
};
|
|
603
|
+
|
|
604
|
+
var bind = functionBind;
|
|
605
|
+
var hasOwn = src;
|
|
606
|
+
var $concat = bind.call(Function.call, Array.prototype.concat);
|
|
607
|
+
var $spliceApply = bind.call(Function.apply, Array.prototype.splice);
|
|
608
|
+
var $replace = bind.call(Function.call, String.prototype.replace);
|
|
609
|
+
var $strSlice = bind.call(Function.call, String.prototype.slice);
|
|
610
|
+
var $exec = bind.call(Function.call, RegExp.prototype.exec);
|
|
611
|
+
|
|
612
|
+
/* adapted from https://github.com/lodash/lodash/blob/4.17.15/dist/lodash.js#L6735-L6744 */
|
|
613
|
+
var rePropName = /[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g;
|
|
614
|
+
var reEscapeChar = /\\(\\)?/g; /** Used to match backslashes in property paths. */
|
|
615
|
+
var stringToPath = function stringToPath(string) {
|
|
616
|
+
var first = $strSlice(string, 0, 1);
|
|
617
|
+
var last = $strSlice(string, -1);
|
|
618
|
+
if (first === '%' && last !== '%') {
|
|
619
|
+
throw new $SyntaxError('invalid intrinsic syntax, expected closing `%`');
|
|
620
|
+
} else if (last === '%' && first !== '%') {
|
|
621
|
+
throw new $SyntaxError('invalid intrinsic syntax, expected opening `%`');
|
|
622
|
+
}
|
|
623
|
+
var result = [];
|
|
624
|
+
$replace(string, rePropName, function (match, number, quote, subString) {
|
|
625
|
+
result[result.length] = quote ? $replace(subString, reEscapeChar, '$1') : number || match;
|
|
626
|
+
});
|
|
627
|
+
return result;
|
|
628
|
+
};
|
|
629
|
+
/* end adaptation */
|
|
630
|
+
|
|
631
|
+
var getBaseIntrinsic = function getBaseIntrinsic(name, allowMissing) {
|
|
632
|
+
var intrinsicName = name;
|
|
633
|
+
var alias;
|
|
634
|
+
if (hasOwn(LEGACY_ALIASES, intrinsicName)) {
|
|
635
|
+
alias = LEGACY_ALIASES[intrinsicName];
|
|
636
|
+
intrinsicName = '%' + alias[0] + '%';
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
if (hasOwn(INTRINSICS, intrinsicName)) {
|
|
640
|
+
var value = INTRINSICS[intrinsicName];
|
|
641
|
+
if (value === needsEval) {
|
|
642
|
+
value = doEval(intrinsicName);
|
|
643
|
+
}
|
|
644
|
+
if (typeof value === 'undefined' && !allowMissing) {
|
|
645
|
+
throw new $TypeError('intrinsic ' + name + ' exists, but is not available. Please file an issue!');
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
return {
|
|
649
|
+
alias: alias,
|
|
650
|
+
name: intrinsicName,
|
|
651
|
+
value: value
|
|
652
|
+
};
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
throw new $SyntaxError('intrinsic ' + name + ' does not exist!');
|
|
656
|
+
};
|
|
657
|
+
|
|
658
|
+
var getIntrinsic = function GetIntrinsic(name, allowMissing) {
|
|
659
|
+
if (typeof name !== 'string' || name.length === 0) {
|
|
660
|
+
throw new $TypeError('intrinsic name must be a non-empty string');
|
|
661
|
+
}
|
|
662
|
+
if (arguments.length > 1 && typeof allowMissing !== 'boolean') {
|
|
663
|
+
throw new $TypeError('"allowMissing" argument must be a boolean');
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
if ($exec(/^%?[^%]*%?$/, name) === null) {
|
|
667
|
+
throw new $SyntaxError('`%` may not be present anywhere but at the beginning and end of the intrinsic name');
|
|
668
|
+
}
|
|
669
|
+
var parts = stringToPath(name);
|
|
670
|
+
var intrinsicBaseName = parts.length > 0 ? parts[0] : '';
|
|
671
|
+
|
|
672
|
+
var intrinsic = getBaseIntrinsic('%' + intrinsicBaseName + '%', allowMissing);
|
|
673
|
+
var intrinsicRealName = intrinsic.name;
|
|
674
|
+
var value = intrinsic.value;
|
|
675
|
+
var skipFurtherCaching = false;
|
|
676
|
+
|
|
677
|
+
var alias = intrinsic.alias;
|
|
678
|
+
if (alias) {
|
|
679
|
+
intrinsicBaseName = alias[0];
|
|
680
|
+
$spliceApply(parts, $concat([0, 1], alias));
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
for (var i = 1, isOwn = true; i < parts.length; i += 1) {
|
|
684
|
+
var part = parts[i];
|
|
685
|
+
var first = $strSlice(part, 0, 1);
|
|
686
|
+
var last = $strSlice(part, -1);
|
|
687
|
+
if (
|
|
688
|
+
(
|
|
689
|
+
(first === '"' || first === "'" || first === '`')
|
|
690
|
+
|| (last === '"' || last === "'" || last === '`')
|
|
691
|
+
)
|
|
692
|
+
&& first !== last
|
|
693
|
+
) {
|
|
694
|
+
throw new $SyntaxError('property names with quotes must have matching quotes');
|
|
695
|
+
}
|
|
696
|
+
if (part === 'constructor' || !isOwn) {
|
|
697
|
+
skipFurtherCaching = true;
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
intrinsicBaseName += '.' + part;
|
|
701
|
+
intrinsicRealName = '%' + intrinsicBaseName + '%';
|
|
702
|
+
|
|
703
|
+
if (hasOwn(INTRINSICS, intrinsicRealName)) {
|
|
704
|
+
value = INTRINSICS[intrinsicRealName];
|
|
705
|
+
} else if (value != null) {
|
|
706
|
+
if (!(part in value)) {
|
|
707
|
+
if (!allowMissing) {
|
|
708
|
+
throw new $TypeError('base intrinsic for ' + name + ' exists, but the property is not available.');
|
|
709
|
+
}
|
|
710
|
+
return void undefined$1;
|
|
711
|
+
}
|
|
712
|
+
if ($gOPD && (i + 1) >= parts.length) {
|
|
713
|
+
var desc = $gOPD(value, part);
|
|
714
|
+
isOwn = !!desc;
|
|
715
|
+
|
|
716
|
+
// By convention, when a data property is converted to an accessor
|
|
717
|
+
// property to emulate a data property that does not suffer from
|
|
718
|
+
// the override mistake, that accessor's getter is marked with
|
|
719
|
+
// an `originalValue` property. Here, when we detect this, we
|
|
720
|
+
// uphold the illusion by pretending to see that original data
|
|
721
|
+
// property, i.e., returning the value rather than the getter
|
|
722
|
+
// itself.
|
|
723
|
+
if (isOwn && 'get' in desc && !('originalValue' in desc.get)) {
|
|
724
|
+
value = desc.get;
|
|
725
|
+
} else {
|
|
726
|
+
value = value[part];
|
|
727
|
+
}
|
|
728
|
+
} else {
|
|
729
|
+
isOwn = hasOwn(value, part);
|
|
730
|
+
value = value[part];
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
if (isOwn && !skipFurtherCaching) {
|
|
734
|
+
INTRINSICS[intrinsicRealName] = value;
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
return value;
|
|
739
|
+
};
|
|
740
|
+
|
|
741
|
+
var GetIntrinsic = getIntrinsic;
|
|
742
|
+
|
|
743
|
+
var $defineProperty = GetIntrinsic('%Object.defineProperty%', true);
|
|
744
|
+
|
|
745
|
+
var hasPropertyDescriptors$1 = function hasPropertyDescriptors() {
|
|
746
|
+
if ($defineProperty) {
|
|
747
|
+
try {
|
|
748
|
+
$defineProperty({}, 'a', { value: 1 });
|
|
749
|
+
return true;
|
|
750
|
+
} catch (e) {
|
|
751
|
+
// IE 8 has a broken defineProperty
|
|
752
|
+
return false;
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
return false;
|
|
756
|
+
};
|
|
757
|
+
|
|
758
|
+
hasPropertyDescriptors$1.hasArrayLengthDefineBug = function hasArrayLengthDefineBug() {
|
|
759
|
+
// node v0.6 has a bug where array lengths can be Set but not Defined
|
|
760
|
+
if (!hasPropertyDescriptors$1()) {
|
|
761
|
+
return null;
|
|
762
|
+
}
|
|
763
|
+
try {
|
|
764
|
+
return $defineProperty([], 'length', { value: 1 }).length !== 1;
|
|
765
|
+
} catch (e) {
|
|
766
|
+
// In Firefox 4-22, defining length on an array throws an exception.
|
|
767
|
+
return true;
|
|
768
|
+
}
|
|
769
|
+
};
|
|
770
|
+
|
|
771
|
+
var hasPropertyDescriptors_1 = hasPropertyDescriptors$1;
|
|
772
|
+
|
|
773
|
+
var keys = objectKeys;
|
|
774
|
+
var hasSymbols = typeof Symbol === 'function' && typeof Symbol('foo') === 'symbol';
|
|
775
|
+
|
|
776
|
+
var toStr = Object.prototype.toString;
|
|
777
|
+
var concat = Array.prototype.concat;
|
|
778
|
+
var origDefineProperty = Object.defineProperty;
|
|
779
|
+
|
|
780
|
+
var isFunction = function (fn) {
|
|
781
|
+
return typeof fn === 'function' && toStr.call(fn) === '[object Function]';
|
|
782
|
+
};
|
|
783
|
+
|
|
784
|
+
var hasPropertyDescriptors = hasPropertyDescriptors_1();
|
|
785
|
+
|
|
786
|
+
var supportsDescriptors = origDefineProperty && hasPropertyDescriptors;
|
|
787
|
+
|
|
788
|
+
var defineProperty = function (object, name, value, predicate) {
|
|
789
|
+
if (name in object) {
|
|
790
|
+
if (predicate === true) {
|
|
791
|
+
if (object[name] === value) {
|
|
792
|
+
return;
|
|
793
|
+
}
|
|
794
|
+
} else if (!isFunction(predicate) || !predicate()) {
|
|
795
|
+
return;
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
if (supportsDescriptors) {
|
|
799
|
+
origDefineProperty(object, name, {
|
|
800
|
+
configurable: true,
|
|
801
|
+
enumerable: false,
|
|
802
|
+
value: value,
|
|
803
|
+
writable: true
|
|
804
|
+
});
|
|
805
|
+
} else {
|
|
806
|
+
object[name] = value; // eslint-disable-line no-param-reassign
|
|
807
|
+
}
|
|
808
|
+
};
|
|
809
|
+
|
|
810
|
+
var defineProperties$1 = function (object, map) {
|
|
811
|
+
var predicates = arguments.length > 2 ? arguments[2] : {};
|
|
812
|
+
var props = keys(map);
|
|
813
|
+
if (hasSymbols) {
|
|
814
|
+
props = concat.call(props, Object.getOwnPropertySymbols(map));
|
|
815
|
+
}
|
|
816
|
+
for (var i = 0; i < props.length; i += 1) {
|
|
817
|
+
defineProperty(object, props[i], map[props[i]], predicates[props[i]]);
|
|
818
|
+
}
|
|
819
|
+
};
|
|
820
|
+
|
|
821
|
+
defineProperties$1.supportsDescriptors = !!supportsDescriptors;
|
|
822
|
+
|
|
823
|
+
var defineProperties_1 = defineProperties$1;
|
|
824
|
+
|
|
825
|
+
var implementation$2 = commonjsGlobal;
|
|
826
|
+
|
|
827
|
+
var implementation$1 = implementation$2;
|
|
828
|
+
|
|
829
|
+
var polyfill$1 = function getPolyfill() {
|
|
830
|
+
if (typeof commonjsGlobal !== 'object' || !commonjsGlobal || commonjsGlobal.Math !== Math || commonjsGlobal.Array !== Array) {
|
|
831
|
+
return implementation$1;
|
|
832
|
+
}
|
|
833
|
+
return commonjsGlobal;
|
|
834
|
+
};
|
|
835
|
+
|
|
836
|
+
var define = defineProperties_1;
|
|
837
|
+
var getPolyfill$1 = polyfill$1;
|
|
838
|
+
|
|
839
|
+
var shim$1 = function shimGlobal() {
|
|
840
|
+
var polyfill = getPolyfill$1();
|
|
841
|
+
if (define.supportsDescriptors) {
|
|
842
|
+
var descriptor = Object.getOwnPropertyDescriptor(polyfill, 'globalThis');
|
|
843
|
+
if (!descriptor || (descriptor.configurable && (descriptor.enumerable || !descriptor.writable || globalThis !== polyfill))) { // eslint-disable-line max-len
|
|
844
|
+
Object.defineProperty(polyfill, 'globalThis', {
|
|
845
|
+
configurable: true,
|
|
846
|
+
enumerable: false,
|
|
847
|
+
value: polyfill,
|
|
848
|
+
writable: true
|
|
849
|
+
});
|
|
850
|
+
}
|
|
851
|
+
} else if (typeof globalThis !== 'object' || globalThis !== polyfill) {
|
|
852
|
+
polyfill.globalThis = polyfill;
|
|
853
|
+
}
|
|
854
|
+
return polyfill;
|
|
855
|
+
};
|
|
856
|
+
|
|
857
|
+
var defineProperties = defineProperties_1;
|
|
858
|
+
|
|
859
|
+
var implementation = implementation$2;
|
|
860
|
+
var getPolyfill = polyfill$1;
|
|
861
|
+
var shim = shim$1;
|
|
862
|
+
|
|
863
|
+
var polyfill = getPolyfill();
|
|
864
|
+
|
|
865
|
+
var getGlobal = function () { return polyfill; };
|
|
866
|
+
|
|
867
|
+
defineProperties(getGlobal, {
|
|
868
|
+
getPolyfill: getPolyfill,
|
|
869
|
+
implementation: implementation,
|
|
870
|
+
shim: shim
|
|
871
|
+
});
|
|
872
|
+
|
|
873
|
+
var globalthis = getGlobal;
|
|
874
|
+
|
|
875
|
+
var __extends = (commonjsGlobal && commonjsGlobal.__extends) || (function () {
|
|
876
|
+
var extendStatics = function (d, b) {
|
|
877
|
+
extendStatics = Object.setPrototypeOf ||
|
|
878
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
879
|
+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
880
|
+
return extendStatics(d, b);
|
|
881
|
+
};
|
|
882
|
+
return function (d, b) {
|
|
883
|
+
extendStatics(d, b);
|
|
884
|
+
function __() { this.constructor = d; }
|
|
885
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
886
|
+
};
|
|
887
|
+
})();
|
|
888
|
+
Object.defineProperty(xstream, "__esModule", { value: true });
|
|
889
|
+
var NO_IL_1 = xstream.NO_IL = NO_1 = xstream.NO = MemoryStream_1 = xstream.MemoryStream = Stream_1 = xstream.Stream = void 0;
|
|
890
|
+
var ponyfill_1 = ponyfill;
|
|
891
|
+
var globalthis_1 = globalthis;
|
|
892
|
+
var $$observable = ponyfill_1.default(globalthis_1.getPolyfill());
|
|
893
|
+
var NO = {};
|
|
894
|
+
var NO_1 = xstream.NO = NO;
|
|
895
|
+
function noop() { }
|
|
896
|
+
function cp(a) {
|
|
897
|
+
var l = a.length;
|
|
898
|
+
var b = Array(l);
|
|
899
|
+
for (var i = 0; i < l; ++i)
|
|
900
|
+
b[i] = a[i];
|
|
901
|
+
return b;
|
|
902
|
+
}
|
|
903
|
+
function and(f1, f2) {
|
|
904
|
+
return function andFn(t) {
|
|
905
|
+
return f1(t) && f2(t);
|
|
906
|
+
};
|
|
907
|
+
}
|
|
908
|
+
function _try(c, t, u) {
|
|
909
|
+
try {
|
|
910
|
+
return c.f(t);
|
|
911
|
+
}
|
|
912
|
+
catch (e) {
|
|
913
|
+
u._e(e);
|
|
914
|
+
return NO;
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
var NO_IL = {
|
|
918
|
+
_n: noop,
|
|
919
|
+
_e: noop,
|
|
920
|
+
_c: noop,
|
|
921
|
+
};
|
|
922
|
+
NO_IL_1 = xstream.NO_IL = NO_IL;
|
|
923
|
+
// mutates the input
|
|
924
|
+
function internalizeProducer(producer) {
|
|
925
|
+
producer._start = function _start(il) {
|
|
926
|
+
il.next = il._n;
|
|
927
|
+
il.error = il._e;
|
|
928
|
+
il.complete = il._c;
|
|
929
|
+
this.start(il);
|
|
930
|
+
};
|
|
931
|
+
producer._stop = producer.stop;
|
|
932
|
+
}
|
|
933
|
+
var StreamSub = /** @class */ (function () {
|
|
934
|
+
function StreamSub(_stream, _listener) {
|
|
935
|
+
this._stream = _stream;
|
|
936
|
+
this._listener = _listener;
|
|
937
|
+
}
|
|
938
|
+
StreamSub.prototype.unsubscribe = function () {
|
|
939
|
+
this._stream._remove(this._listener);
|
|
940
|
+
};
|
|
941
|
+
return StreamSub;
|
|
942
|
+
}());
|
|
943
|
+
var Observer = /** @class */ (function () {
|
|
944
|
+
function Observer(_listener) {
|
|
945
|
+
this._listener = _listener;
|
|
946
|
+
}
|
|
947
|
+
Observer.prototype.next = function (value) {
|
|
948
|
+
this._listener._n(value);
|
|
949
|
+
};
|
|
950
|
+
Observer.prototype.error = function (err) {
|
|
951
|
+
this._listener._e(err);
|
|
952
|
+
};
|
|
953
|
+
Observer.prototype.complete = function () {
|
|
954
|
+
this._listener._c();
|
|
955
|
+
};
|
|
956
|
+
return Observer;
|
|
957
|
+
}());
|
|
958
|
+
var FromObservable = /** @class */ (function () {
|
|
959
|
+
function FromObservable(observable) {
|
|
960
|
+
this.type = 'fromObservable';
|
|
961
|
+
this.ins = observable;
|
|
962
|
+
this.active = false;
|
|
963
|
+
}
|
|
964
|
+
FromObservable.prototype._start = function (out) {
|
|
965
|
+
this.out = out;
|
|
966
|
+
this.active = true;
|
|
967
|
+
this._sub = this.ins.subscribe(new Observer(out));
|
|
968
|
+
if (!this.active)
|
|
969
|
+
this._sub.unsubscribe();
|
|
970
|
+
};
|
|
971
|
+
FromObservable.prototype._stop = function () {
|
|
972
|
+
if (this._sub)
|
|
973
|
+
this._sub.unsubscribe();
|
|
974
|
+
this.active = false;
|
|
975
|
+
};
|
|
976
|
+
return FromObservable;
|
|
977
|
+
}());
|
|
978
|
+
var Merge = /** @class */ (function () {
|
|
979
|
+
function Merge(insArr) {
|
|
980
|
+
this.type = 'merge';
|
|
981
|
+
this.insArr = insArr;
|
|
982
|
+
this.out = NO;
|
|
983
|
+
this.ac = 0;
|
|
984
|
+
}
|
|
985
|
+
Merge.prototype._start = function (out) {
|
|
986
|
+
this.out = out;
|
|
987
|
+
var s = this.insArr;
|
|
988
|
+
var L = s.length;
|
|
989
|
+
this.ac = L;
|
|
990
|
+
for (var i = 0; i < L; i++)
|
|
991
|
+
s[i]._add(this);
|
|
992
|
+
};
|
|
993
|
+
Merge.prototype._stop = function () {
|
|
994
|
+
var s = this.insArr;
|
|
995
|
+
var L = s.length;
|
|
996
|
+
for (var i = 0; i < L; i++)
|
|
997
|
+
s[i]._remove(this);
|
|
998
|
+
this.out = NO;
|
|
999
|
+
};
|
|
1000
|
+
Merge.prototype._n = function (t) {
|
|
1001
|
+
var u = this.out;
|
|
1002
|
+
if (u === NO)
|
|
1003
|
+
return;
|
|
1004
|
+
u._n(t);
|
|
1005
|
+
};
|
|
1006
|
+
Merge.prototype._e = function (err) {
|
|
1007
|
+
var u = this.out;
|
|
1008
|
+
if (u === NO)
|
|
1009
|
+
return;
|
|
1010
|
+
u._e(err);
|
|
1011
|
+
};
|
|
1012
|
+
Merge.prototype._c = function () {
|
|
1013
|
+
if (--this.ac <= 0) {
|
|
1014
|
+
var u = this.out;
|
|
1015
|
+
if (u === NO)
|
|
1016
|
+
return;
|
|
1017
|
+
u._c();
|
|
1018
|
+
}
|
|
1019
|
+
};
|
|
1020
|
+
return Merge;
|
|
1021
|
+
}());
|
|
1022
|
+
var CombineListener = /** @class */ (function () {
|
|
1023
|
+
function CombineListener(i, out, p) {
|
|
1024
|
+
this.i = i;
|
|
1025
|
+
this.out = out;
|
|
1026
|
+
this.p = p;
|
|
1027
|
+
p.ils.push(this);
|
|
1028
|
+
}
|
|
1029
|
+
CombineListener.prototype._n = function (t) {
|
|
1030
|
+
var p = this.p, out = this.out;
|
|
1031
|
+
if (out === NO)
|
|
1032
|
+
return;
|
|
1033
|
+
if (p.up(t, this.i)) {
|
|
1034
|
+
var b = cp(p.vals);
|
|
1035
|
+
out._n(b);
|
|
1036
|
+
}
|
|
1037
|
+
};
|
|
1038
|
+
CombineListener.prototype._e = function (err) {
|
|
1039
|
+
var out = this.out;
|
|
1040
|
+
if (out === NO)
|
|
1041
|
+
return;
|
|
1042
|
+
out._e(err);
|
|
1043
|
+
};
|
|
1044
|
+
CombineListener.prototype._c = function () {
|
|
1045
|
+
var p = this.p;
|
|
1046
|
+
if (p.out === NO)
|
|
1047
|
+
return;
|
|
1048
|
+
if (--p.Nc === 0)
|
|
1049
|
+
p.out._c();
|
|
1050
|
+
};
|
|
1051
|
+
return CombineListener;
|
|
1052
|
+
}());
|
|
1053
|
+
var Combine = /** @class */ (function () {
|
|
1054
|
+
function Combine(insArr) {
|
|
1055
|
+
this.type = 'combine';
|
|
1056
|
+
this.insArr = insArr;
|
|
1057
|
+
this.out = NO;
|
|
1058
|
+
this.ils = [];
|
|
1059
|
+
this.Nc = this.Nn = 0;
|
|
1060
|
+
this.vals = [];
|
|
1061
|
+
}
|
|
1062
|
+
Combine.prototype.up = function (t, i) {
|
|
1063
|
+
var v = this.vals[i];
|
|
1064
|
+
var Nn = !this.Nn ? 0 : v === NO ? --this.Nn : this.Nn;
|
|
1065
|
+
this.vals[i] = t;
|
|
1066
|
+
return Nn === 0;
|
|
1067
|
+
};
|
|
1068
|
+
Combine.prototype._start = function (out) {
|
|
1069
|
+
this.out = out;
|
|
1070
|
+
var s = this.insArr;
|
|
1071
|
+
var n = this.Nc = this.Nn = s.length;
|
|
1072
|
+
var vals = this.vals = new Array(n);
|
|
1073
|
+
if (n === 0) {
|
|
1074
|
+
out._n([]);
|
|
1075
|
+
out._c();
|
|
1076
|
+
}
|
|
1077
|
+
else {
|
|
1078
|
+
for (var i = 0; i < n; i++) {
|
|
1079
|
+
vals[i] = NO;
|
|
1080
|
+
s[i]._add(new CombineListener(i, out, this));
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
};
|
|
1084
|
+
Combine.prototype._stop = function () {
|
|
1085
|
+
var s = this.insArr;
|
|
1086
|
+
var n = s.length;
|
|
1087
|
+
var ils = this.ils;
|
|
1088
|
+
for (var i = 0; i < n; i++)
|
|
1089
|
+
s[i]._remove(ils[i]);
|
|
1090
|
+
this.out = NO;
|
|
1091
|
+
this.ils = [];
|
|
1092
|
+
this.vals = [];
|
|
1093
|
+
};
|
|
1094
|
+
return Combine;
|
|
1095
|
+
}());
|
|
1096
|
+
var FromArray = /** @class */ (function () {
|
|
1097
|
+
function FromArray(a) {
|
|
1098
|
+
this.type = 'fromArray';
|
|
1099
|
+
this.a = a;
|
|
1100
|
+
}
|
|
1101
|
+
FromArray.prototype._start = function (out) {
|
|
1102
|
+
var a = this.a;
|
|
1103
|
+
for (var i = 0, n = a.length; i < n; i++)
|
|
1104
|
+
out._n(a[i]);
|
|
1105
|
+
out._c();
|
|
1106
|
+
};
|
|
1107
|
+
FromArray.prototype._stop = function () {
|
|
1108
|
+
};
|
|
1109
|
+
return FromArray;
|
|
1110
|
+
}());
|
|
1111
|
+
var FromPromise = /** @class */ (function () {
|
|
1112
|
+
function FromPromise(p) {
|
|
1113
|
+
this.type = 'fromPromise';
|
|
1114
|
+
this.on = false;
|
|
1115
|
+
this.p = p;
|
|
1116
|
+
}
|
|
1117
|
+
FromPromise.prototype._start = function (out) {
|
|
1118
|
+
var prod = this;
|
|
1119
|
+
this.on = true;
|
|
1120
|
+
this.p.then(function (v) {
|
|
1121
|
+
if (prod.on) {
|
|
1122
|
+
out._n(v);
|
|
1123
|
+
out._c();
|
|
1124
|
+
}
|
|
1125
|
+
}, function (e) {
|
|
1126
|
+
out._e(e);
|
|
1127
|
+
}).then(noop, function (err) {
|
|
1128
|
+
setTimeout(function () { throw err; });
|
|
1129
|
+
});
|
|
1130
|
+
};
|
|
1131
|
+
FromPromise.prototype._stop = function () {
|
|
1132
|
+
this.on = false;
|
|
1133
|
+
};
|
|
1134
|
+
return FromPromise;
|
|
1135
|
+
}());
|
|
1136
|
+
var Periodic = /** @class */ (function () {
|
|
1137
|
+
function Periodic(period) {
|
|
1138
|
+
this.type = 'periodic';
|
|
1139
|
+
this.period = period;
|
|
1140
|
+
this.intervalID = -1;
|
|
1141
|
+
this.i = 0;
|
|
1142
|
+
}
|
|
1143
|
+
Periodic.prototype._start = function (out) {
|
|
1144
|
+
var self = this;
|
|
1145
|
+
function intervalHandler() { out._n(self.i++); }
|
|
1146
|
+
this.intervalID = setInterval(intervalHandler, this.period);
|
|
1147
|
+
};
|
|
1148
|
+
Periodic.prototype._stop = function () {
|
|
1149
|
+
if (this.intervalID !== -1)
|
|
1150
|
+
clearInterval(this.intervalID);
|
|
1151
|
+
this.intervalID = -1;
|
|
1152
|
+
this.i = 0;
|
|
1153
|
+
};
|
|
1154
|
+
return Periodic;
|
|
1155
|
+
}());
|
|
1156
|
+
var Debug = /** @class */ (function () {
|
|
1157
|
+
function Debug(ins, arg) {
|
|
1158
|
+
this.type = 'debug';
|
|
1159
|
+
this.ins = ins;
|
|
1160
|
+
this.out = NO;
|
|
1161
|
+
this.s = noop;
|
|
1162
|
+
this.l = '';
|
|
1163
|
+
if (typeof arg === 'string')
|
|
1164
|
+
this.l = arg;
|
|
1165
|
+
else if (typeof arg === 'function')
|
|
1166
|
+
this.s = arg;
|
|
1167
|
+
}
|
|
1168
|
+
Debug.prototype._start = function (out) {
|
|
1169
|
+
this.out = out;
|
|
1170
|
+
this.ins._add(this);
|
|
1171
|
+
};
|
|
1172
|
+
Debug.prototype._stop = function () {
|
|
1173
|
+
this.ins._remove(this);
|
|
1174
|
+
this.out = NO;
|
|
1175
|
+
};
|
|
1176
|
+
Debug.prototype._n = function (t) {
|
|
1177
|
+
var u = this.out;
|
|
1178
|
+
if (u === NO)
|
|
1179
|
+
return;
|
|
1180
|
+
var s = this.s, l = this.l;
|
|
1181
|
+
if (s !== noop) {
|
|
1182
|
+
try {
|
|
1183
|
+
s(t);
|
|
1184
|
+
}
|
|
1185
|
+
catch (e) {
|
|
1186
|
+
u._e(e);
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
else if (l)
|
|
1190
|
+
console.log(l + ':', t);
|
|
1191
|
+
else
|
|
1192
|
+
console.log(t);
|
|
1193
|
+
u._n(t);
|
|
1194
|
+
};
|
|
1195
|
+
Debug.prototype._e = function (err) {
|
|
1196
|
+
var u = this.out;
|
|
1197
|
+
if (u === NO)
|
|
1198
|
+
return;
|
|
1199
|
+
u._e(err);
|
|
1200
|
+
};
|
|
1201
|
+
Debug.prototype._c = function () {
|
|
1202
|
+
var u = this.out;
|
|
1203
|
+
if (u === NO)
|
|
1204
|
+
return;
|
|
1205
|
+
u._c();
|
|
1206
|
+
};
|
|
1207
|
+
return Debug;
|
|
1208
|
+
}());
|
|
1209
|
+
var Drop = /** @class */ (function () {
|
|
1210
|
+
function Drop(max, ins) {
|
|
1211
|
+
this.type = 'drop';
|
|
1212
|
+
this.ins = ins;
|
|
1213
|
+
this.out = NO;
|
|
1214
|
+
this.max = max;
|
|
1215
|
+
this.dropped = 0;
|
|
1216
|
+
}
|
|
1217
|
+
Drop.prototype._start = function (out) {
|
|
1218
|
+
this.out = out;
|
|
1219
|
+
this.dropped = 0;
|
|
1220
|
+
this.ins._add(this);
|
|
1221
|
+
};
|
|
1222
|
+
Drop.prototype._stop = function () {
|
|
1223
|
+
this.ins._remove(this);
|
|
1224
|
+
this.out = NO;
|
|
1225
|
+
};
|
|
1226
|
+
Drop.prototype._n = function (t) {
|
|
1227
|
+
var u = this.out;
|
|
1228
|
+
if (u === NO)
|
|
1229
|
+
return;
|
|
1230
|
+
if (this.dropped++ >= this.max)
|
|
1231
|
+
u._n(t);
|
|
1232
|
+
};
|
|
1233
|
+
Drop.prototype._e = function (err) {
|
|
1234
|
+
var u = this.out;
|
|
1235
|
+
if (u === NO)
|
|
1236
|
+
return;
|
|
1237
|
+
u._e(err);
|
|
1238
|
+
};
|
|
1239
|
+
Drop.prototype._c = function () {
|
|
1240
|
+
var u = this.out;
|
|
1241
|
+
if (u === NO)
|
|
1242
|
+
return;
|
|
1243
|
+
u._c();
|
|
1244
|
+
};
|
|
1245
|
+
return Drop;
|
|
1246
|
+
}());
|
|
1247
|
+
var EndWhenListener = /** @class */ (function () {
|
|
1248
|
+
function EndWhenListener(out, op) {
|
|
1249
|
+
this.out = out;
|
|
1250
|
+
this.op = op;
|
|
1251
|
+
}
|
|
1252
|
+
EndWhenListener.prototype._n = function () {
|
|
1253
|
+
this.op.end();
|
|
1254
|
+
};
|
|
1255
|
+
EndWhenListener.prototype._e = function (err) {
|
|
1256
|
+
this.out._e(err);
|
|
1257
|
+
};
|
|
1258
|
+
EndWhenListener.prototype._c = function () {
|
|
1259
|
+
this.op.end();
|
|
1260
|
+
};
|
|
1261
|
+
return EndWhenListener;
|
|
1262
|
+
}());
|
|
1263
|
+
var EndWhen = /** @class */ (function () {
|
|
1264
|
+
function EndWhen(o, ins) {
|
|
1265
|
+
this.type = 'endWhen';
|
|
1266
|
+
this.ins = ins;
|
|
1267
|
+
this.out = NO;
|
|
1268
|
+
this.o = o;
|
|
1269
|
+
this.oil = NO_IL;
|
|
1270
|
+
}
|
|
1271
|
+
EndWhen.prototype._start = function (out) {
|
|
1272
|
+
this.out = out;
|
|
1273
|
+
this.o._add(this.oil = new EndWhenListener(out, this));
|
|
1274
|
+
this.ins._add(this);
|
|
1275
|
+
};
|
|
1276
|
+
EndWhen.prototype._stop = function () {
|
|
1277
|
+
this.ins._remove(this);
|
|
1278
|
+
this.o._remove(this.oil);
|
|
1279
|
+
this.out = NO;
|
|
1280
|
+
this.oil = NO_IL;
|
|
1281
|
+
};
|
|
1282
|
+
EndWhen.prototype.end = function () {
|
|
1283
|
+
var u = this.out;
|
|
1284
|
+
if (u === NO)
|
|
1285
|
+
return;
|
|
1286
|
+
u._c();
|
|
1287
|
+
};
|
|
1288
|
+
EndWhen.prototype._n = function (t) {
|
|
1289
|
+
var u = this.out;
|
|
1290
|
+
if (u === NO)
|
|
1291
|
+
return;
|
|
1292
|
+
u._n(t);
|
|
1293
|
+
};
|
|
1294
|
+
EndWhen.prototype._e = function (err) {
|
|
1295
|
+
var u = this.out;
|
|
1296
|
+
if (u === NO)
|
|
1297
|
+
return;
|
|
1298
|
+
u._e(err);
|
|
1299
|
+
};
|
|
1300
|
+
EndWhen.prototype._c = function () {
|
|
1301
|
+
this.end();
|
|
1302
|
+
};
|
|
1303
|
+
return EndWhen;
|
|
1304
|
+
}());
|
|
1305
|
+
var Filter = /** @class */ (function () {
|
|
1306
|
+
function Filter(passes, ins) {
|
|
1307
|
+
this.type = 'filter';
|
|
1308
|
+
this.ins = ins;
|
|
1309
|
+
this.out = NO;
|
|
1310
|
+
this.f = passes;
|
|
1311
|
+
}
|
|
1312
|
+
Filter.prototype._start = function (out) {
|
|
1313
|
+
this.out = out;
|
|
1314
|
+
this.ins._add(this);
|
|
1315
|
+
};
|
|
1316
|
+
Filter.prototype._stop = function () {
|
|
1317
|
+
this.ins._remove(this);
|
|
1318
|
+
this.out = NO;
|
|
1319
|
+
};
|
|
1320
|
+
Filter.prototype._n = function (t) {
|
|
1321
|
+
var u = this.out;
|
|
1322
|
+
if (u === NO)
|
|
1323
|
+
return;
|
|
1324
|
+
var r = _try(this, t, u);
|
|
1325
|
+
if (r === NO || !r)
|
|
1326
|
+
return;
|
|
1327
|
+
u._n(t);
|
|
1328
|
+
};
|
|
1329
|
+
Filter.prototype._e = function (err) {
|
|
1330
|
+
var u = this.out;
|
|
1331
|
+
if (u === NO)
|
|
1332
|
+
return;
|
|
1333
|
+
u._e(err);
|
|
1334
|
+
};
|
|
1335
|
+
Filter.prototype._c = function () {
|
|
1336
|
+
var u = this.out;
|
|
1337
|
+
if (u === NO)
|
|
1338
|
+
return;
|
|
1339
|
+
u._c();
|
|
1340
|
+
};
|
|
1341
|
+
return Filter;
|
|
1342
|
+
}());
|
|
1343
|
+
var FlattenListener = /** @class */ (function () {
|
|
1344
|
+
function FlattenListener(out, op) {
|
|
1345
|
+
this.out = out;
|
|
1346
|
+
this.op = op;
|
|
1347
|
+
}
|
|
1348
|
+
FlattenListener.prototype._n = function (t) {
|
|
1349
|
+
this.out._n(t);
|
|
1350
|
+
};
|
|
1351
|
+
FlattenListener.prototype._e = function (err) {
|
|
1352
|
+
this.out._e(err);
|
|
1353
|
+
};
|
|
1354
|
+
FlattenListener.prototype._c = function () {
|
|
1355
|
+
this.op.inner = NO;
|
|
1356
|
+
this.op.less();
|
|
1357
|
+
};
|
|
1358
|
+
return FlattenListener;
|
|
1359
|
+
}());
|
|
1360
|
+
var Flatten = /** @class */ (function () {
|
|
1361
|
+
function Flatten(ins) {
|
|
1362
|
+
this.type = 'flatten';
|
|
1363
|
+
this.ins = ins;
|
|
1364
|
+
this.out = NO;
|
|
1365
|
+
this.open = true;
|
|
1366
|
+
this.inner = NO;
|
|
1367
|
+
this.il = NO_IL;
|
|
1368
|
+
}
|
|
1369
|
+
Flatten.prototype._start = function (out) {
|
|
1370
|
+
this.out = out;
|
|
1371
|
+
this.open = true;
|
|
1372
|
+
this.inner = NO;
|
|
1373
|
+
this.il = NO_IL;
|
|
1374
|
+
this.ins._add(this);
|
|
1375
|
+
};
|
|
1376
|
+
Flatten.prototype._stop = function () {
|
|
1377
|
+
this.ins._remove(this);
|
|
1378
|
+
if (this.inner !== NO)
|
|
1379
|
+
this.inner._remove(this.il);
|
|
1380
|
+
this.out = NO;
|
|
1381
|
+
this.open = true;
|
|
1382
|
+
this.inner = NO;
|
|
1383
|
+
this.il = NO_IL;
|
|
1384
|
+
};
|
|
1385
|
+
Flatten.prototype.less = function () {
|
|
1386
|
+
var u = this.out;
|
|
1387
|
+
if (u === NO)
|
|
1388
|
+
return;
|
|
1389
|
+
if (!this.open && this.inner === NO)
|
|
1390
|
+
u._c();
|
|
1391
|
+
};
|
|
1392
|
+
Flatten.prototype._n = function (s) {
|
|
1393
|
+
var u = this.out;
|
|
1394
|
+
if (u === NO)
|
|
1395
|
+
return;
|
|
1396
|
+
var _a = this, inner = _a.inner, il = _a.il;
|
|
1397
|
+
if (inner !== NO && il !== NO_IL)
|
|
1398
|
+
inner._remove(il);
|
|
1399
|
+
(this.inner = s)._add(this.il = new FlattenListener(u, this));
|
|
1400
|
+
};
|
|
1401
|
+
Flatten.prototype._e = function (err) {
|
|
1402
|
+
var u = this.out;
|
|
1403
|
+
if (u === NO)
|
|
1404
|
+
return;
|
|
1405
|
+
u._e(err);
|
|
1406
|
+
};
|
|
1407
|
+
Flatten.prototype._c = function () {
|
|
1408
|
+
this.open = false;
|
|
1409
|
+
this.less();
|
|
1410
|
+
};
|
|
1411
|
+
return Flatten;
|
|
1412
|
+
}());
|
|
1413
|
+
var Fold = /** @class */ (function () {
|
|
1414
|
+
function Fold(f, seed, ins) {
|
|
1415
|
+
var _this = this;
|
|
1416
|
+
this.type = 'fold';
|
|
1417
|
+
this.ins = ins;
|
|
1418
|
+
this.out = NO;
|
|
1419
|
+
this.f = function (t) { return f(_this.acc, t); };
|
|
1420
|
+
this.acc = this.seed = seed;
|
|
1421
|
+
}
|
|
1422
|
+
Fold.prototype._start = function (out) {
|
|
1423
|
+
this.out = out;
|
|
1424
|
+
this.acc = this.seed;
|
|
1425
|
+
out._n(this.acc);
|
|
1426
|
+
this.ins._add(this);
|
|
1427
|
+
};
|
|
1428
|
+
Fold.prototype._stop = function () {
|
|
1429
|
+
this.ins._remove(this);
|
|
1430
|
+
this.out = NO;
|
|
1431
|
+
this.acc = this.seed;
|
|
1432
|
+
};
|
|
1433
|
+
Fold.prototype._n = function (t) {
|
|
1434
|
+
var u = this.out;
|
|
1435
|
+
if (u === NO)
|
|
1436
|
+
return;
|
|
1437
|
+
var r = _try(this, t, u);
|
|
1438
|
+
if (r === NO)
|
|
1439
|
+
return;
|
|
1440
|
+
u._n(this.acc = r);
|
|
1441
|
+
};
|
|
1442
|
+
Fold.prototype._e = function (err) {
|
|
1443
|
+
var u = this.out;
|
|
1444
|
+
if (u === NO)
|
|
1445
|
+
return;
|
|
1446
|
+
u._e(err);
|
|
1447
|
+
};
|
|
1448
|
+
Fold.prototype._c = function () {
|
|
1449
|
+
var u = this.out;
|
|
1450
|
+
if (u === NO)
|
|
1451
|
+
return;
|
|
1452
|
+
u._c();
|
|
1453
|
+
};
|
|
1454
|
+
return Fold;
|
|
1455
|
+
}());
|
|
1456
|
+
var Last = /** @class */ (function () {
|
|
1457
|
+
function Last(ins) {
|
|
1458
|
+
this.type = 'last';
|
|
1459
|
+
this.ins = ins;
|
|
1460
|
+
this.out = NO;
|
|
1461
|
+
this.has = false;
|
|
1462
|
+
this.val = NO;
|
|
1463
|
+
}
|
|
1464
|
+
Last.prototype._start = function (out) {
|
|
1465
|
+
this.out = out;
|
|
1466
|
+
this.has = false;
|
|
1467
|
+
this.ins._add(this);
|
|
1468
|
+
};
|
|
1469
|
+
Last.prototype._stop = function () {
|
|
1470
|
+
this.ins._remove(this);
|
|
1471
|
+
this.out = NO;
|
|
1472
|
+
this.val = NO;
|
|
1473
|
+
};
|
|
1474
|
+
Last.prototype._n = function (t) {
|
|
1475
|
+
this.has = true;
|
|
1476
|
+
this.val = t;
|
|
1477
|
+
};
|
|
1478
|
+
Last.prototype._e = function (err) {
|
|
1479
|
+
var u = this.out;
|
|
1480
|
+
if (u === NO)
|
|
1481
|
+
return;
|
|
1482
|
+
u._e(err);
|
|
1483
|
+
};
|
|
1484
|
+
Last.prototype._c = function () {
|
|
1485
|
+
var u = this.out;
|
|
1486
|
+
if (u === NO)
|
|
1487
|
+
return;
|
|
1488
|
+
if (this.has) {
|
|
1489
|
+
u._n(this.val);
|
|
1490
|
+
u._c();
|
|
1491
|
+
}
|
|
1492
|
+
else
|
|
1493
|
+
u._e(new Error('last() failed because input stream completed'));
|
|
1494
|
+
};
|
|
1495
|
+
return Last;
|
|
1496
|
+
}());
|
|
1497
|
+
var MapOp = /** @class */ (function () {
|
|
1498
|
+
function MapOp(project, ins) {
|
|
1499
|
+
this.type = 'map';
|
|
1500
|
+
this.ins = ins;
|
|
1501
|
+
this.out = NO;
|
|
1502
|
+
this.f = project;
|
|
1503
|
+
}
|
|
1504
|
+
MapOp.prototype._start = function (out) {
|
|
1505
|
+
this.out = out;
|
|
1506
|
+
this.ins._add(this);
|
|
1507
|
+
};
|
|
1508
|
+
MapOp.prototype._stop = function () {
|
|
1509
|
+
this.ins._remove(this);
|
|
1510
|
+
this.out = NO;
|
|
1511
|
+
};
|
|
1512
|
+
MapOp.prototype._n = function (t) {
|
|
1513
|
+
var u = this.out;
|
|
1514
|
+
if (u === NO)
|
|
1515
|
+
return;
|
|
1516
|
+
var r = _try(this, t, u);
|
|
1517
|
+
if (r === NO)
|
|
1518
|
+
return;
|
|
1519
|
+
u._n(r);
|
|
1520
|
+
};
|
|
1521
|
+
MapOp.prototype._e = function (err) {
|
|
1522
|
+
var u = this.out;
|
|
1523
|
+
if (u === NO)
|
|
1524
|
+
return;
|
|
1525
|
+
u._e(err);
|
|
1526
|
+
};
|
|
1527
|
+
MapOp.prototype._c = function () {
|
|
1528
|
+
var u = this.out;
|
|
1529
|
+
if (u === NO)
|
|
1530
|
+
return;
|
|
1531
|
+
u._c();
|
|
1532
|
+
};
|
|
1533
|
+
return MapOp;
|
|
1534
|
+
}());
|
|
1535
|
+
var Remember = /** @class */ (function () {
|
|
1536
|
+
function Remember(ins) {
|
|
1537
|
+
this.type = 'remember';
|
|
1538
|
+
this.ins = ins;
|
|
1539
|
+
this.out = NO;
|
|
1540
|
+
}
|
|
1541
|
+
Remember.prototype._start = function (out) {
|
|
1542
|
+
this.out = out;
|
|
1543
|
+
this.ins._add(out);
|
|
1544
|
+
};
|
|
1545
|
+
Remember.prototype._stop = function () {
|
|
1546
|
+
this.ins._remove(this.out);
|
|
1547
|
+
this.out = NO;
|
|
1548
|
+
};
|
|
1549
|
+
return Remember;
|
|
1550
|
+
}());
|
|
1551
|
+
var ReplaceError = /** @class */ (function () {
|
|
1552
|
+
function ReplaceError(replacer, ins) {
|
|
1553
|
+
this.type = 'replaceError';
|
|
1554
|
+
this.ins = ins;
|
|
1555
|
+
this.out = NO;
|
|
1556
|
+
this.f = replacer;
|
|
1557
|
+
}
|
|
1558
|
+
ReplaceError.prototype._start = function (out) {
|
|
1559
|
+
this.out = out;
|
|
1560
|
+
this.ins._add(this);
|
|
1561
|
+
};
|
|
1562
|
+
ReplaceError.prototype._stop = function () {
|
|
1563
|
+
this.ins._remove(this);
|
|
1564
|
+
this.out = NO;
|
|
1565
|
+
};
|
|
1566
|
+
ReplaceError.prototype._n = function (t) {
|
|
1567
|
+
var u = this.out;
|
|
1568
|
+
if (u === NO)
|
|
1569
|
+
return;
|
|
1570
|
+
u._n(t);
|
|
1571
|
+
};
|
|
1572
|
+
ReplaceError.prototype._e = function (err) {
|
|
1573
|
+
var u = this.out;
|
|
1574
|
+
if (u === NO)
|
|
1575
|
+
return;
|
|
1576
|
+
try {
|
|
1577
|
+
this.ins._remove(this);
|
|
1578
|
+
(this.ins = this.f(err))._add(this);
|
|
1579
|
+
}
|
|
1580
|
+
catch (e) {
|
|
1581
|
+
u._e(e);
|
|
1582
|
+
}
|
|
1583
|
+
};
|
|
1584
|
+
ReplaceError.prototype._c = function () {
|
|
1585
|
+
var u = this.out;
|
|
1586
|
+
if (u === NO)
|
|
1587
|
+
return;
|
|
1588
|
+
u._c();
|
|
1589
|
+
};
|
|
1590
|
+
return ReplaceError;
|
|
1591
|
+
}());
|
|
1592
|
+
var StartWith = /** @class */ (function () {
|
|
1593
|
+
function StartWith(ins, val) {
|
|
1594
|
+
this.type = 'startWith';
|
|
1595
|
+
this.ins = ins;
|
|
1596
|
+
this.out = NO;
|
|
1597
|
+
this.val = val;
|
|
1598
|
+
}
|
|
1599
|
+
StartWith.prototype._start = function (out) {
|
|
1600
|
+
this.out = out;
|
|
1601
|
+
this.out._n(this.val);
|
|
1602
|
+
this.ins._add(out);
|
|
1603
|
+
};
|
|
1604
|
+
StartWith.prototype._stop = function () {
|
|
1605
|
+
this.ins._remove(this.out);
|
|
1606
|
+
this.out = NO;
|
|
1607
|
+
};
|
|
1608
|
+
return StartWith;
|
|
1609
|
+
}());
|
|
1610
|
+
var Take = /** @class */ (function () {
|
|
1611
|
+
function Take(max, ins) {
|
|
1612
|
+
this.type = 'take';
|
|
1613
|
+
this.ins = ins;
|
|
1614
|
+
this.out = NO;
|
|
1615
|
+
this.max = max;
|
|
1616
|
+
this.taken = 0;
|
|
1617
|
+
}
|
|
1618
|
+
Take.prototype._start = function (out) {
|
|
1619
|
+
this.out = out;
|
|
1620
|
+
this.taken = 0;
|
|
1621
|
+
if (this.max <= 0)
|
|
1622
|
+
out._c();
|
|
1623
|
+
else
|
|
1624
|
+
this.ins._add(this);
|
|
1625
|
+
};
|
|
1626
|
+
Take.prototype._stop = function () {
|
|
1627
|
+
this.ins._remove(this);
|
|
1628
|
+
this.out = NO;
|
|
1629
|
+
};
|
|
1630
|
+
Take.prototype._n = function (t) {
|
|
1631
|
+
var u = this.out;
|
|
1632
|
+
if (u === NO)
|
|
1633
|
+
return;
|
|
1634
|
+
var m = ++this.taken;
|
|
1635
|
+
if (m < this.max)
|
|
1636
|
+
u._n(t);
|
|
1637
|
+
else if (m === this.max) {
|
|
1638
|
+
u._n(t);
|
|
1639
|
+
u._c();
|
|
1640
|
+
}
|
|
1641
|
+
};
|
|
1642
|
+
Take.prototype._e = function (err) {
|
|
1643
|
+
var u = this.out;
|
|
1644
|
+
if (u === NO)
|
|
1645
|
+
return;
|
|
1646
|
+
u._e(err);
|
|
1647
|
+
};
|
|
1648
|
+
Take.prototype._c = function () {
|
|
1649
|
+
var u = this.out;
|
|
1650
|
+
if (u === NO)
|
|
1651
|
+
return;
|
|
1652
|
+
u._c();
|
|
1653
|
+
};
|
|
1654
|
+
return Take;
|
|
1655
|
+
}());
|
|
1656
|
+
var Stream = /** @class */ (function () {
|
|
1657
|
+
function Stream(producer) {
|
|
1658
|
+
this._prod = producer || NO;
|
|
1659
|
+
this._ils = [];
|
|
1660
|
+
this._stopID = NO;
|
|
1661
|
+
this._dl = NO;
|
|
1662
|
+
this._d = false;
|
|
1663
|
+
this._target = null;
|
|
1664
|
+
this._err = NO;
|
|
1665
|
+
}
|
|
1666
|
+
Stream.prototype._n = function (t) {
|
|
1667
|
+
var a = this._ils;
|
|
1668
|
+
var L = a.length;
|
|
1669
|
+
if (this._d)
|
|
1670
|
+
this._dl._n(t);
|
|
1671
|
+
if (L == 1)
|
|
1672
|
+
a[0]._n(t);
|
|
1673
|
+
else if (L == 0)
|
|
1674
|
+
return;
|
|
1675
|
+
else {
|
|
1676
|
+
var b = cp(a);
|
|
1677
|
+
for (var i = 0; i < L; i++)
|
|
1678
|
+
b[i]._n(t);
|
|
1679
|
+
}
|
|
1680
|
+
};
|
|
1681
|
+
Stream.prototype._e = function (err) {
|
|
1682
|
+
if (this._err !== NO)
|
|
1683
|
+
return;
|
|
1684
|
+
this._err = err;
|
|
1685
|
+
var a = this._ils;
|
|
1686
|
+
var L = a.length;
|
|
1687
|
+
this._x();
|
|
1688
|
+
if (this._d)
|
|
1689
|
+
this._dl._e(err);
|
|
1690
|
+
if (L == 1)
|
|
1691
|
+
a[0]._e(err);
|
|
1692
|
+
else if (L == 0)
|
|
1693
|
+
return;
|
|
1694
|
+
else {
|
|
1695
|
+
var b = cp(a);
|
|
1696
|
+
for (var i = 0; i < L; i++)
|
|
1697
|
+
b[i]._e(err);
|
|
1698
|
+
}
|
|
1699
|
+
if (!this._d && L == 0)
|
|
1700
|
+
throw this._err;
|
|
1701
|
+
};
|
|
1702
|
+
Stream.prototype._c = function () {
|
|
1703
|
+
var a = this._ils;
|
|
1704
|
+
var L = a.length;
|
|
1705
|
+
this._x();
|
|
1706
|
+
if (this._d)
|
|
1707
|
+
this._dl._c();
|
|
1708
|
+
if (L == 1)
|
|
1709
|
+
a[0]._c();
|
|
1710
|
+
else if (L == 0)
|
|
1711
|
+
return;
|
|
1712
|
+
else {
|
|
1713
|
+
var b = cp(a);
|
|
1714
|
+
for (var i = 0; i < L; i++)
|
|
1715
|
+
b[i]._c();
|
|
1716
|
+
}
|
|
1717
|
+
};
|
|
1718
|
+
Stream.prototype._x = function () {
|
|
1719
|
+
if (this._ils.length === 0)
|
|
1720
|
+
return;
|
|
1721
|
+
if (this._prod !== NO)
|
|
1722
|
+
this._prod._stop();
|
|
1723
|
+
this._err = NO;
|
|
1724
|
+
this._ils = [];
|
|
1725
|
+
};
|
|
1726
|
+
Stream.prototype._stopNow = function () {
|
|
1727
|
+
// WARNING: code that calls this method should
|
|
1728
|
+
// first check if this._prod is valid (not `NO`)
|
|
1729
|
+
this._prod._stop();
|
|
1730
|
+
this._err = NO;
|
|
1731
|
+
this._stopID = NO;
|
|
1732
|
+
};
|
|
1733
|
+
Stream.prototype._add = function (il) {
|
|
1734
|
+
var ta = this._target;
|
|
1735
|
+
if (ta)
|
|
1736
|
+
return ta._add(il);
|
|
1737
|
+
var a = this._ils;
|
|
1738
|
+
a.push(il);
|
|
1739
|
+
if (a.length > 1)
|
|
1740
|
+
return;
|
|
1741
|
+
if (this._stopID !== NO) {
|
|
1742
|
+
clearTimeout(this._stopID);
|
|
1743
|
+
this._stopID = NO;
|
|
1744
|
+
}
|
|
1745
|
+
else {
|
|
1746
|
+
var p = this._prod;
|
|
1747
|
+
if (p !== NO)
|
|
1748
|
+
p._start(this);
|
|
1749
|
+
}
|
|
1750
|
+
};
|
|
1751
|
+
Stream.prototype._remove = function (il) {
|
|
1752
|
+
var _this = this;
|
|
1753
|
+
var ta = this._target;
|
|
1754
|
+
if (ta)
|
|
1755
|
+
return ta._remove(il);
|
|
1756
|
+
var a = this._ils;
|
|
1757
|
+
var i = a.indexOf(il);
|
|
1758
|
+
if (i > -1) {
|
|
1759
|
+
a.splice(i, 1);
|
|
1760
|
+
if (this._prod !== NO && a.length <= 0) {
|
|
1761
|
+
this._err = NO;
|
|
1762
|
+
this._stopID = setTimeout(function () { return _this._stopNow(); });
|
|
1763
|
+
}
|
|
1764
|
+
else if (a.length === 1) {
|
|
1765
|
+
this._pruneCycles();
|
|
1766
|
+
}
|
|
1767
|
+
}
|
|
1768
|
+
};
|
|
1769
|
+
// If all paths stemming from `this` stream eventually end at `this`
|
|
1770
|
+
// stream, then we remove the single listener of `this` stream, to
|
|
1771
|
+
// force it to end its execution and dispose resources. This method
|
|
1772
|
+
// assumes as a precondition that this._ils has just one listener.
|
|
1773
|
+
Stream.prototype._pruneCycles = function () {
|
|
1774
|
+
if (this._hasNoSinks(this, []))
|
|
1775
|
+
this._remove(this._ils[0]);
|
|
1776
|
+
};
|
|
1777
|
+
// Checks whether *there is no* path starting from `x` that leads to an end
|
|
1778
|
+
// listener (sink) in the stream graph, following edges A->B where B is a
|
|
1779
|
+
// listener of A. This means these paths constitute a cycle somehow. Is given
|
|
1780
|
+
// a trace of all visited nodes so far.
|
|
1781
|
+
Stream.prototype._hasNoSinks = function (x, trace) {
|
|
1782
|
+
if (trace.indexOf(x) !== -1)
|
|
1783
|
+
return true;
|
|
1784
|
+
else if (x.out === this)
|
|
1785
|
+
return true;
|
|
1786
|
+
else if (x.out && x.out !== NO)
|
|
1787
|
+
return this._hasNoSinks(x.out, trace.concat(x));
|
|
1788
|
+
else if (x._ils) {
|
|
1789
|
+
for (var i = 0, N = x._ils.length; i < N; i++)
|
|
1790
|
+
if (!this._hasNoSinks(x._ils[i], trace.concat(x)))
|
|
1791
|
+
return false;
|
|
1792
|
+
return true;
|
|
1793
|
+
}
|
|
1794
|
+
else
|
|
1795
|
+
return false;
|
|
1796
|
+
};
|
|
1797
|
+
Stream.prototype.ctor = function () {
|
|
1798
|
+
return this instanceof MemoryStream ? MemoryStream : Stream;
|
|
1799
|
+
};
|
|
1800
|
+
/**
|
|
1801
|
+
* Adds a Listener to the Stream.
|
|
1802
|
+
*
|
|
1803
|
+
* @param {Listener} listener
|
|
1804
|
+
*/
|
|
1805
|
+
Stream.prototype.addListener = function (listener) {
|
|
1806
|
+
listener._n = listener.next || noop;
|
|
1807
|
+
listener._e = listener.error || noop;
|
|
1808
|
+
listener._c = listener.complete || noop;
|
|
1809
|
+
this._add(listener);
|
|
1810
|
+
};
|
|
1811
|
+
/**
|
|
1812
|
+
* Removes a Listener from the Stream, assuming the Listener was added to it.
|
|
1813
|
+
*
|
|
1814
|
+
* @param {Listener<T>} listener
|
|
1815
|
+
*/
|
|
1816
|
+
Stream.prototype.removeListener = function (listener) {
|
|
1817
|
+
this._remove(listener);
|
|
1818
|
+
};
|
|
1819
|
+
/**
|
|
1820
|
+
* Adds a Listener to the Stream returning a Subscription to remove that
|
|
1821
|
+
* listener.
|
|
1822
|
+
*
|
|
1823
|
+
* @param {Listener} listener
|
|
1824
|
+
* @returns {Subscription}
|
|
1825
|
+
*/
|
|
1826
|
+
Stream.prototype.subscribe = function (listener) {
|
|
1827
|
+
this.addListener(listener);
|
|
1828
|
+
return new StreamSub(this, listener);
|
|
1829
|
+
};
|
|
1830
|
+
/**
|
|
1831
|
+
* Add interop between most.js and RxJS 5
|
|
1832
|
+
*
|
|
1833
|
+
* @returns {Stream}
|
|
1834
|
+
*/
|
|
1835
|
+
Stream.prototype[$$observable] = function () {
|
|
1836
|
+
return this;
|
|
1837
|
+
};
|
|
1838
|
+
/**
|
|
1839
|
+
* Creates a new Stream given a Producer.
|
|
1840
|
+
*
|
|
1841
|
+
* @factory true
|
|
1842
|
+
* @param {Producer} producer An optional Producer that dictates how to
|
|
1843
|
+
* start, generate events, and stop the Stream.
|
|
1844
|
+
* @return {Stream}
|
|
1845
|
+
*/
|
|
1846
|
+
Stream.create = function (producer) {
|
|
1847
|
+
if (producer) {
|
|
1848
|
+
if (typeof producer.start !== 'function'
|
|
1849
|
+
|| typeof producer.stop !== 'function')
|
|
1850
|
+
throw new Error('producer requires both start and stop functions');
|
|
1851
|
+
internalizeProducer(producer); // mutates the input
|
|
1852
|
+
}
|
|
1853
|
+
return new Stream(producer);
|
|
1854
|
+
};
|
|
1855
|
+
/**
|
|
1856
|
+
* Creates a new MemoryStream given a Producer.
|
|
1857
|
+
*
|
|
1858
|
+
* @factory true
|
|
1859
|
+
* @param {Producer} producer An optional Producer that dictates how to
|
|
1860
|
+
* start, generate events, and stop the Stream.
|
|
1861
|
+
* @return {MemoryStream}
|
|
1862
|
+
*/
|
|
1863
|
+
Stream.createWithMemory = function (producer) {
|
|
1864
|
+
if (producer)
|
|
1865
|
+
internalizeProducer(producer); // mutates the input
|
|
1866
|
+
return new MemoryStream(producer);
|
|
1867
|
+
};
|
|
1868
|
+
/**
|
|
1869
|
+
* Creates a Stream that does nothing when started. It never emits any event.
|
|
1870
|
+
*
|
|
1871
|
+
* Marble diagram:
|
|
1872
|
+
*
|
|
1873
|
+
* ```text
|
|
1874
|
+
* never
|
|
1875
|
+
* -----------------------
|
|
1876
|
+
* ```
|
|
1877
|
+
*
|
|
1878
|
+
* @factory true
|
|
1879
|
+
* @return {Stream}
|
|
1880
|
+
*/
|
|
1881
|
+
Stream.never = function () {
|
|
1882
|
+
return new Stream({ _start: noop, _stop: noop });
|
|
1883
|
+
};
|
|
1884
|
+
/**
|
|
1885
|
+
* Creates a Stream that immediately emits the "complete" notification when
|
|
1886
|
+
* started, and that's it.
|
|
1887
|
+
*
|
|
1888
|
+
* Marble diagram:
|
|
1889
|
+
*
|
|
1890
|
+
* ```text
|
|
1891
|
+
* empty
|
|
1892
|
+
* -|
|
|
1893
|
+
* ```
|
|
1894
|
+
*
|
|
1895
|
+
* @factory true
|
|
1896
|
+
* @return {Stream}
|
|
1897
|
+
*/
|
|
1898
|
+
Stream.empty = function () {
|
|
1899
|
+
return new Stream({
|
|
1900
|
+
_start: function (il) { il._c(); },
|
|
1901
|
+
_stop: noop,
|
|
1902
|
+
});
|
|
1903
|
+
};
|
|
1904
|
+
/**
|
|
1905
|
+
* Creates a Stream that immediately emits an "error" notification with the
|
|
1906
|
+
* value you passed as the `error` argument when the stream starts, and that's
|
|
1907
|
+
* it.
|
|
1908
|
+
*
|
|
1909
|
+
* Marble diagram:
|
|
1910
|
+
*
|
|
1911
|
+
* ```text
|
|
1912
|
+
* throw(X)
|
|
1913
|
+
* -X
|
|
1914
|
+
* ```
|
|
1915
|
+
*
|
|
1916
|
+
* @factory true
|
|
1917
|
+
* @param error The error event to emit on the created stream.
|
|
1918
|
+
* @return {Stream}
|
|
1919
|
+
*/
|
|
1920
|
+
Stream.throw = function (error) {
|
|
1921
|
+
return new Stream({
|
|
1922
|
+
_start: function (il) { il._e(error); },
|
|
1923
|
+
_stop: noop,
|
|
1924
|
+
});
|
|
1925
|
+
};
|
|
1926
|
+
/**
|
|
1927
|
+
* Creates a stream from an Array, Promise, or an Observable.
|
|
1928
|
+
*
|
|
1929
|
+
* @factory true
|
|
1930
|
+
* @param {Array|PromiseLike|Observable} input The input to make a stream from.
|
|
1931
|
+
* @return {Stream}
|
|
1932
|
+
*/
|
|
1933
|
+
Stream.from = function (input) {
|
|
1934
|
+
if (typeof input[$$observable] === 'function')
|
|
1935
|
+
return Stream.fromObservable(input);
|
|
1936
|
+
else if (typeof input.then === 'function')
|
|
1937
|
+
return Stream.fromPromise(input);
|
|
1938
|
+
else if (Array.isArray(input))
|
|
1939
|
+
return Stream.fromArray(input);
|
|
1940
|
+
throw new TypeError("Type of input to from() must be an Array, Promise, or Observable");
|
|
1941
|
+
};
|
|
1942
|
+
/**
|
|
1943
|
+
* Creates a Stream that immediately emits the arguments that you give to
|
|
1944
|
+
* *of*, then completes.
|
|
1945
|
+
*
|
|
1946
|
+
* Marble diagram:
|
|
1947
|
+
*
|
|
1948
|
+
* ```text
|
|
1949
|
+
* of(1,2,3)
|
|
1950
|
+
* 123|
|
|
1951
|
+
* ```
|
|
1952
|
+
*
|
|
1953
|
+
* @factory true
|
|
1954
|
+
* @param a The first value you want to emit as an event on the stream.
|
|
1955
|
+
* @param b The second value you want to emit as an event on the stream. One
|
|
1956
|
+
* or more of these values may be given as arguments.
|
|
1957
|
+
* @return {Stream}
|
|
1958
|
+
*/
|
|
1959
|
+
Stream.of = function () {
|
|
1960
|
+
var items = [];
|
|
1961
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1962
|
+
items[_i] = arguments[_i];
|
|
1963
|
+
}
|
|
1964
|
+
return Stream.fromArray(items);
|
|
1965
|
+
};
|
|
1966
|
+
/**
|
|
1967
|
+
* Converts an array to a stream. The returned stream will emit synchronously
|
|
1968
|
+
* all the items in the array, and then complete.
|
|
1969
|
+
*
|
|
1970
|
+
* Marble diagram:
|
|
1971
|
+
*
|
|
1972
|
+
* ```text
|
|
1973
|
+
* fromArray([1,2,3])
|
|
1974
|
+
* 123|
|
|
1975
|
+
* ```
|
|
1976
|
+
*
|
|
1977
|
+
* @factory true
|
|
1978
|
+
* @param {Array} array The array to be converted as a stream.
|
|
1979
|
+
* @return {Stream}
|
|
1980
|
+
*/
|
|
1981
|
+
Stream.fromArray = function (array) {
|
|
1982
|
+
return new Stream(new FromArray(array));
|
|
1983
|
+
};
|
|
1984
|
+
/**
|
|
1985
|
+
* Converts a promise to a stream. The returned stream will emit the resolved
|
|
1986
|
+
* value of the promise, and then complete. However, if the promise is
|
|
1987
|
+
* rejected, the stream will emit the corresponding error.
|
|
1988
|
+
*
|
|
1989
|
+
* Marble diagram:
|
|
1990
|
+
*
|
|
1991
|
+
* ```text
|
|
1992
|
+
* fromPromise( ----42 )
|
|
1993
|
+
* -----------------42|
|
|
1994
|
+
* ```
|
|
1995
|
+
*
|
|
1996
|
+
* @factory true
|
|
1997
|
+
* @param {PromiseLike} promise The promise to be converted as a stream.
|
|
1998
|
+
* @return {Stream}
|
|
1999
|
+
*/
|
|
2000
|
+
Stream.fromPromise = function (promise) {
|
|
2001
|
+
return new Stream(new FromPromise(promise));
|
|
2002
|
+
};
|
|
2003
|
+
/**
|
|
2004
|
+
* Converts an Observable into a Stream.
|
|
2005
|
+
*
|
|
2006
|
+
* @factory true
|
|
2007
|
+
* @param {any} observable The observable to be converted as a stream.
|
|
2008
|
+
* @return {Stream}
|
|
2009
|
+
*/
|
|
2010
|
+
Stream.fromObservable = function (obs) {
|
|
2011
|
+
if (obs.endWhen !== undefined)
|
|
2012
|
+
return obs;
|
|
2013
|
+
var o = typeof obs[$$observable] === 'function' ? obs[$$observable]() : obs;
|
|
2014
|
+
return new Stream(new FromObservable(o));
|
|
2015
|
+
};
|
|
2016
|
+
/**
|
|
2017
|
+
* Creates a stream that periodically emits incremental numbers, every
|
|
2018
|
+
* `period` milliseconds.
|
|
2019
|
+
*
|
|
2020
|
+
* Marble diagram:
|
|
2021
|
+
*
|
|
2022
|
+
* ```text
|
|
2023
|
+
* periodic(1000)
|
|
2024
|
+
* ---0---1---2---3---4---...
|
|
2025
|
+
* ```
|
|
2026
|
+
*
|
|
2027
|
+
* @factory true
|
|
2028
|
+
* @param {number} period The interval in milliseconds to use as a rate of
|
|
2029
|
+
* emission.
|
|
2030
|
+
* @return {Stream}
|
|
2031
|
+
*/
|
|
2032
|
+
Stream.periodic = function (period) {
|
|
2033
|
+
return new Stream(new Periodic(period));
|
|
2034
|
+
};
|
|
2035
|
+
Stream.prototype._map = function (project) {
|
|
2036
|
+
return new (this.ctor())(new MapOp(project, this));
|
|
2037
|
+
};
|
|
2038
|
+
/**
|
|
2039
|
+
* Transforms each event from the input Stream through a `project` function,
|
|
2040
|
+
* to get a Stream that emits those transformed events.
|
|
2041
|
+
*
|
|
2042
|
+
* Marble diagram:
|
|
2043
|
+
*
|
|
2044
|
+
* ```text
|
|
2045
|
+
* --1---3--5-----7------
|
|
2046
|
+
* map(i => i * 10)
|
|
2047
|
+
* --10--30-50----70-----
|
|
2048
|
+
* ```
|
|
2049
|
+
*
|
|
2050
|
+
* @param {Function} project A function of type `(t: T) => U` that takes event
|
|
2051
|
+
* `t` of type `T` from the input Stream and produces an event of type `U`, to
|
|
2052
|
+
* be emitted on the output Stream.
|
|
2053
|
+
* @return {Stream}
|
|
2054
|
+
*/
|
|
2055
|
+
Stream.prototype.map = function (project) {
|
|
2056
|
+
return this._map(project);
|
|
2057
|
+
};
|
|
2058
|
+
/**
|
|
2059
|
+
* It's like `map`, but transforms each input event to always the same
|
|
2060
|
+
* constant value on the output Stream.
|
|
2061
|
+
*
|
|
2062
|
+
* Marble diagram:
|
|
2063
|
+
*
|
|
2064
|
+
* ```text
|
|
2065
|
+
* --1---3--5-----7-----
|
|
2066
|
+
* mapTo(10)
|
|
2067
|
+
* --10--10-10----10----
|
|
2068
|
+
* ```
|
|
2069
|
+
*
|
|
2070
|
+
* @param projectedValue A value to emit on the output Stream whenever the
|
|
2071
|
+
* input Stream emits any value.
|
|
2072
|
+
* @return {Stream}
|
|
2073
|
+
*/
|
|
2074
|
+
Stream.prototype.mapTo = function (projectedValue) {
|
|
2075
|
+
var s = this.map(function () { return projectedValue; });
|
|
2076
|
+
var op = s._prod;
|
|
2077
|
+
op.type = 'mapTo';
|
|
2078
|
+
return s;
|
|
2079
|
+
};
|
|
2080
|
+
/**
|
|
2081
|
+
* Only allows events that pass the test given by the `passes` argument.
|
|
2082
|
+
*
|
|
2083
|
+
* Each event from the input stream is given to the `passes` function. If the
|
|
2084
|
+
* function returns `true`, the event is forwarded to the output stream,
|
|
2085
|
+
* otherwise it is ignored and not forwarded.
|
|
2086
|
+
*
|
|
2087
|
+
* Marble diagram:
|
|
2088
|
+
*
|
|
2089
|
+
* ```text
|
|
2090
|
+
* --1---2--3-----4-----5---6--7-8--
|
|
2091
|
+
* filter(i => i % 2 === 0)
|
|
2092
|
+
* ------2--------4---------6----8--
|
|
2093
|
+
* ```
|
|
2094
|
+
*
|
|
2095
|
+
* @param {Function} passes A function of type `(t: T) => boolean` that takes
|
|
2096
|
+
* an event from the input stream and checks if it passes, by returning a
|
|
2097
|
+
* boolean.
|
|
2098
|
+
* @return {Stream}
|
|
2099
|
+
*/
|
|
2100
|
+
Stream.prototype.filter = function (passes) {
|
|
2101
|
+
var p = this._prod;
|
|
2102
|
+
if (p instanceof Filter)
|
|
2103
|
+
return new Stream(new Filter(and(p.f, passes), p.ins));
|
|
2104
|
+
return new Stream(new Filter(passes, this));
|
|
2105
|
+
};
|
|
2106
|
+
/**
|
|
2107
|
+
* Lets the first `amount` many events from the input stream pass to the
|
|
2108
|
+
* output stream, then makes the output stream complete.
|
|
2109
|
+
*
|
|
2110
|
+
* Marble diagram:
|
|
2111
|
+
*
|
|
2112
|
+
* ```text
|
|
2113
|
+
* --a---b--c----d---e--
|
|
2114
|
+
* take(3)
|
|
2115
|
+
* --a---b--c|
|
|
2116
|
+
* ```
|
|
2117
|
+
*
|
|
2118
|
+
* @param {number} amount How many events to allow from the input stream
|
|
2119
|
+
* before completing the output stream.
|
|
2120
|
+
* @return {Stream}
|
|
2121
|
+
*/
|
|
2122
|
+
Stream.prototype.take = function (amount) {
|
|
2123
|
+
return new (this.ctor())(new Take(amount, this));
|
|
2124
|
+
};
|
|
2125
|
+
/**
|
|
2126
|
+
* Ignores the first `amount` many events from the input stream, and then
|
|
2127
|
+
* after that starts forwarding events from the input stream to the output
|
|
2128
|
+
* stream.
|
|
2129
|
+
*
|
|
2130
|
+
* Marble diagram:
|
|
2131
|
+
*
|
|
2132
|
+
* ```text
|
|
2133
|
+
* --a---b--c----d---e--
|
|
2134
|
+
* drop(3)
|
|
2135
|
+
* --------------d---e--
|
|
2136
|
+
* ```
|
|
2137
|
+
*
|
|
2138
|
+
* @param {number} amount How many events to ignore from the input stream
|
|
2139
|
+
* before forwarding all events from the input stream to the output stream.
|
|
2140
|
+
* @return {Stream}
|
|
2141
|
+
*/
|
|
2142
|
+
Stream.prototype.drop = function (amount) {
|
|
2143
|
+
return new Stream(new Drop(amount, this));
|
|
2144
|
+
};
|
|
2145
|
+
/**
|
|
2146
|
+
* When the input stream completes, the output stream will emit the last event
|
|
2147
|
+
* emitted by the input stream, and then will also complete.
|
|
2148
|
+
*
|
|
2149
|
+
* Marble diagram:
|
|
2150
|
+
*
|
|
2151
|
+
* ```text
|
|
2152
|
+
* --a---b--c--d----|
|
|
2153
|
+
* last()
|
|
2154
|
+
* -----------------d|
|
|
2155
|
+
* ```
|
|
2156
|
+
*
|
|
2157
|
+
* @return {Stream}
|
|
2158
|
+
*/
|
|
2159
|
+
Stream.prototype.last = function () {
|
|
2160
|
+
return new Stream(new Last(this));
|
|
2161
|
+
};
|
|
2162
|
+
/**
|
|
2163
|
+
* Prepends the given `initial` value to the sequence of events emitted by the
|
|
2164
|
+
* input stream. The returned stream is a MemoryStream, which means it is
|
|
2165
|
+
* already `remember()`'d.
|
|
2166
|
+
*
|
|
2167
|
+
* Marble diagram:
|
|
2168
|
+
*
|
|
2169
|
+
* ```text
|
|
2170
|
+
* ---1---2-----3---
|
|
2171
|
+
* startWith(0)
|
|
2172
|
+
* 0--1---2-----3---
|
|
2173
|
+
* ```
|
|
2174
|
+
*
|
|
2175
|
+
* @param initial The value or event to prepend.
|
|
2176
|
+
* @return {MemoryStream}
|
|
2177
|
+
*/
|
|
2178
|
+
Stream.prototype.startWith = function (initial) {
|
|
2179
|
+
return new MemoryStream(new StartWith(this, initial));
|
|
2180
|
+
};
|
|
2181
|
+
/**
|
|
2182
|
+
* Uses another stream to determine when to complete the current stream.
|
|
2183
|
+
*
|
|
2184
|
+
* When the given `other` stream emits an event or completes, the output
|
|
2185
|
+
* stream will complete. Before that happens, the output stream will behaves
|
|
2186
|
+
* like the input stream.
|
|
2187
|
+
*
|
|
2188
|
+
* Marble diagram:
|
|
2189
|
+
*
|
|
2190
|
+
* ```text
|
|
2191
|
+
* ---1---2-----3--4----5----6---
|
|
2192
|
+
* endWhen( --------a--b--| )
|
|
2193
|
+
* ---1---2-----3--4--|
|
|
2194
|
+
* ```
|
|
2195
|
+
*
|
|
2196
|
+
* @param other Some other stream that is used to know when should the output
|
|
2197
|
+
* stream of this operator complete.
|
|
2198
|
+
* @return {Stream}
|
|
2199
|
+
*/
|
|
2200
|
+
Stream.prototype.endWhen = function (other) {
|
|
2201
|
+
return new (this.ctor())(new EndWhen(other, this));
|
|
2202
|
+
};
|
|
2203
|
+
/**
|
|
2204
|
+
* "Folds" the stream onto itself.
|
|
2205
|
+
*
|
|
2206
|
+
* Combines events from the past throughout
|
|
2207
|
+
* the entire execution of the input stream, allowing you to accumulate them
|
|
2208
|
+
* together. It's essentially like `Array.prototype.reduce`. The returned
|
|
2209
|
+
* stream is a MemoryStream, which means it is already `remember()`'d.
|
|
2210
|
+
*
|
|
2211
|
+
* The output stream starts by emitting the `seed` which you give as argument.
|
|
2212
|
+
* Then, when an event happens on the input stream, it is combined with that
|
|
2213
|
+
* seed value through the `accumulate` function, and the output value is
|
|
2214
|
+
* emitted on the output stream. `fold` remembers that output value as `acc`
|
|
2215
|
+
* ("accumulator"), and then when a new input event `t` happens, `acc` will be
|
|
2216
|
+
* combined with that to produce the new `acc` and so forth.
|
|
2217
|
+
*
|
|
2218
|
+
* Marble diagram:
|
|
2219
|
+
*
|
|
2220
|
+
* ```text
|
|
2221
|
+
* ------1-----1--2----1----1------
|
|
2222
|
+
* fold((acc, x) => acc + x, 3)
|
|
2223
|
+
* 3-----4-----5--7----8----9------
|
|
2224
|
+
* ```
|
|
2225
|
+
*
|
|
2226
|
+
* @param {Function} accumulate A function of type `(acc: R, t: T) => R` that
|
|
2227
|
+
* takes the previous accumulated value `acc` and the incoming event from the
|
|
2228
|
+
* input stream and produces the new accumulated value.
|
|
2229
|
+
* @param seed The initial accumulated value, of type `R`.
|
|
2230
|
+
* @return {MemoryStream}
|
|
2231
|
+
*/
|
|
2232
|
+
Stream.prototype.fold = function (accumulate, seed) {
|
|
2233
|
+
return new MemoryStream(new Fold(accumulate, seed, this));
|
|
2234
|
+
};
|
|
2235
|
+
/**
|
|
2236
|
+
* Replaces an error with another stream.
|
|
2237
|
+
*
|
|
2238
|
+
* When (and if) an error happens on the input stream, instead of forwarding
|
|
2239
|
+
* that error to the output stream, *replaceError* will call the `replace`
|
|
2240
|
+
* function which returns the stream that the output stream will replicate.
|
|
2241
|
+
* And, in case that new stream also emits an error, `replace` will be called
|
|
2242
|
+
* again to get another stream to start replicating.
|
|
2243
|
+
*
|
|
2244
|
+
* Marble diagram:
|
|
2245
|
+
*
|
|
2246
|
+
* ```text
|
|
2247
|
+
* --1---2-----3--4-----X
|
|
2248
|
+
* replaceError( () => --10--| )
|
|
2249
|
+
* --1---2-----3--4--------10--|
|
|
2250
|
+
* ```
|
|
2251
|
+
*
|
|
2252
|
+
* @param {Function} replace A function of type `(err) => Stream` that takes
|
|
2253
|
+
* the error that occurred on the input stream or on the previous replacement
|
|
2254
|
+
* stream and returns a new stream. The output stream will behave like the
|
|
2255
|
+
* stream that this function returns.
|
|
2256
|
+
* @return {Stream}
|
|
2257
|
+
*/
|
|
2258
|
+
Stream.prototype.replaceError = function (replace) {
|
|
2259
|
+
return new (this.ctor())(new ReplaceError(replace, this));
|
|
2260
|
+
};
|
|
2261
|
+
/**
|
|
2262
|
+
* Flattens a "stream of streams", handling only one nested stream at a time
|
|
2263
|
+
* (no concurrency).
|
|
2264
|
+
*
|
|
2265
|
+
* If the input stream is a stream that emits streams, then this operator will
|
|
2266
|
+
* return an output stream which is a flat stream: emits regular events. The
|
|
2267
|
+
* flattening happens without concurrency. It works like this: when the input
|
|
2268
|
+
* stream emits a nested stream, *flatten* will start imitating that nested
|
|
2269
|
+
* one. However, as soon as the next nested stream is emitted on the input
|
|
2270
|
+
* stream, *flatten* will forget the previous nested one it was imitating, and
|
|
2271
|
+
* will start imitating the new nested one.
|
|
2272
|
+
*
|
|
2273
|
+
* Marble diagram:
|
|
2274
|
+
*
|
|
2275
|
+
* ```text
|
|
2276
|
+
* --+--------+---------------
|
|
2277
|
+
* \ \
|
|
2278
|
+
* \ ----1----2---3--
|
|
2279
|
+
* --a--b----c----d--------
|
|
2280
|
+
* flatten
|
|
2281
|
+
* -----a--b------1----2---3--
|
|
2282
|
+
* ```
|
|
2283
|
+
*
|
|
2284
|
+
* @return {Stream}
|
|
2285
|
+
*/
|
|
2286
|
+
Stream.prototype.flatten = function () {
|
|
2287
|
+
return new Stream(new Flatten(this));
|
|
2288
|
+
};
|
|
2289
|
+
/**
|
|
2290
|
+
* Passes the input stream to a custom operator, to produce an output stream.
|
|
2291
|
+
*
|
|
2292
|
+
* *compose* is a handy way of using an existing function in a chained style.
|
|
2293
|
+
* Instead of writing `outStream = f(inStream)` you can write
|
|
2294
|
+
* `outStream = inStream.compose(f)`.
|
|
2295
|
+
*
|
|
2296
|
+
* @param {function} operator A function that takes a stream as input and
|
|
2297
|
+
* returns a stream as well.
|
|
2298
|
+
* @return {Stream}
|
|
2299
|
+
*/
|
|
2300
|
+
Stream.prototype.compose = function (operator) {
|
|
2301
|
+
return operator(this);
|
|
2302
|
+
};
|
|
2303
|
+
/**
|
|
2304
|
+
* Returns an output stream that behaves like the input stream, but also
|
|
2305
|
+
* remembers the most recent event that happens on the input stream, so that a
|
|
2306
|
+
* newly added listener will immediately receive that memorised event.
|
|
2307
|
+
*
|
|
2308
|
+
* @return {MemoryStream}
|
|
2309
|
+
*/
|
|
2310
|
+
Stream.prototype.remember = function () {
|
|
2311
|
+
return new MemoryStream(new Remember(this));
|
|
2312
|
+
};
|
|
2313
|
+
/**
|
|
2314
|
+
* Returns an output stream that identically behaves like the input stream,
|
|
2315
|
+
* but also runs a `spy` function for each event, to help you debug your app.
|
|
2316
|
+
*
|
|
2317
|
+
* *debug* takes a `spy` function as argument, and runs that for each event
|
|
2318
|
+
* happening on the input stream. If you don't provide the `spy` argument,
|
|
2319
|
+
* then *debug* will just `console.log` each event. This helps you to
|
|
2320
|
+
* understand the flow of events through some operator chain.
|
|
2321
|
+
*
|
|
2322
|
+
* Please note that if the output stream has no listeners, then it will not
|
|
2323
|
+
* start, which means `spy` will never run because no actual event happens in
|
|
2324
|
+
* that case.
|
|
2325
|
+
*
|
|
2326
|
+
* Marble diagram:
|
|
2327
|
+
*
|
|
2328
|
+
* ```text
|
|
2329
|
+
* --1----2-----3-----4--
|
|
2330
|
+
* debug
|
|
2331
|
+
* --1----2-----3-----4--
|
|
2332
|
+
* ```
|
|
2333
|
+
*
|
|
2334
|
+
* @param {function} labelOrSpy A string to use as the label when printing
|
|
2335
|
+
* debug information on the console, or a 'spy' function that takes an event
|
|
2336
|
+
* as argument, and does not need to return anything.
|
|
2337
|
+
* @return {Stream}
|
|
2338
|
+
*/
|
|
2339
|
+
Stream.prototype.debug = function (labelOrSpy) {
|
|
2340
|
+
return new (this.ctor())(new Debug(this, labelOrSpy));
|
|
2341
|
+
};
|
|
2342
|
+
/**
|
|
2343
|
+
* *imitate* changes this current Stream to emit the same events that the
|
|
2344
|
+
* `other` given Stream does. This method returns nothing.
|
|
2345
|
+
*
|
|
2346
|
+
* This method exists to allow one thing: **circular dependency of streams**.
|
|
2347
|
+
* For instance, let's imagine that for some reason you need to create a
|
|
2348
|
+
* circular dependency where stream `first$` depends on stream `second$`
|
|
2349
|
+
* which in turn depends on `first$`:
|
|
2350
|
+
*
|
|
2351
|
+
* <!-- skip-example -->
|
|
2352
|
+
* ```js
|
|
2353
|
+
* import delay from 'xstream/extra/delay'
|
|
2354
|
+
*
|
|
2355
|
+
* var first$ = second$.map(x => x * 10).take(3);
|
|
2356
|
+
* var second$ = first$.map(x => x + 1).startWith(1).compose(delay(100));
|
|
2357
|
+
* ```
|
|
2358
|
+
*
|
|
2359
|
+
* However, that is invalid JavaScript, because `second$` is undefined
|
|
2360
|
+
* on the first line. This is how *imitate* can help solve it:
|
|
2361
|
+
*
|
|
2362
|
+
* ```js
|
|
2363
|
+
* import delay from 'xstream/extra/delay'
|
|
2364
|
+
*
|
|
2365
|
+
* var secondProxy$ = xs.create();
|
|
2366
|
+
* var first$ = secondProxy$.map(x => x * 10).take(3);
|
|
2367
|
+
* var second$ = first$.map(x => x + 1).startWith(1).compose(delay(100));
|
|
2368
|
+
* secondProxy$.imitate(second$);
|
|
2369
|
+
* ```
|
|
2370
|
+
*
|
|
2371
|
+
* We create `secondProxy$` before the others, so it can be used in the
|
|
2372
|
+
* declaration of `first$`. Then, after both `first$` and `second$` are
|
|
2373
|
+
* defined, we hook `secondProxy$` with `second$` with `imitate()` to tell
|
|
2374
|
+
* that they are "the same". `imitate` will not trigger the start of any
|
|
2375
|
+
* stream, it just binds `secondProxy$` and `second$` together.
|
|
2376
|
+
*
|
|
2377
|
+
* The following is an example where `imitate()` is important in Cycle.js
|
|
2378
|
+
* applications. A parent component contains some child components. A child
|
|
2379
|
+
* has an action stream which is given to the parent to define its state:
|
|
2380
|
+
*
|
|
2381
|
+
* <!-- skip-example -->
|
|
2382
|
+
* ```js
|
|
2383
|
+
* const childActionProxy$ = xs.create();
|
|
2384
|
+
* const parent = Parent({...sources, childAction$: childActionProxy$});
|
|
2385
|
+
* const childAction$ = parent.state$.map(s => s.child.action$).flatten();
|
|
2386
|
+
* childActionProxy$.imitate(childAction$);
|
|
2387
|
+
* ```
|
|
2388
|
+
*
|
|
2389
|
+
* Note, though, that **`imitate()` does not support MemoryStreams**. If we
|
|
2390
|
+
* would attempt to imitate a MemoryStream in a circular dependency, we would
|
|
2391
|
+
* either get a race condition (where the symptom would be "nothing happens")
|
|
2392
|
+
* or an infinite cyclic emission of values. It's useful to think about
|
|
2393
|
+
* MemoryStreams as cells in a spreadsheet. It doesn't make any sense to
|
|
2394
|
+
* define a spreadsheet cell `A1` with a formula that depends on `B1` and
|
|
2395
|
+
* cell `B1` defined with a formula that depends on `A1`.
|
|
2396
|
+
*
|
|
2397
|
+
* If you find yourself wanting to use `imitate()` with a
|
|
2398
|
+
* MemoryStream, you should rework your code around `imitate()` to use a
|
|
2399
|
+
* Stream instead. Look for the stream in the circular dependency that
|
|
2400
|
+
* represents an event stream, and that would be a candidate for creating a
|
|
2401
|
+
* proxy Stream which then imitates the target Stream.
|
|
2402
|
+
*
|
|
2403
|
+
* @param {Stream} target The other stream to imitate on the current one. Must
|
|
2404
|
+
* not be a MemoryStream.
|
|
2405
|
+
*/
|
|
2406
|
+
Stream.prototype.imitate = function (target) {
|
|
2407
|
+
if (target instanceof MemoryStream)
|
|
2408
|
+
throw new Error('A MemoryStream was given to imitate(), but it only ' +
|
|
2409
|
+
'supports a Stream. Read more about this restriction here: ' +
|
|
2410
|
+
'https://github.com/staltz/xstream#faq');
|
|
2411
|
+
this._target = target;
|
|
2412
|
+
for (var ils = this._ils, N = ils.length, i = 0; i < N; i++)
|
|
2413
|
+
target._add(ils[i]);
|
|
2414
|
+
this._ils = [];
|
|
2415
|
+
};
|
|
2416
|
+
/**
|
|
2417
|
+
* Forces the Stream to emit the given value to its listeners.
|
|
2418
|
+
*
|
|
2419
|
+
* As the name indicates, if you use this, you are most likely doing something
|
|
2420
|
+
* The Wrong Way. Please try to understand the reactive way before using this
|
|
2421
|
+
* method. Use it only when you know what you are doing.
|
|
2422
|
+
*
|
|
2423
|
+
* @param value The "next" value you want to broadcast to all listeners of
|
|
2424
|
+
* this Stream.
|
|
2425
|
+
*/
|
|
2426
|
+
Stream.prototype.shamefullySendNext = function (value) {
|
|
2427
|
+
this._n(value);
|
|
2428
|
+
};
|
|
2429
|
+
/**
|
|
2430
|
+
* Forces the Stream to emit the given error to its listeners.
|
|
2431
|
+
*
|
|
2432
|
+
* As the name indicates, if you use this, you are most likely doing something
|
|
2433
|
+
* The Wrong Way. Please try to understand the reactive way before using this
|
|
2434
|
+
* method. Use it only when you know what you are doing.
|
|
2435
|
+
*
|
|
2436
|
+
* @param {any} error The error you want to broadcast to all the listeners of
|
|
2437
|
+
* this Stream.
|
|
2438
|
+
*/
|
|
2439
|
+
Stream.prototype.shamefullySendError = function (error) {
|
|
2440
|
+
this._e(error);
|
|
2441
|
+
};
|
|
2442
|
+
/**
|
|
2443
|
+
* Forces the Stream to emit the "completed" event to its listeners.
|
|
2444
|
+
*
|
|
2445
|
+
* As the name indicates, if you use this, you are most likely doing something
|
|
2446
|
+
* The Wrong Way. Please try to understand the reactive way before using this
|
|
2447
|
+
* method. Use it only when you know what you are doing.
|
|
2448
|
+
*/
|
|
2449
|
+
Stream.prototype.shamefullySendComplete = function () {
|
|
2450
|
+
this._c();
|
|
2451
|
+
};
|
|
2452
|
+
/**
|
|
2453
|
+
* Adds a "debug" listener to the stream. There can only be one debug
|
|
2454
|
+
* listener, that's why this is 'setDebugListener'. To remove the debug
|
|
2455
|
+
* listener, just call setDebugListener(null).
|
|
2456
|
+
*
|
|
2457
|
+
* A debug listener is like any other listener. The only difference is that a
|
|
2458
|
+
* debug listener is "stealthy": its presence/absence does not trigger the
|
|
2459
|
+
* start/stop of the stream (or the producer inside the stream). This is
|
|
2460
|
+
* useful so you can inspect what is going on without changing the behavior
|
|
2461
|
+
* of the program. If you have an idle stream and you add a normal listener to
|
|
2462
|
+
* it, the stream will start executing. But if you set a debug listener on an
|
|
2463
|
+
* idle stream, it won't start executing (not until the first normal listener
|
|
2464
|
+
* is added).
|
|
2465
|
+
*
|
|
2466
|
+
* As the name indicates, we don't recommend using this method to build app
|
|
2467
|
+
* logic. In fact, in most cases the debug operator works just fine. Only use
|
|
2468
|
+
* this one if you know what you're doing.
|
|
2469
|
+
*
|
|
2470
|
+
* @param {Listener<T>} listener
|
|
2471
|
+
*/
|
|
2472
|
+
Stream.prototype.setDebugListener = function (listener) {
|
|
2473
|
+
if (!listener) {
|
|
2474
|
+
this._d = false;
|
|
2475
|
+
this._dl = NO;
|
|
2476
|
+
}
|
|
2477
|
+
else {
|
|
2478
|
+
this._d = true;
|
|
2479
|
+
listener._n = listener.next || noop;
|
|
2480
|
+
listener._e = listener.error || noop;
|
|
2481
|
+
listener._c = listener.complete || noop;
|
|
2482
|
+
this._dl = listener;
|
|
2483
|
+
}
|
|
2484
|
+
};
|
|
2485
|
+
/**
|
|
2486
|
+
* Blends multiple streams together, emitting events from all of them
|
|
2487
|
+
* concurrently.
|
|
2488
|
+
*
|
|
2489
|
+
* *merge* takes multiple streams as arguments, and creates a stream that
|
|
2490
|
+
* behaves like each of the argument streams, in parallel.
|
|
2491
|
+
*
|
|
2492
|
+
* Marble diagram:
|
|
2493
|
+
*
|
|
2494
|
+
* ```text
|
|
2495
|
+
* --1----2-----3--------4---
|
|
2496
|
+
* ----a-----b----c---d------
|
|
2497
|
+
* merge
|
|
2498
|
+
* --1-a--2--b--3-c---d--4---
|
|
2499
|
+
* ```
|
|
2500
|
+
*
|
|
2501
|
+
* @factory true
|
|
2502
|
+
* @param {Stream} stream1 A stream to merge together with other streams.
|
|
2503
|
+
* @param {Stream} stream2 A stream to merge together with other streams. Two
|
|
2504
|
+
* or more streams may be given as arguments.
|
|
2505
|
+
* @return {Stream}
|
|
2506
|
+
*/
|
|
2507
|
+
Stream.merge = function merge() {
|
|
2508
|
+
var streams = [];
|
|
2509
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2510
|
+
streams[_i] = arguments[_i];
|
|
2511
|
+
}
|
|
2512
|
+
return new Stream(new Merge(streams));
|
|
2513
|
+
};
|
|
2514
|
+
/**
|
|
2515
|
+
* Combines multiple input streams together to return a stream whose events
|
|
2516
|
+
* are arrays that collect the latest events from each input stream.
|
|
2517
|
+
*
|
|
2518
|
+
* *combine* internally remembers the most recent event from each of the input
|
|
2519
|
+
* streams. When any of the input streams emits an event, that event together
|
|
2520
|
+
* with all the other saved events are combined into an array. That array will
|
|
2521
|
+
* be emitted on the output stream. It's essentially a way of joining together
|
|
2522
|
+
* the events from multiple streams.
|
|
2523
|
+
*
|
|
2524
|
+
* Marble diagram:
|
|
2525
|
+
*
|
|
2526
|
+
* ```text
|
|
2527
|
+
* --1----2-----3--------4---
|
|
2528
|
+
* ----a-----b-----c--d------
|
|
2529
|
+
* combine
|
|
2530
|
+
* ----1a-2a-2b-3b-3c-3d-4d--
|
|
2531
|
+
* ```
|
|
2532
|
+
*
|
|
2533
|
+
* @factory true
|
|
2534
|
+
* @param {Stream} stream1 A stream to combine together with other streams.
|
|
2535
|
+
* @param {Stream} stream2 A stream to combine together with other streams.
|
|
2536
|
+
* Multiple streams, not just two, may be given as arguments.
|
|
2537
|
+
* @return {Stream}
|
|
2538
|
+
*/
|
|
2539
|
+
Stream.combine = function combine() {
|
|
2540
|
+
var streams = [];
|
|
2541
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2542
|
+
streams[_i] = arguments[_i];
|
|
2543
|
+
}
|
|
2544
|
+
return new Stream(new Combine(streams));
|
|
2545
|
+
};
|
|
2546
|
+
return Stream;
|
|
2547
|
+
}());
|
|
2548
|
+
var Stream_1 = xstream.Stream = Stream;
|
|
2549
|
+
var MemoryStream = /** @class */ (function (_super) {
|
|
2550
|
+
__extends(MemoryStream, _super);
|
|
2551
|
+
function MemoryStream(producer) {
|
|
2552
|
+
var _this = _super.call(this, producer) || this;
|
|
2553
|
+
_this._has = false;
|
|
2554
|
+
return _this;
|
|
2555
|
+
}
|
|
2556
|
+
MemoryStream.prototype._n = function (x) {
|
|
2557
|
+
this._v = x;
|
|
2558
|
+
this._has = true;
|
|
2559
|
+
_super.prototype._n.call(this, x);
|
|
2560
|
+
};
|
|
2561
|
+
MemoryStream.prototype._add = function (il) {
|
|
2562
|
+
var ta = this._target;
|
|
2563
|
+
if (ta)
|
|
2564
|
+
return ta._add(il);
|
|
2565
|
+
var a = this._ils;
|
|
2566
|
+
a.push(il);
|
|
2567
|
+
if (a.length > 1) {
|
|
2568
|
+
if (this._has)
|
|
2569
|
+
il._n(this._v);
|
|
2570
|
+
return;
|
|
2571
|
+
}
|
|
2572
|
+
if (this._stopID !== NO) {
|
|
2573
|
+
if (this._has)
|
|
2574
|
+
il._n(this._v);
|
|
2575
|
+
clearTimeout(this._stopID);
|
|
2576
|
+
this._stopID = NO;
|
|
2577
|
+
}
|
|
2578
|
+
else if (this._has)
|
|
2579
|
+
il._n(this._v);
|
|
2580
|
+
else {
|
|
2581
|
+
var p = this._prod;
|
|
2582
|
+
if (p !== NO)
|
|
2583
|
+
p._start(this);
|
|
2584
|
+
}
|
|
2585
|
+
};
|
|
2586
|
+
MemoryStream.prototype._stopNow = function () {
|
|
2587
|
+
this._has = false;
|
|
2588
|
+
_super.prototype._stopNow.call(this);
|
|
2589
|
+
};
|
|
2590
|
+
MemoryStream.prototype._x = function () {
|
|
2591
|
+
this._has = false;
|
|
2592
|
+
_super.prototype._x.call(this);
|
|
2593
|
+
};
|
|
2594
|
+
MemoryStream.prototype.map = function (project) {
|
|
2595
|
+
return this._map(project);
|
|
2596
|
+
};
|
|
2597
|
+
MemoryStream.prototype.mapTo = function (projectedValue) {
|
|
2598
|
+
return _super.prototype.mapTo.call(this, projectedValue);
|
|
2599
|
+
};
|
|
2600
|
+
MemoryStream.prototype.take = function (amount) {
|
|
2601
|
+
return _super.prototype.take.call(this, amount);
|
|
2602
|
+
};
|
|
2603
|
+
MemoryStream.prototype.endWhen = function (other) {
|
|
2604
|
+
return _super.prototype.endWhen.call(this, other);
|
|
2605
|
+
};
|
|
2606
|
+
MemoryStream.prototype.replaceError = function (replace) {
|
|
2607
|
+
return _super.prototype.replaceError.call(this, replace);
|
|
2608
|
+
};
|
|
2609
|
+
MemoryStream.prototype.remember = function () {
|
|
2610
|
+
return this;
|
|
2611
|
+
};
|
|
2612
|
+
MemoryStream.prototype.debug = function (labelOrSpy) {
|
|
2613
|
+
return _super.prototype.debug.call(this, labelOrSpy);
|
|
2614
|
+
};
|
|
2615
|
+
return MemoryStream;
|
|
2616
|
+
}(Stream));
|
|
2617
|
+
var MemoryStream_1 = xstream.MemoryStream = MemoryStream;
|
|
2618
|
+
var xs$1 = Stream;
|
|
2619
|
+
var _default = xstream.default = xs$1;
|
|
2620
|
+
|
|
2621
|
+
var xstreamNamespace = /*#__PURE__*/_mergeNamespaces({
|
|
2622
|
+
__proto__: null,
|
|
2623
|
+
get MemoryStream () { return MemoryStream_1; },
|
|
2624
|
+
get NO () { return NO_1; },
|
|
2625
|
+
get NO_IL () { return NO_IL_1; },
|
|
2626
|
+
get Stream () { return Stream_1; },
|
|
2627
|
+
default: _default
|
|
2628
|
+
}, [xstream]);
|
|
2629
|
+
|
|
2630
|
+
function resolveInteropDefault(namespaceValue) {
|
|
2631
|
+
if (namespaceValue &&
|
|
2632
|
+
namespaceValue.default &&
|
|
2633
|
+
namespaceValue.default.default &&
|
|
2634
|
+
typeof namespaceValue.default.default === 'function') {
|
|
2635
|
+
return namespaceValue.default.default;
|
|
2636
|
+
}
|
|
2637
|
+
if (namespaceValue && namespaceValue.default) {
|
|
2638
|
+
return namespaceValue.default;
|
|
2639
|
+
}
|
|
2640
|
+
return namespaceValue;
|
|
2641
|
+
}
|
|
2642
|
+
function getXs(namespaceValue) {
|
|
2643
|
+
const value = resolveInteropDefault(namespaceValue);
|
|
2644
|
+
if (value &&
|
|
2645
|
+
value.default &&
|
|
2646
|
+
typeof value.default.create === 'function') {
|
|
2647
|
+
return value.default;
|
|
2648
|
+
}
|
|
2649
|
+
return value;
|
|
2650
|
+
}
|
|
2651
|
+
const xs = getXs(xstreamNamespace);
|
|
2652
|
+
Stream_1 ||
|
|
2653
|
+
(_default && _default.Stream) ||
|
|
2654
|
+
(xs && xs.Stream);
|
|
2655
|
+
|
|
2656
|
+
const DOCS_BASE_URL = 'https://sygnal.js.org';
|
|
2657
|
+
const CODE_SEVERITY = {
|
|
2658
|
+
SYG101: 'warn',
|
|
2659
|
+
SYG102: 'info',
|
|
2660
|
+
SYG103: 'info',
|
|
2661
|
+
SYG104: 'warn',
|
|
2662
|
+
SYG105: 'info',
|
|
2663
|
+
SYG106: 'warn',
|
|
2664
|
+
SYG110: 'warn',
|
|
2665
|
+
SYG111: 'warn',
|
|
2666
|
+
SYG201: 'warn',
|
|
2667
|
+
SYG202: 'warn',
|
|
2668
|
+
SYG301: 'error',
|
|
2669
|
+
SYG401: 'warn',
|
|
2670
|
+
SYG900: 'warn',
|
|
2671
|
+
// ---- 1E retrofit codes (SYG206-299, 402-499, 601-699, 901-999) ----
|
|
2672
|
+
SYG206: 'error',
|
|
2673
|
+
SYG207: 'warn',
|
|
2674
|
+
SYG208: 'warn',
|
|
2675
|
+
SYG209: 'error',
|
|
2676
|
+
SYG210: 'warn',
|
|
2677
|
+
SYG211: 'error',
|
|
2678
|
+
SYG212: 'error',
|
|
2679
|
+
SYG213: 'warn',
|
|
2680
|
+
SYG214: 'error',
|
|
2681
|
+
SYG215: 'error',
|
|
2682
|
+
SYG216: 'error',
|
|
2683
|
+
SYG217: 'warn',
|
|
2684
|
+
SYG218: 'error',
|
|
2685
|
+
SYG219: 'warn',
|
|
2686
|
+
SYG220: 'warn',
|
|
2687
|
+
SYG402: 'error',
|
|
2688
|
+
SYG403: 'error',
|
|
2689
|
+
SYG404: 'error',
|
|
2690
|
+
SYG405: 'error',
|
|
2691
|
+
SYG406: 'error',
|
|
2692
|
+
SYG407: 'error',
|
|
2693
|
+
SYG408: 'error',
|
|
2694
|
+
SYG409: 'warn',
|
|
2695
|
+
SYG410: 'error',
|
|
2696
|
+
SYG411: 'error',
|
|
2697
|
+
SYG412: 'error',
|
|
2698
|
+
SYG413: 'error',
|
|
2699
|
+
SYG414: 'error',
|
|
2700
|
+
SYG415: 'error',
|
|
2701
|
+
SYG416: 'error',
|
|
2702
|
+
SYG417: 'warn',
|
|
2703
|
+
SYG418: 'error',
|
|
2704
|
+
SYG419: 'error',
|
|
2705
|
+
SYG420: 'error',
|
|
2706
|
+
SYG601: 'error',
|
|
2707
|
+
SYG602: 'error',
|
|
2708
|
+
SYG603: 'error',
|
|
2709
|
+
SYG604: 'error',
|
|
2710
|
+
SYG605: 'error',
|
|
2711
|
+
SYG606: 'error',
|
|
2712
|
+
SYG607: 'error',
|
|
2713
|
+
SYG608: 'warn',
|
|
2714
|
+
SYG609: 'warn',
|
|
2715
|
+
SYG610: 'error',
|
|
2716
|
+
SYG901: 'error',
|
|
2717
|
+
SYG902: 'error',
|
|
2718
|
+
SYG903: 'error',
|
|
2719
|
+
// ---- end 1E retrofit codes ----
|
|
2720
|
+
};
|
|
2721
|
+
function docsUrlFor(code) {
|
|
2722
|
+
return `${DOCS_BASE_URL}/reference/errors#${code.toLowerCase()}`;
|
|
2723
|
+
}
|
|
2724
|
+
|
|
2725
|
+
class DiagnosticError extends Error {
|
|
2726
|
+
constructor(diagnostic) {
|
|
2727
|
+
super(diagnostic.text);
|
|
2728
|
+
this.diagnostic = diagnostic;
|
|
2729
|
+
}
|
|
2730
|
+
}
|
|
2731
|
+
let mode = 'off';
|
|
2732
|
+
let enabled = false;
|
|
2733
|
+
let ignored = new Set();
|
|
2734
|
+
let listeners = [];
|
|
2735
|
+
let checks = [];
|
|
2736
|
+
function resolveDiagnosticsMode() {
|
|
2737
|
+
mode = (globalThis.__SYGNAL_DEV__ === true ? 'warn' : 'off');
|
|
2738
|
+
enabled = mode !== 'off';
|
|
2739
|
+
return mode;
|
|
2740
|
+
}
|
|
2741
|
+
function getDiagnosticsMode() {
|
|
2742
|
+
return mode;
|
|
2743
|
+
}
|
|
2744
|
+
function isDiagnosticsEnabled() {
|
|
2745
|
+
return enabled;
|
|
2746
|
+
}
|
|
2747
|
+
const nameOf = (c) => (c && typeof c === 'object' ? c.name : c) || undefined;
|
|
2748
|
+
const sentence = (s) => /[.!?]$/.test(s) ? s : s + '.';
|
|
2749
|
+
function formatDiagnostic(code, details) {
|
|
2750
|
+
const name = nameOf(details.component);
|
|
2751
|
+
return `[Sygnal ${code}] ${name ? name + ': ' : ''}${sentence(details.message)}` +
|
|
2752
|
+
(details.fix ? ' ' + sentence(details.fix) : '') + ' ' + docsUrlFor(code);
|
|
2753
|
+
}
|
|
2754
|
+
function report(code, details) {
|
|
2755
|
+
if (!enabled || ignored.has(code))
|
|
2756
|
+
return;
|
|
2757
|
+
const severity = details.severity || CODE_SEVERITY[code] || 'warn';
|
|
2758
|
+
const d = {
|
|
2759
|
+
code,
|
|
2760
|
+
severity,
|
|
2761
|
+
component: nameOf(details.component),
|
|
2762
|
+
message: details.message,
|
|
2763
|
+
fix: details.fix,
|
|
2764
|
+
data: details.data,
|
|
2765
|
+
docsUrl: docsUrlFor(code),
|
|
2766
|
+
get text() { return formatDiagnostic(code, this); },
|
|
2767
|
+
timestamp: Date.now(),
|
|
2768
|
+
};
|
|
2769
|
+
listeners.forEach(cb => { try {
|
|
2770
|
+
cb(d);
|
|
2771
|
+
}
|
|
2772
|
+
catch (_) { } });
|
|
2773
|
+
if (severity !== 'info') {
|
|
2774
|
+
if (mode === 'error')
|
|
2775
|
+
throw new DiagnosticError(d);
|
|
2776
|
+
if (mode === 'warn')
|
|
2777
|
+
console[severity](d.text);
|
|
2778
|
+
}
|
|
2779
|
+
return d;
|
|
2780
|
+
}
|
|
2781
|
+
function registerCheck(check) {
|
|
2782
|
+
checks = [...checks, check];
|
|
2783
|
+
return () => { checks = checks.filter(c => c !== check); };
|
|
2784
|
+
}
|
|
2785
|
+
const defaultAsyncThrow = (err) => {
|
|
2786
|
+
const raise = () => { throw err; };
|
|
2787
|
+
typeof queueMicrotask === 'function' ? queueMicrotask(raise) : setTimeout(raise);
|
|
2788
|
+
};
|
|
2789
|
+
let asyncThrow = defaultAsyncThrow;
|
|
2790
|
+
const hook = (name) => (component, ...args) => {
|
|
2791
|
+
for (const check of checks) {
|
|
2792
|
+
if (!enabled && !check.always)
|
|
2793
|
+
continue;
|
|
2794
|
+
try {
|
|
2795
|
+
check[name]?.(component, ...args);
|
|
2796
|
+
}
|
|
2797
|
+
catch (err) {
|
|
2798
|
+
// Never throw into the stream pipeline: 'error'-mode diagnostics (also a
|
|
2799
|
+
// SYG900 escalated by 'error' mode) are rethrown asynchronously.
|
|
2800
|
+
try {
|
|
2801
|
+
if (err instanceof DiagnosticError)
|
|
2802
|
+
throw err;
|
|
2803
|
+
report('SYG900', {
|
|
2804
|
+
component,
|
|
2805
|
+
message: `Diagnostics check '${check.id}' threw in ${name}: ${err?.message}`,
|
|
2806
|
+
data: { check: check.id, hook: name, error: err },
|
|
2807
|
+
});
|
|
2808
|
+
}
|
|
2809
|
+
catch (e) {
|
|
2810
|
+
asyncThrow(e);
|
|
2811
|
+
}
|
|
2812
|
+
}
|
|
2813
|
+
}
|
|
2814
|
+
};
|
|
2815
|
+
const onIntent = hook('onIntent');
|
|
2816
|
+
const onModel = hook('onModel');
|
|
2817
|
+
const onRender = hook('onRender');
|
|
2818
|
+
const onReducer = hook('onReducer');
|
|
2819
|
+
const onDispose = hook('onDispose');
|
|
2820
|
+
/**
|
|
2821
|
+
* (PLAN-2 E2) The sources object a component's intent is called with: `component.sources`,
|
|
2822
|
+
* wrapped by every active check with a `sources` hook (the dev entry's SYG609 check,
|
|
2823
|
+
* renderComponent's fake sources). Without such a check it is `component.sources` itself.
|
|
2824
|
+
*/
|
|
2825
|
+
function sourcesFor(component) {
|
|
2826
|
+
let s = component.sources;
|
|
2827
|
+
for (const check of checks) {
|
|
2828
|
+
if (!check.sources || (!enabled && !check.always))
|
|
2829
|
+
continue;
|
|
2830
|
+
try {
|
|
2831
|
+
s = check.sources(component, s) || s;
|
|
2832
|
+
}
|
|
2833
|
+
catch (_) { }
|
|
2834
|
+
}
|
|
2835
|
+
return s;
|
|
2836
|
+
}
|
|
2837
|
+
globalThis.__SYGNAL_DIAGNOSTICS__ = { registerCheck, report, hooks: { onIntent, onModel, onRender, onReducer, onDispose, sourcesFor, on: isDiagnosticsEnabled } };
|
|
2838
|
+
resolveDiagnosticsMode();
|
|
2839
|
+
|
|
2840
|
+
const emit = (severity) => (code, component, message, fix, ...extra) => {
|
|
2841
|
+
const details = { component, message, fix, severity, data: extra[0] };
|
|
2842
|
+
const mode = getDiagnosticsMode();
|
|
2843
|
+
if (mode === 'off') {
|
|
2844
|
+
console[severity](formatDiagnostic(code, details), ...extra);
|
|
2845
|
+
return;
|
|
2846
|
+
}
|
|
2847
|
+
try {
|
|
2848
|
+
const d = report(code, details);
|
|
2849
|
+
if (d && mode === 'collect' && severity === 'error')
|
|
2850
|
+
console.error(d.text, ...extra);
|
|
2851
|
+
else if (d && mode === 'warn' && extra.length)
|
|
2852
|
+
console[severity](...extra);
|
|
2853
|
+
}
|
|
2854
|
+
catch (err) {
|
|
2855
|
+
setTimeout(() => { throw err; });
|
|
2856
|
+
}
|
|
2857
|
+
};
|
|
2858
|
+
const error = emit('error');
|
|
2859
|
+
globalThis.__SYGNAL_DIAGNOSTICS__.error = error;
|
|
2860
|
+
|
|
2861
|
+
const isObj = (o) => o !== null && typeof o == 'object' && !Array.isArray(o);
|
|
2862
|
+
|
|
2863
|
+
/**
|
|
2864
|
+
* PLAN-4.6 core: state cells (03-proposal §4). Pull-based views of the one state tree,
|
|
2865
|
+
* memoized on the parent value's identity. A write goes straight to the parent (no reducer
|
|
2866
|
+
* wrappers climbing the tree); the root's (or an isolated instance's local) write commits.
|
|
2867
|
+
*
|
|
2868
|
+
* | cell | get | set |
|
|
2869
|
+
* | root | app.state | app.state = v; commit |
|
|
2870
|
+
* | key | parent.get()[k] (or a default, isolated) | parent.set({...p, [k]: v}); SYG409 when k is a calculated field of the parent |
|
|
2871
|
+
* | lens | lens.get(parent.get()) | parent.set(lens.set(p, v)) |
|
|
2872
|
+
* | local | its own value; the parent's until written | own value; commit (isolatedState) |
|
|
2873
|
+
*
|
|
2874
|
+
* Calculated fields (and `idle` defaults) are a decorator: get() adds them, memoized per input
|
|
2875
|
+
* identity and per declared dependency values; set() stores them (the only behaviour after D164).
|
|
2876
|
+
* Children read through their parent's decorated cell, so they see its calculated fields, and a
|
|
2877
|
+
* child's write stores freshly computed ones (4-F).
|
|
2878
|
+
*/
|
|
2879
|
+
// ------------------------------------------------------------------ Collection items
|
|
2880
|
+
/**
|
|
2881
|
+
* An item's key: the `id` of an object item (anything but undefined / null, compared as a string,
|
|
2882
|
+
* as today's stringified keys), else its raw index in the state array (D169: not its
|
|
2883
|
+
* filtered/sorted position), in a namespace of its own ('\0' + index: G-306/G-307, so an index
|
|
2884
|
+
* never collides with an id).
|
|
2885
|
+
*/
|
|
2886
|
+
const keyOf = (it, i) => (isObj(it) && it.id != null ? '' + it.id : '\0' + i);
|
|
2887
|
+
|
|
2888
|
+
(typeof window != 'undefined' && window) || (typeof process != 'undefined' && process.env) || {};
|
|
2889
|
+
|
|
2890
|
+
/**
|
|
2891
|
+
* PLAN-4.6 core: the Collection host (03-proposal §2 hosts/, R2). Registered on import (the
|
|
2892
|
+
* public `Collection` module imports this file); the core only looks `hosts.collection` up.
|
|
2893
|
+
*
|
|
2894
|
+
* It stands where the `<Collection>` marker was in its owner's template and renders the items
|
|
2895
|
+
* inside the owner's render: no stream of its own, no pickCombine.
|
|
2896
|
+
* - `of`: a component function (D163: no names). `from`: a state key (SYG409 on a calculated
|
|
2897
|
+
* one), a `{ get, set }` lens (SYG412 without get(); SYG401 for a non-array) or none (the
|
|
2898
|
+
* owner's state is the array).
|
|
2899
|
+
* - Items are keyed by `id`, an id-less item by its raw index (D169); one key -> index map per
|
|
2900
|
+
* array identity serves every item (cell.ts indexer). A duplicate key renders its first element
|
|
2901
|
+
* only; the dev warning is R4's (hooks.onDuplicateKey is the hook point).
|
|
2902
|
+
* - `filter` / `sort` (every form today's core accepts; SYG418 for an invalid one) change what
|
|
2903
|
+
* renders and in which order; the state array keeps its order, and an item writes back to its
|
|
2904
|
+
* own element. An item returning `undefined` removes itself.
|
|
2905
|
+
* - The other props go to every item, and the Collection's children are each item's children.
|
|
2906
|
+
* - 4-H (D229): no element of its own. It renders a keyed fragment of the items' vnodes (its key:
|
|
2907
|
+
* the marker's, else its id), which the DOM driver splices into the parent's children before
|
|
2908
|
+
* each patch (utils.ts flat): the items are the parent element's own children, and their keys
|
|
2909
|
+
* take the fragment's, so two sibling Collections' items never collide. The wrapper `div` of
|
|
2910
|
+
* 5.x is gone: `className` / `style` / `class` / ... on the marker are a removed-form error in development
|
|
2911
|
+
* (checks/next.ts) and are ignored.
|
|
2912
|
+
* - Removed items are disposed synchronously in the render that drops them (G-257: a move between
|
|
2913
|
+
* two Collections is one patch).
|
|
2914
|
+
* - PLAN-5 A-1: `viewTransitionName="card"` styles each keyed item's root element with
|
|
2915
|
+
* `view-transition-name: card-<id>` (shared.ts vtStyle) and `view-transition-class:
|
|
2916
|
+
* card`, the item's own style winning, so a `viewTransitions` action animates each item between
|
|
2917
|
+
* its places, across Collections with the same prefix too. Id-less items (keyed by index) and
|
|
2918
|
+
* fragment roots get none.
|
|
2919
|
+
*/
|
|
2920
|
+
const SORT_FIX = "Use a field name, { field: 'asc'|'desc'|1|-1 }, or a function";
|
|
2921
|
+
const sortError = (msg, value) => void error('SYG418', 'Collection', msg, SORT_FIX, value);
|
|
2922
|
+
const base = (a, b, asc = true) => (a > b ? (asc ? 1 : -1) : a < b ? (asc ? -1 : 1) : 0);
|
|
2923
|
+
function fromObj(item) {
|
|
2924
|
+
const e = Object.entries(item);
|
|
2925
|
+
if (e.length > 1)
|
|
2926
|
+
return sortError('sort object must have one key; ignored', item);
|
|
2927
|
+
const [f, d] = e[0];
|
|
2928
|
+
let asc;
|
|
2929
|
+
if (typeof d == 'string') {
|
|
2930
|
+
const x = d.toLowerCase();
|
|
2931
|
+
if (x != 'asc' && x != 'desc')
|
|
2932
|
+
return sortError("sort direction must be 'asc' or 'desc'; ignored", item);
|
|
2933
|
+
asc = x == 'asc';
|
|
2934
|
+
}
|
|
2935
|
+
else if (typeof d == 'number') {
|
|
2936
|
+
if (d !== 1 && d !== -1)
|
|
2937
|
+
return sortError('sort direction must be 1 or -1; ignored', item);
|
|
2938
|
+
asc = d === 1;
|
|
2939
|
+
}
|
|
2940
|
+
else
|
|
2941
|
+
return sortError('sort direction must be a string or number; ignored', item);
|
|
2942
|
+
return (a, b) => base(a[f], b[f], asc);
|
|
2943
|
+
}
|
|
2944
|
+
/** the comparator of a `sort` prop (today's sortFunctionFromProp) */
|
|
2945
|
+
function sortFn(p) {
|
|
2946
|
+
if (!p)
|
|
2947
|
+
return;
|
|
2948
|
+
if (typeof p == 'function')
|
|
2949
|
+
return p;
|
|
2950
|
+
if (typeof p == 'string') {
|
|
2951
|
+
const d = p.toLowerCase();
|
|
2952
|
+
if (d == 'asc' || d == 'desc')
|
|
2953
|
+
return (a, b) => base(a, b, d == 'asc');
|
|
2954
|
+
return (a, b) => base(a[p], b[p]);
|
|
2955
|
+
}
|
|
2956
|
+
if (Array.isArray(p)) {
|
|
2957
|
+
const fs = p.map(i => typeof i == 'function' ? i
|
|
2958
|
+
: typeof i == 'string' ? (['asc', 'desc'].includes(i.toLowerCase()) ? undefined : (a, b) => base(a[i], b[i]))
|
|
2959
|
+
: isObj(i) ? fromObj(i) : undefined).filter(f => typeof f == 'function');
|
|
2960
|
+
return (a, b) => fs.reduce((r, f) => (r !== 0 ? r : f(a, b)), 0);
|
|
2961
|
+
}
|
|
2962
|
+
if (isObj(p))
|
|
2963
|
+
return fromObj(p);
|
|
2964
|
+
return sortError('Invalid sort prop; ignored', p);
|
|
2965
|
+
}
|
|
2966
|
+
|
|
5
2967
|
/**
|
|
6
2968
|
* Server-Side Rendering utilities for Sygnal components.
|
|
7
2969
|
*
|
|
@@ -21,7 +2983,12 @@ const ESC_MAP = {
|
|
|
21
2983
|
'"': '"',
|
|
22
2984
|
"'": ''',
|
|
23
2985
|
};
|
|
24
|
-
|
|
2986
|
+
// 4-F: renderComponent's t.html() serialises like the browser's innerHTML: text escapes only
|
|
2987
|
+
// & < >, attribute values only & and " (SSR output keeps escaping all five)
|
|
2988
|
+
let innerHtmlMode = false;
|
|
2989
|
+
// G-480: the <Slot> marker (its function in `data.m`), not a plain <slot> element
|
|
2990
|
+
const isSlot = (v) => v?.data?.m && v.sel === 'slot';
|
|
2991
|
+
function escapeHtml(str, attr) {
|
|
25
2992
|
return String(str).replace(/[&<>"']/g, (ch) => ESC_MAP[ch]);
|
|
26
2993
|
}
|
|
27
2994
|
/**
|
|
@@ -52,6 +3019,116 @@ function serializeStyle(style) {
|
|
|
52
3019
|
}
|
|
53
3020
|
return parts.join('; ');
|
|
54
3021
|
}
|
|
3022
|
+
// the `onError` option of the outermost renderToString call that has one (GS-11)
|
|
3023
|
+
let ssrOnError;
|
|
3024
|
+
// the `head` option of the outermost renderToString call that has one
|
|
3025
|
+
let heads;
|
|
3026
|
+
// 5-5: the `cache` option of the outermost renderToString call that has one
|
|
3027
|
+
let ssrCache;
|
|
3028
|
+
/**
|
|
3029
|
+
* PLAN-4 GS-1: a host's behaviors: each `uses` key missing from the state is the slice the
|
|
3030
|
+
* behavior starts with (its initialState, the options naming its keys, its calculated fields: the
|
|
3031
|
+
* factory's precomputed `state`), as the client's merge gives it (behaviors.ts). A host with no
|
|
3032
|
+
* state gets an object with just its slices
|
|
3033
|
+
*/
|
|
3034
|
+
function withUses(def, state) {
|
|
3035
|
+
const uses = def && def.uses;
|
|
3036
|
+
if (!uses || typeof uses !== 'object')
|
|
3037
|
+
return state;
|
|
3038
|
+
if (state == null)
|
|
3039
|
+
state = {};
|
|
3040
|
+
if (typeof state !== 'object' || Array.isArray(state))
|
|
3041
|
+
return state;
|
|
3042
|
+
let out = state;
|
|
3043
|
+
for (const k in uses) {
|
|
3044
|
+
const u = uses[k];
|
|
3045
|
+
if (!u)
|
|
3046
|
+
continue;
|
|
3047
|
+
let v = out[k] === undefined ? u.state : out[k];
|
|
3048
|
+
// G-423: a sygnal/ui part (ui/shared.ts keyed()) names its ids by its `uses` key (or its
|
|
3049
|
+
// `id` option) when the slice has no id, as the client's merge and calculated `id` do
|
|
3050
|
+
if (u.keyed && v && typeof v === 'object' && v.id == null)
|
|
3051
|
+
v = { ...v, id: u.options?.id ?? k };
|
|
3052
|
+
if (v !== out[k] && v !== undefined) {
|
|
3053
|
+
if (out === state)
|
|
3054
|
+
out = { ...state };
|
|
3055
|
+
out[k] = v;
|
|
3056
|
+
}
|
|
3057
|
+
}
|
|
3058
|
+
return out;
|
|
3059
|
+
}
|
|
3060
|
+
/**
|
|
3061
|
+
* 5-5 (H-7): the state a component's view renders with: each `resources` entry missing from the
|
|
3062
|
+
* state reads from the cache ('success' with the cached data), else 'loading' ('idle' for a
|
|
3063
|
+
* falsy request), as the client's first paint does with the same (hydrated) cache
|
|
3064
|
+
*/
|
|
3065
|
+
function withResources(def, state) {
|
|
3066
|
+
state = withUses(def, state);
|
|
3067
|
+
const res = def && def.resources;
|
|
3068
|
+
if (!res || !state || typeof state !== 'object' || Array.isArray(state))
|
|
3069
|
+
return state;
|
|
3070
|
+
const out = { ...state };
|
|
3071
|
+
for (const n of Object.keys(res)) {
|
|
3072
|
+
if (out[n] !== undefined)
|
|
3073
|
+
continue;
|
|
3074
|
+
let q;
|
|
3075
|
+
try {
|
|
3076
|
+
q = typeof res[n] === 'function' ? res[n](state) : res[n];
|
|
3077
|
+
}
|
|
3078
|
+
catch (_) { }
|
|
3079
|
+
const E = q && ssrCache ? ssrCache.get(ssrCache.key(q, 1)) : undefined;
|
|
3080
|
+
out[n] = E && E.at > 0 ? { status: 'success', data: E.v } : { status: q ? 'loading' : 'idle' };
|
|
3081
|
+
}
|
|
3082
|
+
return out;
|
|
3083
|
+
}
|
|
3084
|
+
// PLAN-4 GS-9: uid(name?) as on the client: the root is 'u'; a child component adds its path in
|
|
3085
|
+
// the parent's view (or its `id` prop), as getComponentIdFromElement and instantiateSubComponents
|
|
3086
|
+
// in the core do; a Collection item adds its key, a Switchable page its name; anything but
|
|
3087
|
+
// each part encoded by uidPart (G-214); in the root option anything but [A-Za-z0-9_-] becomes '_'
|
|
3088
|
+
// (as run() does). SSR ids = hydration ids
|
|
3089
|
+
const makeUid = (base) => (n) => n ? base + '-' + n : base;
|
|
3090
|
+
function childUid(uid, vnode, path) {
|
|
3091
|
+
const id = vnode.data?.props?.id;
|
|
3092
|
+
return uid + '-' + uidPart(('::' + ((id && JSON.stringify(id).replaceAll('"', '')) || path)).replace(/.*::(r\.)?/, ''));
|
|
3093
|
+
}
|
|
3094
|
+
// G-567: a view that returns a string or a number renders it as text (core/instance.ts view());
|
|
3095
|
+
// another falsy value, an empty <div>
|
|
3096
|
+
const textOr = (r) => typeof r == 'string' || typeof r == 'number' ? { text: '' + r } : r;
|
|
3097
|
+
const viewOut = (r) => textOr(r) || { sel: 'div', data: {}, children: [], text: undefined, elm: undefined, key: undefined };
|
|
3098
|
+
const errorDiv = () => ({ sel: 'div', data: { attrs: { 'data-sygnal-error': '' } }, children: [], text: undefined, elm: undefined, key: undefined });
|
|
3099
|
+
/**
|
|
3100
|
+
* A view threw: the component's onError boundary picks the fallback (the error <div> without
|
|
3101
|
+
* one, or when it throws), then the app's onError hook is told (GS-11)
|
|
3102
|
+
*/
|
|
3103
|
+
function viewFailed(def, err, name) {
|
|
3104
|
+
let vnode = errorDiv();
|
|
3105
|
+
if (typeof def.onError === 'function') {
|
|
3106
|
+
try {
|
|
3107
|
+
vnode = def.onError(err, { componentName: name });
|
|
3108
|
+
}
|
|
3109
|
+
catch (_) {
|
|
3110
|
+
vnode = errorDiv();
|
|
3111
|
+
}
|
|
3112
|
+
}
|
|
3113
|
+
// reporting only: a throwing hook is logged and swallowed (no diagnostics import: the Astro and
|
|
3114
|
+
// Vike server bundles carry this file without the core)
|
|
3115
|
+
try {
|
|
3116
|
+
ssrOnError && ssrOnError(err, { componentName: name, phase: 'view' });
|
|
3117
|
+
}
|
|
3118
|
+
catch (e) {
|
|
3119
|
+
console.error(e);
|
|
3120
|
+
}
|
|
3121
|
+
return vnode;
|
|
3122
|
+
}
|
|
3123
|
+
function collectHead(def, state) {
|
|
3124
|
+
const h = def && def.head;
|
|
3125
|
+
if (!heads || !h)
|
|
3126
|
+
return;
|
|
3127
|
+
try {
|
|
3128
|
+
heads.push(typeof h === 'function' ? h(state) : h);
|
|
3129
|
+
}
|
|
3130
|
+
catch (_) { }
|
|
3131
|
+
}
|
|
55
3132
|
/**
|
|
56
3133
|
* Render a Sygnal component to an HTML string.
|
|
57
3134
|
*
|
|
@@ -62,12 +3139,38 @@ function serializeStyle(style) {
|
|
|
62
3139
|
* import { renderToString } from 'sygnal'
|
|
63
3140
|
*
|
|
64
3141
|
* const html = renderToString(App, { state: { count: 0 } })
|
|
65
|
-
* // → '<div><h1>Count: 0</h1></div>'
|
|
3142
|
+
* // → '<div data-sygnal-ssr=""><h1>Count: 0</h1></div>'
|
|
66
3143
|
* ```
|
|
3144
|
+
*
|
|
3145
|
+
* The root element (a fragment's first element) carries an empty `data-sygnal-ssr` attribute,
|
|
3146
|
+
* which marks the markup as Sygnal's server HTML (persist() under plain run() then restores after
|
|
3147
|
+
* the first render); the first client render removes it.
|
|
67
3148
|
*/
|
|
68
3149
|
function renderToString(componentDef, options = {}) {
|
|
3150
|
+
const prevHeads = heads, prevCache = ssrCache, prevOnError = ssrOnError;
|
|
3151
|
+
if (options.head)
|
|
3152
|
+
heads = options.head;
|
|
3153
|
+
if (options.cache)
|
|
3154
|
+
ssrCache = options.cache;
|
|
3155
|
+
if (options.onError)
|
|
3156
|
+
ssrOnError = options.onError;
|
|
3157
|
+
try {
|
|
3158
|
+
return renderRoot(componentDef, options);
|
|
3159
|
+
}
|
|
3160
|
+
finally {
|
|
3161
|
+
heads = prevHeads;
|
|
3162
|
+
ssrCache = prevCache;
|
|
3163
|
+
ssrOnError = prevOnError;
|
|
3164
|
+
}
|
|
3165
|
+
}
|
|
3166
|
+
function renderRoot(componentDef, options) {
|
|
69
3167
|
const { state, props = {}, context = {}, hydrateState } = options;
|
|
70
|
-
|
|
3168
|
+
// G-206: the uid root (sanitized as run() does)
|
|
3169
|
+
const uid = (options.uid || 'u').replace(/[^\w-]+/g, '_');
|
|
3170
|
+
const ownState = state !== undefined ? state : componentDef.initialState;
|
|
3171
|
+
// 5-5: the view sees its resources; the hydration script keeps the state as it was given
|
|
3172
|
+
const resolvedState = withResources(componentDef, ownState);
|
|
3173
|
+
collectHead(componentDef, resolvedState);
|
|
71
3174
|
// Build context: merge parent context with component's own context definitions
|
|
72
3175
|
const componentContext = componentDef.context || {};
|
|
73
3176
|
const mergedContext = { ...context };
|
|
@@ -89,36 +3192,42 @@ function renderToString(componentDef, options = {}) {
|
|
|
89
3192
|
children: props.children || [],
|
|
90
3193
|
slots: props.slots || {},
|
|
91
3194
|
context: mergedContext,
|
|
92
|
-
|
|
93
|
-
}
|
|
3195
|
+
uid: makeUid(uid),
|
|
3196
|
+
});
|
|
94
3197
|
}
|
|
95
3198
|
catch (err) {
|
|
96
3199
|
// Error boundary
|
|
97
|
-
|
|
98
|
-
const name = componentDef.componentName || componentDef.name || 'Component';
|
|
99
|
-
try {
|
|
100
|
-
vnode = componentDef.onError(err, { componentName: name });
|
|
101
|
-
}
|
|
102
|
-
catch (_) {
|
|
103
|
-
vnode = { sel: 'div', data: { attrs: { 'data-sygnal-error': '' } }, children: [], text: undefined, elm: undefined, key: undefined };
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
vnode = { sel: 'div', data: { attrs: { 'data-sygnal-error': '' } }, children: [], text: undefined, elm: undefined, key: undefined };
|
|
108
|
-
}
|
|
3200
|
+
vnode = viewFailed(componentDef, err, componentDef.componentName || componentDef.name || 'Component');
|
|
109
3201
|
}
|
|
110
3202
|
if (!vnode) {
|
|
111
3203
|
vnode = { sel: 'div', data: {}, children: [], text: undefined, elm: undefined, key: undefined };
|
|
112
3204
|
}
|
|
113
3205
|
// Process special components in the VNode tree
|
|
114
|
-
vnode = processSSRTree(vnode, mergedContext, resolvedState);
|
|
3206
|
+
vnode = processSSRTree(vnode, mergedContext, resolvedState, uid, 'r');
|
|
3207
|
+
// PLAN-4 3-R: mark the root element (a fragment's first element) as Sygnal's server markup, so
|
|
3208
|
+
// persist() under plain run() can tell it from a client-only app's loading placeholder. The
|
|
3209
|
+
// first client render drops the attribute (the new vnode doesn't have it)
|
|
3210
|
+
// (4-H: through nested fragments, e.g. a Collection's)
|
|
3211
|
+
const firstEl = (v) => {
|
|
3212
|
+
if (v?.sel)
|
|
3213
|
+
return v.sel !== '!' && v;
|
|
3214
|
+
if (Array.isArray(v?.children))
|
|
3215
|
+
for (const c of v.children) {
|
|
3216
|
+
const f = firstEl(c);
|
|
3217
|
+
if (f)
|
|
3218
|
+
return f;
|
|
3219
|
+
}
|
|
3220
|
+
};
|
|
3221
|
+
const first = vnode?.sel ? vnode : firstEl(vnode);
|
|
3222
|
+
if (first && !innerHtmlMode)
|
|
3223
|
+
first.data = { ...first.data, attrs: { 'data-sygnal-ssr': '', ...first.data?.attrs } };
|
|
115
3224
|
// Serialize to HTML
|
|
116
3225
|
let html = vnodeToHtml(vnode);
|
|
117
3226
|
// Optionally embed state for hydration
|
|
118
|
-
if (hydrateState &&
|
|
3227
|
+
if (hydrateState && ownState != null) {
|
|
119
3228
|
const varName = typeof hydrateState === 'string' ? hydrateState : '__SYGNAL_STATE__';
|
|
120
|
-
escapeHtml(JSON.stringify(
|
|
121
|
-
html += `<script>window.${varName}=${JSON.stringify(
|
|
3229
|
+
escapeHtml(JSON.stringify(ownState));
|
|
3230
|
+
html += `<script>window.${varName}=${JSON.stringify(ownState)}</script>`;
|
|
122
3231
|
}
|
|
123
3232
|
return html;
|
|
124
3233
|
}
|
|
@@ -126,7 +3235,7 @@ function renderToString(componentDef, options = {}) {
|
|
|
126
3235
|
* Walk the VNode tree and recursively render sub-components,
|
|
127
3236
|
* handle Suspense/Portal/Transition markers, and process Collections.
|
|
128
3237
|
*/
|
|
129
|
-
function processSSRTree(vnode, context, parentState) {
|
|
3238
|
+
function processSSRTree(vnode, context, parentState, uid, path) {
|
|
130
3239
|
if (!vnode)
|
|
131
3240
|
return vnode;
|
|
132
3241
|
if (typeof vnode === 'string' || vnode.text != null)
|
|
@@ -135,7 +3244,7 @@ function processSSRTree(vnode, context, parentState) {
|
|
|
135
3244
|
// Fragment: no selector, recurse into children
|
|
136
3245
|
if (!sel && vnode.children && Array.isArray(vnode.children)) {
|
|
137
3246
|
vnode.children = vnode.children
|
|
138
|
-
.map((c) => processSSRTree(c, context, parentState))
|
|
3247
|
+
.map((c, i) => processSSRTree(c, context, parentState, uid, `${path}.${i}`))
|
|
139
3248
|
.filter((c) => c != null);
|
|
140
3249
|
return vnode;
|
|
141
3250
|
}
|
|
@@ -145,11 +3254,13 @@ function processSSRTree(vnode, context, parentState) {
|
|
|
145
3254
|
if (children.length === 0)
|
|
146
3255
|
return null;
|
|
147
3256
|
if (children.length === 1)
|
|
148
|
-
return processSSRTree(children[0], context, parentState);
|
|
3257
|
+
return processSSRTree(children[0], context, parentState, uid, `${path}.0`);
|
|
3258
|
+
// P46-Q (D187): the client placeholder's selector (div.sygnal-portal), so hydration patches
|
|
3259
|
+
// this element in place and the Portal mounts from its postpatch (G-318)
|
|
149
3260
|
return {
|
|
150
|
-
sel: 'div',
|
|
151
|
-
data: { attrs: { 'data-sygnal-portal': '' } },
|
|
152
|
-
children: children.map((c) => processSSRTree(c, context, parentState)),
|
|
3261
|
+
sel: 'div.sygnal-portal',
|
|
3262
|
+
data: { attrs: { 'data-sygnal-portal': vnode.data?.props?.target ?? '' } },
|
|
3263
|
+
children: children.map((c, i) => processSSRTree(c, context, parentState, uid, `${path}.${i}`)),
|
|
153
3264
|
text: undefined,
|
|
154
3265
|
elm: undefined,
|
|
155
3266
|
key: undefined,
|
|
@@ -161,7 +3272,7 @@ function processSSRTree(vnode, context, parentState) {
|
|
|
161
3272
|
const child = children[0];
|
|
162
3273
|
if (!child)
|
|
163
3274
|
return null;
|
|
164
|
-
return processSSRTree(child, context, parentState);
|
|
3275
|
+
return processSSRTree(child, context, parentState, uid, path);
|
|
165
3276
|
}
|
|
166
3277
|
// Suspense: render children (SSR always shows content, not fallback)
|
|
167
3278
|
if (sel === 'suspense') {
|
|
@@ -169,11 +3280,11 @@ function processSSRTree(vnode, context, parentState) {
|
|
|
169
3280
|
if (children.length === 0)
|
|
170
3281
|
return null;
|
|
171
3282
|
if (children.length === 1)
|
|
172
|
-
return processSSRTree(children[0], context, parentState);
|
|
3283
|
+
return processSSRTree(children[0], context, parentState, uid, `${path}.0`);
|
|
173
3284
|
return {
|
|
174
3285
|
sel: 'div',
|
|
175
3286
|
data: { attrs: { 'data-sygnal-suspense': 'resolved' } },
|
|
176
|
-
children: children.map((c) => processSSRTree(c, context, parentState)),
|
|
3287
|
+
children: children.map((c, i) => processSSRTree(c, context, parentState, uid, `${path}.${i}`)),
|
|
177
3288
|
text: undefined,
|
|
178
3289
|
elm: undefined,
|
|
179
3290
|
key: undefined,
|
|
@@ -185,7 +3296,7 @@ function processSSRTree(vnode, context, parentState) {
|
|
|
185
3296
|
const fallback = props.fallback;
|
|
186
3297
|
if (fallback) {
|
|
187
3298
|
// fallback can be a VNode or a string
|
|
188
|
-
return processSSRTree(fallback, context, parentState);
|
|
3299
|
+
return processSSRTree(fallback, context, parentState, uid, path);
|
|
189
3300
|
}
|
|
190
3301
|
// No fallback — render an empty placeholder div
|
|
191
3302
|
return {
|
|
@@ -197,85 +3308,70 @@ function processSSRTree(vnode, context, parentState) {
|
|
|
197
3308
|
key: undefined,
|
|
198
3309
|
};
|
|
199
3310
|
}
|
|
3311
|
+
// PLAN-5 W-1 widget marker: the host element with the widget's `fallback` inside (processed like
|
|
3312
|
+
// any children); the client patch replaces the fallback and mounts the widget (extra/widget.ts)
|
|
3313
|
+
if (sel === 'widget' && vnode.data?.ww) {
|
|
3314
|
+
const { ww, wp, h } = vnode.data, fb = ww.def.fallback, host = ww.$ssr(vnode);
|
|
3315
|
+
if (fb != null)
|
|
3316
|
+
host.children = [].concat(typeof fb == 'function' ? fb(wp, h) : fb).map((c) => typeof c == 'object' ? c : { text: String(c) });
|
|
3317
|
+
return processSSRTree(host, context, parentState, uid, path);
|
|
3318
|
+
}
|
|
200
3319
|
// Slot: unwrap to children
|
|
201
|
-
if (
|
|
3320
|
+
if (isSlot(vnode)) {
|
|
202
3321
|
const children = vnode.children || [];
|
|
203
3322
|
if (children.length === 0)
|
|
204
3323
|
return null;
|
|
205
3324
|
if (children.length === 1)
|
|
206
|
-
return processSSRTree(children[0], context, parentState);
|
|
3325
|
+
return processSSRTree(children[0], context, parentState, uid, `${path}.0`);
|
|
207
3326
|
return {
|
|
208
3327
|
sel: 'div',
|
|
209
3328
|
data: {},
|
|
210
|
-
children: children.map((c) => processSSRTree(c, context, parentState)),
|
|
3329
|
+
children: children.map((c, i) => processSSRTree(c, context, parentState, uid, `${path}.${i}`)),
|
|
211
3330
|
text: undefined,
|
|
212
3331
|
elm: undefined,
|
|
213
3332
|
key: undefined,
|
|
214
3333
|
};
|
|
215
3334
|
}
|
|
216
3335
|
// Sub-component: render recursively
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
3336
|
+
vnode.data?.props || {};
|
|
3337
|
+
// (PLAN-4.6: the pragma's `data.c`, the component function)
|
|
3338
|
+
if (typeof vnode.data?.c === 'function') {
|
|
3339
|
+
return renderSubComponent(vnode, context, parentState, childUid(uid, vnode, path));
|
|
220
3340
|
}
|
|
221
3341
|
// Collection: render each item
|
|
222
3342
|
if (sel === 'collection') {
|
|
223
|
-
return renderCollection(vnode, context, parentState);
|
|
3343
|
+
return renderCollection(vnode, context, parentState, childUid(uid, vnode, path));
|
|
3344
|
+
}
|
|
3345
|
+
// PLAN-5 V-1: a VirtualCollection renders its no-layout window (the first rows) in its container
|
|
3346
|
+
if (sel === 'virtual-collection') {
|
|
3347
|
+
return renderVirtual(vnode, context, parentState, childUid(uid, vnode, path));
|
|
224
3348
|
}
|
|
225
3349
|
// Switchable: render the active component
|
|
226
3350
|
if (sel === 'switchable') {
|
|
227
|
-
return renderSwitchable(vnode, context, parentState);
|
|
3351
|
+
return renderSwitchable(vnode, context, parentState, childUid(uid, vnode, path));
|
|
228
3352
|
}
|
|
229
3353
|
// Regular element: recurse into children
|
|
230
3354
|
if (vnode.children) {
|
|
231
3355
|
if (Array.isArray(vnode.children)) {
|
|
232
3356
|
if (vnode.children.length > 0) {
|
|
233
3357
|
vnode.children = vnode.children
|
|
234
|
-
.map((c) => processSSRTree(c, context, parentState))
|
|
3358
|
+
.map((c, i) => processSSRTree(c, context, parentState, uid, `${path}.${i}`))
|
|
235
3359
|
.filter((c) => c != null);
|
|
236
3360
|
}
|
|
237
3361
|
}
|
|
238
3362
|
else if (vnode.children && typeof vnode.children === 'object') {
|
|
239
3363
|
// Single child object (text element)
|
|
240
|
-
vnode.children = processSSRTree(vnode.children, context, parentState);
|
|
3364
|
+
vnode.children = processSSRTree(vnode.children, context, parentState, uid, `${path}.0`);
|
|
241
3365
|
}
|
|
242
3366
|
}
|
|
243
3367
|
return vnode;
|
|
244
3368
|
}
|
|
245
3369
|
/**
|
|
246
|
-
* Render a sub-component (
|
|
3370
|
+
* Render a sub-component (the pragma's `data.c`: the component function, with its statics).
|
|
247
3371
|
*/
|
|
248
|
-
function renderSubComponent(vnode, context, parentState) {
|
|
249
|
-
const
|
|
250
|
-
const
|
|
251
|
-
// Get the component definition (view function with static properties)
|
|
252
|
-
let componentDef;
|
|
253
|
-
if (sygnalOptions) {
|
|
254
|
-
componentDef = sygnalOptions.view;
|
|
255
|
-
// Copy static properties
|
|
256
|
-
if (!componentDef.initialState && sygnalOptions.initialState) {
|
|
257
|
-
componentDef = Object.assign(componentDef, {
|
|
258
|
-
initialState: sygnalOptions.initialState,
|
|
259
|
-
model: sygnalOptions.model,
|
|
260
|
-
intent: sygnalOptions.intent,
|
|
261
|
-
context: sygnalOptions.context,
|
|
262
|
-
onError: sygnalOptions.onError,
|
|
263
|
-
calculated: sygnalOptions.calculated,
|
|
264
|
-
});
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
else if (sygnalFactory && sygnalFactory.componentName) {
|
|
268
|
-
// Factory-created component — we can't easily extract the view from an already-wrapped factory.
|
|
269
|
-
// Return a placeholder.
|
|
270
|
-
return {
|
|
271
|
-
sel: 'div',
|
|
272
|
-
data: { attrs: { 'data-sygnal-ssr': vnode.sel || 'component' } },
|
|
273
|
-
children: vnode.children || [],
|
|
274
|
-
text: undefined,
|
|
275
|
-
elm: undefined,
|
|
276
|
-
key: undefined,
|
|
277
|
-
};
|
|
278
|
-
}
|
|
3372
|
+
function renderSubComponent(vnode, context, parentState, uid) {
|
|
3373
|
+
const childProps = vnode.data?.props || {};
|
|
3374
|
+
const componentDef = vnode.data?.c;
|
|
279
3375
|
if (!componentDef || typeof componentDef !== 'function') {
|
|
280
3376
|
// Can't render — return children or empty div
|
|
281
3377
|
return {
|
|
@@ -297,6 +3393,7 @@ function renderSubComponent(vnode, context, parentState) {
|
|
|
297
3393
|
// State passed directly
|
|
298
3394
|
childState = stateProp;
|
|
299
3395
|
}
|
|
3396
|
+
childState = withResources(componentDef, childState);
|
|
300
3397
|
// Build child context
|
|
301
3398
|
const childContext = { ...context };
|
|
302
3399
|
const componentContext = componentDef.context || {};
|
|
@@ -314,7 +3411,7 @@ function renderSubComponent(vnode, context, parentState) {
|
|
|
314
3411
|
const defaultSlotChildren = [];
|
|
315
3412
|
const vnodeChildren = vnode.children || [];
|
|
316
3413
|
for (const child of vnodeChildren) {
|
|
317
|
-
if (child
|
|
3414
|
+
if (isSlot(child)) {
|
|
318
3415
|
const slotName = child.data?.props?.name || 'default';
|
|
319
3416
|
if (!slots[slotName])
|
|
320
3417
|
slots[slotName] = [];
|
|
@@ -330,6 +3427,7 @@ function renderSubComponent(vnode, context, parentState) {
|
|
|
330
3427
|
slots.default = [];
|
|
331
3428
|
slots.default.push(...defaultSlotChildren);
|
|
332
3429
|
}
|
|
3430
|
+
collectHead(componentDef, childState);
|
|
333
3431
|
// Call the view function
|
|
334
3432
|
let result;
|
|
335
3433
|
try {
|
|
@@ -339,43 +3437,102 @@ function renderSubComponent(vnode, context, parentState) {
|
|
|
339
3437
|
children: slots.default || vnodeChildren,
|
|
340
3438
|
slots,
|
|
341
3439
|
context: childContext,
|
|
342
|
-
|
|
343
|
-
}
|
|
3440
|
+
uid: makeUid(uid),
|
|
3441
|
+
});
|
|
344
3442
|
}
|
|
345
3443
|
catch (err) {
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
3444
|
+
result = viewFailed(componentDef, err, componentDef.componentName || componentDef.name || 'Component');
|
|
3445
|
+
}
|
|
3446
|
+
// Recursively process the rendered sub-tree
|
|
3447
|
+
return processSSRTree(viewOut(result), childContext, childState, uid, 'r');
|
|
3448
|
+
}
|
|
3449
|
+
/** the Collection's own props (core/hosts/collection.ts OWN): the others go to every item */
|
|
3450
|
+
const COLLECTION_OWN = new Set(['of', 'from', 'filter', 'sort', 'idfield', 'className', 'viewTransitionName']);
|
|
3451
|
+
/** the VirtualCollection container's props (extra/virtual.ts OWN) */
|
|
3452
|
+
const VIRTUAL_OWN = /^(estimateSize|overscan|role|tabIndex|style|id|aria-(label|labelledby|describedby))$/;
|
|
3453
|
+
/**
|
|
3454
|
+
* PLAN-5 2-S G-396: the items a Collection shows, as the client's host lists them
|
|
3455
|
+
* (core/hosts/collection.ts arrayCell + list()): `from` a state key (missing or not an array:
|
|
3456
|
+
* none, D178), a `{ get }` lens, or none (the owner's state is the array, or its `value`); then
|
|
3457
|
+
* `filter` (item, index, array) and `sort` (every form sortFn takes); a duplicate key once (D177).
|
|
3458
|
+
* Each entry: [the item, its raw index]
|
|
3459
|
+
*/
|
|
3460
|
+
function collectionItems(props, parentState) {
|
|
3461
|
+
const { from, filter, sort } = props;
|
|
3462
|
+
let a;
|
|
3463
|
+
if (from === undefined)
|
|
3464
|
+
a = !Array.isArray(parentState) && Array.isArray(parentState?.value) ? parentState.value : parentState;
|
|
3465
|
+
else if (typeof from === 'string')
|
|
3466
|
+
a = parentState?.[from];
|
|
3467
|
+
else if (from && typeof from === 'object' && typeof from.get === 'function') {
|
|
3468
|
+
try {
|
|
3469
|
+
a = from.get(parentState);
|
|
354
3470
|
}
|
|
355
|
-
|
|
356
|
-
|
|
3471
|
+
catch (_) {
|
|
3472
|
+
a = undefined;
|
|
357
3473
|
}
|
|
358
3474
|
}
|
|
359
|
-
if (!
|
|
360
|
-
|
|
3475
|
+
if (!Array.isArray(a))
|
|
3476
|
+
return [];
|
|
3477
|
+
let idx = a.map((_, i) => i);
|
|
3478
|
+
try {
|
|
3479
|
+
if (typeof filter === 'function')
|
|
3480
|
+
idx = idx.filter((i) => filter(a[i], i, a));
|
|
3481
|
+
const cmp = sort ? sortFn(sort) : undefined;
|
|
3482
|
+
if (cmp)
|
|
3483
|
+
idx.sort((x, y) => cmp(a[x], a[y]));
|
|
3484
|
+
}
|
|
3485
|
+
catch (_) { /* as the client: a throwing filter / sort renders the array as it is */ }
|
|
3486
|
+
const first = new Map(), out = [];
|
|
3487
|
+
for (let i = 0; i < a.length; i++) {
|
|
3488
|
+
const k = keyOf(a[i], i);
|
|
3489
|
+
if (!first.has(k))
|
|
3490
|
+
first.set(k, i);
|
|
361
3491
|
}
|
|
362
|
-
|
|
363
|
-
|
|
3492
|
+
for (const i of idx)
|
|
3493
|
+
if (first.get(keyOf(a[i], i)) === i)
|
|
3494
|
+
out.push([a[i], i]);
|
|
3495
|
+
return out;
|
|
3496
|
+
}
|
|
3497
|
+
/** a component's children split into slots (as renderSubComponent: `<Slot name>` children by name, the rest `default`) */
|
|
3498
|
+
function slotsOf(children) {
|
|
3499
|
+
const slots = {};
|
|
3500
|
+
for (const child of children) {
|
|
3501
|
+
const name = isSlot(child) ? child.data?.props?.name || 'default' : 'default';
|
|
3502
|
+
(slots[name] || (slots[name] = [])).push(...(isSlot(child) ? child.children || [] : [child]));
|
|
3503
|
+
}
|
|
3504
|
+
return slots;
|
|
364
3505
|
}
|
|
365
3506
|
/**
|
|
366
|
-
* Render a Collection
|
|
3507
|
+
* Render a Collection: its items (collectionItems: from, filter, sort), each with the other
|
|
3508
|
+
* props and the Collection's children, as the client's host gives them (G-396). `limit`: only
|
|
3509
|
+
* the first that many (a VirtualCollection's window); `skip`: props that aren't the items'.
|
|
3510
|
+
* 4-H (D229): a fragment of the items (no wrapper element), as the client's.
|
|
367
3511
|
*/
|
|
368
|
-
function renderCollection(vnode, context, parentState) {
|
|
3512
|
+
function renderCollection(vnode, context, parentState, uid, limit, skip, deco) {
|
|
369
3513
|
const props = vnode.data?.props || {};
|
|
370
|
-
const { of: itemComponent,
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
const
|
|
3514
|
+
const { of: itemComponent, viewTransitionName: vtn } = props;
|
|
3515
|
+
const frag = (children) => ({ sel: undefined, data: {}, children, text: undefined, elm: undefined, key: undefined });
|
|
3516
|
+
if (!itemComponent || typeof itemComponent !== 'function')
|
|
3517
|
+
return frag([]);
|
|
3518
|
+
let items = collectionItems(props, parentState);
|
|
3519
|
+
items.length;
|
|
3520
|
+
if (limit !== undefined)
|
|
3521
|
+
items = items.slice(0, limit);
|
|
3522
|
+
const itemProps = {};
|
|
3523
|
+
for (const k in props)
|
|
3524
|
+
if (!COLLECTION_OWN.has(k) && !(skip && skip.test(k)) && k !== 'key' && k !== 'children')
|
|
3525
|
+
itemProps[k] = props[k];
|
|
3526
|
+
const kids = vnode.children || [];
|
|
3527
|
+
const slots = slotsOf(kids);
|
|
3528
|
+
const renderedItems = items.map(([raw, index], pos) => {
|
|
3529
|
+
let itemState = raw;
|
|
3530
|
+
// GS-9: the key the client's Collection gives this item
|
|
3531
|
+
const isItemObj = itemState && typeof itemState === 'object' && !Array.isArray(itemState);
|
|
3532
|
+
// PLAN-4.6 G-322: an id-less item's uid part is `_i<index>` (core/cell.ts keyName)
|
|
3533
|
+
const itemUid = uid + '-' + (isItemObj && itemState.id != null ? uidPart(itemState.id) : '_i' + index);
|
|
3534
|
+
// GS-1: an item host's behavior slices (the client reads them as defaults, behaviors.ts)
|
|
3535
|
+
itemState = withUses(itemComponent, itemState);
|
|
379
3536
|
// Build context for this item
|
|
380
3537
|
const itemContext = { ...context };
|
|
381
3538
|
const componentContext = itemComponent.context || {};
|
|
@@ -391,45 +3548,70 @@ function renderCollection(vnode, context, parentState) {
|
|
|
391
3548
|
let itemVnode;
|
|
392
3549
|
try {
|
|
393
3550
|
itemVnode = itemComponent({
|
|
3551
|
+
...itemProps,
|
|
394
3552
|
state: itemState,
|
|
395
|
-
children:
|
|
396
|
-
slots
|
|
3553
|
+
children: slots.default || kids,
|
|
3554
|
+
slots,
|
|
397
3555
|
context: itemContext,
|
|
398
|
-
|
|
399
|
-
}
|
|
3556
|
+
uid: makeUid(itemUid),
|
|
3557
|
+
});
|
|
400
3558
|
}
|
|
401
3559
|
catch (err) {
|
|
402
|
-
|
|
403
|
-
try {
|
|
404
|
-
itemVnode = itemComponent.onError(err, { componentName: itemComponent.name || 'CollectionItem' });
|
|
405
|
-
}
|
|
406
|
-
catch (_) {
|
|
407
|
-
itemVnode = { sel: 'div', data: { attrs: { 'data-sygnal-error': '' } }, children: [], text: undefined, elm: undefined, key: undefined };
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
else {
|
|
411
|
-
itemVnode = { sel: 'div', data: { attrs: { 'data-sygnal-error': '' } }, children: [], text: undefined, elm: undefined, key: undefined };
|
|
412
|
-
}
|
|
3560
|
+
itemVnode = viewFailed(itemComponent, err, itemComponent.name || 'CollectionItem');
|
|
413
3561
|
}
|
|
414
|
-
|
|
3562
|
+
const out = processSSRTree(textOr(itemVnode), itemContext, itemState, itemUid, 'r');
|
|
3563
|
+
// PLAN-5 A-1: the names the client's Collection gives a keyed item's root element
|
|
3564
|
+
const named = vtn && isItemObj && itemState.id != null && out?.sel
|
|
3565
|
+
? { ...out, data: { ...out.data, style: vtStyle(vtn, itemState.id, out.data?.style) } }
|
|
3566
|
+
: out;
|
|
3567
|
+
// a VirtualCollection's row decoration, with the row's position in the list (G-431: counted
|
|
3568
|
+
// before the rows that render nothing are left out, as the client counts them)
|
|
3569
|
+
return deco && named?.sel ? deco(named, pos) : named;
|
|
415
3570
|
}).filter((v) => v != null);
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
3571
|
+
return frag(renderedItems);
|
|
3572
|
+
}
|
|
3573
|
+
/**
|
|
3574
|
+
* PLAN-5 V-1: a VirtualCollection on the server: the client's markup (extra/virtual.ts) for the
|
|
3575
|
+
* window it computes without layout, the first 10 rows + overscan, with the spacer as tall as
|
|
3576
|
+
* every row's estimate. The client measures and moves the window once it has layout. G-396: the
|
|
3577
|
+
* rows are the Collection's (from, filter, sort, the other props and the children to every
|
|
3578
|
+
* item); aria-setsize and the spacer count the filtered list.
|
|
3579
|
+
*/
|
|
3580
|
+
function renderVirtual(vnode, context, parentState, uid) {
|
|
3581
|
+
const p = vnode.data?.props || {}, est = p.estimateSize, size = est > 0 ? est : 32;
|
|
3582
|
+
const n = 10 + (p.overscan >= 0 ? p.overscan : 5);
|
|
3583
|
+
const items = typeof p.of === 'function' ? collectionItems(p, parentState) : [];
|
|
3584
|
+
const role = p.role === undefined ? 'list' : p.role;
|
|
3585
|
+
const rows = renderCollection(vnode, context, parentState, uid, n, VIRTUAL_OWN, (r, i) => {
|
|
3586
|
+
const own = r.data?.attrs?.role || r.data?.props?.role, attrs = { ...r.data?.attrs, 'data-index': i };
|
|
3587
|
+
if (role == 'list' || own)
|
|
3588
|
+
attrs['aria-posinset'] = i + 1, attrs['aria-setsize'] = items.length;
|
|
3589
|
+
if (role == 'list' && !own)
|
|
3590
|
+
attrs.role = 'listitem';
|
|
3591
|
+
return { ...r, data: { ...r.data, attrs } };
|
|
3592
|
+
}).children;
|
|
3593
|
+
const attrs = { tabindex: p.tabIndex ?? 0 };
|
|
3594
|
+
if (role != null)
|
|
3595
|
+
attrs.role = role;
|
|
3596
|
+
for (const k of ['id', 'aria-label', 'aria-labelledby', 'aria-describedby'])
|
|
3597
|
+
if (p[k] != null)
|
|
3598
|
+
attrs[k] = p[k];
|
|
3599
|
+
let total = 0;
|
|
3600
|
+
for (let i = 0; i < items.length; i++) {
|
|
3601
|
+
const s = typeof est == 'function' ? est(items[i][0], i) : size;
|
|
3602
|
+
total += s > 0 ? s : 32;
|
|
419
3603
|
}
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
key: undefined,
|
|
427
|
-
};
|
|
3604
|
+
const div = (data, children) => ({ sel: 'div', data, children, text: undefined, elm: undefined, key: undefined });
|
|
3605
|
+
return div({ props: p.className ? { className: p.className } : {}, attrs, style: { overflowY: 'auto', overflowAnchor: 'none', ...p.style } }, [
|
|
3606
|
+
div({ style: { position: 'relative', width: '100%', height: total + 'px' } }, [
|
|
3607
|
+
div({ style: { position: 'absolute', top: '0', left: '0', width: '100%', transform: 'translateY(0px)' } }, rows),
|
|
3608
|
+
]),
|
|
3609
|
+
]);
|
|
428
3610
|
}
|
|
429
3611
|
/**
|
|
430
3612
|
* Render a Switchable by determining the active component from state.
|
|
431
3613
|
*/
|
|
432
|
-
function renderSwitchable(vnode, context, parentState) {
|
|
3614
|
+
function renderSwitchable(vnode, context, parentState, uid) {
|
|
433
3615
|
const props = vnode.data?.props || {};
|
|
434
3616
|
const { components, active, initial } = props;
|
|
435
3617
|
if (!components) {
|
|
@@ -456,13 +3638,13 @@ function renderSwitchable(vnode, context, parentState) {
|
|
|
456
3638
|
if (!activeComponent || typeof activeComponent !== 'function') {
|
|
457
3639
|
return { sel: 'div', data: {}, children: [], text: undefined, elm: undefined, key: undefined };
|
|
458
3640
|
}
|
|
459
|
-
return renderToStringInternal(activeComponent, parentState, context);
|
|
3641
|
+
return renderToStringInternal(activeComponent, parentState, context, uid + '-' + uidPart(activeName));
|
|
460
3642
|
}
|
|
461
3643
|
/**
|
|
462
3644
|
* Internal helper: render a component def to a VNode (not HTML string).
|
|
463
3645
|
*/
|
|
464
|
-
function renderToStringInternal(componentDef, state, context) {
|
|
465
|
-
const resolvedState = state !== undefined ? state : componentDef.initialState;
|
|
3646
|
+
function renderToStringInternal(componentDef, state, context, uid) {
|
|
3647
|
+
const resolvedState = withResources(componentDef, state !== undefined ? state : componentDef.initialState);
|
|
466
3648
|
const componentContext = componentDef.context || {};
|
|
467
3649
|
const mergedContext = { ...context };
|
|
468
3650
|
for (const key of Object.keys(componentContext)) {
|
|
@@ -474,6 +3656,7 @@ function renderToStringInternal(componentDef, state, context) {
|
|
|
474
3656
|
catch (_) { }
|
|
475
3657
|
}
|
|
476
3658
|
}
|
|
3659
|
+
collectHead(componentDef, resolvedState);
|
|
477
3660
|
let vnode;
|
|
478
3661
|
try {
|
|
479
3662
|
vnode = componentDef({
|
|
@@ -481,31 +3664,34 @@ function renderToStringInternal(componentDef, state, context) {
|
|
|
481
3664
|
children: [],
|
|
482
3665
|
slots: {},
|
|
483
3666
|
context: mergedContext,
|
|
484
|
-
|
|
485
|
-
}
|
|
3667
|
+
uid: makeUid(uid),
|
|
3668
|
+
});
|
|
486
3669
|
}
|
|
487
3670
|
catch (err) {
|
|
488
|
-
|
|
489
|
-
try {
|
|
490
|
-
vnode = componentDef.onError(err, { componentName: componentDef.name || 'Component' });
|
|
491
|
-
}
|
|
492
|
-
catch (_) {
|
|
493
|
-
vnode = { sel: 'div', data: { attrs: { 'data-sygnal-error': '' } }, children: [], text: undefined, elm: undefined, key: undefined };
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
else {
|
|
497
|
-
vnode = { sel: 'div', data: { attrs: { 'data-sygnal-error': '' } }, children: [], text: undefined, elm: undefined, key: undefined };
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
if (!vnode) {
|
|
501
|
-
vnode = { sel: 'div', data: {}, children: [], text: undefined, elm: undefined, key: undefined };
|
|
3671
|
+
vnode = viewFailed(componentDef, err, componentDef.name || 'Component');
|
|
502
3672
|
}
|
|
503
|
-
return processSSRTree(vnode, mergedContext, resolvedState);
|
|
3673
|
+
return processSSRTree(viewOut(vnode), mergedContext, resolvedState, uid, 'r');
|
|
504
3674
|
}
|
|
3675
|
+
const ws = (t) => t.replace(/[\t\n\f\r ]+/g, ' ').replace(/^ | $/g, '');
|
|
3676
|
+
const fieldValue = (data) => data?.props?.value ?? data?.attrs?.value;
|
|
3677
|
+
const withoutValue = (data) => {
|
|
3678
|
+
const out = { ...data };
|
|
3679
|
+
if (out.props) {
|
|
3680
|
+
out.props = { ...out.props };
|
|
3681
|
+
delete out.props.value;
|
|
3682
|
+
}
|
|
3683
|
+
if (out.attrs) {
|
|
3684
|
+
out.attrs = { ...out.attrs };
|
|
3685
|
+
delete out.attrs.value;
|
|
3686
|
+
}
|
|
3687
|
+
return out;
|
|
3688
|
+
};
|
|
3689
|
+
const textOf = (v) => v == null ? '' : typeof v != 'object' ? String(v)
|
|
3690
|
+
: v.text != null ? String(v.text) : Array.isArray(v.children) ? v.children.map(textOf).join('') : '';
|
|
505
3691
|
/**
|
|
506
3692
|
* Serialize a VNode tree to an HTML string.
|
|
507
3693
|
*/
|
|
508
|
-
function vnodeToHtml(vnode) {
|
|
3694
|
+
function vnodeToHtml(vnode, sv) {
|
|
509
3695
|
if (vnode == null)
|
|
510
3696
|
return '';
|
|
511
3697
|
// Text node
|
|
@@ -520,14 +3706,35 @@ function vnodeToHtml(vnode) {
|
|
|
520
3706
|
return escapeHtml(String(vnode.text));
|
|
521
3707
|
// Fragment: no selector, but has children — concatenate child HTML
|
|
522
3708
|
if (vnode.children && Array.isArray(vnode.children)) {
|
|
523
|
-
return vnode.children.map((c) => vnodeToHtml(c)).join('');
|
|
3709
|
+
return vnode.children.map((c) => vnodeToHtml(c, sv)).join('');
|
|
524
3710
|
}
|
|
525
3711
|
return '';
|
|
526
3712
|
}
|
|
527
3713
|
// Parse selector: tag#id.class1.class2
|
|
528
3714
|
const { tag, id, selectorClasses } = parseSelector(sel);
|
|
3715
|
+
let data = vnode.data || {}, content;
|
|
3716
|
+
const value = fieldValue(data);
|
|
3717
|
+
if (tag == 'textarea' && value != null) {
|
|
3718
|
+
data = withoutValue(data);
|
|
3719
|
+
// the HTML parser drops a leading newline (a CR or CRLF is one: G-495), so one is added
|
|
3720
|
+
const t = String(value);
|
|
3721
|
+
content = escapeHtml((t[0] == '\n' || t[0] == '\r' ? '\n' : '') + t);
|
|
3722
|
+
}
|
|
3723
|
+
else if (tag == 'select' && value != null) {
|
|
3724
|
+
data = withoutValue(data);
|
|
3725
|
+
sv = { v: [].concat(value).map(String), m: !!(data.props?.multiple ?? data.attrs?.multiple) };
|
|
3726
|
+
}
|
|
3727
|
+
else if (tag == 'option' && sv && data.props?.selected == null && data.attrs?.selected == null) {
|
|
3728
|
+
if (sv.v.includes(value != null ? String(value) : ws(textOf(vnode)))) {
|
|
3729
|
+
data = { ...data, attrs: { ...data.attrs, selected: true } };
|
|
3730
|
+
if (!sv.m)
|
|
3731
|
+
sv.v = [];
|
|
3732
|
+
}
|
|
3733
|
+
}
|
|
3734
|
+
if (tag != 'select' && tag != 'optgroup' && tag != 'option')
|
|
3735
|
+
sv = undefined;
|
|
529
3736
|
// Build attributes from VNode data
|
|
530
|
-
const attrs = buildAttributes(
|
|
3737
|
+
const attrs = buildAttributes(data, id, selectorClasses, tag.includes('-'));
|
|
531
3738
|
// Opening tag
|
|
532
3739
|
let html = `<${tag}`;
|
|
533
3740
|
for (const [key, val] of attrs) {
|
|
@@ -551,14 +3758,17 @@ function vnodeToHtml(vnode) {
|
|
|
551
3758
|
}
|
|
552
3759
|
// Children — snabbdom uses `text` for single text children (even when
|
|
553
3760
|
// `children` holds a text element object). Prioritize `text` when set.
|
|
554
|
-
if (
|
|
3761
|
+
if (content !== undefined) {
|
|
3762
|
+
html += content;
|
|
3763
|
+
}
|
|
3764
|
+
else if (vnode.text != null) {
|
|
555
3765
|
html += escapeHtml(String(vnode.text));
|
|
556
3766
|
}
|
|
557
3767
|
else if (vnode.children) {
|
|
558
3768
|
// children can be an array or a single text element object
|
|
559
3769
|
const kids = Array.isArray(vnode.children) ? vnode.children : [vnode.children];
|
|
560
3770
|
for (const child of kids) {
|
|
561
|
-
html += vnodeToHtml(child);
|
|
3771
|
+
html += vnodeToHtml(child, sv);
|
|
562
3772
|
}
|
|
563
3773
|
}
|
|
564
3774
|
html += `</${tag}>`;
|
|
@@ -606,12 +3816,15 @@ function parseSelector(sel) {
|
|
|
606
3816
|
/**
|
|
607
3817
|
* Build an ordered list of [attrName, attrValue] from VNode data.
|
|
608
3818
|
*/
|
|
609
|
-
|
|
3819
|
+
// 1-R G-365: camelCase HTML IDL properties whose content attribute is their lowercase name
|
|
3820
|
+
const IDL_ATTRS = /^(tabIndex|readOnly|maxLength|minLength|contentEditable|accessKey|inputMode|enterKeyHint|spellCheck|autoFocus|autoComplete|autoCapitalize|autoPlay|noValidate|formAction|formEnctype|formMethod|formNoValidate|formTarget|crossOrigin|referrerPolicy|useMap|isMap|dateTime|colSpan|rowSpan|srcSet|allowFullscreen|playsInline|noModule|popoverTarget|popoverTargetAction|encType)$/;
|
|
3821
|
+
const kebab = (k) => k.replace(/[A-Z]/g, (c) => '-' + c.toLowerCase());
|
|
3822
|
+
function buildAttributes(data, selectorId, selectorClasses, custom) {
|
|
610
3823
|
const result = [];
|
|
611
3824
|
const classNames = [...selectorClasses];
|
|
612
3825
|
// From data.props (DOM properties like className, htmlFor, etc.)
|
|
613
3826
|
if (data.props) {
|
|
614
|
-
for (
|
|
3827
|
+
for (let [key, val] of Object.entries(data.props)) {
|
|
615
3828
|
if (key === 'className') {
|
|
616
3829
|
if (typeof val === 'string' && val)
|
|
617
3830
|
classNames.push(val);
|
|
@@ -620,13 +3833,28 @@ function buildAttributes(data, selectorId, selectorClasses) {
|
|
|
620
3833
|
result.push(['for', val]);
|
|
621
3834
|
}
|
|
622
3835
|
else if (key === 'innerHTML' || key === 'textContent') ;
|
|
623
|
-
else if (
|
|
624
|
-
else
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
3836
|
+
else if (custom && (typeof val === 'function' || (val && typeof val === 'object'))) ;
|
|
3837
|
+
else {
|
|
3838
|
+
// PLAN-5 D199 / 1-R G-365: a custom element's camelCase property as attributes. A
|
|
3839
|
+
// reflected HTML IDL name gets its attribute (tabIndex → tabindex, readOnly → readonly),
|
|
3840
|
+
// an ARIA reflection its aria-* one (ariaLabel → aria-label). Any other camelCase name is
|
|
3841
|
+
// written twice: kebab-case (withClear → with-clear: Web Awesome / Shoelace's declared
|
|
3842
|
+
// attributes, Stencil's default, sygnal/element's defineElement) and lowercase
|
|
3843
|
+
// (withclear: Lit's and FAST's default attribute name); the element reads the one it
|
|
3844
|
+
// observes and ignores the other
|
|
3845
|
+
const keys = !custom || !/[A-Z]/.test(key) ? [key]
|
|
3846
|
+
: IDL_ATTRS.test(key) ? [key.toLowerCase()]
|
|
3847
|
+
: /^aria[A-Z]/.test(key) ? [kebab(key)]
|
|
3848
|
+
: [kebab(key), key.toLowerCase()];
|
|
3849
|
+
for (const k of keys) {
|
|
3850
|
+
if (typeof val === 'boolean') {
|
|
3851
|
+
if (val)
|
|
3852
|
+
result.push([k, true]);
|
|
3853
|
+
}
|
|
3854
|
+
else if (val != null) {
|
|
3855
|
+
result.push([k, val]);
|
|
3856
|
+
}
|
|
3857
|
+
}
|
|
630
3858
|
}
|
|
631
3859
|
}
|
|
632
3860
|
}
|
|
@@ -683,8 +3911,7 @@ function buildAttributes(data, selectorId, selectorClasses) {
|
|
|
683
3911
|
function looksLikeSygnalComponent(Component) {
|
|
684
3912
|
if (typeof Component !== 'function')
|
|
685
3913
|
return false;
|
|
686
|
-
return Boolean(Component.
|
|
687
|
-
Component.model ||
|
|
3914
|
+
return Boolean(Component.model ||
|
|
688
3915
|
Component.intent ||
|
|
689
3916
|
Component.initialState ||
|
|
690
3917
|
Component.componentName);
|
|
@@ -699,6 +3926,10 @@ function renderToStaticMarkup(Component, props = {}, _slotted, _metadata) {
|
|
|
699
3926
|
const html = renderToString(Component, {
|
|
700
3927
|
state: props.initialState || Component.initialState,
|
|
701
3928
|
props: { ...props, props },
|
|
3929
|
+
// PLAN-4 GS-11: the app-level error hook (as the client's run() gets)
|
|
3930
|
+
onError,
|
|
3931
|
+
// G-206: a `uid` island prop is its uid root (as on the client), for two islands on a page
|
|
3932
|
+
uid: props.uid,
|
|
702
3933
|
});
|
|
703
3934
|
return { html, attrs: {} };
|
|
704
3935
|
}
|