@pacem/pacem-2d 1.0.0-bessel → 1.0.0-dirac
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/dist/browser/pacem-2d.js +149 -2
- package/dist/browser/pacem-2d.js.map +1 -1
- package/dist/browser/pacem-2d.min.js +1 -1
- package/dist/bundle/pacem-2d.min.mjs +1 -1
- package/dist/bundle/pacem-2d.mjs +71 -1
- package/dist/bundle/pacem-2d.mjs.map +2 -2
- package/dist/docs/pacem-2d.json +11549 -0
- package/dist/esm/adapter.js +15 -1
- package/dist/esm/constants.js +3 -1
- package/dist/esm/drawable-element.js +8 -1
- package/dist/esm/drawing.js +28 -1
- package/dist/esm/ellipse.js +20 -1
- package/dist/esm/group.js +3 -1
- package/dist/esm/image.js +2 -1
- package/dist/esm/index-components-drawing.js +1 -1
- package/dist/esm/index-components.js +1 -1
- package/dist/esm/index-iife.js +1 -1
- package/dist/esm/index-root.js +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/line.js +4 -1
- package/dist/esm/path.js +3 -1
- package/dist/esm/polygon.js +11 -1
- package/dist/esm/polyline.js +10 -1
- package/dist/esm/rect.js +4 -1
- package/dist/esm/stage-abstractions.js +1 -1
- package/dist/esm/stage.js +14 -1
- package/dist/esm/text.js +2 -1
- package/dist/esm/types.js +18 -1
- package/package.json +2 -1
- package/typings/index.d.ts +236 -1
package/dist/esm/adapter.js
CHANGED
|
@@ -1,19 +1,33 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @pacem/pacem-2d v1.0.0-
|
|
2
|
+
* @pacem/pacem-2d v1.0.0-dirac (https://js.pacem.it)
|
|
3
3
|
* Pacem (https://pacem.it)
|
|
4
4
|
* Licensed under Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
import { PacemEventTarget, Utils } from '@pacem/pacem-core';
|
|
7
7
|
const JPEG_QUALITY = .9;
|
|
8
|
+
/**
|
|
9
|
+
* Base class for the rendering adapters (SVG, Canvas) assignable to a `Pacem2DElement` stage. Concrete
|
|
10
|
+
* adapters are responsible for initializing/disposing the underlying DOM surface, sizing it, drawing the
|
|
11
|
+
* scene graph, hit-testing and producing snapshot images.
|
|
12
|
+
*/
|
|
8
13
|
export class Pacem2DAdapterElement extends PacemEventTarget {
|
|
9
14
|
constructor() {
|
|
10
15
|
super(...arguments);
|
|
16
|
+
/** Fallback stroke/fill/lineWidth values used when a shape doesn't provide its own. */
|
|
11
17
|
this.DefaultShapeValues = {
|
|
12
18
|
stroke: "#000",
|
|
13
19
|
lineWidth: 1,
|
|
14
20
|
fill: "#fff"
|
|
15
21
|
};
|
|
16
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Rasterizes the given DOM element into an image `Blob`, defaulting to JPEG when `bgColor` is provided
|
|
25
|
+
* (to flatten transparency against it) and to PNG otherwise.
|
|
26
|
+
* @param element Element to snapshot.
|
|
27
|
+
* @param bgColor Background color to flatten transparency against; if set, defaults `type` to `'image/jpeg'`.
|
|
28
|
+
* @param type Explicit image MIME type, overrides the `bgColor`-based default.
|
|
29
|
+
* @param quality Compression quality, applicable to lossy formats (defaults to `.9` for JPEG).
|
|
30
|
+
*/
|
|
17
31
|
snapshotElement(element, bgColor, type, quality) {
|
|
18
32
|
const jpeg = !Utils.isNullOrEmpty(bgColor), mime = type ?? (jpeg ? 'image/jpeg' : null), compression = quality ?? (jpeg ? JPEG_QUALITY : null);
|
|
19
33
|
return Utils.snapshotElement(element, bgColor, mime, compression);
|
package/dist/esm/constants.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @pacem/pacem-2d v1.0.0-
|
|
2
|
+
* @pacem/pacem-2d v1.0.0-dirac (https://js.pacem.it)
|
|
3
3
|
* Pacem (https://pacem.it)
|
|
4
4
|
* Licensed under Apache-2.0
|
|
5
5
|
*/
|
|
6
|
+
/** Middle segment shared by every `<pacem-2d-*>` custom element tag name. */
|
|
6
7
|
export const TAG_MIDDLE_NAME = "2d";
|
|
8
|
+
/** `2 * Math.PI`, a full turn in radians. */
|
|
7
9
|
export const TWO_PI = 2 * Math.PI;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @pacem/pacem-2d v1.0.0-
|
|
2
|
+
* @pacem/pacem-2d v1.0.0-dirac (https://js.pacem.it)
|
|
3
3
|
* Pacem (https://pacem.it)
|
|
4
4
|
* Licensed under Apache-2.0
|
|
5
5
|
*/
|
|
@@ -11,6 +11,11 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
11
11
|
};
|
|
12
12
|
import { Components, CustomElementUtils, PropertyConverters, Watch, } from '@pacem/pacem-core';
|
|
13
13
|
import { Pacem2DElement } from './stage';
|
|
14
|
+
/**
|
|
15
|
+
* Root of the `<pacem-2d-*>` drawable elements hierarchy: wires a custom element up to its containing
|
|
16
|
+
* `Pacem2DElement` stage and, in case of nesting, its parent drawable. By default children are not allowed
|
|
17
|
+
* (only `PacemGroupElement` overrides `validate` to accept them).
|
|
18
|
+
*/
|
|
14
19
|
export class DrawableElement extends Components.PacemCrossItemsContainerElement {
|
|
15
20
|
validate(_) {
|
|
16
21
|
// by default no children allowed (Group will except)
|
|
@@ -20,9 +25,11 @@ export class DrawableElement extends Components.PacemCrossItemsContainerElement
|
|
|
20
25
|
// override
|
|
21
26
|
return this.parent || this.stage;
|
|
22
27
|
}
|
|
28
|
+
/** @readonly Gets the `Pacem2DElement` stage this drawable belongs to. */
|
|
23
29
|
get stage() {
|
|
24
30
|
return this['_scene'] = this['_scene'] || CustomElementUtils.findAncestorOfType(this, Pacem2DElement);
|
|
25
31
|
}
|
|
32
|
+
/** @readonly Gets the closest ancestor `DrawableElement` (e.g. a containing group), if any. */
|
|
26
33
|
get parent() {
|
|
27
34
|
return this['_drawableParent'] = this['_drawableParent'] || CustomElementUtils.findAncestor(this, i => i instanceof DrawableElement);
|
|
28
35
|
}
|
package/dist/esm/drawing.js
CHANGED
|
@@ -1,28 +1,40 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @pacem/pacem-2d v1.0.0-
|
|
2
|
+
* @pacem/pacem-2d v1.0.0-dirac (https://js.pacem.it)
|
|
3
3
|
* Pacem (https://pacem.it)
|
|
4
4
|
* Licensed under Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
import { Utils, CustomUIEvent } from '@pacem/pacem-core';
|
|
7
7
|
import { Point, Matrix2D } from '@pacem/pacem-foundation';
|
|
8
|
+
/** Type guard telling whether `object` implements `Drawable`. */
|
|
8
9
|
export function isDrawable(object) {
|
|
9
10
|
return !Utils.isNull(object) && 'stage' in object;
|
|
10
11
|
}
|
|
12
|
+
/** Type guard telling whether `object` implements `UiObject`. */
|
|
11
13
|
export function isUiObject(object) {
|
|
12
14
|
return /*'transformMatrix' in object &&*/ isDrawable(object);
|
|
13
15
|
}
|
|
14
16
|
function isGradient(object) {
|
|
15
17
|
return 'stops' in object && Utils.isArray(object.stops);
|
|
16
18
|
}
|
|
19
|
+
/** Type guard telling whether `object` is a `LinearGradient`. */
|
|
17
20
|
export function isLinearGradient(object) {
|
|
18
21
|
return isGradient(object) && 'start' in object && Point.isPoint(object.start)
|
|
19
22
|
&& 'end' in object && Point.isPoint(object.end);
|
|
20
23
|
}
|
|
24
|
+
/** Type guard telling whether `object` is a `RadialGradient`. */
|
|
21
25
|
export function isRadialGradient(object) {
|
|
22
26
|
return isGradient(object) && 'center' in object && Point.isPoint(object.center)
|
|
23
27
|
&& 'radius' in object && typeof object.radius === 'number';
|
|
24
28
|
}
|
|
29
|
+
/** Static helpers to combine `PresentationState` instances (e.g. a shape's own state with its inherited parent state). */
|
|
25
30
|
export class PresentationState {
|
|
31
|
+
/**
|
|
32
|
+
* Combines two presentation states (typically an item's own state and the one inherited from its
|
|
33
|
+
* ancestors), giving precedence to `lhs` whenever both define a value.
|
|
34
|
+
* @param lhs Own/most specific presentation state.
|
|
35
|
+
* @param rhs Inherited/fallback presentation state.
|
|
36
|
+
* @param precomputedMatrix If provided, used as-is instead of multiplying `lhs`'s and `rhs`'s transform matrices.
|
|
37
|
+
*/
|
|
26
38
|
static combine(lhs, rhs, precomputedMatrix = null) {
|
|
27
39
|
return {
|
|
28
40
|
opacity: (lhs.opacity ?? 1) * (rhs.opacity ?? 1),
|
|
@@ -36,6 +48,7 @@ export class PresentationState {
|
|
|
36
48
|
};
|
|
37
49
|
}
|
|
38
50
|
}
|
|
51
|
+
/** Type guard telling whether `object` implements `PresentationObject`. */
|
|
39
52
|
export function isPresentationObject(object) {
|
|
40
53
|
return isUiObject(object)
|
|
41
54
|
&& ('fill' in object
|
|
@@ -47,18 +60,26 @@ export function isPresentationObject(object) {
|
|
|
47
60
|
|| 'opacity' in object
|
|
48
61
|
|| 'lineCap' in object);
|
|
49
62
|
}
|
|
63
|
+
/** Type guard telling whether `object` implements `Shape`. */
|
|
50
64
|
export function isShape(object) {
|
|
51
65
|
return isUiObject(object) && 'pathData' in object;
|
|
52
66
|
}
|
|
67
|
+
/** Type guard telling whether `object` implements `Group` and has at least one child drawable. */
|
|
53
68
|
export function isGroup(object) {
|
|
54
69
|
return isUiObject(object) && 'childDrawables' in object && !Utils.isNullOrEmpty(object['childDrawables']);
|
|
55
70
|
}
|
|
71
|
+
/** Type guard telling whether `object` implements `Text`. */
|
|
56
72
|
export function isText(object) {
|
|
57
73
|
return isUiObject(object) && 'text' in object && typeof object['text'] === 'string';
|
|
58
74
|
}
|
|
75
|
+
/** Type guard telling whether `object` implements `Image`. */
|
|
59
76
|
export function isImage(object) {
|
|
60
77
|
return isUiObject(object) && 'src' in object && typeof object['src'] === 'string';
|
|
61
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* Base class for the custom UI events dispatched by the 2D stage/adapters, carrying the screen transform
|
|
81
|
+
* matrix in effect at dispatch time so consumers can project screen coordinates into stage coordinates.
|
|
82
|
+
*/
|
|
62
83
|
export class UI2DEvent extends CustomUIEvent {
|
|
63
84
|
constructor(type, eventInit, originalEvent, transformMatrix) {
|
|
64
85
|
super(type, eventInit, originalEvent);
|
|
@@ -69,22 +90,28 @@ export class UI2DEvent extends CustomUIEvent {
|
|
|
69
90
|
get transformMatrix() {
|
|
70
91
|
return this.#transformMatrix;
|
|
71
92
|
}
|
|
93
|
+
/** Projects a point (defaults to the event's screen coordinates) through the event's transform matrix. */
|
|
72
94
|
project(pt = { x: this.screenX, y: this.screenY }) {
|
|
73
95
|
return Matrix2D.multiply(pt, this.#transformMatrix);
|
|
74
96
|
}
|
|
75
97
|
}
|
|
98
|
+
/** Static helper to build an empty `ShapeGeometry`. */
|
|
76
99
|
export class Shape {
|
|
100
|
+
/** Returns an empty `ShapeGeometry` (no path, no vertices, zero-sized bounding rect). */
|
|
77
101
|
static empty() {
|
|
78
102
|
return { pathData: '', vertices: [], boundingRect: { x: 0, y: 0, width: 0, height: 0 } };
|
|
79
103
|
}
|
|
80
104
|
}
|
|
105
|
+
/** Event dispatched throughout a `Drawable`'s drag lifecycle, carrying `DragEventArgs`. */
|
|
81
106
|
export class DragEvent extends UI2DEvent {
|
|
82
107
|
}
|
|
108
|
+
/** Event dispatched for pointer interactions (over/out/down/up/click) targeting a `Drawable`. */
|
|
83
109
|
export class DrawableEvent extends UI2DEvent {
|
|
84
110
|
constructor(type, args, originalEvent, m) {
|
|
85
111
|
super(type, { detail: args, bubbles: true, cancelable: true }, originalEvent, m);
|
|
86
112
|
}
|
|
87
113
|
}
|
|
114
|
+
/** Event dispatched for pointer interactions (move/down/up/click) targeting a `Stage` at large (i.e. no specific hit `Drawable`). */
|
|
88
115
|
export class StageEvent extends UI2DEvent {
|
|
89
116
|
constructor(type, args, originalEvent, m = args.transformMatrix) {
|
|
90
117
|
super(type, { detail: args, bubbles: true, cancelable: true }, originalEvent, m);
|
package/dist/esm/ellipse.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @pacem/pacem-2d v1.0.0-
|
|
2
|
+
* @pacem/pacem-2d v1.0.0-dirac (https://js.pacem.it)
|
|
3
3
|
* Pacem (https://pacem.it)
|
|
4
4
|
* Licensed under Apache-2.0
|
|
5
5
|
*/
|
|
@@ -65,6 +65,7 @@ function getShapeGeometry(c, rx, ry, start, end) {
|
|
|
65
65
|
const threesixty = (start - end).isCloseTo(0);
|
|
66
66
|
return threesixty ? full(c, rx, ry) : sect(c, rx, ry, start, end);
|
|
67
67
|
}
|
|
68
|
+
/** `<pacem-2d-ellipse>`: renders a full ellipse, or a pie-slice sector when `start`/`end` are set. */
|
|
68
69
|
let PacemEllipseElement = PacemEllipseElement_1 = class PacemEllipseElement extends ShapeElement {
|
|
69
70
|
propertyChangedCallback(name, old, val, first) {
|
|
70
71
|
super.propertyChangedCallback(name, old, val, first);
|
|
@@ -80,6 +81,7 @@ let PacemEllipseElement = PacemEllipseElement_1 = class PacemEllipseElement exte
|
|
|
80
81
|
}
|
|
81
82
|
}
|
|
82
83
|
}
|
|
84
|
+
/** Computes the SVG path data of the ellipse (or sector) out of its own `center`/`rx`/`ry`/`start`/`end`. */
|
|
83
85
|
getPathData() {
|
|
84
86
|
const a = this.rx, b = this.ry, c = this.center, s = this.start ?? 0, e = this.end ?? 0;
|
|
85
87
|
if (!Utils.isNull(c) && !Utils.isNull(a) && !Utils.isNull(b)) {
|
|
@@ -92,6 +94,14 @@ let PacemEllipseElement = PacemEllipseElement_1 = class PacemEllipseElement exte
|
|
|
92
94
|
const a = this.rx ?? 0, b = this.ry ?? 0;
|
|
93
95
|
return getShapeGeometry(center, a, b, this.start, this.end);
|
|
94
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* Computes the SVG path data of an ellipse, or of a pie-slice sector when `start`/`end` don't describe a full turn.
|
|
99
|
+
* @param c Center point.
|
|
100
|
+
* @param rx Horizontal radius.
|
|
101
|
+
* @param ry Vertical radius.
|
|
102
|
+
* @param start Sector start angle, in degrees.
|
|
103
|
+
* @param end Sector end angle, in degrees.
|
|
104
|
+
*/
|
|
95
105
|
static getPathData(c = { x: NaN, y: NaN }, rx = NaN, ry = NaN, start, end) {
|
|
96
106
|
const { pathData } = getShapeGeometry(c, rx, ry, start, end);
|
|
97
107
|
return pathData;
|
|
@@ -116,6 +126,7 @@ PacemEllipseElement = PacemEllipseElement_1 = __decorate([
|
|
|
116
126
|
CustomElement({ tagName: P + '-' + TAG_MIDDLE_NAME + '-ellipse' })
|
|
117
127
|
], PacemEllipseElement);
|
|
118
128
|
export { PacemEllipseElement };
|
|
129
|
+
/** `<pacem-2d-circle>`: renders a full circle, or a pie-slice sector when `start`/`end` are set. */
|
|
119
130
|
let PacemCircleElement = PacemCircleElement_1 = class PacemCircleElement extends ShapeElement {
|
|
120
131
|
propertyChangedCallback(name, old, val, first) {
|
|
121
132
|
super.propertyChangedCallback(name, old, val, first);
|
|
@@ -130,6 +141,7 @@ let PacemCircleElement = PacemCircleElement_1 = class PacemCircleElement extends
|
|
|
130
141
|
}
|
|
131
142
|
}
|
|
132
143
|
}
|
|
144
|
+
/** Computes the SVG path data of the circle (or sector) out of its own `center`/`radius`/`start`/`end`. */
|
|
133
145
|
getPathData() {
|
|
134
146
|
const r = this.radius, c = this.center;
|
|
135
147
|
if (!Utils.isNull(c) && !Utils.isNull(r)) {
|
|
@@ -142,6 +154,13 @@ let PacemCircleElement = PacemCircleElement_1 = class PacemCircleElement extends
|
|
|
142
154
|
const r = this.radius ?? 0;
|
|
143
155
|
return getShapeGeometry(center, r, r, this.start, this.end);
|
|
144
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* Computes the SVG path data of a circle, or of a pie-slice sector when `start`/`end` don't describe a full turn.
|
|
159
|
+
* @param c Center point.
|
|
160
|
+
* @param r Radius.
|
|
161
|
+
* @param start Sector start angle, in degrees.
|
|
162
|
+
* @param end Sector end angle, in degrees.
|
|
163
|
+
*/
|
|
145
164
|
static getPathData(c = { x: NaN, y: NaN }, r = NaN, start, end) {
|
|
146
165
|
return PacemEllipseElement.getPathData(c, r, r, start, end);
|
|
147
166
|
}
|
package/dist/esm/group.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @pacem/pacem-2d v1.0.0-
|
|
2
|
+
* @pacem/pacem-2d v1.0.0-dirac (https://js.pacem.it)
|
|
3
3
|
* Pacem (https://pacem.it)
|
|
4
4
|
* Licensed under Apache-2.0
|
|
5
5
|
*/
|
|
@@ -14,11 +14,13 @@ import { PresentationElement } from './types';
|
|
|
14
14
|
import { TAG_MIDDLE_NAME } from './constants';
|
|
15
15
|
import { DrawableElement } from './drawable-element';
|
|
16
16
|
//namespace Pacem.Components.Drawing {
|
|
17
|
+
/** `<pacem-2d-group>`: a container that groups child drawables, applying its own transform/presentation state to all of them. */
|
|
17
18
|
let PacemGroupElement = class PacemGroupElement extends PresentationElement {
|
|
18
19
|
validate(item) {
|
|
19
20
|
return item instanceof DrawableElement && item.parent === this;
|
|
20
21
|
}
|
|
21
22
|
#children = [];
|
|
23
|
+
/** @readonly Gets the child drawables currently in the group. */
|
|
22
24
|
get childDrawables() {
|
|
23
25
|
return this.#children;
|
|
24
26
|
}
|
package/dist/esm/image.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @pacem/pacem-2d v1.0.0-
|
|
2
|
+
* @pacem/pacem-2d v1.0.0-dirac (https://js.pacem.it)
|
|
3
3
|
* Pacem (https://pacem.it)
|
|
4
4
|
* Licensed under Apache-2.0
|
|
5
5
|
*/
|
|
@@ -13,6 +13,7 @@ import { CustomElement, Watch, PropertyConverters, P } from '@pacem/pacem-core';
|
|
|
13
13
|
import { UiElement } from './types';
|
|
14
14
|
import { TAG_MIDDLE_NAME } from './constants';
|
|
15
15
|
//namespace Pacem.Components.Drawing {
|
|
16
|
+
/** `<pacem-2d-image>`: renders a raster image at a given position and size within the stage. */
|
|
16
17
|
let PacemImageElement = class PacemImageElement extends UiElement {
|
|
17
18
|
propertyChangedCallback(name, old, val, first) {
|
|
18
19
|
super.propertyChangedCallback(name, old, val, first);
|
package/dist/esm/index-iife.js
CHANGED
package/dist/esm/index-root.js
CHANGED
package/dist/esm/index.js
CHANGED
package/dist/esm/line.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @pacem/pacem-2d v1.0.0-
|
|
2
|
+
* @pacem/pacem-2d v1.0.0-dirac (https://js.pacem.it)
|
|
3
3
|
* Pacem (https://pacem.it)
|
|
4
4
|
* Licensed under Apache-2.0
|
|
5
5
|
*/
|
|
@@ -15,6 +15,7 @@ import { ShapeElement } from './types';
|
|
|
15
15
|
import { TAG_MIDDLE_NAME } from './constants';
|
|
16
16
|
import { Shape } from './drawing';
|
|
17
17
|
//namespace Pacem.Components.Drawing {
|
|
18
|
+
/** `<pacem-2d-line>`: renders a straight segment between two points. */
|
|
18
19
|
let PacemLineElement = PacemLineElement_1 = class PacemLineElement extends ShapeElement {
|
|
19
20
|
propertyChangedCallback(name, old, val, first) {
|
|
20
21
|
super.propertyChangedCallback(name, old, val, first);
|
|
@@ -36,6 +37,7 @@ let PacemLineElement = PacemLineElement_1 = class PacemLineElement extends Shape
|
|
|
36
37
|
const boundingRect = { x: Math.min(x0, x1), y: Math.min(y0, y1), width: Math.abs(x0 - x1), height: Math.abs(y0 - y1) };
|
|
37
38
|
return { pathData: this.getPathData(), vertices: [from, to], boundingRect };
|
|
38
39
|
}
|
|
40
|
+
/** Computes the SVG path data of the line out of its own `from`/`to` points. */
|
|
39
41
|
getPathData() {
|
|
40
42
|
const from = this.from, to = this.to;
|
|
41
43
|
if (!Utils.isNull(from) && !Utils.isNull(to)) {
|
|
@@ -43,6 +45,7 @@ let PacemLineElement = PacemLineElement_1 = class PacemLineElement extends Shape
|
|
|
43
45
|
}
|
|
44
46
|
return null;
|
|
45
47
|
}
|
|
48
|
+
/** Computes the SVG path data of a straight segment between `from` and `to`. */
|
|
46
49
|
static getPathData(from = { x: NaN, y: NaN }, to = { x: NaN, y: NaN }) {
|
|
47
50
|
const x0 = from.x, y0 = from.y, x1 = to.x, y1 = to.y;
|
|
48
51
|
return `M ${x0} ${y0} L ${x1} ${y1}`;
|
package/dist/esm/path.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @pacem/pacem-2d v1.0.0-
|
|
2
|
+
* @pacem/pacem-2d v1.0.0-dirac (https://js.pacem.it)
|
|
3
3
|
* Pacem (https://pacem.it)
|
|
4
4
|
* Licensed under Apache-2.0
|
|
5
5
|
*/
|
|
@@ -13,9 +13,11 @@ import { CustomElement, Watch, PropertyConverters, P } from '@pacem/pacem-core';
|
|
|
13
13
|
import { ShapeElement } from './types';
|
|
14
14
|
import { TAG_MIDDLE_NAME } from './constants';
|
|
15
15
|
//namespace Pacem.Components.Drawing {
|
|
16
|
+
/** `<pacem-2d-path>`: renders an arbitrary SVG path, provided verbatim through the `d` property. */
|
|
16
17
|
let PacemPathElement = class PacemPathElement extends ShapeElement {
|
|
17
18
|
constructor() {
|
|
18
19
|
super(...arguments);
|
|
20
|
+
/** Returns the raw path data, i.e. `d`. */
|
|
19
21
|
this.getPathData = () => this.d;
|
|
20
22
|
}
|
|
21
23
|
propertyChangedCallback(name, old, val, first) {
|
package/dist/esm/polygon.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @pacem/pacem-2d v1.0.0-
|
|
2
|
+
* @pacem/pacem-2d v1.0.0-dirac (https://js.pacem.it)
|
|
3
3
|
* Pacem (https://pacem.it)
|
|
4
4
|
* Licensed under Apache-2.0
|
|
5
5
|
*/
|
|
@@ -15,6 +15,7 @@ import { ShapeElement } from './types';
|
|
|
15
15
|
import { TAG_MIDDLE_NAME } from './constants';
|
|
16
16
|
import { Shape } from './drawing';
|
|
17
17
|
//namespace Pacem.Components.Drawing {
|
|
18
|
+
/** `<pacem-2d-polygon>`: renders a regular polygon (or, with `starIndent` set, a star) centered on `center`. */
|
|
18
19
|
let PacemPolygonElement = PacemPolygonElement_1 = class PacemPolygonElement extends ShapeElement {
|
|
19
20
|
propertyChangedCallback(name, old, val, first) {
|
|
20
21
|
super.propertyChangedCallback(name, old, val, first);
|
|
@@ -28,6 +29,7 @@ let PacemPolygonElement = PacemPolygonElement_1 = class PacemPolygonElement exte
|
|
|
28
29
|
}
|
|
29
30
|
}
|
|
30
31
|
}
|
|
32
|
+
/** Computes the SVG path data of the polygon out of its own `center`, `radius`, `sides` and `starIndent`. */
|
|
31
33
|
getPathData() {
|
|
32
34
|
const sides = this.sides, radius = this.radius, center = this.center;
|
|
33
35
|
if (!Utils.isNull(sides) && !Utils.isNull(radius)) {
|
|
@@ -42,6 +44,13 @@ let PacemPolygonElement = PacemPolygonElement_1 = class PacemPolygonElement exte
|
|
|
42
44
|
}
|
|
43
45
|
return PacemPolygonElement_1.getShapeGeometry(c, r, sides, si);
|
|
44
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Computes the geometry (path data, vertices, bounding rect) of a regular polygon or star.
|
|
49
|
+
* @param center Center point.
|
|
50
|
+
* @param radius Circumradius.
|
|
51
|
+
* @param sides Number of sides (or points, for a star).
|
|
52
|
+
* @param starIndent Star indentation factor (0 = regular polygon).
|
|
53
|
+
*/
|
|
45
54
|
static getShapeGeometry(center, radius, sides, starIndent = .0) {
|
|
46
55
|
const p0 = { x: center.x, y: center.y - radius };
|
|
47
56
|
let retval = `M ${p0.x} ${(p0.y)}`;
|
|
@@ -72,6 +81,7 @@ let PacemPolygonElement = PacemPolygonElement_1 = class PacemPolygonElement exte
|
|
|
72
81
|
pathData: retval + ' Z', vertices, boundingRect: { x: p0.x - radius, y: p0.y, width, height: width }
|
|
73
82
|
};
|
|
74
83
|
}
|
|
84
|
+
/** Computes the SVG path data of a regular polygon or star. See `getShapeGeometry` for the parameters. */
|
|
75
85
|
static getPathData(center, radius, sides, starIndent = .0) {
|
|
76
86
|
const { pathData } = PacemPolygonElement_1.getShapeGeometry(center, radius, sides, starIndent);
|
|
77
87
|
return pathData;
|
package/dist/esm/polyline.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @pacem/pacem-2d v1.0.0-
|
|
2
|
+
* @pacem/pacem-2d v1.0.0-dirac (https://js.pacem.it)
|
|
3
3
|
* Pacem (https://pacem.it)
|
|
4
4
|
* Licensed under Apache-2.0
|
|
5
5
|
*/
|
|
@@ -16,6 +16,7 @@ import { ShapeElement } from './types';
|
|
|
16
16
|
import { TAG_MIDDLE_NAME } from './constants';
|
|
17
17
|
import { Shape } from './drawing';
|
|
18
18
|
//namespace Pacem.Components.Drawing {
|
|
19
|
+
/** Converts the `points` attribute either from a flat `x1,y1,x2,y2,...` numeric list or from JSON. */
|
|
19
20
|
const PointArrayOrJsonConverter = {
|
|
20
21
|
convert: (attr) => {
|
|
21
22
|
const arr = parseAsNumericalArray(attr);
|
|
@@ -30,6 +31,7 @@ const PointArrayOrJsonConverter = {
|
|
|
30
31
|
},
|
|
31
32
|
convertBack: (prop) => JSON.stringify(prop)
|
|
32
33
|
};
|
|
34
|
+
/** `<pacem-2d-polyline>`: renders a series of connected segments through `points`, optionally `closed` into a polygon. */
|
|
33
35
|
let PacemPolylineElement = PacemPolylineElement_1 = class PacemPolylineElement extends ShapeElement {
|
|
34
36
|
propertyChangedCallback(name, old, val, first) {
|
|
35
37
|
super.propertyChangedCallback(name, old, val, first);
|
|
@@ -42,6 +44,11 @@ let PacemPolylineElement = PacemPolylineElement_1 = class PacemPolylineElement e
|
|
|
42
44
|
}
|
|
43
45
|
}
|
|
44
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Computes the geometry (path data, vertices, bounding rect) of a polyline.
|
|
49
|
+
* @param points Vertices, in order.
|
|
50
|
+
* @param closed Whether the polyline is closed back onto its first point.
|
|
51
|
+
*/
|
|
45
52
|
static getShapeGeometry(points, closed) {
|
|
46
53
|
if (Utils.isNullOrEmpty(points)) {
|
|
47
54
|
return Shape.empty();
|
|
@@ -65,10 +72,12 @@ let PacemPolylineElement = PacemPolylineElement_1 = class PacemPolylineElement e
|
|
|
65
72
|
getShapeGeometry() {
|
|
66
73
|
return PacemPolylineElement_1.getShapeGeometry(this.points, this.closed);
|
|
67
74
|
}
|
|
75
|
+
/** Computes the SVG path data of the polyline out of its own `points`/`closed`. */
|
|
68
76
|
getPathData() {
|
|
69
77
|
const { pathData } = this.getShapeGeometry();
|
|
70
78
|
return pathData;
|
|
71
79
|
}
|
|
80
|
+
/** Computes the SVG path data of a polyline. See `getShapeGeometry` for the parameters. */
|
|
72
81
|
static getPathData(points, closed) {
|
|
73
82
|
const { pathData } = PacemPolylineElement_1.getShapeGeometry(points, closed);
|
|
74
83
|
return pathData;
|
package/dist/esm/rect.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @pacem/pacem-2d v1.0.0-
|
|
2
|
+
* @pacem/pacem-2d v1.0.0-dirac (https://js.pacem.it)
|
|
3
3
|
* Pacem (https://pacem.it)
|
|
4
4
|
* Licensed under Apache-2.0
|
|
5
5
|
*/
|
|
@@ -62,11 +62,13 @@ function stringifyCornerRadii(radii) {
|
|
|
62
62
|
const blX = stringifyCornerRadiusComponent(bottomLeft.rx), blY = stringifyCornerRadiusComponent(bottomLeft.ry);
|
|
63
63
|
return `${tlX},${tlY} ${trX},${trY} ${brX},${brY} ${blX},${blY}`;
|
|
64
64
|
}
|
|
65
|
+
/** How a `PacemRectElement` corner is rendered: smoothly `Rounded` or straight-line `Cut` (chamfered). */
|
|
65
66
|
export var CornerType;
|
|
66
67
|
(function (CornerType) {
|
|
67
68
|
CornerType["Rounded"] = "rounded";
|
|
68
69
|
CornerType["Cut"] = "cut";
|
|
69
70
|
})(CornerType || (CornerType = {}));
|
|
71
|
+
/** `<pacem-2d-rect>`: renders a rectangle, optionally with independently rounded or cut corners. */
|
|
70
72
|
let PacemRectElement = PacemRectElement_1 = class PacemRectElement extends ShapeElement {
|
|
71
73
|
propertyChangedCallback(name, old, val, first) {
|
|
72
74
|
super.propertyChangedCallback(name, old, val, first);
|
|
@@ -74,6 +76,7 @@ let PacemRectElement = PacemRectElement_1 = class PacemRectElement extends Shape
|
|
|
74
76
|
this.recomputeShape();
|
|
75
77
|
}
|
|
76
78
|
}
|
|
79
|
+
/** Computes the SVG path data of the rectangle out of its own `x`/`y`/`w`/`h`/`r`/`cornerType`. */
|
|
77
80
|
getPathData() {
|
|
78
81
|
const x = this.x, y = this.y, w = this.w, h = this.h;
|
|
79
82
|
let r = this.r ?? { rx: { value: 0 }, ry: { value: 0 }, type: CornerType.Rounded };
|
package/dist/esm/stage.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @pacem/pacem-2d v1.0.0-
|
|
2
|
+
* @pacem/pacem-2d v1.0.0-dirac (https://js.pacem.it)
|
|
3
3
|
* Pacem (https://pacem.it)
|
|
4
4
|
* Licensed under Apache-2.0
|
|
5
5
|
*/
|
|
@@ -43,10 +43,20 @@ const DEFAULT_STAGE_OPTIONS = {
|
|
|
43
43
|
zoomModifiers: [EventKeyModifier.AltKey],
|
|
44
44
|
clickModifiers: []
|
|
45
45
|
};
|
|
46
|
+
/**
|
|
47
|
+
* Returns the effective `StageOptions` for the given stage, filling in any option left unset with the
|
|
48
|
+
* library defaults.
|
|
49
|
+
* @param stage The stage to resolve options for.
|
|
50
|
+
*/
|
|
46
51
|
export function getStageOptions(stage) {
|
|
47
52
|
const options = stage instanceof Pacem2DElement ? stage.options : {};
|
|
48
53
|
return Utils.extend({}, DEFAULT_STAGE_OPTIONS, options);
|
|
49
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* The `<pacem-2d>` element: root stage/scene container for the drawable elements (shapes, text, images,
|
|
57
|
+
* groups...). Delegates actual rendering to the assigned `adapter` (SVG or Canvas) and handles the
|
|
58
|
+
* viewbox/aspect-ratio mapping plus built-in pan and zoom interactions.
|
|
59
|
+
*/
|
|
50
60
|
let Pacem2DElement = class Pacem2DElement extends Components.PacemItemsContainerElement {
|
|
51
61
|
constructor() {
|
|
52
62
|
super(...arguments);
|
|
@@ -111,9 +121,11 @@ let Pacem2DElement = class Pacem2DElement extends Components.PacemItemsContainer
|
|
|
111
121
|
this.#panningStart = null;
|
|
112
122
|
};
|
|
113
123
|
}
|
|
124
|
+
/** @readonly Gets the DOM element hosting the stage content. */
|
|
114
125
|
get stage() {
|
|
115
126
|
return this._stage;
|
|
116
127
|
}
|
|
128
|
+
/** Processes the stage content and returns a snapshot image (delegates to the current `adapter`). */
|
|
117
129
|
snapshot(bgColor, type, quality) {
|
|
118
130
|
const adapter = this.adapter;
|
|
119
131
|
if (Utils.isNull(adapter)) {
|
|
@@ -123,6 +135,7 @@ let Pacem2DElement = class Pacem2DElement extends Components.PacemItemsContainer
|
|
|
123
135
|
}
|
|
124
136
|
#originalViewBox;
|
|
125
137
|
#transformMatrix;
|
|
138
|
+
/** @readonly Gets the matrix that projects stage coords into screen coords. */
|
|
126
139
|
get transformMatrix() {
|
|
127
140
|
return this.#transformMatrix;
|
|
128
141
|
}
|
package/dist/esm/text.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @pacem/pacem-2d v1.0.0-
|
|
2
|
+
* @pacem/pacem-2d v1.0.0-dirac (https://js.pacem.it)
|
|
3
3
|
* Pacem (https://pacem.it)
|
|
4
4
|
* Licensed under Apache-2.0
|
|
5
5
|
*/
|
|
@@ -13,6 +13,7 @@ import { CustomElement, Watch, PropertyConverters, P, Utils } from '@pacem/pacem
|
|
|
13
13
|
import { UiElement } from './types';
|
|
14
14
|
import { TAG_MIDDLE_NAME } from './constants';
|
|
15
15
|
//namespace Pacem.Components.Drawing {
|
|
16
|
+
/** `<pacem-2d-text>`: renders a text label anchored at a given point. */
|
|
16
17
|
let PacemTextElement = class PacemTextElement extends UiElement {
|
|
17
18
|
propertyChangedCallback(name, old, val, first) {
|
|
18
19
|
if (!first) {
|
package/dist/esm/types.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @pacem/pacem-2d v1.0.0-
|
|
2
|
+
* @pacem/pacem-2d v1.0.0-dirac (https://js.pacem.it)
|
|
3
3
|
* Pacem (https://pacem.it)
|
|
4
4
|
* Licensed under Apache-2.0
|
|
5
5
|
*/
|
|
@@ -14,6 +14,10 @@ import { Matrix2D } from '@pacem/pacem-foundation';
|
|
|
14
14
|
import { DrawableElement } from './drawable-element';
|
|
15
15
|
//namespace Pacem.Components.Drawing {
|
|
16
16
|
const DEG2RAD = Math.PI / 180.0;
|
|
17
|
+
/**
|
|
18
|
+
* Base class for every drawable that participates in the 2D transform pipeline (rotation, scale,
|
|
19
|
+
* translation) and exposes an `opacity`. Computes and caches the corresponding `transformMatrix`.
|
|
20
|
+
*/
|
|
17
21
|
export class UiElement extends DrawableElement {
|
|
18
22
|
#transformMatrix = Matrix2D.identity;
|
|
19
23
|
viewActivatedCallback() {
|
|
@@ -65,6 +69,10 @@ __decorate([
|
|
|
65
69
|
__decorate([
|
|
66
70
|
Watch({ emit: false, converter: PropertyConverters.Number })
|
|
67
71
|
], UiElement.prototype, "opacity", void 0);
|
|
72
|
+
/**
|
|
73
|
+
* Base class for drawables that carry stroke/fill presentation state (color, line width, dash pattern,
|
|
74
|
+
* line join/cap), on top of the transform/opacity inherited from `UiElement`.
|
|
75
|
+
*/
|
|
68
76
|
export class PresentationElement extends UiElement {
|
|
69
77
|
propertyChangedCallback(name, old, val, first) {
|
|
70
78
|
super.propertyChangedCallback(name, old, val, first);
|
|
@@ -107,6 +115,11 @@ __decorate([
|
|
|
107
115
|
__decorate([
|
|
108
116
|
Watch({ emit: false, converter: PropertyConverters.String })
|
|
109
117
|
], PresentationElement.prototype, "lineCap", void 0);
|
|
118
|
+
/**
|
|
119
|
+
* Base class for drawables whose visual is an SVG path (`pathData`) computed out of their own geometry
|
|
120
|
+
* properties (e.g. center/radius, points, corners). Subclasses implement `getShapeGeometry` and this
|
|
121
|
+
* class takes care of recomputing `data`/`vertices`/`boundingRect` and requesting a redraw.
|
|
122
|
+
*/
|
|
110
123
|
export class ShapeElement extends PresentationElement {
|
|
111
124
|
propertyChangedCallback(name, old, val, first) {
|
|
112
125
|
super.propertyChangedCallback(name, old, val, first);
|
|
@@ -122,20 +135,24 @@ export class ShapeElement extends PresentationElement {
|
|
|
122
135
|
super.viewActivatedCallback();
|
|
123
136
|
this.recomputeShape();
|
|
124
137
|
}
|
|
138
|
+
/** Recomputes `data`, `vertices` and `boundingRect` from `getShapeGeometry()`. */
|
|
125
139
|
recomputeShape() {
|
|
126
140
|
const { pathData, vertices, boundingRect } = this.getShapeGeometry();
|
|
127
141
|
this.#vertices = vertices;
|
|
128
142
|
this.#boundingRect = boundingRect;
|
|
129
143
|
this.data = pathData;
|
|
130
144
|
}
|
|
145
|
+
/** @readonly Gets the SVG path data backing the shape. */
|
|
131
146
|
get pathData() {
|
|
132
147
|
return this.data;
|
|
133
148
|
}
|
|
134
149
|
#boundingRect;
|
|
150
|
+
/** @readonly Gets the bounding rectangle of the shape. */
|
|
135
151
|
get boundingRect() {
|
|
136
152
|
return this.#boundingRect;
|
|
137
153
|
}
|
|
138
154
|
#vertices;
|
|
155
|
+
/** @readonly Gets the vertices making up the shape. */
|
|
139
156
|
get vertices() {
|
|
140
157
|
return this.#vertices;
|
|
141
158
|
}
|
package/package.json
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
"dist/browser/*.*",
|
|
5
5
|
"dist/bundle/*.*",
|
|
6
6
|
"dist/esm/*.*",
|
|
7
|
+
"dist/docs/*.*",
|
|
7
8
|
"typings/*.*",
|
|
8
9
|
"README.md",
|
|
9
10
|
"LICENSE",
|
|
@@ -24,7 +25,7 @@
|
|
|
24
25
|
"types": "./typings/index.d.ts"
|
|
25
26
|
}
|
|
26
27
|
},
|
|
27
|
-
"version": "1.0.0-
|
|
28
|
+
"version": "1.0.0-dirac",
|
|
28
29
|
"author": {
|
|
29
30
|
"name": "Pacem",
|
|
30
31
|
"url": "https://pacem.it"
|