import BezierDemo from "@/components/BezierDemo"; import BezierDemoPane from "@/components/BezierDemoPane"; import SubpathDemo from "@/components/SubpathDemo"; import SubpathDemoPane from "@/components/SubpathDemoPane"; import bezierFeatures, { BezierFeatureKey } from "@/features/bezier-features"; import subpathFeatures, { SubpathFeatureKey } from "@/features/subpath-features"; import "@/style.css"; declare global { interface HTMLElementTagNameMap { "bezier-demo": BezierDemo; "bezier-demo-pane": BezierDemoPane; "subpath-demo": SubpathDemo; "subpath-demo-pane": SubpathDemoPane; } } window.document.title = "Bezier-rs Interactive Documentation"; window.document.head.innerHTML += ` `.trim(); window.customElements.define("bezier-demo", BezierDemo); window.customElements.define("bezier-demo-pane", BezierDemoPane); window.customElements.define("subpath-demo", SubpathDemo); window.customElements.define("subpath-demo-pane", SubpathDemoPane); function renderBezierPane(featureName: BezierFeatureKey, container: HTMLElement | null): void { const feature = bezierFeatures[featureName]; const demo = document.createElement("bezier-demo-pane"); demo.setAttribute("name", featureName); demo.setAttribute("demoOptions", JSON.stringify(feature.demoOptions || {})); demo.setAttribute("triggerOnMouseMove", String(feature.triggerOnMouseMove)); container?.append(demo); } function renderSubpathPane(featureName: SubpathFeatureKey, container: HTMLElement | null): void { const feature = subpathFeatures[featureName]; const demo = document.createElement("subpath-demo-pane"); demo.setAttribute("name", featureName); demo.setAttribute("inputOptions", JSON.stringify(feature.inputOptions || [])); demo.setAttribute("triggerOnMouseMove", String(feature.triggerOnMouseMove)); container?.append(demo); } function isUrlSolo(url: string): boolean { const hash = url.split("#")?.[1]; const splitHash = hash?.split("/"); return splitHash?.length === 3 && splitHash?.[2] === "solo"; } window.addEventListener("hashchange", (e: Event): void => { const hashChangeEvent = e as HashChangeEvent; const isOldHashSolo = isUrlSolo(hashChangeEvent.oldURL); const isNewHashSolo = isUrlSolo(hashChangeEvent.newURL); const target = document.getElementById(window.location.hash.substring(1)); // Determine whether the page needs to recompute which examples to show if (!target || isOldHashSolo !== isNewHashSolo) { renderExamples(); } }); function renderExamples(): void { const hash = window.location.hash; const splitHash = hash.split("/"); // Determine which examples to render based on hash if (splitHash[0] === "#bezier" && splitHash[1] in bezierFeatures && splitHash[2] === "solo") { window.document.body.innerHTML = `
`; renderBezierPane(splitHash[1] as BezierFeatureKey, document.getElementById("bezier-demos")); } else if (splitHash[0] === "#subpath" && splitHash[1] in subpathFeatures && splitHash[2] === "solo") { window.document.body.innerHTML = ``; renderSubpathPane(splitHash[1] as SubpathFeatureKey, document.getElementById("subpath-demos")); } else { window.document.body.innerHTML = `This is the interactive documentation for the Bezier-rs library. View the crate documentation for detailed function descriptions and API usage. Click and drag on the endpoints of the demo curves to visualize the various Bezier utilities and functions.