@cratis/scene 0.158.1 → 0.159.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.
- package/dist/Prototypes/Editor/fitOverlay.d.ts +14 -0
- package/dist/ScreenEditor/index.js +131 -112
- package/package.json +1 -1
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface OverlayViewport {
|
|
2
|
+
width: number;
|
|
3
|
+
height: number;
|
|
4
|
+
}
|
|
5
|
+
export interface FittedOverlay {
|
|
6
|
+
width: number;
|
|
7
|
+
height: number;
|
|
8
|
+
offsetX: number;
|
|
9
|
+
}
|
|
10
|
+
export declare const overlayMargin = 8;
|
|
11
|
+
export declare function fitOverlay(size: {
|
|
12
|
+
width: number;
|
|
13
|
+
height: number;
|
|
14
|
+
}, viewport: OverlayViewport, requestedOffsetX: number): FittedOverlay;
|
|
@@ -1,14 +1,22 @@
|
|
|
1
|
-
import { c as
|
|
2
|
-
import { i as
|
|
3
|
-
import { useCallback as f, useEffect as
|
|
4
|
-
import { jsx as
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { c as J, u as K, x as Q } from "../Scene-DaQtzf1e.js";
|
|
2
|
+
import { i as Z, r as tt, t as et } from "../renderPrototypeElement-Xm7OIVPs.js";
|
|
3
|
+
import { useCallback as f, useEffect as X, useRef as E, useState as v } from "react";
|
|
4
|
+
import { jsx as w, jsxs as z } from "react/jsx-runtime";
|
|
5
|
+
function ot(t, r, n) {
|
|
6
|
+
const i = Math.max(1, Math.min(t.width, r.width - 16)), h = Math.max(1, Math.min(t.height, r.height - 16)), a = Math.max(0, (r.width - i) / 2 - 8);
|
|
7
|
+
return {
|
|
8
|
+
width: i,
|
|
9
|
+
height: h,
|
|
10
|
+
offsetX: Math.min(a, Math.max(-a, n))
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
var L = 900, $ = 640, rt = 320, nt = 300, yt = 360, it = (t) => t ? {
|
|
14
|
+
width: t.width > 0 ? t.width : L,
|
|
15
|
+
height: t.height > 0 ? t.height : $
|
|
8
16
|
} : {
|
|
9
|
-
width:
|
|
10
|
-
height:
|
|
11
|
-
},
|
|
17
|
+
width: L,
|
|
18
|
+
height: $
|
|
19
|
+
}, at = [
|
|
12
20
|
"n",
|
|
13
21
|
"s",
|
|
14
22
|
"e",
|
|
@@ -17,153 +25,164 @@ var $ = 900, k = 640, Z = 320, tt = 300, dt = 360, et = (t) => t ? {
|
|
|
17
25
|
"nw",
|
|
18
26
|
"se",
|
|
19
27
|
"sw"
|
|
20
|
-
],
|
|
21
|
-
const [
|
|
22
|
-
|
|
23
|
-
const [
|
|
24
|
-
|
|
25
|
-
|
|
28
|
+
], gt = ({ sourceRect: t, initialSize: r, centerOffsetX: n = 0, children: i, renderInspector: h, canClose: a, onClosed: l }) => {
|
|
29
|
+
const [s, y] = v("entering"), [p, H] = v(() => it(r)), C = E(p);
|
|
30
|
+
C.current = p;
|
|
31
|
+
const [g, k] = v(!1), [P, _] = v(() => ({
|
|
32
|
+
width: window.innerWidth,
|
|
33
|
+
height: window.innerHeight
|
|
34
|
+
}));
|
|
35
|
+
X(() => {
|
|
36
|
+
const e = () => _({
|
|
37
|
+
width: window.innerWidth,
|
|
38
|
+
height: window.innerHeight
|
|
39
|
+
});
|
|
40
|
+
return window.addEventListener("resize", e), () => window.removeEventListener("resize", e);
|
|
41
|
+
}, []);
|
|
42
|
+
const O = f(() => k((e) => !e), []), b = E(null);
|
|
43
|
+
X(() => {
|
|
44
|
+
const e = requestAnimationFrame(() => y("visible"));
|
|
26
45
|
return () => cancelAnimationFrame(e);
|
|
27
46
|
}, []);
|
|
28
47
|
const I = f(async () => {
|
|
29
|
-
|
|
30
|
-
}, [
|
|
31
|
-
o.stopPropagation(), o.preventDefault(),
|
|
48
|
+
a && !await a(C.current) || (y("closing"), setTimeout(() => l(C.current), 300));
|
|
49
|
+
}, [a, l]), Y = (e, o) => {
|
|
50
|
+
o.stopPropagation(), o.preventDefault(), b.current = {
|
|
32
51
|
direction: e,
|
|
33
52
|
startX: o.clientX,
|
|
34
53
|
startY: o.clientY,
|
|
35
|
-
startWidth:
|
|
36
|
-
startHeight:
|
|
54
|
+
startWidth: p.width,
|
|
55
|
+
startHeight: p.height
|
|
37
56
|
}, o.target.setPointerCapture(o.pointerId);
|
|
38
|
-
},
|
|
39
|
-
const o =
|
|
57
|
+
}, G = f((e) => {
|
|
58
|
+
const o = b.current;
|
|
40
59
|
if (!o) return;
|
|
41
|
-
const { direction:
|
|
60
|
+
const { direction: m } = o;
|
|
42
61
|
let F = o.startWidth, T = o.startHeight;
|
|
43
|
-
if (
|
|
44
|
-
const
|
|
45
|
-
F = Math.max(
|
|
62
|
+
if (m.includes("e") || m.includes("w")) {
|
|
63
|
+
const M = m.includes("e") ? e.clientX - o.startX : o.startX - e.clientX;
|
|
64
|
+
F = Math.max(rt, o.startWidth + M * 2);
|
|
46
65
|
}
|
|
47
|
-
if (
|
|
48
|
-
const
|
|
49
|
-
T = Math.max(
|
|
66
|
+
if (m.includes("s") || m.includes("n")) {
|
|
67
|
+
const M = m.includes("s") ? e.clientY - o.startY : o.startY - e.clientY;
|
|
68
|
+
T = Math.max(nt, o.startHeight + M * 2);
|
|
50
69
|
}
|
|
51
|
-
|
|
70
|
+
H({
|
|
52
71
|
width: F,
|
|
53
72
|
height: T
|
|
54
73
|
});
|
|
55
74
|
}, []), N = f(() => {
|
|
56
|
-
|
|
57
|
-
}, []),
|
|
58
|
-
size:
|
|
59
|
-
setSize:
|
|
60
|
-
isInspectorOpen:
|
|
61
|
-
toggleInspector:
|
|
75
|
+
b.current = null;
|
|
76
|
+
}, []), c = ot(p, P, n - (g ? 360 / 2 : 0)), S = c.offsetX, W = {
|
|
77
|
+
size: p,
|
|
78
|
+
setSize: H,
|
|
79
|
+
isInspectorOpen: g,
|
|
80
|
+
toggleInspector: O,
|
|
62
81
|
close: () => {
|
|
63
82
|
I();
|
|
64
83
|
}
|
|
65
|
-
},
|
|
84
|
+
}, R = t.left + t.width / 2, j = t.top + t.height / 2, U = P.width / 2 + S - c.width / 2, B = P.height / 2 - c.height / 2, q = `${R - U}px ${j - B}px`, A = [
|
|
66
85
|
"prototype-editor-overlay-content",
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
].join(" "),
|
|
70
|
-
return /* @__PURE__ */
|
|
71
|
-
className:
|
|
86
|
+
s === "visible" ? "prototype-editor-overlay-content--visible" : "",
|
|
87
|
+
s === "closing" ? "prototype-editor-overlay-content--closing" : ""
|
|
88
|
+
].join(" "), V = ["prototype-editor-overlay-backdrop", s === "visible" ? "prototype-editor-overlay-backdrop--visible" : ""].join(" ");
|
|
89
|
+
return /* @__PURE__ */ z("div", {
|
|
90
|
+
className: V,
|
|
72
91
|
"data-testid": "studio-screen-editor-backdrop",
|
|
73
92
|
onClick: I,
|
|
74
|
-
children: [/* @__PURE__ */
|
|
75
|
-
className:
|
|
93
|
+
children: [/* @__PURE__ */ z("div", {
|
|
94
|
+
className: A,
|
|
76
95
|
"data-testid": "studio-screen-editor-frame",
|
|
77
96
|
style: {
|
|
78
|
-
transformOrigin:
|
|
79
|
-
width:
|
|
80
|
-
height:
|
|
81
|
-
marginLeft: -(
|
|
82
|
-
marginTop: -(
|
|
97
|
+
transformOrigin: q,
|
|
98
|
+
width: c.width,
|
|
99
|
+
height: c.height,
|
|
100
|
+
marginLeft: -(c.width / 2) + S,
|
|
101
|
+
marginTop: -(c.height / 2)
|
|
83
102
|
},
|
|
84
103
|
onClick: (e) => e.stopPropagation(),
|
|
85
104
|
onPointerDown: (e) => e.stopPropagation(),
|
|
86
|
-
children: [
|
|
105
|
+
children: [s === "visible" && at.map((e) => /* @__PURE__ */ w("div", {
|
|
87
106
|
className: `prototype-editor-overlay-resize prototype-editor-overlay-resize--${e}`,
|
|
88
|
-
onPointerDown: (o) =>
|
|
89
|
-
onPointerMove:
|
|
107
|
+
onPointerDown: (o) => Y(e, o),
|
|
108
|
+
onPointerMove: G,
|
|
90
109
|
onPointerUp: N,
|
|
91
110
|
onPointerCancel: N
|
|
92
|
-
}, e)),
|
|
93
|
-
}),
|
|
94
|
-
className: `prototype-editor-overlay-inspector${
|
|
111
|
+
}, e)), i(W)]
|
|
112
|
+
}), h && /* @__PURE__ */ w("aside", {
|
|
113
|
+
className: `prototype-editor-overlay-inspector${g && s === "visible" ? " prototype-editor-overlay-inspector--open" : ""}`,
|
|
95
114
|
style: { width: 360 },
|
|
96
|
-
"aria-hidden": !
|
|
97
|
-
inert: !
|
|
115
|
+
"aria-hidden": !g,
|
|
116
|
+
inert: !g,
|
|
98
117
|
onClick: (e) => e.stopPropagation(),
|
|
99
118
|
onPointerDown: (e) => e.stopPropagation(),
|
|
100
|
-
children:
|
|
119
|
+
children: h(W)
|
|
101
120
|
})]
|
|
102
121
|
});
|
|
103
|
-
},
|
|
122
|
+
}, d = /* @__PURE__ */ (function(t) {
|
|
104
123
|
return t.Row = "row", t.Column = "column", t.Grid = "grid", t.Wrap = "wrap", t.Freeform = "freeform", t.Grouping = "grouping", t;
|
|
105
|
-
})({}),
|
|
124
|
+
})({}), x = 8, st = (t) => {
|
|
106
125
|
switch (t) {
|
|
107
|
-
case
|
|
126
|
+
case d.Row:
|
|
108
127
|
return {
|
|
109
128
|
display: "flex",
|
|
110
129
|
flexDirection: "row",
|
|
111
|
-
gap:
|
|
130
|
+
gap: x
|
|
112
131
|
};
|
|
113
|
-
case
|
|
132
|
+
case d.Wrap:
|
|
114
133
|
return {
|
|
115
134
|
display: "flex",
|
|
116
135
|
flexDirection: "row",
|
|
117
136
|
flexWrap: "wrap",
|
|
118
|
-
gap:
|
|
137
|
+
gap: x
|
|
119
138
|
};
|
|
120
|
-
case
|
|
139
|
+
case d.Grid:
|
|
121
140
|
return {
|
|
122
141
|
display: "grid",
|
|
123
142
|
gridTemplateColumns: "repeat(auto-fill, minmax(120px, 1fr))",
|
|
124
|
-
gap:
|
|
143
|
+
gap: x
|
|
125
144
|
};
|
|
126
|
-
case
|
|
145
|
+
case d.Freeform:
|
|
127
146
|
return { position: "relative" };
|
|
128
|
-
case
|
|
129
|
-
case
|
|
147
|
+
case d.Column:
|
|
148
|
+
case d.Grouping:
|
|
130
149
|
return {
|
|
131
150
|
display: "flex",
|
|
132
151
|
flexDirection: "column",
|
|
133
|
-
gap:
|
|
152
|
+
gap: x
|
|
134
153
|
};
|
|
135
154
|
}
|
|
136
|
-
},
|
|
137
|
-
const
|
|
138
|
-
return /* @__PURE__ */
|
|
155
|
+
}, lt = (t) => t !== d.Freeform, ct = ({ component: t, arrangement: r, isDragOver: n }) => {
|
|
156
|
+
const i = (t.children ?? []).filter(Boolean).map(J), h = lt(r);
|
|
157
|
+
return /* @__PURE__ */ z("div", {
|
|
139
158
|
className: `prototype-layout-container${n ? " prototype-layout-container--drag-over" : ""}`,
|
|
140
159
|
"data-layout-arrangement": r,
|
|
141
|
-
style:
|
|
142
|
-
children: [
|
|
160
|
+
style: st(r),
|
|
161
|
+
children: [i.length === 0 && /* @__PURE__ */ w("div", {
|
|
143
162
|
className: "prototype-layout-container__empty",
|
|
144
163
|
"aria-hidden": "true"
|
|
145
|
-
}),
|
|
146
|
-
const
|
|
147
|
-
width:
|
|
148
|
-
height:
|
|
164
|
+
}), i.map((a) => {
|
|
165
|
+
const l = Z(a), s = tt(a), y = {
|
|
166
|
+
width: l.width > 0 ? l.width : void 0,
|
|
167
|
+
height: l.height > 0 ? l.height : void 0
|
|
149
168
|
};
|
|
150
|
-
return /* @__PURE__ */
|
|
169
|
+
return /* @__PURE__ */ w("div", {
|
|
151
170
|
className: "prototype-layout-container__item",
|
|
152
|
-
style:
|
|
171
|
+
style: h ? y : {
|
|
153
172
|
position: "absolute",
|
|
154
|
-
left:
|
|
155
|
-
top:
|
|
156
|
-
...
|
|
173
|
+
left: s.x,
|
|
174
|
+
top: s.y,
|
|
175
|
+
...y
|
|
157
176
|
},
|
|
158
|
-
children:
|
|
159
|
-
}, String(
|
|
177
|
+
children: et(a)
|
|
178
|
+
}, String(a.id));
|
|
160
179
|
})]
|
|
161
180
|
});
|
|
162
|
-
},
|
|
163
|
-
class r extends
|
|
181
|
+
}, u = "StudioLayout", D = "Layout", dt = (t) => {
|
|
182
|
+
class r extends Q {
|
|
164
183
|
componentName = t.type;
|
|
165
|
-
category =
|
|
166
|
-
library =
|
|
184
|
+
category = D;
|
|
185
|
+
library = u;
|
|
167
186
|
initialSize = {
|
|
168
187
|
width: 260,
|
|
169
188
|
height: 140
|
|
@@ -173,44 +192,44 @@ var $ = 900, k = 640, Z = 320, tt = 300, dt = 360, et = (t) => t ? {
|
|
|
173
192
|
get toolbarIcon() {
|
|
174
193
|
return t.icon;
|
|
175
194
|
}
|
|
176
|
-
RenderPrototype(
|
|
177
|
-
return /* @__PURE__ */
|
|
178
|
-
...
|
|
195
|
+
RenderPrototype(i) {
|
|
196
|
+
return /* @__PURE__ */ w(ct, {
|
|
197
|
+
...i,
|
|
179
198
|
arrangement: t.arrangement
|
|
180
199
|
});
|
|
181
200
|
}
|
|
182
201
|
}
|
|
183
202
|
return r;
|
|
184
|
-
},
|
|
203
|
+
}, wt = (t) => {
|
|
185
204
|
const r = {};
|
|
186
205
|
for (const n of t) {
|
|
187
|
-
const
|
|
188
|
-
r[n.type] =
|
|
206
|
+
const i = dt(n);
|
|
207
|
+
r[n.type] = i, r[`${u}.${n.type}`] = i;
|
|
189
208
|
}
|
|
190
|
-
return
|
|
191
|
-
name:
|
|
209
|
+
return K(u, r), {
|
|
210
|
+
name: u,
|
|
192
211
|
bundlePath: "",
|
|
193
212
|
categories: [{
|
|
194
|
-
name:
|
|
213
|
+
name: D,
|
|
195
214
|
components: t.map((n) => ({
|
|
196
215
|
name: n.name,
|
|
197
|
-
category:
|
|
198
|
-
library:
|
|
216
|
+
category: D,
|
|
217
|
+
library: u,
|
|
199
218
|
bundlePath: "",
|
|
200
|
-
type: `${
|
|
219
|
+
type: `${u}.${n.type}`,
|
|
201
220
|
component: new r[n.type]()
|
|
202
221
|
}))
|
|
203
222
|
}]
|
|
204
223
|
};
|
|
205
224
|
};
|
|
206
225
|
export {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
226
|
+
d as LayoutArrangement,
|
|
227
|
+
gt as PrototypeOverlayFrame,
|
|
228
|
+
st as arrangementStyle,
|
|
229
|
+
dt as createLayoutContainerComponent,
|
|
230
|
+
yt as inspectorWidth,
|
|
231
|
+
lt as isFlowArrangement,
|
|
232
|
+
D as layoutContainerCategory,
|
|
233
|
+
u as layoutContainerLibrary,
|
|
234
|
+
wt as registerLayoutContainers
|
|
216
235
|
};
|