@contrail/documents 1.15.0-alpha.567dcf0 → 1.15.0-alpha.8841401

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.
package/CHANGELOG.md CHANGED
@@ -5,15 +5,12 @@ All notable changes to `@contrail/documents` are documented here.
5
5
  Format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
6
6
  Versioning follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
- ## [1.15.0] - 2026-08-18
8
+ ## [1.15.0] - 2026-08-20
9
9
 
10
10
  ### Added
11
11
 
12
- - `isValidSortIndex` — whether a value is a usable fractional-indexing key. `fractional-indexing` keeps its own `validateOrderKey` private, so callers that need to check a key before storing it had no way to do so beyond a non-empty-string test. A key that passes that test but breaks the grammar still sorts, so ordering looks fine; the failure surfaces later, when the next insert beside it calls `generateKeyBetween` and throws. One point is stricter than the library: every character must be in the base-62 digit set, since a key holding anything else can sort below the integer part it claims.
13
-
14
- ### Changed
15
-
16
- - `SortOrderErrorMessage.SORT_INDEX_NOT_USABLE` now reads "sortIndex must be a valid fractional-indexing key". The code is unchanged; the old text described only the non-empty-string half of the condition a caller can now check with `isValidSortIndex`.
12
+ - `MaskDefinition` and `MaskShapeKey` on `DocumentElement` — `maskDefinition` records that an image is masked into one of nine preset shapes, with an optional clockwise `rotation`. Its presence changes how `cropDefinition`'s percents are read: element-space (the mask window within the element) instead of the source-image crop they otherwise mean. Anything deriving image geometry must check `hasShapeMask` before treating a crop as a source crop — reading one as the other samples the wrong region of the bitmap.
13
+ - `@contrail/documents/util/mask` — the shared mask model, exported from the package root: the nine shapes as renderer-agnostic cubic path segments (`getMaskShapeSegments`), `rotatedRectAABB` for the bounds a tilted shape actually occupies, `rotatePoint`, the mask-rect/percent conversions, and `MASK_SHAPE_PRESET_GEOMETRY` mapping each shape to its OOXML preset so exporters and the canvas cannot drift apart. Segments are cubic-only because cubics survive affine maps exactly, letting each consumer render them however it draws — `Path2D` in a browser, preset geometry in pptx.
17
14
 
18
15
  ## [1.14.0] - 2026-07-29
19
16
 
@@ -90,7 +90,7 @@ class DocumentElementFactory {
90
90
  return element;
91
91
  }
92
92
  static copyElements(elements, documentId, commonOptions = {}, positionOffset, lastFrameNumber) {
93
- var _a, _b;
93
+ var _a, _b, _c;
94
94
  const oldIdToNewId = new Map();
95
95
  const newElements = [];
96
96
  const groupElements = [];
@@ -118,11 +118,10 @@ class DocumentElementFactory {
118
118
  const oldChildElements = elements.filter((e) => e.tableId === element.id && ['cell', 'column', 'row'].indexOf(e.type) !== -1);
119
119
  let newTableElement, newChildElements = [];
120
120
  try {
121
- [newTableElement, ...newChildElements] = document_table_1.TableCopyService.copy(newElement, oldChildElements);
121
+ [newTableElement, ...newChildElements] = document_table_1.TableCopyService.copy(element, oldChildElements);
122
122
  }
123
- catch (e) { }
124
- if (oldChildElements.length > newChildElements.length || oldChildElements.length === 0) {
125
- telemetry_1.logger.warn({ newElement, oldChildElements, newChildElements }, 'Invalid table element to copy');
123
+ catch (e) {
124
+ telemetry_1.logger.warn({ element, oldChildElements, newChildElements }, (_b = e === null || e === void 0 ? void 0 : e.message) !== null && _b !== void 0 ? _b : 'Invalid table element to copy');
126
125
  continue;
127
126
  }
128
127
  newElement = newTableElement;
@@ -159,7 +158,7 @@ class DocumentElementFactory {
159
158
  newElement.position.x = newElement.position.x + positionOffset.x;
160
159
  newElement.position.y = newElement.position.y + positionOffset.y;
161
160
  }
162
- if (['line', 'callout'].includes(newElement.type) && ((_b = newElement.points) === null || _b === void 0 ? void 0 : _b.length) > 0) {
161
+ if (['line', 'callout'].includes(newElement.type) && ((_c = newElement.points) === null || _c === void 0 ? void 0 : _c.length) > 0) {
163
162
  newElement.points = newElement.points.map(([x, y]) => [x + positionOffset.x, y + positionOffset.y]);
164
163
  }
165
164
  }
package/lib/index.d.ts CHANGED
@@ -11,4 +11,5 @@ export * from './document-element-constants';
11
11
  export * from './util/curved-line/point';
12
12
  export * from './util/curved-line/curved-line';
13
13
  export * from './util/callout/callout';
14
+ export * from './util/mask';
14
15
  export * from './document-frame.service';
package/lib/index.js CHANGED
@@ -27,4 +27,5 @@ __exportStar(require("./document-element-constants"), exports);
27
27
  __exportStar(require("./util/curved-line/point"), exports);
28
28
  __exportStar(require("./util/curved-line/curved-line"), exports);
29
29
  __exportStar(require("./util/callout/callout"), exports);
30
+ __exportStar(require("./util/mask"), exports);
30
31
  __exportStar(require("./document-frame.service"), exports);
@@ -1,6 +1,5 @@
1
1
  import { DocumentElement } from './types';
2
2
  export declare function allElementsHaveSortIndex(elements: unknown[]): boolean;
3
- export declare function isValidSortIndex(sortIndex: unknown): sortIndex is string;
4
3
  export declare function buildKeyBetween(a: string | null, b: string | null): string;
5
4
  export declare function buildNKeysBetween(a: string | null, b: string | null, n: number): string[];
6
5
  export declare function compareSortIndex(a: DocumentElement, b: DocumentElement): number;
package/lib/sort-index.js CHANGED
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.allElementsHaveSortIndex = allElementsHaveSortIndex;
4
- exports.isValidSortIndex = isValidSortIndex;
5
4
  exports.buildKeyBetween = buildKeyBetween;
6
5
  exports.buildNKeysBetween = buildNKeysBetween;
7
6
  exports.compareSortIndex = compareSortIndex;
@@ -10,26 +9,6 @@ function allElementsHaveSortIndex(elements) {
10
9
  return elements.every((element) => typeof element.sortIndex === 'string' &&
11
10
  element.sortIndex.length > 0);
12
11
  }
13
- const SMALLEST_INTEGER = 'A00000000000000000000000000';
14
- function getIntegerPartLength(head) {
15
- if (head >= 'a' && head <= 'z')
16
- return head.charCodeAt(0) - 'a'.charCodeAt(0) + 2;
17
- if (head >= 'A' && head <= 'Z')
18
- return 'Z'.charCodeAt(0) - head.charCodeAt(0) + 2;
19
- return null;
20
- }
21
- function isValidSortIndex(sortIndex) {
22
- if (typeof sortIndex !== 'string' || sortIndex.length === 0)
23
- return false;
24
- if (sortIndex === SMALLEST_INTEGER)
25
- return false;
26
- if (![...sortIndex].every((character) => fractional_indexing_1.BASE_62_DIGITS.includes(character)))
27
- return false;
28
- const integerPartLength = getIntegerPartLength(sortIndex[0]);
29
- if (integerPartLength === null || integerPartLength > sortIndex.length)
30
- return false;
31
- return !sortIndex.slice(integerPartLength).endsWith('0');
32
- }
33
12
  function buildKeyBetween(a, b) {
34
13
  return (0, fractional_indexing_1.generateKeyBetween)(a, b);
35
14
  }
@@ -6,5 +6,5 @@ export declare enum SortOrderErrorCode {
6
6
  export declare enum SortOrderErrorMessage {
7
7
  SORT_MIGRATION_IN_PROGRESS = "Sort order is being migrated for this document; editing is briefly locked",
8
8
  SORT_MODE_MISMATCH = "Ordering write does not match the document's sort mode",
9
- SORT_INDEX_NOT_USABLE = "sortIndex must be a valid fractional-indexing key"
9
+ SORT_INDEX_NOT_USABLE = "sortIndex must be a non-empty string"
10
10
  }
@@ -11,5 +11,5 @@ var SortOrderErrorMessage;
11
11
  (function (SortOrderErrorMessage) {
12
12
  SortOrderErrorMessage["SORT_MIGRATION_IN_PROGRESS"] = "Sort order is being migrated for this document; editing is briefly locked";
13
13
  SortOrderErrorMessage["SORT_MODE_MISMATCH"] = "Ordering write does not match the document's sort mode";
14
- SortOrderErrorMessage["SORT_INDEX_NOT_USABLE"] = "sortIndex must be a valid fractional-indexing key";
14
+ SortOrderErrorMessage["SORT_INDEX_NOT_USABLE"] = "sortIndex must be a non-empty string";
15
15
  })(SortOrderErrorMessage || (exports.SortOrderErrorMessage = SortOrderErrorMessage = {}));
@@ -74,6 +74,11 @@ export interface LineDefinition {
74
74
  markerEnd?: string;
75
75
  lineType?: LineType;
76
76
  }
77
+ export type MaskShapeKey = 'circle' | 'square' | 'rounded' | 'triangle' | 'diamond' | 'parallelogram' | 'star' | 'heart' | 'cloud';
78
+ export interface MaskDefinition {
79
+ shape: MaskShapeKey;
80
+ rotation?: number;
81
+ }
77
82
  export interface CropDefinition {
78
83
  x1?: number;
79
84
  x2?: number;
@@ -1,5 +1,5 @@
1
1
  import { PropertyLevel } from '@contrail/types';
2
- import { CropDefinition, LineDefinition, PositionDefinition, RotationDefinition, SizeDefinition } from './common';
2
+ import { CropDefinition, LineDefinition, MaskDefinition, PositionDefinition, RotationDefinition, SizeDefinition } from './common';
3
3
  import { Document } from './document';
4
4
  import { ScaleTransformation } from './element-transformation';
5
5
  export interface AlternateUrls {
@@ -20,6 +20,8 @@ export interface DocumentElement extends Document {
20
20
  sortIndex?: string;
21
21
  type?: string;
22
22
  rotate?: RotationDefinition;
23
+ flipH?: boolean;
24
+ flipV?: boolean;
23
25
  scale?: ScaleTransformation;
24
26
  text?: string;
25
27
  url?: string;
@@ -30,6 +32,7 @@ export interface DocumentElement extends Document {
30
32
  annotations?: any;
31
33
  isLocked?: boolean;
32
34
  cropDefinition?: CropDefinition;
35
+ maskDefinition?: MaskDefinition;
33
36
  embedInfo?: any;
34
37
  isHidden?: boolean;
35
38
  elementIds?: Array<string>;
@@ -0,0 +1,4 @@
1
+ export * from './mask-shape-geometry';
2
+ export * from './rotation-math';
3
+ export * from './shape-mask-element';
4
+ export * from './mask-preset-geometry';
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./mask-shape-geometry"), exports);
18
+ __exportStar(require("./rotation-math"), exports);
19
+ __exportStar(require("./shape-mask-element"), exports);
20
+ __exportStar(require("./mask-preset-geometry"), exports);
@@ -0,0 +1,3 @@
1
+ import { MaskShapeKey } from './mask-shape-geometry';
2
+ export declare const MASK_SHAPE_PRESET_GEOMETRY: Record<MaskShapeKey, string>;
3
+ export declare function getMaskPresetGeometry(shape: MaskShapeKey | null): string | null;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MASK_SHAPE_PRESET_GEOMETRY = void 0;
4
+ exports.getMaskPresetGeometry = getMaskPresetGeometry;
5
+ exports.MASK_SHAPE_PRESET_GEOMETRY = {
6
+ circle: 'ellipse',
7
+ square: 'rect',
8
+ rounded: 'roundRect',
9
+ triangle: 'triangle',
10
+ diamond: 'diamond',
11
+ parallelogram: 'parallelogram',
12
+ star: 'star5',
13
+ heart: 'heart',
14
+ cloud: 'cloud',
15
+ };
16
+ function getMaskPresetGeometry(shape) {
17
+ var _a;
18
+ return shape ? (_a = exports.MASK_SHAPE_PRESET_GEOMETRY[shape]) !== null && _a !== void 0 ? _a : null : null;
19
+ }
@@ -0,0 +1,26 @@
1
+ import { MaskShapeKey } from '../../types';
2
+ export { MaskShapeKey };
3
+ export declare const MASK_SHAPE_KEYS: readonly MaskShapeKey[];
4
+ export interface MaskRect {
5
+ x: number;
6
+ y: number;
7
+ width: number;
8
+ height: number;
9
+ }
10
+ export type PathSegment = {
11
+ op: 'move' | 'line';
12
+ x: number;
13
+ y: number;
14
+ } | {
15
+ op: 'cubic';
16
+ c1x: number;
17
+ c1y: number;
18
+ c2x: number;
19
+ c2y: number;
20
+ x: number;
21
+ y: number;
22
+ } | {
23
+ op: 'close';
24
+ };
25
+ export declare function getMaskShapeSegments(shape: MaskShapeKey, rect: MaskRect, rotationDeg?: number): PathSegment[];
26
+ export declare function rotatedRectAABB(rect: MaskRect, rotationDeg: number): MaskRect;
@@ -0,0 +1,154 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MASK_SHAPE_KEYS = void 0;
4
+ exports.getMaskShapeSegments = getMaskShapeSegments;
5
+ exports.rotatedRectAABB = rotatedRectAABB;
6
+ const rotation_math_1 = require("./rotation-math");
7
+ exports.MASK_SHAPE_KEYS = [
8
+ 'circle',
9
+ 'square',
10
+ 'rounded',
11
+ 'triangle',
12
+ 'diamond',
13
+ 'parallelogram',
14
+ 'star',
15
+ 'heart',
16
+ 'cloud',
17
+ ];
18
+ const K = 0.5522847498;
19
+ function polygon(points) {
20
+ const [first, ...rest] = points;
21
+ return [
22
+ { op: 'move', x: first[0], y: first[1] },
23
+ ...rest.map(([x, y]) => ({ op: 'line', x, y })),
24
+ { op: 'close' },
25
+ ];
26
+ }
27
+ function ellipse(cx, cy, rx, ry) {
28
+ return [
29
+ { op: 'move', x: cx + rx, y: cy },
30
+ { op: 'cubic', c1x: cx + rx, c1y: cy + K * ry, c2x: cx + K * rx, c2y: cy + ry, x: cx, y: cy + ry },
31
+ { op: 'cubic', c1x: cx - K * rx, c1y: cy + ry, c2x: cx - rx, c2y: cy + K * ry, x: cx - rx, y: cy },
32
+ { op: 'cubic', c1x: cx - rx, c1y: cy - K * ry, c2x: cx - K * rx, c2y: cy - ry, x: cx, y: cy - ry },
33
+ { op: 'cubic', c1x: cx + K * rx, c1y: cy - ry, c2x: cx + rx, c2y: cy - K * ry, x: cx + rx, y: cy },
34
+ { op: 'close' },
35
+ ];
36
+ }
37
+ function roundedRect(x, y, w, h, r) {
38
+ const x2 = x + w;
39
+ const y2 = y + h;
40
+ return [
41
+ { op: 'move', x: x + r, y },
42
+ { op: 'line', x: x2 - r, y },
43
+ { op: 'cubic', c1x: x2 - r + K * r, c1y: y, c2x: x2, c2y: y + r - K * r, x: x2, y: y + r },
44
+ { op: 'line', x: x2, y: y2 - r },
45
+ { op: 'cubic', c1x: x2, c1y: y2 - r + K * r, c2x: x2 - r + K * r, c2y: y2, x: x2 - r, y: y2 },
46
+ { op: 'line', x: x + r, y: y2 },
47
+ { op: 'cubic', c1x: x + r - K * r, c1y: y2, c2x: x, c2y: y2 - r + K * r, x, y: y2 - r },
48
+ { op: 'line', x, y: y + r },
49
+ { op: 'cubic', c1x: x, c1y: y + r - K * r, c2x: x + r - K * r, c2y: y, x: x + r, y },
50
+ { op: 'close' },
51
+ ];
52
+ }
53
+ const UNIT_SEGMENTS = {
54
+ circle: ellipse(50, 50, 49, 49),
55
+ square: polygon([
56
+ [1, 1],
57
+ [99, 1],
58
+ [99, 99],
59
+ [1, 99],
60
+ ]),
61
+ rounded: roundedRect(1, 1, 98, 98, 16),
62
+ triangle: polygon([
63
+ [50, 3],
64
+ [97, 96],
65
+ [3, 96],
66
+ ]),
67
+ diamond: polygon([
68
+ [50, 2],
69
+ [98, 50],
70
+ [50, 98],
71
+ [2, 50],
72
+ ]),
73
+ parallelogram: polygon([
74
+ [27, 12],
75
+ [98, 12],
76
+ [73, 88],
77
+ [2, 88],
78
+ ]),
79
+ star: polygon([
80
+ [50, 3],
81
+ [61, 37],
82
+ [97, 37],
83
+ [68, 59],
84
+ [79, 95],
85
+ [50, 73],
86
+ [21, 95],
87
+ [32, 59],
88
+ [3, 37],
89
+ [39, 37],
90
+ ]),
91
+ heart: [
92
+ { op: 'move', x: 50, y: 90 },
93
+ { op: 'cubic', c1x: 6, c1y: 58, c2x: 10, c2y: 20, x: 32, y: 18 },
94
+ { op: 'cubic', c1x: 44, c1y: 17, c2x: 50, c2y: 27, x: 50, y: 34 },
95
+ { op: 'cubic', c1x: 50, c1y: 27, c2x: 56, c2y: 17, x: 68, y: 18 },
96
+ { op: 'cubic', c1x: 90, c1y: 20, c2x: 94, c2y: 58, x: 50, y: 90 },
97
+ { op: 'close' },
98
+ ],
99
+ cloud: [
100
+ { op: 'move', x: 30, y: 80 },
101
+ { op: 'cubic', c1x: 13, c1y: 80, c2x: 6, c2y: 66, x: 16, y: 56 },
102
+ { op: 'cubic', c1x: 11, c1y: 42, c2x: 27, c2y: 34, x: 37, y: 42 },
103
+ { op: 'cubic', c1x: 41, c1y: 24, c2x: 66, c2y: 24, x: 70, y: 42 },
104
+ { op: 'cubic', c1x: 86, c1y: 38, c2x: 96, c2y: 56, x: 84, y: 68 },
105
+ { op: 'cubic', c1x: 92, c1y: 78, c2x: 82, c2y: 88, x: 70, y: 84 },
106
+ { op: 'close' },
107
+ ],
108
+ };
109
+ function getMaskShapeSegments(shape, rect, rotationDeg = 0) {
110
+ const unit = UNIT_SEGMENTS[shape];
111
+ if (!unit) {
112
+ throw new Error(`Unknown mask shape: ${shape}`);
113
+ }
114
+ const sx = rect.width / 100;
115
+ const sy = rect.height / 100;
116
+ const tx = (x) => rect.x + x * sx;
117
+ const ty = (y) => rect.y + y * sy;
118
+ const cx = rect.x + rect.width * 0.5;
119
+ const cy = rect.y + rect.height * 0.5;
120
+ const rotate = (x, y) => rotationDeg ? (0, rotation_math_1.rotatePoint)({ x, y }, rotationDeg, { x: cx, y: cy }) : { x, y };
121
+ return unit.map((s) => {
122
+ if (s.op === 'close') {
123
+ return { op: 'close' };
124
+ }
125
+ if (s.op === 'cubic') {
126
+ const c1 = rotate(tx(s.c1x), ty(s.c1y));
127
+ const c2 = rotate(tx(s.c2x), ty(s.c2y));
128
+ const p = rotate(tx(s.x), ty(s.y));
129
+ return { op: 'cubic', c1x: c1.x, c1y: c1.y, c2x: c2.x, c2y: c2.y, x: p.x, y: p.y };
130
+ }
131
+ const p = rotate(tx(s.x), ty(s.y));
132
+ return { op: s.op, x: p.x, y: p.y };
133
+ });
134
+ }
135
+ function rotatedRectAABB(rect, rotationDeg) {
136
+ if (!rotationDeg) {
137
+ return Object.assign({}, rect);
138
+ }
139
+ const cx = rect.x + rect.width * 0.5;
140
+ const cy = rect.y + rect.height * 0.5;
141
+ const corners = [
142
+ { x: rect.x, y: rect.y },
143
+ { x: rect.x + rect.width, y: rect.y },
144
+ { x: rect.x + rect.width, y: rect.y + rect.height },
145
+ { x: rect.x, y: rect.y + rect.height },
146
+ ].map(p => (0, rotation_math_1.rotatePoint)(p, rotationDeg, { x: cx, y: cy }));
147
+ const xs = corners.map(p => p.x);
148
+ const ys = corners.map(p => p.y);
149
+ const minX = Math.min(...xs);
150
+ const maxX = Math.max(...xs);
151
+ const minY = Math.min(...ys);
152
+ const maxY = Math.max(...ys);
153
+ return { x: minX, y: minY, width: maxX - minX, height: maxY - minY };
154
+ }
@@ -0,0 +1,2 @@
1
+ import type { PositionDefinition } from '../../types';
2
+ export declare function rotatePoint(point: PositionDefinition, angleDeg: number, pivot?: PositionDefinition): PositionDefinition;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.rotatePoint = rotatePoint;
4
+ function rotatePoint(point, angleDeg, pivot = { x: 0, y: 0 }) {
5
+ const theta = (angleDeg * Math.PI) / 180;
6
+ const cos = Math.cos(theta);
7
+ const sin = Math.sin(theta);
8
+ const dx = point.x - pivot.x;
9
+ const dy = point.y - pivot.y;
10
+ return {
11
+ x: dx * cos - dy * sin + pivot.x,
12
+ y: dx * sin + dy * cos + pivot.y,
13
+ };
14
+ }
@@ -0,0 +1,16 @@
1
+ import { CropDefinition, DocumentElement, SizeDefinition } from '../../types';
2
+ import { MaskRect, MaskShapeKey } from './mask-shape-geometry';
3
+ export declare function hasShapeMask(element: DocumentElement): boolean;
4
+ export declare function getShapeMaskKey(element: DocumentElement): MaskShapeKey | null;
5
+ export declare function getShapeMaskRotation(element: DocumentElement): number;
6
+ export declare function normalizeMaskRotation(rotation: number): number;
7
+ export declare function isShapeMaskable(element: DocumentElement): boolean;
8
+ export declare function getDefaultShapeMaskCrop(size: SizeDefinition): CropDefinition;
9
+ export declare function cropDefinitionToMaskRect(crop: CropDefinition, size: SizeDefinition): MaskRect;
10
+ export declare function maskRectToCropDefinition(rect: MaskRect, size: SizeDefinition): CropDefinition;
11
+ export declare const SHAPE_MASK_CLEAR_FIELDS: {
12
+ readonly maskDefinition: any;
13
+ readonly cropDefinition: any;
14
+ readonly imageSize: any;
15
+ readonly imagePosition: any;
16
+ };
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SHAPE_MASK_CLEAR_FIELDS = void 0;
4
+ exports.hasShapeMask = hasShapeMask;
5
+ exports.getShapeMaskKey = getShapeMaskKey;
6
+ exports.getShapeMaskRotation = getShapeMaskRotation;
7
+ exports.normalizeMaskRotation = normalizeMaskRotation;
8
+ exports.isShapeMaskable = isShapeMaskable;
9
+ exports.getDefaultShapeMaskCrop = getDefaultShapeMaskCrop;
10
+ exports.cropDefinitionToMaskRect = cropDefinitionToMaskRect;
11
+ exports.maskRectToCropDefinition = maskRectToCropDefinition;
12
+ const DEFAULT_MASK_FRACTION = 0.72;
13
+ function hasShapeMask(element) {
14
+ var _a, _b;
15
+ return (!!getShapeMaskKey(element) && !!((_a = element === null || element === void 0 ? void 0 : element.cropDefinition) === null || _a === void 0 ? void 0 : _a.widthPercent) && !!((_b = element === null || element === void 0 ? void 0 : element.cropDefinition) === null || _b === void 0 ? void 0 : _b.heightPercent));
16
+ }
17
+ function getShapeMaskKey(element) {
18
+ var _a, _b;
19
+ return (_b = (_a = element === null || element === void 0 ? void 0 : element.maskDefinition) === null || _a === void 0 ? void 0 : _a.shape) !== null && _b !== void 0 ? _b : null;
20
+ }
21
+ function getShapeMaskRotation(element) {
22
+ var _a, _b;
23
+ return (_b = (_a = element === null || element === void 0 ? void 0 : element.maskDefinition) === null || _a === void 0 ? void 0 : _a.rotation) !== null && _b !== void 0 ? _b : 0;
24
+ }
25
+ function normalizeMaskRotation(rotation) {
26
+ return ((rotation % 360) + 360) % 360;
27
+ }
28
+ function isShapeMaskable(element) {
29
+ return (element === null || element === void 0 ? void 0 : element.type) === 'image';
30
+ }
31
+ function getDefaultShapeMaskCrop(size) {
32
+ const side = Math.min(size.width, size.height) * DEFAULT_MASK_FRACTION;
33
+ return {
34
+ x1Percent: ((size.width - side) * 0.5) / size.width,
35
+ y1Percent: ((size.height - side) * 0.5) / size.height,
36
+ widthPercent: side / size.width,
37
+ heightPercent: side / size.height,
38
+ };
39
+ }
40
+ function cropDefinitionToMaskRect(crop, size) {
41
+ return {
42
+ x: crop.x1Percent * size.width,
43
+ y: crop.y1Percent * size.height,
44
+ width: crop.widthPercent * size.width,
45
+ height: crop.heightPercent * size.height,
46
+ };
47
+ }
48
+ function maskRectToCropDefinition(rect, size) {
49
+ return {
50
+ x1Percent: rect.x / size.width,
51
+ y1Percent: rect.y / size.height,
52
+ widthPercent: rect.width / size.width,
53
+ heightPercent: rect.height / size.height,
54
+ };
55
+ }
56
+ exports.SHAPE_MASK_CLEAR_FIELDS = {
57
+ maskDefinition: null,
58
+ cropDefinition: null,
59
+ imageSize: null,
60
+ imagePosition: null,
61
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/documents",
3
- "version": "1.15.0-alpha.567dcf0",
3
+ "version": "1.15.0-alpha.8841401",
4
4
  "description": "Documents library for contrail platform",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -40,7 +40,7 @@
40
40
  },
41
41
  "dependencies": {
42
42
  "@contrail/actions": "^1.0.18",
43
- "@contrail/document-table": "^1.1.0",
43
+ "@contrail/document-table": "^1.2.3",
44
44
  "@contrail/document-util": "^1.2.0",
45
45
  "@contrail/types": "^3.4.0",
46
46
  "fractional-indexing": "^2.1.0",