@nasser-sw/fabric 7.0.1-beta8 → 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 (138) 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 +915 -23
  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 +915 -23
  83. package/dist/index.mjs.map +1 -1
  84. package/dist/index.node.cjs +915 -23
  85. package/dist/index.node.cjs.map +1 -1
  86. package/dist/index.node.mjs +915 -23
  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/Text/Text.d.ts +19 -0
  91. package/dist/src/shapes/Text/Text.d.ts.map +1 -1
  92. package/dist/src/shapes/Text/Text.min.mjs +1 -1
  93. package/dist/src/shapes/Text/Text.min.mjs.map +1 -1
  94. package/dist/src/shapes/Text/Text.mjs +238 -4
  95. package/dist/src/shapes/Text/Text.mjs.map +1 -1
  96. package/dist/src/shapes/Textbox.d.ts +38 -1
  97. package/dist/src/shapes/Textbox.d.ts.map +1 -1
  98. package/dist/src/shapes/Textbox.min.mjs +1 -1
  99. package/dist/src/shapes/Textbox.min.mjs.map +1 -1
  100. package/dist/src/shapes/Textbox.mjs +497 -15
  101. package/dist/src/shapes/Textbox.mjs.map +1 -1
  102. package/dist/src/text/examples/arabicTextExample.d.ts +60 -0
  103. package/dist/src/text/examples/arabicTextExample.d.ts.map +1 -0
  104. package/dist/src/text/measure.d.ts +9 -0
  105. package/dist/src/text/measure.d.ts.map +1 -1
  106. package/dist/src/text/measure.min.mjs +1 -1
  107. package/dist/src/text/measure.min.mjs.map +1 -1
  108. package/dist/src/text/measure.mjs +175 -4
  109. package/dist/src/text/measure.mjs.map +1 -1
  110. package/dist/src/text/overlayEditor.d.ts.map +1 -1
  111. package/dist/src/text/overlayEditor.min.mjs +1 -1
  112. package/dist/src/text/overlayEditor.min.mjs.map +1 -1
  113. package/dist/src/text/overlayEditor.mjs +7 -0
  114. package/dist/src/text/overlayEditor.mjs.map +1 -1
  115. package/dist/src/text/scriptUtils.d.ts +142 -0
  116. package/dist/src/text/scriptUtils.d.ts.map +1 -0
  117. package/dist/src/text/scriptUtils.min.mjs +2 -0
  118. package/dist/src/text/scriptUtils.min.mjs.map +1 -0
  119. package/dist/src/text/scriptUtils.mjs +212 -0
  120. package/dist/src/text/scriptUtils.mjs.map +1 -0
  121. package/dist-extensions/src/shapes/Text/Text.d.ts +19 -0
  122. package/dist-extensions/src/shapes/Text/Text.d.ts.map +1 -1
  123. package/dist-extensions/src/shapes/Textbox.d.ts +38 -1
  124. package/dist-extensions/src/shapes/Textbox.d.ts.map +1 -1
  125. package/dist-extensions/src/text/measure.d.ts +9 -0
  126. package/dist-extensions/src/text/measure.d.ts.map +1 -1
  127. package/dist-extensions/src/text/overlayEditor.d.ts.map +1 -1
  128. package/dist-extensions/src/text/scriptUtils.d.ts +142 -0
  129. package/dist-extensions/src/text/scriptUtils.d.ts.map +1 -0
  130. package/fabric-test-editor.html +2401 -46
  131. package/fonts/STV Bold.ttf +0 -0
  132. package/fonts/STV Light.ttf +0 -0
  133. package/fonts/STV Regular.ttf +0 -0
  134. package/package.json +1 -1
  135. package/src/shapes/Text/Text.ts +238 -5
  136. package/src/shapes/Textbox.ts +521 -11
  137. package/src/text/measure.ts +200 -50
  138. package/src/text/overlayEditor.ts +7 -0
@@ -0,0 +1,230 @@
1
+ import { Util } from './Util.ts';
2
+ import type { Context } from './Context.ts';
3
+ import { SceneContext, HitContext } from './Context.ts';
4
+ import { Konva } from './Global.ts';
5
+
6
+ // calculate pixel ratio
7
+ let _pixelRatio;
8
+ function getDevicePixelRatio() {
9
+ if (_pixelRatio) {
10
+ return _pixelRatio;
11
+ }
12
+ const canvas = Util.createCanvasElement();
13
+ const context = canvas.getContext('2d') as any;
14
+ _pixelRatio = (function () {
15
+ const devicePixelRatio = Konva._global.devicePixelRatio || 1,
16
+ backingStoreRatio =
17
+ context.webkitBackingStorePixelRatio ||
18
+ context.mozBackingStorePixelRatio ||
19
+ context.msBackingStorePixelRatio ||
20
+ context.oBackingStorePixelRatio ||
21
+ context.backingStorePixelRatio ||
22
+ 1;
23
+ return devicePixelRatio / backingStoreRatio;
24
+ })();
25
+ Util.releaseCanvas(canvas);
26
+ return _pixelRatio;
27
+ }
28
+
29
+ interface ICanvasConfig {
30
+ width?: number;
31
+ height?: number;
32
+ pixelRatio?: number;
33
+ willReadFrequently?: boolean;
34
+ }
35
+
36
+ /**
37
+ * Canvas Renderer constructor. It is a wrapper around native canvas element.
38
+ * Usually you don't need to use it manually.
39
+ * @constructor
40
+ * @abstract
41
+ * @memberof Konva
42
+ * @param {Object} config
43
+ * @param {Number} config.width
44
+ * @param {Number} config.height
45
+ * @param {Number} config.pixelRatio
46
+ */
47
+ export class Canvas {
48
+ pixelRatio = 1;
49
+ _canvas: HTMLCanvasElement;
50
+ context: Context;
51
+ width = 0;
52
+ height = 0;
53
+
54
+ isCache = false;
55
+
56
+ constructor(config: ICanvasConfig) {
57
+ const conf = config || {};
58
+
59
+ const pixelRatio =
60
+ conf.pixelRatio || Konva.pixelRatio || getDevicePixelRatio();
61
+
62
+ this.pixelRatio = pixelRatio;
63
+
64
+ this._canvas = Util.createCanvasElement();
65
+ // set inline styles
66
+ this._canvas.style.padding = '0';
67
+ this._canvas.style.margin = '0';
68
+ this._canvas.style.border = '0';
69
+ this._canvas.style.background = 'transparent';
70
+ this._canvas.style.position = 'absolute';
71
+ this._canvas.style.top = '0';
72
+ this._canvas.style.left = '0';
73
+ }
74
+
75
+ /**
76
+ * get canvas context
77
+ * @method
78
+ * @name Konva.Canvas#getContext
79
+ * @returns {CanvasContext} context
80
+ */
81
+ getContext() {
82
+ return this.context;
83
+ }
84
+ /**
85
+ * get pixel ratio
86
+ * @method
87
+ * @name Konva.Canvas#getPixelRatio
88
+ * @returns {Number} pixel ratio
89
+ * @example
90
+ * var pixelRatio = layer.getCanvas.getPixelRatio();
91
+ */
92
+ getPixelRatio() {
93
+ return this.pixelRatio;
94
+ }
95
+ /**
96
+ * set pixel ratio
97
+ * KonvaJS automatically handles pixel ratio adustments in order to render crisp drawings
98
+ * on all devices. Most desktops, low end tablets, and low end phones, have device pixel ratios
99
+ * of 1. Some high end tablets and phones, like iPhones and iPads have a device pixel ratio
100
+ * of 2. Some Macbook Pros, and iMacs also have a device pixel ratio of 2. Some high end Android devices have pixel
101
+ * ratios of 2 or 3. Some browsers like Firefox allow you to configure the pixel ratio of the viewport. Unless otherwise
102
+ * specificed, the pixel ratio will be defaulted to the actual device pixel ratio. You can override the device pixel
103
+ * ratio for special situations, or, if you don't want the pixel ratio to be taken into account, you can set it to 1.
104
+ * @method
105
+ * @name Konva.Canvas#setPixelRatio
106
+ * @param {Number} pixelRatio
107
+ * @example
108
+ * layer.getCanvas().setPixelRatio(3);
109
+ */
110
+ setPixelRatio(pixelRatio) {
111
+ const previousRatio = this.pixelRatio;
112
+ this.pixelRatio = pixelRatio;
113
+ this.setSize(
114
+ this.getWidth() / previousRatio,
115
+ this.getHeight() / previousRatio
116
+ );
117
+ }
118
+ setWidth(width) {
119
+ // take into account pixel ratio
120
+ this.width = this._canvas.width = width * this.pixelRatio;
121
+ this._canvas.style.width = width + 'px';
122
+
123
+ const pixelRatio = this.pixelRatio,
124
+ _context = this.getContext()._context;
125
+ _context.scale(pixelRatio, pixelRatio);
126
+ }
127
+ setHeight(height) {
128
+ // take into account pixel ratio
129
+ this.height = this._canvas.height = height * this.pixelRatio;
130
+ this._canvas.style.height = height + 'px';
131
+ const pixelRatio = this.pixelRatio,
132
+ _context = this.getContext()._context;
133
+ _context.scale(pixelRatio, pixelRatio);
134
+ }
135
+ getWidth() {
136
+ return this.width;
137
+ }
138
+ getHeight() {
139
+ return this.height;
140
+ }
141
+ setSize(width, height) {
142
+ this.setWidth(width || 0);
143
+ this.setHeight(height || 0);
144
+ }
145
+ /**
146
+ * to data url
147
+ * @method
148
+ * @name Konva.Canvas#toDataURL
149
+ * @param {String} mimeType
150
+ * @param {Number} quality between 0 and 1 for jpg mime types
151
+ * @returns {String} data url string
152
+ */
153
+ toDataURL(mimeType, quality) {
154
+ try {
155
+ // If this call fails (due to browser bug, like in Firefox 3.6),
156
+ // then revert to previous no-parameter image/png behavior
157
+ return this._canvas.toDataURL(mimeType, quality);
158
+ } catch (e) {
159
+ try {
160
+ return this._canvas.toDataURL();
161
+ } catch (err: any) {
162
+ Util.error(
163
+ 'Unable to get data URL. ' +
164
+ err.message +
165
+ ' For more info read https://konvajs.org/docs/posts/Tainted_Canvas.html.'
166
+ );
167
+ return '';
168
+ }
169
+ }
170
+ }
171
+ }
172
+
173
+ export class SceneCanvas extends Canvas {
174
+ constructor(
175
+ config: ICanvasConfig = { width: 0, height: 0, willReadFrequently: false }
176
+ ) {
177
+ super(config);
178
+ this.context = new SceneContext(this, {
179
+ willReadFrequently: config.willReadFrequently,
180
+ });
181
+ this.setSize(config.width, config.height);
182
+ }
183
+ }
184
+
185
+ // function checks if canvas farbling is active
186
+ // canvas farbling is a Browser security feature, it break konva internals
187
+ function isCanvasFarblingActive() {
188
+ const c = Util.createCanvasElement();
189
+ c.width = 1;
190
+ c.height = 1;
191
+ const ctx = c.getContext('2d', {
192
+ willReadFrequently: true,
193
+ }) as CanvasRenderingContext2D;
194
+ ctx.clearRect(0, 0, 1, 1);
195
+ ctx.fillStyle = 'rgba(255,0,255,1)'; // clear #FF00FF, no alpha
196
+ ctx.fillRect(0, 0, 1, 1);
197
+ const d = ctx.getImageData(0, 0, 1, 1).data;
198
+ const exact = d[0] === 255 && d[1] === 0 && d[2] === 255 && d[3] === 255;
199
+ return !exact;
200
+ }
201
+
202
+ function isBraveBrowser() {
203
+ if (typeof navigator === 'undefined') {
204
+ return false;
205
+ }
206
+ // @ts-ignore
207
+ return navigator.brave?.isBrave() ?? false;
208
+ }
209
+
210
+ let warned = false;
211
+ function checkHitCanvasSupport() {
212
+ if (isBraveBrowser() && isCanvasFarblingActive() && !warned) {
213
+ warned = true;
214
+ Util.error(
215
+ 'Looks like you have "Brave shield" enabled in your browser. It breaks KonvaJS internals. Please disable it. You may need to ask your users to do the same.'
216
+ );
217
+ }
218
+ return isBraveBrowser() && isCanvasFarblingActive();
219
+ }
220
+
221
+ export class HitCanvas extends Canvas {
222
+ hitCanvas = true;
223
+ constructor(config: ICanvasConfig = { width: 0, height: 0 }) {
224
+ super(config);
225
+
226
+ this.context = new HitContext(this);
227
+ this.setSize(config.width, config.height);
228
+ checkHitCanvasSupport();
229
+ }
230
+ }