tyrell-components 1.0.0-RC10
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-brand.css +767 -0
- package/css/tyrell.css +1679 -0
- package/dist/tyrell-brand.css +767 -0
- package/dist/tyrell.css +1679 -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 +135 -0
- package/lib/components/button.d.ts.map +1 -0
- package/lib/components/button.js +277 -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 +424 -0
- package/lib/components/dropdown.d.ts.map +1 -0
- package/lib/components/dropdown.js +1640 -0
- package/lib/components/dropdown.js.map +1 -0
- package/lib/components/file-upload.d.ts +121 -0
- package/lib/components/file-upload.d.ts.map +1 -0
- package/lib/components/file-upload.js +441 -0
- package/lib/components/file-upload.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 +78 -0
- package/lib/components/modal.d.ts.map +1 -0
- package/lib/components/modal.js +497 -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 +1595 -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 +86 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +78 -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 +498 -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 +438 -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 +1081 -0
- package/lib/styles/dropdown.js.map +1 -0
- package/lib/styles/file-upload.d.ts +2 -0
- package/lib/styles/file-upload.d.ts.map +1 -0
- package/lib/styles/file-upload.js +241 -0
- package/lib/styles/file-upload.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 +825 -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 +409 -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 +133 -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 +348 -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/loader-registry.d.ts +35 -0
- package/lib/utils/loader-registry.d.ts.map +1 -0
- package/lib/utils/loader-registry.js +43 -0
- package/lib/utils/loader-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 +163 -0
|
@@ -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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CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC,UAAU,EAAE,WAAW,CAAC;IACxB,YAAY,EAAE,WAAW,CAAC;IAC1B,SAAS,EAAE,SAAS,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,MAAM,CAAC;IACvB,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC;AAMnC;;GAEG;AACH,eAAO,MAAM,UAAU,EAAE,MAAM,CAAC,SAAS,EAAE,eAAe,CAuDzD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,oBAAoB;aAI1B,SAAS,EAAE;aAIX,SAAS,EAAE;cAIX,SAAS,EAAE;CACjB,CAAC;AAMF;;GAEG;AACH,wBAAgB,cAAc,CAAC,EAAE,EAAE,WAAW,GAAG,WAAW,CAY3D;AAED;;GAEG;AACH,wBAAgB,eAAe,IAAI,YAAY,CAO9C;AAMD;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,yBAAyB,GAAG,cAAc,CA6ErF;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,eAAe,GAAG,cAAc,CAuCzE;AAMD;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CACxB,QAAQ,EAAE,WAAW,EACrB,UAAU,EAAE,WAAW,EACvB,QAAQ,EAAE,CAAC,QAAQ,EAAE,cAAc,KAAK,IAAI,EAC5C,MAAM,EAAE,IAAI,CAAC,eAAe,EAAE,UAAU,GAAG,YAAY,CAAC,GACvD,SAAS,CA8EX"}
|
|
@@ -0,0 +1,308 @@
|
|
|
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 Definitions
|
|
11
|
+
// ============================================================================
|
|
12
|
+
/**
|
|
13
|
+
* Map of all placement configurations
|
|
14
|
+
*/
|
|
15
|
+
export const placements = {
|
|
16
|
+
'top-start': {
|
|
17
|
+
vertical: 'top',
|
|
18
|
+
horizontal: 'start',
|
|
19
|
+
},
|
|
20
|
+
'top': {
|
|
21
|
+
vertical: 'top',
|
|
22
|
+
horizontal: 'center',
|
|
23
|
+
},
|
|
24
|
+
'top-end': {
|
|
25
|
+
vertical: 'top',
|
|
26
|
+
horizontal: 'end',
|
|
27
|
+
},
|
|
28
|
+
'right-start': {
|
|
29
|
+
vertical: 'center',
|
|
30
|
+
horizontal: 'end',
|
|
31
|
+
orientation: 'vertical',
|
|
32
|
+
},
|
|
33
|
+
'right': {
|
|
34
|
+
vertical: 'center',
|
|
35
|
+
horizontal: 'end',
|
|
36
|
+
orientation: 'vertical',
|
|
37
|
+
},
|
|
38
|
+
'right-end': {
|
|
39
|
+
vertical: 'end',
|
|
40
|
+
horizontal: 'end',
|
|
41
|
+
orientation: 'vertical',
|
|
42
|
+
},
|
|
43
|
+
'bottom-start': {
|
|
44
|
+
vertical: 'bottom',
|
|
45
|
+
horizontal: 'start',
|
|
46
|
+
},
|
|
47
|
+
'bottom': {
|
|
48
|
+
vertical: 'bottom',
|
|
49
|
+
horizontal: 'center',
|
|
50
|
+
},
|
|
51
|
+
'bottom-end': {
|
|
52
|
+
vertical: 'bottom',
|
|
53
|
+
horizontal: 'end',
|
|
54
|
+
},
|
|
55
|
+
'left-start': {
|
|
56
|
+
vertical: 'center',
|
|
57
|
+
horizontal: 'start',
|
|
58
|
+
orientation: 'vertical',
|
|
59
|
+
},
|
|
60
|
+
'left': {
|
|
61
|
+
vertical: 'center',
|
|
62
|
+
horizontal: 'start',
|
|
63
|
+
orientation: 'vertical',
|
|
64
|
+
},
|
|
65
|
+
'left-end': {
|
|
66
|
+
vertical: 'end',
|
|
67
|
+
horizontal: 'start',
|
|
68
|
+
orientation: 'vertical',
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Default placement preference lists for different use cases
|
|
73
|
+
*/
|
|
74
|
+
export const placementPreferences = {
|
|
75
|
+
default: [
|
|
76
|
+
'bottom-start', 'bottom-end', 'top-start', 'top-end',
|
|
77
|
+
'bottom', 'top', 'left', 'right'
|
|
78
|
+
],
|
|
79
|
+
tooltip: [
|
|
80
|
+
'top', 'bottom', 'left', 'right',
|
|
81
|
+
'top-start', 'top-end', 'bottom-start', 'bottom-end'
|
|
82
|
+
],
|
|
83
|
+
dropdown: [
|
|
84
|
+
'bottom-start', 'bottom-end', 'top-start', 'top-end',
|
|
85
|
+
'bottom', 'top', 'right', 'left'
|
|
86
|
+
],
|
|
87
|
+
};
|
|
88
|
+
// ============================================================================
|
|
89
|
+
// DOM Measurement Helpers
|
|
90
|
+
// ============================================================================
|
|
91
|
+
/**
|
|
92
|
+
* Get element dimensions relative to viewport with calculated center points
|
|
93
|
+
*/
|
|
94
|
+
export function getElementRect(el) {
|
|
95
|
+
const rect = el.getBoundingClientRect();
|
|
96
|
+
return {
|
|
97
|
+
top: rect.top,
|
|
98
|
+
left: rect.left,
|
|
99
|
+
right: rect.right,
|
|
100
|
+
bottom: rect.bottom,
|
|
101
|
+
width: rect.width,
|
|
102
|
+
height: rect.height,
|
|
103
|
+
centerX: rect.left + rect.width / 2,
|
|
104
|
+
centerY: rect.top + rect.height / 2,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Get viewport dimensions and scroll position
|
|
109
|
+
*/
|
|
110
|
+
export function getViewportRect() {
|
|
111
|
+
return {
|
|
112
|
+
width: window.innerWidth,
|
|
113
|
+
height: window.innerHeight,
|
|
114
|
+
scrollX: window.scrollX,
|
|
115
|
+
scrollY: window.scrollY,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
// ============================================================================
|
|
119
|
+
// Position Calculation
|
|
120
|
+
// ============================================================================
|
|
121
|
+
/**
|
|
122
|
+
* Calculate position for a specific placement
|
|
123
|
+
* Returns x, y coordinates and overflow information
|
|
124
|
+
*/
|
|
125
|
+
export function calculatePlacement(options) {
|
|
126
|
+
const { targetRect, floatingRect, placement, offset, padding, scrollbarWidth, containerPadding, } = options;
|
|
127
|
+
const config = placements[placement];
|
|
128
|
+
const { vertical, horizontal, orientation } = config;
|
|
129
|
+
const viewport = getViewportRect();
|
|
130
|
+
// Calculate X position
|
|
131
|
+
let x;
|
|
132
|
+
if (orientation === 'vertical') {
|
|
133
|
+
// Left/right placements
|
|
134
|
+
if (horizontal === 'start') {
|
|
135
|
+
x = targetRect.left - floatingRect.width - offset + containerPadding;
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
x = targetRect.right + offset - containerPadding;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
// Top/bottom placements
|
|
143
|
+
if (horizontal === 'start') {
|
|
144
|
+
x = targetRect.left;
|
|
145
|
+
}
|
|
146
|
+
else if (horizontal === 'center') {
|
|
147
|
+
x = targetRect.centerX - floatingRect.width / 2;
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
x = targetRect.right - floatingRect.width;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
// Calculate Y position
|
|
154
|
+
let y;
|
|
155
|
+
if (orientation === 'vertical') {
|
|
156
|
+
// Left/right placements
|
|
157
|
+
if (vertical === 'center') {
|
|
158
|
+
y = targetRect.centerY - floatingRect.height / 2;
|
|
159
|
+
}
|
|
160
|
+
else if (vertical === 'end') {
|
|
161
|
+
y = targetRect.bottom - floatingRect.height - containerPadding;
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
y = targetRect.top;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
// Top/bottom placements
|
|
169
|
+
if (vertical === 'top') {
|
|
170
|
+
y = targetRect.top - floatingRect.height - offset + containerPadding;
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
y = targetRect.bottom + offset - containerPadding;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
// Calculate overflow for each edge
|
|
177
|
+
const overflow = {
|
|
178
|
+
top: Math.min(0, y - padding),
|
|
179
|
+
left: Math.min(0, x - padding),
|
|
180
|
+
bottom: Math.min(0, viewport.height - (y + floatingRect.height + padding)),
|
|
181
|
+
right: Math.min(0, viewport.width - (x + floatingRect.width + padding + scrollbarWidth)),
|
|
182
|
+
};
|
|
183
|
+
// Sum of absolute overflow values
|
|
184
|
+
const overflowAmount = Object.values(overflow).reduce((sum, val) => sum + Math.abs(val), 0);
|
|
185
|
+
return {
|
|
186
|
+
x: Math.round(x),
|
|
187
|
+
y: Math.round(y),
|
|
188
|
+
placement,
|
|
189
|
+
overflow,
|
|
190
|
+
overflowAmount,
|
|
191
|
+
fits: overflowAmount === 0,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Find the best position for the floating element
|
|
196
|
+
* Tries all preference placements and returns the one that fits best
|
|
197
|
+
*/
|
|
198
|
+
export function findBestPosition(options) {
|
|
199
|
+
const { targetEl, floatingEl, preferences = placementPreferences.default, offset = 8, padding = 8, containerPadding = 0, } = options;
|
|
200
|
+
const targetRect = getElementRect(targetEl);
|
|
201
|
+
const floatingRect = getElementRect(floatingEl);
|
|
202
|
+
const scrollbarWidth = 15;
|
|
203
|
+
// Calculate all candidate positions
|
|
204
|
+
const candidates = preferences.map(placement => calculatePlacement({
|
|
205
|
+
targetRect,
|
|
206
|
+
floatingRect,
|
|
207
|
+
placement,
|
|
208
|
+
offset,
|
|
209
|
+
padding,
|
|
210
|
+
containerPadding,
|
|
211
|
+
scrollbarWidth,
|
|
212
|
+
}));
|
|
213
|
+
// Find first that fits, or one with least overflow
|
|
214
|
+
const bestPosition = candidates.find(c => c.fits) ||
|
|
215
|
+
candidates.reduce((best, current) => current.overflowAmount < best.overflowAmount ? current : best);
|
|
216
|
+
// Adjust for scrollbar if needed
|
|
217
|
+
if (bestPosition.overflow.right < 0) {
|
|
218
|
+
bestPosition.x += bestPosition.overflow.right;
|
|
219
|
+
}
|
|
220
|
+
return bestPosition;
|
|
221
|
+
}
|
|
222
|
+
// ============================================================================
|
|
223
|
+
// Auto-Update Functionality
|
|
224
|
+
// ============================================================================
|
|
225
|
+
/**
|
|
226
|
+
* Create auto-update system for position tracking
|
|
227
|
+
* Continuously monitors and updates position when target or floating element changes
|
|
228
|
+
*
|
|
229
|
+
* @param targetEl - The anchor element to position relative to
|
|
230
|
+
* @param floatingEl - The floating element to position
|
|
231
|
+
* @param updateFn - Callback function that receives new position data
|
|
232
|
+
* @param config - Position options (same as findBestPosition)
|
|
233
|
+
* @returns Cleanup function to stop auto-updating
|
|
234
|
+
*/
|
|
235
|
+
export function autoUpdate(targetEl, floatingEl, updateFn, config) {
|
|
236
|
+
let active = true;
|
|
237
|
+
let scrollRafId = null;
|
|
238
|
+
let resizeTimeout = null;
|
|
239
|
+
let resizeObserver = null;
|
|
240
|
+
let mutationObserver = null;
|
|
241
|
+
// Update function that recalculates position
|
|
242
|
+
const update = () => {
|
|
243
|
+
if (!active)
|
|
244
|
+
return;
|
|
245
|
+
const position = findBestPosition({
|
|
246
|
+
targetEl,
|
|
247
|
+
floatingEl,
|
|
248
|
+
...config,
|
|
249
|
+
});
|
|
250
|
+
updateFn(position);
|
|
251
|
+
};
|
|
252
|
+
// Initial update
|
|
253
|
+
update();
|
|
254
|
+
// Debounced update for resize events
|
|
255
|
+
const debouncedUpdate = () => {
|
|
256
|
+
if (resizeTimeout !== null) {
|
|
257
|
+
clearTimeout(resizeTimeout);
|
|
258
|
+
}
|
|
259
|
+
resizeTimeout = window.setTimeout(() => {
|
|
260
|
+
resizeTimeout = null;
|
|
261
|
+
update();
|
|
262
|
+
}, 10);
|
|
263
|
+
};
|
|
264
|
+
// RAF-based scroll handler for smooth updates
|
|
265
|
+
const handleScroll = () => {
|
|
266
|
+
if (!active)
|
|
267
|
+
return;
|
|
268
|
+
if (scrollRafId === null) {
|
|
269
|
+
scrollRafId = requestAnimationFrame(() => {
|
|
270
|
+
scrollRafId = null;
|
|
271
|
+
update();
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
// Observe size changes on target, floating element, and body
|
|
276
|
+
resizeObserver = new ResizeObserver(debouncedUpdate);
|
|
277
|
+
resizeObserver.observe(targetEl);
|
|
278
|
+
resizeObserver.observe(floatingEl);
|
|
279
|
+
resizeObserver.observe(document.body);
|
|
280
|
+
// Observe DOM attribute changes on target
|
|
281
|
+
mutationObserver = new MutationObserver(update);
|
|
282
|
+
mutationObserver.observe(targetEl, {
|
|
283
|
+
attributes: true,
|
|
284
|
+
attributeFilter: ['class', 'style'],
|
|
285
|
+
});
|
|
286
|
+
// Listen for scroll events (capture phase for better performance)
|
|
287
|
+
window.addEventListener('scroll', handleScroll, true);
|
|
288
|
+
window.addEventListener('resize', debouncedUpdate);
|
|
289
|
+
// Return cleanup function
|
|
290
|
+
return () => {
|
|
291
|
+
active = false;
|
|
292
|
+
if (scrollRafId !== null) {
|
|
293
|
+
cancelAnimationFrame(scrollRafId);
|
|
294
|
+
}
|
|
295
|
+
if (resizeTimeout !== null) {
|
|
296
|
+
clearTimeout(resizeTimeout);
|
|
297
|
+
}
|
|
298
|
+
if (resizeObserver) {
|
|
299
|
+
resizeObserver.disconnect();
|
|
300
|
+
}
|
|
301
|
+
if (mutationObserver) {
|
|
302
|
+
mutationObserver.disconnect();
|
|
303
|
+
}
|
|
304
|
+
window.removeEventListener('scroll', handleScroll, true);
|
|
305
|
+
window.removeEventListener('resize', debouncedUpdate);
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
//# sourceMappingURL=positioning.js.map
|
|
@@ -0,0 +1 @@
|
|
|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Utility
|
|
3
|
+
*
|
|
4
|
+
* Solves the problem of frameworks (React, Reagent, etc.) setting properties
|
|
5
|
+
* on custom elements BEFORE connectedCallback runs.
|
|
6
|
+
*
|
|
7
|
+
* PROBLEM:
|
|
8
|
+
* 1. Framework creates element: document.createElement('ty-dropdown')
|
|
9
|
+
* 2. Framework sets properties: element.value = "foo"
|
|
10
|
+
* 3. Constructor runs and defines getters/setters
|
|
11
|
+
* 4. BUT properties were already set, creating instance properties
|
|
12
|
+
* 5. Instance properties shadow the class getters/setters
|
|
13
|
+
* 6. connectedCallback runs - too late!
|
|
14
|
+
*
|
|
15
|
+
* SOLUTION:
|
|
16
|
+
* In connectedCallback, capture any pre-set properties and apply them properly.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* connectedCallback(): void {
|
|
21
|
+
* const preSetProps = capturePreSetProperties(this, [
|
|
22
|
+
* 'value', 'clearable', 'disabled'
|
|
23
|
+
* ])
|
|
24
|
+
*
|
|
25
|
+
* if (preSetProps.value !== undefined) {
|
|
26
|
+
* this._value = preSetProps.value
|
|
27
|
+
* }
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
/**
|
|
32
|
+
* Captured property data
|
|
33
|
+
*/
|
|
34
|
+
export interface CapturedProperty<T = any> {
|
|
35
|
+
name: string;
|
|
36
|
+
value: T;
|
|
37
|
+
hadProperty: boolean;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Options for property capture
|
|
41
|
+
*/
|
|
42
|
+
export interface PropertyCaptureOptions {
|
|
43
|
+
/**
|
|
44
|
+
* Whether to delete instance properties after capture (default: true)
|
|
45
|
+
* This ensures the class getter/setter will work going forward
|
|
46
|
+
*/
|
|
47
|
+
cleanup?: boolean;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Capture properties that were set before connectedCallback
|
|
51
|
+
*
|
|
52
|
+
* @param element - The custom element instance
|
|
53
|
+
* @param propertyNames - Array of property names to check
|
|
54
|
+
* @param options - Capture options
|
|
55
|
+
* @returns Record of captured properties with metadata
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* const captured = capturePreSetProperties(this, ['value', 'disabled'])
|
|
60
|
+
* // {
|
|
61
|
+
* // value: { name: 'value', value: 'foo', hadProperty: true },
|
|
62
|
+
* // disabled: { name: 'disabled', value: undefined, hadProperty: false }
|
|
63
|
+
* // }
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export declare function capturePreSetProperties(element: HTMLElement, propertyNames: string[], options?: PropertyCaptureOptions): Record<string, CapturedProperty>;
|
|
67
|
+
/**
|
|
68
|
+
* Simpler API - just get the values that were pre-set
|
|
69
|
+
*
|
|
70
|
+
* @param element - The custom element instance
|
|
71
|
+
* @param propertyNames - Array of property names to check
|
|
72
|
+
* @param options - Capture options
|
|
73
|
+
* @returns Record of property names to values (only includes properties that were set)
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* const values = getCapturedValues(this, ['value', 'disabled'])
|
|
78
|
+
* if (values.value !== undefined) {
|
|
79
|
+
* this._value = values.value
|
|
80
|
+
* }
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export declare function getCapturedValues(element: HTMLElement, propertyNames: string[], options?: PropertyCaptureOptions): Record<string, any>;
|
|
84
|
+
/**
|
|
85
|
+
* Mapping of public property names to private field names
|
|
86
|
+
*/
|
|
87
|
+
export type PropertyMap = Record<string, string>;
|
|
88
|
+
/**
|
|
89
|
+
* Automatically apply pre-set properties to private fields
|
|
90
|
+
*
|
|
91
|
+
* @param element - The custom element instance
|
|
92
|
+
* @param propertyNames - Array of property names to check
|
|
93
|
+
* @param propertyMap - Optional mapping of public names to private field names
|
|
94
|
+
* Default: adds underscore prefix (e.g., 'value' -> '_value')
|
|
95
|
+
* @param options - Capture options
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* // Simple usage (uses _propertyName convention)
|
|
100
|
+
* applyPreSetProperties(this, ['value', 'disabled'])
|
|
101
|
+
* // Sets this._value and this._disabled
|
|
102
|
+
*
|
|
103
|
+
* // Custom mapping
|
|
104
|
+
* applyPreSetProperties(this, ['value'], { value: 'internalValue' })
|
|
105
|
+
* // Sets this.internalValue
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
export declare function applyPreSetProperties(element: any, propertyNames: string[], propertyMap?: PropertyMap, options?: PropertyCaptureOptions): void;
|
|
109
|
+
/**
|
|
110
|
+
* Helper for components with standard _propertyName pattern
|
|
111
|
+
*
|
|
112
|
+
* @param element - The custom element instance
|
|
113
|
+
* @param propertyNames - Array of property names to check
|
|
114
|
+
* @param transformer - Optional function to transform values before setting
|
|
115
|
+
* @param options - Capture options
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```typescript
|
|
119
|
+
* connectedCallback(): void {
|
|
120
|
+
* // Basic usage
|
|
121
|
+
* captureAndApplyProperties(this, ['value', 'disabled', 'required'])
|
|
122
|
+
*
|
|
123
|
+
* // With transformation
|
|
124
|
+
* captureAndApplyProperties(this, ['value'], (name, value) => {
|
|
125
|
+
* if (name === 'value') return this.parseValue(value)
|
|
126
|
+
* return value
|
|
127
|
+
* })
|
|
128
|
+
* }
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
export declare function captureAndApplyProperties(element: any, propertyNames: string[], transformer?: (name: string, value: any) => any, options?: PropertyCaptureOptions): void;
|
|
132
|
+
//# sourceMappingURL=property-capture.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"property-capture.d.ts","sourceRoot":"","sources":["../../src/utils/property-capture.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH;;GAEG;AACH,MAAM,WAAW,gBAAgB,CAAC,CAAC,GAAG,GAAG;I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