@contrail/documents 1.20.0-alpha.5014a52 → 2.0.0
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 +0 -22
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -1
- package/lib/types/common.d.ts +0 -5
- package/lib/types/document-change.d.ts +0 -2
- package/lib/types/document-element.d.ts +1 -2
- package/package.json +10 -7
- package/lib/util/mask/index.d.ts +0 -4
- package/lib/util/mask/index.js +0 -20
- package/lib/util/mask/mask-bake-layout.d.ts +0 -17
- package/lib/util/mask/mask-bake-layout.js +0 -56
- package/lib/util/mask/mask-shape-geometry.d.ts +0 -27
- package/lib/util/mask/mask-shape-geometry.js +0 -171
- package/lib/util/mask/rotation-math.d.ts +0 -2
- package/lib/util/mask/rotation-math.js +0 -14
- package/lib/util/mask/shape-mask-element.d.ts +0 -16
- package/lib/util/mask/shape-mask-element.js +0 -61
package/CHANGELOG.md
CHANGED
|
@@ -5,28 +5,6 @@ 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.20.0] - 2026-09-10
|
|
9
|
-
|
|
10
|
-
### Added
|
|
11
|
-
|
|
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`, and the mask-rect/percent conversions, 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, an SVG composite in a service.
|
|
14
|
-
- `getMaskBakeGeometry`, `getMaskBakeLayout` and `maskShapeSegmentsToSvgPath` — the bake inputs a consumer needs to flatten a mask into a bitmap, and an SVG serializer for renderers that go through SVG rather than a canvas path. The layout scales to the source bitmap's own resolution rather than the element's on-board size, so a shrunk image does not bake at reduced detail, and re-bases a rotated mask onto its own bounding box. Only the rasterizer stays per-consumer: `Path2D` in a browser, an SVG composite in a service.
|
|
15
|
-
|
|
16
|
-
## [1.18.0] - 2026-09-10
|
|
17
|
-
|
|
18
|
-
### Added
|
|
19
|
-
|
|
20
|
-
- `DocumentChange.gestureId?: string` — optional marker a producer sets to correlate the
|
|
21
|
-
actions of one user gesture across a batch.
|
|
22
|
-
|
|
23
|
-
## [1.17.0] - 2026-09-09
|
|
24
|
-
|
|
25
|
-
### Added
|
|
26
|
-
|
|
27
|
-
- `DocumentChange.skipUndo?: boolean` — optional marker a producer sets on a forward
|
|
28
|
-
change definition to keep the action out of undo history.
|
|
29
|
-
|
|
30
8
|
## [1.16.0] - 2026-08-28
|
|
31
9
|
|
|
32
10
|
### Added
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -28,5 +28,4 @@ __exportStar(require("./document-element-constants"), exports);
|
|
|
28
28
|
__exportStar(require("./util/curved-line/point"), exports);
|
|
29
29
|
__exportStar(require("./util/curved-line/curved-line"), exports);
|
|
30
30
|
__exportStar(require("./util/callout/callout"), exports);
|
|
31
|
-
__exportStar(require("./util/mask"), exports);
|
|
32
31
|
__exportStar(require("./document-frame.service"), exports);
|
package/lib/types/common.d.ts
CHANGED
|
@@ -74,11 +74,6 @@ 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
|
-
}
|
|
82
77
|
export interface CropDefinition {
|
|
83
78
|
x1?: number;
|
|
84
79
|
x2?: number;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PropertyLevel } from '@contrail/types';
|
|
2
|
-
import { CropDefinition, LineDefinition,
|
|
2
|
+
import { CropDefinition, LineDefinition, PositionDefinition, RotationDefinition, SizeDefinition } from './common';
|
|
3
3
|
import { Document } from './document';
|
|
4
4
|
import { ScaleTransformation } from './element-transformation';
|
|
5
5
|
export interface AlternateUrls {
|
|
@@ -32,7 +32,6 @@ export interface DocumentElement extends Document {
|
|
|
32
32
|
annotations?: any;
|
|
33
33
|
isLocked?: boolean;
|
|
34
34
|
cropDefinition?: CropDefinition;
|
|
35
|
-
maskDefinition?: MaskDefinition;
|
|
36
35
|
embedInfo?: any;
|
|
37
36
|
isHidden?: boolean;
|
|
38
37
|
elementIds?: Array<string>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contrail/documents",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Documents library for contrail platform",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"tslint": "^5.11.0",
|
|
23
23
|
"tslint-config-prettier": "^1.18.0",
|
|
24
24
|
"typescript": "^5.8.3",
|
|
25
|
-
"@contrail/telemetry": "^
|
|
25
|
+
"@contrail/telemetry": "^3.0.0"
|
|
26
26
|
},
|
|
27
27
|
"jest": {
|
|
28
28
|
"moduleFileExtensions": [
|
|
@@ -39,14 +39,17 @@
|
|
|
39
39
|
"testEnvironment": "node"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@contrail/actions": "^
|
|
43
|
-
"@contrail/document-table": "^
|
|
44
|
-
"@contrail/document-util": "^
|
|
45
|
-
"@contrail/types": "^
|
|
42
|
+
"@contrail/actions": "^2.0.0",
|
|
43
|
+
"@contrail/document-table": "^2.0.0",
|
|
44
|
+
"@contrail/document-util": "^2.0.0",
|
|
45
|
+
"@contrail/types": "^4.0.0",
|
|
46
46
|
"fractional-indexing": "^2.1.0",
|
|
47
47
|
"reflect-metadata": "^0.1.13"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"@contrail/telemetry": "^
|
|
50
|
+
"@contrail/telemetry": "^3.0.0"
|
|
51
|
+
},
|
|
52
|
+
"engines": {
|
|
53
|
+
"node": ">=24"
|
|
51
54
|
}
|
|
52
55
|
}
|
package/lib/util/mask/index.d.ts
DELETED
package/lib/util/mask/index.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
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-bake-layout"), exports);
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { DocumentElement, SizeDefinition } from '../../types';
|
|
2
|
-
import { MaskRect, MaskShapeKey } from './mask-shape-geometry';
|
|
3
|
-
export declare const MASK_BAKE_MAX_SIDE = 4096;
|
|
4
|
-
export interface MaskBakeGeometry {
|
|
5
|
-
shape: MaskShapeKey;
|
|
6
|
-
rotation: number;
|
|
7
|
-
maskRect: MaskRect;
|
|
8
|
-
imageRect: MaskRect;
|
|
9
|
-
}
|
|
10
|
-
export interface MaskBakeLayout {
|
|
11
|
-
size: SizeDefinition;
|
|
12
|
-
scale: number;
|
|
13
|
-
maskRect: MaskRect;
|
|
14
|
-
imageRect: MaskRect;
|
|
15
|
-
}
|
|
16
|
-
export declare function getMaskBakeGeometry(element: DocumentElement): MaskBakeGeometry | null;
|
|
17
|
-
export declare function getMaskBakeLayout(geometry: MaskBakeGeometry, sourceImageSize: SizeDefinition): MaskBakeLayout | null;
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MASK_BAKE_MAX_SIDE = void 0;
|
|
4
|
-
exports.getMaskBakeGeometry = getMaskBakeGeometry;
|
|
5
|
-
exports.getMaskBakeLayout = getMaskBakeLayout;
|
|
6
|
-
const mask_shape_geometry_1 = require("./mask-shape-geometry");
|
|
7
|
-
const shape_mask_element_1 = require("./shape-mask-element");
|
|
8
|
-
exports.MASK_BAKE_MAX_SIDE = 4096;
|
|
9
|
-
function getMaskBakeGeometry(element) {
|
|
10
|
-
var _a, _b;
|
|
11
|
-
const shape = (0, shape_mask_element_1.getShapeMaskKey)(element);
|
|
12
|
-
if (!shape || !(0, shape_mask_element_1.hasShapeMask)(element) || !((_a = element.size) === null || _a === void 0 ? void 0 : _a.width) || !((_b = element.size) === null || _b === void 0 ? void 0 : _b.height)) {
|
|
13
|
-
return null;
|
|
14
|
-
}
|
|
15
|
-
const imageRect = element.imageSize && element.imagePosition
|
|
16
|
-
? {
|
|
17
|
-
x: element.imagePosition.x,
|
|
18
|
-
y: element.imagePosition.y,
|
|
19
|
-
width: element.imageSize.width,
|
|
20
|
-
height: element.imageSize.height,
|
|
21
|
-
}
|
|
22
|
-
: { x: 0, y: 0, width: element.size.width, height: element.size.height };
|
|
23
|
-
return {
|
|
24
|
-
shape,
|
|
25
|
-
rotation: (0, shape_mask_element_1.getShapeMaskRotation)(element),
|
|
26
|
-
maskRect: (0, shape_mask_element_1.cropDefinitionToMaskRect)(element.cropDefinition, element.size),
|
|
27
|
-
imageRect,
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
function scaleRect(rect, scale, originX, originY) {
|
|
31
|
-
return {
|
|
32
|
-
x: (rect.x - originX) * scale,
|
|
33
|
-
y: (rect.y - originY) * scale,
|
|
34
|
-
width: rect.width * scale,
|
|
35
|
-
height: rect.height * scale,
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
function getMaskBakeLayout(geometry, sourceImageSize) {
|
|
39
|
-
const { maskRect, imageRect, rotation } = geometry;
|
|
40
|
-
if (!imageRect.width || !imageRect.height || !(sourceImageSize === null || sourceImageSize === void 0 ? void 0 : sourceImageSize.width) || !maskRect.width || !maskRect.height) {
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
const extent = rotation ? (0, mask_shape_geometry_1.rotatedRectAABB)(maskRect, rotation) : Object.assign({}, maskRect);
|
|
44
|
-
const nativeScale = sourceImageSize.width / imageRect.width;
|
|
45
|
-
const longestSide = Math.max(extent.width, extent.height) * nativeScale;
|
|
46
|
-
const scale = longestSide > exports.MASK_BAKE_MAX_SIDE ? (exports.MASK_BAKE_MAX_SIDE / longestSide) * nativeScale : nativeScale;
|
|
47
|
-
return {
|
|
48
|
-
size: {
|
|
49
|
-
width: Math.ceil(extent.width * scale),
|
|
50
|
-
height: Math.ceil(extent.height * scale),
|
|
51
|
-
},
|
|
52
|
-
scale,
|
|
53
|
-
maskRect: scaleRect(maskRect, scale, extent.x, extent.y),
|
|
54
|
-
imageRect: scaleRect(imageRect, scale, extent.x, extent.y),
|
|
55
|
-
};
|
|
56
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
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;
|
|
27
|
-
export declare function maskShapeSegmentsToSvgPath(segments: PathSegment[]): string;
|
|
@@ -1,171 +0,0 @@
|
|
|
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
|
-
exports.maskShapeSegmentsToSvgPath = maskShapeSegmentsToSvgPath;
|
|
7
|
-
const rotation_math_1 = require("./rotation-math");
|
|
8
|
-
exports.MASK_SHAPE_KEYS = [
|
|
9
|
-
'circle',
|
|
10
|
-
'square',
|
|
11
|
-
'rounded',
|
|
12
|
-
'triangle',
|
|
13
|
-
'diamond',
|
|
14
|
-
'parallelogram',
|
|
15
|
-
'star',
|
|
16
|
-
'heart',
|
|
17
|
-
'cloud',
|
|
18
|
-
];
|
|
19
|
-
const K = 0.5522847498;
|
|
20
|
-
function polygon(points) {
|
|
21
|
-
const [first, ...rest] = points;
|
|
22
|
-
return [
|
|
23
|
-
{ op: 'move', x: first[0], y: first[1] },
|
|
24
|
-
...rest.map(([x, y]) => ({ op: 'line', x, y })),
|
|
25
|
-
{ op: 'close' },
|
|
26
|
-
];
|
|
27
|
-
}
|
|
28
|
-
function ellipse(cx, cy, rx, ry) {
|
|
29
|
-
return [
|
|
30
|
-
{ op: 'move', x: cx + rx, y: cy },
|
|
31
|
-
{ op: 'cubic', c1x: cx + rx, c1y: cy + K * ry, c2x: cx + K * rx, c2y: cy + ry, x: cx, y: cy + ry },
|
|
32
|
-
{ op: 'cubic', c1x: cx - K * rx, c1y: cy + ry, c2x: cx - rx, c2y: cy + K * ry, x: cx - rx, y: cy },
|
|
33
|
-
{ op: 'cubic', c1x: cx - rx, c1y: cy - K * ry, c2x: cx - K * rx, c2y: cy - ry, x: cx, y: cy - ry },
|
|
34
|
-
{ op: 'cubic', c1x: cx + K * rx, c1y: cy - ry, c2x: cx + rx, c2y: cy - K * ry, x: cx + rx, y: cy },
|
|
35
|
-
{ op: 'close' },
|
|
36
|
-
];
|
|
37
|
-
}
|
|
38
|
-
function roundedRect(x, y, w, h, r) {
|
|
39
|
-
const x2 = x + w;
|
|
40
|
-
const y2 = y + h;
|
|
41
|
-
return [
|
|
42
|
-
{ op: 'move', x: x + r, y },
|
|
43
|
-
{ op: 'line', x: x2 - r, y },
|
|
44
|
-
{ op: 'cubic', c1x: x2 - r + K * r, c1y: y, c2x: x2, c2y: y + r - K * r, x: x2, y: y + r },
|
|
45
|
-
{ op: 'line', x: x2, y: y2 - r },
|
|
46
|
-
{ op: 'cubic', c1x: x2, c1y: y2 - r + K * r, c2x: x2 - r + K * r, c2y: y2, x: x2 - r, y: y2 },
|
|
47
|
-
{ op: 'line', x: x + r, y: y2 },
|
|
48
|
-
{ op: 'cubic', c1x: x + r - K * r, c1y: y2, c2x: x, c2y: y2 - r + K * r, x, y: y2 - r },
|
|
49
|
-
{ op: 'line', x, y: y + r },
|
|
50
|
-
{ op: 'cubic', c1x: x, c1y: y + r - K * r, c2x: x + r - K * r, c2y: y, x: x + r, y },
|
|
51
|
-
{ op: 'close' },
|
|
52
|
-
];
|
|
53
|
-
}
|
|
54
|
-
const UNIT_SEGMENTS = {
|
|
55
|
-
circle: ellipse(50, 50, 49, 49),
|
|
56
|
-
square: polygon([
|
|
57
|
-
[1, 1],
|
|
58
|
-
[99, 1],
|
|
59
|
-
[99, 99],
|
|
60
|
-
[1, 99],
|
|
61
|
-
]),
|
|
62
|
-
rounded: roundedRect(1, 1, 98, 98, 16),
|
|
63
|
-
triangle: polygon([
|
|
64
|
-
[50, 3],
|
|
65
|
-
[97, 96],
|
|
66
|
-
[3, 96],
|
|
67
|
-
]),
|
|
68
|
-
diamond: polygon([
|
|
69
|
-
[50, 2],
|
|
70
|
-
[98, 50],
|
|
71
|
-
[50, 98],
|
|
72
|
-
[2, 50],
|
|
73
|
-
]),
|
|
74
|
-
parallelogram: polygon([
|
|
75
|
-
[27, 12],
|
|
76
|
-
[98, 12],
|
|
77
|
-
[73, 88],
|
|
78
|
-
[2, 88],
|
|
79
|
-
]),
|
|
80
|
-
star: polygon([
|
|
81
|
-
[50, 3],
|
|
82
|
-
[61, 37],
|
|
83
|
-
[97, 37],
|
|
84
|
-
[68, 59],
|
|
85
|
-
[79, 95],
|
|
86
|
-
[50, 73],
|
|
87
|
-
[21, 95],
|
|
88
|
-
[32, 59],
|
|
89
|
-
[3, 37],
|
|
90
|
-
[39, 37],
|
|
91
|
-
]),
|
|
92
|
-
heart: [
|
|
93
|
-
{ op: 'move', x: 50, y: 90 },
|
|
94
|
-
{ op: 'cubic', c1x: 6, c1y: 58, c2x: 10, c2y: 20, x: 32, y: 18 },
|
|
95
|
-
{ op: 'cubic', c1x: 44, c1y: 17, c2x: 50, c2y: 27, x: 50, y: 34 },
|
|
96
|
-
{ op: 'cubic', c1x: 50, c1y: 27, c2x: 56, c2y: 17, x: 68, y: 18 },
|
|
97
|
-
{ op: 'cubic', c1x: 90, c1y: 20, c2x: 94, c2y: 58, x: 50, y: 90 },
|
|
98
|
-
{ op: 'close' },
|
|
99
|
-
],
|
|
100
|
-
cloud: [
|
|
101
|
-
{ op: 'move', x: 30, y: 80 },
|
|
102
|
-
{ op: 'cubic', c1x: 13, c1y: 80, c2x: 6, c2y: 66, x: 16, y: 56 },
|
|
103
|
-
{ op: 'cubic', c1x: 11, c1y: 42, c2x: 27, c2y: 34, x: 37, y: 42 },
|
|
104
|
-
{ op: 'cubic', c1x: 41, c1y: 24, c2x: 66, c2y: 24, x: 70, y: 42 },
|
|
105
|
-
{ op: 'cubic', c1x: 86, c1y: 38, c2x: 96, c2y: 56, x: 84, y: 68 },
|
|
106
|
-
{ op: 'cubic', c1x: 92, c1y: 78, c2x: 82, c2y: 88, x: 70, y: 84 },
|
|
107
|
-
{ op: 'close' },
|
|
108
|
-
],
|
|
109
|
-
};
|
|
110
|
-
function getMaskShapeSegments(shape, rect, rotationDeg = 0) {
|
|
111
|
-
const unit = UNIT_SEGMENTS[shape];
|
|
112
|
-
if (!unit) {
|
|
113
|
-
throw new Error(`Unknown mask shape: ${shape}`);
|
|
114
|
-
}
|
|
115
|
-
const sx = rect.width / 100;
|
|
116
|
-
const sy = rect.height / 100;
|
|
117
|
-
const tx = (x) => rect.x + x * sx;
|
|
118
|
-
const ty = (y) => rect.y + y * sy;
|
|
119
|
-
const cx = rect.x + rect.width * 0.5;
|
|
120
|
-
const cy = rect.y + rect.height * 0.5;
|
|
121
|
-
const rotate = (x, y) => rotationDeg ? (0, rotation_math_1.rotatePoint)({ x, y }, rotationDeg, { x: cx, y: cy }) : { x, y };
|
|
122
|
-
return unit.map((s) => {
|
|
123
|
-
if (s.op === 'close') {
|
|
124
|
-
return { op: 'close' };
|
|
125
|
-
}
|
|
126
|
-
if (s.op === 'cubic') {
|
|
127
|
-
const c1 = rotate(tx(s.c1x), ty(s.c1y));
|
|
128
|
-
const c2 = rotate(tx(s.c2x), ty(s.c2y));
|
|
129
|
-
const p = rotate(tx(s.x), ty(s.y));
|
|
130
|
-
return { op: 'cubic', c1x: c1.x, c1y: c1.y, c2x: c2.x, c2y: c2.y, x: p.x, y: p.y };
|
|
131
|
-
}
|
|
132
|
-
const p = rotate(tx(s.x), ty(s.y));
|
|
133
|
-
return { op: s.op, x: p.x, y: p.y };
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
function rotatedRectAABB(rect, rotationDeg) {
|
|
137
|
-
if (!rotationDeg) {
|
|
138
|
-
return Object.assign({}, rect);
|
|
139
|
-
}
|
|
140
|
-
const cx = rect.x + rect.width * 0.5;
|
|
141
|
-
const cy = rect.y + rect.height * 0.5;
|
|
142
|
-
const corners = [
|
|
143
|
-
{ x: rect.x, y: rect.y },
|
|
144
|
-
{ x: rect.x + rect.width, y: rect.y },
|
|
145
|
-
{ x: rect.x + rect.width, y: rect.y + rect.height },
|
|
146
|
-
{ x: rect.x, y: rect.y + rect.height },
|
|
147
|
-
].map((p) => (0, rotation_math_1.rotatePoint)(p, rotationDeg, { x: cx, y: cy }));
|
|
148
|
-
const xs = corners.map((p) => p.x);
|
|
149
|
-
const ys = corners.map((p) => p.y);
|
|
150
|
-
const minX = Math.min(...xs);
|
|
151
|
-
const maxX = Math.max(...xs);
|
|
152
|
-
const minY = Math.min(...ys);
|
|
153
|
-
const maxY = Math.max(...ys);
|
|
154
|
-
return { x: minX, y: minY, width: maxX - minX, height: maxY - minY };
|
|
155
|
-
}
|
|
156
|
-
function maskShapeSegmentsToSvgPath(segments) {
|
|
157
|
-
return segments
|
|
158
|
-
.map((segment) => {
|
|
159
|
-
if (segment.op === 'move') {
|
|
160
|
-
return `M ${segment.x} ${segment.y}`;
|
|
161
|
-
}
|
|
162
|
-
if (segment.op === 'line') {
|
|
163
|
-
return `L ${segment.x} ${segment.y}`;
|
|
164
|
-
}
|
|
165
|
-
if (segment.op === 'cubic') {
|
|
166
|
-
return `C ${segment.c1x} ${segment.c1y} ${segment.c2x} ${segment.c2y} ${segment.x} ${segment.y}`;
|
|
167
|
-
}
|
|
168
|
-
return 'Z';
|
|
169
|
-
})
|
|
170
|
-
.join(' ');
|
|
171
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,61 +0,0 @@
|
|
|
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
|
-
};
|