js-draw 1.23.1 → 1.24.2
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/Editor.css +21 -0
- package/dist/bundle.js +2 -2
- package/dist/bundledStyles.js +1 -1
- package/dist/cjs/Editor.d.ts +7 -1
- package/dist/cjs/Editor.js +71 -9
- package/dist/cjs/SVGLoader/SVGLoader.js +17 -7
- package/dist/cjs/Viewport.d.ts +2 -0
- package/dist/cjs/Viewport.js +0 -1
- package/dist/cjs/components/AbstractComponent.d.ts +1 -1
- package/dist/cjs/components/BackgroundComponent.js +17 -7
- package/dist/cjs/components/SVGGlobalAttributesObject.js +17 -7
- package/dist/cjs/components/TextComponent.d.ts +11 -0
- package/dist/cjs/components/TextComponent.js +14 -3
- package/dist/cjs/components/UnknownSVGObject.js +17 -7
- package/dist/cjs/components/lib.js +17 -7
- package/dist/cjs/image/EditorImage.js +17 -7
- package/dist/cjs/testing/sendPenEvent.js +17 -7
- package/dist/cjs/testing/sendTouchEvent.js +17 -7
- package/dist/cjs/toolbar/EdgeToolbar.d.ts +1 -1
- package/dist/cjs/toolbar/widgets/DocumentPropertiesWidget.js +17 -7
- package/dist/cjs/toolbar/widgets/HandToolWidget.js +17 -7
- package/dist/cjs/tools/InputFilter/ContextMenuRecognizer.js +17 -7
- package/dist/cjs/tools/Pen.js +17 -7
- package/dist/cjs/tools/SelectionTool/Selection.js +17 -7
- package/dist/cjs/tools/SelectionTool/SelectionMenuShortcut.js +1 -1
- package/dist/cjs/tools/SelectionTool/util/makeClipboardErrorHandlers.d.ts +2 -2
- package/dist/cjs/tools/SelectionTool/util/makeClipboardErrorHandlers.js +1 -1
- package/dist/cjs/tools/SoundUITool.js +1 -1
- package/dist/cjs/tools/TextTool.d.ts +4 -4
- package/dist/cjs/tools/TextTool.js +45 -51
- package/dist/cjs/tools/ToolController.js +17 -7
- package/dist/cjs/tools/UndoRedoShortcut.js +2 -2
- package/dist/cjs/util/ClipboardHandler.js +1 -0
- package/dist/cjs/version.js +1 -1
- package/dist/mjs/Editor.d.ts +7 -1
- package/dist/mjs/Editor.mjs +54 -2
- package/dist/mjs/Viewport.d.ts +2 -0
- package/dist/mjs/Viewport.mjs +0 -1
- package/dist/mjs/components/AbstractComponent.d.ts +1 -1
- package/dist/mjs/components/TextComponent.d.ts +11 -0
- package/dist/mjs/components/TextComponent.mjs +14 -3
- package/dist/mjs/toolbar/EdgeToolbar.d.ts +1 -1
- package/dist/mjs/tools/SelectionTool/SelectionMenuShortcut.mjs +1 -1
- package/dist/mjs/tools/SelectionTool/util/makeClipboardErrorHandlers.d.ts +2 -2
- package/dist/mjs/tools/SelectionTool/util/makeClipboardErrorHandlers.mjs +1 -1
- package/dist/mjs/tools/SoundUITool.mjs +1 -1
- package/dist/mjs/tools/TextTool.d.ts +4 -4
- package/dist/mjs/tools/TextTool.mjs +45 -51
- package/dist/mjs/tools/UndoRedoShortcut.mjs +2 -2
- package/dist/mjs/util/ClipboardHandler.mjs +1 -0
- package/dist/mjs/version.mjs +1 -1
- package/package.json +4 -4
- package/src/Editor.scss +31 -0
@@ -18,13 +18,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
18
18
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
19
19
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
20
20
|
};
|
21
|
-
var __importStar = (this && this.__importStar) || function (
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
};
|
21
|
+
var __importStar = (this && this.__importStar) || (function () {
|
22
|
+
var ownKeys = function(o) {
|
23
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
24
|
+
var ar = [];
|
25
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
26
|
+
return ar;
|
27
|
+
};
|
28
|
+
return ownKeys(o);
|
29
|
+
};
|
30
|
+
return function (mod) {
|
31
|
+
if (mod && mod.__esModule) return mod;
|
32
|
+
var result = {};
|
33
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
34
|
+
__setModuleDefault(result, mod);
|
35
|
+
return result;
|
36
|
+
};
|
37
|
+
})();
|
28
38
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
29
39
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
30
40
|
};
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
15
15
|
}) : function(o, v) {
|
16
16
|
o["default"] = v;
|
17
17
|
});
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
};
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
19
|
+
var ownKeys = function(o) {
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
21
|
+
var ar = [];
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
23
|
+
return ar;
|
24
|
+
};
|
25
|
+
return ownKeys(o);
|
26
|
+
};
|
27
|
+
return function (mod) {
|
28
|
+
if (mod && mod.__esModule) return mod;
|
29
|
+
var result = {};
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
31
|
+
__setModuleDefault(result, mod);
|
32
|
+
return result;
|
33
|
+
};
|
34
|
+
})();
|
25
35
|
var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
|
26
36
|
if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
|
27
37
|
return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
15
15
|
}) : function(o, v) {
|
16
16
|
o["default"] = v;
|
17
17
|
});
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
};
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
19
|
+
var ownKeys = function(o) {
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
21
|
+
var ar = [];
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
23
|
+
return ar;
|
24
|
+
};
|
25
|
+
return ownKeys(o);
|
26
|
+
};
|
27
|
+
return function (mod) {
|
28
|
+
if (mod && mod.__esModule) return mod;
|
29
|
+
var result = {};
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
31
|
+
__setModuleDefault(result, mod);
|
32
|
+
return result;
|
33
|
+
};
|
34
|
+
})();
|
25
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
26
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
27
37
|
};
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
15
15
|
}) : function(o, v) {
|
16
16
|
o["default"] = v;
|
17
17
|
});
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
};
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
19
|
+
var ownKeys = function(o) {
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
21
|
+
var ar = [];
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
23
|
+
return ar;
|
24
|
+
};
|
25
|
+
return ownKeys(o);
|
26
|
+
};
|
27
|
+
return function (mod) {
|
28
|
+
if (mod && mod.__esModule) return mod;
|
29
|
+
var result = {};
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
31
|
+
__setModuleDefault(result, mod);
|
32
|
+
return result;
|
33
|
+
};
|
34
|
+
})();
|
25
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
26
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
27
37
|
};
|
@@ -49,7 +49,7 @@ export default class EdgeToolbar extends AbstractToolbar {
|
|
49
49
|
constructor(editor: Editor, parent: HTMLElement, localizationTable: ToolbarLocalization);
|
50
50
|
private listenForVisibilityChanges;
|
51
51
|
private onToolbarRowResize;
|
52
|
-
addSpacer(_options?: Partial<SpacerOptions>
|
52
|
+
addSpacer(_options?: Partial<SpacerOptions>): void;
|
53
53
|
addUndoRedoButtons(): void;
|
54
54
|
addDefaults(): void;
|
55
55
|
private updateWidgetCSSClasses;
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
15
15
|
}) : function(o, v) {
|
16
16
|
o["default"] = v;
|
17
17
|
});
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
};
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
19
|
+
var ownKeys = function(o) {
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
21
|
+
var ar = [];
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
23
|
+
return ar;
|
24
|
+
};
|
25
|
+
return ownKeys(o);
|
26
|
+
};
|
27
|
+
return function (mod) {
|
28
|
+
if (mod && mod.__esModule) return mod;
|
29
|
+
var result = {};
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
31
|
+
__setModuleDefault(result, mod);
|
32
|
+
return result;
|
33
|
+
};
|
34
|
+
})();
|
25
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
26
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
27
37
|
};
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
15
15
|
}) : function(o, v) {
|
16
16
|
o["default"] = v;
|
17
17
|
});
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
};
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
19
|
+
var ownKeys = function(o) {
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
21
|
+
var ar = [];
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
23
|
+
return ar;
|
24
|
+
};
|
25
|
+
return ownKeys(o);
|
26
|
+
};
|
27
|
+
return function (mod) {
|
28
|
+
if (mod && mod.__esModule) return mod;
|
29
|
+
var result = {};
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
31
|
+
__setModuleDefault(result, mod);
|
32
|
+
return result;
|
33
|
+
};
|
34
|
+
})();
|
25
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
26
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
27
37
|
};
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
15
15
|
}) : function(o, v) {
|
16
16
|
o["default"] = v;
|
17
17
|
});
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
};
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
19
|
+
var ownKeys = function(o) {
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
21
|
+
var ar = [];
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
23
|
+
return ar;
|
24
|
+
};
|
25
|
+
return ownKeys(o);
|
26
|
+
};
|
27
|
+
return function (mod) {
|
28
|
+
if (mod && mod.__esModule) return mod;
|
29
|
+
var result = {};
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
31
|
+
__setModuleDefault(result, mod);
|
32
|
+
return result;
|
33
|
+
};
|
34
|
+
})();
|
25
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
26
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
27
37
|
};
|
package/dist/cjs/tools/Pen.js
CHANGED
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
15
15
|
}) : function(o, v) {
|
16
16
|
o["default"] = v;
|
17
17
|
});
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
};
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
19
|
+
var ownKeys = function(o) {
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
21
|
+
var ar = [];
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
23
|
+
return ar;
|
24
|
+
};
|
25
|
+
return ownKeys(o);
|
26
|
+
};
|
27
|
+
return function (mod) {
|
28
|
+
if (mod && mod.__esModule) return mod;
|
29
|
+
var result = {};
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
31
|
+
__setModuleDefault(result, mod);
|
32
|
+
return result;
|
33
|
+
};
|
34
|
+
})();
|
25
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
26
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
27
37
|
};
|
@@ -19,13 +19,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
19
19
|
}) : function(o, v) {
|
20
20
|
o["default"] = v;
|
21
21
|
});
|
22
|
-
var __importStar = (this && this.__importStar) || function (
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
};
|
22
|
+
var __importStar = (this && this.__importStar) || (function () {
|
23
|
+
var ownKeys = function(o) {
|
24
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
25
|
+
var ar = [];
|
26
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
27
|
+
return ar;
|
28
|
+
};
|
29
|
+
return ownKeys(o);
|
30
|
+
};
|
31
|
+
return function (mod) {
|
32
|
+
if (mod && mod.__esModule) return mod;
|
33
|
+
var result = {};
|
34
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
35
|
+
__setModuleDefault(result, mod);
|
36
|
+
return result;
|
37
|
+
};
|
38
|
+
})();
|
29
39
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
30
40
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
31
41
|
};
|
@@ -12,7 +12,7 @@ class SelectionMenuShortcut {
|
|
12
12
|
this.element = document.createElement('div');
|
13
13
|
this.element.classList.add(`${SelectionTool_1.cssPrefix}handle`, `${SelectionTool_1.cssPrefix}selection-menu`);
|
14
14
|
this.element.style.setProperty('--vertical-offset', `${verticalOffset}px`);
|
15
|
-
this.onClick =
|
15
|
+
this.onClick = () => {
|
16
16
|
const anchor = this.getBBoxCanvasCoords().center;
|
17
17
|
showContextMenu(anchor);
|
18
18
|
};
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import Editor from '../../../Editor';
|
2
2
|
declare const makeClipboardErrorHandlers: (editor: Editor) => {
|
3
|
-
onCopyError(error:
|
4
|
-
onPasteError(error:
|
3
|
+
onCopyError(error: unknown): void;
|
4
|
+
onPasteError(error: unknown): void;
|
5
5
|
};
|
6
6
|
export default makeClipboardErrorHandlers;
|
@@ -21,7 +21,7 @@ const makeClipboardErrorHandlers = (editor) => {
|
|
21
21
|
return dialog;
|
22
22
|
};
|
23
23
|
return {
|
24
|
-
|
24
|
+
onCopyError(error) {
|
25
25
|
const dialog = makeErrorDialog(error);
|
26
26
|
const textboxLabel = document.createElement('label');
|
27
27
|
textboxLabel.textContent = editor.localization.copyPasteError__copyRetry;
|
@@ -5,23 +5,22 @@ import BaseTool from './BaseTool';
|
|
5
5
|
import { ToolLocalization } from './localization';
|
6
6
|
import TextRenderingStyle from '../rendering/TextRenderingStyle';
|
7
7
|
import { MutableReactiveValue } from '../util/ReactiveValue';
|
8
|
+
/** A tool that allows users to enter and edit text. */
|
8
9
|
export default class TextTool extends BaseTool {
|
9
10
|
private editor;
|
10
11
|
private localizationTable;
|
11
12
|
private textStyleValue;
|
12
13
|
private textStyle;
|
14
|
+
private anchorControl;
|
15
|
+
private contentTransform;
|
13
16
|
private textEditOverlay;
|
14
17
|
private textInputElem;
|
15
|
-
private textTargetPosition;
|
16
18
|
private textMeasuringCtx;
|
17
|
-
private textRotation;
|
18
|
-
private textScale;
|
19
19
|
private removeExistingCommand;
|
20
20
|
constructor(editor: Editor, description: string, localizationTable: ToolLocalization);
|
21
21
|
private initTextMeasuringCanvas;
|
22
22
|
private getTextAscent;
|
23
23
|
private flushInput;
|
24
|
-
private getTextScaleMatrix;
|
25
24
|
private updateTextInput;
|
26
25
|
private startTextInput;
|
27
26
|
setEnabled(enabled: boolean): void;
|
@@ -33,4 +32,5 @@ export default class TextTool extends BaseTool {
|
|
33
32
|
getTextStyle(): TextRenderingStyle;
|
34
33
|
getStyleValue(): MutableReactiveValue<TextRenderingStyle>;
|
35
34
|
private setTextStyle;
|
35
|
+
onDestroy(): void;
|
36
36
|
}
|
@@ -13,15 +13,14 @@ const Erase_1 = __importDefault(require("../commands/Erase"));
|
|
13
13
|
const uniteCommands_1 = __importDefault(require("../commands/uniteCommands"));
|
14
14
|
const ReactiveValue_1 = require("../util/ReactiveValue");
|
15
15
|
const overlayCSSClass = 'textEditorOverlay';
|
16
|
+
/** A tool that allows users to enter and edit text. */
|
16
17
|
class TextTool extends BaseTool_1.default {
|
17
18
|
constructor(editor, description, localizationTable) {
|
18
19
|
super(editor.notifier, description);
|
19
20
|
this.editor = editor;
|
20
21
|
this.localizationTable = localizationTable;
|
21
22
|
this.textInputElem = null;
|
22
|
-
this.textTargetPosition = null;
|
23
23
|
this.textMeasuringCtx = null;
|
24
|
-
this.textScale = math_1.Vec2.of(1, 1);
|
25
24
|
this.removeExistingCommand = null;
|
26
25
|
const editorFonts = editor.getCurrentSettings().text?.fonts ?? [];
|
27
26
|
this.textStyleValue = ReactiveValue_1.ReactiveValue.fromInitialValue({
|
@@ -39,18 +38,10 @@ class TextTool extends BaseTool_1.default {
|
|
39
38
|
tool: this,
|
40
39
|
});
|
41
40
|
});
|
41
|
+
this.contentTransform = ReactiveValue_1.ReactiveValue.fromInitialValue(math_1.Mat33.identity);
|
42
42
|
this.textEditOverlay = document.createElement('div');
|
43
43
|
this.textEditOverlay.classList.add(overlayCSSClass);
|
44
44
|
this.editor.addStyleSheet(`
|
45
|
-
.${overlayCSSClass} {
|
46
|
-
height: 0;
|
47
|
-
overflow: visible;
|
48
|
-
|
49
|
-
/* Allows absolutely-positioned textareas to scroll with
|
50
|
-
the containing overlay. */
|
51
|
-
position: relative;
|
52
|
-
}
|
53
|
-
|
54
45
|
.${overlayCSSClass} textarea {
|
55
46
|
background-color: rgba(0, 0, 0, 0);
|
56
47
|
|
@@ -66,8 +57,7 @@ class TextTool extends BaseTool_1.default {
|
|
66
57
|
min-height: 1.1em;
|
67
58
|
}
|
68
59
|
`);
|
69
|
-
this.editor.
|
70
|
-
this.editor.notifier.on(types_1.EditorEventType.ViewportChanged, () => this.updateTextInput());
|
60
|
+
this.anchorControl = this.editor.anchorElementToCanvas(this.textEditOverlay, this.contentTransform);
|
71
61
|
}
|
72
62
|
initTextMeasuringCanvas() {
|
73
63
|
this.textMeasuringCtx ??= document.createElement('canvas').getContext('2d');
|
@@ -87,24 +77,32 @@ class TextTool extends BaseTool_1.default {
|
|
87
77
|
// If [removeInput], the HTML input element is removed. Otherwise, its value
|
88
78
|
// is cleared.
|
89
79
|
flushInput(removeInput = true) {
|
90
|
-
if (this.textInputElem
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
80
|
+
if (!this.textInputElem)
|
81
|
+
return;
|
82
|
+
// Determine the scroll first -- removing the input (and other DOM changes)
|
83
|
+
// also change the scroll.
|
84
|
+
const scrollingRegion = this.textEditOverlay.parentElement;
|
85
|
+
const containerScroll = math_1.Vec2.of(scrollingRegion?.scrollLeft ?? 0, scrollingRegion?.scrollTop ?? 0);
|
86
|
+
const content = this.textInputElem.value.trimEnd();
|
87
|
+
this.textInputElem.value = '';
|
88
|
+
if (removeInput) {
|
89
|
+
// In some browsers, .remove() triggers a .blur event (synchronously).
|
90
|
+
// Clear this.textInputElem before removal
|
91
|
+
const input = this.textInputElem;
|
92
|
+
this.textInputElem = null;
|
93
|
+
input.remove();
|
94
|
+
}
|
95
|
+
if (content !== '') {
|
96
|
+
// When the text is long, it can cause its container to scroll so that the
|
97
|
+
// editing caret is in view.
|
98
|
+
// So that the text added to the document is in the same position as the text
|
99
|
+
// shown in the editor, account for this scroll when computing the transform:
|
100
|
+
const scrollCorrectionScreen = containerScroll.times(-1);
|
101
|
+
// Uses .transformVec3 to avoid also translating the scroll correction (treating
|
102
|
+
// it as a point):
|
103
|
+
const scrollCorrectionCanvas = this.editor.viewport.screenToCanvasTransform.transformVec3(scrollCorrectionScreen);
|
104
|
+
const scrollTransform = math_1.Mat33.translation(scrollCorrectionCanvas);
|
105
|
+
const textComponent = TextComponent_1.default.fromLines(content.split('\n'), scrollTransform.rightMul(this.contentTransform.get()), this.textStyle);
|
108
106
|
const action = EditorImage_1.default.addElement(textComponent);
|
109
107
|
if (this.removeExistingCommand) {
|
110
108
|
// Unapply so that `removeExistingCommand` can be added to the undo stack.
|
@@ -117,16 +115,10 @@ class TextTool extends BaseTool_1.default {
|
|
117
115
|
}
|
118
116
|
}
|
119
117
|
}
|
120
|
-
getTextScaleMatrix() {
|
121
|
-
return math_1.Mat33.scaling2D(this.textScale.times(1 / this.editor.viewport.getSizeOfPixelOnCanvas()));
|
122
|
-
}
|
123
118
|
updateTextInput() {
|
124
|
-
if (!this.textInputElem
|
125
|
-
this.textInputElem?.remove();
|
119
|
+
if (!this.textInputElem) {
|
126
120
|
return;
|
127
121
|
}
|
128
|
-
const viewport = this.editor.viewport;
|
129
|
-
const textScreenPos = viewport.canvasToScreen(this.textTargetPosition);
|
130
122
|
this.textInputElem.placeholder = this.localizationTable.enterTextToInsert;
|
131
123
|
this.textInputElem.style.fontFamily = this.textStyle.fontFamily;
|
132
124
|
this.textInputElem.style.fontStyle = this.textStyle.fontStyle ?? '';
|
@@ -134,9 +126,6 @@ class TextTool extends BaseTool_1.default {
|
|
134
126
|
this.textInputElem.style.fontWeight = this.textStyle.fontWeight ?? '';
|
135
127
|
this.textInputElem.style.fontSize = `${this.textStyle.size}px`;
|
136
128
|
this.textInputElem.style.color = this.textStyle.renderingStyle.fill.toHexString();
|
137
|
-
this.textInputElem.style.position = 'absolute';
|
138
|
-
this.textInputElem.style.left = `${textScreenPos.x}px`;
|
139
|
-
this.textInputElem.style.top = `${textScreenPos.y}px`;
|
140
129
|
this.textInputElem.style.margin = '0';
|
141
130
|
this.textInputElem.style.width = `${this.textInputElem.scrollWidth}px`;
|
142
131
|
this.textInputElem.style.height = `${this.textInputElem.scrollHeight}px`;
|
@@ -145,9 +134,7 @@ class TextTool extends BaseTool_1.default {
|
|
145
134
|
const tallText = 'Testing!';
|
146
135
|
const ascent = this.getTextAscent(tallText, this.textStyle);
|
147
136
|
const vertAdjust = ascent;
|
148
|
-
|
149
|
-
const scale = this.getTextScaleMatrix();
|
150
|
-
this.textInputElem.style.transform = `${scale.toCSSMatrix()} rotate(${(rotation * 180) / Math.PI}deg) translate(0, ${-vertAdjust}px)`;
|
137
|
+
this.textInputElem.style.transform = `translate(0, ${-vertAdjust}px)`;
|
151
138
|
this.textInputElem.style.transformOrigin = 'top left';
|
152
139
|
// Match the line height of default rendered text.
|
153
140
|
const lineHeight = Math.floor(this.textStyle.size);
|
@@ -158,9 +145,14 @@ class TextTool extends BaseTool_1.default {
|
|
158
145
|
this.textInputElem = document.createElement('textarea');
|
159
146
|
this.textInputElem.value = initialText;
|
160
147
|
this.textInputElem.style.display = 'inline-block';
|
161
|
-
|
162
|
-
|
163
|
-
|
148
|
+
const textTargetPosition = this.editor.viewport.roundPoint(textCanvasPos);
|
149
|
+
const textRotation = -this.editor.viewport.getRotationAngle();
|
150
|
+
const textScale = math_1.Vec2.of(1, 1).times(this.editor.viewport.getSizeOfPixelOnCanvas());
|
151
|
+
this.contentTransform.set(
|
152
|
+
// Scale, then rotate, then translate:
|
153
|
+
math_1.Mat33.translation(textTargetPosition)
|
154
|
+
.rightMul(math_1.Mat33.zRotation(textRotation))
|
155
|
+
.rightMul(math_1.Mat33.scaling2D(textScale)));
|
164
156
|
this.updateTextInput();
|
165
157
|
// Update the input size/position/etc. after the placeHolder has had time to appear.
|
166
158
|
setTimeout(() => this.updateTextInput(), 0);
|
@@ -229,10 +221,7 @@ class TextTool extends BaseTool_1.default {
|
|
229
221
|
this.removeExistingCommand = new Erase_1.default([targetNode]);
|
230
222
|
this.removeExistingCommand.apply(this.editor);
|
231
223
|
this.startTextInput(targetNode.getBaselinePos(), targetNode.getText());
|
232
|
-
|
233
|
-
this.textRotation = transform.transformVec3(math_1.Vec2.unitX).angle();
|
234
|
-
const scaleFactor = transform.transformVec3(math_1.Vec2.unitX).magnitude();
|
235
|
-
this.textScale = math_1.Vec2.of(1, 1).times(scaleFactor);
|
224
|
+
this.contentTransform.set(targetNode.getTransform());
|
236
225
|
this.updateTextInput();
|
237
226
|
}
|
238
227
|
else {
|
@@ -283,5 +272,10 @@ class TextTool extends BaseTool_1.default {
|
|
283
272
|
setTextStyle(style) {
|
284
273
|
this.textStyleValue.set(style);
|
285
274
|
}
|
275
|
+
// @internal
|
276
|
+
onDestroy() {
|
277
|
+
super.onDestroy();
|
278
|
+
this.anchorControl.remove();
|
279
|
+
}
|
286
280
|
}
|
287
281
|
exports.default = TextTool;
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
15
15
|
}) : function(o, v) {
|
16
16
|
o["default"] = v;
|
17
17
|
});
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
};
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
19
|
+
var ownKeys = function(o) {
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
21
|
+
var ar = [];
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
23
|
+
return ar;
|
24
|
+
};
|
25
|
+
return ownKeys(o);
|
26
|
+
};
|
27
|
+
return function (mod) {
|
28
|
+
if (mod && mod.__esModule) return mod;
|
29
|
+
var result = {};
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
31
|
+
__setModuleDefault(result, mod);
|
32
|
+
return result;
|
33
|
+
};
|
34
|
+
})();
|
25
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
26
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
27
37
|
};
|
@@ -14,11 +14,11 @@ class UndoRedoShortcut extends BaseTool_1.default {
|
|
14
14
|
// @internal
|
15
15
|
onKeyPress(event) {
|
16
16
|
if (this.editor.shortcuts.matchesShortcut(keybindings_1.undoKeyboardShortcutId, event)) {
|
17
|
-
this.editor.history.undo();
|
17
|
+
void this.editor.history.undo();
|
18
18
|
return true;
|
19
19
|
}
|
20
20
|
else if (this.editor.shortcuts.matchesShortcut(keybindings_1.redoKeyboardShortcutId, event)) {
|
21
|
-
this.editor.history.redo();
|
21
|
+
void this.editor.history.redo();
|
22
22
|
return true;
|
23
23
|
}
|
24
24
|
return false;
|
@@ -1,4 +1,5 @@
|
|
1
1
|
"use strict";
|
2
|
+
/* eslint-disable @typescript-eslint/no-redundant-type-constituents -- Used for clarity */
|
2
3
|
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
3
4
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
4
5
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
package/dist/cjs/version.js
CHANGED
package/dist/mjs/Editor.d.ts
CHANGED
@@ -5,7 +5,7 @@ import { HTMLPointerEventFilter, InputEvtType, PointerEvtType } from './inputEve
|
|
5
5
|
import Command from './commands/Command';
|
6
6
|
import UndoRedoHistory from './UndoRedoHistory';
|
7
7
|
import Viewport from './Viewport';
|
8
|
-
import { Point2, Vec2, Color4, Rect2 } from '@js-draw/math';
|
8
|
+
import { Point2, Vec2, Color4, Mat33, Rect2 } from '@js-draw/math';
|
9
9
|
import Display, { RenderingMode } from './rendering/Display';
|
10
10
|
import Pointer from './Pointer';
|
11
11
|
import { EditorLocalization } from './localization';
|
@@ -486,6 +486,12 @@ export declare class Editor {
|
|
486
486
|
createHTMLOverlay(overlay: HTMLElement): {
|
487
487
|
remove: () => void;
|
488
488
|
};
|
489
|
+
/**
|
490
|
+
* Anchors the given `element` to the canvas with a given position/transformation in canvas space.
|
491
|
+
*/
|
492
|
+
anchorElementToCanvas(element: HTMLElement, canvasTransform: Mat33 | ReactiveValue<Mat33>): {
|
493
|
+
remove: () => void;
|
494
|
+
};
|
489
495
|
/**
|
490
496
|
* Creates a CSS stylesheet with `content` and applies it to the document
|
491
497
|
* (and thus, to this editor).
|