@hkdigital/lib-core 0.3.1
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 +149 -0
- package/dist/assets/autospuiten/car-paint-picker/army-green.jpg +0 -0
- package/dist/assets/autospuiten/car-paint-picker/electric-blue.jpg +0 -0
- package/dist/assets/autospuiten/car-paint-picker/lemon-yellow.jpg +0 -0
- package/dist/assets/autospuiten/car-paint-picker/opaque-purple.jpg +0 -0
- package/dist/assets/autospuiten/car-paint-picker/rusty.jpg +0 -0
- package/dist/assets/autospuiten/car-paint-picker/sunset-orange.jpg +0 -0
- package/dist/assets/autospuiten/car-paint-picker/tomato-red.jpg +0 -0
- package/dist/assets/autospuiten/car-paint-picker.d.ts +17 -0
- package/dist/assets/autospuiten/car-paint-picker.js +41 -0
- package/dist/assets/autospuiten/labels.d.ts +7 -0
- package/dist/assets/autospuiten/labels.js +7 -0
- package/dist/classes/cache/IndexedDbCache.d.ts +216 -0
- package/dist/classes/cache/IndexedDbCache.js +1407 -0
- package/dist/classes/cache/MemoryResponseCache.d.ts +106 -0
- package/dist/classes/cache/MemoryResponseCache.js +138 -0
- package/dist/classes/cache/index.d.ts +3 -0
- package/dist/classes/cache/index.js +5 -0
- package/dist/classes/cache/typedef.d.ts +67 -0
- package/dist/classes/cache/typedef.js +41 -0
- package/dist/classes/data/IterableTree.d.ts +51 -0
- package/dist/classes/data/IterableTree.js +243 -0
- package/dist/classes/data/Selector.d.ts +30 -0
- package/dist/classes/data/Selector.js +190 -0
- package/dist/classes/data/index.d.ts +2 -0
- package/dist/classes/data/index.js +2 -0
- package/dist/classes/events/EventEmitter.d.ts +142 -0
- package/dist/classes/events/EventEmitter.js +275 -0
- package/dist/classes/events/index.d.ts +1 -0
- package/dist/classes/events/index.js +2 -0
- package/dist/classes/index.d.ts +4 -0
- package/dist/classes/index.js +4 -0
- package/dist/classes/logging/Logger.d.ts +78 -0
- package/dist/classes/logging/Logger.js +210 -0
- package/dist/classes/logging/constants.d.ts +12 -0
- package/dist/classes/logging/constants.js +16 -0
- package/dist/classes/logging/index.d.ts +2 -0
- package/dist/classes/logging/index.js +4 -0
- package/dist/classes/logging/typedef.d.ts +34 -0
- package/dist/classes/logging/typedef.js +17 -0
- package/dist/classes/promise/HkPromise.d.ts +121 -0
- package/dist/classes/promise/HkPromise.js +377 -0
- package/dist/classes/promise/index.d.ts +1 -0
- package/dist/classes/promise/index.js +1 -0
- package/dist/classes/services/ServiceBase.d.ts +163 -0
- package/dist/classes/services/ServiceBase.js +463 -0
- package/dist/classes/services/ServiceManager.d.ts +179 -0
- package/dist/classes/services/ServiceManager.js +614 -0
- package/dist/classes/services/index.d.ts +4 -0
- package/dist/classes/services/index.js +5 -0
- package/dist/classes/services/service-states.d.ts +159 -0
- package/dist/classes/services/service-states.js +205 -0
- package/dist/classes/services/typedef.d.ts +247 -0
- package/dist/classes/services/typedef.js +179 -0
- package/dist/classes/stores/SubscribersCount.d.ts +39 -0
- package/dist/classes/stores/SubscribersCount.js +107 -0
- package/dist/classes/stores/index.d.ts +1 -0
- package/dist/classes/stores/index.js +1 -0
- package/dist/classes/streams/LogTransformStream.d.ts +4 -0
- package/dist/classes/streams/LogTransformStream.js +19 -0
- package/dist/classes/streams/ServerEventsStore.d.ts +22 -0
- package/dist/classes/streams/ServerEventsStore.js +110 -0
- package/dist/classes/streams/TimeStampSource.d.ts +13 -0
- package/dist/classes/streams/TimeStampSource.js +26 -0
- package/dist/classes/streams/index.d.ts +3 -0
- package/dist/classes/streams/index.js +3 -0
- package/dist/classes/svelte/audio/AudioLoader.svelte.d.ts +30 -0
- package/dist/classes/svelte/audio/AudioLoader.svelte.js +58 -0
- package/dist/classes/svelte/audio/AudioScene.svelte.d.ts +74 -0
- package/dist/classes/svelte/audio/AudioScene.svelte.js +324 -0
- package/dist/classes/svelte/audio/mocks.d.ts +7 -0
- package/dist/classes/svelte/audio/mocks.js +35 -0
- package/dist/classes/svelte/finite-state-machine/FiniteStateMachine.svelte.d.ts +50 -0
- package/dist/classes/svelte/finite-state-machine/FiniteStateMachine.svelte.js +133 -0
- package/dist/classes/svelte/finite-state-machine/index.d.ts +1 -0
- package/dist/classes/svelte/finite-state-machine/index.js +1 -0
- package/dist/classes/svelte/image/ImageLoader.svelte.d.ts +19 -0
- package/dist/classes/svelte/image/ImageLoader.svelte.js +45 -0
- package/dist/classes/svelte/image/ImageScene.svelte.d.ts +78 -0
- package/dist/classes/svelte/image/ImageScene.svelte.js +249 -0
- package/dist/classes/svelte/image/ImageVariantsLoader.svelte.d.ts +43 -0
- package/dist/classes/svelte/image/ImageVariantsLoader.svelte.js +152 -0
- package/dist/classes/svelte/image/index.d.ts +2 -0
- package/dist/classes/svelte/image/index.js +4 -0
- package/dist/classes/svelte/image/mocks.d.ts +7 -0
- package/dist/classes/svelte/image/mocks.js +35 -0
- package/dist/classes/svelte/image/typedef.d.ts +16 -0
- package/dist/classes/svelte/image/typedef.js +8 -0
- package/dist/classes/svelte/index.d.ts +9 -0
- package/dist/classes/svelte/index.js +14 -0
- package/dist/classes/svelte/loading-state-machine/LoadingStateMachine.svelte.d.ts +12 -0
- package/dist/classes/svelte/loading-state-machine/LoadingStateMachine.svelte.js +109 -0
- package/dist/classes/svelte/loading-state-machine/constants.d.ts +12 -0
- package/dist/classes/svelte/loading-state-machine/constants.js +16 -0
- package/dist/classes/svelte/loading-state-machine/index.d.ts +2 -0
- package/dist/classes/svelte/loading-state-machine/index.js +3 -0
- package/dist/classes/svelte/network-loader/NetworkLoader.svelte.d.ts +91 -0
- package/dist/classes/svelte/network-loader/NetworkLoader.svelte.js +338 -0
- package/dist/classes/svelte/network-loader/constants.d.ts +2 -0
- package/dist/classes/svelte/network-loader/constants.js +3 -0
- package/dist/classes/svelte/network-loader/index.d.ts +2 -0
- package/dist/classes/svelte/network-loader/index.js +3 -0
- package/dist/classes/svelte/network-loader/mocks.d.ts +7 -0
- package/dist/classes/svelte/network-loader/mocks.js +30 -0
- package/dist/classes/svelte/network-loader/typedef.d.ts +7 -0
- package/dist/classes/svelte/network-loader/typedef.js +8 -0
- package/dist/components/area/HkArea.svelte +49 -0
- package/dist/components/area/HkArea.svelte.d.ts +26 -0
- package/dist/components/area/HkGridArea.svelte +77 -0
- package/dist/components/area/HkGridArea.svelte.d.ts +42 -0
- package/dist/components/area/index.d.ts +2 -0
- package/dist/components/area/index.js +2 -0
- package/dist/components/buttons/button/Button.svelte +82 -0
- package/dist/components/buttons/button/Button.svelte.d.ts +44 -0
- package/dist/components/buttons/button-icon-steeze/SteezeIconButton.svelte +30 -0
- package/dist/components/buttons/button-icon-steeze/SteezeIconButton.svelte.d.ts +16 -0
- package/dist/components/buttons/button-text/TextButton.svelte +21 -0
- package/dist/components/buttons/button-text/TextButton.svelte.d.ts +12 -0
- package/dist/components/buttons/index.d.ts +3 -0
- package/dist/components/buttons/index.js +3 -0
- package/dist/components/debug/debug-panel-design-scaling/DebugPanelDesignScaling.svelte +146 -0
- package/dist/components/debug/debug-panel-design-scaling/DebugPanelDesignScaling.svelte.d.ts +6 -0
- package/dist/components/debug/index.d.ts +1 -0
- package/dist/components/debug/index.js +1 -0
- package/dist/components/drag-drop/DragController.d.ts +20 -0
- package/dist/components/drag-drop/DragController.js +44 -0
- package/dist/components/drag-drop/DragDropContext.svelte +111 -0
- package/dist/components/drag-drop/DragDropContext.svelte.d.ts +18 -0
- package/dist/components/drag-drop/Draggable.svelte +519 -0
- package/dist/components/drag-drop/Draggable.svelte.d.ts +95 -0
- package/dist/components/drag-drop/DropZone.svelte +258 -0
- package/dist/components/drag-drop/DropZone.svelte.d.ts +96 -0
- package/dist/components/drag-drop/DropZoneArea.svelte +119 -0
- package/dist/components/drag-drop/DropZoneArea.svelte.d.ts +90 -0
- package/dist/components/drag-drop/DropZoneList.svelte +125 -0
- package/dist/components/drag-drop/DropZoneList.svelte.d.ts +92 -0
- package/dist/components/drag-drop/actions.d.ts +9 -0
- package/dist/components/drag-drop/actions.js +26 -0
- package/dist/components/drag-drop/drag-state.svelte.d.ts +97 -0
- package/dist/components/drag-drop/drag-state.svelte.js +322 -0
- package/dist/components/drag-drop/index.d.ts +6 -0
- package/dist/components/drag-drop/index.js +7 -0
- package/dist/components/drag-drop/util.d.ts +0 -0
- package/dist/components/drag-drop/util.js +85 -0
- package/dist/components/hkdev/blocks/TextBlock.svelte +47 -0
- package/dist/components/hkdev/blocks/TextBlock.svelte.d.ts +24 -0
- package/dist/components/hkdev/buttons/CheckButton.svelte +63 -0
- package/dist/components/hkdev/buttons/CheckButton.svelte.d.ts +34 -0
- package/dist/components/icons/HkIcon.svelte +86 -0
- package/dist/components/icons/HkIcon.svelte.d.ts +22 -0
- package/dist/components/icons/HkTabIcon.svelte +116 -0
- package/dist/components/icons/HkTabIcon.svelte.d.ts +40 -0
- package/dist/components/icons/SteezeIcon.svelte +97 -0
- package/dist/components/icons/SteezeIcon.svelte.d.ts +22 -0
- package/dist/components/icons/index.d.ts +4 -0
- package/dist/components/icons/index.js +6 -0
- package/dist/components/icons/typedef.d.ts +13 -0
- package/dist/components/icons/typedef.js +16 -0
- package/dist/components/index.d.ts +0 -0
- package/dist/components/index.js +2 -0
- package/dist/components/inputs/index.d.ts +1 -0
- package/dist/components/inputs/index.js +1 -0
- package/dist/components/inputs/text-input/TestTextInput.svelte__ +102 -0
- package/dist/components/inputs/text-input/TextInput.svelte +223 -0
- package/dist/components/inputs/text-input/TextInput.svelte.d.ts +56 -0
- package/dist/components/inputs/text-input/TextInput.svelte___ +83 -0
- package/dist/components/inputs/text-input/assets/IconInvalid.svelte +14 -0
- package/dist/components/inputs/text-input/assets/IconInvalid.svelte.d.ts +26 -0
- package/dist/components/inputs/text-input/assets/IconValid.svelte +12 -0
- package/dist/components/inputs/text-input/assets/IconValid.svelte.d.ts +26 -0
- package/dist/components/layout/grid-layers/GridLayers.svelte +63 -0
- package/dist/components/layout/grid-layers/GridLayers.svelte.d.ts +26 -0
- package/dist/components/layout/grid-layers/GridLayers.svelte__heightFrom__ +372 -0
- package/dist/components/layout/grid-layers/util.d.ts +19 -0
- package/dist/components/layout/grid-layers/util.js +74 -0
- package/dist/components/layout/index.d.ts +1 -0
- package/dist/components/layout/index.js +1 -0
- package/dist/components/panels/index.d.ts +1 -0
- package/dist/components/panels/index.js +1 -0
- package/dist/components/panels/panel/Panel.svelte +43 -0
- package/dist/components/panels/panel/Panel.svelte.d.ts +24 -0
- package/dist/components/rows/index.d.ts +2 -0
- package/dist/components/rows/index.js +3 -0
- package/dist/components/rows/panel-grid-row/PanelGridRow.svelte +104 -0
- package/dist/components/rows/panel-grid-row/PanelGridRow.svelte.d.ts +26 -0
- package/dist/components/rows/panel-row-2/PanelRow2.svelte +40 -0
- package/dist/components/rows/panel-row-2/PanelRow2.svelte.d.ts +26 -0
- package/dist/components/tab-bar/HkTabBar.state.svelte.d.ts +54 -0
- package/dist/components/tab-bar/HkTabBar.state.svelte.js +149 -0
- package/dist/components/tab-bar/HkTabBar.svelte +74 -0
- package/dist/components/tab-bar/HkTabBar.svelte.d.ts +34 -0
- package/dist/components/tab-bar/HkTabBarSelector.state.svelte.d.ts +19 -0
- package/dist/components/tab-bar/HkTabBarSelector.state.svelte.js +93 -0
- package/dist/components/tab-bar/HkTabBarSelector.svelte +49 -0
- package/dist/components/tab-bar/HkTabBarSelector.svelte.d.ts +36 -0
- package/dist/components/tab-bar/index.d.ts +5 -0
- package/dist/components/tab-bar/index.js +17 -0
- package/dist/components/tab-bar/typedef.d.ts +8 -0
- package/dist/components/tab-bar/typedef.js +11 -0
- package/dist/config/imagetools-config.d.ts +26 -0
- package/dist/config/imagetools-config.js +189 -0
- package/dist/config/imagetools.d.ts +72 -0
- package/dist/constants/bases.d.ts +10 -0
- package/dist/constants/bases.js +13 -0
- package/dist/constants/errors/api.d.ts +10 -0
- package/dist/constants/errors/api.js +9 -0
- package/dist/constants/errors/generic.d.ts +20 -0
- package/dist/constants/errors/generic.js +20 -0
- package/dist/constants/errors/http.d.ts +16 -0
- package/dist/constants/errors/http.js +16 -0
- package/dist/constants/errors/index.d.ts +4 -0
- package/dist/constants/errors/index.js +4 -0
- package/dist/constants/errors/jwt.d.ts +8 -0
- package/dist/constants/errors/jwt.js +5 -0
- package/dist/constants/http/headers.d.ts +5 -0
- package/dist/constants/http/headers.js +6 -0
- package/dist/constants/http/index.d.ts +2 -0
- package/dist/constants/http/index.js +2 -0
- package/dist/constants/http/methods.d.ts +7 -0
- package/dist/constants/http/methods.js +14 -0
- package/dist/constants/index.d.ts +2 -0
- package/dist/constants/index.js +3 -0
- package/dist/constants/mime/application.d.ts +3 -0
- package/dist/constants/mime/application.js +5 -0
- package/dist/constants/mime/audio.d.ts +10 -0
- package/dist/constants/mime/audio.js +13 -0
- package/dist/constants/mime/image.d.ts +3 -0
- package/dist/constants/mime/image.js +3 -0
- package/dist/constants/mime/index.d.ts +4 -0
- package/dist/constants/mime/index.js +4 -0
- package/dist/constants/mime/text.d.ts +2 -0
- package/dist/constants/mime/text.js +2 -0
- package/dist/constants/regexp/index.d.ts +3 -0
- package/dist/constants/regexp/index.js +31 -0
- package/dist/constants/regexp/inspiratie.js__ +95 -0
- package/dist/constants/regexp/text.d.ts +47 -0
- package/dist/constants/regexp/text.js +49 -0
- package/dist/constants/regexp/user.d.ts +6 -0
- package/dist/constants/regexp/user.js +33 -0
- package/dist/constants/regexp/web.d.ts +1 -0
- package/dist/constants/regexp/web.js +3 -0
- package/dist/constants/state-labels/drag-states.d.ts +5 -0
- package/dist/constants/state-labels/drag-states.js +6 -0
- package/dist/constants/state-labels/drop-states.d.ts +4 -0
- package/dist/constants/state-labels/drop-states.js +6 -0
- package/dist/constants/state-labels/input-states.d.ts +8 -0
- package/dist/constants/state-labels/input-states.js +11 -0
- package/dist/constants/state-labels/submit-states.d.ts +4 -0
- package/dist/constants/state-labels/submit-states.js +4 -0
- package/dist/constants/time.d.ts +18 -0
- package/dist/constants/time.js +28 -0
- package/dist/css/utilities.css +43 -0
- package/dist/design/design-config.d.ts +157 -0
- package/dist/design/design-config.js +73 -0
- package/dist/design/tailwind-theme-extend.d.ts +23 -0
- package/dist/design/tailwind-theme-extend.js +158 -0
- package/dist/features/button-group/ButtonGroup.svelte +82 -0
- package/dist/features/button-group/ButtonGroup.svelte.d.ts +34 -0
- package/dist/features/button-group/typedef.d.ts +7 -0
- package/dist/features/button-group/typedef.js +10 -0
- package/dist/features/compare-left-right/CompareLeftRight.svelte +179 -0
- package/dist/features/compare-left-right/CompareLeftRight.svelte.d.ts +18 -0
- package/dist/features/compare-left-right/index.d.ts +1 -0
- package/dist/features/compare-left-right/index.js +1 -0
- package/dist/features/game-box/GameBox.svelte +577 -0
- package/dist/features/game-box/GameBox.svelte.d.ts +140 -0
- package/dist/features/game-box/gamebox.util.d.ts +32 -0
- package/dist/features/game-box/gamebox.util.js +83 -0
- package/dist/features/hk-app-layout/HkAppLayout.state.svelte.d.ts +6 -0
- package/dist/features/hk-app-layout/HkAppLayout.state.svelte.js +25 -0
- package/dist/features/hk-app-layout/HkAppLayout.svelte +251 -0
- package/dist/features/hk-app-layout/HkAppLayout.svelte.d.ts +19 -0
- package/dist/features/image-box/ImageBox.svelte +210 -0
- package/dist/features/image-box/ImageBox.svelte.d.ts +38 -0
- package/dist/features/image-box/index.d.ts +4 -0
- package/dist/features/image-box/index.js +5 -0
- package/dist/features/image-box/typedef.d.ts +4 -0
- package/dist/features/image-box/typedef.js +32 -0
- package/dist/features/index.d.ts +11 -0
- package/dist/features/index.js +23 -0
- package/dist/features/presenter/ImageSlide.svelte +64 -0
- package/dist/features/presenter/ImageSlide.svelte.d.ts +36 -0
- package/dist/features/presenter/Presenter.state.svelte.d.ts +74 -0
- package/dist/features/presenter/Presenter.state.svelte.js +638 -0
- package/dist/features/presenter/Presenter.svelte +142 -0
- package/dist/features/presenter/Presenter.svelte.d.ts +18 -0
- package/dist/features/presenter/constants.d.ts +5 -0
- package/dist/features/presenter/constants.js +7 -0
- package/dist/features/presenter/index.d.ts +6 -0
- package/dist/features/presenter/index.js +10 -0
- package/dist/features/presenter/typedef.d.ts +92 -0
- package/dist/features/presenter/typedef.js +106 -0
- package/dist/features/presenter/util.d.ts +63 -0
- package/dist/features/presenter/util.js +210 -0
- package/dist/features/virtual-viewport/VirtualViewport.svelte +196 -0
- package/dist/features/virtual-viewport/VirtualViewport.svelte.d.ts +42 -0
- package/dist/index.d.ts +0 -0
- package/dist/index.js +0 -0
- package/dist/logging/adapters/console.d.ts +48 -0
- package/dist/logging/adapters/console.js +114 -0
- package/dist/logging/adapters/pino.d.ts +25 -0
- package/dist/logging/adapters/pino.js +60 -0
- package/dist/logging/constants.d.ts +1 -0
- package/dist/logging/constants.js +1 -0
- package/dist/logging/factories/client.d.ts +10 -0
- package/dist/logging/factories/client.js +21 -0
- package/dist/logging/factories/server.d.ts +10 -0
- package/dist/logging/factories/server.js +22 -0
- package/dist/logging/factories/universal.d.ts +9 -0
- package/dist/logging/factories/universal.js +23 -0
- package/dist/logging/index.d.ts +5 -0
- package/dist/logging/index.js +8 -0
- package/dist/schemas/index.d.ts +1 -0
- package/dist/schemas/index.js +1 -0
- package/dist/schemas/validate-url.d.ts +30 -0
- package/dist/schemas/validate-url.js +180 -0
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js +1 -0
- package/dist/server/logger.d.ts +25 -0
- package/dist/server/logger.js +94 -0
- package/dist/states/index.d.ts +1 -0
- package/dist/states/index.js +1 -0
- package/dist/states/navigation.svelte.d.ts +23 -0
- package/dist/states/navigation.svelte.js +55 -0
- package/dist/stores/index.d.ts +1 -0
- package/dist/stores/index.js +1 -0
- package/dist/stores/theme.d.ts +28 -0
- package/dist/stores/theme.js +80 -0
- package/dist/themes/hkdev/components/blocks/text-block.css +34 -0
- package/dist/themes/hkdev/components/boxes/game-box.css +11 -0
- package/dist/themes/hkdev/components/buttons/button-icon-steeze.css +22 -0
- package/dist/themes/hkdev/components/buttons/button-text.css +32 -0
- package/dist/themes/hkdev/components/buttons/button.css +146 -0
- package/dist/themes/hkdev/components/buttons/skip-button.css +5 -0
- package/dist/themes/hkdev/components/drag-drop/draggable.css +73 -0
- package/dist/themes/hkdev/components/drag-drop/drop-zone.css +58 -0
- package/dist/themes/hkdev/components/icons/icon-steeze.css +16 -0
- package/dist/themes/hkdev/components/inputs/text-input.css +102 -0
- package/dist/themes/hkdev/components/panels/panel.css +25 -0
- package/dist/themes/hkdev/components/rows/panel-grid-row.css +4 -0
- package/dist/themes/hkdev/components/rows/panel-row-2.css +5 -0
- package/dist/themes/hkdev/components.css +29 -0
- package/dist/themes/hkdev/debug.css +2 -0
- package/dist/themes/hkdev/global/layout.css +32 -0
- package/dist/themes/hkdev/global/on-colors.css +32 -0
- package/dist/themes/hkdev/globals.css +4 -0
- package/dist/themes/hkdev/responsive.css +12 -0
- package/dist/themes/hkdev/theme-ext.d.ts +4 -0
- package/dist/themes/hkdev/theme-ext.js +12 -0
- package/dist/themes/hkdev/theme.css +219 -0
- package/dist/themes/index.d.ts +1 -0
- package/dist/themes/index.js +1 -0
- package/dist/typedef/context.d.ts +3 -0
- package/dist/typedef/context.js +6 -0
- package/dist/typedef/drag.d.ts +29 -0
- package/dist/typedef/drag.js +25 -0
- package/dist/typedef/drop.d.ts +15 -0
- package/dist/typedef/drop.js +12 -0
- package/dist/typedef/image.d.ts +12 -0
- package/dist/typedef/image.js +38 -0
- package/dist/typedef/index.d.ts +4 -0
- package/dist/typedef/index.js +4 -0
- package/dist/util/array/index.d.ts +183 -0
- package/dist/util/array/index.js +436 -0
- package/dist/util/bases/base58.d.ts +58 -0
- package/dist/util/bases/base58.js +262 -0
- package/dist/util/bases/index.d.ts +1 -0
- package/dist/util/bases/index.js +1 -0
- package/dist/util/compare/index.d.ts +68 -0
- package/dist/util/compare/index.js +247 -0
- package/dist/util/css/css-vars.d.ts +24 -0
- package/dist/util/css/css-vars.js +83 -0
- package/dist/util/css/index.d.ts +1 -0
- package/dist/util/css/index.js +1 -0
- package/dist/util/design-system/components/states.d.ts +15 -0
- package/dist/util/design-system/components/states.js +22 -0
- package/dist/util/design-system/css/clamp.d.ts +17 -0
- package/dist/util/design-system/css/clamp.js +66 -0
- package/dist/util/design-system/css/root-design-vars.d.ts +77 -0
- package/dist/util/design-system/css/root-design-vars.js +102 -0
- package/dist/util/design-system/index.d.ts +5 -0
- package/dist/util/design-system/index.js +5 -0
- package/dist/util/design-system/layout/scaling.d.ts +98 -0
- package/dist/util/design-system/layout/scaling.js +228 -0
- package/dist/util/design-system/skeleton.d.ts +41 -0
- package/dist/util/design-system/skeleton.js +208 -0
- package/dist/util/design-system/tailwind.d.ts +183 -0
- package/dist/util/design-system/tailwind.js +288 -0
- package/dist/util/env/index.d.ts +1 -0
- package/dist/util/env/index.js +9 -0
- package/dist/util/exceptions/index.d.ts +15 -0
- package/dist/util/exceptions/index.js +23 -0
- package/dist/util/expect/arrays.d.ts +30 -0
- package/dist/util/expect/arrays.js +47 -0
- package/dist/util/expect/index.d.ts +103 -0
- package/dist/util/expect/index.js +259 -0
- package/dist/util/expect/primitives.d.ts +30 -0
- package/dist/util/expect/primitives.js +55 -0
- package/dist/util/expect/url.d.ts +32 -0
- package/dist/util/expect/url.js +60 -0
- package/dist/util/function/index.d.ts +34 -0
- package/dist/util/function/index.js +218 -0
- package/dist/util/geo/index.d.ts +10 -0
- package/dist/util/geo/index.js +26 -0
- package/dist/util/http/caching.d.ts +28 -0
- package/dist/util/http/caching.js +263 -0
- package/dist/util/http/errors.d.ts +18 -0
- package/dist/util/http/errors.js +97 -0
- package/dist/util/http/headers.d.ts +40 -0
- package/dist/util/http/headers.js +75 -0
- package/dist/util/http/http-request.d.ts +267 -0
- package/dist/util/http/http-request.js +578 -0
- package/dist/util/http/index.d.ts +6 -0
- package/dist/util/http/index.js +22 -0
- package/dist/util/http/json-request.d.ts +84 -0
- package/dist/util/http/json-request.js +224 -0
- package/dist/util/http/mocks.d.ts +20 -0
- package/dist/util/http/mocks.js +65 -0
- package/dist/util/http/response.d.ts +125 -0
- package/dist/util/http/response.js +294 -0
- package/dist/util/http/test-data__/content-length-test-hkdigital-small.V4HfZyBQ.avif +0 -0
- package/dist/util/http/typedef.d.ts +184 -0
- package/dist/util/http/typedef.js +93 -0
- package/dist/util/http/url.d.ts +25 -0
- package/dist/util/http/url.js +52 -0
- package/dist/util/image/index.d.ts +25 -0
- package/dist/util/image/index.js +86 -0
- package/dist/util/index.d.ts +3 -0
- package/dist/util/index.js +3 -0
- package/dist/util/is/index.d.ts +68 -0
- package/dist/util/is/index.js +140 -0
- package/dist/util/iterate/index.d.ts +131 -0
- package/dist/util/iterate/index.js +234 -0
- package/dist/util/object/index.d.ts +326 -0
- package/dist/util/object/index.js +1361 -0
- package/dist/util/singleton/index.d.ts +34 -0
- package/dist/util/singleton/index.js +97 -0
- package/dist/util/string/array-path.d.ts +15 -0
- package/dist/util/string/array-path.js +75 -0
- package/dist/util/string/convert.d.ts +22 -0
- package/dist/util/string/convert.js +54 -0
- package/dist/util/string/fs.d.ts +55 -0
- package/dist/util/string/fs.js +226 -0
- package/dist/util/string/index.d.ts +5 -0
- package/dist/util/string/index.js +5 -0
- package/dist/util/string/interpolate.d.ts +22 -0
- package/dist/util/string/interpolate.js +61 -0
- package/dist/util/string/pad.d.ts +8 -0
- package/dist/util/string/pad.js +10 -0
- package/dist/util/svelte/index.d.ts +3 -0
- package/dist/util/svelte/index.js +4 -0
- package/dist/util/svelte/loading/loading-tracker.svelte.d.ts +31 -0
- package/dist/util/svelte/loading/loading-tracker.svelte.js +108 -0
- package/dist/util/svelte/observe/index.d.ts +10 -0
- package/dist/util/svelte/observe/index.js +49 -0
- package/dist/util/svelte/state-context/index.d.ts +18 -0
- package/dist/util/svelte/state-context/index.js +117 -0
- package/dist/util/svelte/wait/index.d.ts +15 -0
- package/dist/util/svelte/wait/index.js +38 -0
- package/dist/util/sveltekit/index.d.ts +1 -0
- package/dist/util/sveltekit/index.js +1 -0
- package/dist/util/sveltekit/route-folders/index.d.ts +28 -0
- package/dist/util/sveltekit/route-folders/index.js +101 -0
- package/dist/util/time/index.d.ts +108 -0
- package/dist/util/time/index.js +323 -0
- package/dist/util/unique/index.d.ts +81 -0
- package/dist/util/unique/index.js +249 -0
- package/dist/valibot/date.js__ +10 -0
- package/dist/valibot/index.d.ts +4 -0
- package/dist/valibot/index.js +9 -0
- package/dist/valibot/url.d.ts +26 -0
- package/dist/valibot/url.js +95 -0
- package/dist/valibot/user.d.ts +6 -0
- package/dist/valibot/user.js +23 -0
- package/dist/zod/all.d.ts +6 -0
- package/dist/zod/all.js +33 -0
- package/dist/zod/generic.d.ts +6 -0
- package/dist/zod/generic.js +11 -0
- package/dist/zod/javascript.d.ts +8 -0
- package/dist/zod/javascript.js +32 -0
- package/dist/zod/user.d.ts +9 -0
- package/dist/zod/user.js +16 -0
- package/dist/zod/web.d.ts +21 -0
- package/dist/zod/web.js +52 -0
- package/package.json +133 -0
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* function.js
|
|
3
|
+
*
|
|
4
|
+
* @description
|
|
5
|
+
* This file contains code for working with functions
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
*
|
|
9
|
+
* import { once } from "./function.js";
|
|
10
|
+
*
|
|
11
|
+
* const sayHelloOnce = once( () => { console.log("Hello"); } );
|
|
12
|
+
*
|
|
13
|
+
* sayHelloOnce();
|
|
14
|
+
* sayHelloOnce();
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
*
|
|
18
|
+
* import { defer } from './process.js';
|
|
19
|
+
*
|
|
20
|
+
* defer( () => {
|
|
21
|
+
* console.log("The execution of the function has been defered");
|
|
22
|
+
* } );
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/* ------------------------------------------------------------------ Imports */
|
|
26
|
+
|
|
27
|
+
import * as expect from '../expect/index.js';
|
|
28
|
+
|
|
29
|
+
/* ---------------------------------------------------------------- Internals */
|
|
30
|
+
|
|
31
|
+
const NEXT_TICK_MESSAGE = 'hk-next-tick';
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Detect and return the most suitable setImmediate implementation available
|
|
35
|
+
* on the current platform
|
|
36
|
+
*/
|
|
37
|
+
function set_immediate_implementation() {
|
|
38
|
+
if (typeof global !== 'undefined') {
|
|
39
|
+
if (undefined !== global.setImmediate) {
|
|
40
|
+
return global.setImmediate;
|
|
41
|
+
}
|
|
42
|
+
} else if (typeof window !== 'undefined') {
|
|
43
|
+
if (window.postMessage && window.addEventListener) {
|
|
44
|
+
const queue = [];
|
|
45
|
+
|
|
46
|
+
window.addEventListener(
|
|
47
|
+
'message',
|
|
48
|
+
(event) => {
|
|
49
|
+
const source = event.source;
|
|
50
|
+
|
|
51
|
+
if ((source === window || source === null) && event.data === NEXT_TICK_MESSAGE) {
|
|
52
|
+
event.stopPropagation();
|
|
53
|
+
if (queue.length > 0) {
|
|
54
|
+
const fn = queue.shift();
|
|
55
|
+
fn();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
true
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
return function nextTickUsingPostMessage(fn) {
|
|
63
|
+
expect.function(fn);
|
|
64
|
+
|
|
65
|
+
queue.push(fn);
|
|
66
|
+
window.postMessage(NEXT_TICK_MESSAGE, '*');
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
throw new Error('No suitable [setImmediate] implementation available');
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/* ------------------------------------------------------------------ Exports */
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* 'No operation' function
|
|
78
|
+
* - A function that does nothing
|
|
79
|
+
*/
|
|
80
|
+
export const noop = () => {};
|
|
81
|
+
|
|
82
|
+
// -----------------------------------------------------------------------------
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Wraps a function so that the callback function will be called only once
|
|
86
|
+
*
|
|
87
|
+
* @param {function} callback
|
|
88
|
+
*
|
|
89
|
+
* @returns {function} callback wrapped in `once` function
|
|
90
|
+
*/
|
|
91
|
+
export function once(callback) {
|
|
92
|
+
expect.function(callback);
|
|
93
|
+
|
|
94
|
+
let ignore = false;
|
|
95
|
+
|
|
96
|
+
return function () {
|
|
97
|
+
if (!ignore) {
|
|
98
|
+
ignore = true;
|
|
99
|
+
callback(...arguments);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// -----------------------------------------------------------------------------
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Returns a debounced function
|
|
108
|
+
* - The original function is not called more than once during the
|
|
109
|
+
* specified interval
|
|
110
|
+
*
|
|
111
|
+
* @param {function} fn
|
|
112
|
+
* @param {number} [intervalMs=200]
|
|
113
|
+
*
|
|
114
|
+
* @returns {function} debounced function
|
|
115
|
+
*/
|
|
116
|
+
export function debounce(fn, intervalMs = 200) {
|
|
117
|
+
let idleTimer;
|
|
118
|
+
let lastArguments;
|
|
119
|
+
|
|
120
|
+
// console.log("debounce");
|
|
121
|
+
|
|
122
|
+
return function debounced() {
|
|
123
|
+
// console.log("debounced");
|
|
124
|
+
|
|
125
|
+
if (idleTimer) {
|
|
126
|
+
// console.log("idleTimer running");
|
|
127
|
+
|
|
128
|
+
// The function has been called recently
|
|
129
|
+
lastArguments = arguments;
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
idleTimer = setTimeout(() => {
|
|
134
|
+
// console.log("idleTimer finished", lastArguments);
|
|
135
|
+
|
|
136
|
+
idleTimer = null;
|
|
137
|
+
|
|
138
|
+
if (lastArguments) {
|
|
139
|
+
//
|
|
140
|
+
// At least one call has been "debounced"
|
|
141
|
+
// -> make call with last arguments, so function always receives
|
|
142
|
+
// the arguments of the last call to the function
|
|
143
|
+
//
|
|
144
|
+
fn(...lastArguments);
|
|
145
|
+
lastArguments = undefined;
|
|
146
|
+
}
|
|
147
|
+
}, intervalMs);
|
|
148
|
+
|
|
149
|
+
fn(...arguments);
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// -----------------------------------------------------------------------------
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Defer the execution of a function
|
|
157
|
+
* - Uses the best 'setImmediate' implementation supported by the current
|
|
158
|
+
* runtime environment
|
|
159
|
+
*
|
|
160
|
+
* @param {function} fn - Function to execute
|
|
161
|
+
*
|
|
162
|
+
* --
|
|
163
|
+
*
|
|
164
|
+
* @note setImmediate is preferred over nextTick
|
|
165
|
+
*
|
|
166
|
+
* @see https://nodejs.org/en/docs/guides/event-loop-timers-and-nexttick/
|
|
167
|
+
*/
|
|
168
|
+
export const defer = set_immediate_implementation();
|
|
169
|
+
|
|
170
|
+
// -----------------------------------------------------------------------------
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Adds a wrapper around a function that only calls the supplied function
|
|
174
|
+
* if the (first) supplied argument to the returned function is not `null`
|
|
175
|
+
*
|
|
176
|
+
* @param {object} [object]
|
|
177
|
+
* Optional function context to be used as `this`
|
|
178
|
+
*
|
|
179
|
+
* @param {function} functionOrMethodName
|
|
180
|
+
*
|
|
181
|
+
* @returns {function} not null wrapper function
|
|
182
|
+
*/
|
|
183
|
+
// export function ifNotNull( /* object, functionOrMethodName */ )
|
|
184
|
+
// {
|
|
185
|
+
// let fn;
|
|
186
|
+
|
|
187
|
+
// switch( arguments.length )
|
|
188
|
+
// {
|
|
189
|
+
// case 1:
|
|
190
|
+
// fn = arguments[0];
|
|
191
|
+
// expectFunction( fn, "Missing or invalid parameter [fn]" );
|
|
192
|
+
// break;
|
|
193
|
+
|
|
194
|
+
// case 2:
|
|
195
|
+
// {
|
|
196
|
+
// const object = arguments[0];
|
|
197
|
+
// const methodName = arguments[1];
|
|
198
|
+
|
|
199
|
+
// expectObject( object, "Invalid parameter [object]" );
|
|
200
|
+
// expectNotEmptyString( methodName, "Invalid parameter [methodName]" );
|
|
201
|
+
|
|
202
|
+
// fn = object[ methodName ].bind( object );
|
|
203
|
+
|
|
204
|
+
// expectFunction( fn, `Invalid method [<object>.${methodName}]` );
|
|
205
|
+
// }
|
|
206
|
+
// break;
|
|
207
|
+
|
|
208
|
+
// default:
|
|
209
|
+
// throw new Error("Invalid number of arguments");
|
|
210
|
+
// }
|
|
211
|
+
|
|
212
|
+
// return async ( value ) => {
|
|
213
|
+
// if( null !== value )
|
|
214
|
+
// {
|
|
215
|
+
// await fn( value );
|
|
216
|
+
// }
|
|
217
|
+
// };
|
|
218
|
+
// }
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if a point lies within a polygon
|
|
3
|
+
*
|
|
4
|
+
* @param {number} xPct - X-coordinate as percentage
|
|
5
|
+
* @param {number} yPct - Y-coordinate as percentage
|
|
6
|
+
* @param {Array} polygon - Array of [x, y] points
|
|
7
|
+
*
|
|
8
|
+
* @returns {boolean} True if the point lies within the polygon
|
|
9
|
+
*/
|
|
10
|
+
export function isPointInPolygon(xPct: number, yPct: number, polygon: any[]): boolean;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if a point lies within a polygon
|
|
3
|
+
*
|
|
4
|
+
* @param {number} xPct - X-coordinate as percentage
|
|
5
|
+
* @param {number} yPct - Y-coordinate as percentage
|
|
6
|
+
* @param {Array} polygon - Array of [x, y] points
|
|
7
|
+
*
|
|
8
|
+
* @returns {boolean} True if the point lies within the polygon
|
|
9
|
+
*/
|
|
10
|
+
export function isPointInPolygon(xPct, yPct, polygon) {
|
|
11
|
+
let inside = false;
|
|
12
|
+
for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
|
|
13
|
+
const xi = polygon[i][0];
|
|
14
|
+
const yi = polygon[i][1];
|
|
15
|
+
const xj = polygon[j][0];
|
|
16
|
+
const yj = polygon[j][1];
|
|
17
|
+
|
|
18
|
+
const intersect =
|
|
19
|
+
yi > yPct !== yj > yPct &&
|
|
20
|
+
xPct < ((xj - xi) * (yPct - yi)) / (yj - yi) + xi;
|
|
21
|
+
if (intersect) {
|
|
22
|
+
inside = !inside;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return inside;
|
|
26
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Store a response in the cache
|
|
3
|
+
*
|
|
4
|
+
* @param {object} cacheKeyParams - Parameters to use for cache key generation
|
|
5
|
+
* @param {string|URL} cacheKeyParams.url - URL string or URL object
|
|
6
|
+
* @param {object} [cacheKeyParams.headers] - Request headers that affect caching
|
|
7
|
+
* @param {Response} response - Response to cache
|
|
8
|
+
* @param {object} metadata - Cache metadata
|
|
9
|
+
* @returns {Promise<void>}
|
|
10
|
+
*/
|
|
11
|
+
export function storeResponseInCache(cacheKeyParams: {
|
|
12
|
+
url: string | URL;
|
|
13
|
+
headers?: object;
|
|
14
|
+
}, response: Response, metadata: object): Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* Get a cached response if available and valid
|
|
17
|
+
*
|
|
18
|
+
* @param {object} cacheKeyParams - Parameters to use for cache key generation
|
|
19
|
+
* @param {string|URL} cacheKeyParams.url - URL string or URL object
|
|
20
|
+
* @param {object} [cacheKeyParams.headers] - Request headers that affect caching
|
|
21
|
+
*
|
|
22
|
+
* @returns {Promise<Response|import('./typedef').ResponseWithStale|null>}
|
|
23
|
+
* Cached response or null
|
|
24
|
+
*/
|
|
25
|
+
export function getCachedResponse(cacheKeyParams: {
|
|
26
|
+
url: string | URL;
|
|
27
|
+
headers?: object;
|
|
28
|
+
}): Promise<Response | import("./typedef").ResponseWithStale | null>;
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MemoryResponseCache,
|
|
3
|
+
IndexedDbCache
|
|
4
|
+
} from '../../classes/cache';
|
|
5
|
+
|
|
6
|
+
import { browser } from '$app/environment';
|
|
7
|
+
|
|
8
|
+
import { isTestEnv } from '../env';
|
|
9
|
+
|
|
10
|
+
let defaultCacheStorage = null;
|
|
11
|
+
|
|
12
|
+
function getCacheStorage()
|
|
13
|
+
{
|
|
14
|
+
if( !defaultCacheStorage )
|
|
15
|
+
{
|
|
16
|
+
let type;
|
|
17
|
+
|
|
18
|
+
if( !browser || isTestEnv )
|
|
19
|
+
{
|
|
20
|
+
type = 'memory';
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
type = 'indexed-db';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
defaultCacheStorage = createCacheStorage( type);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return defaultCacheStorage
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Store a response in the cache
|
|
34
|
+
*
|
|
35
|
+
* @param {object} cacheKeyParams - Parameters to use for cache key generation
|
|
36
|
+
* @param {string|URL} cacheKeyParams.url - URL string or URL object
|
|
37
|
+
* @param {object} [cacheKeyParams.headers] - Request headers that affect caching
|
|
38
|
+
* @param {Response} response - Response to cache
|
|
39
|
+
* @param {object} metadata - Cache metadata
|
|
40
|
+
* @returns {Promise<void>}
|
|
41
|
+
*/
|
|
42
|
+
export async function storeResponseInCache(cacheKeyParams, response, metadata) {
|
|
43
|
+
try {
|
|
44
|
+
const { url: rawUrl, ...headers } = cacheKeyParams;
|
|
45
|
+
const url = typeof rawUrl === 'string' ? rawUrl : rawUrl.toString();
|
|
46
|
+
|
|
47
|
+
// Generate cache key
|
|
48
|
+
const cacheKey = generateCacheKey(url, headers);
|
|
49
|
+
|
|
50
|
+
// Extract Vary header info
|
|
51
|
+
const varyHeader = response.headers.get('Vary');
|
|
52
|
+
let varyHeaders = null;
|
|
53
|
+
|
|
54
|
+
if (varyHeader) {
|
|
55
|
+
varyHeaders = {};
|
|
56
|
+
const varyFields = varyHeader.split(',').map(field => field.trim().toLowerCase());
|
|
57
|
+
|
|
58
|
+
// Store hashes of headers mentioned in Vary
|
|
59
|
+
for (const field of varyFields) {
|
|
60
|
+
if (field !== '*') {
|
|
61
|
+
const value = headers[field];
|
|
62
|
+
varyHeaders[field] = hashValue(value);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Add vary headers to metadata
|
|
68
|
+
const enhancedMetadata = {
|
|
69
|
+
...metadata,
|
|
70
|
+
varyHeaders
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// Store in cache
|
|
74
|
+
await getCacheStorage().set(cacheKey, response, enhancedMetadata);
|
|
75
|
+
} catch (error) {
|
|
76
|
+
console.error('Cache storage error:', error);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Get a cached response if available and valid
|
|
82
|
+
*
|
|
83
|
+
* @param {object} cacheKeyParams - Parameters to use for cache key generation
|
|
84
|
+
* @param {string|URL} cacheKeyParams.url - URL string or URL object
|
|
85
|
+
* @param {object} [cacheKeyParams.headers] - Request headers that affect caching
|
|
86
|
+
*
|
|
87
|
+
* @returns {Promise<Response|import('./typedef').ResponseWithStale|null>}
|
|
88
|
+
* Cached response or null
|
|
89
|
+
*/
|
|
90
|
+
export async function getCachedResponse(cacheKeyParams) {
|
|
91
|
+
try {
|
|
92
|
+
const { url: rawUrl, ...headers } = cacheKeyParams;
|
|
93
|
+
const url = typeof rawUrl === 'string' ? rawUrl : rawUrl.toString();
|
|
94
|
+
|
|
95
|
+
// Generate cache key
|
|
96
|
+
const cacheKey = generateCacheKey(url, headers);
|
|
97
|
+
|
|
98
|
+
// Get cached entry
|
|
99
|
+
const cachedEntry = await getCacheStorage().get(cacheKey);
|
|
100
|
+
|
|
101
|
+
if (!cachedEntry) {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Validate based on Vary headers
|
|
106
|
+
if (!isValidForVaryHeaders(cachedEntry, headers)) {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const { response, metadata } = cachedEntry;
|
|
111
|
+
|
|
112
|
+
// Check if expired
|
|
113
|
+
const isExpired = metadata.expires && Date.now() > metadata.expires;
|
|
114
|
+
|
|
115
|
+
if (!isExpired) {
|
|
116
|
+
// Not expired, return as-is
|
|
117
|
+
return response;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Response is stale, add stale info
|
|
121
|
+
return enhanceResponseWithStale(response, {
|
|
122
|
+
isStale: true,
|
|
123
|
+
fresh: null, // No fresh data available yet
|
|
124
|
+
timestamp: metadata.timestamp,
|
|
125
|
+
expires: metadata.expires
|
|
126
|
+
});
|
|
127
|
+
} catch (error) {
|
|
128
|
+
console.error('Cache retrieval error:', error);
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// > Internal functions
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Create a cache storage adapter
|
|
137
|
+
* @param {string} type Type of storage ('indexed-db', 'memory')
|
|
138
|
+
* @param {Object} options Options for the storage adapter
|
|
139
|
+
*
|
|
140
|
+
* @returns {import('../../classes/cache').CacheStorage}
|
|
141
|
+
*/
|
|
142
|
+
function createCacheStorage(type = 'indexed-db', options = {}) {
|
|
143
|
+
switch (type) {
|
|
144
|
+
case 'indexed-db':
|
|
145
|
+
return new IndexedDbCache(
|
|
146
|
+
{
|
|
147
|
+
dbName: 'http-cache',
|
|
148
|
+
storeName: 'responses'
|
|
149
|
+
} );
|
|
150
|
+
|
|
151
|
+
case 'memory':
|
|
152
|
+
return new MemoryResponseCache();
|
|
153
|
+
|
|
154
|
+
default:
|
|
155
|
+
throw new Error(`Unsupported cache storage type: ${type}`);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Check if cached entry is valid based on Vary headers
|
|
161
|
+
*
|
|
162
|
+
* @param {object} cachedEntry - Cached entry with response and metadata
|
|
163
|
+
* @param {object} headers - Current request headers
|
|
164
|
+
* @returns {boolean} True if valid for these headers
|
|
165
|
+
*/
|
|
166
|
+
function isValidForVaryHeaders(cachedEntry, headers) {
|
|
167
|
+
const { metadata } = cachedEntry;
|
|
168
|
+
|
|
169
|
+
// If no vary headers stored, consider valid
|
|
170
|
+
if (!metadata.varyHeaders) {
|
|
171
|
+
return true;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Check each stored vary header
|
|
175
|
+
for (const [name, storedHash] of Object.entries(metadata.varyHeaders)) {
|
|
176
|
+
const currentValue = headers[name];
|
|
177
|
+
const currentHash = hashValue(currentValue);
|
|
178
|
+
|
|
179
|
+
// Compare hashes
|
|
180
|
+
if (currentHash !== storedHash) {
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return true;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Generate a cache key based on URL and relevant headers
|
|
190
|
+
*
|
|
191
|
+
* @param {string} url - URL string
|
|
192
|
+
* @param {object} headers - Request headers
|
|
193
|
+
* @returns {string} Cache key
|
|
194
|
+
*/
|
|
195
|
+
function generateCacheKey(url, headers) {
|
|
196
|
+
// Start with a hash of the URL
|
|
197
|
+
const keyParts = [hashValue(url)];
|
|
198
|
+
|
|
199
|
+
// If we have headers
|
|
200
|
+
if (headers && Object.keys(headers).length > 0) {
|
|
201
|
+
// Get all header names, sorted for consistency
|
|
202
|
+
const headerNames = Object.keys(headers).sort();
|
|
203
|
+
|
|
204
|
+
// Create a hash for each header value
|
|
205
|
+
const headerHashes = headerNames.map(name => {
|
|
206
|
+
const value = headers[name];
|
|
207
|
+
// Format: "name:hash_of_value"
|
|
208
|
+
return `${name}:${hashValue(value)}`;
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
if (headerHashes.length > 0) {
|
|
212
|
+
keyParts.push(headerHashes.join('|'));
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
return keyParts.join('::');
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Create a hash of a value
|
|
221
|
+
*
|
|
222
|
+
* @param {string} value - Value to hash
|
|
223
|
+
* @returns {string} Hash representation
|
|
224
|
+
*/
|
|
225
|
+
function hashValue(value) {
|
|
226
|
+
if (!value) return '';
|
|
227
|
+
|
|
228
|
+
// Convert to string if not already
|
|
229
|
+
const stringValue = String(value);
|
|
230
|
+
|
|
231
|
+
// Simple non-cryptographic hash function
|
|
232
|
+
let hash = 0;
|
|
233
|
+
for (let i = 0; i < stringValue.length; i++) {
|
|
234
|
+
const char = stringValue.charCodeAt(i);
|
|
235
|
+
hash = ((hash << 5) - hash) + char;
|
|
236
|
+
hash = hash & hash; // Convert to 32bit integer
|
|
237
|
+
}
|
|
238
|
+
return hash.toString(16); // Convert to hex
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Enhance a Response object with stale data properties
|
|
244
|
+
*
|
|
245
|
+
* @param {Response} response - The original Response object
|
|
246
|
+
* @param {import('./typedef').StaleInfo} staleInfo - Stale data information
|
|
247
|
+
*
|
|
248
|
+
* @returns {import('./typedef').ResponseWithStale}
|
|
249
|
+
* Enhanced response with stale data properties
|
|
250
|
+
*/
|
|
251
|
+
function enhanceResponseWithStale(response, staleInfo) {
|
|
252
|
+
// Create a new object that inherits from Response prototype
|
|
253
|
+
const enhanced = Object.create(
|
|
254
|
+
Object.getPrototypeOf(response),
|
|
255
|
+
Object.getOwnPropertyDescriptors(response)
|
|
256
|
+
);
|
|
257
|
+
|
|
258
|
+
// Add stale properties
|
|
259
|
+
enhanced.isStale = staleInfo.isStale || false;
|
|
260
|
+
enhanced.fresh = staleInfo.fresh || null;
|
|
261
|
+
|
|
262
|
+
return enhanced;
|
|
263
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Try to get error information from the server error response
|
|
3
|
+
*
|
|
4
|
+
* This method tries to get error info from JSON responses. The
|
|
5
|
+
* error info may be set as one of the following properties
|
|
6
|
+
*
|
|
7
|
+
* - message
|
|
8
|
+
* - error
|
|
9
|
+
* - messages (array)
|
|
10
|
+
* - errors (array)
|
|
11
|
+
*
|
|
12
|
+
* Otherwise tris method will use the plain text response
|
|
13
|
+
*
|
|
14
|
+
* @param {object} response
|
|
15
|
+
*
|
|
16
|
+
* @returns {Error} error
|
|
17
|
+
*/
|
|
18
|
+
export function getErrorFromResponse(response: object): Error;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import * as expect from '../expect/index.js';
|
|
2
|
+
|
|
3
|
+
import { CONTENT_TYPE } from '../../constants/http/index.js';
|
|
4
|
+
|
|
5
|
+
import { APPLICATION_JSON } from '../../constants/mime/index.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Try to get error information from the server error response
|
|
9
|
+
*
|
|
10
|
+
* This method tries to get error info from JSON responses. The
|
|
11
|
+
* error info may be set as one of the following properties
|
|
12
|
+
*
|
|
13
|
+
* - message
|
|
14
|
+
* - error
|
|
15
|
+
* - messages (array)
|
|
16
|
+
* - errors (array)
|
|
17
|
+
*
|
|
18
|
+
* Otherwise tris method will use the plain text response
|
|
19
|
+
*
|
|
20
|
+
* @param {object} response
|
|
21
|
+
*
|
|
22
|
+
* @returns {Error} error
|
|
23
|
+
*/
|
|
24
|
+
export async function getErrorFromResponse(response) {
|
|
25
|
+
expect.object(response);
|
|
26
|
+
|
|
27
|
+
let message;
|
|
28
|
+
let details = null;
|
|
29
|
+
|
|
30
|
+
const headers = response.headers;
|
|
31
|
+
const contentType = headers.get(CONTENT_TYPE);
|
|
32
|
+
|
|
33
|
+
let content;
|
|
34
|
+
|
|
35
|
+
if (contentType === APPLICATION_JSON) {
|
|
36
|
+
content = await response.json();
|
|
37
|
+
|
|
38
|
+
if (content instanceof Object) {
|
|
39
|
+
if (typeof content.message === 'string') {
|
|
40
|
+
// Use string propery 'message' as error message
|
|
41
|
+
message = content.message;
|
|
42
|
+
} else if (typeof content.error === 'string') {
|
|
43
|
+
// Use string propery 'error' as error message
|
|
44
|
+
message = content.error;
|
|
45
|
+
} else {
|
|
46
|
+
if (Array.isArray(content.errors)) {
|
|
47
|
+
// Use array propery 'errors' for error messages
|
|
48
|
+
|
|
49
|
+
details = content.errors;
|
|
50
|
+
} else if (Array.isArray(content.messages)) {
|
|
51
|
+
// Use array propery 'messages' for error messages
|
|
52
|
+
|
|
53
|
+
details = content.messages;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (details) {
|
|
57
|
+
// Multiple error messages (array) =>
|
|
58
|
+
// create string respresentation by combining
|
|
59
|
+
// text parts from all error messages
|
|
60
|
+
const tmp = [];
|
|
61
|
+
|
|
62
|
+
for (const current of details) {
|
|
63
|
+
if (typeof current === 'string') {
|
|
64
|
+
// Error is a string
|
|
65
|
+
tmp.push(current);
|
|
66
|
+
} else if (current instanceof Object && typeof current.message === 'string') {
|
|
67
|
+
// Error is an object with string property 'message'
|
|
68
|
+
tmp.push(current.message);
|
|
69
|
+
} else {
|
|
70
|
+
// JSON stringify everything else
|
|
71
|
+
tmp.push(JSON.stringify(current));
|
|
72
|
+
}
|
|
73
|
+
} // end for
|
|
74
|
+
|
|
75
|
+
message = tmp.join(', ');
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
} else {
|
|
80
|
+
const tmp = await response.text();
|
|
81
|
+
|
|
82
|
+
if (tmp.length) {
|
|
83
|
+
message = tmp;
|
|
84
|
+
} else {
|
|
85
|
+
message = response.statusText;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
// console.log( "message", message );
|
|
89
|
+
|
|
90
|
+
const error = new Error(message);
|
|
91
|
+
|
|
92
|
+
if (details) {
|
|
93
|
+
error.details = details;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return error;
|
|
97
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Set headers in an existing `Headers` object
|
|
3
|
+
*
|
|
4
|
+
* This function adds or updates headers in an existing Headers object.
|
|
5
|
+
* Existing headers with the same name will be overwritten.
|
|
6
|
+
* The supplied `Headers` object will be updated in place.
|
|
7
|
+
*
|
|
8
|
+
* @param {Headers} target
|
|
9
|
+
* Headers object to set the extra headers in
|
|
10
|
+
*
|
|
11
|
+
* @param {null|object|[string, string][]} [pairs]
|
|
12
|
+
* Headers to add, can be null, an object of name-value pairs,
|
|
13
|
+
* or an array of [name, value] pairs
|
|
14
|
+
*
|
|
15
|
+
* @throws {Error} If target is not a Headers object
|
|
16
|
+
* @throws {Error} If pairs is a Headers object
|
|
17
|
+
* @throws {Error} If pairs is not null, object, or array
|
|
18
|
+
* @throws {Error} If any header name or value is empty
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* // Add headers from an object
|
|
22
|
+
* const headers = new Headers();
|
|
23
|
+
* setRequestHeaders(headers, {
|
|
24
|
+
* 'content-type': 'application/json',
|
|
25
|
+
* 'accept': 'application/json'
|
|
26
|
+
* });
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* // Add headers from an array of pairs
|
|
30
|
+
* const headers = new Headers();
|
|
31
|
+
* setRequestHeaders(headers, [
|
|
32
|
+
* ['content-type', 'application/json'],
|
|
33
|
+
* ['authorization', 'Bearer token123']
|
|
34
|
+
* ]);
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* // Passing null is valid and does nothing
|
|
38
|
+
* setRequestHeaders(headers, null);
|
|
39
|
+
*/
|
|
40
|
+
export function setRequestHeaders(target: Headers, pairs?: null | object | [string, string][]): void;
|