@antv/infographic 0.2.11 → 0.2.12
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 +1 -1
- 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.js +4 -3
- 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/item.js +3 -2
- 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.js +2 -1
- package/esm/editor/managers/command.js +45 -27
- package/esm/editor/managers/interaction.js +46 -33
- package/esm/editor/managers/state.js +1 -1
- 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 +96 -200
- 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/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.js +4 -3
- 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/item.js +3 -2
- 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.js +2 -1
- package/lib/editor/managers/command.js +43 -25
- package/lib/editor/managers/interaction.js +46 -33
- package/lib/editor/managers/state.js +1 -1
- 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 +96 -200
- 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/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +1 -1
- package/src/version.ts +1 -1
|
@@ -28,8 +28,9 @@ const ALIGN_OPTIONS = [
|
|
|
28
28
|
{ icon: ELEMENT_ICONS.distributeV, action: 'V_DISTRIBUTE' },
|
|
29
29
|
];
|
|
30
30
|
export const ElementAlign = (selection, _attrs, commander, options) => {
|
|
31
|
+
var _a;
|
|
31
32
|
injectStyleOnce(GRID_STYLE_ID, GRID_STYLES);
|
|
32
|
-
const enableDistribution = options
|
|
33
|
+
const enableDistribution = (_a = options === null || options === void 0 ? void 0 : options.enableDistribution) !== null && _a !== void 0 ? _a : true;
|
|
33
34
|
const content = createAlignContent((action) => alignSelection(selection, action, commander), enableDistribution);
|
|
34
35
|
return Popover({
|
|
35
36
|
target: IconButton({ icon: ELEMENT_ICONS.align }),
|
|
@@ -284,6 +285,7 @@ function getAttrInfo(element, bounds) {
|
|
|
284
285
|
return { x, y, hasX, hasY, hasDataX, hasDataY };
|
|
285
286
|
}
|
|
286
287
|
function getTransformInfo(element) {
|
|
288
|
+
var _a;
|
|
287
289
|
const transform = element.getAttribute('transform');
|
|
288
290
|
if (transform === null)
|
|
289
291
|
return null;
|
|
@@ -299,7 +301,7 @@ function getTransformInfo(element) {
|
|
|
299
301
|
}
|
|
300
302
|
const x = Number(match[1]) || 0;
|
|
301
303
|
const y = match[2] !== undefined ? Number(match[2]) || 0 : 0;
|
|
302
|
-
const start = match.index
|
|
304
|
+
const start = (_a = match.index) !== null && _a !== void 0 ? _a : 0;
|
|
303
305
|
const before = transform.slice(0, start).trim();
|
|
304
306
|
const after = transform.slice(start + match[0].length).trim();
|
|
305
307
|
const rest = { before, after };
|
|
@@ -307,6 +309,6 @@ function getTransformInfo(element) {
|
|
|
307
309
|
}
|
|
308
310
|
function composeTransform(x, y, rest) {
|
|
309
311
|
const translate = `translate(${x}, ${y})`;
|
|
310
|
-
const parts = [rest
|
|
312
|
+
const parts = [rest === null || rest === void 0 ? void 0 : rest.before, translate, rest === null || rest === void 0 ? void 0 : rest.after].filter((part) => part && part.length);
|
|
311
313
|
return parts.join(' ');
|
|
312
314
|
}
|
|
@@ -67,7 +67,7 @@ function createAlignContent(state, onAlignChange) {
|
|
|
67
67
|
return;
|
|
68
68
|
Object.assign(state, { [stateKey]: align });
|
|
69
69
|
updateAllButtons();
|
|
70
|
-
onAlignChange({
|
|
70
|
+
onAlignChange(Object.assign({}, state));
|
|
71
71
|
},
|
|
72
72
|
activate: align === state[stateKey],
|
|
73
73
|
});
|
|
@@ -11,9 +11,9 @@ export const FontColor = (selection, attrs, commander) => {
|
|
|
11
11
|
const button = document.createElement('button');
|
|
12
12
|
button.type = 'button';
|
|
13
13
|
button.classList.add(FONT_COLOR_BUTTON_CLASS);
|
|
14
|
-
setButtonColor(button, color
|
|
14
|
+
setButtonColor(button, color !== null && color !== void 0 ? color : DEFAULT_COLOR, isMixed);
|
|
15
15
|
const picker = ColorPicker({
|
|
16
|
-
value: color
|
|
16
|
+
value: color !== null && color !== void 0 ? color : DEFAULT_COLOR,
|
|
17
17
|
onChange: (nextColor) => {
|
|
18
18
|
setButtonColor(button, nextColor, false);
|
|
19
19
|
commander.executeBatch(selection.map((text) => new UpdateElementCommand(text, {
|
|
@@ -11,9 +11,9 @@ export const IconColor = (selection, attrs, commander) => {
|
|
|
11
11
|
const button = document.createElement('button');
|
|
12
12
|
button.type = 'button';
|
|
13
13
|
button.classList.add(ICON_COLOR_BUTTON_CLASS);
|
|
14
|
-
setButtonColor(button, color
|
|
14
|
+
setButtonColor(button, color !== null && color !== void 0 ? color : DEFAULT_COLOR, isMixed);
|
|
15
15
|
const picker = ColorPicker({
|
|
16
|
-
value: color
|
|
16
|
+
value: color !== null && color !== void 0 ? color : DEFAULT_COLOR,
|
|
17
17
|
onChange: (nextColor) => {
|
|
18
18
|
setButtonColor(button, nextColor, false);
|
|
19
19
|
commander.executeBatch(selection.map((icon) => new UpdateElementCommand(icon, {
|
|
@@ -205,7 +205,8 @@ export class ResizeElement extends Plugin {
|
|
|
205
205
|
this.handles.forEach((handle) => (handle.style.display = 'none'));
|
|
206
206
|
}
|
|
207
207
|
removeContainer() {
|
|
208
|
-
|
|
208
|
+
var _a;
|
|
209
|
+
(_a = this.container) === null || _a === void 0 ? void 0 : _a.remove();
|
|
209
210
|
this.container = undefined;
|
|
210
211
|
this.outline = undefined;
|
|
211
212
|
this.overlay = undefined;
|
|
@@ -224,7 +225,7 @@ export class ResizeElement extends Plugin {
|
|
|
224
225
|
this.startPointer = point;
|
|
225
226
|
const currentRect = this.getCurrentAttributes(this.target);
|
|
226
227
|
this.startRect = currentRect;
|
|
227
|
-
this.startAttrs = {
|
|
228
|
+
this.startAttrs = Object.assign({}, currentRect);
|
|
228
229
|
this.lastRect = currentRect;
|
|
229
230
|
this.lastViewportRect = this.getViewportRect(this.target);
|
|
230
231
|
window.addEventListener('pointermove', this.handlePointerMove);
|
|
@@ -256,8 +257,9 @@ export class ResizeElement extends Plugin {
|
|
|
256
257
|
return { x, y, width, height };
|
|
257
258
|
}
|
|
258
259
|
clientToElement(element, x, y) {
|
|
259
|
-
|
|
260
|
-
|
|
260
|
+
var _a, _b;
|
|
261
|
+
const matrix = ((_a = element.getScreenCTM()) === null || _a === void 0 ? void 0 : _a.inverse()) ||
|
|
262
|
+
((_b = this.editor.getDocument().getScreenCTM()) === null || _b === void 0 ? void 0 : _b.inverse()) ||
|
|
261
263
|
new DOMMatrix();
|
|
262
264
|
return new DOMPoint(x, y).matrixTransform(matrix);
|
|
263
265
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export class ClickHandler {
|
|
2
2
|
constructor(element, options = {}) {
|
|
3
|
+
var _a;
|
|
3
4
|
this.clickTimer = null;
|
|
4
5
|
this.singleClickCallback = null;
|
|
5
6
|
this.doubleClickCallback = null;
|
|
@@ -48,7 +49,7 @@ export class ClickHandler {
|
|
|
48
49
|
};
|
|
49
50
|
this.element = element;
|
|
50
51
|
this.delay = options.delay || 300;
|
|
51
|
-
this.dragThreshold = options.dragThreshold
|
|
52
|
+
this.dragThreshold = (_a = options.dragThreshold) !== null && _a !== void 0 ? _a : 4;
|
|
52
53
|
this.init();
|
|
53
54
|
}
|
|
54
55
|
init() {
|
|
@@ -64,17 +65,19 @@ export class ClickHandler {
|
|
|
64
65
|
if (this.clickTimer)
|
|
65
66
|
clearTimeout(this.clickTimer);
|
|
66
67
|
this.clickTimer = window.setTimeout(() => {
|
|
67
|
-
|
|
68
|
+
var _a;
|
|
69
|
+
(_a = this.singleClickCallback) === null || _a === void 0 ? void 0 : _a.call(this, e);
|
|
68
70
|
}, this.delay);
|
|
69
71
|
}
|
|
70
72
|
handleDoubleClick(e) {
|
|
73
|
+
var _a;
|
|
71
74
|
if (this.skipClick) {
|
|
72
75
|
this.skipClick = false;
|
|
73
76
|
return;
|
|
74
77
|
}
|
|
75
78
|
if (this.clickTimer)
|
|
76
79
|
clearTimeout(this.clickTimer);
|
|
77
|
-
this.doubleClickCallback
|
|
80
|
+
(_a = this.doubleClickCallback) === null || _a === void 0 ? void 0 : _a.call(this, e);
|
|
78
81
|
}
|
|
79
82
|
onClick(callback) {
|
|
80
83
|
this.singleClickCallback = callback;
|
|
@@ -2,7 +2,8 @@ export function getScreenCTM(svg) {
|
|
|
2
2
|
return svg.getScreenCTM() || new DOMMatrix();
|
|
3
3
|
}
|
|
4
4
|
export function getInverseScreenCTM(svg) {
|
|
5
|
-
|
|
5
|
+
var _a;
|
|
6
|
+
return ((_a = svg.getScreenCTM()) === null || _a === void 0 ? void 0 : _a.inverse()) || new DOMMatrix();
|
|
6
7
|
}
|
|
7
8
|
export function viewportToClient(svg, x, y) {
|
|
8
9
|
const svgPoint = new DOMPoint(x, y).matrixTransform(getScreenCTM(svg));
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getIconEntity, isIconElement } from '../../utils/index.js';
|
|
2
2
|
export function getIndexesFromElement(element) {
|
|
3
|
-
|
|
3
|
+
var _a, _b;
|
|
4
|
+
return (((_b = (_a = getElementEntity(element)) === null || _a === void 0 ? void 0 : _a.dataset.indexes) === null || _b === void 0 ? void 0 : _b.split(',').map(Number)) || []);
|
|
4
5
|
}
|
|
5
6
|
function getElementEntity(element) {
|
|
6
7
|
if (isIconElement(element))
|
|
@@ -32,6 +32,7 @@ export function getSelectableTarget(element) {
|
|
|
32
32
|
return null;
|
|
33
33
|
}
|
|
34
34
|
const getRoughEventTarget = (element) => {
|
|
35
|
+
var _a;
|
|
35
36
|
const is = (ele) => {
|
|
36
37
|
if (!ele)
|
|
37
38
|
return false;
|
|
@@ -41,7 +42,7 @@ const getRoughEventTarget = (element) => {
|
|
|
41
42
|
return element.parentElement;
|
|
42
43
|
}
|
|
43
44
|
if (is(element.parentElement)) {
|
|
44
|
-
return element.parentElement
|
|
45
|
+
return (_a = element.parentElement) === null || _a === void 0 ? void 0 : _a.parentElement;
|
|
45
46
|
}
|
|
46
47
|
return null;
|
|
47
48
|
};
|
|
@@ -3,7 +3,7 @@ export class Extension {
|
|
|
3
3
|
this.extensions = new Map();
|
|
4
4
|
}
|
|
5
5
|
register(name, extension, options) {
|
|
6
|
-
if (!options
|
|
6
|
+
if (!(options === null || options === void 0 ? void 0 : options.override) && this.extensions.has(name)) {
|
|
7
7
|
throw new Error(`Extension "${name}" already registered`);
|
|
8
8
|
}
|
|
9
9
|
this.extensions.set(name, extension);
|
|
@@ -35,10 +35,11 @@ const normalizeCombo = (combo) => {
|
|
|
35
35
|
return comboObj;
|
|
36
36
|
};
|
|
37
37
|
const matchCombo = (event, combo) => {
|
|
38
|
+
var _a;
|
|
38
39
|
const key = event.key.toLowerCase();
|
|
39
40
|
if (key !== combo.key)
|
|
40
41
|
return false;
|
|
41
|
-
const wantsMod = combo.mod
|
|
42
|
+
const wantsMod = (_a = combo.mod) !== null && _a !== void 0 ? _a : false;
|
|
42
43
|
const hasMeta = event.metaKey;
|
|
43
44
|
const hasCtrl = event.ctrlKey;
|
|
44
45
|
const hasMod = hasMeta || hasCtrl;
|
package/esm/exporter/font.js
CHANGED
|
@@ -1,51 +1,62 @@
|
|
|
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 postcss from 'postcss';
|
|
2
11
|
import { getFontURLs, getWoff2BaseURL } from '../renderer/index.js';
|
|
3
12
|
import { createElement, decodeFontFamily, fetchWithCache, join, normalizeFontWeightName, splitFontFamily, } from '../utils/index.js';
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const parsedFontsFaces = [];
|
|
10
|
-
// 2. 对每个使用到的字体,解析 CSS + 结合 document.fonts 的实际加载子集
|
|
11
|
-
await Promise.all(Array.from(usedFonts).map(async (fontFamily) => {
|
|
12
|
-
const loadedFonts = getActualLoadedFontFace(fontFamily);
|
|
13
|
-
if (!loadedFonts.length)
|
|
14
|
-
return;
|
|
15
|
-
const cssFontFaces = await parseFontFamily(fontFamily);
|
|
16
|
-
if (!cssFontFaces.length)
|
|
13
|
+
export function embedFonts(svg_1) {
|
|
14
|
+
return __awaiter(this, arguments, void 0, function* (svg, embedResources = true) {
|
|
15
|
+
// 1. 收集使用到的 font-family
|
|
16
|
+
const usedFonts = collectUsedFonts(svg);
|
|
17
|
+
if (usedFonts.size === 0)
|
|
17
18
|
return;
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
fontFace.src
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
19
|
+
const parsedFontsFaces = [];
|
|
20
|
+
// 2. 对每个使用到的字体,解析 CSS + 结合 document.fonts 的实际加载子集
|
|
21
|
+
yield Promise.all(Array.from(usedFonts).map((fontFamily) => __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
const loadedFonts = getActualLoadedFontFace(fontFamily);
|
|
23
|
+
if (!loadedFonts.length)
|
|
24
|
+
return;
|
|
25
|
+
const cssFontFaces = yield parseFontFamily(fontFamily);
|
|
26
|
+
if (!cssFontFaces.length)
|
|
27
|
+
return;
|
|
28
|
+
const processed = yield Promise.all(cssFontFaces.map((rawFace) => __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
const fontFace = normalizeFontFace(rawFace);
|
|
30
|
+
const unicodeRange = fontFace['unicode-range'].replace(/\s/g, '');
|
|
31
|
+
const subset = loadedFonts.find((font) => font.unicodeRange &&
|
|
32
|
+
font.unicodeRange.replace(/\s/g, '') === unicodeRange);
|
|
33
|
+
// 如果找不到对应子集,就不处理这个 font-face
|
|
34
|
+
if (!subset)
|
|
35
|
+
return null;
|
|
36
|
+
const baseURL = getWoff2BaseURL(fontFace['font-family'], normalizeFontWeightName(fontFace['font-weight']));
|
|
37
|
+
if (!baseURL)
|
|
38
|
+
return null;
|
|
39
|
+
// 更宽松地从 src 中提取 .woff2 URL 片段
|
|
40
|
+
const urlMatch = fontFace.src.match(/url\(["']?(.*?\.woff2)[^"']*["']?\)/);
|
|
41
|
+
if (!(urlMatch === null || urlMatch === void 0 ? void 0 : urlMatch[1]))
|
|
42
|
+
return null;
|
|
43
|
+
const woff2URL = join(baseURL, urlMatch[1]);
|
|
44
|
+
if (embedResources) {
|
|
45
|
+
const woff2DataUrl = yield loadWoff2(woff2URL);
|
|
46
|
+
fontFace.src = `url(${woff2DataUrl}) format('woff2')`;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
fontFace.src = `url(${woff2URL}) format('woff2')`;
|
|
50
|
+
}
|
|
51
|
+
return fontFace;
|
|
52
|
+
})));
|
|
53
|
+
parsedFontsFaces.push(...(processed.filter(Boolean) || []));
|
|
54
|
+
})));
|
|
55
|
+
// 3. 创建 <style>@font-face...</style> 并插入 SVG
|
|
56
|
+
if (parsedFontsFaces.length > 0) {
|
|
57
|
+
insertFontStyle(svg, parsedFontsFaces);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
49
60
|
}
|
|
50
61
|
/**
|
|
51
62
|
* 收集 SVG 中用到的 font-family
|
|
@@ -71,33 +82,35 @@ function collectUsedFonts(svg) {
|
|
|
71
82
|
/**
|
|
72
83
|
* 解析给定 font-family 对应的 CSS @font-face
|
|
73
84
|
*/
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
if (!cssText)
|
|
85
|
-
return;
|
|
86
|
-
try {
|
|
87
|
-
const root = postcss.parse(cssText);
|
|
88
|
-
root.walkAtRules('font-face', (rule) => {
|
|
89
|
-
const fontFace = {};
|
|
90
|
-
rule.walkDecls((decl) => {
|
|
91
|
-
fontFace[decl.prop] = decl.value;
|
|
92
|
-
});
|
|
93
|
-
fontFaces.push(fontFace);
|
|
85
|
+
function parseFontFamily(fontFamily) {
|
|
86
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
87
|
+
const urls = getFontURLs(fontFamily);
|
|
88
|
+
const fontFaces = [];
|
|
89
|
+
yield Promise.allSettled(urls.map((url) => __awaiter(this, void 0, void 0, function* () {
|
|
90
|
+
const cssText = yield fetchWithCache(url)
|
|
91
|
+
.then((res) => res.text())
|
|
92
|
+
.catch(() => {
|
|
93
|
+
console.error(`Failed to fetch font CSS: ${url}`);
|
|
94
|
+
return null;
|
|
94
95
|
});
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
96
|
+
if (!cssText)
|
|
97
|
+
return;
|
|
98
|
+
try {
|
|
99
|
+
const root = postcss.parse(cssText);
|
|
100
|
+
root.walkAtRules('font-face', (rule) => {
|
|
101
|
+
const fontFace = {};
|
|
102
|
+
rule.walkDecls((decl) => {
|
|
103
|
+
fontFace[decl.prop] = decl.value;
|
|
104
|
+
});
|
|
105
|
+
fontFaces.push(fontFace);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
console.error(`Failed to parse CSS: ${url}`, error);
|
|
110
|
+
}
|
|
111
|
+
})));
|
|
112
|
+
return fontFaces;
|
|
113
|
+
});
|
|
101
114
|
}
|
|
102
115
|
/**
|
|
103
116
|
* 从 document.fonts 中获取给定 family 且已加载的 FontFace
|
|
@@ -117,13 +130,14 @@ export function getActualLoadedFontFace(fontFamily) {
|
|
|
117
130
|
* 将不完整的 FontFaceAttributes 补全为完整结构,给后续逻辑使用
|
|
118
131
|
*/
|
|
119
132
|
function normalizeFontFace(face) {
|
|
133
|
+
var _a, _b, _c, _d, _e, _f;
|
|
120
134
|
return {
|
|
121
|
-
'font-family': face['font-family']
|
|
122
|
-
src: face.src
|
|
123
|
-
'font-style': face['font-style']
|
|
124
|
-
'font-display': face['font-display']
|
|
125
|
-
'font-weight': face['font-weight']
|
|
126
|
-
'unicode-range': face['unicode-range']
|
|
135
|
+
'font-family': (_a = face['font-family']) !== null && _a !== void 0 ? _a : '',
|
|
136
|
+
src: (_b = face.src) !== null && _b !== void 0 ? _b : '',
|
|
137
|
+
'font-style': (_c = face['font-style']) !== null && _c !== void 0 ? _c : 'normal',
|
|
138
|
+
'font-display': (_d = face['font-display']) !== null && _d !== void 0 ? _d : 'swap',
|
|
139
|
+
'font-weight': (_e = face['font-weight']) !== null && _e !== void 0 ? _e : '400',
|
|
140
|
+
'unicode-range': (_f = face['unicode-range']) !== null && _f !== void 0 ? _f : 'U+0-FFFF',
|
|
127
141
|
};
|
|
128
142
|
}
|
|
129
143
|
/**
|
|
@@ -173,19 +187,21 @@ function insertFontStyle(svg, fontFaces) {
|
|
|
173
187
|
/**
|
|
174
188
|
* 加载 woff2 并转为 DataURL
|
|
175
189
|
*/
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
const
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
190
|
+
function loadWoff2(url) {
|
|
191
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
192
|
+
const response = yield fetchWithCache(url);
|
|
193
|
+
if (!response.ok) {
|
|
194
|
+
throw new Error(`Failed to load font: ${url}`);
|
|
195
|
+
}
|
|
196
|
+
const blob = yield response.blob();
|
|
197
|
+
const dataUrl = yield new Promise((resolve, reject) => {
|
|
198
|
+
const reader = new FileReader();
|
|
199
|
+
reader.onloadend = () => {
|
|
200
|
+
resolve(reader.result);
|
|
201
|
+
};
|
|
202
|
+
reader.onerror = reject;
|
|
203
|
+
reader.readAsDataURL(blob);
|
|
204
|
+
});
|
|
205
|
+
return dataUrl;
|
|
189
206
|
});
|
|
190
|
-
return dataUrl;
|
|
191
207
|
}
|
package/esm/exporter/png.js
CHANGED
|
@@ -1,42 +1,54 @@
|
|
|
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 { getViewBox } from '../utils/index.js';
|
|
2
11
|
import { exportToSVG } from './svg.js';
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
export function exportToPNGString(svg_1) {
|
|
13
|
+
return __awaiter(this, arguments, void 0, function* (svg, options = {}) {
|
|
14
|
+
var _a;
|
|
15
|
+
const { dpr = (_a = globalThis.devicePixelRatio) !== null && _a !== void 0 ? _a : 2 } = options;
|
|
16
|
+
const node = yield exportToSVG(svg);
|
|
17
|
+
const { width, height } = getViewBox(node);
|
|
18
|
+
return new Promise((resolve, reject) => {
|
|
19
|
+
try {
|
|
20
|
+
const canvas = document.createElement('canvas');
|
|
21
|
+
canvas.width = width * dpr;
|
|
22
|
+
canvas.height = height * dpr;
|
|
23
|
+
const ctx = canvas.getContext('2d');
|
|
24
|
+
if (!ctx) {
|
|
25
|
+
reject(new Error('Failed to get canvas context'));
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
// 应用 DPR 缩放
|
|
29
|
+
ctx.scale(dpr, dpr);
|
|
30
|
+
ctx.imageSmoothingEnabled = true;
|
|
31
|
+
ctx.imageSmoothingQuality = 'high';
|
|
32
|
+
node.setAttribute('width', String(width));
|
|
33
|
+
node.setAttribute('height', String(height));
|
|
34
|
+
const updatedSvgData = new XMLSerializer().serializeToString(node);
|
|
35
|
+
const svgURL = 'data:image/svg+xml;charset=utf-8,' +
|
|
36
|
+
encodeURIComponent(updatedSvgData);
|
|
37
|
+
const img = new Image();
|
|
38
|
+
img.onload = function () {
|
|
39
|
+
ctx.clearRect(0, 0, width, height);
|
|
40
|
+
ctx.drawImage(img, 0, 0, width, height);
|
|
41
|
+
const pngURL = canvas.toDataURL('image/png');
|
|
42
|
+
resolve(pngURL);
|
|
43
|
+
};
|
|
44
|
+
img.onerror = function (error) {
|
|
45
|
+
reject(new Error('Image load failed: ' + error));
|
|
46
|
+
};
|
|
47
|
+
img.src = svgURL;
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
reject(error);
|
|
16
51
|
}
|
|
17
|
-
|
|
18
|
-
ctx.scale(dpr, dpr);
|
|
19
|
-
ctx.imageSmoothingEnabled = true;
|
|
20
|
-
ctx.imageSmoothingQuality = 'high';
|
|
21
|
-
node.setAttribute('width', String(width));
|
|
22
|
-
node.setAttribute('height', String(height));
|
|
23
|
-
const updatedSvgData = new XMLSerializer().serializeToString(node);
|
|
24
|
-
const svgURL = 'data:image/svg+xml;charset=utf-8,' +
|
|
25
|
-
encodeURIComponent(updatedSvgData);
|
|
26
|
-
const img = new Image();
|
|
27
|
-
img.onload = function () {
|
|
28
|
-
ctx.clearRect(0, 0, width, height);
|
|
29
|
-
ctx.drawImage(img, 0, 0, width, height);
|
|
30
|
-
const pngURL = canvas.toDataURL('image/png');
|
|
31
|
-
resolve(pngURL);
|
|
32
|
-
};
|
|
33
|
-
img.onerror = function (error) {
|
|
34
|
-
reject(new Error('Image load failed: ' + error));
|
|
35
|
-
};
|
|
36
|
-
img.src = svgURL;
|
|
37
|
-
}
|
|
38
|
-
catch (error) {
|
|
39
|
-
reject(error);
|
|
40
|
-
}
|
|
52
|
+
});
|
|
41
53
|
});
|
|
42
54
|
}
|