@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
Binary file
Binary file
Binary file
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@nasser-sw/fabric",
3
3
  "description": "Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.",
4
4
  "homepage": "http://fabricjs.com/",
5
- "version": "7.0.1-beta8",
5
+ "version": "7.0.1-beta9",
6
6
  "author": "Juriy Zaytsev <kangax@gmail.com>",
7
7
  "contributors": [
8
8
  {
@@ -560,6 +560,15 @@ export class FabricText<
560
560
  * Does not return dimensions.
561
561
  */
562
562
  initDimensions(): void {
563
+ // Check if font is ready for accurate measurements
564
+ // Only block initialization if it's a critical font loading situation
565
+ const fontReady = this._isFontReady();
566
+ if (!fontReady && !this.initialized) {
567
+ // Only schedule font loading on first initialization
568
+ this._scheduleInitAfterFontLoad();
569
+ // Continue with fallback measurements for now
570
+ }
571
+
563
572
  // Use advanced layout if enabled
564
573
  if (this.enableAdvancedLayout && !this.path) {
565
574
  return this.initDimensionsAdvanced();
@@ -578,7 +587,20 @@ export class FabricText<
578
587
  }
579
588
  if (this.textAlign.includes(JUSTIFY)) {
580
589
  // once text is measured we need to make space fatter to make justified text.
581
- this.enlargeSpaces();
590
+ // Ensure __charBounds exists before calling enlargeSpaces
591
+ if (this.__charBounds && this.__charBounds.length > 0) {
592
+ this.enlargeSpaces();
593
+ } else {
594
+ console.warn('⚠️ __charBounds not ready for justify alignment, deferring enlargeSpaces');
595
+ // Defer the justify calculation until the next frame
596
+ setTimeout(() => {
597
+ if (this.__charBounds && this.__charBounds.length > 0 && this.enlargeSpaces) {
598
+ console.log('🔧 Applying deferred justify alignment');
599
+ this.enlargeSpaces();
600
+ this.canvas?.requestRenderAll();
601
+ }
602
+ }, 0);
603
+ }
582
604
  }
583
605
  }
584
606
 
@@ -597,7 +619,7 @@ export class FabricText<
597
619
 
598
620
  for (let i = 0, len = this._textLines.length; i < len; i++) {
599
621
  if (
600
- this.textAlign !== JUSTIFY &&
622
+ !this.textAlign.includes('justify') &&
601
623
  (i === len - 1 || this.isEndOfWrapping(i))
602
624
  ) {
603
625
  continue;
@@ -612,6 +634,10 @@ export class FabricText<
612
634
  numberOfSpaces = spaces.length;
613
635
  diffSpace = (this.width - currentLineWidth) / numberOfSpaces;
614
636
 
637
+ console.log(`🔧 EnlargeSpaces Line ${i}:`);
638
+ console.log(` Current width: ${currentLineWidth}, Target: ${this.width}`);
639
+ console.log(` Spaces: ${numberOfSpaces}, diffSpace: ${diffSpace.toFixed(2)}`);
640
+
615
641
  if (isRtl) {
616
642
  // For RTL text, we need to redistribute spaces while maintaining correct visual order
617
643
  // The key insight is that RTL text is stored in logical order but displayed in visual order
@@ -740,6 +766,17 @@ export class FabricText<
740
766
  // Convert layout to legacy format for compatibility
741
767
  this._convertLayoutToLegacyFormat(layout);
742
768
 
769
+ // Ensure justify alignment is properly applied for compatibility with legacy rendering
770
+ if (this.textAlign.includes(JUSTIFY)) {
771
+ // Force enlarge spaces after advanced layout calculation
772
+ setTimeout(() => {
773
+ if (this.enlargeSpaces) {
774
+ this.enlargeSpaces();
775
+ this.canvas?.renderAll();
776
+ }
777
+ }, 0);
778
+ }
779
+
743
780
  this.dirty = true;
744
781
  }
745
782
 
@@ -1958,13 +1995,27 @@ export class FabricText<
1958
1995
  > = {},
1959
1996
  forMeasuring?: boolean,
1960
1997
  ): string {
1961
- const parsedFontFamily =
1998
+ let parsedFontFamily =
1962
1999
  fontFamily.includes("'") ||
1963
2000
  fontFamily.includes('"') ||
1964
2001
  fontFamily.includes(',') ||
1965
2002
  FabricText.genericFonts.includes(fontFamily.toLowerCase())
1966
2003
  ? fontFamily
1967
2004
  : `"${fontFamily}"`;
2005
+
2006
+ // For fonts like STV that don't support English/Latin characters,
2007
+ // add fallback fonts for consistent rendering of unsupported characters
2008
+ // Only add fallbacks during actual rendering, not for measurements
2009
+ if (!forMeasuring && // Only during rendering, not measuring
2010
+ !fontFamily.includes(',') && // Don't add fallbacks if already has them
2011
+ (fontFamily.toLowerCase().includes('stv') ||
2012
+ fontFamily.toLowerCase().includes('arabic') ||
2013
+ fontFamily.toLowerCase().includes('naskh') ||
2014
+ fontFamily.toLowerCase().includes('kufi'))) {
2015
+ // Add fallback fonts for unsupported characters (spaces, punctuation, etc.)
2016
+ parsedFontFamily = `${parsedFontFamily}, "Arial Unicode MS", Arial, sans-serif`;
2017
+ }
2018
+
1968
2019
  return [
1969
2020
  fontStyle,
1970
2021
  fontWeight,
@@ -2018,7 +2069,13 @@ export class FabricText<
2018
2069
  newLine = ['\n'];
2019
2070
  let newText: string[] = [];
2020
2071
  for (let i = 0; i < lines.length; i++) {
2021
- newLines[i] = this.graphemeSplit(lines[i]);
2072
+ // Use BiDi-aware grapheme splitting for RTL text
2073
+ if (this.direction === 'rtl' || this._containsArabicText(lines[i])) {
2074
+ newLines[i] = segmentGraphemes(lines[i]);
2075
+ console.log(`🔤 BiDi-aware split line ${i}: "${lines[i]}" -> [${newLines[i].join(', ')}]`);
2076
+ } else {
2077
+ newLines[i] = this.graphemeSplit(lines[i]);
2078
+ }
2022
2079
  newText = newText.concat(newLines[i], newLine);
2023
2080
  }
2024
2081
  newText.pop();
@@ -2029,6 +2086,14 @@ export class FabricText<
2029
2086
  graphemeLines: newLines,
2030
2087
  };
2031
2088
  }
2089
+
2090
+ /**
2091
+ * Check if text contains Arabic characters
2092
+ * @private
2093
+ */
2094
+ _containsArabicText(text: string): boolean {
2095
+ return /[\u0600-\u06FF\u0750-\u077F\uFB50-\uFDFF\uFE70-\uFEFF]/.test(text);
2096
+ }
2032
2097
 
2033
2098
  /**
2034
2099
  * Returns object representation of an instance
@@ -2200,6 +2265,87 @@ export class FabricText<
2200
2265
 
2201
2266
  /* _FROM_SVG_END_ */
2202
2267
 
2268
+ /**
2269
+ * Check if the font is ready for accurate measurements
2270
+ * @private
2271
+ */
2272
+ _isFontReady(): boolean {
2273
+ if (typeof document === 'undefined' || !('fonts' in document)) {
2274
+ return true; // Assume ready in non-browser environments
2275
+ }
2276
+
2277
+ try {
2278
+ return document.fonts.check(`${this.fontSize}px ${this.fontFamily}`);
2279
+ } catch (e) {
2280
+ return true; // Fallback to assuming ready if check fails
2281
+ }
2282
+ }
2283
+
2284
+ /**
2285
+ * Schedule re-initialization after font loads
2286
+ * @private
2287
+ */
2288
+ _scheduleInitAfterFontLoad(): void {
2289
+ if (typeof document === 'undefined' || !('fonts' in document)) {
2290
+ return;
2291
+ }
2292
+
2293
+ // Only schedule if not already waiting
2294
+ if ((this as any)._fontLoadScheduled) {
2295
+ return;
2296
+ }
2297
+ (this as any)._fontLoadScheduled = true;
2298
+
2299
+ const fontSpec = `${this.fontSize}px ${this.fontFamily}`;
2300
+ document.fonts.load(fontSpec).then(() => {
2301
+ (this as any)._fontLoadScheduled = false;
2302
+ // Re-initialize dimensions with proper font metrics
2303
+ this.initDimensions();
2304
+
2305
+ // Extra step for justify alignment after font loading
2306
+ if (this.textAlign && this.textAlign.includes(JUSTIFY)) {
2307
+ setTimeout(() => {
2308
+ if (this.enlargeSpaces) {
2309
+ this.enlargeSpaces();
2310
+ }
2311
+ this.canvas?.requestRenderAll();
2312
+ }, 10);
2313
+ } else {
2314
+ this.canvas?.requestRenderAll();
2315
+ }
2316
+ }).catch(() => {
2317
+ (this as any)._fontLoadScheduled = false;
2318
+ });
2319
+ }
2320
+
2321
+ /**
2322
+ * Force complete text re-initialization (useful after JSON loading)
2323
+ */
2324
+ forceTextReinitialization(): void {
2325
+ console.log('🔄 Force reinitializing text object');
2326
+
2327
+ // Clear all caches
2328
+ this._clearCache();
2329
+ this.dirty = true;
2330
+
2331
+ // Force text splitting to rebuild internal structures
2332
+ this._splitText();
2333
+
2334
+ // Re-initialize dimensions
2335
+ this.initDimensions();
2336
+
2337
+ // Special handling for justify alignment
2338
+ if (this.textAlign && this.textAlign.includes(JUSTIFY)) {
2339
+ // Ensure justify is applied after dimensions are set
2340
+ setTimeout(() => {
2341
+ if (this.__charBounds && this.__charBounds.length > 0 && this.enlargeSpaces) {
2342
+ this.enlargeSpaces();
2343
+ this.canvas?.requestRenderAll();
2344
+ }
2345
+ }, 10);
2346
+ }
2347
+ }
2348
+
2203
2349
  /**
2204
2350
  * Returns FabricText instance from an object representation
2205
2351
  * @param {Object} object plain js Object to create an instance from
@@ -2217,7 +2363,94 @@ export class FabricText<
2217
2363
  {
2218
2364
  extraParam: 'text',
2219
2365
  },
2220
- );
2366
+ ).then((textObject: S) => {
2367
+ // Ensure text object is properly initialized after JSON deserialization
2368
+ // This is critical for justify alignment and other text layout features
2369
+ textObject.initialized = true;
2370
+
2371
+ // Force reinitialization to ensure proper layout
2372
+ if (textObject._clearCache) {
2373
+ textObject._clearCache();
2374
+ }
2375
+ textObject.dirty = true;
2376
+
2377
+ // Check if we need to wait for font loading (especially for custom fonts like STV)
2378
+ const fontSpec = `${textObject.fontSize}px ${textObject.fontFamily}`;
2379
+
2380
+ // For custom fonts, ensure they're loaded before initializing dimensions
2381
+ if (typeof document !== 'undefined' && 'fonts' in document && textObject.fontFamily !== 'Arial' && textObject.fontFamily !== 'Times New Roman') {
2382
+ return document.fonts.load(fontSpec).then(() => {
2383
+ console.log(`🔤 Font loaded for JSON object: ${fontSpec}`);
2384
+ // Ensure initialized flag is set again (in case constructor reset it)
2385
+ textObject.initialized = true;
2386
+
2387
+ // Special handling for STV fonts which have measurement issues
2388
+ const isStvFont = textObject.fontFamily?.toLowerCase().includes('stv');
2389
+ if (isStvFont) {
2390
+ console.log(`🔤 STV font detected, using enhanced reinitialization`);
2391
+
2392
+ // Clear all cached state that might interfere with browser wrapping
2393
+ (textObject as any)._browserWrapCache = null;
2394
+ (textObject as any)._lastDimensionState = null;
2395
+ (textObject as any)._browserWrapInitialized = false;
2396
+ console.log(`🔤 STV font: Cleared all cached states for fresh initialization`);
2397
+
2398
+ // Force browser wrapping flag for STV fonts
2399
+ (textObject as any)._usingBrowserWrapping = true;
2400
+ console.log(`🔤 STV font: Forcing browser wrapping flag during JSON load`);
2401
+
2402
+ // Multiple initialization attempts for STV fonts
2403
+ const reinitWithDelay = (attempt: number) => {
2404
+ if ((textObject as any).forceTextReinitialization) {
2405
+ (textObject as any).forceTextReinitialization();
2406
+ } else {
2407
+ textObject.initDimensions();
2408
+ }
2409
+
2410
+ // Check if width is still problematic after initialization
2411
+ if (textObject.width < 50 && attempt < 3) {
2412
+ console.log(`🔤 STV font width still ${textObject.width}px, retrying in ${100 * attempt}ms (attempt ${attempt + 1}/3)`);
2413
+ setTimeout(() => reinitWithDelay(attempt + 1), 100 * attempt);
2414
+ }
2415
+ };
2416
+ reinitWithDelay(0);
2417
+ } else {
2418
+ // Use specialized reinitialization for Textbox objects
2419
+ if ((textObject as any).forceTextReinitialization) {
2420
+ console.log(`🔤 Using Textbox specialized reinitialization`);
2421
+ (textObject as any).forceTextReinitialization();
2422
+ } else {
2423
+ // Reinitialize dimensions with proper font metrics
2424
+ textObject.initDimensions();
2425
+ }
2426
+ }
2427
+ return textObject;
2428
+ }).catch(() => {
2429
+ console.warn(`⚠️ Font loading failed for ${fontSpec}, proceeding with fallback`);
2430
+ // Ensure initialized flag is set again
2431
+ textObject.initialized = true;
2432
+
2433
+ // Still initialize dimensions even if font loading fails
2434
+ if ((textObject as any).forceTextReinitialization) {
2435
+ (textObject as any).forceTextReinitialization();
2436
+ } else {
2437
+ textObject.initDimensions();
2438
+ }
2439
+ return textObject;
2440
+ });
2441
+ } else {
2442
+ // Standard fonts - ensure initialized and use appropriate method
2443
+ textObject.initialized = true;
2444
+
2445
+ if ((textObject as any).forceTextReinitialization) {
2446
+ console.log(`🔤 Using Textbox specialized reinitialization for standard font`);
2447
+ (textObject as any).forceTextReinitialization();
2448
+ } else {
2449
+ textObject.initDimensions();
2450
+ }
2451
+ return textObject;
2452
+ }
2453
+ });
2221
2454
  }
2222
2455
  }
2223
2456