@leapfrog/interactive-canvas 1.5.3 → 1.7.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.
@@ -276,7 +276,7 @@ export declare abstract class AbstractInteractiveCanvas implements IInteractiveC
276
276
  * @override
277
277
  * @inheritDoc
278
278
  */
279
- toImage(): string;
279
+ toImage(multiplier?: number): string;
280
280
  /**
281
281
  * @override
282
282
  * @inheritDoc
@@ -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
@@ -3072,11 +3093,11 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
3072
3093
  * @override
3073
3094
  * @inheritDoc
3074
3095
  */
3075
- AbstractInteractiveCanvas.prototype.toImage = function () {
3096
+ AbstractInteractiveCanvas.prototype.toImage = function (multiplier) {
3076
3097
  var _this = this;
3077
3098
  var options = {
3078
3099
  format: "png",
3079
- multiplier: this.IMAGE_CAPTURE_COEFFICIENT,
3100
+ multiplier: multiplier || this.IMAGE_CAPTURE_COEFFICIENT,
3080
3101
  enableRetinaScaling: true
3081
3102
  };
3082
3103
  console.debug("Capturing canvas image", options);
@@ -219,8 +219,9 @@ export interface IInteractiveCanvas {
219
219
  toSvg(): string;
220
220
  /**
221
221
  * Export the canvas to a DataUrl image.
222
+ * @param multiplier Multiply the image pixel density by this amount.
222
223
  */
223
- toImage(): string;
224
+ toImage(multiplier?: number): string;
224
225
  /**
225
226
  * Notify the canvas that the object list has changed.
226
227
  */
@@ -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
@@ -3072,11 +3093,11 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
3072
3093
  * @override
3073
3094
  * @inheritDoc
3074
3095
  */
3075
- AbstractInteractiveCanvas.prototype.toImage = function () {
3096
+ AbstractInteractiveCanvas.prototype.toImage = function (multiplier) {
3076
3097
  var _this = this;
3077
3098
  var options = {
3078
3099
  format: "png",
3079
- multiplier: this.IMAGE_CAPTURE_COEFFICIENT,
3100
+ multiplier: multiplier || this.IMAGE_CAPTURE_COEFFICIENT,
3080
3101
  enableRetinaScaling: true
3081
3102
  };
3082
3103
  console.debug("Capturing canvas image", options);
@@ -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.3",
3
+ "version": "1.7.0",
4
4
  "description": "Leapfrog interactive canvas",
5
5
  "files": [
6
6
  "dist"