@hyperframes/core 0.9.99 → 0.9.100

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,17 @@
1
+ import type { EditingElementHandle } from "../editingElement.js";
2
+ export declare const MAX_FONT_FACES = 256;
3
+ /** Each property's inline value, else the last same-origin rule's that matches; null for an unknown handle. */
4
+ export declare function authoredStyles({ handle, properties, }: {
5
+ handle: EditingElementHandle;
6
+ properties: string[];
7
+ }): {
8
+ styles: Record<string, string> | null;
9
+ };
10
+ /** The families the document's fonts draw, and each same-origin `@font-face` rule's family and src. */
11
+ export declare function fontFaces(): {
12
+ families: string[];
13
+ ownFaces: Array<{
14
+ family: string;
15
+ src: string;
16
+ }>;
17
+ };
@@ -0,0 +1,57 @@
1
+ import { MAX_ELEMENT_VALUE } from "../editingElement.js";
2
+ import { elementForHandle } from "../editingHandles.js";
3
+ export const MAX_FONT_FACES = 256;
4
+ const cut = (value) => value.slice(0, MAX_ELEMENT_VALUE);
5
+ function sameOriginRules() {
6
+ return [...document.styleSheets].flatMap((sheet) => {
7
+ try {
8
+ return [...sheet.cssRules];
9
+ }
10
+ catch {
11
+ return [];
12
+ }
13
+ });
14
+ }
15
+ const isStyleRule = (rule) => "selectorText" in rule;
16
+ const isFontFaceRule = (rule) => rule.cssText.startsWith("@font-face");
17
+ function matches(element, selector) {
18
+ try {
19
+ return element.matches(selector);
20
+ }
21
+ catch {
22
+ return false;
23
+ }
24
+ }
25
+ /** Each property's inline value, else the last same-origin rule's that matches; null for an unknown handle. */
26
+ export function authoredStyles({ handle, properties, }) {
27
+ const element = elementForHandle(handle);
28
+ if (!element)
29
+ return { styles: null };
30
+ const inline = element.style;
31
+ const rules = sameOriginRules().filter(isStyleRule);
32
+ const styles = {};
33
+ for (const name of properties) {
34
+ const ruled = rules.filter((rule) => rule.style.getPropertyValue(name) && matches(element, rule.selectorText));
35
+ const value = inline?.getPropertyValue(name) || ruled.at(-1)?.style.getPropertyValue(name);
36
+ if (value)
37
+ styles[name] = cut(value);
38
+ }
39
+ return { styles };
40
+ }
41
+ /** The families the document's fonts draw, and each same-origin `@font-face` rule's family and src. */
42
+ export function fontFaces() {
43
+ const families = new Set();
44
+ for (const face of document.fonts ?? []) {
45
+ if (families.size >= MAX_FONT_FACES)
46
+ break;
47
+ families.add(cut(face.family));
48
+ }
49
+ const ownFaces = sameOriginRules()
50
+ .filter(isFontFaceRule)
51
+ .slice(0, MAX_FONT_FACES)
52
+ .map((rule) => ({
53
+ family: cut(rule.style.getPropertyValue("font-family")),
54
+ src: cut(rule.style.getPropertyValue("src")),
55
+ }));
56
+ return { families: [...families], ownFaces };
57
+ }
@@ -38,6 +38,8 @@ 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_EDIT_ENTRIES } from "./editing/editElement.js";
42
+ export { MAX_FONT_FACES } from "./editing/textStyleReads.js";
41
43
  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
44
  export { compositionPoint, coversComposition, isDomLayerElement, isInspectableLayerElement, pointerTarget, pointerTargets, resolveAllVisualDomEditTargets, resolveLayerSelector, type EditingLocalPointer, type EditingViewport, } from "./editingTargets.js";
43
45
  export { elementZIndex, hasOnlyFormattingChildren, NON_PAINTING_TAGS, isCompositionHost, layerKindOf, type EditingLayer, type EditingStackingSibling, type LayerKind, } from "./editingLayers.js";
@@ -21,6 +21,8 @@ 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_EDIT_ENTRIES } from "./editing/editElement.js";
25
+ export { MAX_FONT_FACES } from "./editing/textStyleReads.js";
24
26
  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
27
  export { compositionPoint, coversComposition, isDomLayerElement, isInspectableLayerElement, pointerTarget, pointerTargets, resolveAllVisualDomEditTargets, resolveLayerSelector, } from "./editingTargets.js";
26
28
  export { elementZIndex, hasOnlyFormattingChildren, NON_PAINTING_TAGS, isCompositionHost, layerKindOf, } from "./editingLayers.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperframes/core",
3
- "version": "0.9.99",
3
+ "version": "0.9.100",
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.99",
529
- "@hyperframes/parsers": "0.9.99",
530
- "@hyperframes/studio-server": "0.9.99"
528
+ "@hyperframes/parsers": "0.9.100",
529
+ "@hyperframes/lint": "0.9.100",
530
+ "@hyperframes/studio-server": "0.9.100"
531
531
  },
532
532
  "devDependencies": {
533
533
  "@fontsource/archivo-black": "^5.2.8",