@x33025/sveltely 0.0.52 → 0.0.53
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/components/Popover/Popover.svelte +53 -2
- package/dist/style/index.css +1 -13
- package/dist/style.css +1 -17
- package/package.json +1 -1
|
@@ -39,9 +39,11 @@
|
|
|
39
39
|
|
|
40
40
|
let triggerEl = $state<HTMLElement | null>(null);
|
|
41
41
|
let panelEl = $state<HTMLElement | null>(null);
|
|
42
|
+
let contentEl = $state<HTMLElement | null>(null);
|
|
42
43
|
let panelCoords = $state({ top: 0, left: 0 });
|
|
43
44
|
let panelTransform = $state('none');
|
|
44
45
|
let resolvedAnchor = $state<Anchor>('bottom');
|
|
46
|
+
let computedPanelRadius = $state<string | null>(null);
|
|
45
47
|
|
|
46
48
|
const popoverId = createPopoverId();
|
|
47
49
|
let parentPopoverId = $state<string | null>(null);
|
|
@@ -131,10 +133,50 @@
|
|
|
131
133
|
];
|
|
132
134
|
};
|
|
133
135
|
|
|
136
|
+
const parsePx = (value: string) => {
|
|
137
|
+
const first = value.split(' ')[0];
|
|
138
|
+
const parsed = Number.parseFloat(first);
|
|
139
|
+
return Number.isFinite(parsed) ? parsed : 0;
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
const updateComputedPanelRadius = () => {
|
|
143
|
+
if (!panelEl || !contentEl) {
|
|
144
|
+
computedPanelRadius = null;
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const itemEl =
|
|
149
|
+
contentEl.querySelector<HTMLElement>('[data-popover-radius-item]') ||
|
|
150
|
+
contentEl.querySelector<HTMLElement>('.popover-item') ||
|
|
151
|
+
contentEl.querySelector<HTMLElement>('.dropdown-item');
|
|
152
|
+
if (!itemEl) {
|
|
153
|
+
computedPanelRadius = null;
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const itemRect = itemEl.getBoundingClientRect();
|
|
158
|
+
const itemStyle = getComputedStyle(itemEl);
|
|
159
|
+
const itemRadius = parsePx(itemStyle.borderTopLeftRadius);
|
|
160
|
+
const effectiveItemRadius = Math.min(itemRadius, itemRect.height / 2, itemRect.width / 2);
|
|
161
|
+
|
|
162
|
+
const panelStyle = getComputedStyle(panelEl);
|
|
163
|
+
const panelPadding = Math.min(parsePx(panelStyle.paddingTop), parsePx(panelStyle.paddingLeft));
|
|
164
|
+
|
|
165
|
+
const panelRect = panelEl.getBoundingClientRect();
|
|
166
|
+
const outerRadius = Math.min(
|
|
167
|
+
effectiveItemRadius + panelPadding,
|
|
168
|
+
panelRect.height / 2,
|
|
169
|
+
panelRect.width / 2
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
computedPanelRadius = `${outerRadius}px`;
|
|
173
|
+
};
|
|
174
|
+
|
|
134
175
|
const positionAndMeasure = async () => {
|
|
135
176
|
await tick();
|
|
136
177
|
await new Promise<void>((resolve) => requestAnimationFrame(() => resolve()));
|
|
137
178
|
positionPanel();
|
|
179
|
+
updateComputedPanelRadius();
|
|
138
180
|
};
|
|
139
181
|
|
|
140
182
|
const getPopoverIdsFromEvent = (event: Event) => {
|
|
@@ -171,6 +213,7 @@
|
|
|
171
213
|
|
|
172
214
|
function closePanel() {
|
|
173
215
|
open = false;
|
|
216
|
+
computedPanelRadius = null;
|
|
174
217
|
}
|
|
175
218
|
|
|
176
219
|
function toggle() {
|
|
@@ -213,6 +256,11 @@
|
|
|
213
256
|
if (!open) return;
|
|
214
257
|
void positionAndMeasure();
|
|
215
258
|
});
|
|
259
|
+
|
|
260
|
+
$effect(() => {
|
|
261
|
+
if (!open) return;
|
|
262
|
+
updateComputedPanelRadius();
|
|
263
|
+
});
|
|
216
264
|
</script>
|
|
217
265
|
|
|
218
266
|
<svelte:window
|
|
@@ -248,13 +296,16 @@
|
|
|
248
296
|
data-popover
|
|
249
297
|
data-popover-id={popoverId}
|
|
250
298
|
data-popover-parent-id={parentPopoverId ?? ''}
|
|
251
|
-
style="top: {panelCoords.top}px; left: {panelCoords.left}px; transform: {panelTransform};
|
|
299
|
+
style="top: {panelCoords.top}px; left: {panelCoords.left}px; transform: {panelTransform}; border-radius: {computedPanelRadius ??
|
|
300
|
+
'0.375rem'};"
|
|
252
301
|
role="dialog"
|
|
253
302
|
aria-modal="false"
|
|
254
303
|
tabindex="-1"
|
|
255
304
|
bind:this={panelEl}
|
|
256
305
|
>
|
|
257
|
-
{
|
|
306
|
+
<div role="none" bind:this={contentEl}>
|
|
307
|
+
{@render children()}
|
|
308
|
+
</div>
|
|
258
309
|
</div>
|
|
259
310
|
{/if}
|
|
260
311
|
</div>
|
package/dist/style/index.css
CHANGED
|
@@ -94,20 +94,8 @@
|
|
|
94
94
|
@apply rounded p-1.5 hover:bg-zinc-100;
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
.dropdown {
|
|
98
|
-
@apply rounded-md border border-gray-200 bg-white p-1 shadow-md;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
.dropdown-item {
|
|
102
|
-
@apply rounded-md;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
.dropdown-item:hover {
|
|
106
|
-
@apply bg-zinc-100;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
97
|
.popover {
|
|
110
|
-
@apply rounded-md border border-gray-200 bg-white p-
|
|
98
|
+
@apply rounded-md border border-gray-200 bg-white p-1 shadow-md;
|
|
111
99
|
}
|
|
112
100
|
|
|
113
101
|
.sheet {
|
package/dist/style.css
CHANGED
|
@@ -685,29 +685,13 @@
|
|
|
685
685
|
}
|
|
686
686
|
}
|
|
687
687
|
}
|
|
688
|
-
.dropdown {
|
|
689
|
-
border-radius: var(--radius-md);
|
|
690
|
-
border-style: var(--tw-border-style);
|
|
691
|
-
border-width: 1px;
|
|
692
|
-
border-color: var(--color-gray-200);
|
|
693
|
-
background-color: var(--color-white);
|
|
694
|
-
padding: calc(var(--spacing) * 1);
|
|
695
|
-
--tw-shadow: 0 4px 6px -1px var(--tw-shadow-color, rgb(0 0 0 / 0.1)), 0 2px 4px -2px var(--tw-shadow-color, rgb(0 0 0 / 0.1));
|
|
696
|
-
box-shadow: var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow);
|
|
697
|
-
}
|
|
698
|
-
.dropdown-item {
|
|
699
|
-
border-radius: var(--radius-md);
|
|
700
|
-
}
|
|
701
|
-
.dropdown-item:hover {
|
|
702
|
-
background-color: var(--color-zinc-100);
|
|
703
|
-
}
|
|
704
688
|
.popover {
|
|
705
689
|
border-radius: var(--radius-md);
|
|
706
690
|
border-style: var(--tw-border-style);
|
|
707
691
|
border-width: 1px;
|
|
708
692
|
border-color: var(--color-gray-200);
|
|
709
693
|
background-color: var(--color-white);
|
|
710
|
-
padding: calc(var(--spacing) *
|
|
694
|
+
padding: calc(var(--spacing) * 1);
|
|
711
695
|
--tw-shadow: 0 4px 6px -1px var(--tw-shadow-color, rgb(0 0 0 / 0.1)), 0 2px 4px -2px var(--tw-shadow-color, rgb(0 0 0 / 0.1));
|
|
712
696
|
box-shadow: var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow);
|
|
713
697
|
}
|