### Automatic Import Transformation Example Source: https://context7.com/haruaki07/phosphor-svelte/llms.txt Illustrates how the `sveltePhosphorOptimize` plugin transforms input imports from a Phosphor-Svelte barrel import into individual deep imports. It also shows examples of imports that are intentionally not transformed. ```javascript // INPUT (your source code — unchanged, easy to read): import { CubeIcon, HeartIcon, HorseIcon, IconContext } from "phosphor-svelte"; import { CubeIcon as MyCube } from "phosphor-svelte"; // aliased import // OUTPUT (emitted by the plugin — never written to disk): import CubeIcon from "phosphor-svelte/lib/CubeIcon"; import HeartIcon from "phosphor-svelte/lib/HeartIcon"; import HorseIcon from "phosphor-svelte/lib/HorseIcon"; import IconContext from "phosphor-svelte/lib/IconContext"; import MyCube from "phosphor-svelte/lib/CubeIcon"; // alias preserved // Files that are NOT transformed (returned as-is): // - /project/node_modules/some-pkg/index.js // - /project/.svelte-kit/generated/client.js // - virtual:__sveltekit/something // - *.css, *.less, *.sass, *.scss, *.styl, *.pcss, *.sss // - *.html, *.htm // - Component.svelte?type=style ``` -------------------------------- ### Install phosphor-svelte with npm Source: https://github.com/haruaki07/phosphor-svelte/blob/main/README.md Use this command to add phosphor-svelte as a development dependency using npm. ```bash npm install --save-dev phosphor-svelte ``` -------------------------------- ### Install phosphor-svelte with Yarn Source: https://github.com/haruaki07/phosphor-svelte/blob/main/README.md Use this command to add phosphor-svelte as a development dependency using Yarn. ```bash yarn add --dev phosphor-svelte ``` -------------------------------- ### Rendering Icons with Default and Custom Props Source: https://context7.com/haruaki07/phosphor-svelte/llms.txt Demonstrates how to import and render Phosphor icons as Svelte components, showcasing default rendering and the use of custom props for color, weight, and size. ```APIDOC ## Rendering an icon with default props Every icon is a Svelte 5 component that renders an accessible `` at `1em` size in `currentColor` with `regular` weight. All standard SVG attributes are forwarded onto the root `` element in addition to the four icon-specific props. ```svelte ``` ``` -------------------------------- ### Using the Mirrored Prop Source: https://context7.com/haruaki07/phosphor-svelte/llms.txt Demonstrates the `mirrored` prop for horizontally flipping an icon, useful for RTL layouts or directional icons. ```APIDOC ### `mirrored` prop — horizontal flip Flips the icon horizontally using `transform="scale(-1, 1)"`. Useful for RTL language support or directional icons like arrows. Defaults to `false`. ```svelte ``` ``` -------------------------------- ### Select Icon Weight with `weight` Prop Source: https://context7.com/haruaki07/phosphor-svelte/llms.txt Demonstrates using the `weight` prop to choose between the six available Phosphor icon styles (thin, light, regular, bold, fill, duotone). Defaults to `regular`. ```svelte ``` -------------------------------- ### Render Icon with Default and Custom Props Source: https://context7.com/haruaki07/phosphor-svelte/llms.txt Demonstrates rendering icons with default properties and overriding them with custom values for color, weight, and size. Standard SVG attributes can also be passed. ```svelte ``` -------------------------------- ### Basic Icon Usage in Svelte Source: https://github.com/haruaki07/phosphor-svelte/blob/main/README.md Import and render icons from the phosphor-svelte library. For faster compilation, import individual icons from 'phosphor-svelte/lib/'. ```html ``` -------------------------------- ### Set Icon Size with `size` Prop Source: https://context7.com/haruaki07/phosphor-svelte/llms.txt Shows how to control the width and height of an icon using the `size` prop. It accepts pixel values, CSS units, or percentages, defaulting to `1em`. ```svelte ``` -------------------------------- ### Configure Vite with sveltePhosphorOptimize Plugin Source: https://context7.com/haruaki07/phosphor-svelte/llms.txt Integrate the `sveltePhosphorOptimize` plugin into your Vite configuration to automatically optimize Phosphor icon imports. This plugin rewrites barrel imports into deep imports during the build process, improving performance without manual code changes. ```javascript import { sveltekit } from "@sveltejs/kit/vite"; import { defineConfig } from "vite"; import { sveltePhosphorOptimize } from "phosphor-svelte/vite"; export default defineConfig({ plugins: [sveltekit(), sveltePhosphorOptimize()], }); ``` -------------------------------- ### Customizing Icon Color Source: https://context7.com/haruaki07/phosphor-svelte/llms.txt Explains how to use the `color` prop to set the stroke and fill color of an icon, accepting any valid CSS color string. ```APIDOC ### `color` prop — stroke and fill color Accepts any CSS color string. Defaults to `"currentColor"`, which inherits the surrounding text color automatically. Can be overridden per-icon or set globally via `IconContext`. ```svelte ``` ``` -------------------------------- ### Generate Index Files with definitionsTemplate and moduleTemplate Source: https://context7.com/haruaki07/phosphor-svelte/llms.txt Use definitionsTemplate and moduleTemplate to generate the lib/index.d.ts and lib/index.js barrel exports respectively. These functions export all icons with preferred and deprecated identifiers, along with IconContext and shared types. ```javascript import { definitionsTemplate, moduleTemplate } from "./scripts/template.js"; const components = [ { name: "Minus", nameWithIcon: "MinusIcon" }, { name: "Plus", nameWithIcon: "PlusIcon" }, ]; console.log(definitionsTemplate(components)); // export { default as IconContext } from "./IconContext.svelte"; // export { default as MinusIcon } from "./MinusIcon.svelte"; // export { default as Minus } from "./Minus.svelte"; // export { default as PlusIcon } from "./PlusIcon.svelte"; // export { default as Plus } from "./Plus.svelte"; // export type * from "./shared.d.ts"; console.log(moduleTemplate(components)); // export { default as IconContext } from './IconContext.svelte'; // export { default as MinusIcon } from './MinusIcon.svelte'; // export { default as Minus } from './Minus.svelte'; // export { default as PlusIcon } from './PlusIcon.svelte'; // export { default as Plus } from './Plus.svelte'; ``` -------------------------------- ### Customizing Icon Size Source: https://context7.com/haruaki07/phosphor-svelte/llms.txt Details the `size` prop for controlling the width and height of an icon, accepting numbers (pixels) or CSS unit strings. ```APIDOC ### `size` prop — width and height Sets both the `width` and `height` attributes of the SVG. Accepts a number (treated as pixels) or any CSS unit string. Defaults to `"1em"`. ```svelte ``` ``` -------------------------------- ### Configure Vite for Phosphor Svelte Optimization Source: https://github.com/haruaki07/phosphor-svelte/blob/main/README.md Add the sveltePhosphorOptimize plugin to your vite.config.ts file to enable import optimization for phosphor-svelte. ```javascript // vite.config.ts import { sveltekit } from "@sveltejs/kit/vite"; import { defineConfig } from "vite"; import { sveltePhosphorOptimize } from "phosphor-svelte/vite"; export default defineConfig({ plugins: [sveltekit(), sveltePhosphorOptimize()], }); ``` -------------------------------- ### Internal setIconContext and getIconContext Utilities Source: https://context7.com/haruaki07/phosphor-svelte/llms.txt These low-level utilities manage the Svelte context for icon defaults. `setIconContext` writes defaults, and `getIconContext` safely reads them, providing a fallback empty object if no context is present. This ensures icons always have a safe default. ```javascript // src/lib/context.js — usage inside a custom wrapper component import { setIconContext, getIconContext } from "phosphor-svelte/lib/context"; // In a custom provider component: // setIconContext({ color: "blue", size: 20, weight: "light" }); // In a custom consumer (e.g., a custom icon wrapper): const ctx = getIconContext(); // ctx => { color: "blue", size: 20, weight: "light" } // If no IconContext ancestor exists: // ctx => {} // Precedence chain inside every generated icon component: // let weight = $derived(props.weight ?? ctx.weight ?? "regular"); // let color = $derived(props.color ?? ctx.color ?? "currentColor"); // let size = $derived(props.size ?? ctx.size ?? "1em"); ``` -------------------------------- ### Set Icon Color with `color` Prop Source: https://context7.com/haruaki07/phosphor-svelte/llms.txt Illustrates how to set the stroke and fill color of an icon using the `color` prop. It accepts various CSS color formats and defaults to `currentColor`. ```svelte ``` -------------------------------- ### Customizing Icon Weight Source: https://context7.com/haruaki07/phosphor-svelte/llms.txt Explains the `weight` prop for selecting one of the six Phosphor icon style variants (thin, light, regular, bold, fill, duotone). ```APIDOC ### `weight` prop — icon style variant Selects which of the six Phosphor weight variants to render. Defaults to `"regular"`. Passing an unsupported value logs a console error and renders nothing inside the SVG. ```svelte ``` ``` -------------------------------- ### Optimize Imports with Vite Plugin Source: https://github.com/haruaki07/phosphor-svelte/blob/main/README.md This diff shows how to change named imports to default imports using the svelte-phosphor-optimize Vite plugin, which can improve compile times. ```diff ``` -------------------------------- ### Applying Default Styles with IconContext Source: https://github.com/haruaki07/phosphor-svelte/blob/main/README.md Use IconContext to apply default props like color, size, and weight to all icons within its scope. Individual icon props will override context values. ```html ``` -------------------------------- ### Flip Icon Horizontally with `mirrored` Prop Source: https://context7.com/haruaki07/phosphor-svelte/llms.txt Explains the use of the `mirrored` prop to horizontally flip an icon, which is useful for Right-to-Left (RTL) language support or directional indicators. Defaults to `false`. ```svelte ``` -------------------------------- ### Generate Svelte Icon Components Source: https://context7.com/haruaki07/phosphor-svelte/llms.txt Use the `generateComponents` function to create Svelte component files (`.svelte`) and their type definitions (`.d.ts`) for each weight variant of a Phosphor icon. This function reads raw SVG path data and generates both preferred and deprecated component formats. ```javascript // scripts/build.js import { generateComponents } from "./scripts/build.js"; // Generates: lib/CircleIcon.svelte, lib/CircleIcon.svelte.d.ts // lib/Circle.svelte (deprecated), lib/Circle.svelte.d.ts const result = await generateComponents("circle.svg", [ "regular", "thin", "light", "bold", "fill", "duotone" ]); // result => // { // iconName: "circle.svg", // name: "Circle", // nameWithIcon: "CircleIcon", // weights: [ // { weight: "regular", svgPath: ' ✔ 1248 components generated ``` -------------------------------- ### Generate Svelte Component Source Code Source: https://context7.com/haruaki07/phosphor-svelte/llms.txt The `componentTemplate` function generates the complete source code for a Svelte icon component. It uses Svelte 5 runes and conditional rendering (`{#if}` blocks) for different icon weights, integrating `getIconContext` for context-based defaults. ```javascript import { componentTemplate } from "./scripts/template.js"; const iconWeights = [ { weight: "regular", svgPath: ` // // // {#if weight === "regular"} {:else if weight === "bold"} ... {/if} // ``` -------------------------------- ### IconContext Component for Default Props Source: https://context7.com/haruaki07/phosphor-svelte/llms.txt Apply default props to all descendant icons using the IconContext component. Per-icon props override context values, which in turn override built-in defaults. Nest multiple IconContext providers for scoped overrides. ```svelte ``` -------------------------------- ### Compositing Icons with SVG Elements Source: https://github.com/haruaki07/phosphor-svelte/blob/main/README.md Enhance icons by adding arbitrary SVG elements as children. These children are rendered below the icon's main content and can be used for animations or effects. ```html ``` -------------------------------- ### Composable SVG Content with Children Slot Source: https://context7.com/haruaki07/phosphor-svelte/llms.txt Use the children slot to render arbitrary SVG elements inside an icon. This enables animations, filters, masks, and custom overlays within the icon's coordinate space. Ensure child SVG elements are compatible with the icon's viewBox. ```svelte ``` -------------------------------- ### Phosphor-Svelte TypeScript Types Source: https://context7.com/haruaki07/phosphor-svelte/llms.txt Import and utilize various icon-related TypeScript types from 'phosphor-svelte'. IconComponentProps extends Svelte's SVGAttributes, allowing standard SVG attributes in addition to icon-specific props. ```typescript import type { IconWeight, IconBaseProps, IconComponentProps, IconContextProps, } from "phosphor-svelte"; // IconWeight — the six valid weight strings const w: IconWeight = "duotone"; // "thin"|"light"|"regular"|"bold"|"fill"|"duotone" // IconBaseProps — only the four icon-specific props const base: IconBaseProps = { color: "#ff0000", // string, default "currentColor" size: "1.5rem", // number | string, default "1em" weight: "fill", // IconWeight, default "regular" mirrored: false, // boolean, default false }; // IconComponentProps — icon props + all SVG element attributes const full: IconComponentProps = { ...base, "aria-label": "Heart icon", role: "img", class: "icon icon--heart", tabindex: 0, }; // IconContextProps — props accepted by const ctx: IconContextProps = { values: { color: "steelblue", size: 20, weight: "bold" }, // children is a Svelte Snippet }; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.