UNPKG

2.78 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7
8var _preact = require("preact");
9
10function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
11
12function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
13
14function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
15
16class AnimatedPath extends _preact.Component {
17 constructor(props) {
18 super(props);
19 this.state = {
20 firstRender: true,
21 length: 0
22 };
23 }
24
25 componentDidMount() {
26 setTimeout(() => {
27 const length = Math.round(this.base.getTotalLength());
28 this.setState({
29 length
30 });
31 setTimeout(() => {
32 this.setState({
33 firstRender: false
34 });
35 }, 100);
36 }, 100);
37 }
38
39 render({
40 path,
41 animate
42 }, {
43 firstRender,
44 length
45 }) {
46 if (!animate) {
47 return (0, _preact.h)("path", {
48 d: path,
49 fill: "none",
50 stroke: "black",
51 "stroke-width": "5"
52 });
53 }
54
55 return (0, _preact.h)("path", {
56 key: length ? 'real' : 'fake',
57 d: path,
58 fill: "none",
59 stroke: length ? 'black' : 'none',
60 "stroke-width": "5",
61 style: {
62 transitionDuration: '1s',
63 transitionDelay: '.25s',
64 transitionProperty: 'stroke-dashoffset',
65 strokeDashoffset: firstRender ? length : 0,
66 strokeDasharray: length
67 }
68 });
69 }
70
71}
72
73var _default = (_ref) => {
74 let {
75 path,
76 width = '100',
77 animate
78 } = _ref,
79 rest = _objectWithoutProperties(_ref, ["path", "width", "animate"]);
80
81 return (0, _preact.h)("svg", _extends({
82 width: width,
83 height: width / 2,
84 viewBox: "0 0 800 400"
85 }, rest), (0, _preact.h)(AnimatedPath, {
86 key: path.slice(0, 10),
87 path: path,
88 animate: animate
89 }));
90};
91
92exports.default = _default;
\No newline at end of file