@antv/infographic 0.2.11 → 0.2.13
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/dist/infographic.min.js +98 -94
- package/dist/infographic.min.js.map +1 -1
- package/esm/designs/components/Btn.js +15 -4
- package/esm/designs/components/BtnsGroup.js +1 -1
- package/esm/designs/components/Illus.js +15 -3
- package/esm/designs/components/ItemDesc.js +17 -11
- package/esm/designs/components/ItemIcon.js +17 -18
- package/esm/designs/components/ItemLabel.js +17 -11
- package/esm/designs/components/ItemValue.js +17 -12
- package/esm/designs/components/ItemsGroup.js +1 -1
- package/esm/designs/components/ShapesGroup.js +1 -1
- package/esm/designs/components/Title.js +2 -2
- package/esm/designs/decorations/simple-arrow.js +14 -2
- package/esm/designs/decorations/triangle.js +14 -2
- package/esm/designs/defs/DropShadow.js +13 -2
- package/esm/designs/defs/LinearGradient.js +1 -1
- package/esm/designs/items/BadgeCard.js +2 -2
- package/esm/designs/items/CandyCardLite.js +1 -1
- package/esm/designs/items/CapsuleItem.js +3 -3
- package/esm/designs/items/CircleNode.js +1 -1
- package/esm/designs/items/CircularProgress.js +3 -2
- package/esm/designs/items/CompactCard.js +1 -1
- package/esm/designs/items/DoneList.js +1 -1
- package/esm/designs/items/HorizontalIconArrow.js +2 -2
- package/esm/designs/items/HorizontalIconLine.js +2 -2
- package/esm/designs/items/IconBadge.js +4 -3
- package/esm/designs/items/IndexedCard.js +1 -1
- package/esm/designs/items/LCornerCard.js +1 -1
- package/esm/designs/items/LetterCard.js +4 -3
- package/esm/designs/items/LinedText.js +6 -5
- package/esm/designs/items/PillBadge.js +2 -2
- package/esm/designs/items/PlainText.js +4 -4
- package/esm/designs/items/ProgressCard.js +4 -4
- package/esm/designs/items/QuarterCircular.js +1 -1
- package/esm/designs/items/QuarterSimpleCard.js +1 -1
- package/esm/designs/items/RibbonCard.js +2 -2
- package/esm/designs/items/RoundedRectNode.js +2 -2
- package/esm/designs/items/SimpleCircleNode.js +1 -1
- package/esm/designs/items/SimpleHorizontalArrow.js +2 -2
- package/esm/designs/items/SimpleIllusItem.js +1 -1
- package/esm/designs/items/SimpleItem.js +3 -3
- package/esm/designs/items/SimpleVerticalArrow.js +2 -2
- package/esm/designs/items/UnderlineText.js +1 -1
- package/esm/designs/items/VerticalIconArrow.js +2 -2
- package/esm/designs/layouts/Align.js +22 -15
- package/esm/designs/layouts/Flex.js +23 -16
- package/esm/designs/structures/chart-bar.js +7 -5
- package/esm/designs/structures/chart-column.js +3 -2
- package/esm/designs/structures/chart-line.js +7 -5
- package/esm/designs/structures/chart-pie.d.ts +25 -0
- package/esm/designs/structures/chart-pie.js +186 -26
- package/esm/designs/structures/chart-wordcloud.js +5 -14
- package/esm/designs/structures/compare-binary-horizontal/dividers/pros-cons-arrow.js +1 -1
- package/esm/designs/structures/compare-binary-horizontal/dividers/pros-cons-fold.js +1 -1
- package/esm/designs/structures/compare-binary-horizontal/dividers/types.js +2 -1
- package/esm/designs/structures/compare-hierarchy-left-right.js +6 -5
- package/esm/designs/structures/compare-hierarchy-row.js +3 -2
- package/esm/designs/structures/compare-quadrant.js +2 -3
- package/esm/designs/structures/hierarchy-mindmap.js +19 -19
- package/esm/designs/structures/hierarchy-structure.js +1 -1
- package/esm/designs/structures/hierarchy-tree.js +15 -24
- package/esm/designs/structures/list-sector.js +5 -6
- package/esm/designs/structures/list-zigzag.js +2 -1
- package/esm/designs/structures/relation-dagre-flow.js +30 -35
- package/esm/designs/structures/relation-network.js +2 -2
- package/esm/designs/structures/sequence-funnel.js +1 -1
- package/esm/designs/structures/sequence-mountain.js +4 -4
- package/esm/designs/structures/sequence-pyramid.js +1 -1
- package/esm/designs/structures/sequence-zigzag-steps.js +2 -1
- package/esm/designs/utils/color.js +8 -4
- package/esm/designs/utils/index.d.ts +1 -0
- package/esm/designs/utils/index.js +1 -0
- package/esm/designs/utils/item.js +3 -2
- package/esm/designs/utils/normalize-percent.d.ts +19 -0
- package/esm/designs/utils/normalize-percent.js +32 -0
- package/esm/editor/commands/Batch.js +21 -8
- package/esm/editor/commands/UpdateElement.js +25 -22
- package/esm/editor/commands/UpdateOptions.js +23 -10
- package/esm/editor/commands/UpdateText.js +24 -11
- package/esm/editor/interactions/brush-select.js +27 -13
- package/esm/editor/interactions/click-select.js +13 -3
- package/esm/editor/interactions/dblclick-edit-text.js +36 -20
- package/esm/editor/interactions/drag-element.js +23 -9
- package/esm/editor/interactions/hotkey-history.js +17 -7
- package/esm/editor/interactions/select-highlight.js +5 -9
- package/esm/editor/interactions/zoom-wheel.d.ts +3 -0
- package/esm/editor/interactions/zoom-wheel.js +46 -22
- package/esm/editor/managers/command.js +45 -27
- package/esm/editor/managers/interaction.js +46 -33
- package/esm/editor/managers/state.js +9 -3
- package/esm/editor/plugins/edit-bar/components/color-picker.js +9 -6
- package/esm/editor/plugins/edit-bar/components/popover.js +15 -12
- package/esm/editor/plugins/edit-bar/components/select.js +10 -8
- package/esm/editor/plugins/edit-bar/edit-bar.js +7 -25
- package/esm/editor/plugins/edit-bar/edit-items/align-elements.js +5 -3
- package/esm/editor/plugins/edit-bar/edit-items/font-align.js +1 -1
- package/esm/editor/plugins/edit-bar/edit-items/font-color.js +2 -2
- package/esm/editor/plugins/edit-bar/edit-items/icon-color.js +2 -2
- package/esm/editor/plugins/resize-element.js +6 -4
- package/esm/editor/utils/click-handler.js +6 -3
- package/esm/editor/utils/coordinate.js +2 -1
- package/esm/editor/utils/element.js +2 -1
- package/esm/editor/utils/event.js +2 -1
- package/esm/editor/utils/extension.js +1 -1
- package/esm/editor/utils/hotkey.js +2 -1
- package/esm/exporter/font.js +106 -90
- package/esm/exporter/png.js +49 -37
- package/esm/exporter/svg.js +55 -38
- package/esm/jsx/components/Ellipse.js +5 -4
- package/esm/jsx/components/Path.js +2 -4
- package/esm/jsx/components/Polygon.js +15 -6
- package/esm/jsx/components/Text.js +21 -41
- package/esm/jsx/renderer.js +15 -7
- package/esm/jsx/utils/bounds.js +18 -16
- package/esm/jsx/utils/children.js +2 -1
- package/esm/jsx/utils/clone.js +13 -2
- package/esm/jsx/utils/element.js +2 -1
- package/esm/options/parser.js +45 -46
- package/esm/renderer/composites/background.js +3 -2
- package/esm/renderer/composites/icon.js +14 -19
- package/esm/renderer/composites/illus.js +17 -22
- package/esm/renderer/composites/shape.js +4 -2
- package/esm/renderer/composites/svg.js +2 -1
- package/esm/renderer/composites/text.js +5 -3
- package/esm/renderer/fonts/loader.js +4 -3
- package/esm/renderer/fonts/registry.js +1 -1
- package/esm/renderer/palettes/utils.js +3 -2
- package/esm/renderer/renderer.js +7 -5
- package/esm/renderer/stylize/gradient.js +3 -2
- package/esm/renderer/stylize/pattern.js +15 -8
- package/esm/renderer/stylize/rough.js +1 -1
- package/esm/resource/load-tracker.js +22 -10
- package/esm/resource/loader.js +80 -67
- package/esm/resource/loaders/image.js +71 -59
- package/esm/resource/loaders/remote.js +26 -15
- package/esm/resource/loaders/search.js +38 -25
- package/esm/resource/utils/parser.js +2 -1
- package/esm/runtime/Infographic.js +26 -13
- package/esm/runtime/utils.js +5 -8
- package/esm/ssr/renderer.js +42 -35
- package/esm/syntax/index.js +19 -6
- package/esm/syntax/mapper.js +2 -2
- package/esm/templates/built-in.js +91 -269
- package/esm/templates/chart-pie.d.ts +2 -0
- package/esm/templates/chart-pie.js +87 -0
- package/esm/templates/hierarchy-mindmap.js +1 -5
- package/esm/templates/hierarchy-tree.js +1 -5
- package/esm/templates/relation-dagre-flow.js +4 -28
- package/esm/themes/generator.js +8 -14
- package/esm/utils/fetch.js +48 -35
- package/esm/utils/icon.js +1 -4
- package/esm/utils/is-browser.js +2 -2
- package/esm/utils/measure-text.js +2 -1
- package/esm/utils/padding.js +1 -1
- package/esm/utils/recognizer.js +2 -1
- package/esm/utils/text.js +14 -3
- package/esm/utils/viewbox.d.ts +20 -0
- package/esm/utils/viewbox.js +10 -0
- package/esm/version.d.ts +1 -1
- package/esm/version.js +1 -1
- package/lib/designs/components/Btn.js +15 -4
- package/lib/designs/components/BtnsGroup.js +1 -1
- package/lib/designs/components/Illus.js +15 -3
- package/lib/designs/components/ItemDesc.js +17 -11
- package/lib/designs/components/ItemIcon.js +17 -18
- package/lib/designs/components/ItemLabel.js +17 -11
- package/lib/designs/components/ItemValue.js +17 -12
- package/lib/designs/components/ItemsGroup.js +1 -1
- package/lib/designs/components/ShapesGroup.js +1 -1
- package/lib/designs/components/Title.js +2 -2
- package/lib/designs/decorations/simple-arrow.js +14 -2
- package/lib/designs/decorations/triangle.js +14 -2
- package/lib/designs/defs/DropShadow.js +13 -2
- package/lib/designs/defs/LinearGradient.js +1 -1
- package/lib/designs/items/BadgeCard.js +2 -2
- package/lib/designs/items/CandyCardLite.js +1 -1
- package/lib/designs/items/CapsuleItem.js +3 -3
- package/lib/designs/items/CircleNode.js +1 -1
- package/lib/designs/items/CircularProgress.js +3 -2
- package/lib/designs/items/CompactCard.js +1 -1
- package/lib/designs/items/DoneList.js +1 -1
- package/lib/designs/items/HorizontalIconArrow.js +2 -2
- package/lib/designs/items/HorizontalIconLine.js +2 -2
- package/lib/designs/items/IconBadge.js +4 -3
- package/lib/designs/items/IndexedCard.js +1 -1
- package/lib/designs/items/LCornerCard.js +1 -1
- package/lib/designs/items/LetterCard.js +4 -3
- package/lib/designs/items/LinedText.js +6 -5
- package/lib/designs/items/PillBadge.js +2 -2
- package/lib/designs/items/PlainText.js +4 -4
- package/lib/designs/items/ProgressCard.js +4 -4
- package/lib/designs/items/QuarterCircular.js +1 -1
- package/lib/designs/items/QuarterSimpleCard.js +1 -1
- package/lib/designs/items/RibbonCard.js +2 -2
- package/lib/designs/items/RoundedRectNode.js +2 -2
- package/lib/designs/items/SimpleCircleNode.js +1 -1
- package/lib/designs/items/SimpleHorizontalArrow.js +2 -2
- package/lib/designs/items/SimpleIllusItem.js +1 -1
- package/lib/designs/items/SimpleItem.js +3 -3
- package/lib/designs/items/SimpleVerticalArrow.js +2 -2
- package/lib/designs/items/UnderlineText.js +1 -1
- package/lib/designs/items/VerticalIconArrow.js +2 -2
- package/lib/designs/layouts/Align.js +22 -15
- package/lib/designs/layouts/Flex.js +23 -16
- package/lib/designs/structures/chart-bar.js +7 -5
- package/lib/designs/structures/chart-column.js +3 -2
- package/lib/designs/structures/chart-line.js +7 -5
- package/lib/designs/structures/chart-pie.d.ts +25 -0
- package/lib/designs/structures/chart-pie.js +186 -25
- package/lib/designs/structures/chart-wordcloud.js +5 -14
- package/lib/designs/structures/compare-binary-horizontal/dividers/pros-cons-arrow.js +1 -1
- package/lib/designs/structures/compare-binary-horizontal/dividers/pros-cons-fold.js +1 -1
- package/lib/designs/structures/compare-binary-horizontal/dividers/types.js +2 -1
- package/lib/designs/structures/compare-hierarchy-left-right.js +6 -5
- package/lib/designs/structures/compare-hierarchy-row.js +3 -2
- package/lib/designs/structures/compare-quadrant.js +2 -3
- package/lib/designs/structures/hierarchy-mindmap.js +19 -19
- package/lib/designs/structures/hierarchy-structure.js +1 -1
- package/lib/designs/structures/hierarchy-tree.js +15 -24
- package/lib/designs/structures/list-sector.js +5 -6
- package/lib/designs/structures/list-zigzag.js +2 -1
- package/lib/designs/structures/relation-dagre-flow.js +30 -35
- package/lib/designs/structures/relation-network.js +2 -2
- package/lib/designs/structures/sequence-funnel.js +1 -1
- package/lib/designs/structures/sequence-mountain.js +4 -4
- package/lib/designs/structures/sequence-pyramid.js +1 -1
- package/lib/designs/structures/sequence-zigzag-steps.js +2 -1
- package/lib/designs/utils/color.js +8 -4
- package/lib/designs/utils/index.d.ts +1 -0
- package/lib/designs/utils/index.js +1 -0
- package/lib/designs/utils/item.js +3 -2
- package/lib/designs/utils/normalize-percent.d.ts +19 -0
- package/lib/designs/utils/normalize-percent.js +35 -0
- package/lib/editor/commands/Batch.js +21 -8
- package/lib/editor/commands/UpdateElement.js +25 -22
- package/lib/editor/commands/UpdateOptions.js +23 -10
- package/lib/editor/commands/UpdateText.js +24 -11
- package/lib/editor/interactions/brush-select.js +27 -13
- package/lib/editor/interactions/click-select.js +13 -3
- package/lib/editor/interactions/dblclick-edit-text.js +36 -20
- package/lib/editor/interactions/drag-element.js +23 -9
- package/lib/editor/interactions/hotkey-history.js +17 -7
- package/lib/editor/interactions/select-highlight.js +5 -9
- package/lib/editor/interactions/zoom-wheel.d.ts +3 -0
- package/lib/editor/interactions/zoom-wheel.js +45 -21
- package/lib/editor/managers/command.js +43 -25
- package/lib/editor/managers/interaction.js +46 -33
- package/lib/editor/managers/state.js +9 -3
- package/lib/editor/plugins/edit-bar/components/color-picker.js +9 -6
- package/lib/editor/plugins/edit-bar/components/popover.js +15 -12
- package/lib/editor/plugins/edit-bar/components/select.js +10 -8
- package/lib/editor/plugins/edit-bar/edit-bar.js +7 -25
- package/lib/editor/plugins/edit-bar/edit-items/align-elements.js +5 -3
- package/lib/editor/plugins/edit-bar/edit-items/font-align.js +1 -1
- package/lib/editor/plugins/edit-bar/edit-items/font-color.js +2 -2
- package/lib/editor/plugins/edit-bar/edit-items/icon-color.js +2 -2
- package/lib/editor/plugins/resize-element.js +6 -4
- package/lib/editor/utils/click-handler.js +6 -3
- package/lib/editor/utils/coordinate.js +2 -1
- package/lib/editor/utils/element.js +2 -1
- package/lib/editor/utils/event.js +2 -1
- package/lib/editor/utils/extension.js +1 -1
- package/lib/editor/utils/hotkey.js +2 -1
- package/lib/exporter/font.js +106 -90
- package/lib/exporter/png.js +49 -37
- package/lib/exporter/svg.js +55 -38
- package/lib/jsx/components/Ellipse.js +5 -4
- package/lib/jsx/components/Path.js +2 -4
- package/lib/jsx/components/Polygon.js +15 -6
- package/lib/jsx/components/Text.js +21 -41
- package/lib/jsx/renderer.js +15 -7
- package/lib/jsx/utils/bounds.js +18 -16
- package/lib/jsx/utils/children.js +2 -1
- package/lib/jsx/utils/clone.js +13 -2
- package/lib/jsx/utils/element.js +2 -1
- package/lib/options/parser.js +45 -46
- package/lib/renderer/composites/background.js +3 -2
- package/lib/renderer/composites/icon.js +14 -19
- package/lib/renderer/composites/illus.js +17 -22
- package/lib/renderer/composites/shape.js +4 -2
- package/lib/renderer/composites/svg.js +2 -1
- package/lib/renderer/composites/text.js +5 -3
- package/lib/renderer/fonts/loader.js +4 -3
- package/lib/renderer/fonts/registry.js +1 -1
- package/lib/renderer/palettes/utils.js +3 -2
- package/lib/renderer/renderer.js +7 -5
- package/lib/renderer/stylize/gradient.js +3 -2
- package/lib/renderer/stylize/pattern.js +15 -8
- package/lib/renderer/stylize/rough.js +1 -1
- package/lib/resource/load-tracker.js +22 -10
- package/lib/resource/loader.js +80 -67
- package/lib/resource/loaders/image.js +71 -59
- package/lib/resource/loaders/remote.js +26 -15
- package/lib/resource/loaders/search.js +38 -25
- package/lib/resource/utils/parser.js +2 -1
- package/lib/runtime/Infographic.js +26 -13
- package/lib/runtime/utils.js +5 -8
- package/lib/ssr/renderer.js +42 -35
- package/lib/syntax/index.js +19 -6
- package/lib/syntax/mapper.js +2 -2
- package/lib/templates/built-in.js +91 -269
- package/lib/templates/chart-pie.d.ts +2 -0
- package/lib/templates/chart-pie.js +90 -0
- package/lib/templates/hierarchy-mindmap.js +1 -5
- package/lib/templates/hierarchy-tree.js +1 -5
- package/lib/templates/relation-dagre-flow.js +4 -28
- package/lib/themes/generator.js +8 -14
- package/lib/utils/fetch.js +48 -35
- package/lib/utils/icon.js +1 -4
- package/lib/utils/is-browser.js +2 -2
- package/lib/utils/measure-text.js +2 -1
- package/lib/utils/padding.js +1 -1
- package/lib/utils/recognizer.js +2 -1
- package/lib/utils/text.js +14 -3
- package/lib/utils/viewbox.d.ts +20 -0
- package/lib/utils/viewbox.js +12 -0
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +1 -2
- package/src/designs/structures/chart-pie.tsx +259 -26
- package/src/designs/utils/index.ts +1 -0
- package/src/designs/utils/normalize-percent.ts +33 -0
- package/src/editor/interactions/zoom-wheel.ts +64 -22
- package/src/editor/managers/state.ts +10 -5
- package/src/templates/built-in.ts +2 -81
- package/src/templates/chart-pie.ts +89 -0
- package/src/utils/viewbox.ts +23 -0
- package/src/version.ts +1 -1
|
@@ -1,19 +1,32 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
1
10
|
export class UpdateOptionsCommand {
|
|
2
11
|
constructor(options, original) {
|
|
3
12
|
this.options = options;
|
|
4
13
|
this.original = original;
|
|
5
14
|
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
this.original
|
|
10
|
-
|
|
11
|
-
|
|
15
|
+
apply(state) {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
const prev = state.getOptions();
|
|
18
|
+
if (!this.original) {
|
|
19
|
+
this.original = prev;
|
|
20
|
+
}
|
|
21
|
+
state.updateOptions(Object.assign(Object.assign({}, prev), this.options));
|
|
22
|
+
});
|
|
12
23
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
24
|
+
undo(state) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
if (this.original) {
|
|
27
|
+
state.updateOptions(this.original);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
17
30
|
}
|
|
18
31
|
serialize() {
|
|
19
32
|
return {
|
|
@@ -1,22 +1,35 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
1
10
|
import { getElementRole, getTextContent, setTextContent } from '../../utils/index.js';
|
|
2
11
|
import { getIndexesFromElement } from '../utils/index.js';
|
|
3
12
|
export class UpdateTextCommand {
|
|
4
13
|
constructor(element, newText, originalText) {
|
|
5
14
|
this.element = element;
|
|
6
|
-
this.originalText = originalText
|
|
15
|
+
this.originalText = originalText !== null && originalText !== void 0 ? originalText : getTextContent(element);
|
|
7
16
|
this.modifiedText = newText;
|
|
8
17
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
18
|
+
apply(state) {
|
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
if (this.originalText === this.modifiedText)
|
|
21
|
+
return;
|
|
22
|
+
setTextContent(this.element, this.modifiedText);
|
|
23
|
+
updateItemText(state, this.element, this.modifiedText);
|
|
24
|
+
});
|
|
14
25
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
26
|
+
undo(state) {
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
if (this.originalText === this.modifiedText)
|
|
29
|
+
return;
|
|
30
|
+
setTextContent(this.element, this.originalText);
|
|
31
|
+
updateItemText(state, this.element, this.originalText);
|
|
32
|
+
});
|
|
20
33
|
}
|
|
21
34
|
serialize() {
|
|
22
35
|
return {
|
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
1
10
|
import { createElement, setAttributes } from '../../utils/index.js';
|
|
2
11
|
import { clientToViewport, getElementViewportBounds, getEventTarget, getSelectableTarget, } from '../utils/index.js';
|
|
3
12
|
import { Interaction } from './base.js';
|
|
@@ -17,15 +26,17 @@ export class BrushSelect extends Interaction {
|
|
|
17
26
|
return;
|
|
18
27
|
if (this.hasElementAtStart(event.target))
|
|
19
28
|
return;
|
|
20
|
-
this.interaction.executeExclusiveInteraction(this,
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
+
this.interaction.executeExclusiveInteraction(this, () => __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
return new Promise((resolve) => {
|
|
31
|
+
this.completeInteraction = resolve;
|
|
32
|
+
const svg = this.editor.getDocument();
|
|
33
|
+
this.startPoint = clientToViewport(svg, event.clientX, event.clientY);
|
|
34
|
+
this.pointerId = event.pointerId;
|
|
35
|
+
this.shiftKey = event.shiftKey;
|
|
36
|
+
this.dragging = false;
|
|
37
|
+
window.addEventListener('pointermove', this.handleMove);
|
|
38
|
+
window.addEventListener('pointerup', this.handleEnd);
|
|
39
|
+
});
|
|
29
40
|
}));
|
|
30
41
|
};
|
|
31
42
|
this.handleMove = (event) => {
|
|
@@ -47,6 +58,7 @@ export class BrushSelect extends Interaction {
|
|
|
47
58
|
this.updateBrush(this.startPoint, current);
|
|
48
59
|
};
|
|
49
60
|
this.handleEnd = (event) => {
|
|
61
|
+
var _a, _b;
|
|
50
62
|
if (event.pointerId !== this.pointerId || !this.startPoint)
|
|
51
63
|
return;
|
|
52
64
|
window.removeEventListener('pointermove', this.handleMove);
|
|
@@ -66,12 +78,12 @@ export class BrushSelect extends Interaction {
|
|
|
66
78
|
const withShift = this.shiftKey;
|
|
67
79
|
this.shiftKey = false;
|
|
68
80
|
if (!rect) {
|
|
69
|
-
this.completeInteraction
|
|
81
|
+
(_a = this.completeInteraction) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
70
82
|
this.completeInteraction = undefined;
|
|
71
83
|
return;
|
|
72
84
|
}
|
|
73
85
|
const selection = this.collectSelection(rect);
|
|
74
|
-
this.completeInteraction
|
|
86
|
+
(_b = this.completeInteraction) === null || _b === void 0 ? void 0 : _b.call(this);
|
|
75
87
|
this.completeInteraction = undefined;
|
|
76
88
|
if (selection.length === 0) {
|
|
77
89
|
if (!withShift)
|
|
@@ -117,7 +129,8 @@ export class BrushSelect extends Interaction {
|
|
|
117
129
|
return { x, y, width, height };
|
|
118
130
|
}
|
|
119
131
|
clearBrush() {
|
|
120
|
-
|
|
132
|
+
var _a;
|
|
133
|
+
(_a = this.brush) === null || _a === void 0 ? void 0 : _a.remove();
|
|
121
134
|
this.brush = undefined;
|
|
122
135
|
}
|
|
123
136
|
collectSelection(rect) {
|
|
@@ -150,11 +163,12 @@ export class BrushSelect extends Interaction {
|
|
|
150
163
|
}, []);
|
|
151
164
|
}
|
|
152
165
|
hasElementAtStart(target) {
|
|
166
|
+
var _a;
|
|
153
167
|
if (!(target instanceof Element))
|
|
154
168
|
return false;
|
|
155
169
|
if (getEventTarget(target))
|
|
156
170
|
return true;
|
|
157
|
-
return Boolean(target.closest
|
|
171
|
+
return Boolean((_a = target.closest) === null || _a === void 0 ? void 0 : _a.call(target, '[data-element-type]'));
|
|
158
172
|
}
|
|
159
173
|
isTextSelectionTarget(target) {
|
|
160
174
|
if (!(target instanceof HTMLElement))
|
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
1
10
|
import { isEditingText } from '../../utils/index.js';
|
|
2
11
|
import { ClickHandler, getEventTarget } from '../utils/index.js';
|
|
3
12
|
import { Interaction } from './base.js';
|
|
@@ -29,7 +38,7 @@ export class ClickSelect extends Interaction {
|
|
|
29
38
|
const handleSelect = (event) => {
|
|
30
39
|
if (!interaction.isActive())
|
|
31
40
|
return;
|
|
32
|
-
interaction.executeExclusiveInteraction(this,
|
|
41
|
+
interaction.executeExclusiveInteraction(this, () => __awaiter(this, void 0, void 0, function* () {
|
|
33
42
|
const target = getEventTarget(event.target);
|
|
34
43
|
if (isEditingText(target))
|
|
35
44
|
return;
|
|
@@ -51,7 +60,7 @@ export class ClickSelect extends Interaction {
|
|
|
51
60
|
else
|
|
52
61
|
interaction.clearSelection();
|
|
53
62
|
}
|
|
54
|
-
});
|
|
63
|
+
}));
|
|
55
64
|
};
|
|
56
65
|
this.clickHandler.onClick(handleSelect);
|
|
57
66
|
document.addEventListener('keydown', this.onShiftKeyDown);
|
|
@@ -59,7 +68,8 @@ export class ClickSelect extends Interaction {
|
|
|
59
68
|
document.addEventListener('keydown', this.onEscKeyDown);
|
|
60
69
|
}
|
|
61
70
|
destroy() {
|
|
62
|
-
|
|
71
|
+
var _a;
|
|
72
|
+
(_a = this.clickHandler) === null || _a === void 0 ? void 0 : _a.destroy();
|
|
63
73
|
document.removeEventListener('keydown', this.onShiftKeyDown);
|
|
64
74
|
document.removeEventListener('keyup', this.onShiftKeyUp);
|
|
65
75
|
document.removeEventListener('keydown', this.onEscKeyDown);
|
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
1
10
|
import { getTextContent, getTextEntity, injectStyleOnce, isEditableText, } from '../../utils/index.js';
|
|
2
11
|
import { UpdateTextCommand } from '../commands/index.js';
|
|
3
12
|
import { ClickHandler, getEventTarget } from '../utils/index.js';
|
|
@@ -13,14 +22,14 @@ export class DblClickEditText extends Interaction {
|
|
|
13
22
|
this.clickHandler = new ClickHandler(editor.getDocument()).onDoubleClick((event) => {
|
|
14
23
|
if (!interaction.isActive())
|
|
15
24
|
return;
|
|
16
|
-
interaction.executeExclusiveInteraction(this,
|
|
25
|
+
interaction.executeExclusiveInteraction(this, () => __awaiter(this, void 0, void 0, function* () {
|
|
17
26
|
const target = getEventTarget(event.target);
|
|
18
27
|
if (!target)
|
|
19
28
|
return;
|
|
20
29
|
if (isEditableText(target)) {
|
|
21
30
|
interaction.select([target], 'replace');
|
|
22
31
|
const originalText = getTextContent(target);
|
|
23
|
-
const text =
|
|
32
|
+
const text = yield new Promise((resolve) => {
|
|
24
33
|
const stopListen = this.listenSelectionChange(target);
|
|
25
34
|
editText(target, {
|
|
26
35
|
cursorPosition: {
|
|
@@ -34,17 +43,19 @@ export class DblClickEditText extends Interaction {
|
|
|
34
43
|
});
|
|
35
44
|
commander.execute(new UpdateTextCommand(target, text, originalText));
|
|
36
45
|
}
|
|
37
|
-
});
|
|
46
|
+
}));
|
|
38
47
|
});
|
|
39
48
|
}
|
|
40
49
|
destroy() {
|
|
41
|
-
|
|
42
|
-
this.
|
|
50
|
+
var _a, _b;
|
|
51
|
+
(_a = this.clickHandler) === null || _a === void 0 ? void 0 : _a.destroy();
|
|
52
|
+
(_b = this.detachSelectionListener) === null || _b === void 0 ? void 0 : _b.call(this);
|
|
43
53
|
}
|
|
44
54
|
listenSelectionChange(target) {
|
|
45
55
|
const handler = ({ next }) => {
|
|
56
|
+
var _a;
|
|
46
57
|
if (!next.includes(target)) {
|
|
47
|
-
this.detachSelectionListener
|
|
58
|
+
(_a = this.detachSelectionListener) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
48
59
|
this.detachSelectionListener = undefined;
|
|
49
60
|
const entity = getTextEntity(target);
|
|
50
61
|
if (entity)
|
|
@@ -81,14 +92,16 @@ class InlineTextEditor {
|
|
|
81
92
|
}
|
|
82
93
|
};
|
|
83
94
|
this.handleInput = () => {
|
|
95
|
+
var _a, _b;
|
|
84
96
|
this.normalizeSpanContent();
|
|
85
|
-
this.options
|
|
97
|
+
(_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.onInput) === null || _b === void 0 ? void 0 : _b.call(_a, this.getText());
|
|
86
98
|
};
|
|
87
99
|
this.handleBlur = () => {
|
|
100
|
+
var _a, _b;
|
|
88
101
|
this.entity.removeAttribute('contenteditable');
|
|
89
102
|
this.entity.classList.remove(EDITOR_BASE_CLASS);
|
|
90
103
|
this.normalizeSpanContent();
|
|
91
|
-
this.options
|
|
104
|
+
(_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.onBlur) === null || _b === void 0 ? void 0 : _b.call(_a, this.getText());
|
|
92
105
|
this.detachListeners();
|
|
93
106
|
};
|
|
94
107
|
}
|
|
@@ -111,6 +124,7 @@ class InlineTextEditor {
|
|
|
111
124
|
this.entity.removeEventListener('input', this.handleInput);
|
|
112
125
|
}
|
|
113
126
|
insertPlainText(text) {
|
|
127
|
+
var _a, _b;
|
|
114
128
|
const selection = window.getSelection();
|
|
115
129
|
if (!selection)
|
|
116
130
|
return;
|
|
@@ -129,11 +143,12 @@ class InlineTextEditor {
|
|
|
129
143
|
selection.addRange(range);
|
|
130
144
|
// Mirror native input behavior so consumers stay in sync.
|
|
131
145
|
this.normalizeSpanContent();
|
|
132
|
-
this.options
|
|
146
|
+
(_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.onInput) === null || _b === void 0 ? void 0 : _b.call(_a, this.getText());
|
|
133
147
|
}
|
|
134
148
|
normalizeSpanContent() {
|
|
149
|
+
var _a;
|
|
135
150
|
if (this.entity.childNodes.length === 1 &&
|
|
136
|
-
this.entity.firstChild
|
|
151
|
+
((_a = this.entity.firstChild) === null || _a === void 0 ? void 0 : _a.nodeType) === Node.TEXT_NODE) {
|
|
137
152
|
return;
|
|
138
153
|
}
|
|
139
154
|
const plainText = this.getText();
|
|
@@ -152,21 +167,22 @@ class InlineTextEditor {
|
|
|
152
167
|
this.placeCaretAtEnd();
|
|
153
168
|
}
|
|
154
169
|
getRangeFromPoint() {
|
|
170
|
+
var _a, _b;
|
|
155
171
|
const { cursorPosition } = this.options || {};
|
|
156
172
|
if (!cursorPosition)
|
|
157
173
|
return null;
|
|
158
174
|
const { clientX, clientY } = cursorPosition;
|
|
159
175
|
const doc = document;
|
|
160
|
-
const rangeFromPoint = doc.caretRangeFromPoint
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
176
|
+
const rangeFromPoint = (_b = (_a = doc.caretRangeFromPoint) === null || _a === void 0 ? void 0 : _a.call(doc, clientX, clientY)) !== null && _b !== void 0 ? _b : (() => {
|
|
177
|
+
var _a;
|
|
178
|
+
const caretPosition = (_a = doc.caretPositionFromPoint) === null || _a === void 0 ? void 0 : _a.call(doc, clientX, clientY);
|
|
179
|
+
if (!caretPosition)
|
|
180
|
+
return null;
|
|
181
|
+
const caretRange = document.createRange();
|
|
182
|
+
caretRange.setStart(caretPosition.offsetNode, caretPosition.offset);
|
|
183
|
+
caretRange.collapse(true);
|
|
184
|
+
return caretRange;
|
|
185
|
+
})();
|
|
170
186
|
if (!rangeFromPoint)
|
|
171
187
|
return null;
|
|
172
188
|
if (!this.entity.contains(rangeFromPoint.startContainer))
|
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
1
10
|
import { getCombinedBounds } from '../../jsx/utils/bounds.js';
|
|
2
11
|
import { createElement, getAttributes, isEditableText, isEditingText, setAttributes, } from '../../utils/index.js';
|
|
3
12
|
import { UpdateElementCommand } from '../commands/index.js';
|
|
@@ -114,9 +123,11 @@ export class DragElement extends Interaction {
|
|
|
114
123
|
if (this.dragItems.length === 0)
|
|
115
124
|
return false;
|
|
116
125
|
let started = false;
|
|
117
|
-
this.interaction.executeExclusiveInteraction(this,
|
|
118
|
-
|
|
119
|
-
|
|
126
|
+
this.interaction.executeExclusiveInteraction(this, () => __awaiter(this, void 0, void 0, function* () {
|
|
127
|
+
return new Promise((resolve) => {
|
|
128
|
+
this.completeInteraction = resolve;
|
|
129
|
+
started = true;
|
|
130
|
+
});
|
|
120
131
|
}));
|
|
121
132
|
this.exclusiveStarted = started;
|
|
122
133
|
return started;
|
|
@@ -252,7 +263,8 @@ export class DragElement extends Interaction {
|
|
|
252
263
|
return rest && rest.length ? `${translate} ${rest}` : translate;
|
|
253
264
|
}
|
|
254
265
|
emitGeometryChange() {
|
|
255
|
-
|
|
266
|
+
var _a;
|
|
267
|
+
const target = (_a = this.dragItems[0]) === null || _a === void 0 ? void 0 : _a.element;
|
|
256
268
|
if (!target)
|
|
257
269
|
return;
|
|
258
270
|
const rect = getElementViewportBounds(this.editor.getDocument(), target);
|
|
@@ -268,6 +280,7 @@ export class DragElement extends Interaction {
|
|
|
268
280
|
window.removeEventListener('pointercancel', this.handleEnd);
|
|
269
281
|
}
|
|
270
282
|
reset() {
|
|
283
|
+
var _a;
|
|
271
284
|
this.detachPointerListeners();
|
|
272
285
|
this.clearGuides();
|
|
273
286
|
this.pointerId = undefined;
|
|
@@ -280,7 +293,7 @@ export class DragElement extends Interaction {
|
|
|
280
293
|
this.dragging = false;
|
|
281
294
|
this.startBounds = undefined;
|
|
282
295
|
this.guideCandidates = undefined;
|
|
283
|
-
this.completeInteraction
|
|
296
|
+
(_a = this.completeInteraction) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
284
297
|
this.completeInteraction = undefined;
|
|
285
298
|
}
|
|
286
299
|
getSelectionBounds(selection) {
|
|
@@ -315,8 +328,8 @@ export class DragElement extends Interaction {
|
|
|
315
328
|
const snapX = this.getSnapOffset([moving.x, moving.x + moving.width / 2, moving.x + moving.width], this.guideCandidates.vertical);
|
|
316
329
|
const snapY = this.getSnapOffset([moving.y, moving.y + moving.height / 2, moving.y + moving.height], this.guideCandidates.horizontal);
|
|
317
330
|
return {
|
|
318
|
-
dx: dx + (snapX
|
|
319
|
-
dy: dy + (snapY
|
|
331
|
+
dx: dx + ((snapX === null || snapX === void 0 ? void 0 : snapX.offset) || 0),
|
|
332
|
+
dy: dy + ((snapY === null || snapY === void 0 ? void 0 : snapY.offset) || 0),
|
|
320
333
|
snapX,
|
|
321
334
|
snapY,
|
|
322
335
|
};
|
|
@@ -383,8 +396,9 @@ export class DragElement extends Interaction {
|
|
|
383
396
|
}
|
|
384
397
|
}
|
|
385
398
|
clearGuides() {
|
|
386
|
-
|
|
387
|
-
this.
|
|
399
|
+
var _a, _b;
|
|
400
|
+
(_a = this.guideVertical) === null || _a === void 0 ? void 0 : _a.remove();
|
|
401
|
+
(_b = this.guideHorizontal) === null || _b === void 0 ? void 0 : _b.remove();
|
|
388
402
|
this.guideVertical = undefined;
|
|
389
403
|
this.guideHorizontal = undefined;
|
|
390
404
|
}
|
|
@@ -1,17 +1,26 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
1
10
|
import { Hotkey } from '../utils/index.js';
|
|
2
11
|
import { Interaction } from './base.js';
|
|
3
12
|
export class HotkeyHistory extends Interaction {
|
|
4
13
|
constructor() {
|
|
5
14
|
super(...arguments);
|
|
6
15
|
this.name = 'hotkey-history';
|
|
7
|
-
this.handleUndo =
|
|
16
|
+
this.handleUndo = (event) => __awaiter(this, void 0, void 0, function* () {
|
|
8
17
|
event.preventDefault();
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
this.handleRedo =
|
|
18
|
+
yield this.commander.undo();
|
|
19
|
+
});
|
|
20
|
+
this.handleRedo = (event) => __awaiter(this, void 0, void 0, function* () {
|
|
12
21
|
event.preventDefault();
|
|
13
|
-
|
|
14
|
-
};
|
|
22
|
+
yield this.commander.redo();
|
|
23
|
+
});
|
|
15
24
|
}
|
|
16
25
|
init(options) {
|
|
17
26
|
super.init(options);
|
|
@@ -22,6 +31,7 @@ export class HotkeyHistory extends Interaction {
|
|
|
22
31
|
this.hotkey.bind(['mod+shift+z', 'mod+y'], this.handleRedo);
|
|
23
32
|
}
|
|
24
33
|
destroy() {
|
|
25
|
-
|
|
34
|
+
var _a;
|
|
35
|
+
(_a = this.hotkey) === null || _a === void 0 ? void 0 : _a.destroy();
|
|
26
36
|
}
|
|
27
37
|
}
|
|
@@ -70,19 +70,14 @@ export class SelectHighlight extends Interaction {
|
|
|
70
70
|
this.highlightMasks = this.highlightMasks.slice(0, selection.length);
|
|
71
71
|
}
|
|
72
72
|
drawCombinedBoundsMask(selection) {
|
|
73
|
+
var _a;
|
|
73
74
|
if (selection.length < 2) {
|
|
74
|
-
this.combinedBoundsMask
|
|
75
|
+
(_a = this.combinedBoundsMask) === null || _a === void 0 ? void 0 : _a.remove();
|
|
75
76
|
this.combinedBoundsMask = undefined;
|
|
76
77
|
return;
|
|
77
78
|
}
|
|
78
79
|
const bounds = getCombinedBounds(selection.map((element) => getElementViewportBounds(this.editor.getDocument(), element)));
|
|
79
|
-
const attrs = {
|
|
80
|
-
...bounds,
|
|
81
|
-
fill: 'none',
|
|
82
|
-
stroke: '#3384F5',
|
|
83
|
-
'stroke-width': 2,
|
|
84
|
-
'pointer-events': 'none',
|
|
85
|
-
};
|
|
80
|
+
const attrs = Object.assign(Object.assign({}, bounds), { fill: 'none', stroke: '#3384F5', 'stroke-width': 2, 'pointer-events': 'none' });
|
|
86
81
|
if (this.combinedBoundsMask) {
|
|
87
82
|
setAttributes(this.combinedBoundsMask, attrs);
|
|
88
83
|
}
|
|
@@ -91,9 +86,10 @@ export class SelectHighlight extends Interaction {
|
|
|
91
86
|
}
|
|
92
87
|
}
|
|
93
88
|
clearMasks() {
|
|
89
|
+
var _a;
|
|
94
90
|
this.highlightMasks.forEach((mask) => mask.remove());
|
|
95
91
|
this.highlightMasks = [];
|
|
96
|
-
this.combinedBoundsMask
|
|
92
|
+
(_a = this.combinedBoundsMask) === null || _a === void 0 ? void 0 : _a.remove();
|
|
97
93
|
this.combinedBoundsMask = undefined;
|
|
98
94
|
}
|
|
99
95
|
}
|
|
@@ -3,6 +3,9 @@ import { Interaction } from './base';
|
|
|
3
3
|
export declare class ZoomWheel extends Interaction implements IInteraction {
|
|
4
4
|
name: string;
|
|
5
5
|
private wheelListener;
|
|
6
|
+
private getMousePoint;
|
|
7
|
+
private getCenterPoint;
|
|
8
|
+
private shouldZoom;
|
|
6
9
|
init(options: InteractionInitOptions): void;
|
|
7
10
|
destroy(): void;
|
|
8
11
|
}
|
|
@@ -1,40 +1,64 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { inRange } from 'lodash-es';
|
|
2
|
+
import { calculateZoomedViewBox, getViewBox, viewBoxToString, } from '../../utils/viewbox.js';
|
|
3
3
|
import { UpdateOptionsCommand } from '../commands/index.js';
|
|
4
|
+
import { clientToViewport } from '../utils/index.js';
|
|
4
5
|
import { Interaction } from './base.js';
|
|
5
|
-
const MIN_VIEWBOX_SIZE =
|
|
6
|
-
const
|
|
7
|
-
const
|
|
6
|
+
const MIN_VIEWBOX_SIZE = 20;
|
|
7
|
+
const MAX_VIEWBOX_SIZE = 2000;
|
|
8
|
+
const ZOOM_FACTOR = 1.1;
|
|
8
9
|
export class ZoomWheel extends Interaction {
|
|
9
10
|
constructor() {
|
|
10
11
|
super(...arguments);
|
|
11
12
|
this.name = 'zoom-wheel';
|
|
12
13
|
this.wheelListener = (event) => {
|
|
13
|
-
if (!this.
|
|
14
|
-
return;
|
|
15
|
-
if (!event.ctrlKey && !event.metaKey)
|
|
14
|
+
if (!this.shouldZoom(event))
|
|
16
15
|
return;
|
|
17
16
|
event.preventDefault();
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const parsed = parsePadding(currentPadding);
|
|
17
|
+
// Standard Zoom: Scroll Up (deltaY < 0) = Zoom In
|
|
18
|
+
const isZoomIn = event.deltaY < 0;
|
|
19
|
+
const factor = isZoomIn ? 1 / ZOOM_FACTOR : ZOOM_FACTOR;
|
|
22
20
|
const svg = this.editor.getDocument();
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
if (
|
|
21
|
+
const viewBox = getViewBox(svg);
|
|
22
|
+
const { width, height } = viewBox;
|
|
23
|
+
const newWidth = width * factor;
|
|
24
|
+
const newHeight = height * factor;
|
|
25
|
+
if (!inRange(newWidth, MIN_VIEWBOX_SIZE, MAX_VIEWBOX_SIZE) ||
|
|
26
|
+
!inRange(newHeight, MIN_VIEWBOX_SIZE, MAX_VIEWBOX_SIZE))
|
|
27
|
+
return;
|
|
28
|
+
// TODO: Remove after implementing the reset UI plugin
|
|
29
|
+
if ((event.ctrlKey || event.metaKey) && event.shiftKey) {
|
|
30
|
+
const command = new UpdateOptionsCommand({
|
|
31
|
+
viewBox: undefined,
|
|
32
|
+
});
|
|
33
|
+
void this.commander.execute(command);
|
|
32
34
|
return;
|
|
35
|
+
}
|
|
36
|
+
const pivot = (event.ctrlKey || event.metaKey) && !event.shiftKey
|
|
37
|
+
? this.getMousePoint(svg, event)
|
|
38
|
+
: this.getCenterPoint(viewBox);
|
|
39
|
+
const newViewBox = calculateZoomedViewBox(viewBox, factor, pivot);
|
|
33
40
|
const command = new UpdateOptionsCommand({
|
|
34
|
-
|
|
41
|
+
viewBox: viewBoxToString(newViewBox),
|
|
35
42
|
});
|
|
36
43
|
void this.commander.execute(command);
|
|
37
44
|
};
|
|
45
|
+
this.getMousePoint = (svg, event) => {
|
|
46
|
+
return clientToViewport(svg, event.clientX, event.clientY);
|
|
47
|
+
};
|
|
48
|
+
this.getCenterPoint = (viewBox) => {
|
|
49
|
+
const centerX = viewBox.x + viewBox.width / 2;
|
|
50
|
+
const centerY = viewBox.y + viewBox.height / 2;
|
|
51
|
+
return { x: centerX, y: centerY };
|
|
52
|
+
};
|
|
53
|
+
this.shouldZoom = (event) => {
|
|
54
|
+
if (!this.interaction.isActive())
|
|
55
|
+
return false;
|
|
56
|
+
if (event.deltaY === 0)
|
|
57
|
+
return false;
|
|
58
|
+
const isMouseZoom = event.ctrlKey || event.metaKey;
|
|
59
|
+
const isCenterZoom = event.shiftKey;
|
|
60
|
+
return isMouseZoom || isCenterZoom;
|
|
61
|
+
};
|
|
38
62
|
}
|
|
39
63
|
init(options) {
|
|
40
64
|
super.init(options);
|