@prosekit/web 0.5.7 → 0.5.9

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.
@@ -1,270 +1,242 @@
1
- // src/components/resizable/resizable-handle/element.gen.ts
2
- import { defineCustomElement, registerCustomElement } from "@aria-ui/core";
1
+ import { createContext, createSignal, defineCustomElement, registerCustomElement, useAttribute, useEffect } from "@aria-ui/core";
2
+ import { getWindow } from "@ocavue/utils";
3
3
 
4
- // src/components/resizable/resizable-handle/setup.ts
5
- import {
6
- createSignal,
7
- useEffect
8
- } from "@aria-ui/core";
9
- import { getWindow } from "@zag-js/dom-query";
4
+ //#region src/components/resizable/context.ts
5
+ /**
6
+ * @internal
7
+ */
8
+ const onResizeContext = createContext("prosekit/resizable/onResize", null);
9
+ /**
10
+ * @internal
11
+ */
12
+ const onResizeStartContext = createContext("prosekit/resizable/onResizeStart", null);
13
+ /**
14
+ * @internal
15
+ */
16
+ const onResizeEndContext = createContext("prosekit/resizable/onResizeEnd", null);
10
17
 
11
- // src/components/resizable/context.ts
12
- import { createContext } from "@aria-ui/core";
13
- var onResizeContext = createContext(
14
- "prosekit/resizable/onResize",
15
- null
16
- );
17
- var onResizeStartContext = createContext(
18
- "prosekit/resizable/onResizeStart",
19
- null
20
- );
21
- var onResizeEndContext = createContext(
22
- "prosekit/resizable/onResizeEnd",
23
- null
24
- );
25
-
26
- // src/utils/is-finite-positive-number.ts
18
+ //#endregion
19
+ //#region src/utils/is-finite-positive-number.ts
27
20
  function isFinitePositiveNumber(value) {
28
- return typeof value === "number" && Number.isFinite(value) && value > 0;
21
+ return typeof value === "number" && Number.isFinite(value) && value > 0;
29
22
  }
30
23
 
31
- // src/components/resizable/resizable-handle/calc-resize.ts
24
+ //#endregion
25
+ //#region src/components/resizable/resizable-handle/calc-resize.ts
32
26
  function calcResize(position, w, h, dx, dy, aspectRatio) {
33
- aspectRatio = aspectRatio ? aspectRatio : w / h;
34
- aspectRatio = isFinitePositiveNumber(aspectRatio) ? aspectRatio : 1;
35
- switch (position) {
36
- case "bottom-right":
37
- return calcBottomRightResize(w, h, dx, dy, aspectRatio);
38
- case "bottom-left":
39
- return calcBottomLeftResize(w, h, dx, dy, aspectRatio);
40
- case "top-right":
41
- return calcTopRightResize(w, h, dx, dy, aspectRatio);
42
- case "top-left":
43
- return calcTopLeftResize(w, h, dx, dy, aspectRatio);
44
- case "top":
45
- return calcTopResize(w, h, dx, dy, aspectRatio);
46
- case "right":
47
- return calcRightResize(w, h, dx, dy, aspectRatio);
48
- case "bottom":
49
- return calcBottomResize(w, h, dx, dy, aspectRatio);
50
- case "left":
51
- return calcLeftResize(w, h, dx, dy, aspectRatio);
52
- default:
53
- throw new RangeError(`Invalid position: ${position}`);
54
- }
27
+ aspectRatio = aspectRatio ? aspectRatio : w / h;
28
+ aspectRatio = isFinitePositiveNumber(aspectRatio) ? aspectRatio : 1;
29
+ switch (position) {
30
+ case "bottom-right": return calcBottomRightResize(w, h, dx, dy, aspectRatio);
31
+ case "bottom-left": return calcBottomLeftResize(w, h, dx, dy, aspectRatio);
32
+ case "top-right": return calcTopRightResize(w, h, dx, dy, aspectRatio);
33
+ case "top-left": return calcTopLeftResize(w, h, dx, dy, aspectRatio);
34
+ case "top": return calcTopResize(w, h, dx, dy, aspectRatio);
35
+ case "right": return calcRightResize(w, h, dx, dy, aspectRatio);
36
+ case "bottom": return calcBottomResize(w, h, dx, dy, aspectRatio);
37
+ case "left": return calcLeftResize(w, h, dx, dy, aspectRatio);
38
+ default: throw new RangeError(`Invalid position: ${position}`);
39
+ }
55
40
  }
56
- var calcBottomRightResize = (w, h, dx, dy, r) => {
57
- w += dx;
58
- h += dy;
59
- const sum = w + h;
60
- h = sum / (r + 1);
61
- w = sum - h;
62
- return [w, h];
41
+ const calcBottomRightResize = (w, h, dx, dy, r) => {
42
+ w += dx;
43
+ h += dy;
44
+ const sum = w + h;
45
+ h = sum / (r + 1);
46
+ w = sum - h;
47
+ return [w, h];
63
48
  };
64
- var calcBottomLeftResize = (w, h, dx, dy, r) => {
65
- w -= dx;
66
- h += dy;
67
- const sum = w + h;
68
- h = sum / (r + 1);
69
- w = sum - h;
70
- return [w, h];
49
+ const calcBottomLeftResize = (w, h, dx, dy, r) => {
50
+ w -= dx;
51
+ h += dy;
52
+ const sum = w + h;
53
+ h = sum / (r + 1);
54
+ w = sum - h;
55
+ return [w, h];
71
56
  };
72
- var calcTopRightResize = (w, h, dx, dy, r) => {
73
- w += dx;
74
- h -= dy;
75
- const sum = w + h;
76
- h = sum / (r + 1);
77
- w = sum - h;
78
- return [w, h];
57
+ const calcTopRightResize = (w, h, dx, dy, r) => {
58
+ w += dx;
59
+ h -= dy;
60
+ const sum = w + h;
61
+ h = sum / (r + 1);
62
+ w = sum - h;
63
+ return [w, h];
79
64
  };
80
- var calcTopLeftResize = (w, h, dx, dy, r) => {
81
- w -= dx;
82
- h -= dy;
83
- const sum = w + h;
84
- h = sum / (r + 1);
85
- w = sum - h;
86
- return [w, h];
65
+ const calcTopLeftResize = (w, h, dx, dy, r) => {
66
+ w -= dx;
67
+ h -= dy;
68
+ const sum = w + h;
69
+ h = sum / (r + 1);
70
+ w = sum - h;
71
+ return [w, h];
87
72
  };
88
- var calcTopResize = (w, h, dx, dy, r) => {
89
- h -= dy;
90
- w = h * r;
91
- return [w, h];
73
+ const calcTopResize = (w, h, dx, dy, r) => {
74
+ h -= dy;
75
+ w = h * r;
76
+ return [w, h];
92
77
  };
93
- var calcRightResize = (w, h, dx, dy, r) => {
94
- w += dx;
95
- h = w / r;
96
- return [w, h];
78
+ const calcRightResize = (w, h, dx, dy, r) => {
79
+ w += dx;
80
+ h = w / r;
81
+ return [w, h];
97
82
  };
98
- var calcBottomResize = (w, h, dx, dy, r) => {
99
- h += dy;
100
- w = h * r;
101
- return [w, h];
83
+ const calcBottomResize = (w, h, dx, dy, r) => {
84
+ h += dy;
85
+ w = h * r;
86
+ return [w, h];
102
87
  };
103
- var calcLeftResize = (w, h, dx, dy, r) => {
104
- w -= dx;
105
- h = w / r;
106
- return [w, h];
88
+ const calcLeftResize = (w, h, dx, dy, r) => {
89
+ w -= dx;
90
+ h = w / r;
91
+ return [w, h];
107
92
  };
108
93
 
109
- // src/components/resizable/resizable-handle/setup.ts
94
+ //#endregion
95
+ //#region src/components/resizable/resizable-handle/setup.ts
110
96
  function useResizableHandle(host, { state }) {
111
- const onResize = onResizeContext.consume(host);
112
- const onResizeStart = onResizeStartContext.consume(host);
113
- const onResizeEnd = onResizeEndContext.consume(host);
114
- useResizableHandleState(host, state, { onResize, onResizeStart, onResizeEnd });
97
+ const onResize = onResizeContext.consume(host);
98
+ const onResizeStart = onResizeStartContext.consume(host);
99
+ const onResizeEnd = onResizeEndContext.consume(host);
100
+ useResizableHandleState(host, state, {
101
+ onResize,
102
+ onResizeStart,
103
+ onResizeEnd
104
+ });
115
105
  }
116
106
  function useResizableHandleState(host, state, context) {
117
- let startX = 0;
118
- let startY = 0;
119
- let width = 0;
120
- let height = 0;
121
- let aspectRatio = 1;
122
- const pointerPressing = createSignal(false);
123
- const handlePointerDown = (event) => {
124
- event.preventDefault();
125
- pointerPressing.set(true);
126
- startX = event.x;
127
- startY = event.y;
128
- const size = context.onResizeStart.get()?.();
129
- if (size) {
130
- ;
131
- [width, height, aspectRatio] = size;
132
- }
133
- };
134
- const handlePointerMove = (event) => {
135
- event.preventDefault();
136
- const dx = event.x - startX;
137
- const dy = event.y - startY;
138
- const [w, h] = calcResize(
139
- state.position.peek(),
140
- width,
141
- height,
142
- dx,
143
- dy,
144
- aspectRatio
145
- );
146
- context.onResize.get()?.(w, h);
147
- };
148
- const handlePointerUp = (event) => {
149
- event.preventDefault();
150
- pointerPressing.set(false);
151
- context.onResizeEnd.get()?.();
152
- };
153
- useEffect(host, () => {
154
- host.addEventListener("pointerdown", handlePointerDown);
155
- return () => {
156
- host.removeEventListener("pointerdown", handlePointerDown);
157
- };
158
- });
159
- useEffect(host, () => {
160
- if (!pointerPressing.get()) {
161
- return;
162
- }
163
- const win = getWindow(host);
164
- win.addEventListener("pointermove", handlePointerMove);
165
- win.addEventListener("pointerup", handlePointerUp);
166
- return () => {
167
- win.removeEventListener("pointermove", handlePointerMove);
168
- win.removeEventListener("pointerup", handlePointerUp);
169
- };
170
- });
107
+ let startX = 0;
108
+ let startY = 0;
109
+ let width = 0;
110
+ let height = 0;
111
+ let aspectRatio = 1;
112
+ const pointerPressing = createSignal(false);
113
+ const handlePointerDown = (event) => {
114
+ event.preventDefault();
115
+ pointerPressing.set(true);
116
+ startX = event.x;
117
+ startY = event.y;
118
+ const size = context.onResizeStart.get()?.();
119
+ if (size) [width, height, aspectRatio] = size;
120
+ };
121
+ const handlePointerMove = (event) => {
122
+ event.preventDefault();
123
+ const dx = event.x - startX;
124
+ const dy = event.y - startY;
125
+ const [w, h] = calcResize(state.position.peek(), width, height, dx, dy, aspectRatio);
126
+ context.onResize.get()?.(w, h);
127
+ };
128
+ const handlePointerUp = (event) => {
129
+ event.preventDefault();
130
+ pointerPressing.set(false);
131
+ context.onResizeEnd.get()?.();
132
+ };
133
+ useEffect(host, () => {
134
+ host.addEventListener("pointerdown", handlePointerDown);
135
+ return () => {
136
+ host.removeEventListener("pointerdown", handlePointerDown);
137
+ };
138
+ });
139
+ useEffect(host, () => {
140
+ if (!pointerPressing.get()) return;
141
+ const win = getWindow(host);
142
+ win.addEventListener("pointermove", handlePointerMove);
143
+ win.addEventListener("pointerup", handlePointerUp);
144
+ return () => {
145
+ win.removeEventListener("pointermove", handlePointerMove);
146
+ win.removeEventListener("pointerup", handlePointerUp);
147
+ };
148
+ });
171
149
  }
172
150
 
173
- // src/components/resizable/resizable-handle/types.ts
174
- var resizableHandleProps = {
175
- position: { default: "bottom-right" }
176
- };
177
- var resizableHandleEvents = {};
151
+ //#endregion
152
+ //#region src/components/resizable/resizable-handle/types.ts
153
+ /** @internal */
154
+ const resizableHandleProps = { position: { default: "bottom-right" } };
155
+ /** @internal */
156
+ const resizableHandleEvents = {};
178
157
 
179
- // src/components/resizable/resizable-handle/element.gen.ts
180
- var ResizableHandleElement = class extends defineCustomElement({
181
- props: resizableHandleProps,
182
- events: resizableHandleEvents,
183
- setup: useResizableHandle
184
- }) {
185
- };
158
+ //#endregion
159
+ //#region src/components/resizable/resizable-handle/element.gen.ts
160
+ const ResizableHandleElementBase = defineCustomElement({
161
+ props: resizableHandleProps,
162
+ events: resizableHandleEvents,
163
+ setup: useResizableHandle
164
+ });
165
+ var ResizableHandleElement = class extends ResizableHandleElementBase {};
186
166
  registerCustomElement("prosekit-resizable-handle", ResizableHandleElement);
187
167
 
188
- // src/components/resizable/resizable-root/element.gen.ts
189
- import { defineCustomElement as defineCustomElement2, registerCustomElement as registerCustomElement2 } from "@aria-ui/core";
190
-
191
- // src/components/resizable/resizable-root/setup.ts
192
- import {
193
- createSignal as createSignal2,
194
- useAttribute,
195
- useEffect as useEffect2
196
- } from "@aria-ui/core";
168
+ //#endregion
169
+ //#region src/components/resizable/resizable-root/setup.ts
197
170
  function useResizableRoot(host, { state, emit }) {
198
- const resizing = createSignal2(false);
199
- const onResizeStart = () => {
200
- const { width, height } = host.getBoundingClientRect();
201
- let aspectRatio = state.aspectRatio.peek() ?? width / height;
202
- if (!isFinitePositiveNumber(aspectRatio)) {
203
- aspectRatio = 0;
204
- }
205
- emit("resizeStart", { width, height });
206
- resizing.set(true);
207
- return [width, height, aspectRatio];
208
- };
209
- const onResize = (width, height) => {
210
- state.width.set(width);
211
- state.height.set(height);
212
- };
213
- const onResizeEnd = () => {
214
- const { width, height } = host.getBoundingClientRect();
215
- emit("resizeEnd", { width, height });
216
- resizing.set(false);
217
- };
218
- onResizeStartContext.provide(host, createSignal2(onResizeStart));
219
- onResizeContext.provide(host, createSignal2(onResize));
220
- onResizeEndContext.provide(host, createSignal2(onResizeEnd));
221
- useEffect2(host, () => {
222
- updateResizableRootStyles(
223
- host,
224
- Math.max(state.width.get() || 0, 1),
225
- Math.max(state.height.get() || 0, 1),
226
- state.aspectRatio.get()
227
- );
228
- });
229
- useAttribute(host, "data-resizing", () => resizing.get() ? "" : void 0);
171
+ const resizing = createSignal(false);
172
+ const onResizeStart = () => {
173
+ const { width, height } = host.getBoundingClientRect();
174
+ let aspectRatio = state.aspectRatio.peek() ?? width / height;
175
+ if (!isFinitePositiveNumber(aspectRatio)) aspectRatio = 0;
176
+ emit("resizeStart", {
177
+ width,
178
+ height
179
+ });
180
+ resizing.set(true);
181
+ return [
182
+ width,
183
+ height,
184
+ aspectRatio
185
+ ];
186
+ };
187
+ const onResize = (width, height) => {
188
+ state.width.set(width);
189
+ state.height.set(height);
190
+ };
191
+ const onResizeEnd = () => {
192
+ const { width, height } = host.getBoundingClientRect();
193
+ emit("resizeEnd", {
194
+ width,
195
+ height
196
+ });
197
+ resizing.set(false);
198
+ };
199
+ onResizeStartContext.provide(host, createSignal(onResizeStart));
200
+ onResizeContext.provide(host, createSignal(onResize));
201
+ onResizeEndContext.provide(host, createSignal(onResizeEnd));
202
+ useEffect(host, () => {
203
+ updateResizableRootStyles(host, Math.max(state.width.get() || 0, 1), Math.max(state.height.get() || 0, 1), state.aspectRatio.get());
204
+ });
205
+ useAttribute(host, "data-resizing", () => resizing.get() ? "" : void 0);
230
206
  }
231
207
  function updateResizableRootStyles(host, width, height, aspectRatio) {
232
- host.style.width = isFinitePositiveNumber(width) ? `${width}px` : "";
233
- host.style.height = isFinitePositiveNumber(height) ? `${height}px` : "";
234
- if (isFinitePositiveNumber(aspectRatio)) {
235
- host.style.aspectRatio = `${aspectRatio}`;
236
- if (width && width > 0 && aspectRatio >= 1) {
237
- host.style.height = "auto";
238
- } else if (height && height > 0 && aspectRatio <= 1) {
239
- host.style.width = "min-content";
240
- }
241
- }
208
+ host.style.width = isFinitePositiveNumber(width) ? `${width}px` : "";
209
+ host.style.height = isFinitePositiveNumber(height) ? `${height}px` : "";
210
+ if (isFinitePositiveNumber(aspectRatio)) {
211
+ host.style.aspectRatio = `${aspectRatio}`;
212
+ if (width && width > 0 && aspectRatio >= 1) host.style.height = "auto";
213
+ else if (height && height > 0 && aspectRatio <= 1) host.style.width = "min-content";
214
+ }
242
215
  }
243
216
 
244
- // src/components/resizable/resizable-root/types.ts
245
- var resizableRootProps = {
246
- width: { default: null },
247
- height: { default: null },
248
- aspectRatio: { default: null }
217
+ //#endregion
218
+ //#region src/components/resizable/resizable-root/types.ts
219
+ /** @internal */
220
+ const resizableRootProps = {
221
+ width: { default: null },
222
+ height: { default: null },
223
+ aspectRatio: { default: null }
249
224
  };
250
- var resizableRootEvents = {
251
- resizeStart: {},
252
- resizeEnd: {}
225
+ /** @internal */
226
+ const resizableRootEvents = {
227
+ resizeStart: {},
228
+ resizeEnd: {}
253
229
  };
254
230
 
255
- // src/components/resizable/resizable-root/element.gen.ts
256
- var ResizableRootElement = class extends defineCustomElement2({
257
- props: resizableRootProps,
258
- events: resizableRootEvents,
259
- setup: useResizableRoot
260
- }) {
261
- };
262
- registerCustomElement2("prosekit-resizable-root", ResizableRootElement);
263
- export {
264
- ResizableHandleElement,
265
- ResizableRootElement,
266
- resizableHandleEvents,
267
- resizableHandleProps,
268
- resizableRootEvents,
269
- resizableRootProps
270
- };
231
+ //#endregion
232
+ //#region src/components/resizable/resizable-root/element.gen.ts
233
+ const ResizableRootElementBase = defineCustomElement({
234
+ props: resizableRootProps,
235
+ events: resizableRootEvents,
236
+ setup: useResizableRoot
237
+ });
238
+ var ResizableRootElement = class extends ResizableRootElementBase {};
239
+ registerCustomElement("prosekit-resizable-root", ResizableRootElement);
240
+
241
+ //#endregion
242
+ export { ResizableHandleElement, ResizableRootElement, resizableHandleEvents, resizableHandleProps, resizableRootEvents, resizableRootProps };