GSAP 사례 연구

convertToPath()

배경 · MIT (local companion); GSAP Standard No Charge License (runtime)

배경 더 보기
CASE STUDY
convertToPath() 정적 미리보기

갤러리 안에서는 화면을 벗어나거나 움직임을 멈추면 예제도 닫힙니다. 다시 재생할 때는 처음부터 시작해요.

큰 화면으로 보기 새 탭실행 HTML 저장

저장한 HTML에서는 갤러리의 재생 설정이 적용되지 않아요.

SOURCE FILES

독립 예제 코드 읽기

6개 파일

사례의 구도나 문서의 원리를 바탕으로 새로 만든 예제입니다. 아래 코드를 복사해 직접 응용할 수 있습니다. 실행 HTML에는 미리보기를 위한 실행 환경이 들어 있습니다.

vendor/gsap-previews/sources/gsap-fa5c18e802b2/study-brief.json실행 안내·자료
파일 저장

{
  "id": "gsap-fa5c18e802b2",
  "sourceId": "gsap",
  "title": "convertToPath()",
  "sourceUrl": "https://demos.gsap.com/demo/converttopath",
  "demoUrl": "https://codepen.io/GreenSock/pen/gagNeR",
  "sourceStatus": "unresolved",
  "sourceReason": "Public page unavailable through web browsing",
  "sourceRevision": null,
  "sourceLicense": null,
  "originalDemoAcquired": false,
  "disposition": "ready_for_independent_study",
  "evidenceBasis": "catalog_linked_api",
  "studyId": "gsap-fa5c18e802b2",
  "sharedStudyCanonicalId": null,
  "label": "Independently authored documentation study; original Pen unavailable",
  "catalogEvidence": {
    "localPath": "artifacts/full-import/gsap/remaining-docs/catalog-evidence.json",
    "sha256": "4f2a4f9aa64456b85b905b562b60d7733629b41026787b3057cba29e8b10de69",
    "bytes": 30117,
    "recordId": "gsap-fa5c18e802b2"
  },
  "sourceInputs": [
    {
      "kind": "authored-study-specification",
      "localPath": "artifacts/full-import/gsap/remaining-docs/study-specs.json",
      "sha256": "cbb89331eda8783b5cf2f173b326b9195eeabfb223374fb60019161d9f46d4a6",
      "bytes": 52279,
      "recordId": "gsap-fa5c18e802b2"
    },
    {
      "kind": "official-catalog-metadata",
      "localPath": "artifacts/full-import/gsap/remaining-docs/catalog-evidence.json",
      "sha256": "4f2a4f9aa64456b85b905b562b60d7733629b41026787b3057cba29e8b10de69",
      "bytes": 30117,
      "recordId": "gsap-fa5c18e802b2"
    },
    {
      "kind": "official-documentation-evidence",
      "localPath": "artifacts/full-import/gsap/remaining-docs/official-documentation-evidence.json",
      "sha256": "bfa25f561e61c597569cf1bc0b3538e6dce4b9985a932775ceab41e665ca24a2",
      "bytes": 11430,
      "recordIds": [
        "convert",
        "morph"
      ]
    },
    {
      "kind": "original-library-source",
      "localPath": "artifacts/full-import/gsap/library/src/gsap-core.js",
      "sha256": "8063816e0e7c3e6c07970fb06feafb06146fd266db5d8346419176b3d496e284",
      "gitBlob": "c673b9e2e0ee04832afb13cb892ae75f503e268c",
      "revision": "13e2b790546426a1a2e0e9b409f3f8dc6d6611f2",
      "sourcePath": "src/gsap-core.js",
      "ranges": [
        {
          "id": "tween-factories",
          "startLine": 2637,
          "endLine": 2657,
          "rangeSha256": "23ae9d51865c9b7966bbc3b6cdbdb560fc790ff19e3b8bb524a3493fbf60c58a"
        }
      ]
    },
    {
      "kind": "original-library-source",
      "localPath": "artifacts/full-import/gsap/library/src/MorphSVGPlugin.js",
      "sha256": "ed1a050ea542e5f7918b079f1a9d7094baa7ca2eef4a03c9700fc975f330859b",
      "gitBlob": "16ca88dddb9dca68d6823e903e87685e031c6a39",
      "revision": "13e2b790546426a1a2e0e9b409f3f8dc6d6611f2",
      "sourcePath": "src/MorphSVGPlugin.js",
      "ranges": [
        {
          "id": "morph-convert-api",
          "startLine": 847,
          "endLine": 854,
          "rangeSha256": "af9fad8bb68b4770c92909a707a270c24fb17ca7be1c4af7f51a90036e1bf532"
        },
        {
          "id": "morph-smooth-endpoint",
          "startLine": 675,
          "endLine": 692,
          "rangeSha256": "b8dd321271beb04d7e3b0f262dc6d550c6568185928a205cf5031ece19d5bab3"
        }
      ]
    },
    {
      "kind": "original-library-source",
      "localPath": "artifacts/full-import/gsap/library/src/utils/paths.js",
      "sha256": "37a33aa0685b114dd21562c7ec348095abaf7be022103b481947a011c1eb42fb",
      "gitBlob": "7c7337ff9923da1a2f95872f37f1551ffe4bb725",
      "revision": "13e2b790546426a1a2e0e9b409f3f8dc6d6611f2",
      "sourcePath": "src/utils/paths.js",
      "ranges": [
        {
          "id": "svg-primitive-conversion",
          "startLine": 164,
          "endLine": 226,
          "rangeSha256": "fe9d4f8a563b0c2b6d52f6517e8ffe6f4a5cfe543a6d80c2a166b0b6f7545d18"
        }
      ]
    }
  ],
  "studiedPrinciple": "Convert SVG primitive elements to path elements and inspect the DOM change before using a converted shape as a morph target.",
  "namedApis": [
    {
      "name": "MorphSVGPlugin.convertToPath(targets, swap)",
      "purpose": "Convert selected primitives; true/default swaps DOM elements and false returns detached paths.",
      "libraryEvidence": [
        "morph-convert-api",
        "svg-primitive-conversion"
      ],
      "documentationEvidence": [
        "convert"
      ]
    },
    {
      "name": "gsap.to(path, {morphSVG: targetPath})",
      "purpose": "Demonstrate an optional next step using the returned path reference.",
      "libraryEvidence": [
        "morph-smooth-endpoint",
        "tween-factories"
      ],
      "documentationEvidence": [
        "morph"
      ]
    }
  ],
  "implementationBrief": {
    "scene": "An authored SVG with a rect, circle, ellipse, line, polyline, and polygon in separate labeled cells. Use local SVG geometry and expose a small tag-name/path-data inspection panel.",
    "controls": [
      {
        "label": "Convert primitives",
        "type": "button",
        "action": "Call convertToPath on the retained primitive node references, save its returned array, then report each current tagName and d attribute."
      },
      {
        "label": "Swap elements",
        "type": "checkbox",
        "action": "Choose true or false for swap before conversion. Explain that false returns paths without inserting them."
      },
      {
        "label": "Morph selected path",
        "type": "button",
        "action": "Enabled after a swapped conversion; morph one returned path to an independently authored closed path."
      },
      {
        "label": "Reset",
        "type": "button",
        "action": "Kill the study tween and rebuild the original authored SVG primitives, then refresh retained node references."
      }
    ],
    "mechanismSteps": [
      "Load core and MorphSVGPlugin, register it, and create the original primitive nodes from the study's own geometry.",
      "Capture node references before conversion. With swap enabled, convertToPath replaces each primitive with a new path, so use the returned nodes for later animation and event bindings.",
      "Display original and resulting element types and whether each returned node is connected. Do not attach a detached return value implicitly when demonstrating swap:false.",
      "For the optional morph keep source and target coordinates in the same viewBox and use only one selected returned path.",
      "Reset by recreating primitives rather than repeatedly converting a prior path and pretending that a new conversion occurred."
    ]
  },
  "authoredDefaults": {
    "svgViewBox": "0 0 600 300",
    "swap": true,
    "morphDurationSeconds": 1,
    "ease": "power1.inOut",
    "pathGeometry": "New primitives and one new closed morph endpoint"
  },
  "verificationRequired": [
    "With swap:true all six returned elements are paths connected to the SVG and the original primitive nodes are disconnected.",
    "With swap:false the original elements remain connected and returned new paths remain detached.",
    "The optional morph uses the returned reference and changes its d attribute; reset restores the original six primitive types.",
    "Compare geometry before and after conversion at two widths, without claiming exact mathematical equality for circular cubic approximations."
  ],
  "unsupportedClaims": [
    "Original composition, assets, timing, breakpoint behavior, and live interaction are not observable in captured frames. This brief does not establish visual fidelity or recover original code.",
    "The catalog's Text Effects category does not establish a text-morphing implementation; the explicit convertToPath API link is the mechanism evidence.",
    "Original shape selection, path art, interaction, and layout are unknown.",
    "Conversion can replace nodes, so listeners bound to the old elements are not assumed to transfer."
  ],
  "dependencies": {
    "package": "gsap",
    "version": "3.15.0",
    "revision": "13e2b790546426a1a2e0e9b409f3f8dc6d6611f2",
    "repository": "https://github.com/greensock/GSAP",
    "plugins": [
      "MorphSVGPlugin"
    ],
    "registration": "gsap.registerPlugin(MorphSVGPlugin) after loading core and those plugin scripts",
    "runtimeCandidates": [
      {
        "path": "dist/gsap.js",
        "localPath": "artifacts/full-import/gsap/library/dist/gsap.js",
        "gitBlob": "ec5ffee3f099bc454f2f1c79cee6a55ba97e7400",
        "sha256": "01effe0e121c22ba0f885a3f091f3dc6d1f0d445c4fba37dcb298e314eca5cfb",
        "bytes": 179557
      },
      {
        "path": "dist/MorphSVGPlugin.js",
        "localPath": "artifacts/full-import/gsap/library/dist/MorphSVGPlugin.js",
        "gitBlob": "40531f708058713a7ad2942b74d0e1442c31431c",
        "sha256": "786b51ffe878fa747bb7e115815d438ec9113bde1303967172c34b129f5472ef",
        "bytes": 55989
      }
    ],
    "license": {
      "name": "GSAP Standard 'No Charge' License (custom, not MIT)",
      "localPath": "artifacts/full-import/gsap/licenses/gsap-standard-license.html",
      "sha256": "bf8536e67b77db780f7db0c14a645f184f554bb19e938d1e52d58986e2f10528",
      "bytes": 6988,
      "url": "https://gsap.com/community/standard-license/"
    },
    "originalDependencyVersionKnown": false
  },
  "runtimeVerified": false,
  "implementationWritten": false
}
vendor/gsap-previews/sources/gsap-fa5c18e802b2/source-inputs.json실행 안내·자료
파일 저장

[
  {
    "kind": "authored-study-specification",
    "localPath": "artifacts/full-import/gsap/remaining-docs/study-specs.json",
    "sha256": "cbb89331eda8783b5cf2f173b326b9195eeabfb223374fb60019161d9f46d4a6",
    "bytes": 52279,
    "recordId": "gsap-fa5c18e802b2"
  },
  {
    "kind": "official-catalog-metadata",
    "localPath": "artifacts/full-import/gsap/remaining-docs/catalog-evidence.json",
    "sha256": "4f2a4f9aa64456b85b905b562b60d7733629b41026787b3057cba29e8b10de69",
    "bytes": 30117,
    "recordId": "gsap-fa5c18e802b2"
  },
  {
    "kind": "official-documentation-evidence",
    "localPath": "artifacts/full-import/gsap/remaining-docs/official-documentation-evidence.json",
    "sha256": "bfa25f561e61c597569cf1bc0b3538e6dce4b9985a932775ceab41e665ca24a2",
    "bytes": 11430,
    "recordIds": [
      "convert",
      "morph"
    ]
  },
  {
    "kind": "original-library-source",
    "localPath": "artifacts/full-import/gsap/library/src/gsap-core.js",
    "sha256": "8063816e0e7c3e6c07970fb06feafb06146fd266db5d8346419176b3d496e284",
    "gitBlob": "c673b9e2e0ee04832afb13cb892ae75f503e268c",
    "revision": "13e2b790546426a1a2e0e9b409f3f8dc6d6611f2",
    "sourcePath": "src/gsap-core.js",
    "ranges": [
      {
        "id": "tween-factories",
        "startLine": 2637,
        "endLine": 2657,
        "rangeSha256": "23ae9d51865c9b7966bbc3b6cdbdb560fc790ff19e3b8bb524a3493fbf60c58a"
      }
    ]
  },
  {
    "kind": "original-library-source",
    "localPath": "artifacts/full-import/gsap/library/src/MorphSVGPlugin.js",
    "sha256": "ed1a050ea542e5f7918b079f1a9d7094baa7ca2eef4a03c9700fc975f330859b",
    "gitBlob": "16ca88dddb9dca68d6823e903e87685e031c6a39",
    "revision": "13e2b790546426a1a2e0e9b409f3f8dc6d6611f2",
    "sourcePath": "src/MorphSVGPlugin.js",
    "ranges": [
      {
        "id": "morph-convert-api",
        "startLine": 847,
        "endLine": 854,
        "rangeSha256": "af9fad8bb68b4770c92909a707a270c24fb17ca7be1c4af7f51a90036e1bf532"
      },
      {
        "id": "morph-smooth-endpoint",
        "startLine": 675,
        "endLine": 692,
        "rangeSha256": "b8dd321271beb04d7e3b0f262dc6d550c6568185928a205cf5031ece19d5bab3"
      }
    ]
  },
  {
    "kind": "original-library-source",
    "localPath": "artifacts/full-import/gsap/library/src/utils/paths.js",
    "sha256": "37a33aa0685b114dd21562c7ec348095abaf7be022103b481947a011c1eb42fb",
    "gitBlob": "7c7337ff9923da1a2f95872f37f1551ffe4bb725",
    "revision": "13e2b790546426a1a2e0e9b409f3f8dc6d6611f2",
    "sourcePath": "src/utils/paths.js",
    "ranges": [
      {
        "id": "svg-primitive-conversion",
        "startLine": 164,
        "endLine": 226,
        "rangeSha256": "fe9d4f8a563b0c2b6d52f6517e8ffe6f4a5cfe543a6d80c2a166b0b6f7545d18"
      }
    ]
  }
]
함께 쓰는 파일 4개 보기
vendor/gsap-previews/sources/gsap-fa5c18e802b2/index.html실행 안내·자료
파일 저장

<main class="study"><p class="study-label">공식 API 기반 · 독립 예제</p><header><h2>도형에서 경로로</h2><p>겉모양과 DOM의 요소 종류는 다릅니다. 바꾸기 옵션은 반환 경로의 연결 상태를 결정합니다.</p></header><div class="stage"><svg id="primitives" viewBox="0 0 600 280" role="img" aria-label="사각형 원 타원 선 꺾은선 다각형"><rect class="primitive" x="36" y="32" width="112" height="82" rx="18"/><circle class="primitive" cx="296" cy="72" r="46"/><ellipse class="primitive" cx="496" cy="72" rx="65" ry="38"/><line class="primitive" x1="38" y1="210" x2="148" y2="165"/><polyline class="primitive" points="242 220 268 162 300 217 346 158"/><polygon class="primitive" points="490 154 550 210 490 250 436 207"/></svg></div><div class="controls"><button id="convert" type="button">경로로 변환</button><label><input id="swap" type="checkbox" checked>요소 바꾸기</label><button id="morph" type="button">첫 경로 모핑</button><button id="reset" type="button">초기화</button><label><input id="static-mode" type="checkbox">정적 보기</label></div><p class="readout" id="reading" aria-live="off"></p><pre class="small-code" id="inspection">rect · circle · ellipse · line · polyline · polygon</pre></main>
vendor/gsap-previews/sources/gsap-fa5c18e802b2/style.css실행 안내·자료
파일 저장


*{box-sizing:border-box}body{background:#111522;color:#f5f2eb;font-family:system-ui,sans-serif;margin:0}button{font:inherit}.study{margin:0 auto;max-width:1100px;min-height:100vh;padding:clamp(20px,4vw,42px)}.study-label{color:#95efd2;font-size:12px;letter-spacing:.08em;margin:0 0 24px}header h2{font-size:clamp(24px,4vw,40px);letter-spacing:-.04em;margin:0 0 12px}header p{color:#aeb7c9;line-height:1.6;margin:0 0 24px;max-width:62ch}.controls{display:flex;flex-wrap:wrap;gap:8px;margin:20px 0}button{background:#26314b;border:1px solid #617394;border-radius:9px;color:#f5f2eb;cursor:pointer;padding:9px 14px}button:hover{background:#334261}button:focus-visible{outline:3px solid #95efd2;outline-offset:3px}button:disabled{cursor:default;opacity:.45}.stage{align-items:center;background:radial-gradient(ellipse at top,#243253,#141c2d);border:1px solid #3d4c68;border-radius:20px;display:flex;justify-content:center;min-height:220px;overflow:hidden;position:relative}.note{color:#aeb7c9;font-size:13px;line-height:1.5}.readout{color:#95efd2;font-family:ui-monospace,monospace;font-size:13px;min-height:2em}.stage svg{display:block;max-width:100%}code{font-family:ui-monospace,monospace}button[aria-pressed="true"]{background:#95efd2;color:#111522}


.study{padding:18px;max-width:960px}.study-label{margin-bottom:10px}header h2{font-size:clamp(22px,4vw,32px);margin-bottom:8px}header p{font-size:14px;margin-bottom:16px}.controls{align-items:center;gap:9px;margin:14px 0}.controls label{align-items:center;color:#cbd4e3;display:flex;flex-wrap:wrap;font-size:13px;gap:7px}.controls input[type=range]{accent-color:#95efd2;max-width:145px}.controls select{background:#26314b;border:1px solid #617394;border-radius:7px;color:#f5f2eb;font:inherit;padding:6px}.stage{min-height:180px}.readout{line-height:1.5;margin:8px 0}.small-code{background:#172036;border:1px solid #354258;border-radius:10px;color:#c3d1e7;font-size:12px;line-height:1.5;max-height:180px;overflow:auto;padding:12px;white-space:pre-wrap;word-break:break-word}.pair{display:flex;gap:12px;justify-content:center}.pair figure{flex:1;margin:0;max-width:300px;min-width:0;padding:8px}.pair figcaption{color:#aeb7c9;font-family:ui-monospace,monospace;font-size:12px;margin-bottom:6px;text-align:center}.pair svg{display:block;max-height:210px;width:100%}.tile-art{align-items:center;border-radius:14px;color:#152039;display:flex;justify-content:center}.tile-art svg{height:65%;width:65%}.menu-stage{min-height:196px;padding:18px}.menu-panels{display:flex;gap:10px;max-width:570px;width:100%}.menu-panel{align-items:center;background:linear-gradient(135deg,#95efd2,#75d8ed);border-radius:14px;color:#142137;display:flex;flex:1;flex-direction:column;font-weight:650;gap:10px;justify-content:center;min-height:135px;min-width:0;padding:12px}.menu-panel:nth-child(2){background:linear-gradient(135deg,#fbadce,#897dff)}.menu-panel:nth-child(3){background:linear-gradient(135deg,#ffd28c,#fc7f8e)}.menu-panel svg{height:58px;width:58px}.icon-bars{display:inline-flex;flex-direction:column;gap:5px;margin-right:7px;vertical-align:middle}.icon-bars span{background:currentColor;display:block;height:2px;width:17px}.endpoint-note{color:#aeb7c9;font-size:12px;line-height:1.5}button[hidden],[hidden]{display:none!important}@media(max-width:380px){.study{padding:14px}.controls label{max-width:100%}.menu-panels{gap:6px}.menu-panel{font-size:12px;padding:7px}.pair{gap:0}}

#primitives{max-height:250px;width:100%}.primitive{fill:#95efd2;stroke:#95efd2;stroke-width:7;stroke-linejoin:round}.primitive:nth-child(2n){fill:#fbadce;stroke:#fbadce}.primitive:nth-child(4),.primitive:nth-child(5){fill:none}
vendor/gsap-previews/sources/gsap-fa5c18e802b2/script.js실행 안내·자료
파일 저장

gsap.registerPlugin(MorphSVGPlugin);

const q=selector=>document.querySelector(selector),qa=selector=>Array.from(document.querySelectorAll(selector));
const studyAbort=new AbortController(),studyCleanup=[];
const listen=(target,type,handler)=>target.addEventListener(type,handler,{signal:studyAbort.signal});
const preference=matchMedia('(prefers-reduced-motion: reduce)'),staticControl=q('#static-mode');
staticControl.checked=preference.matches;staticControl.disabled=preference.matches;
const isStatic=()=>staticControl.checked||preference.matches;
let applyMode=()=>{};
listen(staticControl,'change',()=>applyMode());
listen(preference,'change',()=>{staticControl.checked=preference.matches;staticControl.disabled=preference.matches;applyMode();});
listen(window,'pagehide',()=>{studyCleanup.forEach(cleanup=>cleanup());studyAbort.abort();});
const reading=text=>q('#reading').textContent=text;

const primitiveSvg=q('#primitives'),PRIMITIVES="<rect class=\"primitive\" x=\"36\" y=\"32\" width=\"112\" height=\"82\" rx=\"18\"/><circle class=\"primitive\" cx=\"296\" cy=\"72\" r=\"46\"/><ellipse class=\"primitive\" cx=\"496\" cy=\"72\" rx=\"65\" ry=\"38\"/><line class=\"primitive\" x1=\"38\" y1=\"210\" x2=\"148\" y2=\"165\"/><polyline class=\"primitive\" points=\"242 220 268 162 300 217 346 158\"/><polygon class=\"primitive\" points=\"490 154 550 210 490 250 436 207\"/>";let originals=[],converted=[],morphTween=null;
function reset(){morphTween?.kill();primitiveSvg.innerHTML=PRIMITIVES;originals=qa('.primitive');converted=[];q('#morph').disabled=true;q('#convert').disabled=false;q('#inspection').textContent=originals.map(node=>node.tagName).join(' · ');reading('변환 전 · 여섯 기본 요소');}
listen(q('#convert'),'click',()=>{converted=MorphSVGPlugin.convertToPath(originals,q('#swap').checked);q('#convert').disabled=true;q('#morph').disabled=!q('#swap').checked;q('#inspection').textContent=converted.map((node,i)=>originals[i].tagName+' → '+node.tagName+' / 연결: '+node.isConnected+' / d 길이: '+node.getAttribute('d').length).join('\n');reading(q('#swap').checked?'원래 노드는 교체되고 새 경로가 연결되었습니다.':'원래 도형은 유지되고 반환 경로는 분리되어 있습니다.');});
listen(q('#morph'),'click',()=>{if(!converted[0]?.isConnected)return;morphTween?.kill();morphTween=gsap.to(converted[0],{duration:isStatic()?0:1,ease:'power1.inOut',morphSVG:'M92 24 152 72 92 122 30 72Z'});});
listen(q('#reset'),'click',reset);listen(q('#swap'),'change',reset);applyMode=()=>{morphTween?.kill();};studyCleanup.push(()=>morphTween?.kill());reset();
LICENSE실행 안내·자료
파일 저장

Locally authored companion HTML/CSS/control wiring: MIT License.
Copyright (c) 2026 StyleGallery contributors

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

The typed source-inputs.json and study-brief.json preserve official catalog, documentation and original library source pointers. This is independently authored API research, not a recovered CodePen source or documentation snippet. The local MIT notice does not assign new licenses to referenced third-party sources.
GSAP 3.15.0: Copyright 2026, GreenSock. All rights reserved. Subject to https://gsap.com/standard-license. Original library notices are preserved.