@idraw/util 0.4.0-beta.4 → 0.4.0-beta.41

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 (111) hide show
  1. package/dist/esm/index.d.ts +46 -30
  2. package/dist/esm/index.js +46 -30
  3. package/dist/esm/{lib → tool}/color.js +9 -6
  4. package/dist/esm/{lib → tool}/event.d.ts +4 -2
  5. package/dist/esm/tool/event.js +70 -0
  6. package/dist/esm/{lib → tool}/file.d.ts +2 -1
  7. package/dist/esm/{lib → tool}/file.js +4 -1
  8. package/dist/esm/tool/flat-object.d.ts +6 -0
  9. package/dist/esm/tool/flat-object.js +28 -0
  10. package/dist/esm/tool/get-set-del.d.ts +4 -0
  11. package/dist/esm/tool/get-set-del.js +65 -0
  12. package/dist/esm/tool/hash.d.ts +1 -0
  13. package/dist/esm/tool/hash.js +33 -0
  14. package/dist/esm/{lib → tool}/html.d.ts +1 -1
  15. package/dist/esm/{lib → tool}/html.js +6 -2
  16. package/dist/esm/{lib → tool}/istype.d.ts +1 -0
  17. package/dist/esm/{lib → tool}/istype.js +3 -0
  18. package/dist/esm/tool/merge.d.ts +1 -0
  19. package/dist/esm/tool/merge.js +17 -0
  20. package/dist/esm/tool/omit.d.ts +1 -0
  21. package/dist/esm/tool/omit.js +7 -0
  22. package/dist/esm/tool/store.d.ts +16 -0
  23. package/dist/esm/tool/store.js +52 -0
  24. package/dist/esm/{lib → tool}/time.d.ts +1 -0
  25. package/dist/esm/{lib → tool}/time.js +13 -1
  26. package/dist/esm/tool/unflat-object.d.ts +3 -0
  27. package/dist/esm/tool/unflat-object.js +91 -0
  28. package/dist/esm/tool/uuid.js +13 -0
  29. package/dist/esm/view/box.d.ts +2 -0
  30. package/dist/esm/view/box.js +173 -0
  31. package/dist/esm/{lib → view}/canvas.d.ts +0 -1
  32. package/dist/esm/view/canvas.js +57 -0
  33. package/dist/esm/{lib → view}/check.js +14 -14
  34. package/dist/esm/view/config.d.ts +9 -0
  35. package/dist/esm/{lib → view}/config.js +9 -9
  36. package/dist/esm/{lib → view}/context2d.d.ts +4 -0
  37. package/dist/esm/{lib → view}/context2d.js +20 -0
  38. package/dist/esm/view/controller.d.ts +12 -0
  39. package/dist/esm/view/controller.js +321 -0
  40. package/dist/esm/view/data.d.ts +10 -0
  41. package/dist/esm/view/data.js +202 -0
  42. package/dist/esm/{lib → view}/element.d.ts +5 -0
  43. package/dist/esm/{lib → view}/element.js +65 -4
  44. package/dist/esm/view/flat.d.ts +2 -0
  45. package/dist/esm/view/flat.js +133 -0
  46. package/dist/esm/view/group.d.ts +3 -0
  47. package/dist/esm/view/group.js +81 -0
  48. package/dist/esm/{lib → view}/handle-element.d.ts +11 -1
  49. package/dist/esm/view/handle-element.js +286 -0
  50. package/dist/esm/view/handle-global.d.ts +4 -0
  51. package/dist/esm/view/handle-global.js +28 -0
  52. package/dist/esm/view/handle-layout.d.ts +4 -0
  53. package/dist/esm/view/handle-layout.js +28 -0
  54. package/dist/esm/{lib → view}/is.d.ts +3 -1
  55. package/dist/esm/{lib → view}/is.js +22 -6
  56. package/dist/esm/view/modify-record.d.ts +4 -0
  57. package/dist/esm/view/modify-record.js +10 -0
  58. package/dist/esm/view/point-move-element.d.ts +5 -0
  59. package/dist/esm/view/point-move-element.js +26 -0
  60. package/dist/esm/view/position.d.ts +15 -0
  61. package/dist/esm/view/position.js +79 -0
  62. package/dist/esm/view/rect.js +11 -0
  63. package/dist/esm/view/resize-element.d.ts +2 -0
  64. package/dist/esm/view/resize-element.js +101 -0
  65. package/dist/esm/{lib → view}/rotate.js +8 -13
  66. package/dist/esm/view/text.d.ts +1 -0
  67. package/dist/esm/view/text.js +4 -0
  68. package/dist/esm/{lib → view}/view-box.js +4 -2
  69. package/dist/esm/{lib → view}/view-calc.d.ts +16 -3
  70. package/dist/esm/{lib → view}/view-calc.js +127 -3
  71. package/dist/esm/view/view-content.d.ts +14 -0
  72. package/dist/esm/view/view-content.js +88 -0
  73. package/dist/index.global.js +1977 -326
  74. package/dist/index.global.min.js +1 -1
  75. package/package.json +2 -2
  76. package/dist/esm/lib/canvas.js +0 -81
  77. package/dist/esm/lib/config.d.ts +0 -14
  78. package/dist/esm/lib/controller.d.ts +0 -6
  79. package/dist/esm/lib/controller.js +0 -103
  80. package/dist/esm/lib/data.d.ts +0 -5
  81. package/dist/esm/lib/data.js +0 -92
  82. package/dist/esm/lib/event.js +0 -50
  83. package/dist/esm/lib/handle-element.js +0 -226
  84. package/dist/esm/lib/rect.js +0 -11
  85. package/dist/esm/lib/store.d.ts +0 -12
  86. package/dist/esm/lib/store.js +0 -22
  87. package/dist/esm/lib/uuid.js +0 -31
  88. /package/dist/esm/{lib → tool}/color.d.ts +0 -0
  89. /package/dist/esm/{lib → tool}/image.d.ts +0 -0
  90. /package/dist/esm/{lib → tool}/image.js +0 -0
  91. /package/dist/esm/{lib → tool}/number.d.ts +0 -0
  92. /package/dist/esm/{lib → tool}/number.js +0 -0
  93. /package/dist/esm/{lib → tool}/uuid.d.ts +0 -0
  94. /package/dist/esm/{lib → view}/check.d.ts +0 -0
  95. /package/dist/esm/{lib → view}/load.d.ts +0 -0
  96. /package/dist/esm/{lib → view}/load.js +0 -0
  97. /package/dist/esm/{lib → view}/matrix.d.ts +0 -0
  98. /package/dist/esm/{lib → view}/matrix.js +0 -0
  99. /package/dist/esm/{lib → view}/middleware.d.ts +0 -0
  100. /package/dist/esm/{lib → view}/middleware.js +0 -0
  101. /package/dist/esm/{lib → view}/parser.d.ts +0 -0
  102. /package/dist/esm/{lib → view}/parser.js +0 -0
  103. /package/dist/esm/{lib → view}/point.d.ts +0 -0
  104. /package/dist/esm/{lib → view}/point.js +0 -0
  105. /package/dist/esm/{lib → view}/rect.d.ts +0 -0
  106. /package/dist/esm/{lib → view}/rotate.d.ts +0 -0
  107. /package/dist/esm/{lib → view}/svg-path.d.ts +0 -0
  108. /package/dist/esm/{lib → view}/svg-path.js +0 -0
  109. /package/dist/esm/{lib → view}/vertex.d.ts +0 -0
  110. /package/dist/esm/{lib → view}/vertex.js +0 -0
  111. /package/dist/esm/{lib → view}/view-box.d.ts +0 -0
@@ -27,7 +27,7 @@ export function delay(time) {
27
27
  export function throttle(fn, timeout) {
28
28
  let timer = -1;
29
29
  return function (...args) {
30
- if (timer > 0) {
30
+ if (timer >= 0) {
31
31
  return;
32
32
  }
33
33
  timer = setTimeout(() => {
@@ -36,3 +36,15 @@ export function throttle(fn, timeout) {
36
36
  }, timeout);
37
37
  };
38
38
  }
39
+ export function debounce(fn, timeout) {
40
+ let timer = -1;
41
+ return function (...args) {
42
+ if (timer >= 0) {
43
+ window.clearTimeout(timer);
44
+ }
45
+ timer = setTimeout(() => {
46
+ fn(...args);
47
+ timer = -1;
48
+ }, timeout);
49
+ };
50
+ }
@@ -0,0 +1,3 @@
1
+ type NestedStructure = object | unknown[];
2
+ export declare function unflatObject<T extends Record<string, unknown>>(flatObj: T): NestedStructure;
3
+ export {};
@@ -0,0 +1,91 @@
1
+ export function unflatObject(flatObj) {
2
+ const result = {};
3
+ for (const [flatKey, value] of Object.entries(flatObj)) {
4
+ const pathParts = parseKeyToPath(flatKey);
5
+ buildNestedStructure(result, pathParts, value);
6
+ }
7
+ return result;
8
+ }
9
+ function parseKeyToPath(flatKey) {
10
+ const regex = /([\w-]+)|\[(\d+)\]/g;
11
+ const pathParts = [];
12
+ let match;
13
+ while ((match = regex.exec(flatKey)) !== null) {
14
+ const prop = match[1] || match[2];
15
+ if (prop) {
16
+ pathParts.push(prop);
17
+ }
18
+ }
19
+ return pathParts;
20
+ }
21
+ function buildNestedStructure(currentObj, pathParts, value) {
22
+ let currentLevel = currentObj;
23
+ for (let i = 0; i < pathParts.length; i++) {
24
+ const part = pathParts[i];
25
+ const isArrayPart = isArrayIndex(part);
26
+ const isLast = i === pathParts.length - 1;
27
+ try {
28
+ if (isArrayPart) {
29
+ validateArrayPath(currentLevel, part);
30
+ }
31
+ else {
32
+ validateObjectPath(currentLevel, part);
33
+ }
34
+ }
35
+ catch (e) {
36
+ throw new Error(`Structure conflict at path '${pathParts.slice(0, i + 1).join('.')}': ${e.message}`);
37
+ }
38
+ if (isLast) {
39
+ assignValue(currentLevel, part, value);
40
+ }
41
+ else {
42
+ currentLevel = prepareNextLevel(currentLevel, part, pathParts[i + 1]);
43
+ }
44
+ }
45
+ }
46
+ function isArrayIndex(key) {
47
+ return /^\d+$/.test(key);
48
+ }
49
+ function validateArrayPath(obj, index) {
50
+ if (!Array.isArray(obj)) {
51
+ throw new Error(`Expected array but found ${typeof obj}`);
52
+ }
53
+ const idx = Number(index);
54
+ if (idx > obj.length) {
55
+ obj.length = idx + 1;
56
+ }
57
+ }
58
+ function validateObjectPath(obj, key) {
59
+ if (Array.isArray(obj)) {
60
+ throw new Error(`Cannot create object property '${key}' on array`);
61
+ }
62
+ if (typeof obj !== 'object' || obj === null) {
63
+ throw new Error(`Invalid structure for property '${key}'`);
64
+ }
65
+ }
66
+ function prepareNextLevel(current, part, nextPart) {
67
+ const isNextArray = nextPart ? isArrayIndex(nextPart) : false;
68
+ if (Array.isArray(current)) {
69
+ const index = Number(part);
70
+ if (!current[index]) {
71
+ current[index] = isNextArray ? [] : {};
72
+ }
73
+ return current[index];
74
+ }
75
+ if (!current[part]) {
76
+ current[part] = isNextArray ? [] : {};
77
+ }
78
+ return current[part];
79
+ }
80
+ function assignValue(target, key, value) {
81
+ if (Array.isArray(target)) {
82
+ const index = Number(key);
83
+ if (index >= target.length) {
84
+ target.length = index + 1;
85
+ }
86
+ target[index] = value;
87
+ }
88
+ else {
89
+ target[key] = value;
90
+ }
91
+ }
@@ -0,0 +1,13 @@
1
+ import { generate32Base36Hash } from './hash';
2
+ export function createUUID() {
3
+ function _createStr() {
4
+ return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
5
+ }
6
+ return `${_createStr()}${_createStr()}-${_createStr()}-${_createStr()}-${_createStr()}-${_createStr()}${_createStr()}${_createStr()}`;
7
+ }
8
+ export function createAssetId(assetStr) {
9
+ return `@assets/${generate32Base36Hash(assetStr)}`;
10
+ }
11
+ export function isAssetId(id) {
12
+ return /^@assets\/[0-9a-z-]{0,}$/.test(`${id}`);
13
+ }
@@ -0,0 +1,2 @@
1
+ import type { BoxInfo, Element } from '@idraw/types';
2
+ export declare function elementToBoxInfo(elem: Element): BoxInfo;
@@ -0,0 +1,173 @@
1
+ import { is } from './is';
2
+ export function elementToBoxInfo(elem) {
3
+ const { x, y, w, h, detail } = elem;
4
+ const { borderWidth, borderRadius, boxSizing } = detail;
5
+ let btw = 0;
6
+ let brw = 0;
7
+ let bbw = 0;
8
+ let blw = 0;
9
+ let btlr = 0;
10
+ let btrr = 0;
11
+ let bblr = 0;
12
+ let bbrr = 0;
13
+ if (typeof borderWidth === 'number' && borderWidth > 0) {
14
+ btw = borderWidth;
15
+ brw = borderWidth;
16
+ bbw = borderWidth;
17
+ blw = borderWidth;
18
+ }
19
+ else if (Array.isArray(borderWidth)) {
20
+ btw = is.positiveNum(borderWidth[0]) ? borderWidth[0] : 0;
21
+ brw = is.positiveNum(borderWidth[1]) ? borderWidth[0] : 0;
22
+ bbw = is.positiveNum(borderWidth[2]) ? borderWidth[0] : 0;
23
+ blw = is.positiveNum(borderWidth[3]) ? borderWidth[0] : 0;
24
+ }
25
+ if (typeof borderRadius === 'number' && borderRadius > 0) {
26
+ btlr = borderRadius;
27
+ btrr = borderRadius;
28
+ bblr = borderRadius;
29
+ bbrr = borderRadius;
30
+ }
31
+ else if (Array.isArray(borderRadius)) {
32
+ btlr = is.positiveNum(borderRadius[0]) ? borderRadius[0] : 0;
33
+ btrr = is.positiveNum(borderRadius[0]) ? borderRadius[0] : 0;
34
+ bblr = is.positiveNum(borderRadius[0]) ? borderRadius[0] : 0;
35
+ bbrr = is.positiveNum(borderRadius[0]) ? borderRadius[0] : 0;
36
+ }
37
+ const p0 = { x: x, y: y };
38
+ const p1 = { x: x + w, y: y };
39
+ const p2 = { x: x + w, y: y + h };
40
+ const p3 = { x: x, y: y + h };
41
+ const p0s = { x: x, y: y + btlr };
42
+ const p0e = { x: x + btlr, y: y };
43
+ const p1s = { x: x + w - btrr, y: y };
44
+ const p1e = { x: x + w, y: y + btrr };
45
+ const p2s = { x: x + w, y: y + h - bbrr };
46
+ const p2e = { x: x + w - bbrr, y: y + h };
47
+ const p3s = { x: x + bblr, y: y + h };
48
+ const p3e = { x: x, y: y + h - bblr };
49
+ let op0 = Object.assign({}, p0);
50
+ let op1 = Object.assign({}, p1);
51
+ let op2 = Object.assign({}, p2);
52
+ let op3 = Object.assign({}, p3);
53
+ let op0s = Object.assign({}, p0s);
54
+ let op0e = Object.assign({}, p0e);
55
+ let op1s = Object.assign({}, p1s);
56
+ let op1e = Object.assign({}, p1e);
57
+ let op2s = Object.assign({}, p2s);
58
+ let op2e = Object.assign({}, p2e);
59
+ let op3s = Object.assign({}, p3s);
60
+ let op3e = Object.assign({}, p3e);
61
+ let ip0 = Object.assign({}, p0);
62
+ let ip1 = Object.assign({}, p1);
63
+ let ip2 = Object.assign({}, p2);
64
+ let ip3 = Object.assign({}, p3);
65
+ let ip0s = Object.assign({}, p0s);
66
+ let ip0e = Object.assign({}, p0e);
67
+ let ip1s = Object.assign({}, p1s);
68
+ let ip1e = Object.assign({}, p1e);
69
+ let ip2s = Object.assign({}, p2s);
70
+ let ip2e = Object.assign({}, p2e);
71
+ let ip3s = Object.assign({}, p3s);
72
+ let ip3e = Object.assign({}, p3e);
73
+ if (boxSizing === 'border-box') {
74
+ ip0 = { x: ip0.x + blw, y: ip0.y + btw };
75
+ ip1 = { x: ip1.x - brw, y: ip1.y + btw };
76
+ ip2 = { x: ip2.x - brw, y: ip2.y - bbw };
77
+ ip3 = { x: ip3.x + blw, y: ip3.y - bbw };
78
+ ip0s = { x: ip0s.x + blw, y: ip0s.y + btw };
79
+ ip0e = { x: ip0e.x + blw, y: ip0e.y + btw };
80
+ ip1s = { x: ip1s.x - brw, y: ip1s.y + btw };
81
+ ip1e = { x: ip1e.x - brw, y: ip1e.y + btw };
82
+ ip2s = { x: ip2s.x - brw, y: ip2s.y - bbw };
83
+ ip2e = { x: ip2e.x - brw, y: ip2e.y - bbw };
84
+ ip3s = { x: ip3s.x + blw, y: ip3s.y - bbw };
85
+ ip3e = { x: ip3e.x + blw, y: ip3e.y - bbw };
86
+ }
87
+ else if (boxSizing === 'content-box') {
88
+ op0 = { x: op0.x - blw, y: op0.y - btw };
89
+ op1 = { x: op1.x + brw, y: op1.y - btw };
90
+ op2 = { x: op2.x + brw, y: op2.y + bbw };
91
+ op3 = { x: op3.x - blw, y: op3.y + bbw };
92
+ op0s = { x: op0s.x - blw, y: op0s.y - btw };
93
+ op0e = { x: op0e.x - blw, y: op0e.y - btw };
94
+ op1s = { x: op1s.x + brw, y: op1s.y - btw };
95
+ op1e = { x: op1e.x + brw, y: op1e.y - btw };
96
+ op2s = { x: op2s.x + brw, y: op2s.y + bbw };
97
+ op2e = { x: op2e.x + brw, y: op2e.y + bbw };
98
+ op3s = { x: op3s.x - blw, y: op3s.y + bbw };
99
+ op3e = { x: op3e.x - blw, y: op3e.y + bbw };
100
+ }
101
+ else {
102
+ ip0 = { x: ip0.x + blw / 2, y: ip0.y + btw / 2 };
103
+ ip1 = { x: ip1.x - brw / 2, y: ip1.y + btw / 2 };
104
+ ip2 = { x: ip2.x - brw / 2, y: ip2.y - bbw / 2 };
105
+ ip3 = { x: ip3.x + blw / 2, y: ip3.y - bbw / 2 };
106
+ ip0s = { x: ip0s.x + blw / 2, y: ip0s.y + btw / 2 };
107
+ ip0e = { x: ip0e.x + blw / 2, y: ip0e.y + btw / 2 };
108
+ ip1s = { x: ip1s.x - brw / 2, y: ip1s.y + btw / 2 };
109
+ ip1e = { x: ip1e.x - brw / 2, y: ip1e.y + btw / 2 };
110
+ ip2s = { x: ip2s.x - brw / 2, y: ip2s.y - bbw / 2 };
111
+ ip2e = { x: ip2e.x - brw / 2, y: ip2e.y - bbw / 2 };
112
+ ip3s = { x: ip3s.x + blw / 2, y: ip3s.y - bbw / 2 };
113
+ ip3e = { x: ip3e.x + blw / 2, y: ip3e.y - bbw / 2 };
114
+ op0 = { x: op0.x - blw / 2, y: op0.y - btw / 2 };
115
+ op1 = { x: op1.x + brw / 2, y: op1.y - btw / 2 };
116
+ op2 = { x: op2.x + brw / 2, y: op2.y + bbw / 2 };
117
+ op3 = { x: op3.x - blw / 2, y: op3.y + bbw / 2 };
118
+ op0s = { x: op0s.x - blw / 2, y: op0s.y - btw / 2 };
119
+ op0e = { x: op0e.x - blw / 2, y: op0e.y - btw / 2 };
120
+ op1s = { x: op1s.x + brw / 2, y: op1s.y - btw / 2 };
121
+ op1e = { x: op1e.x + brw / 2, y: op1e.y - btw / 2 };
122
+ op2s = { x: op2s.x + brw / 2, y: op2s.y + bbw / 2 };
123
+ op2e = { x: op2e.x + brw / 2, y: op2e.y + bbw / 2 };
124
+ op3s = { x: op3s.x - blw / 2, y: op3s.y + bbw / 2 };
125
+ op3e = { x: op3e.x - blw / 2, y: op3e.y + bbw / 2 };
126
+ }
127
+ return {
128
+ btw,
129
+ brw,
130
+ bbw,
131
+ blw,
132
+ btlr,
133
+ btrr,
134
+ bblr,
135
+ bbrr,
136
+ p0,
137
+ p1,
138
+ p2,
139
+ p3,
140
+ p0s,
141
+ p0e,
142
+ p1s,
143
+ p1e,
144
+ p2s,
145
+ p2e,
146
+ p3s,
147
+ p3e,
148
+ op0,
149
+ op1,
150
+ op2,
151
+ op3,
152
+ op0s,
153
+ op0e,
154
+ op1s,
155
+ op1e,
156
+ op2s,
157
+ op2e,
158
+ op3s,
159
+ op3e,
160
+ ip0,
161
+ ip1,
162
+ ip2,
163
+ ip3,
164
+ ip0s,
165
+ ip0e,
166
+ ip1s,
167
+ ip1e,
168
+ ip2s,
169
+ ip2e,
170
+ ip3s,
171
+ ip3e
172
+ };
173
+ }
@@ -15,5 +15,4 @@ export declare function createBoardContent(canvas: HTMLCanvasElement, opts: {
15
15
  width: number;
16
16
  height: number;
17
17
  devicePixelRatio: number;
18
- offscreen?: boolean;
19
18
  }): BoardContent;
@@ -0,0 +1,57 @@
1
+ import { Context2D } from './context2d';
2
+ export function createContext2D(opts) {
3
+ const { width, height, ctx, devicePixelRatio } = opts;
4
+ let context = ctx;
5
+ if (!context) {
6
+ const canvas = document.createElement('canvas');
7
+ canvas.width = width * devicePixelRatio;
8
+ canvas.height = height * devicePixelRatio;
9
+ context = canvas.getContext('2d');
10
+ }
11
+ const context2d = new Context2D(context, opts);
12
+ return context2d;
13
+ }
14
+ export function createOffscreenContext2D(opts) {
15
+ const { width, height, devicePixelRatio } = opts;
16
+ const offCanvas = new OffscreenCanvas(width * devicePixelRatio, height * devicePixelRatio);
17
+ const offRenderCtx = offCanvas.getContext('2d');
18
+ const offCtx = offRenderCtx.canvas.getContext('2d');
19
+ const context2d = new Context2D(offCtx, {
20
+ devicePixelRatio,
21
+ offscreenCanvas: offCanvas
22
+ });
23
+ return context2d;
24
+ }
25
+ export function createBoardContent(canvas, opts) {
26
+ const { width, height, devicePixelRatio } = opts;
27
+ const ctxOpts = {
28
+ width,
29
+ height,
30
+ devicePixelRatio
31
+ };
32
+ const ctx = canvas.getContext('2d');
33
+ const viewContext = createOffscreenContext2D(ctxOpts);
34
+ const overlayContext = createOffscreenContext2D(ctxOpts);
35
+ const underlayContext = createOffscreenContext2D(ctxOpts);
36
+ const boardContext = createContext2D(Object.assign({ ctx }, ctxOpts));
37
+ const tempContext = createOffscreenContext2D(ctxOpts);
38
+ const drawView = () => {
39
+ const { width: w, height: h } = viewContext.$getSize();
40
+ boardContext.clearRect(0, 0, w, h);
41
+ boardContext.drawImage(underlayContext.canvas, 0, 0, w, h);
42
+ boardContext.drawImage(viewContext.canvas, 0, 0, w, h);
43
+ boardContext.drawImage(overlayContext.canvas, 0, 0, w, h);
44
+ underlayContext.clearRect(0, 0, w, h);
45
+ viewContext.clearRect(0, 0, w, h);
46
+ overlayContext.clearRect(0, 0, w, h);
47
+ };
48
+ const content = {
49
+ underlayContext,
50
+ viewContext,
51
+ overlayContext,
52
+ boardContext,
53
+ tempContext,
54
+ drawView
55
+ };
56
+ return content;
57
+ }
@@ -11,20 +11,20 @@ function attrs(attrs) {
11
11
  }
12
12
  function box(detail = {}) {
13
13
  const { borderColor, borderRadius, borderWidth } = detail;
14
- if (detail.hasOwnProperty('borderColor') && !is.color(borderColor)) {
14
+ if (Object.prototype.hasOwnProperty.call(detail, 'borderColor') && !is.color(borderColor)) {
15
15
  return false;
16
16
  }
17
- if (detail.hasOwnProperty('borderRadius') && !is.number(borderRadius)) {
17
+ if (Object.prototype.hasOwnProperty.call(detail, 'borderRadius') && !is.number(borderRadius)) {
18
18
  return false;
19
19
  }
20
- if (detail.hasOwnProperty('borderWidth') && !is.number(borderWidth)) {
20
+ if (Object.prototype.hasOwnProperty.call(detail, 'borderWidth') && !is.number(borderWidth)) {
21
21
  return false;
22
22
  }
23
23
  return true;
24
24
  }
25
25
  function rectDesc(detail) {
26
26
  const { background } = detail;
27
- if (detail.hasOwnProperty('background') && !is.color(background)) {
27
+ if (Object.prototype.hasOwnProperty.call(detail, 'background') && !is.color(background)) {
28
28
  return false;
29
29
  }
30
30
  if (!box(detail)) {
@@ -34,13 +34,13 @@ function rectDesc(detail) {
34
34
  }
35
35
  function circleDesc(detail) {
36
36
  const { background, borderColor, borderWidth } = detail;
37
- if (detail.hasOwnProperty('background') && !is.color(background)) {
37
+ if (Object.prototype.hasOwnProperty.call(detail, 'background') && !is.color(background)) {
38
38
  return false;
39
39
  }
40
- if (detail.hasOwnProperty('borderColor') && !is.color(borderColor)) {
40
+ if (Object.prototype.hasOwnProperty.call(detail, 'borderColor') && !is.color(borderColor)) {
41
41
  return false;
42
42
  }
43
- if (detail.hasOwnProperty('borderWidth') && !is.number(borderWidth)) {
43
+ if (Object.prototype.hasOwnProperty.call(detail, 'borderWidth') && !is.number(borderWidth)) {
44
44
  return false;
45
45
  }
46
46
  return true;
@@ -77,25 +77,25 @@ function textDesc(detail) {
77
77
  if (!is.fontSize(fontSize)) {
78
78
  return false;
79
79
  }
80
- if (detail.hasOwnProperty('background') && !is.color(background)) {
80
+ if (Object.prototype.hasOwnProperty.call(detail, 'background') && !is.color(background)) {
81
81
  return false;
82
82
  }
83
- if (detail.hasOwnProperty('fontWeight') && !is.fontWeight(fontWeight)) {
83
+ if (Object.prototype.hasOwnProperty.call(detail, 'fontWeight') && !is.fontWeight(fontWeight)) {
84
84
  return false;
85
85
  }
86
- if (detail.hasOwnProperty('lineHeight') && !is.lineHeight(lineHeight)) {
86
+ if (Object.prototype.hasOwnProperty.call(detail, 'lineHeight') && !is.lineHeight(lineHeight)) {
87
87
  return false;
88
88
  }
89
- if (detail.hasOwnProperty('fontFamily') && !is.fontFamily(fontFamily)) {
89
+ if (Object.prototype.hasOwnProperty.call(detail, 'fontFamily') && !is.fontFamily(fontFamily)) {
90
90
  return false;
91
91
  }
92
- if (detail.hasOwnProperty('textAlign') && !is.textAlign(textAlign)) {
92
+ if (Object.prototype.hasOwnProperty.call(detail, 'textAlign') && !is.textAlign(textAlign)) {
93
93
  return false;
94
94
  }
95
- if (detail.hasOwnProperty('strokeWidth') && !is.strokeWidth(strokeWidth)) {
95
+ if (Object.prototype.hasOwnProperty.call(detail, 'strokeWidth') && !is.strokeWidth(strokeWidth)) {
96
96
  return false;
97
97
  }
98
- if (detail.hasOwnProperty('strokeColor') && !is.color(strokeColor)) {
98
+ if (Object.prototype.hasOwnProperty.call(detail, 'strokeColor') && !is.color(strokeColor)) {
99
99
  return false;
100
100
  }
101
101
  if (!box(detail)) {
@@ -0,0 +1,9 @@
1
+ import type { DefaultElementDetailConfig, ElementSize, ElementRectDetail, ElementCircleDetail, ElementTextDetail, ElementSVGDetail, ElementImageDetail, ElementGroupDetail } from '@idraw/types';
2
+ export declare const defaultText = "Text Element";
3
+ export declare function getDefaultElementDetailConfig(): DefaultElementDetailConfig;
4
+ export declare function getDefaultElementRectDetail(): ElementRectDetail;
5
+ export declare function getDefaultElementCircleDetail(): ElementCircleDetail;
6
+ export declare function getDefaultElementTextDetail(elementSize: ElementSize): ElementTextDetail;
7
+ export declare function getDefaultElementSVGDetail(): ElementSVGDetail;
8
+ export declare function getDefaultElementImageDetail(): ElementImageDetail;
9
+ export declare function getDefaultElementGroupDetail(): ElementGroupDetail;
@@ -1,3 +1,4 @@
1
+ export const defaultText = 'Text Element';
1
2
  export function getDefaultElementDetailConfig() {
2
3
  const config = {
3
4
  boxSizing: 'border-box',
@@ -14,9 +15,10 @@ export function getDefaultElementDetailConfig() {
14
15
  textAlign: 'left',
15
16
  verticalAlign: 'top',
16
17
  fontSize: 16,
17
- lineHeight: 20,
18
18
  fontFamily: 'sans-serif',
19
19
  fontWeight: 400,
20
+ minInlineSize: 'auto',
21
+ wordBreak: 'break-all',
20
22
  overflow: 'hidden'
21
23
  };
22
24
  return config;
@@ -27,24 +29,22 @@ export function getDefaultElementRectDetail() {
27
29
  };
28
30
  return detail;
29
31
  }
30
- export function getDefaultElementCircleDetail(opts) {
32
+ export function getDefaultElementCircleDetail() {
31
33
  const detail = {
32
34
  background: '#D9D9D9',
33
35
  radius: 0
34
36
  };
35
37
  return detail;
36
38
  }
37
- export function getDefaultElementTextDetail(opts) {
38
- var _a;
39
+ export function getDefaultElementTextDetail(elementSize) {
39
40
  const detailConfig = getDefaultElementDetailConfig();
40
- const scale = ((_a = opts === null || opts === void 0 ? void 0 : opts.viewScaleInfo) === null || _a === void 0 ? void 0 : _a.scale) || 1;
41
41
  const detail = {
42
- text: 'Text Element',
42
+ text: defaultText,
43
43
  color: detailConfig.color,
44
44
  fontFamily: detailConfig.fontFamily,
45
45
  fontWeight: detailConfig.fontWeight,
46
- lineHeight: detailConfig.fontSize * scale,
47
- fontSize: detailConfig.fontSize * scale,
46
+ lineHeight: elementSize.w / defaultText.length,
47
+ fontSize: elementSize.w / defaultText.length,
48
48
  textAlign: 'center',
49
49
  verticalAlign: 'middle'
50
50
  };
@@ -62,7 +62,7 @@ export function getDefaultElementImageDetail() {
62
62
  };
63
63
  return detail;
64
64
  }
65
- export function getDefaultElementGroupDetail(opts) {
65
+ export function getDefaultElementGroupDetail() {
66
66
  const detail = {
67
67
  children: [],
68
68
  background: '#D9D9D9',
@@ -5,11 +5,13 @@ export declare class Context2D implements ViewContext2D {
5
5
  $undoPixelRatio(num: number): number;
6
6
  $doPixelRatio(num: number): number;
7
7
  $getContext(): CanvasRenderingContext2D;
8
+ $setContext(ctx: CanvasRenderingContext2D): void;
8
9
  $setFont(opts: {
9
10
  fontSize: number;
10
11
  fontFamily?: string;
11
12
  fontWeight?: 'bold' | number | string;
12
13
  }): void;
14
+ $resetFont(): void;
13
15
  $getOffscreenCanvas(): OffscreenCanvas | null;
14
16
  $resize(opts: {
15
17
  width: number;
@@ -57,6 +59,8 @@ export declare class Context2D implements ViewContext2D {
57
59
  lineTo(x: number, y: number): void;
58
60
  moveTo(x: number, y: number): void;
59
61
  arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): void;
62
+ bezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number): void;
63
+ quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): void;
60
64
  getLineDash(): number[];
61
65
  setLineDash(nums: number[]): void;
62
66
  stroke(path?: Path2D): void;
@@ -10,12 +10,16 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
12
  var _Context2D_ctx, _Context2D_opts;
13
+ const defaultFontSize = 12;
14
+ const defaultFontWeight = '400';
15
+ const defaultFontFamily = `-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji'`;
13
16
  export class Context2D {
14
17
  constructor(ctx, opts) {
15
18
  _Context2D_ctx.set(this, void 0);
16
19
  _Context2D_opts.set(this, void 0);
17
20
  __classPrivateFieldSet(this, _Context2D_ctx, ctx, "f");
18
21
  __classPrivateFieldSet(this, _Context2D_opts, Object.assign({ devicePixelRatio: 1, offscreenCanvas: null }, opts), "f");
22
+ this.$resetFont();
19
23
  }
20
24
  $undoPixelRatio(num) {
21
25
  return num / __classPrivateFieldGet(this, _Context2D_opts, "f").devicePixelRatio;
@@ -26,6 +30,9 @@ export class Context2D {
26
30
  $getContext() {
27
31
  return __classPrivateFieldGet(this, _Context2D_ctx, "f");
28
32
  }
33
+ $setContext(ctx) {
34
+ __classPrivateFieldSet(this, _Context2D_ctx, ctx, "f");
35
+ }
29
36
  $setFont(opts) {
30
37
  const strList = [];
31
38
  if (opts.fontWeight) {
@@ -35,6 +42,13 @@ export class Context2D {
35
42
  strList.push(`${opts.fontFamily || 'sans-serif'}`);
36
43
  __classPrivateFieldGet(this, _Context2D_ctx, "f").font = `${strList.join(' ')}`;
37
44
  }
45
+ $resetFont() {
46
+ this.$setFont({
47
+ fontSize: defaultFontSize,
48
+ fontFamily: defaultFontFamily,
49
+ fontWeight: defaultFontWeight
50
+ });
51
+ }
38
52
  $getOffscreenCanvas() {
39
53
  return __classPrivateFieldGet(this, _Context2D_opts, "f").offscreenCanvas;
40
54
  }
@@ -165,6 +179,12 @@ export class Context2D {
165
179
  arcTo(x1, y1, x2, y2, radius) {
166
180
  return __classPrivateFieldGet(this, _Context2D_ctx, "f").arcTo(this.$doPixelRatio(x1), this.$doPixelRatio(y1), this.$doPixelRatio(x2), this.$doPixelRatio(y2), this.$doPixelRatio(radius));
167
181
  }
182
+ bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y) {
183
+ return __classPrivateFieldGet(this, _Context2D_ctx, "f").bezierCurveTo(this.$doPixelRatio(cp1x), this.$doPixelRatio(cp1y), this.$doPixelRatio(cp2x), this.$doPixelRatio(cp2y), this.$doPixelRatio(x), this.$doPixelRatio(y));
184
+ }
185
+ quadraticCurveTo(cpx, cpy, x, y) {
186
+ return __classPrivateFieldGet(this, _Context2D_ctx, "f").quadraticCurveTo(this.$doPixelRatio(cpx), this.$doPixelRatio(cpy), this.$doPixelRatio(x), this.$doPixelRatio(y));
187
+ }
168
188
  getLineDash() {
169
189
  return __classPrivateFieldGet(this, _Context2D_ctx, "f").getLineDash();
170
190
  }
@@ -0,0 +1,12 @@
1
+ import type { Element, ElementSize, ElementSizeController, ViewScaleInfo, LayoutSizeController } from '@idraw/types';
2
+ export declare function calcElementSizeController(elemSize: ElementSize, opts: {
3
+ groupQueue: Element<'group'>[];
4
+ controllerSize: number;
5
+ rotateControllerSize: number;
6
+ rotateControllerPosition: number;
7
+ viewScaleInfo: ViewScaleInfo;
8
+ }): ElementSizeController;
9
+ export declare function calcLayoutSizeController(layoutSize: Pick<ElementSize, 'x' | 'y' | 'w' | 'h'>, opts: {
10
+ controllerSize?: number;
11
+ viewScaleInfo: ViewScaleInfo;
12
+ }): LayoutSizeController;