js-draw 0.18.2 → 0.20.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.
- package/.eslintrc.js +1 -0
- package/CHANGELOG.md +10 -0
- package/dist/bundle.js +2 -2
- package/dist/bundledStyles.js +1 -0
- package/dist/cjs/src/Color4.d.ts +8 -0
- package/dist/cjs/src/Color4.js +67 -0
- package/dist/cjs/src/Editor.d.ts +2 -2
- package/dist/cjs/src/Editor.js +7 -7
- package/dist/cjs/src/SVGLoader.js +77 -12
- package/dist/cjs/src/Viewport.d.ts +2 -0
- package/dist/cjs/src/Viewport.js +6 -2
- package/dist/cjs/src/components/AbstractComponent.d.ts +2 -2
- package/dist/cjs/src/components/AbstractComponent.js +3 -3
- package/dist/cjs/src/components/{ImageBackground.d.ts → BackgroundComponent.d.ts} +23 -3
- package/dist/cjs/src/components/BackgroundComponent.js +309 -0
- package/dist/cjs/src/components/RestylableComponent.d.ts +21 -2
- package/dist/cjs/src/components/Stroke.d.ts +35 -0
- package/dist/cjs/src/components/Stroke.js +37 -3
- package/dist/cjs/src/components/TextComponent.d.ts +27 -17
- package/dist/cjs/src/components/TextComponent.js +23 -1
- package/dist/cjs/src/components/lib.d.ts +4 -3
- package/dist/cjs/src/components/lib.js +2 -2
- package/dist/cjs/src/components/util/StrokeSmoother.js +25 -15
- package/dist/cjs/src/lib.d.ts +30 -0
- package/dist/cjs/src/lib.js +30 -0
- package/dist/cjs/src/localizations/de.js +1 -1
- package/dist/cjs/src/localizations/es.js +1 -1
- package/dist/cjs/src/math/Path.js +1 -1
- package/dist/cjs/src/math/polynomial/QuadraticBezier.d.ts +28 -0
- package/dist/cjs/src/math/polynomial/QuadraticBezier.js +115 -0
- package/dist/cjs/src/math/polynomial/solveQuadratic.d.ts +6 -0
- package/dist/cjs/src/math/polynomial/solveQuadratic.js +36 -0
- package/dist/cjs/src/rendering/RenderingStyle.d.ts +4 -4
- package/dist/cjs/src/rendering/TextRenderingStyle.d.ts +10 -10
- package/dist/cjs/src/rendering/lib.d.ts +2 -0
- package/dist/cjs/src/rendering/renderers/AbstractRenderer.d.ts +2 -2
- package/dist/cjs/src/rendering/renderers/CanvasRenderer.d.ts +2 -2
- package/dist/cjs/src/rendering/renderers/CanvasRenderer.js +5 -3
- package/dist/cjs/src/rendering/renderers/DummyRenderer.d.ts +2 -2
- package/dist/cjs/src/rendering/renderers/SVGRenderer.d.ts +2 -2
- package/dist/cjs/src/rendering/renderers/SVGRenderer.js +15 -6
- package/dist/cjs/src/rendering/renderers/TextOnlyRenderer.d.ts +2 -2
- package/dist/cjs/src/toolbar/IconProvider.d.ts +2 -2
- package/dist/cjs/src/toolbar/localization.d.ts +2 -1
- package/dist/cjs/src/toolbar/localization.js +3 -2
- package/dist/cjs/src/toolbar/widgets/BaseWidget.js +1 -1
- package/dist/cjs/src/toolbar/widgets/DocumentPropertiesWidget.d.ts +5 -0
- package/dist/cjs/src/toolbar/widgets/DocumentPropertiesWidget.js +77 -2
- package/dist/cjs/src/toolbar/widgets/PenToolWidget.js +1 -1
- package/dist/cjs/src/tools/FindTool.js +1 -1
- package/dist/cjs/src/tools/SoundUITool.d.ts +24 -0
- package/dist/cjs/src/tools/SoundUITool.js +164 -0
- package/dist/cjs/src/tools/TextTool.d.ts +2 -2
- package/dist/cjs/src/tools/ToolController.js +6 -1
- package/dist/cjs/src/tools/lib.d.ts +1 -0
- package/dist/cjs/src/tools/lib.js +3 -1
- package/dist/cjs/src/tools/localization.d.ts +3 -0
- package/dist/cjs/src/tools/localization.js +3 -0
- package/dist/mjs/src/Color4.d.ts +8 -0
- package/dist/mjs/src/Color4.mjs +64 -0
- package/dist/mjs/src/Editor.d.ts +2 -2
- package/dist/mjs/src/Editor.mjs +6 -6
- package/dist/mjs/src/SVGLoader.mjs +76 -11
- package/dist/mjs/src/Viewport.d.ts +2 -0
- package/dist/mjs/src/Viewport.mjs +6 -2
- package/dist/mjs/src/components/AbstractComponent.d.ts +2 -2
- package/dist/mjs/src/components/AbstractComponent.mjs +3 -3
- package/dist/mjs/src/components/{ImageBackground.d.ts → BackgroundComponent.d.ts} +23 -3
- package/dist/mjs/src/components/BackgroundComponent.mjs +279 -0
- package/dist/mjs/src/components/RestylableComponent.d.ts +21 -2
- package/dist/mjs/src/components/Stroke.d.ts +35 -0
- package/dist/mjs/src/components/Stroke.mjs +37 -3
- package/dist/mjs/src/components/TextComponent.d.ts +27 -17
- package/dist/mjs/src/components/TextComponent.mjs +23 -1
- package/dist/mjs/src/components/lib.d.ts +4 -3
- package/dist/mjs/src/components/lib.mjs +2 -2
- package/dist/mjs/src/components/util/StrokeSmoother.mjs +25 -15
- package/dist/mjs/src/lib.d.ts +30 -0
- package/dist/mjs/src/lib.mjs +30 -0
- package/dist/mjs/src/localizations/de.mjs +1 -1
- package/dist/mjs/src/localizations/es.mjs +1 -1
- package/dist/mjs/src/math/Path.mjs +1 -1
- package/dist/mjs/src/math/polynomial/QuadraticBezier.d.ts +28 -0
- package/dist/mjs/src/math/polynomial/QuadraticBezier.mjs +109 -0
- package/dist/mjs/src/math/polynomial/solveQuadratic.d.ts +6 -0
- package/dist/mjs/src/math/polynomial/solveQuadratic.mjs +34 -0
- package/dist/mjs/src/rendering/RenderingStyle.d.ts +4 -4
- package/dist/mjs/src/rendering/TextRenderingStyle.d.ts +10 -10
- package/dist/mjs/src/rendering/lib.d.ts +2 -0
- package/dist/mjs/src/rendering/renderers/AbstractRenderer.d.ts +2 -2
- package/dist/mjs/src/rendering/renderers/CanvasRenderer.d.ts +2 -2
- package/dist/mjs/src/rendering/renderers/CanvasRenderer.mjs +5 -3
- package/dist/mjs/src/rendering/renderers/DummyRenderer.d.ts +2 -2
- package/dist/mjs/src/rendering/renderers/SVGRenderer.d.ts +2 -2
- package/dist/mjs/src/rendering/renderers/SVGRenderer.mjs +15 -6
- package/dist/mjs/src/rendering/renderers/TextOnlyRenderer.d.ts +2 -2
- package/dist/mjs/src/toolbar/IconProvider.d.ts +2 -2
- package/dist/mjs/src/toolbar/localization.d.ts +2 -1
- package/dist/mjs/src/toolbar/localization.mjs +3 -2
- package/dist/mjs/src/toolbar/widgets/BaseWidget.mjs +1 -1
- package/dist/mjs/src/toolbar/widgets/DocumentPropertiesWidget.d.ts +5 -0
- package/dist/mjs/src/toolbar/widgets/DocumentPropertiesWidget.mjs +54 -2
- package/dist/mjs/src/toolbar/widgets/PenToolWidget.mjs +1 -1
- package/dist/mjs/src/tools/FindTool.mjs +1 -1
- package/dist/mjs/src/tools/SoundUITool.d.ts +24 -0
- package/dist/mjs/src/tools/SoundUITool.mjs +158 -0
- package/dist/mjs/src/tools/TextTool.d.ts +2 -2
- package/dist/mjs/src/tools/ToolController.mjs +6 -1
- package/dist/mjs/src/tools/lib.d.ts +1 -0
- package/dist/mjs/src/tools/lib.mjs +1 -0
- package/dist/mjs/src/tools/localization.d.ts +3 -0
- package/dist/mjs/src/tools/localization.mjs +3 -0
- package/jest.config.js +1 -1
- package/package.json +19 -17
- package/src/Editor.css +2 -2
- package/src/tools/SoundUITool.css +15 -0
- package/src/tools/tools.css +4 -0
- package/dist/cjs/src/components/ImageBackground.js +0 -146
- package/dist/mjs/src/components/ImageBackground.mjs +0 -139
- package/src/Color4.test.ts +0 -40
- package/src/Color4.ts +0 -236
- package/src/Editor.loadFrom.test.ts +0 -24
- package/src/Editor.toSVG.test.ts +0 -111
- package/src/Editor.ts +0 -1122
- package/src/EditorImage.test.ts +0 -120
- package/src/EditorImage.ts +0 -603
- package/src/EventDispatcher.test.ts +0 -123
- package/src/EventDispatcher.ts +0 -71
- package/src/Pointer.ts +0 -127
- package/src/SVGLoader.test.ts +0 -114
- package/src/SVGLoader.ts +0 -511
- package/src/UndoRedoHistory.test.ts +0 -33
- package/src/UndoRedoHistory.ts +0 -102
- package/src/Viewport.ts +0 -319
- package/src/bundle/bundled.ts +0 -7
- package/src/commands/Command.ts +0 -45
- package/src/commands/Duplicate.ts +0 -48
- package/src/commands/Erase.ts +0 -74
- package/src/commands/SerializableCommand.ts +0 -49
- package/src/commands/UnresolvedCommand.ts +0 -37
- package/src/commands/invertCommand.ts +0 -51
- package/src/commands/lib.ts +0 -16
- package/src/commands/localization.ts +0 -47
- package/src/commands/uniteCommands.test.ts +0 -23
- package/src/commands/uniteCommands.ts +0 -135
- package/src/components/AbstractComponent.transformBy.test.ts +0 -22
- package/src/components/AbstractComponent.ts +0 -364
- package/src/components/ImageBackground.test.ts +0 -35
- package/src/components/ImageBackground.ts +0 -176
- package/src/components/ImageComponent.ts +0 -171
- package/src/components/RestylableComponent.ts +0 -142
- package/src/components/SVGGlobalAttributesObject.ts +0 -81
- package/src/components/Stroke.test.ts +0 -139
- package/src/components/Stroke.ts +0 -245
- package/src/components/TextComponent.test.ts +0 -99
- package/src/components/TextComponent.ts +0 -315
- package/src/components/UnknownSVGObject.test.ts +0 -10
- package/src/components/UnknownSVGObject.ts +0 -60
- package/src/components/builders/ArrowBuilder.ts +0 -107
- package/src/components/builders/FreehandLineBuilder.ts +0 -212
- package/src/components/builders/LineBuilder.ts +0 -77
- package/src/components/builders/PressureSensitiveFreehandLineBuilder.ts +0 -454
- package/src/components/builders/RectangleBuilder.ts +0 -74
- package/src/components/builders/types.ts +0 -15
- package/src/components/lib.ts +0 -25
- package/src/components/localization.ts +0 -22
- package/src/components/util/StrokeSmoother.ts +0 -293
- package/src/components/util/describeComponentList.ts +0 -18
- package/src/lib.ts +0 -37
- package/src/localization.ts +0 -34
- package/src/localizations/de.ts +0 -98
- package/src/localizations/en.ts +0 -8
- package/src/localizations/es.ts +0 -74
- package/src/localizations/getLocalizationTable.test.ts +0 -27
- package/src/localizations/getLocalizationTable.ts +0 -55
- package/src/math/LineSegment2.test.ts +0 -99
- package/src/math/LineSegment2.ts +0 -160
- package/src/math/Mat33.test.ts +0 -244
- package/src/math/Mat33.ts +0 -437
- package/src/math/Path.fromString.test.ts +0 -223
- package/src/math/Path.test.ts +0 -198
- package/src/math/Path.toString.test.ts +0 -77
- package/src/math/Path.ts +0 -790
- package/src/math/Rect2.test.ts +0 -204
- package/src/math/Rect2.ts +0 -315
- package/src/math/Triangle.ts +0 -29
- package/src/math/Vec2.test.ts +0 -30
- package/src/math/Vec2.ts +0 -18
- package/src/math/Vec3.test.ts +0 -44
- package/src/math/Vec3.ts +0 -218
- package/src/math/lib.ts +0 -15
- package/src/math/rounding.test.ts +0 -65
- package/src/math/rounding.ts +0 -156
- package/src/rendering/Display.ts +0 -249
- package/src/rendering/RenderingStyle.test.ts +0 -68
- package/src/rendering/RenderingStyle.ts +0 -55
- package/src/rendering/TextRenderingStyle.ts +0 -45
- package/src/rendering/caching/CacheRecord.test.ts +0 -49
- package/src/rendering/caching/CacheRecord.ts +0 -77
- package/src/rendering/caching/CacheRecordManager.ts +0 -71
- package/src/rendering/caching/RenderingCache.test.ts +0 -44
- package/src/rendering/caching/RenderingCache.ts +0 -66
- package/src/rendering/caching/RenderingCacheNode.ts +0 -405
- package/src/rendering/caching/testUtils.ts +0 -35
- package/src/rendering/caching/types.ts +0 -34
- package/src/rendering/lib.ts +0 -6
- package/src/rendering/localization.ts +0 -20
- package/src/rendering/renderers/AbstractRenderer.ts +0 -222
- package/src/rendering/renderers/CanvasRenderer.ts +0 -296
- package/src/rendering/renderers/DummyRenderer.test.ts +0 -42
- package/src/rendering/renderers/DummyRenderer.ts +0 -136
- package/src/rendering/renderers/SVGRenderer.ts +0 -354
- package/src/rendering/renderers/TextOnlyRenderer.ts +0 -70
- package/src/testing/beforeEachFile.ts +0 -8
- package/src/testing/createEditor.ts +0 -11
- package/src/testing/global.d.ts +0 -17
- package/src/testing/lib.ts +0 -3
- package/src/testing/loadExpectExtensions.ts +0 -25
- package/src/testing/sendPenEvent.ts +0 -31
- package/src/testing/sendTouchEvent.ts +0 -78
- package/src/toolbar/HTMLToolbar.ts +0 -492
- package/src/toolbar/IconProvider.ts +0 -736
- package/src/toolbar/lib.ts +0 -4
- package/src/toolbar/localization.ts +0 -106
- package/src/toolbar/makeColorInput.ts +0 -145
- package/src/toolbar/types.ts +0 -5
- package/src/toolbar/widgets/ActionButtonWidget.ts +0 -39
- package/src/toolbar/widgets/BaseToolWidget.ts +0 -56
- package/src/toolbar/widgets/BaseWidget.ts +0 -377
- package/src/toolbar/widgets/DocumentPropertiesWidget.ts +0 -167
- package/src/toolbar/widgets/EraserToolWidget.ts +0 -85
- package/src/toolbar/widgets/HandToolWidget.ts +0 -250
- package/src/toolbar/widgets/InsertImageWidget.ts +0 -223
- package/src/toolbar/widgets/OverflowWidget.ts +0 -92
- package/src/toolbar/widgets/PenToolWidget.ts +0 -288
- package/src/toolbar/widgets/SelectionToolWidget.ts +0 -190
- package/src/toolbar/widgets/TextToolWidget.ts +0 -145
- package/src/toolbar/widgets/lib.ts +0 -13
- package/src/tools/BaseTool.ts +0 -76
- package/src/tools/Eraser.test.ts +0 -103
- package/src/tools/Eraser.ts +0 -139
- package/src/tools/FindTool.ts +0 -152
- package/src/tools/PanZoom.test.ts +0 -310
- package/src/tools/PanZoom.ts +0 -520
- package/src/tools/PasteHandler.ts +0 -95
- package/src/tools/Pen.test.ts +0 -194
- package/src/tools/Pen.ts +0 -226
- package/src/tools/PipetteTool.ts +0 -55
- package/src/tools/SelectionTool/SelectAllShortcutHandler.ts +0 -28
- package/src/tools/SelectionTool/Selection.ts +0 -607
- package/src/tools/SelectionTool/SelectionHandle.ts +0 -108
- package/src/tools/SelectionTool/SelectionTool.test.ts +0 -261
- package/src/tools/SelectionTool/SelectionTool.ts +0 -480
- package/src/tools/SelectionTool/TransformMode.ts +0 -114
- package/src/tools/SelectionTool/types.ts +0 -11
- package/src/tools/TextTool.ts +0 -326
- package/src/tools/ToolController.ts +0 -178
- package/src/tools/ToolEnabledGroup.ts +0 -14
- package/src/tools/ToolSwitcherShortcut.ts +0 -39
- package/src/tools/ToolbarShortcutHandler.ts +0 -34
- package/src/tools/UndoRedoShortcut.test.ts +0 -56
- package/src/tools/UndoRedoShortcut.ts +0 -25
- package/src/tools/lib.ts +0 -21
- package/src/tools/localization.ts +0 -66
- package/src/types.ts +0 -234
- package/src/util/assertions.ts +0 -55
- package/src/util/fileToBase64.ts +0 -18
- package/src/util/untilNextAnimationFrame.ts +0 -9
- package/src/util/waitForTimeout.ts +0 -9
@@ -0,0 +1,309 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
+
}) : function(o, v) {
|
16
|
+
o["default"] = v;
|
17
|
+
});
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
+
if (mod && mod.__esModule) return mod;
|
20
|
+
var result = {};
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
+
__setModuleDefault(result, mod);
|
23
|
+
return result;
|
24
|
+
};
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
27
|
+
};
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
29
|
+
exports.backgroundTypeToClassNameMap = exports.imageBackgroundNonAutomaticSecondaryColorCSSClassName = exports.imageBackgroundGridSizeCSSPrefix = exports.imageBackgroundCSSClassName = exports.BackgroundType = void 0;
|
30
|
+
const Color4_1 = __importDefault(require("../Color4"));
|
31
|
+
const EditorImage_1 = require("../EditorImage");
|
32
|
+
const Rect2_1 = __importDefault(require("../math/Rect2"));
|
33
|
+
const AbstractComponent_1 = __importDefault(require("./AbstractComponent"));
|
34
|
+
const RestylableComponent_1 = require("./RestylableComponent");
|
35
|
+
const Path_1 = __importStar(require("../math/Path"));
|
36
|
+
const Vec2_1 = require("../math/Vec2");
|
37
|
+
const Viewport_1 = __importDefault(require("../Viewport"));
|
38
|
+
const rounding_1 = require("../math/rounding");
|
39
|
+
var BackgroundType;
|
40
|
+
(function (BackgroundType) {
|
41
|
+
BackgroundType[BackgroundType["SolidColor"] = 0] = "SolidColor";
|
42
|
+
BackgroundType[BackgroundType["Grid"] = 1] = "Grid";
|
43
|
+
BackgroundType[BackgroundType["None"] = 2] = "None";
|
44
|
+
})(BackgroundType = exports.BackgroundType || (exports.BackgroundType = {}));
|
45
|
+
exports.imageBackgroundCSSClassName = 'js-draw-image-background';
|
46
|
+
// Class name prefix indicating the size of the background's grid cells (if present).
|
47
|
+
exports.imageBackgroundGridSizeCSSPrefix = 'js-draw-image-background-grid-';
|
48
|
+
// Flag included in rendered SVGs (etc) that indicates that the secondary color of the
|
49
|
+
// background has been manually set.
|
50
|
+
exports.imageBackgroundNonAutomaticSecondaryColorCSSClassName = 'js-draw-image-background-non-automatic-secondary-color';
|
51
|
+
exports.backgroundTypeToClassNameMap = {
|
52
|
+
[BackgroundType.Grid]: 'js-draw-image-background-grid',
|
53
|
+
[BackgroundType.SolidColor]: exports.imageBackgroundCSSClassName,
|
54
|
+
[BackgroundType.None]: '',
|
55
|
+
};
|
56
|
+
// Represents the background of the editor's canvas.
|
57
|
+
class BackgroundComponent extends AbstractComponent_1.default {
|
58
|
+
constructor(backgroundType, mainColor) {
|
59
|
+
super('image-background', 0);
|
60
|
+
this.backgroundType = backgroundType;
|
61
|
+
this.mainColor = mainColor;
|
62
|
+
this.viewportSizeChangeListener = null;
|
63
|
+
this.gridSize = Viewport_1.default.getGridSize(2);
|
64
|
+
this.gridStrokeWidth = 0.7;
|
65
|
+
this.secondaryColor = null;
|
66
|
+
// eslint-disable-next-line @typescript-eslint/prefer-as-const
|
67
|
+
this.isRestylableComponent = true;
|
68
|
+
this.contentBBox = Rect2_1.default.empty;
|
69
|
+
}
|
70
|
+
static ofGrid(backgroundColor, gridSize, gridColor, gridStrokeWidth) {
|
71
|
+
const background = new BackgroundComponent(BackgroundType.Grid, backgroundColor);
|
72
|
+
if (gridSize !== undefined) {
|
73
|
+
background.gridSize = gridSize;
|
74
|
+
}
|
75
|
+
if (gridColor !== undefined) {
|
76
|
+
background.secondaryColor = gridColor;
|
77
|
+
}
|
78
|
+
if (gridStrokeWidth !== undefined) {
|
79
|
+
background.gridStrokeWidth = gridStrokeWidth;
|
80
|
+
}
|
81
|
+
return background;
|
82
|
+
}
|
83
|
+
getBackgroundType() {
|
84
|
+
return this.backgroundType;
|
85
|
+
}
|
86
|
+
// @internal
|
87
|
+
getMainColor() {
|
88
|
+
return this.mainColor;
|
89
|
+
}
|
90
|
+
// @internal
|
91
|
+
getSecondaryColor() {
|
92
|
+
return this.secondaryColor;
|
93
|
+
}
|
94
|
+
// @internal
|
95
|
+
getGridSize() {
|
96
|
+
return this.gridSize;
|
97
|
+
}
|
98
|
+
getStyle() {
|
99
|
+
let color = this.mainColor;
|
100
|
+
if (this.backgroundType === BackgroundType.None) {
|
101
|
+
color = undefined;
|
102
|
+
}
|
103
|
+
return {
|
104
|
+
color,
|
105
|
+
};
|
106
|
+
}
|
107
|
+
updateStyle(style) {
|
108
|
+
return (0, RestylableComponent_1.createRestyleComponentCommand)(this.getStyle(), style, this);
|
109
|
+
}
|
110
|
+
// @internal
|
111
|
+
forceStyle(style, editor) {
|
112
|
+
const fill = style.color;
|
113
|
+
if (!fill) {
|
114
|
+
return;
|
115
|
+
}
|
116
|
+
this.mainColor = fill;
|
117
|
+
// A solid background and transparent fill is equivalent to no background.
|
118
|
+
if (fill.eq(Color4_1.default.transparent) && this.backgroundType === BackgroundType.SolidColor) {
|
119
|
+
this.backgroundType = BackgroundType.None;
|
120
|
+
}
|
121
|
+
else if (this.backgroundType === BackgroundType.None) {
|
122
|
+
this.backgroundType = BackgroundType.SolidColor;
|
123
|
+
}
|
124
|
+
if (editor) {
|
125
|
+
editor.image.queueRerenderOf(this);
|
126
|
+
editor.queueRerender();
|
127
|
+
}
|
128
|
+
}
|
129
|
+
onAddToImage(image) {
|
130
|
+
if (this.viewportSizeChangeListener) {
|
131
|
+
console.warn('onAddToImage called when background is already in an image');
|
132
|
+
this.onRemoveFromImage();
|
133
|
+
}
|
134
|
+
this.viewportSizeChangeListener = image.notifier.on(EditorImage_1.EditorImageEventType.ExportViewportChanged, () => {
|
135
|
+
this.recomputeBBox(image);
|
136
|
+
});
|
137
|
+
this.recomputeBBox(image);
|
138
|
+
}
|
139
|
+
onRemoveFromImage() {
|
140
|
+
var _a;
|
141
|
+
(_a = this.viewportSizeChangeListener) === null || _a === void 0 ? void 0 : _a.remove();
|
142
|
+
this.viewportSizeChangeListener = null;
|
143
|
+
}
|
144
|
+
recomputeBBox(image) {
|
145
|
+
const importExportRect = image.getImportExportViewport().visibleRect;
|
146
|
+
if (!this.contentBBox.eq(importExportRect)) {
|
147
|
+
this.contentBBox = importExportRect;
|
148
|
+
// Re-render this if already added to the EditorImage.
|
149
|
+
image.queueRerenderOf(this);
|
150
|
+
}
|
151
|
+
}
|
152
|
+
generateGridPath(visibleRect) {
|
153
|
+
var _a, _b;
|
154
|
+
const targetRect = (_b = (_a = visibleRect === null || visibleRect === void 0 ? void 0 : visibleRect.grownBy(this.gridStrokeWidth)) === null || _a === void 0 ? void 0 : _a.intersection(this.contentBBox)) !== null && _b !== void 0 ? _b : this.contentBBox;
|
155
|
+
const roundDownToGrid = (coord) => Math.floor(coord / this.gridSize) * this.gridSize;
|
156
|
+
const roundUpToGrid = (coord) => Math.ceil(coord / this.gridSize) * this.gridSize;
|
157
|
+
const startY = roundUpToGrid(targetRect.y);
|
158
|
+
const endY = roundDownToGrid(targetRect.y + targetRect.h);
|
159
|
+
const startX = roundUpToGrid(targetRect.x);
|
160
|
+
const endX = roundDownToGrid(targetRect.x + targetRect.w);
|
161
|
+
const result = [];
|
162
|
+
// Don't generate grids with a huge number of rows/columns -- such grids
|
163
|
+
// take a long time to render and are likely invisible due to the number of
|
164
|
+
// cells.
|
165
|
+
const rowCount = (endY - startY) / this.gridSize;
|
166
|
+
const colCount = (endX - startX) / this.gridSize;
|
167
|
+
const maxGridCols = 1000;
|
168
|
+
const maxGridRows = 1000;
|
169
|
+
if (rowCount > maxGridRows || colCount > maxGridCols) {
|
170
|
+
return Path_1.default.empty;
|
171
|
+
}
|
172
|
+
const startPoint = Vec2_1.Vec2.of(targetRect.x, startY);
|
173
|
+
for (let y = startY; y <= endY; y += this.gridSize) {
|
174
|
+
result.push({
|
175
|
+
kind: Path_1.PathCommandType.MoveTo,
|
176
|
+
point: Vec2_1.Vec2.of(targetRect.x, y),
|
177
|
+
});
|
178
|
+
result.push({
|
179
|
+
kind: Path_1.PathCommandType.LineTo,
|
180
|
+
point: Vec2_1.Vec2.of(targetRect.x + targetRect.w, y),
|
181
|
+
});
|
182
|
+
}
|
183
|
+
for (let x = startX; x <= endX; x += this.gridSize) {
|
184
|
+
result.push({
|
185
|
+
kind: Path_1.PathCommandType.MoveTo,
|
186
|
+
point: Vec2_1.Vec2.of(x, targetRect.y),
|
187
|
+
});
|
188
|
+
result.push({
|
189
|
+
kind: Path_1.PathCommandType.LineTo,
|
190
|
+
point: Vec2_1.Vec2.of(x, targetRect.y + targetRect.h)
|
191
|
+
});
|
192
|
+
}
|
193
|
+
return new Path_1.default(startPoint, result);
|
194
|
+
}
|
195
|
+
render(canvas, visibleRect) {
|
196
|
+
if (this.backgroundType === BackgroundType.None) {
|
197
|
+
return;
|
198
|
+
}
|
199
|
+
const clip = true;
|
200
|
+
canvas.startObject(this.contentBBox, clip);
|
201
|
+
if (this.backgroundType === BackgroundType.SolidColor || this.backgroundType === BackgroundType.Grid) {
|
202
|
+
// If the rectangle for this region contains the visible rect,
|
203
|
+
// we can fill the entire visible rectangle (which may be more efficient than
|
204
|
+
// filling the entire region for this.)
|
205
|
+
if (visibleRect) {
|
206
|
+
const intersection = visibleRect.intersection(this.contentBBox);
|
207
|
+
if (intersection) {
|
208
|
+
canvas.fillRect(intersection, this.mainColor);
|
209
|
+
}
|
210
|
+
}
|
211
|
+
else {
|
212
|
+
canvas.fillRect(this.contentBBox, this.mainColor);
|
213
|
+
}
|
214
|
+
}
|
215
|
+
if (this.backgroundType === BackgroundType.Grid) {
|
216
|
+
let gridColor = this.secondaryColor;
|
217
|
+
gridColor !== null && gridColor !== void 0 ? gridColor : (gridColor = Color4_1.default.ofRGBA(1 - this.mainColor.r, 1 - this.mainColor.g, 1 - this.mainColor.b, 0.2));
|
218
|
+
// If the background fill is completely transparent, ensure visibility on otherwise light
|
219
|
+
// and dark backgrounds.
|
220
|
+
if (this.mainColor.a === 0) {
|
221
|
+
gridColor = Color4_1.default.ofRGBA(0.5, 0.5, 0.5, 0.2);
|
222
|
+
}
|
223
|
+
const style = {
|
224
|
+
fill: Color4_1.default.transparent,
|
225
|
+
stroke: { width: this.gridStrokeWidth, color: gridColor }
|
226
|
+
};
|
227
|
+
canvas.drawPath(this.generateGridPath(visibleRect).toRenderable(style));
|
228
|
+
}
|
229
|
+
const backgroundTypeCSSClass = exports.backgroundTypeToClassNameMap[this.backgroundType];
|
230
|
+
const classNames = [exports.imageBackgroundCSSClassName];
|
231
|
+
if (backgroundTypeCSSClass !== exports.imageBackgroundCSSClassName) {
|
232
|
+
classNames.push(backgroundTypeCSSClass);
|
233
|
+
const gridSizeStr = (0, rounding_1.toRoundedString)(this.gridSize).replace(/[.]/g, 'p');
|
234
|
+
classNames.push(exports.imageBackgroundGridSizeCSSPrefix + gridSizeStr);
|
235
|
+
}
|
236
|
+
if (this.secondaryColor !== null) {
|
237
|
+
classNames.push(exports.imageBackgroundNonAutomaticSecondaryColorCSSClassName);
|
238
|
+
}
|
239
|
+
canvas.endObject(this.getLoadSaveData(), classNames);
|
240
|
+
}
|
241
|
+
intersects(lineSegment) {
|
242
|
+
return this.contentBBox.getEdges().some(edge => edge.intersects(lineSegment));
|
243
|
+
}
|
244
|
+
isSelectable() {
|
245
|
+
return false;
|
246
|
+
}
|
247
|
+
isBackground() {
|
248
|
+
return true;
|
249
|
+
}
|
250
|
+
serializeToJSON() {
|
251
|
+
var _a;
|
252
|
+
return {
|
253
|
+
mainColor: this.mainColor.toHexString(),
|
254
|
+
secondaryColor: (_a = this.secondaryColor) === null || _a === void 0 ? void 0 : _a.toHexString(),
|
255
|
+
backgroundType: this.backgroundType,
|
256
|
+
gridSize: this.gridSize,
|
257
|
+
gridStrokeWidth: this.gridStrokeWidth,
|
258
|
+
};
|
259
|
+
}
|
260
|
+
applyTransformation(_affineTransfm) {
|
261
|
+
// Do nothing — it doesn't make sense to transform the background.
|
262
|
+
}
|
263
|
+
description(localizationTable) {
|
264
|
+
if (this.backgroundType === BackgroundType.SolidColor) {
|
265
|
+
return localizationTable.filledBackgroundWithColor(this.mainColor.toString());
|
266
|
+
}
|
267
|
+
else {
|
268
|
+
return localizationTable.emptyBackground;
|
269
|
+
}
|
270
|
+
}
|
271
|
+
createClone() {
|
272
|
+
return new BackgroundComponent(this.backgroundType, this.mainColor);
|
273
|
+
}
|
274
|
+
// @internal
|
275
|
+
static deserializeFromJSON(json) {
|
276
|
+
var _a, _b;
|
277
|
+
if (typeof json === 'string') {
|
278
|
+
json = JSON.parse(json);
|
279
|
+
}
|
280
|
+
if (typeof json.mainColor !== 'string') {
|
281
|
+
throw new Error('Error deserializing — mainColor must be of type string.');
|
282
|
+
}
|
283
|
+
let backgroundType;
|
284
|
+
const jsonBackgroundType = json.backgroundType;
|
285
|
+
if (jsonBackgroundType === BackgroundType.None || jsonBackgroundType === BackgroundType.Grid
|
286
|
+
|| jsonBackgroundType === BackgroundType.SolidColor) {
|
287
|
+
backgroundType = jsonBackgroundType;
|
288
|
+
}
|
289
|
+
else {
|
290
|
+
const exhaustivenessCheck = jsonBackgroundType;
|
291
|
+
return exhaustivenessCheck;
|
292
|
+
}
|
293
|
+
const mainColor = Color4_1.default.fromHex(json.mainColor);
|
294
|
+
const secondaryColor = json.secondaryColor ? Color4_1.default.fromHex(json.secondaryColor) : null;
|
295
|
+
const gridSize = (_a = json.gridSize) !== null && _a !== void 0 ? _a : undefined;
|
296
|
+
const gridStrokeWidth = (_b = json.gridStrokeWidth) !== null && _b !== void 0 ? _b : undefined;
|
297
|
+
const result = new BackgroundComponent(backgroundType, mainColor);
|
298
|
+
result.secondaryColor = secondaryColor;
|
299
|
+
if (gridSize) {
|
300
|
+
result.gridSize = gridSize;
|
301
|
+
}
|
302
|
+
if (gridStrokeWidth) {
|
303
|
+
result.gridStrokeWidth = gridStrokeWidth;
|
304
|
+
}
|
305
|
+
return result;
|
306
|
+
}
|
307
|
+
}
|
308
|
+
exports.default = BackgroundComponent;
|
309
|
+
AbstractComponent_1.default.registerComponent('image-background', BackgroundComponent.deserializeFromJSON);
|
@@ -1,16 +1,35 @@
|
|
1
1
|
import Color4 from '../Color4';
|
2
2
|
import SerializableCommand from '../commands/SerializableCommand';
|
3
3
|
import Editor from '../Editor';
|
4
|
-
import
|
4
|
+
import TextRenderingStyle from '../rendering/TextRenderingStyle';
|
5
5
|
import AbstractComponent from './AbstractComponent';
|
6
6
|
export interface ComponentStyle {
|
7
7
|
color?: Color4;
|
8
|
-
textStyle?:
|
8
|
+
textStyle?: TextRenderingStyle;
|
9
9
|
}
|
10
10
|
export declare const createRestyleComponentCommand: (initialStyle: ComponentStyle, newStyle: ComponentStyle, component: RestyleableComponent) => SerializableCommand;
|
11
11
|
export declare const isRestylableComponent: (component: AbstractComponent) => component is RestyleableComponent;
|
12
|
+
/**
|
13
|
+
* An interface to be implemented by components with a changable color or {@link TextRenderingStyle}.
|
14
|
+
*
|
15
|
+
* All such classes must have a member variable, `isRestylableComponent` that is set to `true`
|
16
|
+
* to allow testing whether the class is a `RestylableComponent` (see {@link isRestylableComponent}).
|
17
|
+
*/
|
12
18
|
export interface RestyleableComponent extends AbstractComponent {
|
19
|
+
/**
|
20
|
+
* @returns a partial representation of this component's style.
|
21
|
+
*/
|
13
22
|
getStyle(): ComponentStyle;
|
23
|
+
/**
|
24
|
+
* Returns a {@link Command} that updates portions of this component's style
|
25
|
+
* to the given `style`.
|
26
|
+
*
|
27
|
+
* @example
|
28
|
+
* For some component and editor,
|
29
|
+
* ```ts
|
30
|
+
* editor.dispatch(component.updateStyle({ color: Color4.red }));
|
31
|
+
* ```
|
32
|
+
*/
|
14
33
|
updateStyle(style: ComponentStyle): SerializableCommand;
|
15
34
|
/**
|
16
35
|
* Set the style of this component in a way that can't be undone/redone
|
@@ -8,11 +8,43 @@ import AbstractRenderer, { RenderablePathSpec } from '../rendering/renderers/Abs
|
|
8
8
|
import AbstractComponent from './AbstractComponent';
|
9
9
|
import { ImageComponentLocalization } from './localization';
|
10
10
|
import RestyleableComponent, { ComponentStyle } from './RestylableComponent';
|
11
|
+
/**
|
12
|
+
* Represents an {@link AbstractComponent} made up of one or more {@link Path}s.
|
13
|
+
*
|
14
|
+
* @example
|
15
|
+
* For some {@link Editor} editor and `Stroke` stroke,
|
16
|
+
*
|
17
|
+
* **Restyling**:
|
18
|
+
* ```ts
|
19
|
+
* editor.dispatch(stroke.updateStyle({ color: Color4.red }));
|
20
|
+
* ```
|
21
|
+
*
|
22
|
+
* **Transforming**:
|
23
|
+
* ```ts
|
24
|
+
* editor.dispatch(stroke.transformBy(Mat33.translation(Vec2.of(10, 0))));
|
25
|
+
* ```
|
26
|
+
*/
|
11
27
|
export default class Stroke extends AbstractComponent implements RestyleableComponent {
|
12
28
|
private parts;
|
13
29
|
protected contentBBox: Rect2;
|
14
30
|
readonly isRestylableComponent: true;
|
15
31
|
private approximateRenderingTime;
|
32
|
+
/**
|
33
|
+
* Creates a `Stroke` from the given `parts`. All parts should have the
|
34
|
+
* same color.
|
35
|
+
*
|
36
|
+
* @example
|
37
|
+
* ```ts
|
38
|
+
* // A path that starts at (1,1), moves to the right by (2, 0),
|
39
|
+
* // then moves down and right by (3, 3)
|
40
|
+
* const path = Path.fromString('m1,1 2,0 3,3');
|
41
|
+
*
|
42
|
+
* const stroke = new Stroke([
|
43
|
+
* // Fill with red
|
44
|
+
* path.toRenderable({ fill: Color4.red })
|
45
|
+
* ]);
|
46
|
+
* ```
|
47
|
+
*/
|
16
48
|
constructor(parts: RenderablePathSpec[]);
|
17
49
|
getStyle(): ComponentStyle;
|
18
50
|
updateStyle(style: ComponentStyle): SerializableCommand;
|
@@ -22,6 +54,9 @@ export default class Stroke extends AbstractComponent implements RestyleableComp
|
|
22
54
|
getProportionalRenderingTime(): number;
|
23
55
|
private bboxForPart;
|
24
56
|
protected applyTransformation(affineTransfm: Mat33): void;
|
57
|
+
/**
|
58
|
+
* @returns the {@link Path.union} of all paths that make up this stroke.
|
59
|
+
*/
|
25
60
|
getPath(): Path;
|
26
61
|
description(localization: ImageComponentLocalization): string;
|
27
62
|
protected createClone(): AbstractComponent;
|
@@ -8,12 +8,43 @@ const Rect2_1 = __importDefault(require("../math/Rect2"));
|
|
8
8
|
const RenderingStyle_1 = require("../rendering/RenderingStyle");
|
9
9
|
const AbstractComponent_1 = __importDefault(require("./AbstractComponent"));
|
10
10
|
const RestylableComponent_1 = require("./RestylableComponent");
|
11
|
+
/**
|
12
|
+
* Represents an {@link AbstractComponent} made up of one or more {@link Path}s.
|
13
|
+
*
|
14
|
+
* @example
|
15
|
+
* For some {@link Editor} editor and `Stroke` stroke,
|
16
|
+
*
|
17
|
+
* **Restyling**:
|
18
|
+
* ```ts
|
19
|
+
* editor.dispatch(stroke.updateStyle({ color: Color4.red }));
|
20
|
+
* ```
|
21
|
+
*
|
22
|
+
* **Transforming**:
|
23
|
+
* ```ts
|
24
|
+
* editor.dispatch(stroke.transformBy(Mat33.translation(Vec2.of(10, 0))));
|
25
|
+
* ```
|
26
|
+
*/
|
11
27
|
class Stroke extends AbstractComponent_1.default {
|
12
|
-
|
13
|
-
|
28
|
+
/**
|
29
|
+
* Creates a `Stroke` from the given `parts`. All parts should have the
|
30
|
+
* same color.
|
31
|
+
*
|
32
|
+
* @example
|
33
|
+
* ```ts
|
34
|
+
* // A path that starts at (1,1), moves to the right by (2, 0),
|
35
|
+
* // then moves down and right by (3, 3)
|
36
|
+
* const path = Path.fromString('m1,1 2,0 3,3');
|
37
|
+
*
|
38
|
+
* const stroke = new Stroke([
|
39
|
+
* // Fill with red
|
40
|
+
* path.toRenderable({ fill: Color4.red })
|
41
|
+
* ]);
|
42
|
+
* ```
|
43
|
+
*/
|
14
44
|
constructor(parts) {
|
15
45
|
var _a;
|
16
46
|
super('stroke');
|
47
|
+
// @internal
|
17
48
|
// eslint-disable-next-line @typescript-eslint/prefer-as-const
|
18
49
|
this.isRestylableComponent = true;
|
19
50
|
this.approximateRenderingTime = 0;
|
@@ -99,7 +130,7 @@ class Stroke extends AbstractComponent_1.default {
|
|
99
130
|
if (!bbox.intersects(visibleRect)) {
|
100
131
|
continue;
|
101
132
|
}
|
102
|
-
const muchBiggerThanVisible = bbox.size.x > visibleRect.size.x *
|
133
|
+
const muchBiggerThanVisible = bbox.size.x > visibleRect.size.x * 3 || bbox.size.y > visibleRect.size.y * 3;
|
103
134
|
if (muchBiggerThanVisible && !part.path.roughlyIntersects(visibleRect, (_b = (_a = part.style.stroke) === null || _a === void 0 ? void 0 : _a.width) !== null && _b !== void 0 ? _b : 0)) {
|
104
135
|
continue;
|
105
136
|
}
|
@@ -146,6 +177,9 @@ class Stroke extends AbstractComponent_1.default {
|
|
146
177
|
};
|
147
178
|
});
|
148
179
|
}
|
180
|
+
/**
|
181
|
+
* @returns the {@link Path.union} of all paths that make up this stroke.
|
182
|
+
*/
|
149
183
|
getPath() {
|
150
184
|
let result = null;
|
151
185
|
for (const part of this.parts) {
|
@@ -4,18 +4,26 @@ import Mat33 from '../math/Mat33';
|
|
4
4
|
import Rect2 from '../math/Rect2';
|
5
5
|
import Editor from '../Editor';
|
6
6
|
import AbstractRenderer from '../rendering/renderers/AbstractRenderer';
|
7
|
-
import {
|
7
|
+
import { TextRenderingStyle } from '../rendering/TextRenderingStyle';
|
8
8
|
import AbstractComponent from './AbstractComponent';
|
9
9
|
import { ImageComponentLocalization } from './localization';
|
10
10
|
import RestyleableComponent, { ComponentStyle } from './RestylableComponent';
|
11
|
+
/**
|
12
|
+
* Displays text.
|
13
|
+
*/
|
11
14
|
export default class TextComponent extends AbstractComponent implements RestyleableComponent {
|
12
15
|
protected readonly textObjects: Array<string | TextComponent>;
|
13
16
|
private transform;
|
14
17
|
private style;
|
15
18
|
protected contentBBox: Rect2;
|
16
19
|
readonly isRestylableComponent: true;
|
17
|
-
|
18
|
-
|
20
|
+
/**
|
21
|
+
* Creates a new text object from a list of component text or child TextComponents.
|
22
|
+
*
|
23
|
+
* @see {@link fromLines}
|
24
|
+
*/
|
25
|
+
constructor(textObjects: Array<string | TextComponent>, transform: Mat33, style: TextRenderingStyle);
|
26
|
+
static applyTextStyles(ctx: CanvasRenderingContext2D, style: TextRenderingStyle): void;
|
19
27
|
private static textMeasuringCtx;
|
20
28
|
private static estimateTextDimens;
|
21
29
|
private static getTextDimens;
|
@@ -28,19 +36,7 @@ export default class TextComponent extends AbstractComponent implements Restylea
|
|
28
36
|
getStyle(): ComponentStyle;
|
29
37
|
updateStyle(style: ComponentStyle): SerializableCommand;
|
30
38
|
forceStyle(style: ComponentStyle, editor: Editor | null): void;
|
31
|
-
getTextStyle():
|
32
|
-
renderingStyle: {
|
33
|
-
fill: import("../Color4").default;
|
34
|
-
stroke: {
|
35
|
-
color: import("../Color4").default;
|
36
|
-
width: number;
|
37
|
-
} | undefined;
|
38
|
-
};
|
39
|
-
size: number;
|
40
|
-
fontFamily: string;
|
41
|
-
fontWeight?: string | undefined;
|
42
|
-
fontVariant?: string | undefined;
|
43
|
-
};
|
39
|
+
getTextStyle(): TextRenderingStyle;
|
44
40
|
getBaselinePos(): import("../lib").Vec3;
|
45
41
|
getTransform(): Mat33;
|
46
42
|
protected applyTransformation(affineTransfm: Mat33): void;
|
@@ -49,5 +45,19 @@ export default class TextComponent extends AbstractComponent implements Restylea
|
|
49
45
|
description(localizationTable: ImageComponentLocalization): string;
|
50
46
|
protected serializeToJSON(): Record<string, any>;
|
51
47
|
static deserializeFromString(json: any): TextComponent;
|
52
|
-
|
48
|
+
/**
|
49
|
+
* Creates a `TextComponent` from `lines`.
|
50
|
+
*
|
51
|
+
* @example
|
52
|
+
* ```ts
|
53
|
+
* const textStyle = {
|
54
|
+
* size: 12,
|
55
|
+
* fontFamily: 'serif',
|
56
|
+
* renderingStyle: { fill: Color4.black },
|
57
|
+
* };
|
58
|
+
*
|
59
|
+
* const text = TextComponent.fromLines('foo\nbar'.split('\n'), Mat33.identity, textStyle);
|
60
|
+
* ```
|
61
|
+
*/
|
62
|
+
static fromLines(lines: string[], transform: Mat33, style: TextRenderingStyle): AbstractComponent;
|
53
63
|
}
|
@@ -11,7 +11,15 @@ const TextRenderingStyle_1 = require("../rendering/TextRenderingStyle");
|
|
11
11
|
const AbstractComponent_1 = __importDefault(require("./AbstractComponent"));
|
12
12
|
const RestylableComponent_1 = require("./RestylableComponent");
|
13
13
|
const componentTypeId = 'text';
|
14
|
+
/**
|
15
|
+
* Displays text.
|
16
|
+
*/
|
14
17
|
class TextComponent extends AbstractComponent_1.default {
|
18
|
+
/**
|
19
|
+
* Creates a new text object from a list of component text or child TextComponents.
|
20
|
+
*
|
21
|
+
* @see {@link fromLines}
|
22
|
+
*/
|
15
23
|
constructor(textObjects, transform, style) {
|
16
24
|
super(componentTypeId);
|
17
25
|
this.textObjects = textObjects;
|
@@ -155,7 +163,7 @@ class TextComponent extends AbstractComponent_1.default {
|
|
155
163
|
editor.queueRerender();
|
156
164
|
}
|
157
165
|
}
|
158
|
-
// See
|
166
|
+
// See {@link getStyle}
|
159
167
|
getTextStyle() {
|
160
168
|
return (0, TextRenderingStyle_1.cloneTextStyle)(this.style);
|
161
169
|
}
|
@@ -237,6 +245,20 @@ class TextComponent extends AbstractComponent_1.default {
|
|
237
245
|
const transform = new Mat33_1.default(...transformData);
|
238
246
|
return new TextComponent(textObjects, transform, style);
|
239
247
|
}
|
248
|
+
/**
|
249
|
+
* Creates a `TextComponent` from `lines`.
|
250
|
+
*
|
251
|
+
* @example
|
252
|
+
* ```ts
|
253
|
+
* const textStyle = {
|
254
|
+
* size: 12,
|
255
|
+
* fontFamily: 'serif',
|
256
|
+
* renderingStyle: { fill: Color4.black },
|
257
|
+
* };
|
258
|
+
*
|
259
|
+
* const text = TextComponent.fromLines('foo\nbar'.split('\n'), Mat33.identity, textStyle);
|
260
|
+
* ```
|
261
|
+
*/
|
240
262
|
static fromLines(lines, transform, style) {
|
241
263
|
let lastComponent = null;
|
242
264
|
const components = [];
|
@@ -7,6 +7,7 @@ export { default as AbstractComponent } from './AbstractComponent';
|
|
7
7
|
import Stroke from './Stroke';
|
8
8
|
import TextComponent from './TextComponent';
|
9
9
|
import ImageComponent from './ImageComponent';
|
10
|
-
import RestyleableComponent
|
11
|
-
import
|
12
|
-
|
10
|
+
import RestyleableComponent from './RestylableComponent';
|
11
|
+
import { createRestyleComponentCommand, isRestylableComponent, ComponentStyle as RestyleableComponentStyle } from './RestylableComponent';
|
12
|
+
import BackgroundComponent from './BackgroundComponent';
|
13
|
+
export { Stroke, TextComponent as Text, RestyleableComponent, createRestyleComponentCommand, isRestylableComponent, RestyleableComponentStyle, TextComponent, Stroke as StrokeComponent, BackgroundComponent, ImageComponent, };
|
@@ -39,5 +39,5 @@ exports.ImageComponent = ImageComponent_1.default;
|
|
39
39
|
const RestylableComponent_1 = require("./RestylableComponent");
|
40
40
|
Object.defineProperty(exports, "createRestyleComponentCommand", { enumerable: true, get: function () { return RestylableComponent_1.createRestyleComponentCommand; } });
|
41
41
|
Object.defineProperty(exports, "isRestylableComponent", { enumerable: true, get: function () { return RestylableComponent_1.isRestylableComponent; } });
|
42
|
-
const
|
43
|
-
exports.BackgroundComponent =
|
42
|
+
const BackgroundComponent_1 = __importDefault(require("./BackgroundComponent"));
|
43
|
+
exports.BackgroundComponent = BackgroundComponent_1.default;
|