@leapfrog/interactive-canvas 1.13.2 → 1.14.0-beta.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.
@@ -284,6 +284,63 @@ var RedrawAllLayoutFunction = /** @class */ (function () {
284
284
  return RedrawAllLayoutFunction;
285
285
  }());
286
286
 
287
+ var RepositionCutoffsLayoutFunction = /** @class */ (function () {
288
+ function RepositionCutoffsLayoutFunction() {
289
+ }
290
+ RepositionCutoffsLayoutFunction.prototype.execute = function (canvas) {
291
+ canvas.getObjectsByTypeInternal(ObjectType.CUTOFF)
292
+ .forEach(function (cutoff) { return cutoff.updatePosition(); });
293
+ };
294
+ return RepositionCutoffsLayoutFunction;
295
+ }());
296
+
297
+ var RepositionBordersLayoutFunction = /** @class */ (function () {
298
+ function RepositionBordersLayoutFunction() {
299
+ }
300
+ RepositionBordersLayoutFunction.prototype.execute = function (canvas) {
301
+ canvas.getObjectsByTypeInternal(ObjectType.BORDER)
302
+ .forEach(function (border) { return border.updatePosition(); });
303
+ };
304
+ return RepositionBordersLayoutFunction;
305
+ }());
306
+
307
+ var PinToBottomLayoutFunction = /** @class */ (function () {
308
+ function PinToBottomLayoutFunction() {
309
+ }
310
+ PinToBottomLayoutFunction.prototype.execute = function (canvas) {
311
+ canvas.getObjectsInternal()
312
+ .forEach(function (object) { return object.moveToPinnedPosition(); });
313
+ };
314
+ return PinToBottomLayoutFunction;
315
+ }());
316
+
317
+ var ResizeCanvasLayoutFunction = /** @class */ (function () {
318
+ function ResizeCanvasLayoutFunction() {
319
+ }
320
+ ResizeCanvasLayoutFunction.prototype.execute = function (canvas) {
321
+ if (canvas.getLayoutManager().isEnforcedPositioning)
322
+ return;
323
+ if (oc(canvas.getDimensionsRestrictions()).fixed(false))
324
+ return;
325
+ var currentDimensions = canvas.getDimensions();
326
+ var baseDimensions = canvas.getBaseDimensions();
327
+ var textHeightIncreasePx = _(canvas.getObjectsByTypeInternal(ObjectType.TEXT))
328
+ .filter(function (text) { return text.isResizeCanvas(); })
329
+ .reduce(function (x, text) { return x + text.getSizeIncreaseSinceCreation(); }, 0);
330
+ var increase = baseDimensions.withSize(currentDimensions.width, 0);
331
+ while (increase.heightPx < textHeightIncreasePx) {
332
+ increase = increase.withSize(increase.width, increase.height + 1);
333
+ }
334
+ var targetHeight = increase.withSize(increase.width, baseDimensions.height + increase.height);
335
+ if (currentDimensions.height !== targetHeight.height) {
336
+ canvas.setDimensions(targetHeight);
337
+ }
338
+ canvas.getObjectsInternal().forEach(function (object) { return object.setCoords(); });
339
+ canvas.redraw();
340
+ };
341
+ return ResizeCanvasLayoutFunction;
342
+ }());
343
+
287
344
  var LayoutManager;
288
345
  (function (LayoutManager) {
289
346
  LayoutManager["LEGACY"] = "LEGACY";
@@ -291,6 +348,45 @@ var LayoutManager;
291
348
  LayoutManager["ADVANCED"] = "ADVANCED";
292
349
  })(LayoutManager || (LayoutManager = {}));
293
350
 
351
+ var RepositionBackgroundsLayoutFunction = /** @class */ (function () {
352
+ function RepositionBackgroundsLayoutFunction() {
353
+ }
354
+ RepositionBackgroundsLayoutFunction.prototype.execute = function (canvas) {
355
+ canvas.getObjectsByTypeInternal(ObjectType.BACKGROUND_IMAGE)
356
+ .forEach(function (border) { return border.updatePosition(); });
357
+ };
358
+ return RepositionBackgroundsLayoutFunction;
359
+ }());
360
+
361
+ var AdvancedLayoutManager = /** @class */ (function (_super) {
362
+ __extends(AdvancedLayoutManager, _super);
363
+ function AdvancedLayoutManager(canvas) {
364
+ var _this = _super.call(this, canvas) || this;
365
+ _this.key = LayoutManager.ADVANCED;
366
+ _this.pinToBottom = new PinToBottomLayoutFunction();
367
+ _this.redrawAll = new RedrawAllLayoutFunction();
368
+ _this.repositionBorders = new RepositionBordersLayoutFunction();
369
+ _this.repositionCutoffs = new RepositionCutoffsLayoutFunction();
370
+ _this.repositionBackgrounds = new RepositionBackgroundsLayoutFunction();
371
+ _this.resizeCanvas = new ResizeCanvasLayoutFunction();
372
+ return _this;
373
+ }
374
+ AdvancedLayoutManager.prototype.onCanvasDimensionsChange = function () {
375
+ this.pinToBottom.execute(this.canvas);
376
+ this.repositionCutoffs.execute(this.canvas);
377
+ this.repositionBorders.execute(this.canvas);
378
+ this.repositionBackgrounds.execute(this.canvas);
379
+ this.redrawAll.execute(this.canvas);
380
+ };
381
+ AdvancedLayoutManager.prototype.onTextChange = function () {
382
+ this.resizeCanvas.execute(this.canvas);
383
+ };
384
+ AdvancedLayoutManager.prototype.onObjectListChange = function () {
385
+ this.redrawAll.execute(this.canvas);
386
+ };
387
+ return AdvancedLayoutManager;
388
+ }(AbstractLayoutManager));
389
+
294
390
  var UpdateObjectDimensionsLayoutFunction = /** @class */ (function () {
295
391
  function UpdateObjectDimensionsLayoutFunction() {
296
392
  }
@@ -366,6 +462,8 @@ var StackObjectsLayoutFunction = /** @class */ (function () {
366
462
  var objectLeft = canvasMargin.left + columnOffset + objectMargin;
367
463
  if (object.getType() === ObjectType.TEXT && object.isBulleted())
368
464
  objectLeft += object.getBulletMargin();
465
+ if (object.getType() === ObjectType.TEXT && object.isOrderedList())
466
+ objectLeft += object.getOrderedListMargin();
369
467
  if (object.getType() === ObjectType.VERTICAL_RULE)
370
468
  object.setPosition({ height: row.height });
371
469
  object.setPosition({
@@ -454,26 +552,6 @@ var StackObjectsLayoutFunction = /** @class */ (function () {
454
552
  return StackObjectsLayoutFunction;
455
553
  }());
456
554
 
457
- var RepositionBordersLayoutFunction = /** @class */ (function () {
458
- function RepositionBordersLayoutFunction() {
459
- }
460
- RepositionBordersLayoutFunction.prototype.execute = function (canvas) {
461
- canvas.getObjectsByTypeInternal(ObjectType.BORDER)
462
- .forEach(function (border) { return border.updatePosition(); });
463
- };
464
- return RepositionBordersLayoutFunction;
465
- }());
466
-
467
- var RepositionBackgroundsLayoutFunction = /** @class */ (function () {
468
- function RepositionBackgroundsLayoutFunction() {
469
- }
470
- RepositionBackgroundsLayoutFunction.prototype.execute = function (canvas) {
471
- canvas.getObjectsByTypeInternal(ObjectType.BACKGROUND_IMAGE)
472
- .forEach(function (border) { return border.updatePosition(); });
473
- };
474
- return RepositionBackgroundsLayoutFunction;
475
- }());
476
-
477
555
  var StandardLayoutManager = /** @class */ (function (_super) {
478
556
  __extends(StandardLayoutManager, _super);
479
557
  function StandardLayoutManager(canvas) {
@@ -2166,6 +2244,20 @@ var Text = /** @class */ (function (_super) {
2166
2244
  });
2167
2245
  return fontSize * 0.6;
2168
2246
  };
2247
+ /**
2248
+ * @override
2249
+ * @inheritDoc
2250
+ */
2251
+ Text.prototype.getOrderedListMargin = function () {
2252
+ var _this = this;
2253
+ if (!this.isOrderedList())
2254
+ return 0;
2255
+ var fontSize = 0;
2256
+ each(this.fabricObject._textLines, function (textLine, lineIndex) {
2257
+ fontSize = Math.max(fontSize, _this.fabricObject.getValueOfPropertyAt(lineIndex, 0, "fontSize"));
2258
+ });
2259
+ return fontSize * 1.5;
2260
+ };
2169
2261
  /**
2170
2262
  * @override
2171
2263
  * @inheritDoc
@@ -2226,6 +2318,7 @@ var Text = /** @class */ (function (_super) {
2226
2318
  * @inheritDoc
2227
2319
  */
2228
2320
  Text.prototype.enableBullets = function () {
2321
+ this.disableOrderedList();
2229
2322
  this.fabricObject["objectCaching"] = false;
2230
2323
  this.fabricObject["_bullets"] = this.fabricObject["_bullets"] || {};
2231
2324
  this.data.bulleted = true;
@@ -2242,6 +2335,34 @@ var Text = /** @class */ (function (_super) {
2242
2335
  this.notifyCanvasOfTextChanges();
2243
2336
  this.redraw();
2244
2337
  };
2338
+ /**
2339
+ * @override
2340
+ * @inheritDoc
2341
+ */
2342
+ Text.prototype.isOrderedList = function () {
2343
+ return this.fabricObject.orderedList || false;
2344
+ };
2345
+ /**
2346
+ * @override
2347
+ * @inheritDoc
2348
+ */
2349
+ Text.prototype.enableOrderedList = function () {
2350
+ this.disableBullets();
2351
+ this.fabricObject["objectCaching"] = false;
2352
+ this.fabricObject.orderedList = true;
2353
+ this.notifyCanvasOfTextChanges();
2354
+ this.redraw();
2355
+ };
2356
+ /**
2357
+ * @override
2358
+ * @inheritDoc
2359
+ */
2360
+ Text.prototype.disableOrderedList = function () {
2361
+ this.removeOrderedList();
2362
+ delete this.fabricObject.orderedList;
2363
+ this.notifyCanvasOfTextChanges();
2364
+ this.redraw();
2365
+ };
2245
2366
  Text.prototype.getSizeIncreaseSinceCreation = function () {
2246
2367
  return Math.max(0, this.fabricObject.height - this.baseComponentHeight);
2247
2368
  };
@@ -2254,9 +2375,20 @@ var Text = /** @class */ (function (_super) {
2254
2375
  this.fabricObject["objectCaching"] = true;
2255
2376
  }
2256
2377
  };
2378
+ Text.prototype.removeOrderedList = function () {
2379
+ var _this = this;
2380
+ if (this.fabricObject.orderedList) {
2381
+ var lineNumbers = this.fabricObject["_currentLineNumbers"];
2382
+ delete this.fabricObject["_currentLineNumbers"];
2383
+ each(lineNumbers, function (lineNumber) { return _this.canvas.removeFabricObject(lineNumber); });
2384
+ this.fabricObject["objectCaching"] = true;
2385
+ }
2386
+ };
2257
2387
  Text.prototype.applyBulletListMonkeyPatches = function () {
2258
2388
  if (this.data.bulleted)
2259
2389
  this.enableBullets();
2390
+ if (this.fabricObject.orderedList)
2391
+ this.enableOrderedList();
2260
2392
  var originalRender = this.fabricObject["_render"];
2261
2393
  var fabric = this.canvas.fabric;
2262
2394
  this.fabricObject["_render"] = function (ctx) {
@@ -2318,6 +2450,61 @@ var Text = /** @class */ (function (_super) {
2318
2450
  setTimeout(canvas_1.renderAll.bind(canvas_1));
2319
2451
  }
2320
2452
  }
2453
+ if (fabricText["orderedList"]) {
2454
+ // Determine list of active bullets
2455
+ var currentLineNumbers_1 = fabricText["_currentLineNumbers"] || {};
2456
+ var activeLineNumbers_1 = {};
2457
+ each(fabricText._textLines, function (textLine, lineIndex) {
2458
+ if (textLine.length) {
2459
+ // Start of real lines will have offset 0 in styleMap
2460
+ var styleMap = fabricText._styleMap[lineIndex];
2461
+ if (styleMap.offset === 0) {
2462
+ if (currentLineNumbers_1[lineIndex]) {
2463
+ // Reuse existing bullet for this line
2464
+ activeLineNumbers_1[lineIndex] = currentLineNumbers_1[lineIndex];
2465
+ }
2466
+ else {
2467
+ // Create new bullet for this line
2468
+ activeLineNumbers_1[lineIndex] = new fabric.Textbox(lineIndex + ".", {
2469
+ left: 0,
2470
+ top: 0,
2471
+ fill: fabricText.fill,
2472
+ scaleX: fabricText.scaleX,
2473
+ scaleY: fabricText.scaleY,
2474
+ strokeWidth: 0,
2475
+ lockMovementX: true,
2476
+ lockMovementY: true,
2477
+ hasControls: false,
2478
+ selectable: false,
2479
+ excludeFromExport: true
2480
+ });
2481
+ }
2482
+ }
2483
+ }
2484
+ });
2485
+ // Add/Remove bullets from canvas
2486
+ var canvas_2 = fabricText.canvas;
2487
+ var canvasDirty_2 = false;
2488
+ canvas_2.renderOnAddRemove = false;
2489
+ each(activeLineNumbers_1, function (bullet) {
2490
+ if (!canvas_2.contains(bullet)) {
2491
+ canvas_2.add(bullet);
2492
+ canvasDirty_2 = true;
2493
+ }
2494
+ });
2495
+ each(currentLineNumbers_1, function (bullet, key) {
2496
+ if (!activeLineNumbers_1[key]) {
2497
+ canvas_2.remove(bullet);
2498
+ canvasDirty_2 = true;
2499
+ }
2500
+ });
2501
+ canvas_2.renderOnAddRemove = true;
2502
+ fabricText["_currentLineNumbers"] = activeLineNumbers_1;
2503
+ if (canvasDirty_2) {
2504
+ // Fabric doesn't like it when you add new things within render so use a sneaky timeout to delay render
2505
+ setTimeout(canvas_2.renderAll.bind(canvas_2));
2506
+ }
2507
+ }
2321
2508
  originalRender.apply(fabricText, [ctx]);
2322
2509
  };
2323
2510
  var originalRenderTextLine = this.fabricObject["_renderTextLine"];
@@ -2343,6 +2530,28 @@ var Text = /** @class */ (function (_super) {
2343
2530
  top: fabricText.top + yOffset + bulletCenterOffset[1]
2344
2531
  });
2345
2532
  }
2533
+ var currentLineNumbers = fabricText._currentLineNumbers;
2534
+ if (currentLineNumbers && currentLineNumbers[lineIndex]) {
2535
+ var lineNumber = currentLineNumbers[lineIndex];
2536
+ var fontSize = this.getValueOfPropertyAt(lineIndex, 0, "fontSize");
2537
+ var fontFamily = this.getValueOfPropertyAt(lineIndex, 0, "fontFamily");
2538
+ var color = this.getValueOfPropertyAt(lineIndex, 0, "fill");
2539
+ var angle = fabricText.angle;
2540
+ var theta = angle * Math.PI / 180;
2541
+ var xShift = -fontSize * 1.5;
2542
+ var yShift = (fabricText.height / 2) + top - fontSize - 1;
2543
+ var xOffset = (xShift * Math.cos(theta)) - (yShift * Math.sin(theta));
2544
+ var yOffset = (xShift * Math.sin(theta)) + (yShift * Math.cos(theta));
2545
+ lineNumber.set({
2546
+ fontSize: fontSize,
2547
+ fontFamily: fontFamily,
2548
+ fill: color,
2549
+ left: fabricText.left + xOffset,
2550
+ top: fabricText.top + yOffset,
2551
+ angle: fabricText.angle,
2552
+ text: lineIndex + 1 + "."
2553
+ });
2554
+ }
2346
2555
  originalRenderTextLine.apply(fabricText, [method, ctx, line, left, top, lineIndex]);
2347
2556
  };
2348
2557
  };
@@ -3246,7 +3455,7 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
3246
3455
  var objects = _(this.objects$.value)
3247
3456
  .map(function (x) { return x.persist(); })
3248
3457
  .value();
3249
- var includedProperties = ["id"];
3458
+ var includedProperties = ["id", "orderedList"];
3250
3459
  var json = this.fabricCanvas.toJSON(includedProperties);
3251
3460
  return {
3252
3461
  dimensions: this.dimensions$.value,
@@ -3730,80 +3939,4 @@ var InteractiveCanvas = /** @class */ (function (_super) {
3730
3939
  return InteractiveCanvas;
3731
3940
  }(AbstractInteractiveCanvas));
3732
3941
 
3733
- var RepositionCutoffsLayoutFunction = /** @class */ (function () {
3734
- function RepositionCutoffsLayoutFunction() {
3735
- }
3736
- RepositionCutoffsLayoutFunction.prototype.execute = function (canvas) {
3737
- canvas.getObjectsByTypeInternal(ObjectType.CUTOFF)
3738
- .forEach(function (cutoff) { return cutoff.updatePosition(); });
3739
- };
3740
- return RepositionCutoffsLayoutFunction;
3741
- }());
3742
-
3743
- var PinToBottomLayoutFunction = /** @class */ (function () {
3744
- function PinToBottomLayoutFunction() {
3745
- }
3746
- PinToBottomLayoutFunction.prototype.execute = function (canvas) {
3747
- canvas.getObjectsInternal()
3748
- .forEach(function (object) { return object.moveToPinnedPosition(); });
3749
- };
3750
- return PinToBottomLayoutFunction;
3751
- }());
3752
-
3753
- var ResizeCanvasLayoutFunction = /** @class */ (function () {
3754
- function ResizeCanvasLayoutFunction() {
3755
- }
3756
- ResizeCanvasLayoutFunction.prototype.execute = function (canvas) {
3757
- if (canvas.getLayoutManager().isEnforcedPositioning)
3758
- return;
3759
- if (oc(canvas.getDimensionsRestrictions()).fixed(false))
3760
- return;
3761
- var currentDimensions = canvas.getDimensions();
3762
- var baseDimensions = canvas.getBaseDimensions();
3763
- var textHeightIncreasePx = _(canvas.getObjectsByTypeInternal(ObjectType.TEXT))
3764
- .filter(function (text) { return text.isResizeCanvas(); })
3765
- .reduce(function (x, text) { return x + text.getSizeIncreaseSinceCreation(); }, 0);
3766
- var increase = baseDimensions.withSize(currentDimensions.width, 0);
3767
- while (increase.heightPx < textHeightIncreasePx) {
3768
- increase = increase.withSize(increase.width, increase.height + 1);
3769
- }
3770
- var targetHeight = increase.withSize(increase.width, baseDimensions.height + increase.height);
3771
- if (currentDimensions.height !== targetHeight.height) {
3772
- canvas.setDimensions(targetHeight);
3773
- }
3774
- canvas.getObjectsInternal().forEach(function (object) { return object.setCoords(); });
3775
- canvas.redraw();
3776
- };
3777
- return ResizeCanvasLayoutFunction;
3778
- }());
3779
-
3780
- var AdvancedLayoutManager = /** @class */ (function (_super) {
3781
- __extends(AdvancedLayoutManager, _super);
3782
- function AdvancedLayoutManager(canvas) {
3783
- var _this = _super.call(this, canvas) || this;
3784
- _this.key = LayoutManager.ADVANCED;
3785
- _this.pinToBottom = new PinToBottomLayoutFunction();
3786
- _this.redrawAll = new RedrawAllLayoutFunction();
3787
- _this.repositionBorders = new RepositionBordersLayoutFunction();
3788
- _this.repositionCutoffs = new RepositionCutoffsLayoutFunction();
3789
- _this.repositionBackgrounds = new RepositionBackgroundsLayoutFunction();
3790
- _this.resizeCanvas = new ResizeCanvasLayoutFunction();
3791
- return _this;
3792
- }
3793
- AdvancedLayoutManager.prototype.onCanvasDimensionsChange = function () {
3794
- this.pinToBottom.execute(this.canvas);
3795
- this.repositionCutoffs.execute(this.canvas);
3796
- this.repositionBorders.execute(this.canvas);
3797
- this.repositionBackgrounds.execute(this.canvas);
3798
- this.redrawAll.execute(this.canvas);
3799
- };
3800
- AdvancedLayoutManager.prototype.onTextChange = function () {
3801
- this.resizeCanvas.execute(this.canvas);
3802
- };
3803
- AdvancedLayoutManager.prototype.onObjectListChange = function () {
3804
- this.redrawAll.execute(this.canvas);
3805
- };
3806
- return AdvancedLayoutManager;
3807
- }(AbstractLayoutManager));
3808
-
3809
3942
  export { AbstractCanvasObject, AbstractInteractiveCanvas, AbstractLayoutManager, AdvancedLayoutManager, BackgroundImage, Border, CanvasObjectData, Cutoff, DefaultCanvasProfile, Font, FontLibrary, HeadlessInteractiveCanvas, HorizontalRule, Image, ImageType, InteractiveCanvas, LayoutManager, MillimeterDimensions, ObjectType, PixelCanvasDimensions, Print6ColCanvasDimensions, Print8ColCanvasDimensions, Rectangle, RichText, SelectionData, StandardLayoutManager, Text, UNKNOWN_FONT, UnknownFont, VerticalRule, isMutableBackgroundColor, isMutableColor, isMutableImage, isMutablePosition, isMutableStroke, isMutableText, isMutableTextStyle };
@@ -287,12 +287,108 @@ var RedrawAllLayoutFunction = /** @class */ (function () {
287
287
  return RedrawAllLayoutFunction;
288
288
  }());
289
289
 
290
+ var RepositionCutoffsLayoutFunction = /** @class */ (function () {
291
+ function RepositionCutoffsLayoutFunction() {
292
+ }
293
+ RepositionCutoffsLayoutFunction.prototype.execute = function (canvas) {
294
+ canvas.getObjectsByTypeInternal(exports.ObjectType.CUTOFF)
295
+ .forEach(function (cutoff) { return cutoff.updatePosition(); });
296
+ };
297
+ return RepositionCutoffsLayoutFunction;
298
+ }());
299
+
300
+ var RepositionBordersLayoutFunction = /** @class */ (function () {
301
+ function RepositionBordersLayoutFunction() {
302
+ }
303
+ RepositionBordersLayoutFunction.prototype.execute = function (canvas) {
304
+ canvas.getObjectsByTypeInternal(exports.ObjectType.BORDER)
305
+ .forEach(function (border) { return border.updatePosition(); });
306
+ };
307
+ return RepositionBordersLayoutFunction;
308
+ }());
309
+
310
+ var PinToBottomLayoutFunction = /** @class */ (function () {
311
+ function PinToBottomLayoutFunction() {
312
+ }
313
+ PinToBottomLayoutFunction.prototype.execute = function (canvas) {
314
+ canvas.getObjectsInternal()
315
+ .forEach(function (object) { return object.moveToPinnedPosition(); });
316
+ };
317
+ return PinToBottomLayoutFunction;
318
+ }());
319
+
320
+ var ResizeCanvasLayoutFunction = /** @class */ (function () {
321
+ function ResizeCanvasLayoutFunction() {
322
+ }
323
+ ResizeCanvasLayoutFunction.prototype.execute = function (canvas) {
324
+ if (canvas.getLayoutManager().isEnforcedPositioning)
325
+ return;
326
+ if (tsOptchain.oc(canvas.getDimensionsRestrictions()).fixed(false))
327
+ return;
328
+ var currentDimensions = canvas.getDimensions();
329
+ var baseDimensions = canvas.getBaseDimensions();
330
+ var textHeightIncreasePx = _(canvas.getObjectsByTypeInternal(exports.ObjectType.TEXT))
331
+ .filter(function (text) { return text.isResizeCanvas(); })
332
+ .reduce(function (x, text) { return x + text.getSizeIncreaseSinceCreation(); }, 0);
333
+ var increase = baseDimensions.withSize(currentDimensions.width, 0);
334
+ while (increase.heightPx < textHeightIncreasePx) {
335
+ increase = increase.withSize(increase.width, increase.height + 1);
336
+ }
337
+ var targetHeight = increase.withSize(increase.width, baseDimensions.height + increase.height);
338
+ if (currentDimensions.height !== targetHeight.height) {
339
+ canvas.setDimensions(targetHeight);
340
+ }
341
+ canvas.getObjectsInternal().forEach(function (object) { return object.setCoords(); });
342
+ canvas.redraw();
343
+ };
344
+ return ResizeCanvasLayoutFunction;
345
+ }());
346
+
290
347
  (function (LayoutManager) {
291
348
  LayoutManager["LEGACY"] = "LEGACY";
292
349
  LayoutManager["STANDARD"] = "STANDARD";
293
350
  LayoutManager["ADVANCED"] = "ADVANCED";
294
351
  })(exports.LayoutManager || (exports.LayoutManager = {}));
295
352
 
353
+ var RepositionBackgroundsLayoutFunction = /** @class */ (function () {
354
+ function RepositionBackgroundsLayoutFunction() {
355
+ }
356
+ RepositionBackgroundsLayoutFunction.prototype.execute = function (canvas) {
357
+ canvas.getObjectsByTypeInternal(exports.ObjectType.BACKGROUND_IMAGE)
358
+ .forEach(function (border) { return border.updatePosition(); });
359
+ };
360
+ return RepositionBackgroundsLayoutFunction;
361
+ }());
362
+
363
+ var AdvancedLayoutManager = /** @class */ (function (_super) {
364
+ __extends(AdvancedLayoutManager, _super);
365
+ function AdvancedLayoutManager(canvas) {
366
+ var _this = _super.call(this, canvas) || this;
367
+ _this.key = exports.LayoutManager.ADVANCED;
368
+ _this.pinToBottom = new PinToBottomLayoutFunction();
369
+ _this.redrawAll = new RedrawAllLayoutFunction();
370
+ _this.repositionBorders = new RepositionBordersLayoutFunction();
371
+ _this.repositionCutoffs = new RepositionCutoffsLayoutFunction();
372
+ _this.repositionBackgrounds = new RepositionBackgroundsLayoutFunction();
373
+ _this.resizeCanvas = new ResizeCanvasLayoutFunction();
374
+ return _this;
375
+ }
376
+ AdvancedLayoutManager.prototype.onCanvasDimensionsChange = function () {
377
+ this.pinToBottom.execute(this.canvas);
378
+ this.repositionCutoffs.execute(this.canvas);
379
+ this.repositionBorders.execute(this.canvas);
380
+ this.repositionBackgrounds.execute(this.canvas);
381
+ this.redrawAll.execute(this.canvas);
382
+ };
383
+ AdvancedLayoutManager.prototype.onTextChange = function () {
384
+ this.resizeCanvas.execute(this.canvas);
385
+ };
386
+ AdvancedLayoutManager.prototype.onObjectListChange = function () {
387
+ this.redrawAll.execute(this.canvas);
388
+ };
389
+ return AdvancedLayoutManager;
390
+ }(AbstractLayoutManager));
391
+
296
392
  var UpdateObjectDimensionsLayoutFunction = /** @class */ (function () {
297
393
  function UpdateObjectDimensionsLayoutFunction() {
298
394
  }
@@ -368,6 +464,8 @@ var StackObjectsLayoutFunction = /** @class */ (function () {
368
464
  var objectLeft = canvasMargin.left + columnOffset + objectMargin;
369
465
  if (object.getType() === exports.ObjectType.TEXT && object.isBulleted())
370
466
  objectLeft += object.getBulletMargin();
467
+ if (object.getType() === exports.ObjectType.TEXT && object.isOrderedList())
468
+ objectLeft += object.getOrderedListMargin();
371
469
  if (object.getType() === exports.ObjectType.VERTICAL_RULE)
372
470
  object.setPosition({ height: row.height });
373
471
  object.setPosition({
@@ -456,26 +554,6 @@ var StackObjectsLayoutFunction = /** @class */ (function () {
456
554
  return StackObjectsLayoutFunction;
457
555
  }());
458
556
 
459
- var RepositionBordersLayoutFunction = /** @class */ (function () {
460
- function RepositionBordersLayoutFunction() {
461
- }
462
- RepositionBordersLayoutFunction.prototype.execute = function (canvas) {
463
- canvas.getObjectsByTypeInternal(exports.ObjectType.BORDER)
464
- .forEach(function (border) { return border.updatePosition(); });
465
- };
466
- return RepositionBordersLayoutFunction;
467
- }());
468
-
469
- var RepositionBackgroundsLayoutFunction = /** @class */ (function () {
470
- function RepositionBackgroundsLayoutFunction() {
471
- }
472
- RepositionBackgroundsLayoutFunction.prototype.execute = function (canvas) {
473
- canvas.getObjectsByTypeInternal(exports.ObjectType.BACKGROUND_IMAGE)
474
- .forEach(function (border) { return border.updatePosition(); });
475
- };
476
- return RepositionBackgroundsLayoutFunction;
477
- }());
478
-
479
557
  var StandardLayoutManager = /** @class */ (function (_super) {
480
558
  __extends(StandardLayoutManager, _super);
481
559
  function StandardLayoutManager(canvas) {
@@ -2168,6 +2246,20 @@ var Text = /** @class */ (function (_super) {
2168
2246
  });
2169
2247
  return fontSize * 0.6;
2170
2248
  };
2249
+ /**
2250
+ * @override
2251
+ * @inheritDoc
2252
+ */
2253
+ Text.prototype.getOrderedListMargin = function () {
2254
+ var _this = this;
2255
+ if (!this.isOrderedList())
2256
+ return 0;
2257
+ var fontSize = 0;
2258
+ _.each(this.fabricObject._textLines, function (textLine, lineIndex) {
2259
+ fontSize = Math.max(fontSize, _this.fabricObject.getValueOfPropertyAt(lineIndex, 0, "fontSize"));
2260
+ });
2261
+ return fontSize * 1.5;
2262
+ };
2171
2263
  /**
2172
2264
  * @override
2173
2265
  * @inheritDoc
@@ -2228,6 +2320,7 @@ var Text = /** @class */ (function (_super) {
2228
2320
  * @inheritDoc
2229
2321
  */
2230
2322
  Text.prototype.enableBullets = function () {
2323
+ this.disableOrderedList();
2231
2324
  this.fabricObject["objectCaching"] = false;
2232
2325
  this.fabricObject["_bullets"] = this.fabricObject["_bullets"] || {};
2233
2326
  this.data.bulleted = true;
@@ -2244,6 +2337,34 @@ var Text = /** @class */ (function (_super) {
2244
2337
  this.notifyCanvasOfTextChanges();
2245
2338
  this.redraw();
2246
2339
  };
2340
+ /**
2341
+ * @override
2342
+ * @inheritDoc
2343
+ */
2344
+ Text.prototype.isOrderedList = function () {
2345
+ return this.fabricObject.orderedList || false;
2346
+ };
2347
+ /**
2348
+ * @override
2349
+ * @inheritDoc
2350
+ */
2351
+ Text.prototype.enableOrderedList = function () {
2352
+ this.disableBullets();
2353
+ this.fabricObject["objectCaching"] = false;
2354
+ this.fabricObject.orderedList = true;
2355
+ this.notifyCanvasOfTextChanges();
2356
+ this.redraw();
2357
+ };
2358
+ /**
2359
+ * @override
2360
+ * @inheritDoc
2361
+ */
2362
+ Text.prototype.disableOrderedList = function () {
2363
+ this.removeOrderedList();
2364
+ delete this.fabricObject.orderedList;
2365
+ this.notifyCanvasOfTextChanges();
2366
+ this.redraw();
2367
+ };
2247
2368
  Text.prototype.getSizeIncreaseSinceCreation = function () {
2248
2369
  return Math.max(0, this.fabricObject.height - this.baseComponentHeight);
2249
2370
  };
@@ -2256,9 +2377,20 @@ var Text = /** @class */ (function (_super) {
2256
2377
  this.fabricObject["objectCaching"] = true;
2257
2378
  }
2258
2379
  };
2380
+ Text.prototype.removeOrderedList = function () {
2381
+ var _this = this;
2382
+ if (this.fabricObject.orderedList) {
2383
+ var lineNumbers = this.fabricObject["_currentLineNumbers"];
2384
+ delete this.fabricObject["_currentLineNumbers"];
2385
+ _.each(lineNumbers, function (lineNumber) { return _this.canvas.removeFabricObject(lineNumber); });
2386
+ this.fabricObject["objectCaching"] = true;
2387
+ }
2388
+ };
2259
2389
  Text.prototype.applyBulletListMonkeyPatches = function () {
2260
2390
  if (this.data.bulleted)
2261
2391
  this.enableBullets();
2392
+ if (this.fabricObject.orderedList)
2393
+ this.enableOrderedList();
2262
2394
  var originalRender = this.fabricObject["_render"];
2263
2395
  var fabric = this.canvas.fabric;
2264
2396
  this.fabricObject["_render"] = function (ctx) {
@@ -2320,6 +2452,61 @@ var Text = /** @class */ (function (_super) {
2320
2452
  setTimeout(canvas_1.renderAll.bind(canvas_1));
2321
2453
  }
2322
2454
  }
2455
+ if (fabricText["orderedList"]) {
2456
+ // Determine list of active bullets
2457
+ var currentLineNumbers_1 = fabricText["_currentLineNumbers"] || {};
2458
+ var activeLineNumbers_1 = {};
2459
+ _.each(fabricText._textLines, function (textLine, lineIndex) {
2460
+ if (textLine.length) {
2461
+ // Start of real lines will have offset 0 in styleMap
2462
+ var styleMap = fabricText._styleMap[lineIndex];
2463
+ if (styleMap.offset === 0) {
2464
+ if (currentLineNumbers_1[lineIndex]) {
2465
+ // Reuse existing bullet for this line
2466
+ activeLineNumbers_1[lineIndex] = currentLineNumbers_1[lineIndex];
2467
+ }
2468
+ else {
2469
+ // Create new bullet for this line
2470
+ activeLineNumbers_1[lineIndex] = new fabric.Textbox(lineIndex + ".", {
2471
+ left: 0,
2472
+ top: 0,
2473
+ fill: fabricText.fill,
2474
+ scaleX: fabricText.scaleX,
2475
+ scaleY: fabricText.scaleY,
2476
+ strokeWidth: 0,
2477
+ lockMovementX: true,
2478
+ lockMovementY: true,
2479
+ hasControls: false,
2480
+ selectable: false,
2481
+ excludeFromExport: true
2482
+ });
2483
+ }
2484
+ }
2485
+ }
2486
+ });
2487
+ // Add/Remove bullets from canvas
2488
+ var canvas_2 = fabricText.canvas;
2489
+ var canvasDirty_2 = false;
2490
+ canvas_2.renderOnAddRemove = false;
2491
+ _.each(activeLineNumbers_1, function (bullet) {
2492
+ if (!canvas_2.contains(bullet)) {
2493
+ canvas_2.add(bullet);
2494
+ canvasDirty_2 = true;
2495
+ }
2496
+ });
2497
+ _.each(currentLineNumbers_1, function (bullet, key) {
2498
+ if (!activeLineNumbers_1[key]) {
2499
+ canvas_2.remove(bullet);
2500
+ canvasDirty_2 = true;
2501
+ }
2502
+ });
2503
+ canvas_2.renderOnAddRemove = true;
2504
+ fabricText["_currentLineNumbers"] = activeLineNumbers_1;
2505
+ if (canvasDirty_2) {
2506
+ // Fabric doesn't like it when you add new things within render so use a sneaky timeout to delay render
2507
+ setTimeout(canvas_2.renderAll.bind(canvas_2));
2508
+ }
2509
+ }
2323
2510
  originalRender.apply(fabricText, [ctx]);
2324
2511
  };
2325
2512
  var originalRenderTextLine = this.fabricObject["_renderTextLine"];
@@ -2345,6 +2532,28 @@ var Text = /** @class */ (function (_super) {
2345
2532
  top: fabricText.top + yOffset + bulletCenterOffset[1]
2346
2533
  });
2347
2534
  }
2535
+ var currentLineNumbers = fabricText._currentLineNumbers;
2536
+ if (currentLineNumbers && currentLineNumbers[lineIndex]) {
2537
+ var lineNumber = currentLineNumbers[lineIndex];
2538
+ var fontSize = this.getValueOfPropertyAt(lineIndex, 0, "fontSize");
2539
+ var fontFamily = this.getValueOfPropertyAt(lineIndex, 0, "fontFamily");
2540
+ var color = this.getValueOfPropertyAt(lineIndex, 0, "fill");
2541
+ var angle = fabricText.angle;
2542
+ var theta = angle * Math.PI / 180;
2543
+ var xShift = -fontSize * 1.5;
2544
+ var yShift = (fabricText.height / 2) + top - fontSize - 1;
2545
+ var xOffset = (xShift * Math.cos(theta)) - (yShift * Math.sin(theta));
2546
+ var yOffset = (xShift * Math.sin(theta)) + (yShift * Math.cos(theta));
2547
+ lineNumber.set({
2548
+ fontSize: fontSize,
2549
+ fontFamily: fontFamily,
2550
+ fill: color,
2551
+ left: fabricText.left + xOffset,
2552
+ top: fabricText.top + yOffset,
2553
+ angle: fabricText.angle,
2554
+ text: lineIndex + 1 + "."
2555
+ });
2556
+ }
2348
2557
  originalRenderTextLine.apply(fabricText, [method, ctx, line, left, top, lineIndex]);
2349
2558
  };
2350
2559
  };
@@ -3246,7 +3455,7 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
3246
3455
  var objects = _(this.objects$.value)
3247
3456
  .map(function (x) { return x.persist(); })
3248
3457
  .value();
3249
- var includedProperties = ["id"];
3458
+ var includedProperties = ["id", "orderedList"];
3250
3459
  var json = this.fabricCanvas.toJSON(includedProperties);
3251
3460
  return {
3252
3461
  dimensions: this.dimensions$.value,
@@ -3730,82 +3939,6 @@ var InteractiveCanvas = /** @class */ (function (_super) {
3730
3939
  return InteractiveCanvas;
3731
3940
  }(AbstractInteractiveCanvas));
3732
3941
 
3733
- var RepositionCutoffsLayoutFunction = /** @class */ (function () {
3734
- function RepositionCutoffsLayoutFunction() {
3735
- }
3736
- RepositionCutoffsLayoutFunction.prototype.execute = function (canvas) {
3737
- canvas.getObjectsByTypeInternal(exports.ObjectType.CUTOFF)
3738
- .forEach(function (cutoff) { return cutoff.updatePosition(); });
3739
- };
3740
- return RepositionCutoffsLayoutFunction;
3741
- }());
3742
-
3743
- var PinToBottomLayoutFunction = /** @class */ (function () {
3744
- function PinToBottomLayoutFunction() {
3745
- }
3746
- PinToBottomLayoutFunction.prototype.execute = function (canvas) {
3747
- canvas.getObjectsInternal()
3748
- .forEach(function (object) { return object.moveToPinnedPosition(); });
3749
- };
3750
- return PinToBottomLayoutFunction;
3751
- }());
3752
-
3753
- var ResizeCanvasLayoutFunction = /** @class */ (function () {
3754
- function ResizeCanvasLayoutFunction() {
3755
- }
3756
- ResizeCanvasLayoutFunction.prototype.execute = function (canvas) {
3757
- if (canvas.getLayoutManager().isEnforcedPositioning)
3758
- return;
3759
- if (tsOptchain.oc(canvas.getDimensionsRestrictions()).fixed(false))
3760
- return;
3761
- var currentDimensions = canvas.getDimensions();
3762
- var baseDimensions = canvas.getBaseDimensions();
3763
- var textHeightIncreasePx = _(canvas.getObjectsByTypeInternal(exports.ObjectType.TEXT))
3764
- .filter(function (text) { return text.isResizeCanvas(); })
3765
- .reduce(function (x, text) { return x + text.getSizeIncreaseSinceCreation(); }, 0);
3766
- var increase = baseDimensions.withSize(currentDimensions.width, 0);
3767
- while (increase.heightPx < textHeightIncreasePx) {
3768
- increase = increase.withSize(increase.width, increase.height + 1);
3769
- }
3770
- var targetHeight = increase.withSize(increase.width, baseDimensions.height + increase.height);
3771
- if (currentDimensions.height !== targetHeight.height) {
3772
- canvas.setDimensions(targetHeight);
3773
- }
3774
- canvas.getObjectsInternal().forEach(function (object) { return object.setCoords(); });
3775
- canvas.redraw();
3776
- };
3777
- return ResizeCanvasLayoutFunction;
3778
- }());
3779
-
3780
- var AdvancedLayoutManager = /** @class */ (function (_super) {
3781
- __extends(AdvancedLayoutManager, _super);
3782
- function AdvancedLayoutManager(canvas) {
3783
- var _this = _super.call(this, canvas) || this;
3784
- _this.key = exports.LayoutManager.ADVANCED;
3785
- _this.pinToBottom = new PinToBottomLayoutFunction();
3786
- _this.redrawAll = new RedrawAllLayoutFunction();
3787
- _this.repositionBorders = new RepositionBordersLayoutFunction();
3788
- _this.repositionCutoffs = new RepositionCutoffsLayoutFunction();
3789
- _this.repositionBackgrounds = new RepositionBackgroundsLayoutFunction();
3790
- _this.resizeCanvas = new ResizeCanvasLayoutFunction();
3791
- return _this;
3792
- }
3793
- AdvancedLayoutManager.prototype.onCanvasDimensionsChange = function () {
3794
- this.pinToBottom.execute(this.canvas);
3795
- this.repositionCutoffs.execute(this.canvas);
3796
- this.repositionBorders.execute(this.canvas);
3797
- this.repositionBackgrounds.execute(this.canvas);
3798
- this.redrawAll.execute(this.canvas);
3799
- };
3800
- AdvancedLayoutManager.prototype.onTextChange = function () {
3801
- this.resizeCanvas.execute(this.canvas);
3802
- };
3803
- AdvancedLayoutManager.prototype.onObjectListChange = function () {
3804
- this.redrawAll.execute(this.canvas);
3805
- };
3806
- return AdvancedLayoutManager;
3807
- }(AbstractLayoutManager));
3808
-
3809
3942
  exports.AbstractCanvasObject = AbstractCanvasObject;
3810
3943
  exports.AbstractInteractiveCanvas = AbstractInteractiveCanvas;
3811
3944
  exports.AbstractLayoutManager = AbstractLayoutManager;
@@ -56,5 +56,17 @@ export interface IMutableText extends ICanvasObject {
56
56
  * Disable bullet points.
57
57
  */
58
58
  disableBullets(): void;
59
+ /**
60
+ * Is the text an ordered list?
61
+ */
62
+ isOrderedList(): boolean;
63
+ /**
64
+ * Enable ordered list markers.
65
+ */
66
+ enableOrderedList(): void;
67
+ /**
68
+ * Disable ordered list markers.
69
+ */
70
+ disableOrderedList(): void;
59
71
  }
60
72
  export declare function isMutableText(object: any): object is IMutableText;
@@ -44,6 +44,10 @@ export interface IText extends ICanvasObject, IMutableColor, IMutableText, IMuta
44
44
  * Return the margin needed for bullets on this object.
45
45
  */
46
46
  getBulletMargin(): number;
47
+ /**
48
+ * Return the margin needed for ordered lists on this object.
49
+ */
50
+ getOrderedListMargin(): number;
47
51
  }
48
52
  export declare class Text extends AbstractCanvasObject<fabric.Textbox> implements IText {
49
53
  private readonly fontLibrary;
@@ -216,6 +220,11 @@ export declare class Text extends AbstractCanvasObject<fabric.Textbox> implement
216
220
  * @inheritDoc
217
221
  */
218
222
  getBulletMargin(): number;
223
+ /**
224
+ * @override
225
+ * @inheritDoc
226
+ */
227
+ getOrderedListMargin(): number;
219
228
  /**
220
229
  * @override
221
230
  * @inheritDoc
@@ -261,8 +270,24 @@ export declare class Text extends AbstractCanvasObject<fabric.Textbox> implement
261
270
  * @inheritDoc
262
271
  */
263
272
  disableBullets(): void;
273
+ /**
274
+ * @override
275
+ * @inheritDoc
276
+ */
277
+ isOrderedList(): boolean;
278
+ /**
279
+ * @override
280
+ * @inheritDoc
281
+ */
282
+ enableOrderedList(): void;
283
+ /**
284
+ * @override
285
+ * @inheritDoc
286
+ */
287
+ disableOrderedList(): void;
264
288
  getSizeIncreaseSinceCreation(): number;
265
289
  private removeBullets;
290
+ private removeOrderedList;
266
291
  private applyBulletListMonkeyPatches;
267
292
  /**
268
293
  * @override
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leapfrog/interactive-canvas",
3
- "version": "1.13.2",
3
+ "version": "1.14.0-beta.0",
4
4
  "description": "Leapfrog interactive canvas",
5
5
  "files": [
6
6
  "dist"
package/readme.md CHANGED
@@ -48,7 +48,6 @@ library in the calling project.
48
48
 
49
49
  ### Publishing
50
50
  The `.npmrc` file contains the access token needed to publish to the `@leapfrog` npm repo.
51
- * Increment the version number in `package.json`.
52
- * `npm install` to update the `package-lock.json`.
51
+ * `npm version <version>` or `npm version <version>-beta.0`
53
52
  * `npm run build`
54
- * `npm publish`
53
+ * `npm publish` or `npm publish --tag beta`