@inweb/markup 25.8.19 → 25.8.20

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.
@@ -2,11 +2,11 @@ import { IMarkupEllipse } from "../IMarkupEllipse";
2
2
  export declare class KonvaEllipse implements IMarkupEllipse {
3
3
  private _ref;
4
4
  constructor(params: {
5
- position: {
5
+ position?: {
6
6
  x: number;
7
7
  y: number;
8
8
  };
9
- radius: {
9
+ radius?: {
10
10
  x: number;
11
11
  y: number;
12
12
  };
@@ -4,12 +4,14 @@ export declare class KonvaImage implements IMarkupImage {
4
4
  private _canvasImage;
5
5
  private _ratio;
6
6
  private readonly EPSILON;
7
+ private readonly BASE64_NOT_FOUND;
8
+ private readonly BASE64_HEADER_START;
7
9
  constructor(params: {
8
- position: {
10
+ position?: {
9
11
  x: number;
10
12
  y: number;
11
13
  };
12
- src: string;
14
+ src?: string;
13
15
  width?: number;
14
16
  height?: number;
15
17
  maxWidth?: number;
@@ -2,7 +2,7 @@ import { IMarkupLine, MarkupLineType } from "../IMarkupLine";
2
2
  export declare class KonvaLine implements IMarkupLine {
3
3
  private _ref;
4
4
  constructor(params: {
5
- points: {
5
+ points?: {
6
6
  x: number;
7
7
  y: number;
8
8
  }[];
@@ -2,7 +2,7 @@ import { IMarkupRectangle } from "../IMarkupRectangle";
2
2
  export declare class KonvaRectangle implements IMarkupRectangle {
3
3
  private _ref;
4
4
  constructor(params: {
5
- position: {
5
+ position?: {
6
6
  x: number;
7
7
  y: number;
8
8
  };
@@ -3,11 +3,11 @@ export declare class KonvaText implements IMarkupText {
3
3
  private _ref;
4
4
  private readonly TEXT_FONT_FAMILY;
5
5
  constructor(params: {
6
- position: {
6
+ position?: {
7
7
  x: number;
8
8
  y: number;
9
9
  };
10
- text: string;
10
+ text?: string;
11
11
  rotation?: number;
12
12
  fontSize?: number;
13
13
  color?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inweb/markup",
3
- "version": "25.8.19",
3
+ "version": "25.8.20",
4
4
  "description": "JavaScript 2D markups",
5
5
  "homepage": "https://cloud.opendesign.com/docs/index.html",
6
6
  "license": "SEE LICENSE IN LICENSE",
@@ -26,8 +26,8 @@
26
26
  "docs": "typedoc"
27
27
  },
28
28
  "dependencies": {
29
- "@inweb/eventemitter2": "~25.8.19",
30
- "@inweb/viewer-core": "~25.8.19"
29
+ "@inweb/eventemitter2": "~25.8.20",
30
+ "@inweb/viewer-core": "~25.8.20"
31
31
  },
32
32
  "devDependencies": {
33
33
  "konva": "^9.2.0"
@@ -29,8 +29,8 @@ export class KonvaArrow implements IMarkupArrow {
29
29
 
30
30
  constructor(
31
31
  params: {
32
- start: { x: number; y: number };
33
- end: { x: number; y: number };
32
+ start?: { x: number; y: number };
33
+ end?: { x: number; y: number };
34
34
  color?: string;
35
35
  id?: string;
36
36
  },
@@ -41,7 +41,9 @@ export class KonvaArrow implements IMarkupArrow {
41
41
  return;
42
42
  }
43
43
 
44
- if (!params || !params.start || !params.end) return;
44
+ if (!params) params = {};
45
+ if (!params.start) params.start = { x: 50, y: 50 };
46
+ if (!params.end) params.end = { x: 100, y: 100 };
45
47
 
46
48
  this._ref = new Konva.Arrow({
47
49
  stroke: params.color ?? "#ff0000",
@@ -6,7 +6,7 @@ export class KonvaCloud implements IMarkupCloud {
6
6
 
7
7
  constructor(
8
8
  params: {
9
- position: { x: number; y: number };
9
+ position?: { x: number; y: number };
10
10
  width?: number;
11
11
  height?: number;
12
12
  lineWidth?: number;
@@ -20,7 +20,8 @@ export class KonvaCloud implements IMarkupCloud {
20
20
  return;
21
21
  }
22
22
 
23
- if (!params || !params.position) return;
23
+ if (!params) params = {};
24
+ if (!params.position) params.position = { x: 100, y: 100 };
24
25
 
25
26
  const arcRadius = 16;
26
27
 
@@ -6,8 +6,8 @@ export class KonvaEllipse implements IMarkupEllipse {
6
6
 
7
7
  constructor(
8
8
  params: {
9
- position: { x: number; y: number };
10
- radius: { x: number; y: number };
9
+ position?: { x: number; y: number };
10
+ radius?: { x: number; y: number };
11
11
  lineWidth?: number;
12
12
  color?: string;
13
13
  id?: string;
@@ -19,7 +19,9 @@ export class KonvaEllipse implements IMarkupEllipse {
19
19
  return;
20
20
  }
21
21
 
22
- if (!params || !params.position || !params.radius) return;
22
+ if (!params) params = {};
23
+ if (!params.position) params.position = { x: 100, y: 100 };
24
+ if (!params.radius) params.radius = { x: 25, y: 25 };
23
25
 
24
26
  this._ref = new Konva.Ellipse({
25
27
  stroke: params.color ?? "#ff0000",
@@ -6,11 +6,14 @@ export class KonvaImage implements IMarkupImage {
6
6
  private _canvasImage: HTMLImageElement;
7
7
  private _ratio = 1;
8
8
  private readonly EPSILON = 10e-6;
9
+ private readonly BASE64_NOT_FOUND =
10
+ "data:image/jpeg;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAACXBIWXMAAADsAAAA7AF5KHG9AAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAAAmhJREFUWIXtlr9rVEEQxz+H8RQUJIdeIopYm0vkCg0GBBtbG1NF7Kxt7dR/IGIw/uhTaBNLERURg2kCEUyCYCPi70b0InjGS57FzOZN3r19d+9HJIVfWO52dma/s7Mz8xa2KAaBCWAR+AkECWOmSOIdwC1gtQOpHc+NfQ8wClQ8+1d0vcdH/lQ3bSIRGAZ2pTjAqNovANXIWlXlAXA2zvi2Ln4AjqYgtagYEutENSLvjRoOImFv5iB32Ae8UrLXwFBk3h9ndF0VJnKSO9gTu3yKu5Z1LKnS8YIcABgw5Ks692JZFXcXRJ46Aq6kikCnHNi/mQ50WwVtfaIoBzL3gRk2drSscJ2wrc4VvUoe2wn/41/iBfoVLRnBGnDSY3AAKacy8AmYR+o7K1zCl6wgrgpOAc/MuhvfgMuk+1JGHQgSBcAloKXy78AjYBppJk5/noTulseBMZ23iD/piHFkEdgTQzKk+5wHjmHC3cmBg0BD5xcSTrFXyQPgIWFtDwMvab+2N8DpbhyY1v/3E8gdDgNfVX9SCVZ0/gW4B0wB71S2BpxLcuCM/jaQSHSDEeAX4VMuAG4gTzyHbcAVXXO6GxxwIX+vvxe7JHcYQ07nHqklj96UIW/YhSWzMKcep8VVtf8B1Dw6h4DfhB+sdbgn2R+gnoEc5NR3dZ+3QJ9H74HqXLPCGlJyTfI9y3YCs0owq3OLOpKkLeBI1HhSDT/mdKIPiUCARMTlQx34TMLjtww8IczmO8AJ/N/2JNSQXAiQ671JePePge0+wzJSQq4FFzlaenIvucUAkiQLhC/mLGNZ9xgn5s63BP4CCk0QDtm4BhoAAAAASUVORK5CYII=";
11
+ private readonly BASE64_HEADER_START = "data:image/";
9
12
 
10
13
  constructor(
11
14
  params: {
12
- position: { x: number; y: number };
13
- src: string;
15
+ position?: { x: number; y: number };
16
+ src?: string;
14
17
  width?: number;
15
18
  height?: number;
16
19
  maxWidth?: number;
@@ -20,7 +23,9 @@ export class KonvaImage implements IMarkupImage {
20
23
  ref = null
21
24
  ) {
22
25
  if (ref) {
23
- // if (ref.height() === 0 || ref.width() === 0) return;
26
+ if (!ref.src || !ref.src.startsWith(this.BASE64_HEADER_START)) ref.src = this.BASE64_NOT_FOUND;
27
+ if (ref.height() <= this.EPSILON) ref.height(32);
28
+ if (ref.width() <= this.EPSILON) ref.width(32);
24
29
 
25
30
  this._ref = ref;
26
31
  this._canvasImage = ref.image();
@@ -28,22 +33,16 @@ export class KonvaImage implements IMarkupImage {
28
33
  this._ref.height() <= this.EPSILON || this._ref.width() <= this.EPSILON
29
34
  ? 1
30
35
  : this._ref.height() / this._ref.width();
36
+
31
37
  return;
32
38
  }
33
39
 
34
- if (!params || !params.position || !params.src) return;
40
+ if (!params) params = {};
41
+ if (!params.position) params.position = { x: 50, y: 50 };
42
+ if (!params.src || !params.src.startsWith(this.BASE64_HEADER_START)) params.src = this.BASE64_NOT_FOUND;
35
43
 
36
44
  this._canvasImage = new Image();
37
45
 
38
- this._ref = new Konva.Image({
39
- x: params.position.x,
40
- y: params.position.y,
41
- image: this._canvasImage,
42
- width: params.width ?? 0,
43
- height: params.height ?? 0,
44
- draggable: true,
45
- });
46
-
47
46
  this._canvasImage.onload = () => {
48
47
  this._ref.image(this._canvasImage);
49
48
  if (this._ref.height() <= this.EPSILON) this._ref.height(this._canvasImage.height);
@@ -74,8 +73,22 @@ export class KonvaImage implements IMarkupImage {
74
73
  }
75
74
  };
76
75
 
76
+ this._canvasImage.onerror = () => {
77
+ this._canvasImage.onerror = function () {};
78
+ this._canvasImage.src = this.BASE64_NOT_FOUND;
79
+ };
80
+
77
81
  this._canvasImage.src = params.src;
78
82
 
83
+ this._ref = new Konva.Image({
84
+ x: params.position.x,
85
+ y: params.position.y,
86
+ image: this._canvasImage,
87
+ width: params.width ?? 0,
88
+ height: params.height ?? 0,
89
+ draggable: true,
90
+ });
91
+
79
92
  this._ref.on("transform", (e) => {
80
93
  const attrs = e.target.attrs;
81
94
 
@@ -12,7 +12,7 @@ export class KonvaLine implements IMarkupLine {
12
12
 
13
13
  constructor(
14
14
  params: {
15
- points: { x: number; y: number }[];
15
+ points?: { x: number; y: number }[];
16
16
  type?: MarkupLineType;
17
17
  width?: number;
18
18
  color?: string;
@@ -25,7 +25,12 @@ export class KonvaLine implements IMarkupLine {
25
25
  return;
26
26
  }
27
27
 
28
- if (!params || !params.points) return;
28
+ if (!params) params = {};
29
+ if (!params.points)
30
+ params.points = [
31
+ { x: 50, y: 50 },
32
+ { x: 100, y: 100 },
33
+ ];
29
34
 
30
35
  const konvaPoints = [];
31
36
  params.points.forEach((point) => konvaPoints.push(point.x, point.y));
@@ -6,7 +6,7 @@ export class KonvaRectangle implements IMarkupRectangle {
6
6
 
7
7
  constructor(
8
8
  params: {
9
- position: { x: number; y: number };
9
+ position?: { x: number; y: number };
10
10
  width?: number;
11
11
  height?: number;
12
12
  lineWidth?: number;
@@ -20,7 +20,8 @@ export class KonvaRectangle implements IMarkupRectangle {
20
20
  return;
21
21
  }
22
22
 
23
- if (!params || !params.position) return;
23
+ if (!params) params = {};
24
+ if (!params.position) params.position = { x: 100, y: 100 };
24
25
 
25
26
  this._ref = new Konva.Rect({
26
27
  stroke: params.color ?? "#ff0000",
@@ -7,8 +7,8 @@ export class KonvaText implements IMarkupText {
7
7
 
8
8
  constructor(
9
9
  params: {
10
- position: { x: number; y: number };
11
- text: string;
10
+ position?: { x: number; y: number };
11
+ text?: string;
12
12
  rotation?: number;
13
13
  fontSize?: number;
14
14
  color?: string;
@@ -21,7 +21,9 @@ export class KonvaText implements IMarkupText {
21
21
  return;
22
22
  }
23
23
 
24
- if (!params || !params.position || !params.text) return;
24
+ if (!params) params = {};
25
+ if (!params.position) params.position = { x: 100, y: 100 };
26
+ if (!params.text) params.text = "default";
25
27
 
26
28
  this._ref = new Konva.Text({
27
29
  x: params.position.x,