ropav 0.0.6 → 0.0.7
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/dist/_plugin-vue_export-helper.js +1 -11
- package/dist/accordion.css +112 -0
- package/dist/accordion.js +360 -0
- package/dist/accordion.js.map +1 -0
- package/dist/badge.css +169 -0
- package/dist/badge.js +103 -0
- package/dist/badge.js.map +1 -0
- package/dist/bem.js +11 -0
- package/dist/bem.js.map +1 -0
- package/dist/button-group.css +8 -8
- package/dist/button-group.js +2 -1
- package/dist/button-group.js.map +1 -1
- package/dist/button.js +3 -2
- package/dist/button.js.map +1 -1
- package/dist/card.js +2 -1
- package/dist/card.js.map +1 -1
- package/dist/checkbox.js +2 -1
- package/dist/checkbox.js.map +1 -1
- package/dist/collapse.css +32 -0
- package/dist/collapse.js +68 -0
- package/dist/collapse.js.map +1 -0
- package/dist/components/accordion/accordion-item.d.ts +40 -0
- package/dist/components/accordion/accordion.d.ts +23 -0
- package/dist/components/accordion/index.d.ts +4 -0
- package/dist/components/accordion/index.js +2 -0
- package/dist/components/accordion/types.d.ts +100 -0
- package/dist/components/accordion/useAccordion.d.ts +3 -0
- package/dist/components/badge/badge.d.ts +25 -0
- package/dist/components/badge/index.d.ts +3 -0
- package/dist/components/badge/index.js +2 -0
- package/dist/components/badge/types.d.ts +16 -0
- package/dist/components/badge/useBadgeColor.d.ts +8 -0
- package/dist/components/collapse/collapse.d.ts +36 -0
- package/dist/components/collapse/index.d.ts +3 -0
- package/dist/components/collapse/index.js +3 -0
- package/dist/components/collapse/types.d.ts +76 -0
- package/dist/components/collapse/useCollapse.d.ts +2 -0
- package/dist/components/dropdown-menu/dropdown-menu-items.d.ts +16 -0
- package/dist/components/dropdown-menu/dropdown-menu-utils.d.ts +23 -0
- package/dist/components/dropdown-menu/dropdown-menu.d.ts +26 -0
- package/dist/components/dropdown-menu/index.d.ts +3 -0
- package/dist/components/dropdown-menu/index.js +2 -0
- package/dist/components/dropdown-menu/types.d.ts +104 -0
- package/dist/components/dropdown-menu/useDropdownMenu.d.ts +32 -0
- package/dist/components/dropdown-menu/useDropdownMenuDisclosure.d.ts +30 -0
- package/dist/components/dropdown-menu/useDropdownMenuDom.d.ts +28 -0
- package/dist/components/dropdown-menu/useDropdownMenuHoverIntent.d.ts +24 -0
- package/dist/components/dropdown-menu/useDropdownMenuInteractions.d.ts +51 -0
- package/dist/components/dropdown-menu/useDropdownMenuNavigation.d.ts +16 -0
- package/dist/components/dropdown-menu/useDropdownMenuRenderItems.d.ts +25 -0
- package/dist/components/dropdown-menu/useDropdownSubmenus.d.ts +18 -0
- package/dist/components/field/field.d.ts +2 -2
- package/dist/components/field/useField.d.ts +16 -0
- package/dist/components/input/useInput.d.ts +8 -0
- package/dist/components/modal/index.d.ts +2 -0
- package/dist/components/modal/index.js +2 -0
- package/dist/components/modal/modal.d.ts +42 -0
- package/dist/components/modal/types.d.ts +32 -0
- package/dist/components/modal/useModal.d.ts +29 -0
- package/dist/components/overlay/index.d.ts +2 -0
- package/dist/components/overlay/index.js +2 -0
- package/dist/components/overlay/overlay.d.ts +19 -0
- package/dist/components/overlay/types.d.ts +12 -0
- package/dist/components/overlay/useOverlay.d.ts +7 -0
- package/dist/components/popover/index.d.ts +2 -0
- package/dist/components/popover/index.js +2 -0
- package/dist/components/popover/popover.d.ts +43 -0
- package/dist/components/popover/types.d.ts +40 -0
- package/dist/components/popover/usePopover.d.ts +20 -0
- package/dist/components/tabs/index.d.ts +6 -0
- package/dist/components/tabs/index.js +2 -0
- package/dist/components/tabs/tabs-content.d.ts +24 -0
- package/dist/components/tabs/tabs-list.d.ts +26 -0
- package/dist/components/tabs/tabs-trigger.d.ts +29 -0
- package/dist/components/tabs/tabs.d.ts +31 -0
- package/dist/components/tabs/types.d.ts +160 -0
- package/dist/components/tabs/useTabs.d.ts +5 -0
- package/dist/dropdown-menu.css +159 -0
- package/dist/dropdown-menu.js +903 -0
- package/dist/dropdown-menu.js.map +1 -0
- package/dist/field.css +8 -8
- package/dist/field.js +68 -50
- package/dist/field.js.map +1 -1
- package/dist/icon-button.css +1 -1
- package/dist/icon-button.js +3 -2
- package/dist/icon-button.js.map +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.js +12 -1
- package/dist/input.css +25 -25
- package/dist/input.js +57 -38
- package/dist/input.js.map +1 -1
- package/dist/modal.css +134 -0
- package/dist/modal.js +433 -0
- package/dist/modal.js.map +1 -0
- package/dist/overlay.css +28 -0
- package/dist/overlay.js +84 -0
- package/dist/overlay.js.map +1 -0
- package/dist/popover.css +75 -0
- package/dist/popover.js +367 -0
- package/dist/popover.js.map +1 -0
- package/dist/progress.js +2 -1
- package/dist/progress.js.map +1 -1
- package/dist/radio.js +4 -9
- package/dist/radio.js.map +1 -1
- package/dist/select.js +8 -37
- package/dist/select.js.map +1 -1
- package/dist/slider.js +2 -1
- package/dist/slider.js.map +1 -1
- package/dist/switch.js +2 -1
- package/dist/switch.js.map +1 -1
- package/dist/tabs.css +279 -0
- package/dist/tabs.js +515 -0
- package/dist/tabs.js.map +1 -0
- package/dist/textarea.js +2 -1
- package/dist/textarea.js.map +1 -1
- package/dist/tooltip.js +2 -1
- package/dist/tooltip.js.map +1 -1
- package/dist/useClickOutside.js +26 -0
- package/dist/useClickOutside.js.map +1 -0
- package/dist/useCollapse.js +94 -0
- package/dist/useCollapse.js.map +1 -0
- package/dist/useRequiredInject.js +11 -0
- package/dist/useRequiredInject.js.map +1 -0
- package/dist/x.js +14 -0
- package/dist/x.js.map +1 -0
- package/package.json +35 -3
- package/dist/_plugin-vue_export-helper.js.map +0 -1
package/dist/popover.css
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
.rp-popover[data-v-afdc2686] {
|
|
2
|
+
--_rp-popover-main-axis-offset: var(--rp-spacing-2);
|
|
3
|
+
--_rp-popover-cross-axis-offset: 0px;
|
|
4
|
+
--_rp-popover-radius: var(--rp-radius-sm);
|
|
5
|
+
position: relative;
|
|
6
|
+
display: inline-flex;
|
|
7
|
+
font-family: var(--rp-font-family);
|
|
8
|
+
vertical-align: middle;
|
|
9
|
+
}
|
|
10
|
+
.rp-popover__content[data-v-afdc2686] {
|
|
11
|
+
position: absolute;
|
|
12
|
+
z-index: 100;
|
|
13
|
+
box-sizing: border-box;
|
|
14
|
+
min-width: 180px;
|
|
15
|
+
max-width: min(24rem, 100vw - var(--rp-spacing-6));
|
|
16
|
+
padding: var(--rp-spacing-4);
|
|
17
|
+
color: var(--rp-color-text);
|
|
18
|
+
font-size: var(--rp-font-size-base);
|
|
19
|
+
line-height: var(--rp-line-height-normal);
|
|
20
|
+
overflow-wrap: anywhere;
|
|
21
|
+
background-color: var(--rp-color-surface-raised);
|
|
22
|
+
border: var(--rp-border-width-thin) solid var(--rp-color-border);
|
|
23
|
+
border-radius: var(--_rp-popover-radius);
|
|
24
|
+
box-shadow: var(--rp-shadow-base);
|
|
25
|
+
}
|
|
26
|
+
.rp-popover--placement-top .rp-popover__content[data-v-afdc2686] {
|
|
27
|
+
bottom: calc(100% + var(--_rp-popover-main-axis-offset));
|
|
28
|
+
left: calc(50% + var(--_rp-popover-cross-axis-offset));
|
|
29
|
+
translate: -50% 0;
|
|
30
|
+
}
|
|
31
|
+
.rp-popover--placement-right .rp-popover__content[data-v-afdc2686] {
|
|
32
|
+
top: calc(50% + var(--_rp-popover-cross-axis-offset));
|
|
33
|
+
left: calc(100% + var(--_rp-popover-main-axis-offset));
|
|
34
|
+
translate: 0 -50%;
|
|
35
|
+
}
|
|
36
|
+
.rp-popover--placement-bottom .rp-popover__content[data-v-afdc2686] {
|
|
37
|
+
top: calc(100% + var(--_rp-popover-main-axis-offset));
|
|
38
|
+
left: calc(50% + var(--_rp-popover-cross-axis-offset));
|
|
39
|
+
translate: -50% 0;
|
|
40
|
+
}
|
|
41
|
+
.rp-popover--placement-left .rp-popover__content[data-v-afdc2686] {
|
|
42
|
+
top: calc(50% + var(--_rp-popover-cross-axis-offset));
|
|
43
|
+
right: calc(100% + var(--_rp-popover-main-axis-offset));
|
|
44
|
+
translate: 0 -50%;
|
|
45
|
+
}
|
|
46
|
+
.rp-popover--target[data-v-afdc2686] {
|
|
47
|
+
display: contents;
|
|
48
|
+
}
|
|
49
|
+
.rp-popover--target .rp-popover__content[data-v-afdc2686] {
|
|
50
|
+
position: fixed;
|
|
51
|
+
top: var(--_rp-popover-target-y, 0);
|
|
52
|
+
right: auto;
|
|
53
|
+
bottom: auto;
|
|
54
|
+
left: var(--_rp-popover-target-x, 0);
|
|
55
|
+
}
|
|
56
|
+
.rp-popover--target.rp-popover--placement-top .rp-popover__content[data-v-afdc2686] {
|
|
57
|
+
translate: calc(-50% + var(--_rp-popover-cross-axis-offset)) calc(-100% - var(--_rp-popover-main-axis-offset));
|
|
58
|
+
}
|
|
59
|
+
.rp-popover--target.rp-popover--placement-right .rp-popover__content[data-v-afdc2686] {
|
|
60
|
+
translate: var(--_rp-popover-main-axis-offset) calc(-50% + var(--_rp-popover-cross-axis-offset));
|
|
61
|
+
}
|
|
62
|
+
.rp-popover--target.rp-popover--placement-bottom .rp-popover__content[data-v-afdc2686] {
|
|
63
|
+
translate: calc(-50% + var(--_rp-popover-cross-axis-offset)) var(--_rp-popover-main-axis-offset);
|
|
64
|
+
}
|
|
65
|
+
.rp-popover--target.rp-popover--placement-left .rp-popover__content[data-v-afdc2686] {
|
|
66
|
+
translate: calc(-100% - var(--_rp-popover-main-axis-offset)) calc(-50% + var(--_rp-popover-cross-axis-offset));
|
|
67
|
+
}
|
|
68
|
+
.rp-popover-content-enter-active[data-v-afdc2686],
|
|
69
|
+
.rp-popover-content-leave-active[data-v-afdc2686] {
|
|
70
|
+
transition: opacity var(--rp-transition-fast);
|
|
71
|
+
}
|
|
72
|
+
.rp-popover-content-enter-from[data-v-afdc2686],
|
|
73
|
+
.rp-popover-content-leave-to[data-v-afdc2686] {
|
|
74
|
+
opacity: 0;
|
|
75
|
+
}
|
package/dist/popover.js
ADDED
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
import './popover.css';
|
|
2
|
+
import { t as bem } from "./bem.js";
|
|
3
|
+
import { t as _plugin_vue_export_helper_default } from "./_plugin-vue_export-helper.js";
|
|
4
|
+
import { VaporTransition, applyVShow, computed, createComponent, createIf, createSlot, defineVaporComponent, extend, isRef, onMounted, ref, renderEffect, setClass, setInsertionState, setProp, setStaticTemplateRef, setStyle, template, unref, useId, useSlots, watch } from "vue";
|
|
5
|
+
//#region src/components/popover/usePopover.ts
|
|
6
|
+
var DEFAULT_PLACEMENT = "bottom";
|
|
7
|
+
var DEFAULT_ROLE = "dialog";
|
|
8
|
+
var TARGET_ATTRIBUTES = [
|
|
9
|
+
"aria-controls",
|
|
10
|
+
"aria-expanded",
|
|
11
|
+
"aria-haspopup"
|
|
12
|
+
];
|
|
13
|
+
function isHTMLElement(value) {
|
|
14
|
+
return typeof HTMLElement !== "undefined" && value instanceof HTMLElement;
|
|
15
|
+
}
|
|
16
|
+
function getTargetPosition(rect, placement) {
|
|
17
|
+
const centerX = rect.left + rect.width / 2;
|
|
18
|
+
const centerY = rect.top + rect.height / 2;
|
|
19
|
+
switch (placement) {
|
|
20
|
+
case "right": return {
|
|
21
|
+
x: rect.right,
|
|
22
|
+
y: centerY
|
|
23
|
+
};
|
|
24
|
+
case "bottom": return {
|
|
25
|
+
x: centerX,
|
|
26
|
+
y: rect.bottom
|
|
27
|
+
};
|
|
28
|
+
case "left": return {
|
|
29
|
+
x: rect.left,
|
|
30
|
+
y: centerY
|
|
31
|
+
};
|
|
32
|
+
default: return {
|
|
33
|
+
x: centerX,
|
|
34
|
+
y: rect.top
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function setPixelVar(style, variable, value) {
|
|
39
|
+
if (value != null) style[variable] = `${value}px`;
|
|
40
|
+
}
|
|
41
|
+
function styleOrUndefined(style) {
|
|
42
|
+
return Object.keys(style).length > 0 ? style : void 0;
|
|
43
|
+
}
|
|
44
|
+
function resolveOffsetStyle(offset) {
|
|
45
|
+
if (offset == null) return void 0;
|
|
46
|
+
const style = {};
|
|
47
|
+
if (typeof offset === "number") {
|
|
48
|
+
setPixelVar(style, "--_rp-popover-main-axis-offset", offset);
|
|
49
|
+
return style;
|
|
50
|
+
}
|
|
51
|
+
setPixelVar(style, "--_rp-popover-main-axis-offset", offset.mainAxis);
|
|
52
|
+
setPixelVar(style, "--_rp-popover-cross-axis-offset", offset.crossAxis);
|
|
53
|
+
return styleOrUndefined(style);
|
|
54
|
+
}
|
|
55
|
+
function addIdReference(currentValue, id) {
|
|
56
|
+
const ids = (currentValue ?? "").split(/\s+/).filter(Boolean);
|
|
57
|
+
if (!ids.includes(id)) ids.push(id);
|
|
58
|
+
return ids.join(" ");
|
|
59
|
+
}
|
|
60
|
+
function snapshotAttributes(element) {
|
|
61
|
+
const snapshot = {};
|
|
62
|
+
for (const attribute of TARGET_ATTRIBUTES) snapshot[attribute] = element.getAttribute(attribute);
|
|
63
|
+
return snapshot;
|
|
64
|
+
}
|
|
65
|
+
function restoreAttributes(element, snapshot) {
|
|
66
|
+
for (const attribute of TARGET_ATTRIBUTES) {
|
|
67
|
+
const value = snapshot[attribute];
|
|
68
|
+
if (value == null) element.removeAttribute(attribute);
|
|
69
|
+
else element.setAttribute(attribute, value);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function applyTargetAttributes(element, snapshot, options) {
|
|
73
|
+
element.setAttribute("aria-controls", addIdReference(snapshot["aria-controls"], options.id));
|
|
74
|
+
element.setAttribute("aria-expanded", String(options.expanded));
|
|
75
|
+
element.setAttribute("aria-haspopup", options.role);
|
|
76
|
+
}
|
|
77
|
+
function resolveTargetElement(target) {
|
|
78
|
+
if (!target) return null;
|
|
79
|
+
if (typeof target !== "string") return isHTMLElement(target) ? target : null;
|
|
80
|
+
if (typeof document === "undefined") return null;
|
|
81
|
+
try {
|
|
82
|
+
const element = document.querySelector(target);
|
|
83
|
+
return isHTMLElement(element) ? element : null;
|
|
84
|
+
} catch {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
function usePopover(props, emitOpenChange) {
|
|
89
|
+
const slots = useSlots();
|
|
90
|
+
const generatedId = useId();
|
|
91
|
+
const rootRef = ref(null);
|
|
92
|
+
const targetElement = ref(null);
|
|
93
|
+
const targetPosition = ref(null);
|
|
94
|
+
const uncontrolledOpen = ref(false);
|
|
95
|
+
const popoverId = computed(() => props.id ?? `${generatedId}-popover`);
|
|
96
|
+
const placement = computed(() => props.placement ?? DEFAULT_PLACEMENT);
|
|
97
|
+
const popoverRole = computed(() => props.role ?? DEFAULT_ROLE);
|
|
98
|
+
const isTargetMode = computed(() => props.target != null && props.target !== "");
|
|
99
|
+
const hasContent = computed(() => Boolean(slots.content || isTargetMode.value && slots.default));
|
|
100
|
+
const isDisabled = computed(() => Boolean(props.disabled || !hasContent.value));
|
|
101
|
+
const isOpen = computed(() => props.open ?? uncontrolledOpen.value);
|
|
102
|
+
const isVisible = computed(() => isOpen.value && !isDisabled.value);
|
|
103
|
+
const shouldRenderContent = computed(() => !isDisabled.value);
|
|
104
|
+
const shouldWireTarget = computed(() => isTargetMode.value && !isDisabled.value);
|
|
105
|
+
const rootClass = computed(() => bem("rp-popover", {
|
|
106
|
+
[`placement-${placement.value}`]: true,
|
|
107
|
+
target: isTargetMode.value,
|
|
108
|
+
open: isVisible.value,
|
|
109
|
+
disabled: props.disabled
|
|
110
|
+
}));
|
|
111
|
+
const contentStyle = computed(() => {
|
|
112
|
+
const style = { ...resolveOffsetStyle(props.offset) };
|
|
113
|
+
if (isTargetMode.value && targetPosition.value) {
|
|
114
|
+
setPixelVar(style, "--_rp-popover-target-x", targetPosition.value.x);
|
|
115
|
+
setPixelVar(style, "--_rp-popover-target-y", targetPosition.value.y);
|
|
116
|
+
}
|
|
117
|
+
return styleOrUndefined(style);
|
|
118
|
+
});
|
|
119
|
+
const triggerProps = computed(() => ({
|
|
120
|
+
"aria-controls": isDisabled.value ? void 0 : popoverId.value,
|
|
121
|
+
"aria-expanded": isDisabled.value ? void 0 : isVisible.value,
|
|
122
|
+
"aria-haspopup": isDisabled.value ? void 0 : popoverRole.value,
|
|
123
|
+
onClick: onTriggerClick,
|
|
124
|
+
onKeydown: onTriggerKeydown
|
|
125
|
+
}));
|
|
126
|
+
const contentSlotProps = computed(() => ({
|
|
127
|
+
isOpen: isVisible.value,
|
|
128
|
+
open: openPopover,
|
|
129
|
+
close: closePopover,
|
|
130
|
+
toggle: togglePopover
|
|
131
|
+
}));
|
|
132
|
+
const slotProps = computed(() => ({
|
|
133
|
+
triggerProps: triggerProps.value,
|
|
134
|
+
...contentSlotProps.value
|
|
135
|
+
}));
|
|
136
|
+
function setOpen(nextOpen) {
|
|
137
|
+
const previousOpen = isOpen.value;
|
|
138
|
+
if (props.open === void 0) uncontrolledOpen.value = nextOpen;
|
|
139
|
+
if (previousOpen !== nextOpen) emitOpenChange?.(nextOpen);
|
|
140
|
+
}
|
|
141
|
+
function openPopover() {
|
|
142
|
+
if (isDisabled.value) return;
|
|
143
|
+
updateTargetPosition();
|
|
144
|
+
setOpen(true);
|
|
145
|
+
}
|
|
146
|
+
function closePopover() {
|
|
147
|
+
setOpen(false);
|
|
148
|
+
}
|
|
149
|
+
function togglePopover() {
|
|
150
|
+
if (isVisible.value) closePopover();
|
|
151
|
+
else openPopover();
|
|
152
|
+
}
|
|
153
|
+
function onTriggerClick() {
|
|
154
|
+
togglePopover();
|
|
155
|
+
}
|
|
156
|
+
function onTriggerKeydown(event) {
|
|
157
|
+
if (event.key !== "Escape") return;
|
|
158
|
+
event.stopPropagation();
|
|
159
|
+
closePopover();
|
|
160
|
+
}
|
|
161
|
+
function onTargetClick() {
|
|
162
|
+
togglePopover();
|
|
163
|
+
}
|
|
164
|
+
function readTarget() {
|
|
165
|
+
return isRef(props.target) ? props.target.value : props.target;
|
|
166
|
+
}
|
|
167
|
+
function updateTargetPosition() {
|
|
168
|
+
if (!isTargetMode.value || !targetElement.value) {
|
|
169
|
+
targetPosition.value = null;
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
targetPosition.value = getTargetPosition(targetElement.value.getBoundingClientRect(), placement.value);
|
|
173
|
+
}
|
|
174
|
+
function isEventInsidePopover(event) {
|
|
175
|
+
const eventTarget = event.target;
|
|
176
|
+
if (typeof Node === "undefined" || !(eventTarget instanceof Node)) return false;
|
|
177
|
+
return Boolean(rootRef.value?.contains(eventTarget) || targetElement.value?.contains(eventTarget));
|
|
178
|
+
}
|
|
179
|
+
function onDocumentClick(event) {
|
|
180
|
+
if (props.closeOnOutsideClick === false || isEventInsidePopover(event)) return;
|
|
181
|
+
closePopover();
|
|
182
|
+
}
|
|
183
|
+
function onDocumentKeydown(event) {
|
|
184
|
+
if (props.closeOnEscape === false || event.key !== "Escape") return;
|
|
185
|
+
closePopover();
|
|
186
|
+
}
|
|
187
|
+
function syncTargetElement() {
|
|
188
|
+
const nextTarget = isTargetMode.value ? resolveTargetElement(readTarget()) : null;
|
|
189
|
+
if (targetElement.value !== nextTarget) targetElement.value = nextTarget;
|
|
190
|
+
if (!nextTarget) {
|
|
191
|
+
targetPosition.value = null;
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
if (isVisible.value) updateTargetPosition();
|
|
195
|
+
}
|
|
196
|
+
watch(isDisabled, (disabled) => {
|
|
197
|
+
if (disabled) closePopover();
|
|
198
|
+
});
|
|
199
|
+
watch(() => readTarget(), () => syncTargetElement(), { flush: "post" });
|
|
200
|
+
watch([shouldWireTarget, targetElement], ([shouldWire, target], _previous, onCleanup) => {
|
|
201
|
+
if (!shouldWire || !target) return;
|
|
202
|
+
target.addEventListener("click", onTargetClick);
|
|
203
|
+
onCleanup(() => {
|
|
204
|
+
target.removeEventListener("click", onTargetClick);
|
|
205
|
+
});
|
|
206
|
+
}, { flush: "sync" });
|
|
207
|
+
watch([
|
|
208
|
+
shouldWireTarget,
|
|
209
|
+
targetElement,
|
|
210
|
+
popoverId,
|
|
211
|
+
popoverRole,
|
|
212
|
+
isVisible
|
|
213
|
+
], ([shouldWire, target], _previous, onCleanup) => {
|
|
214
|
+
if (!shouldWire || !target) return;
|
|
215
|
+
const snapshot = snapshotAttributes(target);
|
|
216
|
+
applyTargetAttributes(target, snapshot, {
|
|
217
|
+
id: popoverId.value,
|
|
218
|
+
expanded: isVisible.value,
|
|
219
|
+
role: popoverRole.value
|
|
220
|
+
});
|
|
221
|
+
onCleanup(() => {
|
|
222
|
+
restoreAttributes(target, snapshot);
|
|
223
|
+
});
|
|
224
|
+
}, { flush: "sync" });
|
|
225
|
+
watch([
|
|
226
|
+
isVisible,
|
|
227
|
+
isTargetMode,
|
|
228
|
+
targetElement
|
|
229
|
+
], ([visible, targetMode, target], _previous, onCleanup) => {
|
|
230
|
+
if (!visible || !targetMode || !target || typeof window === "undefined") return;
|
|
231
|
+
window.addEventListener("resize", updateTargetPosition);
|
|
232
|
+
window.addEventListener("scroll", updateTargetPosition, true);
|
|
233
|
+
onCleanup(() => {
|
|
234
|
+
window.removeEventListener("resize", updateTargetPosition);
|
|
235
|
+
window.removeEventListener("scroll", updateTargetPosition, true);
|
|
236
|
+
});
|
|
237
|
+
}, { flush: "sync" });
|
|
238
|
+
watch(isVisible, (visible, _previous, onCleanup) => {
|
|
239
|
+
if (!visible || typeof document === "undefined") return;
|
|
240
|
+
document.addEventListener("click", onDocumentClick, true);
|
|
241
|
+
document.addEventListener("keydown", onDocumentKeydown);
|
|
242
|
+
onCleanup(() => {
|
|
243
|
+
document.removeEventListener("click", onDocumentClick, true);
|
|
244
|
+
document.removeEventListener("keydown", onDocumentKeydown);
|
|
245
|
+
});
|
|
246
|
+
}, {
|
|
247
|
+
flush: "sync",
|
|
248
|
+
immediate: true
|
|
249
|
+
});
|
|
250
|
+
watch([
|
|
251
|
+
targetElement,
|
|
252
|
+
placement,
|
|
253
|
+
isVisible
|
|
254
|
+
], () => {
|
|
255
|
+
if (isVisible.value) updateTargetPosition();
|
|
256
|
+
}, { flush: "sync" });
|
|
257
|
+
onMounted(syncTargetElement);
|
|
258
|
+
return {
|
|
259
|
+
rootRef,
|
|
260
|
+
popoverId,
|
|
261
|
+
isOpen,
|
|
262
|
+
isVisible,
|
|
263
|
+
isTargetMode,
|
|
264
|
+
popoverRole,
|
|
265
|
+
shouldRenderContent,
|
|
266
|
+
rootClass,
|
|
267
|
+
contentStyle,
|
|
268
|
+
triggerProps,
|
|
269
|
+
slotProps,
|
|
270
|
+
contentSlotProps,
|
|
271
|
+
openPopover,
|
|
272
|
+
closePopover,
|
|
273
|
+
togglePopover,
|
|
274
|
+
onTriggerKeydown
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
//#endregion
|
|
278
|
+
//#region src/components/popover/popover.vue?vue&type=script&setup=true&vapor=true&lang.ts
|
|
279
|
+
var t0 = template("<section data-v-afdc2686 class=rp-popover__content>");
|
|
280
|
+
var t1 = template("<span data-v-afdc2686>", 1);
|
|
281
|
+
//#endregion
|
|
282
|
+
//#region src/components/popover/popover.vue
|
|
283
|
+
var popover_default = /*#__PURE__*/ _plugin_vue_export_helper_default(/* @__PURE__ */ defineVaporComponent({
|
|
284
|
+
name: "RpPopover",
|
|
285
|
+
__name: "popover",
|
|
286
|
+
props: {
|
|
287
|
+
id: {},
|
|
288
|
+
target: {},
|
|
289
|
+
placement: { default: "bottom" },
|
|
290
|
+
offset: {},
|
|
291
|
+
open: {
|
|
292
|
+
type: Boolean,
|
|
293
|
+
default: void 0
|
|
294
|
+
},
|
|
295
|
+
disabled: {
|
|
296
|
+
type: Boolean,
|
|
297
|
+
default: false
|
|
298
|
+
},
|
|
299
|
+
role: { default: "dialog" },
|
|
300
|
+
closeOnOutsideClick: {
|
|
301
|
+
type: Boolean,
|
|
302
|
+
default: true
|
|
303
|
+
},
|
|
304
|
+
closeOnEscape: {
|
|
305
|
+
type: Boolean,
|
|
306
|
+
default: true
|
|
307
|
+
}
|
|
308
|
+
},
|
|
309
|
+
emits: ["update:open"],
|
|
310
|
+
setup(__props, { emit: __emit }) {
|
|
311
|
+
const props = __props;
|
|
312
|
+
const emit = __emit;
|
|
313
|
+
const { rootRef, popoverId, isVisible, isTargetMode, popoverRole, shouldRenderContent, rootClass, contentStyle, slotProps, contentSlotProps } = usePopover(props, (open) => {
|
|
314
|
+
emit("update:open", open);
|
|
315
|
+
});
|
|
316
|
+
const n12 = t1();
|
|
317
|
+
renderEffect(() => setClass(n12, unref(rootClass)));
|
|
318
|
+
setInsertionState(n12, null, 0);
|
|
319
|
+
createIf(() => !unref(isTargetMode), () => {
|
|
320
|
+
return createSlot("default", {
|
|
321
|
+
triggerProps: () => unref(slotProps).triggerProps,
|
|
322
|
+
isOpen: () => unref(slotProps).isOpen,
|
|
323
|
+
open: () => unref(slotProps).open,
|
|
324
|
+
close: () => unref(slotProps).close,
|
|
325
|
+
toggle: () => unref(slotProps).toggle
|
|
326
|
+
}, null, 1);
|
|
327
|
+
});
|
|
328
|
+
setInsertionState(n12, null, 1);
|
|
329
|
+
createComponent(VaporTransition, {
|
|
330
|
+
name: "rp-popover-content",
|
|
331
|
+
persisted: ""
|
|
332
|
+
}, extend(() => {
|
|
333
|
+
return createIf(() => unref(shouldRenderContent), () => {
|
|
334
|
+
const n10 = t0();
|
|
335
|
+
renderEffect(() => {
|
|
336
|
+
setProp(n10, "id", unref(popoverId));
|
|
337
|
+
setProp(n10, "role", unref(popoverRole));
|
|
338
|
+
setStyle(n10, unref(contentStyle));
|
|
339
|
+
});
|
|
340
|
+
setInsertionState(n10, null, 0);
|
|
341
|
+
createSlot("content", {
|
|
342
|
+
isOpen: () => unref(contentSlotProps).isOpen,
|
|
343
|
+
open: () => unref(contentSlotProps).open,
|
|
344
|
+
close: () => unref(contentSlotProps).close,
|
|
345
|
+
toggle: () => unref(contentSlotProps).toggle
|
|
346
|
+
}, () => {
|
|
347
|
+
return createIf(() => unref(isTargetMode), () => {
|
|
348
|
+
return createSlot("default", {
|
|
349
|
+
isOpen: () => unref(contentSlotProps).isOpen,
|
|
350
|
+
open: () => unref(contentSlotProps).open,
|
|
351
|
+
close: () => unref(contentSlotProps).close,
|
|
352
|
+
toggle: () => unref(contentSlotProps).toggle
|
|
353
|
+
}, null, 1);
|
|
354
|
+
}, null, 129);
|
|
355
|
+
}, 1);
|
|
356
|
+
applyVShow(n10, () => unref(isVisible));
|
|
357
|
+
return n10;
|
|
358
|
+
}, null, 129);
|
|
359
|
+
}, { _: 8 }));
|
|
360
|
+
setStaticTemplateRef(n12, rootRef, null, "rootRef");
|
|
361
|
+
return n12;
|
|
362
|
+
}
|
|
363
|
+
}), [["__scopeId", "data-v-afdc2686"]]);
|
|
364
|
+
//#endregion
|
|
365
|
+
export { popover_default as t };
|
|
366
|
+
|
|
367
|
+
//# sourceMappingURL=popover.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"popover.js","names":[],"sources":["../src/components/popover/usePopover.ts","../src/components/popover/popover.vue","../src/components/popover/popover.vue"],"sourcesContent":["import { computed, isRef, onMounted, ref, useId, useSlots, watch, type CSSProperties } from 'vue';\nimport { bem } from '@/utils/bem';\nimport type {\n PopoverContentSlotProps,\n PopoverOffset,\n PopoverPlacement,\n PopoverProps,\n PopoverRole,\n PopoverSlotProps,\n PopoverTriggerProps,\n} from './types';\n\ninterface PopoverPosition {\n x: number;\n y: number;\n}\n\ntype PopoverCssVariable =\n | '--_rp-popover-main-axis-offset'\n | '--_rp-popover-cross-axis-offset'\n | '--_rp-popover-target-x'\n | '--_rp-popover-target-y';\n\nconst DEFAULT_PLACEMENT: PopoverPlacement = 'bottom';\nconst DEFAULT_ROLE: PopoverRole = 'dialog';\nconst TARGET_ATTRIBUTES = ['aria-controls', 'aria-expanded', 'aria-haspopup'] as const;\n\ntype TargetAttribute = (typeof TARGET_ATTRIBUTES)[number];\n\nfunction isHTMLElement(value: unknown): value is HTMLElement {\n return typeof HTMLElement !== 'undefined' && value instanceof HTMLElement;\n}\n\nfunction getTargetPosition(rect: DOMRect, placement: PopoverPlacement): PopoverPosition {\n const centerX = rect.left + rect.width / 2;\n const centerY = rect.top + rect.height / 2;\n\n switch (placement) {\n case 'right':\n return { x: rect.right, y: centerY };\n case 'bottom':\n return { x: centerX, y: rect.bottom };\n case 'left':\n return { x: rect.left, y: centerY };\n case 'top':\n default:\n return { x: centerX, y: rect.top };\n }\n}\n\nfunction setPixelVar(\n style: CSSProperties,\n variable: PopoverCssVariable,\n value: number | undefined,\n) {\n if (value != null) style[variable] = `${value}px`;\n}\n\nfunction styleOrUndefined(style: CSSProperties): CSSProperties | undefined {\n return Object.keys(style).length > 0 ? style : undefined;\n}\n\nfunction resolveOffsetStyle(offset: PopoverOffset | undefined): CSSProperties | undefined {\n if (offset == null) return undefined;\n\n const style: CSSProperties = {};\n\n if (typeof offset === 'number') {\n setPixelVar(style, '--_rp-popover-main-axis-offset', offset);\n return style;\n }\n\n setPixelVar(style, '--_rp-popover-main-axis-offset', offset.mainAxis);\n setPixelVar(style, '--_rp-popover-cross-axis-offset', offset.crossAxis);\n\n return styleOrUndefined(style);\n}\n\nfunction addIdReference(currentValue: string | null, id: string) {\n const ids = (currentValue ?? '').split(/\\s+/).filter(Boolean);\n if (!ids.includes(id)) ids.push(id);\n return ids.join(' ');\n}\n\nfunction snapshotAttributes(element: HTMLElement) {\n const snapshot = {} as Record<TargetAttribute, string | null>;\n\n for (const attribute of TARGET_ATTRIBUTES) {\n snapshot[attribute] = element.getAttribute(attribute);\n }\n\n return snapshot;\n}\n\nfunction restoreAttributes(element: HTMLElement, snapshot: Record<TargetAttribute, string | null>) {\n for (const attribute of TARGET_ATTRIBUTES) {\n const value = snapshot[attribute];\n if (value == null) element.removeAttribute(attribute);\n else element.setAttribute(attribute, value);\n }\n}\n\nfunction applyTargetAttributes(\n element: HTMLElement,\n snapshot: Record<TargetAttribute, string | null>,\n options: {\n id: string;\n expanded: boolean;\n role: PopoverRole;\n },\n) {\n element.setAttribute('aria-controls', addIdReference(snapshot['aria-controls'], options.id));\n element.setAttribute('aria-expanded', String(options.expanded));\n element.setAttribute('aria-haspopup', options.role);\n}\n\nfunction resolveTargetElement(target: string | HTMLElement | null | undefined): HTMLElement | null {\n if (!target) return null;\n\n if (typeof target !== 'string') return isHTMLElement(target) ? target : null;\n if (typeof document === 'undefined') return null;\n\n try {\n const element = document.querySelector(target);\n return isHTMLElement(element) ? element : null;\n } catch {\n return null;\n }\n}\n\nexport function usePopover(\n props: Readonly<PopoverProps>,\n emitOpenChange?: (open: boolean) => void,\n) {\n const slots = useSlots();\n const generatedId = useId();\n const rootRef = ref<HTMLElement | null>(null);\n const targetElement = ref<HTMLElement | null>(null);\n const targetPosition = ref<PopoverPosition | null>(null);\n const uncontrolledOpen = ref(false);\n\n const popoverId = computed(() => props.id ?? `${generatedId}-popover`);\n const placement = computed(() => props.placement ?? DEFAULT_PLACEMENT);\n const popoverRole = computed(() => props.role ?? DEFAULT_ROLE);\n const isTargetMode = computed(() => props.target != null && props.target !== '');\n const hasContent = computed(() =>\n Boolean(slots.content || (isTargetMode.value && slots.default)),\n );\n const isDisabled = computed(() => Boolean(props.disabled || !hasContent.value));\n const isOpen = computed(() => props.open ?? uncontrolledOpen.value);\n const isVisible = computed(() => isOpen.value && !isDisabled.value);\n const shouldRenderContent = computed(() => !isDisabled.value);\n const shouldWireTarget = computed(() => isTargetMode.value && !isDisabled.value);\n\n const rootClass = computed(() =>\n bem('rp-popover', {\n [`placement-${placement.value}`]: true,\n target: isTargetMode.value,\n open: isVisible.value,\n disabled: props.disabled,\n }),\n );\n\n const contentStyle = computed<CSSProperties | undefined>(() => {\n const style: CSSProperties = {\n ...resolveOffsetStyle(props.offset),\n };\n\n if (isTargetMode.value && targetPosition.value) {\n setPixelVar(style, '--_rp-popover-target-x', targetPosition.value.x);\n setPixelVar(style, '--_rp-popover-target-y', targetPosition.value.y);\n }\n\n return styleOrUndefined(style);\n });\n\n const triggerProps = computed<PopoverTriggerProps>(() => ({\n 'aria-controls': isDisabled.value ? undefined : popoverId.value,\n 'aria-expanded': isDisabled.value ? undefined : isVisible.value,\n 'aria-haspopup': isDisabled.value ? undefined : popoverRole.value,\n onClick: onTriggerClick,\n onKeydown: onTriggerKeydown,\n }));\n\n const contentSlotProps = computed<PopoverContentSlotProps>(() => ({\n isOpen: isVisible.value,\n open: openPopover,\n close: closePopover,\n toggle: togglePopover,\n }));\n\n const slotProps = computed<PopoverSlotProps>(() => ({\n triggerProps: triggerProps.value,\n ...contentSlotProps.value,\n }));\n\n function setOpen(nextOpen: boolean) {\n const previousOpen = isOpen.value;\n if (props.open === undefined) uncontrolledOpen.value = nextOpen;\n if (previousOpen !== nextOpen) emitOpenChange?.(nextOpen);\n }\n\n function openPopover() {\n if (isDisabled.value) return;\n updateTargetPosition();\n setOpen(true);\n }\n\n function closePopover() {\n setOpen(false);\n }\n\n function togglePopover() {\n if (isVisible.value) closePopover();\n else openPopover();\n }\n\n function onTriggerClick() {\n togglePopover();\n }\n\n function onTriggerKeydown(event: KeyboardEvent) {\n if (event.key !== 'Escape') return;\n event.stopPropagation();\n closePopover();\n }\n\n function onTargetClick() {\n togglePopover();\n }\n\n function readTarget() {\n return isRef(props.target) ? props.target.value : props.target;\n }\n\n function updateTargetPosition() {\n if (!isTargetMode.value || !targetElement.value) {\n targetPosition.value = null;\n return;\n }\n\n targetPosition.value = getTargetPosition(\n targetElement.value.getBoundingClientRect(),\n placement.value,\n );\n }\n\n function isEventInsidePopover(event: Event) {\n const eventTarget = event.target;\n if (typeof Node === 'undefined' || !(eventTarget instanceof Node)) return false;\n\n return Boolean(\n rootRef.value?.contains(eventTarget) || targetElement.value?.contains(eventTarget),\n );\n }\n\n function onDocumentClick(event: MouseEvent) {\n if (props.closeOnOutsideClick === false || isEventInsidePopover(event)) return;\n closePopover();\n }\n\n function onDocumentKeydown(event: KeyboardEvent) {\n if (props.closeOnEscape === false || event.key !== 'Escape') return;\n closePopover();\n }\n\n function syncTargetElement() {\n const nextTarget = isTargetMode.value ? resolveTargetElement(readTarget()) : null;\n\n if (targetElement.value !== nextTarget) {\n targetElement.value = nextTarget;\n }\n\n if (!nextTarget) {\n targetPosition.value = null;\n return;\n }\n\n if (isVisible.value) updateTargetPosition();\n }\n\n watch(isDisabled, (disabled) => {\n if (disabled) closePopover();\n });\n\n watch(\n () => readTarget(),\n () => syncTargetElement(),\n { flush: 'post' },\n );\n\n watch(\n [shouldWireTarget, targetElement],\n ([shouldWire, target], _previous, onCleanup) => {\n if (!shouldWire || !target) return;\n\n target.addEventListener('click', onTargetClick);\n onCleanup(() => {\n target.removeEventListener('click', onTargetClick);\n });\n },\n { flush: 'sync' },\n );\n\n watch(\n [shouldWireTarget, targetElement, popoverId, popoverRole, isVisible],\n ([shouldWire, target], _previous, onCleanup) => {\n if (!shouldWire || !target) return;\n\n const snapshot = snapshotAttributes(target);\n applyTargetAttributes(target, snapshot, {\n id: popoverId.value,\n expanded: isVisible.value,\n role: popoverRole.value,\n });\n\n onCleanup(() => {\n restoreAttributes(target, snapshot);\n });\n },\n { flush: 'sync' },\n );\n\n watch(\n [isVisible, isTargetMode, targetElement],\n ([visible, targetMode, target], _previous, onCleanup) => {\n if (!visible || !targetMode || !target || typeof window === 'undefined') return;\n\n window.addEventListener('resize', updateTargetPosition);\n window.addEventListener('scroll', updateTargetPosition, true);\n\n onCleanup(() => {\n window.removeEventListener('resize', updateTargetPosition);\n window.removeEventListener('scroll', updateTargetPosition, true);\n });\n },\n { flush: 'sync' },\n );\n\n watch(\n isVisible,\n (visible, _previous, onCleanup) => {\n if (!visible || typeof document === 'undefined') return;\n\n document.addEventListener('click', onDocumentClick, true);\n document.addEventListener('keydown', onDocumentKeydown);\n\n onCleanup(() => {\n document.removeEventListener('click', onDocumentClick, true);\n document.removeEventListener('keydown', onDocumentKeydown);\n });\n },\n { flush: 'sync', immediate: true },\n );\n\n watch(\n [targetElement, placement, isVisible],\n () => {\n if (isVisible.value) updateTargetPosition();\n },\n { flush: 'sync' },\n );\n\n onMounted(syncTargetElement);\n\n return {\n rootRef,\n popoverId,\n isOpen,\n isVisible,\n isTargetMode,\n popoverRole,\n shouldRenderContent,\n rootClass,\n contentStyle,\n triggerProps,\n slotProps,\n contentSlotProps,\n openPopover,\n closePopover,\n togglePopover,\n onTriggerKeydown,\n };\n}\n","<template>\n <span ref=\"rootRef\" :class=\"rootClass\">\n <slot\n v-if=\"!isTargetMode\"\n :trigger-props=\"slotProps.triggerProps\"\n :is-open=\"slotProps.isOpen\"\n :open=\"slotProps.open\"\n :close=\"slotProps.close\"\n :toggle=\"slotProps.toggle\"\n />\n\n <Transition name=\"rp-popover-content\">\n <section\n v-if=\"shouldRenderContent\"\n v-show=\"isVisible\"\n :id=\"popoverId\"\n class=\"rp-popover__content\"\n :role=\"popoverRole\"\n :style=\"contentStyle\"\n >\n <slot\n name=\"content\"\n :is-open=\"contentSlotProps.isOpen\"\n :open=\"contentSlotProps.open\"\n :close=\"contentSlotProps.close\"\n :toggle=\"contentSlotProps.toggle\"\n >\n <slot\n v-if=\"isTargetMode\"\n :is-open=\"contentSlotProps.isOpen\"\n :open=\"contentSlotProps.open\"\n :close=\"contentSlotProps.close\"\n :toggle=\"contentSlotProps.toggle\"\n />\n </slot>\n </section>\n </Transition>\n </span>\n</template>\n\n<script lang=\"ts\" setup vapor>\nimport { usePopover } from './usePopover';\nimport type { PopoverProps } from './types';\n\ndefineOptions({ name: 'RpPopover' });\n\nconst props = withDefaults(defineProps<PopoverProps>(), {\n placement: 'bottom',\n open: undefined,\n disabled: false,\n role: 'dialog',\n closeOnOutsideClick: true,\n closeOnEscape: true,\n});\n\nconst emit = defineEmits<{\n 'update:open': [value: boolean];\n}>();\n\nconst {\n rootRef,\n popoverId,\n isVisible,\n isTargetMode,\n popoverRole,\n shouldRenderContent,\n rootClass,\n contentStyle,\n slotProps,\n contentSlotProps,\n} = usePopover(props, (open) => {\n emit('update:open', open);\n});\n\nvoid rootRef;\n</script>\n\n<style src=\"./popover.scss\" lang=\"scss\" scoped></style>\n","<template>\n <span ref=\"rootRef\" :class=\"rootClass\">\n <slot\n v-if=\"!isTargetMode\"\n :trigger-props=\"slotProps.triggerProps\"\n :is-open=\"slotProps.isOpen\"\n :open=\"slotProps.open\"\n :close=\"slotProps.close\"\n :toggle=\"slotProps.toggle\"\n />\n\n <Transition name=\"rp-popover-content\">\n <section\n v-if=\"shouldRenderContent\"\n v-show=\"isVisible\"\n :id=\"popoverId\"\n class=\"rp-popover__content\"\n :role=\"popoverRole\"\n :style=\"contentStyle\"\n >\n <slot\n name=\"content\"\n :is-open=\"contentSlotProps.isOpen\"\n :open=\"contentSlotProps.open\"\n :close=\"contentSlotProps.close\"\n :toggle=\"contentSlotProps.toggle\"\n >\n <slot\n v-if=\"isTargetMode\"\n :is-open=\"contentSlotProps.isOpen\"\n :open=\"contentSlotProps.open\"\n :close=\"contentSlotProps.close\"\n :toggle=\"contentSlotProps.toggle\"\n />\n </slot>\n </section>\n </Transition>\n </span>\n</template>\n\n<script lang=\"ts\" setup vapor>\nimport { usePopover } from './usePopover';\nimport type { PopoverProps } from './types';\n\ndefineOptions({ name: 'RpPopover' });\n\nconst props = withDefaults(defineProps<PopoverProps>(), {\n placement: 'bottom',\n open: undefined,\n disabled: false,\n role: 'dialog',\n closeOnOutsideClick: true,\n closeOnEscape: true,\n});\n\nconst emit = defineEmits<{\n 'update:open': [value: boolean];\n}>();\n\nconst {\n rootRef,\n popoverId,\n isVisible,\n isTargetMode,\n popoverRole,\n shouldRenderContent,\n rootClass,\n contentStyle,\n slotProps,\n contentSlotProps,\n} = usePopover(props, (open) => {\n emit('update:open', open);\n});\n\nvoid rootRef;\n</script>\n\n<style src=\"./popover.scss\" lang=\"scss\" scoped></style>\n"],"mappings":";;;;AAuBA,IAAM,oBAAsC;AAC5C,IAAM,eAA4B;AAClC,IAAM,oBAAoB;CAAC;CAAiB;CAAiB;AAAe;AAI5E,SAAS,cAAc,OAAsC;CACzD,OAAO,OAAO,gBAAgB,eAAe,iBAAiB;AAClE;AAEA,SAAS,kBAAkB,MAAe,WAA8C;CACpF,MAAM,UAAU,KAAK,OAAO,KAAK,Q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
|
+
import { t as _plugin_vue_export_helper_default } from "./_plugin-vue_export-helper.js";
|
|
2
4
|
import { n as getComponentCustomColor, r as isComponentPresetColor, t as componentColors } from "./componentColors.js";
|
|
3
|
-
import { n as bem, t as _plugin_vue_export_helper_default } from "./_plugin-vue_export-helper.js";
|
|
4
5
|
import { t as useControlState } from "./useControlState.js";
|
|
5
6
|
import { computed, createIf, createSlot, defineVaporComponent, renderEffect, setAttr, setClass, setInsertionState, setProp, setStyle, setText, template, toDisplayString, unref } from "vue";
|
|
6
7
|
//#region src/components/progress/useProgress.ts
|
package/dist/progress.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"progress.js","names":[],"sources":["../src/components/progress/useProgress.ts","../src/components/progress/progress.vue","../src/components/progress/progress.vue","../src/components/progress/types.ts"],"sourcesContent":["import { computed, type CSSProperties } from 'vue';\nimport { useControlState } from '@/composables/useControlState';\nimport { bem } from '@/utils/bem';\nimport { getComponentCustomColor, isComponentPresetColor } from '@/utils/componentColors';\nimport type { ProgressProps } from './types';\n\ntype ProgressStateProps = Readonly<\n ProgressProps & {\n min: number;\n max: number;\n indeterminate: boolean;\n showValue: boolean;\n }\n>;\n\nexport function normalizeProgressBounds(min: number, max: number) {\n const safeMin = Number.isFinite(min) ? min : 0;\n const safeMax = Number.isFinite(max) ? max : 100;\n\n return safeMax >= safeMin ? { min: safeMin, max: safeMax } : { min: safeMax, max: safeMin };\n}\n\nexport function normalizeProgressValue(value: number | null | undefined, min: number, max: number) {\n const safeValue = Number.isFinite(value) ? Number(value) : min;\n\n return Math.min(max, Math.max(min, safeValue));\n}\n\nexport function getProgressValuePercent(value: number, min: number, max: number) {\n if (max <= min) return 0;\n\n const percent = ((value - min) / (max - min)) * 100;\n return Math.min(100, Math.max(0, percent));\n}\n\nfunction getFormattedProgressValue(\n value: number,\n percent: number,\n formatter: ProgressProps['formatValue'],\n) {\n return formatter ? formatter(value, percent) : `${Math.round(percent)}%`;\n}\n\nfunction getProgressAriaValueText(\n value: number,\n percent: number,\n ariaValueText: ProgressProps['ariaValueText'],\n formatter: ProgressProps['formatValue'],\n) {\n if (typeof ariaValueText === 'function') return String(ariaValueText(value, percent));\n if (ariaValueText != null && ariaValueText !== '') return String(ariaValueText);\n if (formatter) return String(formatter(value, percent));\n\n return undefined;\n}\n\nfunction setProgressStyleValue(\n style: CSSProperties,\n property: `--_rp-progress-${string}`,\n value: string | undefined,\n) {\n if (value) {\n style[property] = value;\n }\n}\n\nexport function useProgress(props: ProgressStateProps) {\n const control = useControlState(props);\n\n const bounds = computed(() => normalizeProgressBounds(props.min, props.max));\n const isIndeterminate = computed(() => props.indeterminate || props.value == null);\n const normalizedValue = computed(() =>\n normalizeProgressValue(props.value, bounds.value.min, bounds.value.max),\n );\n const valuePercent = computed(() =>\n getProgressValuePercent(normalizedValue.value, bounds.value.min, bounds.value.max),\n );\n const formattedValue = computed(() =>\n getFormattedProgressValue(normalizedValue.value, valuePercent.value, props.formatValue),\n );\n const ariaValueText = computed(() =>\n isIndeterminate.value\n ? undefined\n : getProgressAriaValueText(\n normalizedValue.value,\n valuePercent.value,\n props.ariaValueText,\n props.formatValue,\n ),\n );\n const rootClass = computed(() =>\n bem('rp-progress', {\n [`color-${props.color}`]: isComponentPresetColor(props.color),\n [`size-${props.size}`]: Boolean(props.size),\n [`radius-${props.radius}`]: Boolean(props.radius),\n indeterminate: isIndeterminate.value,\n }),\n );\n const rootStyle = computed<CSSProperties>(() => {\n const style: CSSProperties = {\n '--_rp-progress-value': `${valuePercent.value}%`,\n '--_rp-progress-ratio': `${valuePercent.value / 100}`,\n };\n\n setProgressStyleValue(\n style,\n '--_rp-progress-custom-color',\n getComponentCustomColor(props.color),\n );\n\n return style;\n });\n\n return {\n control,\n rootClass,\n rootStyle,\n isIndeterminate,\n normalizedValue,\n valuePercent,\n formattedValue,\n ariaValueText,\n ariaValueMin: computed(() => (isIndeterminate.value ? undefined : bounds.value.min)),\n ariaValueMax: computed(() => (isIndeterminate.value ? undefined : bounds.value.max)),\n ariaValueNow: computed(() => (isIndeterminate.value ? undefined : normalizedValue.value)),\n };\n}\n","<template>\n <div\n :id=\"control.id\"\n :class=\"rootClass\"\n :style=\"rootStyle\"\n role=\"progressbar\"\n :data-state=\"isIndeterminate ? 'indeterminate' : 'determinate'\"\n :aria-label=\"ariaLabel || undefined\"\n :aria-labelledby=\"control.ariaLabelledby\"\n :aria-describedby=\"control.ariaDescribedby\"\n :aria-valuemin=\"ariaValueMin\"\n :aria-valuemax=\"ariaValueMax\"\n :aria-valuenow=\"ariaValueNow\"\n :aria-valuetext=\"ariaValueText\"\n >\n <span\n v-if=\"$slots.default || (!isIndeterminate && ($slots.value || showValue))\"\n class=\"rp-progress__header\"\n >\n <span v-if=\"$slots.default\" class=\"rp-progress__label\">\n <slot />\n </span>\n <span\n v-if=\"!isIndeterminate && ($slots.value || showValue)\"\n class=\"rp-progress__value\"\n aria-hidden=\"true\"\n >\n <slot\n v-if=\"$slots.value\"\n name=\"value\"\n :value=\"normalizedValue\"\n :formatted-value=\"formattedValue\"\n :percent=\"valuePercent\"\n />\n <template v-else>{{ formattedValue }}</template>\n </span>\n </span>\n <span class=\"rp-progress__track\" aria-hidden=\"true\">\n <span class=\"rp-progress__indicator\" />\n </span>\n </div>\n</template>\n\n<script lang=\"ts\" setup vapor>\nimport type { ProgressProps } from './types';\nimport { useProgress } from './useProgress';\n\ndefineOptions({ name: 'RpProgress' });\n\nconst props = withDefaults(defineProps<ProgressProps>(), {\n min: 0,\n max: 100,\n indeterminate: false,\n showValue: false,\n});\n\nconst {\n control,\n rootClass,\n rootStyle,\n isIndeterminate,\n normalizedValue,\n valuePercent,\n formattedValue,\n ariaValueText,\n ariaValueMin,\n ariaValueMax,\n ariaValueNow,\n} = useProgress(props);\n</script>\n\n<style src=\"./progress.scss\" lang=\"scss\" scoped></style>\n","<template>\n <div\n :id=\"control.id\"\n :class=\"rootClass\"\n :style=\"rootStyle\"\n role=\"progressbar\"\n :data-state=\"isIndeterminate ? 'indeterminate' : 'determinate'\"\n :aria-label=\"ariaLabel || undefined\"\n :aria-labelledby=\"control.ariaLabelledby\"\n :aria-describedby=\"control.ariaDescribedby\"\n :aria-valuemin=\"ariaValueMin\"\n :aria-valuemax=\"ariaValueMax\"\n :aria-valuenow=\"ariaValueNow\"\n :aria-valuetext=\"ariaValueText\"\n >\n <span\n v-if=\"$slots.default || (!isIndeterminate && ($slots.value || showValue))\"\n class=\"rp-progress__header\"\n >\n <span v-if=\"$slots.default\" class=\"rp-progress__label\">\n <slot />\n </span>\n <span\n v-if=\"!isIndeterminate && ($slots.value || showValue)\"\n class=\"rp-progress__value\"\n aria-hidden=\"true\"\n >\n <slot\n v-if=\"$slots.value\"\n name=\"value\"\n :value=\"normalizedValue\"\n :formatted-value=\"formattedValue\"\n :percent=\"valuePercent\"\n />\n <template v-else>{{ formattedValue }}</template>\n </span>\n </span>\n <span class=\"rp-progress__track\" aria-hidden=\"true\">\n <span class=\"rp-progress__indicator\" />\n </span>\n </div>\n</template>\n\n<script lang=\"ts\" setup vapor>\nimport type { ProgressProps } from './types';\nimport { useProgress } from './useProgress';\n\ndefineOptions({ name: 'RpProgress' });\n\nconst props = withDefaults(defineProps<ProgressProps>(), {\n min: 0,\n max: 100,\n indeterminate: false,\n showValue: false,\n});\n\nconst {\n control,\n rootClass,\n rootStyle,\n isIndeterminate,\n normalizedValue,\n valuePercent,\n formattedValue,\n ariaValueText,\n ariaValueMin,\n ariaValueMax,\n ariaValueNow,\n} = useProgress(props);\n</script>\n\n<style src=\"./progress.scss\" lang=\"scss\" scoped></style>\n","import { componentColors, type ComponentColorValue } from '../../utils/componentColors';\n\nexport const progressColors = componentColors;\n\nexport const progressSizes = ['xs', 'sm', 'md', 'lg', 'xl'] as const;\n\nexport const progressRadiuses = ['none', 'xs', 'sm', 'md', 'lg', 'xl', 'full'] as const;\n\nexport type ProgressColor = ComponentColorValue;\n\nexport type ProgressSize = (typeof progressSizes)[number];\n\nexport type ProgressRadius = (typeof progressRadiuses)[number];\n\nexport type ProgressValueFormatter = (value: number, percent: number) => string | number;\n\nexport interface ProgressProps {\n id?: string;\n value?: number | null;\n min?: number;\n max?: number;\n color?: ProgressColor;\n size?: ProgressSize;\n radius?: ProgressRadius;\n indeterminate?: boolean;\n showValue?: boolean;\n formatValue?: ProgressValueFormatter;\n ariaLabel?: string;\n ariaValueText?: string | ProgressValueFormatter;\n describedby?: string;\n labelledby?: string;\n}\n"],"mappings":";;;;;AAeA,SAAgB,wBAAwB,KAAa,KAAa;CAC9D,MAAM,UAAU,OAAO,SAAS,GAAG,IAAI,MAAM;CAC7C,MAAM,UAAU,OAAO,SAAS,GAAG,IAAI,MAAM;CAE7C,OAAO,WAAW,UAAU;EAAE,KAAK;EAAS,KAAK;CAAQ,IAAI;EAAE,KAAK;EAAS,KAAK;CAAQ;AAC9F;AAEA,SAAgB,uBAAuB,OAAkC,KAAa,KAAa;CAC/F,MAAM,YAAY,OAAO,SAAS,KAAK,IAAI,OAAO,KAAK,IAAI;CAE3D,OAAO,KAAK,IAAI,KAAK,KAAK,IAAI,KAAK,SAAS,CAAC;AACjD;AAEA,SAAgB,wBAAwB,OAAe,KAAa,KAAa;CAC7E,IAAI,OAAO,KAAK,OAAO;CAEvB,MAAM,WAAY,QAAQ,QAAQ,MAAM,OAAQ;CAChD,OAAO,KAAK,IAAI,KAAK,KAAK,IAAI,GAAG,OAAO,CAAC;AAC7C;AAEA,SAAS,0BACL,OACA,SACA,WACF;CACE,OAAO,YAAY,UAAU,OAAO,OAAO,IAAI,GAAG,KAAK,MAAM,OAAO,EAAE;AAC1E;AAEA,SAAS,yBACL,OACA,SACA,eACA,WACF;CACE,IAAI,OAAO,kBAAkB,YAAY,OAAO,OAAO,cAAc,OAAO,OAAO,CAAC;CACpF,IAAI,iBAAiB,QAAQ,kBAAkB,IAAI,OAAO,OAAO,aAAa;CAC9E,IAAI,WAAW,OAAO,OAAO,UAAU,OAAO,OAAO,CAAC;AAG1D;AAEA,SAAS,sB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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ECtEA,MAAM,EACF,SACA,WACA,WACA,iBACA,iBACA,cACA,gBACA,eACA,cACA,cACA,iBACA,YAAY,OAAK;;;;gBAlEZ,MAAI,SAAO,EAAA;iBACJ,MAAA,SAAA,CAAS;iBACT,MAAA,SAAA,CAAS;gBAEhB,cAAY,MAAA,eAAA,IAAe,kBAAA,aAAA;gBAC3B,cAAY,QAAA,aAAa,KAAA,CAAS;gBAClC,mBAAiB,SAAO,cAAA;gBACxB,oBAAkB,SAAO,eAAA;gBACzB,iBAAe,MAAA,YAAA,CAAY;gBAC3B,iBAAe,MAAA,YAAA,CAAY;gBAC3B,iBAAe,MAAA,YAAA,CAAY;gBAC3B,kBAAgB,MAAA,aAAA,CAAa;;;iBAGpB,OAAM,WAAA,CAAc,MAAA,eAAA,MAAoB,OAAM,SAAU,QAAA,kBAAS;;;kBAG3D,OAAM,eAAA;;;;;;;mBAIP,MAAA,eAAA,MAAoB,OAAM,SAAU,QAAA,kBAAS;;;mBAK1C,OAAM,aAAA;uBACZ,SAAY;MACX,aAAO,MAAA,eAAA;MACP,sBAAiB,MAAA,cAAA;MACjB,eAAS,MAAA,YAAA;;;;qDAEM,MAAA,cAAA,CAAc,CAAA,CAAA;;;;;;;;;;;;AEhClD,IAAa,iBAAiB;AAE9B,IAAa,gBAAgB;CAAC;CAAM;CAAM;CAAM;CAAM;AAAI;AAE1D,IAAa,mBAAmB;CAAC;CAAQ;CAAM;CAAM;CAAM;CAAM;CAAM;AAAM"}
|
|
1
|
+
{"version":3,"file":"progress.js","names":[],"sources":["../src/components/progress/useProgress.ts","../src/components/progress/progress.vue","../src/components/progress/progress.vue","../src/components/progress/types.ts"],"sourcesContent":["import { computed, type CSSProperties } from 'vue';\nimport { useControlState } from '@/composables/useControlState';\nimport { bem } from '@/utils/bem';\nimport { getComponentCustomColor, isComponentPresetColor } from '@/utils/componentColors';\nimport type { ProgressProps } from './types';\n\ntype ProgressStateProps = Readonly<\n ProgressProps & {\n min: number;\n max: number;\n indeterminate: boolean;\n showValue: boolean;\n }\n>;\n\nexport function normalizeProgressBounds(min: number, max: number) {\n const safeMin = Number.isFinite(min) ? min : 0;\n const safeMax = Number.isFinite(max) ? max : 100;\n\n return safeMax >= safeMin ? { min: safeMin, max: safeMax } : { min: safeMax, max: safeMin };\n}\n\nexport function normalizeProgressValue(value: number | null | undefined, min: number, max: number) {\n const safeValue = Number.isFinite(value) ? Number(value) : min;\n\n return Math.min(max, Math.max(min, safeValue));\n}\n\nexport function getProgressValuePercent(value: number, min: number, max: number) {\n if (max <= min) return 0;\n\n const percent = ((value - min) / (max - min)) * 100;\n return Math.min(100, Math.max(0, percent));\n}\n\nfunction getFormattedProgressValue(\n value: number,\n percent: number,\n formatter: ProgressProps['formatValue'],\n) {\n return formatter ? formatter(value, percent) : `${Math.round(percent)}%`;\n}\n\nfunction getProgressAriaValueText(\n value: number,\n percent: number,\n ariaValueText: ProgressProps['ariaValueText'],\n formatter: ProgressProps['formatValue'],\n) {\n if (typeof ariaValueText === 'function') return String(ariaValueText(value, percent));\n if (ariaValueText != null && ariaValueText !== '') return String(ariaValueText);\n if (formatter) return String(formatter(value, percent));\n\n return undefined;\n}\n\nfunction setProgressStyleValue(\n style: CSSProperties,\n property: `--_rp-progress-${string}`,\n value: string | undefined,\n) {\n if (value) {\n style[property] = value;\n }\n}\n\nexport function useProgress(props: ProgressStateProps) {\n const control = useControlState(props);\n\n const bounds = computed(() => normalizeProgressBounds(props.min, props.max));\n const isIndeterminate = computed(() => props.indeterminate || props.value == null);\n const normalizedValue = computed(() =>\n normalizeProgressValue(props.value, bounds.value.min, bounds.value.max),\n );\n const valuePercent = computed(() =>\n getProgressValuePercent(normalizedValue.value, bounds.value.min, bounds.value.max),\n );\n const formattedValue = computed(() =>\n getFormattedProgressValue(normalizedValue.value, valuePercent.value, props.formatValue),\n );\n const ariaValueText = computed(() =>\n isIndeterminate.value\n ? undefined\n : getProgressAriaValueText(\n normalizedValue.value,\n valuePercent.value,\n props.ariaValueText,\n props.formatValue,\n ),\n );\n const rootClass = computed(() =>\n bem('rp-progress', {\n [`color-${props.color}`]: isComponentPresetColor(props.color),\n [`size-${props.size}`]: Boolean(props.size),\n [`radius-${props.radius}`]: Boolean(props.radius),\n indeterminate: isIndeterminate.value,\n }),\n );\n const rootStyle = computed<CSSProperties>(() => {\n const style: CSSProperties = {\n '--_rp-progress-value': `${valuePercent.value}%`,\n '--_rp-progress-ratio': `${valuePercent.value / 100}`,\n };\n\n setProgressStyleValue(\n style,\n '--_rp-progress-custom-color',\n getComponentCustomColor(props.color),\n );\n\n return style;\n });\n\n return {\n control,\n rootClass,\n rootStyle,\n isIndeterminate,\n normalizedValue,\n valuePercent,\n formattedValue,\n ariaValueText,\n ariaValueMin: computed(() => (isIndeterminate.value ? undefined : bounds.value.min)),\n ariaValueMax: computed(() => (isIndeterminate.value ? undefined : bounds.value.max)),\n ariaValueNow: computed(() => (isIndeterminate.value ? undefined : normalizedValue.value)),\n };\n}\n","<template>\n <div\n :id=\"control.id\"\n :class=\"rootClass\"\n :style=\"rootStyle\"\n role=\"progressbar\"\n :data-state=\"isIndeterminate ? 'indeterminate' : 'determinate'\"\n :aria-label=\"ariaLabel || undefined\"\n :aria-labelledby=\"control.ariaLabelledby\"\n :aria-describedby=\"control.ariaDescribedby\"\n :aria-valuemin=\"ariaValueMin\"\n :aria-valuemax=\"ariaValueMax\"\n :aria-valuenow=\"ariaValueNow\"\n :aria-valuetext=\"ariaValueText\"\n >\n <span\n v-if=\"$slots.default || (!isIndeterminate && ($slots.value || showValue))\"\n class=\"rp-progress__header\"\n >\n <span v-if=\"$slots.default\" class=\"rp-progress__label\">\n <slot />\n </span>\n <span\n v-if=\"!isIndeterminate && ($slots.value || showValue)\"\n class=\"rp-progress__value\"\n aria-hidden=\"true\"\n >\n <slot\n v-if=\"$slots.value\"\n name=\"value\"\n :value=\"normalizedValue\"\n :formatted-value=\"formattedValue\"\n :percent=\"valuePercent\"\n />\n <template v-else>{{ formattedValue }}</template>\n </span>\n </span>\n <span class=\"rp-progress__track\" aria-hidden=\"true\">\n <span class=\"rp-progress__indicator\" />\n </span>\n </div>\n</template>\n\n<script lang=\"ts\" setup vapor>\nimport type { ProgressProps } from './types';\nimport { useProgress } from './useProgress';\n\ndefineOptions({ name: 'RpProgress' });\n\nconst props = withDefaults(defineProps<ProgressProps>(), {\n min: 0,\n max: 100,\n indeterminate: false,\n showValue: false,\n});\n\nconst {\n control,\n rootClass,\n rootStyle,\n isIndeterminate,\n normalizedValue,\n valuePercent,\n formattedValue,\n ariaValueText,\n ariaValueMin,\n ariaValueMax,\n ariaValueNow,\n} = useProgress(props);\n</script>\n\n<style src=\"./progress.scss\" lang=\"scss\" scoped></style>\n","<template>\n <div\n :id=\"control.id\"\n :class=\"rootClass\"\n :style=\"rootStyle\"\n role=\"progressbar\"\n :data-state=\"isIndeterminate ? 'indeterminate' : 'determinate'\"\n :aria-label=\"ariaLabel || undefined\"\n :aria-labelledby=\"control.ariaLabelledby\"\n :aria-describedby=\"control.ariaDescribedby\"\n :aria-valuemin=\"ariaValueMin\"\n :aria-valuemax=\"ariaValueMax\"\n :aria-valuenow=\"ariaValueNow\"\n :aria-valuetext=\"ariaValueText\"\n >\n <span\n v-if=\"$slots.default || (!isIndeterminate && ($slots.value || showValue))\"\n class=\"rp-progress__header\"\n >\n <span v-if=\"$slots.default\" class=\"rp-progress__label\">\n <slot />\n </span>\n <span\n v-if=\"!isIndeterminate && ($slots.value || showValue)\"\n class=\"rp-progress__value\"\n aria-hidden=\"true\"\n >\n <slot\n v-if=\"$slots.value\"\n name=\"value\"\n :value=\"normalizedValue\"\n :formatted-value=\"formattedValue\"\n :percent=\"valuePercent\"\n />\n <template v-else>{{ formattedValue }}</template>\n </span>\n </span>\n <span class=\"rp-progress__track\" aria-hidden=\"true\">\n <span class=\"rp-progress__indicator\" />\n </span>\n </div>\n</template>\n\n<script lang=\"ts\" setup vapor>\nimport type { ProgressProps } from './types';\nimport { useProgress } from './useProgress';\n\ndefineOptions({ name: 'RpProgress' });\n\nconst props = withDefaults(defineProps<ProgressProps>(), {\n min: 0,\n max: 100,\n indeterminate: false,\n showValue: false,\n});\n\nconst {\n control,\n rootClass,\n rootStyle,\n isIndeterminate,\n normalizedValue,\n valuePercent,\n formattedValue,\n ariaValueText,\n ariaValueMin,\n ariaValueMax,\n ariaValueNow,\n} = useProgress(props);\n</script>\n\n<style src=\"./progress.scss\" lang=\"scss\" scoped></style>\n","import { componentColors, type ComponentColorValue } from '../../utils/componentColors';\n\nexport const progressColors = componentColors;\n\nexport const progressSizes = ['xs', 'sm', 'md', 'lg', 'xl'] as const;\n\nexport const progressRadiuses = ['none', 'xs', 'sm', 'md', 'lg', 'xl', 'full'] as const;\n\nexport type ProgressColor = ComponentColorValue;\n\nexport type ProgressSize = (typeof progressSizes)[number];\n\nexport type ProgressRadius = (typeof progressRadiuses)[number];\n\nexport type ProgressValueFormatter = (value: number, percent: number) => string | number;\n\nexport interface ProgressProps {\n id?: string;\n value?: number | null;\n min?: number;\n max?: number;\n color?: ProgressColor;\n size?: ProgressSize;\n radius?: ProgressRadius;\n indeterminate?: boolean;\n showValue?: boolean;\n formatValue?: ProgressValueFormatter;\n ariaLabel?: string;\n ariaValueText?: string | ProgressValueFormatter;\n describedby?: string;\n labelledby?: string;\n}\n"],"mappings":";;;;;;AAeA,SAAgB,wBAAwB,KAAa,KAAa;CAC9D,MAAM,UAAU,OAAO,SAAS,GAAG,IAAI,MAAM;CAC7C,MAAM,UAAU,OAAO,SAAS,GAAG,IAAI,MAAM;CAE7C,OAAO,WAAW,UAAU;EAAE,KAAK;EAAS,KAAK;CAAQ,IAAI;EAAE,KAAK;EAAS,KAAK;CAAQ;AAC9F;AAEA,SAAgB,uBAAuB,OAAkC,KAAa,KAAa;CAC/F,MAAM,YAAY,OAAO,SAAS,KAAK,IAAI,OAAO,KAAK,IAAI;CAE3D,OAAO,KAAK,IAAI,KAAK,KAAK,IAAI,KA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Y;MACX,aAAO,MAAA,eAAA;MACP,sBAAiB,MAAA,cAAA;MACjB,eAAS,MAAA,YAAA;;;;qDAEM,MAAA,cAAA,CAAc,CAAA,CAAA;;;;;;;;;;;;AEhClD,IAAa,iBAAiB;AAE9B,IAAa,gBAAgB;CAAC;CAAM;CAAM;CAAM;CAAM;AAAI;AAE1D,IAAa,mBAAmB;CAAC;CAAQ;CAAM;CAAM;CAAM;CAAM;CAAM;AAAM"}
|
package/dist/radio.js
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
import './radio.css';
|
|
2
|
+
import { t as useRequiredInject } from "./useRequiredInject.js";
|
|
3
|
+
import { t as bem } from "./bem.js";
|
|
4
|
+
import { t as _plugin_vue_export_helper_default } from "./_plugin-vue_export-helper.js";
|
|
2
5
|
import { n as getComponentCustomColor, r as isComponentPresetColor } from "./componentColors.js";
|
|
3
|
-
import { n as bem, t as _plugin_vue_export_helper_default } from "./_plugin-vue_export-helper.js";
|
|
4
6
|
import { t as useControlState } from "./useControlState.js";
|
|
5
|
-
import { child, computed, createIf, createSlot, defineVaporComponent,
|
|
6
|
-
//#region src/composables/useRequiredInject.ts
|
|
7
|
-
function useRequiredInject(key, componentName) {
|
|
8
|
-
const value = inject(key);
|
|
9
|
-
if (value == null) throw new Error(`[Ropav] <${componentName}> must be used inside its parent provider component.`);
|
|
10
|
-
return value;
|
|
11
|
-
}
|
|
12
|
-
//#endregion
|
|
7
|
+
import { child, computed, createIf, createSlot, defineVaporComponent, on, provide, renderEffect, setAttr, setClass, setInsertionState, setProp, setStyle, setValue, template, unref, useId } from "vue";
|
|
13
8
|
//#region src/components/radio/types.ts
|
|
14
9
|
var radioGroupKey = Symbol("radioGroup");
|
|
15
10
|
//#endregion
|