js-draw 1.0.1 → 1.0.2

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.
Files changed (182) hide show
  1. package/LICENSE +21 -0
  2. package/dist/bundle.js +1 -1
  3. package/dist/cjs/version.js +1 -1
  4. package/dist/mjs/version.mjs +1 -1
  5. package/docs/img/readme-images/js-draw.jpg +0 -0
  6. package/docs/img/readme-images/unsupported-elements--in-editor.png +0 -0
  7. package/package.json +5 -4
  8. package/dist-test/test_imports/package-lock.json +0 -13
  9. package/dist-test/test_imports/package.json +0 -12
  10. package/dist-test/test_imports/test-imports.js +0 -11
  11. package/dist-test/test_imports/test-require.cjs +0 -14
  12. package/src/Editor.loadFrom.test.ts +0 -24
  13. package/src/Editor.test.ts +0 -107
  14. package/src/Editor.toSVG.test.ts +0 -294
  15. package/src/Editor.ts +0 -1443
  16. package/src/EditorImage.test.ts +0 -117
  17. package/src/EditorImage.ts +0 -609
  18. package/src/EventDispatcher.test.ts +0 -123
  19. package/src/EventDispatcher.ts +0 -72
  20. package/src/Pointer.ts +0 -183
  21. package/src/SVGLoader.test.ts +0 -114
  22. package/src/SVGLoader.ts +0 -672
  23. package/src/UndoRedoHistory.test.ts +0 -34
  24. package/src/UndoRedoHistory.ts +0 -102
  25. package/src/Viewport.ts +0 -322
  26. package/src/bundle/bundled.ts +0 -7
  27. package/src/commands/Command.ts +0 -45
  28. package/src/commands/Duplicate.ts +0 -75
  29. package/src/commands/Erase.ts +0 -95
  30. package/src/commands/SerializableCommand.ts +0 -49
  31. package/src/commands/UnresolvedCommand.ts +0 -37
  32. package/src/commands/invertCommand.ts +0 -58
  33. package/src/commands/lib.ts +0 -16
  34. package/src/commands/localization.ts +0 -47
  35. package/src/commands/uniteCommands.test.ts +0 -23
  36. package/src/commands/uniteCommands.ts +0 -140
  37. package/src/components/AbstractComponent.transformBy.test.ts +0 -23
  38. package/src/components/AbstractComponent.ts +0 -383
  39. package/src/components/BackgroundComponent.test.ts +0 -44
  40. package/src/components/BackgroundComponent.ts +0 -348
  41. package/src/components/ImageComponent.ts +0 -176
  42. package/src/components/RestylableComponent.ts +0 -161
  43. package/src/components/SVGGlobalAttributesObject.ts +0 -79
  44. package/src/components/Stroke.test.ts +0 -137
  45. package/src/components/Stroke.ts +0 -294
  46. package/src/components/TextComponent.test.ts +0 -202
  47. package/src/components/TextComponent.ts +0 -429
  48. package/src/components/UnknownSVGObject.test.ts +0 -10
  49. package/src/components/UnknownSVGObject.ts +0 -60
  50. package/src/components/builders/ArrowBuilder.ts +0 -106
  51. package/src/components/builders/CircleBuilder.ts +0 -100
  52. package/src/components/builders/FreehandLineBuilder.test.ts +0 -24
  53. package/src/components/builders/FreehandLineBuilder.ts +0 -210
  54. package/src/components/builders/LineBuilder.ts +0 -77
  55. package/src/components/builders/PressureSensitiveFreehandLineBuilder.ts +0 -453
  56. package/src/components/builders/RectangleBuilder.ts +0 -73
  57. package/src/components/builders/types.ts +0 -15
  58. package/src/components/lib.ts +0 -31
  59. package/src/components/localization.ts +0 -24
  60. package/src/components/util/StrokeSmoother.ts +0 -302
  61. package/src/components/util/describeComponentList.ts +0 -18
  62. package/src/dialogs/makeAboutDialog.ts +0 -82
  63. package/src/inputEvents.ts +0 -143
  64. package/src/lib.ts +0 -91
  65. package/src/localization.ts +0 -34
  66. package/src/localizations/de.ts +0 -146
  67. package/src/localizations/en.ts +0 -8
  68. package/src/localizations/es.ts +0 -74
  69. package/src/localizations/getLocalizationTable.test.ts +0 -27
  70. package/src/localizations/getLocalizationTable.ts +0 -74
  71. package/src/rendering/Display.ts +0 -247
  72. package/src/rendering/RenderablePathSpec.ts +0 -88
  73. package/src/rendering/RenderingStyle.test.ts +0 -68
  74. package/src/rendering/RenderingStyle.ts +0 -55
  75. package/src/rendering/TextRenderingStyle.ts +0 -55
  76. package/src/rendering/caching/CacheRecord.test.ts +0 -48
  77. package/src/rendering/caching/CacheRecord.ts +0 -76
  78. package/src/rendering/caching/CacheRecordManager.ts +0 -71
  79. package/src/rendering/caching/RenderingCache.test.ts +0 -43
  80. package/src/rendering/caching/RenderingCache.ts +0 -66
  81. package/src/rendering/caching/RenderingCacheNode.ts +0 -404
  82. package/src/rendering/caching/testUtils.ts +0 -35
  83. package/src/rendering/caching/types.ts +0 -34
  84. package/src/rendering/lib.ts +0 -8
  85. package/src/rendering/localization.ts +0 -20
  86. package/src/rendering/renderers/AbstractRenderer.ts +0 -232
  87. package/src/rendering/renderers/CanvasRenderer.ts +0 -312
  88. package/src/rendering/renderers/DummyRenderer.test.ts +0 -41
  89. package/src/rendering/renderers/DummyRenderer.ts +0 -142
  90. package/src/rendering/renderers/SVGRenderer.ts +0 -434
  91. package/src/rendering/renderers/TextOnlyRenderer.test.ts +0 -34
  92. package/src/rendering/renderers/TextOnlyRenderer.ts +0 -68
  93. package/src/shortcuts/KeyBinding.test.ts +0 -61
  94. package/src/shortcuts/KeyBinding.ts +0 -257
  95. package/src/shortcuts/KeyboardShortcutManager.test.ts +0 -95
  96. package/src/shortcuts/KeyboardShortcutManager.ts +0 -163
  97. package/src/shortcuts/lib.ts +0 -3
  98. package/src/testing/createEditor.ts +0 -11
  99. package/src/testing/getUniquePointerId.ts +0 -18
  100. package/src/testing/lib.ts +0 -3
  101. package/src/testing/sendPenEvent.ts +0 -36
  102. package/src/testing/sendTouchEvent.ts +0 -71
  103. package/src/toolbar/AbstractToolbar.ts +0 -542
  104. package/src/toolbar/DropdownToolbar.ts +0 -220
  105. package/src/toolbar/EdgeToolbar.test.ts +0 -54
  106. package/src/toolbar/EdgeToolbar.ts +0 -543
  107. package/src/toolbar/IconProvider.ts +0 -861
  108. package/src/toolbar/constants.ts +0 -1
  109. package/src/toolbar/lib.ts +0 -6
  110. package/src/toolbar/localization.ts +0 -136
  111. package/src/toolbar/types.ts +0 -13
  112. package/src/toolbar/widgets/ActionButtonWidget.ts +0 -39
  113. package/src/toolbar/widgets/BaseToolWidget.ts +0 -81
  114. package/src/toolbar/widgets/BaseWidget.ts +0 -495
  115. package/src/toolbar/widgets/DocumentPropertiesWidget.ts +0 -250
  116. package/src/toolbar/widgets/EraserToolWidget.ts +0 -84
  117. package/src/toolbar/widgets/HandToolWidget.ts +0 -239
  118. package/src/toolbar/widgets/InsertImageWidget.ts +0 -248
  119. package/src/toolbar/widgets/OverflowWidget.ts +0 -92
  120. package/src/toolbar/widgets/PenToolWidget.ts +0 -369
  121. package/src/toolbar/widgets/SelectionToolWidget.ts +0 -195
  122. package/src/toolbar/widgets/TextToolWidget.ts +0 -149
  123. package/src/toolbar/widgets/components/makeColorInput.ts +0 -184
  124. package/src/toolbar/widgets/components/makeFileInput.ts +0 -128
  125. package/src/toolbar/widgets/components/makeGridSelector.ts +0 -179
  126. package/src/toolbar/widgets/components/makeSeparator.ts +0 -17
  127. package/src/toolbar/widgets/components/makeThicknessSlider.ts +0 -62
  128. package/src/toolbar/widgets/keybindings.ts +0 -19
  129. package/src/toolbar/widgets/layout/DropdownLayoutManager.ts +0 -262
  130. package/src/toolbar/widgets/layout/EdgeToolbarLayoutManager.ts +0 -71
  131. package/src/toolbar/widgets/layout/types.ts +0 -74
  132. package/src/toolbar/widgets/lib.ts +0 -13
  133. package/src/tools/BaseTool.ts +0 -169
  134. package/src/tools/Eraser.test.ts +0 -103
  135. package/src/tools/Eraser.ts +0 -173
  136. package/src/tools/FindTool.test.ts +0 -67
  137. package/src/tools/FindTool.ts +0 -153
  138. package/src/tools/InputFilter/FunctionMapper.ts +0 -17
  139. package/src/tools/InputFilter/InputMapper.ts +0 -41
  140. package/src/tools/InputFilter/InputPipeline.test.ts +0 -41
  141. package/src/tools/InputFilter/InputPipeline.ts +0 -34
  142. package/src/tools/InputFilter/InputStabilizer.ts +0 -254
  143. package/src/tools/InputFilter/StrokeKeyboardControl.ts +0 -104
  144. package/src/tools/PanZoom.test.ts +0 -339
  145. package/src/tools/PanZoom.ts +0 -525
  146. package/src/tools/PasteHandler.ts +0 -94
  147. package/src/tools/Pen.test.ts +0 -260
  148. package/src/tools/Pen.ts +0 -284
  149. package/src/tools/PipetteTool.ts +0 -84
  150. package/src/tools/SelectionTool/SelectAllShortcutHandler.ts +0 -29
  151. package/src/tools/SelectionTool/Selection.ts +0 -647
  152. package/src/tools/SelectionTool/SelectionHandle.ts +0 -142
  153. package/src/tools/SelectionTool/SelectionTool.test.ts +0 -370
  154. package/src/tools/SelectionTool/SelectionTool.ts +0 -510
  155. package/src/tools/SelectionTool/TransformMode.ts +0 -112
  156. package/src/tools/SelectionTool/types.ts +0 -11
  157. package/src/tools/SoundUITool.ts +0 -221
  158. package/src/tools/TextTool.ts +0 -339
  159. package/src/tools/ToolController.ts +0 -224
  160. package/src/tools/ToolEnabledGroup.ts +0 -14
  161. package/src/tools/ToolSwitcherShortcut.ts +0 -39
  162. package/src/tools/ToolbarShortcutHandler.ts +0 -39
  163. package/src/tools/UndoRedoShortcut.test.ts +0 -62
  164. package/src/tools/UndoRedoShortcut.ts +0 -24
  165. package/src/tools/keybindings.ts +0 -85
  166. package/src/tools/lib.ts +0 -22
  167. package/src/tools/localization.ts +0 -76
  168. package/src/types.ts +0 -151
  169. package/src/util/ReactiveValue.test.ts +0 -168
  170. package/src/util/ReactiveValue.ts +0 -241
  171. package/src/util/assertions.ts +0 -55
  172. package/src/util/fileToBase64.ts +0 -18
  173. package/src/util/guessKeyCodeFromKey.ts +0 -36
  174. package/src/util/listPrefixMatch.ts +0 -19
  175. package/src/util/stopPropagationOfScrollingWheelEvents.ts +0 -20
  176. package/src/util/untilNextAnimationFrame.ts +0 -9
  177. package/src/util/waitForAll.ts +0 -18
  178. package/src/util/waitForTimeout.ts +0 -9
  179. package/src/version.test.ts +0 -12
  180. package/src/version.ts +0 -3
  181. package/tools/allLocales.js +0 -4
  182. package/tools/copyREADME.ts +0 -62
@@ -1,37 +0,0 @@
1
- import EditorImage from '../EditorImage';
2
- import AbstractComponent from '../components/AbstractComponent';
3
- import SerializableCommand from './SerializableCommand';
4
-
5
- export type ResolveFromComponentCallback = () => SerializableCommand;
6
-
7
- /**
8
- * A command that requires a component that may or may not be present in the editor when
9
- * the command is created.
10
- */
11
- export default abstract class UnresolvedSerializableCommand extends SerializableCommand {
12
- protected component: AbstractComponent|null;
13
- protected readonly componentID: string;
14
-
15
- protected constructor(
16
- commandId: string,
17
- componentID: string,
18
- component?: AbstractComponent
19
- ) {
20
- super(commandId);
21
- this.component = component ?? null;
22
- this.componentID = componentID;
23
- }
24
-
25
- protected resolveComponent(image: EditorImage) {
26
- if (this.component) {
27
- return;
28
- }
29
-
30
- const component = image.lookupElement(this.componentID);
31
- if (!component) {
32
- throw new Error(`Unable to resolve component with ID ${this.componentID}`);
33
- }
34
-
35
- this.component = component;
36
- }
37
- }
@@ -1,58 +0,0 @@
1
- import Editor from '../Editor';
2
- import { EditorLocalization } from '../localization';
3
- import Command from './Command';
4
- import SerializableCommand from './SerializableCommand';
5
-
6
- // Returns a command that does the opposite of the given command --- `result.apply()` calls
7
- // `command.unapply()` and `result.unapply()` calls `command.apply()`.
8
- const invertCommand = <T extends Command> (command: T): T extends SerializableCommand ? SerializableCommand : Command => {
9
- if (command instanceof SerializableCommand) {
10
- // SerializableCommand that does the inverse of [command]
11
- return new class extends SerializableCommand {
12
- protected serializeToJSON() {
13
- return command.serialize();
14
- }
15
- public apply(editor: Editor) {
16
- command.unapply(editor);
17
- }
18
- public unapply(editor: Editor) {
19
- command.unapply(editor);
20
- }
21
- public override onDrop(editor: Editor) {
22
- command.onDrop(editor);
23
- }
24
- public description(editor: Editor, localizationTable: EditorLocalization): string {
25
- return localizationTable.inverseOf(command.description(editor, localizationTable));
26
- }
27
- }('inverse');
28
- } else {
29
- // Command that does the inverse of [command].
30
- const result = new class extends Command {
31
- public apply(editor: Editor) {
32
- command.unapply(editor);
33
- }
34
-
35
- public unapply(editor: Editor) {
36
- command.apply(editor);
37
- }
38
-
39
- public override onDrop(editor: Editor) {
40
- command.onDrop(editor);
41
- }
42
-
43
- public description(editor: Editor, localizationTable: EditorLocalization) {
44
- return localizationTable.inverseOf(command.description(editor, localizationTable));
45
- }
46
- };
47
-
48
- // We know that T does not extend SerializableCommand, and thus returning a Command
49
- // is appropriate.
50
- return result as any;
51
- }
52
- };
53
-
54
- SerializableCommand.register('inverse', (data, editor) => {
55
- return invertCommand(SerializableCommand.deserialize(data, editor));
56
- });
57
-
58
- export default invertCommand;
@@ -1,16 +0,0 @@
1
- import Command from './Command';
2
- import Duplicate from './Duplicate';
3
- import Erase from './Erase';
4
- import invertCommand from './invertCommand';
5
- import SerializableCommand from './SerializableCommand';
6
- import uniteCommands from './uniteCommands';
7
-
8
- export {
9
- Command,
10
- Duplicate,
11
- Erase,
12
- SerializableCommand,
13
-
14
- invertCommand,
15
- uniteCommands,
16
- };
@@ -1,47 +0,0 @@
1
- import { Rect2 } from '@js-draw/math';
2
-
3
- export interface CommandLocalization {
4
- movedLeft: string;
5
- movedUp: string;
6
- movedDown: string;
7
- movedRight: string;
8
- rotatedBy: (degrees: number) => string;
9
- zoomedOut: string;
10
- zoomedIn: string;
11
- erasedNoElements: string;
12
- duplicatedNoElements: string;
13
- elements: string;
14
- updatedViewport: string;
15
- transformedElements: (elemCount: number) => string;
16
- resizeOutputCommand: (newSize: Rect2) => string;
17
- addElementAction: (elemDescription: string) => string;
18
- eraseAction: (elemDescription: string, numElems: number) => string;
19
- duplicateAction: (elemDescription: string, count: number)=> string;
20
- inverseOf: (actionDescription: string)=> string;
21
- unionOf: (actionDescription: string, actionCount: number)=> string;
22
-
23
- selectedElements: (count: number)=>string;
24
- }
25
-
26
- export const defaultCommandLocalization: CommandLocalization = {
27
- updatedViewport: 'Transformed Viewport',
28
- transformedElements: (elemCount) => `Transformed ${elemCount} element${elemCount === 1 ? '' : 's'}`,
29
- resizeOutputCommand: (newSize: Rect2) => `Resized image to ${newSize.w}x${newSize.h}`,
30
- addElementAction: (componentDescription: string) => `Added ${componentDescription}`,
31
- eraseAction: (componentDescription: string, numElems: number) => `Erased ${numElems} ${componentDescription}`,
32
- duplicateAction: (componentDescription: string, numElems: number) => `Duplicated ${numElems} ${componentDescription}`,
33
- unionOf: (actionDescription: string, actionCount: number) => `Union: ${actionCount} ${actionDescription}`,
34
- inverseOf: (actionDescription: string) => `Inverse of ${actionDescription}`,
35
- elements: 'Elements',
36
- erasedNoElements: 'Erased nothing',
37
- duplicatedNoElements: 'Duplicated nothing',
38
-
39
- rotatedBy: (degrees) => `Rotated by ${Math.abs(degrees)} degrees ${degrees < 0 ? 'clockwise' : 'counter-clockwise'}`,
40
- movedLeft: 'Moved left',
41
- movedUp: 'Moved up',
42
- movedDown: 'Moved down',
43
- movedRight: 'Moved right',
44
- zoomedOut: 'Zoomed out',
45
- zoomedIn: 'Zoomed in',
46
- selectedElements: (count) => `Selected ${count} element${count === 1 ? '' : 's'}`,
47
- };
@@ -1,23 +0,0 @@
1
- import { Color4, EditorImage, Mat33, Path, SerializableCommand, StrokeComponent, Vec2 } from '../lib';
2
- import uniteCommands from './uniteCommands';
3
- import createEditor from '../testing/createEditor';
4
- import { pathToRenderable } from '../rendering/RenderablePathSpec';
5
-
6
- describe('uniteCommands', () => {
7
- it('should be serializable and deserializable', () => {
8
- const editor = createEditor();
9
- const stroke = new StrokeComponent([ pathToRenderable(Path.fromString('m0,0 l10,10 h-2 z'), { fill: Color4.red }) ]);
10
- const union = uniteCommands([
11
- EditorImage.addElement(stroke),
12
- stroke.transformBy(Mat33.translation(Vec2.of(1, 10))),
13
- ]);
14
- const deserialized = SerializableCommand.deserialize(union.serialize(), editor);
15
-
16
- deserialized.apply(editor);
17
-
18
- const lookupResult = editor.image.lookupElement(stroke.getId());
19
- expect(lookupResult).not.toBeNull();
20
- expect(lookupResult?.getBBox().topLeft).toMatchObject(Vec2.of(1, 10));
21
- expect(lookupResult?.getBBox().bottomRight).toMatchObject(Vec2.of(11, 20));
22
- });
23
- });
@@ -1,140 +0,0 @@
1
- import Editor from '../Editor';
2
- import { EditorLocalization } from '../localization';
3
- import waitForAll from '../util/waitForAll';
4
- import Command from './Command';
5
- import SerializableCommand from './SerializableCommand';
6
-
7
-
8
- class NonSerializableUnion extends Command {
9
- public constructor(private commands: Command[], private applyChunkSize: number|undefined) {
10
- super();
11
- }
12
-
13
- public apply(editor: Editor) {
14
- if (this.applyChunkSize === undefined) {
15
- const results = this.commands.map(cmd => cmd.apply(editor));
16
- return waitForAll(results);
17
- } else {
18
- return editor.asyncApplyCommands(this.commands, this.applyChunkSize);
19
- }
20
- }
21
-
22
- public unapply(editor: Editor) {
23
- const commands = [ ...this.commands ];
24
- commands.reverse();
25
-
26
- if (this.applyChunkSize === undefined) {
27
- const results = commands.map(cmd => cmd.unapply(editor));
28
- return waitForAll(results);
29
- } else {
30
- return editor.asyncUnapplyCommands(commands, this.applyChunkSize, false);
31
- }
32
- }
33
-
34
- public override onDrop(editor: Editor): void {
35
- this.commands.forEach(command => command.onDrop(editor));
36
- }
37
-
38
- public description(editor: Editor, localizationTable: EditorLocalization) {
39
- const descriptions: string[] = [];
40
-
41
- let lastDescription: string|null = null;
42
- let duplicateDescriptionCount: number = 0;
43
- for (const part of this.commands) {
44
- const description = part.description(editor, localizationTable);
45
- if (description !== lastDescription && lastDescription !== null) {
46
- descriptions.push(localizationTable.unionOf(lastDescription, duplicateDescriptionCount));
47
- lastDescription = null;
48
- duplicateDescriptionCount = 0;
49
- }
50
-
51
- duplicateDescriptionCount ++;
52
- lastDescription ??= description;
53
- }
54
-
55
- if (duplicateDescriptionCount > 1) {
56
- descriptions.push(localizationTable.unionOf(lastDescription!, duplicateDescriptionCount));
57
- } else if (duplicateDescriptionCount === 1) {
58
- descriptions.push(lastDescription!);
59
- }
60
-
61
- return descriptions.join(', ');
62
- }
63
- }
64
-
65
- class SerializableUnion extends SerializableCommand {
66
- private nonserializableCommand: NonSerializableUnion;
67
- private serializedData: any;
68
-
69
- public constructor(private commands: SerializableCommand[], private applyChunkSize: number|undefined) {
70
- super('union');
71
- this.nonserializableCommand = new NonSerializableUnion(commands, applyChunkSize);
72
- }
73
-
74
- protected serializeToJSON() {
75
- if (this.serializedData) {
76
- return this.serializedData;
77
- }
78
-
79
- return {
80
- applyChunkSize: this.applyChunkSize,
81
- data: this.commands.map(command => command.serialize()),
82
- };
83
- }
84
-
85
- public apply(editor: Editor) {
86
- // Cache this' serialized form -- applying this may change how commands serialize.
87
- this.serializedData = this.serializeToJSON();
88
-
89
- return this.nonserializableCommand.apply(editor);
90
- }
91
-
92
- public unapply(editor: Editor) {
93
- return this.nonserializableCommand.unapply(editor);
94
- }
95
-
96
- public override onDrop(editor: Editor): void {
97
- this.nonserializableCommand.onDrop(editor);
98
- }
99
-
100
- public description(editor: Editor, localizationTable: EditorLocalization): string {
101
- return this.nonserializableCommand.description(editor, localizationTable);
102
- }
103
- }
104
-
105
- const uniteCommands = <T extends Command> (commands: T[], applyChunkSize?: number): T extends SerializableCommand ? SerializableCommand : Command => {
106
- let allSerializable = true;
107
- for (const command of commands) {
108
- if (!(command instanceof SerializableCommand)) {
109
- allSerializable = false;
110
- break;
111
- }
112
- }
113
-
114
- if (!allSerializable) {
115
- return new NonSerializableUnion(commands, applyChunkSize) as any;
116
- } else {
117
- const castedCommands = commands as any[] as SerializableCommand[];
118
- return new SerializableUnion(castedCommands, applyChunkSize);
119
- }
120
- };
121
-
122
- SerializableCommand.register('union', (data: any, editor) => {
123
- if (typeof data.data.length !== 'number') {
124
- throw new Error('Unions of commands must serialize to lists of serialization data.');
125
- }
126
- const applyChunkSize: number|undefined = data.applyChunkSize;
127
- if (typeof applyChunkSize !== 'number' && applyChunkSize !== undefined) {
128
- throw new Error('serialized applyChunkSize is neither undefined nor a number.');
129
- }
130
-
131
- const commands: SerializableCommand[] = [];
132
- for (const part of data.data as any[]) {
133
- commands.push(SerializableCommand.deserialize(part, editor));
134
- }
135
-
136
- return uniteCommands(commands, applyChunkSize);
137
- });
138
-
139
-
140
- export default uniteCommands;
@@ -1,23 +0,0 @@
1
- import { Color4, EditorImage, Mat33, Path, Rect2, Vec2 } from '../lib';
2
- import { pathToRenderable } from '../rendering/RenderablePathSpec';
3
- import createEditor from '../testing/createEditor';
4
- import Stroke from './Stroke';
5
-
6
- describe('AbstractComponent.transformBy', () => {
7
- it('should restore the component\'s z-index on undo', () => {
8
- const editor = createEditor();
9
- const component = new Stroke([ pathToRenderable(Path.fromRect(Rect2.unitSquare), { fill: Color4.red }) ]);
10
- EditorImage.addElement(component).apply(editor);
11
-
12
- const origZIndex = component.getZIndex();
13
-
14
- const transformCommand = component.transformBy(Mat33.translation(Vec2.unitX));
15
- transformCommand.apply(editor);
16
-
17
- // Should increase the z-index on applying a transform
18
- expect(component.getZIndex()).toBeGreaterThan(origZIndex);
19
-
20
- transformCommand.unapply(editor);
21
- expect(component.getZIndex()).toBe(origZIndex);
22
- });
23
- });