@nasser-sw/fabric 7.0.1-beta7 → 7.0.1-beta9

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 (148) hide show
  1. package/debug/konva-master/CHANGELOG.md +1475 -0
  2. package/debug/konva-master/LICENSE +22 -0
  3. package/debug/konva-master/README.md +209 -0
  4. package/debug/konva-master/gulpfile.mjs +110 -0
  5. package/debug/konva-master/package.json +139 -0
  6. package/debug/konva-master/release.sh +62 -0
  7. package/debug/konva-master/resources/doc-includes/ContainerParams.txt +6 -0
  8. package/debug/konva-master/resources/doc-includes/NodeParams.txt +20 -0
  9. package/debug/konva-master/resources/doc-includes/ShapeParams.txt +53 -0
  10. package/debug/konva-master/resources/jsdoc.conf.json +28 -0
  11. package/debug/konva-master/rollup.config.mjs +32 -0
  12. package/debug/konva-master/src/Animation.ts +237 -0
  13. package/debug/konva-master/src/BezierFunctions.ts +826 -0
  14. package/debug/konva-master/src/Canvas.ts +230 -0
  15. package/debug/konva-master/src/Container.ts +649 -0
  16. package/debug/konva-master/src/Context.ts +1017 -0
  17. package/debug/konva-master/src/Core.ts +5 -0
  18. package/debug/konva-master/src/DragAndDrop.ts +173 -0
  19. package/debug/konva-master/src/Factory.ts +246 -0
  20. package/debug/konva-master/src/FastLayer.ts +29 -0
  21. package/debug/konva-master/src/Global.ts +210 -0
  22. package/debug/konva-master/src/Group.ts +31 -0
  23. package/debug/konva-master/src/Layer.ts +546 -0
  24. package/debug/konva-master/src/Node.ts +3477 -0
  25. package/debug/konva-master/src/PointerEvents.ts +67 -0
  26. package/debug/konva-master/src/Shape.ts +2081 -0
  27. package/debug/konva-master/src/Stage.ts +1000 -0
  28. package/debug/konva-master/src/Tween.ts +811 -0
  29. package/debug/konva-master/src/Util.ts +1123 -0
  30. package/debug/konva-master/src/Validators.ts +210 -0
  31. package/debug/konva-master/src/_CoreInternals.ts +85 -0
  32. package/debug/konva-master/src/_FullInternals.ts +171 -0
  33. package/debug/konva-master/src/canvas-backend.ts +36 -0
  34. package/debug/konva-master/src/filters/Blur.ts +388 -0
  35. package/debug/konva-master/src/filters/Brighten.ts +48 -0
  36. package/debug/konva-master/src/filters/Brightness.ts +30 -0
  37. package/debug/konva-master/src/filters/Contrast.ts +75 -0
  38. package/debug/konva-master/src/filters/Emboss.ts +207 -0
  39. package/debug/konva-master/src/filters/Enhance.ts +154 -0
  40. package/debug/konva-master/src/filters/Grayscale.ts +25 -0
  41. package/debug/konva-master/src/filters/HSL.ts +108 -0
  42. package/debug/konva-master/src/filters/HSV.ts +106 -0
  43. package/debug/konva-master/src/filters/Invert.ts +23 -0
  44. package/debug/konva-master/src/filters/Kaleidoscope.ts +274 -0
  45. package/debug/konva-master/src/filters/Mask.ts +220 -0
  46. package/debug/konva-master/src/filters/Noise.ts +44 -0
  47. package/debug/konva-master/src/filters/Pixelate.ts +107 -0
  48. package/debug/konva-master/src/filters/Posterize.ts +46 -0
  49. package/debug/konva-master/src/filters/RGB.ts +82 -0
  50. package/debug/konva-master/src/filters/RGBA.ts +103 -0
  51. package/debug/konva-master/src/filters/Sepia.ts +27 -0
  52. package/debug/konva-master/src/filters/Solarize.ts +29 -0
  53. package/debug/konva-master/src/filters/Threshold.ts +44 -0
  54. package/debug/konva-master/src/index.ts +3 -0
  55. package/debug/konva-master/src/shapes/Arc.ts +176 -0
  56. package/debug/konva-master/src/shapes/Arrow.ts +231 -0
  57. package/debug/konva-master/src/shapes/Circle.ts +76 -0
  58. package/debug/konva-master/src/shapes/Ellipse.ts +121 -0
  59. package/debug/konva-master/src/shapes/Image.ts +319 -0
  60. package/debug/konva-master/src/shapes/Label.ts +386 -0
  61. package/debug/konva-master/src/shapes/Line.ts +364 -0
  62. package/debug/konva-master/src/shapes/Path.ts +1013 -0
  63. package/debug/konva-master/src/shapes/Rect.ts +79 -0
  64. package/debug/konva-master/src/shapes/RegularPolygon.ts +167 -0
  65. package/debug/konva-master/src/shapes/Ring.ts +94 -0
  66. package/debug/konva-master/src/shapes/Sprite.ts +370 -0
  67. package/debug/konva-master/src/shapes/Star.ts +125 -0
  68. package/debug/konva-master/src/shapes/Text.ts +1065 -0
  69. package/debug/konva-master/src/shapes/TextPath.ts +583 -0
  70. package/debug/konva-master/src/shapes/Transformer.ts +1889 -0
  71. package/debug/konva-master/src/shapes/Wedge.ts +129 -0
  72. package/debug/konva-master/src/skia-backend.ts +35 -0
  73. package/debug/konva-master/src/types.ts +84 -0
  74. package/debug/konva-master/tsconfig.json +31 -0
  75. package/debug/konva-master/tsconfig.test.json +7 -0
  76. package/dist/index.js +977 -29
  77. package/dist/index.js.map +1 -1
  78. package/dist/index.min.js +1 -1
  79. package/dist/index.min.js.map +1 -1
  80. package/dist/index.min.mjs +1 -1
  81. package/dist/index.min.mjs.map +1 -1
  82. package/dist/index.mjs +977 -29
  83. package/dist/index.mjs.map +1 -1
  84. package/dist/index.node.cjs +977 -29
  85. package/dist/index.node.cjs.map +1 -1
  86. package/dist/index.node.mjs +977 -29
  87. package/dist/index.node.mjs.map +1 -1
  88. package/dist/package.json.min.mjs +1 -1
  89. package/dist/package.json.mjs +1 -1
  90. package/dist/src/shapes/Line.d.ts +1 -0
  91. package/dist/src/shapes/Line.d.ts.map +1 -1
  92. package/dist/src/shapes/Line.min.mjs +1 -1
  93. package/dist/src/shapes/Line.min.mjs.map +1 -1
  94. package/dist/src/shapes/Line.mjs +63 -6
  95. package/dist/src/shapes/Line.mjs.map +1 -1
  96. package/dist/src/shapes/Text/Text.d.ts +19 -0
  97. package/dist/src/shapes/Text/Text.d.ts.map +1 -1
  98. package/dist/src/shapes/Text/Text.min.mjs +1 -1
  99. package/dist/src/shapes/Text/Text.min.mjs.map +1 -1
  100. package/dist/src/shapes/Text/Text.mjs +238 -4
  101. package/dist/src/shapes/Text/Text.mjs.map +1 -1
  102. package/dist/src/shapes/Textbox.d.ts +38 -1
  103. package/dist/src/shapes/Textbox.d.ts.map +1 -1
  104. package/dist/src/shapes/Textbox.min.mjs +1 -1
  105. package/dist/src/shapes/Textbox.min.mjs.map +1 -1
  106. package/dist/src/shapes/Textbox.mjs +497 -15
  107. package/dist/src/shapes/Textbox.mjs.map +1 -1
  108. package/dist/src/text/examples/arabicTextExample.d.ts +60 -0
  109. package/dist/src/text/examples/arabicTextExample.d.ts.map +1 -0
  110. package/dist/src/text/measure.d.ts +9 -0
  111. package/dist/src/text/measure.d.ts.map +1 -1
  112. package/dist/src/text/measure.min.mjs +1 -1
  113. package/dist/src/text/measure.min.mjs.map +1 -1
  114. package/dist/src/text/measure.mjs +175 -4
  115. package/dist/src/text/measure.mjs.map +1 -1
  116. package/dist/src/text/overlayEditor.d.ts.map +1 -1
  117. package/dist/src/text/overlayEditor.min.mjs +1 -1
  118. package/dist/src/text/overlayEditor.min.mjs.map +1 -1
  119. package/dist/src/text/overlayEditor.mjs +7 -0
  120. package/dist/src/text/overlayEditor.mjs.map +1 -1
  121. package/dist/src/text/scriptUtils.d.ts +142 -0
  122. package/dist/src/text/scriptUtils.d.ts.map +1 -0
  123. package/dist/src/text/scriptUtils.min.mjs +2 -0
  124. package/dist/src/text/scriptUtils.min.mjs.map +1 -0
  125. package/dist/src/text/scriptUtils.mjs +212 -0
  126. package/dist/src/text/scriptUtils.mjs.map +1 -0
  127. package/dist-extensions/src/shapes/Line.d.ts +1 -0
  128. package/dist-extensions/src/shapes/Line.d.ts.map +1 -1
  129. package/dist-extensions/src/shapes/Text/Text.d.ts +19 -0
  130. package/dist-extensions/src/shapes/Text/Text.d.ts.map +1 -1
  131. package/dist-extensions/src/shapes/Textbox.d.ts +38 -1
  132. package/dist-extensions/src/shapes/Textbox.d.ts.map +1 -1
  133. package/dist-extensions/src/text/measure.d.ts +9 -0
  134. package/dist-extensions/src/text/measure.d.ts.map +1 -1
  135. package/dist-extensions/src/text/overlayEditor.d.ts.map +1 -1
  136. package/dist-extensions/src/text/scriptUtils.d.ts +142 -0
  137. package/dist-extensions/src/text/scriptUtils.d.ts.map +1 -0
  138. package/fabric-test-editor.html +2401 -46
  139. package/fabric-test2.html +43 -0
  140. package/fonts/STV Bold.ttf +0 -0
  141. package/fonts/STV Light.ttf +0 -0
  142. package/fonts/STV Regular.ttf +0 -0
  143. package/package.json +1 -1
  144. package/src/shapes/Line.ts +132 -46
  145. package/src/shapes/Text/Text.ts +238 -5
  146. package/src/shapes/Textbox.ts +521 -11
  147. package/src/text/measure.ts +200 -50
  148. package/src/text/overlayEditor.ts +7 -0
@@ -0,0 +1,386 @@
1
+ import { Factory } from '../Factory.ts';
2
+ import type { ShapeConfig } from '../Shape.ts';
3
+ import { Shape } from '../Shape.ts';
4
+ import { Group } from '../Group.ts';
5
+ import type { Context } from '../Context.ts';
6
+ import type { ContainerConfig } from '../Container.ts';
7
+ import {
8
+ getNumberOrArrayOfNumbersValidator,
9
+ getNumberValidator,
10
+ } from '../Validators.ts';
11
+ import { _registerNode } from '../Global.ts';
12
+
13
+ import type { GetSet } from '../types.ts';
14
+ import type { Text } from './Text.ts';
15
+
16
+ export interface LabelConfig extends ContainerConfig {}
17
+
18
+ // constants
19
+ const ATTR_CHANGE_LIST = [
20
+ 'fontFamily',
21
+ 'fontSize',
22
+ 'fontStyle',
23
+ 'padding',
24
+ 'lineHeight',
25
+ 'text',
26
+ 'width',
27
+ 'height',
28
+ 'pointerDirection',
29
+ 'pointerWidth',
30
+ 'pointerHeight',
31
+ ],
32
+ CHANGE_KONVA = 'Change.konva',
33
+ NONE = 'none',
34
+ UP = 'up',
35
+ RIGHT = 'right',
36
+ DOWN = 'down',
37
+ LEFT = 'left',
38
+ // cached variables
39
+ attrChangeListLen = ATTR_CHANGE_LIST.length;
40
+
41
+ /**
42
+ * Label constructor.  Labels are groups that contain a Text and Tag shape
43
+ * @constructor
44
+ * @memberof Konva
45
+ * @param {Object} config
46
+ * @@nodeParams
47
+ * @example
48
+ * // create label
49
+ * var label = new Konva.Label({
50
+ * x: 100,
51
+ * y: 100,
52
+ * draggable: true
53
+ * });
54
+ *
55
+ * // add a tag to the label
56
+ * label.add(new Konva.Tag({
57
+ * fill: '#bbb',
58
+ * stroke: '#333',
59
+ * shadowColor: 'black',
60
+ * shadowBlur: 10,
61
+ * shadowOffset: [10, 10],
62
+ * shadowOpacity: 0.2,
63
+ * lineJoin: 'round',
64
+ * pointerDirection: 'up',
65
+ * pointerWidth: 20,
66
+ * pointerHeight: 20,
67
+ * cornerRadius: 5
68
+ * }));
69
+ *
70
+ * // add text to the label
71
+ * label.add(new Konva.Text({
72
+ * text: 'Hello World!',
73
+ * fontSize: 50,
74
+ * lineHeight: 1.2,
75
+ * padding: 10,
76
+ * fill: 'green'
77
+ * }));
78
+ */
79
+ export class Label extends Group {
80
+ constructor(config?: LabelConfig) {
81
+ super(config);
82
+ this.on('add.konva', function (evt) {
83
+ this._addListeners(evt.child);
84
+ this._sync();
85
+ });
86
+ }
87
+
88
+ /**
89
+ * get Text shape for the label. You need to access the Text shape in order to update
90
+ * the text properties
91
+ * @name Konva.Label#getText
92
+ * @method
93
+ * @example
94
+ * label.getText().fill('red')
95
+ */
96
+ getText() {
97
+ return this.find<Text>('Text')[0];
98
+ }
99
+ /**
100
+ * get Tag shape for the label. You need to access the Tag shape in order to update
101
+ * the pointer properties and the corner radius
102
+ * @name Konva.Label#getTag
103
+ * @method
104
+ */
105
+ getTag() {
106
+ return this.find('Tag')[0] as Tag;
107
+ }
108
+ _addListeners(text) {
109
+ let that = this,
110
+ n;
111
+ const func = function () {
112
+ that._sync();
113
+ };
114
+
115
+ // update text data for certain attr changes
116
+ for (n = 0; n < attrChangeListLen; n++) {
117
+ text.on(ATTR_CHANGE_LIST[n] + CHANGE_KONVA, func);
118
+ }
119
+ }
120
+ getWidth() {
121
+ return this.getText().width();
122
+ }
123
+ getHeight() {
124
+ return this.getText().height();
125
+ }
126
+ _sync() {
127
+ let text = this.getText(),
128
+ tag = this.getTag(),
129
+ width,
130
+ height,
131
+ pointerDirection,
132
+ pointerWidth,
133
+ x,
134
+ y,
135
+ pointerHeight;
136
+
137
+ if (text && tag) {
138
+ width = text.width();
139
+ height = text.height();
140
+ pointerDirection = tag.pointerDirection();
141
+ pointerWidth = tag.pointerWidth();
142
+ pointerHeight = tag.pointerHeight();
143
+ x = 0;
144
+ y = 0;
145
+
146
+ switch (pointerDirection) {
147
+ case UP:
148
+ x = width / 2;
149
+ y = -1 * pointerHeight;
150
+ break;
151
+ case RIGHT:
152
+ x = width + pointerWidth;
153
+ y = height / 2;
154
+ break;
155
+ case DOWN:
156
+ x = width / 2;
157
+ y = height + pointerHeight;
158
+ break;
159
+ case LEFT:
160
+ x = -1 * pointerWidth;
161
+ y = height / 2;
162
+ break;
163
+ }
164
+
165
+ tag.setAttrs({
166
+ x: -1 * x,
167
+ y: -1 * y,
168
+ width: width,
169
+ height: height,
170
+ });
171
+
172
+ text.setAttrs({
173
+ x: -1 * x,
174
+ y: -1 * y,
175
+ });
176
+ }
177
+ }
178
+ }
179
+
180
+ Label.prototype.className = 'Label';
181
+ _registerNode(Label);
182
+
183
+ export interface TagConfig extends ShapeConfig {
184
+ pointerDirection?: string;
185
+ pointerWidth?: number;
186
+ pointerHeight?: number;
187
+ cornerRadius?: number | Array<number>;
188
+ }
189
+
190
+ /**
191
+ * Tag constructor.&nbsp; A Tag can be configured
192
+ * to have a pointer element that points up, right, down, or left
193
+ * @constructor
194
+ * @memberof Konva
195
+ * @param {Object} config
196
+ * @param {String} [config.pointerDirection] can be up, right, down, left, or none; the default
197
+ * is none. When a pointer is present, the positioning of the label is relative to the tip of the pointer.
198
+ * @param {Number} [config.pointerWidth]
199
+ * @param {Number} [config.pointerHeight]
200
+ * @param {Number} [config.cornerRadius]
201
+ */
202
+ export class Tag extends Shape<TagConfig> {
203
+ _sceneFunc(context: Context) {
204
+ const width = this.width(),
205
+ height = this.height(),
206
+ pointerDirection = this.pointerDirection(),
207
+ pointerWidth = this.pointerWidth(),
208
+ pointerHeight = this.pointerHeight(),
209
+ cornerRadius = this.cornerRadius();
210
+
211
+ let topLeft = 0;
212
+ let topRight = 0;
213
+ let bottomLeft = 0;
214
+ let bottomRight = 0;
215
+
216
+ if (typeof cornerRadius === 'number') {
217
+ topLeft =
218
+ topRight =
219
+ bottomLeft =
220
+ bottomRight =
221
+ Math.min(cornerRadius, width / 2, height / 2);
222
+ } else {
223
+ topLeft = Math.min(cornerRadius[0] || 0, width / 2, height / 2);
224
+ topRight = Math.min(cornerRadius[1] || 0, width / 2, height / 2);
225
+ bottomRight = Math.min(cornerRadius[2] || 0, width / 2, height / 2);
226
+ bottomLeft = Math.min(cornerRadius[3] || 0, width / 2, height / 2);
227
+ }
228
+
229
+ context.beginPath();
230
+ context.moveTo(topLeft, 0);
231
+
232
+ if (pointerDirection === UP) {
233
+ context.lineTo((width - pointerWidth) / 2, 0);
234
+ context.lineTo(width / 2, -1 * pointerHeight);
235
+ context.lineTo((width + pointerWidth) / 2, 0);
236
+ }
237
+
238
+ context.lineTo(width - topRight, 0);
239
+ context.arc(
240
+ width - topRight,
241
+ topRight,
242
+ topRight,
243
+ (Math.PI * 3) / 2,
244
+ 0,
245
+ false
246
+ );
247
+
248
+ if (pointerDirection === RIGHT) {
249
+ context.lineTo(width, (height - pointerHeight) / 2);
250
+ context.lineTo(width + pointerWidth, height / 2);
251
+ context.lineTo(width, (height + pointerHeight) / 2);
252
+ }
253
+
254
+ context.lineTo(width, height - bottomRight);
255
+ context.arc(
256
+ width - bottomRight,
257
+ height - bottomRight,
258
+ bottomRight,
259
+ 0,
260
+ Math.PI / 2,
261
+ false
262
+ );
263
+
264
+ if (pointerDirection === DOWN) {
265
+ context.lineTo((width + pointerWidth) / 2, height);
266
+ context.lineTo(width / 2, height + pointerHeight);
267
+ context.lineTo((width - pointerWidth) / 2, height);
268
+ }
269
+
270
+ context.lineTo(bottomLeft, height);
271
+ context.arc(
272
+ bottomLeft,
273
+ height - bottomLeft,
274
+ bottomLeft,
275
+ Math.PI / 2,
276
+ Math.PI,
277
+ false
278
+ );
279
+
280
+ if (pointerDirection === LEFT) {
281
+ context.lineTo(0, (height + pointerHeight) / 2);
282
+ context.lineTo(-1 * pointerWidth, height / 2);
283
+ context.lineTo(0, (height - pointerHeight) / 2);
284
+ }
285
+
286
+ context.lineTo(0, topLeft);
287
+ context.arc(topLeft, topLeft, topLeft, Math.PI, (Math.PI * 3) / 2, false);
288
+
289
+ context.closePath();
290
+ context.fillStrokeShape(this);
291
+ }
292
+ getSelfRect() {
293
+ let x = 0,
294
+ y = 0,
295
+ pointerWidth = this.pointerWidth(),
296
+ pointerHeight = this.pointerHeight(),
297
+ direction = this.pointerDirection(),
298
+ width = this.width(),
299
+ height = this.height();
300
+
301
+ if (direction === UP) {
302
+ y -= pointerHeight;
303
+ height += pointerHeight;
304
+ } else if (direction === DOWN) {
305
+ height += pointerHeight;
306
+ } else if (direction === LEFT) {
307
+ // ARGH!!! I have no idea why should I used magic 1.5!!!!!!!!!
308
+ x -= pointerWidth * 1.5;
309
+ width += pointerWidth;
310
+ } else if (direction === RIGHT) {
311
+ width += pointerWidth * 1.5;
312
+ }
313
+ return {
314
+ x: x,
315
+ y: y,
316
+ width: width,
317
+ height: height,
318
+ };
319
+ }
320
+
321
+ pointerDirection: GetSet<
322
+ 'left' | 'up' | 'right' | 'down' | typeof NONE,
323
+ this
324
+ >;
325
+ pointerWidth: GetSet<number, this>;
326
+ pointerHeight: GetSet<number, this>;
327
+ cornerRadius: GetSet<number, this>;
328
+ }
329
+
330
+ Tag.prototype.className = 'Tag';
331
+ _registerNode(Tag);
332
+
333
+ /**
334
+ * get/set pointer direction
335
+ * @name Konva.Tag#pointerDirection
336
+ * @method
337
+ * @param {String} pointerDirection can be up, right, down, left, or none. The default is none.
338
+ * @returns {String}
339
+ * @example
340
+ * tag.pointerDirection('right');
341
+ */
342
+ Factory.addGetterSetter(Tag, 'pointerDirection', NONE);
343
+
344
+ /**
345
+ * get/set pointer width
346
+ * @name Konva.Tag#pointerWidth
347
+ * @method
348
+ * @param {Number} pointerWidth
349
+ * @returns {Number}
350
+ * @example
351
+ * tag.pointerWidth(20);
352
+ */
353
+ Factory.addGetterSetter(Tag, 'pointerWidth', 0, getNumberValidator());
354
+
355
+ /**
356
+ * get/set pointer height
357
+ * @method
358
+ * @name Konva.Tag#pointerHeight
359
+ * @param {Number} pointerHeight
360
+ * @returns {Number}
361
+ * @example
362
+ * tag.pointerHeight(20);
363
+ */
364
+
365
+ Factory.addGetterSetter(Tag, 'pointerHeight', 0, getNumberValidator());
366
+
367
+ /**
368
+ * get/set cornerRadius
369
+ * @name Konva.Tag#cornerRadius
370
+ * @method
371
+ * @param {Number} cornerRadius
372
+ * @returns {Number}
373
+ * @example
374
+ * tag.cornerRadius(20);
375
+ *
376
+ * // set different corner radius values
377
+ * // top-left, top-right, bottom-right, bottom-left
378
+ * tag.cornerRadius([0, 10, 20, 30]);
379
+ */
380
+
381
+ Factory.addGetterSetter(
382
+ Tag,
383
+ 'cornerRadius',
384
+ 0,
385
+ getNumberOrArrayOfNumbersValidator(4)
386
+ );