@studiometa/js-toolkit 4.0.0-alpha.1 → 4.0.0-alpha.3
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 +10 -0
- package/dist/Base.d.ts +0 -2
- package/dist/Base.js +1 -2
- package/dist/Base.js.map +1 -1
- package/dist/attribute-namespaces.d.ts +0 -2
- package/dist/attribute-namespaces.js +1 -2
- package/dist/attributes.d.ts +0 -2
- package/dist/attributes.js +1 -2
- package/dist/children-watchers.d.ts +0 -2
- package/dist/children-watchers.js +1 -2
- package/dist/component-brand.d.ts +0 -2
- package/dist/component-brand.js +1 -2
- package/dist/component-declarations.d.ts +0 -2
- package/dist/component-declarations.js +1 -2
- package/dist/context-subscription.d.ts +0 -2
- package/dist/context-subscription.js +1 -2
- package/dist/context.d.ts +0 -2
- package/dist/context.js +1 -2
- package/dist/decorators.d.ts +0 -2
- package/dist/decorators.js +1 -2
- package/dist/diagnostic-contract.d.ts +0 -2
- package/dist/diagnostic-contract.js +1 -2
- package/dist/diagnostics.d.ts +0 -2
- package/dist/diagnostics.js +1 -2
- package/dist/document-order.d.ts +0 -2
- package/dist/document-order.js +1 -2
- package/dist/dom-mutations.d.ts +0 -2
- package/dist/dom-mutations.js +1 -2
- package/dist/events.d.ts +0 -2
- package/dist/events.js +1 -2
- package/dist/group.d.ts +0 -2
- package/dist/group.js +1 -2
- package/dist/instances.d.ts +0 -2
- package/dist/instances.js +1 -2
- package/dist/manifest.d.ts +0 -2
- package/dist/manifest.js +1 -2
- package/dist/mount-strategies.d.ts +0 -2
- package/dist/mount-strategies.js +1 -2
- package/dist/negotiated-events.d.ts +0 -2
- package/dist/negotiated-events.js +1 -2
- package/dist/protocol-symbols.d.ts +0 -2
- package/dist/protocol-symbols.js +1 -2
- package/dist/registry.d.ts +0 -2
- package/dist/registry.js +1 -2
- package/dist/responsive-options.d.ts +0 -2
- package/dist/responsive-options.js +1 -2
- package/dist/scheduler.d.ts +0 -2
- package/dist/scheduler.js +1 -2
- package/dist/scheduler.js.map +1 -1
- package/dist/services/breakpoint.d.ts +0 -2
- package/dist/services/breakpoint.js +1 -2
- package/dist/services/drag.d.ts +0 -2
- package/dist/services/drag.js +1 -2
- package/dist/services/in-view.d.ts +0 -2
- package/dist/services/in-view.js +1 -2
- package/dist/services/key.d.ts +0 -2
- package/dist/services/key.js +1 -2
- package/dist/services/media.d.ts +0 -2
- package/dist/services/media.js +1 -2
- package/dist/services/mixin.d.ts +0 -2
- package/dist/services/mixin.js +1 -2
- package/dist/services/mutation.d.ts +0 -2
- package/dist/services/mutation.js +1 -2
- package/dist/services/pointer.d.ts +0 -2
- package/dist/services/pointer.js +1 -2
- package/dist/services/raf.d.ts +0 -2
- package/dist/services/raf.js +1 -2
- package/dist/services/resize.d.ts +0 -2
- package/dist/services/resize.js +1 -2
- package/dist/services/scroll-progress-offset.d.ts +0 -2
- package/dist/services/scroll-progress-offset.js +1 -2
- package/dist/services/scroll-progress.d.ts +0 -2
- package/dist/services/scroll-progress.js +1 -2
- package/dist/services/scroll.d.ts +0 -2
- package/dist/services/scroll.js +1 -2
- package/dist/services/service.d.ts +0 -2
- package/dist/services/service.js +1 -2
- package/dist/services/toggle.d.ts +0 -2
- package/dist/services/toggle.js +1 -2
- package/dist/services/until.d.ts +0 -2
- package/dist/services/until.js +1 -2
- package/dist/shared-runtime.d.ts +0 -2
- package/dist/shared-runtime.js +1 -2
- package/dist/storage/createStorage.d.ts +0 -2
- package/dist/storage/createStorage.js +1 -2
- package/dist/storage/index.d.ts +0 -2
- package/dist/storage/index.js +1 -2
- package/dist/storage/providers.d.ts +0 -2
- package/dist/storage/providers.js +1 -2
- package/dist/storage/serializers.d.ts +0 -2
- package/dist/storage/serializers.js +1 -2
- package/dist/storage/sync.d.ts +0 -2
- package/dist/storage/sync.js +1 -2
- package/dist/storage/types.d.ts +0 -2
- package/dist/subpaths/BREAKPOINTS.js +1 -2
- package/dist/subpaths/Base.js +1 -2
- package/dist/subpaths/DIAGNOSTICS.js +1 -2
- package/dist/subpaths/DRAG_MODES.js +1 -2
- package/dist/subpaths/EVENTS.js +1 -2
- package/dist/subpaths/MOUNT_ATTRIBUTE.js +1 -2
- package/dist/subpaths/SWAP_MODES.js +1 -2
- package/dist/subpaths/children.js +1 -2
- package/dist/subpaths/component.js +1 -2
- package/dist/subpaths/createContext.js +1 -2
- package/dist/subpaths/createFallbackProvider.js +1 -2
- package/dist/subpaths/createGroup.js +1 -2
- package/dist/subpaths/createLocalStorage.js +1 -2
- package/dist/subpaths/createMemoryStorageProvider.js +1 -2
- package/dist/subpaths/createService.js +1 -2
- package/dist/subpaths/createServiceMixin.js +1 -2
- package/dist/subpaths/createSessionStorage.js +1 -2
- package/dist/subpaths/createStorage.js +1 -2
- package/dist/subpaths/createUrlSearchParamsInHashProvider.js +1 -2
- package/dist/subpaths/createUrlSearchParamsInHashStorage.js +1 -2
- package/dist/subpaths/createUrlSearchParamsProvider.js +1 -2
- package/dist/subpaths/createUrlSearchParamsStorage.js +1 -2
- package/dist/subpaths/defaultScheduler.js +1 -2
- package/dist/subpaths/defineManifest.js +1 -2
- package/dist/subpaths/domUpdate.js +1 -2
- package/dist/subpaths/emitExtendable.js +1 -2
- package/dist/subpaths/fromMetaGlob.js +1 -2
- package/dist/subpaths/fromWebpackContext.js +1 -2
- package/dist/subpaths/getBreakpoints.js +1 -2
- package/dist/subpaths/getInstance.js +1 -2
- package/dist/subpaths/getInstances.js +1 -2
- package/dist/subpaths/getMountedInstances.js +1 -2
- package/dist/subpaths/getUnmountedInstances.js +1 -2
- package/dist/subpaths/inject.js +1 -2
- package/dist/subpaths/injectContext.js +1 -2
- package/dist/subpaths/injectContextSync.js +1 -2
- package/dist/subpaths/jsonSerializer.js +1 -2
- package/dist/subpaths/localStorageProvider.js +1 -2
- package/dist/subpaths/memoryStorageProvider.js +1 -2
- package/dist/subpaths/namespaceQualifier.js +1 -2
- package/dist/subpaths/nextFrame.js +1 -2
- package/dist/subpaths/on.js +1 -2
- package/dist/subpaths/perTarget.js +1 -2
- package/dist/subpaths/provide.js +1 -2
- package/dist/subpaths/provideContext.js +1 -2
- package/dist/subpaths/provideRootContext.js +1 -2
- package/dist/subpaths/read.js +1 -2
- package/dist/subpaths/registerComponent.js +1 -2
- package/dist/subpaths/registerComponents.js +1 -2
- package/dist/subpaths/registerManifest.js +1 -2
- package/dist/subpaths/reportDiagnostic.js +1 -2
- package/dist/subpaths/sessionStorageProvider.js +1 -2
- package/dist/subpaths/setBreakpoints.js +1 -2
- package/dist/subpaths/signal.js +1 -2
- package/dist/subpaths/subscribeContext.js +1 -2
- package/dist/subpaths/swap.js +1 -2
- package/dist/subpaths/toggle.js +1 -2
- package/dist/subpaths/until.js +1 -2
- package/dist/subpaths/urlSearchParamsInHashProvider.js +1 -2
- package/dist/subpaths/urlSearchParamsProvider.js +1 -2
- package/dist/subpaths/useBreakpoint.js +1 -2
- package/dist/subpaths/useDrag.js +1 -2
- package/dist/subpaths/useInView.js +1 -2
- package/dist/subpaths/useKey.js +1 -2
- package/dist/subpaths/useMediaQuery.js +1 -2
- package/dist/subpaths/useMutation.js +1 -2
- package/dist/subpaths/usePointer.js +1 -2
- package/dist/subpaths/usePrefersReducedMotion.js +1 -2
- package/dist/subpaths/useRaf.js +1 -2
- package/dist/subpaths/useResize.js +1 -2
- package/dist/subpaths/useScroll.js +1 -2
- package/dist/subpaths/useScrollProgress.js +1 -2
- package/dist/subpaths/useWindowScroll.js +1 -2
- package/dist/subpaths/useWindowSize.js +1 -2
- package/dist/subpaths/utils/DEFAULT_DAMP_FACTOR.js +1 -2
- package/dist/subpaths/utils/INERTIA_FRAME.js +1 -2
- package/dist/subpaths/utils/MAX_SPRING_RATIO.js +1 -2
- package/dist/subpaths/utils/SCROLL_ALIGNMENTS.js +1 -2
- package/dist/subpaths/utils/SCROLL_AXES.js +1 -2
- package/dist/subpaths/utils/TRANSFORM_PROPS.js +1 -2
- package/dist/subpaths/utils/TRANSITION_OPTIONS.js +1 -2
- package/dist/subpaths/utils/camelCase.js +1 -2
- package/dist/subpaths/utils/capitalize.js +1 -2
- package/dist/subpaths/utils/clamp.js +1 -2
- package/dist/subpaths/utils/clamp01.js +1 -2
- package/dist/subpaths/utils/clampDampFactor.js +1 -2
- package/dist/subpaths/utils/createEaseInOut.js +1 -2
- package/dist/subpaths/utils/createEaseOut.js +1 -2
- package/dist/subpaths/utils/createElement.js +1 -2
- package/dist/subpaths/utils/createRange.js +1 -2
- package/dist/subpaths/utils/damp.js +1 -2
- package/dist/subpaths/utils/debounce.js +1 -2
- package/dist/subpaths/utils/decayOver.js +1 -2
- package/dist/subpaths/utils/deepmerge.js +1 -2
- package/dist/subpaths/utils/easeInCirc.js +1 -2
- package/dist/subpaths/utils/easeInCubic.js +1 -2
- package/dist/subpaths/utils/easeInExpo.js +1 -2
- package/dist/subpaths/utils/easeInOutCirc.js +1 -2
- package/dist/subpaths/utils/easeInOutCubic.js +1 -2
- package/dist/subpaths/utils/easeInOutExpo.js +1 -2
- package/dist/subpaths/utils/easeInOutQuad.js +1 -2
- package/dist/subpaths/utils/easeInOutQuart.js +1 -2
- package/dist/subpaths/utils/easeInOutQuint.js +1 -2
- package/dist/subpaths/utils/easeInOutSine.js +1 -2
- package/dist/subpaths/utils/easeInQuad.js +1 -2
- package/dist/subpaths/utils/easeInQuart.js +1 -2
- package/dist/subpaths/utils/easeInQuint.js +1 -2
- package/dist/subpaths/utils/easeInSine.js +1 -2
- package/dist/subpaths/utils/easeLinear.js +1 -2
- package/dist/subpaths/utils/easeOutCirc.js +1 -2
- package/dist/subpaths/utils/easeOutCubic.js +1 -2
- package/dist/subpaths/utils/easeOutExpo.js +1 -2
- package/dist/subpaths/utils/easeOutQuad.js +1 -2
- package/dist/subpaths/utils/easeOutQuart.js +1 -2
- package/dist/subpaths/utils/easeOutQuint.js +1 -2
- package/dist/subpaths/utils/easeOutSine.js +1 -2
- package/dist/subpaths/utils/enterTransition.js +1 -2
- package/dist/subpaths/utils/fold.js +1 -2
- package/dist/subpaths/utils/getOffsetSizes.js +1 -2
- package/dist/subpaths/utils/historyPush.js +1 -2
- package/dist/subpaths/utils/historyReplace.js +1 -2
- package/dist/subpaths/utils/inertiaDecay.js +1 -2
- package/dist/subpaths/utils/inertiaFinalValue.js +1 -2
- package/dist/subpaths/utils/inertiaStep.js +1 -2
- package/dist/subpaths/utils/inertiaTimeConstant.js +1 -2
- package/dist/subpaths/utils/isBoolean.js +1 -2
- package/dist/subpaths/utils/isDefined.js +1 -2
- package/dist/subpaths/utils/isFunction.js +1 -2
- package/dist/subpaths/utils/isNull.js +1 -2
- package/dist/subpaths/utils/isNumber.js +1 -2
- package/dist/subpaths/utils/isObject.js +1 -2
- package/dist/subpaths/utils/isString.js +1 -2
- package/dist/subpaths/utils/kebabCase.js +1 -2
- package/dist/subpaths/utils/leaveTransition.js +1 -2
- package/dist/subpaths/utils/lerp.js +1 -2
- package/dist/subpaths/utils/loadImage.js +1 -2
- package/dist/subpaths/utils/loadLink.js +1 -2
- package/dist/subpaths/utils/loadScript.js +1 -2
- package/dist/subpaths/utils/lockScroll.js +1 -2
- package/dist/subpaths/utils/lowerCase.js +1 -2
- package/dist/subpaths/utils/map.js +1 -2
- package/dist/subpaths/utils/matrix.js +1 -2
- package/dist/subpaths/utils/mean.js +1 -2
- package/dist/subpaths/utils/memo.js +1 -2
- package/dist/subpaths/utils/noop.js +1 -2
- package/dist/subpaths/utils/noopValue.js +1 -2
- package/dist/subpaths/utils/objectToURLSearchParams.js +1 -2
- package/dist/subpaths/utils/pascalCase.js +1 -2
- package/dist/subpaths/utils/random.js +1 -2
- package/dist/subpaths/utils/randomInt.js +1 -2
- package/dist/subpaths/utils/randomItem.js +1 -2
- package/dist/subpaths/utils/round.js +1 -2
- package/dist/subpaths/utils/saveActiveElement.js +1 -2
- package/dist/subpaths/utils/scrollPosition.js +1 -2
- package/dist/subpaths/utils/scrollTo.js +1 -2
- package/dist/subpaths/utils/selectorFor.js +1 -2
- package/dist/subpaths/utils/setClassesOrStyles.js +1 -2
- package/dist/subpaths/utils/smoothTo.js +1 -2
- package/dist/subpaths/utils/snakeCase.js +1 -2
- package/dist/subpaths/utils/spring.js +1 -2
- package/dist/subpaths/utils/throttle.js +1 -2
- package/dist/subpaths/utils/transform.js +1 -2
- package/dist/subpaths/utils/transition.js +1 -2
- package/dist/subpaths/utils/trapFocus.js +1 -2
- package/dist/subpaths/utils/untrapFocus.js +1 -2
- package/dist/subpaths/utils/upperCase.js +1 -2
- package/dist/subpaths/utils/wait.js +1 -2
- package/dist/subpaths/utils/withLeadingCharacters.js +1 -2
- package/dist/subpaths/utils/withLeadingSlash.js +1 -2
- package/dist/subpaths/utils/withTrailingCharacters.js +1 -2
- package/dist/subpaths/utils/withTrailingSlash.js +1 -2
- package/dist/subpaths/utils/withoutLeadingCharacters.js +1 -2
- package/dist/subpaths/utils/withoutLeadingCharactersRecursive.js +1 -2
- package/dist/subpaths/utils/withoutLeadingSlash.js +1 -2
- package/dist/subpaths/utils/withoutTrailingCharacters.js +1 -2
- package/dist/subpaths/utils/withoutTrailingCharactersRecursive.js +1 -2
- package/dist/subpaths/utils/withoutTrailingSlash.js +1 -2
- package/dist/subpaths/utils/wrap.js +1 -2
- package/dist/subpaths/viewTransition.js +1 -2
- package/dist/subpaths/warn.js +1 -2
- package/dist/subpaths/watchAttributeNamespace.js +1 -2
- package/dist/subpaths/watchAttributes.js +1 -2
- package/dist/subpaths/whenDOMSettled.js +1 -2
- package/dist/subpaths/withDrag.js +1 -2
- package/dist/subpaths/withInView.js +1 -2
- package/dist/subpaths/withKey.js +1 -2
- package/dist/subpaths/withMutation.js +1 -2
- package/dist/subpaths/withPointer.js +1 -2
- package/dist/subpaths/withRaf.js +1 -2
- package/dist/subpaths/withResize.js +1 -2
- package/dist/subpaths/withScroll.js +1 -2
- package/dist/subpaths/withScrollProgress.js +1 -2
- package/dist/subpaths/write.js +1 -2
- package/dist/swap.d.ts +0 -2
- package/dist/swap.js +1 -2
- package/dist/test/index.d.ts +0 -2
- package/dist/test/index.js +1 -2
- package/dist/utils/deepmerge.d.ts +0 -2
- package/dist/utils/deepmerge.js +1 -2
- package/dist/utils/dom.d.ts +0 -2
- package/dist/utils/dom.js +1 -2
- package/dist/utils/easings.d.ts +0 -2
- package/dist/utils/easings.js +1 -2
- package/dist/utils/focus.d.ts +0 -2
- package/dist/utils/focus.js +1 -2
- package/dist/utils/history.d.ts +0 -2
- package/dist/utils/history.js +1 -2
- package/dist/utils/is.d.ts +0 -2
- package/dist/utils/is.js +1 -2
- package/dist/utils/load.d.ts +0 -2
- package/dist/utils/load.js +1 -2
- package/dist/utils/maths.d.ts +0 -2
- package/dist/utils/maths.js +1 -2
- package/dist/utils/memo.d.ts +0 -2
- package/dist/utils/memo.js +1 -2
- package/dist/utils/noop.d.ts +0 -2
- package/dist/utils/noop.js +1 -2
- package/dist/utils/random.d.ts +0 -2
- package/dist/utils/random.js +1 -2
- package/dist/utils/scroll-lock.d.ts +0 -2
- package/dist/utils/scroll-lock.js +1 -2
- package/dist/utils/scrollTo.d.ts +0 -2
- package/dist/utils/scrollTo.js +1 -2
- package/dist/utils/selectors.d.ts +0 -2
- package/dist/utils/selectors.js +1 -2
- package/dist/utils/smoothTo.d.ts +0 -2
- package/dist/utils/smoothTo.js +1 -2
- package/dist/utils/strings.d.ts +0 -2
- package/dist/utils/strings.js +1 -2
- package/dist/utils/timing.d.ts +0 -2
- package/dist/utils/timing.js +1 -2
- package/dist/utils/transform.d.ts +0 -2
- package/dist/utils/transform.js +1 -2
- package/dist/utils/transition.d.ts +0 -2
- package/dist/utils/transition.js +1 -2
- package/dist/viewTransition.d.ts +0 -2
- package/dist/viewTransition.js +1 -2
- package/package.json +6 -3
- package/skills/studiometa-js-toolkit/SKILL.md +87 -0
- package/skills/studiometa-js-toolkit/references/api/configuration.md +169 -0
- package/skills/studiometa-js-toolkit/references/api/context/createContext.md +46 -0
- package/skills/studiometa-js-toolkit/references/api/context/createGroup.md +67 -0
- package/skills/studiometa-js-toolkit/references/api/context/index.md +69 -0
- package/skills/studiometa-js-toolkit/references/api/context/injectContext.md +58 -0
- package/skills/studiometa-js-toolkit/references/api/context/injectContextSync.md +44 -0
- package/skills/studiometa-js-toolkit/references/api/context/provideContext.md +61 -0
- package/skills/studiometa-js-toolkit/references/api/context/provideRootContext.md +42 -0
- package/skills/studiometa-js-toolkit/references/api/context/signal.md +85 -0
- package/skills/studiometa-js-toolkit/references/api/context/subscribeContext.md +71 -0
- package/skills/studiometa-js-toolkit/references/api/decorators/children.md +92 -0
- package/skills/studiometa-js-toolkit/references/api/decorators/component.md +75 -0
- package/skills/studiometa-js-toolkit/references/api/decorators/index.md +41 -0
- package/skills/studiometa-js-toolkit/references/api/decorators/inject.md +73 -0
- package/skills/studiometa-js-toolkit/references/api/decorators/on.md +149 -0
- package/skills/studiometa-js-toolkit/references/api/decorators/provide.md +77 -0
- package/skills/studiometa-js-toolkit/references/api/decorators/read-write.md +93 -0
- package/skills/studiometa-js-toolkit/references/api/diagnostics/DIAGNOSTICS.md +137 -0
- package/skills/studiometa-js-toolkit/references/api/diagnostics/EVENTS.md +45 -0
- package/skills/studiometa-js-toolkit/references/api/diagnostics/index.md +58 -0
- package/skills/studiometa-js-toolkit/references/api/diagnostics/reportDiagnostic.md +67 -0
- package/skills/studiometa-js-toolkit/references/api/diagnostics/warn.md +54 -0
- package/skills/studiometa-js-toolkit/references/api/dom/breakpoints.md +81 -0
- package/skills/studiometa-js-toolkit/references/api/dom/domUpdate.md +70 -0
- package/skills/studiometa-js-toolkit/references/api/dom/emitExtendable.md +68 -0
- package/skills/studiometa-js-toolkit/references/api/dom/index.md +26 -0
- package/skills/studiometa-js-toolkit/references/api/dom/swap.md +105 -0
- package/skills/studiometa-js-toolkit/references/api/dom/watchAttributeNamespace.md +96 -0
- package/skills/studiometa-js-toolkit/references/api/dom/watchAttributes.md +56 -0
- package/skills/studiometa-js-toolkit/references/api/dom/whenDOMSettled.md +41 -0
- package/skills/studiometa-js-toolkit/references/api/html/data-component.md +105 -0
- package/skills/studiometa-js-toolkit/references/api/html/data-mount.md +69 -0
- package/skills/studiometa-js-toolkit/references/api/html/data-option.md +106 -0
- package/skills/studiometa-js-toolkit/references/api/html/data-ref.md +63 -0
- package/skills/studiometa-js-toolkit/references/api/html/index.md +32 -0
- package/skills/studiometa-js-toolkit/references/api/index.md +73 -0
- package/skills/studiometa-js-toolkit/references/api/instance-events.md +75 -0
- package/skills/studiometa-js-toolkit/references/api/instance-methods.md +267 -0
- package/skills/studiometa-js-toolkit/references/api/instance-properties.md +90 -0
- package/skills/studiometa-js-toolkit/references/api/methods-hooks-events.md +149 -0
- package/skills/studiometa-js-toolkit/references/api/methods-hooks-lifecycle.md +90 -0
- package/skills/studiometa-js-toolkit/references/api/methods-hooks-options.md +96 -0
- package/skills/studiometa-js-toolkit/references/api/methods-hooks-services.md +164 -0
- package/skills/studiometa-js-toolkit/references/api/registry/defineManifest.md +57 -0
- package/skills/studiometa-js-toolkit/references/api/registry/fromMetaGlob.md +33 -0
- package/skills/studiometa-js-toolkit/references/api/registry/fromWebpackContext.md +37 -0
- package/skills/studiometa-js-toolkit/references/api/registry/getInstance.md +52 -0
- package/skills/studiometa-js-toolkit/references/api/registry/getInstances.md +48 -0
- package/skills/studiometa-js-toolkit/references/api/registry/getMountedInstances.md +39 -0
- package/skills/studiometa-js-toolkit/references/api/registry/getUnmountedInstances.md +46 -0
- package/skills/studiometa-js-toolkit/references/api/registry/index.md +49 -0
- package/skills/studiometa-js-toolkit/references/api/registry/registerComponent.md +93 -0
- package/skills/studiometa-js-toolkit/references/api/registry/registerComponents.md +37 -0
- package/skills/studiometa-js-toolkit/references/api/registry/registerManifest.md +72 -0
- package/skills/studiometa-js-toolkit/references/api/scheduler/defaultScheduler.md +104 -0
- package/skills/studiometa-js-toolkit/references/api/scheduler/index.md +27 -0
- package/skills/studiometa-js-toolkit/references/api/scheduler/nextFrame.md +31 -0
- package/skills/studiometa-js-toolkit/references/api/scheduler/viewTransition.md +53 -0
- package/skills/studiometa-js-toolkit/references/api/services/createService.md +95 -0
- package/skills/studiometa-js-toolkit/references/api/services/createServiceMixin.md +81 -0
- package/skills/studiometa-js-toolkit/references/api/services/index.md +94 -0
- package/skills/studiometa-js-toolkit/references/api/services/mixins.md +148 -0
- package/skills/studiometa-js-toolkit/references/api/services/perTarget.md +65 -0
- package/skills/studiometa-js-toolkit/references/api/services/toggle.md +80 -0
- package/skills/studiometa-js-toolkit/references/api/services/until.md +44 -0
- package/skills/studiometa-js-toolkit/references/api/services/useBreakpoint.md +42 -0
- package/skills/studiometa-js-toolkit/references/api/services/useDrag.md +119 -0
- package/skills/studiometa-js-toolkit/references/api/services/useInView.md +64 -0
- package/skills/studiometa-js-toolkit/references/api/services/useKey.md +105 -0
- package/skills/studiometa-js-toolkit/references/api/services/useMediaQuery.md +45 -0
- package/skills/studiometa-js-toolkit/references/api/services/useMutation.md +69 -0
- package/skills/studiometa-js-toolkit/references/api/services/usePointer.md +91 -0
- package/skills/studiometa-js-toolkit/references/api/services/usePrefersReducedMotion.md +42 -0
- package/skills/studiometa-js-toolkit/references/api/services/useRaf.md +91 -0
- package/skills/studiometa-js-toolkit/references/api/services/useResize.md +60 -0
- package/skills/studiometa-js-toolkit/references/api/services/useScroll.md +88 -0
- package/skills/studiometa-js-toolkit/references/api/services/useScrollProgress.md +88 -0
- package/skills/studiometa-js-toolkit/references/api/services/useWindowScroll.md +25 -0
- package/skills/studiometa-js-toolkit/references/api/services/useWindowSize.md +25 -0
- package/skills/studiometa-js-toolkit/references/api/storage/createStorage.md +126 -0
- package/skills/studiometa-js-toolkit/references/api/storage/index.md +33 -0
- package/skills/studiometa-js-toolkit/references/api/storage/presets.md +58 -0
- package/skills/studiometa-js-toolkit/references/api/storage/providers.md +109 -0
- package/skills/studiometa-js-toolkit/references/api/test/index.md +214 -0
- package/skills/studiometa-js-toolkit/references/guide/concepts/attribute-grammar.md +93 -0
- package/skills/studiometa-js-toolkit/references/guide/concepts/mutation-engine.md +71 -0
- package/skills/studiometa-js-toolkit/references/guide/concepts/philosophy.md +78 -0
- package/skills/studiometa-js-toolkit/references/guide/concepts/the-registry.md +110 -0
- package/skills/studiometa-js-toolkit/references/guide/going-further/autoloading.md +104 -0
- package/skills/studiometa-js-toolkit/references/guide/going-further/handling-diagnostics.md +104 -0
- package/skills/studiometa-js-toolkit/references/guide/going-further/mount-strategies.md +95 -0
- package/skills/studiometa-js-toolkit/references/guide/going-further/scheduling-work.md +124 -0
- package/skills/studiometa-js-toolkit/references/guide/going-further/sharing-state.md +218 -0
- package/skills/studiometa-js-toolkit/references/guide/going-further/swapping-content.md +92 -0
- package/skills/studiometa-js-toolkit/references/guide/going-further/testing-components.md +137 -0
- package/skills/studiometa-js-toolkit/references/guide/going-further/typing-components.md +190 -0
- package/skills/studiometa-js-toolkit/references/guide/going-further/using-decorators.md +168 -0
- package/skills/studiometa-js-toolkit/references/guide/going-further/using-storage.md +125 -0
- package/skills/studiometa-js-toolkit/references/guide/index.md +163 -0
- package/skills/studiometa-js-toolkit/references/guide/introduction/installation.md +144 -0
- package/skills/studiometa-js-toolkit/references/guide/introduction/lifecycle-hooks.md +174 -0
- package/skills/studiometa-js-toolkit/references/guide/introduction/managing-components.md +229 -0
- package/skills/studiometa-js-toolkit/references/guide/introduction/managing-options.md +235 -0
- package/skills/studiometa-js-toolkit/references/guide/introduction/managing-refs.md +174 -0
- package/skills/studiometa-js-toolkit/references/guide/introduction/using-services.md +218 -0
- package/skills/studiometa-js-toolkit/references/guide/introduction/working-with-events.md +251 -0
- package/skills/studiometa-js-toolkit/references/guide/migration/v3-to-v4.md +373 -0
- package/skills/studiometa-js-toolkit/references/utils/css.md +98 -0
- package/skills/studiometa-js-toolkit/references/utils/dom.md +54 -0
- package/skills/studiometa-js-toolkit/references/utils/easings.md +217 -0
- package/skills/studiometa-js-toolkit/references/utils/focus.md +84 -0
- package/skills/studiometa-js-toolkit/references/utils/history.md +69 -0
- package/skills/studiometa-js-toolkit/references/utils/index.md +53 -0
- package/skills/studiometa-js-toolkit/references/utils/is.md +84 -0
- package/skills/studiometa-js-toolkit/references/utils/load.md +59 -0
- package/skills/studiometa-js-toolkit/references/utils/math.md +129 -0
- package/skills/studiometa-js-toolkit/references/utils/motion.md +218 -0
- package/skills/studiometa-js-toolkit/references/utils/objects.md +68 -0
- package/skills/studiometa-js-toolkit/references/utils/scroll.md +128 -0
- package/skills/studiometa-js-toolkit/references/utils/strings.md +176 -0
- package/skills/studiometa-js-toolkit/references/utils/timing.md +111 -0
- package/skills/studiometa-js-toolkit/references/utils/transitions.md +122 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Loading
|
|
2
|
+
|
|
3
|
+
```js
|
|
4
|
+
import { loadImage, loadLink, loadScript } from '@studiometa/js-toolkit/utils';
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
Three promises over three tags. Each resolves with the **element** it created, so a caller can read the loaded image's natural size, or keep the script tag to remove it later.
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
```js
|
|
12
|
+
import { loadImage, loadLink, loadScript } from '@studiometa/js-toolkit/utils';
|
|
13
|
+
|
|
14
|
+
async function load() {
|
|
15
|
+
const img = await loadImage('/hero.webp');
|
|
16
|
+
|
|
17
|
+
await loadScript('https://example.com/widget.js', { async: '', crossorigin: 'anonymous' });
|
|
18
|
+
|
|
19
|
+
await loadLink('/print.css', { rel: 'stylesheet', media: 'print' });
|
|
20
|
+
}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### loadImage
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
loadImage(src: string): Promise<HTMLImageElement>
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### loadScript
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
loadScript(src: string, attributes?: Record<string, string>): Promise<HTMLScriptElement>
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### loadLink
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
loadLink(href: string, attributes: { rel: string; [key: string]: string }): Promise<HTMLLinkElement>
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Where they belong
|
|
42
|
+
|
|
43
|
+
A third-party widget, a heavy stylesheet or a decorative image is exactly what a deferred mount is for. Reach for these **inside** a component whose mount is already deferred, rather than as a substitute for deferring it:
|
|
44
|
+
|
|
45
|
+
```html
|
|
46
|
+
<div data-component="Widget" data-mount="interaction:page"></div>
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
```js
|
|
50
|
+
mounted() {
|
|
51
|
+
return loadScript('https://example.com/widget.js').then(() => this.init());
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
The [mount strategy](../guide/going-further/mount-strategies.md) decides _when_, and these decide _what_.
|
|
56
|
+
|
|
57
|
+
## What is not here
|
|
58
|
+
|
|
59
|
+
`loadIframe` and `loadElement` are not ported. An iframe is one `createElement()` and one `load` listener, and a generic element loader had no caller that a specific one did not serve better.
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# Math
|
|
2
|
+
|
|
3
|
+
```js
|
|
4
|
+
import { clamp, lerp, map } from '@studiometa/js-toolkit/utils';
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
Values in, values out. For anything with a time dimension — damping, springs, inertia — see [Motion](motion.md).
|
|
8
|
+
|
|
9
|
+
## Ranges
|
|
10
|
+
|
|
11
|
+
```js
|
|
12
|
+
import { clamp, clamp01 } from '@studiometa/js-toolkit/utils';
|
|
13
|
+
|
|
14
|
+
clamp(15, 0, 10); // 10
|
|
15
|
+
clamp(-5, 0, 10); // 0
|
|
16
|
+
clamp01(1.5); // 1
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### clamp
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
clamp(value: number, min: number, max: number): number
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Keep a value inside a range.
|
|
26
|
+
|
|
27
|
+
### clamp01
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
clamp01(value: number): number
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Keep a value inside `0 → 1`. It is the case that comes up in every progress calculation, so it has its own name and no arguments to get the wrong way round.
|
|
34
|
+
|
|
35
|
+
## Interpolation
|
|
36
|
+
|
|
37
|
+
```js
|
|
38
|
+
import { lerp, map } from '@studiometa/js-toolkit/utils';
|
|
39
|
+
|
|
40
|
+
lerp(0, 100, 0.5); // 50
|
|
41
|
+
map(5, 0, 10, 0, 100); // 50
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### lerp
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
lerp(min: number, max: number, ratio: number): number
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Interpolate between two values by a `0 → 1` ratio.
|
|
51
|
+
|
|
52
|
+
### map
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
map(value: number, inputMin: number, inputMax: number, outputMin: number, outputMax: number): number
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Re-scale one range onto another. It is `lerp` with the input range worked out for you.
|
|
59
|
+
|
|
60
|
+
## Wrapping and folding
|
|
61
|
+
|
|
62
|
+
```js
|
|
63
|
+
import { fold, wrap } from '@studiometa/js-toolkit/utils';
|
|
64
|
+
|
|
65
|
+
wrap(11, 0, 10); // 1 — it comes back round
|
|
66
|
+
fold(11, 0, 10); // 9 — it bounces back
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Two behaviours, two names, no flag.
|
|
70
|
+
|
|
71
|
+
### wrap
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
wrap(value: number, min: number, max: number): number
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
A carousel that loops: past the end, it comes back round to the start.
|
|
78
|
+
|
|
79
|
+
### fold
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
fold(value: number, min: number, max: number): number
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
A value that reverses at the edges rather than looping.
|
|
86
|
+
|
|
87
|
+
## Rounding and averaging
|
|
88
|
+
|
|
89
|
+
```js
|
|
90
|
+
import { mean, round } from '@studiometa/js-toolkit/utils';
|
|
91
|
+
|
|
92
|
+
round(1.2345, 2); // 1.23
|
|
93
|
+
mean([1, 2, 3, 4]); // 2.5
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### round
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
round(value: number, decimals?: number): number
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Round to a number of decimals.
|
|
103
|
+
|
|
104
|
+
### mean
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
mean(numbers: readonly number[]): number
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
The arithmetic mean of a list.
|
|
111
|
+
|
|
112
|
+
## Series
|
|
113
|
+
|
|
114
|
+
### createRange
|
|
115
|
+
|
|
116
|
+
```ts
|
|
117
|
+
createRange(min: number, max: number, step: number): number[]
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
```js
|
|
121
|
+
import { createRange } from '@studiometa/js-toolkit/utils';
|
|
122
|
+
|
|
123
|
+
createRange(0, 1, 0.25); // [0, 0.25, 0.5, 0.75, 1]
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## See also
|
|
127
|
+
|
|
128
|
+
- [Easings](easings.md) — shaping a `0 → 1` progress
|
|
129
|
+
- [Motion](motion.md) — everything with an elapsed time
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
# Motion
|
|
2
|
+
|
|
3
|
+
```js
|
|
4
|
+
import { damp, smoothTo, spring } from '@studiometa/js-toolkit/utils';
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
Everything here takes a **time**, not a frame count.
|
|
8
|
+
|
|
9
|
+
> **Decay is expressed in time, not in frames.** `INERTIA_FRAME` (16.67 ms) is the reference of every factor.
|
|
10
|
+
|
|
11
|
+
That is what makes a factor mean the same thing at 60 Hz and at 120 Hz, and it is why `damp()` takes the elapsed time as a **required** argument.
|
|
12
|
+
|
|
13
|
+
## Damping
|
|
14
|
+
|
|
15
|
+
### damp
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
damp(targetValue: number, currentValue: number, factor: number, elapsed: number, precision?: number): number
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
```js
|
|
22
|
+
import { useRaf } from '@studiometa/js-toolkit';
|
|
23
|
+
import { damp } from '@studiometa/js-toolkit/utils';
|
|
24
|
+
let current = 0;
|
|
25
|
+
let target = 100;
|
|
26
|
+
|
|
27
|
+
useRaf().subscribe(({ delta }) => {
|
|
28
|
+
current = damp(target, current, 0.1, delta);
|
|
29
|
+
});
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
`factor` is **the fraction of the gap that closes per reference frame**, so it is stable for every value a caller can pass. `precision` defaults to `0.01`: below it, the value snaps to the target.
|
|
33
|
+
|
|
34
|
+
**v3's `damp()` had no `elapsed`**
|
|
35
|
+
|
|
36
|
+
```js
|
|
37
|
+
damp(current, target, 0.1); // [!code --]
|
|
38
|
+
damp(target, current, 0.1, delta); // [!code ++]
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
A factor without a time is a factor that means something different on every display.
|
|
42
|
+
|
|
43
|
+
### clampDampFactor
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
clampDampFactor(factor: number): number
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Keeps a factor in the usable range.
|
|
50
|
+
|
|
51
|
+
### decayOver
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
decayOver(retained: number, elapsed: number): number
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
The decay of an elapsed time.
|
|
58
|
+
|
|
59
|
+
## Springs
|
|
60
|
+
|
|
61
|
+
### spring
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
spring(
|
|
65
|
+
targetValue: number,
|
|
66
|
+
currentValue: number,
|
|
67
|
+
currentVelocity: number,
|
|
68
|
+
elapsed: number,
|
|
69
|
+
options?: { stiffness?: number; damping?: number; mass?: number; precision?: number },
|
|
70
|
+
): [value: number, velocity: number]
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
```js
|
|
74
|
+
import { useRaf } from '@studiometa/js-toolkit';
|
|
75
|
+
import { spring } from '@studiometa/js-toolkit/utils';
|
|
76
|
+
let value = 0;
|
|
77
|
+
let velocity = 0;
|
|
78
|
+
|
|
79
|
+
useRaf().subscribe(({ delta }) => {
|
|
80
|
+
[value, velocity] = spring(100, value, velocity, delta, { stiffness: 0.1, damping: 0.8 });
|
|
81
|
+
});
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
It returns the pair, because a spring's state **is** the value and its velocity — hiding the velocity would make the next step wrong.
|
|
85
|
+
|
|
86
|
+
**It integrates on a fixed step of a quarter frame**, however long the real frame is, so `stiffness`, `damping` and `mass` keep their meaning and the duration is real. `stiffness / mass` is clamped to `MAX_SPRING_RATIO`, from which that step is derived.
|
|
87
|
+
|
|
88
|
+
`precision` defaults to `1e-4`.
|
|
89
|
+
|
|
90
|
+
## Smoothing
|
|
91
|
+
|
|
92
|
+
### smoothTo
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
smoothTo(start?: number, options?: SmoothToOptions): SmoothTo
|
|
96
|
+
smoothTo<K extends string>(start: Record<K, number>, options?: SmoothToOptions): SmoothToRecord<K>
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
**A `toggle()` over `useRaf()`**: one subscription however many times the target is set, started when the value has somewhere to go, released when it arrives.
|
|
100
|
+
|
|
101
|
+
```js
|
|
102
|
+
import { smoothTo } from '@studiometa/js-toolkit/utils';
|
|
103
|
+
|
|
104
|
+
const x = smoothTo(0, { damping: 0.85 });
|
|
105
|
+
|
|
106
|
+
x(400); // set a target, read the smoothed value
|
|
107
|
+
x(); // read it
|
|
108
|
+
x.raw(); // the target, unsmoothed
|
|
109
|
+
x.add(50); // move the target
|
|
110
|
+
x.jump(0); // set value and target at once — no travel, no frame
|
|
111
|
+
x.isMoving; // still travelling?
|
|
112
|
+
|
|
113
|
+
const unsubscribe = x.subscribe((value) => {
|
|
114
|
+
document.body.style.setProperty('--x', `${value}px`);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
x.destroy(); // release the frame subscription and every subscriber
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
#### Several channels on one subscription
|
|
121
|
+
|
|
122
|
+
```js
|
|
123
|
+
import { smoothTo } from '@studiometa/js-toolkit/utils';
|
|
124
|
+
|
|
125
|
+
const view = smoothTo({ x: 0, y: 0, scale: 1 });
|
|
126
|
+
|
|
127
|
+
view({ x: 100, y: 50 }); // only these two are re-aimed; `scale` keeps travelling
|
|
128
|
+
view.jump({ scale: 1 }); // reset one channel with no travel
|
|
129
|
+
view.isMoving; // true while *any* channel moves
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
**The keys are the consumer's own** — a scale, an opacity or a progress as readily as a coordinate. One frame subscription, one settled state (the loop stops when the **last** channel arrives), and one subscriber call per frame carrying the whole record.
|
|
133
|
+
|
|
134
|
+
**The record handed out is the same object every frame**
|
|
135
|
+
|
|
136
|
+
As a service hands the same props. Treat it as read-only, and copy it with `{ ...values }` to keep one.
|
|
137
|
+
|
|
138
|
+
The mode — `spring`, `stiffness`, `mass` — belongs to the **instance**, not the channel.
|
|
139
|
+
|
|
140
|
+
#### `damping` accepts a function
|
|
141
|
+
|
|
142
|
+
```js
|
|
143
|
+
smoothTo({ x: 0, y: 0 }, { damping: (key) => (key === 'x' ? 0.9 : 0.7) });
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
It is read on **every frame and for every channel**, which matters for three reasons:
|
|
147
|
+
|
|
148
|
+
1. **A component's factor is an option**, and `$options` is a live view over attributes — so a factor captured once would freeze an attribute the framework keeps live.
|
|
149
|
+
2. It expresses a factor that depends on the **direction of travel**: read the current value and decide.
|
|
150
|
+
3. It gives one channel of a record a different rate from its neighbour.
|
|
151
|
+
|
|
152
|
+
A number stays a number.
|
|
153
|
+
|
|
154
|
+
#### `precision`
|
|
155
|
+
|
|
156
|
+
Defaults to the default of the function each mode wraps — `0.01` damping, `1e-4` springing — so converting a raw `damp()` call to the helper does not move where it snaps.
|
|
157
|
+
|
|
158
|
+
## Inertia
|
|
159
|
+
|
|
160
|
+
The family a coast is built from, and what [`useDrag()`](../api/services/useDrag.md) uses.
|
|
161
|
+
|
|
162
|
+
**`inertiaStep()` integrates the decay across the step**, so any sequence of frames sums to `velocity · τ` exactly — a coast lands in the same place whatever the frame rate did on the way. `inertiaFinalValue()` is what lets a carousel know which slide a fling is heading for **before** the coast starts.
|
|
163
|
+
|
|
164
|
+
### inertiaDecay
|
|
165
|
+
|
|
166
|
+
```ts
|
|
167
|
+
inertiaDecay(dampFactor: number, elapsed: number): number
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
`decayOver` with the tighter clamp a coast needs.
|
|
171
|
+
|
|
172
|
+
### inertiaTimeConstant
|
|
173
|
+
|
|
174
|
+
```ts
|
|
175
|
+
inertiaTimeConstant(dampFactor: number): number
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
`τ = INERTIA_FRAME / ln(1 / damp)`.
|
|
179
|
+
|
|
180
|
+
### inertiaStep
|
|
181
|
+
|
|
182
|
+
```ts
|
|
183
|
+
inertiaStep(velocity: number, dampFactor: number, elapsed: number): number
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
The distance travelled across the step.
|
|
187
|
+
|
|
188
|
+
### inertiaFinalValue
|
|
189
|
+
|
|
190
|
+
```ts
|
|
191
|
+
inertiaFinalValue(value: number, velocity: number, dampFactor: number): number
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
Where it will come to rest: `value + velocity · τ`.
|
|
195
|
+
|
|
196
|
+
## Constants
|
|
197
|
+
|
|
198
|
+
### INERTIA_FRAME
|
|
199
|
+
|
|
200
|
+
```ts
|
|
201
|
+
const INERTIA_FRAME: number;
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
`16.67` — the reference frame, in milliseconds.
|
|
205
|
+
|
|
206
|
+
### DEFAULT_DAMP_FACTOR
|
|
207
|
+
|
|
208
|
+
```ts
|
|
209
|
+
const DEFAULT_DAMP_FACTOR = 0.85;
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
### MAX_SPRING_RATIO
|
|
213
|
+
|
|
214
|
+
```ts
|
|
215
|
+
const MAX_SPRING_RATIO: number;
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
The clamp on `stiffness / mass`.
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Objects & random
|
|
2
|
+
|
|
3
|
+
```js
|
|
4
|
+
import { deepmerge, random, randomInt, randomItem } from '@studiometa/js-toolkit/utils';
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
## Merging
|
|
8
|
+
|
|
9
|
+
### deepmerge
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
deepmerge(...layers: Record<string, unknown>[]): Record<string, unknown>
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
import { deepmerge } from '@studiometa/js-toolkit/utils';
|
|
17
|
+
|
|
18
|
+
deepmerge({ tween: { ease: 'linear', duration: 300 } }, { tween: { ease: 'ease-out' } });
|
|
19
|
+
// { tween: { ease: 'ease-out', duration: 300 } }
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Later layers win, at every depth. Plain objects merge; anything else — an array, a `Date`, an element, a class instance — **replaces**.
|
|
23
|
+
|
|
24
|
+
That last rule is the one worth knowing: an array is a value, not a structure to merge, because merging two arrays by index is almost never what a caller meant.
|
|
25
|
+
|
|
26
|
+
**It ships for the consumer, not for core**
|
|
27
|
+
|
|
28
|
+
A utility is judged by consumer need, not by whether core calls it. Layering a default config under an author's config is the case every component author meets, and getting the array rule wrong is exactly how a hand-rolled merge misbehaves.
|
|
29
|
+
|
|
30
|
+
## Random
|
|
31
|
+
|
|
32
|
+
```js
|
|
33
|
+
import { random, randomInt, randomItem } from '@studiometa/js-toolkit/utils';
|
|
34
|
+
|
|
35
|
+
random(10); // 0 → 10
|
|
36
|
+
random(5, 10); // 5 → 10
|
|
37
|
+
randomInt(10); // an integer, 0 → 10
|
|
38
|
+
randomItem(['a', 'b', 'c']);
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
**One argument is a maximum; two are a range.**
|
|
42
|
+
|
|
43
|
+
### random
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
random(a: number, b?: number): number
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
A float in the range.
|
|
50
|
+
|
|
51
|
+
### randomInt
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
randomInt(a: number, b?: number): number
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
An integer in the range, bounds inclusive.
|
|
58
|
+
|
|
59
|
+
### randomItem
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
randomItem<T>(items: readonly T[]): T | undefined
|
|
63
|
+
randomItem(items: string): string | undefined
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
One item from an array, or one character from a string.
|
|
67
|
+
|
|
68
|
+
The return includes `undefined` because an empty input has no item to give — and a signature that pretended otherwise would put the bug three lines later.
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# Scroll
|
|
2
|
+
|
|
3
|
+
```js
|
|
4
|
+
import { lockScroll, scrollPosition, scrollTo } from '@studiometa/js-toolkit/utils';
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
## Scrolling to a target
|
|
8
|
+
|
|
9
|
+
**The two halves are separate because callers need them separately.** `scrollPosition()` measures and returns; `scrollTo()` calls it and moves.
|
|
10
|
+
|
|
11
|
+
A carousel asks which slide is nearest three times for every time it travels — and in v3, asking meant scrolling.
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
import { scrollPosition, scrollTo } from '@studiometa/js-toolkit/utils';
|
|
15
|
+
|
|
16
|
+
const el = document.body;
|
|
17
|
+
|
|
18
|
+
// Where would we end up?
|
|
19
|
+
const { top, left } = scrollPosition(el, { align: 'center' });
|
|
20
|
+
|
|
21
|
+
// Go there.
|
|
22
|
+
scrollTo(el, { align: 'center', offset: -80 });
|
|
23
|
+
scrollTo('#section', { axis: 'y' });
|
|
24
|
+
scrollTo(0);
|
|
25
|
+
scrollTo({ top: 200 });
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### scrollPosition
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
scrollPosition(target: ScrollToTarget, options?: ScrollPositionOptions): ScrollPosition
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Measures and returns `{ top, left }` without moving anything.
|
|
35
|
+
|
|
36
|
+
### scrollTo
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
scrollTo(target: ScrollToTarget, options?: ScrollToOptions): ScrollPosition
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Calls `scrollPosition()` and moves there, returning the same result.
|
|
43
|
+
|
|
44
|
+
`behavior` defaults to `'smooth'`, or to `'instant'` when the reader has asked for less motion — so honouring the preference is the default rather than a call site's responsibility.
|
|
45
|
+
|
|
46
|
+
### The target
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
type ScrollToTarget = string | Element | number | Partial<{ left: number; top: number }>;
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
A selector, an element, a number, or a position. **A number or a position names its own destination**, so `align` does not apply to it.
|
|
53
|
+
|
|
54
|
+
### The options
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
interface ScrollPositionOptions {
|
|
58
|
+
rootElement?: Element | Window; // what scrolls. Defaults to the window.
|
|
59
|
+
axis?: 'x' | 'y' | 'both'; // which axes a target that names none may move. Defaults to 'y'.
|
|
60
|
+
offset?: number; // pixels to stop short. Defaults to 0.
|
|
61
|
+
align?: ScrollAlign | { x?: ScrollAlign; y?: ScrollAlign };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
interface ScrollToOptions extends ScrollPositionOptions {
|
|
65
|
+
behavior?: ScrollBehavior;
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
**`align` is `'start' | 'center' | 'end'`, or one per axis**, and it applies to an **element** target only.
|
|
70
|
+
|
|
71
|
+
**The names are physical, like `axis`**
|
|
72
|
+
|
|
73
|
+
`x` and `y`, not the platform's `inline` and `block`. Nothing here maps a writing mode, and borrowing that vocabulary without the mapping would promise what `compute-scroll-into-view` promises and does not deliver.
|
|
74
|
+
|
|
75
|
+
What the arithmetic gets right: **the viewport is the client box**, so a scrollbar gutter is out of it with no special case, and **the destination is clamped to the scroll range** — centring the first slide asks for a negative offset and gets `0`.
|
|
76
|
+
|
|
77
|
+
### SCROLL_AXES
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
const SCROLL_AXES: Readonly<{ x: 'x'; y: 'y'; both: 'both' }>;
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### SCROLL_ALIGNMENTS
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
const SCROLL_ALIGNMENTS: Readonly<{ start: 'start'; center: 'center'; end: 'end' }>;
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### A dependency was measured and refused
|
|
90
|
+
|
|
91
|
+
`compute-scroll-into-view` is 1.4 kB and walks **every** scrolling ancestor — which is what v4's single `rootElement` contract declines, and what a boundary option already cancels. Its own source leaves writing modes unimplemented and reads no `scroll-padding`, so the real delta over core was about twenty lines.
|
|
92
|
+
|
|
93
|
+
## Locking the page
|
|
94
|
+
|
|
95
|
+
### lockScroll
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
lockScroll(target?: HTMLElement): () => void
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
```js
|
|
102
|
+
import { lockScroll } from '@studiometa/js-toolkit/utils';
|
|
103
|
+
|
|
104
|
+
const release = lockScroll();
|
|
105
|
+
// … the modal is open
|
|
106
|
+
release();
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
**It counts.** A modal surface is not alone on a page: a dialog opened from inside a drawer is two holders, and the one that closes first must not put the scroll back under the one still open.
|
|
110
|
+
|
|
111
|
+
- The **first** lock saves the inline value it found.
|
|
112
|
+
- The **last** release puts exactly that value back.
|
|
113
|
+
- The ones between only move the count.
|
|
114
|
+
|
|
115
|
+
**The release is idempotent**, so a surface calls it on close and again on unmount without counting twice — and a component unmounted while open owes the page its scroll, which is what the second call is for.
|
|
116
|
+
|
|
117
|
+
**The count is shared across evaluated copies of the package**, through the same runtime slot the focus helpers use, for the same reason: there is one scroll per document.
|
|
118
|
+
|
|
119
|
+
It is **`overflow: hidden` and nothing else**. No `paddingRight` compensation: `scrollbar-gutter: stable` is the page's own answer and it does not mis-handle fixed children. iOS Safari remains unreliable, which is the argument for having one function rather than a copy per component.
|
|
120
|
+
|
|
121
|
+
**A native `<dialog>` needs it too**
|
|
122
|
+
|
|
123
|
+
`showModal()` gives the top layer, the backdrop, a focus trap and `Escape`. It does **not** stop the page behind it scrolling.
|
|
124
|
+
|
|
125
|
+
## See also
|
|
126
|
+
|
|
127
|
+
- [`useScroll()`](../api/services/useScroll.md) — scroll position as a service
|
|
128
|
+
- [`useScrollProgress()`](../api/services/useScrollProgress.md) — an element's progress through the viewport
|