@hyperframes/core 0.9.65 → 0.9.66

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,18 @@
1
+ import { type EditingElementHandle } from "../editingElement.js";
2
+ export type ElementEditEntry = [name: string, value: string | null];
3
+ export type StyleEditEntry = [name: string, value: string | null, priority?: "important"];
4
+ export type EditElementParams = {
5
+ handle: EditingElementHandle;
6
+ styles: StyleEditEntry[];
7
+ attributes: ElementEditEntry[];
8
+ };
9
+ export type EditElementResult = {
10
+ applied: boolean;
11
+ styles: StyleEditEntry[];
12
+ attributes: ElementEditEntry[];
13
+ };
14
+ export declare const MAX_EDIT_ENTRIES = 64;
15
+ export declare const MAX_EDIT_VALUE = 200000;
16
+ export declare function parseEditElement(params: unknown): EditElementParams | null;
17
+ /** Draws nothing it could not put back: a `src` off media, or a value too long to send back. */
18
+ export declare function editElement({ handle, styles, attributes }: EditElementParams): EditElementResult;
@@ -0,0 +1,72 @@
1
+ // `edit-element`: a property panel edit drawn live on one element: inline styles and attributes,
2
+ // null removing one. The reply carries what each name held before, so a failed save can put it back.
3
+ import { EDITING_ELEMENT_HANDLE } from "../editingElement.js";
4
+ import { elementForHandle } from "../editingHandles.js";
5
+ import { isStylableElement } from "../domRealm.js";
6
+ export const MAX_EDIT_ENTRIES = 64;
7
+ export const MAX_EDIT_VALUE = 200_000;
8
+ const STYLE_NAME = /^(?:-?[a-z][a-z0-9-]*|--[\w\u0080-￿-]+)$/;
9
+ const DATA_ATTRIBUTE = /^data-[a-z0-9_-]+$/;
10
+ const PANEL_ATTRIBUTES = new Set(["loop", "muted", "alt", "title", "src"]);
11
+ const MEDIA_TAGS = new Set(["img", "video", "audio"]);
12
+ const isAttributeName = (name) => DATA_ATTRIBUTE.test(name) || PANEL_ATTRIBUTES.has(name);
13
+ const isValue = (value) => value === null || (typeof value === "string" && value.length <= MAX_EDIT_VALUE);
14
+ function entries(value, valid) {
15
+ if (!Array.isArray(value) || value.length > MAX_EDIT_ENTRIES)
16
+ return null;
17
+ const ok = value.every((entry) => Array.isArray(entry) && valid(entry));
18
+ return ok ? value : null;
19
+ }
20
+ const styleEntry = ([name, value, priority, ...rest]) => typeof name === "string" &&
21
+ STYLE_NAME.test(name) &&
22
+ isValue(value) &&
23
+ (priority === undefined || priority === "important") &&
24
+ rest.length === 0;
25
+ const attributeEntry = ([name, value, ...rest]) => typeof name === "string" && isAttributeName(name) && isValue(value) && rest.length === 0;
26
+ export function parseEditElement(params) {
27
+ if (Object.prototype.toString.call(params) !== "[object Object]")
28
+ return null;
29
+ const record = params;
30
+ if (Object.keys(record).sort().join() !== "attributes,handle,styles")
31
+ return null;
32
+ const { handle } = record;
33
+ if (typeof handle !== "string" || !EDITING_ELEMENT_HANDLE.test(handle))
34
+ return null;
35
+ const styles = entries(record.styles, styleEntry);
36
+ const attributes = entries(record.attributes, attributeEntry);
37
+ return styles && attributes ? { handle, styles, attributes } : null;
38
+ }
39
+ const NOT_APPLIED = { applied: false, styles: [], attributes: [] };
40
+ /** Draws nothing it could not put back: a `src` off media, or a value too long to send back. */
41
+ export function editElement({ handle, styles, attributes }) {
42
+ const element = elementForHandle(handle);
43
+ if (!isStylableElement(element))
44
+ return NOT_APPLIED;
45
+ const style = element.style;
46
+ const media = MEDIA_TAGS.has(element.localName);
47
+ if (attributes.some(([name]) => name === "src") && !media)
48
+ return NOT_APPLIED;
49
+ const before = {
50
+ applied: true,
51
+ styles: styles.map(([name]) => {
52
+ const value = style.getPropertyValue(name) || null;
53
+ return style.getPropertyPriority(name) ? [name, value, "important"] : [name, value];
54
+ }),
55
+ attributes: attributes.map(([name]) => [name, element.getAttribute(name)]),
56
+ };
57
+ if (![...before.styles, ...before.attributes].every(([, value]) => isValue(value)))
58
+ return NOT_APPLIED;
59
+ for (const [name, value, priority] of styles) {
60
+ if (value === null)
61
+ style.removeProperty(name);
62
+ else
63
+ style.setProperty(name, value, priority ?? "");
64
+ }
65
+ for (const [name, value] of attributes) {
66
+ if (value === null)
67
+ element.removeAttribute(name);
68
+ else
69
+ element.setAttribute(name, value);
70
+ }
71
+ return before;
72
+ }
@@ -44,6 +44,14 @@ export const trackedHandleCount = () => elements.size;
44
44
  const sameSource = (a, b) => a.file === b.file &&
45
45
  a.compositionId === b.compositionId &&
46
46
  a.originalCompositionId === b.originalCompositionId;
47
+ /** The element's source when every field fits the port; null otherwise, since a cut path or id names another file. */
48
+ function boundedSource(element) {
49
+ const source = readElementSource(element);
50
+ const fields = [source.file, source.compositionId, source.originalCompositionId];
51
+ return fields.every((field) => field === null || field.length <= MAX_ELEMENT_VALUE)
52
+ ? source
53
+ : null;
54
+ }
47
55
  function matchesBefore(element, selector) {
48
56
  if (!selector?.startsWith("."))
49
57
  return null;
@@ -58,7 +66,9 @@ function matchesBefore(element, selector) {
58
66
  for (const match of matches) {
59
67
  if (match === element)
60
68
  return groups;
61
- const source = readElementSource(match);
69
+ const source = boundedSource(match);
70
+ if (!source)
71
+ return null;
62
72
  const group = groups.find((entry) => sameSource(entry.source, source));
63
73
  if (group)
64
74
  group.count += 1;
@@ -87,13 +97,18 @@ function inlineStyles(element, state) {
87
97
  state.truncated = true;
88
98
  for (let index = 0; index < Math.min(declared.length, MAX_ELEMENT_ENTRIES); index += 1) {
89
99
  const name = declared.item(index);
100
+ if (name.length > MAX_ELEMENT_VALUE) {
101
+ state.truncated = true;
102
+ continue;
103
+ }
90
104
  styles[name] = cut(declared.getPropertyValue(name), MAX_ELEMENT_VALUE, state, true);
91
105
  }
92
106
  return styles;
93
107
  }
94
108
  function attributes(element, state) {
95
- const kept = Array.from(element.attributes).filter((attribute) => attribute.name !== "style");
96
- if (kept.length > MAX_ELEMENT_ENTRIES)
109
+ const named = Array.from(element.attributes).filter((attribute) => attribute.name !== "style");
110
+ const kept = named.filter((attribute) => attribute.name.length <= MAX_ELEMENT_VALUE);
111
+ if (kept.length < named.length || kept.length > MAX_ELEMENT_ENTRIES)
97
112
  state.truncated = true;
98
113
  return kept
99
114
  .slice(0, MAX_ELEMENT_ENTRIES)
@@ -118,21 +133,25 @@ export function elementHit(element) {
118
133
  const rect = element.getBoundingClientRect();
119
134
  return {
120
135
  handle: handleFor(element),
121
- tag: element.tagName.toLowerCase(),
136
+ tag: element.tagName.toLowerCase().slice(0, MAX_ELEMENT_VALUE),
122
137
  rect: { x: rect.x, y: rect.y, width: rect.width, height: rect.height },
123
138
  };
124
139
  }
140
+ const whole = (value) => value && value.length <= MAX_ELEMENT_VALUE ? value : undefined;
125
141
  function describeElement(element) {
126
- const selector = buildStableSelector(element);
142
+ const source = boundedSource(element);
143
+ if (!source)
144
+ return null;
145
+ const selector = whole(buildStableSelector(element));
127
146
  const state = { truncated: false };
128
147
  return {
129
148
  ...elementHit(element),
130
- label: buildElementLabel(element),
149
+ label: buildElementLabel(element).slice(0, MAX_ELEMENT_VALUE),
131
150
  parent: element.parentElement ? handleFor(element.parentElement) : null,
132
- id: element.id || null,
151
+ id: whole(element.id) ?? null,
133
152
  selector: selector ?? null,
134
153
  matchesBefore: matchesBefore(element, selector),
135
- source: readElementSource(element),
154
+ source,
136
155
  locked: element.closest("[data-timeline-locked]") !== null,
137
156
  attributes: attributes(element, state),
138
157
  inlineStyles: inlineStyles(element, state),
@@ -165,10 +184,15 @@ export function ancestorHandles(requested) {
165
184
  }
166
185
  export function queryElements(selector) {
167
186
  const matches = [];
187
+ let truncated = false;
168
188
  for (const element of document.querySelectorAll(selector)) {
169
189
  if (matches.length === MAX_QUERY_MATCHES)
170
190
  return { matches, truncated: true };
171
- matches.push({ handle: handleFor(element), source: readElementSource(element) });
191
+ const source = boundedSource(element);
192
+ if (source)
193
+ matches.push({ handle: handleFor(element), source });
194
+ else
195
+ truncated = true;
172
196
  }
173
- return { matches, truncated: false };
197
+ return { matches, truncated };
174
198
  }
@@ -26,6 +26,7 @@ import { type ColorGradingPlaybackRequest } from "./editing/color-grading-playba
26
26
  import { type AssignAudioGroupParams } from "./editing/assignAudioGroup.js";
27
27
  import { type AudioMeterLevels } from "./editing/audioMeter.js";
28
28
  import { type SetAudioGroupAttributeParams } from "./editing/setAudioGroupAttribute.js";
29
+ import { type EditElementParams, type EditElementResult } from "./editing/editElement.js";
29
30
  export { buildStableSelector, escapeCssString, getPreferredClassSelector, readElementSource, EDITING_ELEMENT_HANDLE, MAX_DESCRIBE_HANDLES, MAX_ELEMENT_ENTRIES, MAX_ELEMENT_TEXT, MAX_ELEMENT_VALUE, MAX_POINT_STACK, MAX_QUERY_MATCHES, MAX_SOURCE_GROUPS, type EditingElementDescription, type EditingElementHandle, type EditingElementHit, type EditingElementMatch, type EditingElementSource, type EditingRect, } from "./editingElement.js";
30
31
  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";
31
32
  export type { EditingGestureStart } from "./editingGestureStart.js";
@@ -39,7 +40,7 @@ export declare const EDITING_PROTOCOL_VERSION: 1;
39
40
  export declare const EDITING_CONNECT = "editing-connect";
40
41
  /** Frame to parent, on the window: carries the port in its transfer list. */
41
42
  export declare const EDITING_PORT = "editing-port";
42
- export declare const EDITING_REQUEST_KINDS: readonly ["hello", "runtime-snapshot", "wait-for-seek", "set-loop-start", "computed-styles", "elements-at-point", "pointer-targets", "describe", "ancestors", "query", "geometry", "layers", "draft", "gesture-start", "console-errors", "watch-keys", "restore-attributes", "caption-words", "caption-transform", "color-grading-status", "color-grading-previews", "color-grading-playback", "watch-geometry", "audio-meter", "document-markup", "set-audio-group-attribute", "assign-audio-group", "gsap-snapshot", "motion-path-home"];
43
+ export declare const EDITING_REQUEST_KINDS: readonly ["hello", "runtime-snapshot", "wait-for-seek", "set-loop-start", "computed-styles", "elements-at-point", "pointer-targets", "describe", "ancestors", "query", "geometry", "layers", "draft", "gesture-start", "console-errors", "watch-keys", "restore-attributes", "caption-words", "caption-transform", "color-grading-status", "color-grading-previews", "color-grading-playback", "watch-geometry", "audio-meter", "document-markup", "set-audio-group-attribute", "assign-audio-group", "gsap-snapshot", "motion-path-home", "max-z-index", "crop-lift", "edit-element"];
43
44
  export type EditingRequestKind = (typeof EDITING_REQUEST_KINDS)[number];
44
45
  export interface EditingRuntimeSnapshot {
45
46
  /** The runtime has installed its player API. */
@@ -302,6 +303,26 @@ export interface EditingRequests {
302
303
  };
303
304
  result: MotionPathFrameHome;
304
305
  };
306
+ "max-z-index": {
307
+ params: NoParams;
308
+ result: {
309
+ zIndex: number;
310
+ };
311
+ };
312
+ "crop-lift": {
313
+ params: {
314
+ handle: EditingElementHandle;
315
+ lift: boolean;
316
+ };
317
+ result: {
318
+ lifted: boolean;
319
+ clipPath: string | null;
320
+ };
321
+ };
322
+ "edit-element": {
323
+ params: EditElementParams;
324
+ result: EditElementResult;
325
+ };
305
326
  }
306
327
  export type EditingParams<K extends EditingRequestKind> = EditingRequests[K]["params"];
307
328
  export type EditingResult<K extends EditingRequestKind> = EditingRequests[K]["result"];
@@ -22,6 +22,7 @@ import { parseColorGradingPlaybackParams, } from "./editing/color-grading-playba
22
22
  import { parseAssignAudioGroup } from "./editing/assignAudioGroup.js";
23
23
  import { parseAudioMeter } from "./editing/audioMeter.js";
24
24
  import { parseSetAudioGroupAttribute, } from "./editing/setAudioGroupAttribute.js";
25
+ import { parseEditElement, } from "./editing/editElement.js";
25
26
  export { buildStableSelector, escapeCssString, getPreferredClassSelector, readElementSource, EDITING_ELEMENT_HANDLE, MAX_DESCRIBE_HANDLES, MAX_ELEMENT_ENTRIES, MAX_ELEMENT_TEXT, MAX_ELEMENT_VALUE, MAX_POINT_STACK, MAX_QUERY_MATCHES, MAX_SOURCE_GROUPS, } from "./editingElement.js";
26
27
  export { elementCornerPoints, isElementVisibleThroughAncestors, readElementTransformSnapshot, rotationDegreesFromMatrix, snapCandidates, MAX_GEOMETRY_CHILDREN, MAX_SNAP_TARGETS, ROTATION_GATE_EPSILON_DEG, } from "./editingGeometry.js";
27
28
  export { MAX_CAPTION_TRANSFORM } from "./editing/captionTransform.js";
@@ -64,6 +65,9 @@ export const EDITING_REQUEST_KINDS = [
64
65
  "assign-audio-group",
65
66
  "gsap-snapshot",
66
67
  "motion-path-home",
68
+ "max-z-index",
69
+ "crop-lift",
70
+ "edit-element",
67
71
  ];
68
72
  export const MAX_DRAFT_PX = 100_000;
69
73
  export const MAX_WATCHED_KEYS = 32;
@@ -231,6 +235,11 @@ const PARAM_PARSERS = {
231
235
  "motion-path-home": (params) => hasKeys(params, "selector") && isSelector(params.selector)
232
236
  ? { selector: params.selector }
233
237
  : null,
238
+ "max-z-index": noParams,
239
+ "crop-lift": (params) => hasKeys(params, "handle,lift") && isHandle(params.handle) && typeof params.lift === "boolean"
240
+ ? { handle: params.handle, lift: params.lift }
241
+ : null,
242
+ "edit-element": parseEditElement,
234
243
  };
235
244
  /** Validates one request off the wire. Never throws: anything unusable becomes a typed error. */
236
245
  export function parseEditingRequest(data) {
@@ -284,6 +293,7 @@ function readHandoff(event, frame) {
284
293
  : null;
285
294
  }
286
295
  const onlyPort = (ports) => ports.length === 1 ? (ports[0] ?? null) : null;
296
+ const portsTaken = new WeakSet();
287
297
  /**
288
298
  * The parent's end of the editing channel for one preview frame load. Asks for
289
299
  * the port at once and again on the runtime's `ready`, and takes the first port
@@ -344,8 +354,9 @@ export function createEditingPortClient(options) {
344
354
  const handoff = readHandoff(event, iframe.contentWindow);
345
355
  if (handoff === "ready")
346
356
  return connect();
347
- if (!handoff)
357
+ if (!handoff || portsTaken.has(handoff))
348
358
  return;
359
+ portsTaken.add(handoff);
349
360
  port = handoff;
350
361
  host.removeEventListener("message", onWindowMessage);
351
362
  port.onmessage = onReply;
package/dist/safePath.js CHANGED
@@ -157,7 +157,9 @@ const TOOL_CONFIG_FAMILIES = [
157
157
  /^mise(?:\.[^.]+)*\.toml$/,
158
158
  /^simple-git-hooks\.(?:json|[cm]?js)$/,
159
159
  /^[jt]sconfig\..+\.json$/,
160
+ /\.gypi?$/,
160
161
  ];
162
+ const RUN_BY_PACKAGE_MANAGER_DEFAULT = new Set(["server.js"]);
161
163
  // Tools load these on their own: vite.config.ts, jest.config.json, docker-compose.yml, gulpfile.js and the like.
162
164
  const TOOL_CONFIG = /\.config\.(?:[cm]?[jt]sx?|json[c5]?|ya?ml|toml)$|^(?:gulp|grunt)file\.[cm]?[jt]s$/;
163
165
  // Coding agents load these on their own, wherever they sit.
@@ -207,7 +209,7 @@ export function toolTrustedFileKind(relPath) {
207
209
  return "tool-config";
208
210
  if (AGENT_INSTRUCTIONS.test(name))
209
211
  return "agent-instructions";
210
- if (PROGRAM.test(name))
212
+ if (PROGRAM.test(name) || RUN_BY_PACKAGE_MANAGER_DEFAULT.has(name))
211
213
  return "program";
212
214
  return null;
213
215
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperframes/core",
3
- "version": "0.9.65",
3
+ "version": "0.9.66",
4
4
  "description": "",
5
5
  "repository": {
6
6
  "type": "git",
@@ -465,9 +465,9 @@
465
465
  "linkedom": "^0.18.12",
466
466
  "postcss": "^8.5.8",
467
467
  "wawoff2": "^2.0.1",
468
- "@hyperframes/lint": "0.9.65",
469
- "@hyperframes/studio-server": "0.9.65",
470
- "@hyperframes/parsers": "0.9.65"
468
+ "@hyperframes/parsers": "0.9.66",
469
+ "@hyperframes/studio-server": "0.9.66",
470
+ "@hyperframes/lint": "0.9.66"
471
471
  },
472
472
  "devDependencies": {
473
473
  "@fontsource/archivo-black": "^5.2.8",