tyrell-components 1.0.0-RC6
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/LICENSE +21 -0
- package/README.md +221 -0
- package/css/tyrell.css +1783 -0
- package/dist/tyrell.css +1783 -0
- package/dist/tyrell.js +2 -0
- package/lib/base/ty-component.d.ts +133 -0
- package/lib/base/ty-component.d.ts.map +1 -0
- package/lib/base/ty-component.js +297 -0
- package/lib/base/ty-component.js.map +1 -0
- package/lib/components/button.d.ts +126 -0
- package/lib/components/button.d.ts.map +1 -0
- package/lib/components/button.js +244 -0
- package/lib/components/button.js.map +1 -0
- package/lib/components/calendar-month.d.ts +132 -0
- package/lib/components/calendar-month.d.ts.map +1 -0
- package/lib/components/calendar-month.js +440 -0
- package/lib/components/calendar-month.js.map +1 -0
- package/lib/components/calendar-navigation.d.ts +137 -0
- package/lib/components/calendar-navigation.d.ts.map +1 -0
- package/lib/components/calendar-navigation.js +366 -0
- package/lib/components/calendar-navigation.js.map +1 -0
- package/lib/components/calendar.d.ts +166 -0
- package/lib/components/calendar.d.ts.map +1 -0
- package/lib/components/calendar.js +774 -0
- package/lib/components/calendar.js.map +1 -0
- package/lib/components/checkbox.d.ts +189 -0
- package/lib/components/checkbox.d.ts.map +1 -0
- package/lib/components/checkbox.js +400 -0
- package/lib/components/checkbox.js.map +1 -0
- package/lib/components/copy.d.ts +180 -0
- package/lib/components/copy.d.ts.map +1 -0
- package/lib/components/copy.js +393 -0
- package/lib/components/copy.js.map +1 -0
- package/lib/components/date-picker.d.ts +379 -0
- package/lib/components/date-picker.d.ts.map +1 -0
- package/lib/components/date-picker.js +1586 -0
- package/lib/components/date-picker.js.map +1 -0
- package/lib/components/dropdown.d.ts +402 -0
- package/lib/components/dropdown.d.ts.map +1 -0
- package/lib/components/dropdown.js +1552 -0
- package/lib/components/dropdown.js.map +1 -0
- package/lib/components/icon.d.ts +118 -0
- package/lib/components/icon.d.ts.map +1 -0
- package/lib/components/icon.js +245 -0
- package/lib/components/icon.js.map +1 -0
- package/lib/components/input.d.ts +270 -0
- package/lib/components/input.d.ts.map +1 -0
- package/lib/components/input.js +721 -0
- package/lib/components/input.js.map +1 -0
- package/lib/components/modal.d.ts +58 -0
- package/lib/components/modal.d.ts.map +1 -0
- package/lib/components/modal.js +473 -0
- package/lib/components/modal.js.map +1 -0
- package/lib/components/multiselect.d.ts +397 -0
- package/lib/components/multiselect.d.ts.map +1 -0
- package/lib/components/multiselect.js +1580 -0
- package/lib/components/multiselect.js.map +1 -0
- package/lib/components/option.d.ts +66 -0
- package/lib/components/option.d.ts.map +1 -0
- package/lib/components/option.js +314 -0
- package/lib/components/option.js.map +1 -0
- package/lib/components/popup.d.ts +43 -0
- package/lib/components/popup.d.ts.map +1 -0
- package/lib/components/popup.js +380 -0
- package/lib/components/popup.js.map +1 -0
- package/lib/components/radio.d.ts +198 -0
- package/lib/components/radio.d.ts.map +1 -0
- package/lib/components/radio.js +437 -0
- package/lib/components/radio.js.map +1 -0
- package/lib/components/resize-observer.d.ts +48 -0
- package/lib/components/resize-observer.d.ts.map +1 -0
- package/lib/components/resize-observer.js +108 -0
- package/lib/components/resize-observer.js.map +1 -0
- package/lib/components/scroll-container.d.ts +51 -0
- package/lib/components/scroll-container.d.ts.map +1 -0
- package/lib/components/scroll-container.js +239 -0
- package/lib/components/scroll-container.js.map +1 -0
- package/lib/components/step.d.ts +26 -0
- package/lib/components/step.d.ts.map +1 -0
- package/lib/components/step.js +75 -0
- package/lib/components/step.js.map +1 -0
- package/lib/components/switch.d.ts +111 -0
- package/lib/components/switch.d.ts.map +1 -0
- package/lib/components/switch.js +240 -0
- package/lib/components/switch.js.map +1 -0
- package/lib/components/tab.d.ts +23 -0
- package/lib/components/tab.d.ts.map +1 -0
- package/lib/components/tab.js +76 -0
- package/lib/components/tab.js.map +1 -0
- package/lib/components/tabs.d.ts +93 -0
- package/lib/components/tabs.d.ts.map +1 -0
- package/lib/components/tabs.js +653 -0
- package/lib/components/tabs.js.map +1 -0
- package/lib/components/tag.d.ts +144 -0
- package/lib/components/tag.d.ts.map +1 -0
- package/lib/components/tag.js +316 -0
- package/lib/components/tag.js.map +1 -0
- package/lib/components/textarea.d.ts +241 -0
- package/lib/components/textarea.d.ts.map +1 -0
- package/lib/components/textarea.js +585 -0
- package/lib/components/textarea.js.map +1 -0
- package/lib/components/tooltip.d.ts +40 -0
- package/lib/components/tooltip.d.ts.map +1 -0
- package/lib/components/tooltip.js +439 -0
- package/lib/components/tooltip.js.map +1 -0
- package/lib/components/wizard.d.ts +86 -0
- package/lib/components/wizard.d.ts.map +1 -0
- package/lib/components/wizard.js +636 -0
- package/lib/components/wizard.js.map +1 -0
- package/lib/icons/fontawesome/brands.d.ts +557 -0
- package/lib/icons/fontawesome/brands.d.ts.map +1 -0
- package/lib/icons/fontawesome/brands.js +557 -0
- package/lib/icons/fontawesome/brands.js.map +1 -0
- package/lib/icons/fontawesome/regular.d.ts +281 -0
- package/lib/icons/fontawesome/regular.d.ts.map +1 -0
- package/lib/icons/fontawesome/regular.js +281 -0
- package/lib/icons/fontawesome/regular.js.map +1 -0
- package/lib/icons/fontawesome/solid.d.ts +1992 -0
- package/lib/icons/fontawesome/solid.d.ts.map +1 -0
- package/lib/icons/fontawesome/solid.js +1992 -0
- package/lib/icons/fontawesome/solid.js.map +1 -0
- package/lib/icons/heroicons/micro.d.ts +324 -0
- package/lib/icons/heroicons/micro.d.ts.map +1 -0
- package/lib/icons/heroicons/micro.js +1032 -0
- package/lib/icons/heroicons/micro.js.map +1 -0
- package/lib/icons/heroicons/mini.d.ts +332 -0
- package/lib/icons/heroicons/mini.d.ts.map +1 -0
- package/lib/icons/heroicons/mini.js +1038 -0
- package/lib/icons/heroicons/mini.js.map +1 -0
- package/lib/icons/heroicons/outline.d.ts +332 -0
- package/lib/icons/heroicons/outline.d.ts.map +1 -0
- package/lib/icons/heroicons/outline.js +993 -0
- package/lib/icons/heroicons/outline.js.map +1 -0
- package/lib/icons/heroicons/solid.d.ts +332 -0
- package/lib/icons/heroicons/solid.d.ts.map +1 -0
- package/lib/icons/heroicons/solid.js +1063 -0
- package/lib/icons/heroicons/solid.js.map +1 -0
- package/lib/icons/lucide.d.ts +1872 -0
- package/lib/icons/lucide.d.ts.map +1 -0
- package/lib/icons/lucide.js +28212 -0
- package/lib/icons/lucide.js.map +1 -0
- package/lib/icons/material/filled.d.ts +2180 -0
- package/lib/icons/material/filled.d.ts.map +1 -0
- package/lib/icons/material/filled.js +14003 -0
- package/lib/icons/material/filled.js.map +1 -0
- package/lib/icons/material/outlined.d.ts +2142 -0
- package/lib/icons/material/outlined.d.ts.map +1 -0
- package/lib/icons/material/outlined.js +14545 -0
- package/lib/icons/material/outlined.js.map +1 -0
- package/lib/icons/material/round.d.ts +2147 -0
- package/lib/icons/material/round.d.ts.map +1 -0
- package/lib/icons/material/round.js +14779 -0
- package/lib/icons/material/round.js.map +1 -0
- package/lib/icons/material/sharp.d.ts +2147 -0
- package/lib/icons/material/sharp.d.ts.map +1 -0
- package/lib/icons/material/sharp.js +14189 -0
- package/lib/icons/material/sharp.js.map +1 -0
- package/lib/icons/material/two-tone.d.ts +2185 -0
- package/lib/icons/material/two-tone.d.ts.map +1 -0
- package/lib/icons/material/two-tone.js +17152 -0
- package/lib/icons/material/two-tone.js.map +1 -0
- package/lib/index.d.ts +78 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +71 -0
- package/lib/index.js.map +1 -0
- package/lib/styles/button.d.ts +14 -0
- package/lib/styles/button.d.ts.map +1 -0
- package/lib/styles/button.js +457 -0
- package/lib/styles/button.js.map +1 -0
- package/lib/styles/calendar-month.d.ts +6 -0
- package/lib/styles/calendar-month.d.ts.map +1 -0
- package/lib/styles/calendar-month.js +275 -0
- package/lib/styles/calendar-month.js.map +1 -0
- package/lib/styles/calendar-navigation.d.ts +6 -0
- package/lib/styles/calendar-navigation.d.ts.map +1 -0
- package/lib/styles/calendar-navigation.js +143 -0
- package/lib/styles/calendar-navigation.js.map +1 -0
- package/lib/styles/calendar.d.ts +6 -0
- package/lib/styles/calendar.d.ts.map +1 -0
- package/lib/styles/calendar.js +28 -0
- package/lib/styles/calendar.js.map +1 -0
- package/lib/styles/checkbox.d.ts +9 -0
- package/lib/styles/checkbox.d.ts.map +1 -0
- package/lib/styles/checkbox.js +19 -0
- package/lib/styles/checkbox.js.map +1 -0
- package/lib/styles/copy.d.ts +7 -0
- package/lib/styles/copy.d.ts.map +1 -0
- package/lib/styles/copy.js +94 -0
- package/lib/styles/copy.js.map +1 -0
- package/lib/styles/custom-scrollbar.d.ts +6 -0
- package/lib/styles/custom-scrollbar.d.ts.map +1 -0
- package/lib/styles/custom-scrollbar.js +157 -0
- package/lib/styles/custom-scrollbar.js.map +1 -0
- package/lib/styles/date-picker.d.ts +6 -0
- package/lib/styles/date-picker.d.ts.map +1 -0
- package/lib/styles/date-picker.js +435 -0
- package/lib/styles/date-picker.js.map +1 -0
- package/lib/styles/dropdown.d.ts +12 -0
- package/lib/styles/dropdown.d.ts.map +1 -0
- package/lib/styles/dropdown.js +983 -0
- package/lib/styles/dropdown.js.map +1 -0
- package/lib/styles/icon.d.ts +6 -0
- package/lib/styles/icon.d.ts.map +1 -0
- package/lib/styles/icon.js +241 -0
- package/lib/styles/icon.js.map +1 -0
- package/lib/styles/input.d.ts +7 -0
- package/lib/styles/input.d.ts.map +1 -0
- package/lib/styles/input.js +685 -0
- package/lib/styles/input.js.map +1 -0
- package/lib/styles/modal.d.ts +8 -0
- package/lib/styles/modal.d.ts.map +1 -0
- package/lib/styles/modal.js +134 -0
- package/lib/styles/modal.js.map +1 -0
- package/lib/styles/multiselect.d.ts +6 -0
- package/lib/styles/multiselect.d.ts.map +1 -0
- package/lib/styles/multiselect.js +774 -0
- package/lib/styles/multiselect.js.map +1 -0
- package/lib/styles/option.d.ts +6 -0
- package/lib/styles/option.d.ts.map +1 -0
- package/lib/styles/option.js +116 -0
- package/lib/styles/option.js.map +1 -0
- package/lib/styles/popup.d.ts +8 -0
- package/lib/styles/popup.d.ts.map +1 -0
- package/lib/styles/popup.js +95 -0
- package/lib/styles/popup.js.map +1 -0
- package/lib/styles/radio.d.ts +8 -0
- package/lib/styles/radio.d.ts.map +1 -0
- package/lib/styles/radio.js +160 -0
- package/lib/styles/radio.js.map +1 -0
- package/lib/styles/resize-observer.d.ts +6 -0
- package/lib/styles/resize-observer.d.ts.map +1 -0
- package/lib/styles/resize-observer.js +18 -0
- package/lib/styles/resize-observer.js.map +1 -0
- package/lib/styles/scroll-container.d.ts +6 -0
- package/lib/styles/scroll-container.d.ts.map +1 -0
- package/lib/styles/scroll-container.js +198 -0
- package/lib/styles/scroll-container.js.map +1 -0
- package/lib/styles/step.d.ts +5 -0
- package/lib/styles/step.d.ts.map +1 -0
- package/lib/styles/step.js +50 -0
- package/lib/styles/step.js.map +1 -0
- package/lib/styles/switch.d.ts +9 -0
- package/lib/styles/switch.d.ts.map +1 -0
- package/lib/styles/switch.js +100 -0
- package/lib/styles/switch.js.map +1 -0
- package/lib/styles/tab.d.ts +5 -0
- package/lib/styles/tab.d.ts.map +1 -0
- package/lib/styles/tab.js +51 -0
- package/lib/styles/tab.js.map +1 -0
- package/lib/styles/tabs.d.ts +13 -0
- package/lib/styles/tabs.d.ts.map +1 -0
- package/lib/styles/tabs.js +184 -0
- package/lib/styles/tabs.js.map +1 -0
- package/lib/styles/tag.d.ts +6 -0
- package/lib/styles/tag.d.ts.map +1 -0
- package/lib/styles/tag.js +420 -0
- package/lib/styles/tag.js.map +1 -0
- package/lib/styles/textarea.d.ts +6 -0
- package/lib/styles/textarea.d.ts.map +1 -0
- package/lib/styles/textarea.js +350 -0
- package/lib/styles/textarea.js.map +1 -0
- package/lib/styles/tooltip.d.ts +9 -0
- package/lib/styles/tooltip.d.ts.map +1 -0
- package/lib/styles/tooltip.js +136 -0
- package/lib/styles/tooltip.js.map +1 -0
- package/lib/styles/wizard.d.ts +25 -0
- package/lib/styles/wizard.d.ts.map +1 -0
- package/lib/styles/wizard.js +325 -0
- package/lib/styles/wizard.js.map +1 -0
- package/lib/types/common.d.ts +143 -0
- package/lib/types/common.d.ts.map +1 -0
- package/lib/types/common.js +5 -0
- package/lib/types/common.js.map +1 -0
- package/lib/utils/calendar-utils.d.ts +176 -0
- package/lib/utils/calendar-utils.d.ts.map +1 -0
- package/lib/utils/calendar-utils.js +370 -0
- package/lib/utils/calendar-utils.js.map +1 -0
- package/lib/utils/custom-scrollbar.d.ts +82 -0
- package/lib/utils/custom-scrollbar.d.ts.map +1 -0
- package/lib/utils/custom-scrollbar.js +320 -0
- package/lib/utils/custom-scrollbar.js.map +1 -0
- package/lib/utils/icon-registry.d.ts +78 -0
- package/lib/utils/icon-registry.d.ts.map +1 -0
- package/lib/utils/icon-registry.js +304 -0
- package/lib/utils/icon-registry.js.map +1 -0
- package/lib/utils/locale.d.ts +136 -0
- package/lib/utils/locale.d.ts.map +1 -0
- package/lib/utils/locale.js +213 -0
- package/lib/utils/locale.js.map +1 -0
- package/lib/utils/mobile.d.ts +14 -0
- package/lib/utils/mobile.d.ts.map +1 -0
- package/lib/utils/mobile.js +21 -0
- package/lib/utils/mobile.js.map +1 -0
- package/lib/utils/number-format.d.ts +83 -0
- package/lib/utils/number-format.d.ts.map +1 -0
- package/lib/utils/number-format.js +143 -0
- package/lib/utils/number-format.js.map +1 -0
- package/lib/utils/parse-boolean.d.ts +39 -0
- package/lib/utils/parse-boolean.d.ts.map +1 -0
- package/lib/utils/parse-boolean.js +58 -0
- package/lib/utils/parse-boolean.js.map +1 -0
- package/lib/utils/positioning.d.ts +143 -0
- package/lib/utils/positioning.d.ts.map +1 -0
- package/lib/utils/positioning.js +308 -0
- package/lib/utils/positioning.js.map +1 -0
- package/lib/utils/property-capture.d.ts +132 -0
- package/lib/utils/property-capture.d.ts.map +1 -0
- package/lib/utils/property-capture.js +152 -0
- package/lib/utils/property-capture.js.map +1 -0
- package/lib/utils/property-manager.d.ts +90 -0
- package/lib/utils/property-manager.d.ts.map +1 -0
- package/lib/utils/property-manager.js +197 -0
- package/lib/utils/property-manager.js.map +1 -0
- package/lib/utils/resize-observer.d.ts +42 -0
- package/lib/utils/resize-observer.d.ts.map +1 -0
- package/lib/utils/resize-observer.js +71 -0
- package/lib/utils/resize-observer.js.map +1 -0
- package/lib/utils/scroll-lock.d.ts +79 -0
- package/lib/utils/scroll-lock.d.ts.map +1 -0
- package/lib/utils/scroll-lock.js +197 -0
- package/lib/utils/scroll-lock.js.map +1 -0
- package/lib/utils/styles.d.ts +27 -0
- package/lib/utils/styles.d.ts.map +1 -0
- package/lib/utils/styles.js +53 -0
- package/lib/utils/styles.js.map +1 -0
- package/lib/version.d.ts +8 -0
- package/lib/version.d.ts.map +1 -0
- package/lib/version.js +11 -0
- package/lib/version.js.map +1 -0
- package/package.json +159 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mobile.d.ts","sourceRoot":"","sources":["../../src/utils/mobile.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAQH;;;GAGG;AACH,wBAAgB,aAAa,CAAC,UAAU,GAAE,MAA0B,GAAG,OAAO,CAE7E"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mobile detection utility
|
|
3
|
+
*
|
|
4
|
+
* Uses CSS media query via matchMedia for reliable detection:
|
|
5
|
+
* - `pointer: coarse` identifies touch-primary devices (not laptops with touchscreens)
|
|
6
|
+
* - Breakpoint is evaluated by the browser, always in sync with CSS
|
|
7
|
+
* - Called on each use (not cached), so it responds to viewport changes and rotation
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Default mobile breakpoint (px).
|
|
11
|
+
* Matches phones in portrait and most phones in landscape.
|
|
12
|
+
*/
|
|
13
|
+
const MOBILE_BREAKPOINT = 768;
|
|
14
|
+
/**
|
|
15
|
+
* Detect mobile touch devices.
|
|
16
|
+
* Returns true when the primary pointer is coarse (touch) AND viewport is narrow.
|
|
17
|
+
*/
|
|
18
|
+
export function isMobileTouch(breakpoint = MOBILE_BREAKPOINT) {
|
|
19
|
+
return window.matchMedia(`(pointer: coarse) and (max-width: ${breakpoint}px)`).matches;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=mobile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mobile.js","sourceRoot":"","sources":["../../src/utils/mobile.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;GAGG;AACH,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAE9B;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,aAAqB,iBAAiB;IAClE,OAAO,MAAM,CAAC,UAAU,CAAC,qCAAqC,UAAU,KAAK,CAAC,CAAC,OAAO,CAAC;AACzF,CAAC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Number Formatting Utilities
|
|
3
|
+
* PORTED FROM: clj/ty/i18n/number.cljs
|
|
4
|
+
*
|
|
5
|
+
* Uses native Intl.NumberFormat for locale-aware number formatting
|
|
6
|
+
* Supports currency, percent, compact notation, and custom precision
|
|
7
|
+
*/
|
|
8
|
+
export type NumberFormatType = 'number' | 'currency' | 'percent' | 'compact';
|
|
9
|
+
export interface FormatConfig {
|
|
10
|
+
type: NumberFormatType;
|
|
11
|
+
locale?: string;
|
|
12
|
+
currency?: string;
|
|
13
|
+
precision?: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Format a number based on configuration
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* formatNumber(1234.56, { type: 'currency', currency: 'USD', locale: 'en-US' })
|
|
21
|
+
* // Returns: "$1,234.56"
|
|
22
|
+
*
|
|
23
|
+
* formatNumber(0.15, { type: 'percent', precision: 2 })
|
|
24
|
+
* // Returns: "15.00%"
|
|
25
|
+
*
|
|
26
|
+
* formatNumber(1234567, { type: 'compact' })
|
|
27
|
+
* // Returns: "1.2M"
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare function formatNumber(value: number, config: FormatConfig): string;
|
|
31
|
+
/**
|
|
32
|
+
* Parse a numeric string to a number
|
|
33
|
+
*
|
|
34
|
+
* Simple rule: the last occurring . or , is the decimal separator.
|
|
35
|
+
* Everything else is stripped. This works for both US (1,234.56) and
|
|
36
|
+
* European (1.234,56) input, and for mobile keyboards that use , as decimal.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* parseNumericValue("1,234.56") // 1234.56 (last separator is .)
|
|
41
|
+
* parseNumericValue("1.234,56") // 1234.56 (last separator is ,)
|
|
42
|
+
* parseNumericValue("12,50") // 12.5 (last separator is ,)
|
|
43
|
+
* parseNumericValue("12.50") // 12.5 (last separator is .)
|
|
44
|
+
* parseNumericValue("1234") // 1234
|
|
45
|
+
* parseNumericValue("$1,234") // 1234
|
|
46
|
+
* parseNumericValue("15%") // 15
|
|
47
|
+
* parseNumericValue("") // null
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export declare function parseNumericValue(value: string): number | null;
|
|
51
|
+
/**
|
|
52
|
+
* Check if input type requires numeric formatting
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* shouldFormat('currency') // true
|
|
57
|
+
* shouldFormat('percent') // true
|
|
58
|
+
* shouldFormat('text') // false
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export declare function shouldFormat(type: string): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Format currency with locale
|
|
64
|
+
* Convenience function for currency formatting
|
|
65
|
+
*/
|
|
66
|
+
export declare function formatCurrency(value: number, currency?: string, locale?: string): string;
|
|
67
|
+
/**
|
|
68
|
+
* Format percent with locale
|
|
69
|
+
* Convenience function for percent formatting
|
|
70
|
+
*
|
|
71
|
+
* Note: Expects value as 0.15 for 15%
|
|
72
|
+
*/
|
|
73
|
+
export declare function formatPercent(value: number, locale?: string, precision?: number): string;
|
|
74
|
+
/**
|
|
75
|
+
* Format compact notation
|
|
76
|
+
* Convenience function for compact formatting
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* formatCompact(1234567) // "1.2M"
|
|
80
|
+
* formatCompact(1234) // "1.2K"
|
|
81
|
+
*/
|
|
82
|
+
export declare function formatCompact(value: number, locale?: string): string;
|
|
83
|
+
//# sourceMappingURL=number-format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"number-format.d.ts","sourceRoot":"","sources":["../../src/utils/number-format.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,MAAM,gBAAgB,GAAG,QAAQ,GAAG,UAAU,GAAG,SAAS,GAAG,SAAS,CAAA;AAE5E,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,gBAAgB,CAAA;IACtB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,YAAY,GACnB,MAAM,CA4CR;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CA2B9D;AAED;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAElD;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,MAAM,EACb,QAAQ,GAAE,MAAc,EACxB,MAAM,GAAE,MAAgB,GACvB,MAAM,CAER;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,MAAM,EACb,MAAM,GAAE,MAAgB,EACxB,SAAS,CAAC,EAAE,MAAM,GACjB,MAAM,CAER;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,MAAM,EACb,MAAM,GAAE,MAAgB,GACvB,MAAM,CAER"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Number Formatting Utilities
|
|
3
|
+
* PORTED FROM: clj/ty/i18n/number.cljs
|
|
4
|
+
*
|
|
5
|
+
* Uses native Intl.NumberFormat for locale-aware number formatting
|
|
6
|
+
* Supports currency, percent, compact notation, and custom precision
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Format a number based on configuration
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* formatNumber(1234.56, { type: 'currency', currency: 'USD', locale: 'en-US' })
|
|
14
|
+
* // Returns: "$1,234.56"
|
|
15
|
+
*
|
|
16
|
+
* formatNumber(0.15, { type: 'percent', precision: 2 })
|
|
17
|
+
* // Returns: "15.00%"
|
|
18
|
+
*
|
|
19
|
+
* formatNumber(1234567, { type: 'compact' })
|
|
20
|
+
* // Returns: "1.2M"
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export function formatNumber(value, config) {
|
|
24
|
+
const { type, locale = 'en-US', currency = 'USD', precision } = config;
|
|
25
|
+
const options = {};
|
|
26
|
+
// Add precision if specified
|
|
27
|
+
if (precision !== undefined) {
|
|
28
|
+
options.minimumFractionDigits = precision;
|
|
29
|
+
options.maximumFractionDigits = precision;
|
|
30
|
+
}
|
|
31
|
+
// Configure based on type
|
|
32
|
+
switch (type) {
|
|
33
|
+
case 'currency':
|
|
34
|
+
options.style = 'currency';
|
|
35
|
+
options.currency = currency;
|
|
36
|
+
break;
|
|
37
|
+
case 'percent':
|
|
38
|
+
options.style = 'percent';
|
|
39
|
+
// Note: Intl.NumberFormat expects decimal (0.15 for 15%)
|
|
40
|
+
// We'll handle the division in the input component
|
|
41
|
+
break;
|
|
42
|
+
case 'compact':
|
|
43
|
+
options.notation = 'compact';
|
|
44
|
+
options.compactDisplay = 'short';
|
|
45
|
+
break;
|
|
46
|
+
case 'number':
|
|
47
|
+
default:
|
|
48
|
+
options.style = 'decimal';
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
const formatter = new Intl.NumberFormat(locale, options);
|
|
52
|
+
const formatted = formatter.format(value);
|
|
53
|
+
// Normalize Unicode spaces for better HTML input compatibility
|
|
54
|
+
// Replace narrow no-break space (U+202F) and thin space (U+2009) with regular non-breaking space (U+00A0)
|
|
55
|
+
// This ensures proper rendering in HTML input elements
|
|
56
|
+
return formatted
|
|
57
|
+
.replace(/\u202F/g, '\u00A0') // Narrow no-break space → non-breaking space
|
|
58
|
+
.replace(/\u2009/g, '\u00A0'); // Thin space → non-breaking space
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Parse a numeric string to a number
|
|
62
|
+
*
|
|
63
|
+
* Simple rule: the last occurring . or , is the decimal separator.
|
|
64
|
+
* Everything else is stripped. This works for both US (1,234.56) and
|
|
65
|
+
* European (1.234,56) input, and for mobile keyboards that use , as decimal.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* parseNumericValue("1,234.56") // 1234.56 (last separator is .)
|
|
70
|
+
* parseNumericValue("1.234,56") // 1234.56 (last separator is ,)
|
|
71
|
+
* parseNumericValue("12,50") // 12.5 (last separator is ,)
|
|
72
|
+
* parseNumericValue("12.50") // 12.5 (last separator is .)
|
|
73
|
+
* parseNumericValue("1234") // 1234
|
|
74
|
+
* parseNumericValue("$1,234") // 1234
|
|
75
|
+
* parseNumericValue("15%") // 15
|
|
76
|
+
* parseNumericValue("") // null
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export function parseNumericValue(value) {
|
|
80
|
+
if (!value || value.trim() === '')
|
|
81
|
+
return null;
|
|
82
|
+
// Strip everything except digits, dots, commas, and minus
|
|
83
|
+
let stripped = value
|
|
84
|
+
.replace(/[^\d.,-]/g, '')
|
|
85
|
+
.trim();
|
|
86
|
+
if (stripped === '' || stripped === '-')
|
|
87
|
+
return null;
|
|
88
|
+
// Find the last occurring . or , — that's the decimal separator
|
|
89
|
+
const lastComma = stripped.lastIndexOf(',');
|
|
90
|
+
const lastDot = stripped.lastIndexOf('.');
|
|
91
|
+
const lastSep = Math.max(lastComma, lastDot);
|
|
92
|
+
if (lastSep === -1) {
|
|
93
|
+
// No separators — pure integer
|
|
94
|
+
const parsed = parseFloat(stripped);
|
|
95
|
+
return isNaN(parsed) ? null : parsed;
|
|
96
|
+
}
|
|
97
|
+
// Split at the last separator
|
|
98
|
+
const intPart = stripped.slice(0, lastSep).replace(/[.,]/g, '');
|
|
99
|
+
const decPart = stripped.slice(lastSep + 1);
|
|
100
|
+
const parsed = parseFloat(intPart + '.' + decPart);
|
|
101
|
+
return isNaN(parsed) ? null : parsed;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Check if input type requires numeric formatting
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```typescript
|
|
108
|
+
* shouldFormat('currency') // true
|
|
109
|
+
* shouldFormat('percent') // true
|
|
110
|
+
* shouldFormat('text') // false
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
export function shouldFormat(type) {
|
|
114
|
+
return ['number', 'currency', 'percent', 'compact'].includes(type);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Format currency with locale
|
|
118
|
+
* Convenience function for currency formatting
|
|
119
|
+
*/
|
|
120
|
+
export function formatCurrency(value, currency = 'USD', locale = 'en-US') {
|
|
121
|
+
return formatNumber(value, { type: 'currency', currency, locale });
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Format percent with locale
|
|
125
|
+
* Convenience function for percent formatting
|
|
126
|
+
*
|
|
127
|
+
* Note: Expects value as 0.15 for 15%
|
|
128
|
+
*/
|
|
129
|
+
export function formatPercent(value, locale = 'en-US', precision) {
|
|
130
|
+
return formatNumber(value, { type: 'percent', locale, precision });
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Format compact notation
|
|
134
|
+
* Convenience function for compact formatting
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* formatCompact(1234567) // "1.2M"
|
|
138
|
+
* formatCompact(1234) // "1.2K"
|
|
139
|
+
*/
|
|
140
|
+
export function formatCompact(value, locale = 'en-US') {
|
|
141
|
+
return formatNumber(value, { type: 'compact', locale });
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=number-format.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"number-format.js","sourceRoot":"","sources":["../../src/utils/number-format.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAWH;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,YAAY,CAC1B,KAAa,EACb,MAAoB;IAEpB,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,EAAE,QAAQ,GAAG,KAAK,EAAE,SAAS,EAAE,GAAG,MAAM,CAAA;IAEtE,MAAM,OAAO,GAA6B,EAAE,CAAA;IAE5C,6BAA6B;IAC7B,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;QAC5B,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAA;QACzC,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAA;IAC3C,CAAC;IAED,0BAA0B;IAC1B,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,UAAU;YACb,OAAO,CAAC,KAAK,GAAG,UAAU,CAAA;YAC1B,OAAO,CAAC,QAAQ,GAAG,QAAQ,CAAA;YAC3B,MAAK;QAEP,KAAK,SAAS;YACZ,OAAO,CAAC,KAAK,GAAG,SAAS,CAAA;YACzB,yDAAyD;YACzD,mDAAmD;YACnD,MAAK;QAEP,KAAK,SAAS;YACZ,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAA;YAC5B,OAAO,CAAC,cAAc,GAAG,OAAO,CAAA;YAChC,MAAK;QAEP,KAAK,QAAQ,CAAC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
|
+
* This utility helps web components handle boolean attributes consistently:
|
|
5
|
+
* - HTML5 boolean attributes: presence = true, absence = false, empty string = true
|
|
6
|
+
* - Framework boolean values: true/false/"true"/"false"
|
|
7
|
+
* - Numeric boolean values: 1/0/"1"/"0"
|
|
8
|
+
*
|
|
9
|
+
* @param value - The attribute value to parse
|
|
10
|
+
* @returns boolean - The parsed boolean value
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* parseBoolean(null) // false - attribute not present
|
|
14
|
+
* parseBoolean('') // true - HTML boolean attribute (present but empty)
|
|
15
|
+
* parseBoolean('true') // true
|
|
16
|
+
* parseBoolean('false') // false
|
|
17
|
+
* parseBoolean('TRUE') // true - case insensitive
|
|
18
|
+
* parseBoolean('1') // true
|
|
19
|
+
* parseBoolean('0') // false
|
|
20
|
+
* parseBoolean('yes') // true - any other non-empty string
|
|
21
|
+
* parseBoolean('anything') // true - truthy by default unless explicitly false
|
|
22
|
+
*/
|
|
23
|
+
export declare function parseBoolean(value: string | null): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Check if a value looks like a boolean string
|
|
26
|
+
* Used to determine if an attribute should be treated as a boolean
|
|
27
|
+
*
|
|
28
|
+
* @param value - The value to check
|
|
29
|
+
* @returns boolean - True if value represents a boolean
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* isBooleanString('true') // true
|
|
33
|
+
* isBooleanString('false') // true
|
|
34
|
+
* isBooleanString('1') // true
|
|
35
|
+
* isBooleanString('0') // true
|
|
36
|
+
* isBooleanString('custom') // false
|
|
37
|
+
*/
|
|
38
|
+
export declare function isBooleanString(value: string | null): boolean;
|
|
39
|
+
//# sourceMappingURL=parse-boolean.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-boolean.d.ts","sourceRoot":"","sources":["../../src/utils/parse-boolean.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAe1D;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAI7D"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse a value as a boolean following web standards
|
|
3
|
+
*
|
|
4
|
+
* This utility helps web components handle boolean attributes consistently:
|
|
5
|
+
* - HTML5 boolean attributes: presence = true, absence = false, empty string = true
|
|
6
|
+
* - Framework boolean values: true/false/"true"/"false"
|
|
7
|
+
* - Numeric boolean values: 1/0/"1"/"0"
|
|
8
|
+
*
|
|
9
|
+
* @param value - The attribute value to parse
|
|
10
|
+
* @returns boolean - The parsed boolean value
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* parseBoolean(null) // false - attribute not present
|
|
14
|
+
* parseBoolean('') // true - HTML boolean attribute (present but empty)
|
|
15
|
+
* parseBoolean('true') // true
|
|
16
|
+
* parseBoolean('false') // false
|
|
17
|
+
* parseBoolean('TRUE') // true - case insensitive
|
|
18
|
+
* parseBoolean('1') // true
|
|
19
|
+
* parseBoolean('0') // false
|
|
20
|
+
* parseBoolean('yes') // true - any other non-empty string
|
|
21
|
+
* parseBoolean('anything') // true - truthy by default unless explicitly false
|
|
22
|
+
*/
|
|
23
|
+
export function parseBoolean(value) {
|
|
24
|
+
// No attribute or null = false (HTML standard)
|
|
25
|
+
if (value === null)
|
|
26
|
+
return false;
|
|
27
|
+
// Empty string = true (HTML boolean attribute pattern: <input checked>)
|
|
28
|
+
if (value === '')
|
|
29
|
+
return true;
|
|
30
|
+
// Normalize to lowercase for case-insensitive comparison
|
|
31
|
+
const normalized = value.toLowerCase().trim();
|
|
32
|
+
// Explicit false values
|
|
33
|
+
if (normalized === 'false' || normalized === '0')
|
|
34
|
+
return false;
|
|
35
|
+
// Everything else is truthy (follows HTML/JavaScript conventions)
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Check if a value looks like a boolean string
|
|
40
|
+
* Used to determine if an attribute should be treated as a boolean
|
|
41
|
+
*
|
|
42
|
+
* @param value - The value to check
|
|
43
|
+
* @returns boolean - True if value represents a boolean
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* isBooleanString('true') // true
|
|
47
|
+
* isBooleanString('false') // true
|
|
48
|
+
* isBooleanString('1') // true
|
|
49
|
+
* isBooleanString('0') // true
|
|
50
|
+
* isBooleanString('custom') // false
|
|
51
|
+
*/
|
|
52
|
+
export function isBooleanString(value) {
|
|
53
|
+
if (value === null || value === '')
|
|
54
|
+
return false;
|
|
55
|
+
const normalized = value.toLowerCase().trim();
|
|
56
|
+
return ['true', 'false', '1', '0'].includes(normalized);
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=parse-boolean.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-boolean.js","sourceRoot":"","sources":["../../src/utils/parse-boolean.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,YAAY,CAAC,KAAoB;IAC/C,+CAA+C;IAC/C,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,KAAK,CAAA;IAEhC,wEAAwE;IACxE,IAAI,KAAK,KAAK,EAAE;QAAE,OAAO,IAAI,CAAA;IAE7B,yDAAyD;IACzD,MAAM,UAAU,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,CAAA;IAE7C,wBAAwB;IACxB,IAAI,UAAU,KAAK,OAAO,IAAI,UAAU,KAAK,GAAG;QAAE,OAAO,KAAK,CAAA;IAE9D,kEAAkE;IAClE,OAAO,IAAI,CAAA;AACb,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,eAAe,CAAC,KAAoB;IAClD,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,EAAE;QAAE,OAAO,KAAK,CAAA;IAChD,MAAM,UAAU,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,CAAA;IAC7C,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAA;AACzD,CAAC"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core positioning engine for floating elements
|
|
3
|
+
* Adapted from ty.positioning ClojureScript implementation
|
|
4
|
+
*
|
|
5
|
+
* Handles smart positioning of tooltips, dropdowns, popups, and other
|
|
6
|
+
* floating elements relative to anchor elements with automatic overflow
|
|
7
|
+
* detection and placement fallback.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Placement orientation - how the floating element is positioned
|
|
11
|
+
*/
|
|
12
|
+
export type PlacementOrientation = 'horizontal' | 'vertical';
|
|
13
|
+
/**
|
|
14
|
+
* Vertical alignment options
|
|
15
|
+
*/
|
|
16
|
+
export type VerticalAlign = 'top' | 'center' | 'bottom' | 'end';
|
|
17
|
+
/**
|
|
18
|
+
* Horizontal alignment options
|
|
19
|
+
*/
|
|
20
|
+
export type HorizontalAlign = 'start' | 'center' | 'end';
|
|
21
|
+
/**
|
|
22
|
+
* All available placement options
|
|
23
|
+
*/
|
|
24
|
+
export type Placement = 'top-start' | 'top' | 'top-end' | 'right-start' | 'right' | 'right-end' | 'bottom-start' | 'bottom' | 'bottom-end' | 'left-start' | 'left' | 'left-end';
|
|
25
|
+
/**
|
|
26
|
+
* Placement configuration
|
|
27
|
+
*/
|
|
28
|
+
export interface PlacementConfig {
|
|
29
|
+
vertical: VerticalAlign;
|
|
30
|
+
horizontal: HorizontalAlign;
|
|
31
|
+
orientation?: PlacementOrientation;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Element rectangle with calculated center points
|
|
35
|
+
*/
|
|
36
|
+
export interface ElementRect {
|
|
37
|
+
top: number;
|
|
38
|
+
left: number;
|
|
39
|
+
right: number;
|
|
40
|
+
bottom: number;
|
|
41
|
+
width: number;
|
|
42
|
+
height: number;
|
|
43
|
+
centerX: number;
|
|
44
|
+
centerY: number;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Viewport dimensions and scroll position
|
|
48
|
+
*/
|
|
49
|
+
export interface ViewportRect {
|
|
50
|
+
width: number;
|
|
51
|
+
height: number;
|
|
52
|
+
scrollX: number;
|
|
53
|
+
scrollY: number;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Overflow data for all edges
|
|
57
|
+
*/
|
|
58
|
+
export interface OverflowData {
|
|
59
|
+
top: number;
|
|
60
|
+
left: number;
|
|
61
|
+
bottom: number;
|
|
62
|
+
right: number;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Calculated position result
|
|
66
|
+
*/
|
|
67
|
+
export interface PositionResult {
|
|
68
|
+
x: number;
|
|
69
|
+
y: number;
|
|
70
|
+
placement: Placement;
|
|
71
|
+
overflow: OverflowData;
|
|
72
|
+
overflowAmount: number;
|
|
73
|
+
fits: boolean;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Options for findBestPosition
|
|
77
|
+
*/
|
|
78
|
+
export interface PositionOptions {
|
|
79
|
+
targetEl: HTMLElement;
|
|
80
|
+
floatingEl: HTMLElement;
|
|
81
|
+
preferences?: Placement[];
|
|
82
|
+
offset?: number;
|
|
83
|
+
padding?: number;
|
|
84
|
+
containerPadding?: number;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Options for calculatePlacement
|
|
88
|
+
*/
|
|
89
|
+
export interface CalculatePlacementOptions {
|
|
90
|
+
targetRect: ElementRect;
|
|
91
|
+
floatingRect: ElementRect;
|
|
92
|
+
placement: Placement;
|
|
93
|
+
offset: number;
|
|
94
|
+
padding: number;
|
|
95
|
+
scrollbarWidth: number;
|
|
96
|
+
containerPadding: number;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Cleanup function type
|
|
100
|
+
*/
|
|
101
|
+
export type CleanupFn = () => void;
|
|
102
|
+
/**
|
|
103
|
+
* Map of all placement configurations
|
|
104
|
+
*/
|
|
105
|
+
export declare const placements: Record<Placement, PlacementConfig>;
|
|
106
|
+
/**
|
|
107
|
+
* Default placement preference lists for different use cases
|
|
108
|
+
*/
|
|
109
|
+
export declare const placementPreferences: {
|
|
110
|
+
default: Placement[];
|
|
111
|
+
tooltip: Placement[];
|
|
112
|
+
dropdown: Placement[];
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* Get element dimensions relative to viewport with calculated center points
|
|
116
|
+
*/
|
|
117
|
+
export declare function getElementRect(el: HTMLElement): ElementRect;
|
|
118
|
+
/**
|
|
119
|
+
* Get viewport dimensions and scroll position
|
|
120
|
+
*/
|
|
121
|
+
export declare function getViewportRect(): ViewportRect;
|
|
122
|
+
/**
|
|
123
|
+
* Calculate position for a specific placement
|
|
124
|
+
* Returns x, y coordinates and overflow information
|
|
125
|
+
*/
|
|
126
|
+
export declare function calculatePlacement(options: CalculatePlacementOptions): PositionResult;
|
|
127
|
+
/**
|
|
128
|
+
* Find the best position for the floating element
|
|
129
|
+
* Tries all preference placements and returns the one that fits best
|
|
130
|
+
*/
|
|
131
|
+
export declare function findBestPosition(options: PositionOptions): PositionResult;
|
|
132
|
+
/**
|
|
133
|
+
* Create auto-update system for position tracking
|
|
134
|
+
* Continuously monitors and updates position when target or floating element changes
|
|
135
|
+
*
|
|
136
|
+
* @param targetEl - The anchor element to position relative to
|
|
137
|
+
* @param floatingEl - The floating element to position
|
|
138
|
+
* @param updateFn - Callback function that receives new position data
|
|
139
|
+
* @param config - Position options (same as findBestPosition)
|
|
140
|
+
* @returns Cleanup function to stop auto-updating
|
|
141
|
+
*/
|
|
142
|
+
export declare function autoUpdate(targetEl: HTMLElement, floatingEl: HTMLElement, updateFn: (position: PositionResult) => void, config: Omit<PositionOptions, 'targetEl' | 'floatingEl'>): CleanupFn;
|
|
143
|
+
//# sourceMappingURL=positioning.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"positioning.d.ts","sourceRoot":"","sources":["../../src/utils/positioning.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,YAAY,GAAG,UAAU,CAAC;AAE7D;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,QAAQ,GAAG,QAAQ,GAAG,KAAK,CAAC;AAEhE;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,QAAQ,GAAG,KAAK,CAAC;AAEzD;;GAEG;AACH,MAAM,MAAM,SAAS,GACjB,WAAW,GAAG,KAAK,GAAG,SAAS,GAC/B,aAAa,GAAG,OAAO,GAAG,WAAW,GACrC,cAAc,GAAG,QAAQ,GAAG,YAAY,GACxC,YAAY,GAAG,MAAM,GAAG,UAAU,CAAC;AAEvC;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,aAAa,CAAC;IACxB,UAAU,EAAE,eAAe,CAAC;IAC5B,WAAW,CAAC,EAAE,oBAAoB,CAAC;CACpC;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,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