@cratis/scene 0.158.2 → 0.159.1

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.
@@ -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 B, u as q, x as A } from "../Scene-DaQtzf1e.js";
2
- import { i as J, r as K, t as Q } from "../renderPrototypeElement-Xm7OIVPs.js";
3
- import { useCallback as f, useEffect as V, useRef as W, useState as b } from "react";
4
- import { jsx as y, jsxs as x } from "react/jsx-runtime";
5
- var $ = 900, k = 640, Z = 320, tt = 300, dt = 360, et = (t) => t ? {
6
- width: t.width > 0 ? t.width : $,
7
- height: t.height > 0 ? t.height : k
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: k
11
- }, ot = [
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
- ], ht = ({ sourceRect: t, initialSize: r, centerOffsetX: n = 0, children: a, renderInspector: g, canClose: s, onClosed: c }) => {
21
- const [l, m] = b("entering"), [i, D] = b(() => et(r)), v = W(i);
22
- v.current = i;
23
- const [u, X] = b(!1), _ = f(() => X((e) => !e), []), C = W(null);
24
- V(() => {
25
- const e = requestAnimationFrame(() => m("visible"));
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
- s && !await s(v.current) || (m("closing"), setTimeout(() => c(v.current), 300));
30
- }, [s, c]), E = (e, o) => {
31
- o.stopPropagation(), o.preventDefault(), C.current = {
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: i.width,
36
- startHeight: i.height
54
+ startWidth: p.width,
55
+ startHeight: p.height
37
56
  }, o.target.setPointerCapture(o.pointerId);
38
- }, L = f((e) => {
39
- const o = C.current;
57
+ }, G = f((e) => {
58
+ const o = b.current;
40
59
  if (!o) return;
41
- const { direction: d } = o;
60
+ const { direction: m } = o;
42
61
  let F = o.startWidth, T = o.startHeight;
43
- if (d.includes("e") || d.includes("w")) {
44
- const P = d.includes("e") ? e.clientX - o.startX : o.startX - e.clientX;
45
- F = Math.max(Z, o.startWidth + P * 2);
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 (d.includes("s") || d.includes("n")) {
48
- const P = d.includes("s") ? e.clientY - o.startY : o.startY - e.clientY;
49
- T = Math.max(tt, o.startHeight + P * 2);
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
- D({
70
+ H({
52
71
  width: F,
53
72
  height: T
54
73
  });
55
74
  }, []), N = f(() => {
56
- C.current = null;
57
- }, []), H = n - (u ? 360 / 2 : 0), S = {
58
- size: i,
59
- setSize: D,
60
- isInspectorOpen: u,
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
- }, Y = t.left + t.width / 2, G = t.top + t.height / 2, M = window.innerWidth / 2 + H - i.width / 2, O = window.innerHeight / 2 - i.height / 2, R = `${Y - M}px ${G - O}px`, j = [
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
- l === "visible" ? "prototype-editor-overlay-content--visible" : "",
68
- l === "closing" ? "prototype-editor-overlay-content--closing" : ""
69
- ].join(" "), U = ["prototype-editor-overlay-backdrop", l === "visible" ? "prototype-editor-overlay-backdrop--visible" : ""].join(" ");
70
- return /* @__PURE__ */ x("div", {
71
- className: U,
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__ */ x("div", {
75
- className: j,
93
+ children: [/* @__PURE__ */ z("div", {
94
+ className: A,
76
95
  "data-testid": "studio-screen-editor-frame",
77
96
  style: {
78
- transformOrigin: R,
79
- width: i.width,
80
- height: i.height,
81
- marginLeft: -(i.width / 2) + H,
82
- marginTop: -(i.height / 2)
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: [l === "visible" && ot.map((e) => /* @__PURE__ */ y("div", {
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) => E(e, o),
89
- onPointerMove: L,
107
+ onPointerDown: (o) => Y(e, o),
108
+ onPointerMove: G,
90
109
  onPointerUp: N,
91
110
  onPointerCancel: N
92
- }, e)), a(S)]
93
- }), g && /* @__PURE__ */ y("aside", {
94
- className: `prototype-editor-overlay-inspector${u && l === "visible" ? " prototype-editor-overlay-inspector--open" : ""}`,
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": !u,
97
- inert: !u,
115
+ "aria-hidden": !g,
116
+ inert: !g,
98
117
  onClick: (e) => e.stopPropagation(),
99
118
  onPointerDown: (e) => e.stopPropagation(),
100
- children: g(S)
119
+ children: h(W)
101
120
  })]
102
121
  });
103
- }, p = /* @__PURE__ */ (function(t) {
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
- })({}), w = 8, rt = (t) => {
124
+ })({}), x = 8, st = (t) => {
106
125
  switch (t) {
107
- case p.Row:
126
+ case d.Row:
108
127
  return {
109
128
  display: "flex",
110
129
  flexDirection: "row",
111
- gap: w
130
+ gap: x
112
131
  };
113
- case p.Wrap:
132
+ case d.Wrap:
114
133
  return {
115
134
  display: "flex",
116
135
  flexDirection: "row",
117
136
  flexWrap: "wrap",
118
- gap: w
137
+ gap: x
119
138
  };
120
- case p.Grid:
139
+ case d.Grid:
121
140
  return {
122
141
  display: "grid",
123
142
  gridTemplateColumns: "repeat(auto-fill, minmax(120px, 1fr))",
124
- gap: w
143
+ gap: x
125
144
  };
126
- case p.Freeform:
145
+ case d.Freeform:
127
146
  return { position: "relative" };
128
- case p.Column:
129
- case p.Grouping:
147
+ case d.Column:
148
+ case d.Grouping:
130
149
  return {
131
150
  display: "flex",
132
151
  flexDirection: "column",
133
- gap: w
152
+ gap: x
134
153
  };
135
154
  }
136
- }, nt = (t) => t !== p.Freeform, it = ({ component: t, arrangement: r, isDragOver: n }) => {
137
- const a = (t.children ?? []).filter(Boolean).map(B), g = nt(r);
138
- return /* @__PURE__ */ x("div", {
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: rt(r),
142
- children: [a.length === 0 && /* @__PURE__ */ y("div", {
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
- }), a.map((s) => {
146
- const c = J(s), l = K(s), m = {
147
- width: c.width > 0 ? c.width : void 0,
148
- height: c.height > 0 ? c.height : void 0
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__ */ y("div", {
169
+ return /* @__PURE__ */ w("div", {
151
170
  className: "prototype-layout-container__item",
152
- style: g ? m : {
171
+ style: h ? y : {
153
172
  position: "absolute",
154
- left: l.x,
155
- top: l.y,
156
- ...m
173
+ left: s.x,
174
+ top: s.y,
175
+ ...y
157
176
  },
158
- children: Q(s)
159
- }, String(s.id));
177
+ children: et(a)
178
+ }, String(a.id));
160
179
  })]
161
180
  });
162
- }, h = "StudioLayout", z = "Layout", at = (t) => {
163
- class r extends A {
181
+ }, u = "StudioLayout", D = "Layout", dt = (t) => {
182
+ class r extends Q {
164
183
  componentName = t.type;
165
- category = z;
166
- library = h;
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(a) {
177
- return /* @__PURE__ */ y(it, {
178
- ...a,
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
- }, mt = (t) => {
203
+ }, wt = (t) => {
185
204
  const r = {};
186
205
  for (const n of t) {
187
- const a = at(n);
188
- r[n.type] = a, r[`${h}.${n.type}`] = a;
206
+ const i = dt(n);
207
+ r[n.type] = i, r[`${u}.${n.type}`] = i;
189
208
  }
190
- return q(h, r), {
191
- name: h,
209
+ return K(u, r), {
210
+ name: u,
192
211
  bundlePath: "",
193
212
  categories: [{
194
- name: z,
213
+ name: D,
195
214
  components: t.map((n) => ({
196
215
  name: n.name,
197
- category: z,
198
- library: h,
216
+ category: D,
217
+ library: u,
199
218
  bundlePath: "",
200
- type: `${h}.${n.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
- p as LayoutArrangement,
208
- ht as PrototypeOverlayFrame,
209
- rt as arrangementStyle,
210
- at as createLayoutContainerComponent,
211
- dt as inspectorWidth,
212
- nt as isFlowArrangement,
213
- z as layoutContainerCategory,
214
- h as layoutContainerLibrary,
215
- mt as registerLayoutContainers
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
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cratis/scene",
3
- "version": "0.158.2",
3
+ "version": "0.159.1",
4
4
  "description": "Cratis Scene: renders Studio prototypes as thumbnails and previews.",
5
5
  "license": "MIT",
6
6
  "author": "Cratis",