@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
|
@@ -3,7 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.renderSVG = renderSVG;
|
|
4
4
|
const fonts_1 = require("../fonts");
|
|
5
5
|
function renderSVG(svg, options) {
|
|
6
|
+
var _a;
|
|
6
7
|
const { themeConfig } = options;
|
|
7
|
-
const { 'font-family': fontFamily = fonts_1.DEFAULT_FONT } = themeConfig.base
|
|
8
|
+
const { 'font-family': fontFamily = fonts_1.DEFAULT_FONT } = ((_a = themeConfig.base) === null || _a === void 0 ? void 0 : _a.text) || {};
|
|
8
9
|
svg.setAttribute('font-family', fontFamily);
|
|
9
10
|
}
|
|
@@ -19,6 +19,7 @@ function renderText(node, text, attrs = {}) {
|
|
|
19
19
|
return renderedText;
|
|
20
20
|
}
|
|
21
21
|
function renderItemText(type, node, options) {
|
|
22
|
+
var _a, _b, _c;
|
|
22
23
|
const textShape = node.nodeName === 'text' ? node : null;
|
|
23
24
|
if (!textShape)
|
|
24
25
|
return null;
|
|
@@ -26,13 +27,14 @@ function renderItemText(type, node, options) {
|
|
|
26
27
|
const indexes = (0, utils_1.getItemIndexes)(node.dataset.indexes || '0');
|
|
27
28
|
const datum = (0, utils_1.getDatumByIndexes)(data, indexes);
|
|
28
29
|
const text = String((0, lodash_es_1.get)(datum, type, ''));
|
|
29
|
-
const dataAttrs = datum
|
|
30
|
-
const attrs = Object.assign({}, themeConfig.base
|
|
30
|
+
const dataAttrs = (_a = datum === null || datum === void 0 ? void 0 : datum.attributes) === null || _a === void 0 ? void 0 : _a[type];
|
|
31
|
+
const attrs = Object.assign({}, (_b = themeConfig.base) === null || _b === void 0 ? void 0 : _b.text, (_c = themeConfig.item) === null || _c === void 0 ? void 0 : _c[type], dataAttrs);
|
|
31
32
|
const staticAttrs = (0, utils_2.parseDynamicAttributes)(textShape, attrs);
|
|
32
33
|
return renderText(node, node.textContent || text, staticAttrs);
|
|
33
34
|
}
|
|
34
35
|
function renderStaticText(text, options) {
|
|
35
|
-
|
|
36
|
+
var _a;
|
|
37
|
+
const attrs = ((_a = options.themeConfig.base) === null || _a === void 0 ? void 0 : _a.text) || {};
|
|
36
38
|
(0, utils_1.setAttributes)(text, attrs);
|
|
37
39
|
if (attrs['font-family']) {
|
|
38
40
|
text.setAttribute('font-family', (0, utils_1.encodeFontFamily)(attrs['font-family']));
|
|
@@ -61,12 +61,13 @@ function isLinkLoaded(link) {
|
|
|
61
61
|
try {
|
|
62
62
|
return !!link.sheet;
|
|
63
63
|
}
|
|
64
|
-
catch {
|
|
64
|
+
catch (_a) {
|
|
65
65
|
return false;
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
function getFontLoadPromise(target, id, link) {
|
|
69
|
-
|
|
69
|
+
var _a;
|
|
70
|
+
const existing = (_a = FONT_PROMISE_MAP.get(target)) === null || _a === void 0 ? void 0 : _a.get(id);
|
|
70
71
|
if (existing)
|
|
71
72
|
return existing;
|
|
72
73
|
if (!link || isLinkLoaded(link)) {
|
|
@@ -84,7 +85,7 @@ function getFontLoadPromise(target, id, link) {
|
|
|
84
85
|
}
|
|
85
86
|
function loadFont(svg, font) {
|
|
86
87
|
const doc = svg.ownerDocument;
|
|
87
|
-
const target = doc
|
|
88
|
+
const target = (doc === null || doc === void 0 ? void 0 : doc.head) || document.head;
|
|
88
89
|
if (!target)
|
|
89
90
|
return;
|
|
90
91
|
if (!FONT_LOAD_MAP.has(target))
|
|
@@ -42,7 +42,7 @@ function setDefaultFont(font) {
|
|
|
42
42
|
* 字体准备说明:https://chinese-font.netlify.app/zh-cn/post/simple_tutorial
|
|
43
43
|
*/
|
|
44
44
|
function registerFont(font) {
|
|
45
|
-
const f = {
|
|
45
|
+
const f = Object.assign({}, font);
|
|
46
46
|
FONT_REGISTRY.set(f.fontFamily, f);
|
|
47
47
|
f.fontFamily = (0, font_1.encodeFontFamily)(f.fontFamily);
|
|
48
48
|
return f;
|
|
@@ -3,11 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getPaletteColor = void 0;
|
|
4
4
|
const registry_1 = require("./registry");
|
|
5
5
|
const getPaletteColor = (args = [], indexes, total) => {
|
|
6
|
+
var _a;
|
|
6
7
|
const palette = typeof args === 'string' ? (0, registry_1.getPalette)(args) || [] : args;
|
|
7
|
-
const index = indexes[0]
|
|
8
|
+
const index = (_a = indexes[0]) !== null && _a !== void 0 ? _a : 0;
|
|
8
9
|
if (typeof palette === 'function') {
|
|
9
10
|
const ratio = total ? index / total : 0;
|
|
10
|
-
return palette(ratio, index, total
|
|
11
|
+
return palette(ratio, index, total !== null && total !== void 0 ? total : 0);
|
|
11
12
|
}
|
|
12
13
|
if (Array.isArray(palette)) {
|
|
13
14
|
if (palette.length === 0)
|
package/lib/renderer/renderer.js
CHANGED
|
@@ -72,21 +72,23 @@ function renderTemplate(svg, options) {
|
|
|
72
72
|
(0, composites_1.renderBackground)(svg, options);
|
|
73
73
|
}
|
|
74
74
|
function fill(svg, options) {
|
|
75
|
+
var _a;
|
|
75
76
|
const { themeConfig, data } = options;
|
|
76
|
-
(0, composites_1.renderBaseElement)(svg, themeConfig.base
|
|
77
|
+
(0, composites_1.renderBaseElement)(svg, (_a = themeConfig.base) === null || _a === void 0 ? void 0 : _a.global);
|
|
77
78
|
const elements = svg.querySelectorAll(`[data-element-type]`);
|
|
78
79
|
elements.forEach((element) => {
|
|
80
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
79
81
|
const id = element.id || '';
|
|
80
82
|
if ((0, utils_1.isTitle)(element)) {
|
|
81
|
-
const modified = (0, composites_1.renderText)(element, data.title || '', Object.assign({}, themeConfig.base
|
|
83
|
+
const modified = (0, composites_1.renderText)(element, data.title || '', Object.assign({}, (_a = themeConfig.base) === null || _a === void 0 ? void 0 : _a.text, themeConfig.title, (_b = data.attributes) === null || _b === void 0 ? void 0 : _b.title));
|
|
82
84
|
return upsert(element, modified);
|
|
83
85
|
}
|
|
84
86
|
if ((0, utils_1.isDesc)(element)) {
|
|
85
|
-
const modified = (0, composites_1.renderText)(element, data.desc || '', Object.assign({}, themeConfig.base
|
|
87
|
+
const modified = (0, composites_1.renderText)(element, data.desc || '', Object.assign({}, (_c = themeConfig.base) === null || _c === void 0 ? void 0 : _c.text, themeConfig.desc, (_d = data.attributes) === null || _d === void 0 ? void 0 : _d.desc));
|
|
86
88
|
return upsert(element, modified);
|
|
87
89
|
}
|
|
88
90
|
if ((0, utils_1.isIllus)(element)) {
|
|
89
|
-
const modified = (0, composites_1.renderIllus)(svg, element, data.illus
|
|
91
|
+
const modified = (0, composites_1.renderIllus)(svg, element, (_e = data.illus) === null || _e === void 0 ? void 0 : _e[id], undefined, (_f = data.attributes) === null || _f === void 0 ? void 0 : _f.illus);
|
|
90
92
|
return upsert(element, modified);
|
|
91
93
|
}
|
|
92
94
|
if ((0, utils_1.isShapesGroup)(element)) {
|
|
@@ -101,7 +103,7 @@ function fill(svg, options) {
|
|
|
101
103
|
if ((0, utils_1.isBtnsGroup)(element)) {
|
|
102
104
|
return (0, composites_1.renderButtonsGroup)(svg, element);
|
|
103
105
|
}
|
|
104
|
-
if (element.dataset.elementType
|
|
106
|
+
if ((_g = element.dataset.elementType) === null || _g === void 0 ? void 0 : _g.startsWith('item-')) {
|
|
105
107
|
const indexes = (0, utils_1.getItemIndexes)(element.dataset.indexes || '0');
|
|
106
108
|
const itemType = element.dataset.elementType.replace('item-', '');
|
|
107
109
|
const datum = (0, utils_1.getDatumByIndexes)(data, indexes);
|
|
@@ -64,10 +64,11 @@ function upsertGradient(svg, id, gradient) {
|
|
|
64
64
|
defs.appendChild(gradient);
|
|
65
65
|
}
|
|
66
66
|
function inferGradientConfig(currentColor, config) {
|
|
67
|
-
|
|
67
|
+
var _a;
|
|
68
|
+
if (((_a = config.colors) === null || _a === void 0 ? void 0 : _a.length) || !currentColor)
|
|
68
69
|
return config;
|
|
69
70
|
const tc = (0, tinycolor2_1.default)(currentColor);
|
|
70
|
-
const inferConfig = {
|
|
71
|
+
const inferConfig = Object.assign({}, config);
|
|
71
72
|
inferConfig.colors = tc.isDark()
|
|
72
73
|
? [currentColor, tc.lighten(20).toHexString()]
|
|
73
74
|
: [tc.darken(20).toHexString(), currentColor];
|
|
@@ -32,6 +32,17 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
32
32
|
return result;
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
36
|
+
var t = {};
|
|
37
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
38
|
+
t[p] = s[p];
|
|
39
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
40
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
41
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
42
|
+
t[p[i]] = s[p[i]];
|
|
43
|
+
}
|
|
44
|
+
return t;
|
|
45
|
+
};
|
|
35
46
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
47
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
48
|
};
|
|
@@ -55,21 +66,17 @@ function applyPatternStyle(node, svg, options) {
|
|
|
55
66
|
const config = options.themeConfig.stylize;
|
|
56
67
|
if (!config || config.type !== 'pattern')
|
|
57
68
|
return;
|
|
58
|
-
const { pattern,
|
|
69
|
+
const { pattern } = config, restConfig = __rest(config, ["pattern"]);
|
|
59
70
|
const generator = PATTERNS.get(pattern);
|
|
60
71
|
if (!generator) {
|
|
61
72
|
return console.warn(`Pattern ${pattern} not found`);
|
|
62
73
|
}
|
|
63
74
|
const { fill } = (0, utils_1.getAttributes)(node, ['fill', 'stroke']);
|
|
64
75
|
const color = fill;
|
|
65
|
-
const style = {
|
|
66
|
-
backgroundColor: color
|
|
76
|
+
const style = Object.assign({ backgroundColor: color
|
|
67
77
|
? (0, tinycolor2_1.default)(color).setAlpha(0.5).toRgbString()
|
|
68
|
-
: color,
|
|
69
|
-
|
|
70
|
-
...restConfig,
|
|
71
|
-
};
|
|
72
|
-
const id = getPatternId({ ...config, ...style });
|
|
78
|
+
: color, foregroundColor: color }, restConfig);
|
|
79
|
+
const id = getPatternId(Object.assign(Object.assign({}, config), style));
|
|
73
80
|
upsertPattern(svg, id, generator(style));
|
|
74
81
|
if ((0, utils_1.hasColor)(fill)) {
|
|
75
82
|
node.setAttribute('fill', `url(#${id})`);
|
|
@@ -113,7 +113,7 @@ function createRoughShape(rc, node, config) {
|
|
|
113
113
|
], true);
|
|
114
114
|
// 分离形状属性、RoughJS选项和SVG属性
|
|
115
115
|
const shapeAttrs = {};
|
|
116
|
-
const roughOptions = {
|
|
116
|
+
const roughOptions = Object.assign({}, config);
|
|
117
117
|
const svgAttributes = {};
|
|
118
118
|
// 处理形状特定的属性
|
|
119
119
|
attrs.forEach((attr) => {
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.getSvgLoadPromises = getSvgLoadPromises;
|
|
4
13
|
exports.getSvgLoadPromise = getSvgLoadPromise;
|
|
@@ -10,7 +19,8 @@ function getSvgLoadPromises(svg) {
|
|
|
10
19
|
return map ? Array.from(map.values()) : [];
|
|
11
20
|
}
|
|
12
21
|
function getSvgLoadPromise(svg, key) {
|
|
13
|
-
|
|
22
|
+
var _a;
|
|
23
|
+
return (_a = SVG_LOAD_PROMISE_MAP.get(svg)) === null || _a === void 0 ? void 0 : _a.get(key);
|
|
14
24
|
}
|
|
15
25
|
function trackSvgLoadPromise(svg, key, promise) {
|
|
16
26
|
let map = SVG_LOAD_PROMISE_MAP.get(svg);
|
|
@@ -30,13 +40,15 @@ function trackSvgLoadPromise(svg, key, promise) {
|
|
|
30
40
|
});
|
|
31
41
|
return promise;
|
|
32
42
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
43
|
+
function waitForSvgLoads(svg) {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
yield Promise.resolve();
|
|
46
|
+
while (true) {
|
|
47
|
+
const promises = getSvgLoadPromises(svg);
|
|
48
|
+
if (!promises.length)
|
|
49
|
+
break;
|
|
50
|
+
yield Promise.allSettled(promises);
|
|
51
|
+
yield Promise.resolve();
|
|
52
|
+
}
|
|
53
|
+
});
|
|
42
54
|
}
|
package/lib/resource/loader.js
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.waitForSvgLoads = exports.getSvgLoadPromises = void 0;
|
|
4
13
|
exports.loadResource = loadResource;
|
|
@@ -7,47 +16,49 @@ const load_tracker_1 = require("./load-tracker");
|
|
|
7
16
|
const loaders_1 = require("./loaders");
|
|
8
17
|
const registry_1 = require("./registry");
|
|
9
18
|
const utils_2 = require("./utils");
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
function getResource(scene, config, datum) {
|
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
const cfg = (0, utils_2.parseResourceConfig)(config);
|
|
22
|
+
if (!cfg)
|
|
23
|
+
return null;
|
|
24
|
+
cfg.scene || (cfg.scene = scene);
|
|
25
|
+
const { source, data, format, encoding } = cfg;
|
|
26
|
+
let resource = null;
|
|
27
|
+
try {
|
|
28
|
+
if (source === 'inline') {
|
|
29
|
+
const isDataURI = data.startsWith('data:');
|
|
30
|
+
if (format === 'svg' && encoding === 'raw') {
|
|
31
|
+
resource = (0, loaders_1.loadSVGResource)(data);
|
|
32
|
+
}
|
|
33
|
+
else if (format === 'svg' && isDataURI) {
|
|
34
|
+
resource = yield (0, loaders_1.loadImageBase64Resource)(data);
|
|
35
|
+
}
|
|
36
|
+
else if (isDataURI || format === 'image') {
|
|
37
|
+
resource = yield (0, loaders_1.loadImageBase64Resource)(data);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
resource = (0, loaders_1.loadSVGResource)(data);
|
|
41
|
+
}
|
|
22
42
|
}
|
|
23
|
-
else if (
|
|
24
|
-
resource =
|
|
43
|
+
else if (source === 'remote') {
|
|
44
|
+
resource = yield (0, loaders_1.loadRemoteResource)(data, format);
|
|
25
45
|
}
|
|
26
|
-
else if (
|
|
27
|
-
resource =
|
|
46
|
+
else if (source === 'search') {
|
|
47
|
+
resource = yield (0, loaders_1.loadSearchResource)(data, format);
|
|
28
48
|
}
|
|
29
49
|
else {
|
|
30
|
-
|
|
50
|
+
const customLoader = (0, registry_1.getCustomResourceLoader)();
|
|
51
|
+
if (customLoader)
|
|
52
|
+
resource = yield customLoader(cfg);
|
|
31
53
|
}
|
|
32
54
|
}
|
|
33
|
-
|
|
34
|
-
resource =
|
|
35
|
-
}
|
|
36
|
-
else if (source === 'search') {
|
|
37
|
-
resource = await (0, loaders_1.loadSearchResource)(data, format);
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
const customLoader = (0, registry_1.getCustomResourceLoader)();
|
|
41
|
-
if (customLoader)
|
|
42
|
-
resource = await customLoader(cfg);
|
|
55
|
+
catch (_a) {
|
|
56
|
+
resource = null;
|
|
43
57
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
if (resource)
|
|
49
|
-
return resource;
|
|
50
|
-
return await (0, loaders_1.loadSearchResource)(getFallbackQuery(cfg, scene, datum), format);
|
|
58
|
+
if (resource)
|
|
59
|
+
return resource;
|
|
60
|
+
return yield (0, loaders_1.loadSearchResource)(getFallbackQuery(cfg, scene, datum), format);
|
|
61
|
+
});
|
|
51
62
|
}
|
|
52
63
|
const RESOURCE_MAP = new Map();
|
|
53
64
|
const RESOURCE_LOAD_MAP = new WeakMap();
|
|
@@ -55,39 +66,41 @@ const RESOURCE_LOAD_MAP = new WeakMap();
|
|
|
55
66
|
* load resource into svg defs
|
|
56
67
|
* @returns resource ref id
|
|
57
68
|
*/
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const cfg = (0, utils_2.parseResourceConfig)(config);
|
|
62
|
-
if (!cfg)
|
|
63
|
-
return null;
|
|
64
|
-
const id = (0, utils_2.getResourceId)(cfg);
|
|
65
|
-
const promiseKey = `resource:${id}`;
|
|
66
|
-
const loadedMap = RESOURCE_LOAD_MAP.get(svg);
|
|
67
|
-
if (loadedMap?.has(id))
|
|
68
|
-
return id;
|
|
69
|
-
const existingPromise = (0, load_tracker_1.getSvgLoadPromise)(svg, promiseKey);
|
|
70
|
-
if (existingPromise)
|
|
71
|
-
return await existingPromise;
|
|
72
|
-
const loadPromise = (async () => {
|
|
73
|
-
const resource = RESOURCE_MAP.has(id)
|
|
74
|
-
? RESOURCE_MAP.get(id) || null
|
|
75
|
-
: await getResource(scene, cfg, datum);
|
|
76
|
-
if (!resource)
|
|
69
|
+
function loadResource(svg, scene, config, datum) {
|
|
70
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
+
if (!svg)
|
|
77
72
|
return null;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
73
|
+
const cfg = (0, utils_2.parseResourceConfig)(config);
|
|
74
|
+
if (!cfg)
|
|
75
|
+
return null;
|
|
76
|
+
const id = (0, utils_2.getResourceId)(cfg);
|
|
77
|
+
const promiseKey = `resource:${id}`;
|
|
78
|
+
const loadedMap = RESOURCE_LOAD_MAP.get(svg);
|
|
79
|
+
if (loadedMap === null || loadedMap === void 0 ? void 0 : loadedMap.has(id))
|
|
80
|
+
return id;
|
|
81
|
+
const existingPromise = (0, load_tracker_1.getSvgLoadPromise)(svg, promiseKey);
|
|
82
|
+
if (existingPromise)
|
|
83
|
+
return yield existingPromise;
|
|
84
|
+
const loadPromise = (() => __awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
const resource = RESOURCE_MAP.has(id)
|
|
86
|
+
? RESOURCE_MAP.get(id) || null
|
|
87
|
+
: yield getResource(scene, cfg, datum);
|
|
88
|
+
if (!resource)
|
|
89
|
+
return null;
|
|
90
|
+
if (!RESOURCE_LOAD_MAP.has(svg))
|
|
91
|
+
RESOURCE_LOAD_MAP.set(svg, new Map());
|
|
92
|
+
const map = RESOURCE_LOAD_MAP.get(svg);
|
|
93
|
+
if (map.has(id))
|
|
94
|
+
return id;
|
|
95
|
+
const defs = (0, utils_1.getOrCreateDefs)(svg);
|
|
96
|
+
resource.id = id;
|
|
97
|
+
defs.appendChild(resource);
|
|
98
|
+
map.set(id, resource);
|
|
82
99
|
return id;
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
return id;
|
|
88
|
-
})();
|
|
89
|
-
(0, load_tracker_1.trackSvgLoadPromise)(svg, promiseKey, loadPromise);
|
|
90
|
-
return await loadPromise;
|
|
100
|
+
}))();
|
|
101
|
+
(0, load_tracker_1.trackSvgLoadPromise)(svg, promiseKey, loadPromise);
|
|
102
|
+
return yield loadPromise;
|
|
103
|
+
});
|
|
91
104
|
}
|
|
92
105
|
var load_tracker_2 = require("./load-tracker");
|
|
93
106
|
Object.defineProperty(exports, "getSvgLoadPromises", { enumerable: true, get: function () { return load_tracker_2.getSvgLoadPromises; } });
|
|
@@ -95,8 +108,8 @@ Object.defineProperty(exports, "waitForSvgLoads", { enumerable: true, get: funct
|
|
|
95
108
|
function getFallbackQuery(cfg, scene, datum) {
|
|
96
109
|
const defaultQuery = scene === 'illus' ? 'illustration' : 'icon';
|
|
97
110
|
const datumQuery = normalizeQuery(cfg.data) ||
|
|
98
|
-
normalizeQuery(datum
|
|
99
|
-
normalizeQuery(datum
|
|
111
|
+
normalizeQuery(datum === null || datum === void 0 ? void 0 : datum.label) ||
|
|
112
|
+
normalizeQuery(datum === null || datum === void 0 ? void 0 : datum.desc);
|
|
100
113
|
if (datumQuery)
|
|
101
114
|
return datumQuery;
|
|
102
115
|
const data = normalizeQuery(cfg.data);
|
|
@@ -1,73 +1,85 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.loadImageBase64Resource = loadImageBase64Resource;
|
|
4
13
|
const utils_1 = require("../../utils");
|
|
5
14
|
function isImageBase64Resource(resource) {
|
|
6
15
|
return resource.startsWith('data:');
|
|
7
16
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const imageData = ctx.getImageData(x, y, 1, 1);
|
|
39
|
-
if (imageData.data[3] < 255) {
|
|
40
|
-
hasAlpha = true;
|
|
17
|
+
function loadImageBase64Resource(data) {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
var _a;
|
|
20
|
+
if (!data || !isImageBase64Resource(data))
|
|
21
|
+
return null;
|
|
22
|
+
const mimeType = (_a = data.match(/^data:([^;]+)/)) === null || _a === void 0 ? void 0 : _a[1];
|
|
23
|
+
if (!mimeType)
|
|
24
|
+
return null;
|
|
25
|
+
const analysis = () => {
|
|
26
|
+
return new Promise((resolve, reject) => {
|
|
27
|
+
const img = new Image();
|
|
28
|
+
img.onload = () => {
|
|
29
|
+
const width = img.naturalWidth;
|
|
30
|
+
const height = img.naturalHeight;
|
|
31
|
+
const canvas = document.createElement('canvas');
|
|
32
|
+
const ctx = canvas.getContext('2d');
|
|
33
|
+
if (!ctx) {
|
|
34
|
+
return resolve({ width, height, hasAlpha: false });
|
|
35
|
+
}
|
|
36
|
+
// skip analysis for jpeg/jpg/webp/gif
|
|
37
|
+
if (['image/jpeg', 'image/jpg', 'image/webp', 'image/gif'].includes(mimeType)) {
|
|
38
|
+
return resolve({ width, height, hasAlpha: false });
|
|
39
|
+
}
|
|
40
|
+
canvas.width = width;
|
|
41
|
+
canvas.height = height;
|
|
42
|
+
ctx.drawImage(img, 0, 0);
|
|
43
|
+
let hasAlpha = false;
|
|
44
|
+
const step = 10;
|
|
45
|
+
for (let x = 0; x < width; x += step) {
|
|
46
|
+
if (hasAlpha)
|
|
41
47
|
break;
|
|
48
|
+
for (let y = 0; y < height; y += step) {
|
|
49
|
+
const imageData = ctx.getImageData(x, y, 1, 1);
|
|
50
|
+
if (imageData.data[3] < 255) {
|
|
51
|
+
hasAlpha = true;
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
42
54
|
}
|
|
43
55
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
return 'xMidYMid
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return (0, utils_1.parseSVG)(`
|
|
56
|
+
resolve({ width, height, hasAlpha });
|
|
57
|
+
};
|
|
58
|
+
img.onerror = () => reject(new Error('Failed to analysis image'));
|
|
59
|
+
img.src = data;
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
const { width, height, hasAlpha } = yield analysis();
|
|
63
|
+
const getPreserveAspectRatio = () => {
|
|
64
|
+
if (hasAlpha)
|
|
65
|
+
return 'xMidYMid meet';
|
|
66
|
+
if ((mimeType === null || mimeType === void 0 ? void 0 : mimeType.includes('image/gif')) || (mimeType === null || mimeType === void 0 ? void 0 : mimeType.includes('image/svg'))) {
|
|
67
|
+
return 'xMidYMid meet';
|
|
68
|
+
}
|
|
69
|
+
const minDimension = Math.min(width, height);
|
|
70
|
+
if (minDimension <= 200)
|
|
71
|
+
return 'xMidYMid meet';
|
|
72
|
+
const aspectRatio = width / height;
|
|
73
|
+
if (aspectRatio >= 0.6 && aspectRatio <= 1.67)
|
|
74
|
+
return 'xMidYMid meet';
|
|
75
|
+
if (aspectRatio < 0.3 || aspectRatio > 3.33)
|
|
76
|
+
return 'xMidYMid meet';
|
|
77
|
+
return 'xMidYMid slice';
|
|
78
|
+
};
|
|
79
|
+
const preserveAspectRatio = getPreserveAspectRatio();
|
|
80
|
+
return (0, utils_1.parseSVG)(`
|
|
70
81
|
<symbol xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${width} ${height}" preserveAspectRatio="${preserveAspectRatio}">
|
|
71
82
|
<image href="${data}" width="${width}" height="${height}" />
|
|
72
83
|
</symbol>`);
|
|
84
|
+
});
|
|
73
85
|
}
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.loadRemoteResource = loadRemoteResource;
|
|
4
13
|
const utils_1 = require("../../utils");
|
|
@@ -8,7 +17,7 @@ function isRemoteResource(resource) {
|
|
|
8
17
|
try {
|
|
9
18
|
return Boolean(new URL(resource));
|
|
10
19
|
}
|
|
11
|
-
catch {
|
|
20
|
+
catch (_a) {
|
|
12
21
|
return false;
|
|
13
22
|
}
|
|
14
23
|
}
|
|
@@ -20,20 +29,22 @@ function shouldParseAsSVG(contentType, format) {
|
|
|
20
29
|
return true;
|
|
21
30
|
return false;
|
|
22
31
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
function loadRemoteResource(resource, format) {
|
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
if (!resource || !isRemoteResource(resource))
|
|
35
|
+
return null;
|
|
36
|
+
const response = yield (0, utils_1.fetchWithCache)(resource);
|
|
37
|
+
if (!response.ok)
|
|
38
|
+
throw new Error('Failed to load resource');
|
|
39
|
+
const contentType = response.headers.get('Content-Type') || '';
|
|
40
|
+
if (shouldParseAsSVG(contentType, format)) {
|
|
41
|
+
const svgText = yield response.text();
|
|
42
|
+
return (0, svg_1.loadSVGResource)(svgText);
|
|
43
|
+
}
|
|
44
|
+
const blob = yield response.blob();
|
|
45
|
+
const base64 = yield blobToBase64(blob);
|
|
46
|
+
return (0, image_1.loadImageBase64Resource)(base64);
|
|
47
|
+
});
|
|
37
48
|
}
|
|
38
49
|
function blobToBase64(blob) {
|
|
39
50
|
return new Promise((resolve, reject) => {
|