@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,105 @@
|
|
|
1
|
+
# useKey
|
|
2
|
+
|
|
3
|
+
```ts
|
|
4
|
+
useKey(target?: Document | Element | Window): Service<KeyProps>
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
The keyboard as a service, one instance per target, defaulting to the document.
|
|
8
|
+
|
|
9
|
+
## Props
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
interface KeyProps {
|
|
13
|
+
readonly event: KeyboardEvent | null;
|
|
14
|
+
readonly triggered: number;
|
|
15
|
+
readonly isDown: boolean;
|
|
16
|
+
readonly isUp: boolean;
|
|
17
|
+
// plus one boolean per named key
|
|
18
|
+
readonly ENTER: boolean;
|
|
19
|
+
readonly SPACE: boolean;
|
|
20
|
+
readonly TAB: boolean;
|
|
21
|
+
readonly ESC: boolean;
|
|
22
|
+
readonly LEFT: boolean;
|
|
23
|
+
readonly UP: boolean;
|
|
24
|
+
readonly RIGHT: boolean;
|
|
25
|
+
readonly DOWN: boolean;
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Usage
|
|
30
|
+
|
|
31
|
+
```js
|
|
32
|
+
import { Base, useKey } from '@studiometa/js-toolkit';
|
|
33
|
+
|
|
34
|
+
class Dialog extends Base {
|
|
35
|
+
static config = { name: 'Dialog' };
|
|
36
|
+
|
|
37
|
+
mounted() {
|
|
38
|
+
return useKey().subscribe(({ ESC, isDown }) => {
|
|
39
|
+
if (ESC && isDown) this.$el.removeAttribute('data-option-open');
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
A region rather than the document:
|
|
46
|
+
|
|
47
|
+
```js
|
|
48
|
+
import { Base, useKey } from '@studiometa/js-toolkit';
|
|
49
|
+
|
|
50
|
+
class Menu extends Base {
|
|
51
|
+
static config = { name: 'Menu' };
|
|
52
|
+
|
|
53
|
+
mounted() {
|
|
54
|
+
return useKey(this.$el).subscribe(({ DOWN, isDown }) => {
|
|
55
|
+
if (DOWN && isDown) this.focusNext();
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
focusNext() {}
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
**An element target is what removes the `hasFocus` bookkeeping** a document-only service forces on a consumer.
|
|
64
|
+
|
|
65
|
+
## The eight names
|
|
66
|
+
|
|
67
|
+
The eight names of v3 are kept, resolved from `KeyboardEvent.key` rather than from the deprecated `keyCode`:
|
|
68
|
+
|
|
69
|
+
| Name | `event.key` |
|
|
70
|
+
| ------- | ------------ |
|
|
71
|
+
| `ENTER` | `Enter` |
|
|
72
|
+
| `SPACE` | `' '` |
|
|
73
|
+
| `TAB` | `Tab` |
|
|
74
|
+
| `ESC` | `Escape` |
|
|
75
|
+
| `LEFT` | `ArrowLeft` |
|
|
76
|
+
| `UP` | `ArrowUp` |
|
|
77
|
+
| `RIGHT` | `ArrowRight` |
|
|
78
|
+
| `DOWN` | `ArrowDown` |
|
|
79
|
+
|
|
80
|
+
The constant that maps them is **module-internal**: the names reach a consumer as props, so nothing is left to compare against. The flags are a mapped type over that constant, so the props cannot drift from it.
|
|
81
|
+
|
|
82
|
+
**Why they are an exception**
|
|
83
|
+
|
|
84
|
+
Props are flat and nothing derivable is a field — and each of these compares `event.key` against a named value, so nothing about them is unavailable from `event`. They are kept for call-site parity with v3, where `keyed({ ESC })` is how components read the keyboard.
|
|
85
|
+
|
|
86
|
+
## `triggered` counts repeats of _one_ key
|
|
87
|
+
|
|
88
|
+
A keydown whose key matches the previous event's **while that key is still down** increments it. A different key, or any keyup, sets it back to `1`.
|
|
89
|
+
|
|
90
|
+
v3 incremented on any two consecutive keydowns, so holding `A` and then pressing `B` reported `2`.
|
|
91
|
+
|
|
92
|
+
## The listeners are neither passive nor capturing
|
|
93
|
+
|
|
94
|
+
- **Not passive**, because `trapFocus()` and every keyboard shortcut call `preventDefault()` on the event the subscriber is handed, and a passive listener cannot.
|
|
95
|
+
- **No capture**, unlike the pointer service, because a descendant that handles its own keys and stops the propagation is **respected** rather than overheard.
|
|
96
|
+
|
|
97
|
+
## Mixin
|
|
98
|
+
|
|
99
|
+
```js
|
|
100
|
+
class Dialog extends withKey(Base) {
|
|
101
|
+
keyed({ ESC, isDown }) {}
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
`withKey` takes the document default too, as `withScroll` and `withResize` do for their own page-wide source. A region is `withKey(Base, { target: (instance) => instance.$refs.wrapper })`.
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# useMediaQuery
|
|
2
|
+
|
|
3
|
+
```ts
|
|
4
|
+
useMediaQuery(query: string): Service<{ readonly matches: boolean }>
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
The `matchMedia` engine, exposed. One instance per query string.
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
```js
|
|
12
|
+
import { useMediaQuery } from '@studiometa/js-toolkit';
|
|
13
|
+
|
|
14
|
+
const wide = useMediaQuery('(min-width: 64rem)');
|
|
15
|
+
|
|
16
|
+
// `props()` answers with no subscription, because asking a MediaQueryList is a read.
|
|
17
|
+
if (wide.props().matches) {
|
|
18
|
+
// …
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const unsubscribe = wide.subscribe(({ matches }) => {
|
|
22
|
+
console.log(matches);
|
|
23
|
+
});
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
**Parameters**
|
|
27
|
+
|
|
28
|
+
- `query` — any media query string.
|
|
29
|
+
|
|
30
|
+
## `props()` needs no subscription
|
|
31
|
+
|
|
32
|
+
Asking a `MediaQueryList` whether it matches **is a read**, so this service can answer without starting anything. Emissions are crossings.
|
|
33
|
+
|
|
34
|
+
That makes it the one service where `props()` outside a subscription is not a compromise.
|
|
35
|
+
|
|
36
|
+
## Where it is used
|
|
37
|
+
|
|
38
|
+
`data-mount="media:<query>"` is this service, which is why that strategy is **reversible**: a crossing out unmounts the instance and a crossing back mounts it again.
|
|
39
|
+
|
|
40
|
+
See [Mount strategies](../../guide/going-further/mount-strategies.md).
|
|
41
|
+
|
|
42
|
+
## See also
|
|
43
|
+
|
|
44
|
+
- [`usePrefersReducedMotion()`](usePrefersReducedMotion.md) — the named case
|
|
45
|
+
- [`useBreakpoint()`](useBreakpoint.md) — the named breakpoint set
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# useMutation
|
|
2
|
+
|
|
3
|
+
```ts
|
|
4
|
+
useMutation(target: Node, init?: MutationObserverInit): Service<MutationProps>
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
A general `MutationObserver` as a service, for "tell me when anything under this node changes".
|
|
8
|
+
|
|
9
|
+
## Props
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
interface MutationProps {
|
|
13
|
+
readonly records: readonly MutationRecord[];
|
|
14
|
+
}
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
The default observation is `{ childList: true, subtree: true }`.
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
```js
|
|
22
|
+
import { Base, useMutation } from '@studiometa/js-toolkit';
|
|
23
|
+
|
|
24
|
+
class Counter extends Base {
|
|
25
|
+
static config = { name: 'Counter', refs: ['list'] };
|
|
26
|
+
|
|
27
|
+
mounted() {
|
|
28
|
+
return useMutation(this.$el, { childList: true }).subscribe(({ records }) => {
|
|
29
|
+
this.$el.dataset.count = String(this.$el.children.length);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Reach for something narrower first
|
|
36
|
+
|
|
37
|
+
| Want | Use |
|
|
38
|
+
| -------------------------------------------- | -------------------------------------------------------------------- |
|
|
39
|
+
| one attribute of one element | [`watchAttributes()`](../dom/watchAttributes.md) |
|
|
40
|
+
| a whole namespace of attributes | [`watchAttributeNamespace()`](../dom/watchAttributeNamespace.md) |
|
|
41
|
+
| what the framework already reconciles | the registry — it is already watching |
|
|
42
|
+
| a subtree, character data, or a foreign node | **this** |
|
|
43
|
+
|
|
44
|
+
## It keeps nothing after the delivery
|
|
45
|
+
|
|
46
|
+
`props()` is **empty between deliveries**, so `{ immediate: true }` waits for a real batch rather than inventing one. That is the honest answer for a service whose value _is_ a batch.
|
|
47
|
+
|
|
48
|
+
## Platform timing, not framework order
|
|
49
|
+
|
|
50
|
+
This service delivers on the **platform's** timing. A subscriber that needs the framework's order awaits `whenDOMSettled()` in its callback:
|
|
51
|
+
|
|
52
|
+
```js
|
|
53
|
+
useMutation(el).subscribe(async () => {
|
|
54
|
+
await whenDOMSettled();
|
|
55
|
+
// the new components have mounted
|
|
56
|
+
});
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Keying
|
|
60
|
+
|
|
61
|
+
Its key is a **canonical init**, through `resolveInit()`, which keeps the DOM contract rather than sorting the object blindly. See [`perTarget()`](perTarget.md).
|
|
62
|
+
|
|
63
|
+
## Mixin
|
|
64
|
+
|
|
65
|
+
```js
|
|
66
|
+
class Counter extends withMutation(Base, { childList: true }) {
|
|
67
|
+
mutated({ records }) {}
|
|
68
|
+
}
|
|
69
|
+
```
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# usePointer
|
|
2
|
+
|
|
3
|
+
```ts
|
|
4
|
+
usePointer(): Service<PointerProps>
|
|
5
|
+
usePointer(target: Element): Service<ElementPointerProps>
|
|
6
|
+
```
|
|
7
|
+
|
|
8
|
+
The pointer, in the viewport or in a box.
|
|
9
|
+
|
|
10
|
+
## Props
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
interface PointerProps {
|
|
14
|
+
readonly event: PointerEvent | null;
|
|
15
|
+
readonly isDown: boolean;
|
|
16
|
+
readonly x: number;
|
|
17
|
+
readonly y: number;
|
|
18
|
+
readonly deltaX: number;
|
|
19
|
+
readonly deltaY: number;
|
|
20
|
+
readonly maxX: number;
|
|
21
|
+
readonly maxY: number;
|
|
22
|
+
readonly progressX: number;
|
|
23
|
+
readonly progressY: number;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface ElementPointerProps extends PointerProps {
|
|
27
|
+
readonly relativeX: number;
|
|
28
|
+
readonly relativeY: number;
|
|
29
|
+
readonly relativeProgressX: number;
|
|
30
|
+
readonly relativeProgressY: number;
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
`isGrabbing` is removed. `usePointer()` uses **pointer events only** and follows one `pointerId` at a time.
|
|
35
|
+
|
|
36
|
+
## Usage
|
|
37
|
+
|
|
38
|
+
```js
|
|
39
|
+
import { Base, usePointer } from '@studiometa/js-toolkit';
|
|
40
|
+
|
|
41
|
+
class Cursor extends Base {
|
|
42
|
+
static config = { name: 'Cursor' };
|
|
43
|
+
|
|
44
|
+
mounted() {
|
|
45
|
+
return usePointer().subscribe(({ x, y }) => {
|
|
46
|
+
this.$el.style.transform = `translate(${x}px, ${y}px)`;
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## The pointer in a box
|
|
53
|
+
|
|
54
|
+
`usePointer(el)` is one lazy service per target, and its props add the four `relative*` fields beside the viewport ones:
|
|
55
|
+
|
|
56
|
+
```js
|
|
57
|
+
import { Base, usePointer } from '@studiometa/js-toolkit';
|
|
58
|
+
|
|
59
|
+
class Tilt extends Base {
|
|
60
|
+
static config = { name: 'Tilt' };
|
|
61
|
+
|
|
62
|
+
mounted() {
|
|
63
|
+
return usePointer(this.$el).subscribe(({ relativeProgressX, relativeProgressY }) => {
|
|
64
|
+
this.$el.style.setProperty('--tilt-x', String(relativeProgressX * 2 - 1));
|
|
65
|
+
this.$el.style.setProperty('--tilt-y', String(relativeProgressY * 2 - 1));
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
**The targeted service subscribes to the singleton**, so one set of document listeners serves every target however many boxes are being watched.
|
|
72
|
+
|
|
73
|
+
## When the box is measured
|
|
74
|
+
|
|
75
|
+
On demand, and kept until a `scroll` (captured at the document), a `resize`, or the target's `ResizeObserver` can have moved it.
|
|
76
|
+
|
|
77
|
+
**The layout box is the frame of reference**, so a transform the consumer applies from its own callback does not invalidate it — which is exactly what a tilt or a parallax needs.
|
|
78
|
+
|
|
79
|
+
## `{ immediate: true }`
|
|
80
|
+
|
|
81
|
+
Does nothing before the pointer has been seen: there is no current value to deliver, which is what `hasProps()` says.
|
|
82
|
+
|
|
83
|
+
## Mixin
|
|
84
|
+
|
|
85
|
+
```js
|
|
86
|
+
class Tilt extends withPointer(Base) {
|
|
87
|
+
moved({ relativeProgressX }) {}
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
`withPointer` defaults its target to `$el`.
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# usePrefersReducedMotion
|
|
2
|
+
|
|
3
|
+
```ts
|
|
4
|
+
usePrefersReducedMotion(): Service<{ readonly matches: boolean }>
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
`(prefers-reduced-motion: reduce)` as a named service.
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
```js
|
|
12
|
+
import { Base, usePrefersReducedMotion } from '@studiometa/js-toolkit';
|
|
13
|
+
|
|
14
|
+
class Carousel extends Base {
|
|
15
|
+
static config = { name: 'Carousel' };
|
|
16
|
+
|
|
17
|
+
mounted() {
|
|
18
|
+
return usePrefersReducedMotion().subscribe(({ matches }) => {
|
|
19
|
+
matches ? this.stopAutoplay() : this.startAutoplay();
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
startAutoplay() {}
|
|
24
|
+
stopAutoplay() {}
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Why it is a service and not a read
|
|
29
|
+
|
|
30
|
+
**The preference changes while the page is open.** A read at load time is a snapshot that goes stale, and the user who turns reduced motion on mid-visit is exactly the user who most wants it honoured.
|
|
31
|
+
|
|
32
|
+
`props()` answers with no subscription, like every [`useMediaQuery()`](useMediaQuery.md) instance — so a one-off check is still one line. Subscribe when the component should follow the change.
|
|
33
|
+
|
|
34
|
+
## Mounting on the preference instead
|
|
35
|
+
|
|
36
|
+
To decide whether a component exists at all, use the mount strategy:
|
|
37
|
+
|
|
38
|
+
```html
|
|
39
|
+
<div data-component="Parallax" data-mount="media:(prefers-reduced-motion: no-preference)"></div>
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
That strategy is **reversible**, so turning the preference on unmounts the component and turning it off mounts it again. `withMountWhenPrefersMotion` is deleted.
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# useRaf
|
|
2
|
+
|
|
3
|
+
```ts
|
|
4
|
+
useRaf(): Service<RafProps, void | RafRender>
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
The frame clock as a service. It has nothing to scope, so there is one instance.
|
|
8
|
+
|
|
9
|
+
## Props
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
interface RafProps {
|
|
13
|
+
readonly time: DOMHighResTimeStamp;
|
|
14
|
+
readonly delta: number;
|
|
15
|
+
}
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
`delta` is clamped to `[1, 40]` ms, and the first tick after the loop wakes reports `1000/60`. `time` stays the raw rAF timestamp.
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
```js
|
|
23
|
+
import { Base, useRaf } from '@studiometa/js-toolkit';
|
|
24
|
+
|
|
25
|
+
class Ticker extends Base {
|
|
26
|
+
static config = { name: 'Ticker' };
|
|
27
|
+
|
|
28
|
+
mounted() {
|
|
29
|
+
return useRaf().subscribe(({ delta }) => {
|
|
30
|
+
// …
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## A callback can return a render function
|
|
37
|
+
|
|
38
|
+
`useRaf` is the one service whose callback return value is used. Return a function and it runs in the frame's `write` phase:
|
|
39
|
+
|
|
40
|
+
```js
|
|
41
|
+
import { Base, useRaf } from '@studiometa/js-toolkit';
|
|
42
|
+
|
|
43
|
+
class Follower extends Base {
|
|
44
|
+
static config = { name: 'Follower' };
|
|
45
|
+
|
|
46
|
+
mounted() {
|
|
47
|
+
return useRaf().subscribe(({ delta }) => {
|
|
48
|
+
const x = this.$el.offsetLeft + delta;
|
|
49
|
+
return () => {
|
|
50
|
+
this.$el.style.transform = `translateX(${x}px)`;
|
|
51
|
+
};
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
The service collects the render functions of its callbacks and **cancels a render whose subscriber left between the two phases**.
|
|
58
|
+
|
|
59
|
+
## It does not own a loop
|
|
60
|
+
|
|
61
|
+
It subscribes to `scheduler.tick()`. The scheduler requests the next frame while a tick subscriber stays, so there is no permanent rAF loop and no loop of the service's own.
|
|
62
|
+
|
|
63
|
+
`{ immediate: true }` does nothing here: the frame tick has **no current value between two frames**, which is what its `hasProps()` says.
|
|
64
|
+
|
|
65
|
+
## Switching it on and off
|
|
66
|
+
|
|
67
|
+
```js
|
|
68
|
+
import { Base, toggle, useRaf } from '@studiometa/js-toolkit';
|
|
69
|
+
|
|
70
|
+
class SliderItem extends Base {
|
|
71
|
+
static config = { name: 'SliderItem' };
|
|
72
|
+
|
|
73
|
+
#frame = toggle(() => useRaf().subscribe(({ delta }) => this.follow(delta)));
|
|
74
|
+
|
|
75
|
+
mounted() {
|
|
76
|
+
return this.#frame.stop;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
follow(delta) {}
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
See [`toggle()`](toggle.md), and `withRaf(Base, { manual: true })` in [Mixins](mixins.md).
|
|
84
|
+
|
|
85
|
+
## Mixin
|
|
86
|
+
|
|
87
|
+
```js
|
|
88
|
+
class Follower extends withRaf(Base) {
|
|
89
|
+
ticked({ delta }) {}
|
|
90
|
+
}
|
|
91
|
+
```
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# useResize
|
|
2
|
+
|
|
3
|
+
```ts
|
|
4
|
+
useResize(target?: Element): Service<ResizeProps>
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
The size of one element. With no target it is the document element, which reports the viewport.
|
|
8
|
+
|
|
9
|
+
## Props
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
interface ResizeProps {
|
|
13
|
+
readonly width: number;
|
|
14
|
+
readonly height: number;
|
|
15
|
+
readonly ratio: number;
|
|
16
|
+
readonly orientation: 'square' | 'landscape' | 'portrait';
|
|
17
|
+
}
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
`breakpoints` and `activeBreakpoints` are removed — [`useBreakpoint()`](useBreakpoint.md) is their own source now.
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
```js
|
|
25
|
+
import { Base, useResize } from '@studiometa/js-toolkit';
|
|
26
|
+
|
|
27
|
+
class Grid extends Base {
|
|
28
|
+
static config = { name: 'Grid' };
|
|
29
|
+
|
|
30
|
+
mounted() {
|
|
31
|
+
return useResize(this.$el).subscribe(({ width, orientation }) => {
|
|
32
|
+
this.$el.classList.toggle('is-narrow', width < 480);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## A `ResizeObserver` does not see the viewport
|
|
39
|
+
|
|
40
|
+
It reports the **box of the observed element**, which is what catches a zoom or a scrollbar. For the root element, `clientWidth` and `clientHeight` report the viewport and are decoupled from the observed box — so the viewport service keeps a `resize` listener as well.
|
|
41
|
+
|
|
42
|
+
That is why `useResize()` with no target and `useResize(someElement)` are not the same kind of measurement, even though they share a props shape.
|
|
43
|
+
|
|
44
|
+
## `{ immediate: true }` works here
|
|
45
|
+
|
|
46
|
+
An element has a current size between deliveries.
|
|
47
|
+
|
|
48
|
+
## Mixin
|
|
49
|
+
|
|
50
|
+
```js
|
|
51
|
+
class Grid extends withResize(Base) {
|
|
52
|
+
resized({ width }) {}
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
`withResize` defaults to the page-wide source, as `withScroll` does. Scope it with `{ target: (instance) => instance.$el }`.
|
|
57
|
+
|
|
58
|
+
## See also
|
|
59
|
+
|
|
60
|
+
[`useWindowSize()`](useWindowSize.md) — the named default case.
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# useScroll
|
|
2
|
+
|
|
3
|
+
```ts
|
|
4
|
+
useScroll(target?: Element | Window): Service<ScrollProps>
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
Scroll position, movement and direction for one scroller. With no target it is the document element; `useScroll(document.documentElement)` is the window service.
|
|
8
|
+
|
|
9
|
+
## Props
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
interface ScrollProps {
|
|
13
|
+
readonly x: number;
|
|
14
|
+
readonly y: number;
|
|
15
|
+
readonly deltaX: number;
|
|
16
|
+
readonly deltaY: number;
|
|
17
|
+
readonly maxX: number;
|
|
18
|
+
readonly maxY: number;
|
|
19
|
+
readonly progressX: number;
|
|
20
|
+
readonly progressY: number;
|
|
21
|
+
readonly directionX: -1 | 0 | 1;
|
|
22
|
+
readonly directionY: -1 | 0 | 1;
|
|
23
|
+
readonly isScrolling: boolean;
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Nothing derivable is a field: `lastX` is `x - deltaX`, and `changedX` is `deltaX !== 0`.
|
|
28
|
+
|
|
29
|
+
## Usage
|
|
30
|
+
|
|
31
|
+
```js
|
|
32
|
+
import { Base, useScroll } from '@studiometa/js-toolkit';
|
|
33
|
+
|
|
34
|
+
class Header extends Base {
|
|
35
|
+
static config = { name: 'Header' };
|
|
36
|
+
|
|
37
|
+
mounted() {
|
|
38
|
+
return useScroll().subscribe(({ y, directionY }) => {
|
|
39
|
+
this.$el.classList.toggle('is-hidden', directionY > 0 && y > 100);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
A region rather than the page:
|
|
46
|
+
|
|
47
|
+
```js
|
|
48
|
+
import { Base, useScroll } from '@studiometa/js-toolkit';
|
|
49
|
+
|
|
50
|
+
class Panel extends Base {
|
|
51
|
+
static config = { name: 'Panel', refs: ['scroller'] };
|
|
52
|
+
|
|
53
|
+
mounted() {
|
|
54
|
+
return useScroll(this.$refs.scroller).subscribe(({ progressY }) => {
|
|
55
|
+
this.$el.style.setProperty('--progress', String(progressY));
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## One `read` per frame
|
|
62
|
+
|
|
63
|
+
The service **coalesces its scroll events into one `read` per frame**, so a page scrolling at speed measures once per frame rather than once per event.
|
|
64
|
+
|
|
65
|
+
## Extents are observed, not sampled once
|
|
66
|
+
|
|
67
|
+
The service watches the scroller **and its element children** with a `ResizeObserver`, plus a `childList` MutationObserver to keep that set correct: `1 + n` observed boxes per scroller, lazy and released with the last subscriber.
|
|
68
|
+
|
|
69
|
+
That is what keeps `maxY` and `progressY` correct when content is added, removed or resized.
|
|
70
|
+
|
|
71
|
+
## `{ immediate: true }` works here
|
|
72
|
+
|
|
73
|
+
A scroller has a current position between deliveries, so the first delivery is honoured. The first props of a run carry **no movement**: the deltas are zero and `directionX`/`directionY` are `0`.
|
|
74
|
+
|
|
75
|
+
## Mixin
|
|
76
|
+
|
|
77
|
+
```js
|
|
78
|
+
class Header extends withScroll(Base) {
|
|
79
|
+
scrolled({ y, directionY }) {}
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
`withScroll` defaults to the page-wide source. A region is `withScroll(Base, { target: (instance) => instance.$refs.scroller })`.
|
|
84
|
+
|
|
85
|
+
## See also
|
|
86
|
+
|
|
87
|
+
- [`useWindowScroll()`](useWindowScroll.md) — the named default case
|
|
88
|
+
- [`useScrollProgress()`](useScrollProgress.md) — an element's progress through the viewport
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# useScrollProgress
|
|
2
|
+
|
|
3
|
+
```ts
|
|
4
|
+
useScrollProgress(target: Element, options?: { offset?: string }): Service<ScrollProgressProps>
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
An element's progress through the viewport as it scrolls.
|
|
8
|
+
|
|
9
|
+
## Props
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
interface ScrollProgressProps {
|
|
13
|
+
readonly startX: number;
|
|
14
|
+
readonly startY: number;
|
|
15
|
+
readonly endX: number;
|
|
16
|
+
readonly endY: number;
|
|
17
|
+
readonly currentX: number;
|
|
18
|
+
readonly currentY: number;
|
|
19
|
+
readonly progressX: number;
|
|
20
|
+
readonly progressY: number;
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
`start` and `end` are the scroll positions at which the progress is `0` and `1`; `current` is where the scroller is now.
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
```js
|
|
29
|
+
import { Base, useScrollProgress } from '@studiometa/js-toolkit';
|
|
30
|
+
|
|
31
|
+
class Parallax extends Base {
|
|
32
|
+
static config = { name: 'Parallax' };
|
|
33
|
+
|
|
34
|
+
mounted() {
|
|
35
|
+
return useScrollProgress(this.$el).subscribe(({ progressY }) => {
|
|
36
|
+
this.$el.style.setProperty('--progress', String(progressY));
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## The `offset` option
|
|
43
|
+
|
|
44
|
+
One string holding **two edge pairs**, separated by a `/`:
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
"<target> <viewport> / <target> <viewport>"
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
The first pair is where the progress is `0`, the second where it is `1`. In each pair, the first token is an edge of the **target** and the second an edge of the **viewport**.
|
|
51
|
+
|
|
52
|
+
The default is:
|
|
53
|
+
|
|
54
|
+
```js
|
|
55
|
+
useScrollProgress(el, { offset: 'start end / end start' });
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
which reads as "0 when the target's start meets the viewport's end, 1 when the target's end meets the viewport's start" — the element travelling the full height of the viewport.
|
|
59
|
+
|
|
60
|
+
Each token is one of:
|
|
61
|
+
|
|
62
|
+
| Token | Means |
|
|
63
|
+
| -------------------------------- | -------------------------------- |
|
|
64
|
+
| `start` | the leading edge |
|
|
65
|
+
| `center` | the middle |
|
|
66
|
+
| `end` | the trailing edge |
|
|
67
|
+
| `50%` | a fraction of the box |
|
|
68
|
+
| `120px` | an absolute offset from the edge |
|
|
69
|
+
| `20vh`, `10vw`, `5vmin`, `5vmax` | a viewport unit |
|
|
70
|
+
| a number | a fraction, as `0.5` |
|
|
71
|
+
|
|
72
|
+
A token that parses as nothing falls back to the edge.
|
|
73
|
+
|
|
74
|
+
The **resolved** offset is part of the service's key, so two callers asking for the same range on the same element share one service.
|
|
75
|
+
|
|
76
|
+
## Mixin
|
|
77
|
+
|
|
78
|
+
```js
|
|
79
|
+
class Parallax extends withScrollProgress(Base, { offset: 'center end / center start' }) {
|
|
80
|
+
scrolledInView({ progressY }) {}
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
The hook is named `scrolledInView`.
|
|
85
|
+
|
|
86
|
+
## Smoothing a progress value
|
|
87
|
+
|
|
88
|
+
Progress props carry no frame delta, and [`damp()`](../../utils/math.md) takes the elapsed time as a required argument — decay is expressed in time, not in frames. So either take the delta from a [`useRaf()`](useRaf.md) tick, or use [`smoothTo()`](../../utils/motion.md), which owns its own frame subscription and releases it when the value arrives.
|