@hyperframes/core 0.9.96 → 0.9.97

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.
@@ -2,7 +2,7 @@ import { handleFor } from "../editingHandles.js";
2
2
  import { MOVES, rendersTransform, withoutGsapTakeover } from "../editingGestureStart.js";
3
3
  import { isPlainRecord } from "../editingPort.js";
4
4
  import { isElementNode } from "../domRealm.js";
5
- import { MAX_SNAPSHOT_CHANNELS, MAX_SNAPSHOT_FIELDS, MAX_SNAPSHOT_TARGETS, MAX_SNAPSHOT_TEXT, MAX_SNAPSHOT_TWEENS, MAX_VARS_DEPTH, } from "./gsapSnapshotLimits.js";
5
+ import { MAX_SNAPSHOT_CHANNELS, MAX_SNAPSHOT_FIELDS, MAX_SNAPSHOT_TARGETS, MAX_SNAPSHOT_TEXT, MAX_SNAPSHOT_TWEENS, MAX_VARS_DEPTH, TARGET_FIELDS, TIMELINE_FIELDS, } from "./gsapSnapshotLimits.js";
6
6
  const VARS_SKIP = new Set([
7
7
  "ease",
8
8
  "easeEach",
@@ -42,6 +42,7 @@ export async function gsapSnapshot() {
42
42
  held.add(tween);
43
43
  if (timelines.length >= MAX_SNAPSHOT_TWEENS)
44
44
  throw new SnapshotBound("timelines");
45
+ reader.spend(TIMELINE_FIELDS);
45
46
  timelines.push({
46
47
  id: capped(id),
47
48
  time: typeof live.time === "function" ? finite(live.time()) : null,
@@ -69,6 +70,7 @@ class SnapshotReader {
69
70
  if (++this.tweens > MAX_SNAPSHOT_TWEENS)
70
71
  throw new SnapshotBound("tweens");
71
72
  const elements = (live.targets?.() ?? []).filter(isElementNode);
73
+ this.spend(elements.length);
72
74
  const vars = this.plain(live.vars, 0);
73
75
  const parsed = parsedChannels(live._pt);
74
76
  const parts = (live.timeline?.getChildren?.() ?? []).map((part) => this.tween(part));
@@ -83,8 +85,11 @@ class SnapshotReader {
83
85
  return [...this.channels].map(([element, channels]) => {
84
86
  if (channels.size > MAX_SNAPSHOT_CHANNELS)
85
87
  throw new SnapshotBound("channels");
88
+ this.spend(TARGET_FIELDS + channels.size);
86
89
  const values = {};
87
90
  const read = (channel) => {
91
+ if (isElementMethod(element, channel))
92
+ return;
88
93
  const value = Number(gsap?.getProperty?.(element, channel));
89
94
  if (Number.isFinite(value))
90
95
  values[channel] = value;
@@ -115,9 +120,12 @@ class SnapshotReader {
115
120
  for (const { p } of [...parsed, ...parts.flatMap((part) => part.parsed)])
116
121
  channels.add(p);
117
122
  }
123
+ spend(fields) {
124
+ if ((this.fields += fields) > MAX_SNAPSHOT_FIELDS)
125
+ throw new SnapshotBound("fields");
126
+ }
118
127
  plain(value, depth) {
119
- if (++this.fields > MAX_SNAPSHOT_FIELDS)
120
- throw new SnapshotBound("tween fields");
128
+ this.spend(1);
121
129
  if (Array.isArray(value))
122
130
  return this.list(value, depth);
123
131
  if (isLiteralRecord(value))
@@ -139,6 +147,7 @@ class SnapshotReader {
139
147
  return out;
140
148
  }
141
149
  }
150
+ const isElementMethod = (element, channel) => typeof Reflect.get(element, channel) === "function";
142
151
  function timing(live) {
143
152
  return {
144
153
  start: finite(live.startTime?.()),
@@ -1,6 +1,8 @@
1
- export declare const MAX_SNAPSHOT_TWEENS = 2048;
2
- export declare const MAX_SNAPSHOT_TARGETS = 512;
3
- export declare const MAX_SNAPSHOT_CHANNELS = 64;
4
1
  export declare const MAX_SNAPSHOT_FIELDS = 100000;
2
+ export declare const MAX_SNAPSHOT_TWEENS = 100000;
3
+ export declare const MAX_SNAPSHOT_TARGETS = 100000;
4
+ export declare const MAX_SNAPSHOT_CHANNELS = 64;
5
5
  export declare const MAX_SNAPSHOT_TEXT = 4096;
6
6
  export declare const MAX_VARS_DEPTH = 6;
7
+ export declare const TARGET_FIELDS = 3;
8
+ export declare const TIMELINE_FIELDS = 3;
@@ -1,6 +1,8 @@
1
- export const MAX_SNAPSHOT_TWEENS = 2_048;
2
- export const MAX_SNAPSHOT_TARGETS = 512;
3
- export const MAX_SNAPSHOT_CHANNELS = 64;
4
1
  export const MAX_SNAPSHOT_FIELDS = 100_000;
2
+ export const MAX_SNAPSHOT_TWEENS = MAX_SNAPSHOT_FIELDS;
3
+ export const MAX_SNAPSHOT_TARGETS = MAX_SNAPSHOT_FIELDS;
4
+ export const MAX_SNAPSHOT_CHANNELS = 64;
5
5
  export const MAX_SNAPSHOT_TEXT = 4_096;
6
6
  export const MAX_VARS_DEPTH = 6;
7
+ export const TARGET_FIELDS = 3;
8
+ export const TIMELINE_FIELDS = 3;
@@ -0,0 +1,14 @@
1
+ export type CaretSide = "before" | "after";
2
+ export type CaretBox = {
3
+ left: number;
4
+ top: number;
5
+ height: number;
6
+ };
7
+ /** The DOM has no side for a soft-wrap point (one line's end is the next one's start): the key that moved there says
8
+ * which, as CodeMirror and ProseMirror keep it. */
9
+ export declare const caretSideAfterKey: (key: string, side: CaretSide) => CaretSide;
10
+ export declare function caretBoxIn(element: HTMLElement, side: CaretSide): CaretBox | null;
11
+ export declare function caretColorOf(element: HTMLElement): string;
12
+ /** Puts the caret after the last character, with nothing selected: into the last text node rather than past the last
13
+ * child, since a caret at a node boundary types in the right place but stands somewhere else on screen. */
14
+ export declare function placeCaretAtEnd(element: HTMLElement): void;
@@ -0,0 +1,98 @@
1
+ const MODIFIERS = new Set(["Shift", "Control", "Alt", "Meta"]);
2
+ // Only End leaves Chrome's own caret at the earlier line's end; an arrow onto a wrap point lands on the next line.
3
+ const SIDE_OF_KEY = { End: "before" };
4
+ /** The DOM has no side for a soft-wrap point (one line's end is the next one's start): the key that moved there says
5
+ * which, as CodeMirror and ProseMirror keep it. */
6
+ export const caretSideAfterKey = (key, side) => MODIFIERS.has(key) ? side : (SIDE_OF_KEY[key] ?? "after");
7
+ export function caretBoxIn(element, side) {
8
+ const view = element.ownerDocument.defaultView;
9
+ const range = view ? caretRange(element, view) : null;
10
+ if (!view || !range)
11
+ return null;
12
+ return (side === "before" && endOfCharBefore(range)) || caretRect(range, element, view);
13
+ }
14
+ export function caretColorOf(element) {
15
+ const style = element.ownerDocument.defaultView?.getComputedStyle(element);
16
+ if (!style)
17
+ return "currentColor";
18
+ return style.caretColor && style.caretColor !== "auto" ? style.caretColor : style.color;
19
+ }
20
+ /** A caret between two nodes has no box, so it stands beside them; in an empty text, at its start, one line tall. */
21
+ function caretRect(range, element, view) {
22
+ const last = [...range.getClientRects()].reverse().find((rect) => rect.height > 0);
23
+ if (last)
24
+ return { left: last.left, top: last.top, height: last.height };
25
+ const beside = besideNode(range);
26
+ if (beside)
27
+ return beside;
28
+ const style = view.getComputedStyle(element);
29
+ const box = element.getBoundingClientRect();
30
+ const fontSize = Number.parseFloat(style.fontSize) || 16;
31
+ const line = Number.parseFloat(style.lineHeight) || fontSize * 1.2;
32
+ return {
33
+ left: box.left + (Number.parseFloat(style.paddingLeft) || 0),
34
+ top: box.top + (Number.parseFloat(style.paddingTop) || 0),
35
+ height: line,
36
+ };
37
+ }
38
+ function caretRange(element, view) {
39
+ const doc = element.ownerDocument;
40
+ const selection = view.getSelection();
41
+ if (!selection || selection.rangeCount === 0 || !selection.isCollapsed)
42
+ return null;
43
+ if (!doc.hasFocus() || !element.contains(doc.activeElement))
44
+ return null;
45
+ const range = selection.getRangeAt(0);
46
+ return element.contains(range.startContainer) ? range : null;
47
+ }
48
+ /** Where a caret that came from before a soft-wrap point stands: the right edge of the character before it. */
49
+ function endOfCharBefore({ startContainer: at, startOffset: offset }) {
50
+ if (at.nodeType !== Node.TEXT_NODE || offset === 0)
51
+ return null;
52
+ const char = at.ownerDocument.createRange();
53
+ // An emoji's second half alone has no box: take the whole pair.
54
+ const low = /[\uDC00-\uDFFF]/.test(at.data[offset - 1] ?? "");
55
+ char.setStart(at, offset - (low && offset > 1 ? 2 : 1));
56
+ char.setEnd(at, offset);
57
+ // A trailing space at a wrap has a box on each line; the earlier line's comes first.
58
+ const rect = [...char.getClientRects()].find((each) => each.height > 0);
59
+ return rect ? { left: rect.right, top: rect.top, height: rect.height } : null;
60
+ }
61
+ /** At an element boundary: the end of the node before, or the start of the node after (a line break's own line). */
62
+ function besideNode(range) {
63
+ const [before, after] = neighbours(range);
64
+ const node = before && before.nodeName !== "BR" ? before : (after ?? before);
65
+ if (!node)
66
+ return null;
67
+ const around = range.cloneRange();
68
+ around.selectNode(node);
69
+ const rects = [...around.getClientRects()].filter((rect) => rect.height > 0);
70
+ const end = node === before;
71
+ const rect = end ? rects.at(-1) : rects[0];
72
+ return rect ? { left: end ? rect.right : rect.left, top: rect.top, height: rect.height } : null;
73
+ }
74
+ function neighbours({ startContainer: at, startOffset: offset }) {
75
+ return at.nodeType === Node.TEXT_NODE
76
+ ? [at.previousSibling, at.nextSibling]
77
+ : [at.childNodes[offset - 1] ?? null, at.childNodes[offset] ?? null];
78
+ }
79
+ /** Puts the caret after the last character, with nothing selected: into the last text node rather than past the last
80
+ * child, since a caret at a node boundary types in the right place but stands somewhere else on screen. */
81
+ export function placeCaretAtEnd(element) {
82
+ const doc = element.ownerDocument;
83
+ const selection = doc.defaultView?.getSelection();
84
+ if (!selection)
85
+ return;
86
+ const range = doc.createRange();
87
+ const last = element.lastChild;
88
+ if (last && last.nodeType === Node.TEXT_NODE) {
89
+ range.setStart(last, last.textContent?.length ?? 0);
90
+ range.collapse(true);
91
+ }
92
+ else {
93
+ range.selectNodeContents(element);
94
+ range.collapse(false);
95
+ }
96
+ selection.removeAllRanges();
97
+ selection.addRange(range);
98
+ }
@@ -41,9 +41,17 @@ export type TextEditSelection = {
41
41
  colours: string[];
42
42
  painted: string | null;
43
43
  };
44
+ export type TextEditCaret = {
45
+ left: number;
46
+ top: number;
47
+ height: number;
48
+ color: string;
49
+ viewportWidth: number;
50
+ };
44
51
  export type TextEditSelectionEvent = {
45
52
  handle: EditingElementHandle;
46
53
  selection: TextEditSelection | null;
54
+ caret: TextEditCaret | null;
47
55
  };
48
56
  export declare function parseTextEdit(params: unknown): TextEditParams | null;
49
57
  export declare function textEditSelectionEvent(data: unknown, version: number): TextEditSelectionEvent | null;
@@ -6,6 +6,7 @@ import { isStylableElement } from "../domRealm.js";
6
6
  import { sanitizeRichTextChildren } from "../../utils/richTextSanitize.js";
7
7
  import { openTextEdits, isTextMarkup, MAX_EDIT_VALUE } from "./editElement.js";
8
8
  import { isEditableText } from "./textMarkup.js";
9
+ import { caretBoxIn, caretColorOf, caretSideAfterKey, placeCaretAtEnd, } from "./textCaret.js";
9
10
  import { applyInlineStyle, INLINE_STYLE_PROPERTIES, readFirstPaintedElement, readInlineStyle, readInlineStyleSpread, } from "../../utils/inlineTextStyleRead.js";
10
11
  const EDITING_OUTLINE = "2px solid #3CE6AC";
11
12
  const MAX_STYLE_VALUE = 256;
@@ -57,13 +58,24 @@ function isSelection(value) {
57
58
  isColours(colours) &&
58
59
  (painted === null || isShortText(painted)));
59
60
  }
61
+ function isCaret(value) {
62
+ if (!isRecord(value) || !keysAre(value, "color,height,left,top,viewportWidth"))
63
+ return false;
64
+ const { left, top, height, color, viewportWidth } = value;
65
+ return ([left, top, height, viewportWidth].every(isFiniteNumber) &&
66
+ height >= 0 &&
67
+ viewportWidth > 0 &&
68
+ isShortText(color));
69
+ }
60
70
  export function textEditSelectionEvent(data, version) {
61
- if (!isRecord(data) || !keysAre(data, "event,handle,selection,v"))
71
+ if (!isRecord(data) || !keysAre(data, "caret,event,handle,selection,v"))
62
72
  return null;
63
73
  if (data.v !== version || data.event !== "text-edit-selection" || !isHandle(data.handle))
64
74
  return null;
65
- const { handle, selection } = data;
66
- return selection === null || isSelection(selection) ? { handle, selection } : null;
75
+ const { handle, selection, caret } = data;
76
+ if (!(selection === null || isSelection(selection)))
77
+ return null;
78
+ return caret === null || isCaret(caret) ? { handle, selection, caret } : null;
67
79
  }
68
80
  const isValue = (value) => value === null || (typeof value === "string" && value.length <= MAX_EDIT_VALUE);
69
81
  const isTextMarkupOrNull = (value) => value === null || (typeof value === "string" && isTextMarkup(value));
@@ -140,6 +152,7 @@ function close(keep) {
140
152
  element.removeAttribute("contenteditable");
141
153
  element.style.outline = open.outline;
142
154
  element.style.outlineOffset = open.outlineOffset;
155
+ element.style.caretColor = open.caretColor;
143
156
  if (element.isConnected) {
144
157
  clearSelectionWithin(element);
145
158
  element.blur();
@@ -167,11 +180,9 @@ function placeCaret(element, at) {
167
180
  const selection = doc.defaultView?.getSelection();
168
181
  if (!selection)
169
182
  return;
170
- let range = at ? caretRangeAt(doc, at) : null;
171
- if (!range || !element.contains(range.startContainer)) {
172
- range = doc.createRange();
173
- range.selectNodeContents(element);
174
- }
183
+ const range = at ? caretRangeAt(doc, at) : null;
184
+ if (!range || !element.contains(range.startContainer))
185
+ return placeCaretAtEnd(element);
175
186
  range.collapse(false);
176
187
  selection.removeAllRanges();
177
188
  selection.addRange(range);
@@ -226,6 +237,42 @@ function listen(element, endInFrame, report) {
226
237
  removed.disconnect();
227
238
  };
228
239
  }
240
+ function followCaret(element, open) {
241
+ const view = element.ownerDocument.defaultView;
242
+ const onKey = ({ key }) => {
243
+ open.caret.side = caretSideAfterKey(key, open.caret.side);
244
+ };
245
+ const onPress = () => {
246
+ open.caret.side = "after";
247
+ };
248
+ const composing = (on) => () => {
249
+ open.caret.composing = on;
250
+ open.report();
251
+ };
252
+ const begin = composing(true);
253
+ const finish = composing(false);
254
+ element.addEventListener("keydown", onKey);
255
+ element.addEventListener("pointerdown", onPress);
256
+ element.addEventListener("input", open.report);
257
+ element.addEventListener("compositionstart", begin);
258
+ element.addEventListener("compositionend", finish);
259
+ view?.addEventListener("resize", open.report);
260
+ view?.addEventListener("scroll", open.report, true);
261
+ return () => {
262
+ element.removeEventListener("keydown", onKey);
263
+ element.removeEventListener("pointerdown", onPress);
264
+ element.removeEventListener("input", open.report);
265
+ element.removeEventListener("compositionstart", begin);
266
+ element.removeEventListener("compositionend", finish);
267
+ view?.removeEventListener("resize", open.report);
268
+ view?.removeEventListener("scroll", open.report, true);
269
+ };
270
+ }
271
+ function caretOf(open) {
272
+ const box = open.caret.composing ? null : caretBoxIn(open.element, open.caret.side);
273
+ const viewportWidth = open.element.ownerDocument.defaultView?.innerWidth || 1;
274
+ return box && { ...box, color: open.caret.color, viewportWidth };
275
+ }
229
276
  function start(handle, caret, port, version) {
230
277
  close(false);
231
278
  const element = elementForHandle(handle);
@@ -239,12 +286,15 @@ function start(handle, caret, port, version) {
239
286
  original: editable.innerHTML,
240
287
  outline: editable.style.outline,
241
288
  outlineOffset: editable.style.outlineOffset,
289
+ caretColor: editable.style.caretColor,
290
+ caret: { color: caretColorOf(editable), side: "after", composing: false },
242
291
  stop: () => { },
243
292
  report: () => {
244
293
  if (session !== open)
245
294
  return;
246
295
  const selection = selectionIn(editable);
247
- port.postMessage({ v: version, event: "text-edit-selection", handle, selection });
296
+ const caret = caretOf(open);
297
+ port.postMessage({ v: version, event: "text-edit-selection", handle, selection, caret });
248
298
  },
249
299
  };
250
300
  const endInFrame = () => {
@@ -254,12 +304,19 @@ function start(handle, caret, port, version) {
254
304
  if (ended)
255
305
  port.postMessage({ v: version, event: "text-edit-ended", handle, ...ended });
256
306
  };
257
- open.stop = listen(editable, endInFrame, open.report);
307
+ const stopListening = listen(editable, endInFrame, open.report);
308
+ const stopFollowing = followCaret(editable, open);
309
+ open.stop = () => {
310
+ stopListening();
311
+ stopFollowing();
312
+ };
258
313
  session = open;
259
314
  openTextEdits.add(editable);
260
315
  editable.style.outline = EDITING_OUTLINE;
261
316
  editable.style.outlineOffset = "2px";
262
317
  editable.setAttribute("contenteditable", "true");
318
+ // Studio draws the caret at screen size: the browser's own would shrink below a pixel in the scaled preview.
319
+ editable.style.caretColor = "transparent";
263
320
  editable.focus({ preventScroll: true });
264
321
  placeCaret(editable, caret);
265
322
  return { applied: true, html: null, previous: open.original };
@@ -38,7 +38,7 @@ export { buildStableSelector, escapeCssString, getPreferredClassSelector, isEdit
38
38
  export { elementCornerPoints, isElementVisibleThroughAncestors, readElementTransformSnapshot, rotationDegreesFromMatrix, snapCandidates, MAX_GEOMETRY_CHILDREN, MAX_SNAP_TARGETS, ROTATION_GATE_EPSILON_DEG, type EditingCorner, type EditingCorners, type EditingElementBox, type EditingElementGeometry, type ElementTransformSnapshot, } from "./editingGeometry.js";
39
39
  export type { EditingGestureBase, EditingGestureStart } from "./editingGestureStart.js";
40
40
  export { MAX_CAPTION_TRANSFORM } from "./editing/captionTransform.js";
41
- export { MAX_SNAPSHOT_CHANNELS, MAX_SNAPSHOT_FIELDS, MAX_SNAPSHOT_TARGETS, MAX_SNAPSHOT_TEXT, MAX_SNAPSHOT_TWEENS, MAX_VARS_DEPTH, } from "./editing/gsapSnapshotLimits.js";
41
+ export { MAX_SNAPSHOT_CHANNELS, MAX_SNAPSHOT_FIELDS, MAX_SNAPSHOT_TARGETS, MAX_SNAPSHOT_TEXT, MAX_SNAPSHOT_TWEENS, MAX_VARS_DEPTH, TARGET_FIELDS, TIMELINE_FIELDS, } from "./editing/gsapSnapshotLimits.js";
42
42
  export { compositionPoint, coversComposition, isDomLayerElement, isInspectableLayerElement, pointerTarget, pointerTargets, resolveAllVisualDomEditTargets, resolveLayerSelector, type EditingLocalPointer, type EditingViewport, } from "./editingTargets.js";
43
43
  export { elementZIndex, hasOnlyFormattingChildren, NON_PAINTING_TAGS, isCompositionHost, layerKindOf, type EditingLayer, type EditingStackingSibling, type LayerKind, } from "./editingLayers.js";
44
44
  export declare const EDITING_PROTOCOL_VERSION: 1;
@@ -518,5 +518,6 @@ export declare function createEditingPortClient(options: {
518
518
  host?: Window;
519
519
  }): EditingPortClient;
520
520
  export { elementHome, transformWDivisor, type MotionPathHome } from "./editing/motionPathHome.js";
521
- export { caretRangeAt, takePlainTextOnly, textEditResult, type TextEditEndedEvent, type TextEditResult, type TextEditSelection, type TextEditSelectionEvent, } from "./editing/textEdit.js";
521
+ export { caretRangeAt, takePlainTextOnly, textEditResult, type TextEditEndedEvent, type TextEditCaret, type TextEditResult, type TextEditSelection, type TextEditSelectionEvent, } from "./editing/textEdit.js";
522
+ export { caretBoxIn, caretColorOf, caretSideAfterKey, placeCaretAtEnd, type CaretBox, type CaretSide, } from "./editing/textCaret.js";
522
523
  export { parsePausedFrameAsk, PAUSED_FRAME_BYTES, PAUSED_FRAME_PARAMS, PAUSED_FRAME_SOURCES, type PausedFrameAsk, type PausedFrameAskMessage, type PausedFrameImage, type PausedFrameReply, } from "./editing/pausedFrames.js";
@@ -21,7 +21,7 @@ import { parseTextEdit, textEditEndedEvent, textEditSelectionEvent, } from "./ed
21
21
  export { buildStableSelector, escapeCssString, getPreferredClassSelector, isEditableTextLeaf, readElementSource, readTextLayer, EDITING_ELEMENT_HANDLE, MAX_DESCRIBE_HANDLES, MAX_ELEMENT_ENTRIES, MAX_ELEMENT_TEXT, MAX_ELEMENT_VALUE, MAX_TIMELINE_TEXT, MAX_POINT_STACK, MAX_QUERY_MATCHES, MAX_SOURCE_GROUPS, isStableSelector, } from "./editingElement.js";
22
22
  export { elementCornerPoints, isElementVisibleThroughAncestors, readElementTransformSnapshot, rotationDegreesFromMatrix, snapCandidates, MAX_GEOMETRY_CHILDREN, MAX_SNAP_TARGETS, ROTATION_GATE_EPSILON_DEG, } from "./editingGeometry.js";
23
23
  export { MAX_CAPTION_TRANSFORM } from "./editing/captionTransform.js";
24
- export { MAX_SNAPSHOT_CHANNELS, MAX_SNAPSHOT_FIELDS, MAX_SNAPSHOT_TARGETS, MAX_SNAPSHOT_TEXT, MAX_SNAPSHOT_TWEENS, MAX_VARS_DEPTH, } from "./editing/gsapSnapshotLimits.js";
24
+ export { MAX_SNAPSHOT_CHANNELS, MAX_SNAPSHOT_FIELDS, MAX_SNAPSHOT_TARGETS, MAX_SNAPSHOT_TEXT, MAX_SNAPSHOT_TWEENS, MAX_VARS_DEPTH, TARGET_FIELDS, TIMELINE_FIELDS, } from "./editing/gsapSnapshotLimits.js";
25
25
  export { compositionPoint, coversComposition, isDomLayerElement, isInspectableLayerElement, pointerTarget, pointerTargets, resolveAllVisualDomEditTargets, resolveLayerSelector, } from "./editingTargets.js";
26
26
  export { elementZIndex, hasOnlyFormattingChildren, NON_PAINTING_TAGS, isCompositionHost, layerKindOf, } from "./editingLayers.js";
27
27
  export const EDITING_PROTOCOL_VERSION = 1;
@@ -545,4 +545,5 @@ export function createEditingPortClient(options) {
545
545
  }
546
546
  export { elementHome, transformWDivisor } from "./editing/motionPathHome.js";
547
547
  export { caretRangeAt, takePlainTextOnly, textEditResult, } from "./editing/textEdit.js";
548
+ export { caretBoxIn, caretColorOf, caretSideAfterKey, placeCaretAtEnd, } from "./editing/textCaret.js";
548
549
  export { parsePausedFrameAsk, PAUSED_FRAME_BYTES, PAUSED_FRAME_PARAMS, PAUSED_FRAME_SOURCES, } from "./editing/pausedFrames.js";
@@ -39,6 +39,8 @@ export type ScheduledSource = ScheduledSourceBase & ({
39
39
  export declare class WebAudioTransport {
40
40
  /** Request options for every decode fetch, over `cache: "no-store"`. */
41
41
  private readonly _fetchInit;
42
+ /** Aborted by `destroy()`, so a fetch or decode still in flight reports and keeps nothing for a gone player. */
43
+ private _fetches;
42
44
  private readonly _busDocument;
43
45
  private _givenContext;
44
46
  private _ctx;
@@ -160,6 +160,8 @@ const BYTES_PER_SAMPLE = 4;
160
160
  export class WebAudioTransport {
161
161
  /** Request options for every decode fetch, over `cache: "no-store"`. */
162
162
  _fetchInit;
163
+ /** Aborted by `destroy()`, so a fetch or decode still in flight reports and keeps nothing for a gone player. */
164
+ _fetches = new AbortController();
163
165
  _busDocument;
164
166
  _givenContext;
165
167
  _ctx = null;
@@ -337,12 +339,16 @@ export class WebAudioTransport {
337
339
  // asset that simply has not been uploaded yet) is TRANSIENT — return null
338
340
  // WITHOUT blacklisting, so the next play/seek generation retries once the
339
341
  // asset becomes available.
340
- async fetchBytes(src, el) {
342
+ async fetchBytes(src, el, signal) {
343
+ if (signal.aborted)
344
+ return null;
341
345
  try {
342
346
  // `no-store`: a retry must actually re-request the asset — not replay a
343
347
  // cached 404/stale response from the failed attempt that we chose not to
344
348
  // blacklist.
345
- const response = await fetch(src, { cache: "no-store", ...this._fetchInit });
349
+ const response = await fetch(src, { cache: "no-store", ...this._fetchInit, signal });
350
+ if (signal.aborted)
351
+ return null;
346
352
  if (!response.ok) {
347
353
  swallow("webAudioTransport.fetch", new Error(`${response.status} ${src}`));
348
354
  reportMediaLoadFailure(el, "fetch", response.status);
@@ -352,19 +358,21 @@ export class WebAudioTransport {
352
358
  }
353
359
  catch (err) {
354
360
  swallow("webAudioTransport.fetch", err);
355
- reportMediaLoadFailure(el, "fetch", null);
361
+ if (!signal.aborted)
362
+ reportMediaLoadFailure(el, "fetch", null);
356
363
  return null;
357
364
  }
358
365
  }
359
366
  async fetchAndDecode(src, el) {
360
367
  if (this._bufferCache.has(src))
361
368
  return this._bufferCache.get(src);
369
+ const { signal } = this._fetches;
362
370
  if (!this._ctx)
363
371
  return null;
364
372
  const length = await this.mayDecode(src, el);
365
373
  if (!length)
366
374
  return null;
367
- const arrayBuffer = await this.fetchBytes(src, el);
375
+ const arrayBuffer = await this.fetchBytes(src, el, signal);
368
376
  if (!arrayBuffer)
369
377
  return null;
370
378
  // A source whose length can't be read and whose bytes could pass the budget plays through its element.
@@ -372,16 +380,18 @@ export class WebAudioTransport {
372
380
  this._failedSrcs.add(src);
373
381
  return null;
374
382
  }
375
- return this.decode(src, el, arrayBuffer);
383
+ return this.decode(src, el, arrayBuffer, signal);
376
384
  }
377
385
  // A decode failure means the bytes themselves are unusable (corrupt or an
378
386
  // unsupported codec) — that IS permanent, so blacklist to avoid re-decoding
379
387
  // the same bad payload on every generation.
380
- async decode(src, el, arrayBuffer) {
388
+ async decode(src, el, arrayBuffer, signal) {
381
389
  if (!this._ctx)
382
390
  return null;
383
391
  try {
384
392
  const audioBuffer = await this._ctx.decodeAudioData(arrayBuffer);
393
+ if (signal.aborted)
394
+ return null;
385
395
  // A file whose container timescale disagrees with its stream decodes short; its element plays it whole.
386
396
  if (Number.isFinite(el.duration) &&
387
397
  el.duration - audioBuffer.duration > SHORT_DECODE_SECONDS) {
@@ -392,8 +402,10 @@ export class WebAudioTransport {
392
402
  return audioBuffer;
393
403
  }
394
404
  catch (err) {
395
- this._failedSrcs.add(src);
396
405
  swallow("webAudioTransport.decode", err);
406
+ if (signal.aborted)
407
+ return null;
408
+ this._failedSrcs.add(src);
397
409
  reportMediaLoadFailure(el, "decode", null, arrayBuffer.byteLength);
398
410
  return null;
399
411
  }
@@ -1129,6 +1141,8 @@ export class WebAudioTransport {
1129
1141
  return !this._paused && this._activeSources.some((source) => source.el === el);
1130
1142
  }
1131
1143
  destroy() {
1144
+ this._fetches.abort();
1145
+ this._fetches = new AbortController();
1132
1146
  this.stopAll();
1133
1147
  this.stopMetering();
1134
1148
  for (const group of this._groups.values())
package/dist/safePath.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { resolve, sep, join, dirname, basename, relative, isAbsolute, parse } from "node:path";
2
2
  import { lstatSync, mkdirSync, readdirSync, readFileSync, realpath as realpathWalk, realpathSync, statSync, } from "node:fs";
3
- import { mkdir, realpath as realpathNative } from "node:fs/promises";
3
+ import { mkdir, realpath as realpathNative, stat as statAsync } from "node:fs/promises";
4
4
  import { promisify } from "node:util";
5
5
  import { isWithinProjectRoot } from "@hyperframes/parsers/asset-resolution";
6
6
  import { projectPathSegments } from "@hyperframes/parsers/private-path";
@@ -260,6 +260,15 @@ export function folderGone(dir) {
260
260
  return false;
261
261
  }
262
262
  }
263
+ async function folderGoneAsync(dir) {
264
+ try {
265
+ await statAsync(dir);
266
+ return false;
267
+ }
268
+ catch (error) {
269
+ return isMissing(error);
270
+ }
271
+ }
263
272
  /** The project folder's real path; ProjectRootMissingError when it is gone. */
264
273
  export function realProjectRoot(root) {
265
274
  try {
@@ -276,7 +285,7 @@ export function realProjectRoot(root) {
276
285
  * A `dir` outside `root` is created recursively, but only while `root` exists.
277
286
  */
278
287
  export function mkdirWithinProject(root, dir) {
279
- const folders = foldersToMake(root, dir);
288
+ const folders = foldersToMake(root, dir, folderGone(root));
280
289
  if (folders === null) {
281
290
  mkdirSync(dir, { recursive: true });
282
291
  return;
@@ -286,13 +295,13 @@ export function mkdirWithinProject(root, dir) {
286
295
  mkdirSync(path);
287
296
  }
288
297
  catch (error) {
289
- madeOrThrow(root, error);
298
+ madeOrThrow(root, error, isMissing(error) && folderGone(root));
290
299
  }
291
300
  }
292
301
  }
293
302
  /** {@link mkdirWithinProject} on fs/promises: a write the drive never answers holds a pool thread, not the caller's. */
294
303
  export async function mkdirWithinProjectAsync(root, dir) {
295
- const folders = foldersToMake(root, dir);
304
+ const folders = foldersToMake(root, dir, await folderGoneAsync(root));
296
305
  if (folders === null) {
297
306
  await mkdir(dir, { recursive: true });
298
307
  return;
@@ -302,13 +311,13 @@ export async function mkdirWithinProjectAsync(root, dir) {
302
311
  await mkdir(path);
303
312
  }
304
313
  catch (error) {
305
- madeOrThrow(root, error);
314
+ madeOrThrow(root, error, isMissing(error) && (await folderGoneAsync(root)));
306
315
  }
307
316
  }
308
317
  }
309
318
  /** Each folder from below `root` down to `dir`, or null when `dir` is outside `root`. */
310
- function foldersToMake(root, dir) {
311
- if (folderGone(root))
319
+ function foldersToMake(root, dir, rootGone) {
320
+ if (rootGone)
312
321
  throw new ProjectRootMissingError(root);
313
322
  const inside = relative(resolve(root), resolve(dir));
314
323
  if (inside === ".." || inside.startsWith(`..${sep}`) || isAbsolute(inside))
@@ -319,13 +328,13 @@ function foldersToMake(root, dir) {
319
328
  .filter(Boolean)
320
329
  .map((part) => (path = join(path, part)));
321
330
  }
322
- function madeOrThrow(root, error) {
323
- const code = error.code;
324
- if (code === "ENOENT" && folderGone(root))
331
+ function madeOrThrow(root, error, rootGone) {
332
+ if (rootGone)
325
333
  throw new ProjectRootMissingError(root);
326
- if (code !== "EEXIST")
334
+ if (error.code !== "EEXIST")
327
335
  throw error;
328
336
  }
337
+ const isMissing = (error) => error.code === "ENOENT";
329
338
  /** The real path; for a path not there (yet, or any more), the nearest existing folder's real path plus the rest. */
330
339
  export function realFilePath(filePath) {
331
340
  try {
@@ -1,3 +1,4 @@
1
1
  export declare function terminalText(text: string): string;
2
+ export declare function quotedFilePath(path: string): string;
2
3
  export declare function terminalLines(text: string): string;
3
4
  export declare function terminalTextDeep<T>(value: T): T;
@@ -13,6 +13,23 @@ export function terminalText(text) {
13
13
  }
14
14
  return shown;
15
15
  }
16
+ export function quotedFilePath(path) {
17
+ let result = "";
18
+ for (const ch of JSON.stringify(path)) {
19
+ const code = ch.charCodeAt(0);
20
+ const escape = isControlCode(code) ||
21
+ reordersOrBreaksTextOnScreen(code) ||
22
+ /\p{Default_Ignorable_Code_Point}/u.test(ch) ||
23
+ ch.normalize("NFKC") !== ch;
24
+ if (escape) {
25
+ for (let index = 0; index < ch.length; index++)
26
+ result += `\\u${ch.charCodeAt(index).toString(16).padStart(4, "0")}`;
27
+ }
28
+ else
29
+ result += ch;
30
+ }
31
+ return result;
32
+ }
16
33
  export function terminalLines(text) {
17
34
  return text.split("\n").map(terminalText).join("\n");
18
35
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperframes/core",
3
- "version": "0.9.96",
3
+ "version": "0.9.97",
4
4
  "description": "",
5
5
  "repository": {
6
6
  "type": "git",
@@ -525,9 +525,9 @@
525
525
  "linkedom": "^0.18.12",
526
526
  "postcss": "^8.5.8",
527
527
  "wawoff2": "^2.0.1",
528
- "@hyperframes/lint": "0.9.96",
529
- "@hyperframes/parsers": "0.9.96",
530
- "@hyperframes/studio-server": "0.9.96"
528
+ "@hyperframes/lint": "0.9.97",
529
+ "@hyperframes/parsers": "0.9.97",
530
+ "@hyperframes/studio-server": "0.9.97"
531
531
  },
532
532
  "devDependencies": {
533
533
  "@fontsource/archivo-black": "^5.2.8",