@hyperframes/core 0.9.41 → 0.9.43

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.
@@ -12,8 +12,9 @@
12
12
  import { EDITING_ELEMENT_HANDLE, MAX_DESCRIBE_HANDLES, } from "./editingElement.js";
13
13
  import { wallClearTimeout, wallSetTimeout } from "./wallClock.js";
14
14
  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";
15
- export { elementCornerPoints, isElementVisibleThroughAncestors, readElementTransformSnapshot, rotationDegreesFromMatrix, MAX_GEOMETRY_CHILDREN, ROTATION_GATE_EPSILON_DEG, } from "./editingGeometry.js";
15
+ export { elementCornerPoints, isElementVisibleThroughAncestors, readElementTransformSnapshot, rotationDegreesFromMatrix, snapCandidates, MAX_GEOMETRY_CHILDREN, MAX_SNAP_TARGETS, ROTATION_GATE_EPSILON_DEG, } from "./editingGeometry.js";
16
16
  export { compositionPoint, coversComposition, isDomLayerElement, isInspectableLayerElement, pointerTarget, pointerTargets, resolveAllVisualDomEditTargets, resolveLayerSelector, } from "./editingTargets.js";
17
+ export { elementZIndex, hasOnlyFormattingChildren, isCompositionHost, layerKindOf, } from "./editingLayers.js";
17
18
  export { composeElementTransform, individualRotateDegrees, } from "./elementTransform.js";
18
19
  export const EDITING_PROTOCOL_VERSION = 1;
19
20
  /** Parent to frame, on the window: asks the runtime for the port. */
@@ -32,7 +33,11 @@ export const EDITING_REQUEST_KINDS = [
32
33
  "ancestors",
33
34
  "query",
34
35
  "geometry",
36
+ "layers",
37
+ "draft",
38
+ "gesture-start",
35
39
  ];
40
+ export const MAX_DRAFT_PX = 100_000;
36
41
  export function isPlainRecord(value) {
37
42
  return Object.prototype.toString.call(value) === "[object Object]";
38
43
  }
@@ -73,6 +78,48 @@ function point(params) {
73
78
  const { x, y } = params;
74
79
  return Number.isFinite(x) && Number.isFinite(y) ? { x: x, y: y } : null;
75
80
  }
81
+ const isOffset = (value) => Number.isSafeInteger(value) && value >= 0;
82
+ function layerParams(params) {
83
+ if (!isPlainRecord(params))
84
+ return null;
85
+ const { group, offset, ...rest } = params;
86
+ const valid = [
87
+ Object.keys(rest).length === 0,
88
+ group === undefined || isHandle(group),
89
+ offset === undefined || isOffset(offset),
90
+ ];
91
+ if (valid.includes(false))
92
+ return null;
93
+ return { ...(isHandle(group) && { group }), ...(isOffset(offset) && { offset }) };
94
+ }
95
+ const isDraftPx = (value, min) => Number.isFinite(value) && value >= min && Math.abs(value) <= MAX_DRAFT_PX;
96
+ function draftPart(value, keys, min) {
97
+ if (value === null)
98
+ return true;
99
+ if (!hasKeys(value, keys))
100
+ return false;
101
+ return keys.split(",").every((key) => isDraftPx(value[key], min));
102
+ }
103
+ function draftEntry(value) {
104
+ if (!isPlainRecord(value) || !isHandle(value.handle))
105
+ return null;
106
+ const { handle, end, translate, size } = value;
107
+ if (hasKeys(value, "end,handle"))
108
+ return end === "keep" || end === "restore" ? { handle, end } : null;
109
+ if (!hasKeys(value, "handle,size,translate"))
110
+ return null;
111
+ const valid = draftPart(translate, "x,y", -MAX_DRAFT_PX) && draftPart(size, "height,width", 0);
112
+ return valid ? value : null;
113
+ }
114
+ function draftList(params) {
115
+ if (!hasKeys(params, "drafts") || !Array.isArray(params.drafts))
116
+ return null;
117
+ const { drafts } = params;
118
+ if (!drafts.length || drafts.length > MAX_DESCRIBE_HANDLES)
119
+ return null;
120
+ const parsed = drafts.map(draftEntry);
121
+ return parsed.includes(null) ? null : { drafts: parsed };
122
+ }
76
123
  const PARAM_PARSERS = {
77
124
  hello: noParams,
78
125
  "runtime-snapshot": noParams,
@@ -110,6 +157,9 @@ const PARAM_PARSERS = {
110
157
  return list;
111
158
  return isHandle(children) ? { ...list, children } : null;
112
159
  },
160
+ layers: (params) => noParams(params) ?? layerParams(params),
161
+ draft: draftList,
162
+ "gesture-start": handleList,
113
163
  };
114
164
  /** Validates one request off the wire. Never throws: anything unusable becomes a typed error. */
115
165
  export function parseEditingRequest(data) {
@@ -242,6 +242,9 @@ export function pointerTarget(doc, point) {
242
242
  if (visualTarget)
243
243
  return visualTarget;
244
244
  }
245
+ return pointerFallbackTarget(doc, point);
246
+ }
247
+ function pointerFallbackTarget(doc, point) {
245
248
  const groupHit = findGroupAtPoint(doc, point.x, point.y);
246
249
  if (groupHit && !hasAuthorPointerEventsNone(groupHit) && isDomLayerElement(groupHit))
247
250
  return groupHit;
@@ -288,7 +291,11 @@ export function pointerTargetsAt(x, y) {
288
291
  const point = compositionPoint(document, x, y);
289
292
  if (!point)
290
293
  return { target: null, stack: [] };
291
- const target = pointerTarget(document, point);
292
- const stack = pointerTargets(document, point).slice(0, MAX_POINT_STACK);
293
- return { target: target && elementHit(target), stack: stack.map(elementHit) };
294
+ const stack = pointerTargets(document, point);
295
+ const visual = typeof document.elementsFromPoint === "function" ? stack[0] : undefined;
296
+ const target = visual ?? pointerFallbackTarget(document, point);
297
+ return {
298
+ target: target && elementHit(target),
299
+ stack: stack.slice(0, MAX_POINT_STACK).map(elementHit),
300
+ };
294
301
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperframes/core",
3
- "version": "0.9.41",
3
+ "version": "0.9.43",
4
4
  "description": "",
5
5
  "repository": {
6
6
  "type": "git",
@@ -445,9 +445,9 @@
445
445
  "linkedom": "^0.18.12",
446
446
  "postcss": "^8.5.8",
447
447
  "wawoff2": "^2.0.1",
448
- "@hyperframes/lint": "0.9.41",
449
- "@hyperframes/parsers": "0.9.41",
450
- "@hyperframes/studio-server": "0.9.41"
448
+ "@hyperframes/lint": "0.9.43",
449
+ "@hyperframes/parsers": "0.9.43",
450
+ "@hyperframes/studio-server": "0.9.43"
451
451
  },
452
452
  "devDependencies": {
453
453
  "@fontsource/archivo-black": "^5.2.8",
@@ -470,12 +470,12 @@
470
470
  "@fontsource/space-mono": "^5.2.9",
471
471
  "@types/jsdom": "^28.0.0",
472
472
  "@types/node": "^25.0.10",
473
- "@vitest/coverage-v8": "^4.1.11",
473
+ "@vitest/coverage-v8": "^4.1.12",
474
474
  "gsap": "^3.15.0",
475
475
  "jsdom": "^29.0.0",
476
476
  "tsx": "^4.21.0",
477
477
  "typescript": "^5.0.0",
478
- "vitest": "^4.1.11"
478
+ "vitest": "^4.1.12"
479
479
  },
480
480
  "optionalDependencies": {
481
481
  "esbuild": "^0.28.2"