@floegence/floe-webapp-core 0.101.48 → 0.101.50

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,60 +1,60 @@
1
- import { use as O, insert as U, createComponent as D, effect as X, setAttribute as h, setStyleProperty as M, memo as W, className as _, template as F, delegateEvents as p } from "solid-js/web";
2
- import { createSignal as j, createMemo as tt, onMount as et, onCleanup as it, For as G, Show as J } from "solid-js";
3
- import { imageAnnotationMarkup as Q, validateImageAnnotation as Y, imagePointFromClient as nt } from "./imageAnnotation.js";
4
- var at = /* @__PURE__ */ F("<div data-floe-image-annotation style=width:100%;height:100%;overflow:auto;scrollbar-gutter:stable;overscroll-behavior:contain><div style=display:grid;place-items:center><svg xmlns=http://www.w3.org/2000/svg role=img style=display:block;user-select:none;flex:none><image></image><g data-annotation-target>"), rt = /* @__PURE__ */ F("<svg><g style=pointer-events:none></svg>", !1, !0, !1), ot = /* @__PURE__ */ F("<svg><rect data-annotation-target fill=white stroke=#111827></svg>", !1, !0, !1);
5
- function ct(e) {
1
+ import { use as W, insert as j, createComponent as D, effect as X, setAttribute as h, setStyleProperty as b, memo as G, className as tt, template as F, delegateEvents as et } from "solid-js/web";
2
+ import { createSignal as J, createMemo as it, onMount as nt, onCleanup as at, For as Q, Show as V } from "solid-js";
3
+ import { imageAnnotationMarkup as Z, validateImageAnnotation as Y, imagePointFromClient as ot } from "./imageAnnotation.js";
4
+ var rt = /* @__PURE__ */ F("<div data-floe-image-annotation style=width:100%;height:100%;overscroll-behavior:contain><div style=display:grid;place-items:center><svg xmlns=http://www.w3.org/2000/svg role=img style=display:block;user-select:none;flex:none><image></image><g data-annotation-target>"), dt = /* @__PURE__ */ F("<svg><g style=pointer-events:none></svg>", !1, !0, !1), lt = /* @__PURE__ */ F("<svg><rect data-annotation-target fill=white stroke=#111827></svg>", !1, !0, !1);
5
+ function gt(e) {
6
6
  let v, u;
7
- const [L, V] = j({
7
+ const [P, $] = J({
8
8
  width: 1,
9
9
  height: 1
10
- }), [N, k] = j();
11
- let b, f;
12
- const z = () => N() ?? e.annotation, w = tt(() => Math.min(L().width / e.width, L().height / e.height) * Math.max(1, e.zoom ?? 1)), Z = () => e.showAnnotation !== !1 && z() && Y(e, z()) ? Q(e, z(), e.marker ?? (e.activeIndex !== void 0 ? e.activeIndex + 1 : 1)) : "";
13
- et(() => {
10
+ }), [N, M] = J();
11
+ let k, f;
12
+ const L = () => N() ?? e.annotation, m = it(() => Math.min(P().width / e.width, P().height / e.height) * Math.max(1, e.zoom ?? 1)), _ = () => e.showAnnotation !== !1 && L() && Y(e, L()) ? Z(e, L(), e.marker ?? (e.activeIndex !== void 0 ? e.activeIndex + 1 : 1)) : "";
13
+ nt(() => {
14
14
  let i = 0;
15
15
  const d = () => {
16
16
  i = 0;
17
- const o = v.clientWidth, c = v.clientHeight;
18
- V((s) => s.width === o && s.height === c ? s : {
19
- width: o,
17
+ const r = v.clientWidth, c = v.clientHeight;
18
+ $((s) => s.width === r && s.height === c ? s : {
19
+ width: r,
20
20
  height: c
21
21
  });
22
22
  }, a = new ResizeObserver(() => {
23
23
  i || (i = requestAnimationFrame(d));
24
24
  });
25
- a.observe(v), d(), it(() => {
25
+ a.observe(v), d(), at(() => {
26
26
  a.disconnect(), cancelAnimationFrame(i);
27
27
  });
28
28
  });
29
- const T = (i, d = !1) => nt(e, u.getBoundingClientRect(), {
29
+ const T = (i, d = !1) => ot(e, u.getBoundingClientRect(), {
30
30
  x: i.clientX,
31
31
  y: i.clientY
32
- }, d), m = () => !!e.onChange && !e.disabled && !e.panning, B = (i) => {
32
+ }, d), w = () => !!e.onChange && !e.disabled && !e.panning, B = (i) => {
33
33
  if (f?.id === i.pointerId) {
34
34
  v.scrollLeft = f.left + f.x - i.clientX, v.scrollTop = f.top + f.y - i.clientY;
35
35
  return;
36
36
  }
37
- const d = b;
38
- if (!d || d.id !== i.pointerId || d.src !== e.src || !m()) return;
37
+ const d = k;
38
+ if (!d || d.id !== i.pointerId || d.src !== e.src || !w()) return;
39
39
  const a = T(i, !0);
40
40
  if (!a) return;
41
- const o = d.original;
42
- if (o && d.corner === void 0) {
43
- const c = o.kind === "rectangle" ? o.width : 0, s = o.kind === "rectangle" ? o.height : 0;
44
- k({
45
- ...o,
46
- x: Math.max(0, Math.min(e.width - c, o.x + a.x - d.start.x)),
47
- y: Math.max(0, Math.min(e.height - s, o.y + a.y - d.start.y))
41
+ const r = d.original;
42
+ if (r && d.corner === void 0) {
43
+ const c = r.kind === "rectangle" ? r.width : 0, s = r.kind === "rectangle" ? r.height : 0;
44
+ M({
45
+ ...r,
46
+ x: Math.max(0, Math.min(e.width - c, r.x + a.x - d.start.x)),
47
+ y: Math.max(0, Math.min(e.height - s, r.y + a.y - d.start.y))
48
48
  });
49
49
  } else {
50
- const c = o?.kind === "rectangle" && d.corner !== void 0 ? {
51
- x: o.x + (d.corner % 2 ? 0 : o.width),
52
- y: o.y + (d.corner < 2 ? o.height : 0)
50
+ const c = r?.kind === "rectangle" && d.corner !== void 0 ? {
51
+ x: r.x + (d.corner % 2 ? 0 : r.width),
52
+ y: r.y + (d.corner < 2 ? r.height : 0)
53
53
  } : d.start, s = Math.abs(a.x - c.x), I = Math.abs(a.y - c.y);
54
- Math.hypot(i.clientX - d.client.x, i.clientY - d.client.y) < 5 && !o ? k({
54
+ Math.hypot(i.clientX - d.client.x, i.clientY - d.client.y) < 5 && !r ? M({
55
55
  kind: "point",
56
56
  ...c
57
- }) : s > 0 && I > 0 && k({
57
+ }) : s > 0 && I > 0 && M({
58
58
  kind: "rectangle",
59
59
  x: Math.min(c.x, a.x),
60
60
  y: Math.min(c.y, a.y),
@@ -67,13 +67,13 @@ function ct(e) {
67
67
  f = void 0, u.hasPointerCapture(i.pointerId) && u.releasePointerCapture(i.pointerId);
68
68
  return;
69
69
  }
70
- const a = b;
70
+ const a = k;
71
71
  if (!a || a.id !== i.pointerId) return;
72
72
  d || B(i);
73
- const o = N();
74
- b = void 0, k(void 0), u.hasPointerCapture(i.pointerId) && u.releasePointerCapture(i.pointerId), !d && a.src === e.src && m() && o && Y(e, o) && e.onChange?.(o);
75
- }, $ = () => {
76
- const i = z();
73
+ const r = N();
74
+ k = void 0, M(void 0), u.hasPointerCapture(i.pointerId) && u.releasePointerCapture(i.pointerId), !d && a.src === e.src && w() && r && Y(e, r) && e.onChange?.(r);
75
+ }, p = () => {
76
+ const i = L();
77
77
  return i?.kind === "rectangle" ? [{
78
78
  x: i.x,
79
79
  y: i.y
@@ -89,11 +89,11 @@ function ct(e) {
89
89
  }] : [];
90
90
  };
91
91
  return (() => {
92
- var i = at(), d = i.firstChild, a = d.firstChild, o = a.firstChild, c = o.nextSibling, s = v;
93
- typeof s == "function" ? O(s, i) : v = i, a.$$keydown = (t) => {
94
- if (!m()) return;
92
+ var i = rt(), d = i.firstChild, a = d.firstChild, r = a.firstChild, c = r.nextSibling, s = v;
93
+ typeof s == "function" ? W(s, i) : v = i, a.$$keydown = (t) => {
94
+ if (!w()) return;
95
95
  if (t.key === "Escape") {
96
- b = void 0, k(void 0);
96
+ k = void 0, M(void 0);
97
97
  return;
98
98
  }
99
99
  const l = {
@@ -104,15 +104,15 @@ function ct(e) {
104
104
  }[t.key];
105
105
  if (!l && t.key !== "Enter" && t.key !== " ") return;
106
106
  t.preventDefault();
107
- const r = e.annotation ?? {
107
+ const o = e.annotation ?? {
108
108
  kind: "point",
109
109
  x: e.width / 2,
110
110
  y: e.height / 2
111
111
  }, n = t.shiftKey ? 10 : 1;
112
112
  e.onChange?.({
113
- ...r,
114
- x: Math.max(0, Math.min(e.width - (r.kind === "rectangle" ? r.width : 0), r.x + (l?.[0] ?? 0) * n)),
115
- y: Math.max(0, Math.min(e.height - (r.kind === "rectangle" ? r.height : 0), r.y + (l?.[1] ?? 0) * n))
113
+ ...o,
114
+ x: Math.max(0, Math.min(e.width - (o.kind === "rectangle" ? o.width : 0), o.x + (l?.[0] ?? 0) * n)),
115
+ y: Math.max(0, Math.min(e.height - (o.kind === "rectangle" ? o.height : 0), o.y + (l?.[1] ?? 0) * n))
116
116
  });
117
117
  }, a.addEventListener("lostpointercapture", (t) => E(t, !0)), a.addEventListener("pointercancel", (t) => E(t, !0)), a.$$pointerup = (t) => E(t), a.$$pointermove = B, a.$$pointerdown = (t) => {
118
118
  if (e.panning && t.button === 0 && !f) {
@@ -125,16 +125,16 @@ function ct(e) {
125
125
  }, u.setPointerCapture(t.pointerId), t.preventDefault();
126
126
  return;
127
127
  }
128
- if (!m() || t.button !== 0 || b) return;
128
+ if (!w() || t.button !== 0 || k) return;
129
129
  const l = T(t);
130
130
  if (!l) return;
131
- const r = t.target, n = r.closest("[data-annotation-index]")?.getAttribute("data-annotation-index");
131
+ const o = t.target, n = o.closest("[data-annotation-index]")?.getAttribute("data-annotation-index");
132
132
  if (n != null && Number(n) !== e.activeIndex) {
133
133
  e.onSelect?.(Number(n)), t.preventDefault();
134
134
  return;
135
135
  }
136
- const g = r.getAttribute("data-corner");
137
- b = {
136
+ const g = o.getAttribute("data-corner");
137
+ k = {
138
138
  id: t.pointerId,
139
139
  start: l,
140
140
  client: {
@@ -142,13 +142,13 @@ function ct(e) {
142
142
  y: t.clientY
143
143
  },
144
144
  src: e.src,
145
- ...r.closest("[data-annotation-target]") ? {
145
+ ...o.closest("[data-annotation-target]") ? {
146
146
  original: e.annotation
147
147
  } : {},
148
148
  ...g !== null ? {
149
149
  corner: Number(g)
150
150
  } : {}
151
- }, k(b.original ?? {
151
+ }, M(k.original ?? {
152
152
  kind: "point",
153
153
  ...l
154
154
  }), u.setPointerCapture(t.pointerId), u.focus({
@@ -156,40 +156,40 @@ function ct(e) {
156
156
  }), t.preventDefault();
157
157
  };
158
158
  var I = u;
159
- return typeof I == "function" ? O(I, a) : u = a, U(a, D(G, {
159
+ return typeof I == "function" ? W(I, a) : u = a, j(a, D(Q, {
160
160
  get each() {
161
161
  return e.annotations?.slice(0, 99);
162
162
  },
163
- children: (t, l) => D(J, {
163
+ children: (t, l) => D(V, {
164
164
  get when() {
165
- return W(() => e.showAnnotation !== !1 && l() !== e.activeIndex)() && Y(e, t);
165
+ return G(() => e.showAnnotation !== !1 && l() !== e.activeIndex)() && Y(e, t);
166
166
  },
167
167
  get children() {
168
- var r = rt();
168
+ var o = dt();
169
169
  return X((n) => {
170
- var g = l(), x = Q(e, t, l() + 1), y = e.cursor ?? (e.onSelect ? "pointer" : void 0);
171
- return g !== n.e && h(r, "data-annotation-index", n.e = g), x !== n.t && (r.innerHTML = n.t = x), y !== n.a && M(r, "cursor", n.a = y), n;
170
+ var g = l(), x = Z(e, t, l() + 1), y = e.cursor ?? (e.onSelect ? "pointer" : void 0);
171
+ return g !== n.e && h(o, "data-annotation-index", n.e = g), x !== n.t && (o.innerHTML = n.t = x), y !== n.a && b(o, "cursor", n.a = y), n;
172
172
  }, {
173
173
  e: void 0,
174
174
  t: void 0,
175
175
  a: void 0
176
- }), r;
176
+ }), o;
177
177
  }
178
178
  })
179
- }), c), U(a, D(J, {
179
+ }), c), j(a, D(V, {
180
180
  get when() {
181
- return W(() => !!m())() && e.showAnnotation !== !1;
181
+ return G(() => !!w())() && e.showAnnotation !== !1;
182
182
  },
183
183
  get children() {
184
- return D(G, {
184
+ return D(Q, {
185
185
  get each() {
186
- return $();
186
+ return p();
187
187
  },
188
188
  children: (t, l) => (() => {
189
- var r = ot();
189
+ var o = lt();
190
190
  return X((n) => {
191
- var g = l(), x = t.x - 5 / w(), y = t.y - 5 / w(), C = 10 / w(), A = 10 / w(), S = 1 / w(), P = e.cursor ?? (l() === 0 || l() === 3 ? "nwse-resize" : "nesw-resize");
192
- return g !== n.e && h(r, "data-corner", n.e = g), x !== n.t && h(r, "x", n.t = x), y !== n.a && h(r, "y", n.a = y), C !== n.o && h(r, "width", n.o = C), A !== n.i && h(r, "height", n.i = A), S !== n.n && h(r, "stroke-width", n.n = S), P !== n.s && M(r, "cursor", n.s = P), n;
191
+ var g = l(), x = t.x - 5 / m(), y = t.y - 5 / m(), C = 10 / m(), A = 10 / m(), S = 1 / m(), z = e.cursor ?? (l() === 0 || l() === 3 ? "nwse-resize" : "nesw-resize");
192
+ return g !== n.e && h(o, "data-corner", n.e = g), x !== n.t && h(o, "x", n.t = x), y !== n.a && h(o, "y", n.a = y), C !== n.o && h(o, "width", n.o = C), A !== n.i && h(o, "height", n.i = A), S !== n.n && h(o, "stroke-width", n.n = S), z !== n.s && b(o, "cursor", n.s = z), n;
193
193
  }, {
194
194
  e: void 0,
195
195
  t: void 0,
@@ -198,13 +198,13 @@ function ct(e) {
198
198
  i: void 0,
199
199
  n: void 0,
200
200
  s: void 0
201
- }), r;
201
+ }), o;
202
202
  })()
203
203
  });
204
204
  }
205
205
  }), null), X((t) => {
206
- var l = e.class, r = `${Math.max(L().width, e.width * w())}px`, n = `${Math.max(L().height, e.height * w())}px`, g = e.width * w(), x = e.height * w(), y = `0 0 ${e.width} ${e.height}`, C = e.label, A = m() ? 0 : void 0, S = m() || e.panning ? "none" : "auto", P = e.cursor ?? (e.panning ? "grab" : m() ? "crosshair" : "default"), H = e.src, R = e.width, q = e.height, K = Z();
207
- return l !== t.e && _(i, t.e = l), r !== t.t && M(d, "width", t.t = r), n !== t.a && M(d, "height", t.a = n), g !== t.o && h(a, "width", t.o = g), x !== t.i && h(a, "height", t.i = x), y !== t.n && h(a, "viewBox", t.n = y), C !== t.s && h(a, "aria-label", t.s = C), A !== t.h && h(a, "tabindex", t.h = A), S !== t.r && M(a, "touch-action", t.r = S), P !== t.d && M(a, "cursor", t.d = P), H !== t.l && h(o, "href", t.l = H), R !== t.u && h(o, "width", t.u = R), q !== t.c && h(o, "height", t.c = q), K !== t.w && (c.innerHTML = t.w = K), t;
206
+ var l = e.class, o = (e.zoom ?? 1) > 1 ? "auto" : "hidden", n = (e.zoom ?? 1) > 1 ? "stable" : "auto", g = `${Math.max(P().width, e.width * m())}px`, x = `${Math.max(P().height, e.height * m())}px`, y = e.width * m(), C = e.height * m(), A = `0 0 ${e.width} ${e.height}`, S = e.label, z = w() ? 0 : void 0, H = w() || e.panning ? "none" : "auto", R = e.cursor ?? (e.panning ? "grab" : w() ? "crosshair" : "default"), q = e.src, K = e.width, O = e.height, U = _();
207
+ return l !== t.e && tt(i, t.e = l), o !== t.t && b(i, "overflow", t.t = o), n !== t.a && b(i, "scrollbar-gutter", t.a = n), g !== t.o && b(d, "width", t.o = g), x !== t.i && b(d, "height", t.i = x), y !== t.n && h(a, "width", t.n = y), C !== t.s && h(a, "height", t.s = C), A !== t.h && h(a, "viewBox", t.h = A), S !== t.r && h(a, "aria-label", t.r = S), z !== t.d && h(a, "tabindex", t.d = z), H !== t.l && b(a, "touch-action", t.l = H), R !== t.u && b(a, "cursor", t.u = R), q !== t.c && h(r, "href", t.c = q), K !== t.w && h(r, "width", t.w = K), O !== t.m && h(r, "height", t.m = O), U !== t.f && (c.innerHTML = t.f = U), t;
208
208
  }, {
209
209
  e: void 0,
210
210
  t: void 0,
@@ -219,11 +219,13 @@ function ct(e) {
219
219
  l: void 0,
220
220
  u: void 0,
221
221
  c: void 0,
222
- w: void 0
222
+ w: void 0,
223
+ m: void 0,
224
+ f: void 0
223
225
  }), i;
224
226
  })();
225
227
  }
226
- p(["pointerdown", "pointermove", "pointerup", "keydown"]);
228
+ et(["pointerdown", "pointermove", "pointerup", "keydown"]);
227
229
  export {
228
- ct as ImageAnnotationSurface
230
+ gt as ImageAnnotationSurface
229
231
  };
@@ -1,5 +1,6 @@
1
1
  import { type JSX } from 'solid-js';
2
2
  import { type SelectOption, type SelectBaseProps } from './Select';
3
+ import { type PromptCardRegion } from './promptCardPlacement';
3
4
  export interface PromptCardProps {
4
5
  open: boolean;
5
6
  /** Viewport coordinates captured by the host at the contextual action. */
@@ -7,6 +8,8 @@ export interface PromptCardProps {
7
8
  x: number;
8
9
  y: number;
9
10
  }> | null;
11
+ /** Selected content to keep visible where space permits, in viewport pixels and preferred order. */
12
+ avoidRegions?: readonly PromptCardRegion[];
10
13
  viewportInsets?: Readonly<{
11
14
  top?: number;
12
15
  right?: number;
@@ -1,111 +1,122 @@
1
- import { createComponent as u, Portal as we, use as ee, setAttribute as y, insert as c, spread as Ce, mergeProps as Se, effect as X, setStyleProperty as M, className as Me, template as D, delegateEvents as Ee } from "solid-js/web";
2
- import { createUniqueId as Pe, createSignal as z, onCleanup as te, createMemo as F, untrack as K, createEffect as U, Show as E } from "solid-js";
1
+ import { createComponent as f, Portal as we, use as te, setAttribute as x, insert as c, spread as Ce, mergeProps as Se, effect as U, setStyleProperty as P, className as Me, template as A, delegateEvents as Pe } from "solid-js/web";
2
+ import { createUniqueId as Ee, createSignal as z, onCleanup as ne, createMemo as F, untrack as j, createEffect as Q, Show as E } from "solid-js";
3
3
  import { useOverlayMask as ke } from "../../hooks/useOverlayMask.js";
4
4
  import { deferAfterPaint as ue } from "../../utils/defer.js";
5
5
  import { ensureSurfacePortalInteractionTracking as me, resolveSurfacePortalHost as $e, resolveSurfacePortalScale as De, resolveSurfacePortalBoundaryRect as Ae, projectSurfacePortalPosition as Le, readFreshInteractionSnapshot as he, resolveSurfacePortalMount as Te, isSurfacePortalMode as Oe } from "./dialogSurfaceScope.js";
6
6
  import { cn as fe } from "../../utils/cn.js";
7
7
  import { readViewportSnapshot as Ie, observeViewport as ze } from "../../viewport.js";
8
- import { X as Fe, Plus as Be, ArrowUp as He } from "../icons/index.js";
9
- import { Button as ne } from "./Button.js";
10
- import { Select as qe } from "./Select.js";
11
- import { createFloatingPresence as Re } from "./floatingPresence.js";
12
- var Ve = /* @__PURE__ */ D("<span class=floe-prompt-card-icon aria-hidden=true>"), _e = /* @__PURE__ */ D("<div class=floe-prompt-card-question>"), Ne = /* @__PURE__ */ D("<div class=floe-prompt-card-references>"), We = /* @__PURE__ */ D("<input type=file multiple hidden tabindex=-1>"), Xe = /* @__PURE__ */ D("<div class=floe-prompt-card-feedback>"), Ke = /* @__PURE__ */ D("<div class=floe-prompt-card-positioner><div role=dialog aria-modal=false tabindex=-1 data-floe-prompt-card data-floe-input-surface data-floe-surface=floating data-floe-local-interaction-surface=true><header class=floe-prompt-card-header><h2></h2></header><div><div class=floe-prompt-card-composer><div class=floe-prompt-card-field><textarea class=floe-prompt-card-input rows=2></textarea></div><div class=floe-prompt-card-actions><div class=floe-prompt-card-tools>");
13
- function Ue(t) {
8
+ import { X as Fe, Plus as Be, ArrowUp as Re } from "../icons/index.js";
9
+ import { Button as ae } from "./Button.js";
10
+ import { Select as He } from "./Select.js";
11
+ import { createFloatingPresence as qe } from "./floatingPresence.js";
12
+ import { avoidPromptCardRegions as Ve } from "./promptCardPlacement.js";
13
+ var _e = /* @__PURE__ */ A("<span class=floe-prompt-card-icon aria-hidden=true>"), Ne = /* @__PURE__ */ A("<div class=floe-prompt-card-question>"), We = /* @__PURE__ */ A("<div class=floe-prompt-card-references>"), Xe = /* @__PURE__ */ A("<input type=file multiple hidden tabindex=-1>"), Ke = /* @__PURE__ */ A("<div class=floe-prompt-card-feedback>"), Ue = /* @__PURE__ */ A("<div class=floe-prompt-card-positioner><div role=dialog aria-modal=false tabindex=-1 data-floe-prompt-card data-floe-input-surface data-floe-surface=floating data-floe-local-interaction-surface=true><header class=floe-prompt-card-header><h2></h2></header><div><div class=floe-prompt-card-composer><div class=floe-prompt-card-field><textarea class=floe-prompt-card-input rows=2></textarea></div><div class=floe-prompt-card-actions><div class=floe-prompt-card-tools>");
14
+ function je(t) {
14
15
  if (typeof document > "u") return null;
15
16
  me();
16
- const w = t ?? he()?.target ?? document.activeElement;
17
- if (!w?.isConnected || w === document.body || w === document.documentElement) return null;
18
- const P = w.getBoundingClientRect();
19
- return P.width > 0 && P.height > 0 ? {
20
- x: P.left,
21
- y: P.bottom
17
+ const y = t ?? he()?.target ?? document.activeElement;
18
+ if (!y?.isConnected || y === document.body || y === document.documentElement) return null;
19
+ const k = y.getBoundingClientRect();
20
+ return k.width > 0 && k.height > 0 ? {
21
+ x: k.left,
22
+ y: k.bottom
22
23
  } : null;
23
24
  }
24
- function it(t) {
25
+ function ot(t) {
25
26
  me();
26
- const w = Pe(), [P, ae] = z(!1), [ge, ie] = z(!1), l = () => t.busy || P();
27
- let j = !1;
28
- te(() => {
29
- j = !0;
27
+ const y = Ee(), [k, ie] = z(!1), [ge, re] = z(!1), l = () => t.busy || k();
28
+ let Y = !1;
29
+ ne(() => {
30
+ Y = !0;
30
31
  });
31
- const [g, ve] = z(Ie(window)), [A, be] = z(), [Q, xe] = z({
32
+ const [v, ve] = z(Ie(window)), [L, be] = z(), [G, xe] = z({
32
33
  width: 0,
33
34
  height: 0
34
- }), ye = F((n) => t.open ? t.anchor ?? K(() => Ue(t.owner)) : n), C = Re({
35
+ }), ye = F((n) => t.open ? t.anchor ?? j(() => je(t.owner)) : n), w = qe({
35
36
  open: () => t.open,
36
- element: A
37
+ element: L
37
38
  });
38
- let v, Y, L = !1, G, B;
39
- const J = () => queueMicrotask(() => {
40
- !j && t.open && !l() && !t.inputDisabled && v?.isConnected && v.focus({
39
+ let b, J, T = !1, Z, B;
40
+ const p = () => queueMicrotask(() => {
41
+ !Y && t.open && !l() && !t.inputDisabled && b?.isConnected && b.focus({
41
42
  preventScroll: !0
42
43
  });
43
- }), Z = (n) => {
44
- t.open && !l() && !t.inputDisabled && n.length && (t.attachment?.onFiles(n), J());
44
+ }), ee = (n) => {
45
+ t.open && !l() && !t.inputDisabled && n.length && (t.attachment?.onFiles(n), p());
45
46
  };
46
- U(() => {
47
- (!t.open || l() || t.inputDisabled) && ie(!1);
47
+ Q(() => {
48
+ (!t.open || l() || t.inputDisabled) && re(!1);
48
49
  });
49
- const T = F(() => !C.mounted() || t.portalScope === "viewport" ? {
50
+ const O = F(() => !w.mounted() || t.portalScope === "viewport" ? {
50
51
  host: null,
51
52
  boundaryHost: null,
52
53
  mountHost: null,
53
54
  mode: "global"
54
55
  } : $e({
55
56
  owner: t.owner
56
- })), H = () => Oe(T()), O = F(() => (g(), Q(), H() ? De(T()) : {
57
- x: g().fixedScale,
58
- y: g().fixedScale
57
+ })), R = () => Oe(O()), I = F(() => (v(), G(), R() ? De(O()) : {
58
+ x: v().fixedScale,
59
+ y: v().fixedScale
59
60
  }));
60
- U(() => {
61
- C.mounted() && te(ze(window, ve));
62
- }), U(() => {
63
- const n = A();
64
- if (!C.mounted() || !n) return;
65
- const i = () => xe((s) => {
66
- const f = n.offsetWidth, d = n.offsetHeight;
67
- return s.width === f && s.height === d ? s : {
68
- width: f,
69
- height: d
61
+ Q(() => {
62
+ w.mounted() && ne(ze(window, ve));
63
+ }), Q(() => {
64
+ const n = L();
65
+ if (!w.mounted() || !n) return;
66
+ const i = () => xe((d) => {
67
+ const u = n.offsetWidth, s = n.offsetHeight;
68
+ return d.width === u && d.height === s ? d : {
69
+ width: u,
70
+ height: s
70
71
  };
71
72
  }), r = new ResizeObserver(i);
72
- r.observe(n), i(), te(() => r.disconnect());
73
+ r.observe(n), i(), ne(() => r.disconnect());
73
74
  });
74
- const S = F(() => {
75
- const n = g(), i = H() ? Ae(T()) : n.visible, r = n.visible.width < 640 ? 8 : 12, s = t.viewportInsets, f = Math.max(n.visible.left, i.left) + Math.max(n.safeArea.left, s?.left ?? 0) + r, d = Math.max(n.visible.top, i.top) + Math.max(n.safeArea.top, s?.top ?? 0) + r, k = Math.min(n.visible.right, i.right) - Math.max(n.safeArea.right, s?.right ?? 0) - r, o = Math.min(n.visible.bottom, i.bottom) - Math.max(n.safeArea.bottom, s?.bottom ?? 0) - r, $ = Math.max(0, k - f), b = Math.min(Q().width * O().x, $), e = Math.max(0, o - d), m = Math.min(Q().height * O().y, e), a = ye(), h = (_, N, W) => Math.max(N, Math.min(_, W)), x = h(a ? a.x + 8 : f + ($ - b) / 2, f, k - b), I = !a || a.y + 8 + m <= o, R = a ? I ? a.y + 8 : a.y - m - 8 : d + Math.max(0, (e - m) * 0.32), V = h(R, d, o - m);
75
+ const C = F(() => {
76
+ const n = v(), i = R() ? Ae(O()) : n.visible, r = n.visible.width < 640 ? 8 : 12, d = t.viewportInsets, u = Math.max(n.visible.left, i.left) + Math.max(n.safeArea.left, d?.left ?? 0) + r, s = Math.max(n.visible.top, i.top) + Math.max(n.safeArea.top, d?.top ?? 0) + r, S = Math.min(n.visible.right, i.right) - Math.max(n.safeArea.right, d?.right ?? 0) - r, o = Math.min(n.visible.bottom, i.bottom) - Math.max(n.safeArea.bottom, d?.bottom ?? 0) - r, $ = Math.max(0, S - u), h = Math.min(G().width * I().x, $), e = Math.max(0, o - s), m = Math.min(G().height * I().y, e), a = ye(), g = (W, X, K) => Math.max(X, Math.min(W, K)), M = g(a ? a.x + 8 : u + ($ - h) / 2, u, S - h), q = !a || a.y + 8 + m <= o, V = a ? q ? a.y + 8 : a.y - m - 8 : s + Math.max(0, (e - m) * 0.32), _ = g(V, s, o - m), D = Ve({
77
+ x: M,
78
+ y: _
79
+ }, {
80
+ width: h,
81
+ height: m
82
+ }, {
83
+ left: u,
84
+ top: s,
85
+ right: S,
86
+ bottom: o
87
+ }, t.avoidRegions ?? []), N = a ? D.y >= a.y ? "bottom" : "top" : "edge";
76
88
  return {
77
- x,
78
- y: V,
89
+ ...D,
79
90
  availableWidth: $,
80
91
  maxHeight: e,
81
- side: a ? I ? "bottom" : "top" : "edge",
82
- originX: a ? h(a.x - x, 16, b - 16) : b / 2
92
+ side: N,
93
+ originX: a ? g(a.x - D.x, 16, h - 16) : h / 2
83
94
  };
84
- }), re = F(() => H() ? Le(S(), T()) : {
85
- x: (S().x + g().fixedOffset.left) / g().fixedScale,
86
- y: (S().y + g().fixedOffset.top) / g().fixedScale
87
- }), q = (n) => {
88
- l() || !t.open || L || (t.onClose(), n && ue(() => K(() => {
89
- !t.open && Y?.isConnected && Y.focus({
95
+ }), oe = F(() => R() ? Le(C(), O()) : {
96
+ x: (C().x + v().fixedOffset.left) / v().fixedScale,
97
+ y: (C().y + v().fixedOffset.top) / v().fixedScale
98
+ }), H = (n) => {
99
+ l() || !t.open || T || (t.onClose(), n && ue(() => j(() => {
100
+ !t.open && J?.isConnected && J.focus({
90
101
  preventScroll: !0
91
102
  });
92
103
  })));
93
104
  };
94
- U(() => {
105
+ Q(() => {
95
106
  if (!t.open) return;
96
107
  const n = document.activeElement, r = t.owner ?? he()?.target?.closest("button, a[href], input, [tabindex]") ?? (n instanceof HTMLElement && n !== document.body ? n : void 0);
97
- r && !K(A)?.contains(r) && !t.containsTarget?.(r) && (Y = r), queueMicrotask(() => {
98
- !t.open || t.autoFocus === !1 || !v?.isConnected || (v.focus({
108
+ r && !j(L)?.contains(r) && !t.containsTarget?.(r) && (J = r), queueMicrotask(() => {
109
+ !t.open || t.autoFocus === !1 || !b?.isConnected || (b.focus({
99
110
  preventScroll: !0
100
- }), v.setSelectionRange(v.value.length, v.value.length));
111
+ }), b.setSelectionRange(b.value.length, b.value.length));
101
112
  });
102
113
  }), ke({
103
114
  open: () => t.open,
104
- root: A,
105
- containsTarget: (n) => !!(n instanceof Node && A()?.contains(n)) || !!t.containsTarget?.(n) || !!(n instanceof Node && document.getElementById(B?.getAttribute("aria-controls") ?? "")?.parentElement?.contains(n)),
106
- onClose: () => q(!0),
115
+ root: L,
116
+ containsTarget: (n) => !!(n instanceof Node && L()?.contains(n)) || !!t.containsTarget?.(n) || !!(n instanceof Node && document.getElementById(B?.getAttribute("aria-controls") ?? "")?.parentElement?.contains(n)),
117
+ onClose: () => H(!0),
107
118
  onInteractOutside: (n) => {
108
- n.type === "pointerdown" && n.button === 0 && q(!1);
119
+ n.type === "pointerdown" && n.button === 0 && H(!1);
109
120
  },
110
121
  // Related previews belong to pointer ownership, but own their Escape command.
111
122
  closeOnEscape: "none",
@@ -116,38 +127,38 @@ function it(t) {
116
127
  restoreFocus: !1,
117
128
  blockHotkeys: !1
118
129
  });
119
- const oe = () => {
120
- !t.open || l() || t.submitDisabled || (ae(!0), ue(() => K(() => {
121
- if (!j)
130
+ const le = () => {
131
+ !t.open || l() || t.submitDisabled || (ie(!0), ue(() => j(() => {
132
+ if (!Y)
122
133
  try {
123
134
  t.open && t.onSubmit();
124
135
  } finally {
125
- ae(!1);
136
+ ie(!1);
126
137
  }
127
138
  })));
128
139
  };
129
- return u(E, {
140
+ return f(E, {
130
141
  get when() {
131
- return C.mounted();
142
+ return w.mounted();
132
143
  },
133
144
  get children() {
134
- return u(we, {
145
+ return f(we, {
135
146
  get mount() {
136
- return Te(T());
147
+ return Te(O());
137
148
  },
138
149
  get children() {
139
- var n = Ke(), i = n.firstChild, r = i.firstChild, s = r.firstChild, f = r.nextSibling, d = f.firstChild, k = d.firstChild, o = k.firstChild, $ = k.nextSibling, b = $.firstChild;
150
+ var n = Ue(), i = n.firstChild, r = i.firstChild, d = r.firstChild, u = r.nextSibling, s = u.firstChild, S = s.firstChild, o = S.firstChild, $ = S.nextSibling, h = $.firstChild;
140
151
  return i.$$keydown = (e) => {
141
- e.key !== "Escape" || e.defaultPrevented || e.isComposing || L || B?.getAttribute("aria-expanded") === "true" && B.contains(e.target) || (e.preventDefault(), e.stopPropagation(), q(!0));
142
- }, i.$$focusin = () => t.onActivate?.(), i.$$pointerdown = () => t.onActivate?.(), ee(be, i), y(i, "aria-labelledby", w), c(r, u(E, {
152
+ e.key !== "Escape" || e.defaultPrevented || e.isComposing || T || B?.getAttribute("aria-expanded") === "true" && B.contains(e.target) || (e.preventDefault(), e.stopPropagation(), H(!0));
153
+ }, i.$$focusin = () => t.onActivate?.(), i.$$pointerdown = () => t.onActivate?.(), te(be, i), x(i, "aria-labelledby", y), c(r, f(E, {
143
154
  get when() {
144
155
  return t.icon;
145
156
  },
146
157
  get children() {
147
- var e = Ve();
158
+ var e = _e();
148
159
  return c(e, () => t.icon), e;
149
160
  }
150
- }), s), y(s, "id", w), c(s, () => t.title), c(r, u(ne, {
161
+ }), d), x(d, "id", y), c(d, () => t.title), c(r, f(ae, {
151
162
  variant: "ghost",
152
163
  size: "icon",
153
164
  icon: Fe,
@@ -161,60 +172,60 @@ function it(t) {
161
172
  get "aria-label"() {
162
173
  return t.closeLabel;
163
174
  },
164
- onClick: () => q(!0)
165
- }), null), Ce(f, Se(() => t.bodyProps, {
175
+ onClick: () => H(!0)
176
+ }), null), Ce(u, Se(() => t.bodyProps, {
166
177
  get class() {
167
178
  return fe("floe-prompt-card-body", t.bodyProps?.class);
168
179
  }
169
- }), !1, !0), c(f, u(E, {
180
+ }), !1, !0), c(u, f(E, {
170
181
  get when() {
171
182
  return t.question;
172
183
  },
173
184
  get children() {
174
- var e = _e();
185
+ var e = Ne();
175
186
  return c(e, () => t.question), e;
176
187
  }
177
- }), d), d.addEventListener("drop", (e) => {
178
- !t.attachment || !e.dataTransfer?.files.length || (e.preventDefault(), Z(Array.from(e.dataTransfer.files)));
179
- }), d.addEventListener("dragover", (e) => {
188
+ }), s), s.addEventListener("drop", (e) => {
189
+ !t.attachment || !e.dataTransfer?.files.length || (e.preventDefault(), ee(Array.from(e.dataTransfer.files)));
190
+ }), s.addEventListener("dragover", (e) => {
180
191
  t.attachment && !l() && !t.inputDisabled && e.dataTransfer?.types.includes("Files") && e.preventDefault();
181
- }), c(d, u(E, {
192
+ }), c(s, f(E, {
182
193
  get when() {
183
194
  return t.references;
184
195
  },
185
196
  get children() {
186
- var e = Ne();
187
- return c(e, () => t.references), X(() => e.inert = !!l()), e;
197
+ var e = We();
198
+ return c(e, () => t.references), U(() => e.inert = !!l()), e;
188
199
  }
189
- }), k), o.$$keydown = (e) => {
190
- e.key === "Enter" && !e.shiftKey && !e.isComposing && !L && (e.preventDefault(), oe());
200
+ }), S), o.$$keydown = (e) => {
201
+ e.key === "Enter" && !e.shiftKey && !e.isComposing && !T && (e.preventDefault(), le());
191
202
  }, o.addEventListener("compositionend", (e) => {
192
- L = !1, t.onValueChange(e.currentTarget.value);
203
+ T = !1, t.onValueChange(e.currentTarget.value);
193
204
  }), o.addEventListener("compositionupdate", (e) => t.onValueChange(e.currentTarget.value)), o.addEventListener("compositionstart", () => {
194
- L = !0;
205
+ T = !0;
195
206
  }), o.$$input = (e) => t.onValueChange(e.currentTarget.value), o.addEventListener("paste", (e) => {
196
- !t.attachment || !e.clipboardData?.files.length || (e.preventDefault(), Z(Array.from(e.clipboardData.files)));
197
- }), ee((e) => {
198
- v = e, t.editorRef?.(e);
199
- }, o), c(b, u(E, {
207
+ !t.attachment || !e.clipboardData?.files.length || (e.preventDefault(), ee(Array.from(e.clipboardData.files)));
208
+ }), te((e) => {
209
+ b = e, t.editorRef?.(e);
210
+ }, o), c(h, f(E, {
200
211
  get when() {
201
212
  return t.attachment;
202
213
  },
203
214
  get children() {
204
215
  return [(() => {
205
- var e = We();
216
+ var e = Xe();
206
217
  e.addEventListener("change", (a) => {
207
- Z(Array.from(a.currentTarget.files ?? [])), a.currentTarget.value = "";
208
- }), e.addEventListener("cancel", J);
209
- var m = G;
210
- return typeof m == "function" ? ee(m, e) : G = e, X((a) => {
211
- var h = t.attachment?.accept, x = l() || t.inputDisabled;
212
- return h !== a.e && y(e, "accept", a.e = h), x !== a.t && (e.disabled = a.t = x), a;
218
+ ee(Array.from(a.currentTarget.files ?? [])), a.currentTarget.value = "";
219
+ }), e.addEventListener("cancel", p);
220
+ var m = Z;
221
+ return typeof m == "function" ? te(m, e) : Z = e, U((a) => {
222
+ var g = t.attachment?.accept, M = l() || t.inputDisabled;
223
+ return g !== a.e && x(e, "accept", a.e = g), M !== a.t && (e.disabled = a.t = M), a;
213
224
  }, {
214
225
  e: void 0,
215
226
  t: void 0
216
227
  }), e;
217
- })(), u(ne, {
228
+ })(), f(ae, {
218
229
  variant: "ghost",
219
230
  size: "icon",
220
231
  icon: Be,
@@ -228,15 +239,15 @@ function it(t) {
228
239
  get title() {
229
240
  return t.attachment?.label;
230
241
  },
231
- onClick: () => G?.click()
242
+ onClick: () => Z?.click()
232
243
  })];
233
244
  }
234
- }), null), c(b, () => t.tools, null), c(b, u(E, {
245
+ }), null), c(h, () => t.tools, null), c(h, f(E, {
235
246
  get when() {
236
247
  return t.selection;
237
248
  },
238
249
  get children() {
239
- return u(qe, {
250
+ return f(He, {
240
251
  ref: (e) => {
241
252
  B = e;
242
253
  },
@@ -244,8 +255,8 @@ function it(t) {
244
255
  get open() {
245
256
  return ge();
246
257
  },
247
- onOpenChange: ie,
248
- onOptionSelect: J,
258
+ onOpenChange: re,
259
+ onOptionSelect: p,
249
260
  get zIndex() {
250
261
  return (t.zIndex ?? 100) + 1;
251
262
  },
@@ -285,10 +296,10 @@ function it(t) {
285
296
  }
286
297
  });
287
298
  }
288
- }), null), c($, u(ne, {
299
+ }), null), c($, f(ae, {
289
300
  variant: "primary",
290
301
  size: "icon",
291
- icon: He,
302
+ icon: Re,
292
303
  class: "floe-prompt-card-submit",
293
304
  get disabled() {
294
305
  return t.submitDisabled;
@@ -305,18 +316,18 @@ function it(t) {
305
316
  get "aria-label"() {
306
317
  return t.submitLabel;
307
318
  },
308
- onClick: oe
309
- }), null), c(f, u(E, {
319
+ onClick: le
320
+ }), null), c(u, f(E, {
310
321
  get when() {
311
322
  return t.feedback;
312
323
  },
313
324
  get children() {
314
- var e = Xe();
325
+ var e = Ke();
315
326
  return c(e, () => t.feedback), e;
316
327
  }
317
- }), null), X((e) => {
318
- var m = H() ? "absolute" : "fixed", a = `${re().x}px`, h = `${re().y}px`, x = `${S().availableWidth / O().x}px`, I = `${S().maxHeight / O().y}px`, R = `${S().originX / O().x}px`, V = t.zIndex ?? 100, p = fe("floe-prompt-card floe-floating-presence", t.class), _ = S().side, N = C.state(), W = C.exiting(), le = C.exiting() ? "true" : void 0, ce = t.inputLabel, se = t.placeholder, de = l() || t.inputDisabled;
319
- return m !== e.e && M(n, "position", e.e = m), a !== e.t && M(n, "left", e.t = a), h !== e.a && M(n, "top", e.a = h), x !== e.o && M(n, "--floe-prompt-max-width", e.o = x), I !== e.i && M(n, "--floe-prompt-max-height", e.i = I), R !== e.n && M(n, "--floe-prompt-origin-x", e.n = R), V !== e.s && M(n, "z-index", e.s = V), p !== e.h && Me(i, e.h = p), _ !== e.r && y(i, "data-floating-side", e.r = _), N !== e.d && y(i, "data-floating-presence", e.d = N), W !== e.l && (i.inert = e.l = W), le !== e.u && y(i, "aria-hidden", e.u = le), ce !== e.c && y(o, "aria-label", e.c = ce), se !== e.w && y(o, "placeholder", e.w = se), de !== e.m && (o.disabled = e.m = de), e;
328
+ }), null), U((e) => {
329
+ var m = R() ? "absolute" : "fixed", a = `${oe().x}px`, g = `${oe().y}px`, M = `${C().availableWidth / I().x}px`, q = `${C().maxHeight / I().y}px`, V = `${C().originX / I().x}px`, _ = t.zIndex ?? 100, D = fe("floe-prompt-card floe-floating-presence", t.class), N = C().side, W = w.state(), X = w.exiting(), K = w.exiting() ? "true" : void 0, ce = t.inputLabel, se = t.placeholder, de = l() || t.inputDisabled;
330
+ return m !== e.e && P(n, "position", e.e = m), a !== e.t && P(n, "left", e.t = a), g !== e.a && P(n, "top", e.a = g), M !== e.o && P(n, "--floe-prompt-max-width", e.o = M), q !== e.i && P(n, "--floe-prompt-max-height", e.i = q), V !== e.n && P(n, "--floe-prompt-origin-x", e.n = V), _ !== e.s && P(n, "z-index", e.s = _), D !== e.h && Me(i, e.h = D), N !== e.r && x(i, "data-floating-side", e.r = N), W !== e.d && x(i, "data-floating-presence", e.d = W), X !== e.l && (i.inert = e.l = X), K !== e.u && x(i, "aria-hidden", e.u = K), ce !== e.c && x(o, "aria-label", e.c = ce), se !== e.w && x(o, "placeholder", e.w = se), de !== e.m && (o.disabled = e.m = de), e;
320
331
  }, {
321
332
  e: void 0,
322
333
  t: void 0,
@@ -333,14 +344,14 @@ function it(t) {
333
344
  c: void 0,
334
345
  w: void 0,
335
346
  m: void 0
336
- }), X(() => o.value = t.value), n;
347
+ }), U(() => o.value = t.value), n;
337
348
  }
338
349
  });
339
350
  }
340
351
  });
341
352
  }
342
- Ee(["pointerdown", "focusin", "keydown", "input"]);
353
+ Pe(["pointerdown", "focusin", "keydown", "input"]);
343
354
  export {
344
- it as PromptCard,
345
- Ue as capturePromptCardAnchor
355
+ ot as PromptCard,
356
+ je as capturePromptCardAnchor
346
357
  };
@@ -0,0 +1,24 @@
1
+ export type PromptCardRegion = Readonly<{
2
+ x: number;
3
+ y: number;
4
+ width: number;
5
+ height: number;
6
+ }>;
7
+ /** Keep a contextual editor near its anchor while avoiding the content it edits.
8
+ * All inputs and results are viewport pixels; portal projection happens afterward.
9
+ */
10
+ export declare function avoidPromptCardRegions(preferred: {
11
+ x: number;
12
+ y: number;
13
+ }, { width, height }: {
14
+ width: number;
15
+ height: number;
16
+ }, { left, top, right, bottom }: {
17
+ left: number;
18
+ top: number;
19
+ right: number;
20
+ bottom: number;
21
+ }, regions: readonly PromptCardRegion[]): {
22
+ x: number;
23
+ y: number;
24
+ };
@@ -0,0 +1,12 @@
1
+ function e(h, { width: m, height: M }, { left: o, top: i, right: c, bottom: d }, n) {
2
+ const s = [[h.x, h.y], ...n.flatMap((a) => [
3
+ [a.x + a.width + 12, a.y],
4
+ [a.x - m - 12, a.y],
5
+ [a.x, a.y + a.height + 12],
6
+ [a.x, a.y - M - 12]
7
+ ])].map(([a, x]) => ({ x: Math.max(o, Math.min(a, c - m)), y: Math.max(i, Math.min(x, d - M)) })), y = (a) => n.reduce((x, t) => x + Math.max(0, Math.min(a.x + m, t.x + t.width + 8) - Math.max(a.x, t.x - 8)) * Math.max(0, Math.min(a.y + M, t.y + t.height + 8) - Math.max(a.y, t.y - 8)), 0);
8
+ return s.sort((a, x) => y(a) - y(x))[0];
9
+ }
10
+ export {
11
+ e as avoidPromptCardRegions
12
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@floegence/floe-webapp-core",
3
- "version": "0.101.48",
3
+ "version": "0.101.50",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",