@askrjs/askr 0.0.52 → 0.0.53
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/README.md +5 -1
- package/dist/{runtime/scheduler.js → access-Bg4RJNC8.js} +182 -9
- package/dist/actions/index.d.ts +2 -0
- package/dist/actions/index.js +103 -0
- package/dist/{common/attr-names.js → attr-names-CjhzmHOn.js} +1 -1
- package/dist/benchmark.d.ts +6 -2
- package/dist/benchmark.js +63 -11
- package/dist/boot/index.d.ts +61 -2
- package/dist/boot/index.js +1 -203
- package/dist/boot-j2KoN6ss.js +647 -0
- package/dist/cleanup-COv77su2.js +487 -0
- package/dist/component-internal-B3z7GXlD.js +614 -0
- package/dist/component-lifecycle-CO4hXlP4.js +357 -0
- package/dist/{runtime/component-scope.js → component-scope-CC3cojX9.js} +8 -1
- package/dist/component-scope-CvPba6O6.d.ts +12 -0
- package/dist/components/index.d.ts +17 -2
- package/dist/components/index.js +39 -1
- package/dist/compose-ref-Cc_YkUpM.js +92 -0
- package/dist/{foundations/utilities/compose-ref.d.ts → compose-ref-Cizq72-x.d.ts} +1 -1
- package/dist/control/index.d.ts +1 -3
- package/dist/control/index.js +1 -3
- package/dist/control-BQvNVfAd.d.ts +436 -0
- package/dist/control-BYyLTFyw.js +165 -0
- package/dist/control-Bf4Wkdvv.d.ts +9 -0
- package/dist/{common/control.js → control-DhFRTIoE.js} +1 -1
- package/dist/data/index.d.ts +2 -6
- package/dist/data/index.js +4 -5
- package/dist/data-DnxnDxD-.js +559 -0
- package/dist/{data/data-runtime.js → data-runtime-SJ1BSUvk.js} +32 -31
- package/dist/deferred-lKE8uR0z.js +386 -0
- package/dist/{runtime/effect.js → effect-BwnIvLah.js} +4 -4
- package/dist/fastlane-Dw8SOBr9.js +343 -0
- package/dist/for-internal-BKf_Tnv1.js +1563 -0
- package/dist/foundations/icon/index.d.ts +68 -2
- package/dist/foundations/icon/index.js +85 -1
- package/dist/foundations/index.d.ts +2 -5
- package/dist/foundations/index.js +2 -5
- package/dist/foundations/interactions/index.d.ts +264 -6
- package/dist/foundations/interactions/index.js +1 -6
- package/dist/foundations/state/index.d.ts +32 -1
- package/dist/foundations/state/index.js +78 -1
- package/dist/foundations/structures/index.d.ts +2 -7
- package/dist/foundations/structures/index.js +2 -7
- package/dist/foundations/utilities/index.d.ts +2 -6
- package/dist/foundations/utilities/index.js +2 -5
- package/dist/fx/index.d.ts +190 -3
- package/dist/fx/index.js +454 -4
- package/dist/index-31Uoz_NS.d.ts +239 -0
- package/dist/index-Bki2rqcr.d.ts +233 -0
- package/dist/index-BnU0NPwM.d.ts +101 -0
- package/dist/index-D73jgYx1.d.ts +48 -0
- package/dist/{runtime/runtime.d.ts → index-R2JJIbM-.d.ts} +31 -8
- package/dist/index-SJXJkssx.d.ts +44 -0
- package/dist/index.d.ts +8 -13
- package/dist/index.js +150 -15
- package/dist/interactions-w7gQN4ha.js +280 -0
- package/dist/{data/invalidation-listeners.js → invalidation-listeners-Des3AHYs.js} +1 -1
- package/dist/{common/props.d.ts → jsx-CP0gmYwJ.d.ts} +17 -5
- package/dist/{common/jsx.js → jsx-CUpRxrLH.js} +1 -1
- package/dist/jsx-dev-runtime.d.ts +2 -4
- package/dist/jsx-dev-runtime.js +7 -5
- package/dist/jsx-runtime-92bV2hSa.d.ts +34 -0
- package/dist/jsx-runtime-BVVgDSdq.d.ts +1 -0
- package/dist/jsx-runtime.d.ts +2 -35
- package/dist/jsx-runtime.js +11 -5
- package/dist/{runtime/lifecycle-operations.js → lifecycle-operations-D9va7GOU.js} +4 -5
- package/dist/navigate-BVDCzOuB.d.ts +34 -0
- package/dist/navigate-CmPLSXyw.js +1449 -0
- package/dist/{runtime/portal.js → portal-CyU3Ucf2.js} +33 -36
- package/dist/query-registry-CQIT4mXr.js +73 -0
- package/dist/{common/render-context.js → render-context-Clw3rFiO.js} +14 -6
- package/dist/renderer-DzPjeLby.js +6197 -0
- package/dist/{runtime/resource-operation.js → resource-operation-CEzfpnDk.js} +118 -15
- package/dist/resources/index.d.ts +42 -3
- package/dist/resources/index.js +3 -4
- package/dist/{common/route-activity.js → route-activity-CNJfpwx-.js} +1 -1
- package/dist/route-matching-vJpvLVbX.js +515 -0
- package/dist/router/index.d.ts +166 -14
- package/dist/router/index.js +150 -12
- package/dist/{common/router.d.ts → router-CeYvjj5_.d.ts} +72 -28
- package/dist/{common/router-internal.js → router-internal-BC0w1_xk.js} +1 -1
- package/dist/{runtime/scheduler.d.ts → scheduler-CmLO4Dfm.d.ts} +1 -3
- package/dist/{runtime/selector.js → selector-DafVYzV4.js} +34 -11
- package/dist/{runtime/snapshot-source.js → snapshot-source-BB42xgwb.js} +1 -1
- package/dist/ssg/index.d.ts +252 -4
- package/dist/ssg/index.js +857 -1
- package/dist/ssr/index.d.ts +225 -8
- package/dist/ssr/index.js +3 -6
- package/dist/{common/ssr.js → ssr-CbQO5xd3.js} +1 -1
- package/dist/ssr-D3t80Rc0.js +1413 -0
- package/dist/{runtime/state.js → state-DPl8lffD.js} +3 -5
- package/dist/structures-DUB3HchX.js +221 -0
- package/dist/testing/index.d.ts +3 -2
- package/dist/testing/index.js +2 -5
- package/dist/{jsx/types.d.ts → types-DnQVG4ZY.d.ts} +2 -5
- package/dist/{foundations/utilities/use-id.js → utilities-C_CGX4Dz.js} +1 -1
- package/dist/{ssr/verify-hydration.js → verify-hydration-io9ahUeq.js} +2 -2
- package/dist/{common/vnode.js → vnode-CGMJYPMB.js} +2 -2
- package/package.json +12 -7
- package/dist/bench/components/benchmark-row.d.ts +0 -20
- package/dist/bench/components/benchmark-row.js +0 -40
- package/dist/bench/components/benchmark-table.js +0 -23
- package/dist/bin/askr-ssg.d.ts +0 -27
- package/dist/bin/askr-ssg.js +0 -186
- package/dist/boot/hydration.js +0 -139
- package/dist/boot/root-lifecycle.d.ts +0 -18
- package/dist/boot/root-lifecycle.js +0 -209
- package/dist/boot/route-startup.js +0 -54
- package/dist/boot/types.d.ts +0 -61
- package/dist/common/component.d.ts +0 -18
- package/dist/common/control.d.ts +0 -12
- package/dist/common/dom-range.d.ts +0 -13
- package/dist/common/env.js +0 -41
- package/dist/common/error-boundary.d.ts +0 -15
- package/dist/common/invariant.js +0 -15
- package/dist/common/jsx.d.ts +0 -22
- package/dist/common/logger.js +0 -34
- package/dist/common/promise.js +0 -6
- package/dist/common/ssr-errors.d.ts +0 -10
- package/dist/common/ssr-errors.js +0 -14
- package/dist/common/ssr.d.ts +0 -41
- package/dist/common/vnode.d.ts +0 -21
- package/dist/components/error-boundary.d.ts +0 -14
- package/dist/components/error-boundary.js +0 -41
- package/dist/components/link.d.ts +0 -68
- package/dist/components/link.js +0 -74
- package/dist/control/case.d.ts +0 -18
- package/dist/control/case.js +0 -68
- package/dist/control/for.d.ts +0 -23
- package/dist/control/for.js +0 -61
- package/dist/control/shared.d.ts +0 -8
- package/dist/control/shared.js +0 -18
- package/dist/control/show.d.ts +0 -14
- package/dist/control/show.js +0 -32
- package/dist/data/data-runtime.d.ts +0 -27
- package/dist/data/invalidation.d.ts +0 -8
- package/dist/data/invalidation.js +0 -25
- package/dist/data/mutation-cell.d.ts +0 -27
- package/dist/data/mutation-cell.js +0 -133
- package/dist/data/query-cell.d.ts +0 -47
- package/dist/data/query-cell.js +0 -324
- package/dist/data/query-key.js +0 -40
- package/dist/data/shared.js +0 -20
- package/dist/data/testing.js +0 -2
- package/dist/data/types.d.ts +0 -160
- package/dist/foundations/icon/icon.d.ts +0 -52
- package/dist/foundations/icon/icon.js +0 -86
- package/dist/foundations/icon/icon.types.d.ts +0 -21
- package/dist/foundations/interactions/dismissable.d.ts +0 -71
- package/dist/foundations/interactions/dismissable.js +0 -24
- package/dist/foundations/interactions/focusable.d.ts +0 -21
- package/dist/foundations/interactions/focusable.js +0 -16
- package/dist/foundations/interactions/hoverable.d.ts +0 -25
- package/dist/foundations/interactions/hoverable.js +0 -13
- package/dist/foundations/interactions/interaction-policy.d.ts +0 -49
- package/dist/foundations/interactions/interaction-policy.js +0 -120
- package/dist/foundations/interactions/pressable.d.ts +0 -60
- package/dist/foundations/interactions/pressable.js +0 -49
- package/dist/foundations/interactions/roving-focus.d.ts +0 -51
- package/dist/foundations/interactions/roving-focus.js +0 -69
- package/dist/foundations/state/controllable.d.ts +0 -32
- package/dist/foundations/state/controllable.js +0 -80
- package/dist/foundations/structures/collection.d.ts +0 -51
- package/dist/foundations/structures/collection.js +0 -49
- package/dist/foundations/structures/layer.d.ts +0 -80
- package/dist/foundations/structures/layer.js +0 -79
- package/dist/foundations/structures/layout.d.ts +0 -32
- package/dist/foundations/structures/layout.js +0 -11
- package/dist/foundations/structures/portal.d.ts +0 -2
- package/dist/foundations/structures/portal.js +0 -3
- package/dist/foundations/structures/presence.d.ts +0 -36
- package/dist/foundations/structures/presence.js +0 -37
- package/dist/foundations/structures/slot.d.ts +0 -34
- package/dist/foundations/structures/slot.js +0 -39
- package/dist/foundations/utilities/aria.d.ts +0 -15
- package/dist/foundations/utilities/aria.js +0 -15
- package/dist/foundations/utilities/compose-handlers.d.ts +0 -36
- package/dist/foundations/utilities/compose-handlers.js +0 -18
- package/dist/foundations/utilities/compose-ref.js +0 -16
- package/dist/foundations/utilities/event-types.d.ts +0 -19
- package/dist/foundations/utilities/merge-props.d.ts +0 -4
- package/dist/foundations/utilities/merge-props.js +0 -47
- package/dist/foundations/utilities/use-id.d.ts +0 -31
- package/dist/fx/fx.d.ts +0 -32
- package/dist/fx/fx.js +0 -211
- package/dist/fx/noop.js +0 -7
- package/dist/fx/timing.d.ts +0 -158
- package/dist/fx/timing.js +0 -241
- package/dist/jsx/index.d.ts +0 -2
- package/dist/jsx/index.js +0 -4
- package/dist/jsx/types.js +0 -2
- package/dist/jsx/utils.d.ts +0 -4
- package/dist/jsx/utils.js +0 -17
- package/dist/jsx-runtime2.d.ts +0 -3
- package/dist/jsx-runtime2.js +0 -4
- package/dist/renderer/attributes.js +0 -254
- package/dist/renderer/boundaries.js +0 -142
- package/dist/renderer/boundary-materialization.js +0 -72
- package/dist/renderer/boundary-range-adoption.js +0 -76
- package/dist/renderer/boundary-range-sync.js +0 -101
- package/dist/renderer/boundary-state.js +0 -50
- package/dist/renderer/child-shape.js +0 -83
- package/dist/renderer/children-fastpath.js +0 -149
- package/dist/renderer/children.js +0 -158
- package/dist/renderer/cleanup.js +0 -267
- package/dist/renderer/component-host-cleanup.js +0 -143
- package/dist/renderer/component-host-instances.js +0 -116
- package/dist/renderer/component-host-replacement.js +0 -105
- package/dist/renderer/component-host-results.js +0 -138
- package/dist/renderer/component-host.js +0 -172
- package/dist/renderer/dom-host.js +0 -11
- package/dist/renderer/dom-internal.js +0 -243
- package/dist/renderer/dom-range.js +0 -161
- package/dist/renderer/dom.js +0 -11
- package/dist/renderer/element-children.js +0 -359
- package/dist/renderer/env.js +0 -2
- package/dist/renderer/error-boundary-dom.js +0 -86
- package/dist/renderer/evaluate-dom-range.js +0 -84
- package/dist/renderer/evaluate-reconcile.js +0 -257
- package/dist/renderer/evaluate.js +0 -95
- package/dist/renderer/fastpath.js +0 -142
- package/dist/renderer/for-commit-dom-map.js +0 -71
- package/dist/renderer/for-commit-removal.js +0 -27
- package/dist/renderer/for-commit-reorder.js +0 -87
- package/dist/renderer/for-commit.js +0 -442
- package/dist/renderer/hydration-boundaries.js +0 -60
- package/dist/renderer/hydration-listener-transaction.js +0 -49
- package/dist/renderer/index.js +0 -39
- package/dist/renderer/intrinsic-blueprint-analysis.js +0 -202
- package/dist/renderer/intrinsic-blueprint-bindings.js +0 -152
- package/dist/renderer/intrinsic-blueprint-materialization.js +0 -100
- package/dist/renderer/intrinsic-blueprint.js +0 -30
- package/dist/renderer/intrinsic-hydration-adoption.js +0 -66
- package/dist/renderer/keyed-children.js +0 -26
- package/dist/renderer/keyed.js +0 -167
- package/dist/renderer/namespaces.js +0 -21
- package/dist/renderer/prop-bindings.js +0 -315
- package/dist/renderer/reactive-child-dom.js +0 -139
- package/dist/renderer/reactive-child-sources.js +0 -182
- package/dist/renderer/reactive-children.js +0 -303
- package/dist/renderer/reconcile-commit.js +0 -36
- package/dist/renderer/reconcile-fastpaths.js +0 -100
- package/dist/renderer/reconcile-resolution.js +0 -163
- package/dist/renderer/reconcile.js +0 -37
- package/dist/renderer/retained-element-rollback.js +0 -288
- package/dist/renderer/stable-patch.js +0 -80
- package/dist/renderer/static-reuse.js +0 -94
- package/dist/renderer/types.js +0 -2
- package/dist/renderer/utils.js +0 -265
- package/dist/router/access.js +0 -34
- package/dist/router/activity.d.ts +0 -9
- package/dist/router/activity.js +0 -85
- package/dist/router/authoring.d.ts +0 -21
- package/dist/router/authoring.js +0 -196
- package/dist/router/internal-types.d.ts +0 -30
- package/dist/router/lazy.d.ts +0 -18
- package/dist/router/lazy.js +0 -50
- package/dist/router/manifest.d.ts +0 -9
- package/dist/router/manifest.js +0 -47
- package/dist/router/match.js +0 -120
- package/dist/router/navigate.d.ts +0 -10
- package/dist/router/navigate.js +0 -73
- package/dist/router/navigation-registry.d.ts +0 -31
- package/dist/router/navigation-registry.js +0 -103
- package/dist/router/navigation-scroll.d.ts +0 -13
- package/dist/router/navigation-scroll.js +0 -91
- package/dist/router/navigation-targets.d.ts +0 -30
- package/dist/router/navigation-targets.js +0 -634
- package/dist/router/policy.d.ts +0 -27
- package/dist/router/policy.js +0 -130
- package/dist/router/rendering.d.ts +0 -9
- package/dist/router/rendering.js +0 -47
- package/dist/router/resolution.d.ts +0 -3
- package/dist/router/resolution.js +0 -84
- package/dist/router/route-context.js +0 -77
- package/dist/router/route-matching.d.ts +0 -19
- package/dist/router/route-matching.js +0 -173
- package/dist/router/route-query.d.ts +0 -16
- package/dist/router/route-query.js +0 -45
- package/dist/router/route.d.ts +0 -8
- package/dist/router/route.js +0 -10
- package/dist/router/store.d.ts +0 -49
- package/dist/router/store.js +0 -169
- package/dist/router/testing.js +0 -4
- package/dist/runtime/access.d.ts +0 -19
- package/dist/runtime/access.js +0 -43
- package/dist/runtime/child-scope.d.ts +0 -41
- package/dist/runtime/child-scope.js +0 -134
- package/dist/runtime/component-cleanup.d.ts +0 -15
- package/dist/runtime/component-cleanup.js +0 -68
- package/dist/runtime/component-commit.js +0 -167
- package/dist/runtime/component-facade.d.ts +0 -5
- package/dist/runtime/component-facade.js +0 -6
- package/dist/runtime/component-internal.d.ts +0 -105
- package/dist/runtime/component-internal.js +0 -237
- package/dist/runtime/component-lifecycle.d.ts +0 -10
- package/dist/runtime/component-lifecycle.js +0 -33
- package/dist/runtime/component-scope.d.ts +0 -54
- package/dist/runtime/component.d.ts +0 -5
- package/dist/runtime/component.js +0 -6
- package/dist/runtime/context.d.ts +0 -72
- package/dist/runtime/context.js +0 -236
- package/dist/runtime/control.d.ts +0 -62
- package/dist/runtime/control.js +0 -239
- package/dist/runtime/derive.d.ts +0 -16
- package/dist/runtime/derive.js +0 -140
- package/dist/runtime/dev-namespace.d.ts +0 -30
- package/dist/runtime/dev-namespace.js +0 -64
- package/dist/runtime/effect.d.ts +0 -35
- package/dist/runtime/error-boundary.d.ts +0 -4
- package/dist/runtime/error-boundary.js +0 -29
- package/dist/runtime/events.d.ts +0 -58
- package/dist/runtime/events.js +0 -201
- package/dist/runtime/execution-model.d.ts +0 -6
- package/dist/runtime/execution-model.js +0 -13
- package/dist/runtime/fastlane.d.ts +0 -33
- package/dist/runtime/fastlane.js +0 -173
- package/dist/runtime/for-bench.d.ts +0 -40
- package/dist/runtime/for-bench.js +0 -13
- package/dist/runtime/for-internal.d.ts +0 -106
- package/dist/runtime/for-internal.js +0 -285
- package/dist/runtime/for-reconcile.d.ts +0 -7
- package/dist/runtime/for-reconcile.js +0 -442
- package/dist/runtime/for-scopes.d.ts +0 -26
- package/dist/runtime/for-scopes.js +0 -280
- package/dist/runtime/for-signals.d.ts +0 -39
- package/dist/runtime/for-signals.js +0 -213
- package/dist/runtime/for-types.d.ts +0 -8
- package/dist/runtime/for.d.ts +0 -4
- package/dist/runtime/for.js +0 -5
- package/dist/runtime/index.d.ts +0 -24
- package/dist/runtime/index.js +0 -33
- package/dist/runtime/lifecycle-batch.d.ts +0 -59
- package/dist/runtime/lifecycle-batch.js +0 -178
- package/dist/runtime/lifecycle-operation-settlement.d.ts +0 -5
- package/dist/runtime/lifecycle-operation-settlement.js +0 -51
- package/dist/runtime/lifecycle-operations.d.ts +0 -30
- package/dist/runtime/operations.d.ts +0 -3
- package/dist/runtime/operations.js +0 -3
- package/dist/runtime/perf-metrics.d.ts +0 -27
- package/dist/runtime/perf-metrics.js +0 -6
- package/dist/runtime/portal.d.ts +0 -21
- package/dist/runtime/readable.d.ts +0 -34
- package/dist/runtime/readable.js +0 -183
- package/dist/runtime/resource-cell.js +0 -112
- package/dist/runtime/resource-operation.d.ts +0 -12
- package/dist/runtime/runtime.js +0 -57
- package/dist/runtime/selector-store.js +0 -22
- package/dist/runtime/selector.d.ts +0 -10
- package/dist/runtime/snapshot-source.d.ts +0 -9
- package/dist/runtime/state.d.ts +0 -54
- package/dist/ssg/batch-render.js +0 -101
- package/dist/ssg/create-static-gen.d.ts +0 -66
- package/dist/ssg/create-static-gen.js +0 -250
- package/dist/ssg/generate-metadata.js +0 -92
- package/dist/ssg/generation-plan.js +0 -68
- package/dist/ssg/incremental-manifest.js +0 -54
- package/dist/ssg/resolve-ssg-data.js +0 -103
- package/dist/ssg/route-utils.js +0 -22
- package/dist/ssg/static-routes.js +0 -100
- package/dist/ssg/types.d.ts +0 -188
- package/dist/ssg/write-static-files.js +0 -77
- package/dist/ssr/attrs.js +0 -92
- package/dist/ssr/boundaries.js +0 -124
- package/dist/ssr/component-runtime.js +0 -85
- package/dist/ssr/context.d.ts +0 -49
- package/dist/ssr/context.js +0 -89
- package/dist/ssr/errors.d.ts +0 -9
- package/dist/ssr/errors.js +0 -12
- package/dist/ssr/escape.js +0 -191
- package/dist/ssr/hydration-data.js +0 -8
- package/dist/ssr/hydration-verify.d.ts +0 -11
- package/dist/ssr/hydration-verify.js +0 -171
- package/dist/ssr/index-internal.d.ts +0 -14
- package/dist/ssr/index-internal.js +0 -17
- package/dist/ssr/render-keys.js +0 -14
- package/dist/ssr/render-resolved.d.ts +0 -19
- package/dist/ssr/render-resolved.js +0 -33
- package/dist/ssr/render-sync.d.ts +0 -20
- package/dist/ssr/render-sync.js +0 -283
- package/dist/ssr/route-policy-resolution.js +0 -76
- package/dist/ssr/route-render.d.ts +0 -76
- package/dist/ssr/route-render.js +0 -118
- package/dist/ssr/sink.d.ts +0 -25
- package/dist/ssr/sink.js +0 -84
- package/dist/ssr/types.d.ts +0 -22
package/dist/fx/index.d.ts
CHANGED
|
@@ -1,4 +1,191 @@
|
|
|
1
|
-
import { scheduleEventHandler } from "../
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { n as scheduleEventHandler } from "../scheduler-CmLO4Dfm.js";
|
|
2
|
+
|
|
3
|
+
//#region src/fx/timing.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Timing utilities — pure helpers for common async patterns
|
|
6
|
+
* No framework coupling. No lifecycle awareness.
|
|
7
|
+
*/
|
|
8
|
+
interface DebounceOptions {
|
|
9
|
+
leading?: boolean;
|
|
10
|
+
trailing?: boolean;
|
|
11
|
+
}
|
|
12
|
+
interface ThrottleOptions {
|
|
13
|
+
leading?: boolean;
|
|
14
|
+
trailing?: boolean;
|
|
15
|
+
}
|
|
16
|
+
interface RetryOptions {
|
|
17
|
+
maxAttempts?: number;
|
|
18
|
+
delayMs?: number;
|
|
19
|
+
backoff?: (attemptIndex: number) => number;
|
|
20
|
+
}
|
|
21
|
+
type AnyFn = (...args: never[]) => unknown;
|
|
22
|
+
/**
|
|
23
|
+
* Debounce — delay execution, coalesce rapid calls
|
|
24
|
+
*
|
|
25
|
+
* Useful for: text input, resize, autosave
|
|
26
|
+
*
|
|
27
|
+
* @param fn Function to debounce
|
|
28
|
+
* @param ms Delay in milliseconds
|
|
29
|
+
* @param options trailing (default true), leading
|
|
30
|
+
* @returns Debounced function with cancel() method
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* const save = debounce((text) => api.save(text), 500);
|
|
35
|
+
* input.addEventListener('input', (e) => save(e.target.value));
|
|
36
|
+
* save.cancel(); // stop any pending execution
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
declare function debounce<T extends AnyFn>(fn: T, ms: number, options?: DebounceOptions): T & {
|
|
40
|
+
cancel(): void;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Throttle — rate-limit execution, keep first/last
|
|
44
|
+
*
|
|
45
|
+
* Useful for: scroll, mouse move, high-frequency events
|
|
46
|
+
*
|
|
47
|
+
* @param fn Function to throttle
|
|
48
|
+
* @param ms Minimum interval between calls in milliseconds
|
|
49
|
+
* @param options leading (default true), trailing (default true)
|
|
50
|
+
* @returns Throttled function with cancel() method
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* const handleScroll = throttle(updateUI, 100);
|
|
55
|
+
* window.addEventListener('scroll', handleScroll);
|
|
56
|
+
* handleScroll.cancel();
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
declare function throttle<T extends AnyFn>(fn: T, ms: number, options?: ThrottleOptions): T & {
|
|
60
|
+
cancel(): void;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Once — guard against double execution
|
|
64
|
+
*
|
|
65
|
+
* Useful for: init logic, event safety
|
|
66
|
+
*
|
|
67
|
+
* @param fn Function to call at most once
|
|
68
|
+
* @returns Function that executes fn only on first call
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* const init = once(setup);
|
|
73
|
+
* init(); // runs
|
|
74
|
+
* init(); // does nothing
|
|
75
|
+
* init(); // does nothing
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
declare function once<T extends AnyFn>(fn: T): T;
|
|
79
|
+
/**
|
|
80
|
+
* Defer — schedule on microtask queue
|
|
81
|
+
*
|
|
82
|
+
* Useful for: run-after-current-stack logic
|
|
83
|
+
* More reliable than setTimeout(..., 0)
|
|
84
|
+
*
|
|
85
|
+
* @param fn Function to defer
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```ts
|
|
89
|
+
* defer(() => update()); // runs after current stack, before next macrotask
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
declare function defer(fn: () => void): void;
|
|
93
|
+
/**
|
|
94
|
+
* RAF — coalesce multiple updates into single frame
|
|
95
|
+
*
|
|
96
|
+
* Useful for: animation, layout work, render updates
|
|
97
|
+
*
|
|
98
|
+
* @param fn Function to schedule on next animation frame
|
|
99
|
+
* @returns Function that schedules fn on requestAnimationFrame
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```ts
|
|
103
|
+
* const update = raf(render);
|
|
104
|
+
* update(); // schedules on next frame
|
|
105
|
+
* update(); // same frame, no duplicate
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
declare function raf<T extends AnyFn>(fn: T): T;
|
|
109
|
+
/**
|
|
110
|
+
* Idle — schedule low-priority work
|
|
111
|
+
*
|
|
112
|
+
* Useful for: background prep, non-urgent updates
|
|
113
|
+
* Falls back to setTimeout if requestIdleCallback unavailable
|
|
114
|
+
*
|
|
115
|
+
* @param fn Function to call when idle
|
|
116
|
+
* @param options timeout for fallback
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```ts
|
|
120
|
+
* idle(() => prefetchData());
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
declare function idle(fn: () => void, options?: {
|
|
124
|
+
timeout?: number;
|
|
125
|
+
}): void;
|
|
126
|
+
/**
|
|
127
|
+
* Timeout — Promise-based delay
|
|
128
|
+
*
|
|
129
|
+
* Useful for: readable async code, waiting between retries
|
|
130
|
+
*
|
|
131
|
+
* @param ms Milliseconds to wait
|
|
132
|
+
* @returns Promise that resolves after delay
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```ts
|
|
136
|
+
* await timeout(300);
|
|
137
|
+
* console.log('300ms later');
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
declare function timeout(ms: number): Promise<void>;
|
|
141
|
+
/**
|
|
142
|
+
* Retry — attempt function with backoff
|
|
143
|
+
*
|
|
144
|
+
* Useful for: network calls, transient failures
|
|
145
|
+
*
|
|
146
|
+
* @param fn Async function to retry
|
|
147
|
+
* @param options maxAttempts, delayMs, backoff function
|
|
148
|
+
* @returns Promise with final result or error
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```ts
|
|
152
|
+
* const data = await retry(() => fetch(url), {
|
|
153
|
+
* maxAttempts: 3,
|
|
154
|
+
* delayMs: 100,
|
|
155
|
+
* });
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
declare function retry<T>(fn: () => Promise<T>, options?: RetryOptions): Promise<T>;
|
|
159
|
+
//#endregion
|
|
160
|
+
//#region src/fx/fx.d.ts
|
|
161
|
+
type CancelFn = () => void;
|
|
162
|
+
declare function debounceEvent(ms: number, handler: EventListener, options?: {
|
|
163
|
+
leading?: boolean;
|
|
164
|
+
trailing?: boolean;
|
|
165
|
+
}): EventListener & {
|
|
166
|
+
cancel(): void;
|
|
167
|
+
flush(): void;
|
|
168
|
+
};
|
|
169
|
+
declare function throttleEvent(ms: number, handler: EventListener, options?: {
|
|
170
|
+
leading?: boolean;
|
|
171
|
+
trailing?: boolean;
|
|
172
|
+
}): EventListener & {
|
|
173
|
+
cancel(): void;
|
|
174
|
+
};
|
|
175
|
+
declare function rafEvent(handler: EventListener): EventListener & {
|
|
176
|
+
cancel(): void;
|
|
177
|
+
};
|
|
178
|
+
declare function scheduleTimeout(ms: number, fn: () => void): CancelFn;
|
|
179
|
+
declare function scheduleIdle(fn: () => void, options?: {
|
|
180
|
+
timeout?: number;
|
|
181
|
+
}): CancelFn;
|
|
182
|
+
interface RetryOptions$1 {
|
|
183
|
+
maxAttempts?: number;
|
|
184
|
+
delayMs?: number;
|
|
185
|
+
backoff?: (attemptIndex: number) => number;
|
|
186
|
+
}
|
|
187
|
+
declare function scheduleRetry<T>(fn: () => Promise<T>, options?: RetryOptions$1): {
|
|
188
|
+
cancel(): void;
|
|
189
|
+
};
|
|
190
|
+
//#endregion
|
|
4
191
|
export { type DebounceOptions, type RetryOptions, type ThrottleOptions, debounce, debounceEvent, defer, idle, once, raf, rafEvent, retry, scheduleEventHandler, scheduleIdle, scheduleRetry, scheduleTimeout, throttle, throttleEvent, timeout };
|
package/dist/fx/index.js
CHANGED
|
@@ -1,5 +1,455 @@
|
|
|
1
|
-
import { scheduleEventHandler } from "../
|
|
2
|
-
import "../
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { h as scheduleEventHandler, n as enqueueRuntimeTask, v as logger } from "../access-Bg4RJNC8.js";
|
|
2
|
+
import { f as getCurrentComponentInstance } from "../component-scope-CC3cojX9.js";
|
|
3
|
+
//#region src/fx/timing.ts
|
|
4
|
+
/**
|
|
5
|
+
* Debounce — delay execution, coalesce rapid calls
|
|
6
|
+
*
|
|
7
|
+
* Useful for: text input, resize, autosave
|
|
8
|
+
*
|
|
9
|
+
* @param fn Function to debounce
|
|
10
|
+
* @param ms Delay in milliseconds
|
|
11
|
+
* @param options trailing (default true), leading
|
|
12
|
+
* @returns Debounced function with cancel() method
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* const save = debounce((text) => api.save(text), 500);
|
|
17
|
+
* input.addEventListener('input', (e) => save(e.target.value));
|
|
18
|
+
* save.cancel(); // stop any pending execution
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
function debounce(fn, ms, options) {
|
|
22
|
+
const callable = fn;
|
|
23
|
+
let timeoutId = null;
|
|
24
|
+
const { leading = false, trailing = true } = options || {};
|
|
25
|
+
let lastArgs = null;
|
|
26
|
+
let lastThis = null;
|
|
27
|
+
let lastCallTime = 0;
|
|
28
|
+
const debounced = function(...args) {
|
|
29
|
+
const callTime = Date.now();
|
|
30
|
+
lastArgs = args;
|
|
31
|
+
lastThis = this;
|
|
32
|
+
if (timeoutId !== null) clearTimeout(timeoutId);
|
|
33
|
+
if (leading && callTime - lastCallTime >= ms) {
|
|
34
|
+
callable.apply(this, args);
|
|
35
|
+
lastCallTime = callTime;
|
|
36
|
+
}
|
|
37
|
+
if (trailing) timeoutId = setTimeout(() => {
|
|
38
|
+
callable.apply(lastThis, lastArgs);
|
|
39
|
+
timeoutId = null;
|
|
40
|
+
lastCallTime = Date.now();
|
|
41
|
+
}, ms);
|
|
42
|
+
};
|
|
43
|
+
debounced.cancel = () => {
|
|
44
|
+
if (timeoutId !== null) {
|
|
45
|
+
clearTimeout(timeoutId);
|
|
46
|
+
timeoutId = null;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
return debounced;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Throttle — rate-limit execution, keep first/last
|
|
53
|
+
*
|
|
54
|
+
* Useful for: scroll, mouse move, high-frequency events
|
|
55
|
+
*
|
|
56
|
+
* @param fn Function to throttle
|
|
57
|
+
* @param ms Minimum interval between calls in milliseconds
|
|
58
|
+
* @param options leading (default true), trailing (default true)
|
|
59
|
+
* @returns Throttled function with cancel() method
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* const handleScroll = throttle(updateUI, 100);
|
|
64
|
+
* window.addEventListener('scroll', handleScroll);
|
|
65
|
+
* handleScroll.cancel();
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
function throttle(fn, ms, options) {
|
|
69
|
+
const callable = fn;
|
|
70
|
+
let lastCallTime = null;
|
|
71
|
+
let timeoutId = null;
|
|
72
|
+
const { leading = true, trailing = true } = options || {};
|
|
73
|
+
let lastArgs = null;
|
|
74
|
+
let lastThis = null;
|
|
75
|
+
const throttled = function(...args) {
|
|
76
|
+
const callTime = Date.now();
|
|
77
|
+
const timeSinceLastCall = lastCallTime === null ? Number.POSITIVE_INFINITY : callTime - lastCallTime;
|
|
78
|
+
lastArgs = args;
|
|
79
|
+
lastThis = this;
|
|
80
|
+
if (leading && timeSinceLastCall >= ms) {
|
|
81
|
+
callable.apply(this, args);
|
|
82
|
+
lastCallTime = callTime;
|
|
83
|
+
if (timeoutId !== null) {
|
|
84
|
+
clearTimeout(timeoutId);
|
|
85
|
+
timeoutId = null;
|
|
86
|
+
}
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (!leading && lastCallTime === null) lastCallTime = callTime;
|
|
90
|
+
if (trailing && timeoutId === null) timeoutId = setTimeout(() => {
|
|
91
|
+
callable.apply(lastThis, lastArgs);
|
|
92
|
+
lastCallTime = Date.now();
|
|
93
|
+
timeoutId = null;
|
|
94
|
+
}, lastCallTime === null ? ms : Math.max(0, ms - (callTime - lastCallTime)));
|
|
95
|
+
};
|
|
96
|
+
throttled.cancel = () => {
|
|
97
|
+
if (timeoutId !== null) {
|
|
98
|
+
clearTimeout(timeoutId);
|
|
99
|
+
timeoutId = null;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
return throttled;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Once — guard against double execution
|
|
106
|
+
*
|
|
107
|
+
* Useful for: init logic, event safety
|
|
108
|
+
*
|
|
109
|
+
* @param fn Function to call at most once
|
|
110
|
+
* @returns Function that executes fn only on first call
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```ts
|
|
114
|
+
* const init = once(setup);
|
|
115
|
+
* init(); // runs
|
|
116
|
+
* init(); // does nothing
|
|
117
|
+
* init(); // does nothing
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
function once(fn) {
|
|
121
|
+
const callable = fn;
|
|
122
|
+
let called = false;
|
|
123
|
+
let result;
|
|
124
|
+
return ((...args) => {
|
|
125
|
+
if (!called) {
|
|
126
|
+
called = true;
|
|
127
|
+
result = callable(...args);
|
|
128
|
+
}
|
|
129
|
+
return result;
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Defer — schedule on microtask queue
|
|
134
|
+
*
|
|
135
|
+
* Useful for: run-after-current-stack logic
|
|
136
|
+
* More reliable than setTimeout(..., 0)
|
|
137
|
+
*
|
|
138
|
+
* @param fn Function to defer
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```ts
|
|
142
|
+
* defer(() => update()); // runs after current stack, before next macrotask
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
function defer(fn) {
|
|
146
|
+
Promise.resolve().then(fn);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* RAF — coalesce multiple updates into single frame
|
|
150
|
+
*
|
|
151
|
+
* Useful for: animation, layout work, render updates
|
|
152
|
+
*
|
|
153
|
+
* @param fn Function to schedule on next animation frame
|
|
154
|
+
* @returns Function that schedules fn on requestAnimationFrame
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```ts
|
|
158
|
+
* const update = raf(render);
|
|
159
|
+
* update(); // schedules on next frame
|
|
160
|
+
* update(); // same frame, no duplicate
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
function raf(fn) {
|
|
164
|
+
const callable = fn;
|
|
165
|
+
let frameId = null;
|
|
166
|
+
let lastArgs = null;
|
|
167
|
+
let lastThis = null;
|
|
168
|
+
return function(...args) {
|
|
169
|
+
lastArgs = args;
|
|
170
|
+
lastThis = this;
|
|
171
|
+
if (frameId === null) frameId = requestAnimationFrame(() => {
|
|
172
|
+
callable.apply(lastThis, lastArgs);
|
|
173
|
+
frameId = null;
|
|
174
|
+
});
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Idle — schedule low-priority work
|
|
179
|
+
*
|
|
180
|
+
* Useful for: background prep, non-urgent updates
|
|
181
|
+
* Falls back to setTimeout if requestIdleCallback unavailable
|
|
182
|
+
*
|
|
183
|
+
* @param fn Function to call when idle
|
|
184
|
+
* @param options timeout for fallback
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* ```ts
|
|
188
|
+
* idle(() => prefetchData());
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
191
|
+
function idle(fn, options) {
|
|
192
|
+
if (typeof requestIdleCallback !== "undefined") requestIdleCallback(fn, options ? { timeout: options.timeout } : void 0);
|
|
193
|
+
else Promise.resolve().then(() => {
|
|
194
|
+
setTimeout(fn, 0);
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Timeout — Promise-based delay
|
|
199
|
+
*
|
|
200
|
+
* Useful for: readable async code, waiting between retries
|
|
201
|
+
*
|
|
202
|
+
* @param ms Milliseconds to wait
|
|
203
|
+
* @returns Promise that resolves after delay
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```ts
|
|
207
|
+
* await timeout(300);
|
|
208
|
+
* console.log('300ms later');
|
|
209
|
+
* ```
|
|
210
|
+
*/
|
|
211
|
+
function timeout(ms) {
|
|
212
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Retry — attempt function with backoff
|
|
216
|
+
*
|
|
217
|
+
* Useful for: network calls, transient failures
|
|
218
|
+
*
|
|
219
|
+
* @param fn Async function to retry
|
|
220
|
+
* @param options maxAttempts, delayMs, backoff function
|
|
221
|
+
* @returns Promise with final result or error
|
|
222
|
+
*
|
|
223
|
+
* @example
|
|
224
|
+
* ```ts
|
|
225
|
+
* const data = await retry(() => fetch(url), {
|
|
226
|
+
* maxAttempts: 3,
|
|
227
|
+
* delayMs: 100,
|
|
228
|
+
* });
|
|
229
|
+
* ```
|
|
230
|
+
*/
|
|
231
|
+
async function retry(fn, options) {
|
|
232
|
+
const { maxAttempts = 3, delayMs = 100, backoff = (i) => delayMs * Math.pow(2, i) } = options || {};
|
|
233
|
+
let lastError = null;
|
|
234
|
+
for (let attempt = 0; attempt < maxAttempts; attempt++) try {
|
|
235
|
+
return await fn();
|
|
236
|
+
} catch (error) {
|
|
237
|
+
lastError = error;
|
|
238
|
+
if (attempt < maxAttempts - 1) await timeout(backoff(attempt));
|
|
239
|
+
}
|
|
240
|
+
throw lastError || /* @__PURE__ */ new Error("Retry failed");
|
|
241
|
+
}
|
|
242
|
+
//#endregion
|
|
243
|
+
//#region src/fx/noop.ts
|
|
244
|
+
const noopEventListener = Object.assign((_ev) => {}, { cancel() {} });
|
|
245
|
+
const noopEventListenerWithFlush = Object.assign((_ev) => {}, {
|
|
246
|
+
cancel() {},
|
|
247
|
+
flush() {}
|
|
248
|
+
});
|
|
249
|
+
//#endregion
|
|
250
|
+
//#region src/fx/fx.ts
|
|
251
|
+
function throwIfDuringRender() {
|
|
252
|
+
if (getCurrentComponentInstance() !== null) throw new Error("[Askr] calling FX handler during render is not allowed. Move calls to event handlers or effects.");
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Helper: schedule a user callback through the global scheduler
|
|
256
|
+
*/
|
|
257
|
+
function enqueueUserCallback(fn) {
|
|
258
|
+
enqueueRuntimeTask(() => {
|
|
259
|
+
try {
|
|
260
|
+
fn();
|
|
261
|
+
} catch (err) {
|
|
262
|
+
logger.error("[Askr] FX handler error:", err);
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
function debounceEvent(ms, handler, options) {
|
|
267
|
+
const { leading = false, trailing = true } = options || {};
|
|
268
|
+
const inst = getCurrentComponentInstance();
|
|
269
|
+
if (inst && inst.ssr) return noopEventListenerWithFlush;
|
|
270
|
+
let timeoutId = null;
|
|
271
|
+
let lastEvent = null;
|
|
272
|
+
let lastCallTime = 0;
|
|
273
|
+
const debounced = function(ev) {
|
|
274
|
+
throwIfDuringRender();
|
|
275
|
+
const now = Date.now();
|
|
276
|
+
lastEvent = ev;
|
|
277
|
+
if (timeoutId !== null) {
|
|
278
|
+
clearTimeout(timeoutId);
|
|
279
|
+
timeoutId = null;
|
|
280
|
+
}
|
|
281
|
+
if (leading && now - lastCallTime >= ms) {
|
|
282
|
+
enqueueUserCallback(() => handler.call(null, ev));
|
|
283
|
+
lastCallTime = now;
|
|
284
|
+
}
|
|
285
|
+
if (trailing) timeoutId = setTimeout(() => {
|
|
286
|
+
if (lastEvent) enqueueUserCallback(() => handler.call(null, lastEvent));
|
|
287
|
+
timeoutId = null;
|
|
288
|
+
lastCallTime = Date.now();
|
|
289
|
+
}, ms);
|
|
290
|
+
};
|
|
291
|
+
debounced.cancel = () => {
|
|
292
|
+
if (timeoutId !== null) {
|
|
293
|
+
clearTimeout(timeoutId);
|
|
294
|
+
timeoutId = null;
|
|
295
|
+
}
|
|
296
|
+
lastEvent = null;
|
|
297
|
+
};
|
|
298
|
+
debounced.flush = () => {
|
|
299
|
+
if (timeoutId !== null) {
|
|
300
|
+
clearTimeout(timeoutId);
|
|
301
|
+
const ev = lastEvent;
|
|
302
|
+
lastEvent = null;
|
|
303
|
+
timeoutId = null;
|
|
304
|
+
if (ev) enqueueUserCallback(() => handler.call(null, ev));
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
if (inst) (inst.cleanupFns ??= []).push(() => {
|
|
308
|
+
debounced.cancel();
|
|
309
|
+
});
|
|
310
|
+
return debounced;
|
|
311
|
+
}
|
|
312
|
+
function throttleEvent(ms, handler, options) {
|
|
313
|
+
const { leading = true, trailing = true } = options || {};
|
|
314
|
+
const inst = getCurrentComponentInstance();
|
|
315
|
+
if (inst && inst.ssr) return noopEventListener;
|
|
316
|
+
let lastCallTime = 0;
|
|
317
|
+
let timeoutId = null;
|
|
318
|
+
let lastEvent = null;
|
|
319
|
+
const throttled = function(ev) {
|
|
320
|
+
throwIfDuringRender();
|
|
321
|
+
const now = Date.now();
|
|
322
|
+
lastEvent = ev;
|
|
323
|
+
if (leading && now - lastCallTime >= ms) {
|
|
324
|
+
enqueueUserCallback(() => handler.call(null, ev));
|
|
325
|
+
lastCallTime = now;
|
|
326
|
+
if (timeoutId !== null) {
|
|
327
|
+
clearTimeout(timeoutId);
|
|
328
|
+
timeoutId = null;
|
|
329
|
+
}
|
|
330
|
+
} else if (!leading && lastCallTime === 0) lastCallTime = now;
|
|
331
|
+
if (trailing && timeoutId === null) {
|
|
332
|
+
const wait = ms - (now - lastCallTime);
|
|
333
|
+
timeoutId = setTimeout(() => {
|
|
334
|
+
if (lastEvent) enqueueUserCallback(() => handler.call(null, lastEvent));
|
|
335
|
+
lastCallTime = Date.now();
|
|
336
|
+
timeoutId = null;
|
|
337
|
+
}, Math.max(0, wait));
|
|
338
|
+
}
|
|
339
|
+
};
|
|
340
|
+
throttled.cancel = () => {
|
|
341
|
+
if (timeoutId !== null) {
|
|
342
|
+
clearTimeout(timeoutId);
|
|
343
|
+
timeoutId = null;
|
|
344
|
+
}
|
|
345
|
+
lastEvent = null;
|
|
346
|
+
};
|
|
347
|
+
if (inst) (inst.cleanupFns ??= []).push(() => throttled.cancel());
|
|
348
|
+
return throttled;
|
|
349
|
+
}
|
|
350
|
+
function rafEvent(handler) {
|
|
351
|
+
const inst = getCurrentComponentInstance();
|
|
352
|
+
if (inst && inst.ssr) return noopEventListener;
|
|
353
|
+
let frameId = null;
|
|
354
|
+
let lastEvent = null;
|
|
355
|
+
const scheduleFrame = () => {
|
|
356
|
+
frameId = (typeof requestAnimationFrame !== "undefined" ? requestAnimationFrame : (cb) => setTimeout(() => cb(Date.now()), 16))(() => {
|
|
357
|
+
frameId = null;
|
|
358
|
+
if (lastEvent) {
|
|
359
|
+
const ev = lastEvent;
|
|
360
|
+
lastEvent = null;
|
|
361
|
+
enqueueUserCallback(() => handler.call(null, ev));
|
|
362
|
+
}
|
|
363
|
+
});
|
|
364
|
+
};
|
|
365
|
+
const fn = function(ev) {
|
|
366
|
+
throwIfDuringRender();
|
|
367
|
+
lastEvent = ev;
|
|
368
|
+
if (frameId === null) scheduleFrame();
|
|
369
|
+
};
|
|
370
|
+
fn.cancel = () => {
|
|
371
|
+
if (frameId !== null) {
|
|
372
|
+
if (typeof cancelAnimationFrame !== "undefined" && typeof frameId === "number") cancelAnimationFrame(frameId);
|
|
373
|
+
else clearTimeout(frameId);
|
|
374
|
+
frameId = null;
|
|
375
|
+
}
|
|
376
|
+
lastEvent = null;
|
|
377
|
+
};
|
|
378
|
+
if (inst) (inst.cleanupFns ??= []).push(() => fn.cancel());
|
|
379
|
+
return fn;
|
|
380
|
+
}
|
|
381
|
+
function scheduleTimeout(ms, fn) {
|
|
382
|
+
throwIfDuringRender();
|
|
383
|
+
const inst = getCurrentComponentInstance();
|
|
384
|
+
if (inst && inst.ssr) return () => {};
|
|
385
|
+
let id = setTimeout(() => {
|
|
386
|
+
id = null;
|
|
387
|
+
enqueueUserCallback(fn);
|
|
388
|
+
}, ms);
|
|
389
|
+
const cancel = () => {
|
|
390
|
+
if (id !== null) {
|
|
391
|
+
clearTimeout(id);
|
|
392
|
+
id = null;
|
|
393
|
+
}
|
|
394
|
+
};
|
|
395
|
+
if (inst) (inst.cleanupFns ??= []).push(cancel);
|
|
396
|
+
return cancel;
|
|
397
|
+
}
|
|
398
|
+
function scheduleIdle(fn, options) {
|
|
399
|
+
throwIfDuringRender();
|
|
400
|
+
const inst = getCurrentComponentInstance();
|
|
401
|
+
if (inst && inst.ssr) return () => {};
|
|
402
|
+
let id = null;
|
|
403
|
+
let usingRIC = false;
|
|
404
|
+
if (typeof requestIdleCallback !== "undefined") {
|
|
405
|
+
usingRIC = true;
|
|
406
|
+
id = requestIdleCallback(() => {
|
|
407
|
+
id = null;
|
|
408
|
+
enqueueUserCallback(fn);
|
|
409
|
+
}, options);
|
|
410
|
+
} else id = setTimeout(() => {
|
|
411
|
+
id = null;
|
|
412
|
+
enqueueUserCallback(fn);
|
|
413
|
+
}, 0);
|
|
414
|
+
const cancel = () => {
|
|
415
|
+
if (id !== null) {
|
|
416
|
+
if (usingRIC && typeof cancelIdleCallback !== "undefined" && typeof id === "number") cancelIdleCallback(id);
|
|
417
|
+
else clearTimeout(id);
|
|
418
|
+
id = null;
|
|
419
|
+
}
|
|
420
|
+
};
|
|
421
|
+
if (inst) (inst.cleanupFns ??= []).push(cancel);
|
|
422
|
+
return cancel;
|
|
423
|
+
}
|
|
424
|
+
function scheduleRetry(fn, options) {
|
|
425
|
+
throwIfDuringRender();
|
|
426
|
+
const inst = getCurrentComponentInstance();
|
|
427
|
+
if (inst && inst.ssr) return { cancel: () => {} };
|
|
428
|
+
const { maxAttempts = 3, delayMs = 100, backoff = (i) => delayMs * Math.pow(2, i) } = options || {};
|
|
429
|
+
let cancelled = false;
|
|
430
|
+
const attempt = (index) => {
|
|
431
|
+
if (cancelled) return;
|
|
432
|
+
enqueueRuntimeTask(() => {
|
|
433
|
+
if (cancelled) return;
|
|
434
|
+
fn().then(() => {}, () => {
|
|
435
|
+
if (cancelled) return;
|
|
436
|
+
if (index + 1 < maxAttempts) {
|
|
437
|
+
const delay = backoff(index);
|
|
438
|
+
setTimeout(() => {
|
|
439
|
+
attempt(index + 1);
|
|
440
|
+
}, delay);
|
|
441
|
+
}
|
|
442
|
+
}).catch((e) => {
|
|
443
|
+
logger.error("[Askr] scheduleRetry error:", e);
|
|
444
|
+
});
|
|
445
|
+
});
|
|
446
|
+
};
|
|
447
|
+
attempt(0);
|
|
448
|
+
const cancel = () => {
|
|
449
|
+
cancelled = true;
|
|
450
|
+
};
|
|
451
|
+
if (inst) (inst.cleanupFns ??= []).push(cancel);
|
|
452
|
+
return { cancel };
|
|
453
|
+
}
|
|
454
|
+
//#endregion
|
|
5
455
|
export { debounce, debounceEvent, defer, idle, once, raf, rafEvent, retry, scheduleEventHandler, scheduleIdle, scheduleRetry, scheduleTimeout, throttle, throttleEvent, timeout };
|