@leapfrog/interactive-canvas 2.0.15 → 2.0.17-beta-1
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.
- package/dist/abstract-interactive-canvas.d.ts +0 -3
- package/dist/interactive-canvas.es.js +254 -278
- package/dist/interactive-canvas.js +265 -297
- package/dist/object/impl/text.d.ts +1 -9
- package/dist/types/selection-data.interface.d.ts +0 -9
- package/dist/types/text-alignment.interface.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,27 +1,29 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as _ from 'lodash';
|
|
2
|
+
import { round, each, values, reduce, clone, replace, find, isEqual } from 'lodash';
|
|
3
|
+
import { oc } from 'ts-optchain';
|
|
2
4
|
import { BehaviorSubject, Subject } from 'rxjs';
|
|
3
5
|
import { fabric } from 'fabric';
|
|
4
6
|
|
|
5
|
-
var PIXELS_PER_MM
|
|
7
|
+
var PIXELS_PER_MM = 3.937;
|
|
6
8
|
var MillimeterDimensions = /** @class */ (function () {
|
|
7
9
|
function MillimeterDimensions(width, height) {
|
|
8
10
|
this.widthUnit = "mm";
|
|
9
11
|
this.heightUnit = "mm";
|
|
10
12
|
this.width = width;
|
|
11
13
|
this.widthMm = Math.max(0, width);
|
|
12
|
-
this.widthPx = round(this.widthMm * PIXELS_PER_MM
|
|
14
|
+
this.widthPx = round(this.widthMm * PIXELS_PER_MM);
|
|
13
15
|
this.height = height;
|
|
14
16
|
this.heightMm = Math.max(0, height);
|
|
15
|
-
this.heightPx = round(this.heightMm * PIXELS_PER_MM
|
|
17
|
+
this.heightPx = round(this.heightMm * PIXELS_PER_MM);
|
|
16
18
|
}
|
|
17
19
|
MillimeterDimensions.prototype.withSize = function (width, height) {
|
|
18
20
|
return new MillimeterDimensions(width, height);
|
|
19
21
|
};
|
|
20
22
|
MillimeterDimensions.prototype.widthPxToMm = function (px) {
|
|
21
|
-
return px / PIXELS_PER_MM
|
|
23
|
+
return px / PIXELS_PER_MM;
|
|
22
24
|
};
|
|
23
25
|
MillimeterDimensions.prototype.heightPxToMm = function (px) {
|
|
24
|
-
return px / PIXELS_PER_MM
|
|
26
|
+
return px / PIXELS_PER_MM;
|
|
25
27
|
};
|
|
26
28
|
return MillimeterDimensions;
|
|
27
29
|
}());
|
|
@@ -47,8 +49,8 @@ var PixelCanvasDimensions = /** @class */ (function () {
|
|
|
47
49
|
return PixelCanvasDimensions;
|
|
48
50
|
}());
|
|
49
51
|
|
|
50
|
-
var COLUMN_WIDTH_MM
|
|
51
|
-
var GUTTER_WIDTH_MM
|
|
52
|
+
var COLUMN_WIDTH_MM = 41;
|
|
53
|
+
var GUTTER_WIDTH_MM = 3;
|
|
52
54
|
var PIXELS_PER_MM$1 = 3.937;
|
|
53
55
|
var Print6ColCanvasDimensions = /** @class */ (function () {
|
|
54
56
|
function Print6ColCanvasDimensions(width, height) {
|
|
@@ -56,8 +58,8 @@ var Print6ColCanvasDimensions = /** @class */ (function () {
|
|
|
56
58
|
this.heightUnit = "cm";
|
|
57
59
|
this.width = width;
|
|
58
60
|
this.gutterCount = Math.max(0, width - 1);
|
|
59
|
-
this.gutterTotalMm = this.gutterCount * GUTTER_WIDTH_MM
|
|
60
|
-
this.columnsTotalMm = width * COLUMN_WIDTH_MM
|
|
61
|
+
this.gutterTotalMm = this.gutterCount * GUTTER_WIDTH_MM;
|
|
62
|
+
this.columnsTotalMm = width * COLUMN_WIDTH_MM;
|
|
61
63
|
this.widthMm = Math.max(0, this.columnsTotalMm + this.gutterTotalMm);
|
|
62
64
|
this.widthPx = round(this.widthMm * PIXELS_PER_MM$1);
|
|
63
65
|
this.height = height;
|
|
@@ -76,119 +78,110 @@ var Print6ColCanvasDimensions = /** @class */ (function () {
|
|
|
76
78
|
return Print6ColCanvasDimensions;
|
|
77
79
|
}());
|
|
78
80
|
|
|
79
|
-
var COLUMN_WIDTH_MM = 30.8772;
|
|
80
|
-
var GUTTER_WIDTH_MM = 2.1053;
|
|
81
|
-
var PIXELS_PER_MM = 3.937;
|
|
81
|
+
var COLUMN_WIDTH_MM$1 = 30.8772;
|
|
82
|
+
var GUTTER_WIDTH_MM$1 = 2.1053;
|
|
83
|
+
var PIXELS_PER_MM$2 = 3.937;
|
|
82
84
|
var Print8ColCanvasDimensions = /** @class */ (function () {
|
|
83
85
|
function Print8ColCanvasDimensions(width, height) {
|
|
84
86
|
this.widthUnit = "column(s)";
|
|
85
87
|
this.heightUnit = "cm";
|
|
86
88
|
this.width = width;
|
|
87
89
|
this.gutterCount = Math.max(0, width - 1);
|
|
88
|
-
this.gutterTotalMm = this.gutterCount * GUTTER_WIDTH_MM;
|
|
89
|
-
this.columnsTotalMm = width * COLUMN_WIDTH_MM;
|
|
90
|
+
this.gutterTotalMm = this.gutterCount * GUTTER_WIDTH_MM$1;
|
|
91
|
+
this.columnsTotalMm = width * COLUMN_WIDTH_MM$1;
|
|
90
92
|
this.widthMm = Math.max(0, this.columnsTotalMm + this.gutterTotalMm);
|
|
91
|
-
this.widthPx = round(this.widthMm * PIXELS_PER_MM);
|
|
93
|
+
this.widthPx = round(this.widthMm * PIXELS_PER_MM$2);
|
|
92
94
|
this.height = height;
|
|
93
95
|
this.heightMm = Math.max(0, height * 10);
|
|
94
|
-
this.heightPx = round(this.heightMm * PIXELS_PER_MM);
|
|
96
|
+
this.heightPx = round(this.heightMm * PIXELS_PER_MM$2);
|
|
95
97
|
}
|
|
96
98
|
Print8ColCanvasDimensions.prototype.withSize = function (width, height) {
|
|
97
99
|
return new Print8ColCanvasDimensions(width, height);
|
|
98
100
|
};
|
|
99
101
|
Print8ColCanvasDimensions.prototype.widthPxToMm = function (px) {
|
|
100
|
-
return px / PIXELS_PER_MM;
|
|
102
|
+
return px / PIXELS_PER_MM$2;
|
|
101
103
|
};
|
|
102
104
|
Print8ColCanvasDimensions.prototype.heightPxToMm = function (px) {
|
|
103
|
-
return px / PIXELS_PER_MM;
|
|
105
|
+
return px / PIXELS_PER_MM$2;
|
|
104
106
|
};
|
|
105
107
|
return Print8ColCanvasDimensions;
|
|
106
108
|
}());
|
|
107
109
|
|
|
108
|
-
|
|
109
|
-
Copyright (c) Microsoft Corporation.
|
|
110
|
-
|
|
111
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
112
|
-
purpose with or without fee is hereby granted.
|
|
113
|
-
|
|
114
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
115
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
116
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
117
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
118
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
119
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
120
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
121
|
-
***************************************************************************** */
|
|
122
|
-
/* global Reflect, Promise
|
|
123
|
-
|
|
124
|
-
var extendStatics = function(d, b) {
|
|
125
|
-
extendStatics = Object.setPrototypeOf ||
|
|
126
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
127
|
-
function (d, b) { for (var p in b) if (
|
|
128
|
-
return extendStatics(d, b);
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
function __extends(d, b) {
|
|
132
|
-
if (typeof b !== "function" && b !== null)
|
|
133
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
134
|
-
extendStatics(d, b);
|
|
135
|
-
function __() { this.constructor = d; }
|
|
136
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
140
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
141
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
142
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
143
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
144
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
145
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
function __generator(thisArg, body) {
|
|
150
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
151
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
152
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
153
|
-
function step(op) {
|
|
154
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
155
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
156
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
157
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
158
|
-
switch (op[0]) {
|
|
159
|
-
case 0: case 1: t = op; break;
|
|
160
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
161
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
162
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
163
|
-
default:
|
|
164
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
165
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
166
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
167
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
168
|
-
if (t[2]) _.ops.pop();
|
|
169
|
-
_.trys.pop(); continue;
|
|
170
|
-
}
|
|
171
|
-
op = body.call(thisArg, _);
|
|
172
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
173
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
function __spreadArray(to, from, pack) {
|
|
178
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
179
|
-
if (ar || !(i in from)) {
|
|
180
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
181
|
-
ar[i] = from[i];
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
188
|
-
var e = new Error(message);
|
|
189
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
110
|
+
/*! *****************************************************************************
|
|
111
|
+
Copyright (c) Microsoft Corporation.
|
|
112
|
+
|
|
113
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
114
|
+
purpose with or without fee is hereby granted.
|
|
115
|
+
|
|
116
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
117
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
118
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
119
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
120
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
121
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
122
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
123
|
+
***************************************************************************** */
|
|
124
|
+
/* global Reflect, Promise */
|
|
125
|
+
|
|
126
|
+
var extendStatics = function(d, b) {
|
|
127
|
+
extendStatics = Object.setPrototypeOf ||
|
|
128
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
129
|
+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
130
|
+
return extendStatics(d, b);
|
|
190
131
|
};
|
|
191
132
|
|
|
133
|
+
function __extends(d, b) {
|
|
134
|
+
extendStatics(d, b);
|
|
135
|
+
function __() { this.constructor = d; }
|
|
136
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
140
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
141
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
142
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
143
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
144
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
145
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function __generator(thisArg, body) {
|
|
150
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
151
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
152
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
153
|
+
function step(op) {
|
|
154
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
155
|
+
while (_) try {
|
|
156
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
157
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
158
|
+
switch (op[0]) {
|
|
159
|
+
case 0: case 1: t = op; break;
|
|
160
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
161
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
162
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
163
|
+
default:
|
|
164
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
165
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
166
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
167
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
168
|
+
if (t[2]) _.ops.pop();
|
|
169
|
+
_.trys.pop(); continue;
|
|
170
|
+
}
|
|
171
|
+
op = body.call(thisArg, _);
|
|
172
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
173
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function __spreadArrays() {
|
|
178
|
+
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
|
179
|
+
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
180
|
+
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
181
|
+
r[k] = a[j];
|
|
182
|
+
return r;
|
|
183
|
+
}
|
|
184
|
+
|
|
192
185
|
var Font = /** @class */ (function () {
|
|
193
186
|
function Font() {
|
|
194
187
|
}
|
|
@@ -291,64 +284,6 @@ var RedrawAllLayoutFunction = /** @class */ (function () {
|
|
|
291
284
|
return RedrawAllLayoutFunction;
|
|
292
285
|
}());
|
|
293
286
|
|
|
294
|
-
var RepositionCutoffsLayoutFunction = /** @class */ (function () {
|
|
295
|
-
function RepositionCutoffsLayoutFunction() {
|
|
296
|
-
}
|
|
297
|
-
RepositionCutoffsLayoutFunction.prototype.execute = function (canvas) {
|
|
298
|
-
canvas.getObjectsByTypeInternal(ObjectType.CUTOFF)
|
|
299
|
-
.forEach(function (cutoff) { return cutoff.updatePosition(); });
|
|
300
|
-
};
|
|
301
|
-
return RepositionCutoffsLayoutFunction;
|
|
302
|
-
}());
|
|
303
|
-
|
|
304
|
-
var RepositionBordersLayoutFunction = /** @class */ (function () {
|
|
305
|
-
function RepositionBordersLayoutFunction() {
|
|
306
|
-
}
|
|
307
|
-
RepositionBordersLayoutFunction.prototype.execute = function (canvas) {
|
|
308
|
-
canvas.getObjectsByTypeInternal(ObjectType.BORDER)
|
|
309
|
-
.forEach(function (border) { return border.updatePosition(); });
|
|
310
|
-
};
|
|
311
|
-
return RepositionBordersLayoutFunction;
|
|
312
|
-
}());
|
|
313
|
-
|
|
314
|
-
var PinToBottomLayoutFunction = /** @class */ (function () {
|
|
315
|
-
function PinToBottomLayoutFunction() {
|
|
316
|
-
}
|
|
317
|
-
PinToBottomLayoutFunction.prototype.execute = function (canvas) {
|
|
318
|
-
canvas.getObjectsInternal()
|
|
319
|
-
.forEach(function (object) { return object.moveToPinnedPosition(); });
|
|
320
|
-
};
|
|
321
|
-
return PinToBottomLayoutFunction;
|
|
322
|
-
}());
|
|
323
|
-
|
|
324
|
-
var ResizeCanvasLayoutFunction = /** @class */ (function () {
|
|
325
|
-
function ResizeCanvasLayoutFunction() {
|
|
326
|
-
}
|
|
327
|
-
ResizeCanvasLayoutFunction.prototype.execute = function (canvas) {
|
|
328
|
-
var _a, _b;
|
|
329
|
-
if (canvas.getLayoutManager().isEnforcedPositioning)
|
|
330
|
-
return;
|
|
331
|
-
if ((_b = (_a = canvas === null || canvas === void 0 ? void 0 : canvas.getDimensionsRestrictions()) === null || _a === void 0 ? void 0 : _a.fixed) !== null && _b !== void 0 ? _b : false)
|
|
332
|
-
return;
|
|
333
|
-
var currentDimensions = canvas.getDimensions();
|
|
334
|
-
var baseDimensions = canvas.getBaseDimensions();
|
|
335
|
-
var textHeightIncreasePx = _(canvas.getObjectsByTypeInternal(ObjectType.TEXT))
|
|
336
|
-
.filter(function (text) { return text.isResizeCanvas(); })
|
|
337
|
-
.reduce(function (x, text) { return x + text.getSizeIncreaseSinceCreation(); }, 0);
|
|
338
|
-
var increase = baseDimensions.withSize(currentDimensions.width, 0);
|
|
339
|
-
while (increase.heightPx < textHeightIncreasePx) {
|
|
340
|
-
increase = increase.withSize(increase.width, increase.height + 1);
|
|
341
|
-
}
|
|
342
|
-
var targetHeight = increase.withSize(increase.width, baseDimensions.height + increase.height);
|
|
343
|
-
if (currentDimensions.height !== targetHeight.height) {
|
|
344
|
-
canvas.setDimensions(targetHeight);
|
|
345
|
-
}
|
|
346
|
-
canvas.getObjectsInternal().forEach(function (object) { return object.setCoords(); });
|
|
347
|
-
canvas.redraw();
|
|
348
|
-
};
|
|
349
|
-
return ResizeCanvasLayoutFunction;
|
|
350
|
-
}());
|
|
351
|
-
|
|
352
287
|
var LayoutManager;
|
|
353
288
|
(function (LayoutManager) {
|
|
354
289
|
LayoutManager["LEGACY"] = "LEGACY";
|
|
@@ -356,45 +291,6 @@ var LayoutManager;
|
|
|
356
291
|
LayoutManager["ADVANCED"] = "ADVANCED";
|
|
357
292
|
})(LayoutManager || (LayoutManager = {}));
|
|
358
293
|
|
|
359
|
-
var RepositionBackgroundsLayoutFunction = /** @class */ (function () {
|
|
360
|
-
function RepositionBackgroundsLayoutFunction() {
|
|
361
|
-
}
|
|
362
|
-
RepositionBackgroundsLayoutFunction.prototype.execute = function (canvas) {
|
|
363
|
-
canvas.getObjectsByTypeInternal(ObjectType.BACKGROUND_IMAGE)
|
|
364
|
-
.forEach(function (border) { return border.updatePosition(); });
|
|
365
|
-
};
|
|
366
|
-
return RepositionBackgroundsLayoutFunction;
|
|
367
|
-
}());
|
|
368
|
-
|
|
369
|
-
var AdvancedLayoutManager = /** @class */ (function (_super) {
|
|
370
|
-
__extends(AdvancedLayoutManager, _super);
|
|
371
|
-
function AdvancedLayoutManager(canvas) {
|
|
372
|
-
var _this = _super.call(this, canvas) || this;
|
|
373
|
-
_this.key = LayoutManager.ADVANCED;
|
|
374
|
-
_this.pinToBottom = new PinToBottomLayoutFunction();
|
|
375
|
-
_this.redrawAll = new RedrawAllLayoutFunction();
|
|
376
|
-
_this.repositionBorders = new RepositionBordersLayoutFunction();
|
|
377
|
-
_this.repositionCutoffs = new RepositionCutoffsLayoutFunction();
|
|
378
|
-
_this.repositionBackgrounds = new RepositionBackgroundsLayoutFunction();
|
|
379
|
-
_this.resizeCanvas = new ResizeCanvasLayoutFunction();
|
|
380
|
-
return _this;
|
|
381
|
-
}
|
|
382
|
-
AdvancedLayoutManager.prototype.onCanvasDimensionsChange = function () {
|
|
383
|
-
this.pinToBottom.execute(this.canvas);
|
|
384
|
-
this.repositionCutoffs.execute(this.canvas);
|
|
385
|
-
this.repositionBorders.execute(this.canvas);
|
|
386
|
-
this.repositionBackgrounds.execute(this.canvas);
|
|
387
|
-
this.redrawAll.execute(this.canvas);
|
|
388
|
-
};
|
|
389
|
-
AdvancedLayoutManager.prototype.onTextChange = function () {
|
|
390
|
-
this.resizeCanvas.execute(this.canvas);
|
|
391
|
-
};
|
|
392
|
-
AdvancedLayoutManager.prototype.onObjectListChange = function () {
|
|
393
|
-
this.redrawAll.execute(this.canvas);
|
|
394
|
-
};
|
|
395
|
-
return AdvancedLayoutManager;
|
|
396
|
-
}(AbstractLayoutManager));
|
|
397
|
-
|
|
398
294
|
var UpdateObjectDimensionsLayoutFunction = /** @class */ (function () {
|
|
399
295
|
function UpdateObjectDimensionsLayoutFunction() {
|
|
400
296
|
}
|
|
@@ -436,14 +332,13 @@ var StackObjectsLayoutFunction = /** @class */ (function () {
|
|
|
436
332
|
var currentColumnWidthPercent = 0;
|
|
437
333
|
each(footerRows.rows, function (row) {
|
|
438
334
|
each(row.objects, function (object) {
|
|
439
|
-
var _a, _b, _c;
|
|
440
335
|
var columnOffset = currentColumnWidthPercent / 100 * layoutAreaWidth;
|
|
441
|
-
var objectMargin = (
|
|
336
|
+
var objectMargin = oc(object.getMargin()).left(0);
|
|
442
337
|
var left = canvasMargin.left + columnOffset + objectMargin;
|
|
443
338
|
if (object.getType() === ObjectType.VERTICAL_RULE)
|
|
444
339
|
object.setPosition({ height: row.height });
|
|
445
340
|
object.setPosition({
|
|
446
|
-
top: nextObjectTop + (
|
|
341
|
+
top: nextObjectTop + oc(object.getMargin()).top(0),
|
|
447
342
|
left: left
|
|
448
343
|
});
|
|
449
344
|
currentColumnWidthPercent += object.getColumnWidthPercent();
|
|
@@ -453,7 +348,6 @@ var StackObjectsLayoutFunction = /** @class */ (function () {
|
|
|
453
348
|
});
|
|
454
349
|
};
|
|
455
350
|
StackObjectsLayoutFunction.prototype.layoutBody = function (bodyRows, canvas, footerHeight) {
|
|
456
|
-
var _a, _b, _c, _d;
|
|
457
351
|
var canvasDimensions = canvas.getDimensions();
|
|
458
352
|
var canvasMargin = canvas.getMargin();
|
|
459
353
|
var workableWidth = canvasDimensions.widthPx - canvasMargin.left - canvasMargin.right;
|
|
@@ -466,10 +360,10 @@ var StackObjectsLayoutFunction = /** @class */ (function () {
|
|
|
466
360
|
for (var i = 0; i < bodyRows.rows.length; i++) {
|
|
467
361
|
var row = bodyRows.rows[i];
|
|
468
362
|
var nextRow = bodyRows.rows[i + 1];
|
|
469
|
-
for (var _i = 0,
|
|
470
|
-
var object =
|
|
363
|
+
for (var _i = 0, _a = row.objects; _i < _a.length; _i++) {
|
|
364
|
+
var object = _a[_i];
|
|
471
365
|
var columnOffset = currentColumnWidthPercent / 100 * workableWidth;
|
|
472
|
-
var objectMargin = (
|
|
366
|
+
var objectMargin = oc(object.getMargin()).left(0);
|
|
473
367
|
var objectLeft = canvasMargin.left + columnOffset + objectMargin;
|
|
474
368
|
if (object.getType() === ObjectType.TEXT && object.isBulleted())
|
|
475
369
|
objectLeft += object.getBulletMargin();
|
|
@@ -478,7 +372,7 @@ var StackObjectsLayoutFunction = /** @class */ (function () {
|
|
|
478
372
|
if (object.getType() === ObjectType.VERTICAL_RULE)
|
|
479
373
|
return;
|
|
480
374
|
object.setPosition({
|
|
481
|
-
top: nextObjectTop + (
|
|
375
|
+
top: nextObjectTop + oc(object.getMargin()).top(0),
|
|
482
376
|
left: objectLeft
|
|
483
377
|
});
|
|
484
378
|
currentColumnWidthPercent += object.getColumnWidthPercent();
|
|
@@ -486,7 +380,7 @@ var StackObjectsLayoutFunction = /** @class */ (function () {
|
|
|
486
380
|
currentColumnWidthPercent = 0;
|
|
487
381
|
nextObjectTop += row.height;
|
|
488
382
|
var thisRowIsHR = row.objects.length === 1 && row.objects[0].getType() === ObjectType.HORIZONTAL_RULE;
|
|
489
|
-
var nextRowIsHR = (
|
|
383
|
+
var nextRowIsHR = oc(nextRow).objects.length() === 1 && oc(nextRow).objects()[0].getType() === ObjectType.HORIZONTAL_RULE;
|
|
490
384
|
if (!thisRowIsHR && !nextRowIsHR) {
|
|
491
385
|
nextObjectTop += spaceSize;
|
|
492
386
|
}
|
|
@@ -494,9 +388,8 @@ var StackObjectsLayoutFunction = /** @class */ (function () {
|
|
|
494
388
|
};
|
|
495
389
|
StackObjectsLayoutFunction.prototype.applyWidths = function (objects, layoutWidth) {
|
|
496
390
|
_(objects).forEach(function (object) {
|
|
497
|
-
var _a, _b;
|
|
498
391
|
var targetWidth = object.getColumnWidthPercent() / 100 * layoutWidth;
|
|
499
|
-
var actualWidth = targetWidth - (
|
|
392
|
+
var actualWidth = targetWidth - oc(object.getMargin()).left(0) - oc(object.getMargin()).right(0);
|
|
500
393
|
if (object.getType() === ObjectType.VERTICAL_RULE)
|
|
501
394
|
return;
|
|
502
395
|
if (object.getType() === ObjectType.TEXT && object.isBulleted())
|
|
@@ -510,11 +403,10 @@ var StackObjectsLayoutFunction = /** @class */ (function () {
|
|
|
510
403
|
});
|
|
511
404
|
};
|
|
512
405
|
StackObjectsLayoutFunction.prototype.adjustCanvasSize = function (canvas, requiredHeight) {
|
|
513
|
-
|
|
514
|
-
if ((_a = canvas === null || canvas === void 0 ? void 0 : canvas.getDimensionsRestrictions()) === null || _a === void 0 ? void 0 : _a.fixed)
|
|
406
|
+
if (oc(canvas.getDimensionsRestrictions()).fixed(false))
|
|
515
407
|
return;
|
|
516
408
|
var dimensions = canvas.getDimensions();
|
|
517
|
-
var minHeight = (
|
|
409
|
+
var minHeight = oc(canvas.getDimensionsRestrictions()).height.min(MIN_MAGNITUDE);
|
|
518
410
|
var targetDimensions = canvas.getDimensions().withSize(dimensions.width, minHeight);
|
|
519
411
|
while (targetDimensions.heightPx < requiredHeight) {
|
|
520
412
|
targetDimensions = targetDimensions.withSize(dimensions.width, targetDimensions.height + 1);
|
|
@@ -547,19 +439,17 @@ var StackObjectsLayoutFunction = /** @class */ (function () {
|
|
|
547
439
|
return result;
|
|
548
440
|
};
|
|
549
441
|
StackObjectsLayoutFunction.prototype.getObjectHeight = function (element) {
|
|
550
|
-
var _a, _b;
|
|
551
442
|
return element.getBoundingBox().height
|
|
552
|
-
+ (
|
|
553
|
-
+ (
|
|
443
|
+
+ oc(element.getMargin()).top(0)
|
|
444
|
+
+ oc(element.getMargin()).bottom(0);
|
|
554
445
|
};
|
|
555
446
|
StackObjectsLayoutFunction.prototype.countSpaces = function (rows) {
|
|
556
|
-
var _a, _b;
|
|
557
447
|
var count = 0;
|
|
558
448
|
for (var i = 0; i < rows.rows.length - 1; i++) {
|
|
559
449
|
var row = rows.rows[i];
|
|
560
450
|
var nextRow = rows.rows[i + 1];
|
|
561
451
|
var thisRowIsHR = row.objects.length === 1 && row.objects[0].getType() === ObjectType.HORIZONTAL_RULE;
|
|
562
|
-
var nextRowIsHR = (
|
|
452
|
+
var nextRowIsHR = oc(nextRow).objects.length() === 1 && oc(nextRow).objects()[0].getType() === ObjectType.HORIZONTAL_RULE;
|
|
563
453
|
if (!thisRowIsHR && !nextRowIsHR) {
|
|
564
454
|
count++;
|
|
565
455
|
}
|
|
@@ -569,6 +459,26 @@ var StackObjectsLayoutFunction = /** @class */ (function () {
|
|
|
569
459
|
return StackObjectsLayoutFunction;
|
|
570
460
|
}());
|
|
571
461
|
|
|
462
|
+
var RepositionBordersLayoutFunction = /** @class */ (function () {
|
|
463
|
+
function RepositionBordersLayoutFunction() {
|
|
464
|
+
}
|
|
465
|
+
RepositionBordersLayoutFunction.prototype.execute = function (canvas) {
|
|
466
|
+
canvas.getObjectsByTypeInternal(ObjectType.BORDER)
|
|
467
|
+
.forEach(function (border) { return border.updatePosition(); });
|
|
468
|
+
};
|
|
469
|
+
return RepositionBordersLayoutFunction;
|
|
470
|
+
}());
|
|
471
|
+
|
|
472
|
+
var RepositionBackgroundsLayoutFunction = /** @class */ (function () {
|
|
473
|
+
function RepositionBackgroundsLayoutFunction() {
|
|
474
|
+
}
|
|
475
|
+
RepositionBackgroundsLayoutFunction.prototype.execute = function (canvas) {
|
|
476
|
+
canvas.getObjectsByTypeInternal(ObjectType.BACKGROUND_IMAGE)
|
|
477
|
+
.forEach(function (border) { return border.updatePosition(); });
|
|
478
|
+
};
|
|
479
|
+
return RepositionBackgroundsLayoutFunction;
|
|
480
|
+
}());
|
|
481
|
+
|
|
572
482
|
var StandardLayoutManager = /** @class */ (function (_super) {
|
|
573
483
|
__extends(StandardLayoutManager, _super);
|
|
574
484
|
function StandardLayoutManager(canvas) {
|
|
@@ -801,15 +711,14 @@ var AbstractCanvasObject = /** @class */ (function () {
|
|
|
801
711
|
* @inheritDoc
|
|
802
712
|
*/
|
|
803
713
|
AbstractCanvasObject.prototype.setMargin = function (margin) {
|
|
804
|
-
var _a, _b;
|
|
805
714
|
if (!margin)
|
|
806
715
|
return;
|
|
807
|
-
var newMargin = (
|
|
716
|
+
var newMargin = oc(this.data).margin({
|
|
808
717
|
top: 0,
|
|
809
718
|
right: 0,
|
|
810
719
|
bottom: 0,
|
|
811
720
|
left: 0
|
|
812
|
-
};
|
|
721
|
+
});
|
|
813
722
|
if (margin.top != undefined)
|
|
814
723
|
newMargin.top = margin.top || 0;
|
|
815
724
|
if (margin.right != undefined)
|
|
@@ -826,8 +735,7 @@ var AbstractCanvasObject = /** @class */ (function () {
|
|
|
826
735
|
* @inheritDoc
|
|
827
736
|
*/
|
|
828
737
|
AbstractCanvasObject.prototype.getColumnWidthPercent = function () {
|
|
829
|
-
|
|
830
|
-
return Math.max(Math.min((_b = (_a = this.data) === null || _a === void 0 ? void 0 : _a.columnWidthPercent) !== null && _b !== void 0 ? _b : 100, 100), 0);
|
|
738
|
+
return Math.max(Math.min(oc(this.data).columnWidthPercent(100), 100), 0);
|
|
831
739
|
};
|
|
832
740
|
/**
|
|
833
741
|
* @override
|
|
@@ -1909,20 +1817,6 @@ var RichText = /** @class */ (function (_super) {
|
|
|
1909
1817
|
return RichText;
|
|
1910
1818
|
}(Image));
|
|
1911
1819
|
|
|
1912
|
-
var ObjectType;
|
|
1913
|
-
(function (ObjectType) {
|
|
1914
|
-
ObjectType["TEXT"] = "TEXT";
|
|
1915
|
-
ObjectType["BORDER"] = "BORDER";
|
|
1916
|
-
ObjectType["IMAGE"] = "IMAGE";
|
|
1917
|
-
ObjectType["RECTANGLE"] = "RECTANGLE";
|
|
1918
|
-
ObjectType["LIBRARY_IMAGE"] = "LIBRARY_IMAGE";
|
|
1919
|
-
ObjectType["CUTOFF"] = "CUTOFF";
|
|
1920
|
-
ObjectType["VERTICAL_RULE"] = "VERTICAL_RULE";
|
|
1921
|
-
ObjectType["HORIZONTAL_RULE"] = "HORIZONTAL_RULE";
|
|
1922
|
-
ObjectType["RICH_TEXT"] = "RICH_TEXT";
|
|
1923
|
-
ObjectType["BACKGROUND_IMAGE"] = "BACKGROUND_IMAGE";
|
|
1924
|
-
})(ObjectType || (ObjectType = {}));
|
|
1925
|
-
|
|
1926
1820
|
var Text = /** @class */ (function (_super) {
|
|
1927
1821
|
__extends(Text, _super);
|
|
1928
1822
|
function Text(canvas, fabricObject, persistedField) {
|
|
@@ -2090,7 +1984,7 @@ var Text = /** @class */ (function (_super) {
|
|
|
2090
1984
|
Text.prototype.setBoldRegion = function (start, end, bold) {
|
|
2091
1985
|
if (bold === void 0) { bold = true; }
|
|
2092
1986
|
if (start > end)
|
|
2093
|
-
throw Error("Bad region specified: ["
|
|
1987
|
+
throw Error("Bad region specified: [" + start + " - " + end + "]");
|
|
2094
1988
|
for (var i = start; i < end; i++) {
|
|
2095
1989
|
var style = this.fabricObject.getStyleAtPosition(i, true);
|
|
2096
1990
|
var font = this.fontLibrary.getFont(style.fontFamily);
|
|
@@ -2121,7 +2015,7 @@ var Text = /** @class */ (function (_super) {
|
|
|
2121
2015
|
Text.prototype.setItalicRegion = function (start, end, italic) {
|
|
2122
2016
|
if (italic === void 0) { italic = true; }
|
|
2123
2017
|
if (start > end)
|
|
2124
|
-
throw Error("Bad region specified: ["
|
|
2018
|
+
throw Error("Bad region specified: [" + start + " - " + end + "]");
|
|
2125
2019
|
this.fabricObject.setSelectionStyles({ fontStyle: italic ? "italic" : "" }, start, end);
|
|
2126
2020
|
this.redraw();
|
|
2127
2021
|
};
|
|
@@ -2272,7 +2166,7 @@ var Text = /** @class */ (function (_super) {
|
|
|
2272
2166
|
if (!this.isBulleted())
|
|
2273
2167
|
return 0;
|
|
2274
2168
|
var fontSize = 0;
|
|
2275
|
-
|
|
2169
|
+
each(this.fabricObject._textLines, function (textLine, lineIndex) {
|
|
2276
2170
|
fontSize = Math.max(fontSize, _this_1.fabricObject.getValueOfPropertyAt(lineIndex, 0, "fontSize"));
|
|
2277
2171
|
});
|
|
2278
2172
|
return fontSize * 0.6;
|
|
@@ -2420,7 +2314,7 @@ var Text = /** @class */ (function (_super) {
|
|
|
2420
2314
|
if (this.data.bulleted) {
|
|
2421
2315
|
var bullets = this.fabricObject["_bullets"];
|
|
2422
2316
|
delete this.fabricObject["_bullets"];
|
|
2423
|
-
|
|
2317
|
+
each(bullets, function (bullet) { return _this_1.canvas.removeFabricObject(bullet); });
|
|
2424
2318
|
this.fabricObject["objectCaching"] = true;
|
|
2425
2319
|
}
|
|
2426
2320
|
};
|
|
@@ -2429,7 +2323,7 @@ var Text = /** @class */ (function (_super) {
|
|
|
2429
2323
|
if (this.fabricObject._isOrderedList) {
|
|
2430
2324
|
var markerEntities = this.fabricObject._orderedListMarkerEntities;
|
|
2431
2325
|
delete this.fabricObject._orderedListMarkerEntities;
|
|
2432
|
-
|
|
2326
|
+
each(markerEntities, function (marker) { return _this_1.canvas.removeFabricObject(marker); });
|
|
2433
2327
|
this.fabricObject["objectCaching"] = true;
|
|
2434
2328
|
}
|
|
2435
2329
|
};
|
|
@@ -2447,7 +2341,7 @@ var Text = /** @class */ (function (_super) {
|
|
|
2447
2341
|
// Determine list of active bullets
|
|
2448
2342
|
var currentBullets_1 = fabricText["_bullets"];
|
|
2449
2343
|
var activeBullets_1 = {};
|
|
2450
|
-
|
|
2344
|
+
each(fabricText._textLines, function (textLine, lineIndex) {
|
|
2451
2345
|
if (textLine.length) {
|
|
2452
2346
|
// Start of real lines will have offset 0 in styleMap
|
|
2453
2347
|
var styleMap = fabricText._styleMap[lineIndex];
|
|
@@ -2481,13 +2375,13 @@ var Text = /** @class */ (function (_super) {
|
|
|
2481
2375
|
var canvas_1 = fabricText.canvas;
|
|
2482
2376
|
var canvasDirty_1 = false;
|
|
2483
2377
|
canvas_1.renderOnAddRemove = false;
|
|
2484
|
-
|
|
2378
|
+
each(activeBullets_1, function (bullet) {
|
|
2485
2379
|
if (!canvas_1.contains(bullet)) {
|
|
2486
2380
|
canvas_1.add(bullet);
|
|
2487
2381
|
canvasDirty_1 = true;
|
|
2488
2382
|
}
|
|
2489
2383
|
});
|
|
2490
|
-
|
|
2384
|
+
each(currentBullets_1, function (bullet, key) {
|
|
2491
2385
|
if (!activeBullets_1[key]) {
|
|
2492
2386
|
canvas_1.remove(bullet);
|
|
2493
2387
|
canvasDirty_1 = true;
|
|
@@ -2503,7 +2397,7 @@ var Text = /** @class */ (function (_super) {
|
|
|
2503
2397
|
if (fabricText._isOrderedList) {
|
|
2504
2398
|
var existingMarkers_1 = fabricText._orderedListMarkerEntities || [];
|
|
2505
2399
|
var activeMarkers_1 = [];
|
|
2506
|
-
|
|
2400
|
+
each(fabricText._textLines, function (textLine, lineIndex) {
|
|
2507
2401
|
if (textLine.length) {
|
|
2508
2402
|
// Start of real lines will have offset 0 in styleMap
|
|
2509
2403
|
var styleMap = fabricText._styleMap[lineIndex];
|
|
@@ -2514,7 +2408,7 @@ var Text = /** @class */ (function (_super) {
|
|
|
2514
2408
|
}
|
|
2515
2409
|
else {
|
|
2516
2410
|
// Create new marker for this line
|
|
2517
|
-
var textbox = new fabric.Textbox(
|
|
2411
|
+
var textbox = new fabric.Textbox(lineIndex + ".", {
|
|
2518
2412
|
left: 0,
|
|
2519
2413
|
top: 0,
|
|
2520
2414
|
fill: fabricText.fill,
|
|
@@ -2536,7 +2430,7 @@ var Text = /** @class */ (function (_super) {
|
|
|
2536
2430
|
var canvas_2 = fabricText.canvas;
|
|
2537
2431
|
var canvasDirty_2 = false;
|
|
2538
2432
|
canvas_2.renderOnAddRemove = false;
|
|
2539
|
-
|
|
2433
|
+
each(activeMarkers_1, function (marker) {
|
|
2540
2434
|
if (!marker)
|
|
2541
2435
|
return;
|
|
2542
2436
|
if (!canvas_2.contains(marker)) {
|
|
@@ -2544,7 +2438,7 @@ var Text = /** @class */ (function (_super) {
|
|
|
2544
2438
|
canvasDirty_2 = true;
|
|
2545
2439
|
}
|
|
2546
2440
|
});
|
|
2547
|
-
|
|
2441
|
+
each(existingMarkers_1, function (marker, key) {
|
|
2548
2442
|
if (!marker)
|
|
2549
2443
|
return;
|
|
2550
2444
|
if (!activeMarkers_1[key]) {
|
|
@@ -2613,7 +2507,7 @@ var Text = /** @class */ (function (_super) {
|
|
|
2613
2507
|
left: fabricText.left + xOffset,
|
|
2614
2508
|
top: fabricText.top + yOffset,
|
|
2615
2509
|
angle: fabricText.angle,
|
|
2616
|
-
text:
|
|
2510
|
+
text: lineNumber + "."
|
|
2617
2511
|
});
|
|
2618
2512
|
}
|
|
2619
2513
|
originalRenderTextLine.apply(fabricText, [method, ctx, line, left, top, lineIndex]);
|
|
@@ -2832,6 +2726,20 @@ var ImageType;
|
|
|
2832
2726
|
ImageType["PHOTO"] = "PHOTO";
|
|
2833
2727
|
})(ImageType || (ImageType = {}));
|
|
2834
2728
|
|
|
2729
|
+
var ObjectType;
|
|
2730
|
+
(function (ObjectType) {
|
|
2731
|
+
ObjectType["TEXT"] = "TEXT";
|
|
2732
|
+
ObjectType["BORDER"] = "BORDER";
|
|
2733
|
+
ObjectType["IMAGE"] = "IMAGE";
|
|
2734
|
+
ObjectType["RECTANGLE"] = "RECTANGLE";
|
|
2735
|
+
ObjectType["LIBRARY_IMAGE"] = "LIBRARY_IMAGE";
|
|
2736
|
+
ObjectType["CUTOFF"] = "CUTOFF";
|
|
2737
|
+
ObjectType["VERTICAL_RULE"] = "VERTICAL_RULE";
|
|
2738
|
+
ObjectType["HORIZONTAL_RULE"] = "HORIZONTAL_RULE";
|
|
2739
|
+
ObjectType["RICH_TEXT"] = "RICH_TEXT";
|
|
2740
|
+
ObjectType["BACKGROUND_IMAGE"] = "BACKGROUND_IMAGE";
|
|
2741
|
+
})(ObjectType || (ObjectType = {}));
|
|
2742
|
+
|
|
2835
2743
|
var AbstractInteractiveCanvas = /** @class */ (function () {
|
|
2836
2744
|
function AbstractInteractiveCanvas(fabric, fabricCanvas, devicePixelRatio) {
|
|
2837
2745
|
this.fabric = fabric;
|
|
@@ -3013,12 +2921,11 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
|
|
|
3013
2921
|
* @inheritDoc
|
|
3014
2922
|
*/
|
|
3015
2923
|
AbstractInteractiveCanvas.prototype.setDimensionRestrictions = function (restrictions) {
|
|
3016
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
3017
2924
|
this.dimensionRestrictions$.next(restrictions);
|
|
3018
2925
|
var dimensions = this.getDimensions();
|
|
3019
2926
|
if (this.dimensionsExceedRestrictions(dimensions)) {
|
|
3020
2927
|
var newDimensions = dimensions
|
|
3021
|
-
.withSize(Math.min(Math.max((
|
|
2928
|
+
.withSize(Math.min(Math.max(oc(restrictions).width.min(dimensions.width), dimensions.width), Math.max(oc(restrictions).width.max(dimensions.width))), Math.min(Math.max(oc(restrictions).height.min(dimensions.height), dimensions.height), Math.max(oc(restrictions).height.max(dimensions.height))));
|
|
3022
2929
|
this.setBaseDimensions(newDimensions);
|
|
3023
2930
|
}
|
|
3024
2931
|
};
|
|
@@ -3435,7 +3342,7 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
|
|
|
3435
3342
|
var objectsToLayout = _(this.getObjectsByTypesInternal(ObjectType.TEXT, ObjectType.IMAGE))
|
|
3436
3343
|
.sortBy(function (x) { return x.getBoundingBox().top; })
|
|
3437
3344
|
.value();
|
|
3438
|
-
var objectsHeight =
|
|
3345
|
+
var objectsHeight = reduce(objectsToLayout, function (total, element) { return total + element.getBoundingBox().height; }, 0);
|
|
3439
3346
|
var workableHeight = canvasHeight - margin.top - margin.bottom;
|
|
3440
3347
|
var requiredPadding = workableHeight - objectsHeight;
|
|
3441
3348
|
var spaceBetween = requiredPadding / (objectsToLayout.length - 1);
|
|
@@ -3609,7 +3516,7 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
|
|
|
3609
3516
|
if (activeObject) {
|
|
3610
3517
|
this.fabricCanvas.setActiveObject(activeObject);
|
|
3611
3518
|
}
|
|
3612
|
-
return
|
|
3519
|
+
return replace(base64, /^data:.*;base64,/, "");
|
|
3613
3520
|
};
|
|
3614
3521
|
/**
|
|
3615
3522
|
* @override
|
|
@@ -3731,20 +3638,20 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
|
|
|
3731
3638
|
case ObjectType.BACKGROUND_IMAGE:
|
|
3732
3639
|
return new BackgroundImage(this, fabricObject, persistedField);
|
|
3733
3640
|
default:
|
|
3734
|
-
throw new Error("Unknown field type: ["
|
|
3641
|
+
throw new Error("Unknown field type: [" + persistedField.type + "]");
|
|
3735
3642
|
}
|
|
3736
3643
|
};
|
|
3737
3644
|
AbstractInteractiveCanvas.prototype.findFabricObject = function (id) {
|
|
3738
3645
|
var objects = this.fabricCanvas.getObjects();
|
|
3739
|
-
var fabricObject =
|
|
3646
|
+
var fabricObject = find(objects, function (o) { return o.id == id; });
|
|
3740
3647
|
if (!fabricObject) {
|
|
3741
|
-
throw new Error("Cannot find fabric object with id ["
|
|
3648
|
+
throw new Error("Cannot find fabric object with id [" + id + "]");
|
|
3742
3649
|
}
|
|
3743
3650
|
return fabricObject;
|
|
3744
3651
|
};
|
|
3745
3652
|
AbstractInteractiveCanvas.prototype.findObject = function (id) {
|
|
3746
3653
|
//Don't use strict compare here. fabric ids are numbers while ad builder ids are strings... mostly.
|
|
3747
|
-
return
|
|
3654
|
+
return find(this.objects$.value, function (object) { return object.getId() == id; });
|
|
3748
3655
|
};
|
|
3749
3656
|
/**
|
|
3750
3657
|
* Reset zoom and canvas dimensions to 1:1 scale, execute a function, then return the canvas to
|
|
@@ -3782,7 +3689,7 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
|
|
|
3782
3689
|
if (!object) {
|
|
3783
3690
|
return null;
|
|
3784
3691
|
}
|
|
3785
|
-
return
|
|
3692
|
+
return find(this.objects$.value, function (field) { return field.getId() == object.id; });
|
|
3786
3693
|
};
|
|
3787
3694
|
AbstractInteractiveCanvas.prototype.getFieldsByCanvasObject = function (objects) {
|
|
3788
3695
|
var _this = this;
|
|
@@ -3794,7 +3701,7 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
|
|
|
3794
3701
|
AbstractInteractiveCanvas.prototype.calculateImageCaptureCoefficient = function () {
|
|
3795
3702
|
var precision = 3;
|
|
3796
3703
|
var devicePixelRatio = this.devicePixelRatio || 1;
|
|
3797
|
-
return
|
|
3704
|
+
return round(2 / devicePixelRatio, precision);
|
|
3798
3705
|
};
|
|
3799
3706
|
AbstractInteractiveCanvas.prototype.randomId = function () {
|
|
3800
3707
|
var min = 0;
|
|
@@ -3809,17 +3716,16 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
|
|
|
3809
3716
|
.reduce(function (x, y) { return Math.max(x, y); }, 0);
|
|
3810
3717
|
};
|
|
3811
3718
|
AbstractInteractiveCanvas.prototype.trackNewObject = function (object) {
|
|
3812
|
-
this.objects$.next(
|
|
3719
|
+
this.objects$.next(__spreadArrays(this.objects$.value, [object]));
|
|
3813
3720
|
};
|
|
3814
3721
|
AbstractInteractiveCanvas.prototype.dimensionsExceedRestrictions = function (dimensions) {
|
|
3815
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
3816
3722
|
var restrictions = this.dimensionRestrictions$.value;
|
|
3817
|
-
return (
|
|
3818
|
-
|| (
|
|
3819
|
-
|| (
|
|
3820
|
-
|| (
|
|
3821
|
-
|| (
|
|
3822
|
-
|| (
|
|
3723
|
+
return oc(restrictions).height.min() != undefined && dimensions.height < oc(restrictions).height.min()
|
|
3724
|
+
|| oc(restrictions).height.max() != undefined && dimensions.height > oc(restrictions).height.max()
|
|
3725
|
+
|| oc(restrictions).width.min() != undefined && dimensions.width < oc(restrictions).width.min()
|
|
3726
|
+
|| oc(restrictions).width.max() != undefined && dimensions.width > oc(restrictions).width.max()
|
|
3727
|
+
|| oc(restrictions).volume.min() != undefined && dimensions.height * dimensions.width < oc(restrictions).volume.min()
|
|
3728
|
+
|| oc(restrictions).volume.max() != undefined && dimensions.height * dimensions.width > oc(restrictions).volume.max();
|
|
3823
3729
|
};
|
|
3824
3730
|
return AbstractInteractiveCanvas;
|
|
3825
3731
|
}());
|
|
@@ -3831,11 +3737,7 @@ var SelectionData = /** @class */ (function () {
|
|
|
3831
3737
|
this.isText = selectedObject
|
|
3832
3738
|
&& selectedObject.getType() === ObjectType.TEXT
|
|
3833
3739
|
&& selectedObject.isEditing();
|
|
3834
|
-
this.event = {};
|
|
3835
3740
|
}
|
|
3836
|
-
SelectionData.prototype.setEvent = function (event) {
|
|
3837
|
-
this.event = event;
|
|
3838
|
-
};
|
|
3839
3741
|
return SelectionData;
|
|
3840
3742
|
}());
|
|
3841
3743
|
|
|
@@ -3947,9 +3849,9 @@ var InteractiveCanvas = /** @class */ (function (_super) {
|
|
|
3947
3849
|
_this.headless = false;
|
|
3948
3850
|
_this.undoStack = new UndoStack(_this);
|
|
3949
3851
|
//Initialize watchers
|
|
3950
|
-
_this.fabricCanvas.on("selection:updated", function (
|
|
3951
|
-
_this.fabricCanvas.on("selection:created", function (
|
|
3952
|
-
_this.fabricCanvas.on("selection:cleared", function (
|
|
3852
|
+
_this.fabricCanvas.on("selection:updated", function () { return _this.onFabricSelectionChanged(); });
|
|
3853
|
+
_this.fabricCanvas.on("selection:created", function () { return _this.onFabricSelectionChanged(); });
|
|
3854
|
+
_this.fabricCanvas.on("selection:cleared", function () { return _this.onFabricSelectionChanged(); });
|
|
3953
3855
|
_this.fabricCanvas.on("text:editing:entered", function () { return _this.onTextEditing(); });
|
|
3954
3856
|
_this.fabricCanvas.on("text:editing:exited", function () { return _this.onTextEditing(); });
|
|
3955
3857
|
_this.fabricCanvas.on("text:changed", function () { return _this.onTextChange(); });
|
|
@@ -3994,11 +3896,9 @@ var InteractiveCanvas = /** @class */ (function (_super) {
|
|
|
3994
3896
|
});
|
|
3995
3897
|
});
|
|
3996
3898
|
};
|
|
3997
|
-
InteractiveCanvas.prototype.onFabricSelectionChanged = function (
|
|
3899
|
+
InteractiveCanvas.prototype.onFabricSelectionChanged = function () {
|
|
3998
3900
|
var selected = this.getFieldsByCanvasObject(this.fabricCanvas.getActiveObjects());
|
|
3999
|
-
|
|
4000
|
-
selection.setEvent(event);
|
|
4001
|
-
this.selection$.next(selection);
|
|
3901
|
+
this.selection$.next(new SelectionData(selected));
|
|
4002
3902
|
this.enterTextSelectionModeIfRequired();
|
|
4003
3903
|
};
|
|
4004
3904
|
InteractiveCanvas.prototype.enterTextSelectionModeIfRequired = function () {
|
|
@@ -4016,4 +3916,80 @@ var InteractiveCanvas = /** @class */ (function (_super) {
|
|
|
4016
3916
|
return InteractiveCanvas;
|
|
4017
3917
|
}(AbstractInteractiveCanvas));
|
|
4018
3918
|
|
|
3919
|
+
var RepositionCutoffsLayoutFunction = /** @class */ (function () {
|
|
3920
|
+
function RepositionCutoffsLayoutFunction() {
|
|
3921
|
+
}
|
|
3922
|
+
RepositionCutoffsLayoutFunction.prototype.execute = function (canvas) {
|
|
3923
|
+
canvas.getObjectsByTypeInternal(ObjectType.CUTOFF)
|
|
3924
|
+
.forEach(function (cutoff) { return cutoff.updatePosition(); });
|
|
3925
|
+
};
|
|
3926
|
+
return RepositionCutoffsLayoutFunction;
|
|
3927
|
+
}());
|
|
3928
|
+
|
|
3929
|
+
var PinToBottomLayoutFunction = /** @class */ (function () {
|
|
3930
|
+
function PinToBottomLayoutFunction() {
|
|
3931
|
+
}
|
|
3932
|
+
PinToBottomLayoutFunction.prototype.execute = function (canvas) {
|
|
3933
|
+
canvas.getObjectsInternal()
|
|
3934
|
+
.forEach(function (object) { return object.moveToPinnedPosition(); });
|
|
3935
|
+
};
|
|
3936
|
+
return PinToBottomLayoutFunction;
|
|
3937
|
+
}());
|
|
3938
|
+
|
|
3939
|
+
var ResizeCanvasLayoutFunction = /** @class */ (function () {
|
|
3940
|
+
function ResizeCanvasLayoutFunction() {
|
|
3941
|
+
}
|
|
3942
|
+
ResizeCanvasLayoutFunction.prototype.execute = function (canvas) {
|
|
3943
|
+
if (canvas.getLayoutManager().isEnforcedPositioning)
|
|
3944
|
+
return;
|
|
3945
|
+
if (oc(canvas.getDimensionsRestrictions()).fixed(false))
|
|
3946
|
+
return;
|
|
3947
|
+
var currentDimensions = canvas.getDimensions();
|
|
3948
|
+
var baseDimensions = canvas.getBaseDimensions();
|
|
3949
|
+
var textHeightIncreasePx = _(canvas.getObjectsByTypeInternal(ObjectType.TEXT))
|
|
3950
|
+
.filter(function (text) { return text.isResizeCanvas(); })
|
|
3951
|
+
.reduce(function (x, text) { return x + text.getSizeIncreaseSinceCreation(); }, 0);
|
|
3952
|
+
var increase = baseDimensions.withSize(currentDimensions.width, 0);
|
|
3953
|
+
while (increase.heightPx < textHeightIncreasePx) {
|
|
3954
|
+
increase = increase.withSize(increase.width, increase.height + 1);
|
|
3955
|
+
}
|
|
3956
|
+
var targetHeight = increase.withSize(increase.width, baseDimensions.height + increase.height);
|
|
3957
|
+
if (currentDimensions.height !== targetHeight.height) {
|
|
3958
|
+
canvas.setDimensions(targetHeight);
|
|
3959
|
+
}
|
|
3960
|
+
canvas.getObjectsInternal().forEach(function (object) { return object.setCoords(); });
|
|
3961
|
+
canvas.redraw();
|
|
3962
|
+
};
|
|
3963
|
+
return ResizeCanvasLayoutFunction;
|
|
3964
|
+
}());
|
|
3965
|
+
|
|
3966
|
+
var AdvancedLayoutManager = /** @class */ (function (_super) {
|
|
3967
|
+
__extends(AdvancedLayoutManager, _super);
|
|
3968
|
+
function AdvancedLayoutManager(canvas) {
|
|
3969
|
+
var _this = _super.call(this, canvas) || this;
|
|
3970
|
+
_this.key = LayoutManager.ADVANCED;
|
|
3971
|
+
_this.pinToBottom = new PinToBottomLayoutFunction();
|
|
3972
|
+
_this.redrawAll = new RedrawAllLayoutFunction();
|
|
3973
|
+
_this.repositionBorders = new RepositionBordersLayoutFunction();
|
|
3974
|
+
_this.repositionCutoffs = new RepositionCutoffsLayoutFunction();
|
|
3975
|
+
_this.repositionBackgrounds = new RepositionBackgroundsLayoutFunction();
|
|
3976
|
+
_this.resizeCanvas = new ResizeCanvasLayoutFunction();
|
|
3977
|
+
return _this;
|
|
3978
|
+
}
|
|
3979
|
+
AdvancedLayoutManager.prototype.onCanvasDimensionsChange = function () {
|
|
3980
|
+
this.pinToBottom.execute(this.canvas);
|
|
3981
|
+
this.repositionCutoffs.execute(this.canvas);
|
|
3982
|
+
this.repositionBorders.execute(this.canvas);
|
|
3983
|
+
this.repositionBackgrounds.execute(this.canvas);
|
|
3984
|
+
this.redrawAll.execute(this.canvas);
|
|
3985
|
+
};
|
|
3986
|
+
AdvancedLayoutManager.prototype.onTextChange = function () {
|
|
3987
|
+
this.resizeCanvas.execute(this.canvas);
|
|
3988
|
+
};
|
|
3989
|
+
AdvancedLayoutManager.prototype.onObjectListChange = function () {
|
|
3990
|
+
this.redrawAll.execute(this.canvas);
|
|
3991
|
+
};
|
|
3992
|
+
return AdvancedLayoutManager;
|
|
3993
|
+
}(AbstractLayoutManager));
|
|
3994
|
+
|
|
4019
3995
|
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 };
|