@leapfrog/interactive-canvas 1.5.2 → 1.6.0

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.
@@ -1713,6 +1713,27 @@ var Text = /** @class */ (function (_super) {
1713
1713
  this.data.userText = this.fabricObject.text;
1714
1714
  this.text$.next(this.fabricObject.text);
1715
1715
  };
1716
+ /**
1717
+ * @override
1718
+ * @inheritDoc
1719
+ */
1720
+ Text.prototype.insertText = function (text, style, start, end) {
1721
+ this.fabricObject.insertChars(text, style, start, end);
1722
+ var newCursorLocation = start + text.length;
1723
+ this.fabricObject.selectionStart = newCursorLocation;
1724
+ this.fabricObject.selectionEnd = newCursorLocation;
1725
+ this.redraw();
1726
+ this.data.userText = this.fabricObject.text;
1727
+ this.text$.next(this.fabricObject.text);
1728
+ };
1729
+ /**
1730
+ * @override
1731
+ * @inheritDoc
1732
+ */
1733
+ Text.prototype.insertTextAtSelection = function (text, style) {
1734
+ var selection = this.getTextSelection();
1735
+ this.insertText(text, style, selection.start, selection.end);
1736
+ };
1716
1737
  /**
1717
1738
  * @override
1718
1739
  * @inheritDoc
@@ -2404,6 +2425,10 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
2404
2425
  this.fontLibrary = new FontLibrary();
2405
2426
  this.dimensionChangeRejections$ = new Subject();
2406
2427
  this.IMAGE_CAPTURE_COEFFICIENT = this.calculateImageCaptureCoefficient();
2428
+ /**
2429
+ * Fabric defaults to only 2 decimal places when saving, which causes havoc on the scaling of large images.
2430
+ */
2431
+ fabric.Object.NUM_FRACTION_DIGITS = 10;
2407
2432
  this.baseDimensions = new PixelCanvasDimensions(this.fabricCanvas.width, this.fabricCanvas.height);
2408
2433
  var baseRestrictions = { width: { min: 1 }, height: { min: 1 } };
2409
2434
  //Initialize properties
@@ -1715,6 +1715,27 @@ var Text = /** @class */ (function (_super) {
1715
1715
  this.data.userText = this.fabricObject.text;
1716
1716
  this.text$.next(this.fabricObject.text);
1717
1717
  };
1718
+ /**
1719
+ * @override
1720
+ * @inheritDoc
1721
+ */
1722
+ Text.prototype.insertText = function (text, style, start, end) {
1723
+ this.fabricObject.insertChars(text, style, start, end);
1724
+ var newCursorLocation = start + text.length;
1725
+ this.fabricObject.selectionStart = newCursorLocation;
1726
+ this.fabricObject.selectionEnd = newCursorLocation;
1727
+ this.redraw();
1728
+ this.data.userText = this.fabricObject.text;
1729
+ this.text$.next(this.fabricObject.text);
1730
+ };
1731
+ /**
1732
+ * @override
1733
+ * @inheritDoc
1734
+ */
1735
+ Text.prototype.insertTextAtSelection = function (text, style) {
1736
+ var selection = this.getTextSelection();
1737
+ this.insertText(text, style, selection.start, selection.end);
1738
+ };
1718
1739
  /**
1719
1740
  * @override
1720
1741
  * @inheritDoc
@@ -2404,6 +2425,10 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
2404
2425
  this.fontLibrary = new FontLibrary();
2405
2426
  this.dimensionChangeRejections$ = new rxjs.Subject();
2406
2427
  this.IMAGE_CAPTURE_COEFFICIENT = this.calculateImageCaptureCoefficient();
2428
+ /**
2429
+ * Fabric defaults to only 2 decimal places when saving, which causes havoc on the scaling of large images.
2430
+ */
2431
+ fabric.Object.NUM_FRACTION_DIGITS = 10;
2407
2432
  this.baseDimensions = new PixelCanvasDimensions(this.fabricCanvas.width, this.fabricCanvas.height);
2408
2433
  var baseRestrictions = { width: { min: 1 }, height: { min: 1 } };
2409
2434
  //Initialize properties
@@ -24,6 +24,26 @@ export interface IMutableText extends ICanvasObject {
24
24
  * @param replacement Replacement fragment.
25
25
  */
26
26
  replaceText(target: string, replacement: string): void;
27
+ /**
28
+ * Taken from the fabric JSDOC:
29
+ * Insert characters at start position, before start position.
30
+ * start equal 1 it means the text get inserted between actual grapheme 0 and 1
31
+ * if style array is provided, it must be as the same length of text in graphemes
32
+ * if end is provided and is bigger than start, old text is replaced.
33
+ * start/end ar per grapheme position in _text array.
34
+ *
35
+ * @param text text to insert
36
+ * @param style array of style objects
37
+ * @param start
38
+ * @param end default to start + 1
39
+ */
40
+ insertText(text: string, style?: any[], start?: number, end?: number): void;
41
+ /**
42
+ * {@link #insertText} but at the current cursor location.
43
+ * @param text
44
+ * @param style
45
+ */
46
+ insertTextAtSelection(text: string, style?: any[]): void;
27
47
  /**
28
48
  * Is the text bulleted?
29
49
  */
@@ -71,6 +71,16 @@ export declare class Text extends AbstractCanvasObject<fabric.Textbox> implement
71
71
  * @inheritDoc
72
72
  */
73
73
  replaceText(target: string, replacement: string): void;
74
+ /**
75
+ * @override
76
+ * @inheritDoc
77
+ */
78
+ insertText(text: string, style?: any[], start?: number, end?: number): void;
79
+ /**
80
+ * @override
81
+ * @inheritDoc
82
+ */
83
+ insertTextAtSelection(text: string, style?: any[]): void;
74
84
  /**
75
85
  * @override
76
86
  * @inheritDoc
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leapfrog/interactive-canvas",
3
- "version": "1.5.2",
3
+ "version": "1.6.0",
4
4
  "description": "Leapfrog interactive canvas",
5
5
  "files": [
6
6
  "dist"