@nasser-sw/fabric 7.0.1-beta3 → 7.0.1-beta4

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 (105) hide show
  1. package/0 +0 -0
  2. package/dist/index.js +323 -155
  3. package/dist/index.js.map +1 -1
  4. package/dist/index.min.js +1 -1
  5. package/dist/index.min.js.map +1 -1
  6. package/dist/index.min.mjs +1 -1
  7. package/dist/index.min.mjs.map +1 -1
  8. package/dist/index.mjs +323 -155
  9. package/dist/index.mjs.map +1 -1
  10. package/dist/index.node.cjs +323 -155
  11. package/dist/index.node.cjs.map +1 -1
  12. package/dist/index.node.mjs +323 -155
  13. package/dist/index.node.mjs.map +1 -1
  14. package/dist/package.json.min.mjs +1 -1
  15. package/dist/package.json.mjs +1 -1
  16. package/dist/src/shapes/Line.d.ts +31 -86
  17. package/dist/src/shapes/Line.d.ts.map +1 -1
  18. package/dist/src/shapes/Line.min.mjs +1 -1
  19. package/dist/src/shapes/Line.min.mjs.map +1 -1
  20. package/dist/src/shapes/Line.mjs +323 -154
  21. package/dist/src/shapes/Line.mjs.map +1 -1
  22. package/dist-extensions/src/shapes/CustomLine.d.ts +10 -0
  23. package/dist-extensions/src/shapes/CustomLine.d.ts.map +1 -0
  24. package/dist-extensions/src/shapes/Line.d.ts +31 -86
  25. package/dist-extensions/src/shapes/Line.d.ts.map +1 -1
  26. package/fabric-test-editor.html +157 -8
  27. package/fabric-test2.html +513 -0
  28. package/fabric.ts +182 -182
  29. package/package.json +1 -1
  30. package/src/shapes/Line.ts +372 -158
  31. package/debug/konva/CHANGELOG.md +0 -1474
  32. package/debug/konva/LICENSE +0 -22
  33. package/debug/konva/README.md +0 -205
  34. package/debug/konva/gulpfile.mjs +0 -110
  35. package/debug/konva/package.json +0 -139
  36. package/debug/konva/release.sh +0 -65
  37. package/debug/konva/resources/doc-includes/ContainerParams.txt +0 -6
  38. package/debug/konva/resources/doc-includes/NodeParams.txt +0 -20
  39. package/debug/konva/resources/doc-includes/ShapeParams.txt +0 -53
  40. package/debug/konva/resources/jsdoc.conf.json +0 -28
  41. package/debug/konva/rollup.config.mjs +0 -32
  42. package/debug/konva/src/Animation.ts +0 -237
  43. package/debug/konva/src/BezierFunctions.ts +0 -826
  44. package/debug/konva/src/Canvas.ts +0 -193
  45. package/debug/konva/src/Container.ts +0 -649
  46. package/debug/konva/src/Context.ts +0 -1017
  47. package/debug/konva/src/Core.ts +0 -5
  48. package/debug/konva/src/DragAndDrop.ts +0 -173
  49. package/debug/konva/src/Factory.ts +0 -246
  50. package/debug/konva/src/FastLayer.ts +0 -29
  51. package/debug/konva/src/Global.ts +0 -210
  52. package/debug/konva/src/Group.ts +0 -31
  53. package/debug/konva/src/Layer.ts +0 -546
  54. package/debug/konva/src/Node.ts +0 -3477
  55. package/debug/konva/src/PointerEvents.ts +0 -67
  56. package/debug/konva/src/Shape.ts +0 -2081
  57. package/debug/konva/src/Stage.ts +0 -1000
  58. package/debug/konva/src/Tween.ts +0 -811
  59. package/debug/konva/src/Util.ts +0 -1123
  60. package/debug/konva/src/Validators.ts +0 -210
  61. package/debug/konva/src/_CoreInternals.ts +0 -85
  62. package/debug/konva/src/_FullInternals.ts +0 -171
  63. package/debug/konva/src/canvas-backend.ts +0 -36
  64. package/debug/konva/src/filters/Blur.ts +0 -388
  65. package/debug/konva/src/filters/Brighten.ts +0 -48
  66. package/debug/konva/src/filters/Brightness.ts +0 -30
  67. package/debug/konva/src/filters/Contrast.ts +0 -75
  68. package/debug/konva/src/filters/Emboss.ts +0 -207
  69. package/debug/konva/src/filters/Enhance.ts +0 -154
  70. package/debug/konva/src/filters/Grayscale.ts +0 -25
  71. package/debug/konva/src/filters/HSL.ts +0 -108
  72. package/debug/konva/src/filters/HSV.ts +0 -106
  73. package/debug/konva/src/filters/Invert.ts +0 -23
  74. package/debug/konva/src/filters/Kaleidoscope.ts +0 -274
  75. package/debug/konva/src/filters/Mask.ts +0 -220
  76. package/debug/konva/src/filters/Noise.ts +0 -44
  77. package/debug/konva/src/filters/Pixelate.ts +0 -107
  78. package/debug/konva/src/filters/Posterize.ts +0 -46
  79. package/debug/konva/src/filters/RGB.ts +0 -82
  80. package/debug/konva/src/filters/RGBA.ts +0 -103
  81. package/debug/konva/src/filters/Sepia.ts +0 -27
  82. package/debug/konva/src/filters/Solarize.ts +0 -29
  83. package/debug/konva/src/filters/Threshold.ts +0 -44
  84. package/debug/konva/src/index.ts +0 -3
  85. package/debug/konva/src/shapes/Arc.ts +0 -176
  86. package/debug/konva/src/shapes/Arrow.ts +0 -231
  87. package/debug/konva/src/shapes/Circle.ts +0 -76
  88. package/debug/konva/src/shapes/Ellipse.ts +0 -121
  89. package/debug/konva/src/shapes/Image.ts +0 -319
  90. package/debug/konva/src/shapes/Label.ts +0 -386
  91. package/debug/konva/src/shapes/Line.ts +0 -364
  92. package/debug/konva/src/shapes/Path.ts +0 -1013
  93. package/debug/konva/src/shapes/Rect.ts +0 -79
  94. package/debug/konva/src/shapes/RegularPolygon.ts +0 -167
  95. package/debug/konva/src/shapes/Ring.ts +0 -94
  96. package/debug/konva/src/shapes/Sprite.ts +0 -370
  97. package/debug/konva/src/shapes/Star.ts +0 -125
  98. package/debug/konva/src/shapes/Text.ts +0 -1065
  99. package/debug/konva/src/shapes/TextPath.ts +0 -583
  100. package/debug/konva/src/shapes/Transformer.ts +0 -1889
  101. package/debug/konva/src/shapes/Wedge.ts +0 -129
  102. package/debug/konva/src/skia-backend.ts +0 -35
  103. package/debug/konva/src/types.ts +0 -84
  104. package/debug/konva/tsconfig.json +0 -31
  105. package/debug/konva/tsconfig.test.json +0 -7
@@ -1,76 +0,0 @@
1
- import { Factory } from '../Factory.ts';
2
- import type { ShapeConfig } from '../Shape.ts';
3
- import { Shape } from '../Shape.ts';
4
- import type { GetSet } from '../types.ts';
5
- import { getNumberValidator } from '../Validators.ts';
6
- import { _registerNode } from '../Global.ts';
7
- import type { Context } from '../Context.ts';
8
-
9
- export interface CircleConfig extends ShapeConfig {
10
- radius?: number;
11
- }
12
-
13
- /**
14
- * Circle constructor
15
- * @constructor
16
- * @memberof Konva
17
- * @augments Konva.Shape
18
- * @param {Object} config
19
- * @param {Number} config.radius
20
- * @@shapeParams
21
- * @@nodeParams
22
- * @example
23
- * // create circle
24
- * var circle = new Konva.Circle({
25
- * radius: 40,
26
- * fill: 'red',
27
- * stroke: 'black',
28
- * strokeWidth: 5
29
- * });
30
- */
31
- export class Circle extends Shape<CircleConfig> {
32
- _sceneFunc(context: Context) {
33
- context.beginPath();
34
- context.arc(0, 0, this.attrs.radius || 0, 0, Math.PI * 2, false);
35
- context.closePath();
36
- context.fillStrokeShape(this);
37
- }
38
- getWidth() {
39
- return this.radius() * 2;
40
- }
41
- getHeight() {
42
- return this.radius() * 2;
43
- }
44
- setWidth(width: number) {
45
- if (this.radius() !== width / 2) {
46
- this.radius(width / 2);
47
- }
48
- }
49
- setHeight(height: number) {
50
- if (this.radius() !== height / 2) {
51
- this.radius(height / 2);
52
- }
53
- }
54
-
55
- radius: GetSet<number, this>;
56
- }
57
-
58
- Circle.prototype._centroid = true;
59
- Circle.prototype.className = 'Circle';
60
- Circle.prototype._attrsAffectingSize = ['radius'];
61
- _registerNode(Circle);
62
-
63
- /**
64
- * get/set radius
65
- * @name Konva.Circle#radius
66
- * @method
67
- * @param {Number} radius
68
- * @returns {Number}
69
- * @example
70
- * // get radius
71
- * var radius = circle.radius();
72
- *
73
- * // set radius
74
- * circle.radius(10);
75
- */
76
- Factory.addGetterSetter(Circle, 'radius', 0, getNumberValidator());
@@ -1,121 +0,0 @@
1
- import { Factory } from '../Factory.ts';
2
- import type { ShapeConfig } from '../Shape.ts';
3
- import { Shape } from '../Shape.ts';
4
- import { getNumberValidator } from '../Validators.ts';
5
- import { _registerNode } from '../Global.ts';
6
- import type { Context } from '../Context.ts';
7
-
8
- import type { GetSet, Vector2d } from '../types.ts';
9
-
10
- export interface EllipseConfig extends ShapeConfig {
11
- radiusX: number;
12
- radiusY: number;
13
- }
14
-
15
- /**
16
- * Ellipse constructor
17
- * @constructor
18
- * @memberof Konva
19
- * @augments Konva.Shape
20
- * @param {Object} config
21
- * @param {Object} config.radius defines x and y radius
22
- * @@shapeParams
23
- * @@nodeParams
24
- * @example
25
- * var ellipse = new Konva.Ellipse({
26
- * radius : {
27
- * x : 50,
28
- * y : 50
29
- * },
30
- * fill: 'red'
31
- * });
32
- */
33
- export class Ellipse extends Shape<EllipseConfig> {
34
- _sceneFunc(context: Context) {
35
- const rx = this.radiusX(),
36
- ry = this.radiusY();
37
-
38
- context.beginPath();
39
- context.save();
40
- if (rx !== ry) {
41
- context.scale(1, ry / rx);
42
- }
43
- context.arc(0, 0, rx, 0, Math.PI * 2, false);
44
- context.restore();
45
- context.closePath();
46
- context.fillStrokeShape(this);
47
- }
48
- getWidth() {
49
- return this.radiusX() * 2;
50
- }
51
- getHeight() {
52
- return this.radiusY() * 2;
53
- }
54
- setWidth(width: number) {
55
- this.radiusX(width / 2);
56
- }
57
- setHeight(height: number) {
58
- this.radiusY(height / 2);
59
- }
60
-
61
- radius: GetSet<Vector2d, this>;
62
- radiusX: GetSet<number, this>;
63
- radiusY: GetSet<number, this>;
64
- }
65
-
66
- Ellipse.prototype.className = 'Ellipse';
67
- Ellipse.prototype._centroid = true;
68
- Ellipse.prototype._attrsAffectingSize = ['radiusX', 'radiusY'];
69
- _registerNode(Ellipse);
70
-
71
- // add getters setters
72
- Factory.addComponentsGetterSetter(Ellipse, 'radius', ['x', 'y']);
73
-
74
- /**
75
- * get/set radius
76
- * @name Konva.Ellipse#radius
77
- * @method
78
- * @param {Object} radius
79
- * @param {Number} radius.x
80
- * @param {Number} radius.y
81
- * @returns {Object}
82
- * @example
83
- * // get radius
84
- * var radius = ellipse.radius();
85
- *
86
- * // set radius
87
- * ellipse.radius({
88
- * x: 200,
89
- * y: 100
90
- * });
91
- */
92
-
93
- Factory.addGetterSetter(Ellipse, 'radiusX', 0, getNumberValidator());
94
- /**
95
- * get/set radius x
96
- * @name Konva.Ellipse#radiusX
97
- * @method
98
- * @param {Number} x
99
- * @returns {Number}
100
- * @example
101
- * // get radius x
102
- * var radiusX = ellipse.radiusX();
103
- *
104
- * // set radius x
105
- * ellipse.radiusX(200);
106
- */
107
-
108
- Factory.addGetterSetter(Ellipse, 'radiusY', 0, getNumberValidator());
109
- /**
110
- * get/set radius y
111
- * @name Konva.Ellipse#radiusY
112
- * @method
113
- * @param {Number} y
114
- * @returns {Number}
115
- * @example
116
- * // get radius y
117
- * var radiusY = ellipse.radiusY();
118
- *
119
- * // set radius y
120
- * ellipse.radiusY(200);
121
- */
@@ -1,319 +0,0 @@
1
- import { Util } from '../Util.ts';
2
- import { Factory } from '../Factory.ts';
3
- import type { ShapeConfig } from '../Shape.ts';
4
- import { Shape } from '../Shape.ts';
5
- import { _registerNode } from '../Global.ts';
6
- import {
7
- getNumberOrArrayOfNumbersValidator,
8
- getNumberValidator,
9
- } from '../Validators.ts';
10
-
11
- import type { GetSet, IRect } from '../types.ts';
12
- import type { Context } from '../Context.ts';
13
-
14
- export interface ImageConfig extends ShapeConfig {
15
- image: CanvasImageSource | undefined;
16
- crop?: IRect;
17
- cornerRadius?: number | number[];
18
- }
19
-
20
- /**
21
- * Image constructor
22
- * @constructor
23
- * @memberof Konva
24
- * @augments Konva.Shape
25
- * @param {Object} config
26
- * @param {Image} config.image
27
- * @param {Object} [config.crop]
28
- * @@shapeParams
29
- * @@nodeParams
30
- * @example
31
- * var imageObj = new Image();
32
- * imageObj.onload = function() {
33
- * var image = new Konva.Image({
34
- * x: 200,
35
- * y: 50,
36
- * image: imageObj,
37
- * width: 100,
38
- * height: 100
39
- * });
40
- * };
41
- * imageObj.src = '/path/to/image.jpg'
42
- */
43
- export class Image extends Shape<ImageConfig> {
44
- private _loadListener: () => void;
45
-
46
- constructor(attrs: ImageConfig) {
47
- super(attrs);
48
- this._loadListener = () => {
49
- this._requestDraw();
50
- };
51
-
52
- this.on('imageChange.konva', (props: any) => {
53
- this._removeImageLoad(props.oldVal);
54
- this._setImageLoad();
55
- });
56
-
57
- this._setImageLoad();
58
- }
59
- _setImageLoad() {
60
- const image = this.image() as any;
61
- // check is image is already loaded
62
- if (image && image.complete) {
63
- return;
64
- }
65
- // check is video is already loaded
66
- if (image && image.readyState === 4) {
67
- return;
68
- }
69
- if (image && image['addEventListener']) {
70
- image['addEventListener']('load', this._loadListener);
71
- }
72
- }
73
- _removeImageLoad(image: any) {
74
- if (image && image['removeEventListener']) {
75
- image['removeEventListener']('load', this._loadListener);
76
- }
77
- }
78
- destroy() {
79
- this._removeImageLoad(this.image());
80
- super.destroy();
81
- return this;
82
- }
83
- _useBufferCanvas() {
84
- const hasCornerRadius = !!this.cornerRadius();
85
- const hasShadow = this.hasShadow();
86
- if (hasCornerRadius && hasShadow) {
87
- return true;
88
- }
89
- return super._useBufferCanvas(true);
90
- }
91
- _sceneFunc(context: Context) {
92
- const width = this.getWidth();
93
- const height = this.getHeight();
94
- const cornerRadius = this.cornerRadius();
95
- const image = this.attrs.image;
96
- let params;
97
-
98
- if (image) {
99
- const cropWidth = this.attrs.cropWidth;
100
- const cropHeight = this.attrs.cropHeight;
101
- if (cropWidth && cropHeight) {
102
- params = [
103
- image,
104
- this.cropX(),
105
- this.cropY(),
106
- cropWidth,
107
- cropHeight,
108
- 0,
109
- 0,
110
- width,
111
- height,
112
- ];
113
- } else {
114
- params = [image, 0, 0, width, height];
115
- }
116
- }
117
-
118
- if (this.hasFill() || this.hasStroke() || cornerRadius) {
119
- context.beginPath();
120
- cornerRadius
121
- ? Util.drawRoundedRectPath(context, width, height, cornerRadius)
122
- : context.rect(0, 0, width, height);
123
- context.closePath();
124
- context.fillStrokeShape(this);
125
- }
126
-
127
- if (image) {
128
- if (cornerRadius) {
129
- context.clip();
130
- }
131
- context.drawImage.apply(context, params);
132
- }
133
- // If you need to draw later, you need to execute save/restore
134
- }
135
- _hitFunc(context: Context) {
136
- const width = this.width(),
137
- height = this.height(),
138
- cornerRadius = this.cornerRadius();
139
-
140
- context.beginPath();
141
- if (!cornerRadius) {
142
- context.rect(0, 0, width, height);
143
- } else {
144
- Util.drawRoundedRectPath(context, width, height, cornerRadius);
145
- }
146
- context.closePath();
147
- context.fillStrokeShape(this);
148
- }
149
- getWidth() {
150
- return this.attrs.width ?? (this.image() as any)?.width;
151
- }
152
- getHeight() {
153
- return this.attrs.height ?? (this.image() as any)?.height;
154
- }
155
-
156
- /**
157
- * load image from given url and create `Konva.Image` instance
158
- * @method
159
- * @memberof Konva.Image
160
- * @param {String} url image source
161
- * @param {Function} callback with Konva.Image instance as first argument
162
- * @param {Function} onError optional error handler
163
- * @example
164
- * Konva.Image.fromURL(imageURL, function(image){
165
- * // image is Konva.Image instance
166
- * layer.add(image);
167
- * });
168
- */
169
- static fromURL(
170
- url: string,
171
- callback: (img: Image) => void,
172
- onError: OnErrorEventHandler = null
173
- ) {
174
- const img = Util.createImageElement();
175
- img.onload = function () {
176
- const image = new Image({
177
- image: img,
178
- });
179
- callback(image);
180
- };
181
- img.onerror = onError;
182
- img.crossOrigin = 'Anonymous';
183
- img.src = url;
184
- }
185
-
186
- image: GetSet<CanvasImageSource | undefined, this>;
187
- crop: GetSet<IRect, this>;
188
- cropX: GetSet<number, this>;
189
- cropY: GetSet<number, this>;
190
- cropWidth: GetSet<number, this>;
191
- cropHeight: GetSet<number, this>;
192
- cornerRadius: GetSet<number | number[], this>;
193
- }
194
-
195
- Image.prototype.className = 'Image';
196
- _registerNode(Image);
197
-
198
- /**
199
- * get/set corner radius
200
- * @method
201
- * @name Konva.Image#cornerRadius
202
- * @param {Number} cornerRadius
203
- * @returns {Number}
204
- * @example
205
- * // get corner radius
206
- * var cornerRadius = image.cornerRadius();
207
- *
208
- * // set corner radius
209
- * image.cornerRadius(10);
210
- *
211
- * // set different corner radius values
212
- * // top-left, top-right, bottom-right, bottom-left
213
- * image.cornerRadius([0, 10, 20, 30]);
214
- */
215
- Factory.addGetterSetter(
216
- Image,
217
- 'cornerRadius',
218
- 0,
219
- getNumberOrArrayOfNumbersValidator(4)
220
- );
221
-
222
- /**
223
- * get/set image source. It can be image, canvas or video element
224
- * @name Konva.Image#image
225
- * @method
226
- * @param {Object} image source
227
- * @returns {Object}
228
- * @example
229
- * // get value
230
- * var image = shape.image();
231
- *
232
- * // set value
233
- * shape.image(img);
234
- */
235
- Factory.addGetterSetter(Image, 'image');
236
-
237
- Factory.addComponentsGetterSetter(Image, 'crop', ['x', 'y', 'width', 'height']);
238
- /**
239
- * get/set crop
240
- * @method
241
- * @name Konva.Image#crop
242
- * @param {Object} crop
243
- * @param {Number} crop.x
244
- * @param {Number} crop.y
245
- * @param {Number} crop.width
246
- * @param {Number} crop.height
247
- * @returns {Object}
248
- * @example
249
- * // get crop
250
- * var crop = image.crop();
251
- *
252
- * // set crop
253
- * image.crop({
254
- * x: 20,
255
- * y: 20,
256
- * width: 20,
257
- * height: 20
258
- * });
259
- */
260
-
261
- Factory.addGetterSetter(Image, 'cropX', 0, getNumberValidator());
262
- /**
263
- * get/set crop x
264
- * @method
265
- * @name Konva.Image#cropX
266
- * @param {Number} x
267
- * @returns {Number}
268
- * @example
269
- * // get crop x
270
- * var cropX = image.cropX();
271
- *
272
- * // set crop x
273
- * image.cropX(20);
274
- */
275
-
276
- Factory.addGetterSetter(Image, 'cropY', 0, getNumberValidator());
277
- /**
278
- * get/set crop y
279
- * @name Konva.Image#cropY
280
- * @method
281
- * @param {Number} y
282
- * @returns {Number}
283
- * @example
284
- * // get crop y
285
- * var cropY = image.cropY();
286
- *
287
- * // set crop y
288
- * image.cropY(20);
289
- */
290
-
291
- Factory.addGetterSetter(Image, 'cropWidth', 0, getNumberValidator());
292
- /**
293
- * get/set crop width
294
- * @name Konva.Image#cropWidth
295
- * @method
296
- * @param {Number} width
297
- * @returns {Number}
298
- * @example
299
- * // get crop width
300
- * var cropWidth = image.cropWidth();
301
- *
302
- * // set crop width
303
- * image.cropWidth(20);
304
- */
305
-
306
- Factory.addGetterSetter(Image, 'cropHeight', 0, getNumberValidator());
307
- /**
308
- * get/set crop height
309
- * @name Konva.Image#cropHeight
310
- * @method
311
- * @param {Number} height
312
- * @returns {Number}
313
- * @example
314
- * // get crop height
315
- * var cropHeight = image.cropHeight();
316
- *
317
- * // set crop height
318
- * image.cropHeight(20);
319
- */