svelte-p5-components 0.2.1 → 0.3.0
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.
|
@@ -56,14 +56,14 @@
|
|
|
56
56
|
return typeof v === 'number' ? `${v}px` : v;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
// Focus management
|
|
59
|
+
// Focus management - each window gets a reactive z-index slot shared
|
|
60
60
|
// across every DraggableWindow on the page. Clicking brings it to top.
|
|
61
61
|
const win = registerWindow();
|
|
62
62
|
|
|
63
63
|
// Live position. Neodrag's `position` plugin drives the element via
|
|
64
64
|
// transform; we update this state from onDrag AND on resize/clamp,
|
|
65
65
|
// and the Compartment re-evaluates to push changes back into neodrag.
|
|
66
|
-
// `untrack` prevents these props from forming a reactive dep
|
|
66
|
+
// `untrack` prevents these props from forming a reactive dep - they're
|
|
67
67
|
// *initial* values only; later position comes from user drag.
|
|
68
68
|
let pos = $state(untrack(() => ({ x: initialX, y: initialY })));
|
|
69
69
|
|
|
@@ -74,9 +74,13 @@
|
|
|
74
74
|
|
|
75
75
|
function clampToViewport() {
|
|
76
76
|
if (typeof window === 'undefined') return;
|
|
77
|
+
// When constrained to a parent, neodrag's `bounds(BoundsFrom.parent())`
|
|
78
|
+
// already keeps the window inside; viewport math here would be wrong
|
|
79
|
+
// because positions are relative to the parent, not the viewport.
|
|
80
|
+
if (constrained === 'parent') return;
|
|
77
81
|
const vw = window.innerWidth;
|
|
78
82
|
const vh = window.innerHeight;
|
|
79
|
-
// Never allow the titlebar above the viewport top
|
|
83
|
+
// Never allow the titlebar above the viewport top - that's the
|
|
80
84
|
// "unreachable" case. Allow partial horizontal overflow so narrow
|
|
81
85
|
// screens don't trap wide windows, but always keep `minVisible`
|
|
82
86
|
// pixels of the window on-screen for a grab handle.
|
|
@@ -90,7 +94,7 @@
|
|
|
90
94
|
};
|
|
91
95
|
}
|
|
92
96
|
|
|
93
|
-
// Keep size fresh (used for clamp math)
|
|
97
|
+
// Keep size fresh (used for clamp math) - ResizeObserver on our own
|
|
94
98
|
// root element catches CSS resize-from-corner too.
|
|
95
99
|
$effect(() => {
|
|
96
100
|
if (!rootEl) return;
|
|
@@ -106,7 +110,7 @@
|
|
|
106
110
|
return () => ro.disconnect();
|
|
107
111
|
});
|
|
108
112
|
|
|
109
|
-
// Re-clamp on window resize
|
|
113
|
+
// Re-clamp on window resize - this is the "snap back in when the
|
|
110
114
|
// viewport shrinks" case.
|
|
111
115
|
$effect(() => {
|
|
112
116
|
if (typeof window === 'undefined') return;
|
|
@@ -139,6 +143,8 @@
|
|
|
139
143
|
<div
|
|
140
144
|
bind:this={rootEl}
|
|
141
145
|
class="draggable-window"
|
|
146
|
+
class:dw-fixed={constrained !== 'parent'}
|
|
147
|
+
class:dw-absolute={constrained === 'parent'}
|
|
142
148
|
style:width={toCssSize(width)}
|
|
143
149
|
style:height={toCssSize(height)}
|
|
144
150
|
style:min-width={toCssSize(minWidth)}
|
|
@@ -162,7 +168,6 @@
|
|
|
162
168
|
|
|
163
169
|
<style>
|
|
164
170
|
.draggable-window {
|
|
165
|
-
position: fixed;
|
|
166
171
|
top: 0;
|
|
167
172
|
left: 0;
|
|
168
173
|
display: flex;
|
|
@@ -177,6 +182,16 @@
|
|
|
177
182
|
/* Native resize from the bottom-right corner. */
|
|
178
183
|
resize: both;
|
|
179
184
|
}
|
|
185
|
+
/* Default: float above the viewport (suits constrained="viewport" or "none"). */
|
|
186
|
+
.dw-fixed {
|
|
187
|
+
position: fixed;
|
|
188
|
+
}
|
|
189
|
+
/* When constrained to a parent, position absolute inside that parent so
|
|
190
|
+
the visual position matches the drag bounds. The parent must be a
|
|
191
|
+
positioning context (`position: relative` or similar). */
|
|
192
|
+
.dw-absolute {
|
|
193
|
+
position: absolute;
|
|
194
|
+
}
|
|
180
195
|
.dw-titlebar {
|
|
181
196
|
display: flex;
|
|
182
197
|
align-items: center;
|
|
@@ -18,7 +18,7 @@ export function registerWindow() {
|
|
|
18
18
|
return myZ;
|
|
19
19
|
},
|
|
20
20
|
focus() {
|
|
21
|
-
// Only reassign if we're not already the top window
|
|
21
|
+
// Only reassign if we're not already the top window - avoids a
|
|
22
22
|
// no-op reactive write when the already-focused window gets clicked.
|
|
23
23
|
if (myZ !== counter)
|
|
24
24
|
myZ = ++counter;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svelte-p5-components",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Higher-level Svelte 5 components built on svelte-p5: responsive canvas, FPS monitor, sketch debug overlay, draggable windows",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"svelte",
|
|
@@ -39,6 +39,9 @@
|
|
|
39
39
|
"README.md",
|
|
40
40
|
"LICENSE"
|
|
41
41
|
],
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public"
|
|
44
|
+
},
|
|
42
45
|
"sideEffects": false,
|
|
43
46
|
"scripts": {
|
|
44
47
|
"build": "svelte-package -o dist && publint",
|