docusaurus-live-brython 3.0.0-beta.8 → 3.0.1
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/.devcontainer/devcontainer.json +38 -0
- package/.prettierignore +17 -0
- package/.prettierrc +9 -8
- package/CHANGELOG.md +5 -0
- package/README.md +7 -4
- package/lib/assets/py_back_trace.py +2 -1
- package/lib/index.d.ts +1 -7
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +94 -16
- package/lib/options.d.ts +1 -0
- package/lib/options.d.ts.map +1 -0
- package/lib/options.js +2 -2
- package/lib/theme/CodeBlock/index.d.ts +3 -3
- package/lib/theme/CodeBlock/index.d.ts.map +1 -0
- package/lib/theme/CodeBlock/index.jsx +24 -14
- package/lib/theme/CodeEditor/Actions/DownloadCode.d.ts +1 -0
- package/lib/theme/CodeEditor/Actions/DownloadCode.d.ts.map +1 -0
- package/lib/theme/CodeEditor/Actions/DownloadCode.jsx +8 -8
- package/lib/theme/CodeEditor/Actions/Reset.d.ts +1 -0
- package/lib/theme/CodeEditor/Actions/Reset.d.ts.map +1 -0
- package/lib/theme/CodeEditor/Actions/Reset.jsx +5 -5
- package/lib/theme/CodeEditor/Actions/RunCode.d.ts +2 -1
- package/lib/theme/CodeEditor/Actions/RunCode.d.ts.map +1 -0
- package/lib/theme/CodeEditor/Actions/RunCode.jsx +4 -4
- package/lib/theme/CodeEditor/Actions/ShowRaw.d.ts +1 -0
- package/lib/theme/CodeEditor/Actions/ShowRaw.d.ts.map +1 -0
- package/lib/theme/CodeEditor/Actions/ShowRaw.jsx +13 -7
- package/lib/theme/CodeEditor/Actions/ShowSyncStatus.d.ts +1 -0
- package/lib/theme/CodeEditor/Actions/ShowSyncStatus.d.ts.map +1 -0
- package/lib/theme/CodeEditor/Actions/ShowSyncStatus.jsx +21 -16
- package/lib/theme/CodeEditor/Actions/styles.module.css +2 -3
- package/lib/theme/CodeEditor/BrythonCommunicator.d.ts +2 -1
- package/lib/theme/CodeEditor/BrythonCommunicator.d.ts.map +1 -0
- package/lib/theme/CodeEditor/BrythonCommunicator.jsx +13 -9
- package/lib/theme/CodeEditor/Button/index.d.ts +3 -2
- package/lib/theme/CodeEditor/Button/index.d.ts.map +1 -0
- package/lib/theme/CodeEditor/Button/index.jsx +1 -1
- package/lib/theme/CodeEditor/Button/styles.module.css +1 -1
- package/lib/theme/CodeEditor/CodeHistory/index.d.ts +1 -0
- package/lib/theme/CodeEditor/CodeHistory/index.d.ts.map +1 -0
- package/lib/theme/CodeEditor/CodeHistory/index.jsx +26 -15
- package/lib/theme/CodeEditor/CodeHistory/styles.module.css +31 -31
- package/lib/theme/CodeEditor/ContextEditor/index.d.ts +22 -0
- package/lib/theme/CodeEditor/ContextEditor/index.d.ts.map +1 -0
- package/lib/theme/CodeEditor/ContextEditor/index.jsx +36 -0
- package/lib/theme/CodeEditor/Editor/EditorAce.d.ts +2 -1
- package/lib/theme/CodeEditor/Editor/EditorAce.d.ts.map +1 -0
- package/lib/theme/CodeEditor/Editor/EditorAce.jsx +17 -14
- package/lib/theme/CodeEditor/Editor/Header/index.d.ts +2 -1
- package/lib/theme/CodeEditor/Editor/Header/index.d.ts.map +1 -0
- package/lib/theme/CodeEditor/Editor/Header/index.jsx +12 -12
- package/lib/theme/CodeEditor/Editor/Header/styles.module.css +7 -7
- package/lib/theme/CodeEditor/Editor/HiddenCode/index.d.ts +8 -0
- package/lib/theme/CodeEditor/Editor/HiddenCode/index.d.ts.map +1 -0
- package/lib/theme/CodeEditor/Editor/HiddenCode/index.jsx +27 -0
- package/lib/theme/CodeEditor/Editor/HiddenCode/styles.module.css +52 -0
- package/lib/theme/CodeEditor/Editor/Result/Graphics/Canvas.d.ts +1 -0
- package/lib/theme/CodeEditor/Editor/Result/Graphics/Canvas.d.ts.map +1 -0
- package/lib/theme/CodeEditor/Editor/Result/Graphics/Canvas.jsx +8 -9
- package/lib/theme/CodeEditor/Editor/Result/Graphics/Turtle.d.ts +1 -0
- package/lib/theme/CodeEditor/Editor/Result/Graphics/Turtle.d.ts.map +1 -0
- package/lib/theme/CodeEditor/Editor/Result/Graphics/Turtle.jsx +11 -11
- package/lib/theme/CodeEditor/Editor/Result/Graphics/index.d.ts +4 -3
- package/lib/theme/CodeEditor/Editor/Result/Graphics/index.d.ts.map +1 -0
- package/lib/theme/CodeEditor/Editor/Result/Graphics/index.jsx +12 -10
- package/lib/theme/CodeEditor/Editor/Result/Graphics/styles.module.css +2 -2
- package/lib/theme/CodeEditor/Editor/Result/index.d.ts +2 -3
- package/lib/theme/CodeEditor/Editor/Result/index.d.ts.map +1 -0
- package/lib/theme/CodeEditor/Editor/Result/index.jsx +6 -9
- package/lib/theme/CodeEditor/Editor/Result/styles.module.css +15 -10
- package/lib/theme/CodeEditor/Editor/index.d.ts +6 -3
- package/lib/theme/CodeEditor/Editor/index.d.ts.map +1 -0
- package/lib/theme/CodeEditor/Editor/index.jsx +34 -28
- package/lib/theme/CodeEditor/Editor/styles.module.css +15 -7
- package/lib/theme/CodeEditor/Editor/utils/checkForButtonClick.d.ts +1 -0
- package/lib/theme/CodeEditor/Editor/utils/checkForButtonClick.d.ts.map +1 -0
- package/lib/theme/CodeEditor/Editor/utils/saveSvg.d.ts +1 -0
- package/lib/theme/CodeEditor/Editor/utils/saveSvg.d.ts.map +1 -0
- package/lib/theme/CodeEditor/Editor/utils/saveSvg.js +19 -8
- package/lib/theme/CodeEditor/Editor/utils/svgWithoutAnimations.d.ts +1 -0
- package/lib/theme/CodeEditor/Editor/utils/svgWithoutAnimations.d.ts.map +1 -0
- package/lib/theme/CodeEditor/Editor/utils/svgWithoutAnimations.js +43 -49
- package/lib/theme/CodeEditor/Icon/icons.d.ts +4 -1
- package/lib/theme/CodeEditor/Icon/icons.d.ts.map +1 -0
- package/lib/theme/CodeEditor/Icon/icons.js +3 -1
- package/lib/theme/CodeEditor/Icon/index.d.ts +4 -2
- package/lib/theme/CodeEditor/Icon/index.d.ts.map +1 -0
- package/lib/theme/CodeEditor/Icon/index.jsx +10 -3
- package/lib/theme/CodeEditor/Icon/styles.module.css +1 -1
- package/lib/theme/CodeEditor/WithScript/ScriptContext.d.ts +8 -0
- package/lib/theme/CodeEditor/WithScript/ScriptContext.d.ts.map +1 -0
- package/lib/theme/CodeEditor/WithScript/ScriptContext.jsx +27 -0
- package/lib/theme/CodeEditor/WithScript/Storage.d.ts +2 -1
- package/lib/theme/CodeEditor/WithScript/Storage.d.ts.map +1 -0
- package/lib/theme/CodeEditor/WithScript/Types.d.ts +12 -4
- package/lib/theme/CodeEditor/WithScript/Types.d.ts.map +1 -0
- package/lib/theme/CodeEditor/WithScript/bryRunner.d.ts +3 -0
- package/lib/theme/CodeEditor/WithScript/bryRunner.d.ts.map +1 -0
- package/lib/theme/CodeEditor/WithScript/bryRunner.js +29 -0
- package/lib/theme/CodeEditor/WithScript/createStore.d.ts +4 -0
- package/lib/theme/CodeEditor/WithScript/createStore.d.ts.map +1 -0
- package/lib/theme/CodeEditor/WithScript/{Store.jsx → createStore.js} +62 -74
- package/lib/theme/CodeEditor/WithScript/helpers.d.ts +1 -4
- package/lib/theme/CodeEditor/WithScript/helpers.d.ts.map +1 -0
- package/lib/theme/CodeEditor/WithScript/helpers.js +4 -14
- package/lib/theme/CodeEditor/constants.d.ts +1 -0
- package/lib/theme/CodeEditor/constants.d.ts.map +1 -0
- package/lib/theme/CodeEditor/hooks/index.d.ts +3 -0
- package/lib/theme/CodeEditor/hooks/index.d.ts.map +1 -0
- package/lib/theme/CodeEditor/hooks/index.js +2 -0
- package/lib/theme/CodeEditor/hooks/useScript.d.ts +3 -0
- package/lib/theme/CodeEditor/hooks/useScript.d.ts.map +1 -0
- package/lib/theme/CodeEditor/hooks/useScript.js +4 -0
- package/lib/theme/CodeEditor/hooks/useStore.d.ts +3 -0
- package/lib/theme/CodeEditor/hooks/useStore.d.ts.map +1 -0
- package/lib/theme/CodeEditor/hooks/useStore.js +10 -0
- package/lib/theme/CodeEditor/index.d.ts +24 -5
- package/lib/theme/CodeEditor/index.d.ts.map +1 -0
- package/lib/theme/CodeEditor/index.jsx +17 -16
- package/lib/theme/CodeEditor/styles.module.css +28 -30
- package/og-image.md +23 -0
- package/package.json +39 -20
- package/src/assets/py_back_trace.py +2 -1
- package/src/index.ts +96 -25
- package/src/options.ts +12 -12
- package/src/theme/CodeBlock/index.tsx +44 -68
- package/src/theme/CodeEditor/Actions/DownloadCode.tsx +23 -22
- package/src/theme/CodeEditor/Actions/Reset.tsx +14 -12
- package/src/theme/CodeEditor/Actions/RunCode.tsx +14 -11
- package/src/theme/CodeEditor/Actions/ShowRaw.tsx +17 -11
- package/src/theme/CodeEditor/Actions/ShowSyncStatus.tsx +32 -27
- package/src/theme/CodeEditor/Actions/styles.module.css +2 -3
- package/src/theme/CodeEditor/BrythonCommunicator.tsx +16 -19
- package/src/theme/CodeEditor/Button/index.tsx +17 -13
- package/src/theme/CodeEditor/Button/styles.module.css +1 -1
- package/src/theme/CodeEditor/CodeHistory/index.tsx +32 -20
- package/src/theme/CodeEditor/CodeHistory/styles.module.css +31 -31
- package/src/theme/CodeEditor/ContextEditor/index.tsx +74 -0
- package/src/theme/CodeEditor/Editor/EditorAce.tsx +20 -16
- package/src/theme/CodeEditor/Editor/Header/index.tsx +13 -19
- package/src/theme/CodeEditor/Editor/Header/styles.module.css +7 -7
- package/src/theme/CodeEditor/Editor/HiddenCode/index.tsx +49 -0
- package/src/theme/CodeEditor/Editor/HiddenCode/styles.module.css +52 -0
- package/src/theme/CodeEditor/Editor/Result/Graphics/Canvas.tsx +25 -22
- package/src/theme/CodeEditor/Editor/Result/Graphics/Turtle.tsx +23 -19
- package/src/theme/CodeEditor/Editor/Result/Graphics/index.tsx +16 -16
- package/src/theme/CodeEditor/Editor/Result/Graphics/styles.module.css +2 -2
- package/src/theme/CodeEditor/Editor/Result/index.tsx +7 -13
- package/src/theme/CodeEditor/Editor/Result/styles.module.css +15 -10
- package/src/theme/CodeEditor/Editor/index.tsx +67 -65
- package/src/theme/CodeEditor/Editor/styles.module.css +15 -7
- package/src/theme/CodeEditor/Editor/utils/checkForButtonClick.ts +5 -5
- package/src/theme/CodeEditor/Editor/utils/saveSvg.ts +63 -53
- package/src/theme/CodeEditor/Editor/utils/svgWithoutAnimations.ts +182 -201
- package/src/theme/CodeEditor/Icon/icons.ts +27 -13
- package/src/theme/CodeEditor/Icon/index.tsx +31 -11
- package/src/theme/CodeEditor/Icon/styles.module.css +1 -1
- package/src/theme/CodeEditor/WithScript/ScriptContext.tsx +36 -0
- package/src/theme/CodeEditor/WithScript/Storage.ts +3 -3
- package/src/theme/CodeEditor/WithScript/Types.ts +17 -11
- package/src/theme/CodeEditor/WithScript/bryRunner.ts +39 -0
- package/src/theme/CodeEditor/WithScript/createStore.ts +276 -0
- package/src/theme/CodeEditor/WithScript/helpers.ts +16 -26
- package/src/theme/CodeEditor/constants.ts +9 -11
- package/src/theme/CodeEditor/hooks/index.ts +2 -0
- package/src/theme/CodeEditor/hooks/useScript.ts +9 -0
- package/src/theme/CodeEditor/hooks/useStore.ts +15 -0
- package/src/theme/CodeEditor/index.tsx +45 -31
- package/src/theme/CodeEditor/styles.module.css +28 -30
- package/src/typings.d.ts +11 -0
- package/lib/theme/CodeEditor/WithScript/Store.d.ts +0 -15
- package/lib/types.d.ts +0 -28
- package/lib/types.js +0 -1
- package/src/theme/CodeEditor/WithScript/Store.tsx +0 -294
- package/src/types.ts +0 -29
|
@@ -1,78 +1,88 @@
|
|
|
1
|
-
import { removeAnimations } from
|
|
1
|
+
import { removeAnimations } from '@theme/CodeEditor/Editor/utils/svgWithoutAnimations';
|
|
2
2
|
|
|
3
3
|
const duration = (anim: SVGAnimateElement) => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
4
|
+
const dur = anim.getAttribute('dur') || '';
|
|
5
|
+
if (/ms$/.test(dur)) {
|
|
6
|
+
return Number.parseFloat(dur) / 1000 || 0;
|
|
7
|
+
} else if (/s$/.test(dur)) {
|
|
8
|
+
return Number.parseFloat(dur) || 0;
|
|
9
|
+
}
|
|
10
|
+
return 0;
|
|
11
|
+
};
|
|
12
12
|
|
|
13
13
|
const saveSvg = (svgEl: SVGSVGElement, name: string, code?: string, animated?: boolean) => {
|
|
14
|
-
svgEl.setAttribute(
|
|
15
|
-
|
|
14
|
+
svgEl.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
|
|
15
|
+
|
|
16
16
|
const bbox = svgEl.getBBox();
|
|
17
17
|
const svgProps = {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
18
|
+
viewBox: `${bbox.x - 5},${bbox.y - 5},${bbox.width + 10},${bbox.height + 10}`,
|
|
19
|
+
width: bbox.width + 10,
|
|
20
|
+
height: bbox.height + 10
|
|
21
|
+
};
|
|
22
22
|
var svgData = svgEl.outerHTML;
|
|
23
23
|
var preface = '<?xml version="1.0" standalone="no"?>';
|
|
24
24
|
const wrapper = document.createElement('div');
|
|
25
25
|
let animDuration = 0;
|
|
26
26
|
// if animations should be rendered, set window.__KEEP_TURTLE_ANIMATIONS__ = true
|
|
27
27
|
if (animated || (window as any).__KEEP_TURTLE_ANIMATIONS__) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
28
|
+
const saveSvg = svgEl.cloneNode(true) as SVGSVGElement;
|
|
29
|
+
const anims = saveSvg.querySelectorAll('animate');
|
|
30
|
+
const frameIds = Array.from(anims)
|
|
31
|
+
.map((n) => (n.id.match(/\d+/) || [])[0])
|
|
32
|
+
.filter((nr) => nr)
|
|
33
|
+
.map((nr) => Number.parseInt(nr!))
|
|
34
|
+
.sort((a, b) => (a > b ? 1 : -1));
|
|
35
|
+
if (frameIds.length > 0) {
|
|
36
|
+
const lastAnim = frameIds[frameIds.length - 1];
|
|
37
|
+
const firstAnim = saveSvg.getElementById('animation_frame0') as SVGAnimateElement;
|
|
38
|
+
if (firstAnim) {
|
|
39
|
+
const looper = document.createElement('rect');
|
|
40
|
+
looper.innerHTML = ` <rect><animate id="looper_animation" begin="0;animation_frame${lastAnim}.end" dur="1ms" attributeName="visibility" from="hide" to="hide"/></rect>`;
|
|
41
|
+
firstAnim.parentElement!.insertBefore(looper, firstAnim);
|
|
42
|
+
firstAnim.setAttribute('begin', 'looper_animation.end');
|
|
43
|
+
firstAnim.setAttribute('width', `${svgProps.width}`);
|
|
44
|
+
}
|
|
40
45
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
46
|
+
saveSvg.querySelectorAll('animate[attributeName="width"]').forEach((anim) => {
|
|
47
|
+
if (anim.getAttribute('from') === anim.getAttribute('to')) {
|
|
48
|
+
anim.setAttribute('from', `${svgProps.width}`);
|
|
49
|
+
}
|
|
50
|
+
anim.setAttribute('to', `${svgProps.width}`);
|
|
51
|
+
});
|
|
52
|
+
saveSvg.setAttribute('viewBox', svgProps.viewBox);
|
|
53
|
+
saveSvg.setAttribute('height', `${svgProps.height}`);
|
|
54
|
+
saveSvg.setAttribute('width', `${svgProps.width}`);
|
|
55
|
+
wrapper.innerHTML = `${preface}\r\n${saveSvg.outerHTML}`;
|
|
56
|
+
animDuration = Array.from(saveSvg.querySelectorAll('animate'))
|
|
57
|
+
.map(duration)
|
|
58
|
+
.reduce((d, c) => d + c, 0);
|
|
54
59
|
} else {
|
|
55
|
-
|
|
56
|
-
|
|
60
|
+
const svgWithoutAnim = removeAnimations(`${preface}${svgData}`, svgProps);
|
|
61
|
+
wrapper.innerHTML = svgWithoutAnim;
|
|
57
62
|
}
|
|
58
63
|
// if no metadata should be added, set window.__DISABLE_TURTLE_METADATA__ = true
|
|
59
64
|
if (!(window as any).__DISABLE_TURTLE_METADATA__) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
65
|
+
const svg = wrapper.querySelector('svg')!;
|
|
66
|
+
const metadata = document.createElement('metadata');
|
|
67
|
+
const script = document.createElement('raw');
|
|
68
|
+
script.innerHTML = code || '';
|
|
69
|
+
metadata.appendChild(script);
|
|
70
|
+
svg.appendChild(metadata);
|
|
66
71
|
}
|
|
67
72
|
|
|
68
|
-
var svgBlob = new Blob([wrapper.innerHTML], {
|
|
73
|
+
var svgBlob = new Blob([wrapper.innerHTML], {
|
|
74
|
+
type: 'image/svg+xml;charset=utf-8'
|
|
75
|
+
});
|
|
69
76
|
var svgUrl = URL.createObjectURL(svgBlob);
|
|
70
|
-
var downloadLink = document.createElement(
|
|
77
|
+
var downloadLink = document.createElement('a');
|
|
71
78
|
downloadLink.href = svgUrl;
|
|
72
|
-
downloadLink.download =
|
|
79
|
+
downloadLink.download =
|
|
80
|
+
animDuration > 0
|
|
81
|
+
? `${name}__${(Math.round(animDuration * 10) / 10).toString().replace('.', '_')}s.svg`
|
|
82
|
+
: `${name}.svg`;
|
|
73
83
|
document.body.appendChild(downloadLink);
|
|
74
84
|
downloadLink.click();
|
|
75
85
|
document.body.removeChild(downloadLink);
|
|
76
|
-
|
|
86
|
+
};
|
|
77
87
|
|
|
78
|
-
|
|
88
|
+
export { saveSvg };
|
|
@@ -1,218 +1,199 @@
|
|
|
1
|
-
import { parse, RootNode, Node } from
|
|
1
|
+
import { parse, RootNode, Node } from 'svg-parser';
|
|
2
2
|
|
|
3
3
|
const objToAttr = (obj: Object) => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
return Object.entries(obj || {})
|
|
5
|
+
.map((v) => `${v[0]}="${v[1]}"`)
|
|
6
|
+
.join(' ');
|
|
7
7
|
};
|
|
8
8
|
|
|
9
9
|
const mergeSvgProps = (parsedSvg: Node | RootNode, svgProps: Record<string, string | number> | undefined) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"properties" in parsedSvg
|
|
18
|
-
) {
|
|
19
|
-
parsedSvg.properties = { ...(parsedSvg.properties || {}), ...svgProps };
|
|
20
|
-
}
|
|
10
|
+
if (parsedSvg.type === 'root') {
|
|
11
|
+
parsedSvg.children.forEach((child) => {
|
|
12
|
+
mergeSvgProps(child, svgProps);
|
|
13
|
+
});
|
|
14
|
+
} else if (parsedSvg.type === 'element' && parsedSvg.tagName === 'svg' && 'properties' in parsedSvg) {
|
|
15
|
+
parsedSvg.properties = { ...(parsedSvg.properties || {}), ...svgProps };
|
|
16
|
+
}
|
|
21
17
|
};
|
|
22
18
|
|
|
23
19
|
const svgWithoutAnimations = (element: Node | RootNode | string): string[] => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
if (element.type === 'element') {
|
|
35
|
-
const { tagName, type, children } = element;
|
|
36
|
-
const properties = element.properties || {};
|
|
37
|
-
switch (element.tagName) {
|
|
38
|
-
case "svg":
|
|
39
|
-
if (element.metadata) {
|
|
40
|
-
newSvg.push(element.metadata);
|
|
41
|
-
}
|
|
42
|
-
newSvg.push(`<svg ${objToAttr(properties)}>`);
|
|
43
|
-
children.forEach((child) => {
|
|
44
|
-
newSvg.push(...svgWithoutAnimations(child));
|
|
45
|
-
});
|
|
46
|
-
newSvg.push(`</svg>`);
|
|
47
|
-
break;
|
|
48
|
-
case "rect":
|
|
49
|
-
children.forEach((child) => {
|
|
50
|
-
if (typeof child === "string" || child.type !== "element") {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
if (["animate", "set"].includes(child.tagName || '') && !!child.properties) {
|
|
54
|
-
const animProps = child.properties;
|
|
55
|
-
if (!("to" in animProps) || !("attributeName" in animProps)) {
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
if (
|
|
59
|
-
animProps.attributeName === "display" &&
|
|
60
|
-
animProps.attributeType === "CSS"
|
|
61
|
-
) {
|
|
62
|
-
properties.style = `${properties.style}`.replace(
|
|
63
|
-
/display:\s*\b\w+\b;/g,
|
|
64
|
-
`display: ${animProps.to};`
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
properties[animProps.attributeName] = animProps.to;
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
newSvg.push(`<rect ${objToAttr(properties)}></rect>`);
|
|
71
|
-
break;
|
|
72
|
-
case "g":
|
|
73
|
-
if ((children || []).length === 0) {
|
|
74
|
-
return newSvg;
|
|
75
|
-
}
|
|
76
|
-
newSvg.push(`<g ${objToAttr(properties)}>`);
|
|
77
|
-
children.forEach((child) => {
|
|
78
|
-
newSvg.push(...svgWithoutAnimations(child));
|
|
79
|
-
});
|
|
80
|
-
newSvg.push("</g>");
|
|
81
|
-
break;
|
|
82
|
-
case "line":
|
|
83
|
-
children.forEach((child) => {
|
|
84
|
-
if (typeof child === "string" || child.type !== "element") {
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
if (["animate", "set"].includes(child.tagName || '') && !!child.properties) {
|
|
88
|
-
const animProps = child.properties;
|
|
89
|
-
if (!("to" in animProps) || !("attributeName" in animProps)) {
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
properties[animProps.attributeName] = animProps.to;
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
newSvg.push(`<line ${objToAttr(properties)}></line>`);
|
|
96
|
-
break;
|
|
97
|
-
case "circle":
|
|
98
|
-
children.forEach((child) => {
|
|
99
|
-
if (typeof child === "string" || child.type !== "element") {
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
if (["animate", "set"].includes(child.tagName || '') && !!child.properties) {
|
|
103
|
-
const animProps = child.properties;
|
|
104
|
-
if (!("to" in animProps) || !("attributeName" in animProps)) {
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
if (
|
|
108
|
-
properties.attributeName === "display" &&
|
|
109
|
-
properties.attributeType === "CSS"
|
|
110
|
-
) {
|
|
111
|
-
properties.style = `${properties.style}`.replace(
|
|
112
|
-
/display:\s*\b\w+\b;/g,
|
|
113
|
-
`display: ${animProps.to}`
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
if (properties.style && /\s*display:\s*none;\s*/.test(`${properties.style}`)) {
|
|
119
|
-
properties.style = `${properties.style}`.replace(
|
|
120
|
-
/\s*display:\s*none;\s*/g,
|
|
121
|
-
""
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
newSvg.push(`<circle ${objToAttr(properties)}></circle>`);
|
|
125
|
-
break;
|
|
126
|
-
case "text":
|
|
127
|
-
var text: string | number | boolean | undefined;
|
|
128
|
-
children.forEach((child) => {
|
|
129
|
-
if (typeof child === 'string') {
|
|
130
|
-
text = child;
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
switch (child.type) {
|
|
134
|
-
case "text":
|
|
135
|
-
text = child.value;
|
|
136
|
-
break;
|
|
137
|
-
case "element":
|
|
138
|
-
const textProps = child.properties;
|
|
139
|
-
if (!textProps || !["animate", "set"].includes(child.tagName || '')) {
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
if (!("to" in textProps) || !("attributeName" in textProps)) {
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
if (
|
|
146
|
-
textProps.attributeName === "display" &&
|
|
147
|
-
textProps.attributeType === "CSS"
|
|
148
|
-
) {
|
|
149
|
-
properties.style = `${properties.style}`.replace(
|
|
150
|
-
/display:\s*\b\w+\b;/g,
|
|
151
|
-
`display: ${textProps.to};`
|
|
152
|
-
);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
properties[textProps.attributeName] = textProps.to;
|
|
156
|
-
break;
|
|
157
|
-
}
|
|
20
|
+
if (typeof element === 'string') {
|
|
21
|
+
return [element];
|
|
22
|
+
}
|
|
23
|
+
const newSvg: string[] = [];
|
|
24
|
+
// const { properties, tagName, type, children } = element;
|
|
25
|
+
if (element.type === 'root') {
|
|
26
|
+
element.children.forEach((child) => {
|
|
27
|
+
newSvg.push(...svgWithoutAnimations(child));
|
|
158
28
|
});
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
29
|
+
}
|
|
30
|
+
if (element.type === 'element') {
|
|
31
|
+
const { tagName, type, children } = element;
|
|
32
|
+
const properties = element.properties || {};
|
|
33
|
+
switch (element.tagName) {
|
|
34
|
+
case 'svg':
|
|
35
|
+
if (element.metadata) {
|
|
36
|
+
newSvg.push(element.metadata);
|
|
37
|
+
}
|
|
38
|
+
newSvg.push(`<svg ${objToAttr(properties)}>`);
|
|
39
|
+
children.forEach((child) => {
|
|
40
|
+
newSvg.push(...svgWithoutAnimations(child));
|
|
41
|
+
});
|
|
42
|
+
newSvg.push(`</svg>`);
|
|
43
|
+
break;
|
|
44
|
+
case 'rect':
|
|
45
|
+
children.forEach((child) => {
|
|
46
|
+
if (typeof child === 'string' || child.type !== 'element') {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (['animate', 'set'].includes(child.tagName || '') && !!child.properties) {
|
|
50
|
+
const animProps = child.properties;
|
|
51
|
+
if (!('to' in animProps) || !('attributeName' in animProps)) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (animProps.attributeName === 'display' && animProps.attributeType === 'CSS') {
|
|
55
|
+
properties.style = `${properties.style}`.replace(
|
|
56
|
+
/display:\s*\b\w+\b;/g,
|
|
57
|
+
`display: ${animProps.to};`
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
properties[animProps.attributeName] = animProps.to;
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
newSvg.push(`<rect ${objToAttr(properties)}></rect>`);
|
|
64
|
+
break;
|
|
65
|
+
case 'g':
|
|
66
|
+
if ((children || []).length === 0) {
|
|
67
|
+
return newSvg;
|
|
68
|
+
}
|
|
69
|
+
newSvg.push(`<g ${objToAttr(properties)}>`);
|
|
70
|
+
children.forEach((child) => {
|
|
71
|
+
newSvg.push(...svgWithoutAnimations(child));
|
|
72
|
+
});
|
|
73
|
+
newSvg.push('</g>');
|
|
74
|
+
break;
|
|
75
|
+
case 'line':
|
|
76
|
+
children.forEach((child) => {
|
|
77
|
+
if (typeof child === 'string' || child.type !== 'element') {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (['animate', 'set'].includes(child.tagName || '') && !!child.properties) {
|
|
81
|
+
const animProps = child.properties;
|
|
82
|
+
if (!('to' in animProps) || !('attributeName' in animProps)) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
properties[animProps.attributeName] = animProps.to;
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
newSvg.push(`<line ${objToAttr(properties)}></line>`);
|
|
89
|
+
break;
|
|
90
|
+
case 'circle':
|
|
91
|
+
children.forEach((child) => {
|
|
92
|
+
if (typeof child === 'string' || child.type !== 'element') {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (['animate', 'set'].includes(child.tagName || '') && !!child.properties) {
|
|
96
|
+
const animProps = child.properties;
|
|
97
|
+
if (!('to' in animProps) || !('attributeName' in animProps)) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if (properties.attributeName === 'display' && properties.attributeType === 'CSS') {
|
|
101
|
+
properties.style = `${properties.style}`.replace(
|
|
102
|
+
/display:\s*\b\w+\b;/g,
|
|
103
|
+
`display: ${animProps.to}`
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
if (properties.style && /\s*display:\s*none;\s*/.test(`${properties.style}`)) {
|
|
109
|
+
properties.style = `${properties.style}`.replace(/\s*display:\s*none;\s*/g, '');
|
|
110
|
+
}
|
|
111
|
+
newSvg.push(`<circle ${objToAttr(properties)}></circle>`);
|
|
112
|
+
break;
|
|
113
|
+
case 'text':
|
|
114
|
+
var text: string | number | boolean | undefined;
|
|
115
|
+
children.forEach((child) => {
|
|
116
|
+
if (typeof child === 'string') {
|
|
117
|
+
text = child;
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
switch (child.type) {
|
|
121
|
+
case 'text':
|
|
122
|
+
text = child.value;
|
|
123
|
+
break;
|
|
124
|
+
case 'element':
|
|
125
|
+
const textProps = child.properties;
|
|
126
|
+
if (!textProps || !['animate', 'set'].includes(child.tagName || '')) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
if (!('to' in textProps) || !('attributeName' in textProps)) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
if (textProps.attributeName === 'display' && textProps.attributeType === 'CSS') {
|
|
133
|
+
properties.style = `${properties.style}`.replace(
|
|
134
|
+
/display:\s*\b\w+\b;/g,
|
|
135
|
+
`display: ${textProps.to};`
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
properties[textProps.attributeName] = textProps.to;
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
newSvg.push(`<text ${objToAttr(properties)}>${text}</text>`);
|
|
144
|
+
break;
|
|
145
|
+
case 'polygon':
|
|
146
|
+
var endRot = '0,0,0';
|
|
147
|
+
var endPos = '0,0';
|
|
148
|
+
children.forEach((child) => {
|
|
149
|
+
if (typeof child === 'string' || child.type !== 'element' || !child.properties) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
const polyProps = child.properties;
|
|
153
|
+
switch (child.tagName) {
|
|
154
|
+
case 'set':
|
|
155
|
+
case 'animate':
|
|
156
|
+
if (!('to' in polyProps) || !('attributeName' in polyProps)) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
if (polyProps.attributeName === 'display' && polyProps.attributeType === 'CSS') {
|
|
160
|
+
properties.style = `${properties.style}`.replace(
|
|
161
|
+
/display:\s*\b\w+\b;/g,
|
|
162
|
+
`display: ${polyProps.to};`
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
properties[polyProps.attributeName] = polyProps.to;
|
|
167
|
+
break;
|
|
168
|
+
case 'animateTransform':
|
|
169
|
+
if (child.properties.type === 'rotate') {
|
|
170
|
+
endRot = `${child.properties.to}`;
|
|
171
|
+
}
|
|
172
|
+
break;
|
|
173
|
+
case 'animateMotion':
|
|
174
|
+
if ('to' in child.properties) {
|
|
175
|
+
endPos = `${child.properties.to}`;
|
|
176
|
+
}
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
newSvg.push(
|
|
181
|
+
`<polygon ${objToAttr(
|
|
182
|
+
properties
|
|
183
|
+
)} transform="translate(${endPos}) rotate(${endRot})"></polygon>`
|
|
182
184
|
);
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
properties[polyProps.attributeName] = polyProps.to;
|
|
186
|
-
break;
|
|
187
|
-
case "animateTransform":
|
|
188
|
-
if (child.properties.type === "rotate") {
|
|
189
|
-
endRot = `${child.properties.to}`;
|
|
190
|
-
}
|
|
191
|
-
break;
|
|
192
|
-
case "animateMotion":
|
|
193
|
-
if ("to" in child.properties) {
|
|
194
|
-
endPos = `${child.properties.to}`;
|
|
195
|
-
}
|
|
196
|
-
break;
|
|
197
|
-
}
|
|
198
|
-
});
|
|
199
|
-
newSvg.push(
|
|
200
|
-
`<polygon ${objToAttr(
|
|
201
|
-
properties
|
|
202
|
-
)} transform="translate(${endPos}) rotate(${endRot})"></polygon>`
|
|
203
|
-
);
|
|
185
|
+
}
|
|
204
186
|
}
|
|
205
|
-
|
|
206
|
-
return newSvg;
|
|
187
|
+
return newSvg;
|
|
207
188
|
};
|
|
208
189
|
|
|
209
190
|
const removeAnimations = (svg: string, svgProps: Record<string, string | number>): string => {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
191
|
+
const parsed = parse(svg);
|
|
192
|
+
if (svgProps) {
|
|
193
|
+
mergeSvgProps(parsed, svgProps);
|
|
194
|
+
}
|
|
195
|
+
const elements = svgWithoutAnimations(parsed);
|
|
196
|
+
return elements.join('\n');
|
|
216
197
|
};
|
|
217
198
|
|
|
218
199
|
export { removeAnimations };
|
|
@@ -1,15 +1,27 @@
|
|
|
1
|
-
|
|
2
1
|
const Download = 'M5,20H19V18H5M19,9H15V3H9V9H5L12,16L19,9Z';
|
|
3
|
-
const Python =
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
2
|
+
const Python =
|
|
3
|
+
'M19.14,7.5A2.86,2.86 0 0,1 22,10.36V14.14A2.86,2.86 0 0,1 19.14,17H12C12,17.39 12.32,17.96 12.71,17.96H17V19.64A2.86,2.86 0 0,1 14.14,22.5H9.86A2.86,2.86 0 0,1 7,19.64V15.89C7,14.31 8.28,13.04 9.86,13.04H15.11C16.69,13.04 17.96,11.76 17.96,10.18V7.5H19.14M14.86,19.29C14.46,19.29 14.14,19.59 14.14,20.18C14.14,20.77 14.46,20.89 14.86,20.89A0.71,0.71 0 0,0 15.57,20.18C15.57,19.59 15.25,19.29 14.86,19.29M4.86,17.5C3.28,17.5 2,16.22 2,14.64V10.86C2,9.28 3.28,8 4.86,8H12C12,7.61 11.68,7.04 11.29,7.04H7V5.36C7,3.78 8.28,2.5 9.86,2.5H14.14C15.72,2.5 17,3.78 17,5.36V9.11C17,10.69 15.72,11.96 14.14,11.96H8.89C7.31,11.96 6.04,13.24 6.04,14.82V17.5H4.86M9.14,5.71C9.54,5.71 9.86,5.41 9.86,4.82C9.86,4.23 9.54,4.11 9.14,4.11C8.75,4.11 8.43,4.23 8.43,4.82C8.43,5.41 8.75,5.71 9.14,5.71Z';
|
|
4
|
+
const Play =
|
|
5
|
+
'M 7.4219 1.8281 c -0.6938 -0.4266 -1.5656 -0.4406 -2.2734 -0.0422 S 4 2.9344 4 3.75 V 20.25 c 0 0.8156 0.4406 1.5656 1.1484 1.9641 s 1.5797 0.3797 2.2734 -0.0422 L 20.9219 13.9219 c 0.6703 -0.4078 1.0781 -1.1344 1.0781 -1.9219 s -0.4078 -1.5094 -1.0781 -1.9219 L 7.4219 1.8281 Z';
|
|
6
|
+
const Close =
|
|
7
|
+
'M13.46,12L19,17.54V19H17.54L12,13.46L6.46,19H5V17.54L10.54,12L5,6.46V5H6.46L12,10.54L17.54,5H19V6.46L13.46,12Z';
|
|
8
|
+
const AnimationPlay =
|
|
9
|
+
'M4,2H14V4H4V14H2V4C2,2.89 2.89,2 4,2M8,6H18V8H8V18H6V8C6,6.89 6.89,6 8,6M12,10H20C21.11,10 22,10.89 22,12V20C22,21.11 21.11,22 20,22H12C10.89,22 10,21.11 10,20V12C10,10.89 10.89,10 12,10M14,12V20L20,16L14,12Z';
|
|
10
|
+
const Sync =
|
|
11
|
+
'M12,18A6,6 0 0,1 6,12C6,11 6.25,10.03 6.7,9.2L5.24,7.74C4.46,8.97 4,10.43 4,12A8,8 0 0,0 12,20V23L16,19L12,15M12,4V1L8,5L12,9V6A6,6 0 0,1 18,12C18,13 17.75,13.97 17.3,14.8L18.76,16.26C19.54,15.03 20,13.57 20,12A8,8 0 0,0 12,4Z';
|
|
12
|
+
const Check =
|
|
13
|
+
'M12 2C6.5 2 2 6.5 2 12S6.5 22 12 22 22 17.5 22 12 17.5 2 12 2M10 17L5 12L6.41 10.59L10 14.17L17.59 6.58L19 8L10 17Z';
|
|
14
|
+
const ErrorIcon =
|
|
15
|
+
'M12,2C17.53,2 22,6.47 22,12C22,17.53 17.53,22 12,22C6.47,22 2,17.53 2,12C2,6.47 6.47,2 12,2M15.59,7L12,10.59L8.41,7L7,8.41L10.59,12L7,15.59L8.41,17L12,13.41L15.59,17L17,15.59L13.41,12L17,8.41L15.59,7Z';
|
|
16
|
+
const EditCode =
|
|
17
|
+
'M 9.54 13.65 L 11.63 15.74 L 10.35 17 L 7 13.65 L 10.35 10.3 L 11.63 11.56 L 9.54 13.65 M 17 13.65 L 13.65 17 L 12.38 15.74 L 14.47 13.65 L 12.38 11.56 L 13.65 10.3 l 3.35 3.35 Z M 10 20 H 6 V 4 H 13 V 9 H 18 V 12.1 L 20 10.1 V 8 L 14 2 H 6 A 2 2 0 0 0 4 4 V 20 A 2 2 0 0 0 6 22 H 10 V 20 M 20.2 13 C 20.3 13 20.5 13.1 20.6 13.2 L 21.9 14.5 C 22.1 14.7 22.1 15.1 21.9 15.3 L 20.9 16.3 L 18.8 14.2 L 19.8 13.2 C 19.9 13.1 20 13 20.2 13 M 20.2 16.9 L 14.1 23 H 12 V 20.9 L 18.1 14.8 L 20.2 16.9 Z';
|
|
18
|
+
const Code =
|
|
19
|
+
'M14 2H6C4.89 2 4 2.9 4 4V20C4 21.11 4.89 22 6 22H18C19.11 22 20 21.11 20 20V8L14 2M18 20H6V4H13V9H18V20M9.54 15.65L11.63 17.74L10.35 19L7 15.65L10.35 12.3L11.63 13.56L9.54 15.65M17 15.65L13.65 19L12.38 17.74L14.47 15.65L12.38 13.56L13.65 12.3L17 15.65Z';
|
|
20
|
+
const Reset =
|
|
21
|
+
'M13,3A9,9 0 0,0 4,12H1L4.89,15.89L4.96,16.03L9,12H6A7,7 0 0,1 13,5A7,7 0 0,1 20,12A7,7 0 0,1 13,19C11.07,19 9.32,18.21 8.06,16.94L6.64,18.36C8.27,20 10.5,21 13,21A9,9 0 0,0 22,12A9,9 0 0,0 13,3Z';
|
|
22
|
+
const TrayPlus =
|
|
23
|
+
'M2 12H4V17H20V12H22V17A2 2 0 0 1 20 19H4A2 2 0 0 1 2 17M11 5H13V8H16V10H13V13H11V10H8V8H11Z';
|
|
24
|
+
const TrayMinus = 'M16 10H8V8H16M2 17A2 2 0 0 0 4 19H20A2 2 0 0 0 22 17V12H20V17H4V12H2Z';
|
|
13
25
|
|
|
14
26
|
export {
|
|
15
27
|
Download,
|
|
@@ -22,5 +34,7 @@ export {
|
|
|
22
34
|
ErrorIcon,
|
|
23
35
|
EditCode,
|
|
24
36
|
Code,
|
|
25
|
-
Reset
|
|
26
|
-
|
|
37
|
+
Reset,
|
|
38
|
+
TrayPlus,
|
|
39
|
+
TrayMinus
|
|
40
|
+
};
|