js-draw 1.2.1 → 1.3.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/README.md +30 -30
- package/dist/Editor.css +70 -4
- package/dist/bundle.js +2 -2
- package/dist/bundledStyles.js +1 -1
- package/dist/cjs/Editor.d.ts +73 -40
- package/dist/cjs/Editor.js +90 -24
- package/dist/cjs/EditorImage.d.ts +58 -6
- package/dist/cjs/EditorImage.js +336 -60
- package/dist/cjs/SVGLoader.d.ts +10 -4
- package/dist/cjs/SVGLoader.js +30 -10
- package/dist/cjs/UndoRedoHistory.d.ts +2 -2
- package/dist/cjs/UndoRedoHistory.js +4 -2
- package/dist/cjs/Viewport.d.ts +2 -1
- package/dist/cjs/Viewport.js +12 -3
- package/dist/cjs/commands/Command.d.ts +1 -0
- package/dist/cjs/commands/Command.js +1 -0
- package/dist/cjs/commands/Erase.js +1 -1
- package/dist/cjs/commands/SerializableCommand.d.ts +1 -1
- package/dist/cjs/commands/SerializableCommand.js +16 -2
- package/dist/cjs/commands/localization.d.ts +2 -0
- package/dist/cjs/commands/localization.js +2 -0
- package/dist/cjs/components/AbstractComponent.d.ts +38 -0
- package/dist/cjs/components/AbstractComponent.js +31 -0
- package/dist/cjs/components/BackgroundComponent.d.ts +10 -1
- package/dist/cjs/components/BackgroundComponent.js +60 -6
- package/dist/cjs/components/SVGGlobalAttributesObject.d.ts +2 -1
- package/dist/cjs/components/SVGGlobalAttributesObject.js +30 -1
- package/dist/cjs/components/Stroke.d.ts +1 -0
- package/dist/cjs/components/Stroke.js +44 -0
- package/dist/cjs/components/UnknownSVGObject.d.ts +2 -1
- package/dist/cjs/components/UnknownSVGObject.js +30 -1
- package/dist/cjs/components/lib.d.ts +2 -2
- package/dist/cjs/components/lib.js +15 -2
- package/dist/cjs/lib.d.ts +2 -45
- package/dist/cjs/lib.js +2 -45
- package/dist/cjs/rendering/RenderablePathSpec.d.ts +1 -0
- package/dist/cjs/rendering/RenderablePathSpec.js +1 -0
- package/dist/cjs/rendering/RenderingStyle.d.ts +1 -0
- package/dist/cjs/rendering/lib.d.ts +1 -0
- package/dist/cjs/rendering/lib.js +5 -1
- package/dist/cjs/rendering/renderers/AbstractRenderer.js +1 -1
- package/dist/cjs/shortcuts/KeyboardShortcutManager.d.ts +2 -2
- package/dist/cjs/shortcuts/KeyboardShortcutManager.js +2 -2
- package/dist/cjs/toolbar/localization.d.ts +1 -0
- package/dist/cjs/toolbar/localization.js +1 -0
- package/dist/cjs/toolbar/widgets/BaseWidget.js +5 -0
- package/dist/cjs/toolbar/widgets/DocumentPropertiesWidget.js +54 -25
- package/dist/cjs/toolbar/widgets/components/makeGridSelector.js +8 -0
- package/dist/cjs/tools/PanZoom.js +13 -8
- package/dist/cjs/tools/ScrollbarTool.d.ts +18 -0
- package/dist/cjs/tools/ScrollbarTool.js +85 -0
- package/dist/cjs/tools/SelectionTool/SelectionTool.selecting.test.d.ts +1 -0
- package/dist/cjs/tools/ToolController.js +2 -0
- package/dist/cjs/types.d.ts +3 -1
- package/dist/cjs/util/adjustEditorThemeForContrast.js +1 -0
- package/dist/cjs/util/assertions.d.ts +4 -0
- package/dist/cjs/util/assertions.js +12 -1
- package/dist/cjs/version.js +1 -1
- package/dist/mjs/Editor.d.ts +73 -40
- package/dist/mjs/Editor.mjs +90 -24
- package/dist/mjs/EditorImage.d.ts +58 -6
- package/dist/mjs/EditorImage.mjs +313 -61
- package/dist/mjs/SVGLoader.d.ts +10 -4
- package/dist/mjs/SVGLoader.mjs +29 -9
- package/dist/mjs/UndoRedoHistory.d.ts +2 -2
- package/dist/mjs/UndoRedoHistory.mjs +4 -2
- package/dist/mjs/Viewport.d.ts +2 -1
- package/dist/mjs/Viewport.mjs +12 -3
- package/dist/mjs/commands/Command.d.ts +1 -0
- package/dist/mjs/commands/Command.mjs +1 -0
- package/dist/mjs/commands/Erase.mjs +1 -1
- package/dist/mjs/commands/SerializableCommand.d.ts +1 -1
- package/dist/mjs/commands/SerializableCommand.mjs +16 -2
- package/dist/mjs/commands/localization.d.ts +2 -0
- package/dist/mjs/commands/localization.mjs +2 -0
- package/dist/mjs/components/AbstractComponent.d.ts +38 -0
- package/dist/mjs/components/AbstractComponent.mjs +30 -0
- package/dist/mjs/components/BackgroundComponent.d.ts +10 -1
- package/dist/mjs/components/BackgroundComponent.mjs +37 -6
- package/dist/mjs/components/SVGGlobalAttributesObject.d.ts +2 -1
- package/dist/mjs/components/SVGGlobalAttributesObject.mjs +7 -1
- package/dist/mjs/components/Stroke.d.ts +1 -0
- package/dist/mjs/components/Stroke.mjs +44 -0
- package/dist/mjs/components/UnknownSVGObject.d.ts +2 -1
- package/dist/mjs/components/UnknownSVGObject.mjs +7 -1
- package/dist/mjs/components/lib.d.ts +2 -2
- package/dist/mjs/components/lib.mjs +2 -2
- package/dist/mjs/lib.d.ts +2 -45
- package/dist/mjs/lib.mjs +2 -45
- package/dist/mjs/rendering/RenderablePathSpec.d.ts +1 -0
- package/dist/mjs/rendering/RenderablePathSpec.mjs +1 -0
- package/dist/mjs/rendering/RenderingStyle.d.ts +1 -0
- package/dist/mjs/rendering/lib.d.ts +1 -0
- package/dist/mjs/rendering/lib.mjs +1 -0
- package/dist/mjs/rendering/renderers/AbstractRenderer.mjs +1 -1
- package/dist/mjs/shortcuts/KeyboardShortcutManager.d.ts +2 -2
- package/dist/mjs/shortcuts/KeyboardShortcutManager.mjs +2 -2
- package/dist/mjs/toolbar/localization.d.ts +1 -0
- package/dist/mjs/toolbar/localization.mjs +1 -0
- package/dist/mjs/toolbar/widgets/BaseWidget.mjs +5 -0
- package/dist/mjs/toolbar/widgets/DocumentPropertiesWidget.mjs +54 -25
- package/dist/mjs/toolbar/widgets/components/makeGridSelector.mjs +8 -0
- package/dist/mjs/tools/PanZoom.mjs +13 -8
- package/dist/mjs/tools/ScrollbarTool.d.ts +18 -0
- package/dist/mjs/tools/ScrollbarTool.mjs +79 -0
- package/dist/mjs/tools/SelectionTool/SelectionTool.selecting.test.d.ts +1 -0
- package/dist/mjs/tools/ToolController.mjs +2 -0
- package/dist/mjs/types.d.ts +3 -1
- package/dist/mjs/util/adjustEditorThemeForContrast.mjs +1 -0
- package/dist/mjs/util/assertions.d.ts +4 -0
- package/dist/mjs/util/assertions.mjs +10 -0
- package/dist/mjs/version.mjs +1 -1
- package/package.json +3 -4
- package/src/Editor.scss +8 -0
- package/src/dialogs/dialogs.scss +2 -1
- package/src/toolbar/AbstractToolbar.scss +3 -0
- package/src/toolbar/EdgeToolbar.scss +4 -1
- package/src/toolbar/widgets/DocumentPropertiesWidget.scss +12 -0
- package/src/toolbar/widgets/components/makeGridSelector.scss +6 -1
- package/src/tools/ScrollbarTool.scss +57 -0
- package/src/tools/{SoundUITool.css → SoundUITool.scss} +4 -0
- package/src/tools/tools.scss +2 -1
package/dist/cjs/Editor.js
CHANGED
@@ -37,7 +37,7 @@ const EventDispatcher_1 = __importDefault(require("./EventDispatcher"));
|
|
37
37
|
const math_1 = require("@js-draw/math");
|
38
38
|
const Display_1 = __importStar(require("./rendering/Display"));
|
39
39
|
const SVGRenderer_1 = __importDefault(require("./rendering/renderers/SVGRenderer"));
|
40
|
-
const SVGLoader_1 =
|
40
|
+
const SVGLoader_1 = __importStar(require("./SVGLoader"));
|
41
41
|
const Pointer_1 = __importDefault(require("./Pointer"));
|
42
42
|
const getLocalizationTable_1 = __importDefault(require("./localizations/getLocalizationTable"));
|
43
43
|
const IconProvider_1 = __importDefault(require("./toolbar/IconProvider"));
|
@@ -58,25 +58,29 @@ const version_1 = __importDefault(require("./version"));
|
|
58
58
|
/**
|
59
59
|
* The main entrypoint for the full editor.
|
60
60
|
*
|
61
|
-
*
|
61
|
+
* ## Example
|
62
62
|
* To create an editor with a toolbar,
|
63
|
-
* ```
|
63
|
+
* ```ts,runnable
|
64
|
+
* import { Editor } from 'js-draw';
|
65
|
+
*
|
64
66
|
* const editor = new Editor(document.body);
|
65
67
|
*
|
66
68
|
* const toolbar = editor.addToolbar();
|
67
|
-
* toolbar.
|
69
|
+
* toolbar.addSaveButton(() => {
|
68
70
|
* const saveData = editor.toSVG().outerHTML;
|
69
71
|
* // Do something with saveData...
|
70
72
|
* });
|
71
73
|
* ```
|
72
74
|
*
|
73
75
|
* See also
|
74
|
-
* [`docs/example/example.ts`](https://github.com/personalizedrefrigerator/js-draw/blob/main/docs/demo/example.ts
|
76
|
+
* [`docs/example/example.ts`](https://github.com/personalizedrefrigerator/js-draw/blob/main/docs/demo/example.ts).
|
75
77
|
*/
|
76
78
|
class Editor {
|
77
79
|
/**
|
78
80
|
* @example
|
79
|
-
* ```
|
81
|
+
* ```ts,runnable
|
82
|
+
* import { Editor } from 'js-draw';
|
83
|
+
*
|
80
84
|
* const container = document.body;
|
81
85
|
*
|
82
86
|
* // Create an editor
|
@@ -89,13 +93,16 @@ class Editor {
|
|
89
93
|
* // Add the default toolbar
|
90
94
|
* const toolbar = editor.addToolbar();
|
91
95
|
*
|
92
|
-
*
|
96
|
+
* const createCustomIcon = () => {
|
97
|
+
* // Create/return an icon here.
|
98
|
+
* };
|
99
|
+
*
|
100
|
+
* // Add a custom button
|
93
101
|
* toolbar.addActionButton({
|
94
|
-
* label: '
|
95
|
-
* icon:
|
102
|
+
* label: 'Custom Button'
|
103
|
+
* icon: createCustomIcon(),
|
96
104
|
* }, () => {
|
97
|
-
*
|
98
|
-
* // Do something with saveData
|
105
|
+
* // Do something here
|
99
106
|
* });
|
100
107
|
* ```
|
101
108
|
*/
|
@@ -128,6 +135,10 @@ class Editor {
|
|
128
135
|
iconProvider: settings.iconProvider ?? new IconProvider_1.default(),
|
129
136
|
notices: [],
|
130
137
|
};
|
138
|
+
// Validate settings
|
139
|
+
if (this.settings.minZoom > this.settings.maxZoom) {
|
140
|
+
throw new Error('Minimum zoom must be lesser than maximum zoom!');
|
141
|
+
}
|
131
142
|
this.icons = this.settings.iconProvider;
|
132
143
|
this.shortcuts = new KeyboardShortcutManager_1.default(this.settings.keyboardShortcutOverrides);
|
133
144
|
this.container = document.createElement('div');
|
@@ -182,6 +193,10 @@ class Editor {
|
|
182
193
|
if (oldZoom <= this.settings.maxZoom && oldZoom >= this.settings.minZoom) {
|
183
194
|
resetTransform = evt.oldTransform;
|
184
195
|
}
|
196
|
+
else {
|
197
|
+
// If 1x zoom isn't acceptable, try a zoom between the minimum and maximum.
|
198
|
+
resetTransform = math_1.Mat33.scaling2D((this.settings.minZoom + this.settings.maxZoom) / 2);
|
199
|
+
}
|
185
200
|
this.viewport.resetTransform(resetTransform);
|
186
201
|
}
|
187
202
|
}
|
@@ -235,6 +250,7 @@ class Editor {
|
|
235
250
|
registerListeners() {
|
236
251
|
this.handlePointerEventsFrom(this.renderingRegion);
|
237
252
|
this.handleKeyEventsFrom(this.renderingRegion);
|
253
|
+
this.handlePointerEventsFrom(this.accessibilityAnnounceArea);
|
238
254
|
this.container.addEventListener('wheel', evt => {
|
239
255
|
let delta = math_1.Vec3.of(evt.deltaX, evt.deltaY, evt.deltaZ);
|
240
256
|
// Process wheel events if the ctrl key is down, even if disabled -- we do want to handle
|
@@ -311,6 +327,8 @@ class Editor {
|
|
311
327
|
// still fill the screen.
|
312
328
|
this.container.style.setProperty('--editor-current-width-px', `${this.container.clientWidth}px`);
|
313
329
|
this.container.style.setProperty('--editor-current-height-px', `${this.container.clientHeight}px`);
|
330
|
+
this.container.style.setProperty('--editor-current-display-width-px', `${this.renderingRegion.clientWidth}px`);
|
331
|
+
this.container.style.setProperty('--editor-current-display-height-px', `${this.renderingRegion.clientHeight}px`);
|
314
332
|
}
|
315
333
|
getPointerList() {
|
316
334
|
const nowTime = performance.now();
|
@@ -731,12 +749,12 @@ class Editor {
|
|
731
749
|
this.display.setDraftMode(false);
|
732
750
|
this.hideLoadingWarning();
|
733
751
|
}
|
734
|
-
// @see {@link
|
752
|
+
// @see {@link asyncApplyOrUnapplyCommands }
|
735
753
|
asyncApplyCommands(commands, chunkSize) {
|
736
754
|
return this.asyncApplyOrUnapplyCommands(commands, true, chunkSize);
|
737
755
|
}
|
738
756
|
// If `unapplyInReverseOrder`, commands are reversed before unapplying.
|
739
|
-
// @see {@link
|
757
|
+
// @see {@link asyncApplyOrUnapplyCommands }
|
740
758
|
asyncUnapplyCommands(commands, chunkSize, unapplyInReverseOrder = false) {
|
741
759
|
if (unapplyInReverseOrder) {
|
742
760
|
commands = [...commands]; // copy
|
@@ -783,8 +801,8 @@ class Editor {
|
|
783
801
|
}
|
784
802
|
const renderer = this.display.getDryInkRenderer();
|
785
803
|
this.image.renderWithCache(renderer, this.display.getCache(), this.viewport);
|
786
|
-
|
787
|
-
|
804
|
+
// Draw a rectangle around the region that will be visible on save
|
805
|
+
if (showImageBounds && !this.image.getAutoresizeEnabled()) {
|
788
806
|
const exportRectFill = { fill: math_1.Color4.fromHex('#44444455') };
|
789
807
|
const exportRectStrokeWidth = 5 * this.viewport.getSizeOfPixelOnCanvas();
|
790
808
|
renderer.drawRect(this.getImportExportRect(), exportRectStrokeWidth, exportRectFill);
|
@@ -807,6 +825,9 @@ class Editor {
|
|
807
825
|
/**
|
808
826
|
* Clears the wet ink display.
|
809
827
|
*
|
828
|
+
* The wet ink display can be used by the currently active tool to display a preview
|
829
|
+
* of an in-progress action.
|
830
|
+
*
|
810
831
|
* @see {@link Display.getWetInkRenderer}
|
811
832
|
*/
|
812
833
|
clearWetInk() {
|
@@ -822,16 +843,23 @@ class Editor {
|
|
822
843
|
* Creates an element that will be positioned on top of the dry/wet ink
|
823
844
|
* renderers.
|
824
845
|
*
|
846
|
+
* So as not to change the position of other overlays, `overlay` should either
|
847
|
+
* be styled to have 0 height or have `position: absolute`.
|
848
|
+
*
|
825
849
|
* This is useful for displaying content on top of the rendered content
|
826
850
|
* (e.g. a selection box).
|
827
851
|
*/
|
828
852
|
createHTMLOverlay(overlay) {
|
829
|
-
overlay.classList.add('overlay');
|
853
|
+
overlay.classList.add('overlay', 'js-draw-editor-overlay');
|
830
854
|
this.container.appendChild(overlay);
|
831
855
|
return {
|
832
856
|
remove: () => overlay.remove(),
|
833
857
|
};
|
834
858
|
}
|
859
|
+
/**
|
860
|
+
* Creates a CSS stylesheet with `content` and applies it to the document
|
861
|
+
* (and thus, to this editor).
|
862
|
+
*/
|
835
863
|
addStyleSheet(content) {
|
836
864
|
const styleSheet = document.createElement('style');
|
837
865
|
styleSheet.innerText = content;
|
@@ -912,11 +940,14 @@ class Editor {
|
|
912
940
|
}
|
913
941
|
}
|
914
942
|
}
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
943
|
+
/**
|
944
|
+
* Get a data URL (e.g. as produced by `HTMLCanvasElement::toDataURL`).
|
945
|
+
* If `format` is not `image/png`, a PNG image URL may still be returned (as in the
|
946
|
+
* case of `HTMLCanvasElement::toDataURL`).
|
947
|
+
*
|
948
|
+
* The export resolution is the same as the size of the drawing canvas, unless `outputSize`
|
949
|
+
* is given.
|
950
|
+
*/
|
920
951
|
toDataURL(format = 'image/png', outputSize) {
|
921
952
|
const canvas = document.createElement('canvas');
|
922
953
|
const importExportViewport = this.image.getImportExportViewport();
|
@@ -933,6 +964,12 @@ class Editor {
|
|
933
964
|
const dataURL = canvas.toDataURL(format);
|
934
965
|
return dataURL;
|
935
966
|
}
|
967
|
+
/**
|
968
|
+
* Converts the editor's content into an SVG image.
|
969
|
+
*
|
970
|
+
* @see
|
971
|
+
* {@link SVGRenderer}
|
972
|
+
*/
|
936
973
|
toSVG() {
|
937
974
|
const importExportViewport = this.image.getImportExportViewport().getTemporaryClone();
|
938
975
|
const sanitize = false;
|
@@ -948,6 +985,12 @@ class Editor {
|
|
948
985
|
result.setAttribute('viewBox', [rect.x, rect.y, rect.w, rect.h].map(part => (0, math_1.toRoundedString)(part)).join(' '));
|
949
986
|
result.setAttribute('width', (0, math_1.toRoundedString)(rect.w));
|
950
987
|
result.setAttribute('height', (0, math_1.toRoundedString)(rect.h));
|
988
|
+
if (this.image.getAutoresizeEnabled()) {
|
989
|
+
result.classList.add(SVGLoader_1.svgLoaderAutoresizeClassName);
|
990
|
+
}
|
991
|
+
else {
|
992
|
+
result.classList.remove(SVGLoader_1.svgLoaderAutoresizeClassName);
|
993
|
+
}
|
951
994
|
return result;
|
952
995
|
}
|
953
996
|
/**
|
@@ -960,6 +1003,7 @@ class Editor {
|
|
960
1003
|
this.display.setDraftMode(true);
|
961
1004
|
const originalBackgrounds = this.image.getBackgroundComponents();
|
962
1005
|
const eraseBackgroundCommand = new Erase_1.default(originalBackgrounds);
|
1006
|
+
let autoresizeEnabled = false;
|
963
1007
|
await loader.start(async (component) => {
|
964
1008
|
await this.dispatchNoAnnounce(EditorImage_1.default.addElement(component));
|
965
1009
|
}, (countProcessed, totalToProcess) => {
|
@@ -969,10 +1013,17 @@ class Editor {
|
|
969
1013
|
return (0, untilNextAnimationFrame_1.default)();
|
970
1014
|
}
|
971
1015
|
return null;
|
972
|
-
}, (importExportRect) => {
|
1016
|
+
}, (importExportRect, options) => {
|
973
1017
|
this.dispatchNoAnnounce(this.setImportExportRect(importExportRect), false);
|
974
1018
|
this.dispatchNoAnnounce(this.viewport.zoomTo(importExportRect), false);
|
1019
|
+
if (options) {
|
1020
|
+
autoresizeEnabled = options.autoresize;
|
1021
|
+
}
|
975
1022
|
});
|
1023
|
+
// TODO: Move this call into the callback above. Currently, this would cause
|
1024
|
+
// decrease in performance as the main background would be repeatedly added
|
1025
|
+
// and removed from the editor every time another component is added.
|
1026
|
+
this.dispatchNoAnnounce(this.image.setAutoresizeEnabled(autoresizeEnabled), false);
|
976
1027
|
// Ensure that we don't have multiple overlapping BackgroundComponents. Remove
|
977
1028
|
// old BackgroundComponents.
|
978
1029
|
// Overlapping BackgroundComponents may cause changing the background color to
|
@@ -1033,8 +1084,23 @@ class Editor {
|
|
1033
1084
|
/**
|
1034
1085
|
* Alias for `loadFrom(SVGLoader.fromString)`.
|
1035
1086
|
*
|
1036
|
-
*
|
1037
|
-
*
|
1087
|
+
* @example
|
1088
|
+
* ```ts,runnable
|
1089
|
+
* import {Editor} from 'js-draw';
|
1090
|
+
* const editor = new Editor(document.body);
|
1091
|
+
*
|
1092
|
+
* ---visible---
|
1093
|
+
* await editor.loadFromSVG(`
|
1094
|
+
* <svg viewBox="5 23 52 30" width="52" height="16" version="1.1" baseProfile="full" xmlns="http://www.w3.org/2000/svg">
|
1095
|
+
* <text style="
|
1096
|
+
* transform: matrix(0.181846, 0.1, 0, 0.181846, 11.4, 33.2);
|
1097
|
+
* font-family: serif;
|
1098
|
+
* font-size: 32px;
|
1099
|
+
* fill: rgb(100, 140, 61);
|
1100
|
+
* ">An SVG image!</text>
|
1101
|
+
* </svg>
|
1102
|
+
* `);
|
1103
|
+
* ```
|
1038
1104
|
*/
|
1039
1105
|
async loadFromSVG(svgData, sanitize = false) {
|
1040
1106
|
const loader = SVGLoader_1.default.fromString(svgData, sanitize);
|
@@ -5,9 +5,11 @@ import { Rect2 } from '@js-draw/math';
|
|
5
5
|
import RenderingCache from './rendering/caching/RenderingCache';
|
6
6
|
import SerializableCommand from './commands/SerializableCommand';
|
7
7
|
import EventDispatcher from './EventDispatcher';
|
8
|
+
import Command from './commands/Command';
|
8
9
|
export declare const sortLeavesByZIndex: (leaves: Array<ImageNode>) => void;
|
9
10
|
export declare enum EditorImageEventType {
|
10
|
-
ExportViewportChanged = 0
|
11
|
+
ExportViewportChanged = 0,
|
12
|
+
AutoresizeModeChanged = 1
|
11
13
|
}
|
12
14
|
export type EditorImageNotifier = EventDispatcher<EditorImageEventType, {
|
13
15
|
image: EditorImage;
|
@@ -19,6 +21,7 @@ export default class EditorImage {
|
|
19
21
|
private componentCount;
|
20
22
|
/** Viewport for the exported/imported image. */
|
21
23
|
private importExportViewport;
|
24
|
+
private shouldAutoresizeExportViewport;
|
22
25
|
readonly notifier: EditorImageNotifier;
|
23
26
|
constructor();
|
24
27
|
getBackgroundComponents(): AbstractComponent[];
|
@@ -35,14 +38,20 @@ export default class EditorImage {
|
|
35
38
|
render(renderer: AbstractRenderer, viewport: Viewport | null): void;
|
36
39
|
/** Renders all nodes, even ones not within the viewport. @internal */
|
37
40
|
renderAll(renderer: AbstractRenderer): void;
|
38
|
-
/**
|
41
|
+
/**
|
42
|
+
* @returns all elements in the image, sorted by z-index. This can be slow for large images.
|
43
|
+
*
|
44
|
+
* Does not include background elements. See {@link getBackgroundComponents}.
|
45
|
+
*/
|
39
46
|
getAllElements(): AbstractComponent[];
|
40
47
|
/** Returns the number of elements added to this image. @internal */
|
41
48
|
estimateNumElements(): number;
|
42
49
|
/** @returns a list of `AbstractComponent`s intersecting `region`, sorted by z-index. */
|
43
|
-
getElementsIntersectingRegion(region: Rect2): AbstractComponent[];
|
44
|
-
/** Called whenever an element is completely removed. @internal */
|
50
|
+
getElementsIntersectingRegion(region: Rect2, includeBackground?: boolean): AbstractComponent[];
|
51
|
+
/** Called whenever (just after) an element is completely removed. @internal */
|
45
52
|
onDestroyElement(elem: AbstractComponent): void;
|
53
|
+
/** Called just after an element is added. @internal */
|
54
|
+
private onElementAdded;
|
46
55
|
/**
|
47
56
|
* @returns the AbstractComponent with `id`, if it exists.
|
48
57
|
*
|
@@ -66,11 +75,40 @@ export default class EditorImage {
|
|
66
75
|
* @returns a `Viewport` for rendering the image when importing/exporting.
|
67
76
|
*/
|
68
77
|
getImportExportViewport(): Viewport;
|
78
|
+
/**
|
79
|
+
* @see {@link setImportExportRect}
|
80
|
+
*/
|
81
|
+
getImportExportRect(): Rect2;
|
82
|
+
/**
|
83
|
+
* Sets the import/export rectangle to the given `imageRect`. Disables
|
84
|
+
* autoresize (if it was previously enabled).
|
85
|
+
*/
|
69
86
|
setImportExportRect(imageRect: Rect2): SerializableCommand;
|
87
|
+
getAutoresizeEnabled(): boolean;
|
88
|
+
/** Returns a `Command` that sets whether the image should autoresize. */
|
89
|
+
setAutoresizeEnabled(autoresize: boolean): Command;
|
90
|
+
private setAutoresizeEnabledDirectly;
|
91
|
+
/** Updates the size/position of the viewport */
|
92
|
+
private autoresizeExportViewport;
|
93
|
+
private settingExportRect;
|
94
|
+
/**
|
95
|
+
* Sets the import/export viewport directly, without returning a `Command`.
|
96
|
+
* As such, this is not undoable.
|
97
|
+
*
|
98
|
+
* See setImportExportRect
|
99
|
+
*
|
100
|
+
* Returns true if changes to the viewport were made (and thus
|
101
|
+
* ExportViewportChanged was fired.)
|
102
|
+
*/
|
103
|
+
private setExportRectDirectly;
|
104
|
+
private onExportViewportChanged;
|
70
105
|
private static SetImportExportRectCommand;
|
71
106
|
}
|
72
107
|
type TooSmallToRenderCheck = (rect: Rect2) => boolean;
|
73
|
-
/**
|
108
|
+
/**
|
109
|
+
* Part of the Editor's image. Does not handle fullscreen/invisible components.
|
110
|
+
* @internal
|
111
|
+
*/
|
74
112
|
export declare class ImageNode {
|
75
113
|
private parent;
|
76
114
|
private content;
|
@@ -84,17 +122,31 @@ export declare class ImageNode {
|
|
84
122
|
onContentChange(): void;
|
85
123
|
getContent(): AbstractComponent | null;
|
86
124
|
getParent(): ImageNode | null;
|
87
|
-
|
125
|
+
protected getChildrenIntersectingRegion(region: Rect2, isTooSmallFilter?: TooSmallToRenderCheck): ImageNode[];
|
88
126
|
getChildrenOrSelfIntersectingRegion(region: Rect2): ImageNode[];
|
89
127
|
getLeavesIntersectingRegion(region: Rect2, isTooSmall?: TooSmallToRenderCheck): ImageNode[];
|
90
128
|
getChildWithContent(target: AbstractComponent): ImageNode | null;
|
91
129
|
getLeaves(): ImageNode[];
|
92
130
|
addLeaf(leaf: AbstractComponent): ImageNode;
|
131
|
+
protected static createLeafNode(parent: ImageNode, content: AbstractComponent): ImageNode;
|
93
132
|
getBBox(): Rect2;
|
94
133
|
recomputeBBox(bubbleUp: boolean): void;
|
134
|
+
private unionBBoxWith;
|
95
135
|
private updateParents;
|
96
136
|
private rebalance;
|
137
|
+
protected removeChild(child: ImageNode): void;
|
97
138
|
remove(): void;
|
98
139
|
render(renderer: AbstractRenderer, visibleRect?: Rect2): void;
|
140
|
+
renderDebugBoundingBoxes(renderer: AbstractRenderer, visibleRect: Rect2, depth?: number): void;
|
141
|
+
}
|
142
|
+
/** An `ImageNode` that can properly handle fullscreen/data components. @internal */
|
143
|
+
export declare class RootImageNode extends ImageNode {
|
144
|
+
private fullscreenChildren;
|
145
|
+
private dataComponents;
|
146
|
+
protected getChildrenIntersectingRegion(region: Rect2, _isTooSmall?: TooSmallToRenderCheck): ImageNode[];
|
147
|
+
getLeaves(): ImageNode[];
|
148
|
+
removeChild(child: ImageNode): void;
|
149
|
+
getChildWithContent(target: AbstractComponent): ImageNode | null;
|
150
|
+
addLeaf(leafContent: AbstractComponent): ImageNode;
|
99
151
|
}
|
100
152
|
export {};
|