@itwin/core-markup 5.0.0-dev.7 → 5.0.0-dev.72

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/lib/cjs/Undo.js CHANGED
@@ -12,15 +12,19 @@ const core_bentley_1 = require("@itwin/core-bentley");
12
12
  const Markup_1 = require("./Markup");
13
13
  /* @internal */
14
14
  class UndoAction {
15
+ cmdName;
16
+ cmdId = 0;
15
17
  constructor(cmdName) {
16
18
  this.cmdName = cmdName;
17
- this.cmdId = 0;
18
19
  }
19
20
  }
20
21
  /** created when a new element is added to the markup
21
22
  * @internal
22
23
  */
23
24
  class AddAction extends UndoAction {
25
+ _elem;
26
+ _parent;
27
+ _index;
24
28
  constructor(cmdName, _elem) {
25
29
  super(cmdName);
26
30
  this._elem = _elem;
@@ -38,6 +42,9 @@ class AddAction extends UndoAction {
38
42
  * @internal
39
43
  */
40
44
  class DeleteAction extends UndoAction {
45
+ _elem;
46
+ _parent;
47
+ _index;
41
48
  constructor(cmdName, _elem) {
42
49
  super(cmdName);
43
50
  this._elem = _elem;
@@ -55,6 +62,11 @@ class DeleteAction extends UndoAction {
55
62
  * @internal
56
63
  */
57
64
  class RepositionAction extends UndoAction {
65
+ _elem;
66
+ _oldIndex;
67
+ _oldParent;
68
+ _newParent;
69
+ _newIndex;
58
70
  constructor(cmdName, _elem, _oldIndex, _oldParent) {
59
71
  super(cmdName);
60
72
  this._elem = _elem;
@@ -77,6 +89,8 @@ class RepositionAction extends UndoAction {
77
89
  * @internal
78
90
  */
79
91
  class ModifyAction extends UndoAction {
92
+ _newElem;
93
+ _oldElement;
80
94
  constructor(cmdName, _newElem, _oldElement) {
81
95
  super(cmdName);
82
96
  this._newElem = _newElem;
@@ -97,13 +111,11 @@ class ModifyAction extends UndoAction {
97
111
  * @public
98
112
  */
99
113
  class UndoManager {
100
- constructor() {
101
- this._currentCmd = 0;
102
- this._grouped = 0;
103
- this._stack = [];
104
- this._currentPos = 0;
105
- this._cmdName = "";
106
- }
114
+ _currentCmd = 0;
115
+ _grouped = 0;
116
+ _stack = [];
117
+ _currentPos = 0;
118
+ _cmdName = "";
107
119
  addAction(action) {
108
120
  this._stack.length = this._currentPos;
109
121
  action.cmdId = this._currentCmd;
@@ -1 +1 @@
1
- {"version":3,"file":"Undo.js","sourceRoot":"","sources":["../../src/Undo.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA6C;AAE7C,qCAAqC;AAErC,eAAe;AACf,MAAe,UAAU;IAIvB,YAAmB,OAAe;QAAf,YAAO,GAAP,OAAO,CAAQ;QAH3B,UAAK,GAAW,CAAC,CAAC;IAGa,CAAC;CACxC;AAED;;GAEG;AACH,MAAM,SAAU,SAAQ,UAAU;IAGhC,YAAY,OAAe,EAAU,KAAoB;QACvD,KAAK,CAAC,OAAO,CAAC,CAAC;QADoB,UAAK,GAAL,KAAK,CAAe;QAEvD,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,MAAM,EAAmB,CAAC;QAC/C,IAAA,qBAAM,EAAC,IAAI,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC;QACnC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAC;IACjC,CAAC;IACM,SAAS,KAAK,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC1D,OAAO;QACZ,kBAAS,CAAC,MAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC5C,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;IACtB,CAAC;CACF;AAED;;GAEG;AACH,MAAM,YAAa,SAAQ,UAAU;IAGnC,YAAY,OAAe,EAAU,KAAoB;QACvD,KAAK,CAAC,OAAO,CAAC,CAAC;QADoB,UAAK,GAAL,KAAK,CAAe;QAEvD,IAAI,CAAC,OAAO,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C,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,KAAK,CAAC;QAClD,OAAO,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,IAAI,IAAI,KAAK,KAAK,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,KAAK;YAClF,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,SAAS,EAAE,CAAC;IAChD,CAAC;CACF;AA5ED,kCA4EC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module MarkupTools\r\n */\r\n\r\nimport { assert } from \"@itwin/core-bentley\";\r\nimport { Element as MarkupElement } from \"@svgdotjs/svg.js\";\r\nimport { MarkupApp } from \"./Markup\";\r\n\r\n/* @internal */\r\nabstract class UndoAction {\r\n public cmdId: number = 0;\r\n public abstract reverse(): void;\r\n public abstract reinstate(): void;\r\n constructor(public cmdName: string) { }\r\n}\r\n\r\n/** created when a new element is added to the markup\r\n * @internal\r\n */\r\nclass AddAction extends UndoAction {\r\n private _parent: MarkupElement;\r\n private _index: number;\r\n constructor(cmdName: string, private _elem: MarkupElement) {\r\n super(cmdName);\r\n this._parent = _elem.parent() as MarkupElement;\r\n assert(this._parent !== undefined);\r\n this._index = _elem.position();\r\n }\r\n public reinstate() { this._parent.add(this._elem, this._index); }\r\n public reverse() {\r\n MarkupApp.markup!.selected.drop(this._elem);\r\n this._elem.remove();\r\n }\r\n}\r\n\r\n/** created when an existing element is deleted from the markup\r\n * @internal\r\n */\r\nclass DeleteAction extends UndoAction {\r\n private _parent: MarkupElement;\r\n private _index: number;\r\n constructor(cmdName: string, private _elem: MarkupElement) {\r\n super(cmdName);\r\n this._parent = _elem.parent() as MarkupElement;\r\n assert(this._parent !== undefined);\r\n this._index = _elem.position();\r\n }\r\n public reverse() { this._parent.add(this._elem, this._index); }\r\n public reinstate() {\r\n MarkupApp.markup!.selected.drop(this._elem);\r\n this._elem.remove();\r\n }\r\n}\r\n\r\n/** created when an existing element's position is moved in the display order. This can also include re-parenting\r\n * @internal\r\n */\r\nclass RepositionAction extends UndoAction {\r\n private _newParent: MarkupElement;\r\n private _newIndex: number;\r\n\r\n constructor(cmdName: string, private _elem: MarkupElement, private _oldIndex: number, private _oldParent: MarkupElement) {\r\n super(cmdName);\r\n this._newParent = _elem.parent() as MarkupElement;\r\n assert(this._newParent !== undefined);\r\n this._newIndex = _elem.position();\r\n }\r\n public reinstate() {\r\n this._newParent.add(this._elem, this._newIndex);\r\n }\r\n\r\n public reverse() {\r\n this._oldParent.add(this._elem, this._oldIndex);\r\n if (this._elem.inSelection)\r\n MarkupApp.markup!.selected.drop(this._elem);\r\n }\r\n}\r\n\r\n/** created when an existing element's properties are modified.\r\n * @internal\r\n */\r\nclass ModifyAction extends UndoAction {\r\n constructor(cmdName: string, private _newElem: MarkupElement, private _oldElement: MarkupElement) {\r\n super(cmdName);\r\n assert(_newElem !== undefined && _oldElement !== undefined);\r\n MarkupApp.markup!.selected.replace(_oldElement, _newElem);\r\n }\r\n public reinstate() {\r\n this._oldElement.replace(this._newElem);\r\n MarkupApp.markup!.selected.replace(this._oldElement, this._newElem);\r\n }\r\n\r\n public reverse() {\r\n this._newElem.replace(this._oldElement);\r\n MarkupApp.markup!.selected.replace(this._newElem, this._oldElement);\r\n }\r\n}\r\n\r\n/** Stores the sequence of operations performed on a Markup. Facilitates undo/redo of the operations.\r\n * @public\r\n */\r\nexport class UndoManager {\r\n private _currentCmd = 0;\r\n private _grouped = 0;\r\n private _stack: UndoAction[] = [];\r\n private _currentPos = 0;\r\n private _cmdName = \"\";\r\n\r\n private addAction(action: UndoAction) {\r\n this._stack.length = this._currentPos;\r\n action.cmdId = this._currentCmd;\r\n this._stack.push(action);\r\n this._currentPos = this.size;\r\n }\r\n\r\n /** @internal */\r\n public get size() { return this._stack.length; }\r\n private startCommand() {\r\n if (0 === this._grouped)\r\n ++this._currentCmd;\r\n }\r\n\r\n private startGroup() {\r\n this.startCommand();\r\n ++this._grouped;\r\n }\r\n\r\n private endGroup() { --this._grouped; }\r\n\r\n /** Perform a series of changes to markup elements that should all be reversed as a single operation.\r\n * @param fn the function that performs the changes to the elements. It must call the onXXX methods of this class to store\r\n * the operations in the undo buffer.\r\n * @note all of the onXXX methods of this class should *only* be called from within the callback function of this method.\r\n */\r\n public performOperation(cmdName: string, fn: VoidFunction) {\r\n this._cmdName = cmdName;\r\n this.startGroup();\r\n fn();\r\n this.endGroup();\r\n }\r\n\r\n /** call this from within a [[performOperation]] function *after* an element has been added to a markup */\r\n public onAdded(elem: MarkupElement) { this.addAction(new AddAction(this._cmdName, elem)); }\r\n /** call this from within a [[performOperation]] function *before* an element is about to be deleted from a markup */\r\n public onDelete(elem: MarkupElement) { this.addAction(new DeleteAction(this._cmdName, elem)); }\r\n /** call this from within a [[performOperation]] function *after* an element has been moved in display order in a markup */\r\n public onRepositioned(elem: MarkupElement, oldIndex: number, oldParent: MarkupElement) { this.addAction(new RepositionAction(this._cmdName, elem, oldIndex, oldParent)); }\r\n /** call this from within a [[performOperation]] function *after* an element has been modified in a markup */\r\n public onModified(newElem: MarkupElement, oldElem: MarkupElement) { this.addAction(new ModifyAction(this._cmdName, newElem, oldElem)); }\r\n\r\n /** determine whether there are any un-reversed operations */\r\n public get undoPossible() { return this._currentPos > 0; }\r\n /** determine whether there are any reversed operations */\r\n public get redoPossible() { return this._currentPos < this.size; }\r\n /** the name of the operation that can be undone (or undefined) */\r\n public get undoString() { return this.undoPossible ? this._stack[this._currentPos - 1].cmdName : undefined; }\r\n /** the name of the operation that can be redone (or undefined) */\r\n public get redoString() { return this.redoPossible ? this._stack[this._currentPos].cmdName : undefined; }\r\n\r\n /** reverse the most recent operation, if any */\r\n public doUndo() {\r\n if (this._currentPos === 0)\r\n return; // no operations have been performed\r\n\r\n const cmdId = this._stack[this._currentPos - 1].cmdId;\r\n while (this._currentPos > 0 && cmdId === this._stack[this._currentPos - 1].cmdId)\r\n this._stack[--this._currentPos].reverse();\r\n }\r\n /** reinstate the most recently reversed operation, if any */\r\n public doRedo() {\r\n if (this._currentPos === this.size)\r\n return; // no operations have been reversed.\r\n\r\n const cmdId = this._stack[this._currentPos].cmdId;\r\n while (this._currentPos < this.size && cmdId === this._stack[this._currentPos].cmdId)\r\n this._stack[this._currentPos++].reinstate();\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"Undo.js","sourceRoot":"","sources":["../../src/Undo.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA6C;AAE7C,qCAAqC;AAErC,eAAe;AACf,MAAe,UAAU;IAIJ;IAHZ,KAAK,GAAW,CAAC,CAAC;IAGzB,YAAmB,OAAe;QAAf,YAAO,GAAP,OAAO,CAAQ;IAAI,CAAC;CACxC;AAED;;GAEG;AACH,MAAM,SAAU,SAAQ,UAAU;IAGK;IAF7B,OAAO,CAAgB;IACvB,MAAM,CAAS;IACvB,YAAY,OAAe,EAAU,KAAoB;QACvD,KAAK,CAAC,OAAO,CAAC,CAAC;QADoB,UAAK,GAAL,KAAK,CAAe;QAEvD,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,MAAM,EAAmB,CAAC;QAC/C,IAAA,qBAAM,EAAC,IAAI,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC;QACnC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAC;IACjC,CAAC;IACM,SAAS,KAAK,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC1D,OAAO;QACZ,kBAAS,CAAC,MAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC5C,IAAI,CAAC,KAAK,CAAC,MAA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CAAC,IAAI,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC,KAAK;YAC9E,IAAI,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,OAAO,EAAE,CAAC;IAC9C,CAAC;IACD,6DAA6D;IACtD,MAAM;QACX,IAAI,IAAI,CAAC,WAAW,KAAK,IAAI,CAAC,IAAI;YAChC,OAAO,CAAC,oCAAoC;QAE9C,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,KAAK,CAAC;QAClD,OAAO,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,IAAI,IAAI,KAAK,KAAK,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,KAAK;YAClF,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,SAAS,EAAE,CAAC;IAChD,CAAC;CACF;AA5ED,kCA4EC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module MarkupTools\n */\n\nimport { assert } from \"@itwin/core-bentley\";\nimport { Element as MarkupElement } from \"@svgdotjs/svg.js\";\nimport { MarkupApp } from \"./Markup\";\n\n/* @internal */\nabstract class UndoAction {\n public cmdId: number = 0;\n public abstract reverse(): void;\n public abstract reinstate(): void;\n constructor(public cmdName: string) { }\n}\n\n/** created when a new element is added to the markup\n * @internal\n */\nclass AddAction extends UndoAction {\n private _parent: MarkupElement;\n private _index: number;\n constructor(cmdName: string, private _elem: MarkupElement) {\n super(cmdName);\n this._parent = _elem.parent() as MarkupElement;\n assert(this._parent !== undefined);\n this._index = _elem.position();\n }\n public reinstate() { this._parent.add(this._elem, this._index); }\n public reverse() {\n MarkupApp.markup!.selected.drop(this._elem);\n this._elem.remove();\n }\n}\n\n/** created when an existing element is deleted from the markup\n * @internal\n */\nclass DeleteAction extends UndoAction {\n private _parent: MarkupElement;\n private _index: number;\n constructor(cmdName: string, private _elem: MarkupElement) {\n super(cmdName);\n this._parent = _elem.parent() as MarkupElement;\n assert(this._parent !== undefined);\n this._index = _elem.position();\n }\n public reverse() { this._parent.add(this._elem, this._index); }\n public reinstate() {\n MarkupApp.markup!.selected.drop(this._elem);\n this._elem.remove();\n }\n}\n\n/** created when an existing element's position is moved in the display order. This can also include re-parenting\n * @internal\n */\nclass RepositionAction extends UndoAction {\n private _newParent: MarkupElement;\n private _newIndex: number;\n\n constructor(cmdName: string, private _elem: MarkupElement, private _oldIndex: number, private _oldParent: MarkupElement) {\n super(cmdName);\n this._newParent = _elem.parent() as MarkupElement;\n assert(this._newParent !== undefined);\n this._newIndex = _elem.position();\n }\n public reinstate() {\n this._newParent.add(this._elem, this._newIndex);\n }\n\n public reverse() {\n this._oldParent.add(this._elem, this._oldIndex);\n if (this._elem.inSelection)\n MarkupApp.markup!.selected.drop(this._elem);\n }\n}\n\n/** created when an existing element's properties are modified.\n * @internal\n */\nclass ModifyAction extends UndoAction {\n constructor(cmdName: string, private _newElem: MarkupElement, private _oldElement: MarkupElement) {\n super(cmdName);\n assert(_newElem !== undefined && _oldElement !== undefined);\n MarkupApp.markup!.selected.replace(_oldElement, _newElem);\n }\n public reinstate() {\n this._oldElement.replace(this._newElem);\n MarkupApp.markup!.selected.replace(this._oldElement, this._newElem);\n }\n\n public reverse() {\n this._newElem.replace(this._oldElement);\n MarkupApp.markup!.selected.replace(this._newElem, this._oldElement);\n }\n}\n\n/** Stores the sequence of operations performed on a Markup. Facilitates undo/redo of the operations.\n * @public\n */\nexport class UndoManager {\n private _currentCmd = 0;\n private _grouped = 0;\n private _stack: UndoAction[] = [];\n private _currentPos = 0;\n private _cmdName = \"\";\n\n private addAction(action: UndoAction) {\n this._stack.length = this._currentPos;\n action.cmdId = this._currentCmd;\n this._stack.push(action);\n this._currentPos = this.size;\n }\n\n /** @internal */\n public get size() { return this._stack.length; }\n private startCommand() {\n if (0 === this._grouped)\n ++this._currentCmd;\n }\n\n private startGroup() {\n this.startCommand();\n ++this._grouped;\n }\n\n private endGroup() { --this._grouped; }\n\n /** Perform a series of changes to markup elements that should all be reversed as a single operation.\n * @param fn the function that performs the changes to the elements. It must call the onXXX methods of this class to store\n * the operations in the undo buffer.\n * @note all of the onXXX methods of this class should *only* be called from within the callback function of this method.\n */\n public performOperation(cmdName: string, fn: VoidFunction) {\n this._cmdName = cmdName;\n this.startGroup();\n fn();\n this.endGroup();\n }\n\n /** call this from within a [[performOperation]] function *after* an element has been added to a markup */\n public onAdded(elem: MarkupElement) { this.addAction(new AddAction(this._cmdName, elem)); }\n /** call this from within a [[performOperation]] function *before* an element is about to be deleted from a markup */\n public onDelete(elem: MarkupElement) { this.addAction(new DeleteAction(this._cmdName, elem)); }\n /** call this from within a [[performOperation]] function *after* an element has been moved in display order in a markup */\n public onRepositioned(elem: MarkupElement, oldIndex: number, oldParent: MarkupElement) { this.addAction(new RepositionAction(this._cmdName, elem, oldIndex, oldParent)); }\n /** call this from within a [[performOperation]] function *after* an element has been modified in a markup */\n public onModified(newElem: MarkupElement, oldElem: MarkupElement) { this.addAction(new ModifyAction(this._cmdName, newElem, oldElem)); }\n\n /** determine whether there are any un-reversed operations */\n public get undoPossible() { return this._currentPos > 0; }\n /** determine whether there are any reversed operations */\n public get redoPossible() { return this._currentPos < this.size; }\n /** the name of the operation that can be undone (or undefined) */\n public get undoString() { return this.undoPossible ? this._stack[this._currentPos - 1].cmdName : undefined; }\n /** the name of the operation that can be redone (or undefined) */\n public get redoString() { return this.redoPossible ? this._stack[this._currentPos].cmdName : undefined; }\n\n /** reverse the most recent operation, if any */\n public doUndo() {\n if (this._currentPos === 0)\n return; // no operations have been performed\n\n const cmdId = this._stack[this._currentPos - 1].cmdId;\n while (this._currentPos > 0 && cmdId === this._stack[this._currentPos - 1].cmdId)\n this._stack[--this._currentPos].reverse();\n }\n /** reinstate the most recently reversed operation, if any */\n public doRedo() {\n if (this._currentPos === this.size)\n return; // no operations have been reversed.\n\n const cmdId = this._stack[this._currentPos].cmdId;\n while (this._currentPos < this.size && cmdId === this._stack[this._currentPos].cmdId)\n this._stack[this._currentPos++].reinstate();\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"core-markup.js","sourceRoot":"","sources":["../../src/core-markup.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;;+FAG+F;AAC/F,2CAAyB;AACzB,+CAA6B;AAC7B,gDAA8B;AAC9B,+CAA6B;AAC7B,6CAA2B;AAC3B,yCAAuB;AACvB,6CAA2B;AAE3B;;GAEG;AACH;;;GAGG;AACH;;;GAGG","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\nexport * from \"./Markup\";\r\nexport * from \"./MarkupTool\";\r\nexport * from \"./RedlineTool\";\r\nexport * from \"./SelectTool\";\r\nexport * from \"./TextEdit\";\r\nexport * from \"./Undo\";\r\nexport * from \"./SvgJsExt\";\r\n\r\n/** @docs-package-description\r\n * The core-markup package supplies tools for creating, editing, and saving SVG-based markups of Viewports.\r\n */\r\n/**\r\n * @docs-group-description MarkupApp\r\n * Classes for configuring and administering the markup system.\r\n */\r\n/**\r\n * @docs-group-description MarkupTools\r\n * Classes for supplying interactive tools for creating and editing markup elements.\r\n */\r\n"]}
1
+ {"version":3,"file":"core-markup.js","sourceRoot":"","sources":["../../src/core-markup.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;;+FAG+F;AAC/F,2CAAyB;AACzB,+CAA6B;AAC7B,gDAA8B;AAC9B,+CAA6B;AAC7B,6CAA2B;AAC3B,yCAAuB;AACvB,6CAA2B;AAE3B;;GAEG;AACH;;;GAGG;AACH;;;GAGG","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\nexport * from \"./Markup\";\nexport * from \"./MarkupTool\";\nexport * from \"./RedlineTool\";\nexport * from \"./SelectTool\";\nexport * from \"./TextEdit\";\nexport * from \"./Undo\";\nexport * from \"./SvgJsExt\";\n\n/** @docs-package-description\n * The core-markup package supplies tools for creating, editing, and saving SVG-based markups of Viewports.\n */\n/**\n * @docs-group-description MarkupApp\n * Classes for configuring and administering the markup system.\n */\n/**\n * @docs-group-description MarkupTools\n * Classes for supplying interactive tools for creating and editing markup elements.\n */\n"]}
package/lib/esm/Markup.js CHANGED
@@ -22,6 +22,117 @@ import { UndoManager } from "./Undo";
22
22
  * @public
23
23
  */
24
24
  export class MarkupApp {
25
+ /** the current Markup being created */
26
+ static markup;
27
+ /** The namespace for the Markup tools */
28
+ static namespace;
29
+ /** By setting members of this object, applications can control the appearance and behavior of various parts of MarkupApp. */
30
+ static props = {
31
+ /** the UI controls displayed on Elements by the Select Tool to allow users to modify them. */
32
+ handles: {
33
+ /** The diameter of the circles for the handles. */
34
+ size: 10,
35
+ /** The attributes of the stretch handles */
36
+ stretch: { "fill-opacity": .85, "stroke": "black", "fill": "white" },
37
+ /** The attributes of the line that connects the top-center stretch handle to the rotate handle. */
38
+ rotateLine: { "stroke": "grey", "fill-opacity": .85 },
39
+ /** The attributes of the rotate handle. */
40
+ rotate: { "cursor": `url(${IModelApp.publicPath}Markup/rotate.png) 12 12, auto`, "fill-opacity": .85, "stroke": "black", "fill": "lightBlue" },
41
+ /** The attributes of box around the element. */
42
+ moveOutline: { "cursor": "move", "stroke-dasharray": "6,6", "fill": "none", "stroke-opacity": .85, "stroke": "white" },
43
+ /** The attributes of box that provides the move cursor. */
44
+ move: { "cursor": "move", "opacity": 0, "stroke-width": 10, "stroke": "white" },
45
+ /** The attributes of handles on the vertices of lines. */
46
+ vertex: { "cursor": `url(${IModelApp.publicPath}cursors/crosshair.cur), crosshair`, "fill-opacity": .85, "stroke": "black", "fill": "white" },
47
+ },
48
+ /** properties for providing feedback about selected elements. */
49
+ hilite: {
50
+ /** the color of selected elements */
51
+ color: "magenta",
52
+ /** the color of an element as the cursor passes over it */
53
+ flash: "cyan",
54
+ },
55
+ /** optionally, show a drop-shadow behind all markup elements. */
56
+ dropShadow: {
57
+ /** if false, no drop shadow */
58
+ enable: true,
59
+ /** the attributes of the drop shadow. See https://developer.mozilla.org/en-US/docs/Web/SVG/Element/feDropShadow */
60
+ attr: {
61
+ "stdDeviation": 2,
62
+ "dx": 1.2,
63
+ "dy": 1.4,
64
+ "flood-color": "#1B3838",
65
+ },
66
+ },
67
+ /** The "active placement" parameters. New elements are created with these parameters, so UI controls should set them. */
68
+ active: {
69
+ /** the CSS style properties of new text elements. */
70
+ text: {
71
+ "font-family": "sans-serif",
72
+ "font-size": "30px",
73
+ "stroke": "none",
74
+ "fill": "red",
75
+ },
76
+ /** the CSS style properties of new elements. */
77
+ element: {
78
+ "stroke": "red",
79
+ "stroke-opacity": 0.8,
80
+ "stroke-width": 3,
81
+ "stroke-dasharray": 0,
82
+ "stroke-linecap": "round",
83
+ "stroke-linejoin": "round",
84
+ "fill": "blue",
85
+ "fill-opacity": 0.2,
86
+ },
87
+ arrow: {
88
+ length: 7,
89
+ width: 6,
90
+ },
91
+ cloud: {
92
+ path: "M3.0,2.5 C3.9,.78 5.6,-.4 8.1,1.0 C9.1,0 11.3,-.2 12.5,.5 C14.2,-.5 17,.16 17.9,2.5 C21,3 20.2,7.3 17.6,7.5 C16.5,9.2 14.4,9.8 12.7,8.9 C11.6,10 9.5,10.3 8.1,9.4 C5.7,10.8 3.3,9.4 2.6,7.5 C-.9,7.7 .6,1.7 3.0,2.5z",
93
+ },
94
+ },
95
+ /** Values for placing and editing Text. */
96
+ text: {
97
+ /** A default string for the Markup.Text.Place command. Applications can turn this off, or supply the user's initials, for example. */
98
+ startValue: "Note: ",
99
+ /** Parameters for the size and appearance of the text editor */
100
+ edit: {
101
+ background: "blanchedalmond",
102
+ /** Starting size, will be updated if user stretches the box */
103
+ size: { width: "25%", height: "4em" },
104
+ /** font size of the text editor */
105
+ fontSize: "14pt",
106
+ /** A background box drawn around text so user can tell what's being selected */
107
+ textBox: { "fill": "lightGrey", "fill-opacity": .1, "stroke-opacity": .85, "stroke": "lightBlue" },
108
+ },
109
+ },
110
+ /** Used to draw the border outline around the view while it is being marked up so the user can tell Markup is active */
111
+ borderOutline: {
112
+ "stroke": "gold",
113
+ "stroke-width": 6,
114
+ "stroke-opacity": 0.4,
115
+ "fill": "none",
116
+ },
117
+ /** Used to draw the border corner symbols for the view while it is being marked up so the user can tell Markup is active */
118
+ borderCorners: {
119
+ "stroke": "black",
120
+ "stroke-width": 2,
121
+ "stroke-opacity": 0.2,
122
+ "fill": "gold",
123
+ "fill-opacity": 0.2,
124
+ },
125
+ /** Determines what is returned by MarkupApp.stop */
126
+ result: {
127
+ /** The format for the image data. */
128
+ imageFormat: "image/png",
129
+ /** If true, the markup graphics will be imprinted in the returned image. */
130
+ imprintSvgOnImage: true,
131
+ /** the maximum width for the returned image. If the source view width is larger than this, it will be scaled down to this size. */
132
+ maxWidth: 2048,
133
+ },
134
+ };
135
+ static _saveDefaultToolId = "";
25
136
  /** @internal */
26
137
  static screenToVbMtx() {
27
138
  const matrix = this.markup?.svgMarkup?.screenCTM().inverse();
@@ -42,6 +153,7 @@ export class MarkupApp {
42
153
  }
43
154
  /** determine whether there's a markup session currently active */
44
155
  static get isActive() { return undefined !== this.markup; }
156
+ static markupSelectToolId = "Markup.Select";
45
157
  static createMarkup(view, markupData) { return new Markup(view, markupData); }
46
158
  static lockViewportSize(view, markupData) {
47
159
  const parentDiv = view.vpDiv;
@@ -149,7 +261,7 @@ export class MarkupApp {
149
261
  /** @internal */
150
262
  static async readMarkup() {
151
263
  const result = this.props.result;
152
- let canvas = this.markup.vp.readImageToCanvas();
264
+ let canvas = this.markup.vp.readImageToCanvas({ omitCanvasDecorations: false });
153
265
  let svg, image;
154
266
  try {
155
267
  svg = this.readMarkupSvg(); // read the current svg data for the markup
@@ -176,6 +288,8 @@ export class MarkupApp {
176
288
  return { rect: { width: canvas.width, height: canvas.height }, svg, image };
177
289
  }
178
290
  /** @internal */
291
+ static markupPrefix = "markup-";
292
+ /** @internal */
179
293
  static get dropShadowId() { return `${this.markupPrefix}dropShadow`; } // this is referenced in the markup Svg to apply the drop-shadow filter to all markup elements.
180
294
  /** @internal */
181
295
  static get cornerId() { return `${this.markupPrefix}photoCorner`; }
@@ -206,116 +320,6 @@ export class MarkupApp {
206
320
  /** @internal */
207
321
  static get textEditorClass() { return `${this.markupPrefix}textEditor`; }
208
322
  }
209
- /** By setting members of this object, applications can control the appearance and behavior of various parts of MarkupApp. */
210
- MarkupApp.props = {
211
- /** the UI controls displayed on Elements by the Select Tool to allow users to modify them. */
212
- handles: {
213
- /** The diameter of the circles for the handles. */
214
- size: 10,
215
- /** The attributes of the stretch handles */
216
- stretch: { "fill-opacity": .85, "stroke": "black", "fill": "white" },
217
- /** The attributes of the line that connects the top-center stretch handle to the rotate handle. */
218
- rotateLine: { "stroke": "grey", "fill-opacity": .85 },
219
- /** The attributes of the rotate handle. */
220
- rotate: { "cursor": `url(${IModelApp.publicPath}Markup/rotate.png) 12 12, auto`, "fill-opacity": .85, "stroke": "black", "fill": "lightBlue" },
221
- /** The attributes of box around the element. */
222
- moveOutline: { "cursor": "move", "stroke-dasharray": "6,6", "fill": "none", "stroke-opacity": .85, "stroke": "white" },
223
- /** The attributes of box that provides the move cursor. */
224
- move: { "cursor": "move", "opacity": 0, "stroke-width": 10, "stroke": "white" },
225
- /** The attributes of handles on the vertices of lines. */
226
- vertex: { "cursor": `url(${IModelApp.publicPath}cursors/crosshair.cur), crosshair`, "fill-opacity": .85, "stroke": "black", "fill": "white" },
227
- },
228
- /** properties for providing feedback about selected elements. */
229
- hilite: {
230
- /** the color of selected elements */
231
- color: "magenta",
232
- /** the color of an element as the cursor passes over it */
233
- flash: "cyan",
234
- },
235
- /** optionally, show a drop-shadow behind all markup elements. */
236
- dropShadow: {
237
- /** if false, no drop shadow */
238
- enable: true,
239
- /** the attributes of the drop shadow. See https://developer.mozilla.org/en-US/docs/Web/SVG/Element/feDropShadow */
240
- attr: {
241
- "stdDeviation": 2,
242
- "dx": 1.2,
243
- "dy": 1.4,
244
- "flood-color": "#1B3838",
245
- },
246
- },
247
- /** The "active placement" parameters. New elements are created with these parameters, so UI controls should set them. */
248
- active: {
249
- /** the CSS style properties of new text elements. */
250
- text: {
251
- "font-family": "sans-serif",
252
- "font-size": "30px",
253
- "stroke": "none",
254
- "fill": "red",
255
- },
256
- /** the CSS style properties of new elements. */
257
- element: {
258
- "stroke": "red",
259
- "stroke-opacity": 0.8,
260
- "stroke-width": 3,
261
- "stroke-dasharray": 0,
262
- "stroke-linecap": "round",
263
- "stroke-linejoin": "round",
264
- "fill": "blue",
265
- "fill-opacity": 0.2,
266
- },
267
- arrow: {
268
- length: 7,
269
- width: 6,
270
- },
271
- cloud: {
272
- path: "M3.0,2.5 C3.9,.78 5.6,-.4 8.1,1.0 C9.1,0 11.3,-.2 12.5,.5 C14.2,-.5 17,.16 17.9,2.5 C21,3 20.2,7.3 17.6,7.5 C16.5,9.2 14.4,9.8 12.7,8.9 C11.6,10 9.5,10.3 8.1,9.4 C5.7,10.8 3.3,9.4 2.6,7.5 C-.9,7.7 .6,1.7 3.0,2.5z",
273
- },
274
- },
275
- /** Values for placing and editing Text. */
276
- text: {
277
- /** A default string for the Markup.Text.Place command. Applications can turn this off, or supply the user's initials, for example. */
278
- startValue: "Note: ",
279
- /** Parameters for the size and appearance of the text editor */
280
- edit: {
281
- background: "blanchedalmond",
282
- /** Starting size, will be updated if user stretches the box */
283
- size: { width: "25%", height: "4em" },
284
- /** font size of the text editor */
285
- fontSize: "14pt",
286
- /** A background box drawn around text so user can tell what's being selected */
287
- textBox: { "fill": "lightGrey", "fill-opacity": .1, "stroke-opacity": .85, "stroke": "lightBlue" },
288
- },
289
- },
290
- /** Used to draw the border outline around the view while it is being marked up so the user can tell Markup is active */
291
- borderOutline: {
292
- "stroke": "gold",
293
- "stroke-width": 6,
294
- "stroke-opacity": 0.4,
295
- "fill": "none",
296
- },
297
- /** Used to draw the border corner symbols for the view while it is being marked up so the user can tell Markup is active */
298
- borderCorners: {
299
- "stroke": "black",
300
- "stroke-width": 2,
301
- "stroke-opacity": 0.2,
302
- "fill": "gold",
303
- "fill-opacity": 0.2,
304
- },
305
- /** Determines what is returned by MarkupApp.stop */
306
- result: {
307
- /** The format for the image data. */
308
- imageFormat: "image/png",
309
- /** If true, the markup graphics will be imprinted in the returned image. */
310
- imprintSvgOnImage: true,
311
- /** the maximum width for the returned image. If the source view width is larger than this, it will be scaled down to this size. */
312
- maxWidth: 2048,
313
- },
314
- };
315
- MarkupApp._saveDefaultToolId = "";
316
- MarkupApp.markupSelectToolId = "Markup.Select";
317
- /** @internal */
318
- MarkupApp.markupPrefix = "markup-";
319
323
  const removeSvgNamespace = (svg) => {
320
324
  svg.node.removeAttribute("xmlns:svgjs");
321
325
  return svg;
@@ -327,6 +331,21 @@ const newSvgElement = (name) => adopt(create(name));
327
331
  * @public
328
332
  */
329
333
  export class Markup {
334
+ vp;
335
+ /** @internal */
336
+ markupDiv;
337
+ /** Support undo/redo of markup operations */
338
+ undo = new UndoManager();
339
+ /** The set of currently selected markup elements */
340
+ selected;
341
+ /** @internal */
342
+ svgContainer;
343
+ /** @internal */
344
+ svgMarkup;
345
+ /** @internal */
346
+ svgDynamics;
347
+ /** @internal */
348
+ svgDecorations;
330
349
  /** create the drop-shadow filter in the Defs section of the supplied svg element */
331
350
  createDropShadow(svg) {
332
351
  const filter = SVG(`#${MarkupApp.dropShadowId}`); // see if we already have one?
@@ -358,8 +377,6 @@ export class Markup {
358
377
  */
359
378
  constructor(vp, markupData) {
360
379
  this.vp = vp;
361
- /** Support undo/redo of markup operations */
362
- this.undo = new UndoManager();
363
380
  this.markupDiv = vp.addNewDiv("overlay-markup", true, 20); // this div goes on top of the canvas, but behind UI layers
364
381
  const rect = this.markupDiv.getBoundingClientRect();
365
382
  // First, see if there is a markup passed in as an argument