@pacem/pacem-2d 1.0.0-abel
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/LICENSE +191 -0
- package/NOTICE +4 -0
- package/dist/browser/pacem-2d.js +2750 -0
- package/dist/browser/pacem-2d.js.map +1 -0
- package/dist/browser/pacem-2d.min.js +2 -0
- package/dist/browser/pacem-2d.min.js.map +1 -0
- package/dist/bundle/pacem-2d.min.mjs +1 -0
- package/dist/bundle/pacem-2d.mjs +2600 -0
- package/dist/bundle/pacem-2d.mjs.map +7 -0
- package/dist/esm/adapter.js +16 -0
- package/dist/esm/constants.js +2 -0
- package/dist/esm/drawable-element.js +45 -0
- package/dist/esm/drawing.js +87 -0
- package/dist/esm/ellipse.js +159 -0
- package/dist/esm/group.js +40 -0
- package/dist/esm/image.js +45 -0
- package/dist/esm/index-components-drawing.js +16 -0
- package/dist/esm/index-components.js +1 -0
- package/dist/esm/index-iife.js +3 -0
- package/dist/esm/index-root.js +1 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/line.js +55 -0
- package/dist/esm/path.js +32 -0
- package/dist/esm/polygon.js +90 -0
- package/dist/esm/polyline.js +81 -0
- package/dist/esm/rect.js +174 -0
- package/dist/esm/stage-abstractions.js +1 -0
- package/dist/esm/stage.js +366 -0
- package/dist/esm/text.js +57 -0
- package/dist/esm/types.js +140 -0
- package/package.json +38 -0
- package/typings/index.d.ts +613 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { Utils, CustomUIEvent } from '@pacem/pacem-core';
|
|
2
|
+
import { Point, Matrix2D } from '@pacem/pacem-foundation';
|
|
3
|
+
export function isDrawable(object) {
|
|
4
|
+
return !Utils.isNull(object) && 'stage' in object;
|
|
5
|
+
}
|
|
6
|
+
export function isUiObject(object) {
|
|
7
|
+
return /*'transformMatrix' in object &&*/ isDrawable(object);
|
|
8
|
+
}
|
|
9
|
+
function isGradient(object) {
|
|
10
|
+
return 'stops' in object && Utils.isArray(object.stops);
|
|
11
|
+
}
|
|
12
|
+
export function isLinearGradient(object) {
|
|
13
|
+
return isGradient(object) && 'start' in object && Point.isPoint(object.start)
|
|
14
|
+
&& 'end' in object && Point.isPoint(object.end);
|
|
15
|
+
}
|
|
16
|
+
export function isRadialGradient(object) {
|
|
17
|
+
return isGradient(object) && 'center' in object && Point.isPoint(object.center)
|
|
18
|
+
&& 'radius' in object && typeof object.radius === 'number';
|
|
19
|
+
}
|
|
20
|
+
export class PresentationState {
|
|
21
|
+
static combine(lhs, rhs, precomputedMatrix = null) {
|
|
22
|
+
return {
|
|
23
|
+
opacity: (lhs.opacity ?? 1) * (rhs.opacity ?? 1),
|
|
24
|
+
transformMatrix: precomputedMatrix ?? Matrix2D.multiply(rhs.transformMatrix, lhs.transformMatrix),
|
|
25
|
+
dashArray: lhs.dashArray ?? rhs.dashArray,
|
|
26
|
+
fill: lhs.fill ?? rhs.fill,
|
|
27
|
+
lineCap: lhs.lineCap ?? rhs.lineCap,
|
|
28
|
+
lineJoin: lhs.lineJoin ?? rhs.lineJoin,
|
|
29
|
+
lineWidth: lhs.lineWidth ?? rhs.lineWidth,
|
|
30
|
+
stroke: lhs.stroke ?? rhs.stroke
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export function isPresentationObject(object) {
|
|
35
|
+
return isUiObject(object)
|
|
36
|
+
&& ('fill' in object
|
|
37
|
+
|| 'transformMatrix' in object
|
|
38
|
+
|| 'stroke' in object
|
|
39
|
+
|| 'lineJoin' in object
|
|
40
|
+
|| 'dashArray' in object
|
|
41
|
+
|| 'lineWidth' in object
|
|
42
|
+
|| 'opacity' in object
|
|
43
|
+
|| 'lineCap' in object);
|
|
44
|
+
}
|
|
45
|
+
export function isShape(object) {
|
|
46
|
+
return isUiObject(object) && 'pathData' in object;
|
|
47
|
+
}
|
|
48
|
+
export function isGroup(object) {
|
|
49
|
+
return isUiObject(object) && 'childDrawables' in object && !Utils.isNullOrEmpty(object['childDrawables']);
|
|
50
|
+
}
|
|
51
|
+
export function isText(object) {
|
|
52
|
+
return isUiObject(object) && 'text' in object && typeof object['text'] === 'string';
|
|
53
|
+
}
|
|
54
|
+
export function isImage(object) {
|
|
55
|
+
return isUiObject(object) && 'src' in object && typeof object['src'] === 'string';
|
|
56
|
+
}
|
|
57
|
+
export class UI2DEvent extends CustomUIEvent {
|
|
58
|
+
constructor(type, eventInit, originalEvent, transformMatrix) {
|
|
59
|
+
super(type, eventInit, originalEvent);
|
|
60
|
+
this.#transformMatrix = transformMatrix;
|
|
61
|
+
}
|
|
62
|
+
#transformMatrix;
|
|
63
|
+
/** Gets the screen transform matrix. */
|
|
64
|
+
get transformMatrix() {
|
|
65
|
+
return this.#transformMatrix;
|
|
66
|
+
}
|
|
67
|
+
project(pt = { x: this.screenX, y: this.screenY }) {
|
|
68
|
+
return Matrix2D.multiply(pt, this.#transformMatrix);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
export class Shape {
|
|
72
|
+
static empty() {
|
|
73
|
+
return { pathData: '', vertices: [], boundingRect: { x: 0, y: 0, width: 0, height: 0 } };
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
export class DragEvent extends UI2DEvent {
|
|
77
|
+
}
|
|
78
|
+
export class DrawableEvent extends UI2DEvent {
|
|
79
|
+
constructor(type, args, originalEvent, m) {
|
|
80
|
+
super(type, { detail: args, bubbles: true, cancelable: true }, originalEvent, m);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
export class StageEvent extends UI2DEvent {
|
|
84
|
+
constructor(type, args, originalEvent, m = args.transformMatrix) {
|
|
85
|
+
super(type, { detail: args, bubbles: true, cancelable: true }, originalEvent, m);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var PacemEllipseElement_1, PacemCircleElement_1;
|
|
8
|
+
import { CustomElement, Watch, PropertyConverters, P, Utils } from '@pacem/pacem-core';
|
|
9
|
+
import { Rect } from '@pacem/pacem-foundation';
|
|
10
|
+
import { ShapeElement } from './types';
|
|
11
|
+
import { TAG_MIDDLE_NAME } from './constants';
|
|
12
|
+
//namespace Pacem.Components.Drawing {
|
|
13
|
+
function full(c, rx, ry) {
|
|
14
|
+
const d = 2 * rx, cx = c.x, cy = c.y;
|
|
15
|
+
return {
|
|
16
|
+
pathData: `M ${cx} ${cy} m ${-rx},0 a ${rx},${ry} 0 1,1 ${d},0 a ${rx},${ry} 0 1,1 ${-d},0`,
|
|
17
|
+
vertices: [],
|
|
18
|
+
boundingRect: { x: cx - rx, y: cy - ry, width: 2 * rx, height: 2 * ry }
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function sect(c, rx, ry, start, end) {
|
|
22
|
+
const degToRad = Math.PI / 180;
|
|
23
|
+
const s = degToRad * start, e = degToRad * end;
|
|
24
|
+
//
|
|
25
|
+
const polar = (theta) => rx * ry / Math.sqrt(Math.pow(Math.cos(theta) * ry, 2) + Math.pow(Math.sin(theta) * rx, 2));
|
|
26
|
+
const rhoStart = polar(s), rhoEnd = polar(e);
|
|
27
|
+
const cartesian = (rho, theta) => {
|
|
28
|
+
return { x: rho * Math.cos(theta), y: rho * Math.sin(theta) };
|
|
29
|
+
};
|
|
30
|
+
const cartStart = cartesian(rhoStart, s), cartEnd = cartesian(rhoEnd, e);
|
|
31
|
+
const p0 = { x: c.x + cartStart.x, y: c.y + cartStart.y }, p1 = { x: c.x + cartEnd.x, y: c.y + cartEnd.y };
|
|
32
|
+
let boundingRect = Rect.expand(c, p0, p1);
|
|
33
|
+
if (end < start)
|
|
34
|
+
end += 360;
|
|
35
|
+
if (start <= 0 && end > 0 || end >= 360) {
|
|
36
|
+
boundingRect = Rect.expand(boundingRect, { x: c.x + rx, y: c.y });
|
|
37
|
+
}
|
|
38
|
+
if (start <= 90 && end > 90 || end >= 450) {
|
|
39
|
+
boundingRect = Rect.expand(boundingRect, { x: c.x, y: c.y + ry });
|
|
40
|
+
}
|
|
41
|
+
if (start <= 180 && end > 180 || end >= 540) {
|
|
42
|
+
boundingRect = Rect.expand(boundingRect, { x: c.x - rx, y: c.y });
|
|
43
|
+
}
|
|
44
|
+
if (start <= 270 && end > 270 || end >= 630) {
|
|
45
|
+
boundingRect = Rect.expand(boundingRect, { x: c.x, y: c.y - ry });
|
|
46
|
+
}
|
|
47
|
+
const flag = e - s > Math.PI ? '1' : '0';
|
|
48
|
+
return {
|
|
49
|
+
pathData: `M ${p0.x} ${p0.y} A ${rx},${ry} 0 ${flag},1 ${p1.x},${p1.y} L ${c.x},${c.y} Z`, vertices: [p0, p1], boundingRect
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function getShapeGeometry(c, rx, ry, start, end) {
|
|
53
|
+
start ??= 0, end ??= 0;
|
|
54
|
+
start %= 360;
|
|
55
|
+
end %= 360;
|
|
56
|
+
while (start < 0)
|
|
57
|
+
start += 360;
|
|
58
|
+
while (end < start)
|
|
59
|
+
end += 360;
|
|
60
|
+
const threesixty = (start - end).isCloseTo(0);
|
|
61
|
+
return threesixty ? full(c, rx, ry) : sect(c, rx, ry, start, end);
|
|
62
|
+
}
|
|
63
|
+
let PacemEllipseElement = PacemEllipseElement_1 = class PacemEllipseElement extends ShapeElement {
|
|
64
|
+
propertyChangedCallback(name, old, val, first) {
|
|
65
|
+
super.propertyChangedCallback(name, old, val, first);
|
|
66
|
+
if (!first) {
|
|
67
|
+
switch (name) {
|
|
68
|
+
case 'center':
|
|
69
|
+
case 'rx':
|
|
70
|
+
case 'ry':
|
|
71
|
+
case 'start':
|
|
72
|
+
case 'end':
|
|
73
|
+
this.recomputeShape();
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
getPathData() {
|
|
79
|
+
const a = this.rx, b = this.ry, c = this.center, s = this.start ?? 0, e = this.end ?? 0;
|
|
80
|
+
if (!Utils.isNull(c) && !Utils.isNull(a) && !Utils.isNull(b)) {
|
|
81
|
+
return PacemEllipseElement_1.getPathData(c, a, b, s, e);
|
|
82
|
+
}
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
getShapeGeometry() {
|
|
86
|
+
const center = this.center ?? { x: 0, y: 0 };
|
|
87
|
+
const a = this.rx ?? 0, b = this.ry ?? 0;
|
|
88
|
+
return getShapeGeometry(center, a, b, this.start, this.end);
|
|
89
|
+
}
|
|
90
|
+
static getPathData(c = { x: NaN, y: NaN }, rx = NaN, ry = NaN, start, end) {
|
|
91
|
+
const { pathData } = getShapeGeometry(c, rx, ry, start, end);
|
|
92
|
+
return pathData;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
__decorate([
|
|
96
|
+
Watch({ emit: false, converter: PropertyConverters.Point })
|
|
97
|
+
], PacemEllipseElement.prototype, "center", void 0);
|
|
98
|
+
__decorate([
|
|
99
|
+
Watch({ emit: false, converter: PropertyConverters.Number })
|
|
100
|
+
], PacemEllipseElement.prototype, "rx", void 0);
|
|
101
|
+
__decorate([
|
|
102
|
+
Watch({ emit: false, converter: PropertyConverters.Number })
|
|
103
|
+
], PacemEllipseElement.prototype, "ry", void 0);
|
|
104
|
+
__decorate([
|
|
105
|
+
Watch({ emit: false, converter: PropertyConverters.Number })
|
|
106
|
+
], PacemEllipseElement.prototype, "start", void 0);
|
|
107
|
+
__decorate([
|
|
108
|
+
Watch({ emit: false, converter: PropertyConverters.Number })
|
|
109
|
+
], PacemEllipseElement.prototype, "end", void 0);
|
|
110
|
+
PacemEllipseElement = PacemEllipseElement_1 = __decorate([
|
|
111
|
+
CustomElement({ tagName: P + '-' + TAG_MIDDLE_NAME + '-ellipse' })
|
|
112
|
+
], PacemEllipseElement);
|
|
113
|
+
export { PacemEllipseElement };
|
|
114
|
+
let PacemCircleElement = PacemCircleElement_1 = class PacemCircleElement extends ShapeElement {
|
|
115
|
+
propertyChangedCallback(name, old, val, first) {
|
|
116
|
+
super.propertyChangedCallback(name, old, val, first);
|
|
117
|
+
if (!first) {
|
|
118
|
+
switch (name) {
|
|
119
|
+
case 'center':
|
|
120
|
+
case 'radius':
|
|
121
|
+
case 'start':
|
|
122
|
+
case 'end':
|
|
123
|
+
this.recomputeShape();
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
getPathData() {
|
|
129
|
+
const r = this.radius, c = this.center;
|
|
130
|
+
if (!Utils.isNull(c) && !Utils.isNull(r)) {
|
|
131
|
+
return PacemCircleElement_1.getPathData(c, r, this.start, this.end);
|
|
132
|
+
}
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
getShapeGeometry() {
|
|
136
|
+
const center = this.center ?? { x: 0, y: 0 };
|
|
137
|
+
const r = this.radius ?? 0;
|
|
138
|
+
return getShapeGeometry(center, r, r, this.start, this.end);
|
|
139
|
+
}
|
|
140
|
+
static getPathData(c = { x: NaN, y: NaN }, r = NaN, start, end) {
|
|
141
|
+
return PacemEllipseElement.getPathData(c, r, r, start, end);
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
__decorate([
|
|
145
|
+
Watch({ emit: false, converter: PropertyConverters.Point })
|
|
146
|
+
], PacemCircleElement.prototype, "center", void 0);
|
|
147
|
+
__decorate([
|
|
148
|
+
Watch({ emit: false, converter: PropertyConverters.Number })
|
|
149
|
+
], PacemCircleElement.prototype, "radius", void 0);
|
|
150
|
+
__decorate([
|
|
151
|
+
Watch({ emit: false, converter: PropertyConverters.Number })
|
|
152
|
+
], PacemCircleElement.prototype, "start", void 0);
|
|
153
|
+
__decorate([
|
|
154
|
+
Watch({ emit: false, converter: PropertyConverters.Number })
|
|
155
|
+
], PacemCircleElement.prototype, "end", void 0);
|
|
156
|
+
PacemCircleElement = PacemCircleElement_1 = __decorate([
|
|
157
|
+
CustomElement({ tagName: P + '-' + TAG_MIDDLE_NAME + '-circle' })
|
|
158
|
+
], PacemCircleElement);
|
|
159
|
+
export { PacemCircleElement };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { CustomElement, Watch, P, Utils } from '@pacem/pacem-core';
|
|
8
|
+
import { PresentationElement } from './types';
|
|
9
|
+
import { TAG_MIDDLE_NAME } from './constants';
|
|
10
|
+
import { DrawableElement } from './drawable-element';
|
|
11
|
+
//namespace Pacem.Components.Drawing {
|
|
12
|
+
let PacemGroupElement = class PacemGroupElement extends PresentationElement {
|
|
13
|
+
validate(item) {
|
|
14
|
+
return item instanceof DrawableElement && item.parent === this;
|
|
15
|
+
}
|
|
16
|
+
#children = [];
|
|
17
|
+
get childDrawables() {
|
|
18
|
+
return this.#children;
|
|
19
|
+
}
|
|
20
|
+
propertyChangedCallback(name, old, val, first) {
|
|
21
|
+
super.propertyChangedCallback(name, old, val, first);
|
|
22
|
+
switch (name) {
|
|
23
|
+
case 'items':
|
|
24
|
+
case 'datasource':
|
|
25
|
+
this.#children = (val || []);
|
|
26
|
+
const scene = this.stage;
|
|
27
|
+
if (!Utils.isNull(scene)) {
|
|
28
|
+
scene.draw(this, true);
|
|
29
|
+
}
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
__decorate([
|
|
35
|
+
Watch({ emit: false })
|
|
36
|
+
], PacemGroupElement.prototype, "datasource", void 0);
|
|
37
|
+
PacemGroupElement = __decorate([
|
|
38
|
+
CustomElement({ tagName: P + '-' + TAG_MIDDLE_NAME + '-group' })
|
|
39
|
+
], PacemGroupElement);
|
|
40
|
+
export { PacemGroupElement };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { CustomElement, Watch, PropertyConverters, P } from '@pacem/pacem-core';
|
|
8
|
+
import { UiElement } from './types';
|
|
9
|
+
import { TAG_MIDDLE_NAME } from './constants';
|
|
10
|
+
//namespace Pacem.Components.Drawing {
|
|
11
|
+
let PacemImageElement = class PacemImageElement extends UiElement {
|
|
12
|
+
propertyChangedCallback(name, old, val, first) {
|
|
13
|
+
super.propertyChangedCallback(name, old, val, first);
|
|
14
|
+
if (!first) {
|
|
15
|
+
switch (name) {
|
|
16
|
+
case 'src':
|
|
17
|
+
case 'x':
|
|
18
|
+
case 'y':
|
|
19
|
+
case 'width':
|
|
20
|
+
case 'height':
|
|
21
|
+
this.stage?.draw(this);
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
__decorate([
|
|
28
|
+
Watch({ emit: false, converter: PropertyConverters.String })
|
|
29
|
+
], PacemImageElement.prototype, "src", void 0);
|
|
30
|
+
__decorate([
|
|
31
|
+
Watch({ emit: false, converter: PropertyConverters.Number })
|
|
32
|
+
], PacemImageElement.prototype, "x", void 0);
|
|
33
|
+
__decorate([
|
|
34
|
+
Watch({ emit: false, converter: PropertyConverters.Number })
|
|
35
|
+
], PacemImageElement.prototype, "y", void 0);
|
|
36
|
+
__decorate([
|
|
37
|
+
Watch({ emit: false, converter: PropertyConverters.Number })
|
|
38
|
+
], PacemImageElement.prototype, "width", void 0);
|
|
39
|
+
__decorate([
|
|
40
|
+
Watch({ emit: false, converter: PropertyConverters.Number })
|
|
41
|
+
], PacemImageElement.prototype, "height", void 0);
|
|
42
|
+
PacemImageElement = __decorate([
|
|
43
|
+
CustomElement({ tagName: P + '-' + TAG_MIDDLE_NAME + '-image' })
|
|
44
|
+
], PacemImageElement);
|
|
45
|
+
export { PacemImageElement };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export * from './drawable-element';
|
|
2
|
+
export * from './stage-abstractions';
|
|
3
|
+
export * from './types';
|
|
4
|
+
export * from './group';
|
|
5
|
+
export * from './ellipse';
|
|
6
|
+
export * from './rect';
|
|
7
|
+
export * from './line';
|
|
8
|
+
export * from './path';
|
|
9
|
+
export * from './polygon';
|
|
10
|
+
export * from './polyline';
|
|
11
|
+
export * from './image';
|
|
12
|
+
export * from './text';
|
|
13
|
+
export * from './stage';
|
|
14
|
+
export * from './adapters/utils';
|
|
15
|
+
export * from './adapters/canvasadapter';
|
|
16
|
+
export * from './adapters/svgadapter';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as Drawing from './index-components-drawing';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as Drawing from './drawing';
|
package/dist/esm/line.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var PacemLineElement_1;
|
|
8
|
+
import { CustomElement, Watch, PropertyConverters, P, Utils } from '@pacem/pacem-core';
|
|
9
|
+
import { ShapeElement } from './types';
|
|
10
|
+
import { TAG_MIDDLE_NAME } from './constants';
|
|
11
|
+
import { Shape } from './drawing';
|
|
12
|
+
//namespace Pacem.Components.Drawing {
|
|
13
|
+
let PacemLineElement = PacemLineElement_1 = class PacemLineElement extends ShapeElement {
|
|
14
|
+
propertyChangedCallback(name, old, val, first) {
|
|
15
|
+
super.propertyChangedCallback(name, old, val, first);
|
|
16
|
+
if (!first) {
|
|
17
|
+
switch (name) {
|
|
18
|
+
case 'from':
|
|
19
|
+
case 'to':
|
|
20
|
+
this.recomputeShape();
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
getShapeGeometry() {
|
|
26
|
+
const from = this.from, to = this.to;
|
|
27
|
+
if (Utils.isNull(from) || Utils.isNull(to)) {
|
|
28
|
+
return Shape.empty();
|
|
29
|
+
}
|
|
30
|
+
const x0 = from.x, y0 = from.y, x1 = to.x, y1 = to.y;
|
|
31
|
+
const boundingRect = { x: Math.min(x0, x1), y: Math.min(y0, y1), width: Math.abs(x0 - x1), height: Math.abs(y0 - y1) };
|
|
32
|
+
return { pathData: this.getPathData(), vertices: [from, to], boundingRect };
|
|
33
|
+
}
|
|
34
|
+
getPathData() {
|
|
35
|
+
const from = this.from, to = this.to;
|
|
36
|
+
if (!Utils.isNull(from) && !Utils.isNull(to)) {
|
|
37
|
+
return PacemLineElement_1.getPathData(from, to);
|
|
38
|
+
}
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
static getPathData(from = { x: NaN, y: NaN }, to = { x: NaN, y: NaN }) {
|
|
42
|
+
const x0 = from.x, y0 = from.y, x1 = to.x, y1 = to.y;
|
|
43
|
+
return `M ${x0} ${y0} L ${x1} ${y1}`;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
__decorate([
|
|
47
|
+
Watch({ emit: false, converter: PropertyConverters.Point })
|
|
48
|
+
], PacemLineElement.prototype, "from", void 0);
|
|
49
|
+
__decorate([
|
|
50
|
+
Watch({ emit: false, converter: PropertyConverters.Point })
|
|
51
|
+
], PacemLineElement.prototype, "to", void 0);
|
|
52
|
+
PacemLineElement = PacemLineElement_1 = __decorate([
|
|
53
|
+
CustomElement({ tagName: P + '-' + TAG_MIDDLE_NAME + '-line' })
|
|
54
|
+
], PacemLineElement);
|
|
55
|
+
export { PacemLineElement };
|
package/dist/esm/path.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { CustomElement, Watch, PropertyConverters, P } from '@pacem/pacem-core';
|
|
8
|
+
import { ShapeElement } from './types';
|
|
9
|
+
import { TAG_MIDDLE_NAME } from './constants';
|
|
10
|
+
//namespace Pacem.Components.Drawing {
|
|
11
|
+
let PacemPathElement = class PacemPathElement extends ShapeElement {
|
|
12
|
+
constructor() {
|
|
13
|
+
super(...arguments);
|
|
14
|
+
this.getPathData = () => this.d;
|
|
15
|
+
}
|
|
16
|
+
propertyChangedCallback(name, old, val, first) {
|
|
17
|
+
super.propertyChangedCallback(name, old, val, first);
|
|
18
|
+
if (name === 'd' && !first) {
|
|
19
|
+
this.recomputeShape();
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
getShapeGeometry() {
|
|
23
|
+
return { pathData: this.getPathData(), /* TODO: parse d */ boundingRect: null, vertices: [] };
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
__decorate([
|
|
27
|
+
Watch({ emit: false, converter: PropertyConverters.String })
|
|
28
|
+
], PacemPathElement.prototype, "d", void 0);
|
|
29
|
+
PacemPathElement = __decorate([
|
|
30
|
+
CustomElement({ tagName: P + '-' + TAG_MIDDLE_NAME + '-path' })
|
|
31
|
+
], PacemPathElement);
|
|
32
|
+
export { PacemPathElement };
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var PacemPolygonElement_1;
|
|
8
|
+
import { CustomElement, Watch, PropertyConverters, P, Utils } from '@pacem/pacem-core';
|
|
9
|
+
import { ShapeElement } from './types';
|
|
10
|
+
import { TAG_MIDDLE_NAME } from './constants';
|
|
11
|
+
import { Shape } from './drawing';
|
|
12
|
+
//namespace Pacem.Components.Drawing {
|
|
13
|
+
let PacemPolygonElement = PacemPolygonElement_1 = class PacemPolygonElement extends ShapeElement {
|
|
14
|
+
propertyChangedCallback(name, old, val, first) {
|
|
15
|
+
super.propertyChangedCallback(name, old, val, first);
|
|
16
|
+
if (!first) {
|
|
17
|
+
switch (name) {
|
|
18
|
+
case 'radius':
|
|
19
|
+
case 'starIndent':
|
|
20
|
+
case 'sides':
|
|
21
|
+
this.recomputeShape();
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
getPathData() {
|
|
27
|
+
const sides = this.sides, radius = this.radius, center = this.center;
|
|
28
|
+
if (!Utils.isNull(sides) && !Utils.isNull(radius)) {
|
|
29
|
+
return PacemPolygonElement_1.getPathData(center, radius, sides, this.starIndent);
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
getShapeGeometry() {
|
|
34
|
+
const c = this.center ?? { x: 0, y: 0 }, r = this.radius ?? 0, sides = this.sides ?? 3, si = this.starIndent;
|
|
35
|
+
if (sides < 3) {
|
|
36
|
+
return Shape.empty();
|
|
37
|
+
}
|
|
38
|
+
return PacemPolygonElement_1.getShapeGeometry(c, r, sides, si);
|
|
39
|
+
}
|
|
40
|
+
static getShapeGeometry(center, radius, sides, starIndent = .0) {
|
|
41
|
+
const p0 = { x: center.x, y: center.y - radius };
|
|
42
|
+
let retval = `M ${p0.x} ${(p0.y)}`;
|
|
43
|
+
const vertices = [p0];
|
|
44
|
+
const theta = 2 * Math.PI / sides, theta2 = .5 * theta, isStar = starIndent > 0, apothem = radius * Math.cos(theta2);
|
|
45
|
+
for (let j = 1; j < sides; j++) {
|
|
46
|
+
const angle = j * theta, x = center.x + Math.sin(angle) * radius, y = center.y - Math.cos(angle) * radius;
|
|
47
|
+
if (isStar) {
|
|
48
|
+
const innerRadius = apothem * (1.0 - starIndent);
|
|
49
|
+
const angle2 = angle - theta2, x1 = center.x + Math.sin(angle2) * innerRadius, y1 = center.y - Math.cos(angle2) * innerRadius;
|
|
50
|
+
retval += ` L ${x1} ${y1} L ${x} ${y}`;
|
|
51
|
+
vertices.push({ x: x1, y: y1 });
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
retval += ` L ${x} ${y}`;
|
|
55
|
+
}
|
|
56
|
+
vertices.push({ x, y });
|
|
57
|
+
}
|
|
58
|
+
if (isStar) {
|
|
59
|
+
const innerRadius = apothem * (1.0 - starIndent);
|
|
60
|
+
const angle2 = 2 * Math.PI - theta2, x1 = center.x + Math.sin(angle2) * innerRadius, y1 = center.y - Math.cos(angle2) * innerRadius;
|
|
61
|
+
retval += ` L ${x1} ${y1}`;
|
|
62
|
+
vertices.push({ x: x1, y: y1 });
|
|
63
|
+
}
|
|
64
|
+
vertices.push(p0);
|
|
65
|
+
const width = radius * 2;
|
|
66
|
+
return {
|
|
67
|
+
pathData: retval + ' Z', vertices, boundingRect: { x: p0.x - radius, y: p0.y, width, height: width }
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
static getPathData(center, radius, sides, starIndent = .0) {
|
|
71
|
+
const { pathData } = PacemPolygonElement_1.getShapeGeometry(center, radius, sides, starIndent);
|
|
72
|
+
return pathData;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
__decorate([
|
|
76
|
+
Watch({ emit: false, converter: PropertyConverters.Number })
|
|
77
|
+
], PacemPolygonElement.prototype, "sides", void 0);
|
|
78
|
+
__decorate([
|
|
79
|
+
Watch({ emit: false, converter: PropertyConverters.Number })
|
|
80
|
+
], PacemPolygonElement.prototype, "radius", void 0);
|
|
81
|
+
__decorate([
|
|
82
|
+
Watch({ emit: false, converter: PropertyConverters.Point })
|
|
83
|
+
], PacemPolygonElement.prototype, "center", void 0);
|
|
84
|
+
__decorate([
|
|
85
|
+
Watch({ emit: false, converter: PropertyConverters.Number })
|
|
86
|
+
], PacemPolygonElement.prototype, "starIndent", void 0);
|
|
87
|
+
PacemPolygonElement = PacemPolygonElement_1 = __decorate([
|
|
88
|
+
CustomElement({ tagName: P + '-' + TAG_MIDDLE_NAME + '-polygon' })
|
|
89
|
+
], PacemPolygonElement);
|
|
90
|
+
export { PacemPolygonElement };
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var PacemPolylineElement_1;
|
|
8
|
+
import { CustomElement, Watch, PropertyConverters, P, Utils } from '@pacem/pacem-core';
|
|
9
|
+
import { parseAsNumericalArray } from '@pacem/pacem-foundation';
|
|
10
|
+
import { ShapeElement } from './types';
|
|
11
|
+
import { TAG_MIDDLE_NAME } from './constants';
|
|
12
|
+
import { Shape } from './drawing';
|
|
13
|
+
//namespace Pacem.Components.Drawing {
|
|
14
|
+
const PointArrayOrJsonConverter = {
|
|
15
|
+
convert: (attr) => {
|
|
16
|
+
const arr = parseAsNumericalArray(attr);
|
|
17
|
+
if (arr.length % 2 === 0) {
|
|
18
|
+
const retval = [];
|
|
19
|
+
for (let j = 0; j < arr.length; j += 2) {
|
|
20
|
+
retval.push({ x: arr[j], y: arr[j + 1] });
|
|
21
|
+
}
|
|
22
|
+
return retval;
|
|
23
|
+
}
|
|
24
|
+
return JSON.parse(attr);
|
|
25
|
+
},
|
|
26
|
+
convertBack: (prop) => JSON.stringify(prop)
|
|
27
|
+
};
|
|
28
|
+
let PacemPolylineElement = PacemPolylineElement_1 = class PacemPolylineElement extends ShapeElement {
|
|
29
|
+
propertyChangedCallback(name, old, val, first) {
|
|
30
|
+
super.propertyChangedCallback(name, old, val, first);
|
|
31
|
+
if (!first) {
|
|
32
|
+
switch (name) {
|
|
33
|
+
case 'points':
|
|
34
|
+
case 'closed':
|
|
35
|
+
this.recomputeShape();
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
static getShapeGeometry(points, closed) {
|
|
41
|
+
if (Utils.isNullOrEmpty(points)) {
|
|
42
|
+
return Shape.empty();
|
|
43
|
+
}
|
|
44
|
+
let d = '';
|
|
45
|
+
let xmin = Number.MAX_VALUE, ymin = Number.MAX_VALUE, xmax = Number.MIN_VALUE, ymax = Number.MIN_VALUE;
|
|
46
|
+
for (let j = 0; j < points.length; j++) {
|
|
47
|
+
const { x, y } = points[j];
|
|
48
|
+
d += `${(j === 0 ? 'M' : 'L')} ${x} ${y} `;
|
|
49
|
+
xmin = Math.min(xmin, x);
|
|
50
|
+
xmax = Math.max(xmax, x);
|
|
51
|
+
ymin = Math.min(ymin, y);
|
|
52
|
+
ymax = Math.max(ymax, y);
|
|
53
|
+
}
|
|
54
|
+
const boundingRect = { x: xmin, y: ymin, width: xmax - xmin, height: ymax - ymin };
|
|
55
|
+
if (closed) {
|
|
56
|
+
d += 'Z';
|
|
57
|
+
}
|
|
58
|
+
return { pathData: d, vertices: points, boundingRect };
|
|
59
|
+
}
|
|
60
|
+
getShapeGeometry() {
|
|
61
|
+
return PacemPolylineElement_1.getShapeGeometry(this.points, this.closed);
|
|
62
|
+
}
|
|
63
|
+
getPathData() {
|
|
64
|
+
const { pathData } = this.getShapeGeometry();
|
|
65
|
+
return pathData;
|
|
66
|
+
}
|
|
67
|
+
static getPathData(points, closed) {
|
|
68
|
+
const { pathData } = PacemPolylineElement_1.getShapeGeometry(points, closed);
|
|
69
|
+
return pathData;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
__decorate([
|
|
73
|
+
Watch({ emit: false, converter: PointArrayOrJsonConverter })
|
|
74
|
+
], PacemPolylineElement.prototype, "points", void 0);
|
|
75
|
+
__decorate([
|
|
76
|
+
Watch({ emit: false, converter: PropertyConverters.Boolean })
|
|
77
|
+
], PacemPolylineElement.prototype, "closed", void 0);
|
|
78
|
+
PacemPolylineElement = PacemPolylineElement_1 = __decorate([
|
|
79
|
+
CustomElement({ tagName: P + '-' + TAG_MIDDLE_NAME + '-polyline' })
|
|
80
|
+
], PacemPolylineElement);
|
|
81
|
+
export { PacemPolylineElement };
|