@inweb/markup 25.7.4

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.
Files changed (50) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +7 -0
  3. package/dist/markup.js +13390 -0
  4. package/dist/markup.js.map +1 -0
  5. package/dist/markup.min.js +1 -0
  6. package/dist/markup.module.js +1838 -0
  7. package/dist/markup.module.js.map +1 -0
  8. package/lib/index.d.ts +12 -0
  9. package/lib/markup/IMarkup.d.ts +130 -0
  10. package/lib/markup/IMarkupArrow.d.ts +52 -0
  11. package/lib/markup/IMarkupCloud.d.ts +50 -0
  12. package/lib/markup/IMarkupColorable.d.ts +15 -0
  13. package/lib/markup/IMarkupEllipse.d.ts +50 -0
  14. package/lib/markup/IMarkupImage.d.ts +50 -0
  15. package/lib/markup/IMarkupLine.d.ts +43 -0
  16. package/lib/markup/IMarkupObject.d.ts +47 -0
  17. package/lib/markup/IMarkupRectangle.d.ts +50 -0
  18. package/lib/markup/IMarkupText.d.ts +40 -0
  19. package/lib/markup/IWorldTransform.d.ts +39 -0
  20. package/lib/markup/Konva/KonvaArrow.d.ts +46 -0
  21. package/lib/markup/Konva/KonvaCloud.d.ts +35 -0
  22. package/lib/markup/Konva/KonvaEllipse.d.ts +40 -0
  23. package/lib/markup/Konva/KonvaImage.d.ts +36 -0
  24. package/lib/markup/Konva/KonvaLine.d.ts +35 -0
  25. package/lib/markup/Konva/KonvaMarkup.d.ts +82 -0
  26. package/lib/markup/Konva/KonvaRectangle.d.ts +38 -0
  27. package/lib/markup/Konva/KonvaText.d.ts +37 -0
  28. package/lib/markup/Konva/MarkupColor.d.ts +38 -0
  29. package/package.json +40 -0
  30. package/src/index.ts +35 -0
  31. package/src/markup/IMarkup.ts +173 -0
  32. package/src/markup/IMarkupArrow.ts +69 -0
  33. package/src/markup/IMarkupCloud.ts +78 -0
  34. package/src/markup/IMarkupColorable.ts +39 -0
  35. package/src/markup/IMarkupEllipse.ts +78 -0
  36. package/src/markup/IMarkupImage.ts +78 -0
  37. package/src/markup/IMarkupLine.ts +70 -0
  38. package/src/markup/IMarkupObject.ts +78 -0
  39. package/src/markup/IMarkupRectangle.ts +78 -0
  40. package/src/markup/IMarkupText.ts +66 -0
  41. package/src/markup/IWorldTransform.ts +46 -0
  42. package/src/markup/Konva/KonvaArrow.ts +147 -0
  43. package/src/markup/Konva/KonvaCloud.ts +213 -0
  44. package/src/markup/Konva/KonvaEllipse.ts +150 -0
  45. package/src/markup/Konva/KonvaImage.ts +149 -0
  46. package/src/markup/Konva/KonvaLine.ts +136 -0
  47. package/src/markup/Konva/KonvaMarkup.ts +1264 -0
  48. package/src/markup/Konva/KonvaRectangle.ts +149 -0
  49. package/src/markup/Konva/KonvaText.ts +141 -0
  50. package/src/markup/Konva/MarkupColor.ts +82 -0
@@ -0,0 +1,149 @@
1
+ import Konva from "konva";
2
+ import { IMarkupRectangle } from "../IMarkupRectangle";
3
+ import { IMarkupColorable } from "../IMarkupColorable";
4
+
5
+ export class KonvaRectangle implements IMarkupRectangle, IMarkupColorable {
6
+ private _ref: Konva.Rect;
7
+
8
+ constructor(
9
+ params: {
10
+ position: { x: number; y: number };
11
+ width?: number;
12
+ height?: number;
13
+ lineWidth?: number;
14
+ color?: string;
15
+ id?: string;
16
+ },
17
+ ref = null
18
+ ) {
19
+ if (ref) {
20
+ this._ref = ref;
21
+ return;
22
+ }
23
+
24
+ if (!params.position) return;
25
+
26
+ this._ref = new Konva.Rect({
27
+ stroke: params.color ?? "#ff0000",
28
+ strokeWidth: params.lineWidth ?? 4,
29
+ globalCompositeOperation: "source-over",
30
+ lineCap: "round",
31
+ lineJoin: "round",
32
+ x: params.position.x,
33
+ y: params.position.y,
34
+ width: params.width ?? 200,
35
+ height: params.height ?? 200,
36
+ draggable: true,
37
+ strokeScaleEnabled: false,
38
+ });
39
+
40
+ this._ref.on("transform", (e) => {
41
+ const attrs = e.target.attrs;
42
+
43
+ if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
44
+
45
+ const scaleByX = Math.abs(attrs.scaleX - 1) > 10e-6;
46
+ const scaleByY = Math.abs(attrs.scaleY - 1) > 10e-6;
47
+
48
+ let newWidth = this._ref.width();
49
+ if (scaleByX) newWidth *= attrs.scaleX;
50
+ let newHeight = this._ref.height();
51
+ if (scaleByY) newHeight *= attrs.scaleY;
52
+
53
+ const minWidth = 50;
54
+ const minHeight = 50;
55
+
56
+ if (newWidth < minWidth) newWidth = minWidth;
57
+ if (newHeight < minHeight) newHeight = minHeight;
58
+
59
+ if (scaleByX) {
60
+ this._ref.width(newWidth);
61
+ }
62
+
63
+ if (scaleByY) {
64
+ this._ref.height(newHeight);
65
+ }
66
+
67
+ this._ref.scale({ x: 1, y: 1 });
68
+ });
69
+
70
+ this._ref.id(this._ref._id.toString());
71
+ }
72
+
73
+ getPosition(): { x: number; y: number } {
74
+ return this._ref.position();
75
+ }
76
+
77
+ getWidth(): number {
78
+ return this._ref.width();
79
+ }
80
+
81
+ getHeigth(): number {
82
+ return this._ref.height();
83
+ }
84
+
85
+ setWidth(w: number) {
86
+ this._ref.width(w);
87
+ }
88
+
89
+ setHeight(h: number) {
90
+ this._ref.height(h);
91
+ }
92
+
93
+ setPosition(x: number, y: number) {
94
+ this._ref.setPosition({ x, y });
95
+ }
96
+
97
+ ref() {
98
+ return this._ref;
99
+ }
100
+
101
+ id(): string {
102
+ return this._ref.id();
103
+ }
104
+
105
+ enableMouseEditing(value: boolean): void {
106
+ this._ref.draggable(value);
107
+ }
108
+
109
+ type(): string {
110
+ return "rectangle";
111
+ }
112
+
113
+ getColor(): string {
114
+ return this._ref.stroke() as string;
115
+ }
116
+
117
+ setColor(hex: string): void {
118
+ this._ref.stroke(hex);
119
+ }
120
+
121
+ getRotation(): number {
122
+ return this._ref.rotation();
123
+ }
124
+
125
+ setRotation(degrees: number): void {
126
+ this._ref.rotation(degrees);
127
+ }
128
+
129
+ getZIndex(): number {
130
+ return this._ref.zIndex();
131
+ }
132
+
133
+ setZIndex(zIndex: number): void {
134
+ this._ref.zIndex(zIndex);
135
+ }
136
+
137
+ delete(): void {
138
+ this._ref.destroy();
139
+ this._ref = null;
140
+ }
141
+
142
+ setLineWidth(size: number): void {
143
+ this._ref.strokeWidth(size);
144
+ }
145
+
146
+ getLineWidth(): number {
147
+ return this._ref.strokeWidth();
148
+ }
149
+ }
@@ -0,0 +1,141 @@
1
+ import Konva from "konva";
2
+ import { IMarkupText } from "../IMarkupText";
3
+ import { IMarkupColorable } from "../IMarkupColorable";
4
+
5
+ export class KonvaText implements IMarkupText, IMarkupColorable {
6
+ private _ref: Konva.Text;
7
+ private readonly TEXT_FONT_FAMILY = "Calibri";
8
+
9
+ constructor(
10
+ params: {
11
+ position: { x: number; y: number };
12
+ text: string;
13
+ rotation?: number;
14
+ fontSize?: number;
15
+ color?: string;
16
+ id?: string;
17
+ },
18
+ ref = null
19
+ ) {
20
+ if (ref) {
21
+ this._ref = ref;
22
+ return;
23
+ }
24
+
25
+ if (!params || !params.text) return;
26
+
27
+ this._ref = new Konva.Text({
28
+ x: params.position.x,
29
+ y: params.position.y,
30
+ text: params.text,
31
+ fontSize: params.fontSize ?? 34,
32
+ fontFamily: this.TEXT_FONT_FAMILY,
33
+ fill: params.color ?? "#ff0000",
34
+ align: "left",
35
+ draggable: true,
36
+ rotation: params.rotation ?? 0,
37
+ });
38
+
39
+ this._ref.width(this._ref.getTextWidth());
40
+
41
+ this._ref.on("transform", (e) => {
42
+ const attrs = e.target.attrs;
43
+
44
+ if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
45
+
46
+ const scaleByX = Math.abs(attrs.scaleX - 1) > 10e-6;
47
+ const scaleByY = Math.abs(attrs.scaleY - 1) > 10e-6;
48
+
49
+ let newWidth = this._ref.width();
50
+ if (scaleByX) newWidth *= attrs.scaleX;
51
+ let newHeight = this._ref.height();
52
+ if (scaleByY) newHeight *= attrs.scaleY;
53
+
54
+ const minWidth = 50;
55
+
56
+ if (newWidth < minWidth) newWidth = minWidth;
57
+ if (newHeight < Math.round(this.getFontSize())) newHeight = Math.round(this.getFontSize());
58
+
59
+ if (scaleByX) {
60
+ this._ref.width(newWidth);
61
+ }
62
+
63
+ if (scaleByY) {
64
+ this._ref.height(newHeight);
65
+ }
66
+
67
+ this._ref.scale({ x: 1, y: 1 });
68
+ });
69
+
70
+ this._ref.id(this._ref._id.toString());
71
+ }
72
+
73
+ ref() {
74
+ return this._ref;
75
+ }
76
+
77
+ id(): string {
78
+ return this._ref.id();
79
+ }
80
+
81
+ enableMouseEditing(value: boolean) {
82
+ this._ref.draggable(value);
83
+ }
84
+
85
+ type(): string {
86
+ return "text";
87
+ }
88
+
89
+ getColor(): string {
90
+ return this._ref.fill() as string;
91
+ }
92
+
93
+ setColor(hex: string) {
94
+ this._ref.fill(hex);
95
+ }
96
+
97
+ getRotation(): number {
98
+ return this._ref.rotation();
99
+ }
100
+
101
+ setRotation(degrees: number): void {
102
+ this._ref.rotation(degrees);
103
+ }
104
+
105
+ getZIndex(): number {
106
+ return this._ref.zIndex();
107
+ }
108
+
109
+ setZIndex(zIndex: number): void {
110
+ this._ref.zIndex(zIndex);
111
+ }
112
+
113
+ delete() {
114
+ this._ref.destroy();
115
+ this._ref = null;
116
+ }
117
+
118
+ getText(): string {
119
+ return this._ref.text();
120
+ }
121
+
122
+ setText(text: string): void {
123
+ this._ref.text(text);
124
+ }
125
+
126
+ getPosition(): { x: number; y: number } {
127
+ return this._ref.getPosition();
128
+ }
129
+
130
+ setPosition(x: number, y: number) {
131
+ this._ref.setPosition({ x, y });
132
+ }
133
+
134
+ getFontSize() {
135
+ return this._ref.fontSize();
136
+ }
137
+
138
+ setFontSize(size: number) {
139
+ this._ref.fontSize(size);
140
+ }
141
+ }
@@ -0,0 +1,82 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2002-2024, Open Design Alliance (the "Alliance").
3
+ // All rights reserved.
4
+ //
5
+ // This software and its documentation and related materials are owned by
6
+ // the Alliance. The software may only be incorporated into application
7
+ // programs owned by members of the Alliance, subject to a signed
8
+ // Membership Agreement and Supplemental Software License Agreement with the
9
+ // Alliance. The structure and organization of this software are the valuable
10
+ // trade secrets of the Alliance and its suppliers. The software is also
11
+ // protected by copyright law and international treaty provisions. Application
12
+ // programs incorporating this software must include the following statement
13
+ // with their copyright notices:
14
+ //
15
+ // This application incorporates Open Design Alliance software pursuant to a
16
+ // license agreement with Open Design Alliance.
17
+ // Open Design Alliance Copyright (C) 2002-2024 by Open Design Alliance.
18
+ // All rights reserved.
19
+ //
20
+ // By use of this software, its documentation or related materials, you
21
+ // acknowledge and accept the above terms.
22
+ ///////////////////////////////////////////////////////////////////////////////
23
+
24
+ /**
25
+ * Markup color.
26
+ */
27
+ export class MarkupColor {
28
+ public R: number;
29
+ public G: number;
30
+ public B: number;
31
+
32
+ private _hex: string;
33
+
34
+ /**
35
+ * Color in #000000 format
36
+ */
37
+ get HexColor(): string {
38
+ return "#" + this._hex;
39
+ }
40
+
41
+ /**
42
+ * Color as object with r,g,b properties
43
+ */
44
+ get RGB(): { r: number; g: number; b: number } {
45
+ return { r: this.R, g: this.G, b: this.B };
46
+ }
47
+
48
+ /**
49
+ * Create an instance of Color
50
+ *
51
+ * @param r - Red color in [0,255] range
52
+ * @param g - Green color in [0,255] range
53
+ * @param b - Blue color in [0,255] range
54
+ */
55
+ constructor(r: number, g: number, b: number) {
56
+ this.setColor(r, g, b);
57
+ }
58
+
59
+ /**
60
+ * Set Color for current instance
61
+ *
62
+ * @param r - Red color in [0,255] range
63
+ * @param g - Green color in [0,255] range
64
+ * @param b - Blue color in [0,255] range
65
+ */
66
+ public setColor(r: number, g: number, b: number): void {
67
+ this.R = r;
68
+ this.G = g;
69
+ this.B = b;
70
+
71
+ this._hex = this.rgbToHex(r, g, b);
72
+ }
73
+
74
+ private rgbToHex(r: number, g: number, b: number): string {
75
+ const valueToHex = (c) => {
76
+ const hex = c.toString(16);
77
+ return hex === "0" ? "00" : hex;
78
+ };
79
+
80
+ return valueToHex(r) + valueToHex(g) + valueToHex(b);
81
+ }
82
+ }