@askrjs/askr 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/CHANGELOG.md +874 -0
  2. package/README.md +61 -29
  3. package/capabilities.json +19 -9
  4. package/dist/actions/index.js +56 -12
  5. package/dist/benchmark.js +10 -15
  6. package/dist/boot/index.d.ts +3 -2
  7. package/dist/boot/index.js +1 -1
  8. package/dist/boot-DaoTYoCw.js +3989 -0
  9. package/dist/browser-activity-CB8e-V4f.js +220 -0
  10. package/dist/components/index.d.ts +8 -1
  11. package/dist/components/index.js +1 -43
  12. package/dist/{aria-hKjThHcp.js → compose-ref-DWzdbxsD.js} +41 -4
  13. package/dist/control/index.d.ts +2 -0
  14. package/dist/control/index.js +1 -1
  15. package/dist/control-nfpT2fbK.js +209 -0
  16. package/dist/core.d.ts +5 -9
  17. package/dist/csp-nonce-DwGw1A6Q.js +35 -0
  18. package/dist/data/index.js +3 -3
  19. package/dist/{data-2edW0jhF.js → data-BCwClJiF.js} +283 -94
  20. package/dist/data-runtime-C1bFAlba.js +242 -0
  21. package/dist/{deferred-CbgNhf67.js → deferred-bEEHHvic.js} +42 -20
  22. package/dist/domains/actions.d.ts +8 -3
  23. package/dist/domains/component.d.ts +1 -107
  24. package/dist/domains/context.d.ts +0 -15
  25. package/dist/domains/control.d.ts +36 -249
  26. package/dist/domains/data.d.ts +31 -13
  27. package/dist/domains/diagnostics.d.ts +1 -2
  28. package/dist/domains/lifecycle.d.ts +2 -5
  29. package/dist/domains/refs.d.ts +0 -2
  30. package/dist/domains/routing.d.ts +43 -8
  31. package/dist/domains/scheduler.d.ts +1 -76
  32. package/dist/domains/server.d.ts +5 -2
  33. package/dist/domains/state.d.ts +2 -5
  34. package/dist/domains/telemetry.d.ts +0 -2
  35. package/dist/elements.d.ts +214 -51
  36. package/dist/error-boundary-Bpwofwps.js +293 -0
  37. package/dist/foundations/icon/index.d.ts +0 -58
  38. package/dist/foundations/icon/index.js +2 -2
  39. package/dist/foundations/index.js +2 -1
  40. package/dist/foundations/interactions/index.js +1 -1
  41. package/dist/foundations/state/index.d.ts +3 -3
  42. package/dist/foundations/state/index.js +5 -3
  43. package/dist/foundations/structures/index.js +2 -1
  44. package/dist/foundations/utilities/index.d.ts +2 -0
  45. package/dist/foundations/utilities/index.js +1 -2
  46. package/dist/fx/index.d.ts +31 -58
  47. package/dist/fx/index.js +313 -195
  48. package/dist/hooks-BimKStr4.js +202 -0
  49. package/dist/index.d.ts +11 -74
  50. package/dist/index.js +8 -447
  51. package/dist/instance-BAnfmXOR.js +988 -0
  52. package/dist/{interactions-CTeACdT_.js → interactions-D2BoREb-.js} +3 -2
  53. package/dist/jsx-dev-runtime.d.ts +41 -18
  54. package/dist/jsx-dev-runtime.js +1 -6
  55. package/dist/{jsx-runtime-CPJXAOBF.js → jsx-runtime-C4idqHY0.js} +18 -7
  56. package/dist/jsx-runtime.js +1 -1
  57. package/dist/jsx.d.ts +61 -37
  58. package/dist/{manifest-D1P3UNWV.js → manifest-CW9gyNBY.js} +3 -3
  59. package/dist/{navigate-prC5V8XV.js → navigate-CP_0Zy5U.js} +454 -87
  60. package/dist/navigation.d.ts +12 -3
  61. package/dist/peer-types.d.ts +8 -0
  62. package/dist/portal-DuOKfnLa.js +349 -0
  63. package/dist/promise-Dz8iIHAm.js +16 -0
  64. package/dist/query-registry-WMCN0BJL.js +320 -0
  65. package/dist/readable-DFWOsTac.js +21 -0
  66. package/dist/{render-context-B7ohlh6t.js → render-context-DGHnEveC.js} +27 -11
  67. package/dist/render-sync-IC5lMFpq.js +1240 -0
  68. package/dist/resolution-Cx82-xjW.js +1244 -0
  69. package/dist/resource-CLjB7RBQ.js +377 -0
  70. package/dist/resources/index.d.ts +21 -11
  71. package/dist/resources/index.js +45 -244
  72. package/dist/router/index.d.ts +14 -5
  73. package/dist/router/index.js +22 -53
  74. package/dist/scope-CwpVSHVf.js +55 -0
  75. package/dist/{shared-kU8yvryp.js → shared-O2ZnmYAf.js} +1 -7
  76. package/dist/{snapshot-source-An4iKajG.js → snapshot-Cjx4N988.js} +6 -1
  77. package/dist/ssg/index.d.ts +1 -2
  78. package/dist/ssg/index.js +5 -13
  79. package/dist/ssr/index.d.ts +26 -28
  80. package/dist/ssr/index.js +4 -4
  81. package/dist/{ssr-CiNm6Vzl.js → ssr-BJ8ug7zH.js} +133 -122
  82. package/dist/ssr-DoV-vJ-5.js +229 -0
  83. package/dist/state-DWO1KzkX.js +232 -0
  84. package/dist/structures-D4dDMqHX.js +231 -0
  85. package/dist/testing/index.d.ts +8 -4
  86. package/dist/testing/index.js +29 -34
  87. package/dist/url-CnbfpX0K.js +185 -0
  88. package/dist/utilities.d.ts +48 -2
  89. package/dist/verify-hydration-DpVaDnqz.js +152 -0
  90. package/package.json +19 -9
  91. package/dist/access-CEA2pOry.js +0 -1046
  92. package/dist/activity-oy2YFTFF.js +0 -201
  93. package/dist/boot-BMBMWUGI.js +0 -1084
  94. package/dist/capabilities-Bbf0mlp9.js +0 -42
  95. package/dist/compose-ref-v0qGlHoN.js +0 -26
  96. package/dist/control-BR_mrX__.js +0 -173
  97. package/dist/control-C-ApnFs1.js +0 -20
  98. package/dist/csp-nonce-BfFWcd0w.js +0 -173
  99. package/dist/data-runtime-CxoY98lX.js +0 -149
  100. package/dist/default-portal-runtime-DvMvWJVp.js +0 -20
  101. package/dist/dom-renderer.d.ts +0 -77
  102. package/dist/domains/renderer.d.ts +0 -127
  103. package/dist/eager-control.d.ts +0 -8
  104. package/dist/effect-C3Zsc1k6.js +0 -292
  105. package/dist/for-state-BDykeOJL.js +0 -1753
  106. package/dist/instance-VAFYVJOa.js +0 -1027
  107. package/dist/notify-DxxuDPeY.js +0 -266
  108. package/dist/portal-w3oQ6oQU.js +0 -29
  109. package/dist/query-registry-LrYpQsDJ.js +0 -83
  110. package/dist/render-resolved-BC0W7_5b.js +0 -1123
  111. package/dist/renderer-CT0HeY58.js +0 -8623
  112. package/dist/resolution-3DskUkjG.js +0 -577
  113. package/dist/resource-18-sFRl9.js +0 -344
  114. package/dist/route-matching-CUzZ31gT.js +0 -551
  115. package/dist/router-internal-7nuNEHfG.js +0 -36
  116. package/dist/scope-Cq_iYbTR.js +0 -403
  117. package/dist/selector-BSPVkjKP.js +0 -311
  118. package/dist/ssr-EPjwJH5R.js +0 -29
  119. package/dist/state-BXJfudq1.js +0 -91
  120. package/dist/structures-CjEzfj4h.js +0 -654
  121. package/dist/timer-C7uqnJVt.js +0 -85
  122. package/dist/verify-hydration-ikaxotf7.js +0 -27
  123. package/dist/vnode-D24p6IW2.js +0 -7
@@ -0,0 +1,202 @@
1
+ import { F as logger, M as getOwner, N as runWithOwner, O as notifySource, a as getCurrentInstance, k as trackSource, r as claimHook, t as ComponentInstance } from "./instance-BAnfmXOR.js";
2
+ //#region src/common/report-error.ts
3
+ /**
4
+ * Report an error the way the host reports an uncaught listener exception.
5
+ *
6
+ * `reportError` dispatches a window `error` event (so global handlers and
7
+ * monitoring see it) and lets the caller continue, matching native listener
8
+ * semantics. Hosts without it get the same outcome from an async rethrow.
9
+ * A throwing host reporter never interrupts the caller; the original error
10
+ * and the reporter's failure are logged instead.
11
+ */
12
+ function reportUncaughtError(error) {
13
+ if (typeof globalThis.reportError === "function") {
14
+ try {
15
+ globalThis.reportError(error);
16
+ } catch (reportFailure) {
17
+ logger.error("[Askr] reportError failed:", error, reportFailure);
18
+ }
19
+ return;
20
+ }
21
+ queueMicrotask(() => {
22
+ throw error;
23
+ });
24
+ }
25
+ let deferredErrors;
26
+ function flushDeferredErrors() {
27
+ const errors = deferredErrors;
28
+ deferredErrors = void 0;
29
+ for (const error of errors) reportUncaughtError(error);
30
+ }
31
+ /**
32
+ * Report an error with `reportUncaughtError` once the current task finishes.
33
+ *
34
+ * Cleanup can fail in the middle of a render or commit. Deferring the report
35
+ * keeps error handlers out of that work: they run after the DOM update, may
36
+ * write state, and cannot interrupt or roll it back. Reports keep their order.
37
+ */
38
+ function reportUncaughtErrorLater(error) {
39
+ if (deferredErrors) {
40
+ deferredErrors.push(error);
41
+ return;
42
+ }
43
+ deferredErrors = [error];
44
+ queueMicrotask(flushDeferredErrors);
45
+ }
46
+ //#endregion
47
+ //#region src/common/render-depth.ts
48
+ /**
49
+ * Askr renders nested components recursively, so a very deep tree can exhaust
50
+ * the JavaScript call stack. Replace the engine's bare RangeError with an
51
+ * error that says what happened and how to fix it.
52
+ */
53
+ const STACK_OVERFLOW = /maximum call stack|too much recursion/i;
54
+ var RenderDepthError = class extends Error {
55
+ constructor(cause) {
56
+ super("[Askr] The JavaScript call stack overflowed while rendering. Either the component tree is too deep (Askr renders nested elements and components recursively; render long sequences as lists, for example with <For>, instead of nesting them) or a component or computation recurses without end. `cause` holds the original error.");
57
+ this.name = "RenderDepthError";
58
+ Object.defineProperty(this, "cause", {
59
+ value: cause,
60
+ writable: true,
61
+ configurable: true
62
+ });
63
+ }
64
+ };
65
+ /**
66
+ * `error`, or a `RenderDepthError` when it is an engine stack overflow: a
67
+ * `RangeError` in V8 and JavaScriptCore, an `InternalError` in Firefox.
68
+ * Callers near the overflow may have too little stack left to convert; then
69
+ * the original error is returned and a shallower caller converts it.
70
+ */
71
+ function clarifyRenderOverflow(error) {
72
+ try {
73
+ if (error instanceof Error && (error instanceof RangeError || error.name === "InternalError") && STACK_OVERFLOW.test(error.message)) return new RenderDepthError(error);
74
+ } catch {}
75
+ return error;
76
+ }
77
+ //#endregion
78
+ //#region src/core/component/errors.ts
79
+ /**
80
+ * Error boundaries. A component instance becomes a boundary by setting
81
+ * `boundary`: a handler that accepts an error (returning true) and makes the
82
+ * instance render its fallback on its next render.
83
+ */
84
+ const errorOrigins = /* @__PURE__ */ new WeakMap();
85
+ /** Remember the logical owner where an error first escaped rendering. */
86
+ function noteErrorOrigin(owner, error) {
87
+ if (!owner || typeof error !== "object" && typeof error !== "function" || error === null) return;
88
+ try {
89
+ if (!errorOrigins.has(error)) errorOrigins.set(error, owner);
90
+ } catch {}
91
+ }
92
+ /**
93
+ * Deliver `error` to the nearest boundary at or above `owner` and schedule it
94
+ * to re-render. Returns false when no boundary accepted it.
95
+ */
96
+ function deliverToBoundary(owner, error) {
97
+ for (let o = owner; o; o = o.parent) if (o instanceof ComponentInstance && o.boundary && !o.disposed) {
98
+ if (o.boundary(error)) {
99
+ o.computation.invalidate();
100
+ return true;
101
+ }
102
+ }
103
+ return false;
104
+ }
105
+ /** Deliver `error` to a boundary, or throw it to the caller. */
106
+ function routeError(owner, error) {
107
+ const origin = error !== null && (typeof error === "object" || typeof error === "function") ? errorOrigins.get(error) : void 0;
108
+ if (origin && deliverToBoundary(origin, error)) return;
109
+ if (!deliverToBoundary(owner, error)) throw error;
110
+ }
111
+ /**
112
+ * `caught`, or a `RenderDepthError` when it is a stack overflow. The new error
113
+ * inherits the origin recorded on `caught` so routing still starts where the
114
+ * overflow first escaped. This runs near an exhausted stack, so carrying the
115
+ * origin is best-effort: the cheap lookup runs first, and if recording fails
116
+ * the converted error is still returned without an origin.
117
+ */
118
+ function clarifyRenderError(caught) {
119
+ let origin;
120
+ try {
121
+ origin = caught !== null && typeof caught === "object" ? errorOrigins.get(caught) : void 0;
122
+ } catch {
123
+ origin = void 0;
124
+ }
125
+ const error = clarifyRenderOverflow(caught);
126
+ if (error !== caught && origin) try {
127
+ errorOrigins.set(error, origin);
128
+ } catch {}
129
+ return error;
130
+ }
131
+ //#endregion
132
+ //#region src/core/api/hooks.ts
133
+ function currentComponent() {
134
+ return getCurrentInstance();
135
+ }
136
+ /**
137
+ * Claim the next slot of `instance` for a hook of `kind`, creating its state
138
+ * on the first render. Later renders get the same state back.
139
+ */
140
+ function hookSlot(instance, kind, create) {
141
+ const index = claimHook(instance, kind);
142
+ if (!(index in instance.hooks)) instance.hooks[index] = create();
143
+ return instance.hooks[index];
144
+ }
145
+ /** The index the next hook claim would use (for keyed per-slot stores). */
146
+ function claimHookIndex(instance, kind) {
147
+ return claimHook(instance, kind);
148
+ }
149
+ /** Run `fn` after the current render of `instance` commits. */
150
+ function onCommit(instance, fn) {
151
+ instance.onCommit(() => {
152
+ const result = fn();
153
+ if (typeof result === "function") return result;
154
+ if (result && typeof result.then === "function") Promise.resolve(result).then((cleanup) => {
155
+ if (typeof cleanup !== "function") return;
156
+ if (!instance.disposed) {
157
+ instance.onCleanup(cleanup);
158
+ return;
159
+ }
160
+ try {
161
+ cleanup();
162
+ } catch (error) {
163
+ reportUncaughtError(error);
164
+ }
165
+ }, (error) => reportLifecycleError(instance, error));
166
+ });
167
+ }
168
+ /** The owner whose lifetime callbacks and handlers currently run under. */
169
+ function currentOwner() {
170
+ return getOwner();
171
+ }
172
+ function withOwner(owner, fn) {
173
+ return runWithOwner(owner, fn);
174
+ }
175
+ /** Deliver a lifecycle failure to the nearest error boundary, else report it. */
176
+ function reportLifecycleError(owner, error) {
177
+ if (!deliverToBoundary(owner, error)) reportUncaughtError(error);
178
+ }
179
+ function createSource() {
180
+ return { _observers: null };
181
+ }
182
+ /** Record that the running computation read `source`. */
183
+ function readSource(source) {
184
+ trackSource(source);
185
+ }
186
+ /** Tell everything that read `source` that it changed. */
187
+ function notify(source) {
188
+ notifySource(source);
189
+ }
190
+ const APP_RUNTIME = Symbol("askr.app-runtime");
191
+ /**
192
+ * Make `runtime` the application runtime for everything the rendering
193
+ * component renders (undone if the render is discarded).
194
+ */
195
+ function provideAppRuntime(runtime) {
196
+ getCurrentInstance()?.provide(APP_RUNTIME, runtime);
197
+ }
198
+ function currentAppRuntime() {
199
+ return getOwner()?.lookup(APP_RUNTIME);
200
+ }
201
+ //#endregion
202
+ export { RenderDepthError as _, currentOwner as a, reportUncaughtErrorLater as b, onCommit as c, reportLifecycleError as d, withOwner as f, routeError as g, noteErrorOrigin as h, currentComponent as i, provideAppRuntime as l, deliverToBoundary as m, createSource as n, hookSlot as o, clarifyRenderError as p, currentAppRuntime as r, notify as s, claimHookIndex as t, readSource as u, clarifyRenderOverflow as v, reportUncaughtError as y };
package/dist/index.d.ts CHANGED
@@ -1,121 +1,58 @@
1
- export {
2
- createDOMRendererHost,
3
- DOMComponentOwner,
4
- DOMChildScope,
5
- DOMReactiveSource,
6
- DOMRendererRange,
7
- DOMRendererEvaluation,
8
- DOMRendererCleanup,
9
- DOMRendererScopes,
10
- DOMRendererKeys,
11
- DOMRendererReactivity,
12
- DOMRendererHost,
13
- } from './dom-renderer.js';
14
1
  import {
15
2
  cspNonce,
16
3
  selector,
17
- Show,
18
4
  configureRenderDiagnostics,
19
- ShowProps,
20
- For,
21
- CaseProps,
22
5
  StateSetter,
23
- Match,
24
6
  StateTuple,
25
7
  registerSSRStyle,
26
- MatchProps,
27
8
  state,
28
- ForProps,
29
- createQuery,
30
9
  createRef,
31
10
  RenderDiagnosticsOptions,
32
11
  derive,
33
12
  defineScope,
34
- QueryCollection,
35
- RuntimeKeyedReorderDecision,
36
- defineServerQueries,
37
- QueryCollectionOptions,
38
- getDefaultRuntime,
39
- dehydrateDataRuntime,
40
- createQueryCollection,
41
- serveQuery,
42
- QueryPrefetchContext,
43
13
  Derived,
44
- Case,
45
14
  State,
46
15
  CspNonceScope,
47
- QueryCollectionEntry,
48
- RuntimeRendererHost,
49
- prefetchQuery,
50
- AskrRuntime,
51
- hydrateDataRuntime,
52
- QueryDefinition,
53
16
  getSignal,
54
- AskrRuntimeOptions,
55
- DataRuntime,
56
- defineQuery,
57
- QueryCollectionKey,
58
- createRuntime,
59
- ServerQueryHandler,
60
17
  Ref,
61
18
  readScope,
62
19
  Scope,
63
20
  Selector,
64
21
  } from './core.js';
65
22
  import { Props, Fragment } from './elements.js';
66
- import { jsxs, jsx } from './jsx.js';
23
+ import { createElement, jsxs, jsx } from './jsx.js';
24
+ /**
25
+ * Thrown when the JavaScript call stack overflows during a render, usually
26
+ * because the component tree is too deep. `cause` is the engine's error.
27
+ */
28
+ declare class RenderDepthError extends Error {
29
+ readonly cause: unknown;
30
+ constructor(cause: unknown);
31
+ }
67
32
  export {
68
- AskrRuntime,
69
- type AskrRuntimeOptions,
70
- Case,
71
- type CaseProps,
72
33
  CspNonceScope,
73
- type DataRuntime,
74
34
  type Derived,
75
- For,
76
- type ForProps,
77
35
  Fragment,
78
- Match,
79
- type MatchProps,
80
36
  type Props,
81
- type QueryCollection,
82
- type QueryCollectionEntry,
83
- type QueryCollectionKey,
84
- type QueryCollectionOptions,
85
- type QueryDefinition,
86
- type QueryPrefetchContext,
37
+ RenderDepthError,
87
38
  type Ref,
88
39
  type RenderDiagnosticsOptions,
89
- type RuntimeKeyedReorderDecision,
90
- type RuntimeRendererHost,
91
40
  type Scope,
92
41
  type Selector,
93
- type ServerQueryHandler,
94
- Show,
95
- type ShowProps,
96
42
  type State,
97
43
  type StateSetter,
98
44
  type StateTuple,
99
45
  configureRenderDiagnostics,
100
- createQuery,
101
- createQueryCollection,
46
+ createElement,
102
47
  createRef,
103
- createRuntime,
104
48
  cspNonce,
105
- defineQuery,
106
49
  defineScope,
107
- defineServerQueries,
108
- dehydrateDataRuntime,
109
50
  derive,
110
- getDefaultRuntime,
111
51
  getSignal,
112
- hydrateDataRuntime,
113
52
  jsx,
114
53
  jsxs,
115
- prefetchQuery,
116
54
  readScope,
117
55
  registerSSRStyle,
118
56
  selector,
119
- serveQuery,
120
57
  state,
121
58
  };