@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/bundle/pacem-2d.mjs
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
|
*/
|
|
@@ -91,6 +91,13 @@ function isRadialGradient(object) {
|
|
|
91
91
|
return isGradient(object) && "center" in object && Point.isPoint(object.center) && "radius" in object && typeof object.radius === "number";
|
|
92
92
|
}
|
|
93
93
|
var PresentationState = class {
|
|
94
|
+
/**
|
|
95
|
+
* Combines two presentation states (typically an item's own state and the one inherited from its
|
|
96
|
+
* ancestors), giving precedence to `lhs` whenever both define a value.
|
|
97
|
+
* @param lhs Own/most specific presentation state.
|
|
98
|
+
* @param rhs Inherited/fallback presentation state.
|
|
99
|
+
* @param precomputedMatrix If provided, used as-is instead of multiplying `lhs`'s and `rhs`'s transform matrices.
|
|
100
|
+
*/
|
|
94
101
|
static combine(lhs, rhs, precomputedMatrix = null) {
|
|
95
102
|
return {
|
|
96
103
|
opacity: (lhs.opacity ?? 1) * (rhs.opacity ?? 1),
|
|
@@ -129,11 +136,13 @@ var UI2DEvent = class extends CustomUIEvent {
|
|
|
129
136
|
get transformMatrix() {
|
|
130
137
|
return this.#transformMatrix;
|
|
131
138
|
}
|
|
139
|
+
/** Projects a point (defaults to the event's screen coordinates) through the event's transform matrix. */
|
|
132
140
|
project(pt = { x: this.screenX, y: this.screenY }) {
|
|
133
141
|
return Matrix2D.multiply(pt, this.#transformMatrix);
|
|
134
142
|
}
|
|
135
143
|
};
|
|
136
144
|
var Shape = class {
|
|
145
|
+
/** Returns an empty `ShapeGeometry` (no path, no vertices, zero-sized bounding rect). */
|
|
137
146
|
static empty() {
|
|
138
147
|
return { pathData: "", vertices: [], boundingRect: { x: 0, y: 0, width: 0, height: 0 } };
|
|
139
148
|
}
|
|
@@ -249,9 +258,11 @@ var Pacem2DElement = class Pacem2DElement2 extends Components.PacemItemsContaine
|
|
|
249
258
|
this.#panningStart = null;
|
|
250
259
|
};
|
|
251
260
|
}
|
|
261
|
+
/** @readonly Gets the DOM element hosting the stage content. */
|
|
252
262
|
get stage() {
|
|
253
263
|
return this._stage;
|
|
254
264
|
}
|
|
265
|
+
/** Processes the stage content and returns a snapshot image (delegates to the current `adapter`). */
|
|
255
266
|
snapshot(bgColor, type, quality) {
|
|
256
267
|
const adapter = this.adapter;
|
|
257
268
|
if (Utils2.isNull(adapter)) {
|
|
@@ -261,6 +272,7 @@ var Pacem2DElement = class Pacem2DElement2 extends Components.PacemItemsContaine
|
|
|
261
272
|
}
|
|
262
273
|
#originalViewBox;
|
|
263
274
|
#transformMatrix;
|
|
275
|
+
/** @readonly Gets the matrix that projects stage coords into screen coords. */
|
|
264
276
|
get transformMatrix() {
|
|
265
277
|
return this.#transformMatrix;
|
|
266
278
|
}
|
|
@@ -513,9 +525,11 @@ var DrawableElement = class _DrawableElement extends Components2.PacemCrossItems
|
|
|
513
525
|
findContainer() {
|
|
514
526
|
return this.parent || this.stage;
|
|
515
527
|
}
|
|
528
|
+
/** @readonly Gets the `Pacem2DElement` stage this drawable belongs to. */
|
|
516
529
|
get stage() {
|
|
517
530
|
return this["_scene"] = this["_scene"] || CustomElementUtils.findAncestorOfType(this, Pacem2DElement);
|
|
518
531
|
}
|
|
532
|
+
/** @readonly Gets the closest ancestor `DrawableElement` (e.g. a containing group), if any. */
|
|
519
533
|
get parent() {
|
|
520
534
|
return this["_drawableParent"] = this["_drawableParent"] || CustomElementUtils.findAncestor(this, (i) => i instanceof _DrawableElement);
|
|
521
535
|
}
|
|
@@ -661,20 +675,24 @@ var ShapeElement = class extends PresentationElement {
|
|
|
661
675
|
super.viewActivatedCallback();
|
|
662
676
|
this.recomputeShape();
|
|
663
677
|
}
|
|
678
|
+
/** Recomputes `data`, `vertices` and `boundingRect` from `getShapeGeometry()`. */
|
|
664
679
|
recomputeShape() {
|
|
665
680
|
const { pathData, vertices, boundingRect } = this.getShapeGeometry();
|
|
666
681
|
this.#vertices = vertices;
|
|
667
682
|
this.#boundingRect = boundingRect;
|
|
668
683
|
this.data = pathData;
|
|
669
684
|
}
|
|
685
|
+
/** @readonly Gets the SVG path data backing the shape. */
|
|
670
686
|
get pathData() {
|
|
671
687
|
return this.data;
|
|
672
688
|
}
|
|
673
689
|
#boundingRect;
|
|
690
|
+
/** @readonly Gets the bounding rectangle of the shape. */
|
|
674
691
|
get boundingRect() {
|
|
675
692
|
return this.#boundingRect;
|
|
676
693
|
}
|
|
677
694
|
#vertices;
|
|
695
|
+
/** @readonly Gets the vertices making up the shape. */
|
|
678
696
|
get vertices() {
|
|
679
697
|
return this.#vertices;
|
|
680
698
|
}
|
|
@@ -696,6 +714,7 @@ var PacemGroupElement = class PacemGroupElement2 extends PresentationElement {
|
|
|
696
714
|
return item instanceof DrawableElement && item.parent === this;
|
|
697
715
|
}
|
|
698
716
|
#children = [];
|
|
717
|
+
/** @readonly Gets the child drawables currently in the group. */
|
|
699
718
|
get childDrawables() {
|
|
700
719
|
return this.#children;
|
|
701
720
|
}
|
|
@@ -797,6 +816,7 @@ var PacemEllipseElement = PacemEllipseElement_1 = class PacemEllipseElement2 ext
|
|
|
797
816
|
}
|
|
798
817
|
}
|
|
799
818
|
}
|
|
819
|
+
/** Computes the SVG path data of the ellipse (or sector) out of its own `center`/`rx`/`ry`/`start`/`end`. */
|
|
800
820
|
getPathData() {
|
|
801
821
|
const a = this.rx, b = this.ry, c = this.center, s = this.start ?? 0, e = this.end ?? 0;
|
|
802
822
|
if (!Utils5.isNull(c) && !Utils5.isNull(a) && !Utils5.isNull(b)) {
|
|
@@ -809,6 +829,14 @@ var PacemEllipseElement = PacemEllipseElement_1 = class PacemEllipseElement2 ext
|
|
|
809
829
|
const a = this.rx ?? 0, b = this.ry ?? 0;
|
|
810
830
|
return getShapeGeometry(center, a, b, this.start, this.end);
|
|
811
831
|
}
|
|
832
|
+
/**
|
|
833
|
+
* Computes the SVG path data of an ellipse, or of a pie-slice sector when `start`/`end` don't describe a full turn.
|
|
834
|
+
* @param c Center point.
|
|
835
|
+
* @param rx Horizontal radius.
|
|
836
|
+
* @param ry Vertical radius.
|
|
837
|
+
* @param start Sector start angle, in degrees.
|
|
838
|
+
* @param end Sector end angle, in degrees.
|
|
839
|
+
*/
|
|
812
840
|
static getPathData(c = { x: NaN, y: NaN }, rx = NaN, ry = NaN, start, end) {
|
|
813
841
|
const { pathData } = getShapeGeometry(c, rx, ry, start, end);
|
|
814
842
|
return pathData;
|
|
@@ -846,6 +874,7 @@ var PacemCircleElement = PacemCircleElement_1 = class PacemCircleElement2 extend
|
|
|
846
874
|
}
|
|
847
875
|
}
|
|
848
876
|
}
|
|
877
|
+
/** Computes the SVG path data of the circle (or sector) out of its own `center`/`radius`/`start`/`end`. */
|
|
849
878
|
getPathData() {
|
|
850
879
|
const r = this.radius, c = this.center;
|
|
851
880
|
if (!Utils5.isNull(c) && !Utils5.isNull(r)) {
|
|
@@ -858,6 +887,13 @@ var PacemCircleElement = PacemCircleElement_1 = class PacemCircleElement2 extend
|
|
|
858
887
|
const r = this.radius ?? 0;
|
|
859
888
|
return getShapeGeometry(center, r, r, this.start, this.end);
|
|
860
889
|
}
|
|
890
|
+
/**
|
|
891
|
+
* Computes the SVG path data of a circle, or of a pie-slice sector when `start`/`end` don't describe a full turn.
|
|
892
|
+
* @param c Center point.
|
|
893
|
+
* @param r Radius.
|
|
894
|
+
* @param start Sector start angle, in degrees.
|
|
895
|
+
* @param end Sector end angle, in degrees.
|
|
896
|
+
*/
|
|
861
897
|
static getPathData(c = { x: NaN, y: NaN }, r = NaN, start, end) {
|
|
862
898
|
return PacemEllipseElement.getPathData(c, r, r, start, end);
|
|
863
899
|
}
|
|
@@ -939,6 +975,7 @@ var PacemRectElement = PacemRectElement_1 = class PacemRectElement2 extends Shap
|
|
|
939
975
|
this.recomputeShape();
|
|
940
976
|
}
|
|
941
977
|
}
|
|
978
|
+
/** Computes the SVG path data of the rectangle out of its own `x`/`y`/`w`/`h`/`r`/`cornerType`. */
|
|
942
979
|
getPathData() {
|
|
943
980
|
const x = this.x, y = this.y, w = this.w, h = this.h;
|
|
944
981
|
let r = this.r ?? { rx: { value: 0 }, ry: { value: 0 }, type: CornerType.Rounded };
|
|
@@ -1072,6 +1109,7 @@ var PacemLineElement = PacemLineElement_1 = class PacemLineElement2 extends Shap
|
|
|
1072
1109
|
const boundingRect = { x: Math.min(x0, x1), y: Math.min(y0, y1), width: Math.abs(x0 - x1), height: Math.abs(y0 - y1) };
|
|
1073
1110
|
return { pathData: this.getPathData(), vertices: [from, to], boundingRect };
|
|
1074
1111
|
}
|
|
1112
|
+
/** Computes the SVG path data of the line out of its own `from`/`to` points. */
|
|
1075
1113
|
getPathData() {
|
|
1076
1114
|
const from = this.from, to = this.to;
|
|
1077
1115
|
if (!Utils7.isNull(from) && !Utils7.isNull(to)) {
|
|
@@ -1079,6 +1117,7 @@ var PacemLineElement = PacemLineElement_1 = class PacemLineElement2 extends Shap
|
|
|
1079
1117
|
}
|
|
1080
1118
|
return null;
|
|
1081
1119
|
}
|
|
1120
|
+
/** Computes the SVG path data of a straight segment between `from` and `to`. */
|
|
1082
1121
|
static getPathData(from = { x: NaN, y: NaN }, to = { x: NaN, y: NaN }) {
|
|
1083
1122
|
const x0 = from.x, y0 = from.y, x1 = to.x, y1 = to.y;
|
|
1084
1123
|
return `M ${x0} ${y0} L ${x1} ${y1}`;
|
|
@@ -1151,6 +1190,7 @@ var PacemPolygonElement = PacemPolygonElement_1 = class PacemPolygonElement2 ext
|
|
|
1151
1190
|
}
|
|
1152
1191
|
}
|
|
1153
1192
|
}
|
|
1193
|
+
/** Computes the SVG path data of the polygon out of its own `center`, `radius`, `sides` and `starIndent`. */
|
|
1154
1194
|
getPathData() {
|
|
1155
1195
|
const sides = this.sides, radius = this.radius, center = this.center;
|
|
1156
1196
|
if (!Utils8.isNull(sides) && !Utils8.isNull(radius)) {
|
|
@@ -1165,6 +1205,13 @@ var PacemPolygonElement = PacemPolygonElement_1 = class PacemPolygonElement2 ext
|
|
|
1165
1205
|
}
|
|
1166
1206
|
return PacemPolygonElement_1.getShapeGeometry(c, r, sides, si);
|
|
1167
1207
|
}
|
|
1208
|
+
/**
|
|
1209
|
+
* Computes the geometry (path data, vertices, bounding rect) of a regular polygon or star.
|
|
1210
|
+
* @param center Center point.
|
|
1211
|
+
* @param radius Circumradius.
|
|
1212
|
+
* @param sides Number of sides (or points, for a star).
|
|
1213
|
+
* @param starIndent Star indentation factor (0 = regular polygon).
|
|
1214
|
+
*/
|
|
1168
1215
|
static getShapeGeometry(center, radius, sides, starIndent = 0) {
|
|
1169
1216
|
const p0 = { x: center.x, y: center.y - radius };
|
|
1170
1217
|
let retval = `M ${p0.x} ${p0.y}`;
|
|
@@ -1196,6 +1243,7 @@ var PacemPolygonElement = PacemPolygonElement_1 = class PacemPolygonElement2 ext
|
|
|
1196
1243
|
boundingRect: { x: p0.x - radius, y: p0.y, width, height: width }
|
|
1197
1244
|
};
|
|
1198
1245
|
}
|
|
1246
|
+
/** Computes the SVG path data of a regular polygon or star. See `getShapeGeometry` for the parameters. */
|
|
1199
1247
|
static getPathData(center, radius, sides, starIndent = 0) {
|
|
1200
1248
|
const { pathData } = PacemPolygonElement_1.getShapeGeometry(center, radius, sides, starIndent);
|
|
1201
1249
|
return pathData;
|
|
@@ -1253,6 +1301,11 @@ var PacemPolylineElement = PacemPolylineElement_1 = class PacemPolylineElement2
|
|
|
1253
1301
|
}
|
|
1254
1302
|
}
|
|
1255
1303
|
}
|
|
1304
|
+
/**
|
|
1305
|
+
* Computes the geometry (path data, vertices, bounding rect) of a polyline.
|
|
1306
|
+
* @param points Vertices, in order.
|
|
1307
|
+
* @param closed Whether the polyline is closed back onto its first point.
|
|
1308
|
+
*/
|
|
1256
1309
|
static getShapeGeometry(points, closed) {
|
|
1257
1310
|
if (Utils9.isNullOrEmpty(points)) {
|
|
1258
1311
|
return Shape.empty();
|
|
@@ -1276,10 +1329,12 @@ var PacemPolylineElement = PacemPolylineElement_1 = class PacemPolylineElement2
|
|
|
1276
1329
|
getShapeGeometry() {
|
|
1277
1330
|
return PacemPolylineElement_1.getShapeGeometry(this.points, this.closed);
|
|
1278
1331
|
}
|
|
1332
|
+
/** Computes the SVG path data of the polyline out of its own `points`/`closed`. */
|
|
1279
1333
|
getPathData() {
|
|
1280
1334
|
const { pathData } = this.getShapeGeometry();
|
|
1281
1335
|
return pathData;
|
|
1282
1336
|
}
|
|
1337
|
+
/** Computes the SVG path data of a polyline. See `getShapeGeometry` for the parameters. */
|
|
1283
1338
|
static getPathData(points, closed) {
|
|
1284
1339
|
const { pathData } = PacemPolylineElement_1.getShapeGeometry(points, closed);
|
|
1285
1340
|
return pathData;
|
|
@@ -1397,11 +1452,18 @@ PacemTextElement = __decorate12([
|
|
|
1397
1452
|
import { Utils as Utils11, UI } from "@pacem/pacem-core";
|
|
1398
1453
|
import { Rect as Rect3 } from "@pacem/pacem-foundation";
|
|
1399
1454
|
var AdapterUtils = class {
|
|
1455
|
+
/**
|
|
1456
|
+
* Dispatches a `StageEvent` (prefixed with `'stage'`) on the given stage, when it is an `EventTarget`.
|
|
1457
|
+
* @param stage The target stage.
|
|
1458
|
+
* @param type Short event type name.
|
|
1459
|
+
* @param evt The original event.
|
|
1460
|
+
*/
|
|
1400
1461
|
static stageDispatch(stage, type, evt) {
|
|
1401
1462
|
if (stage instanceof EventTarget) {
|
|
1402
1463
|
stage.dispatchEvent(new StageEvent("stage" + type, stage, evt, stage.transformMatrix));
|
|
1403
1464
|
}
|
|
1404
1465
|
}
|
|
1466
|
+
/** Type guard telling whether `viewbox` is a well-formed, finite `Rect` usable as a stage viewbox. */
|
|
1405
1467
|
static isValidViewbox(viewbox) {
|
|
1406
1468
|
return !Utils11.isNullOrEmpty(viewbox) && Rect3.isRect(viewbox) && Number.isFinite(viewbox.x) && Number.isFinite(viewbox.y) && Number.isFinite(viewbox.width) && Number.isFinite(viewbox.height);
|
|
1407
1469
|
}
|
|
@@ -1451,6 +1513,14 @@ var Pacem2DAdapterElement = class extends PacemEventTarget {
|
|
|
1451
1513
|
fill: "#fff"
|
|
1452
1514
|
};
|
|
1453
1515
|
}
|
|
1516
|
+
/**
|
|
1517
|
+
* Rasterizes the given DOM element into an image `Blob`, defaulting to JPEG when `bgColor` is provided
|
|
1518
|
+
* (to flatten transparency against it) and to PNG otherwise.
|
|
1519
|
+
* @param element Element to snapshot.
|
|
1520
|
+
* @param bgColor Background color to flatten transparency against; if set, defaults `type` to `'image/jpeg'`.
|
|
1521
|
+
* @param type Explicit image MIME type, overrides the `bgColor`-based default.
|
|
1522
|
+
* @param quality Compression quality, applicable to lossy formats (defaults to `.9` for JPEG).
|
|
1523
|
+
*/
|
|
1454
1524
|
snapshotElement(element, bgColor, type, quality) {
|
|
1455
1525
|
const jpeg = !Utils12.isNullOrEmpty(bgColor), mime = type ?? (jpeg ? "image/jpeg" : null), compression = quality ?? (jpeg ? JPEG_QUALITY : null);
|
|
1456
1526
|
return Utils12.snapshotElement(element, bgColor, mime, compression);
|