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