svelte-ag 0.0.2-dev.72
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 +6 -0
- package/dist/app.css +209 -0
- package/dist/app.d.ts +13 -0
- package/dist/app.html +12 -0
- package/dist/icons.css +6 -0
- package/dist/lib/bits/internal/arrays.d.ts +95 -0
- package/dist/lib/bits/internal/arrays.js +250 -0
- package/dist/lib/bits/internal/arrays.test.d.ts +1 -0
- package/dist/lib/bits/internal/arrays.test.js +366 -0
- package/dist/lib/bits/internal/attrs.d.ts +22 -0
- package/dist/lib/bits/internal/attrs.js +69 -0
- package/dist/lib/bits/internal/box-auto-reset.svelte.d.ts +8 -0
- package/dist/lib/bits/internal/box-auto-reset.svelte.js +31 -0
- package/dist/lib/bits/internal/box.svelte.d.ts +21 -0
- package/dist/lib/bits/internal/box.svelte.js +26 -0
- package/dist/lib/bits/internal/clamp.d.ts +4 -0
- package/dist/lib/bits/internal/clamp.js +6 -0
- package/dist/lib/bits/internal/clamp.test.d.ts +1 -0
- package/dist/lib/bits/internal/clamp.test.js +31 -0
- package/dist/lib/bits/internal/create-event-hook.svelte.d.ts +18 -0
- package/dist/lib/bits/internal/create-event-hook.svelte.js +29 -0
- package/dist/lib/bits/internal/create-shared-hook.svelte.d.ts +2 -0
- package/dist/lib/bits/internal/create-shared-hook.svelte.js +27 -0
- package/dist/lib/bits/internal/date-time/announcer.d.ts +7 -0
- package/dist/lib/bits/internal/date-time/announcer.js +82 -0
- package/dist/lib/bits/internal/date-time/calendar-helpers.svelte.d.ts +201 -0
- package/dist/lib/bits/internal/date-time/calendar-helpers.svelte.js +510 -0
- package/dist/lib/bits/internal/date-time/field/helpers.d.ts +76 -0
- package/dist/lib/bits/internal/date-time/field/helpers.js +378 -0
- package/dist/lib/bits/internal/date-time/field/parts.d.ts +6 -0
- package/dist/lib/bits/internal/date-time/field/parts.js +9 -0
- package/dist/lib/bits/internal/date-time/field/segments.d.ts +51 -0
- package/dist/lib/bits/internal/date-time/field/segments.js +128 -0
- package/dist/lib/bits/internal/date-time/field/types.d.ts +25 -0
- package/dist/lib/bits/internal/date-time/field/types.js +1 -0
- package/dist/lib/bits/internal/date-time/formatter.d.ts +24 -0
- package/dist/lib/bits/internal/date-time/formatter.js +97 -0
- package/dist/lib/bits/internal/date-time/placeholders.d.ts +8 -0
- package/dist/lib/bits/internal/date-time/placeholders.js +129 -0
- package/dist/lib/bits/internal/date-time/utils.d.ts +69 -0
- package/dist/lib/bits/internal/date-time/utils.js +212 -0
- package/dist/lib/bits/internal/debounce.d.ts +4 -0
- package/dist/lib/bits/internal/debounce.js +19 -0
- package/dist/lib/bits/internal/debounce.test.d.ts +1 -0
- package/dist/lib/bits/internal/debounce.test.js +50 -0
- package/dist/lib/bits/internal/dom.d.ts +10 -0
- package/dist/lib/bits/internal/dom.js +38 -0
- package/dist/lib/bits/internal/elements.d.ts +2 -0
- package/dist/lib/bits/internal/elements.js +6 -0
- package/dist/lib/bits/internal/events.d.ts +21 -0
- package/dist/lib/bits/internal/events.js +49 -0
- package/dist/lib/bits/internal/floating-svelte/floating-utils.svelte.d.ts +7 -0
- package/dist/lib/bits/internal/floating-svelte/floating-utils.svelte.js +24 -0
- package/dist/lib/bits/internal/floating-svelte/types.d.ts +85 -0
- package/dist/lib/bits/internal/floating-svelte/types.js +1 -0
- package/dist/lib/bits/internal/floating-svelte/use-floating.svelte.d.ts +2 -0
- package/dist/lib/bits/internal/floating-svelte/use-floating.svelte.js +112 -0
- package/dist/lib/bits/internal/focus.d.ts +46 -0
- package/dist/lib/bits/internal/focus.js +109 -0
- package/dist/lib/bits/internal/get-directional-keys.d.ts +21 -0
- package/dist/lib/bits/internal/get-directional-keys.js +37 -0
- package/dist/lib/bits/internal/get-directional-keys.test.d.ts +1 -0
- package/dist/lib/bits/internal/get-directional-keys.test.js +46 -0
- package/dist/lib/bits/internal/is.d.ts +25 -0
- package/dist/lib/bits/internal/is.js +62 -0
- package/dist/lib/bits/internal/is.test.d.ts +1 -0
- package/dist/lib/bits/internal/is.test.js +34 -0
- package/dist/lib/bits/internal/kbd-constants.d.ts +40 -0
- package/dist/lib/bits/internal/kbd-constants.js +40 -0
- package/dist/lib/bits/internal/kbd.d.ts +1 -0
- package/dist/lib/bits/internal/kbd.js +1 -0
- package/dist/lib/bits/internal/locale.d.ts +6 -0
- package/dist/lib/bits/internal/locale.js +9 -0
- package/dist/lib/bits/internal/math.d.ts +5 -0
- package/dist/lib/bits/internal/math.js +43 -0
- package/dist/lib/bits/internal/math.test.d.ts +1 -0
- package/dist/lib/bits/internal/math.test.js +71 -0
- package/dist/lib/bits/internal/noop.d.ts +4 -0
- package/dist/lib/bits/internal/noop.js +4 -0
- package/dist/lib/bits/internal/should-trap-focus.d.ts +6 -0
- package/dist/lib/bits/internal/should-trap-focus.js +6 -0
- package/dist/lib/bits/internal/sleep.d.ts +1 -0
- package/dist/lib/bits/internal/sleep.js +3 -0
- package/dist/lib/bits/internal/tabbable.d.ts +10 -0
- package/dist/lib/bits/internal/tabbable.js +66 -0
- package/dist/lib/bits/internal/types.d.ts +92 -0
- package/dist/lib/bits/internal/types.js +1 -0
- package/dist/lib/bits/internal/use-after-animations.svelte.d.ts +5 -0
- package/dist/lib/bits/internal/use-after-animations.svelte.js +27 -0
- package/dist/lib/bits/internal/use-arrow-navigation.d.ts +62 -0
- package/dist/lib/bits/internal/use-arrow-navigation.js +76 -0
- package/dist/lib/bits/internal/use-body-scroll-lock.svelte.d.ts +6 -0
- package/dist/lib/bits/internal/use-body-scroll-lock.svelte.js +106 -0
- package/dist/lib/bits/internal/use-data-typeahead.svelte.d.ts +14 -0
- package/dist/lib/bits/internal/use-data-typeahead.svelte.js +31 -0
- package/dist/lib/bits/internal/use-dom-typeahead.svelte.d.ts +11 -0
- package/dist/lib/bits/internal/use-dom-typeahead.svelte.js +30 -0
- package/dist/lib/bits/internal/use-form-control.svelte.d.ts +4 -0
- package/dist/lib/bits/internal/use-form-control.svelte.js +16 -0
- package/dist/lib/bits/internal/use-grace-area.svelte.d.ts +12 -0
- package/dist/lib/bits/internal/use-grace-area.svelte.js +197 -0
- package/dist/lib/bits/internal/use-id.d.ts +4 -0
- package/dist/lib/bits/internal/use-id.js +8 -0
- package/dist/lib/bits/internal/use-resize-observer.svelte.d.ts +2 -0
- package/dist/lib/bits/internal/use-resize-observer.svelte.js +17 -0
- package/dist/lib/bits/internal/use-roving-focus.svelte.d.ts +38 -0
- package/dist/lib/bits/internal/use-roving-focus.svelte.js +91 -0
- package/dist/lib/bits/internal/use-size.svelte.d.ts +7 -0
- package/dist/lib/bits/internal/use-size.svelte.js +54 -0
- package/dist/lib/bits/internal/use-state-machine.svelte.d.ts +24 -0
- package/dist/lib/bits/internal/use-state-machine.svelte.js +28 -0
- package/dist/lib/bits/internal/use-timeout-fn.svelte.d.ts +25 -0
- package/dist/lib/bits/internal/use-timeout-fn.svelte.js +39 -0
- package/dist/lib/components/Typeahead.svelte.d.ts +47 -0
- package/dist/lib/components/Typeahead.svelte.js +150 -0
- package/dist/lib/components/animated/animated.svelte +244 -0
- package/dist/lib/components/animated/animated.svelte.d.ts +61 -0
- package/dist/lib/components/animated/index.d.ts +2 -0
- package/dist/lib/components/animated/index.js +2 -0
- package/dist/lib/components/combo/combo.svelte +186 -0
- package/dist/lib/components/combo/combo.svelte.d.ts +21 -0
- package/dist/lib/components/combo/index.d.ts +2 -0
- package/dist/lib/components/combo/index.js +2 -0
- package/dist/lib/components/dnd/Droppable.svelte +25 -0
- package/dist/lib/components/dnd/Droppable.svelte.d.ts +10 -0
- package/dist/lib/components/dnd/context.svelte.d.ts +22 -0
- package/dist/lib/components/dnd/context.svelte.js +25 -0
- package/dist/lib/components/dnd/dnd-context.svelte +45 -0
- package/dist/lib/components/dnd/dnd-context.svelte.d.ts +30 -0
- package/dist/lib/components/dnd/dnd-drag-overlay.svelte +44 -0
- package/dist/lib/components/dnd/dnd-drag-overlay.svelte.d.ts +27 -0
- package/dist/lib/components/dnd/dnd-drag-placeholder.svelte +24 -0
- package/dist/lib/components/dnd/dnd-drag-placeholder.svelte.d.ts +9 -0
- package/dist/lib/components/dnd/dnd-draghandle.svelte +30 -0
- package/dist/lib/components/dnd/dnd-draghandle.svelte.d.ts +6 -0
- package/dist/lib/components/dnd/dnd-overlay.svelte +0 -0
- package/dist/lib/components/dnd/dnd-overlay.svelte.d.ts +26 -0
- package/dist/lib/components/dnd/dnd-sortable-context.svelte +18 -0
- package/dist/lib/components/dnd/dnd-sortable-context.svelte.d.ts +8 -0
- package/dist/lib/components/dnd/dnd-sortable-item.svelte +68 -0
- package/dist/lib/components/dnd/dnd-sortable-item.svelte.d.ts +23 -0
- package/dist/lib/components/dnd/example.svelte +109 -0
- package/dist/lib/components/dnd/example.svelte.d.ts +3 -0
- package/dist/lib/components/dnd/exports.d.ts +9 -0
- package/dist/lib/components/dnd/exports.js +9 -0
- package/dist/lib/components/dnd/index.d.ts +1 -0
- package/dist/lib/components/dnd/index.js +1 -0
- package/dist/lib/components/dnd/sortable.svelte.d.ts +13 -0
- package/dist/lib/components/dnd/sortable.svelte.js +70 -0
- package/dist/lib/components/dnd/utils.svelte.d.ts +20 -0
- package/dist/lib/components/dnd/utils.svelte.js +20 -0
- package/dist/lib/components/search/combinations/searchPopover.svelte +68 -0
- package/dist/lib/components/search/combinations/searchPopover.svelte.d.ts +22 -0
- package/dist/lib/components/search/components/search-empty.svelte +28 -0
- package/dist/lib/components/search/components/search-empty.svelte.d.ts +4 -0
- package/dist/lib/components/search/components/search-input.svelte +53 -0
- package/dist/lib/components/search/components/search-input.svelte.d.ts +4 -0
- package/dist/lib/components/search/components/search-list.svelte +46 -0
- package/dist/lib/components/search/components/search-list.svelte.d.ts +4 -0
- package/dist/lib/components/search/components/search-pagnation.svelte +68 -0
- package/dist/lib/components/search/components/search-pagnation.svelte.d.ts +8 -0
- package/dist/lib/components/search/components/search.svelte +47 -0
- package/dist/lib/components/search/components/search.svelte.d.ts +4 -0
- package/dist/lib/components/search/exports.d.ts +6 -0
- package/dist/lib/components/search/exports.js +5 -0
- package/dist/lib/components/search/index.d.ts +2 -0
- package/dist/lib/components/search/index.js +2 -0
- package/dist/lib/components/search/search.svelte.d.ts +102 -0
- package/dist/lib/components/search/search.svelte.js +202 -0
- package/dist/lib/components/search/types.d.ts +28 -0
- package/dist/lib/components/search/types.js +1 -0
- package/dist/lib/components/utilities/arrow/arrow.svelte +23 -0
- package/dist/lib/components/utilities/arrow/arrow.svelte.d.ts +3 -0
- package/dist/lib/components/utilities/arrow/index.d.ts +2 -0
- package/dist/lib/components/utilities/arrow/index.js +1 -0
- package/dist/lib/components/utilities/arrow/types.d.ts +17 -0
- package/dist/lib/components/utilities/arrow/types.js +1 -0
- package/dist/lib/components/utilities/floating-layer/components/floating-layer-anchor.svelte +15 -0
- package/dist/lib/components/utilities/floating-layer/components/floating-layer-anchor.svelte.d.ts +4 -0
- package/dist/lib/components/utilities/floating-layer/components/floating-layer-arrow.svelte +20 -0
- package/dist/lib/components/utilities/floating-layer/components/floating-layer-arrow.svelte.d.ts +3 -0
- package/dist/lib/components/utilities/floating-layer/components/floating-layer-content-static.svelte +19 -0
- package/dist/lib/components/utilities/floating-layer/components/floating-layer-content-static.svelte.d.ts +13 -0
- package/dist/lib/components/utilities/floating-layer/components/floating-layer-content.svelte +61 -0
- package/dist/lib/components/utilities/floating-layer/components/floating-layer-content.svelte.d.ts +4 -0
- package/dist/lib/components/utilities/floating-layer/components/floating-layer.svelte +10 -0
- package/dist/lib/components/utilities/floating-layer/components/floating-layer.svelte.d.ts +7 -0
- package/dist/lib/components/utilities/floating-layer/components/index.d.ts +6 -0
- package/dist/lib/components/utilities/floating-layer/components/index.js +5 -0
- package/dist/lib/components/utilities/floating-layer/index.d.ts +1 -0
- package/dist/lib/components/utilities/floating-layer/index.js +1 -0
- package/dist/lib/components/utilities/floating-layer/types.d.ts +115 -0
- package/dist/lib/components/utilities/floating-layer/types.js +1 -0
- package/dist/lib/components/utilities/floating-layer/use-floating-layer.svelte.d.ts +118 -0
- package/dist/lib/components/utilities/floating-layer/use-floating-layer.svelte.js +311 -0
- package/dist/lib/index.d.ts +1 -0
- package/dist/lib/index.js +1 -0
- package/dist/lib/utils/asyncDerived.svelte.d.ts +12 -0
- package/dist/lib/utils/asyncDerived.svelte.js +26 -0
- package/dist/lib/utils/bits.d.ts +39 -0
- package/dist/lib/utils/bits.js +69 -0
- package/dist/lib/utils/index.d.ts +3 -0
- package/dist/lib/utils/index.js +3 -0
- package/dist/lib/utils/utils.d.ts +21 -0
- package/dist/lib/utils/utils.js +72 -0
- package/dist/routes/+layout.svelte +0 -0
- package/dist/routes/+layout.svelte.d.ts +26 -0
- package/package.json +79 -0
- package/src/app.css +209 -0
- package/src/app.d.ts +13 -0
- package/src/app.html +12 -0
- package/src/icons.css +6 -0
- package/src/lib/bits/internal/arrays.test.ts +460 -0
- package/src/lib/bits/internal/arrays.ts +301 -0
- package/src/lib/bits/internal/attrs.ts +97 -0
- package/src/lib/bits/internal/box-auto-reset.svelte.ts +40 -0
- package/src/lib/bits/internal/box.svelte.ts +60 -0
- package/src/lib/bits/internal/clamp.test.ts +37 -0
- package/src/lib/bits/internal/clamp.ts +6 -0
- package/src/lib/bits/internal/create-event-hook.svelte.ts +64 -0
- package/src/lib/bits/internal/create-shared-hook.svelte.ts +33 -0
- package/src/lib/bits/internal/date-time/announcer.ts +88 -0
- package/src/lib/bits/internal/date-time/calendar-helpers.svelte.ts +815 -0
- package/src/lib/bits/internal/date-time/field/helpers.ts +441 -0
- package/src/lib/bits/internal/date-time/field/parts.ts +9 -0
- package/src/lib/bits/internal/date-time/field/segments.ts +126 -0
- package/src/lib/bits/internal/date-time/field/types.ts +35 -0
- package/src/lib/bits/internal/date-time/formatter.ts +116 -0
- package/src/lib/bits/internal/date-time/placeholders.ts +143 -0
- package/src/lib/bits/internal/date-time/utils.ts +261 -0
- package/src/lib/bits/internal/debounce.test.ts +67 -0
- package/src/lib/bits/internal/debounce.ts +22 -0
- package/src/lib/bits/internal/dom.ts +47 -0
- package/src/lib/bits/internal/elements.ts +7 -0
- package/src/lib/bits/internal/events.ts +89 -0
- package/src/lib/bits/internal/floating-svelte/floating-utils.svelte.ts +28 -0
- package/src/lib/bits/internal/floating-svelte/types.ts +108 -0
- package/src/lib/bits/internal/floating-svelte/use-floating.svelte.ts +133 -0
- package/src/lib/bits/internal/focus.ts +111 -0
- package/src/lib/bits/internal/get-directional-keys.test.ts +51 -0
- package/src/lib/bits/internal/get-directional-keys.ts +43 -0
- package/src/lib/bits/internal/is.test.ts +40 -0
- package/src/lib/bits/internal/is.ts +78 -0
- package/src/lib/bits/internal/kbd-constants.ts +40 -0
- package/src/lib/bits/internal/kbd.ts +1 -0
- package/src/lib/bits/internal/locale.ts +13 -0
- package/src/lib/bits/internal/math.test.ts +88 -0
- package/src/lib/bits/internal/math.ts +50 -0
- package/src/lib/bits/internal/noop.ts +4 -0
- package/src/lib/bits/internal/should-trap-focus.ts +16 -0
- package/src/lib/bits/internal/sleep.ts +3 -0
- package/src/lib/bits/internal/tabbable.ts +76 -0
- package/src/lib/bits/internal/types.ts +91 -0
- package/src/lib/bits/internal/use-after-animations.svelte.ts +30 -0
- package/src/lib/bits/internal/use-arrow-navigation.ts +168 -0
- package/src/lib/bits/internal/use-body-scroll-lock.svelte.ts +138 -0
- package/src/lib/bits/internal/use-data-typeahead.svelte.ts +44 -0
- package/src/lib/bits/internal/use-dom-typeahead.svelte.ts +44 -0
- package/src/lib/bits/internal/use-form-control.svelte.ts +17 -0
- package/src/lib/bits/internal/use-grace-area.svelte.ts +229 -0
- package/src/lib/bits/internal/use-id.ts +9 -0
- package/src/lib/bits/internal/use-resize-observer.svelte.ts +19 -0
- package/src/lib/bits/internal/use-roving-focus.svelte.ts +141 -0
- package/src/lib/bits/internal/use-size.svelte.ts +60 -0
- package/src/lib/bits/internal/use-state-machine.svelte.ts +46 -0
- package/src/lib/bits/internal/use-timeout-fn.svelte.ts +80 -0
- package/src/lib/components/Typeahead.svelte.ts +200 -0
- package/src/lib/components/animated/animated.svelte +244 -0
- package/src/lib/components/animated/index.ts +3 -0
- package/src/lib/components/combo/combo.svelte +186 -0
- package/src/lib/components/combo/index.ts +3 -0
- package/src/lib/components/dnd/Droppable.svelte +25 -0
- package/src/lib/components/dnd/context.svelte.ts +30 -0
- package/src/lib/components/dnd/dnd-context.svelte +45 -0
- package/src/lib/components/dnd/dnd-drag-overlay.svelte +44 -0
- package/src/lib/components/dnd/dnd-drag-placeholder.svelte +24 -0
- package/src/lib/components/dnd/dnd-draghandle.svelte +30 -0
- package/src/lib/components/dnd/dnd-overlay.svelte +0 -0
- package/src/lib/components/dnd/dnd-sortable-context.svelte +18 -0
- package/src/lib/components/dnd/dnd-sortable-item.svelte +68 -0
- package/src/lib/components/dnd/example.svelte +109 -0
- package/src/lib/components/dnd/exports.ts +12 -0
- package/src/lib/components/dnd/index.ts +1 -0
- package/src/lib/components/dnd/sortable.svelte.ts +82 -0
- package/src/lib/components/dnd/utils.svelte.ts +29 -0
- package/src/lib/components/search/combinations/searchPopover.svelte +68 -0
- package/src/lib/components/search/components/search-empty.svelte +28 -0
- package/src/lib/components/search/components/search-input.svelte +53 -0
- package/src/lib/components/search/components/search-list.svelte +46 -0
- package/src/lib/components/search/components/search-pagnation.svelte +68 -0
- package/src/lib/components/search/components/search.svelte +47 -0
- package/src/lib/components/search/exports.ts +13 -0
- package/src/lib/components/search/index.ts +2 -0
- package/src/lib/components/search/search.svelte.ts +286 -0
- package/src/lib/components/search/types.ts +48 -0
- package/src/lib/components/utilities/arrow/arrow.svelte +23 -0
- package/src/lib/components/utilities/arrow/index.ts +2 -0
- package/src/lib/components/utilities/arrow/types.ts +20 -0
- package/src/lib/components/utilities/floating-layer/components/floating-layer-anchor.svelte +15 -0
- package/src/lib/components/utilities/floating-layer/components/floating-layer-arrow.svelte +20 -0
- package/src/lib/components/utilities/floating-layer/components/floating-layer-content-static.svelte +19 -0
- package/src/lib/components/utilities/floating-layer/components/floating-layer-content.svelte +61 -0
- package/src/lib/components/utilities/floating-layer/components/floating-layer.svelte +10 -0
- package/src/lib/components/utilities/floating-layer/components/index.ts +11 -0
- package/src/lib/components/utilities/floating-layer/index.ts +1 -0
- package/src/lib/components/utilities/floating-layer/types.ts +133 -0
- package/src/lib/components/utilities/floating-layer/use-floating-layer.svelte.ts +406 -0
- package/src/lib/index.ts +1 -0
- package/src/lib/utils/asyncDerived.svelte.ts +38 -0
- package/src/lib/utils/bits.ts +93 -0
- package/src/lib/utils/index.ts +3 -0
- package/src/lib/utils/utils.ts +97 -0
- package/src/routes/+layout.svelte +0 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { isNumberString } from "./is.js";
|
|
3
|
+
describe("isNumberString", () => {
|
|
4
|
+
it("should return true for valid number strings", () => {
|
|
5
|
+
expect(isNumberString("123")).toBe(true);
|
|
6
|
+
expect(isNumberString("0")).toBe(true);
|
|
7
|
+
expect(isNumberString("-42")).toBe(true);
|
|
8
|
+
expect(isNumberString("3.14")).toBe(true);
|
|
9
|
+
});
|
|
10
|
+
it("should return false for strings that are not valid numbers", () => {
|
|
11
|
+
expect(isNumberString("abc")).toBe(false);
|
|
12
|
+
expect(isNumberString("1a2b3c")).toBe(false);
|
|
13
|
+
expect(isNumberString("number")).toBe(false);
|
|
14
|
+
expect(isNumberString("--123")).toBe(false);
|
|
15
|
+
});
|
|
16
|
+
it("should return false for empty string", () => {
|
|
17
|
+
expect(isNumberString("")).toBe(false);
|
|
18
|
+
});
|
|
19
|
+
it("should return true for strings with leading or trailing whitespace", () => {
|
|
20
|
+
expect(isNumberString(" 123")).toBe(true);
|
|
21
|
+
expect(isNumberString("456 ")).toBe(true);
|
|
22
|
+
expect(isNumberString(" 789 ")).toBe(true);
|
|
23
|
+
});
|
|
24
|
+
it("should return false for strings with non-numeric characters and whitespace", () => {
|
|
25
|
+
expect(isNumberString(" abc123")).toBe(false);
|
|
26
|
+
expect(isNumberString("123def ")).toBe(false);
|
|
27
|
+
expect(isNumberString(" 456 xyz ")).toBe(false);
|
|
28
|
+
});
|
|
29
|
+
it("should return true for strings with exponential notation", () => {
|
|
30
|
+
expect(isNumberString("1e3")).toBe(true);
|
|
31
|
+
expect(isNumberString("2.5e-4")).toBe(true);
|
|
32
|
+
expect(isNumberString("-3.2E+5")).toBe(true);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export declare const ALT = "Alt";
|
|
2
|
+
export declare const ARROW_DOWN = "ArrowDown";
|
|
3
|
+
export declare const ARROW_LEFT = "ArrowLeft";
|
|
4
|
+
export declare const ARROW_RIGHT = "ArrowRight";
|
|
5
|
+
export declare const ARROW_UP = "ArrowUp";
|
|
6
|
+
export declare const BACKSPACE = "Backspace";
|
|
7
|
+
export declare const CAPS_LOCK = "CapsLock";
|
|
8
|
+
export declare const CONTROL = "Control";
|
|
9
|
+
export declare const DELETE = "Delete";
|
|
10
|
+
export declare const END = "End";
|
|
11
|
+
export declare const ENTER = "Enter";
|
|
12
|
+
export declare const ESCAPE = "Escape";
|
|
13
|
+
export declare const F1 = "F1";
|
|
14
|
+
export declare const F10 = "F10";
|
|
15
|
+
export declare const F11 = "F11";
|
|
16
|
+
export declare const F12 = "F12";
|
|
17
|
+
export declare const F2 = "F2";
|
|
18
|
+
export declare const F3 = "F3";
|
|
19
|
+
export declare const F4 = "F4";
|
|
20
|
+
export declare const F5 = "F5";
|
|
21
|
+
export declare const F6 = "F6";
|
|
22
|
+
export declare const F7 = "F7";
|
|
23
|
+
export declare const F8 = "F8";
|
|
24
|
+
export declare const F9 = "F9";
|
|
25
|
+
export declare const HOME = "Home";
|
|
26
|
+
export declare const META = "Meta";
|
|
27
|
+
export declare const PAGE_DOWN = "PageDown";
|
|
28
|
+
export declare const PAGE_UP = "PageUp";
|
|
29
|
+
export declare const SHIFT = "Shift";
|
|
30
|
+
export declare const SPACE = " ";
|
|
31
|
+
export declare const TAB = "Tab";
|
|
32
|
+
export declare const CTRL = "Control";
|
|
33
|
+
export declare const ASTERISK = "*";
|
|
34
|
+
export declare const a = "a";
|
|
35
|
+
export declare const P = "P";
|
|
36
|
+
export declare const A = "A";
|
|
37
|
+
export declare const p = "p";
|
|
38
|
+
export declare const n = "n";
|
|
39
|
+
export declare const j = "j";
|
|
40
|
+
export declare const k = "k";
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export const ALT = "Alt";
|
|
2
|
+
export const ARROW_DOWN = "ArrowDown";
|
|
3
|
+
export const ARROW_LEFT = "ArrowLeft";
|
|
4
|
+
export const ARROW_RIGHT = "ArrowRight";
|
|
5
|
+
export const ARROW_UP = "ArrowUp";
|
|
6
|
+
export const BACKSPACE = "Backspace";
|
|
7
|
+
export const CAPS_LOCK = "CapsLock";
|
|
8
|
+
export const CONTROL = "Control";
|
|
9
|
+
export const DELETE = "Delete";
|
|
10
|
+
export const END = "End";
|
|
11
|
+
export const ENTER = "Enter";
|
|
12
|
+
export const ESCAPE = "Escape";
|
|
13
|
+
export const F1 = "F1";
|
|
14
|
+
export const F10 = "F10";
|
|
15
|
+
export const F11 = "F11";
|
|
16
|
+
export const F12 = "F12";
|
|
17
|
+
export const F2 = "F2";
|
|
18
|
+
export const F3 = "F3";
|
|
19
|
+
export const F4 = "F4";
|
|
20
|
+
export const F5 = "F5";
|
|
21
|
+
export const F6 = "F6";
|
|
22
|
+
export const F7 = "F7";
|
|
23
|
+
export const F8 = "F8";
|
|
24
|
+
export const F9 = "F9";
|
|
25
|
+
export const HOME = "Home";
|
|
26
|
+
export const META = "Meta";
|
|
27
|
+
export const PAGE_DOWN = "PageDown";
|
|
28
|
+
export const PAGE_UP = "PageUp";
|
|
29
|
+
export const SHIFT = "Shift";
|
|
30
|
+
export const SPACE = " ";
|
|
31
|
+
export const TAB = "Tab";
|
|
32
|
+
export const CTRL = "Control";
|
|
33
|
+
export const ASTERISK = "*";
|
|
34
|
+
export const a = "a";
|
|
35
|
+
export const P = "P";
|
|
36
|
+
export const A = "A";
|
|
37
|
+
export const p = "p";
|
|
38
|
+
export const n = "n";
|
|
39
|
+
export const j = "j";
|
|
40
|
+
export const k = "k";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as kbd from "./kbd-constants.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as kbd from "./kbd-constants.js";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Direction } from "../../shared/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Detects the text direction in the element.
|
|
4
|
+
* @returns {Direction} The text direction ('ltr' for left-to-right or 'rtl' for right-to-left).
|
|
5
|
+
*/
|
|
6
|
+
export declare function getElemDirection(elem: HTMLElement): Direction;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Detects the text direction in the element.
|
|
3
|
+
* @returns {Direction} The text direction ('ltr' for left-to-right or 'rtl' for right-to-left).
|
|
4
|
+
*/
|
|
5
|
+
export function getElemDirection(elem) {
|
|
6
|
+
const style = window.getComputedStyle(elem);
|
|
7
|
+
const direction = style.getPropertyValue("direction");
|
|
8
|
+
return direction;
|
|
9
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* From https://github.com/melt-ui/melt-ui/blob/main/packages/svelte/src/lib/internal/math.ts
|
|
3
|
+
*/
|
|
4
|
+
export declare function snapValueToStep(value: number, min: number, max: number, step: number): number;
|
|
5
|
+
export declare function linearScale(domain: [number, number], range: [number, number], clamp?: boolean): (x: number) => number;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* From https://github.com/melt-ui/melt-ui/blob/main/packages/svelte/src/lib/internal/math.ts
|
|
3
|
+
*/
|
|
4
|
+
export function snapValueToStep(value, min, max, step) {
|
|
5
|
+
const remainder = (value - (Number.isNaN(min) ? 0 : min)) % step;
|
|
6
|
+
let snappedValue = Math.abs(remainder) * 2 >= step
|
|
7
|
+
? value + Math.sign(remainder) * (step - Math.abs(remainder))
|
|
8
|
+
: value - remainder;
|
|
9
|
+
if (!Number.isNaN(min)) {
|
|
10
|
+
if (snappedValue < min) {
|
|
11
|
+
snappedValue = min;
|
|
12
|
+
}
|
|
13
|
+
else if (!Number.isNaN(max) && snappedValue > max) {
|
|
14
|
+
snappedValue = min + Math.floor((max - min) / step) * step;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
else if (!Number.isNaN(max) && snappedValue > max) {
|
|
18
|
+
snappedValue = Math.floor(max / step) * step;
|
|
19
|
+
}
|
|
20
|
+
const string = step.toString();
|
|
21
|
+
const index = string.indexOf(".");
|
|
22
|
+
const precision = index >= 0 ? string.length - index : 0;
|
|
23
|
+
if (precision > 0) {
|
|
24
|
+
const pow = 10 ** precision;
|
|
25
|
+
snappedValue = Math.round(snappedValue * pow) / pow;
|
|
26
|
+
}
|
|
27
|
+
return snappedValue;
|
|
28
|
+
}
|
|
29
|
+
export function linearScale(domain, range, clamp = true) {
|
|
30
|
+
const [d0, d1] = domain;
|
|
31
|
+
const [r0, r1] = range;
|
|
32
|
+
const slope = (r1 - r0) / (d1 - d0);
|
|
33
|
+
return (x) => {
|
|
34
|
+
const result = r0 + slope * (x - d0);
|
|
35
|
+
if (!clamp)
|
|
36
|
+
return result;
|
|
37
|
+
if (result > Math.max(r0, r1))
|
|
38
|
+
return Math.max(r0, r1);
|
|
39
|
+
if (result < Math.min(r0, r1))
|
|
40
|
+
return Math.min(r0, r1);
|
|
41
|
+
return result;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { linearScale, snapValueToStep } from "./math.js";
|
|
3
|
+
describe("snapValueToStep", () => {
|
|
4
|
+
it("should snap value to nearest step", () => {
|
|
5
|
+
expect(snapValueToStep(3.7, 0, 10, 1)).toBe(4);
|
|
6
|
+
expect(snapValueToStep(3.2, 0, 10, 1)).toBe(3);
|
|
7
|
+
});
|
|
8
|
+
it("should handle decimal steps", () => {
|
|
9
|
+
expect(snapValueToStep(3.7, 0, 10, 0.5)).toBe(3.5);
|
|
10
|
+
expect(snapValueToStep(3.8, 0, 10, 0.5)).toBe(4);
|
|
11
|
+
});
|
|
12
|
+
it("should respect min value", () => {
|
|
13
|
+
expect(snapValueToStep(1.2, 2, 10, 1)).toBe(2);
|
|
14
|
+
});
|
|
15
|
+
it("should respect max value", () => {
|
|
16
|
+
expect(snapValueToStep(9.8, 0, 9, 1)).toBe(9);
|
|
17
|
+
});
|
|
18
|
+
it("should handle NaN min value", () => {
|
|
19
|
+
expect(snapValueToStep(3.7, Number.NaN, 10, 1)).toBe(4);
|
|
20
|
+
});
|
|
21
|
+
it("should handle NaN max value", () => {
|
|
22
|
+
expect(snapValueToStep(3.7, 0, Number.NaN, 1)).toBe(4);
|
|
23
|
+
});
|
|
24
|
+
it("should handle both NaN min and max values", () => {
|
|
25
|
+
expect(snapValueToStep(3.7, Number.NaN, Number.NaN, 1)).toBe(4);
|
|
26
|
+
});
|
|
27
|
+
it("should handle values outside the range", () => {
|
|
28
|
+
expect(snapValueToStep(12, 0, 10, 1)).toBe(10);
|
|
29
|
+
expect(snapValueToStep(-2, 0, 10, 1)).toBe(0);
|
|
30
|
+
});
|
|
31
|
+
it("should handle large steps", () => {
|
|
32
|
+
expect(snapValueToStep(17, 0, 100, 20)).toBe(20);
|
|
33
|
+
});
|
|
34
|
+
it("should maintain precision for decimal steps", () => {
|
|
35
|
+
expect(snapValueToStep(3.14159, 0, 10, 0.01)).toBe(3.14);
|
|
36
|
+
expect(snapValueToStep(3.14159, 0, 10, 0.001)).toBe(3.142);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
describe("linearScale", () => {
|
|
40
|
+
it("correctly scales the value", () => {
|
|
41
|
+
expect(linearScale([0, 1], [0, 100])(0.5)).toBe(50);
|
|
42
|
+
expect(linearScale([0, 1], [10, 90])(0.5)).toBe(50);
|
|
43
|
+
expect(linearScale([0, 1], [0, 100])(0.33)).toBe(33);
|
|
44
|
+
expect(linearScale([0, 1], [0, 100])(0)).toBe(0);
|
|
45
|
+
});
|
|
46
|
+
it("is minimum when below minimum", () => {
|
|
47
|
+
expect(linearScale([0, 1], [0, 100])(2)).toBe(100);
|
|
48
|
+
expect(linearScale([0, 1], [0, 100])(-5)).toBe(0);
|
|
49
|
+
});
|
|
50
|
+
it("correctly handles negative scales", () => {
|
|
51
|
+
expect(linearScale([-1, 1], [0, 100])(0)).toBe(50);
|
|
52
|
+
});
|
|
53
|
+
it("handles reversed ranges", () => {
|
|
54
|
+
expect(linearScale([0, 1], [100, 0])(0.5)).toBe(50);
|
|
55
|
+
expect(linearScale([0, 1], [100, 0])(0)).toBe(100);
|
|
56
|
+
expect(linearScale([0, 1], [100, 0])(2)).toBe(0); // clamped
|
|
57
|
+
});
|
|
58
|
+
it("works with non-zero based domains", () => {
|
|
59
|
+
expect(linearScale([10, 20], [0, 100])(15)).toBe(50);
|
|
60
|
+
expect(linearScale([100, 200], [0, 1])(150)).toBe(0.5);
|
|
61
|
+
});
|
|
62
|
+
it("handles unclamped values when clamp is false", () => {
|
|
63
|
+
const scale = linearScale([0, 1], [0, 100], false);
|
|
64
|
+
expect(scale(2)).toBe(200);
|
|
65
|
+
expect(scale(-1)).toBe(-100);
|
|
66
|
+
});
|
|
67
|
+
it("maintains precision with small numbers", () => {
|
|
68
|
+
expect(linearScale([0, 0.1], [0, 1])(0.05)).toBeCloseTo(0.5, 6);
|
|
69
|
+
expect(linearScale([0, 1e-6], [0, 1])(5e-7)).toBeCloseTo(0.5, 6);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function sleep(ms: number): Promise<unknown>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare function getTabbableIn(container: HTMLElement, direction: "next" | "prev"): any;
|
|
2
|
+
/**
|
|
3
|
+
* Gets all tabbable elements in the body and finds the next/previous tabbable element
|
|
4
|
+
* from the `currentNode` based on the `direction` provided.
|
|
5
|
+
* @param currentNode - the node we want to get the next/previous tabbable from
|
|
6
|
+
*/
|
|
7
|
+
export declare function getTabbableFrom(currentNode: HTMLElement, direction: "next" | "prev"): any;
|
|
8
|
+
export declare function getTabbableFromFocusable(currentNode: HTMLElement, direction: "next" | "prev"): any;
|
|
9
|
+
export declare function getNextTabbable(): any;
|
|
10
|
+
export declare function getPreviousTabbable(): any;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { focusable, isFocusable, isTabbable, tabbable } from "tabbable";
|
|
2
|
+
import { activeElement, getDocument } from "./dom.js";
|
|
3
|
+
function getTabbableOptions() {
|
|
4
|
+
return {
|
|
5
|
+
getShadowRoot: true,
|
|
6
|
+
displayCheck:
|
|
7
|
+
// JSDOM does not support the `tabbable` library. To solve this we can
|
|
8
|
+
// check if `ResizeObserver` is a real function (not polyfilled), which
|
|
9
|
+
// determines if the current environment is JSDOM-like.
|
|
10
|
+
typeof ResizeObserver === "function" &&
|
|
11
|
+
ResizeObserver.toString().includes("[native code]")
|
|
12
|
+
? "full"
|
|
13
|
+
: "none",
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export function getTabbableIn(container, direction) {
|
|
17
|
+
const allTabbable = tabbable(container, getTabbableOptions());
|
|
18
|
+
if (direction === "prev") {
|
|
19
|
+
allTabbable.reverse();
|
|
20
|
+
}
|
|
21
|
+
const activeEl = activeElement(getDocument(container));
|
|
22
|
+
const activeIndex = allTabbable.indexOf(activeEl);
|
|
23
|
+
const nextTabbableElements = allTabbable.slice(activeIndex + 1);
|
|
24
|
+
return nextTabbableElements[0];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Gets all tabbable elements in the body and finds the next/previous tabbable element
|
|
28
|
+
* from the `currentNode` based on the `direction` provided.
|
|
29
|
+
* @param currentNode - the node we want to get the next/previous tabbable from
|
|
30
|
+
*/
|
|
31
|
+
export function getTabbableFrom(currentNode, direction) {
|
|
32
|
+
if (!isTabbable(currentNode, getTabbableOptions())) {
|
|
33
|
+
return getTabbableFromFocusable(currentNode, direction);
|
|
34
|
+
}
|
|
35
|
+
const allTabbable = tabbable(getDocument(currentNode).body, getTabbableOptions());
|
|
36
|
+
if (direction === "prev")
|
|
37
|
+
allTabbable.reverse();
|
|
38
|
+
const activeIndex = allTabbable.indexOf(currentNode);
|
|
39
|
+
if (activeIndex === -1)
|
|
40
|
+
return document.body;
|
|
41
|
+
const nextTabbableElements = allTabbable.slice(activeIndex + 1);
|
|
42
|
+
return nextTabbableElements[0];
|
|
43
|
+
}
|
|
44
|
+
export function getTabbableFromFocusable(currentNode, direction) {
|
|
45
|
+
if (!isFocusable(currentNode, getTabbableOptions()))
|
|
46
|
+
return document.body;
|
|
47
|
+
// find all focusable nodes, since some elements may be focusable but not tabbable
|
|
48
|
+
// such as context menu triggers
|
|
49
|
+
const allFocusable = focusable(getDocument(currentNode).body, getTabbableOptions());
|
|
50
|
+
// find index of current node among focusable siblings
|
|
51
|
+
if (direction === "prev")
|
|
52
|
+
allFocusable.reverse();
|
|
53
|
+
const activeIndex = allFocusable.indexOf(currentNode);
|
|
54
|
+
if (activeIndex === -1)
|
|
55
|
+
return document.body;
|
|
56
|
+
const nextFocusableElements = allFocusable.slice(activeIndex + 1);
|
|
57
|
+
// find the next focusable node that is also tabbable
|
|
58
|
+
return (nextFocusableElements.find((node) => isTabbable(node, getTabbableOptions())) ??
|
|
59
|
+
document.body);
|
|
60
|
+
}
|
|
61
|
+
export function getNextTabbable() {
|
|
62
|
+
return getTabbableIn(document.body, "next");
|
|
63
|
+
}
|
|
64
|
+
export function getPreviousTabbable() {
|
|
65
|
+
return getTabbableIn(document.body, "prev");
|
|
66
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { Snippet } from "svelte";
|
|
2
|
+
import type { Box, ReadableBoxedValues, WritableBoxedValues } from "./box.svelte.js";
|
|
3
|
+
import type { StyleProperties } from "../../shared/index.js";
|
|
4
|
+
export type OnChangeFn<T> = (value: T) => void;
|
|
5
|
+
export type ElementRef = Box<HTMLElement | null>;
|
|
6
|
+
export type WithChild<
|
|
7
|
+
/**
|
|
8
|
+
* The props that the component accepts.
|
|
9
|
+
*/
|
|
10
|
+
Props extends Record<PropertyKey, unknown> = {},
|
|
11
|
+
/**
|
|
12
|
+
* The props that are passed to the `child` and `children` snippets. The `ElementProps` are
|
|
13
|
+
* merged with these props for the `child` snippet.
|
|
14
|
+
*/
|
|
15
|
+
SnippetProps extends Record<PropertyKey, unknown> = {
|
|
16
|
+
_default: never;
|
|
17
|
+
},
|
|
18
|
+
/**
|
|
19
|
+
* The underlying DOM element being rendered. You can bind to this prop to
|
|
20
|
+
* programmatically interact with the element.
|
|
21
|
+
*/
|
|
22
|
+
Ref = HTMLElement> = Omit<Props, "child" | "children"> & {
|
|
23
|
+
child?: SnippetProps extends {
|
|
24
|
+
_default: never;
|
|
25
|
+
} ? Snippet<[{
|
|
26
|
+
props: Record<string, unknown>;
|
|
27
|
+
}]> : Snippet<[SnippetProps & {
|
|
28
|
+
props: Record<string, unknown>;
|
|
29
|
+
}]>;
|
|
30
|
+
children?: SnippetProps extends {
|
|
31
|
+
_default: never;
|
|
32
|
+
} ? Snippet : Snippet<[SnippetProps]>;
|
|
33
|
+
style?: StyleProperties | string | null | undefined;
|
|
34
|
+
ref?: Ref | null | undefined;
|
|
35
|
+
};
|
|
36
|
+
export type WithChildNoChildrenSnippetProps<
|
|
37
|
+
/**
|
|
38
|
+
* The props that the component accepts.
|
|
39
|
+
*/
|
|
40
|
+
Props extends Record<PropertyKey, unknown> = {},
|
|
41
|
+
/**
|
|
42
|
+
* The props that are passed to the `child` and `children` snippets. The `ElementProps` are
|
|
43
|
+
* merged with these props for the `child` snippet.
|
|
44
|
+
*/
|
|
45
|
+
SnippetProps extends Record<PropertyKey, unknown> = {
|
|
46
|
+
_default: never;
|
|
47
|
+
},
|
|
48
|
+
/**
|
|
49
|
+
* The underlying DOM element being rendered. You can bind to this prop to
|
|
50
|
+
* programmatically interact with the element.
|
|
51
|
+
*/
|
|
52
|
+
Ref = HTMLElement> = Omit<Props, "child" | "children"> & {
|
|
53
|
+
child?: SnippetProps extends {
|
|
54
|
+
_default: never;
|
|
55
|
+
} ? Snippet<[{
|
|
56
|
+
props: Record<string, unknown>;
|
|
57
|
+
}]> : Snippet<[SnippetProps & {
|
|
58
|
+
props: Record<string, unknown>;
|
|
59
|
+
}]>;
|
|
60
|
+
children?: Snippet;
|
|
61
|
+
style?: StyleProperties | string | null | undefined;
|
|
62
|
+
ref?: Ref | null | undefined;
|
|
63
|
+
};
|
|
64
|
+
export type WithChildren<Props = {}> = Props & {
|
|
65
|
+
children?: Snippet | undefined;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Constructs a new type by omitting properties from type
|
|
69
|
+
* 'T' that exist in type 'U'.
|
|
70
|
+
*
|
|
71
|
+
* @template T - The base object type from which properties will be omitted.
|
|
72
|
+
* @template U - The object type whose properties will be omitted from 'T'.
|
|
73
|
+
* @example
|
|
74
|
+
* type Result = Without<{ a: number; b: string; }, { b: string; }>;
|
|
75
|
+
* // Result type will be { a: number; }
|
|
76
|
+
*/
|
|
77
|
+
export type Without<T extends object, U extends object> = Omit<T, keyof U>;
|
|
78
|
+
export type Arrayable<T> = T[] | T;
|
|
79
|
+
export type Fn = () => void;
|
|
80
|
+
export type AnyFn = (...args: any[]) => any;
|
|
81
|
+
export type WithRefProps<T = {}> = T & ReadableBoxedValues<{
|
|
82
|
+
id: string;
|
|
83
|
+
}> & WritableBoxedValues<{
|
|
84
|
+
ref: HTMLElement | null;
|
|
85
|
+
}>;
|
|
86
|
+
export type BitsEvent<T extends Event = Event, U extends HTMLElement = HTMLElement> = T & {
|
|
87
|
+
currentTarget: U;
|
|
88
|
+
};
|
|
89
|
+
export type BitsPointerEvent<T extends HTMLElement = HTMLElement> = BitsEvent<PointerEvent, T>;
|
|
90
|
+
export type BitsKeyboardEvent<T extends HTMLElement = HTMLElement> = BitsEvent<KeyboardEvent, T>;
|
|
91
|
+
export type BitsMouseEvent<T extends HTMLElement = HTMLElement> = BitsEvent<MouseEvent, T>;
|
|
92
|
+
export type BitsFocusEvent<T extends HTMLElement = HTMLElement> = BitsEvent<FocusEvent, T>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { flushSync } from "svelte";
|
|
2
|
+
/**
|
|
3
|
+
* Calls a function the next frame after all animations have finished.
|
|
4
|
+
*/
|
|
5
|
+
export function useAfterAnimations(getNode) {
|
|
6
|
+
let frame = -1;
|
|
7
|
+
function cancelFrame() {
|
|
8
|
+
cancelAnimationFrame(frame);
|
|
9
|
+
}
|
|
10
|
+
$effect(() => cancelFrame);
|
|
11
|
+
return (fn) => {
|
|
12
|
+
cancelFrame();
|
|
13
|
+
const node = getNode();
|
|
14
|
+
if (!node)
|
|
15
|
+
return;
|
|
16
|
+
if (typeof node.getAnimations !== "function" || globalThis.bitsAnimationsDisabled) {
|
|
17
|
+
fn();
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
frame = requestAnimationFrame(() => {
|
|
21
|
+
Promise.allSettled(node.getAnimations().map((anim) => anim.finished)).then(() => {
|
|
22
|
+
flushSync(fn);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { Direction } from "../../shared/index.js";
|
|
2
|
+
type ArrowKeyOptions = "horizontal" | "vertical" | "both";
|
|
3
|
+
interface ArrowNavigationOptions {
|
|
4
|
+
/**
|
|
5
|
+
* The arrow key options to allow navigation
|
|
6
|
+
*
|
|
7
|
+
* @defaultValue "both"
|
|
8
|
+
*/
|
|
9
|
+
arrowKeyOptions?: ArrowKeyOptions;
|
|
10
|
+
/**
|
|
11
|
+
* The attribute name to find the collection items in the parent element.
|
|
12
|
+
*/
|
|
13
|
+
attributeName: string;
|
|
14
|
+
/**
|
|
15
|
+
* The parent element where contains all the collection items, this will collect every item to be used when nav
|
|
16
|
+
* It will be ignored if attributeName is provided
|
|
17
|
+
*
|
|
18
|
+
* @defaultValue []
|
|
19
|
+
*/
|
|
20
|
+
itemsArray?: HTMLElement[];
|
|
21
|
+
/**
|
|
22
|
+
* Allow loop navigation. If false, it will stop at the first and last element
|
|
23
|
+
*
|
|
24
|
+
* @defaultValue true
|
|
25
|
+
*/
|
|
26
|
+
loop?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* The orientation of the collection
|
|
29
|
+
*
|
|
30
|
+
* @defaultValue "ltr"
|
|
31
|
+
*/
|
|
32
|
+
dir?: Direction;
|
|
33
|
+
/**
|
|
34
|
+
* Prevent the scroll when navigating. This happens when the direction of the
|
|
35
|
+
* key matches the scroll direction of any ancestor scrollable elements.
|
|
36
|
+
*
|
|
37
|
+
* @defaultValue true
|
|
38
|
+
*/
|
|
39
|
+
preventScroll?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* By default all currentElement would trigger navigation. If `true`, currentElement nodeName in the ignore list will return null
|
|
42
|
+
*
|
|
43
|
+
* @defaultValue false
|
|
44
|
+
*/
|
|
45
|
+
enableIgnoredElement?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Focus the element after navigation
|
|
48
|
+
*
|
|
49
|
+
* @defaultValue false
|
|
50
|
+
*/
|
|
51
|
+
focus?: boolean;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
*
|
|
55
|
+
* @param e Keyboard event
|
|
56
|
+
* @param currentElement Event initiator element or any element that wants to handle the navigation
|
|
57
|
+
* @param parentElement Parent element where contains all the collection items, this will collect every item to be used when nav
|
|
58
|
+
* @param options further options
|
|
59
|
+
* @returns the navigated html element or null if none
|
|
60
|
+
*/
|
|
61
|
+
export declare function useArrowNavigation(e: KeyboardEvent, currentElement: HTMLElement, parentElement: HTMLElement | undefined, options: ArrowNavigationOptions): HTMLElement | null;
|
|
62
|
+
export {};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
const ignoredElement = ["INPUT", "TEXTAREA"];
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @param e Keyboard event
|
|
5
|
+
* @param currentElement Event initiator element or any element that wants to handle the navigation
|
|
6
|
+
* @param parentElement Parent element where contains all the collection items, this will collect every item to be used when nav
|
|
7
|
+
* @param options further options
|
|
8
|
+
* @returns the navigated html element or null if none
|
|
9
|
+
*/
|
|
10
|
+
export function useArrowNavigation(e, currentElement, parentElement, options) {
|
|
11
|
+
if (!currentElement ||
|
|
12
|
+
(options.enableIgnoredElement && ignoredElement.includes(currentElement.nodeName))) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
const { arrowKeyOptions = "both", attributeName, itemsArray = [], loop = true, dir = "ltr", preventScroll = true, focus = false, } = options;
|
|
16
|
+
const [right, left, up, down, home, end] = [
|
|
17
|
+
e.key === "ArrowRight",
|
|
18
|
+
e.key === "ArrowLeft",
|
|
19
|
+
e.key === "ArrowUp",
|
|
20
|
+
e.key === "ArrowDown",
|
|
21
|
+
e.key === "Home",
|
|
22
|
+
e.key === "End",
|
|
23
|
+
];
|
|
24
|
+
const goingVertical = up || down;
|
|
25
|
+
const goingHorizontal = right || left;
|
|
26
|
+
if (!home &&
|
|
27
|
+
!end &&
|
|
28
|
+
((!goingVertical && !goingHorizontal) ||
|
|
29
|
+
(arrowKeyOptions === "vertical" && goingHorizontal) ||
|
|
30
|
+
(arrowKeyOptions === "horizontal" && goingVertical)))
|
|
31
|
+
return null;
|
|
32
|
+
const allCollectionItems = parentElement
|
|
33
|
+
? Array.from(parentElement.querySelectorAll(attributeName))
|
|
34
|
+
: itemsArray;
|
|
35
|
+
if (!allCollectionItems.length)
|
|
36
|
+
return null;
|
|
37
|
+
if (preventScroll)
|
|
38
|
+
e.preventDefault();
|
|
39
|
+
let item = null;
|
|
40
|
+
if (goingHorizontal || goingVertical) {
|
|
41
|
+
const goForward = goingVertical ? down : dir === "ltr" ? right : left;
|
|
42
|
+
item = findNextFocusableElement(allCollectionItems, currentElement, {
|
|
43
|
+
goForward,
|
|
44
|
+
loop,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
else if (home) {
|
|
48
|
+
item = allCollectionItems.at(0) || null;
|
|
49
|
+
}
|
|
50
|
+
else if (end) {
|
|
51
|
+
item = allCollectionItems.at(-1) || null;
|
|
52
|
+
}
|
|
53
|
+
if (focus)
|
|
54
|
+
item?.focus();
|
|
55
|
+
return item;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Recursive function to find the next focusable element to avoid disabled elements
|
|
59
|
+
*/
|
|
60
|
+
function findNextFocusableElement(elements, currentElement, { goForward, loop }, iterations = elements.length) {
|
|
61
|
+
if (--iterations === 0)
|
|
62
|
+
return null;
|
|
63
|
+
const index = elements.indexOf(currentElement);
|
|
64
|
+
const newIndex = goForward ? index + 1 : index - 1;
|
|
65
|
+
if (!loop && (newIndex < 0 || newIndex >= elements.length))
|
|
66
|
+
return null;
|
|
67
|
+
const adjustedNewIndex = (newIndex + elements.length) % elements.length;
|
|
68
|
+
const candidate = elements[adjustedNewIndex];
|
|
69
|
+
if (!candidate)
|
|
70
|
+
return null;
|
|
71
|
+
const isDisabled = candidate.hasAttribute("disabled") && candidate.getAttribute("disabled") !== "false";
|
|
72
|
+
if (isDisabled) {
|
|
73
|
+
return findNextFocusableElement(elements, candidate, { goForward, loop }, iterations);
|
|
74
|
+
}
|
|
75
|
+
return candidate;
|
|
76
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type Getter } from "svelte-toolbelt";
|
|
2
|
+
export type ScrollBodyOption = {
|
|
3
|
+
padding?: boolean | number;
|
|
4
|
+
margin?: boolean | number;
|
|
5
|
+
};
|
|
6
|
+
export declare function useBodyScrollLock(initialState?: boolean | undefined, restoreScrollDelay?: Getter<number | null>): import("svelte-toolbelt").WritableBox<boolean> | undefined;
|