@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.
@@ -0,0 +1,140 @@
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 { Watch, PropertyConverters, Utils } from '@pacem/pacem-core';
8
+ import { Matrix2D } from '@pacem/pacem-foundation';
9
+ import { DrawableElement } from './drawable-element';
10
+ //namespace Pacem.Components.Drawing {
11
+ const DEG2RAD = Math.PI / 180.0;
12
+ export class UiElement extends DrawableElement {
13
+ #transformMatrix = Matrix2D.identity;
14
+ viewActivatedCallback() {
15
+ super.viewActivatedCallback();
16
+ this._updateTransformMatrix();
17
+ }
18
+ propertyChangedCallback(name, old, val, first) {
19
+ super.propertyChangedCallback(name, old, val, first);
20
+ if (!first) {
21
+ switch (name) {
22
+ case 'rotate':
23
+ case 'scaleX':
24
+ case 'scaleY':
25
+ case 'translateX':
26
+ case 'translateY':
27
+ this._updateTransformMatrix();
28
+ // flow down
29
+ case 'opacity':
30
+ this.stage?.draw(this);
31
+ break;
32
+ }
33
+ }
34
+ }
35
+ _updateTransformMatrix() {
36
+ let rotation = DEG2RAD * (this.rotate ?? 0), cos = Math.cos(rotation), sin = Math.sin(rotation), a = (this.scaleX ?? 1) * cos, b = -sin, c = sin, d = (this.scaleY ?? 1) * cos, e = this.translateX ?? 0, f = this.translateY ?? 0;
37
+ this.#transformMatrix = { a, b, c, d, e, f };
38
+ }
39
+ /** @internal */
40
+ get transformMatrix() {
41
+ const m = this.#transformMatrix;
42
+ return { a: m.a, b: m.b, c: m.c, d: m.d, e: m.e, f: m.f };
43
+ }
44
+ }
45
+ __decorate([
46
+ Watch({ emit: false, converter: PropertyConverters.Number })
47
+ ], UiElement.prototype, "rotate", void 0);
48
+ __decorate([
49
+ Watch({ emit: false, converter: PropertyConverters.Number })
50
+ ], UiElement.prototype, "scaleX", void 0);
51
+ __decorate([
52
+ Watch({ emit: false, converter: PropertyConverters.Number })
53
+ ], UiElement.prototype, "scaleY", void 0);
54
+ __decorate([
55
+ Watch({ emit: false, converter: PropertyConverters.Number })
56
+ ], UiElement.prototype, "translateX", void 0);
57
+ __decorate([
58
+ Watch({ emit: false, converter: PropertyConverters.Number })
59
+ ], UiElement.prototype, "translateY", void 0);
60
+ __decorate([
61
+ Watch({ emit: false, converter: PropertyConverters.Number })
62
+ ], UiElement.prototype, "opacity", void 0);
63
+ export class PresentationElement extends UiElement {
64
+ propertyChangedCallback(name, old, val, first) {
65
+ super.propertyChangedCallback(name, old, val, first);
66
+ if (!first) {
67
+ switch (name) {
68
+ case 'stroke':
69
+ case 'lineWidth':
70
+ case 'lineJoin':
71
+ case 'lineCap':
72
+ case 'dashArray':
73
+ case 'fill':
74
+ if (!Utils.isNull(this.stage)) {
75
+ this.stage.draw(this);
76
+ }
77
+ break;
78
+ }
79
+ }
80
+ }
81
+ }
82
+ __decorate([
83
+ Watch({ emit: false, converter: PropertyConverters.String })
84
+ ], PresentationElement.prototype, "stroke", void 0);
85
+ __decorate([
86
+ Watch({ emit: false, converter: PropertyConverters.String })
87
+ ], PresentationElement.prototype, "fill", void 0);
88
+ __decorate([
89
+ Watch({
90
+ emit: false, converter: {
91
+ convert: (attr) => attr?.split(',').map(i => parseInt(i)).filter(i => !Number.isNaN(i)),
92
+ convertBack: (prop) => prop?.join(',')
93
+ }
94
+ })
95
+ ], PresentationElement.prototype, "dashArray", void 0);
96
+ __decorate([
97
+ Watch({ emit: false, converter: PropertyConverters.Number })
98
+ ], PresentationElement.prototype, "lineWidth", void 0);
99
+ __decorate([
100
+ Watch({ emit: false, converter: PropertyConverters.String })
101
+ ], PresentationElement.prototype, "lineJoin", void 0);
102
+ __decorate([
103
+ Watch({ emit: false, converter: PropertyConverters.String })
104
+ ], PresentationElement.prototype, "lineCap", void 0);
105
+ export class ShapeElement extends PresentationElement {
106
+ propertyChangedCallback(name, old, val, first) {
107
+ super.propertyChangedCallback(name, old, val, first);
108
+ if (!first) {
109
+ switch (name) {
110
+ case 'data':
111
+ this.stage?.draw(this);
112
+ break;
113
+ }
114
+ }
115
+ }
116
+ viewActivatedCallback() {
117
+ super.viewActivatedCallback();
118
+ this.recomputeShape();
119
+ }
120
+ recomputeShape() {
121
+ const { pathData, vertices, boundingRect } = this.getShapeGeometry();
122
+ this.#vertices = vertices;
123
+ this.#boundingRect = boundingRect;
124
+ this.data = pathData;
125
+ }
126
+ get pathData() {
127
+ return this.data;
128
+ }
129
+ #boundingRect;
130
+ get boundingRect() {
131
+ return this.#boundingRect;
132
+ }
133
+ #vertices;
134
+ get vertices() {
135
+ return this.#vertices;
136
+ }
137
+ }
138
+ __decorate([
139
+ Watch({ emit: false, converter: PropertyConverters.String })
140
+ ], ShapeElement.prototype, "data", void 0);
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@pacem/pacem-2d",
3
+ "files": [
4
+ "dist/browser/*.*",
5
+ "dist/bundle/*.*",
6
+ "dist/esm/*.*",
7
+ "typings/*.*",
8
+ "README.md",
9
+ "LICENSE",
10
+ "NOTICE",
11
+ "package.json"
12
+ ],
13
+ "type": "module",
14
+ "dependencies": {
15
+ "@pacem/pacem-foundation": "*",
16
+ "@pacem/pacem-core": "*"
17
+ },
18
+ "main": "./dist/esm/index.js",
19
+ "module": "./dist/esm/index.js",
20
+ "typings": "./typings/index.d.ts",
21
+ "exports": {
22
+ ".": {
23
+ "import": "./dist/esm/index.js",
24
+ "types": "./typings/index.d.ts"
25
+ }
26
+ },
27
+ "version": "1.0.0-abel",
28
+ "author": {
29
+ "name": "Pacem",
30
+ "url": "https://pacem.it"
31
+ },
32
+ "license": "Apache-2.0",
33
+ "homepage": "https://js.pacem.it",
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "git+https://github.com/pacem-it/pacem.git"
37
+ }
38
+ }