@contrail/documents 1.3.5 → 1.3.7
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/lib/document-element-property-binding-handler.js +3 -3
- package/lib/index.d.ts +2 -0
- package/lib/index.js +2 -0
- package/lib/types/common.d.ts +6 -0
- package/lib/types/common.js +7 -1
- package/lib/util/curved-line/curved-line.d.ts +12 -0
- package/lib/util/curved-line/curved-line.js +66 -0
- package/lib/util/curved-line/point.d.ts +13 -0
- package/lib/util/curved-line/point.js +47 -0
- package/package.json +1 -1
|
@@ -26,9 +26,9 @@ class DocumentElementPropertyBindingHandler {
|
|
|
26
26
|
if ((propertyValue === null || propertyValue === void 0 ? void 0 : propertyValue.name) && !isNestedPropertyAccess) {
|
|
27
27
|
const isItemObjectReference = (propertyValue === null || propertyValue === void 0 ? void 0 : propertyValue.entityType) === 'item';
|
|
28
28
|
const isItemOptionProperty = pathParts[1] === 'itemOption';
|
|
29
|
-
const isOptionReference = (
|
|
30
|
-
if (isItemObjectReference && !isItemOptionProperty && isOptionReference) {
|
|
31
|
-
propertyValue = `${propertyValue.name} - ${propertyValue.optionName
|
|
29
|
+
const isOptionReference = (_a = propertyValue === null || propertyValue === void 0 ? void 0 : propertyValue.roles) === null || _a === void 0 ? void 0 : _a.includes('option');
|
|
30
|
+
if (isItemObjectReference && !isItemOptionProperty && isOptionReference && propertyValue.optionName) {
|
|
31
|
+
propertyValue = `${propertyValue.name} - ${propertyValue.optionName}`;
|
|
32
32
|
}
|
|
33
33
|
else {
|
|
34
34
|
propertyValue = propertyValue.name;
|
package/lib/index.d.ts
CHANGED
|
@@ -6,3 +6,5 @@ export * from './document-action';
|
|
|
6
6
|
export * from './util/measure-text/measure-text';
|
|
7
7
|
export * from './util/dynamic-text/dynamic-text-util';
|
|
8
8
|
export * from './document-element-constants';
|
|
9
|
+
export * from './util/curved-line/point';
|
|
10
|
+
export * from './util/curved-line/curved-line';
|
package/lib/index.js
CHANGED
|
@@ -22,3 +22,5 @@ __exportStar(require("./document-action"), exports);
|
|
|
22
22
|
__exportStar(require("./util/measure-text/measure-text"), exports);
|
|
23
23
|
__exportStar(require("./util/dynamic-text/dynamic-text-util"), exports);
|
|
24
24
|
__exportStar(require("./document-element-constants"), exports);
|
|
25
|
+
__exportStar(require("./util/curved-line/point"), exports);
|
|
26
|
+
__exportStar(require("./util/curved-line/curved-line"), exports);
|
package/lib/types/common.d.ts
CHANGED
|
@@ -60,6 +60,11 @@ export interface PositionDefinition {
|
|
|
60
60
|
export interface RotationDefinition {
|
|
61
61
|
angle?: number;
|
|
62
62
|
}
|
|
63
|
+
export declare enum LineType {
|
|
64
|
+
STRAIGHT = 0,
|
|
65
|
+
SQUARE = 1,
|
|
66
|
+
CURVE = 2
|
|
67
|
+
}
|
|
63
68
|
export interface LineDefinition {
|
|
64
69
|
x1?: number;
|
|
65
70
|
x2?: number;
|
|
@@ -67,6 +72,7 @@ export interface LineDefinition {
|
|
|
67
72
|
y2?: number;
|
|
68
73
|
markerStart?: string;
|
|
69
74
|
markerEnd?: string;
|
|
75
|
+
lineType?: LineType;
|
|
70
76
|
}
|
|
71
77
|
export interface CropDefinition {
|
|
72
78
|
x1?: number;
|
package/lib/types/common.js
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BackgroundSizeType = void 0;
|
|
3
|
+
exports.LineType = exports.BackgroundSizeType = void 0;
|
|
4
4
|
var BackgroundSizeType;
|
|
5
5
|
(function (BackgroundSizeType) {
|
|
6
6
|
BackgroundSizeType["CONTAIN"] = "CONTAIN";
|
|
7
7
|
BackgroundSizeType["COVER"] = "COVER";
|
|
8
8
|
})(BackgroundSizeType = exports.BackgroundSizeType || (exports.BackgroundSizeType = {}));
|
|
9
|
+
var LineType;
|
|
10
|
+
(function (LineType) {
|
|
11
|
+
LineType[LineType["STRAIGHT"] = 0] = "STRAIGHT";
|
|
12
|
+
LineType[LineType["SQUARE"] = 1] = "SQUARE";
|
|
13
|
+
LineType[LineType["CURVE"] = 2] = "CURVE";
|
|
14
|
+
})(LineType = exports.LineType || (exports.LineType = {}));
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { LineDefinition } from '../../types';
|
|
2
|
+
import { Point } from './point';
|
|
3
|
+
export interface BezierCurvePointDefinition {
|
|
4
|
+
cp1: Point;
|
|
5
|
+
cp2: Point;
|
|
6
|
+
p1: Point;
|
|
7
|
+
p2: Point;
|
|
8
|
+
}
|
|
9
|
+
export declare class CurvedLine {
|
|
10
|
+
static getCurvePoints(lineDefinition: LineDefinition, points: [number, number][]): BezierCurvePointDefinition[];
|
|
11
|
+
static lerp(a: number, b: number, t: number): number;
|
|
12
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CurvedLine = void 0;
|
|
4
|
+
const point_1 = require("./point");
|
|
5
|
+
class CurvedLine {
|
|
6
|
+
static getCurvePoints(lineDefinition, points) {
|
|
7
|
+
const curves = [];
|
|
8
|
+
for (let i = 0; i <= points.length; i++) {
|
|
9
|
+
const p0 = points[i - 1];
|
|
10
|
+
const p1 = points[i];
|
|
11
|
+
const prevPoint = p0 ? new point_1.Point(p0[0], p0[1]) : new point_1.Point(lineDefinition.x1, lineDefinition.y1);
|
|
12
|
+
const point = p1 ? new point_1.Point(p1[0], p1[1]) : new point_1.Point(lineDefinition.x2, lineDefinition.y2);
|
|
13
|
+
curves.push({
|
|
14
|
+
p1: prevPoint,
|
|
15
|
+
p2: point,
|
|
16
|
+
cp1: prevPoint,
|
|
17
|
+
cp2: point,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
const interpolation = [];
|
|
21
|
+
const distance = [];
|
|
22
|
+
const r = 0.4;
|
|
23
|
+
for (let i = 0; i < curves.length; i++) {
|
|
24
|
+
const c0 = curves[i - 1];
|
|
25
|
+
const { p1, p2 } = curves[i];
|
|
26
|
+
interpolation.push(r * p1.distance(p2));
|
|
27
|
+
if (c0) {
|
|
28
|
+
const diff0 = c0.p2
|
|
29
|
+
.clone()
|
|
30
|
+
.subtract(c0.p1)
|
|
31
|
+
.normalize();
|
|
32
|
+
const diff1 = p2
|
|
33
|
+
.clone()
|
|
34
|
+
.subtract(p1)
|
|
35
|
+
.normalize();
|
|
36
|
+
const d = diff0.add(diff1).normalize();
|
|
37
|
+
distance.push(d);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
distance.unshift(new point_1.Point());
|
|
41
|
+
distance.push(new point_1.Point());
|
|
42
|
+
const interpolated = [];
|
|
43
|
+
for (let i = 0; i < curves.length; i++) {
|
|
44
|
+
const d0 = interpolation[i - 1];
|
|
45
|
+
const d1 = interpolation[i];
|
|
46
|
+
const d2 = interpolation[i + 1];
|
|
47
|
+
const i0 = d0 && d0 < d1 ? CurvedLine.lerp(d0, d1, 0.5) : d1;
|
|
48
|
+
const i1 = d2 && d2 < d1 ? CurvedLine.lerp(d1, d2, 0.5) : d1;
|
|
49
|
+
interpolated.push(i0, i1);
|
|
50
|
+
}
|
|
51
|
+
for (let i = 0; i < curves.length; i++) {
|
|
52
|
+
const i1 = interpolated[2 * i];
|
|
53
|
+
const i2 = interpolated[2 * i + 1];
|
|
54
|
+
const d1 = distance[i].clone();
|
|
55
|
+
const d2 = distance[i + 1].clone().invert();
|
|
56
|
+
const c = curves[i];
|
|
57
|
+
c.cp1 = c.p1.clone().add(d1.clone().normalize(i1));
|
|
58
|
+
c.cp2 = c.p2.clone().add(d2.clone().normalize(i2));
|
|
59
|
+
}
|
|
60
|
+
return curves;
|
|
61
|
+
}
|
|
62
|
+
static lerp(a, b, t) {
|
|
63
|
+
return a + (b - a) * t;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.CurvedLine = CurvedLine;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare class Point {
|
|
2
|
+
x: number;
|
|
3
|
+
y: number;
|
|
4
|
+
constructor(x?: number, y?: number);
|
|
5
|
+
clone(): Point;
|
|
6
|
+
magnitude(): number;
|
|
7
|
+
multiply(a: number): Point;
|
|
8
|
+
invert(): Point;
|
|
9
|
+
add(p: Point): Point;
|
|
10
|
+
subtract(p: Point): Point;
|
|
11
|
+
normalize(n?: number): Point;
|
|
12
|
+
distance(p: Point): number;
|
|
13
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Point = void 0;
|
|
4
|
+
class Point {
|
|
5
|
+
constructor(x = 0, y = 0) {
|
|
6
|
+
this.x = x;
|
|
7
|
+
this.y = y;
|
|
8
|
+
}
|
|
9
|
+
clone() {
|
|
10
|
+
return new Point(this.x, this.y);
|
|
11
|
+
}
|
|
12
|
+
magnitude() {
|
|
13
|
+
return Math.hypot(this.x, this.y);
|
|
14
|
+
}
|
|
15
|
+
multiply(a) {
|
|
16
|
+
this.x *= a;
|
|
17
|
+
this.y *= a;
|
|
18
|
+
return this;
|
|
19
|
+
}
|
|
20
|
+
invert() {
|
|
21
|
+
this.x = -this.x;
|
|
22
|
+
this.y = -this.y;
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
|
+
add(p) {
|
|
26
|
+
this.x += p.x;
|
|
27
|
+
this.y += p.y;
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
subtract(p) {
|
|
31
|
+
this.x -= p.x;
|
|
32
|
+
this.y -= p.y;
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
normalize(n) {
|
|
36
|
+
if (this.x !== 0 || this.y !== 0) {
|
|
37
|
+
const e = (n !== null && n !== void 0 ? n : 1) / this.magnitude();
|
|
38
|
+
this.x *= e;
|
|
39
|
+
this.y *= e;
|
|
40
|
+
}
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
distance(p) {
|
|
44
|
+
return Math.hypot(this.x - p.x, this.y - p.y);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.Point = Point;
|