Blame view

天文台pc/tianwentai-ui/node_modules/motion-dom/dist/es/effects/svg/index.mjs 1.84 KB
bc518174   王天杨   提交两个项目文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
  import { MotionValue } from '../../value/index.mjs';
  import { addAttrValue } from '../attr/index.mjs';
  import { addStyleValue } from '../style/index.mjs';
  import { createSelectorEffect } from '../utils/create-dom-effect.mjs';
  import { createEffect } from '../utils/create-effect.mjs';
  import { frame } from '../../frameloop/frame.mjs';
  
  function addSVGPathValue(element, state, key, value) {
      frame.render(() => element.setAttribute("pathLength", "1"));
      if (key === "pathOffset") {
          return state.set(key, value, () => {
              // Use unitless value to avoid Safari zoom bug
              const offset = state.latest[key];
              element.setAttribute("stroke-dashoffset", `${-offset}`);
          });
      }
      else {
          if (!state.get("stroke-dasharray")) {
              state.set("stroke-dasharray", new MotionValue("1 1"), () => {
                  const { pathLength = 1, pathSpacing } = state.latest;
                  // Use unitless values to avoid Safari zoom bug
                  element.setAttribute("stroke-dasharray", `${pathLength} ${pathSpacing ?? 1 - Number(pathLength)}`);
              });
          }
          return state.set(key, value, undefined, state.get("stroke-dasharray"));
      }
  }
  const addSVGValue = (element, state, key, value) => {
      if (key.startsWith("path")) {
          return addSVGPathValue(element, state, key, value);
      }
      else if (key.startsWith("attr")) {
          return addAttrValue(element, state, convertAttrKey(key), value);
      }
      const handler = key in element.style ? addStyleValue : addAttrValue;
      return handler(element, state, key, value);
  };
  const svgEffect = /*@__PURE__*/ createSelectorEffect(
  /*@__PURE__*/ createEffect(addSVGValue));
  function convertAttrKey(key) {
      return key.replace(/^attr([A-Z])/, (_, firstChar) => firstChar.toLowerCase());
  }
  
  export { svgEffect };
  //# sourceMappingURL=index.mjs.map