From 19d9cf01e7840d29b02dce4049729cb529557fe5 Mon Sep 17 00:00:00 2001 From: Gromov Sergei <46241127+gromlab-ru@users.noreply.github.com> Date: Mon, 17 Aug 2026 09:43:40 +0300 Subject: [PATCH] =?UTF-8?q?feat(skills):=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D1=82=D1=8C=20=D1=83=D1=81=D1=82=D0=B0=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=BA=D1=83=20=D1=87=D0=B5=D1=80=D0=B5=D0=B7=20npx=20skills=20?= =?UTF-8?q?add?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release.yml | 6 +- .gitignore | 1 - README.md | 12 +- README_RU.md | 12 +- package-lock.json | 4 +- package.json | 6 +- skills/svg-sprites-ru/SKILL.md | 359 +++++++++ skills/svg-sprites-ru/references/README_RU.md | 303 ++++++++ .../references/complex-svg.md | 0 .../references/docs/ru/README.md | 56 ++ .../references/docs/ru/configuration.md | 139 ++++ .../references/docs/ru/guides/alpine-vite.md | 91 +++ .../docs/ru/guides/alpine-webpack.md | 103 +++ .../docs/ru/guides/angular-application.md | 94 +++ .../docs/ru/guides/angular-webpack.md | 93 +++ .../references/docs/ru/guides/astro-vite.md | 92 +++ .../references/docs/ru/guides/lit-vite.md | 86 +++ .../references/docs/ru/guides/lit-webpack.md | 98 +++ .../docs/ru/guides/next-app-turbopack.md | 108 +++ .../docs/ru/guides/next-app-webpack.md | 108 +++ .../docs/ru/guides/next-pages-turbopack.md | 98 +++ .../docs/ru/guides/next-pages-webpack.md | 98 +++ .../references/docs/ru/guides/nuxt-vite.md | 100 +++ .../references/docs/ru/guides/nuxt-webpack.md | 113 +++ .../references/docs/ru/guides/preact-vite.md | 75 ++ .../docs/ru/guides/preact-webpack.md | 75 ++ .../references/docs/ru/guides/qwik-vite.md | 82 ++ .../references/docs/ru/guides/react-vite.md | 115 +++ .../docs/ru/guides/react-webpack.md | 132 ++++ .../docs/ru/guides/solid-start-vite.md | 83 ++ .../references/docs/ru/guides/solid-vite.md | 83 ++ .../docs/ru/guides/solid-webpack.md | 75 ++ .../docs/ru/guides/standalone-server.md | 113 +++ .../docs/ru/guides/standalone-vite.md | 114 +++ .../docs/ru/guides/standalone-webpack.md | 111 +++ .../references/docs/ru/guides/standalone.md | 83 ++ .../references/docs/ru/guides/svelte-vite.md | 95 +++ .../docs/ru/guides/svelte-webpack.md | 105 +++ .../docs/ru/guides/sveltekit-vite.md | 91 +++ .../references/docs/ru/guides/vue-vite.md | 105 +++ .../references/docs/ru/guides/vue-webpack.md | 126 +++ .../docs/ru/reference/programmatic-api.md | 183 +++++ .../references/docs/ru/reference/technical.md | 716 +++++++++++++++++ skills/svg-sprites/SKILL.md | 359 +++++++++ skills/svg-sprites/references/README.md | 303 ++++++++ .../{src/en => }/references/complex-svg.md | 0 .../svg-sprites/references/docs/en/README.md | 56 ++ .../references/docs/en/configuration.md | 139 ++++ .../references/docs/en/guides/alpine-vite.md | 91 +++ .../docs/en/guides/alpine-webpack.md | 103 +++ .../docs/en/guides/angular-application.md | 94 +++ .../docs/en/guides/angular-webpack.md | 93 +++ .../references/docs/en/guides/astro-vite.md | 92 +++ .../references/docs/en/guides/lit-vite.md | 86 +++ .../references/docs/en/guides/lit-webpack.md | 98 +++ .../docs/en/guides/next-app-turbopack.md | 108 +++ .../docs/en/guides/next-app-webpack.md | 108 +++ .../docs/en/guides/next-pages-turbopack.md | 98 +++ .../docs/en/guides/next-pages-webpack.md | 98 +++ .../references/docs/en/guides/nuxt-vite.md | 100 +++ .../references/docs/en/guides/nuxt-webpack.md | 113 +++ .../references/docs/en/guides/preact-vite.md | 75 ++ .../docs/en/guides/preact-webpack.md | 75 ++ .../references/docs/en/guides/qwik-vite.md | 82 ++ .../references/docs/en/guides/react-vite.md | 115 +++ .../docs/en/guides/react-webpack.md | 132 ++++ .../docs/en/guides/solid-start-vite.md | 83 ++ .../references/docs/en/guides/solid-vite.md | 83 ++ .../docs/en/guides/solid-webpack.md | 75 ++ .../docs/en/guides/standalone-server.md | 113 +++ .../docs/en/guides/standalone-vite.md | 114 +++ .../docs/en/guides/standalone-webpack.md | 111 +++ .../references/docs/en/guides/standalone.md | 83 ++ .../references/docs/en/guides/svelte-vite.md | 95 +++ .../docs/en/guides/svelte-webpack.md | 105 +++ .../docs/en/guides/sveltekit-vite.md | 91 +++ .../references/docs/en/guides/vue-vite.md | 105 +++ .../references/docs/en/guides/vue-webpack.md | 126 +++ .../docs/en/reference/programmatic-api.md | 191 +++++ .../references/docs/en/reference/technical.md | 717 ++++++++++++++++++ {skills => src/skills}/README.md | 6 +- {skills => src/skills}/svg-sprites/build.mjs | 80 +- .../skills}/svg-sprites/skill.config.mjs | 12 +- .../skills}/svg-sprites/src/en/SKILL.md | 0 .../src/en/references/complex-svg.md | 176 +++++ .../skills}/svg-sprites/src/ru/SKILL.md | 0 .../src/ru/references/complex-svg.md | 176 +++++ 87 files changed, 9864 insertions(+), 38 deletions(-) create mode 100644 skills/svg-sprites-ru/SKILL.md create mode 100644 skills/svg-sprites-ru/references/README_RU.md rename skills/{svg-sprites/src/ru => svg-sprites-ru}/references/complex-svg.md (100%) create mode 100644 skills/svg-sprites-ru/references/docs/ru/README.md create mode 100644 skills/svg-sprites-ru/references/docs/ru/configuration.md create mode 100644 skills/svg-sprites-ru/references/docs/ru/guides/alpine-vite.md create mode 100644 skills/svg-sprites-ru/references/docs/ru/guides/alpine-webpack.md create mode 100644 skills/svg-sprites-ru/references/docs/ru/guides/angular-application.md create mode 100644 skills/svg-sprites-ru/references/docs/ru/guides/angular-webpack.md create mode 100644 skills/svg-sprites-ru/references/docs/ru/guides/astro-vite.md create mode 100644 skills/svg-sprites-ru/references/docs/ru/guides/lit-vite.md create mode 100644 skills/svg-sprites-ru/references/docs/ru/guides/lit-webpack.md create mode 100644 skills/svg-sprites-ru/references/docs/ru/guides/next-app-turbopack.md create mode 100644 skills/svg-sprites-ru/references/docs/ru/guides/next-app-webpack.md create mode 100644 skills/svg-sprites-ru/references/docs/ru/guides/next-pages-turbopack.md create mode 100644 skills/svg-sprites-ru/references/docs/ru/guides/next-pages-webpack.md create mode 100644 skills/svg-sprites-ru/references/docs/ru/guides/nuxt-vite.md create mode 100644 skills/svg-sprites-ru/references/docs/ru/guides/nuxt-webpack.md create mode 100644 skills/svg-sprites-ru/references/docs/ru/guides/preact-vite.md create mode 100644 skills/svg-sprites-ru/references/docs/ru/guides/preact-webpack.md create mode 100644 skills/svg-sprites-ru/references/docs/ru/guides/qwik-vite.md create mode 100644 skills/svg-sprites-ru/references/docs/ru/guides/react-vite.md create mode 100644 skills/svg-sprites-ru/references/docs/ru/guides/react-webpack.md create mode 100644 skills/svg-sprites-ru/references/docs/ru/guides/solid-start-vite.md create mode 100644 skills/svg-sprites-ru/references/docs/ru/guides/solid-vite.md create mode 100644 skills/svg-sprites-ru/references/docs/ru/guides/solid-webpack.md create mode 100644 skills/svg-sprites-ru/references/docs/ru/guides/standalone-server.md create mode 100644 skills/svg-sprites-ru/references/docs/ru/guides/standalone-vite.md create mode 100644 skills/svg-sprites-ru/references/docs/ru/guides/standalone-webpack.md create mode 100644 skills/svg-sprites-ru/references/docs/ru/guides/standalone.md create mode 100644 skills/svg-sprites-ru/references/docs/ru/guides/svelte-vite.md create mode 100644 skills/svg-sprites-ru/references/docs/ru/guides/svelte-webpack.md create mode 100644 skills/svg-sprites-ru/references/docs/ru/guides/sveltekit-vite.md create mode 100644 skills/svg-sprites-ru/references/docs/ru/guides/vue-vite.md create mode 100644 skills/svg-sprites-ru/references/docs/ru/guides/vue-webpack.md create mode 100644 skills/svg-sprites-ru/references/docs/ru/reference/programmatic-api.md create mode 100644 skills/svg-sprites-ru/references/docs/ru/reference/technical.md create mode 100644 skills/svg-sprites/SKILL.md create mode 100644 skills/svg-sprites/references/README.md rename skills/svg-sprites/{src/en => }/references/complex-svg.md (100%) create mode 100644 skills/svg-sprites/references/docs/en/README.md create mode 100644 skills/svg-sprites/references/docs/en/configuration.md create mode 100644 skills/svg-sprites/references/docs/en/guides/alpine-vite.md create mode 100644 skills/svg-sprites/references/docs/en/guides/alpine-webpack.md create mode 100644 skills/svg-sprites/references/docs/en/guides/angular-application.md create mode 100644 skills/svg-sprites/references/docs/en/guides/angular-webpack.md create mode 100644 skills/svg-sprites/references/docs/en/guides/astro-vite.md create mode 100644 skills/svg-sprites/references/docs/en/guides/lit-vite.md create mode 100644 skills/svg-sprites/references/docs/en/guides/lit-webpack.md create mode 100644 skills/svg-sprites/references/docs/en/guides/next-app-turbopack.md create mode 100644 skills/svg-sprites/references/docs/en/guides/next-app-webpack.md create mode 100644 skills/svg-sprites/references/docs/en/guides/next-pages-turbopack.md create mode 100644 skills/svg-sprites/references/docs/en/guides/next-pages-webpack.md create mode 100644 skills/svg-sprites/references/docs/en/guides/nuxt-vite.md create mode 100644 skills/svg-sprites/references/docs/en/guides/nuxt-webpack.md create mode 100644 skills/svg-sprites/references/docs/en/guides/preact-vite.md create mode 100644 skills/svg-sprites/references/docs/en/guides/preact-webpack.md create mode 100644 skills/svg-sprites/references/docs/en/guides/qwik-vite.md create mode 100644 skills/svg-sprites/references/docs/en/guides/react-vite.md create mode 100644 skills/svg-sprites/references/docs/en/guides/react-webpack.md create mode 100644 skills/svg-sprites/references/docs/en/guides/solid-start-vite.md create mode 100644 skills/svg-sprites/references/docs/en/guides/solid-vite.md create mode 100644 skills/svg-sprites/references/docs/en/guides/solid-webpack.md create mode 100644 skills/svg-sprites/references/docs/en/guides/standalone-server.md create mode 100644 skills/svg-sprites/references/docs/en/guides/standalone-vite.md create mode 100644 skills/svg-sprites/references/docs/en/guides/standalone-webpack.md create mode 100644 skills/svg-sprites/references/docs/en/guides/standalone.md create mode 100644 skills/svg-sprites/references/docs/en/guides/svelte-vite.md create mode 100644 skills/svg-sprites/references/docs/en/guides/svelte-webpack.md create mode 100644 skills/svg-sprites/references/docs/en/guides/sveltekit-vite.md create mode 100644 skills/svg-sprites/references/docs/en/guides/vue-vite.md create mode 100644 skills/svg-sprites/references/docs/en/guides/vue-webpack.md create mode 100644 skills/svg-sprites/references/docs/en/reference/programmatic-api.md create mode 100644 skills/svg-sprites/references/docs/en/reference/technical.md rename {skills => src/skills}/README.md (59%) rename {skills => src/skills}/svg-sprites/build.mjs (82%) rename {skills => src/skills}/svg-sprites/skill.config.mjs (89%) rename {skills => src/skills}/svg-sprites/src/en/SKILL.md (100%) create mode 100644 src/skills/svg-sprites/src/en/references/complex-svg.md rename {skills => src/skills}/svg-sprites/src/ru/SKILL.md (100%) create mode 100644 src/skills/svg-sprites/src/ru/references/complex-svg.md diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a59956a..045124e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -78,10 +78,10 @@ jobs: run: npm pack --ignore-scripts --pack-destination release - name: Pack skills - working-directory: skills/artifacts + working-directory: skills run: | - zip -r ../../release/svg-sprites.zip svg-sprites - zip -r ../../release/svg-sprites-ru.zip svg-sprites-ru + zip -r ../release/svg-sprites.zip svg-sprites + zip -r ../release/svg-sprites-ru.zip svg-sprites-ru - name: Create checksums run: sha256sum release/* > release/SHA256SUMS diff --git a/.gitignore b/.gitignore index 1f2c7c6..71ee07a 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,6 @@ test/public/ test/.next-fixture-*/ test-results/ .tmp/ -skills/artifacts/ *.generated.ts *.tgz .DS_Store diff --git a/README.md b/README.md index c666323..2fa7949 100644 --- a/README.md +++ b/README.md @@ -28,9 +28,17 @@ You do not have to work with the sprite directly in your application. Use it lik `@gromlab/svg-sprites` is designed to work with AI agents from the start. Add the ready-made skill and ask an agent to configure, migrate, or troubleshoot the package without lengthy instructions or manual documentation research. -[πŸ‡¬πŸ‡§ Download AI skill (English)](https://github.com/gromlab-ru/svg-sprites/releases/latest/download/svg-sprites.zip) +Install the English skill: -[πŸ‡·πŸ‡Ί Download AI skill (Russian)](https://github.com/gromlab-ru/svg-sprites/releases/latest/download/svg-sprites-ru.zip) +```bash +npx skills add gromlab-ru/svg-sprites --skill svg-sprites +``` + +Install the Russian skill: + +```bash +npx skills add gromlab-ru/svg-sprites --skill svg-sprites-ru +``` ## From SVG to component in three steps diff --git a/README_RU.md b/README_RU.md index b0eb0ea..5c2b0f3 100644 --- a/README_RU.md +++ b/README_RU.md @@ -28,9 +28,17 @@ `@gromlab/svg-sprites` сразу рассчитан Π½Π° Ρ€Π°Π±ΠΎΡ‚Ρƒ с AI-Π°Π³Π΅Π½Ρ‚Π°ΠΌΠΈ. ΠŸΠΎΠ΄ΠΊΠ»ΡŽΡ‡ΠΈΡ‚Π΅ Π³ΠΎΡ‚ΠΎΠ²Ρ‹ΠΉ skill ΠΈ ΠΏΠΎΡ€ΡƒΡ‡ΠΈΡ‚Π΅ Π°Π³Π΅Π½Ρ‚Ρƒ настройку, ΠΌΠΈΠ³Ρ€Π°Ρ†ΠΈΡŽ ΠΈΠ»ΠΈ диагностику Π±Π΅Π· Π΄Π»ΠΈΠ½Π½Ρ‹Ρ… инструкций ΠΈ Ρ€ΡƒΡ‡Π½ΠΎΠ³ΠΎ изучСния Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚Π°Ρ†ΠΈΠΈ. -[πŸ‡·πŸ‡Ί Π‘ΠΊΠ°Ρ‡Π°Ρ‚ΡŒ AI skill (Π½Π° русском)](https://github.com/gromlab-ru/svg-sprites/releases/latest/download/svg-sprites-ru.zip) +Π£ΡΡ‚Π°Π½ΠΎΠ²ΠΈΡ‚ΡŒ русскоязычный skill: -[πŸ‡¬πŸ‡§ Π‘ΠΊΠ°Ρ‡Π°Ρ‚ΡŒ AI skill (Π½Π° английском)](https://github.com/gromlab-ru/svg-sprites/releases/latest/download/svg-sprites.zip) +```bash +npx skills add gromlab-ru/svg-sprites --skill svg-sprites-ru +``` + +Π£ΡΡ‚Π°Π½ΠΎΠ²ΠΈΡ‚ΡŒ англоязычный skill: + +```bash +npx skills add gromlab-ru/svg-sprites --skill svg-sprites +``` ## ΠžΡ‚ SVG Π΄ΠΎ ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚Π° Π·Π° Ρ‚Ρ€ΠΈ шага diff --git a/package-lock.json b/package-lock.json index 1fc0887..baea5d8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@gromlab/svg-sprites", - "version": "2.1.0", + "version": "2.1.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@gromlab/svg-sprites", - "version": "2.1.0", + "version": "2.1.1", "license": "MIT", "dependencies": { "colorette": "^2.0.20", diff --git a/package.json b/package.json index 5bccf8a..7a2eb3e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@gromlab/svg-sprites", - "version": "2.1.0", + "version": "2.1.1", "description": "Generate external SVG sprites and typed native icon components for modern web frameworks", "type": "module", "main": "./dist/index.js", @@ -57,8 +57,8 @@ "scripts": { "build": "npm run build:package", "build:package": "tsup && tsup --config tsup.browser.config.ts && tsup --config tsup.viewer.config.ts", - "build:skill": "node skills/svg-sprites/build.mjs", - "check:skill": "node skills/svg-sprites/build.mjs --check", + "build:skill": "node src/skills/svg-sprites/build.mjs", + "check:skill": "node src/skills/svg-sprites/build.mjs --check", "dev": "tsup --watch", "test": "npm run build:package && node --test test/*.test.mjs", "typecheck": "tsc --noEmit", diff --git a/skills/svg-sprites-ru/SKILL.md b/skills/svg-sprites-ru/SKILL.md new file mode 100644 index 0000000..19be497 --- /dev/null +++ b/skills/svg-sprites-ru/SKILL.md @@ -0,0 +1,359 @@ +--- +name: svg-sprites-ru +description: "Π˜ΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ ΠΏΡ€ΠΈ настройкС, ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΠΈ ΠΈΠ»ΠΈ диагностикС @gromlab/svg-sprites. Π’Ρ€ΠΈΠ³Π³Π΅Ρ€Ρ‹: @gromlab/svg-sprites, svg-sprite.config.json, defineSpriteConfig, generateSprite, standalone@server, source: remote, ServerSvgInput, exact modes для standalone, React, Next.js, Vue, Nuxt, Svelte, Angular, Astro, Solid, Preact, Qwik, Lit ΠΈΠ»ΠΈ Alpine.js, SpriteConfig.input, --input, SpriteViewer ΠΈ --icon-color-N. НЕ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉ для самописных SVG-спрайтов, inline SVG, favicon, растровых ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠΉ, icon fonts ΠΈΠ»ΠΈ Π²Ρ‹Π±ΠΎΡ€Π° Π±ΠΈΠ±Π»ΠΈΠΎΡ‚Π΅ΠΊΠΈ ΠΈΠΊΠΎΠ½ΠΎΠΊ." +--- + + + +# @gromlab/svg-sprites + +## Π§Ρ‚ΠΎ Π΄Π΅Π»Π°Π΅Ρ‚ ΠΏΠ°ΠΊΠ΅Ρ‚ + +`@gromlab/svg-sprites` β€” CLI-Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ SVG-спрайтов для ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒΡΠΊΠΈΡ… SVG-Ρ„Π°ΠΉΠ»ΠΎΠ². ΠŸΠ°ΠΊΠ΅Ρ‚ Π½Π΅ содСрТит собствСнного Π½Π°Π±ΠΎΡ€Π° ΠΈΠΊΠΎΠ½ΠΎΠΊ: ΠΎΠ½ собираСт SVG ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π° Π²ΠΎ внСшний sprite asset ΠΈ создаёт Ρ‚ΠΈΠΏΠΈΠ·ΠΈΡ€ΠΎΠ²Π°Π½Π½Ρ‹ΠΉ Π½Π°Ρ‚ΠΈΠ²Π½Ρ‹ΠΉ ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ для Π²Ρ‹Π±Ρ€Π°Π½Π½ΠΎΠ³ΠΎ exact framework/bundler mode. + +ΠŸΠ°ΠΊΠ΅Ρ‚ рассчитан Π½Π° нСсколько нСзависимых спрайтов Π² ΠΎΠ΄Π½ΠΎΠΌ ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π΅. ΠšΠ°ΠΆΠ΄Ρ‹ΠΉ явно Π²Ρ‹Π±Ρ€Π°Π½Π½Ρ‹ΠΉ config-Ρ„Π°ΠΉΠ» ΠΈΠ»ΠΈ config-less ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ описываСт ΠΎΠ΄ΠΈΠ½ спрайт ΠΈ ΠΏΠΎΠ»ΡƒΡ‡Π°Π΅Ρ‚ собствСнныС: + +- SVG asset; +- mode-specific manifest data; +- для всСх modes, ΠΊΡ€ΠΎΠΌΠ΅ bare `standalone`, β€” Ρ‚ΠΈΠΏΡ‹ ΠΈΠΌΡ‘Π½ ΠΈ production entry `.svg-sprite/index.js`; +- для framework modes β€” ΠΈΠ·ΠΎΠ»ΠΈΡ€ΠΎΠ²Π°Π½Π½Ρ‹ΠΉ Π½Π°Ρ‚ΠΈΠ²Π½Ρ‹ΠΉ ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ ΠΈ declarations; +- для `standalone@vite`/`standalone@webpack` β€” Π½Π°Ρ‚ΠΈΠ²Π½Ρ‹ΠΉ Web Component с явной Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠ΅ΠΉ рСгистрации; +- для bare `standalone` β€” deployment-neutral JSON manifest Π±Π΅Π· ΠΏΡƒΠ±Π»ΠΈΡ‡Π½ΠΎΠ³ΠΎ URL. +- для `standalone@server` β€” content-addressed server release с двумя compile profiles ΠΈ integrity manifest. + +ΠšΠΎΠ»ΠΈΡ‡Π΅ΡΡ‚Π²ΠΎ ΠΈ располоТСниС ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ΠΎΠ² опрСдСляСт ΠΏΡ€ΠΎΠ΅ΠΊΡ‚. НапримСр, `name: 'file-manager'` создаёт `FileManagerIcon`, `FileManagerIconName` ΠΈ `fileManagerIconNames`, Π° Π΄Ρ€ΡƒΠ³ΠΎΠΉ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ с `name: 'navigation'` создаст ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½Ρ‹ΠΉ `NavigationIcon`. Π­Ρ‚ΠΎ ΠΏΡ€ΠΈΠΌΠ΅Ρ€Ρ‹ API ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½Ρ‹Ρ… спрайтов, Π° Π½Π΅ фиксированныС экспорты ΠΏΠ°ΠΊΠ΅Ρ‚Π°. + +Generated production runtime ΠΈ declarations Π½Π΅ ΠΈΠΌΠΏΠΎΡ€Ρ‚ΠΈΡ€ΡƒΡŽΡ‚ `@gromlab/svg-sprites`. ГСнСрация Ρ‡Π΅Ρ€Π΅Π· `npx --yes @gromlab/svg-sprites ` Π½Π΅ добавляСт package Π² ΠΏΡ€ΠΎΠ΅ΠΊΡ‚. Устанавливай Π΅Π³ΠΎ ΠΊΠ°ΠΊ development dependency Ρ‚ΠΎΠ»ΡŒΠΊΠΎ для Viewer, package-Ρ‚ΠΈΠΏΠΎΠ² config ΠΈΠ»ΠΈ ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ API. + +Π›ΡŽΠ±ΠΎΠΉ consumer exact mode ΠΌΠΎΠΆΠ΅Ρ‚ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ `source: 'remote'` с ΠΎΠ΄Π½ΠΈΠΌ local path +ΠΈΠ»ΠΈ HTTP(S) URL manifest, созданного `standalone@server`. Π”ΠΎ запуска adapter Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ +скачиваСт ΠΈ провСряСт Π½ΡƒΠΆΠ½Ρ‹ΠΉ profile, послС Ρ‡Π΅Π³ΠΎ создаётся ΠΎΠ±Ρ‹Ρ‡Π½Ρ‹ΠΉ Π»ΠΎΠΊΠ°Π»ΡŒΠ½Ρ‹ΠΉ API ΠΈ +asset; Π² runtime Π±Ρ€Π°ΡƒΠ·Π΅Ρ€ Π½Π΅ зависит ΠΎΡ‚ server manifest. + +## Π’Ρ‹Π±ΠΎΡ€ Ρ€Π΅ΠΆΠΈΠΌΠ° + +Π’Ρ‹Π±Π΅Ρ€ΠΈ Ρ€ΠΎΠ²Π½ΠΎ ΠΎΠ΄ΠΈΠ½ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΈΠ²Π°Π΅ΠΌΡ‹ΠΉ mode key: + +| ΠŸΡ€ΠΎΠ΅ΠΊΡ‚ | Mode key | +|---|---| +| Static HTML / собствСнная публикация | `standalone` | +| Standalone + Vite | `standalone@vite` | +| Standalone + Webpack 5 | `standalone@webpack` | +| Server ΠΈΠ»ΠΈ CI release | `standalone@server` | +| React + Vite | `react@vite` | +| React + Webpack 5 | `react@webpack` | +| Vue + Vite | `vue@vite` | +| Vue + Webpack | `vue@webpack` | +| Nuxt + Vite | `nuxt@vite` | +| Nuxt + Webpack | `nuxt@webpack` | +| Svelte + Vite | `svelte@vite` | +| Svelte + Webpack | `svelte@webpack` | +| SvelteKit + Vite | `sveltekit@vite` | +| Angular application builder | `angular@application` | +| Angular + Webpack | `angular@webpack` | +| Astro + Vite | `astro@vite` | +| Solid + Vite | `solid@vite` | +| Solid + Webpack | `solid@webpack` | +| SolidStart + Vite | `solid-start@vite` | +| Preact + Vite | `preact@vite` | +| Preact + Webpack | `preact@webpack` | +| Qwik + Vite | `qwik@vite` | +| Lit + Vite | `lit@vite` | +| Lit + Webpack | `lit@webpack` | +| Alpine.js + Vite | `alpine@vite` | +| Alpine.js + Webpack | `alpine@webpack` | +| Next.js App Router + Turbopack | `next@app/turbopack` | +| Next.js App Router + Webpack 5 | `next@app/webpack` | +| Next.js Pages Router + Turbopack | `next@pages/turbopack` | +| Next.js Pages Router + Webpack 5 | `next@pages/webpack` | + +Mode задаётся Π² config, CLI ΠΈΠ»ΠΈ ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠΌ API. ΠŸΠΎΡ€ΡΠ΄ΠΎΠΊ примСнСния: `defaults β†’ config β†’ CLI/API overrides`. ПослС объСдинСния mode обязатСлСн. + +`name` нСобязатСлСн. Если ΠΎΠ½ Π½Π΅ Π·Π°Π΄Π°Π½, Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ ΠΏΡ€Π΅ΠΎΠ±Ρ€Π°Π·ΡƒΠ΅Ρ‚ имя ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³Π° sprite-модуля Π² kebab-case; для ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ΠΎΠ² `svg-sprite` ΠΈ `svg-sprites` ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ имя Ρ€ΠΎΠ΄ΠΈΡ‚Π΅Π»ΡŒΡΠΊΠΎΠ³ΠΎ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³Π°. Π―Π²Π½ΠΎΠ΅ `name` Π΄ΠΎΠ»ΠΆΠ½ΠΎ ΡƒΠΆΠ΅ Π±Ρ‹Ρ‚ΡŒ записано Π² kebab-case ΠΈ Π½Π°Ρ‡ΠΈΠ½Π°Ρ‚ΡŒΡΡ с латинской Π±ΡƒΠΊΠ²Ρ‹. + +CLI ΠΏΡ€ΠΈΠ½ΠΈΠΌΠ°Π΅Ρ‚ Ρ€ΠΎΠ²Π½ΠΎ ΠΎΠ΄ΠΈΠ½ ΠΏΡƒΡ‚ΡŒ. ΠŸΡƒΡ‚ΡŒ ΠΊ Ρ„Π°ΠΉΠ»Ρƒ `.ts`, `.js` ΠΈΠ»ΠΈ `.json` Π·Π°Π³Ρ€ΡƒΠΆΠ°Π΅Ρ‚ ΠΈΠΌΠ΅Π½Π½ΠΎ этот ΠΊΠΎΠ½Ρ„ΠΈΠ³ нСзависимо ΠΎΡ‚ ΠΈΠΌΠ΅Π½ΠΈ. ΠŸΡƒΡ‚ΡŒ ΠΊ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³Ρƒ Π²ΠΊΠ»ΡŽΡ‡Π°Π΅Ρ‚ config-less Π³Π΅Π½Π΅Ρ€Π°Ρ†ΠΈΡŽ, ΠΈ настройки ΠΏΠ΅Ρ€Π΅Π΄Π°ΡŽΡ‚ΡΡ Ρ„Π»Π°Π³Π°ΠΌΠΈ CLI. + +```json +{ + "scripts": { + "sprite:": "npx --yes @gromlab/svg-sprites ", + "sprite::cli": "npx --yes @gromlab/svg-sprites --mode " + } +} +``` + +ГСнСрация Ρ‡Π΅Ρ€Π΅Π· `npx` Π½Π΅ добавляСт package Π² ΠΏΡ€ΠΎΠ΅ΠΊΡ‚. НС ΠΏΡ€ΠΈΠ΄ΡƒΠΌΡ‹Π²Π°ΠΉ сокращённыС ΠΈΠ»ΠΈ generic mode keys ΠΈ Π½Π΅ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉ ΡƒΠ΄Π°Π»Ρ‘Π½Π½Ρ‹ΠΉ `legacy`: Π²Ρ‹Π±Π΅Ρ€ΠΈ ΠΎΠ΄ΠΈΠ½ ΠΏΠΎΠ»Π½Ρ‹ΠΉ key ΠΈΠ· Ρ‚Π°Π±Π»ΠΈΡ†Ρ‹. Bare `standalone` Π²Ρ‹Π±ΠΈΡ€Π°ΠΉ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ ΠΊΠΎΠ³Π΄Π° ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠ΅ само ΠΏΡƒΠ±Π»ΠΈΠΊΡƒΠ΅Ρ‚ SVG, Π° `standalone@server` β€” Ρ‚ΠΎΠ»ΡŒΠΊΠΎ для Ρ†Π΅Π½Ρ‚Ρ€Π°Π»ΠΈΠ·ΠΎΠ²Π°Π½Π½ΠΎΠ³ΠΎ release, ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅ΠΌΠΎΠ³ΠΎ Π²ΠΎ врСмя Π³Π΅Π½Π΅Ρ€Π°Ρ†ΠΈΠΈ consumers. Для Π½Π΅ΡΠΊΠΎΠ»ΡŒΠΊΠΈΡ… спрайтов создай ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½ΡƒΡŽ ΠΊΠΎΠΌΠ°Π½Π΄Ρƒ для ΠΊΠ°ΠΆΠ΄ΠΎΠ³ΠΎ config-Ρ„Π°ΠΉΠ»Π° ΠΈΠ»ΠΈ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³Π°. + +## Π˜Π½ΡΠΏΠ΅ΠΊΡ†ΠΈΡ ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π° + +Π”ΠΎ ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΠΉ установи фактичСский ΠΊΠΎΠ½Ρ‚Ρ€Π°ΠΊΡ‚ ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π°: + +1. ΠŸΡ€ΠΎΡ‡ΠΈΡ‚Π°ΠΉ ΠΊΠΎΡ€Π½Π΅Π²ΠΎΠΉ `package.json`, lock-Ρ„Π°ΠΉΠ» ΠΈ workspace-ΠΊΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ†ΠΈΡŽ; ΠΎΠΏΡ€Π΅Π΄Π΅Π»ΠΈ framework, bundler ΠΈ ΡΡƒΡ‰Π΅ΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΠ΅ ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹. +2. Найди config-Ρ„Π°ΠΉΠ»Ρ‹, ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ `svg-sprites` ΠΈ ΠΈΠΌΠΏΠΎΡ€Ρ‚Ρ‹ generated-ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ΠΎΠ². Имя ΠΊΠΎΠ½Ρ„ΠΈΠ³Π° ΠΏΡ€ΠΎΠΈΠ·Π²ΠΎΠ»ΡŒΠ½ΠΎΠ΅; ориСнтируйся Π½Π° ΠΏΠ΅Ρ€Π΅Π΄Π°Π½Π½Ρ‹ΠΉ CLI ΠΏΡƒΡ‚ΡŒ ΠΈ поля ΠΎΠ±ΡŠΠ΅ΠΊΡ‚Π°. +3. ΠžΠΏΡ€Π΅Π΄Π΅Π»ΠΈ framework, router ΠΏΡ€ΠΈ Π΅Π³ΠΎ Π½Π°Π»ΠΈΡ‡ΠΈΠΈ ΠΈ фактичСский bundler ΠΏΠΎ scripts ΠΈ ΠΊΠΎΠ½Ρ„ΠΈΠ³Ρƒ. Для Next.js ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½ΠΎ ΠΎΠΏΡ€Π΅Π΄Π΅Π»ΠΈ App/Pages Router ΠΈ сборщик Ρ€Π΅Π°Π»ΡŒΠ½Ρ‹Ρ… `dev`/`build` ΠΊΠΎΠΌΠ°Π½Π΄. +4. ΠŸΡ€ΠΎΠ²Π΅Ρ€ΡŒ ΡΡƒΡ‰Π΅ΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΠ΅ `predev`, `prebuild`, `pretypecheck` ΠΈ Π°Π³Ρ€Π΅Π³ΠΈΡ€ΡƒΡŽΡ‰ΠΈΠ΅ scripts. НС пСрСзаписывай ΠΈΡ…. +5. Для Π½ΠΎΠ²ΠΎΠ³ΠΎ спрайта Π²Ρ‹Π±Π΅Ρ€ΠΈ Ρ†Π΅Π»Π΅Π²ΠΎΠΉ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³, Π½Π΅ навязывая ΠΊΠΎΠ½ΠΊΡ€Π΅Ρ‚Π½Ρ‹ΠΉ слой ΠΈΠ»ΠΈ Π°Ρ€Ρ…ΠΈΡ‚Π΅ΠΊΡ‚ΡƒΡ€Ρƒ прилоТСния. +6. ΠŸΡ€ΠΎΠ²Π΅Ρ€ΡŒ TypeScript ΠΈ alias-настройки. Для package subpath exports Π½ΡƒΠΆΠ΅Π½ TypeScript 5+ с `moduleResolution: 'bundler'`, `'node16'` ΠΈΠ»ΠΈ `'nodenext'`. + +Для ΠΎΠ±Ρ‹Ρ‡Π½ΠΎΠ³ΠΎ local consumer всС input-ΠΏΡƒΡ‚ΠΈ ΡΡ‡ΠΈΡ‚Π°ΡŽΡ‚ΡΡ ΠΎΡ‚Π½ΠΎΡΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³Π°, содСрТащСго явно ΠΏΠ΅Ρ€Π΅Π΄Π°Π½Π½Ρ‹ΠΉ config-Ρ„Π°ΠΉΠ»; Π² config-less Ρ€Π΅ΠΆΠΈΠΌΠ΅ β€” ΠΎΡ‚Π½ΠΎΡΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ ΠΏΠ΅Ρ€Π΅Π΄Π°Π½Π½ΠΎΠ³ΠΎ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³Π°. ΠŸΡ€ΠΎΠ²Π΅Ρ€ΡΠΉ local `input` ΠΏΠΎ этому ΠΊΠΎΠ½Ρ‚Ρ€Π°ΠΊΡ‚Ρƒ: + +- `input?: string | string[]` ΠΏΠΎ ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ Ρ€Π°Π²Π΅Π½ `./icons`; +- каТдая строка Π·Π°Π΄Π°Ρ‘Ρ‚ ΠΏΠ°ΠΏΠΊΡƒ, Ρ‚ΠΎΡ‡Π½Ρ‹ΠΉ SVG-Ρ„Π°ΠΉΠ» ΠΈΠ»ΠΈ glob; +- ΠΏΠ°ΠΏΠΊΠ° сканируСтся плоско; Π²Π»ΠΎΠΆΠ΅Π½Π½Ρ‹Π΅ Ρ„Π°ΠΉΠ»Ρ‹ Π²ΠΊΠ»ΡŽΡ‡Π°ΡŽΡ‚ΡΡ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ явным recursive glob, Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€ `./icons/**/*.svg`; +- массив ΠΎΠ±ΡŠΠ΅Π΄ΠΈΠ½ΡΠ΅Ρ‚ positive-источники, Π° элСмСнт с прСфиксом `!` ΠΈΡΠΊΠ»ΡŽΡ‡Π°Π΅Ρ‚ свои совпадСния ΠΈΠ· ΠΎΠ±Ρ‰Π΅Π³ΠΎ Π½Π°Π±ΠΎΡ€Π°; +- ΠΊΠ°ΠΆΠ΄Ρ‹ΠΉ positive-источник Π΄ΠΎΠ»ΠΆΠ΅Π½ Ρ€Π°Π·Ρ€Π΅ΡˆΠ°Ρ‚ΡŒΡΡ хотя Π±Ρ‹ Π² ΠΎΠ΄ΠΈΠ½ SVG, поэтому ΠΎΡ‚ΡΡƒΡ‚ΡΡ‚Π²ΡƒΡŽΡ‰Π°Ρ ΠΈΠ»ΠΈ пустая ΠΏΠ°ΠΏΠΊΠ°, glob Π±Π΅Π· совпадСний, ΠΎΡ‚ΡΡƒΡ‚ΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΠΉ Ρ„Π°ΠΉΠ» ΠΈΠ»ΠΈ Ρ‚ΠΎΡ‡Π½Ρ‹ΠΉ ΠΏΡƒΡ‚ΡŒ Π½Π΅ ΠΊ SVG ΡΠ²Π»ΡΡŽΡ‚ΡΡ ошибкой; +- Ρ€Π°Π·Ρ€Π΅ΡˆΡ‘Π½Π½Ρ‹Π΅ Ρ„Π°ΠΉΠ»Ρ‹ Π΄Π΅Π΄ΡƒΠΏΠ»ΠΈΡ†ΠΈΡ€ΡƒΡŽΡ‚ΡΡ ΠΈ Π΄Π΅Ρ‚Π΅Ρ€ΠΌΠΈΠ½ΠΈΡ€ΠΎΠ²Π°Π½Π½ΠΎ ΡΠΎΡ€Ρ‚ΠΈΡ€ΡƒΡŽΡ‚ΡΡ; +- Ρ€Π°Π·Π½Ρ‹Π΅ Ρ„Π°ΠΉΠ»Ρ‹ с ΠΎΠ΄ΠΈΠ½Π°ΠΊΠΎΠ²Ρ‹ΠΌ basename ΠΊΠΎΠ½Ρ„Π»ΠΈΠΊΡ‚ΡƒΡŽΡ‚, Π΄Π°ΠΆΠ΅ Ссли ΠΏΠΎΠ»ΡƒΡ‡Π΅Π½Ρ‹ ΠΈΠ· Ρ€Π°Π·Π½Ρ‹Ρ… источников. + +Π”ΠΎ примСнСния этих ΠΏΡ€Π°Π²ΠΈΠ» Π²Ρ‹Π±Π΅Ρ€ΠΈ Π½ΡƒΠΆΠ½ΡƒΡŽ Π²Π΅Ρ‚ΠΊΡƒ: + +- `standalone@server` ΠΌΠΎΠΆΠ΅Ρ‚ ΠΎΠ±ΡŠΠ΅Π΄ΠΈΠ½ΡΡ‚ΡŒ local strings ΠΈ HTTP(S) descriptors `{ name, url, sha256? }`; `name` Π·Π°Π΄Π°Ρ‘Ρ‚ ΠΏΡƒΠ±Π»ΠΈΡ‡Π½ΠΎΠ΅ имя ΠΈΠΊΠΎΠ½ΠΊΠΈ, Π° Π½Π΅ΠΎΠ±ΡΠ·Π°Ρ‚Π΅Π»ΡŒΠ½Ρ‹ΠΉ `sha256` провСряСт скачанныС Π±Π°ΠΉΡ‚Ρ‹; +- `source: 'remote'` Ρ‚Ρ€Π΅Π±ΡƒΠ΅Ρ‚ Ρ€ΠΎΠ²Π½ΠΎ ΠΎΠ΄Π½Ρƒ строку с local path ΠΈΠ»ΠΈ HTTP(S) URL manifest ΠΈ Π½Π΅ ΠΏΡ€ΠΈΠ½ΠΈΠΌΠ°Π΅Ρ‚ source globs ΠΈΠ»ΠΈ descriptors; +- remote consumer config содСрТит Ρ‚ΠΎΠ»ΡŒΠΊΠΎ `mode`, `source` ΠΈ `input`; name, description, transforms ΠΈ generated notice приходят ΠΈΠ· ΠΏΡ€ΠΎΠ²Π΅Ρ€Π΅Π½Π½ΠΎΠ³ΠΎ server manifest. + +НС ΠΊΠΎΠΏΠΈΡ€ΡƒΠΉ ΠΎΠ±Ρ‰ΠΈΠΉ SVG Π² нСсколько ΠΏΠ°ΠΏΠΎΠΊ: добавь Π΅Π³ΠΎ Ρ‚ΠΎΡ‡Π½Ρ‹ΠΉ ΠΏΡƒΡ‚ΡŒ ΠΈΠ»ΠΈ подходящий glob Π² `input` ΠΊΠ°ΠΆΠ΄ΠΎΠ³ΠΎ Π½ΡƒΠΆΠ½ΠΎΠ³ΠΎ спрайта. Π˜ΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉ `**/*.svg` Ρ‚ΠΎΠ»ΡŒΠΊΠΎ для Π½Π°ΠΌΠ΅Ρ€Π΅Π½Π½ΠΎΠ³ΠΎ рСкурсивного Π²ΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΡ. + +## Настройка ΠΈΠ½Ρ‚Π΅Π³Ρ€Π°Ρ†ΠΈΠΈ + +НС воспроизводи настройку mode ΠΏΠΎ памяти. ПослС инспСкции ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π° Π²Ρ‹Π±Π΅Ρ€ΠΈ ΠΎΠ΄ΠΈΠ½ exact mode ΠΈ ΠΎΡ‚ΠΊΡ€ΠΎΠΉ ΡΠΎΠΎΡ‚Π²Π΅Ρ‚ΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΠΉ Ρ„Π°ΠΉΠ» ΠΈΠ· `references/docs/ru/guides/`. Π˜ΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉ guide ΠΊΠ°ΠΊ Π±Π°Π·ΠΎΠ²Ρ‹ΠΉ Ρ€Π°Π±ΠΎΡ‡ΠΈΠΉ ΠΊΠΎΠ½Ρ‚Ρ€Π°ΠΊΡ‚, Π·Π°Ρ‚Π΅ΠΌ Π°Π΄Π°ΠΏΡ‚ΠΈΡ€ΡƒΠΉ Π΅Π³ΠΎ ΠΊ ΡΡƒΡ‰Π΅ΡΡ‚Π²ΡƒΡŽΡ‰Π΅ΠΉ структурС ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π°. + +Π Π°Π±ΠΎΡ‚Π°ΠΉ Π² Ρ‚Π°ΠΊΠΎΠΌ порядкС: + +1. ΠžΠΏΡ€Π΅Π΄Π΅Π»ΠΈ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ исходных SVG ΠΈ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ ΠΎΠ΄Π½ΠΎΠ³ΠΎ sprite-модуля. Один config создаёт ΠΎΠ΄ΠΈΠ½ нСзависимый спрайт; для Π½Π΅ΡΠΊΠΎΠ»ΡŒΠΊΠΈΡ… Π½Π°Π±ΠΎΡ€ΠΎΠ² Π½ΡƒΠΆΠ½Ρ‹ ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½Ρ‹Π΅ config-Ρ„Π°ΠΉΠ»Ρ‹ ΠΈ ΡƒΠ½ΠΈΠΊΠ°Π»ΡŒΠ½Ρ‹Π΅ `name`. +2. Π‘Π²Π΅Ρ€ΡŒ framework, router ΠΈ bundler с exact mode. Для Next.js провСряй Ρ€Π΅Π°Π»ΡŒΠ½Ρ‹Π΅ `dev` ΠΈ `build` scripts, Π° Π½Π΅ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ Π½Π°Π»ΠΈΡ‡ΠΈΠ΅ `next.config.*`. +3. ΠŸΡ€Π΅Π΄ΠΏΠΎΡ‡ΠΈΡ‚Π°ΠΉ JSON-ΠΊΠΎΠ½Ρ„ΠΈΠ³, Ссли ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Ρƒ Π½Π΅ Π½ΡƒΠΆΠ½Ρ‹ package-Ρ‚ΠΈΠΏΡ‹ config. TypeScript-ΠΊΠΎΠ½Ρ„ΠΈΠ³ Ρ‚Π°ΠΊΠΆΠ΅ загруТаСтся Ρ‡Π΅Ρ€Π΅Π· CLI, Π½ΠΎ установка package Π½ΡƒΠΆΠ½Π°, ΠΊΠΎΠ³Π΄Π° ΠΎΠ½ ΠΈΠΌΠΏΠΎΡ€Ρ‚ΠΈΡ€ΡƒΠ΅Ρ‚ `defineSpriteConfig` ΠΈΠ»ΠΈ Ρ‚ΠΈΠΏΡ‹. +4. Π Π°Π·Ρ€Π΅ΡˆΠ°ΠΉ всС `input` ΠΎΡ‚Π½ΠΎΡΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³Π° config-Ρ„Π°ΠΉΠ»Π°. НС мСняй структуру SVG Π±Π΅Π· нСобходимости: ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉ ΠΏΡƒΡ‚ΡŒ ΠΊ ΠΏΠ°ΠΏΠΊΠ΅, Ρ‚ΠΎΡ‡Π½Ρ‹ΠΉ Ρ„Π°ΠΉΠ», glob ΠΈΠ»ΠΈ массив этих источников. +5. Π”ΠΎΠ±Π°Π²ΡŒ sprite-ΠΊΠΎΠΌΠ°Π½Π΄Ρƒ с явным ΠΏΡƒΡ‚Ρ‘ΠΌ ΠΊ config. Π‘ΠΎΡ…Ρ€Π°Π½ΠΈ ΡΡƒΡ‰Π΅ΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΠ΅ `dev`, `build`, `typecheck` ΠΈ lifecycle hooks; встрой Π³Π΅Π½Π΅Ρ€Π°Ρ†ΠΈΡŽ Π΄ΠΎ ΠΏΠ΅Ρ€Π²ΠΎΠ³ΠΎ процСсса, ΠΈΠΌΠΏΠΎΡ€Ρ‚ΠΈΡ€ΡƒΡŽΡ‰Π΅Π³ΠΎ `.svg-sprite`. +6. НС запускай ΠΎΠ΄Π½Ρƒ Π³Π΅Π½Π΅Ρ€Π°Ρ†ΠΈΡŽ Π΄Π²Π°ΠΆΠ΄Ρ‹ Ρ‡Π΅Ρ€Π΅Π· ΠΎΠ΄Π½ΠΎΠ²Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹ΠΉ `predev` ΠΈ `npm run sprites && ...`. Для Π½Π΅ΡΠΊΠΎΠ»ΡŒΠΊΠΈΡ… спрайтов создай ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½Ρ‹Π΅ ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ ΠΈ ΠΎΠ΄ΠΈΠ½ Π°Π³Ρ€Π΅Π³ΠΈΡ€ΡƒΡŽΡ‰ΠΈΠΉ script. +7. Если ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠ΅ ΠΈΠΌΠΏΠΎΡ€Ρ‚ΠΈΡ€ΡƒΠ΅Ρ‚ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ sprite-модуля, создай ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒΡΠΊΠΈΠΉ `index.ts` рядом с `.svg-sprite`; Π½Π΅ ΠΏΠΎΠΌΠ΅Ρ‰Π°ΠΉ ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒΡΠΊΠΈΠ΅ Ρ„Π°ΠΉΠ»Ρ‹ Π²Π½ΡƒΡ‚Ρ€ΡŒ generated-ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³Π°. +8. Π’Ρ‹ΠΏΠΎΠ»Π½ΠΈ ΠΏΠ΅Ρ€Π²ΡƒΡŽ Π³Π΅Π½Π΅Ρ€Π°Ρ†ΠΈΡŽ Π΄ΠΎ typecheck ΠΈΠ»ΠΈ запуска прилоТСния, Π·Π°Ρ‚Π΅ΠΌ ΠΏΡ€ΠΎΠ²Π΅Ρ€ΡŒ mode-specific output ΠΈ фактичСский ΠΈΠΌΠΏΠΎΡ€Ρ‚ ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚Π°. + +Для Ρ†Π΅Π½Ρ‚Ρ€Π°Π»ΠΈΠ·ΠΎΠ²Π°Π½Π½ΠΎΠ³ΠΎ release ΠΎΡ‚ΠΊΡ€ΠΎΠΉ `references/docs/ru/guides/standalone-server.md`. +Π“Π΅Π½Π΅Ρ€ΠΈΡ€ΡƒΠΉ ΠΈ ΠΏΡƒΠ±Π»ΠΈΠΊΡƒΠΉ вСсь ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ `.svg-sprite` Π°Ρ‚ΠΎΠΌΠ°Ρ€Π½ΠΎ. Π’ ΠΊΠ°ΠΆΠ΄ΠΎΠΌ consumer сохрани +Π΅Π³ΠΎ собствСнный exact framework mode, ΡƒΠΊΠ°ΠΆΠΈ `source: 'remote'` ΠΈ Π½Π°ΠΏΡ€Π°Π²ΡŒ `input` Π½Π° +manifest. НС ΠΊΠΎΠΏΠΈΡ€ΡƒΠΉ server files Π²ΠΎ framework output ΠΈ Π½Π΅ Π·Π°Π³Ρ€ΡƒΠΆΠ°ΠΉ manifest ΠΈΠ· +runtime прилоТСния. + +НС добавляй Viewer автоматичСски. ΠŸΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π°ΠΉ Π΅Π³ΠΎ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ ΠΏΠΎ запросу ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»Ρ ΠΈΠ»ΠΈ ΠΊΠΎΠ³Π΄Π° Π½ΡƒΠΆΠ½Π° Π²ΠΈΠ·ΡƒΠ°Π»ΡŒΠ½Π°Ρ ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΊΠ° Π½Π°Π±ΠΎΡ€Π°, Ρ†Π²Π΅Ρ‚ΠΎΠ² Π»ΠΈΠ±ΠΎ слоТных SVG. Бпособ изоляции Viewer ΠΎΡ‚ production Π±Π΅Ρ€ΠΈ ΠΈΠ· exact guide: frameworks, bundlers ΠΈ routers ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΡŽΡ‚ Ρ€Π°Π·Π½Ρ‹Π΅ Π³Ρ€Π°Π½ΠΈΡ†Ρ‹. + +НС ΠΊΠΎΠΏΠΈΡ€ΡƒΠΉ snippets ΠΌΠ΅ΠΆΠ΄Ρƒ exact modes Π΄Π°ΠΆΠ΅ ΠΏΡ€ΠΈ ΠΏΠΎΡ…ΠΎΠΆΠ΅ΠΌ API. Π Π°Π·Π»ΠΈΡ‡Π°ΡŽΡ‚ΡΡ asset URL, generated-Ρ„Π°ΠΉΠ»Ρ‹, CSS handling, router boundary ΠΈ способ ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΡ debug-инструмСнтов. + +## ΠšΠΎΠ½Ρ‚Ρ€Π°ΠΊΡ‚ generated-ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³Π° + +НапримСр, послС Π³Π΅Π½Π΅Ρ€Π°Ρ†ΠΈΠΈ React/Next-ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ ΠΈΠΌΠ΅Π΅Ρ‚ ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΠΈΠΉ Π²ΠΈΠ΄: + +```text +svg-sprite/ +β”œβ”€β”€ icons/ # ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒΡΠΊΠΈΠ΅ исходники +β”œβ”€β”€ svg-sprite.config.json # Ρ€Π΅ΠΊΠΎΠΌΠ΅Π½Π΄ΡƒΠ΅ΠΌΠΎΠ΅ имя ΠΊΠΎΠ½Ρ„ΠΈΠ³Π° +β”œβ”€β”€ index.ts # Π½Π΅ΠΎΠ±ΡΠ·Π°Ρ‚Π΅Π»ΡŒΠ½Ρ‹ΠΉ ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒΡΠΊΠΈΠΉ barrel +β”œβ”€β”€ .gitignore # управляСт Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ +└── .svg-sprite/ + β”œβ”€β”€ index.js + β”œβ”€β”€ index.d.ts + β”œβ”€β”€ icon-data.js + β”œβ”€β”€ icon-data.d.ts + β”œβ”€β”€ sprite.svg + β”œβ”€β”€ svg-sprite.manifest.js + β”œβ”€β”€ svg-sprite.manifest.d.ts + └── react/ + β”œβ”€β”€ react-component.js + β”œβ”€β”€ react-component.d.ts + └── react-component.module.css +``` + +Standalone Π½Π΅ создаёт `react/`. Bare `standalone` Π³Π΅Π½Π΅Ρ€ΠΈΡ€ΡƒΠ΅Ρ‚ `sprite.svg` ΠΈ `svg-sprite.manifest.json`; `standalone@vite`/`standalone@webpack` Π΄ΠΎΠΏΠΎΠ»Π½ΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ Π³Π΅Π½Π΅Ρ€ΠΈΡ€ΡƒΡŽΡ‚ `index.*`, `icon-data.*` ΠΈ resolved manifest. Π˜Ρ… `index.*` Ρ‚Π°ΠΊΠΆΠ΅ содСрТит Π½Π°Ρ‚ΠΈΠ²Π½Ρ‹ΠΉ generated Web Component; bare `standalone` Π½Π΅ ΠΏΠΎΠ»ΡƒΡ‡Π°Π΅Ρ‚ JS runtime ΠΈ Π½Π΅ создаёт `.gitignore`. + +`standalone@server` Π³Π΅Π½Π΅Ρ€ΠΈΡ€ΡƒΠ΅Ρ‚ `sprite..svg`, +`sprite-root-viewbox..svg` ΠΈ `svg-sprite.manifest.json`. Π£ Π½Π΅Π³ΠΎ Π½Π΅Ρ‚ +consumer facade, browser runtime, Viewer entry ΠΈΠ»ΠΈ `.gitignore`. Manifest Ρ…Ρ€Π°Π½ΠΈΡ‚ +relative URL ΠΎΠ±ΠΎΠΈΡ… profiles, ΠΏΠΎΠ»Π½Ρ‹Π΅ SHA-256, Ρ€Π°Π·ΠΌΠ΅Ρ€Ρ‹ Π² Π±Π°ΠΉΡ‚Π°Ρ…, metadata ΠΈΠΊΠΎΠ½ΠΎΠΊ ΠΈ +настройки transforms. + +Π Π΅Π΄Π°ΠΊΡ‚ΠΈΡ€ΡƒΠΉ исходныС SVG, config-Ρ„Π°ΠΉΠ» ΠΈ ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒΡΠΊΠΈΠΉ `index.ts`. НС измСняй Π²Ρ€ΡƒΡ‡Π½ΡƒΡŽ содСрТимоС `.svg-sprite`: повторная гСнСрация Π΅Π³ΠΎ ΠΏΠ΅Ρ€Π΅Π·Π°ΠΏΠΈΡˆΠ΅Ρ‚. Π’ΠΎ всСх modes, ΠΊΡ€ΠΎΠΌΠ΅ bare `standalone`, generated `.gitignore` Ρ‚Π°ΠΊΠΆΠ΅ находится ΠΏΠΎΠ΄ ΡƒΠΏΡ€Π°Π²Π»Π΅Π½ΠΈΠ΅ΠΌ Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€Π°. Для ΠΈΠΌΠΏΠΎΡ€Ρ‚Π° ΠΈΠ· корня sprite-модуля создай barrel: + +```ts +export * from './.svg-sprite/index.js' +``` + +Π“Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ ΠΏΠΎΠ»Π½ΠΎΡΡ‚ΡŒΡŽ Π²Π»Π°Π΄Π΅Π΅Ρ‚ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ΠΎΠΌ `.svg-sprite` ΠΈ замСняСт Π΅Π³ΠΎ ΠΏΡ€ΠΈ ΠΊΠ°ΠΆΠ΄ΠΎΠΌ запускС. Никогда Π½Π΅ ΠΏΠΎΠΌΠ΅Ρ‰Π°ΠΉ Ρ‚ΡƒΠ΄Π° ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒΡΠΊΠΈΠ΅ Ρ„Π°ΠΉΠ»Ρ‹. Π“Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ Ρ‚Π°ΠΊΠΆΠ΅ Π²Π»Π°Π΄Π΅Π΅Ρ‚ `.gitignore`, ΠΊΠΎΠ³Π΄Π° Π²Ρ‹Π±Ρ€Π°Π½Π½Ρ‹ΠΉ mode Π΅Π³ΠΎ создаёт. Bare `standalone` сохраняСт ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒΡΠΊΠΈΠΉ `.gitignore`, Π½ΠΎ удаляСт управляСмый `.gitignore`, ΠΎΡΡ‚Π°Π²ΡˆΠΈΠΉΡΡ послС Π΄Ρ€ΡƒΠ³ΠΎΠ³ΠΎ mode. Generated-ΠΏΡƒΡ‚ΠΈ Π½Π΅ Π΄ΠΎΠ»ΠΆΠ½Ρ‹ ΡΠΎΠ΄Π΅Ρ€ΠΆΠ°Ρ‚ΡŒ symlink. + +ΠšΠ°ΠΆΠ΄Ρ‹ΠΉ exact-mode adapter Π²Π»Π°Π΄Π΅Π΅Ρ‚ facade, framework-ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ΠΎΠΌ, runtime Π½Π°Ρ‚ΠΈΠ²Π½ΠΎΠ³ΠΎ ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚Π°, declarations, manifest source, styles ΠΈ asset URL. React/Next ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΡŽΡ‚ `react/`; ΠΎΡΡ‚Π°Π»ΡŒΠ½Ρ‹Π΅ framework modes ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΡŽΡ‚ собствСнный generated-ΠΊΠΎΠ½Ρ‚Ρ€Π°ΠΊΡ‚ ΠΈΠ· ΡΠΎΠΎΡ‚Π²Π΅Ρ‚ΡΡ‚Π²ΡƒΡŽΡ‰Π΅Π³ΠΎ guide. Standalone bundler modes ΡΠΊΡΠΏΠΎΡ€Ρ‚ΠΈΡ€ΡƒΡŽΡ‚ Web Component helpers ΠΈ Ρ‚ΠΈΠΏΡ‹, Π° bare `standalone` Π½Π΅ создаёт facade. Manifest declarations ΠΎΠ±ΡŠΡΠ²Π»ΡΡŽΡ‚ Ρ‚ΠΈΠΏΡ‹ локально ΠΈ Π½Π΅ ΠΈΠΌΠΏΠΎΡ€Ρ‚ΠΈΡ€ΡƒΡŽΡ‚ generator package. + +Π’ bundler modes спрайт остаётся ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½Ρ‹ΠΌ asset, Π° SVG path-Π΄Π°Π½Π½Ρ‹Π΅ Π½Π΅ Π²ΡΡ‚Ρ€Π°ΠΈΠ²Π°ΡŽΡ‚ΡΡ Π² JavaScript. Content hash зависит ΠΎΡ‚ настроСк сборщика. Bare `standalone` создаёт Ρ„Π°ΠΉΠ» с фиксированным ΠΈΠΌΠ΅Π½Π΅ΠΌ, Π° ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠ΅ само опрСдСляСт Π΅Π³ΠΎ ΠΏΡƒΠ±Π»ΠΈΡ‡Π½ΠΎΠ΅ имя ΠΈ вСрсионированиС: + +- Vite-based adapters ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΡŽΡ‚ mode-owned static asset import, ΡΠΎΡ…Ρ€Π°Π½ΡΡŽΡ‰ΠΈΠΉ sprite внСшним; +- `standalone@vite` ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ Ρ‚ΠΎΡ‚ ΠΆΠ΅ Vite asset-ΠΌΠ΅Ρ…Π°Π½ΠΈΠ·ΠΌ ΠΈ экспортируСт href helper ΠΈ Π½Π°Ρ‚ΠΈΠ²Π½Ρ‹ΠΉ Web Component Π±Π΅Π· React; +- `standalone@webpack` ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ Webpack Asset Modules ΠΈ экспортируСт Ρ‚Π°ΠΊΠΎΠΉ ΠΆΠ΅ mode-local Web Component Π±Π΅Π· React; +- Webpack-based adapters ΠΈ всС Next modes ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΡŽΡ‚ adapter-owned ΠΌΠ΅Ρ…Π°Π½ΠΈΠ·ΠΌ внСшнСго asset, ΠΎΠ±Ρ‹Ρ‡Π½ΠΎ `new URL(..., import.meta.url).href`; +- кастомный Webpack SVG loader Π½Π΅ Π΄ΠΎΠ»ΠΆΠ΅Π½ ΠΏΠ΅Ρ€Π΅Ρ…Π²Π°Ρ‚Ρ‹Π²Π°Ρ‚ΡŒ generated `sprite.svg`; +- Π² Next mode generated-ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ Π½Π΅ содСрТит `'use client'` ΠΈ Ρ€Π°Π±ΠΎΡ‚Π°Π΅Ρ‚ Π² Server Components, SSR ΠΈ SSG; Π½Π΅ добавляй ΠΊΠ»ΠΈΠ΅Π½Ρ‚ΡΠΊΡƒΡŽ Π³Ρ€Π°Π½ΠΈΡ†Ρƒ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ Ρ€Π°Π΄ΠΈ ΠΈΠΊΠΎΠ½ΠΊΠΈ; +- ΠΊΠΎΠΌΠ°Π½Π΄Π° сборки Next ΠΈ mode key Π΄ΠΎΠ»ΠΆΠ½Ρ‹ ΡΠΎΠ²ΠΏΠ°Π΄Π°Ρ‚ΡŒ: Turbopack с `.../turbopack`, Webpack с `.../webpack`. +- remote consumers всё Ρ€Π°Π²Π½ΠΎ ΠΏΡƒΠ±Π»ΠΈΠΊΡƒΡŽΡ‚ΡΡ Ρ‡Π΅Ρ€Π΅Π· Π»ΠΎΠΊΠ°Π»ΡŒΠ½Ρ‹ΠΉ asset pipeline своСго adapter; Π½Π΅ сохраняй ΠΈ Π½Π΅ собирай URL server profile Π² generated application code. + +Для bundler modes Π½Π΅ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Ρ‰Π°ΠΉ generated sprite Π² `public` ΠΈ Π½Π΅ пСрСписывай URL Π²Ρ€ΡƒΡ‡Π½ΡƒΡŽ. Для bare `standalone` Π½Π΅ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Ρ‰Π°ΠΉ managed original: ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠ΅ ΠΌΠΎΠΆΠ΅Ρ‚ явно ΠΊΠΎΠΏΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ Π΅Π³ΠΎ Π² deploy output ΠΈ само ΠΎΡ‚Π²Π΅Ρ‡Π°Π΅Ρ‚ Π·Π° ΠΏΡƒΠ±Π»ΠΈΡ‡Π½Ρ‹ΠΉ URL ΠΈ очистку ΠΊΠΎΠΏΠΈΠΈ. ΠŸΡ€ΠΈ смСнС mode ΠΏΠ΅Ρ€Π΅Π³Π΅Π½Π΅Ρ€ΠΈΡ€ΡƒΠΉ спрайт с Π½ΠΎΠ²Ρ‹ΠΌ ΠΏΠΎΠ»Π½Ρ‹ΠΌ key. + +## ИспользованиС, Π΄ΠΎΡΡ‚ΡƒΠΏΠ½ΠΎΡΡ‚ΡŒ ΠΈ Ρ†Π²Π΅Ρ‚Π° + +Имя ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚Π° зависит ΠΎΡ‚ `name` ΠΊΠΎΠ½ΠΊΡ€Π΅Ρ‚Π½ΠΎΠ³ΠΎ спрайта. Π’ `standalone@vite` ΠΈ `standalone@webpack` Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ `name: 'file-manager'` создаёт tag `` ΠΈ Ρ„ΡƒΠ½ΠΊΡ†ΠΈΡŽ `defineFileManagerIconElement()`: + +```ts +import { defineFileManagerIconElement } from './svg-sprite' + +defineFileManagerIconElement() +``` + +```html + +``` + +Нативный элСмСнт Π½Π΅ ΠΈΠΌΠ΅Π΅Ρ‚ runtime-зависимостСй, сам Π²Ρ‹Π±ΠΈΡ€Π°Π΅Ρ‚ generated ID ΠΈ `viewBox`, ΠΏΠΎΠ»ΡƒΡ‡Π°Π΅Ρ‚ URL Ρ‡Π΅Ρ€Π΅Π· bundler ΠΈ Ρ€Π΅Π½Π΄Π΅Ρ€ΠΈΡ‚ `` Π² Shadow DOM. Π•Π³ΠΎ property `icon` Ρ‚ΠΈΠΏΠΈΠ·ΠΈΡ€ΠΎΠ²Π°Π½ Ρ‚ΠΎΡ‡Π½Ρ‹ΠΌ union ΠΈΠΌΡ‘Π½, Π½ΠΎ строковыС HTML attributes ΠΏΡ€ΠΎΠ²Π΅Ρ€ΡΡŽΡ‚ΡΡ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ Π² runtime. Π Π°Π·ΠΌΠ΅Ρ€ ΠΏΠΎ ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ Ρ€Π°Π²Π΅Π½ `1em Γ— 1em`; мСняй Π΅Π³ΠΎ Ρ‡Π΅Ρ€Π΅Π· CSS Π½Π° host. Bare `standalone` Web Component Π½Π΅ Π³Π΅Π½Π΅Ρ€ΠΈΡ€ΡƒΠ΅Ρ‚. + +Π’ component modes Ρ‚ΠΎΡ‚ ΠΆΠ΅ `name: 'file-manager'` создаёт Π½Π°Ρ‚ΠΈΠ²Π½Ρ‹ΠΉ ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ `FileManagerIcon`; Π΅Π³ΠΎ синтаксис ΠΈ props опрСдСляСт exact-mode guide. Π’ React/Next.js Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ `name: 'navigation'` создаёт `NavigationIcon`. + +Π˜ΠΌΠΏΠΎΡ€Ρ‚ΠΈΡ€ΡƒΠΉ ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ ΠΈΠ· корня ΡΠΎΠΎΡ‚Π²Π΅Ρ‚ΡΡ‚Π²ΡƒΡŽΡ‰Π΅Π³ΠΎ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³Π° спрайта. `width` ΠΈ `height` Π½Π΅ ΠΎΠ±ΡΠ·Π°Ρ‚Π΅Π»ΡŒΠ½Ρ‹: Ρ€Π°Π·ΠΌΠ΅Ρ€ΠΎΠΌ ΠΌΠΎΠΆΠ½ΠΎ ΡƒΠΏΡ€Π°Π²Π»ΡΡ‚ΡŒ ΠΎΠ±Ρ‹Ρ‡Π½Ρ‹ΠΌ CSS-классом. + +```tsx +import { FileManagerIcon } from './svg-sprite' + +export const OpenButton = () => ( + ΠžΡ‚ΠΊΡ€Ρ‹Ρ‚ΡŒ + +) +``` + +```css +.icon { + width: 24px; + height: 24px; + color: #4b5563; +} +``` + +`icon` ΠΏΡ€ΠΈΠ½ΠΈΠΌΠ°Π΅Ρ‚ Ρ‚ΠΎΡ‡Π½Ρ‹Π΅ ΠΈΠΌΠ΅Π½Π° исходных Ρ„Π°ΠΉΠ»ΠΎΠ² Π±Π΅Π· `.svg`; нСизвСстноС имя являСтся ошибкой TypeScript. Для нСбСзопасных SVG ID ΠΈΠΌΡ‘Π½ Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ Ρ…Ρ€Π°Π½ΠΈΡ‚ ΠΏΡƒΠ±Π»ΠΈΡ‡Π½ΠΎΠ΅ имя, Π½ΠΎ создаёт Π²Π½ΡƒΡ‚Ρ€Π΅Π½Π½ΠΈΠΉ ΡΡ‚Π°Π±ΠΈΠ»ΡŒΠ½Ρ‹ΠΉ hash ID, поэтому Π½Π΅ собирай fragment URL ΠΈΠ· ΠΈΠΌΠ΅Π½ΠΈ Π²Ρ€ΡƒΡ‡Π½ΡƒΡŽ. + +По ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ Ρ€Π΅Π½Π΄Π΅Ρ€ΠΈΡ‚ `` ΠΈ ΠΏΡ€ΠΈΠ½ΠΈΠΌΠ°Π΅Ρ‚ стандартныС SVG attributes: Π½Π΅ΠΎΠ±ΡΠ·Π°Ρ‚Π΅Π»ΡŒΠ½Ρ‹Π΅ `width`/`height`, `className`, `style`, `role`, `aria-*` ΠΈ ΠΎΠ±Ρ€Π°Π±ΠΎΡ‚Ρ‡ΠΈΠΊΠΈ. Π‘ `wrapped={true}` ΠΊΠΎΡ€Π½Π΅ΠΌ становится ``, props относятся ΠΊ span, Π° Π²Π½ΡƒΡ‚Ρ€Π΅Π½Π½ΠΈΠΉ SVG Π·Π°Π½ΠΈΠΌΠ°Π΅Ρ‚ Ρ€Π°Π·ΠΌΠ΅Ρ€ wrapper. + +Generated-ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ Π½Π΅ Π²Ρ‹Π±ΠΈΡ€Π°Π΅Ρ‚ сСмантику Π·Π° ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠ΅ ΠΈ Π½Π΅ добавляСт `title`. Для Π΄Π΅ΠΊΠΎΡ€Π°Ρ‚ΠΈΠ²Π½ΠΎΠΉ ΠΈΠΊΠΎΠ½ΠΊΠΈ ΠΏΠ΅Ρ€Π΅Π΄Π°ΠΉ `aria-hidden="true"`; для ΡΠ°ΠΌΠΎΡΡ‚ΠΎΡΡ‚Π΅Π»ΡŒΠ½ΠΎΠΉ смысловой ΠΈΠΊΠΎΠ½ΠΊΠΈ ΠΏΠ΅Ρ€Π΅Π΄Π°ΠΉ `role="img"` ΠΈ доступноС имя Ρ‡Π΅Ρ€Π΅Π· `aria-label`. НС Π΄ΡƒΠ±Π»ΠΈΡ€ΡƒΠΉ имя, Ссли сосСдний тСкст ΡƒΠΆΠ΅ ΠΎΠ·Π²ΡƒΡ‡ΠΈΠ²Π°Π΅Ρ‚ дСйствиС. Π˜Π½Ρ‚Π΅Ρ€Π°ΠΊΡ‚ΠΈΠ²Π½ΠΎΡΡ‚ΡŒ Ρ€Π°Π·ΠΌΠ΅Ρ‰Π°ΠΉ Π½Π° `button` ΠΈΠ»ΠΈ `a`, Π° Π½Π΅ Π½Π° самой ΠΈΠΊΠΎΠ½ΠΊΠ΅. + +Врансформации `removeSize`, `replaceColors` ΠΈ `addTransition` Π²ΠΊΠ»ΡŽΡ‡Π΅Π½Ρ‹ ΠΏΠΎ ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ. Для ΠΌΠΎΠ½ΠΎΡ…Ρ€ΠΎΠΌΠ½ΠΎΠΉ ΠΈΠΊΠΎΠ½ΠΊΠΈ СдинствСнный Ρ†Π²Π΅Ρ‚ ΠΏΠΎΠ»ΡƒΡ‡Π°Π΅Ρ‚ fallback `currentColor`, поэтому управляй CSS-свойством `color`. Для ΠΌΠ½ΠΎΠ³ΠΎΡ†Π²Π΅Ρ‚Π½ΠΎΠΉ ΠΏΠ΅Ρ€Π΅Π΄Π°Π²Π°ΠΉ Ρ‚ΠΈΠΏΠΈΠ·ΠΈΡ€ΠΎΠ²Π°Π½Π½Ρ‹Π΅ custom properties: + +```tsx + +``` + +АвтозамСна рассчитана Π½Π° `fill`/`stroke` attributes ΠΈ inline `style`. ЗначСния `none`, `transparent`, `inherit`, `unset`, `initial` Π½Π΅ Π·Π°ΠΌΠ΅Π½ΡΡŽΡ‚ΡΡ. CSS-классы ΠΈ внСшниС stylesheets, gradients, patterns, filters ΠΈ `url(#...)` провСряй Π½Π° Ρ€Π΅Π°Π»ΡŒΠ½ΠΎΠΌ Ρ€Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚Π΅. ΠŸΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅ страницы Ρ€Π°Π±ΠΎΡ‚Π°ΡŽΡ‚ Ρ‡Π΅Ρ€Π΅Π· ``, Π½ΠΎ Π½Π΅ ΠΏΡ€ΠΎΠ½ΠΈΠΊΠ°ΡŽΡ‚ Π²ΠΎ внСшний Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚ ΠΏΡ€ΠΈ `` ΠΈΠ»ΠΈ `background-image`; CSS mask оставляСт Ρ‚ΠΎΠ»ΡŒΠΊΠΎ ΠΎΠ΄Π½ΠΎΡ†Π²Π΅Ρ‚Π½Ρ‹ΠΉ силуэт. + +`SpriteViewer` нСобязатСлСн. Установи `@gromlab/svg-sprites` ΠΊΠ°ΠΊ development dependency, Ρ‚ΠΎΠ»ΡŒΠΊΠΎ Ссли ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Ρƒ Π½ΡƒΠΆΠ΅Π½ Viewer. Он ΠΏΡ€ΠΈΠ½ΠΈΠΌΠ°Π΅Ρ‚ manifests ΠΈΠ»ΠΈ статичСски ΠΎΠ±Π½Π°Ρ€ΡƒΠΆΠΈΠΌΡ‹Π΅ loaders, ΠΏΠΎΠΊΠ°Π·Ρ‹Π²Π°Π΅Ρ‚ поиск, Ρ‚Π΅ΠΌΡ‹, Ρ†Π²Π΅Ρ‚Π° ΠΈ ΠΏΡ€ΠΈΠΌΠ΅Ρ€Ρ‹, Π½ΠΎ production-ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚Ρ‹ ΠΎΡ‚ Π½Π΅Π³ΠΎ Π½Π΅ зависят. + +ΠŸΠ΅Ρ€Π΅Π΄ ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅ΠΌ Viewer ΠΎΡ‚ΠΊΡ€ΠΎΠΉ exact guide. Frameworks, bundlers ΠΈ routers Ρ‚Ρ€Π΅Π±ΡƒΡŽΡ‚ Ρ€Π°Π·Π½Ρ‹Ρ… debug entries ΠΈΠ»ΠΈ client boundaries. НС пСрСноси способ ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΡ ΠΌΠ΅ΠΆΠ΄Ρƒ modes. + +## ΠŸΡ€ΠΎΠ²Π΅Ρ€ΠΊΠ° Ρ€Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚Π° + +ПослС измСнСния ΠΊΠΎΠ½Ρ„ΠΈΠ³Π° ΠΈΠ»ΠΈ SVG Π²Ρ‹ΠΏΠΎΠ»Π½ΠΈ ΠΎΠ±ΡΠ·Π°Ρ‚Π΅Π»ΡŒΠ½Ρ‹Π΅ ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΊΠΈ: + +1. Запусти Ρ‚ΠΎΡ‡Π½ΡƒΡŽ sprite-ΠΊΠΎΠΌΠ°Π½Π΄Ρƒ. ΠŸΡ€ΠΎΡ†Π΅ΡΡ Π΄ΠΎΠ»ΠΆΠ΅Π½ Π·Π°Π²Π΅Ρ€ΡˆΠΈΡ‚ΡŒΡΡ с ΠΊΠΎΠ΄ΠΎΠΌ `0` ΠΈ ΡΠΎΠΎΠ±Ρ‰ΠΈΡ‚ΡŒ имя, число ΠΈΠΊΠΎΠ½ΠΎΠΊ, mode ΠΈ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ `.svg-sprite`. +2. ΠŸΡ€ΠΎΠ²Π΅Ρ€ΡŒ output Π²Ρ‹Π±Ρ€Π°Π½Π½ΠΎΠ³ΠΎ exact mode: + - bare `standalone` создаёт `sprite.svg` ΠΈ `svg-sprite.manifest.json`; + - `standalone@server` создаёт Π΄Π²Π° content-addressed SVG profiles ΠΈ server manifest, hashes ΠΈ relative paths ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠ³ΠΎ ΡΠΎΠΎΡ‚Π²Π΅Ρ‚ΡΡ‚Π²ΡƒΡŽΡ‚ этим Ρ„Π°ΠΉΠ»Π°ΠΌ; + - `standalone@vite` ΠΈ `standalone@webpack` Π΄ΠΎΠΏΠΎΠ»Π½ΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ ΡΠΎΠ·Π΄Π°ΡŽΡ‚ `index.*`, `icon-data.*` ΠΈ JS manifest, Π½ΠΎ Π½Π΅ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ `react/`; + - framework modes Ρ‚Π°ΠΊΠΆΠ΅ ΡΠΎΠ·Π΄Π°ΡŽΡ‚ adapter-owned runtime Π½Π°Ρ‚ΠΈΠ²Π½ΠΎΠ³ΠΎ ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚Π°, declaration ΠΈ styles. +3. Для modes с public facade ΠΏΡ€ΠΎΠ²Π΅Ρ€ΡŒ `.svg-sprite/index.js`, сосСдний `index.d.ts`, список ΠΈΠΌΡ‘Π½ ΠΈ фактичСский ΠΈΠΌΠΏΠΎΡ€Ρ‚ Ρ‡Π΅Ρ€Π΅Π· ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒΡΠΊΠΈΠΉ barrel. +4. ΠŸΡ€ΠΎΠ²Π΅Ρ€ΡŒ manifest: mode ΠΈ target Π΄ΠΎΠ»ΠΆΠ½Ρ‹ ΡΠΎΠΎΡ‚Π²Π΅Ρ‚ΡΡ‚Π²ΠΎΠ²Π°Ρ‚ΡŒ Π²Ρ‹Π±Ρ€Π°Π½Π½ΠΎΠΌΡƒ adapter, Π° список ΠΈΠΊΠΎΠ½ΠΎΠΊ β€” исходным SVG. Π’ bundler modes URL Π΄ΠΎΠ»ΠΆΠ΅Π½ Ρ„ΠΎΡ€ΠΌΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒΡΡ mode-specific способом; bare JSON manifest Π½Π°ΠΌΠ΅Ρ€Π΅Π½Π½ΠΎ Π½Π΅ содСрТит ΠΏΡƒΠ±Π»ΠΈΡ‡Π½ΠΎΠ³ΠΎ `spriteUrl`. +5. Запусти ΡΡƒΡ‰Π΅ΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΠΉ typecheck ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π°, Ссли mode создаёт Ρ‚ΠΈΠΏΡ‹ ΠΈΠ»ΠΈ измСнился ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒΡΠΊΠΈΠΉ TypeScript-ΠΊΠΎΠ΄. +6. Запусти ΠΌΠΈΠ½ΠΈΠΌΠ°Π»ΡŒΠ½ΡƒΡŽ ΠΊΠΎΠΌΠ°Π½Π΄Ρƒ прилоТСния, Π·Π°Ρ‚Ρ€ΠΎΠ½ΡƒΡ‚ΡƒΡŽ ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΠ΅ΠΌ: `dev`, build ΠΈΠ»ΠΈ ΡΠΏΠ΅Ρ†ΠΈΠ°Π»ΠΈΠ·ΠΈΡ€ΠΎΠ²Π°Π½Π½ΡƒΡŽ ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΊΡƒ ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π°. + +НС запускай ΠΏΠΎΠ»Π½ΡƒΡŽ production-сборку Ρ‚ΠΎΠ»ΡŒΠΊΠΎ Ρ€Π°Π΄ΠΈ ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΊΠΈ Π½ΠΎΠ²ΠΎΠ³ΠΎ ΠΈΠΌΠ΅Π½ΠΈ ΠΈΠΊΠΎΠ½ΠΊΠΈ. Она Π½ΡƒΠΆΠ½Π°, Ссли мСнялся bundler target, router, Webpack loader, asset URL, deployment path ΠΈΠ»ΠΈ диагностируСтся production-only ошибка. + +Π’ΠΈΠ·ΡƒΠ°Π»ΡŒΠ½ΡƒΡŽ ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΊΡƒ, Network ΠΈ accessibility tree выполняй Ρ‚ΠΎΠ»ΡŒΠΊΠΎ ΠΏΡ€ΠΈ Π½Π°Π»ΠΈΡ‡ΠΈΠΈ Π·Π°ΠΏΡƒΡ‰Π΅Π½Π½ΠΎΠ³ΠΎ прилоТСния ΠΈ Π±Ρ€Π°ΡƒΠ·Π΅Ρ€Π½Ρ‹Ρ… инструмСнтов. Если Ρ‚Π°ΠΊΠΈΡ… инструмСнтов Π½Π΅Ρ‚, Π½Π΅ ΡƒΡ‚Π²Π΅Ρ€ΠΆΠ΄Π°ΠΉ, Ρ‡Ρ‚ΠΎ Ρ†Π²Π΅Ρ‚Π°, Ρ‚Π΅ΠΌΡ‹, Π΄ΠΎΡΡ‚ΡƒΠΏΠ½ΠΎΡΡ‚ΡŒ ΠΈΠ»ΠΈ HTTP-ΠΎΡ‚Π²Π΅Ρ‚ asset ΠΏΡ€ΠΎΠ²Π΅Ρ€Π΅Π½Ρ‹; явно ΡƒΠΊΠ°ΠΆΠΈ Π½Π΅ΠΏΡ€ΠΎΠ²Π΅Ρ€Π΅Π½Π½ΡƒΡŽ Ρ‡Π°ΡΡ‚ΡŒ. + +Viewer ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉ для слоТных Ρ†Π²Π΅Ρ‚ΠΎΠ², transforms ΠΈ массовой Π²ΠΈΠ·ΡƒΠ°Π»ΡŒΠ½ΠΎΠΉ ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΊΠΈ. НС добавляй debug route Ρ€Π°Π΄ΠΈ ΠΎΠ±Ρ‹Ρ‡Π½ΠΎΠΉ Π³Π΅Π½Π΅Ρ€Π°Ρ†ΠΈΠΈ ΠΎΠ΄Π½ΠΎΠ³ΠΎ спрайта. + +## Диагностика + +Π‘ΠΎΠΏΠΎΡΡ‚Π°Π²ΡŒ симптом с ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΊΠΎΠΉ ΠΈ исправляй ΠΏΠ΅Ρ€Π²ΠΎΠΏΡ€ΠΈΡ‡ΠΈΠ½Ρƒ: + +| Π‘ΠΈΠΌΠΏΡ‚ΠΎΠΌ | ВСроятная ΠΏΡ€ΠΈΡ‡ΠΈΠ½Π° | ДСйствиС | +|---|---|---| +| `Missing sprite config file or module directory` | НС ΠΏΠ΅Ρ€Π΅Π΄Π°Π½ ΠΏΠΎΠ·ΠΈΡ†ΠΈΠΎΠ½Π½Ρ‹ΠΉ ΠΏΡƒΡ‚ΡŒ | ΠŸΠ΅Ρ€Π΅Π΄Π°ΠΉ ΠΎΠ΄ΠΈΠ½ config-Ρ„Π°ΠΉΠ» Π»ΠΈΠ±ΠΎ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ для config-less запуска. | +| `Expected one config file or module directory` | ΠŸΠ΅Ρ€Π΅Π΄Π°Π½ΠΎ нСсколько ΠΏΡƒΡ‚Π΅ΠΉ | Π‘ΠΎΠ·Π΄Π°ΠΉ ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½ΡƒΡŽ ΠΊΠΎΠΌΠ°Π½Π΄Ρƒ Π½Π° ΠΊΠ°ΠΆΠ΄Ρ‹ΠΉ спрайт ΠΈ объСдини scripts. | +| `Sprite mode is required` | Mode отсутствуСт ΠΈ Π² config, ΠΈ Π² CLI | Π”ΠΎΠ±Π°Π²ΡŒ `mode` Π² ΠΎΠ±ΡŠΠ΅ΠΊΡ‚ ΠΈΠ»ΠΈ ΠΏΠ΅Ρ€Π΅Π΄Π°ΠΉ ΠΏΠΎΠ»Π½Ρ‹ΠΉ `--mode`. | +| `Unsupported sprite config extension` | ΠŸΠ΅Ρ€Π΅Π΄Π°Π½ Ρ„Π°ΠΉΠ» Π½Π΅ `.ts`, `.js` ΠΈΠ»ΠΈ `.json` | Π˜ΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΈΠ²Π°Π΅ΠΌΡ‹ΠΉ Ρ„ΠΎΡ€ΠΌΠ°Ρ‚ config-Ρ„Π°ΠΉΠ»Π°. | +| Positive input-источник Π½Π΅ Π½Π°ΡˆΡ‘Π» SVG | Папка отсутствуСт ΠΈΠ»ΠΈ пуста, glob Π½Π΅ совпал Π»ΠΈΠ±ΠΎ Ρ‚ΠΎΡ‡Π½Ρ‹ΠΉ ΠΏΡƒΡ‚ΡŒ отсутствуСт ΠΈΠ»ΠΈ Π²Π΅Π΄Ρ‘Ρ‚ Π½Π΅ ΠΊ SVG | Π Π°Π·Ρ€Π΅ΡˆΠΈ источник ΠΎΡ‚ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³Π° ΠΊΠΎΠ½Ρ„ΠΈΠ³Π° ΠΈ ΠΈΡΠΏΡ€Π°Π²ΡŒ `input`; ΠΊΠ°ΠΆΠ΄Ρ‹ΠΉ positive-элСмСнт Π΄ΠΎΠ»ΠΆΠ΅Π½ Π΄Π°Ρ‚ΡŒ хотя Π±Ρ‹ ΠΎΠ΄ΠΈΠ½ SVG. | +| Иконки ΠΈΠ· ΠΏΠΎΠ΄ΠΏΠ°ΠΏΠΊΠΈ Π½Π΅ появились | ΠžΡ‚ ΠΏΠ°ΠΏΠΊΠΈ оТидалось рСкурсивноС сканированиС | Π˜ΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉ явный glob, Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€ `./icons/**/*.svg`; ΠΏΠ°ΠΏΠΊΠΈ ΡΠΊΠ°Π½ΠΈΡ€ΡƒΡŽΡ‚ΡΡ плоско. | +| Π˜ΡΠΊΠ»ΡŽΡ‡Ρ‘Π½Π½Π°Ρ ΠΈΠΊΠΎΠ½ΠΊΠ° всё Π΅Ρ‰Ρ‘ присутствуСт | Π£ ΠΈΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΡ Π½Π΅Ρ‚ прСфикса `!`, ΠΎΠ½ΠΎ находится Π½Π΅ Π² массивС `input` ΠΈΠ»ΠΈ считаСтся Π½Π΅ ΠΎΡ‚ Ρ‚ΠΎΠ³ΠΎ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³Π° | Π”ΠΎΠ±Π°Π²ΡŒ ΡΠΎΠ²ΠΏΠ°Π΄Π°ΡŽΡ‰ΠΈΠΉ `!`-элСмСнт ΠΈ считай Π΅Π³ΠΎ ΠΎΡ‚ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³Π° ΠΊΠΎΠ½Ρ„ΠΈΠ³Π°. | +| CLI Π²Ρ‹Π±Ρ€Π°Π» Π½Π΅ всС источники | НСсколько источников помСстили Π² ΠΎΠ΄Π½ΠΎ Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ `--input` ΠΈΠ»ΠΈ пропустили option | ΠŸΠΎΠ²Ρ‚ΠΎΡ€ΠΈ `--input ` ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½ΠΎ для ΠΊΠ°ΠΆΠ΄ΠΎΠ³ΠΎ источника ΠΈΠ»ΠΈ ΠΈΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΡ. | +| ΠšΠΎΠ½Ρ„Π»ΠΈΠΊΡ‚ ΠΈΠΌΠ΅Π½ΠΈ ΠΈΠΊΠΎΠ½ΠΊΠΈ ΠΈΠ»ΠΈ SVG ID | Π”Π²Π° Ρ€Π°Π·Π½Ρ‹Ρ… Ρ„Π°ΠΉΠ»Π° ΠΈΠΌΠ΅ΡŽΡ‚ ΠΎΠ΄ΠΈΠ½Π°ΠΊΠΎΠ²Ρ‹ΠΉ basename Π»ΠΈΠ±ΠΎ hash-ID столкнулся с ΠΈΠΌΠ΅Π½Π΅ΠΌ | ΠŸΠ΅Ρ€Π΅ΠΈΠΌΠ΅Π½ΡƒΠΉ ΠΎΠ΄ΠΈΠ½ исходный SVG; Π½Π΅ Π²Ρ‹Π±ΠΈΡ€Π°ΠΉ Ρ„Π°ΠΉΠ» нСявно. | +| `Refusing to overwrite a user file` | Π’ ΠΊΠΎΡ€Π½Π΅ sprite-модуля ΡƒΠΆΠ΅ Π΅ΡΡ‚ΡŒ ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒΡΠΊΠΈΠΉ `.gitignore`, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ mode Π΄ΠΎΠ»ΠΆΠ΅Π½ ΡΠΎΠ·Π΄Π°Ρ‚ΡŒ | НС пСрСзаписывай Ρ„Π°ΠΉΠ»: Π²Ρ‹Π±Π΅Ρ€ΠΈ Π΄Ρ€ΡƒΠ³ΠΎΠΉ sprite-ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ ΠΈΠ»ΠΈ согласуй пСрСнос ΡΡƒΡ‰Π΅ΡΡ‚Π²ΡƒΡŽΡ‰Π΅Π³ΠΎ `.gitignore`. | +| НСт `.svg-sprite/index.js` ΠΈΠ»ΠΈ имя отсутствуСт Π² autocomplete | Для bare `standalone` это ΠΎΠΆΠΈΠ΄Π°Π΅ΠΌΠΎ; Π² ΠΎΡΡ‚Π°Π»ΡŒΠ½Ρ‹Ρ… modes гСнСрация Π½Π΅ Π·Π°ΠΏΡƒΡΠΊΠ°Π»Π°ΡΡŒ, barrel Π½Π΅Π²Π΅Ρ€Π΅Π½ Π»ΠΈΠ±ΠΎ type server Π΄Π΅Ρ€ΠΆΠΈΡ‚ старый ΠΌΠΎΠ΄ΡƒΠ»ΡŒ | Π‘Π²Π΅Ρ€ΡŒ exact mode, запусти sprite-ΠΊΠΎΠΌΠ°Π½Π΄Ρƒ, ΠΏΡ€ΠΎΠ²Π΅Ρ€ΡŒ `export * from './.svg-sprite/index.js'`, Π·Π°Ρ‚Π΅ΠΌ typecheck; ΠΏΡ€ΠΈ нСобходимости пСрСзапусти TypeScript server. | +| SVG Π½Π΅ загруТаСтся ΠΈΠ»ΠΈ URL Π½Π΅Π²Π΅Ρ€Π΅Π½ | Mode Π½Π΅ совпадаСт со сборщиком, Π½Π΅Π²Π΅Ρ€Π΅Π½ Webpack `publicPath` Π»ΠΈΠ±ΠΎ кастомный loader ΠΏΠ΅Ρ€Π΅Ρ…Π²Π°Ρ‚ΠΈΠ» asset | Π‘Π²Π΅Ρ€ΡŒ mode ΠΈ build-ΠΊΠΎΠΌΠ°Π½Π΄Ρƒ, ΠΏΡ€ΠΎΠ²Π΅Ρ€ΡŒ Asset Modules/`publicPath`, ΠΈΡΠΊΠ»ΡŽΡ‡ΠΈ generated SVG ΠΈΠ· нСсовмСстимого loader. | +| Next build расходится ΠΌΠ΅ΠΆΠ΄Ρƒ SSR ΠΈ Π±Ρ€Π°ΡƒΠ·Π΅Ρ€ΠΎΠΌ | ΠœΠΎΠ΄ΡƒΠ»ΡŒ сгСнСрирован для Π΄Ρ€ΡƒΠ³ΠΎΠ³ΠΎ bundler/router ΠΈΠ»ΠΈ URL пСрСписан Π²Ρ€ΡƒΡ‡Π½ΡƒΡŽ | Π’Π΅Ρ€Π½ΠΈ generated `new URL(...)`, Π²Ρ‹Π±Π΅Ρ€ΠΈ Ρ‚ΠΎΡ‡Π½Ρ‹ΠΉ Next mode ΠΈ ΠΏΠ΅Ρ€Π΅Π³Π΅Π½Π΅Ρ€ΠΈΡ€ΡƒΠΉ. | +| `color` Π½Π΅ мСняСт ΠΌΠ½ΠΎΠ³ΠΎΡ†Π²Π΅Ρ‚Π½ΡƒΡŽ ΠΈΠΊΠΎΠ½ΠΊΡƒ | Π£ ΠΈΠΊΠΎΠ½ΠΊΠΈ нСсколько ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Ρ… ΠΈΠ»ΠΈ ΠΎΠ½Π° ΠΏΠΎΠΊΠ°Π·Π°Π½Π° Ρ‡Π΅Ρ€Π΅Π· ``/CSS background | Π˜ΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉ ``/`` ΠΈ Π½ΡƒΠΆΠ½Ρ‹Π΅ `--icon-color-N`. | +| Gradient/filter выглядит Π½Π΅Π²Π΅Ρ€Π½ΠΎ | АвтозамСна Ρ†Π²Π΅Ρ‚ΠΎΠ² Π½Π΅ Π³Π°Ρ€Π°Π½Ρ‚ΠΈΡ€ΡƒΠ΅Ρ‚ слоТныС paint servers | Π˜Π·ΡƒΡ‡ΠΈ generated SVG; ΠΏΡ€ΠΈ нСобходимости ΠΎΡ‚ΠΊΠ»ΡŽΡ‡ΠΈ `replaceColors` для спрайта ΠΈΠ»ΠΈ упрости источник. | +| Viewer пуст | Manifest Π½Π΅ создан, loader Π½Π΅ ΠΎΠ±Π½Π°Ρ€ΡƒΠΆΠ΅Π½ сборщиком ΠΈΠ»ΠΈ Π½Π΅Π²Π΅Ρ€Π½Π° Client Component boundary | Π‘Π½Π°Ρ‡Π°Π»Π° сгСнСрируй спрайт, Π·Π°Ρ‚Π΅ΠΌ ΡΠ²Π΅Ρ€ΡŒ manifest import ΠΈ способ ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΡ с exact guide; Π² App Router ΠΎΡΡ‚Π°Π²ΡŒ `'use client'` Ρ‚ΠΎΠ»ΡŒΠΊΠΎ Π² ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚Π΅ Viewer. | +| Remote manifest ΠΎΡ‚ΠΊΠ»ΠΎΠ½Ρ‘Π½ | Π­Ρ‚ΠΎ Π½Π΅ schema `standalone@server`, profile path нСбСзопасСн ΠΈΠ»ΠΈ metadata ΠΏΡ€ΠΎΡ‚ΠΈΠ²ΠΎΡ€Π΅Ρ‡ΠΈΠ²Ρ‹ | ΠžΠΏΡƒΠ±Π»ΠΈΠΊΡƒΠΉ Π½Π΅ΠΈΠ·ΠΌΠ΅Π½Ρ‘Π½Π½Ρ‹ΠΉ ΠΏΠΎΠ»Π½Ρ‹ΠΉ server release ΠΈ Π½Π°ΠΏΡ€Π°Π²ΡŒ `input` Π½Π° Π΅Π³ΠΎ JSON manifest. | +| НС ΠΏΡ€ΠΎΡˆΠ»Π° integrity-ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΊΠ° remote sprite | SVG устарСл, ΠΎΠ±Ρ€Π΅Π·Π°Π½ ΠΈΠ»ΠΈ ΠΈΠ·ΠΌΠ΅Π½Ρ‘Π½ ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½ΠΎ ΠΎΡ‚ manifest | Атомарно ΠΏΠ΅Ρ€Π΅ΠΎΠΏΡƒΠ±Π»ΠΈΠΊΡƒΠΉ manifest ΠΈ ΠΎΠ±Π° content-addressed profiles; Π½ΠΈΠΊΠΎΠ³Π΄Π° Π½Π΅ пСрСзаписывай hashed SVG Π΄Ρ€ΡƒΠ³ΠΈΠΌΠΈ Π±Π°ΠΉΡ‚Π°ΠΌΠΈ. | + +ΠŸΡ€ΠΈ нСизвСстной ошибкС зафиксируй ΠΏΠΎΠ»Π½ΡƒΡŽ CLI-ΠΊΠΎΠΌΠ°Π½Π΄Ρƒ, mode, ΠΏΡƒΡ‚ΡŒ ΠΊ config-Ρ„Π°ΠΉΠ»Ρƒ ΠΈΠ»ΠΈ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³Ρƒ ΠΈ ΠΏΠ΅Ρ€Π²Ρ‹ΠΉ stack/error message. Π—Π°Ρ‚Π΅ΠΌ минимально воспроизвСди ΠΏΡ€ΠΎΠ±Π»Π΅ΠΌΡƒ Π½Π° ΠΎΠ΄Π½ΠΎΠΌ спрайтС, Π½Π΅ удаляя ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒΡΠΊΠΈΠ΅ Ρ„Π°ΠΉΠ»Ρ‹ ΠΈ управляСмый `.gitignore`. + +## ΠšΠ°Ρ€Ρ‚Π° reference-Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚Π°Ρ†ΠΈΠΈ + +References ΡΠ²Π»ΡΡŽΡ‚ΡΡ Ρ‡Π°ΡΡ‚ΡŒΡŽ собранного skill. ΠžΡ‚ΠΊΡ€Ρ‹Π²Π°ΠΉ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚Ρ‹, относящиСся ΠΊ Ρ‚Π΅ΠΊΡƒΡ‰Π΅ΠΉ Π·Π°Π΄Π°Ρ‡Π΅, Π½ΠΎ ΠΏΠ΅Ρ€Π΅Π΄ ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΠ΅ΠΌ ΠΈΠ½Ρ‚Π΅Π³Ρ€Π°Ρ†ΠΈΠΈ exact-mode guide обязатСлСн. + +### ΠžΠ±Π·ΠΎΡ€ + +- [README ΠΏΠ°ΠΊΠ΅Ρ‚Π°](./references/README_RU.md) β€” возмоТности, основной React/Next.js ΠΏΡ€ΠΈΠΌΠ΅Ρ€, всС ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΈΠ²Π°Π΅ΠΌΡ‹Π΅ families ΠΈ ссылки Π½Π° Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚Π°Ρ†ΠΈΡŽ. + +### ΠšΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ†ΠΈΡ + +- [ΠšΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ†ΠΈΡ](./references/docs/ru/configuration.md) β€” JSON, JavaScript, TypeScript, поля config, `input` ΠΈ запуск CLI. + +### Exact-mode guides + +- [`standalone`](./references/docs/ru/guides/standalone.md) β€” static HTML ΠΈ собствСнная публикация SVG. +- [`standalone@vite`](./references/docs/ru/guides/standalone-vite.md) β€” vanilla-ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠ΅ с Vite ΠΈ Web Component. +- [`standalone@webpack`](./references/docs/ru/guides/standalone-webpack.md) β€” vanilla-ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠ΅ с Webpack 5 ΠΈ Web Component. +- [`standalone@server`](./references/docs/ru/guides/standalone-server.md) β€” Ρ†Π΅Π½Ρ‚Ρ€Π°Π»ΠΈΠ·ΠΎΠ²Π°Π½Π½Ρ‹ΠΉ content-addressed release ΠΈ remote consumers. +- [`react@vite`](./references/docs/ru/guides/react-vite.md) β€” React с Vite. +- [`react@webpack`](./references/docs/ru/guides/react-webpack.md) β€” React с Webpack 5. +- [`vue@vite`](./references/docs/ru/guides/vue-vite.md) β€” Vue с Vite. +- [`vue@webpack`](./references/docs/ru/guides/vue-webpack.md) β€” Vue с Webpack. +- [`nuxt@vite`](./references/docs/ru/guides/nuxt-vite.md) β€” Nuxt с Vite. +- [`nuxt@webpack`](./references/docs/ru/guides/nuxt-webpack.md) β€” Nuxt с Webpack. +- [`svelte@vite`](./references/docs/ru/guides/svelte-vite.md) β€” Svelte с Vite. +- [`svelte@webpack`](./references/docs/ru/guides/svelte-webpack.md) β€” Svelte с Webpack. +- [`sveltekit@vite`](./references/docs/ru/guides/sveltekit-vite.md) β€” SvelteKit с Vite. +- [`angular@application`](./references/docs/ru/guides/angular-application.md) β€” Angular application builder. +- [`angular@webpack`](./references/docs/ru/guides/angular-webpack.md) β€” Angular с Webpack. +- [`astro@vite`](./references/docs/ru/guides/astro-vite.md) β€” Astro с Vite. +- [`solid@vite`](./references/docs/ru/guides/solid-vite.md) β€” Solid с Vite. +- [`solid@webpack`](./references/docs/ru/guides/solid-webpack.md) β€” Solid с Webpack. +- [`solid-start@vite`](./references/docs/ru/guides/solid-start-vite.md) β€” SolidStart с Vite. +- [`preact@vite`](./references/docs/ru/guides/preact-vite.md) β€” Preact с Vite. +- [`preact@webpack`](./references/docs/ru/guides/preact-webpack.md) β€” Preact с Webpack. +- [`qwik@vite`](./references/docs/ru/guides/qwik-vite.md) β€” Qwik с Vite. +- [`lit@vite`](./references/docs/ru/guides/lit-vite.md) β€” Lit с Vite. +- [`lit@webpack`](./references/docs/ru/guides/lit-webpack.md) β€” Lit с Webpack. +- [`alpine@vite`](./references/docs/ru/guides/alpine-vite.md) β€” Alpine.js с Vite. +- [`alpine@webpack`](./references/docs/ru/guides/alpine-webpack.md) β€” Alpine.js с Webpack. +- [`next@app/turbopack`](./references/docs/ru/guides/next-app-turbopack.md) β€” Next.js App Router с Turbopack. +- [`next@app/webpack`](./references/docs/ru/guides/next-app-webpack.md) β€” Next.js App Router с Webpack. +- [`next@pages/turbopack`](./references/docs/ru/guides/next-pages-turbopack.md) β€” Next.js Pages Router с Turbopack. +- [`next@pages/webpack`](./references/docs/ru/guides/next-pages-webpack.md) β€” Next.js Pages Router с Webpack. + +### ВСхничСскиС справочники + +- [ВСхничСский справочник](./references/docs/ru/reference/technical.md) β€” requirements, CLI, naming, generated API, assets, transforms, Ρ†Π²Π΅Ρ‚Π°, Viewer, Git, CI ΠΈ диагностика. +- [ΠŸΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½Ρ‹ΠΉ API](./references/docs/ru/reference/programmatic-api.md) β€” `generateSprite`, overrides, config API, compiler ΠΈ Viewer runtime. + +### Agent-specific reference + +- [Π‘Π»ΠΎΠΆΠ½Ρ‹Π΅ SVG](./references/complex-svg.md) β€” gradients, patterns, filters, masks, `url(#...)`, `viewBox`, fragment IDs ΠΈ Π²ΠΈΠ·ΡƒΠ°Π»ΡŒΠ½Π°Ρ диагностика. diff --git a/skills/svg-sprites-ru/references/README_RU.md b/skills/svg-sprites-ru/references/README_RU.md new file mode 100644 index 0000000..5c2b0f3 --- /dev/null +++ b/skills/svg-sprites-ru/references/README_RU.md @@ -0,0 +1,303 @@ +# @gromlab/svg-sprites + +[πŸ‡¬πŸ‡§ English](https://github.com/gromlab-ru/svg-sprites/blob/master/README.md) | πŸ‡·πŸ‡Ί Русский + +![npm](https://img.shields.io/npm/v/@gromlab/svg-sprites) ![license](https://img.shields.io/npm/l/@gromlab/svg-sprites) + +`@gromlab/svg-sprites` β€” CLI-инструмСнт для Π³Π΅Π½Π΅Ρ€Π°Ρ†ΠΈΠΈ SVG-спрайтов Π² соврСмСнных Π²Π΅Π±-прилоТСниях. Он собираСт Π²Ρ‹Π±Ρ€Π°Π½Π½Ρ‹Π΅ SVG-ΠΈΠΊΠΎΠ½ΠΊΠΈ Π² ΠΎΠ΄ΠΈΠ½ ΠΈΠ»ΠΈ нСсколько Π²Π½Π΅ΡˆΠ½ΠΈΡ… ΠΊΠ΅ΡˆΠΈΡ€ΡƒΠ΅ΠΌΡ‹Ρ… спрайтов ΠΈ ΠΏΠΎΠ΄Π³ΠΎΡ‚Π°Π²Π»ΠΈΠ²Π°Π΅Ρ‚ ΠΈΡ… для использования Π² интСрфСйсС. + +ΠšΠ°ΠΆΠ΄Ρ‹ΠΉ exact mode создаёт Π½Π°Ρ‚ΠΈΠ²Π½Ρ‹ΠΉ Ρ‚ΠΈΠΏΠΈΠ·ΠΈΡ€ΠΎΠ²Π°Π½Π½Ρ‹ΠΉ ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ для своСго framework ΠΈ bundler: Web Component, React, Vue, Svelte, Angular, Astro, Solid, Preact, Qwik, Lit ΠΈΠ»ΠΈ Alpine.js. SVG Π²ΠΎ всСх случаях остаётся ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½Ρ‹ΠΌ ΠΊΠ΅ΡˆΠΈΡ€ΡƒΠ΅ΠΌΡ‹ΠΌ asset. + +## SVG-спрайт Ρ‚Π°ΠΊ ΠΆΠ΅ прост, ΠΊΠ°ΠΊ обычная SVG-ΠΈΠΊΠΎΠ½ΠΊΠ° + +Для всСго спрайта гСнСрируСтся ΠΎΠ΄ΠΈΠ½ Ρ‚ΠΈΠΏΠΈΠ·ΠΈΡ€ΠΎΠ²Π°Π½Π½Ρ‹ΠΉ React-ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚. Π’Ρ‹Π±Π΅Ρ€ΠΈΡ‚Π΅ ΠΈΠΊΠΎΠ½ΠΊΡƒ Ρ‡Π΅Ρ€Π΅Π· `icon`, Π° Ρ€Π΅Π΄Π°ΠΊΡ‚ΠΎΡ€ ΠΏΠΎΠΊΠ°ΠΆΠ΅Ρ‚ Π°Π²Ρ‚ΠΎΠΊΠΎΠΌΠΏΠ»ΠΈΡ‚ всСх доступных ΠΈΠΌΡ‘Π½. + +```tsx + +``` + +ΠšΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ ΠΏΡ€ΠΈΠ½ΠΈΠΌΠ°Π΅Ρ‚ ΠΏΡ€ΠΈΠ²Ρ‹Ρ‡Π½Ρ‹Π΅ SVG-Π°Ρ‚Ρ€ΠΈΠ±ΡƒΡ‚Ρ‹: Ρ€Π°Π·ΠΌΠ΅Ρ€Ρ‹, `color`, `className`, `style`, `aria-*` ΠΈ ΠΎΠ±Ρ€Π°Π±ΠΎΡ‚Ρ‡ΠΈΠΊΠΈ событий. Если Π½ΡƒΠΆΠ΅Π½ внСшний ΠΊΠΎΠ½Ρ‚Π΅ΠΉΠ½Π΅Ρ€, Π΄ΠΎΠ±Π°Π²ΡŒΡ‚Π΅ `wrapped`. + +```tsx + +``` + +Π’ ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠΈ Π½Π΅ приходится Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ со спрайтом Π½Π°ΠΏΡ€ΡΠΌΡƒΡŽ. Π’Ρ‹ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚Π΅ Π΅Π³ΠΎ Ρ‚Π°ΠΊ ΠΆΠ΅, ΠΊΠ°ΠΊ ΠΎΠ±Ρ‹Ρ‡Π½ΡƒΡŽ SVG-ΠΈΠΊΠΎΠ½ΠΊΡƒ, Π½ΠΎ ΠΏΠΎΠ»ΡƒΡ‡Π°Π΅Ρ‚Π΅ ΠΎΠ΄ΠΈΠ½ ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚, Π°Π²Ρ‚ΠΎΠΊΠΎΠΌΠΏΠ»ΠΈΡ‚ ΠΈ TypeScript-ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΊΡƒ всСх ΠΈΠΌΡ‘Π½. + +## AI-friendly ΠΈΠ· ΠΊΠΎΡ€ΠΎΠ±ΠΊΠΈ + +`@gromlab/svg-sprites` сразу рассчитан Π½Π° Ρ€Π°Π±ΠΎΡ‚Ρƒ с AI-Π°Π³Π΅Π½Ρ‚Π°ΠΌΠΈ. ΠŸΠΎΠ΄ΠΊΠ»ΡŽΡ‡ΠΈΡ‚Π΅ Π³ΠΎΡ‚ΠΎΠ²Ρ‹ΠΉ skill ΠΈ ΠΏΠΎΡ€ΡƒΡ‡ΠΈΡ‚Π΅ Π°Π³Π΅Π½Ρ‚Ρƒ настройку, ΠΌΠΈΠ³Ρ€Π°Ρ†ΠΈΡŽ ΠΈΠ»ΠΈ диагностику Π±Π΅Π· Π΄Π»ΠΈΠ½Π½Ρ‹Ρ… инструкций ΠΈ Ρ€ΡƒΡ‡Π½ΠΎΠ³ΠΎ изучСния Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚Π°Ρ†ΠΈΠΈ. + +Π£ΡΡ‚Π°Π½ΠΎΠ²ΠΈΡ‚ΡŒ русскоязычный skill: + +```bash +npx skills add gromlab-ru/svg-sprites --skill svg-sprites-ru +``` + +Π£ΡΡ‚Π°Π½ΠΎΠ²ΠΈΡ‚ΡŒ англоязычный skill: + +```bash +npx skills add gromlab-ru/svg-sprites --skill svg-sprites +``` + +## ΠžΡ‚ SVG Π΄ΠΎ ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚Π° Π·Π° Ρ‚Ρ€ΠΈ шага + +Основной ΠΏΡ€ΠΈΠΌΠ΅Ρ€ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ Next.js App Router ΠΈ Turbopack. + +### 1. Π£ΠΊΠ°ΠΆΠΈΡ‚Π΅ Π½ΡƒΠΆΠ½Ρ‹Π΅ ΠΈΠΊΠΎΠ½ΠΊΠΈ + +Π‘ΠΎΠ·Π΄Π°ΠΉΡ‚Π΅ ΠΏΠ°ΠΏΠΊΠΈ для исходных ΠΈΠΊΠΎΠ½ΠΎΠΊ ΠΈ спрайта: + +```text +assets/ +β”œβ”€β”€ app-icons/ +β”‚ └── svg-sprite.config.json +└── svg-icons/ + β”œβ”€β”€ search.svg + └── settings.svg +``` + +Π‘ΠΎΠ·Π΄Π°ΠΉΡ‚Π΅ ΠΊΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ†ΠΈΡŽ спрайта: + +```json +{ + "mode": "next@app/turbopack", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +`input` ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΈΠ²Π°Π΅Ρ‚ ΠΏΡƒΡ‚ΠΈ ΠΊ ΠΏΠ°ΠΏΠΊΠ°ΠΌ, ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½Ρ‹ΠΌ SVG ΠΈ glob-ΡˆΠ°Π±Π»ΠΎΠ½Ρ‹. + +### 2. Π”ΠΎΠ±Π°Π²ΡŒΡ‚Π΅ Π³Π΅Π½Π΅Ρ€Π°Ρ†ΠΈΡŽ + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "predev": "npm run sprites", + "prebuild": "npm run sprites" + } +} +``` + +Π‘ΠΎΠ·Π΄Π°ΠΉΡ‚Π΅ Ρ‚ΠΎΡ‡ΠΊΡƒ Π²Ρ…ΠΎΠ΄Π° для сгСнСрированного API: + +```ts +// assets/app-icons/index.ts +export * from './.svg-sprite/index.js' +``` + +ΠŸΠ΅Ρ€Π²Ρ‹ΠΉ запуск: + +```bash +npm run sprites +``` + +ΠŸΠ°ΠΊΠ΅Ρ‚ создаст `AppIcon`, TypeScript-Ρ‚ΠΈΠΏΡ‹ ΠΈ ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½Ρ‹ΠΉ SVG-спрайт. + +### 3. Π˜ΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ ΠΊΠ°ΠΊ ΠΎΠ±Ρ‹Ρ‡Π½ΡƒΡŽ ΠΈΠΊΠΎΠ½ΠΊΡƒ + +```tsx +// app/page.tsx +import { AppIcon } from '../assets/app-icons' + +export default function SearchButton() { + return ( + + ) +} +``` + +Π­Ρ‚ΠΎ Server Component. Для ΠΈΠΊΠΎΠ½ΠΊΠΈ Π½Π΅ Π½ΡƒΠΆΠ½Ρ‹ provider, `'use client'` ΠΈΠ»ΠΈ ручная сборка URL. + +## Π’ΠΈΠΏΠΈΠ·ΠΈΡ€ΠΎΠ²Π°Π½Π½Ρ‹ΠΉ React-ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ с Π°Π²Ρ‚ΠΎΠΊΠΎΠΌΠΏΠ»ΠΈΡ‚ΠΎΠΌ + +ΠšΠ°ΠΆΠ΄Ρ‹ΠΉ спрайт ΠΏΠΎΠ»ΡƒΡ‡Π°Π΅Ρ‚ собствСнный Π³ΠΎΡ‚ΠΎΠ²Ρ‹ΠΉ ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚. Бвойство `icon` формируСтся ΠΈΠ· Ρ€Π΅Π°Π»ΡŒΠ½Ρ‹Ρ… ΠΈΠΌΡ‘Π½ SVG, поэтому Ρ€Π΅Π΄Π°ΠΊΡ‚ΠΎΡ€ ΠΏΠΎΠΊΠ°Π·Ρ‹Π²Π°Π΅Ρ‚ Ρ‚ΠΎΡ‡Π½Ρ‹ΠΉ список доступных ΠΈΠΊΠΎΠ½ΠΎΠΊ, Π° TypeScript сразу ΠΎΠ±Π½Π°Ρ€ΡƒΠΆΠΈΠ²Π°Π΅Ρ‚ ΠΎΠΏΠ΅Ρ‡Π°Ρ‚ΠΊΠΈ. + +```tsx + // доступная ΠΈΠΊΠΎΠ½ΠΊΠ° + // ошибка TypeScript +``` + +ПослС добавлСния Π½ΠΎΠ²ΠΎΠΉ SVG-ΠΈΠΊΠΎΠ½ΠΊΠΈ ΠΈ ΠΏΠΎΠ²Ρ‚ΠΎΡ€Π½ΠΎΠΉ Π³Π΅Π½Π΅Ρ€Π°Ρ†ΠΈΠΈ Π΅Ρ‘ имя автоматичСски появляСтся Π² Ρ‚ΠΈΠΏΠ°Ρ… ΠΈ Π°Π²Ρ‚ΠΎΠΊΠΎΠΌΠΏΠ»ΠΈΡ‚Π΅. НС Π½ΡƒΠΆΠ½ΠΎ Π²Ρ€ΡƒΡ‡Π½ΡƒΡŽ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΈΠ²Π°Ρ‚ΡŒ ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚Ρ‹, union-Ρ‚ΠΈΠΏΡ‹ ΠΈΠ»ΠΈ рССстр ΠΈΠΌΡ‘Π½. + +## Next.js App Router ΠΈ SSR ΠΈΠ· ΠΊΠΎΡ€ΠΎΠ±ΠΊΠΈ + +Generated-ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚Ρ‹ Ρ€Π°Π±ΠΎΡ‚Π°ΡŽΡ‚ Π² Server Components, SSR ΠΈ SSG Π±Π΅Π· `'use client'`. + +ΠŸΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅ ΠΈΠΊΠΎΠ½ΠΊΠΈ Π½Π΅ пСрСносит страницу Π½Π° ΠΊΠ»ΠΈΠ΅Π½Ρ‚, Π½Π΅ Ρ‚Ρ€Π΅Π±ΡƒΠ΅Ρ‚ provider ΠΈ Π½Π΅ создаёт Π΄ΠΎΠΏΠΎΠ»Π½ΠΈΡ‚Π΅Π»ΡŒΠ½ΡƒΡŽ Π³Ρ€Π°Π½ΠΈΡ†Ρƒ Π³ΠΈΠ΄Ρ€Π°Ρ‚Π°Ρ†ΠΈΠΈ. + +Один ΠΈ Ρ‚ΠΎΡ‚ ΠΆΠ΅ ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ ΠΌΠΎΠΆΠ½ΠΎ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ Π² `page.tsx`, `layout.tsx`, сСрвСрных ΠΈ клиСнтских ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚Π°Ρ…. + +## ΠœΠ½ΠΎΠΆΠ΅ΡΡ‚Π²Π΅Π½Π½Ρ‹Π΅ спрайты вмСсто ΠΎΠ΄Π½ΠΎΠ³ΠΎ глобального + +ΠŸΡ€ΠΎΠ΅ΠΊΡ‚ Π½Π΅ ΠΎΠ³Ρ€Π°Π½ΠΈΡ‡Π΅Π½ ΠΎΠ΄Π½ΠΈΠΌ Π½Π°Π±ΠΎΡ€ΠΎΠΌ ΠΈΠΊΠΎΠ½ΠΎΠΊ. Π‘ΠΎΠ·Π΄Π°Π²Π°ΠΉΡ‚Π΅ нСзависимыС спрайты для ΠΎΠ±Ρ‰ΠΈΡ… элСмСнтов, ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½Ρ‹Ρ… страниц ΠΈ ΠΊΡ€ΡƒΠΏΠ½Ρ‹Ρ… UI-ΠΌΠΎΠ΄ΡƒΠ»Π΅ΠΉ. + +```tsx + + + +``` + +ΠšΠ°ΠΆΠ΄Ρ‹ΠΉ Π½Π°Π±ΠΎΡ€ ΠΏΠΎΠ»ΡƒΡ‡Π°Π΅Ρ‚ собствСнный Ρ‚ΠΈΠΏΠΈΠ·ΠΈΡ€ΠΎΠ²Π°Π½Π½Ρ‹ΠΉ ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ ΠΈ SVG asset, поэтому Ρ€Π°Π·Π΄Π΅Π»Ρ‹ прилоТСния Π½Π΅ нСсут ΠΈΠΊΠΎΠ½ΠΊΠΈ, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ ΠΈΠΌ Π½Π΅ Π½ΡƒΠΆΠ½Ρ‹. + +## КаТдая ΠΈΠΊΠΎΠ½ΠΊΠ° хранится Π² ΠΎΠ΄Π½ΠΎΠΌ экзСмплярС + +Π’ Π±ΠΈΠ±Π»ΠΈΠΎΡ‚Π΅ΠΊΠ΅ исходников каТдая SVG-ΠΈΠΊΠΎΠ½ΠΊΠ° хранится Π² ΠΎΠ΄Π½ΠΎΠΌ экзСмплярС ΠΈ ΠΌΠΎΠΆΠ΅Ρ‚ Π²Ρ…ΠΎΠ΄ΠΈΡ‚ΡŒ Π² любоС количСство спрайтов. ΠžΠ±Ρ‰ΠΈΠ΅ ΠΈΠΊΠΎΠ½ΠΊΠΈ Π½Π΅ приходится ΠΊΠΎΠΏΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ ΠΌΠ΅ΠΆΠ΄Ρƒ страницами ΠΈ модулями: ΠΎΠ½ΠΈ ΠΎΠ±Π½ΠΎΠ²Π»ΡΡŽΡ‚ΡΡ для всСх Π½Π°Π±ΠΎΡ€ΠΎΠ² ΠΈΠ· ΠΎΠ΄Π½ΠΎΠ³ΠΎ мСста. + +```text +search.svg ─┬─→ AppIcon + β”œβ”€β†’ AnalyticsIcon + └─→ EditorIcon +``` + +Π‘ΠΏΡ€Π°ΠΉΡ‚Ρ‹ Ρ€Π°Π·Π΄Π΅Π»ΡΡŽΡ‚ΡΡ Ρ€Π°Π΄ΠΈ ΠΏΡ€ΠΎΠΈΠ·Π²ΠΎΠ΄ΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎΡΡ‚ΠΈ, Π½ΠΎ Π±ΠΈΠ±Π»ΠΈΠΎΡ‚Π΅ΠΊΠ° исходных ΠΈΠΊΠΎΠ½ΠΎΠΊ остаётся Π΅Π΄ΠΈΠ½ΠΎΠΉ. + +## Π‘Ρ€Π°ΡƒΠ·Π΅Ρ€Π½ΠΎΠ΅ ΠΊΠ΅ΡˆΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠ΅ + +ΠŸΡ€ΠΈ стандартной ΠΊΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ†ΠΈΠΈ Vite, Webpack ΠΈΠ»ΠΈ Next.js ΠΊΠ°ΠΆΠ΄Ρ‹ΠΉ спрайт выпускаСтся ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½Ρ‹ΠΌ вСрсионированным SVG-Ρ„Π°ΠΉΠ»ΠΎΠΌ. + +Пока Π½Π°Π±ΠΎΡ€ ΠΈΠΊΠΎΠ½ΠΎΠΊ Π½Π΅ мСняСтся, Π±Ρ€Π°ΡƒΠ·Π΅Ρ€ ΠΌΠΎΠΆΠ΅Ρ‚ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ ΡΠΎΡ…Ρ€Π°Π½Ρ‘Π½Π½ΡƒΡŽ копию нСзависимо ΠΎΡ‚ ΠΎΠ±Π½ΠΎΠ²Π»Π΅Π½ΠΈΠΉ JavaScript прилоТСния. + +ИзмСнСниС React-ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ΠΎΠ² Π½Π΅ Ρ‚Ρ€Π΅Π±ΡƒΠ΅Ρ‚ ΠΏΠΎΠ²Ρ‚ΠΎΡ€Π½ΠΎ Π·Π°Π³Ρ€ΡƒΠΆΠ°Ρ‚ΡŒ Π³Π΅ΠΎΠΌΠ΅Ρ‚Ρ€ΠΈΡŽ всСх ΠΈΠΊΠΎΠ½ΠΎΠΊ. + +## JavaScript Π±Π΅Π· SVG-балласта + +ΠšΠΎΠ½Ρ‚ΡƒΡ€Ρ‹ ΠΈΠΊΠΎΠ½ΠΎΠΊ ΠΎΡΡ‚Π°ΡŽΡ‚ΡΡ Π²ΠΎ Π²Π½Π΅ΡˆΠ½ΠΈΡ… SVG assets ΠΈ Π½Π΅ ΡƒΠ²Π΅Π»ΠΈΡ‡ΠΈΠ²Π°ΡŽΡ‚ chunks прилоТСния. + +```text +React-ΠΊΠΎΠ΄ β†’ JavaScript chunks +SVG-ΠΈΠΊΠΎΠ½ΠΊΠΈ β†’ ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½Ρ‹Π΅ SVG assets +``` + +JavaScript ΠΎΡ‚Π²Π΅Ρ‡Π°Π΅Ρ‚ Π·Π° интСрфСйс ΠΈ ΠΏΠΎΠ²Π΅Π΄Π΅Π½ΠΈΠ΅, Π° Π³Ρ€Π°Ρ„ΠΈΠΊΠ° загруТаСтся ΠΈ ΠΊΠ΅ΡˆΠΈΡ€ΡƒΠ΅Ρ‚ΡΡ ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½ΠΎ. + +## Врансформации SVG ΠΈΠ· ΠΊΠΎΡ€ΠΎΠ±ΠΊΠΈ + +Π’ΠΎ врСмя Π³Π΅Π½Π΅Ρ€Π°Ρ†ΠΈΠΈ ΠΏΠ°ΠΊΠ΅Ρ‚ автоматичСски ΠΏΠΎΠ΄Π³ΠΎΡ‚Π°Π²Π»ΠΈΠ²Π°Π΅Ρ‚ исходныС SVG для интСрфСйса: + +- удаляСт фиксированныС `width` ΠΈ `height`; +- сохраняСт ΡΡƒΡ‰Π΅ΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΠΉ `viewBox`; +- ΠΏΡ€Π΅ΠΎΠ±Ρ€Π°Π·ΡƒΠ΅Ρ‚ `fill` ΠΈ `stroke` Π² CSS-ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅; +- добавляСт ΠΏΠ»Π°Π²Π½Ρ‹Π΅ transitions нСпосрСдствСнно Π² Ρ†Π²Π΅Ρ‚Π½Ρ‹Π΅ элСмСнты ΠΈΠΊΠΎΠ½ΠΊΠΈ. + +ΠšΠ°ΠΆΠ΄ΡƒΡŽ Ρ‚Ρ€Π°Π½ΡΡ„ΠΎΡ€ΠΌΠ°Ρ†ΠΈΡŽ ΠΌΠΎΠΆΠ½ΠΎ Π½Π°ΡΡ‚Ρ€ΠΎΠΈΡ‚ΡŒ ΠΈΠ»ΠΈ ΠΎΡ‚ΠΊΠ»ΡŽΡ‡ΠΈΡ‚ΡŒ нСзависимо. + +## ΠšΠ°ΠΆΠ΄Ρ‹ΠΉ Ρ†Π²Π΅Ρ‚ ΠΏΠΎΠ΄ ΠΊΠΎΠ½Ρ‚Ρ€ΠΎΠ»Π΅ΠΌ CSS + +ΠŸΡ€ΠΈ Π³Π΅Π½Π΅Ρ€Π°Ρ†ΠΈΠΈ Ρ†Π²Π΅Ρ‚Π° `fill` ΠΈ `stroke` автоматичСски ΠΏΡ€Π΅ΠΎΠ±Ρ€Π°Π·ΡƒΡŽΡ‚ΡΡ Π² CSS-ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅ `--icon-color-N`. + +ΠœΠΎΠ½ΠΎΡ…Ρ€ΠΎΠΌΠ½Π°Ρ ΠΈΠΊΠΎΠ½ΠΊΠ° наслСдуСт `currentColor`: + +```tsx + +``` + +Π’ ΠΌΠ½ΠΎΠ³ΠΎΡ†Π²Π΅Ρ‚Π½ΠΎΠΉ ΠΈΠΊΠΎΠ½ΠΊΠ΅ ΠΊΠ°ΠΆΠ΄Ρ‹ΠΉ Ρ†Π²Π΅Ρ‚ ΠΌΠΎΠΆΠ½ΠΎ ΠΌΠ΅Π½ΡΡ‚ΡŒ ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½ΠΎ: + +```tsx + +``` + +Π’Π΅ΠΌΡ‹, состояния ΠΈ hover-эффСкты ΡΠΎΠ·Π΄Π°ΡŽΡ‚ΡΡ Π±Π΅Π· рСдактирования SVG ΠΈ Π΄ΠΎΠΏΠΎΠ»Π½ΠΈΡ‚Π΅Π»ΡŒΠ½Ρ‹Ρ… ΠΊΠΎΠΏΠΈΠΉ ΠΈΠΊΠΎΠ½ΠΊΠΈ. + +## SpriteViewer: всС спрайты Π½Π° ΠΎΠ΄Π½ΠΎΠΉ debug-страницС + +`SpriteViewer` Ρ€Π΅Π½Π΄Π΅Ρ€ΠΈΡ‚ спрайты всСх ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΈΠ²Π°Π΅ΠΌΡ‹Ρ… exact modes Π² ΠΎΠ΄Π½ΠΎΠΌ мСстС. Один Web Component ΠΎΡ‚Π²Π΅Ρ‡Π°Π΅Ρ‚ Π·Π° Π²ΠΈΠ·ΡƒΠ°Π», Π° для React Ρ‚Π°ΠΊΠΆΠ΅ доступСн Ρ‚ΠΎΠ½ΠΊΠΈΠΉ bridge ΠΊ Π½Π΅ΠΌΡƒ. + +Для ΠΊΠ°ΠΆΠ΄ΠΎΠΉ ΠΈΠΊΠΎΠ½ΠΊΠΈ Π²ΠΈΠ΄Π½Ρ‹ созданныС CSS-ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅ ΠΈ ΠΈΡ… fallback-Ρ†Π²Π΅Ρ‚Π°. ЗначСния ΠΌΠΎΠΆΠ½ΠΎ ΠΌΠ΅Π½ΡΡ‚ΡŒ прямо Π² Viewer ΠΈ сразу Π½Π°Π±Π»ΡŽΠ΄Π°Ρ‚ΡŒ Ρ€Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚. + +Π—Π΄Π΅ΡΡŒ ΠΆΠ΅ доступны Π³ΠΎΡ‚ΠΎΠ²Ρ‹Π΅ ΠΏΡ€ΠΈΠΌΠ΅Ρ€Ρ‹ для framework ΠΈΠ· manifest, ``, `` ΠΈ CSS. + +![SpriteViewer](https://raw.githubusercontent.com/gromlab-ru/svg-sprites/master/preview-image.png) + +Viewer ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π°Π΅Ρ‚ΡΡ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ ΠΊ Π²Π½ΡƒΡ‚Ρ€Π΅Π½Π½Π΅ΠΉ debug-страницС ΠΈ Π½Π΅ становится Ρ‡Π°ΡΡ‚ΡŒΡŽ generated-ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ΠΎΠ² ΠΈΠΊΠΎΠ½ΠΎΠΊ. + +Bare standalone ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π°Π΅Ρ‚ Viewer Ρ‡Π΅Ρ€Π΅Π· browser script ΠΈ HTML element. Bundler ΠΈ framework modes ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΡŽΡ‚ npm entry Web Component; React ΠΈ Next.js Ρ‚Π°ΠΊΠΆΠ΅ ΠΌΠΎΠ³ΡƒΡ‚ ΠΈΠΌΠΏΠΎΡ€Ρ‚ΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ bridge ΠΈΠ· `@gromlab/svg-sprites/react`. + +## 30 exact modes + +ΠŸΠ°ΠΊΠ΅Ρ‚ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΈΠ²Π°Π΅Ρ‚ 30 ΠΈΠ·ΠΎΠ»ΠΈΡ€ΠΎΠ²Π°Π½Π½Ρ‹Ρ… exact modes: `standalone@server` для сСрвСрной Π³Π΅Π½Π΅Ρ€Π°Ρ†ΠΈΠΈ ΡƒΠ½ΠΈΠ²Π΅Ρ€ΡΠ°Π»ΡŒΠ½ΠΎΠ³ΠΎ SVG-спрайта ΠΈ 29 consumer modes для соврСмСнных frameworks ΠΈ bundlers. + +`standalone@server` позволяСт Π·Π°Ρ€Π°Π½Π΅Π΅ ΡΠ³Π΅Π½Π΅Ρ€ΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ SVG-спрайт Π½Π° сСрвСрС ΠΈΠ»ΠΈ Π² CI/CD ΠΈ ΠΎΠΏΡƒΠ±Π»ΠΈΠΊΠΎΠ²Π°Ρ‚ΡŒ Π΅Π³ΠΎ для совмСстного использования. Π’Π°ΠΊΠΎΠΉ спрайт Π½Π΅ привязан ΠΊ ΠΊΠΎΠ½ΠΊΡ€Π΅Ρ‚Π½ΠΎΠΌΡƒ framework ΠΈΠ»ΠΈ bundler ΠΈ ΠΏΠΎΠ΄Ρ…ΠΎΠ΄ΠΈΡ‚ всСм consumer modes. + +29 consumer modes ΠΎΡ…Π²Π°Ρ‚Ρ‹Π²Π°ΡŽΡ‚ standalone, React, Next.js, Vue, Nuxt, Svelte, SvelteKit, Angular, Astro, Solid, SolidStart, Preact, Qwik, Lit ΠΈ Alpine.js Π² ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΈΠ²Π°Π΅ΠΌΡ‹Ρ… Π²Π°Ρ€ΠΈΠ°Π½Ρ‚Π°Ρ… Vite, Webpack, Turbopack ΠΈ application builder. + +ВсС 29 consumer modes ΠΌΠΎΠ³ΡƒΡ‚ Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ ΠΊΠ°ΠΊ со спрайтами, сгСнСрированными локально Π² ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π΅, Ρ‚Π°ΠΊ ΠΈ с ΡƒΠ½ΠΈΠ²Π΅Ρ€ΡΠ°Π»ΡŒΠ½Ρ‹ΠΌΠΈ спрайтами, Π·Π°Ρ€Π°Π½Π΅Π΅ сгСнСрированными Π½Π° сСрвСрС Ρ‡Π΅Ρ€Π΅Π· `standalone@server`. API ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ΠΎΠ² ΠΈ способ использования ΠΈΠΊΠΎΠ½ΠΎΠΊ Π² ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠΈ Π² ΠΎΠ±ΠΎΠΈΡ… сцСнариях ΠΎΡΡ‚Π°ΡŽΡ‚ΡΡ ΠΎΠ΄ΠΈΠ½Π°ΠΊΠΎΠ²Ρ‹ΠΌΠΈ. + +Π˜Π½Ρ‚Π΅Π³Ρ€Π°Ρ†ΠΈΠΎΠ½Π½Π°Ρ ΠΌΠ°Ρ‚Ρ€ΠΈΡ†Π° ΠΎΡ…Π²Π°Ρ‚Ρ‹Π²Π°Π΅Ρ‚ всС 30 exact modes. ΠžΡ‚Π΄Π΅Π»ΡŒΠ½Ρ‹ΠΉ producer-стСнд провСряСт ΡΠ΅Ρ€Π²Π΅Ρ€Π½ΡƒΡŽ Π³Π΅Π½Π΅Ρ€Π°Ρ†ΠΈΡŽ ΡƒΠ½ΠΈΠ²Π΅Ρ€ΡΠ°Π»ΡŒΠ½ΠΎΠ³ΠΎ спрайта, Π° ΠΊΠ°ΠΆΠ΄ΠΎΠ΅ ΠΈΠ· 29 consumer-ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠΉ Π³Π΅Π½Π΅Ρ€ΠΈΡ€ΡƒΠ΅Ρ‚ ΠΈ Ρ€Π΅Π½Π΄Π΅Ρ€ΠΈΡ‚ Π΄Π²Π° нСзависимых спрайта: Π»ΠΎΠΊΠ°Π»ΡŒΠ½Ρ‹ΠΉ ΠΈ ΡƒΠ΄Π°Π»Ρ‘Π½Π½Ρ‹ΠΉ. + +ВсС consumer-прилоТСния проходят production build ΠΈ Playwright-тСсты, Π° Ρ‚ΠΈΠΏΠΈΠ·ΠΈΡ€ΠΎΠ²Π°Π½Π½Ρ‹Π΅ modes Π΄ΠΎΠΏΠΎΠ»Π½ΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ ΠΏΡ€ΠΎΠ²Π΅Ρ€ΡΡŽΡ‚ΡΡ ΡˆΡ‚Π°Ρ‚Π½Ρ‹ΠΌ toolchain Ρ„Ρ€Π΅ΠΉΠΌΠ²ΠΎΡ€ΠΊΠ°. ΠšΠ°ΠΆΠ΄Ρ‹ΠΉ E2E-тСст ΠΏΠΎΠ΄Ρ‚Π²Π΅Ρ€ΠΆΠ΄Π°Π΅Ρ‚, Ρ‡Ρ‚ΠΎ Π»ΠΎΠΊΠ°Π»ΡŒΠ½Ρ‹ΠΉ ΠΈ ΡƒΠ΄Π°Π»Ρ‘Π½Π½Ρ‹ΠΉ спрайты Π·Π°Π³Ρ€ΡƒΠΆΠ°ΡŽΡ‚ΡΡ ΠΈ ΠΎΡ‚Ρ€ΠΈΡΠΎΠ²Ρ‹Π²Π°ΡŽΡ‚ΡΡ, Π° Ρ‚Π°ΠΊΠΆΠ΅ провСряСт отсутствиС browser errors ΠΈ ΠΎΡ‚ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅ ΠΎΠ±Π΅ΠΈΡ… Π³Ρ€ΡƒΠΏΠΏ Π² SpriteViewer. + +## Чистый Git + +Bundler ΠΈ framework modes ΡΠΎΠ·Π΄Π°ΡŽΡ‚ Π»ΠΎΠΊΠ°Π»ΡŒΠ½Ρ‹ΠΉ `.gitignore`, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ ΠΈΡΠΊΠ»ΡŽΡ‡Π°Π΅Ρ‚ generated-Ρ„Π°ΠΉΠ»Ρ‹ ΠΈ Π½Π΅ позволяСт ΠΈΠΌ Π·Π°ΡΠΎΡ€ΡΡ‚ΡŒ ΠΈΡΡ‚ΠΎΡ€ΠΈΡŽ, pull requests ΠΈ ΠΊΠΎΠ΄ ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π°. Bare `standalone` оставляСт ΠΏΠΎΠ»ΠΈΡ‚ΠΈΠΊΡƒ рСпозитория ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΡŽ. + +Π’ bundler ΠΈ framework modes Π² Ρ€Π΅ΠΏΠΎΠ·ΠΈΡ‚ΠΎΡ€ΠΈΠΈ ΠΎΡΡ‚Π°ΡŽΡ‚ΡΡ исходныС SVG, конфигурация ΠΈ ΠΏΡ€Π°Π²ΠΈΠ»ΠΎ `.gitignore`, Π° локально ΠΈ Π² CI спрайты, ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚Ρ‹ ΠΈ Ρ‚ΠΈΠΏΡ‹ Π·Π°Π½ΠΎΠ²ΠΎ ΡΠΎΠ·Π΄Π°ΡŽΡ‚ΡΡ Ρ‡Π΅Ρ€Π΅Π· `prebuild`. + +## Π’ production Ρ‚ΠΎΠ»ΡŒΠΊΠΎ ΠΈΠΊΠΎΠ½ΠΊΠΈ + +ГСнСрация ΠΏΠΎΠ»Π½ΠΎΡΡ‚ΡŒΡŽ Ρ€Π°Π±ΠΎΡ‚Π°Π΅Ρ‚ Ρ‡Π΅Ρ€Π΅Π· `npx`, Π±Π΅Π· добавлСния package Π² ΠΏΡ€ΠΎΠ΅ΠΊΡ‚. УстанавливайтС Π΅Π³ΠΎ ΠΊΠ°ΠΊ development dependency, Ρ‚ΠΎΠ»ΡŒΠΊΠΎ Ссли Π½ΡƒΠΆΠ½Ρ‹ Viewer, Ρ‚ΠΈΠΏΡ‹ ΠΊΠΎΠ½Ρ„ΠΈΠ³Π° ΠΈΠ»ΠΈ ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½Ρ‹ΠΉ API. + +Production-ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚Ρ‹ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΡŽΡ‚ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ Π»ΠΎΠΊΠ°Π»ΡŒΠ½Ρ‹ΠΉ generated-ΠΊΠΎΠ΄, стили ΠΈ внСшний SVG-Ρ„Π°ΠΉΠ». Compiler ΠΈ CLI Π½Π΅ ΠΏΠΎΠΏΠ°Π΄Π°ΡŽΡ‚ Π² клиСнтскоС ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠ΅, Π° `SpriteViewer` ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π°Π΅Ρ‚ΡΡ ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½ΠΎ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ Ρ‚Π°ΠΌ, Π³Π΄Π΅ Π½ΡƒΠΆΠ½Π° debug-страница. + +## ДокумСнтация + +README Π·Π½Π°ΠΊΠΎΠΌΠΈΡ‚ с возмоТностями ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π° ΠΈ ΠΏΠΎΠΊΠ°Π·Ρ‹Π²Π°Π΅Ρ‚ основной сцСнарий использования. Для настройки Π²Ρ‹Π±Π΅Ρ€ΠΈΡ‚Π΅ руководство ΠΏΠΎΠ΄ свой стСк. + +### БСрвСрная гСнСрация + +- [Standalone + Server](docs/ru/guides/standalone-server.md) + +### Быстрый старт для consumer modes + +- [Bare standalone](docs/ru/guides/standalone.md) +- [Standalone + Vite](docs/ru/guides/standalone-vite.md) +- [Standalone + Webpack 5](docs/ru/guides/standalone-webpack.md) +- [React + Vite](docs/ru/guides/react-vite.md) +- [React + Webpack 5](docs/ru/guides/react-webpack.md) +- [Vue + Vite](docs/ru/guides/vue-vite.md) +- [Vue + Webpack](docs/ru/guides/vue-webpack.md) +- [Nuxt + Vite](docs/ru/guides/nuxt-vite.md) +- [Nuxt + Webpack](docs/ru/guides/nuxt-webpack.md) +- [Svelte + Vite](docs/ru/guides/svelte-vite.md) +- [Svelte + Webpack](docs/ru/guides/svelte-webpack.md) +- [SvelteKit + Vite](docs/ru/guides/sveltekit-vite.md) +- [Angular application builder](docs/ru/guides/angular-application.md) +- [Angular + Webpack](docs/ru/guides/angular-webpack.md) +- [Astro + Vite](docs/ru/guides/astro-vite.md) +- [Solid + Vite](docs/ru/guides/solid-vite.md) +- [Solid + Webpack](docs/ru/guides/solid-webpack.md) +- [SolidStart + Vite](docs/ru/guides/solid-start-vite.md) +- [Preact + Vite](docs/ru/guides/preact-vite.md) +- [Preact + Webpack](docs/ru/guides/preact-webpack.md) +- [Qwik + Vite](docs/ru/guides/qwik-vite.md) +- [Lit + Vite](docs/ru/guides/lit-vite.md) +- [Lit + Webpack](docs/ru/guides/lit-webpack.md) +- [Alpine.js + Vite](docs/ru/guides/alpine-vite.md) +- [Alpine.js + Webpack](docs/ru/guides/alpine-webpack.md) +- [Next.js App Router + Turbopack](docs/ru/guides/next-app-turbopack.md) +- [Next.js App Router + Webpack](docs/ru/guides/next-app-webpack.md) +- [Next.js Pages Router + Turbopack](docs/ru/guides/next-pages-turbopack.md) +- [Next.js Pages Router + Webpack](docs/ru/guides/next-pages-webpack.md) + +### ВСхничСскиС ΠΌΠ°Ρ‚Π΅Ρ€ΠΈΠ°Π»Ρ‹ + +- [ИндСкс Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚Π°Ρ†ΠΈΠΈ](docs/ru/README.md) +- [ΠšΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ†ΠΈΡ](docs/ru/configuration.md) +- [ВСхничСский справочник](docs/ru/reference/technical.md) +- [ΠŸΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½Ρ‹ΠΉ API](docs/ru/reference/programmatic-api.md) + +## ЛицСнзия + +MIT diff --git a/skills/svg-sprites/src/ru/references/complex-svg.md b/skills/svg-sprites-ru/references/complex-svg.md similarity index 100% rename from skills/svg-sprites/src/ru/references/complex-svg.md rename to skills/svg-sprites-ru/references/complex-svg.md diff --git a/skills/svg-sprites-ru/references/docs/ru/README.md b/skills/svg-sprites-ru/references/docs/ru/README.md new file mode 100644 index 0000000..369e571 --- /dev/null +++ b/skills/svg-sprites-ru/references/docs/ru/README.md @@ -0,0 +1,56 @@ +# ДокумСнтация + +Для настройки Π²Ρ‹Π±Π΅Ρ€ΠΈΡ‚Π΅ guide ΠΎΠ΄Π½ΠΎΠ³ΠΎ exact mode. ΠšΠ°ΠΆΠ΄Ρ‹ΠΉ guide являСтся +ΡΠ°ΠΌΠΎΡΡ‚ΠΎΡΡ‚Π΅Π»ΡŒΠ½Ρ‹ΠΌ Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚ΠΎΠΌ ΠΈ Π±Π΅Π· ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΠΉ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ Π² AI skills. + +ΠžΠ±Ρ‰ΠΈΠΉ Ρ„ΠΎΡ€ΠΌΠ°Ρ‚ JSON, JavaScript ΠΈ TypeScript config-Ρ„Π°ΠΉΠ»ΠΎΠ² описан Π² [руководствС ΠΏΠΎ ΠΊΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ†ΠΈΠΈ](configuration.md). + +## Быстрый старт для consumer modes + +| ΠŸΡ€ΠΎΠ΅ΠΊΡ‚ | Exact mode | Guide | +|---|---|---| +| Static HTML ΠΈΠ»ΠΈ собствСнная публикация | `standalone` | [Bare standalone](guides/standalone.md) | +| Vanilla + Vite | `standalone@vite` | [Standalone + Vite](guides/standalone-vite.md) | +| Vanilla + Webpack 5 | `standalone@webpack` | [Standalone + Webpack](guides/standalone-webpack.md) | +| React + Vite | `react@vite` | [React + Vite](guides/react-vite.md) | +| React + Webpack 5 | `react@webpack` | [React + Webpack](guides/react-webpack.md) | +| Vue + Vite | `vue@vite` | [Vue + Vite](guides/vue-vite.md) | +| Vue + Webpack | `vue@webpack` | [Vue + Webpack](guides/vue-webpack.md) | +| Nuxt + Vite | `nuxt@vite` | [Nuxt + Vite](guides/nuxt-vite.md) | +| Nuxt + Webpack | `nuxt@webpack` | [Nuxt + Webpack](guides/nuxt-webpack.md) | +| Svelte + Vite | `svelte@vite` | [Svelte + Vite](guides/svelte-vite.md) | +| Svelte + Webpack | `svelte@webpack` | [Svelte + Webpack](guides/svelte-webpack.md) | +| SvelteKit + Vite | `sveltekit@vite` | [SvelteKit + Vite](guides/sveltekit-vite.md) | +| Angular application builder | `angular@application` | [Angular application builder](guides/angular-application.md) | +| Angular + Webpack | `angular@webpack` | [Angular + Webpack](guides/angular-webpack.md) | +| Astro + Vite | `astro@vite` | [Astro + Vite](guides/astro-vite.md) | +| Solid + Vite | `solid@vite` | [Solid + Vite](guides/solid-vite.md) | +| Solid + Webpack | `solid@webpack` | [Solid + Webpack](guides/solid-webpack.md) | +| SolidStart + Vite | `solid-start@vite` | [SolidStart + Vite](guides/solid-start-vite.md) | +| Preact + Vite | `preact@vite` | [Preact + Vite](guides/preact-vite.md) | +| Preact + Webpack | `preact@webpack` | [Preact + Webpack](guides/preact-webpack.md) | +| Qwik + Vite | `qwik@vite` | [Qwik + Vite](guides/qwik-vite.md) | +| Lit + Vite | `lit@vite` | [Lit + Vite](guides/lit-vite.md) | +| Lit + Webpack | `lit@webpack` | [Lit + Webpack](guides/lit-webpack.md) | +| Alpine.js + Vite | `alpine@vite` | [Alpine.js + Vite](guides/alpine-vite.md) | +| Alpine.js + Webpack | `alpine@webpack` | [Alpine.js + Webpack](guides/alpine-webpack.md) | +| Next.js App Router + Turbopack | `next@app/turbopack` | [App Router + Turbopack](guides/next-app-turbopack.md) | +| Next.js App Router + Webpack | `next@app/webpack` | [App Router + Webpack](guides/next-app-webpack.md) | +| Next.js Pages Router + Turbopack | `next@pages/turbopack` | [Pages Router + Turbopack](guides/next-pages-turbopack.md) | +| Next.js Pages Router + Webpack | `next@pages/webpack` | [Pages Router + Webpack](guides/next-pages-webpack.md) | + +ВсС consumer guides ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΡŽΡ‚ ΠΎΠ΄ΠΈΠ½ порядок: + +1. ГСнСрация спрайта Ρ‡Π΅Ρ€Π΅Π· `npx` Π±Π΅Π· добавлСния package Π² ΠΏΡ€ΠΎΠ΅ΠΊΡ‚. +2. ИспользованиС спрайта Π² ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠΈ. +3. ΠΠ΅ΠΎΠ±ΡΠ·Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎΠ΅ ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅ Viewer для Π΄Π΅Π±Π°Π³Π° ΠΈ ΠΏΡ€Π΅Π²ΡŒΡŽ. + +## БСрвСрная гСнСрация + +Π˜ΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ [`standalone@server`](guides/standalone-server.md), Ρ‡Ρ‚ΠΎΠ±Ρ‹ ΡΠ³Π΅Π½Π΅Ρ€ΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ Π½Π° сСрвСрС ΠΈΠ»ΠΈ Π² CI/CD ΡƒΠ½ΠΈΠ²Π΅Ρ€ΡΠ°Π»ΡŒΠ½Ρ‹ΠΉ SVG-спрайт для всСх consumer modes. + +## Π‘ΠΏΡ€Π°Π²ΠΎΡ‡Π½ΠΈΠΊΠΈ + +- [ΠšΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ†ΠΈΡ](configuration.md) +- [ВСхничСский справочник](reference/technical.md) +- [ΠŸΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½Ρ‹ΠΉ API](reference/programmatic-api.md) diff --git a/skills/svg-sprites-ru/references/docs/ru/configuration.md b/skills/svg-sprites-ru/references/docs/ru/configuration.md new file mode 100644 index 0000000..4d8c77c --- /dev/null +++ b/skills/svg-sprites-ru/references/docs/ru/configuration.md @@ -0,0 +1,139 @@ +# ΠšΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ†ΠΈΡ + +ΠšΠ°ΠΆΠ΄Ρ‹ΠΉ config-Ρ„Π°ΠΉΠ» описываСт ΠΎΠ΄ΠΈΠ½ нСзависимый спрайт. CLI Π½Π΅ ΠΈΡ‰Π΅Ρ‚ ΠΊΠΎΠ½Ρ„ΠΈΠ³ автоматичСски, поэтому всСгда ΠΏΠ΅Ρ€Π΅Π΄Π°Π²Π°ΠΉΡ‚Π΅ ΠΏΡƒΡ‚ΡŒ явно: + +```bash +npx --yes @gromlab/svg-sprites path/to/svg-sprite.config.json +``` + +## JSON + +JSON ΠΏΠΎΠ΄Ρ…ΠΎΠ΄ΠΈΡ‚ для Π±ΠΎΠ»ΡŒΡˆΠΈΠ½ΡΡ‚Π²Π° ΠΏΡ€ΠΎΠ΅ΠΊΡ‚ΠΎΠ² ΠΈ Π½Π΅ Ρ‚Ρ€Π΅Π±ΡƒΠ΅Ρ‚ локальной установки ΠΏΠ°ΠΊΠ΅Ρ‚Π°: + +```json +{ + "mode": "next@app/turbopack", + "name": "app", + "description": "ΠžΠ±Ρ‰ΠΈΠ΅ ΠΈΠΊΠΎΠ½ΠΊΠΈ прилоТСния", + "input": [ + "./icons", + "../../assets/icons/**/*.svg", + "!../../assets/icons/deprecated-*.svg" + ], + "transform": { + "removeSize": true, + "replaceColors": true, + "addTransition": true + }, + "generatedNotice": true +} +``` + +| ПолС | По ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ | НазначСниС | +|---|---|---| +| `mode` | НСт | Exact mode, ΡΠΎΠΎΡ‚Π²Π΅Ρ‚ΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΠΉ framework ΠΈ сборщику | +| `source` | `local` | `local` для исходных SVG ΠΈΠ»ΠΈ `remote` для manifest ΠΎΡ‚ `standalone@server` | +| `name` | Kebab-case ΠΈΠΌΠ΅Π½ΠΈ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³Π° модуля; для `svg-sprite` ΠΈ `svg-sprites` β€” ΠΈΠΌΠ΅Π½ΠΈ Ρ€ΠΎΠ΄ΠΈΡ‚Π΅Π»ΡŒΡΠΊΠΎΠ³ΠΎ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³Π° | Имя спрайта; Π² modes с ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ΠΎΠΌ Ρ‚Π°ΠΊΠΆΠ΅ Π·Π°Π΄Π°Ρ‘Ρ‚ имя ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚Π° ΠΈ Ρ‚ΠΈΠΏΠΎΠ² | +| `description` | НСт | ОписаниС для Ρ‚ΠΈΠΏΠΎΠ² ΠΈ Viewer | +| `input` | `./icons` | ΠšΠ°Ρ‚Π°Π»ΠΎΠ³, SVG-Ρ„Π°ΠΉΠ», glob-шаблон ΠΈΠ»ΠΈ массив источников | +| `transform` | ВсС Π²ΠΊΠ»ΡŽΡ‡Π΅Π½Ρ‹ | Настройки ΠΏΠΎΠ΄Π³ΠΎΡ‚ΠΎΠ²ΠΊΠΈ SVG | +| `generatedNotice` | `true` | Π’ΠΈΠ΄ прСдупрСТдСния Π² generated-Ρ„Π°ΠΉΠ»Π°Ρ… | + +ΠŸΡƒΡ‚ΠΈ ΠΈ glob-ΡˆΠ°Π±Π»ΠΎΠ½Ρ‹ Π² `input` ΡΡ‡ΠΈΡ‚Π°ΡŽΡ‚ΡΡ ΠΎΡ‚ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³Π° config-Ρ„Π°ΠΉΠ»Π°. ΠŸΠ°Ρ‚Ρ‚Π΅Ρ€Π½ с прСфиксом `!` ΠΈΡΠΊΠ»ΡŽΡ‡Π°Π΅Ρ‚ совпадСния. + +## Π£Π΄Π°Π»Ρ‘Π½Π½ΠΎ собранный спрайт + +Consumer config для server manifest содСрТит Ρ‚ΠΎΠ»ΡŒΠΊΠΎ mode, source ΠΈ input: + +```json +{ + "mode": "react@vite", + "source": "remote", + "input": "https://assets.example/releases/app/svg-sprite.manifest.json" +} +``` + +`input` ΠΏΡ€ΠΈΠ½ΠΈΠΌΠ°Π΅Ρ‚ ΠΎΠ΄ΠΈΠ½ HTTP(S) URL ΠΈΠ»ΠΈ Π»ΠΎΠΊΠ°Π»ΡŒΠ½Ρ‹ΠΉ ΠΏΡƒΡ‚ΡŒ ΠΊ manifest. Имя, описаниС, +transforms ΠΈ generated notice бСрутся ΠΈΠ· manifest. Π“Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ скачиваСт ΠΈ провСряСт +подходящий SVG profile, послС Ρ‡Π΅Π³ΠΎ adapter создаёт ΠΎΠ±Ρ‹Ρ‡Π½Ρ‹Π΅ Π»ΠΎΠΊΠ°Π»ΡŒΠ½Ρ‹Π΅ ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚Ρ‹, +Ρ‚ΠΈΠΏΡ‹ ΠΈ asset для сборщика. + +## БСрвСрная сборка + +`standalone@server` ΠΎΠ±ΡŠΠ΅Π΄ΠΈΠ½ΡΠ΅Ρ‚ local paths/globs ΠΈ HTTP(S) SVG descriptors: + +```js +export default { + mode: 'standalone@server', + name: 'app', + input: [ + './icons/**/*.svg', + { + name: 'remote-logo', + url: 'https://assets.example/logo.svg', + }, + ], +} +``` + +Mode создаёт Π΄Π²Π° content-addressed SVG profiles ΠΈ `svg-sprite.manifest.json`. +`sha256` Ρƒ HTTP input нСобязатСлСн; Ссли ΠΎΠ½ ΡƒΠΊΠ°Π·Π°Π½, это Π΄ΠΎΠ»ΠΆΠ΅Π½ Π±Ρ‹Ρ‚ΡŒ ΠΎΠΆΠΈΠ΄Π°Π΅ΠΌΡ‹ΠΉ +64-ΡΠΈΠΌΠ²ΠΎΠ»ΡŒΠ½Ρ‹ΠΉ hexadecimal SHA-256 digest, ΠΏΠΎ ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠΌΡƒ сборка ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΈΡ‚ ΠΏΠΎΠ»ΡƒΡ‡Π΅Π½Π½Ρ‹Π΅ Π±Π°ΠΉΡ‚Ρ‹. + +## JavaScript + +JavaScript-ΠΊΠΎΠ½Ρ„ΠΈΠ³ экспортируСт ΠΎΠ±Ρ‹Ρ‡Π½Ρ‹ΠΉ ΠΎΠ±ΡŠΠ΅ΠΊΡ‚ ΠΏΠΎ ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ: + +```js +export default { + mode: 'react@vite', + name: 'icons', + input: './icons', +} +``` + +ΠŸΠ΅Ρ€Π΅Π΄Π°ΠΉΡ‚Π΅ CLI ΠΏΡƒΡ‚ΡŒ ΠΊ `.js`-Ρ„Π°ΠΉΠ»Ρƒ Ρ‚Π°ΠΊ ΠΆΠ΅, ΠΊΠ°ΠΊ ΠΊ JSON: + +```bash +npx --yes @gromlab/svg-sprites path/to/svg-sprite.config.js +``` + +## TypeScript + +Для ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΊΠΈ ΠΊΠΎΠ½Ρ„ΠΈΠ³Π° TypeScript установитС ΠΏΠ°ΠΊΠ΅Ρ‚ ΠΊΠ°ΠΊ dev dependency: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +Π˜ΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ `defineSpriteConfig`: + +```ts +import { defineSpriteConfig } from '@gromlab/svg-sprites' + +export default defineSpriteConfig({ + mode: 'react@vite', + name: 'icons', + input: './icons', +}) +``` + +Или ΠΏΡ€ΠΈΠΌΠ΅Π½ΠΈΡ‚Π΅ `satisfies` с type-only ΠΈΠΌΠΏΠΎΡ€Ρ‚ΠΎΠΌ: + +```ts +import type { SpriteConfig } from '@gromlab/svg-sprites' + +export default { + mode: 'react@vite', + name: 'icons', + input: './icons', +} satisfies SpriteConfig +``` + +CLI Π·Π°Π³Ρ€ΡƒΠΆΠ°Π΅Ρ‚ `.ts`-ΠΊΠΎΠ½Ρ„ΠΈΠ³ Π½Π°ΠΏΡ€ΡΠΌΡƒΡŽ: + +```bash +npx --yes @gromlab/svg-sprites path/to/svg-sprite.config.ts +``` + +ΠŸΠΎΠ»Π½Ρ‹ΠΉ список modes, CLI-Ρ„Π»Π°Π³ΠΎΠ², ΠΏΡ€Π°Π²ΠΈΠ» имСнования ΠΈ transform-ΠΎΠΏΡ†ΠΈΠΉ находится Π² [тСхничСском справочникС](reference/technical.md). diff --git a/skills/svg-sprites-ru/references/docs/ru/guides/alpine-vite.md b/skills/svg-sprites-ru/references/docs/ru/guides/alpine-vite.md new file mode 100644 index 0000000..c533a87 --- /dev/null +++ b/skills/svg-sprites-ru/references/docs/ru/guides/alpine-vite.md @@ -0,0 +1,91 @@ +# SVG-спрайт для Alpine.js Π½Π° Vite + +Π˜Π½ΡΡ‚Ρ€ΡƒΠΊΡ†ΠΈΡ ΠΏΠΎ быстрому созданию SVG-спрайта Π² Alpine.js-ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠΈ Π½Π° Vite. + +## ГСнСрация спрайта + +Π’Ρ‹Π±Π΅Ρ€ΠΈΡ‚Π΅ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ для Π±ΡƒΠ΄ΡƒΡ‰Π΅Π³ΠΎ SVG-спрайта, Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€ `assets/app-icons`, ΠΈ создайтС Π² Π½Ρ‘ΠΌ `svg-sprite.config.json`. Π’ `input` ΡƒΠΊΠ°ΠΆΠΈΡ‚Π΅ ΠΏΡƒΡ‚ΡŒ ΠΊ ΡΡƒΡ‰Π΅ΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΠΌ SVG ΠΎΡ‚Π½ΠΎΡΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ Ρ„Π°ΠΉΠ»Π° ΠΊΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ†ΠΈΠΈ. ΠŸΠ΅Ρ€Π΅ΠΌΠ΅Ρ‰Π°Ρ‚ΡŒ ΠΈΠ»ΠΈ ΠΊΠΎΠΏΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ ΠΈΠΊΠΎΠ½ΠΊΠΈ Π½Π΅ трСбуСтся. + +```json +{ + "mode": "alpine@vite", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +Π“Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ Π½Π΅ Π½ΡƒΠΆΠ½ΠΎ Π΄ΠΎΠ±Π°Π²Π»ΡΡ‚ΡŒ Π² зависимости прилоТСния: запускайтС Π΅Π³ΠΎ Ρ‡Π΅Ρ€Π΅Π· `npx`. + +Π”ΠΎΠ±Π°Π²ΡŒΡ‚Π΅ Π³Π΅Π½Π΅Ρ€Π°Ρ†ΠΈΡŽ ΠΏΠ΅Ρ€Π΅Π΄ запуском Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠΈ ΠΈ production-сборкой: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "predev": "npm run sprites", + "dev": "vite", + "prebuild": "npm run sprites", + "build": "vite build" + } +} +``` + +## ИспользованиС спрайта + +Π—Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ `name: "app"` создаёт Alpine plugin `appAlpinePlugin`, Π΄ΠΈΡ€Π΅ΠΊΡ‚ΠΈΠ²Ρƒ `x-app-icon` ΠΈ magic `$appIconHref`. + +Π‘ΠΎΠ·Π΄Π°ΠΉΡ‚Π΅ `assets/app-icons/index.js`: + +```js +export * from './.svg-sprite/index.js' +``` + +ЗарСгистрируйтС generated plugin Π΄ΠΎ запуска Alpine: + +```js +import Alpine from 'alpinejs' +import { appAlpinePlugin } from '../assets/app-icons/index.js' + +Alpine.plugin(appAlpinePlugin) +Alpine.start() +``` + +Π˜ΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ Ρ€Π΅Π°ΠΊΡ‚ΠΈΠ²Π½ΡƒΡŽ Π΄ΠΈΡ€Π΅ΠΊΡ‚ΠΈΠ²Ρƒ Π½Π° SVG-элСмСнтС: + +```html + +``` + +Π’Ρ‹Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅ Π΄ΠΈΡ€Π΅ΠΊΡ‚ΠΈΠ²Ρ‹ Π²ΠΎΠ·Π²Ρ€Π°Ρ‰Π°Π΅Ρ‚ имя исходного SVG Π±Π΅Π· Ρ€Π°ΡΡˆΠΈΡ€Π΅Π½ΠΈΡ. ΠœΠΎΠ½ΠΎΡ…Ρ€ΠΎΠΌΠ½Π°Ρ ΠΈΠΊΠΎΠ½ΠΊΠ° наслСдуСт `color`, Π° слои ΠΌΠ½ΠΎΠ³ΠΎΡ†Π²Π΅Ρ‚Π½ΠΎΠΉ ΠΈΠΊΠΎΠ½ΠΊΠΈ ΠΏΠ΅Ρ€Π΅ΠΎΠΏΡ€Π΅Π΄Π΅Π»ΡΡŽΡ‚ΡΡ Ρ‡Π΅Ρ€Π΅Π· `--icon-color-N`. Vite ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π°Π΅Ρ‚ generated CSS ΠΈ выпускаСт `sprite.svg` ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½Ρ‹ΠΌ production asset. + +## Π”Π΅Π±Π°Π³ ΠΈ ΠΏΡ€Π΅Π²ΡŒΡŽ + +Viewer ΠΏΠΎΠΊΠ°Π·Ρ‹Π²Π°Π΅Ρ‚ всС ΠΈΠΊΠΎΠ½ΠΊΠΈ Π½Π° ΠΎΠ΄Π½ΠΎΠΉ страницС ΠΈ Π½ΡƒΠΆΠ΅Π½ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ ΠΏΡ€ΠΈ Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ΅. УстановитС Π΅Π³ΠΎ ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½ΠΎ: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +Π”ΠΎΠ±Π°Π²ΡŒΡ‚Π΅ Viewer Π½Π° development-страницу: + +```html + + +``` + +Π‘ΠΎΠ·Π΄Π°ΠΉΡ‚Π΅ `src/svg-sprite-debug.js`: + +```js +import '@gromlab/svg-sprites/viewer/element' +import spriteManifest from '../assets/app-icons/.svg-sprite/svg-sprite.manifest.js' + +document.querySelector('gromlab-sprite-viewer').sources = [spriteManifest] +``` + +ЗапуститС `npm run dev` ΠΈ ΠΎΡ‚ΠΊΡ€ΠΎΠΉΡ‚Π΅ development-страницу. Viewer Π½Π΅ зависит ΠΎΡ‚ Alpine plugin. diff --git a/skills/svg-sprites-ru/references/docs/ru/guides/alpine-webpack.md b/skills/svg-sprites-ru/references/docs/ru/guides/alpine-webpack.md new file mode 100644 index 0000000..c05436d --- /dev/null +++ b/skills/svg-sprites-ru/references/docs/ru/guides/alpine-webpack.md @@ -0,0 +1,103 @@ +# SVG-спрайт для Alpine.js Π½Π° Webpack 5 + +Π˜Π½ΡΡ‚Ρ€ΡƒΠΊΡ†ΠΈΡ ΠΏΠΎ быстрому созданию SVG-спрайта Π² Alpine.js-ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠΈ Π½Π° Webpack 5. + +## ГСнСрация спрайта + +Π’Ρ‹Π±Π΅Ρ€ΠΈΡ‚Π΅ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ для Π±ΡƒΠ΄ΡƒΡ‰Π΅Π³ΠΎ SVG-спрайта, Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€ `assets/app-icons`, ΠΈ создайтС Π² Π½Ρ‘ΠΌ `svg-sprite.config.json`. Π’ `input` ΡƒΠΊΠ°ΠΆΠΈΡ‚Π΅ ΠΏΡƒΡ‚ΡŒ ΠΊ ΡΡƒΡ‰Π΅ΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΠΌ SVG ΠΎΡ‚Π½ΠΎΡΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ Ρ„Π°ΠΉΠ»Π° ΠΊΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ†ΠΈΠΈ. ΠŸΠ΅Ρ€Π΅ΠΌΠ΅Ρ‰Π°Ρ‚ΡŒ ΠΈΠ»ΠΈ ΠΊΠΎΠΏΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ ΠΈΠΊΠΎΠ½ΠΊΠΈ Π½Π΅ трСбуСтся. + +```json +{ + "mode": "alpine@webpack", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +Π“Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ Π½Π΅ Π½ΡƒΠΆΠ½ΠΎ Π΄ΠΎΠ±Π°Π²Π»ΡΡ‚ΡŒ Π² зависимости прилоТСния: запускайтС Π΅Π³ΠΎ Ρ‡Π΅Ρ€Π΅Π· `npx`. + +Π”ΠΎΠ±Π°Π²ΡŒΡ‚Π΅ Π³Π΅Π½Π΅Ρ€Π°Ρ†ΠΈΡŽ ΠΏΠ΅Ρ€Π΅Π΄ запуском Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠΈ ΠΈ production-сборкой: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "predev": "npm run sprites", + "dev": "webpack serve --mode development", + "prebuild": "npm run sprites", + "build": "webpack --mode production" + } +} +``` + +## ИспользованиС спрайта + +Π—Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ `name: "app"` создаёт Alpine plugin `appAlpinePlugin`, Π΄ΠΈΡ€Π΅ΠΊΡ‚ΠΈΠ²Ρƒ `x-app-icon` ΠΈ magic `$appIconHref`. + +Generated CSS Alpine импортируСтся с query `?inline`. Π”ΠΎΠ±Π°Π²ΡŒΡ‚Π΅ ΠΏΡ€Π°Π²ΠΈΠ»ΠΎ Asset Modules Π² `webpack.config.js`: + +```js +export default { + module: { + rules: [ + { + test: /\.css$/, + resourceQuery: /inline/, + type: 'asset/source', + }, + ], + }, +} +``` + +Π‘ΠΎΠ·Π΄Π°ΠΉΡ‚Π΅ `assets/app-icons/index.js`: + +```js +export * from './.svg-sprite/index.js' +``` + +ЗарСгистрируйтС generated plugin Π΄ΠΎ запуска Alpine: + +```js +import Alpine from 'alpinejs' +import { appAlpinePlugin } from '../assets/app-icons/index.js' + +Alpine.plugin(appAlpinePlugin) +Alpine.start() +``` + +Π˜ΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ Ρ€Π΅Π°ΠΊΡ‚ΠΈΠ²Π½ΡƒΡŽ Π΄ΠΈΡ€Π΅ΠΊΡ‚ΠΈΠ²Ρƒ Π½Π° SVG-элСмСнтС: + +```html + +``` + +Π’Ρ‹Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅ Π΄ΠΈΡ€Π΅ΠΊΡ‚ΠΈΠ²Ρ‹ Π²ΠΎΠ·Π²Ρ€Π°Ρ‰Π°Π΅Ρ‚ имя исходного SVG Π±Π΅Π· Ρ€Π°ΡΡˆΠΈΡ€Π΅Π½ΠΈΡ. ΠœΠΎΠ½ΠΎΡ…Ρ€ΠΎΠΌΠ½Π°Ρ ΠΈΠΊΠΎΠ½ΠΊΠ° наслСдуСт `color`, Π° слои ΠΌΠ½ΠΎΠ³ΠΎΡ†Π²Π΅Ρ‚Π½ΠΎΠΉ ΠΈΠΊΠΎΠ½ΠΊΠΈ ΠΏΠ΅Ρ€Π΅ΠΎΠΏΡ€Π΅Π΄Π΅Π»ΡΡŽΡ‚ΡΡ Ρ‡Π΅Ρ€Π΅Π· `--icon-color-N`. Webpack 5 выпускаСт `sprite.svg` ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½Ρ‹ΠΌ production asset. + +## Π”Π΅Π±Π°Π³ ΠΈ ΠΏΡ€Π΅Π²ΡŒΡŽ + +Viewer ΠΏΠΎΠΊΠ°Π·Ρ‹Π²Π°Π΅Ρ‚ всС ΠΈΠΊΠΎΠ½ΠΊΠΈ Π½Π° ΠΎΠ΄Π½ΠΎΠΉ страницС ΠΈ Π½ΡƒΠΆΠ΅Π½ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ ΠΏΡ€ΠΈ Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ΅. УстановитС Π΅Π³ΠΎ ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½ΠΎ: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +Π”ΠΎΠ±Π°Π²ΡŒΡ‚Π΅ Viewer Π² development entry: + +```js +import '@gromlab/svg-sprites/viewer/element' +import spriteManifest from '../assets/app-icons/.svg-sprite/svg-sprite.manifest.js' + +const viewer = document.createElement('gromlab-sprite-viewer') +viewer.viewerTitle = 'Иконки ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π°' +viewer.sources = [spriteManifest] +document.body.append(viewer) +``` + +ΠŸΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π°ΠΉΡ‚Π΅ этот entry Ρ‚ΠΎΠ»ΡŒΠΊΠΎ ΠΏΡ€ΠΈ Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ΅. Viewer Π½Π΅ зависит ΠΎΡ‚ Alpine plugin. diff --git a/skills/svg-sprites-ru/references/docs/ru/guides/angular-application.md b/skills/svg-sprites-ru/references/docs/ru/guides/angular-application.md new file mode 100644 index 0000000..16ac7d5 --- /dev/null +++ b/skills/svg-sprites-ru/references/docs/ru/guides/angular-application.md @@ -0,0 +1,94 @@ +# SVG-спрайт для Angular с Application Builder + +Π˜Π½ΡΡ‚Ρ€ΡƒΠΊΡ†ΠΈΡ ΠΏΠΎ быстрому созданию SVG-спрайта Π² Angular-ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠΈ Π½Π° `@angular/build:application`. + +## ГСнСрация спрайта + +Π’Ρ‹Π±Π΅Ρ€ΠΈΡ‚Π΅ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ для Π±ΡƒΠ΄ΡƒΡ‰Π΅Π³ΠΎ SVG-спрайта, Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€ `assets/app-icons`, ΠΈ создайтС Π² Π½Ρ‘ΠΌ `svg-sprite.config.json`. Π’ `input` ΡƒΠΊΠ°ΠΆΠΈΡ‚Π΅ ΠΏΡƒΡ‚ΡŒ ΠΊ ΡΡƒΡ‰Π΅ΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΠΌ SVG ΠΎΡ‚Π½ΠΎΡΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ Ρ„Π°ΠΉΠ»Π° ΠΊΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ†ΠΈΠΈ. ΠŸΠ΅Ρ€Π΅ΠΌΠ΅Ρ‰Π°Ρ‚ΡŒ ΠΈΠ»ΠΈ ΠΊΠΎΠΏΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ ΠΈΠΊΠΎΠ½ΠΊΠΈ Π½Π΅ трСбуСтся. + +```json +{ + "mode": "angular@application", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +ΠŸΠ°ΠΊΠ΅Ρ‚ Π½Π΅ Π½ΡƒΠΆΠ½ΠΎ Π΄ΠΎΠ±Π°Π²Π»ΡΡ‚ΡŒ Π² зависимости ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π°. ЗапускайтС Π³Π΅Π½Π΅Ρ€Π°Ρ†ΠΈΡŽ Ρ‡Π΅Ρ€Π΅Π· `npx` ΠΏΠ΅Ρ€Π΅Π΄ Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠΎΠΉ ΠΈ production-сборкой: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "prestart": "npm run sprites", + "start": "ng serve", + "prebuild": "npm run sprites", + "build": "ng build" + } +} +``` + +Application Builder выпускаСт ΠΈΠΌΠΏΠΎΡ€Ρ‚ΠΈΡ€ΠΎΠ²Π°Π½Π½Ρ‹ΠΉ SVG ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½Ρ‹ΠΌ Ρ„Π°ΠΉΠ»ΠΎΠΌ ΠΏΡ€ΠΈ Π²ΠΊΠ»ΡŽΡ‡Ρ‘Π½Π½ΠΎΠΌ file loader. Π”ΠΎΠ±Π°Π²ΡŒΡ‚Π΅ ΠΎΠΏΡ†ΠΈΡŽ Π² build target Ρ„Π°ΠΉΠ»Π° `angular.json`: + +```json +{ + "builder": "@angular/build:application", + "options": { + "loader": { ".svg": "file" } + } +} +``` + +## ИспользованиС спрайта + +Π‘ΠΎΠ·Π΄Π°ΠΉΡ‚Π΅ `assets/app-icons/index.ts`: + +```ts +export * from './.svg-sprite/index' +``` + +Π˜ΠΌΠΏΠΎΡ€Ρ‚ΠΈΡ€ΡƒΠΉΡ‚Π΅ сгСнСрированный standalone-ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚. Π—Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ `name: "app"` создаёт `AppIcon` с сСлСктором `app-icon`: + +```ts +import { Component } from '@angular/core' +import { AppIcon } from '../assets/app-icons' + +@Component({ + selector: 'app-root', + standalone: true, + imports: [AppIcon], + template: ` + + `, +}) +export class AppComponent {} +``` + +Input `icon` Ρ‚ΠΈΠΏΠΈΠ·ΠΈΡ€ΠΎΠ²Π°Π½ ΠΈΠΌΠ΅Π½Π°ΠΌΠΈ исходных Ρ„Π°ΠΉΠ»ΠΎΠ². ΠœΠΎΠ½ΠΎΡ…Ρ€ΠΎΠΌΠ½Ρ‹Π΅ ΠΈΠΊΠΎΠ½ΠΊΠΈ Π½Π°ΡΠ»Π΅Π΄ΡƒΡŽΡ‚ `color`, ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½Ρ‹Π΅ Ρ†Π²Π΅Ρ‚Π° Π·Π°Π΄Π°ΡŽΡ‚ΡΡ Ρ‡Π΅Ρ€Π΅Π· `--icon-color-N`. + +## Π”Π΅Π±Π°Π³ ΠΈ ΠΏΡ€Π΅Π²ΡŒΡŽ + +Viewer нСобязатСлСн ΠΈ Π½ΡƒΠΆΠ΅Π½ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ ΠΏΡ€ΠΈ Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ΅: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +Π˜ΠΌΠΏΠΎΡ€Ρ‚ΠΈΡ€ΡƒΠΉΡ‚Π΅ `@gromlab/svg-sprites/viewer/element`, Π΄ΠΎΠ±Π°Π²ΡŒΡ‚Π΅ `CUSTOM_ELEMENTS_SCHEMA` ΠΈ помСститС `` Π² шаблон. Π—Π°Π³Ρ€ΡƒΠ·ΠΈΡ‚Π΅ generated manifest Π±Π΅Π· framework-specific metadata: + +```ts +readonly viewerSources = [async () => { + const { default: manifest } = await import( + '../assets/app-icons/.svg-sprite/svg-sprite.manifest.js' + ) + const { usage: _usage, ...viewerManifest } = manifest + return viewerManifest +}] +``` + +Viewer ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ Ρ‚ΠΎΡ‚ ΠΆΠ΅ production URL спрайта, Ρ‡Ρ‚ΠΎ ΠΈ `AppIcon`. diff --git a/skills/svg-sprites-ru/references/docs/ru/guides/angular-webpack.md b/skills/svg-sprites-ru/references/docs/ru/guides/angular-webpack.md new file mode 100644 index 0000000..7be3843 --- /dev/null +++ b/skills/svg-sprites-ru/references/docs/ru/guides/angular-webpack.md @@ -0,0 +1,93 @@ +# SVG-спрайт для Angular Π½Π° Webpack + +Π˜Π½ΡΡ‚Ρ€ΡƒΠΊΡ†ΠΈΡ ΠΏΠΎ быстрому созданию SVG-спрайта Π² Angular-ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠΈ со ΡˆΡ‚Π°Ρ‚Π½Ρ‹ΠΌ Webpack browser builder ΠΈΠ· Angular CLI. + +## ГСнСрация спрайта + +Π’Ρ‹Π±Π΅Ρ€ΠΈΡ‚Π΅ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ для Π±ΡƒΠ΄ΡƒΡ‰Π΅Π³ΠΎ SVG-спрайта, Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€ `assets/app-icons`, ΠΈ создайтС Π² Π½Ρ‘ΠΌ `svg-sprite.config.json`. Π’ `input` ΡƒΠΊΠ°ΠΆΠΈΡ‚Π΅ ΠΏΡƒΡ‚ΡŒ ΠΊ ΡΡƒΡ‰Π΅ΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΠΌ SVG ΠΎΡ‚Π½ΠΎΡΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ Ρ„Π°ΠΉΠ»Π° ΠΊΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ†ΠΈΠΈ. ΠŸΠ΅Ρ€Π΅ΠΌΠ΅Ρ‰Π°Ρ‚ΡŒ ΠΈΠ»ΠΈ ΠΊΠΎΠΏΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ ΠΈΠΊΠΎΠ½ΠΊΠΈ Π½Π΅ трСбуСтся. + +```json +{ + "mode": "angular@webpack", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +Mode ΠΏΡ€Π΅Π΄Π½Π°Π·Π½Π°Ρ‡Π΅Π½ для workspace, Π³Π΄Π΅ build target ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ ΠΎΡ„ΠΈΡ†ΠΈΠ°Π»ΡŒΠ½Ρ‹ΠΉ Webpack builder: + +```json +{ + "builder": "@angular-devkit/build-angular:browser" +} +``` + +ΠŸΠ°ΠΊΠ΅Ρ‚ Π½Π΅ Π½ΡƒΠΆΠ½ΠΎ Π΄ΠΎΠ±Π°Π²Π»ΡΡ‚ΡŒ Π² зависимости ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π°. Π“Π΅Π½Π΅Ρ€ΠΈΡ€ΡƒΠΉΡ‚Π΅ спрайт Ρ‡Π΅Ρ€Π΅Π· `npx` ΠΏΠ΅Ρ€Π΅Π΄ ΠΊΠ°ΠΆΠ΄Ρ‹ΠΌ запуском ΠΈ сборкой: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "prestart": "npm run sprites", + "start": "ng serve", + "prebuild": "npm run sprites", + "build": "ng build" + } +} +``` + +Webpack Ρ€Π°Π·Ρ€Π΅ΡˆΠ°Π΅Ρ‚ generated-Π²Ρ‹Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅ `new URL(..., import.meta.url)` ΠΈ выпускаСт `sprite.svg` ΠΊΠ°ΠΊ production asset. + +## ИспользованиС спрайта + +Π‘ΠΎΠ·Π΄Π°ΠΉΡ‚Π΅ `assets/app-icons/index.ts`: + +```ts +export * from './.svg-sprite/index' +``` + +Π˜ΠΌΠΏΠΎΡ€Ρ‚ΠΈΡ€ΡƒΠΉΡ‚Π΅ сгСнСрированный standalone-ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚. Π—Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ `name: "app"` создаёт `AppIcon` с сСлСктором `app-icon`: + +```ts +import { Component } from '@angular/core' +import { AppIcon } from '../assets/app-icons' + +@Component({ + selector: 'app-root', + standalone: true, + imports: [AppIcon], + template: ` + + `, +}) +export class AppComponent {} +``` + +Input `icon` Ρ‚ΠΈΠΏΠΈΠ·ΠΈΡ€ΠΎΠ²Π°Π½ ΠΈΠΌΠ΅Π½Π°ΠΌΠΈ исходных Ρ„Π°ΠΉΠ»ΠΎΠ². ΠœΠΎΠ½ΠΎΡ…Ρ€ΠΎΠΌΠ½Ρ‹Π΅ ΠΈΠΊΠΎΠ½ΠΊΠΈ Π½Π°ΡΠ»Π΅Π΄ΡƒΡŽΡ‚ `color`, ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½Ρ‹Π΅ Ρ†Π²Π΅Ρ‚Π° Π·Π°Π΄Π°ΡŽΡ‚ΡΡ Ρ‡Π΅Ρ€Π΅Π· `--icon-color-N`. + +## Π”Π΅Π±Π°Π³ ΠΈ ΠΏΡ€Π΅Π²ΡŒΡŽ + +Viewer нСобязатСлСн ΠΈ Π½ΡƒΠΆΠ΅Π½ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ ΠΏΡ€ΠΈ Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ΅: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +Π˜ΠΌΠΏΠΎΡ€Ρ‚ΠΈΡ€ΡƒΠΉΡ‚Π΅ `@gromlab/svg-sprites/viewer/element`, Π΄ΠΎΠ±Π°Π²ΡŒΡ‚Π΅ `CUSTOM_ELEMENTS_SCHEMA` ΠΈ помСститС `` Π² шаблон: + +```ts +readonly viewerSources = [async () => { + const { default: manifest } = await import( + '../assets/app-icons/.svg-sprite/svg-sprite.manifest.js' + ) + const { usage: _usage, ...viewerManifest } = manifest + return viewerManifest +}] +``` + +Viewer ΠΈ `AppIcon` ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΡŽΡ‚ ΠΎΠ΄ΠΈΠ½ Π²Ρ‹ΠΏΡƒΡ‰Π΅Π½Π½Ρ‹ΠΉ Webpack URL спрайта. diff --git a/skills/svg-sprites-ru/references/docs/ru/guides/astro-vite.md b/skills/svg-sprites-ru/references/docs/ru/guides/astro-vite.md new file mode 100644 index 0000000..34bd738 --- /dev/null +++ b/skills/svg-sprites-ru/references/docs/ru/guides/astro-vite.md @@ -0,0 +1,92 @@ +# SVG-спрайт для Astro Π½Π° Vite + +Π˜Π½ΡΡ‚Ρ€ΡƒΠΊΡ†ΠΈΡ ΠΏΠΎ быстрому созданию SVG-спрайта Π² Astro-ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠΈ Π½Π° Vite. + +## ГСнСрация спрайта + +Π’Ρ‹Π±Π΅Ρ€ΠΈΡ‚Π΅ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ для Π±ΡƒΠ΄ΡƒΡ‰Π΅Π³ΠΎ SVG-спрайта, Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€ `assets/app-icons`, ΠΈ создайтС Π² Π½Ρ‘ΠΌ `svg-sprite.config.json`. Π’ `input` ΡƒΠΊΠ°ΠΆΠΈΡ‚Π΅ ΠΏΡƒΡ‚ΡŒ ΠΊ ΡΡƒΡ‰Π΅ΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΠΌ SVG ΠΎΡ‚Π½ΠΎΡΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ Ρ„Π°ΠΉΠ»Π° ΠΊΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ†ΠΈΠΈ. ΠŸΠ΅Ρ€Π΅ΠΌΠ΅Ρ‰Π°Ρ‚ΡŒ ΠΈΠ»ΠΈ ΠΊΠΎΠΏΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ ΠΈΠΊΠΎΠ½ΠΊΠΈ Π½Π΅ трСбуСтся. + +```json +{ + "mode": "astro@vite", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +ΠŸΠ°ΠΊΠ΅Ρ‚ Π½Π΅ Π½ΡƒΠΆΠ½ΠΎ Π΄ΠΎΠ±Π°Π²Π»ΡΡ‚ΡŒ Π² зависимости ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π°. Π“Π΅Π½Π΅Ρ€ΠΈΡ€ΡƒΠΉΡ‚Π΅ спрайт Ρ‡Π΅Ρ€Π΅Π· `npx` ΠΏΠ΅Ρ€Π΅Π΄ Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠΎΠΉ ΠΈ production-сборкой: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "predev": "npm run sprites", + "dev": "astro dev", + "prebuild": "npm run sprites", + "build": "astro check && astro build" + } +} +``` + +## ИспользованиС спрайта + +Π‘ΠΎΠ·Π΄Π°ΠΉΡ‚Π΅ `assets/app-icons/index.js`: + +```js +export * from './.svg-sprite/index.js' +``` + +Π‘ΠΎΠ·Π΄Π°ΠΉΡ‚Π΅ `assets/app-icons/index.d.ts` для Ρ‚ΠΎΠ³ΠΎ ΠΆΠ΅ Ρ‚ΠΈΠΏΠΈΠ·ΠΈΡ€ΠΎΠ²Π°Π½Π½ΠΎΠ³ΠΎ API: + +```ts +export * from './.svg-sprite/index.js' +``` + +Π—Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ `name: "app"` создаёт Π½Π°Ρ‚ΠΈΠ²Π½Ρ‹ΠΉ Astro-ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ `AppIcon`. Π˜ΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ Π΅Π³ΠΎ Π½Π° страницС: + +```astro +--- +import { AppIcon } from '../../assets/app-icons/index.js' +--- + + +``` + +Prop `icon` Ρ‚ΠΈΠΏΠΈΠ·ΠΈΡ€ΠΎΠ²Π°Π½ ΠΈΠΌΠ΅Π½Π°ΠΌΠΈ исходных Ρ„Π°ΠΉΠ»ΠΎΠ². Vite выпускаСт `sprite.svg` ΠΈΠ· статичСского asset import ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚Π°. + +## Π”Π΅Π±Π°Π³ ΠΈ ΠΏΡ€Π΅Π²ΡŒΡŽ + +Viewer нСобязатСлСн ΠΈ Π½ΡƒΠΆΠ΅Π½ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ ΠΏΡ€ΠΈ Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ΅: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +Π”ΠΎΠ±Π°Π²ΡŒΡ‚Π΅ Viewer Π½Π° страницу ΠΈ ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡ΠΈΡ‚Π΅ generated manifest Π² клиСнтском скриптС: + +```astro + + + +``` + +Manifest сохраняСт Astro usage metadata, Π° Viewer ΠΎΡ‚ΠΎΠ±Ρ€Π°ΠΆΠ°Π΅Ρ‚ Ρ‚ΠΎΡ‚ ΠΆΠ΅ production-спрайт. diff --git a/skills/svg-sprites-ru/references/docs/ru/guides/lit-vite.md b/skills/svg-sprites-ru/references/docs/ru/guides/lit-vite.md new file mode 100644 index 0000000..83e0f10 --- /dev/null +++ b/skills/svg-sprites-ru/references/docs/ru/guides/lit-vite.md @@ -0,0 +1,86 @@ +# SVG-спрайт для Lit Π½Π° Vite + +Π˜Π½ΡΡ‚Ρ€ΡƒΠΊΡ†ΠΈΡ ΠΏΠΎ быстрому созданию SVG-спрайта Π² Lit-ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠΈ Π½Π° Vite. + +## ГСнСрация спрайта + +Π’Ρ‹Π±Π΅Ρ€ΠΈΡ‚Π΅ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ для Π±ΡƒΠ΄ΡƒΡ‰Π΅Π³ΠΎ SVG-спрайта, Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€ `assets/app-icons`, ΠΈ создайтС Π² Π½Ρ‘ΠΌ `svg-sprite.config.json`. Π’ `input` ΡƒΠΊΠ°ΠΆΠΈΡ‚Π΅ ΠΏΡƒΡ‚ΡŒ ΠΊ ΡΡƒΡ‰Π΅ΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΠΌ SVG ΠΎΡ‚Π½ΠΎΡΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ Ρ„Π°ΠΉΠ»Π° ΠΊΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ†ΠΈΠΈ. ΠŸΠ΅Ρ€Π΅ΠΌΠ΅Ρ‰Π°Ρ‚ΡŒ ΠΈΠ»ΠΈ ΠΊΠΎΠΏΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ ΠΈΠΊΠΎΠ½ΠΊΠΈ Π½Π΅ трСбуСтся. + +```json +{ + "mode": "lit@vite", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +Π“Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ Π½Π΅ Π½ΡƒΠΆΠ½ΠΎ Π΄ΠΎΠ±Π°Π²Π»ΡΡ‚ΡŒ Π² зависимости прилоТСния: запускайтС Π΅Π³ΠΎ Ρ‡Π΅Ρ€Π΅Π· `npx`. + +Π”ΠΎΠ±Π°Π²ΡŒΡ‚Π΅ Π³Π΅Π½Π΅Ρ€Π°Ρ†ΠΈΡŽ ΠΏΠ΅Ρ€Π΅Π΄ запуском Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠΈ ΠΈ production-сборкой: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "predev": "npm run sprites", + "dev": "vite", + "prebuild": "npm run sprites", + "build": "vite build" + } +} +``` + +## ИспользованиС спрайта + +Π—Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ `name: "app"` создаёт Lit-класс `AppIcon`, Ρ‚Π΅Π³ `` ΠΈ Ρ„ΡƒΠ½ΠΊΡ†ΠΈΡŽ рСгистрации `defineAppIcon`. + +Π‘ΠΎΠ·Π΄Π°ΠΉΡ‚Π΅ `assets/app-icons/index.js`: + +```js +export * from './.svg-sprite/index.js' +``` + +ЗарСгистрируйтС ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ ΠΏΠ΅Ρ€Π΅Π΄ Π΅Π³ΠΎ ΠΎΡ‚ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅ΠΌ: + +```js +import { defineAppIcon } from '../assets/app-icons/index.js' + +defineAppIcon() + +document.querySelector('#app').innerHTML = ` + +` +``` + +Бвойство `icon` ΠΏΡ€ΠΈΠ½ΠΈΠΌΠ°Π΅Ρ‚ имя исходного SVG Π±Π΅Π· Ρ€Π°ΡΡˆΠΈΡ€Π΅Π½ΠΈΡ. ΠœΠΎΠ½ΠΎΡ…Ρ€ΠΎΠΌΠ½Π°Ρ ΠΈΠΊΠΎΠ½ΠΊΠ° наслСдуСт `color`, Π° слои ΠΌΠ½ΠΎΠ³ΠΎΡ†Π²Π΅Ρ‚Π½ΠΎΠΉ ΠΈΠΊΠΎΠ½ΠΊΠΈ ΠΏΠ΅Ρ€Π΅ΠΎΠΏΡ€Π΅Π΄Π΅Π»ΡΡŽΡ‚ΡΡ Ρ‡Π΅Ρ€Π΅Π· `--icon-color-N`. Vite ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π°Π΅Ρ‚ CSS ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚Π° ΠΈ выпускаСт `sprite.svg` ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½Ρ‹ΠΌ production asset. + +## Π”Π΅Π±Π°Π³ ΠΈ ΠΏΡ€Π΅Π²ΡŒΡŽ + +Viewer ΠΏΠΎΠΊΠ°Π·Ρ‹Π²Π°Π΅Ρ‚ всС ΠΈΠΊΠΎΠ½ΠΊΠΈ Π½Π° ΠΎΠ΄Π½ΠΎΠΉ страницС ΠΈ Π½ΡƒΠΆΠ΅Π½ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ ΠΏΡ€ΠΈ Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ΅. УстановитС Π΅Π³ΠΎ ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½ΠΎ: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +Π”ΠΎΠ±Π°Π²ΡŒΡ‚Π΅ Viewer Π½Π° development-страницу: + +```html + + +``` + +Π‘ΠΎΠ·Π΄Π°ΠΉΡ‚Π΅ `src/svg-sprite-debug.js`: + +```js +import '@gromlab/svg-sprites/viewer/element' +import spriteManifest from '../assets/app-icons/.svg-sprite/svg-sprite.manifest.js' + +document.querySelector('gromlab-sprite-viewer').sources = [spriteManifest] +``` + +ЗапуститС `npm run dev` ΠΈ ΠΎΡ‚ΠΊΡ€ΠΎΠΉΡ‚Π΅ development-страницу. Viewer Π½Π΅ трСбуСтся для Ρ€Π°Π±ΠΎΡ‚Ρ‹ `AppIcon`. diff --git a/skills/svg-sprites-ru/references/docs/ru/guides/lit-webpack.md b/skills/svg-sprites-ru/references/docs/ru/guides/lit-webpack.md new file mode 100644 index 0000000..36d7cb4 --- /dev/null +++ b/skills/svg-sprites-ru/references/docs/ru/guides/lit-webpack.md @@ -0,0 +1,98 @@ +# SVG-спрайт для Lit Π½Π° Webpack 5 + +Π˜Π½ΡΡ‚Ρ€ΡƒΠΊΡ†ΠΈΡ ΠΏΠΎ быстрому созданию SVG-спрайта Π² Lit-ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠΈ Π½Π° Webpack 5. + +## ГСнСрация спрайта + +Π’Ρ‹Π±Π΅Ρ€ΠΈΡ‚Π΅ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ для Π±ΡƒΠ΄ΡƒΡ‰Π΅Π³ΠΎ SVG-спрайта, Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€ `assets/app-icons`, ΠΈ создайтС Π² Π½Ρ‘ΠΌ `svg-sprite.config.json`. Π’ `input` ΡƒΠΊΠ°ΠΆΠΈΡ‚Π΅ ΠΏΡƒΡ‚ΡŒ ΠΊ ΡΡƒΡ‰Π΅ΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΠΌ SVG ΠΎΡ‚Π½ΠΎΡΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ Ρ„Π°ΠΉΠ»Π° ΠΊΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ†ΠΈΠΈ. ΠŸΠ΅Ρ€Π΅ΠΌΠ΅Ρ‰Π°Ρ‚ΡŒ ΠΈΠ»ΠΈ ΠΊΠΎΠΏΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ ΠΈΠΊΠΎΠ½ΠΊΠΈ Π½Π΅ трСбуСтся. + +```json +{ + "mode": "lit@webpack", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +Π“Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ Π½Π΅ Π½ΡƒΠΆΠ½ΠΎ Π΄ΠΎΠ±Π°Π²Π»ΡΡ‚ΡŒ Π² зависимости прилоТСния: запускайтС Π΅Π³ΠΎ Ρ‡Π΅Ρ€Π΅Π· `npx`. + +Π”ΠΎΠ±Π°Π²ΡŒΡ‚Π΅ Π³Π΅Π½Π΅Ρ€Π°Ρ†ΠΈΡŽ ΠΏΠ΅Ρ€Π΅Π΄ запуском Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠΈ ΠΈ production-сборкой: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "predev": "npm run sprites", + "dev": "webpack serve --mode development", + "prebuild": "npm run sprites", + "build": "webpack --mode production" + } +} +``` + +## ИспользованиС спрайта + +Π—Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ `name: "app"` создаёт Lit-класс `AppIcon`, Ρ‚Π΅Π³ `` ΠΈ Ρ„ΡƒΠ½ΠΊΡ†ΠΈΡŽ рСгистрации `defineAppIcon`. + +Generated CSS Lit импортируСтся с query `?inline`. Π”ΠΎΠ±Π°Π²ΡŒΡ‚Π΅ ΠΏΡ€Π°Π²ΠΈΠ»ΠΎ Asset Modules Π² `webpack.config.js`: + +```js +export default { + module: { + rules: [ + { + test: /\.css$/, + resourceQuery: /inline/, + type: 'asset/source', + }, + ], + }, +} +``` + +Π‘ΠΎΠ·Π΄Π°ΠΉΡ‚Π΅ `assets/app-icons/index.js`: + +```js +export * from './.svg-sprite/index.js' +``` + +ЗарСгистрируйтС ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ ΠΏΠ΅Ρ€Π΅Π΄ Π΅Π³ΠΎ ΠΎΡ‚ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅ΠΌ: + +```js +import { defineAppIcon } from '../assets/app-icons/index.js' + +defineAppIcon() + +document.querySelector('#app').innerHTML = ` + +` +``` + +Бвойство `icon` ΠΏΡ€ΠΈΠ½ΠΈΠΌΠ°Π΅Ρ‚ имя исходного SVG Π±Π΅Π· Ρ€Π°ΡΡˆΠΈΡ€Π΅Π½ΠΈΡ. ΠœΠΎΠ½ΠΎΡ…Ρ€ΠΎΠΌΠ½Π°Ρ ΠΈΠΊΠΎΠ½ΠΊΠ° наслСдуСт `color`, Π° слои ΠΌΠ½ΠΎΠ³ΠΎΡ†Π²Π΅Ρ‚Π½ΠΎΠΉ ΠΈΠΊΠΎΠ½ΠΊΠΈ ΠΏΠ΅Ρ€Π΅ΠΎΠΏΡ€Π΅Π΄Π΅Π»ΡΡŽΡ‚ΡΡ Ρ‡Π΅Ρ€Π΅Π· `--icon-color-N`. Webpack 5 выпускаСт `sprite.svg` ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½Ρ‹ΠΌ production asset. + +## Π”Π΅Π±Π°Π³ ΠΈ ΠΏΡ€Π΅Π²ΡŒΡŽ + +Viewer ΠΏΠΎΠΊΠ°Π·Ρ‹Π²Π°Π΅Ρ‚ всС ΠΈΠΊΠΎΠ½ΠΊΠΈ Π½Π° ΠΎΠ΄Π½ΠΎΠΉ страницС ΠΈ Π½ΡƒΠΆΠ΅Π½ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ ΠΏΡ€ΠΈ Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ΅. УстановитС Π΅Π³ΠΎ ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½ΠΎ: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +Π”ΠΎΠ±Π°Π²ΡŒΡ‚Π΅ Viewer Π² development entry: + +```js +import '@gromlab/svg-sprites/viewer/element' +import spriteManifest from '../assets/app-icons/.svg-sprite/svg-sprite.manifest.js' + +const viewer = document.createElement('gromlab-sprite-viewer') +viewer.viewerTitle = 'Иконки ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π°' +viewer.sources = [spriteManifest] +document.body.append(viewer) +``` + +ΠŸΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π°ΠΉΡ‚Π΅ этот entry Ρ‚ΠΎΠ»ΡŒΠΊΠΎ ΠΏΡ€ΠΈ Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ΅. Viewer Π½Π΅ трСбуСтся для Ρ€Π°Π±ΠΎΡ‚Ρ‹ `AppIcon`. diff --git a/skills/svg-sprites-ru/references/docs/ru/guides/next-app-turbopack.md b/skills/svg-sprites-ru/references/docs/ru/guides/next-app-turbopack.md new file mode 100644 index 0000000..4f586a2 --- /dev/null +++ b/skills/svg-sprites-ru/references/docs/ru/guides/next-app-turbopack.md @@ -0,0 +1,108 @@ +# SVG-спрайт для Next.js App Router с Turbopack + +Π˜Π½ΡΡ‚Ρ€ΡƒΠΊΡ†ΠΈΡ ΠΏΠΎ быстрому созданию SVG-спрайта Π² ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠΈ Next.js с App Router ΠΈ Turbopack. + +## ГСнСрация спрайта + +Π’Ρ‹Π±Π΅Ρ€ΠΈΡ‚Π΅ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ для Π±ΡƒΠ΄ΡƒΡ‰Π΅Π³ΠΎ SVG-спрайта, Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€ `assets/app-icons`, ΠΈ создайтС Π² Π½Ρ‘ΠΌ `svg-sprite.config.json`. Π’ `input` ΡƒΠΊΠ°ΠΆΠΈΡ‚Π΅ ΠΏΡƒΡ‚ΡŒ ΠΊ ΡΡƒΡ‰Π΅ΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΠΌ SVG ΠΎΡ‚Π½ΠΎΡΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ Ρ„Π°ΠΉΠ»Π° ΠΊΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ†ΠΈΠΈ. ΠŸΠ΅Ρ€Π΅ΠΌΠ΅Ρ‰Π°Ρ‚ΡŒ ΠΈΠ»ΠΈ ΠΊΠΎΠΏΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ ΠΈΠΊΠΎΠ½ΠΊΠΈ Π½Π΅ трСбуСтся. + +ΠŸΡ€ΠΈΠΌΠ΅Ρ€ ΠΊΠΎΠ½Ρ„ΠΈΠ³Π°: + +```json +{ + "mode": "next@app/turbopack", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +ΠŸΠ°ΠΊΠ΅Ρ‚ Π½Π΅ Π½ΡƒΠΆΠ½ΠΎ Π΄ΠΎΠ±Π°Π²Π»ΡΡ‚ΡŒ Π² зависимости ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π°: гСнСрация запускаСтся Ρ‡Π΅Ρ€Π΅Π· `npx`. + +Π”ΠΎΠ±Π°Π²ΡŒΡ‚Π΅ ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ Π³Π΅Π½Π΅Ρ€Π°Ρ†ΠΈΠΈ Π² `package.json`. Π‘Π³Π΅Π½Π΅Ρ€ΠΈΡ€ΠΎΠ²Π°Π½Π½Ρ‹Π΅ Ρ„Π°ΠΉΠ»Ρ‹ ΠΏΠΎ ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ ΠΈΡΠΊΠ»ΡŽΡ‡Π΅Π½Ρ‹ ΠΈΠ· Git, поэтому `predev` ΠΈ `prebuild` ΠΏΠ΅Ρ€Π΅ΡΠΎΠ±ΠΈΡ€Π°ΡŽΡ‚ спрайт ΠΏΠ΅Ρ€Π΅Π΄ ΠΊΠ°ΠΆΠ΄Ρ‹ΠΌ запуском ΠΈ сборкой: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "predev": "npm run sprites", + "dev": "next dev --turbopack", + "prebuild": "npm run sprites", + "build": "next build --turbopack" + } +} +``` + +## ИспользованиС спрайта + +Π—Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ `name: "app"` создаёт React-ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ `AppIcon`. + +Π‘ΠΎΠ·Π΄Π°ΠΉΡ‚Π΅ Ρ‚ΠΎΡ‡ΠΊΡƒ Π²Ρ…ΠΎΠ΄Π° `assets/app-icons/index.ts`: + +```ts +export * from './.svg-sprite/index.js' +``` + +Π˜ΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ Π² Server Component: + +```tsx +// app/page.tsx +import { AppIcon } from '../assets/app-icons' + +export default function Page() { + return ( + + ) +} +``` + +Для `AppIcon` Π½Π΅ Π½ΡƒΠΆΠ΅Π½ `'use client'`. Turbopack сам добавляСт `sprite.svg` Π² ΠΈΡ‚ΠΎΠ³ΠΎΠ²ΡƒΡŽ сборку, поэтому ΠΏΠ΅Ρ€Π΅Π½ΠΎΡΠΈΡ‚ΡŒ Π΅Π³ΠΎ Π² `public` Π½Π΅ Π½ΡƒΠΆΠ½ΠΎ. + +## Π”Π΅Π±Π°Π³ ΠΈ ΠΏΡ€Π΅Π²ΡŒΡŽ + +Viewer ΠΏΠΎΠΊΠ°Π·Ρ‹Π²Π°Π΅Ρ‚ всС ΠΈΠΊΠΎΠ½ΠΊΠΈ Π½Π° ΠΎΠ΄Π½ΠΎΠΉ страницС, позволяСт ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΈΡ‚ΡŒ ΠΈΡ… ΠΎΡ‚ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅, ΠΈΠ·ΠΌΠ΅Π½ΠΈΡ‚ΡŒ Ρ†Π²Π΅Ρ‚Π° ΠΈ ΠΏΠΎΡΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ связанныС CSS-ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅. Он Π½ΡƒΠΆΠ΅Π½ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ для Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠΈ ΠΈ устанавливаСтся ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½ΠΎ: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +Π‘ΠΎΠ·Π΄Π°ΠΉΡ‚Π΅ Client Component `app/svg-sprite/SvgSpriteViewer.tsx`: + +```tsx +'use client' + +import { SpriteViewer } from '@gromlab/svg-sprites/react' + +const sources = [ + () => import('../../assets/app-icons/.svg-sprite/svg-sprite.manifest.js'), +] as const + +export function SvgSpriteViewer() { + return +} +``` + +Π‘ΠΎΠ·Π΄Π°ΠΉΡ‚Π΅ ΠΌΠ°Ρ€ΡˆΡ€ΡƒΡ‚ `app/svg-sprite/page.tsx`: + +```tsx +import { notFound } from 'next/navigation' + +import { SvgSpriteViewer } from './SvgSpriteViewer' + +export default function SvgSpritePage() { + if (process.env.NODE_ENV !== 'development') notFound() + + return +} +``` + +ЗапуститС `npm run dev` ΠΈ ΠΎΡ‚ΠΊΡ€ΠΎΠΉΡ‚Π΅ `/svg-sprite`. Π’ production ΠΌΠ°Ρ€ΡˆΡ€ΡƒΡ‚ Π²Π΅Ρ€Π½Ρ‘Ρ‚ 404. diff --git a/skills/svg-sprites-ru/references/docs/ru/guides/next-app-webpack.md b/skills/svg-sprites-ru/references/docs/ru/guides/next-app-webpack.md new file mode 100644 index 0000000..8297cac --- /dev/null +++ b/skills/svg-sprites-ru/references/docs/ru/guides/next-app-webpack.md @@ -0,0 +1,108 @@ +# SVG-спрайт для Next.js App Router с Webpack + +Π˜Π½ΡΡ‚Ρ€ΡƒΠΊΡ†ΠΈΡ ΠΏΠΎ быстрому созданию SVG-спрайта Π² ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠΈ Next.js с App Router ΠΈ Webpack. + +## ГСнСрация спрайта + +Π’Ρ‹Π±Π΅Ρ€ΠΈΡ‚Π΅ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ для Π±ΡƒΠ΄ΡƒΡ‰Π΅Π³ΠΎ SVG-спрайта, Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€ `assets/app-icons`, ΠΈ создайтС Π² Π½Ρ‘ΠΌ `svg-sprite.config.json`. Π’ `input` ΡƒΠΊΠ°ΠΆΠΈΡ‚Π΅ ΠΏΡƒΡ‚ΡŒ ΠΊ ΡΡƒΡ‰Π΅ΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΠΌ SVG ΠΎΡ‚Π½ΠΎΡΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ Ρ„Π°ΠΉΠ»Π° ΠΊΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ†ΠΈΠΈ. ΠŸΠ΅Ρ€Π΅ΠΌΠ΅Ρ‰Π°Ρ‚ΡŒ ΠΈΠ»ΠΈ ΠΊΠΎΠΏΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ ΠΈΠΊΠΎΠ½ΠΊΠΈ Π½Π΅ трСбуСтся. + +ΠŸΡ€ΠΈΠΌΠ΅Ρ€ ΠΊΠΎΠ½Ρ„ΠΈΠ³Π°: + +```json +{ + "mode": "next@app/webpack", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +ΠŸΠ°ΠΊΠ΅Ρ‚ Π½Π΅ Π½ΡƒΠΆΠ½ΠΎ Π΄ΠΎΠ±Π°Π²Π»ΡΡ‚ΡŒ Π² зависимости ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π°: гСнСрация запускаСтся Ρ‡Π΅Ρ€Π΅Π· `npx`. + +Π”ΠΎΠ±Π°Π²ΡŒΡ‚Π΅ ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ Π³Π΅Π½Π΅Ρ€Π°Ρ†ΠΈΠΈ Π² `package.json`. Π‘Π³Π΅Π½Π΅Ρ€ΠΈΡ€ΠΎΠ²Π°Π½Π½Ρ‹Π΅ Ρ„Π°ΠΉΠ»Ρ‹ ΠΏΠΎ ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ ΠΈΡΠΊΠ»ΡŽΡ‡Π΅Π½Ρ‹ ΠΈΠ· Git, поэтому `predev` ΠΈ `prebuild` ΠΏΠ΅Ρ€Π΅ΡΠΎΠ±ΠΈΡ€Π°ΡŽΡ‚ спрайт ΠΏΠ΅Ρ€Π΅Π΄ ΠΊΠ°ΠΆΠ΄Ρ‹ΠΌ запуском ΠΈ сборкой: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "predev": "npm run sprites", + "dev": "next dev --webpack", + "prebuild": "npm run sprites", + "build": "next build --webpack" + } +} +``` + +## ИспользованиС спрайта + +Π—Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ `name: "app"` создаёт React-ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ `AppIcon`. + +Π‘ΠΎΠ·Π΄Π°ΠΉΡ‚Π΅ Ρ‚ΠΎΡ‡ΠΊΡƒ Π²Ρ…ΠΎΠ΄Π° `assets/app-icons/index.ts`: + +```ts +export * from './.svg-sprite/index.js' +``` + +Π˜ΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ Π² Server Component: + +```tsx +// app/page.tsx +import { AppIcon } from '../assets/app-icons' + +export default function Page() { + return ( + + ) +} +``` + +Для `AppIcon` Π½Π΅ Π½ΡƒΠΆΠ΅Π½ `'use client'`. Next.js сам добавляСт `sprite.svg` Π² ΠΈΡ‚ΠΎΠ³ΠΎΠ²ΡƒΡŽ сборку, поэтому ΠΏΠ΅Ρ€Π΅Π½ΠΎΡΠΈΡ‚ΡŒ Π΅Π³ΠΎ Π² `public` Π½Π΅ Π½ΡƒΠΆΠ½ΠΎ. + +## Π”Π΅Π±Π°Π³ ΠΈ ΠΏΡ€Π΅Π²ΡŒΡŽ + +Viewer ΠΏΠΎΠΊΠ°Π·Ρ‹Π²Π°Π΅Ρ‚ всС ΠΈΠΊΠΎΠ½ΠΊΠΈ Π½Π° ΠΎΠ΄Π½ΠΎΠΉ страницС, позволяСт ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΈΡ‚ΡŒ ΠΈΡ… ΠΎΡ‚ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅, ΠΈΠ·ΠΌΠ΅Π½ΠΈΡ‚ΡŒ Ρ†Π²Π΅Ρ‚Π° ΠΈ ΠΏΠΎΡΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ связанныС CSS-ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅. Он Π½ΡƒΠΆΠ΅Π½ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ для Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠΈ ΠΈ устанавливаСтся ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½ΠΎ: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +Π‘ΠΎΠ·Π΄Π°ΠΉΡ‚Π΅ Client Component `app/svg-sprite/SvgSpriteViewer.tsx`: + +```tsx +'use client' + +import { SpriteViewer } from '@gromlab/svg-sprites/react' + +const sources = [ + () => import('../../assets/app-icons/.svg-sprite/svg-sprite.manifest.js'), +] as const + +export function SvgSpriteViewer() { + return +} +``` + +Π‘ΠΎΠ·Π΄Π°ΠΉΡ‚Π΅ ΠΌΠ°Ρ€ΡˆΡ€ΡƒΡ‚ `app/svg-sprite/page.tsx`: + +```tsx +import { notFound } from 'next/navigation' + +import { SvgSpriteViewer } from './SvgSpriteViewer' + +export default function SvgSpritePage() { + if (process.env.NODE_ENV !== 'development') notFound() + + return +} +``` + +ЗапуститС `npm run dev` ΠΈ ΠΎΡ‚ΠΊΡ€ΠΎΠΉΡ‚Π΅ `/svg-sprite`. Π’ production ΠΌΠ°Ρ€ΡˆΡ€ΡƒΡ‚ Π²Π΅Ρ€Π½Ρ‘Ρ‚ 404. diff --git a/skills/svg-sprites-ru/references/docs/ru/guides/next-pages-turbopack.md b/skills/svg-sprites-ru/references/docs/ru/guides/next-pages-turbopack.md new file mode 100644 index 0000000..b7caa73 --- /dev/null +++ b/skills/svg-sprites-ru/references/docs/ru/guides/next-pages-turbopack.md @@ -0,0 +1,98 @@ +# SVG-спрайт для Next.js Pages Router с Turbopack + +Π˜Π½ΡΡ‚Ρ€ΡƒΠΊΡ†ΠΈΡ ΠΏΠΎ быстрому созданию SVG-спрайта Π² ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠΈ Next.js с Pages Router ΠΈ Turbopack. + +## ГСнСрация спрайта + +Π’Ρ‹Π±Π΅Ρ€ΠΈΡ‚Π΅ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ для Π±ΡƒΠ΄ΡƒΡ‰Π΅Π³ΠΎ SVG-спрайта, Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€ `assets/app-icons`, ΠΈ создайтС Π² Π½Ρ‘ΠΌ `svg-sprite.config.json`. Π’ `input` ΡƒΠΊΠ°ΠΆΠΈΡ‚Π΅ ΠΏΡƒΡ‚ΡŒ ΠΊ ΡΡƒΡ‰Π΅ΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΠΌ SVG ΠΎΡ‚Π½ΠΎΡΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ Ρ„Π°ΠΉΠ»Π° ΠΊΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ†ΠΈΠΈ. ΠŸΠ΅Ρ€Π΅ΠΌΠ΅Ρ‰Π°Ρ‚ΡŒ ΠΈΠ»ΠΈ ΠΊΠΎΠΏΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ ΠΈΠΊΠΎΠ½ΠΊΠΈ Π½Π΅ трСбуСтся. + +ΠŸΡ€ΠΈΠΌΠ΅Ρ€ ΠΊΠΎΠ½Ρ„ΠΈΠ³Π°: + +```json +{ + "mode": "next@pages/turbopack", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +ΠŸΠ°ΠΊΠ΅Ρ‚ Π½Π΅ Π½ΡƒΠΆΠ½ΠΎ Π΄ΠΎΠ±Π°Π²Π»ΡΡ‚ΡŒ Π² зависимости ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π°: гСнСрация запускаСтся Ρ‡Π΅Ρ€Π΅Π· `npx`. + +Π”ΠΎΠ±Π°Π²ΡŒΡ‚Π΅ ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ Π³Π΅Π½Π΅Ρ€Π°Ρ†ΠΈΠΈ Π² `package.json`. Π‘Π³Π΅Π½Π΅Ρ€ΠΈΡ€ΠΎΠ²Π°Π½Π½Ρ‹Π΅ Ρ„Π°ΠΉΠ»Ρ‹ ΠΏΠΎ ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ ΠΈΡΠΊΠ»ΡŽΡ‡Π΅Π½Ρ‹ ΠΈΠ· Git, поэтому `predev` ΠΈ `prebuild` ΠΏΠ΅Ρ€Π΅ΡΠΎΠ±ΠΈΡ€Π°ΡŽΡ‚ спрайт ΠΏΠ΅Ρ€Π΅Π΄ ΠΊΠ°ΠΆΠ΄Ρ‹ΠΌ запуском ΠΈ сборкой: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "predev": "npm run sprites", + "dev": "next dev --turbopack", + "prebuild": "npm run sprites", + "build": "next build --turbopack" + } +} +``` + +## ИспользованиС спрайта + +Π—Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ `name: "app"` создаёт React-ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ `AppIcon`. + +Π‘ΠΎΠ·Π΄Π°ΠΉΡ‚Π΅ Ρ‚ΠΎΡ‡ΠΊΡƒ Π²Ρ…ΠΎΠ΄Π° `assets/app-icons/index.ts`: + +```ts +export * from './.svg-sprite/index.js' +``` + +Π˜ΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ Π½Π° страницС: + +```tsx +// pages/index.tsx +import { AppIcon } from '../assets/app-icons' + +export default function Page() { + return ( + + ) +} +``` + +ΠšΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ Ρ€Π°Π±ΠΎΡ‚Π°Π΅Ρ‚ с SSR, SSG ΠΈ клиСнтскими ΠΏΠ΅Ρ€Π΅Ρ…ΠΎΠ΄Π°ΠΌΠΈ. Turbopack сам добавляСт `sprite.svg` Π² ΠΈΡ‚ΠΎΠ³ΠΎΠ²ΡƒΡŽ сборку, поэтому ΠΏΠ΅Ρ€Π΅Π½ΠΎΡΠΈΡ‚ΡŒ Π΅Π³ΠΎ Π² `public` Π½Π΅ Π½ΡƒΠΆΠ½ΠΎ. + +## Π”Π΅Π±Π°Π³ ΠΈ ΠΏΡ€Π΅Π²ΡŒΡŽ + +Viewer ΠΏΠΎΠΊΠ°Π·Ρ‹Π²Π°Π΅Ρ‚ всС ΠΈΠΊΠΎΠ½ΠΊΠΈ Π½Π° ΠΎΠ΄Π½ΠΎΠΉ страницС, позволяСт ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΈΡ‚ΡŒ ΠΈΡ… ΠΎΡ‚ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅, ΠΈΠ·ΠΌΠ΅Π½ΠΈΡ‚ΡŒ Ρ†Π²Π΅Ρ‚Π° ΠΈ ΠΏΠΎΡΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ связанныС CSS-ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅. Он Π½ΡƒΠΆΠ΅Π½ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ для Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠΈ ΠΈ устанавливаСтся ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½ΠΎ: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +Π‘ΠΎΠ·Π΄Π°ΠΉΡ‚Π΅ страницу `pages/svg-sprite.tsx`: + +```tsx +import type { GetStaticProps } from 'next' +import { SpriteViewer } from '@gromlab/svg-sprites/react' + +const sources = [ + () => import('../assets/app-icons/.svg-sprite/svg-sprite.manifest.js'), +] as const + +export default function SvgSpritePage() { + return +} + +export const getStaticProps: GetStaticProps = () => + process.env.NODE_ENV === 'development' + ? { props: {} } + : { notFound: true } +``` + +ЗапуститС `npm run dev` ΠΈ ΠΎΡ‚ΠΊΡ€ΠΎΠΉΡ‚Π΅ `/svg-sprite`. Π’ production ΠΌΠ°Ρ€ΡˆΡ€ΡƒΡ‚ Π²Π΅Ρ€Π½Ρ‘Ρ‚ 404. diff --git a/skills/svg-sprites-ru/references/docs/ru/guides/next-pages-webpack.md b/skills/svg-sprites-ru/references/docs/ru/guides/next-pages-webpack.md new file mode 100644 index 0000000..e7e52eb --- /dev/null +++ b/skills/svg-sprites-ru/references/docs/ru/guides/next-pages-webpack.md @@ -0,0 +1,98 @@ +# SVG-спрайт для Next.js Pages Router с Webpack + +Π˜Π½ΡΡ‚Ρ€ΡƒΠΊΡ†ΠΈΡ ΠΏΠΎ быстрому созданию SVG-спрайта Π² ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠΈ Next.js с Pages Router ΠΈ Webpack. + +## ГСнСрация спрайта + +Π’Ρ‹Π±Π΅Ρ€ΠΈΡ‚Π΅ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ для Π±ΡƒΠ΄ΡƒΡ‰Π΅Π³ΠΎ SVG-спрайта, Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€ `assets/app-icons`, ΠΈ создайтС Π² Π½Ρ‘ΠΌ `svg-sprite.config.json`. Π’ `input` ΡƒΠΊΠ°ΠΆΠΈΡ‚Π΅ ΠΏΡƒΡ‚ΡŒ ΠΊ ΡΡƒΡ‰Π΅ΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΠΌ SVG ΠΎΡ‚Π½ΠΎΡΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ Ρ„Π°ΠΉΠ»Π° ΠΊΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ†ΠΈΠΈ. ΠŸΠ΅Ρ€Π΅ΠΌΠ΅Ρ‰Π°Ρ‚ΡŒ ΠΈΠ»ΠΈ ΠΊΠΎΠΏΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ ΠΈΠΊΠΎΠ½ΠΊΠΈ Π½Π΅ трСбуСтся. + +ΠŸΡ€ΠΈΠΌΠ΅Ρ€ ΠΊΠΎΠ½Ρ„ΠΈΠ³Π°: + +```json +{ + "mode": "next@pages/webpack", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +ΠŸΠ°ΠΊΠ΅Ρ‚ Π½Π΅ Π½ΡƒΠΆΠ½ΠΎ Π΄ΠΎΠ±Π°Π²Π»ΡΡ‚ΡŒ Π² зависимости ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π°: гСнСрация запускаСтся Ρ‡Π΅Ρ€Π΅Π· `npx`. + +Π”ΠΎΠ±Π°Π²ΡŒΡ‚Π΅ ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ Π³Π΅Π½Π΅Ρ€Π°Ρ†ΠΈΠΈ Π² `package.json`. Π‘Π³Π΅Π½Π΅Ρ€ΠΈΡ€ΠΎΠ²Π°Π½Π½Ρ‹Π΅ Ρ„Π°ΠΉΠ»Ρ‹ ΠΏΠΎ ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ ΠΈΡΠΊΠ»ΡŽΡ‡Π΅Π½Ρ‹ ΠΈΠ· Git, поэтому `predev` ΠΈ `prebuild` ΠΏΠ΅Ρ€Π΅ΡΠΎΠ±ΠΈΡ€Π°ΡŽΡ‚ спрайт ΠΏΠ΅Ρ€Π΅Π΄ ΠΊΠ°ΠΆΠ΄Ρ‹ΠΌ запуском ΠΈ сборкой: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "predev": "npm run sprites", + "dev": "next dev --webpack", + "prebuild": "npm run sprites", + "build": "next build --webpack" + } +} +``` + +## ИспользованиС спрайта + +Π—Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ `name: "app"` создаёт React-ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ `AppIcon`. + +Π‘ΠΎΠ·Π΄Π°ΠΉΡ‚Π΅ Ρ‚ΠΎΡ‡ΠΊΡƒ Π²Ρ…ΠΎΠ΄Π° `assets/app-icons/index.ts`: + +```ts +export * from './.svg-sprite/index.js' +``` + +Π˜ΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ Π½Π° страницС: + +```tsx +// pages/index.tsx +import { AppIcon } from '../assets/app-icons' + +export default function Page() { + return ( + + ) +} +``` + +ΠšΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ Ρ€Π°Π±ΠΎΡ‚Π°Π΅Ρ‚ с SSR, SSG ΠΈ клиСнтскими ΠΏΠ΅Ρ€Π΅Ρ…ΠΎΠ΄Π°ΠΌΠΈ. Next.js сам добавляСт `sprite.svg` Π² ΠΈΡ‚ΠΎΠ³ΠΎΠ²ΡƒΡŽ сборку, поэтому ΠΏΠ΅Ρ€Π΅Π½ΠΎΡΠΈΡ‚ΡŒ Π΅Π³ΠΎ Π² `public` Π½Π΅ Π½ΡƒΠΆΠ½ΠΎ. + +## Π”Π΅Π±Π°Π³ ΠΈ ΠΏΡ€Π΅Π²ΡŒΡŽ + +Viewer ΠΏΠΎΠΊΠ°Π·Ρ‹Π²Π°Π΅Ρ‚ всС ΠΈΠΊΠΎΠ½ΠΊΠΈ Π½Π° ΠΎΠ΄Π½ΠΎΠΉ страницС, позволяСт ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΈΡ‚ΡŒ ΠΈΡ… ΠΎΡ‚ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅, ΠΈΠ·ΠΌΠ΅Π½ΠΈΡ‚ΡŒ Ρ†Π²Π΅Ρ‚Π° ΠΈ ΠΏΠΎΡΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ связанныС CSS-ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅. Он Π½ΡƒΠΆΠ΅Π½ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ для Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠΈ ΠΈ устанавливаСтся ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½ΠΎ: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +Π‘ΠΎΠ·Π΄Π°ΠΉΡ‚Π΅ страницу `pages/svg-sprite.tsx`: + +```tsx +import type { GetStaticProps } from 'next' +import { SpriteViewer } from '@gromlab/svg-sprites/react' + +const sources = [ + () => import('../assets/app-icons/.svg-sprite/svg-sprite.manifest.js'), +] as const + +export default function SvgSpritePage() { + return +} + +export const getStaticProps: GetStaticProps = () => + process.env.NODE_ENV === 'development' + ? { props: {} } + : { notFound: true } +``` + +ЗапуститС `npm run dev` ΠΈ ΠΎΡ‚ΠΊΡ€ΠΎΠΉΡ‚Π΅ `/svg-sprite`. Π’ production ΠΌΠ°Ρ€ΡˆΡ€ΡƒΡ‚ Π²Π΅Ρ€Π½Ρ‘Ρ‚ 404. diff --git a/skills/svg-sprites-ru/references/docs/ru/guides/nuxt-vite.md b/skills/svg-sprites-ru/references/docs/ru/guides/nuxt-vite.md new file mode 100644 index 0000000..30e2c89 --- /dev/null +++ b/skills/svg-sprites-ru/references/docs/ru/guides/nuxt-vite.md @@ -0,0 +1,100 @@ +# SVG-спрайт для Nuxt Π½Π° Vite + +Π˜Π½ΡΡ‚Ρ€ΡƒΠΊΡ†ΠΈΡ ΠΏΠΎ быстрому созданию SVG-спрайта Π² Nuxt-ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠΈ Π½Π° Vite. + +## ГСнСрация спрайта + +Π’Ρ‹Π±Π΅Ρ€ΠΈΡ‚Π΅ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ для Π±ΡƒΠ΄ΡƒΡ‰Π΅Π³ΠΎ SVG-спрайта, Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€ `assets/app-icons`, ΠΈ создайтС Π² Π½Ρ‘ΠΌ `svg-sprite.config.json`. Π’ `input` ΡƒΠΊΠ°ΠΆΠΈΡ‚Π΅ ΠΏΡƒΡ‚ΡŒ ΠΊ ΡΡƒΡ‰Π΅ΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΠΌ SVG ΠΎΡ‚Π½ΠΎΡΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ Ρ„Π°ΠΉΠ»Π° ΠΊΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ†ΠΈΠΈ. ΠŸΠ΅Ρ€Π΅ΠΌΠ΅Ρ‰Π°Ρ‚ΡŒ ΠΈΠ»ΠΈ ΠΊΠΎΠΏΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ ΠΈΠΊΠΎΠ½ΠΊΠΈ Π½Π΅ трСбуСтся. + +ΠŸΡ€ΠΈΠΌΠ΅Ρ€ ΠΊΠΎΠ½Ρ„ΠΈΠ³Π°: + +```json +{ + "mode": "nuxt@vite", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +ΠŸΠ°ΠΊΠ΅Ρ‚ Π½Π΅ Π½ΡƒΠΆΠ½ΠΎ Π΄ΠΎΠ±Π°Π²Π»ΡΡ‚ΡŒ Π² зависимости ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π°: гСнСрация запускаСтся Ρ‡Π΅Ρ€Π΅Π· `npx`. + +Π”ΠΎΠ±Π°Π²ΡŒΡ‚Π΅ ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ Π³Π΅Π½Π΅Ρ€Π°Ρ†ΠΈΠΈ Π² `package.json`: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "predev": "npm run sprites", + "dev": "nuxt dev", + "prebuild": "npm run sprites", + "build": "nuxt build" + } +} +``` + +## ИспользованиС спрайта + +Π—Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ `name: "app"` создаёт Vue-ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ `AppIcon`. Π‘ΠΎΠ·Π΄Π°ΠΉΡ‚Π΅ `assets/app-icons/index.js`: + +```js +export * from './.svg-sprite/index.js' +``` + +Π˜ΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ Π½Π° страницС ΠΈΠ»ΠΈ Π² layout Nuxt: + +```vue + + + +``` + +`AppIcon` бСзопасСн для SSR ΠΈ Π½Π΅ Ρ‚Ρ€Π΅Π±ΡƒΠ΅Ρ‚ client-only ΠΎΠ±Ρ‘Ρ€Ρ‚ΠΊΠΈ. Vite выпускаСт `sprite.svg` ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½Ρ‹ΠΌ production asset. + +## Π”Π΅Π±Π°Π³ ΠΈ ΠΏΡ€Π΅Π²ΡŒΡŽ + +Viewer ΠΏΠΎΠΊΠ°Π·Ρ‹Π²Π°Π΅Ρ‚ всС ΠΈΠΊΠΎΠ½ΠΊΠΈ Π½Π° ΠΎΠ΄Π½ΠΎΠΉ страницС, позволяСт ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΈΡ‚ΡŒ ΠΈΡ… ΠΎΡ‚ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅, ΠΈΠ·ΠΌΠ΅Π½ΠΈΡ‚ΡŒ Ρ†Π²Π΅Ρ‚Π° ΠΈ ΠΏΠΎΡΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ связанныС CSS-ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅. Он Π½ΡƒΠΆΠ΅Π½ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ для Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠΈ ΠΈ устанавливаСтся ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½ΠΎ: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +Π‘ΠΎΠ·Π΄Π°ΠΉΡ‚Π΅ `app/components/SvgSpriteViewer.client.vue`, Ρ‡Ρ‚ΠΎΠ±Ρ‹ browser-only Viewer Π½Π΅ выполнялся Π²ΠΎ врСмя SSR: + +```vue + + + +``` + +ΠžΡ‚ΠΌΠ΅Ρ‚ΡŒΡ‚Π΅ `gromlab-sprite-viewer` ΠΊΠ°ΠΊ custom element Π² `nuxt.config.ts`: + +```ts +export default defineNuxtConfig({ + vue: { + compilerOptions: { + isCustomElement: (tag) => tag === 'gromlab-sprite-viewer', + }, + }, +}) +``` + +ΠŸΠΎΠΊΠ°ΠΆΠΈΡ‚Π΅ `` Π½Π° страницС Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠΈ. Viewer ΠΈΠ·ΠΎΠ»ΠΈΡ€ΠΎΠ²Π°Π½ ΠΎΡ‚ generated runtime ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚Π° `AppIcon`. diff --git a/skills/svg-sprites-ru/references/docs/ru/guides/nuxt-webpack.md b/skills/svg-sprites-ru/references/docs/ru/guides/nuxt-webpack.md new file mode 100644 index 0000000..31d79d3 --- /dev/null +++ b/skills/svg-sprites-ru/references/docs/ru/guides/nuxt-webpack.md @@ -0,0 +1,113 @@ +# SVG-спрайт для Nuxt Π½Π° Webpack + +Π˜Π½ΡΡ‚Ρ€ΡƒΠΊΡ†ΠΈΡ ΠΏΠΎ быстрому созданию SVG-спрайта Π² Nuxt-ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠΈ Π½Π° Webpack. + +## ГСнСрация спрайта + +Π’Ρ‹Π±Π΅Ρ€ΠΈΡ‚Π΅ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ для Π±ΡƒΠ΄ΡƒΡ‰Π΅Π³ΠΎ SVG-спрайта, Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€ `assets/app-icons`, ΠΈ создайтС Π² Π½Ρ‘ΠΌ `svg-sprite.config.json`. Π’ `input` ΡƒΠΊΠ°ΠΆΠΈΡ‚Π΅ ΠΏΡƒΡ‚ΡŒ ΠΊ ΡΡƒΡ‰Π΅ΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΠΌ SVG ΠΎΡ‚Π½ΠΎΡΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ Ρ„Π°ΠΉΠ»Π° ΠΊΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ†ΠΈΠΈ. ΠŸΠ΅Ρ€Π΅ΠΌΠ΅Ρ‰Π°Ρ‚ΡŒ ΠΈΠ»ΠΈ ΠΊΠΎΠΏΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ ΠΈΠΊΠΎΠ½ΠΊΠΈ Π½Π΅ трСбуСтся. + +ΠŸΡ€ΠΈΠΌΠ΅Ρ€ ΠΊΠΎΠ½Ρ„ΠΈΠ³Π°: + +```json +{ + "mode": "nuxt@webpack", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +ΠŸΠ°ΠΊΠ΅Ρ‚ Π½Π΅ Π½ΡƒΠΆΠ½ΠΎ Π΄ΠΎΠ±Π°Π²Π»ΡΡ‚ΡŒ Π² зависимости ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π°: гСнСрация запускаСтся Ρ‡Π΅Ρ€Π΅Π· `npx`. + +ΠŸΠΎΠ΄ΠΊΠ»ΡŽΡ‡ΠΈΡ‚Π΅ Webpack builder Nuxt Π² `nuxt.config.ts`: + +```bash +npm install --save-dev @nuxt/webpack-builder +``` + +```ts +export default defineNuxtConfig({ + builder: '@nuxt/webpack-builder', +}) +``` + +Π”ΠΎΠ±Π°Π²ΡŒΡ‚Π΅ ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ Π³Π΅Π½Π΅Ρ€Π°Ρ†ΠΈΠΈ Π² `package.json`: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "predev": "npm run sprites", + "dev": "nuxt dev", + "prebuild": "npm run sprites", + "build": "nuxt build" + } +} +``` + +## ИспользованиС спрайта + +Π—Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ `name: "app"` создаёт Vue-ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ `AppIcon`. Π‘ΠΎΠ·Π΄Π°ΠΉΡ‚Π΅ `assets/app-icons/index.js`: + +```js +export * from './.svg-sprite/index.js' +``` + +Π˜ΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ Π½Π° страницС ΠΈΠ»ΠΈ Π² layout Nuxt: + +```vue + + + +``` + +`AppIcon` бСзопасСн для SSR ΠΈ Π½Π΅ Ρ‚Ρ€Π΅Π±ΡƒΠ΅Ρ‚ client-only ΠΎΠ±Ρ‘Ρ€Ρ‚ΠΊΠΈ. Webpack выпускаСт `sprite.svg` ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½Ρ‹ΠΌ production asset. + +## Π”Π΅Π±Π°Π³ ΠΈ ΠΏΡ€Π΅Π²ΡŒΡŽ + +Viewer ΠΏΠΎΠΊΠ°Π·Ρ‹Π²Π°Π΅Ρ‚ всС ΠΈΠΊΠΎΠ½ΠΊΠΈ Π½Π° ΠΎΠ΄Π½ΠΎΠΉ страницС, позволяСт ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΈΡ‚ΡŒ ΠΈΡ… ΠΎΡ‚ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅, ΠΈΠ·ΠΌΠ΅Π½ΠΈΡ‚ΡŒ Ρ†Π²Π΅Ρ‚Π° ΠΈ ΠΏΠΎΡΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ связанныС CSS-ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅. Он Π½ΡƒΠΆΠ΅Π½ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ для Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠΈ ΠΈ устанавливаСтся ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½ΠΎ: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +Π‘ΠΎΠ·Π΄Π°ΠΉΡ‚Π΅ `app/components/SvgSpriteViewer.client.vue`, Ρ‡Ρ‚ΠΎΠ±Ρ‹ browser-only Viewer Π½Π΅ выполнялся Π²ΠΎ врСмя SSR: + +```vue + + + +``` + +Π”ΠΎΠΏΠΎΠ»Π½ΠΈΡ‚Π΅ ΡΡƒΡ‰Π΅ΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΠ΅ настройки `nuxt.config.ts`, Ρ‡Ρ‚ΠΎΠ±Ρ‹ Vue считал Viewer custom element: + +```ts +export default defineNuxtConfig({ + builder: '@nuxt/webpack-builder', + vue: { + compilerOptions: { + isCustomElement: (tag) => tag === 'gromlab-sprite-viewer', + }, + }, +}) +``` + +ΠŸΠΎΠΊΠ°ΠΆΠΈΡ‚Π΅ `` Π½Π° страницС Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠΈ. Viewer ΠΈΠ·ΠΎΠ»ΠΈΡ€ΠΎΠ²Π°Π½ ΠΎΡ‚ generated runtime ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚Π° `AppIcon`. diff --git a/skills/svg-sprites-ru/references/docs/ru/guides/preact-vite.md b/skills/svg-sprites-ru/references/docs/ru/guides/preact-vite.md new file mode 100644 index 0000000..26bea8b --- /dev/null +++ b/skills/svg-sprites-ru/references/docs/ru/guides/preact-vite.md @@ -0,0 +1,75 @@ +# SVG-спрайт для Preact Π½Π° Vite + +Π˜Π½ΡΡ‚Ρ€ΡƒΠΊΡ†ΠΈΡ ΠΏΠΎ быстрому созданию SVG-спрайта Π² Preact-ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠΈ Π½Π° Vite. + +## ГСнСрация спрайта + +Π’Ρ‹Π±Π΅Ρ€ΠΈΡ‚Π΅ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ для Π±ΡƒΠ΄ΡƒΡ‰Π΅Π³ΠΎ SVG-спрайта, Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€ `assets/app-icons`, ΠΈ создайтС Π² Π½Ρ‘ΠΌ `svg-sprite.config.json`. Π’ `input` ΡƒΠΊΠ°ΠΆΠΈΡ‚Π΅ ΠΏΡƒΡ‚ΡŒ ΠΊ ΡΡƒΡ‰Π΅ΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΠΌ SVG ΠΎΡ‚Π½ΠΎΡΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ Ρ„Π°ΠΉΠ»Π° ΠΊΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ†ΠΈΠΈ. ΠŸΠ΅Ρ€Π΅ΠΌΠ΅Ρ‰Π°Ρ‚ΡŒ ΠΈΠ»ΠΈ ΠΊΠΎΠΏΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ ΠΈΠΊΠΎΠ½ΠΊΠΈ Π½Π΅ трСбуСтся. + +```json +{ + "mode": "preact@vite", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +ΠŸΠ°ΠΊΠ΅Ρ‚ Π½Π΅ Π½ΡƒΠΆΠ½ΠΎ Π΄ΠΎΠ±Π°Π²Π»ΡΡ‚ΡŒ Π² зависимости ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π°. ЗапускайтС Π΅Π³ΠΎ Ρ‡Π΅Ρ€Π΅Π· `npx` ΠΏΠ΅Ρ€Π΅Π΄ Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠΎΠΉ ΠΈ production-сборкой: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "predev": "npm run sprites", + "dev": "vite", + "prebuild": "npm run sprites", + "build": "tsc --noEmit && vite build" + } +} +``` + +## ИспользованиС спрайта + +Π‘ΠΎΠ·Π΄Π°ΠΉΡ‚Π΅ `assets/app-icons/index.js` ΠΈ `assets/app-icons/index.d.ts` с ΠΎΠ΄ΠΈΠ½Π°ΠΊΠΎΠ²Ρ‹ΠΌ экспортом: + +```js +export * from './.svg-sprite/index.js' +``` + +Π˜ΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ сгСнСрированный Preact-ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ Π½Π° plain JavaScript: + +```jsx +import { AppIcon } from '../assets/app-icons/index.js' + +export function SaveIcon() { + return ( + + ) +} +``` + +Vite автоматичСски выпускаСт ΠΈΠΌΠΏΠΎΡ€Ρ‚ΠΈΡ€ΠΎΠ²Π°Π½Π½Ρ‹ΠΉ `sprite.svg` ΠΊΠ°ΠΊ production asset. + +## Π”Π΅Π±Π°Π³ ΠΈ ΠΏΡ€Π΅Π²ΡŒΡŽ + +УстановитС Viewer Ρ‚ΠΎΠ»ΡŒΠΊΠΎ для Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠΈ: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +ΠŸΠΎΠ΄ΠΊΠ»ΡŽΡ‡ΠΈΡ‚Π΅ Π΅Π³ΠΎ Π² ΠΎΡ‚Π»Π°Π΄ΠΎΡ‡Π½ΠΎΠΉ entry: + +```js +import '@gromlab/svg-sprites/viewer/element' + +const viewer = document.createElement('gromlab-sprite-viewer') +viewer.sources = [() => import('../assets/app-icons/.svg-sprite/svg-sprite.manifest.js')] +document.body.append(viewer) +``` diff --git a/skills/svg-sprites-ru/references/docs/ru/guides/preact-webpack.md b/skills/svg-sprites-ru/references/docs/ru/guides/preact-webpack.md new file mode 100644 index 0000000..e16e9e6 --- /dev/null +++ b/skills/svg-sprites-ru/references/docs/ru/guides/preact-webpack.md @@ -0,0 +1,75 @@ +# SVG-спрайт для Preact Π½Π° Webpack + +Π˜Π½ΡΡ‚Ρ€ΡƒΠΊΡ†ΠΈΡ ΠΏΠΎ быстрому созданию SVG-спрайта Π² Preact-ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠΈ Π½Π° Webpack 5. + +## ГСнСрация спрайта + +Π’Ρ‹Π±Π΅Ρ€ΠΈΡ‚Π΅ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ для Π±ΡƒΠ΄ΡƒΡ‰Π΅Π³ΠΎ SVG-спрайта, Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€ `assets/app-icons`, ΠΈ создайтС Π² Π½Ρ‘ΠΌ `svg-sprite.config.json`. Π’ `input` ΡƒΠΊΠ°ΠΆΠΈΡ‚Π΅ ΠΏΡƒΡ‚ΡŒ ΠΊ ΡΡƒΡ‰Π΅ΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΠΌ SVG ΠΎΡ‚Π½ΠΎΡΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ Ρ„Π°ΠΉΠ»Π° ΠΊΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ†ΠΈΠΈ. ΠŸΠ΅Ρ€Π΅ΠΌΠ΅Ρ‰Π°Ρ‚ΡŒ ΠΈΠ»ΠΈ ΠΊΠΎΠΏΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ ΠΈΠΊΠΎΠ½ΠΊΠΈ Π½Π΅ трСбуСтся. + +```json +{ + "mode": "preact@webpack", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +ΠŸΠ°ΠΊΠ΅Ρ‚ Π½Π΅ Π½ΡƒΠΆΠ½ΠΎ Π΄ΠΎΠ±Π°Π²Π»ΡΡ‚ΡŒ Π² зависимости ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π°. ЗапускайтС Π΅Π³ΠΎ Ρ‡Π΅Ρ€Π΅Π· `npx` ΠΏΠ΅Ρ€Π΅Π΄ запуском ΠΈ сборкой Webpack: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "predev": "npm run sprites", + "dev": "webpack serve --mode development", + "prebuild": "npm run sprites", + "build": "tsc --noEmit && webpack --mode production" + } +} +``` + +## ИспользованиС спрайта + +Π‘ΠΎΠ·Π΄Π°ΠΉΡ‚Π΅ `assets/app-icons/index.js` ΠΈ `assets/app-icons/index.d.ts` с ΠΎΠ΄ΠΈΠ½Π°ΠΊΠΎΠ²Ρ‹ΠΌ экспортом: + +```js +export * from './.svg-sprite/index.js' +``` + +Π˜ΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ сгСнСрированный Preact-ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚: + +```jsx +import { AppIcon } from '../assets/app-icons/index.js' + +export function SaveIcon() { + return ( + + ) +} +``` + +Webpack Asset Modules Π²Ρ‹ΠΏΡƒΡΠΊΠ°ΡŽΡ‚ `sprite.svg` ΠΈΠ· сгСнСрированного выраТСния `new URL(...)`. + +## Π”Π΅Π±Π°Π³ ΠΈ ΠΏΡ€Π΅Π²ΡŒΡŽ + +УстановитС Viewer Ρ‚ΠΎΠ»ΡŒΠΊΠΎ для Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠΈ: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +ΠŸΠΎΠ΄ΠΊΠ»ΡŽΡ‡ΠΈΡ‚Π΅ Π΅Π³ΠΎ Π² ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½ΠΎΠΉ development entry: + +```js +import '@gromlab/svg-sprites/viewer/element' + +const viewer = document.createElement('gromlab-sprite-viewer') +viewer.sources = [() => import('../assets/app-icons/.svg-sprite/svg-sprite.manifest.js')] +document.body.append(viewer) +``` diff --git a/skills/svg-sprites-ru/references/docs/ru/guides/qwik-vite.md b/skills/svg-sprites-ru/references/docs/ru/guides/qwik-vite.md new file mode 100644 index 0000000..76532cc --- /dev/null +++ b/skills/svg-sprites-ru/references/docs/ru/guides/qwik-vite.md @@ -0,0 +1,82 @@ +# SVG-спрайт для Qwik Π½Π° Vite + +Π˜Π½ΡΡ‚Ρ€ΡƒΠΊΡ†ΠΈΡ ΠΏΠΎ быстрому созданию SVG-спрайта Π² SSR-ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠΈ Qwik Π½Π° Vite. + +## ГСнСрация спрайта + +Π’Ρ‹Π±Π΅Ρ€ΠΈΡ‚Π΅ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ для Π±ΡƒΠ΄ΡƒΡ‰Π΅Π³ΠΎ SVG-спрайта, Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€ `assets/app-icons`, ΠΈ создайтС Π² Π½Ρ‘ΠΌ `svg-sprite.config.json`. Π’ `input` ΡƒΠΊΠ°ΠΆΠΈΡ‚Π΅ ΠΏΡƒΡ‚ΡŒ ΠΊ ΡΡƒΡ‰Π΅ΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΠΌ SVG ΠΎΡ‚Π½ΠΎΡΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ Ρ„Π°ΠΉΠ»Π° ΠΊΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ†ΠΈΠΈ. ΠŸΠ΅Ρ€Π΅ΠΌΠ΅Ρ‰Π°Ρ‚ΡŒ ΠΈΠ»ΠΈ ΠΊΠΎΠΏΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ ΠΈΠΊΠΎΠ½ΠΊΠΈ Π½Π΅ трСбуСтся. + +```json +{ + "mode": "qwik@vite", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +ΠŸΠ°ΠΊΠ΅Ρ‚ Π½Π΅ Π½ΡƒΠΆΠ½ΠΎ Π΄ΠΎΠ±Π°Π²Π»ΡΡ‚ΡŒ Π² зависимости ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π°. ΠŸΠ΅Ρ€Π΅Π³Π΅Π½Π΅Ρ€ΠΈΡ€ΡƒΠΉΡ‚Π΅ спрайт Ρ‡Π΅Ρ€Π΅Π· `npx` ΠΏΠ΅Ρ€Π΅Π΄ запуском ΠΈ сборкой Vite: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "predev": "npm run sprites", + "dev": "vite --mode ssr", + "prebuild": "npm run sprites", + "build": "tsc --noEmit && vite build" + } +} +``` + +## ИспользованиС спрайта + +Π‘ΠΎΠ·Π΄Π°ΠΉΡ‚Π΅ `assets/app-icons/index.ts`: + +```ts +export * from './.svg-sprite/index.js' +``` + +Π‘Π³Π΅Π½Π΅Ρ€ΠΈΡ€ΠΎΠ²Π°Π½Π½Ρ‹ΠΉ ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ являСтся Qwik `component$` ΠΈ бСзопасСн Π²ΠΎ врСмя SSR: + +```tsx +import { component$ } from '@builder.io/qwik' +import { AppIcon } from '../assets/app-icons' + +export default component$(() => ( + +)) +``` + +ΠšΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ статичСский Vite asset import ΠΈ Π½Π΅ обращаСтся ΠΊ browser globals Π²ΠΎ врСмя SSR. + +## Π”Π΅Π±Π°Π³ ΠΈ ΠΏΡ€Π΅Π²ΡŒΡŽ + +Viewer Ρ€Π°Π±ΠΎΡ‚Π°Π΅Ρ‚ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ Π² Π±Ρ€Π°ΡƒΠ·Π΅Ρ€Π΅ ΠΈ Π½ΡƒΠΆΠ΅Π½ лишь для Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠΈ: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +Π—Π°Π³Ρ€ΡƒΠ·ΠΈΡ‚Π΅ Π΅Π³ΠΎ ΠΈΠ· visible task: + +```tsx +import { component$, useSignal, useVisibleTask$ } from '@builder.io/qwik' +import type { SpriteViewerElement } from '@gromlab/svg-sprites/viewer' + +export const IconViewer = component$(() => { + const host = useSignal() + useVisibleTask$(async () => { + await import('@gromlab/svg-sprites/viewer/element') + const viewer = document.createElement('gromlab-sprite-viewer') as SpriteViewerElement + viewer.sources = [() => import('../assets/app-icons/.svg-sprite/svg-sprite.manifest.js')] + host.value?.append(viewer) + }) + return
+}) +``` diff --git a/skills/svg-sprites-ru/references/docs/ru/guides/react-vite.md b/skills/svg-sprites-ru/references/docs/ru/guides/react-vite.md new file mode 100644 index 0000000..1f7018c --- /dev/null +++ b/skills/svg-sprites-ru/references/docs/ru/guides/react-vite.md @@ -0,0 +1,115 @@ +# SVG-спрайт для React Π½Π° Vite + +Π˜Π½ΡΡ‚Ρ€ΡƒΠΊΡ†ΠΈΡ ΠΏΠΎ быстрому созданию SVG-спрайта Π² React-ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠΈ Π½Π° Vite. + +## ГСнСрация спрайта + +Π’Ρ‹Π±Π΅Ρ€ΠΈΡ‚Π΅ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ для Π±ΡƒΠ΄ΡƒΡ‰Π΅Π³ΠΎ SVG-спрайта, Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€ `assets/app-icons`, ΠΈ создайтС Π² Π½Ρ‘ΠΌ `svg-sprite.config.json`. Π’ `input` ΡƒΠΊΠ°ΠΆΠΈΡ‚Π΅ ΠΏΡƒΡ‚ΡŒ ΠΊ ΡΡƒΡ‰Π΅ΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΠΌ SVG ΠΎΡ‚Π½ΠΎΡΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ Ρ„Π°ΠΉΠ»Π° ΠΊΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ†ΠΈΠΈ. ΠŸΠ΅Ρ€Π΅ΠΌΠ΅Ρ‰Π°Ρ‚ΡŒ ΠΈΠ»ΠΈ ΠΊΠΎΠΏΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ ΠΈΠΊΠΎΠ½ΠΊΠΈ Π½Π΅ трСбуСтся. + +ΠŸΡ€ΠΈΠΌΠ΅Ρ€ ΠΊΠΎΠ½Ρ„ΠΈΠ³Π°: + +```json +{ + "mode": "react@vite", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +ΠŸΠ°ΠΊΠ΅Ρ‚ Π½Π΅ Π½ΡƒΠΆΠ½ΠΎ Π΄ΠΎΠ±Π°Π²Π»ΡΡ‚ΡŒ Π² зависимости ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π°: гСнСрация запускаСтся Ρ‡Π΅Ρ€Π΅Π· `npx`. + +Π”ΠΎΠ±Π°Π²ΡŒΡ‚Π΅ ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ Π³Π΅Π½Π΅Ρ€Π°Ρ†ΠΈΠΈ Π² `package.json`. Π‘Π³Π΅Π½Π΅Ρ€ΠΈΡ€ΠΎΠ²Π°Π½Π½Ρ‹Π΅ Ρ„Π°ΠΉΠ»Ρ‹ ΠΏΠΎ ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ ΠΈΡΠΊΠ»ΡŽΡ‡Π΅Π½Ρ‹ ΠΈΠ· Git, поэтому `predev` ΠΈ `prebuild` ΠΏΠ΅Ρ€Π΅ΡΠΎΠ±ΠΈΡ€Π°ΡŽΡ‚ спрайт ΠΏΠ΅Ρ€Π΅Π΄ ΠΊΠ°ΠΆΠ΄Ρ‹ΠΌ запуском ΠΈ сборкой: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "predev": "npm run sprites", + "dev": "vite", + "prebuild": "npm run sprites", + "build": "tsc --noEmit && vite build" + } +} +``` + +## ИспользованиС спрайта + +Π—Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ `name: "app"` создаёт React-ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ `AppIcon`. + +Π‘ΠΎΠ·Π΄Π°ΠΉΡ‚Π΅ Ρ‚ΠΎΡ‡ΠΊΡƒ Π²Ρ…ΠΎΠ΄Π° `assets/app-icons/index.ts`: + +```ts +export * from './.svg-sprite/index.js' +``` + +Π˜ΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ Π² ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠΈ: + +```tsx +import { AppIcon } from '../assets/app-icons' + +export function SaveIcon() { + return ( + + ) +} +``` + +Бвойство `icon` ΠΏΡ€ΠΈΠ½ΠΈΠΌΠ°Π΅Ρ‚ ΠΈΠΌΠ΅Π½Π° исходных SVG Π±Π΅Π· Ρ€Π°ΡΡˆΠΈΡ€Π΅Π½ΠΈΡ. ΠœΠΎΠ½ΠΎΡ…Ρ€ΠΎΠΌΠ½Π°Ρ ΠΈΠΊΠΎΠ½ΠΊΠ° наслСдуСт `color`, Π° Ρ†Π²Π΅Ρ‚Π° ΠΌΠ½ΠΎΠ³ΠΎΡ†Π²Π΅Ρ‚Π½ΠΎΠΉ ΠΏΠ΅Ρ€Π΅ΠΎΠΏΡ€Π΅Π΄Π΅Π»ΡΡŽΡ‚ΡΡ Ρ‡Π΅Ρ€Π΅Π· `--icon-color-N`. + +Vite сам ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π°Π΅Ρ‚ стили ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚Π° ΠΈ добавляСт `sprite.svg` Π² ΠΈΡ‚ΠΎΠ³ΠΎΠ²ΡƒΡŽ сборку. + +## Π”Π΅Π±Π°Π³ ΠΈ ΠΏΡ€Π΅Π²ΡŒΡŽ + +Viewer ΠΏΠΎΠΊΠ°Π·Ρ‹Π²Π°Π΅Ρ‚ всС ΠΈΠΊΠΎΠ½ΠΊΠΈ Π½Π° ΠΎΠ΄Π½ΠΎΠΉ страницС, позволяСт ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΈΡ‚ΡŒ ΠΈΡ… ΠΎΡ‚ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅, ΠΈΠ·ΠΌΠ΅Π½ΠΈΡ‚ΡŒ Ρ†Π²Π΅Ρ‚Π° ΠΈ ΠΏΠΎΡΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ связанныС CSS-ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅. Он Π½ΡƒΠΆΠ΅Π½ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ для Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠΈ ΠΈ устанавливаСтся ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½ΠΎ: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +Π‘ΠΎΠ·Π΄Π°ΠΉΡ‚Π΅ `svg-sprite.html` Π² ΠΊΠΎΡ€Π½Π΅ ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π°: + +```html + + + + + Иконки ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π° + + + +
+ + + + + +``` + +Π‘ΠΎΠ·Π΄Π°ΠΉΡ‚Π΅ `src/svg-sprite-debug.tsx`: + +```tsx +import { createRoot } from 'react-dom/client' +import { SpriteViewer } from '@gromlab/svg-sprites/react' + +const sources = [ + () => import('../assets/app-icons/.svg-sprite/svg-sprite.manifest.js'), +] as const + +createRoot(document.getElementById('svg-sprite-viewer')!).render( + , +) +``` + +ЗапуститС `npm run dev` ΠΈ ΠΎΡ‚ΠΊΡ€ΠΎΠΉΡ‚Π΅ `/svg-sprite.html`. + +Бтандартная production-сборка Vite ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ `index.html` ΠΈ Π½Π΅ Π²ΠΊΠ»ΡŽΡ‡Π°Π΅Ρ‚ страницу Viewer. diff --git a/skills/svg-sprites-ru/references/docs/ru/guides/react-webpack.md b/skills/svg-sprites-ru/references/docs/ru/guides/react-webpack.md new file mode 100644 index 0000000..6508c0a --- /dev/null +++ b/skills/svg-sprites-ru/references/docs/ru/guides/react-webpack.md @@ -0,0 +1,132 @@ +# SVG-спрайт для React Π½Π° Webpack 5 + +Π˜Π½ΡΡ‚Ρ€ΡƒΠΊΡ†ΠΈΡ ΠΏΠΎ быстрому созданию SVG-спрайта Π² React-ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠΈ Π½Π° Webpack 5. + +## ГСнСрация спрайта + +Π’Ρ‹Π±Π΅Ρ€ΠΈΡ‚Π΅ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ для Π±ΡƒΠ΄ΡƒΡ‰Π΅Π³ΠΎ SVG-спрайта, Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€ `assets/app-icons`, ΠΈ создайтС Π² Π½Ρ‘ΠΌ `svg-sprite.config.json`. Π’ `input` ΡƒΠΊΠ°ΠΆΠΈΡ‚Π΅ ΠΏΡƒΡ‚ΡŒ ΠΊ ΡΡƒΡ‰Π΅ΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΠΌ SVG ΠΎΡ‚Π½ΠΎΡΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ Ρ„Π°ΠΉΠ»Π° ΠΊΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ†ΠΈΠΈ. ΠŸΠ΅Ρ€Π΅ΠΌΠ΅Ρ‰Π°Ρ‚ΡŒ ΠΈΠ»ΠΈ ΠΊΠΎΠΏΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ ΠΈΠΊΠΎΠ½ΠΊΠΈ Π½Π΅ трСбуСтся. + +ΠŸΡ€ΠΈΠΌΠ΅Ρ€ ΠΊΠΎΠ½Ρ„ΠΈΠ³Π°: + +```json +{ + "mode": "react@webpack", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +ΠŸΠ°ΠΊΠ΅Ρ‚ Π½Π΅ Π½ΡƒΠΆΠ½ΠΎ Π΄ΠΎΠ±Π°Π²Π»ΡΡ‚ΡŒ Π² зависимости ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π°: гСнСрация запускаСтся Ρ‡Π΅Ρ€Π΅Π· `npx`. + +Π”ΠΎΠ±Π°Π²ΡŒΡ‚Π΅ ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ Π³Π΅Π½Π΅Ρ€Π°Ρ†ΠΈΠΈ Π² `package.json`. Π‘Π³Π΅Π½Π΅Ρ€ΠΈΡ€ΠΎΠ²Π°Π½Π½Ρ‹Π΅ Ρ„Π°ΠΉΠ»Ρ‹ ΠΏΠΎ ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ ΠΈΡΠΊΠ»ΡŽΡ‡Π΅Π½Ρ‹ ΠΈΠ· Git, поэтому `predev` ΠΈ `prebuild` ΠΏΠ΅Ρ€Π΅ΡΠΎΠ±ΠΈΡ€Π°ΡŽΡ‚ спрайт ΠΏΠ΅Ρ€Π΅Π΄ ΠΊΠ°ΠΆΠ΄Ρ‹ΠΌ запуском ΠΈ сборкой: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "predev": "npm run sprites", + "dev": "webpack serve --mode development", + "prebuild": "npm run sprites", + "build": "webpack --mode production" + } +} +``` + +## ИспользованиС спрайта + +Π—Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ `name: "app"` создаёт React-ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ `AppIcon`. + +Π‘ΠΎΠ·Π΄Π°ΠΉΡ‚Π΅ Ρ‚ΠΎΡ‡ΠΊΡƒ Π²Ρ…ΠΎΠ΄Π° `assets/app-icons/index.ts`: + +```ts +export * from './.svg-sprite/index.js' +``` + +Π˜ΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ Π² ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠΈ: + +```tsx +import { AppIcon } from '../assets/app-icons' + +export function SaveIcon() { + return ( + + ) +} +``` + +Бвойство `icon` ΠΏΡ€ΠΈΠ½ΠΈΠΌΠ°Π΅Ρ‚ ΠΈΠΌΠ΅Π½Π° исходных SVG Π±Π΅Π· Ρ€Π°ΡΡˆΠΈΡ€Π΅Π½ΠΈΡ. ΠœΠΎΠ½ΠΎΡ…Ρ€ΠΎΠΌΠ½Π°Ρ ΠΈΠΊΠΎΠ½ΠΊΠ° наслСдуСт `color`, Π° Ρ†Π²Π΅Ρ‚Π° ΠΌΠ½ΠΎΠ³ΠΎΡ†Π²Π΅Ρ‚Π½ΠΎΠΉ ΠΏΠ΅Ρ€Π΅ΠΎΠΏΡ€Π΅Π΄Π΅Π»ΡΡŽΡ‚ΡΡ Ρ‡Π΅Ρ€Π΅Π· `--icon-color-N`. + +ΠšΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ CSS Modules. Если ΠΏΡ€ΠΎΠ΅ΠΊΡ‚ Π΅Ρ‰Ρ‘ Π½Π΅ ΠΎΠ±Ρ€Π°Π±Π°Ρ‚Ρ‹Π²Π°Π΅Ρ‚ ΠΈΡ…, установитС loaders: + +```bash +npm install --save-dev style-loader css-loader +``` + +Π—Π°Ρ‚Π΅ΠΌ Π΄ΠΎΠ±Π°Π²ΡŒΡ‚Π΅ ΠΏΡ€Π°Π²ΠΈΠ»ΠΎ с default export Π² `webpack.config.js`: + +```js +{ + test: /\.module\.css$/i, + use: [ + 'style-loader', + { + loader: 'css-loader', + options: { modules: { namedExport: false } }, + }, + ], +} +``` + +Webpack 5 сам добавляСт `sprite.svg` Π² ΠΈΡ‚ΠΎΠ³ΠΎΠ²ΡƒΡŽ сборку. + +## Π”Π΅Π±Π°Π³ ΠΈ ΠΏΡ€Π΅Π²ΡŒΡŽ + +Viewer ΠΏΠΎΠΊΠ°Π·Ρ‹Π²Π°Π΅Ρ‚ всС ΠΈΠΊΠΎΠ½ΠΊΠΈ Π½Π° ΠΎΠ΄Π½ΠΎΠΉ страницС, позволяСт ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΈΡ‚ΡŒ ΠΈΡ… ΠΎΡ‚ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅, ΠΈΠ·ΠΌΠ΅Π½ΠΈΡ‚ΡŒ Ρ†Π²Π΅Ρ‚Π° ΠΈ ΠΏΠΎΡΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ связанныС CSS-ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅. Он Π½ΡƒΠΆΠ΅Π½ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ для Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠΈ. + +УстановитС Viewer: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +Π‘ΠΎΠ·Π΄Π°ΠΉΡ‚Π΅ entry `src/svg-sprite-debug.tsx`: + +```tsx +import { createRoot } from 'react-dom/client' +import { SpriteViewer } from '@gromlab/svg-sprites/react' + +const sources = [ + () => import('../assets/app-icons/.svg-sprite/svg-sprite.manifest.js'), +] as const + +const container = document.createElement('div') +document.body.append(container) + +createRoot(container).render( + , +) +``` + +Π”ΠΎΠ±Π°Π²ΡŒΡ‚Π΅ скрипт ΠΊ основному entry Ρ‚ΠΎΠ»ΡŒΠΊΠΎ Π² development-Ρ€Π΅ΠΆΠΈΠΌΠ΅. Π‘ΠΎΡ…Ρ€Π°Π½ΠΈΡ‚Π΅ ΠΎΡΡ‚Π°Π»ΡŒΠ½Ρ‹Π΅ настройки `webpack.config.js`: + +```js +export default (_env, argv) => ({ + // ΠžΡΡ‚Π°Π»ΡŒΠ½Ρ‹Π΅ настройки Webpack. + entry: [ + './src/main.tsx', + ...(argv.mode === 'development' ? ['./src/svg-sprite-debug.tsx'] : []), + ], +}) +``` + +ЗапуститС `npm run dev`. Viewer появится Π½Π° основной страницС прилоТСния ΠΈ Π½Π΅ ΠΏΠΎΠΏΠ°Π΄Ρ‘Ρ‚ Π² production-сборку. diff --git a/skills/svg-sprites-ru/references/docs/ru/guides/solid-start-vite.md b/skills/svg-sprites-ru/references/docs/ru/guides/solid-start-vite.md new file mode 100644 index 0000000..82c2bc2 --- /dev/null +++ b/skills/svg-sprites-ru/references/docs/ru/guides/solid-start-vite.md @@ -0,0 +1,83 @@ +# SVG-спрайт для SolidStart Π½Π° Vite + +Π˜Π½ΡΡ‚Ρ€ΡƒΠΊΡ†ΠΈΡ ΠΏΠΎ быстрому созданию SVG-спрайта Π² SSR-ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠΈ SolidStart Π½Π° Vite. + +## ГСнСрация спрайта + +Π’Ρ‹Π±Π΅Ρ€ΠΈΡ‚Π΅ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ для Π±ΡƒΠ΄ΡƒΡ‰Π΅Π³ΠΎ SVG-спрайта, Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€ `assets/app-icons`, ΠΈ создайтС Π² Π½Ρ‘ΠΌ `svg-sprite.config.json`. Π’ `input` ΡƒΠΊΠ°ΠΆΠΈΡ‚Π΅ ΠΏΡƒΡ‚ΡŒ ΠΊ ΡΡƒΡ‰Π΅ΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΠΌ SVG ΠΎΡ‚Π½ΠΎΡΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ Ρ„Π°ΠΉΠ»Π° ΠΊΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ†ΠΈΠΈ. ΠŸΠ΅Ρ€Π΅ΠΌΠ΅Ρ‰Π°Ρ‚ΡŒ ΠΈΠ»ΠΈ ΠΊΠΎΠΏΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ ΠΈΠΊΠΎΠ½ΠΊΠΈ Π½Π΅ трСбуСтся. + +```json +{ + "mode": "solid-start@vite", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +ΠŸΠ°ΠΊΠ΅Ρ‚ Π½Π΅ Π½ΡƒΠΆΠ½ΠΎ Π΄ΠΎΠ±Π°Π²Π»ΡΡ‚ΡŒ Π² зависимости ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π°. ΠŸΠ΅Ρ€Π΅Π³Π΅Π½Π΅Ρ€ΠΈΡ€ΡƒΠΉΡ‚Π΅ спрайт Ρ‡Π΅Ρ€Π΅Π· `npx` ΠΏΠ΅Ρ€Π΅Π΄ запуском ΠΈ сборкой Vinxi: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "predev": "npm run sprites", + "dev": "vinxi dev", + "prebuild": "npm run sprites", + "build": "vinxi build" + } +} +``` + +## ИспользованиС спрайта + +Π‘ΠΎΠ·Π΄Π°ΠΉΡ‚Π΅ `assets/app-icons/index.ts`: + +```ts +export * from './.svg-sprite/index.js' +``` + +Π‘Π³Π΅Π½Π΅Ρ€ΠΈΡ€ΠΎΠ²Π°Π½Π½Ρ‹ΠΉ ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ бСзопасно рСндСрится Π½Π° сСрвСрС: + +```tsx +import { AppIcon } from '../assets/app-icons' + +export default function Home() { + return ( + + ) +} +``` + +ΠšΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ статичСский Vite asset import ΠΈ Π½Π΅ обращаСтся ΠΊ browser globals Π²ΠΎ врСмя SSR. + +## Π”Π΅Π±Π°Π³ ΠΈ ΠΏΡ€Π΅Π²ΡŒΡŽ + +Viewer Ρ€Π°Π±ΠΎΡ‚Π°Π΅Ρ‚ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ Π² Π±Ρ€Π°ΡƒΠ·Π΅Ρ€Π΅ ΠΈ Π½ΡƒΠΆΠ΅Π½ лишь для Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠΈ: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +Π—Π°Π³Ρ€ΡƒΠ·ΠΈΡ‚Π΅ Π΅Π³ΠΎ ΠΈΠ· `onMount`, Ρ‡Ρ‚ΠΎΠ±Ρ‹ ΠΈΡΠΊΠ»ΡŽΡ‡ΠΈΡ‚ΡŒ ΠΈΠ· сСрвСрного Ρ€Π΅Π½Π΄Π΅Ρ€Π°: + +```tsx +import { onMount } from 'solid-js' +import type { SpriteViewerElement } from '@gromlab/svg-sprites/viewer' + +export function IconViewer() { + let host!: HTMLDivElement + onMount(async () => { + await import('@gromlab/svg-sprites/viewer/element') + const viewer = document.createElement('gromlab-sprite-viewer') as SpriteViewerElement + viewer.sources = [() => import('../assets/app-icons/.svg-sprite/svg-sprite.manifest.js')] + host.append(viewer) + }) + return
+} +``` diff --git a/skills/svg-sprites-ru/references/docs/ru/guides/solid-vite.md b/skills/svg-sprites-ru/references/docs/ru/guides/solid-vite.md new file mode 100644 index 0000000..3d0227c --- /dev/null +++ b/skills/svg-sprites-ru/references/docs/ru/guides/solid-vite.md @@ -0,0 +1,83 @@ +# SVG-спрайт для Solid Π½Π° Vite + +Π˜Π½ΡΡ‚Ρ€ΡƒΠΊΡ†ΠΈΡ ΠΏΠΎ быстрому созданию SVG-спрайта Π² Solid-ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠΈ Π½Π° Vite. + +## ГСнСрация спрайта + +Π’Ρ‹Π±Π΅Ρ€ΠΈΡ‚Π΅ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ для Π±ΡƒΠ΄ΡƒΡ‰Π΅Π³ΠΎ SVG-спрайта, Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€ `assets/app-icons`, ΠΈ создайтС Π² Π½Ρ‘ΠΌ `svg-sprite.config.json`. Π’ `input` ΡƒΠΊΠ°ΠΆΠΈΡ‚Π΅ ΠΏΡƒΡ‚ΡŒ ΠΊ ΡΡƒΡ‰Π΅ΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΠΌ SVG ΠΎΡ‚Π½ΠΎΡΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ Ρ„Π°ΠΉΠ»Π° ΠΊΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ†ΠΈΠΈ. ΠŸΠ΅Ρ€Π΅ΠΌΠ΅Ρ‰Π°Ρ‚ΡŒ ΠΈΠ»ΠΈ ΠΊΠΎΠΏΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ ΠΈΠΊΠΎΠ½ΠΊΠΈ Π½Π΅ трСбуСтся. + +```json +{ + "mode": "solid@vite", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +ΠŸΠ°ΠΊΠ΅Ρ‚ Π½Π΅ Π½ΡƒΠΆΠ½ΠΎ Π΄ΠΎΠ±Π°Π²Π»ΡΡ‚ΡŒ Π² зависимости ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π°. ЗапускайтС Π΅Π³ΠΎ Ρ‡Π΅Ρ€Π΅Π· `npx` ΠΏΠ΅Ρ€Π΅Π΄ Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠΎΠΉ ΠΈ production-сборкой: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "predev": "npm run sprites", + "dev": "vite", + "prebuild": "npm run sprites", + "build": "tsc --noEmit && vite build" + } +} +``` + +## ИспользованиС спрайта + +Π‘ΠΎΠ·Π΄Π°ΠΉΡ‚Π΅ `assets/app-icons/index.ts`: + +```ts +export * from './.svg-sprite/index.js' +``` + +Имя `app` создаёт Solid-ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ `AppIcon`: + +```tsx +import { AppIcon } from '../assets/app-icons' + +export function SaveIcon() { + return ( + + ) +} +``` + +Vite выпускаСт `sprite.svg` ΠΊΠ°ΠΊ production asset. ΠœΠΎΠ½ΠΎΡ…Ρ€ΠΎΠΌΠ½Ρ‹Π΅ ΠΈΠΊΠΎΠ½ΠΊΠΈ Π½Π°ΡΠ»Π΅Π΄ΡƒΡŽΡ‚ `color`, ΠΌΠ½ΠΎΠ³ΠΎΡ†Π²Π΅Ρ‚Π½Ρ‹Π΅ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΡŽΡ‚ `--icon-color-N`. + +## Π”Π΅Π±Π°Π³ ΠΈ ΠΏΡ€Π΅Π²ΡŒΡŽ + +Viewer Π½ΡƒΠΆΠ΅Π½ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ Π²ΠΎ врСмя Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠΈ ΠΈ устанавливаСтся ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½ΠΎ: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +ΠŸΠΎΠ΄ΠΊΠ»ΡŽΡ‡ΠΈΡ‚Π΅ Π΅Π³ΠΎ Π² ΠΎΡ‚Π»Π°Π΄ΠΎΡ‡Π½ΠΎΠΌ ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚Π΅ послС запуска Π±Ρ€Π°ΡƒΠ·Π΅Ρ€Π½ΠΎΠ³ΠΎ ΠΊΠΎΠ΄Π°: + +```tsx +import { onMount } from 'solid-js' +import type { SpriteViewerElement } from '@gromlab/svg-sprites/viewer' + +export function IconViewer() { + let host!: HTMLDivElement + onMount(async () => { + await import('@gromlab/svg-sprites/viewer/element') + const viewer = document.createElement('gromlab-sprite-viewer') as SpriteViewerElement + viewer.sources = [() => import('../assets/app-icons/.svg-sprite/svg-sprite.manifest.js')] + host.append(viewer) + }) + return
+} +``` diff --git a/skills/svg-sprites-ru/references/docs/ru/guides/solid-webpack.md b/skills/svg-sprites-ru/references/docs/ru/guides/solid-webpack.md new file mode 100644 index 0000000..602bdae --- /dev/null +++ b/skills/svg-sprites-ru/references/docs/ru/guides/solid-webpack.md @@ -0,0 +1,75 @@ +# SVG-спрайт для Solid Π½Π° Webpack + +Π˜Π½ΡΡ‚Ρ€ΡƒΠΊΡ†ΠΈΡ ΠΏΠΎ быстрому созданию SVG-спрайта Π² Solid-ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠΈ Π½Π° Webpack 5. + +## ГСнСрация спрайта + +Π’Ρ‹Π±Π΅Ρ€ΠΈΡ‚Π΅ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ для Π±ΡƒΠ΄ΡƒΡ‰Π΅Π³ΠΎ SVG-спрайта, Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€ `assets/app-icons`, ΠΈ создайтС Π² Π½Ρ‘ΠΌ `svg-sprite.config.json`. Π’ `input` ΡƒΠΊΠ°ΠΆΠΈΡ‚Π΅ ΠΏΡƒΡ‚ΡŒ ΠΊ ΡΡƒΡ‰Π΅ΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΠΌ SVG ΠΎΡ‚Π½ΠΎΡΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ Ρ„Π°ΠΉΠ»Π° ΠΊΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ†ΠΈΠΈ. ΠŸΠ΅Ρ€Π΅ΠΌΠ΅Ρ‰Π°Ρ‚ΡŒ ΠΈΠ»ΠΈ ΠΊΠΎΠΏΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ ΠΈΠΊΠΎΠ½ΠΊΠΈ Π½Π΅ трСбуСтся. + +```json +{ + "mode": "solid@webpack", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +ΠŸΠ°ΠΊΠ΅Ρ‚ Π½Π΅ Π½ΡƒΠΆΠ½ΠΎ Π΄ΠΎΠ±Π°Π²Π»ΡΡ‚ΡŒ Π² зависимости ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π°. ЗапускайтС Π΅Π³ΠΎ Ρ‡Π΅Ρ€Π΅Π· `npx` ΠΏΠ΅Ρ€Π΅Π΄ запуском ΠΈ сборкой Webpack: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "predev": "npm run sprites", + "dev": "webpack serve --mode development", + "prebuild": "npm run sprites", + "build": "tsc --noEmit && webpack --mode production" + } +} +``` + +## ИспользованиС спрайта + +Π‘ΠΎΠ·Π΄Π°ΠΉΡ‚Π΅ `assets/app-icons/index.js` ΠΈ `assets/app-icons/index.d.ts` с ΠΎΠ΄ΠΈΠ½Π°ΠΊΠΎΠ²Ρ‹ΠΌ экспортом: + +```js +export * from './.svg-sprite/index.js' +``` + +Π˜ΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ сгСнСрированный Solid-ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚: + +```jsx +import { AppIcon } from '../assets/app-icons/index.js' + +export function SaveIcon() { + return ( + + ) +} +``` + +Webpack Asset Modules Π²Ρ‹ΠΏΡƒΡΠΊΠ°ΡŽΡ‚ `sprite.svg` ΠΈΠ· сгСнСрированного `new URL(...)`. ΠžΠ±Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° `.jsx` Π΄ΠΎΠ»ΠΆΠ½Π° ΠΎΡ…Π²Π°Ρ‚Ρ‹Π²Π°Ρ‚ΡŒ сгСнСрированный Solid-ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚. + +## Π”Π΅Π±Π°Π³ ΠΈ ΠΏΡ€Π΅Π²ΡŒΡŽ + +УстановитС Viewer Ρ‚ΠΎΠ»ΡŒΠΊΠΎ для Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠΈ: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +ΠŸΠΎΠ΄ΠΊΠ»ΡŽΡ‡ΠΈΡ‚Π΅ Π΅Π³ΠΎ Π² ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½ΠΎΠΉ development entry: + +```js +import '@gromlab/svg-sprites/viewer/element' + +const viewer = document.createElement('gromlab-sprite-viewer') +viewer.sources = [() => import('../assets/app-icons/.svg-sprite/svg-sprite.manifest.js')] +document.body.append(viewer) +``` diff --git a/skills/svg-sprites-ru/references/docs/ru/guides/standalone-server.md b/skills/svg-sprites-ru/references/docs/ru/guides/standalone-server.md new file mode 100644 index 0000000..0941967 --- /dev/null +++ b/skills/svg-sprites-ru/references/docs/ru/guides/standalone-server.md @@ -0,0 +1,113 @@ +# Π£Π½ΠΈΠ²Π΅Ρ€ΡΠ°Π»ΡŒΠ½Ρ‹ΠΉ SVG-спрайт Π½Π° сСрвСрС + +Π‘Π³Π΅Π½Π΅Ρ€ΠΈΡ€ΡƒΠΉΡ‚Π΅ Π² CI ΠΈΠ»ΠΈ server worker ΡƒΠ½ΠΈΠ²Π΅Ρ€ΡΠ°Π»ΡŒΠ½Ρ‹ΠΉ SVG-спрайт, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ смогут ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ прилоТСния с Ρ€Π°Π·Π½Ρ‹ΠΌΠΈ frameworks ΠΈ bundlers. + +## ГСнСрация спрайта + +Π£ΡΡ‚Π°Π½Π°Π²Π»ΠΈΠ²Π°Ρ‚ΡŒ ΠΏΠ°ΠΊΠ΅Ρ‚ Π² worker Π½Π΅ Π½ΡƒΠΆΠ½ΠΎ. + +### 1. ΠŸΠΎΠ΄Π³ΠΎΡ‚ΠΎΠ²ΡŒΡ‚Π΅ Ρ€Π°Π±ΠΎΡ‡ΠΈΠΉ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ + +ΠŸΠΎΠΌΠ΅ΡΡ‚ΠΈΡ‚Π΅ исходныС SVG Π² ΠΏΠ°ΠΏΠΊΡƒ `icons` Ρ‚Π΅ΠΊΡƒΡ‰Π΅Π³ΠΎ workspace: + +```text +. +└── icons/ + β”œβ”€β”€ search.svg + └── settings.svg +``` + +ИмСна Ρ„Π°ΠΉΠ»ΠΎΠ² Π±Π΅Π· Ρ€Π°ΡΡˆΠΈΡ€Π΅Π½ΠΈΡ станут ΠΈΠΌΠ΅Π½Π°ΠΌΠΈ ΠΈΠΊΠΎΠ½ΠΎΠΊ. + +### 2. ЗапуститС Π³Π΅Π½Π΅Ρ€Π°Ρ†ΠΈΡŽ + +ΠŸΠ΅Ρ€Π΅Π΄Π°ΠΉΡ‚Π΅ mode, имя спрайта ΠΈ ΠΏΡƒΡ‚ΡŒ ΠΊ SVG Ρ‡Π΅Ρ€Π΅Π· CLI: + +```bash +npx --yes @gromlab/svg-sprites \ + --mode standalone@server \ + --name app \ + --input './icons/**/*.svg' \ + . +``` + +Config-Ρ„Π°ΠΉΠ» для этого worker-сцСнария Π½Π΅ Π½ΡƒΠΆΠ΅Π½. Π Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚ появится Π² `./.svg-sprite`: + +```text +. +β”œβ”€β”€ icons/ +β”‚ β”œβ”€β”€ search.svg +β”‚ └── settings.svg +└── .svg-sprite/ + β”œβ”€β”€ sprite..svg + β”œβ”€β”€ sprite-root-viewbox..svg + └── svg-sprite.manifest.json +``` + +### 3. ΠžΠΏΡƒΠ±Π»ΠΈΠΊΡƒΠΉΡ‚Π΅ Ρ€Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚ + +Π—Π°Π³Ρ€ΡƒΠ·ΠΈΡ‚Π΅ содСрТимоС `.svg-sprite` Π² ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½Ρ‹ΠΉ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ S3 bucket: + +```bash +aws s3 sync ./.svg-sprite/ s3://my-bucket/app-icons/ +``` + +Π­Ρ‚ΠΎΡ‚ ΠΆΠ΅ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ ΠΌΠΎΠΆΠ½ΠΎ Ρ€Π°Π·Π΄Π°Π²Π°Ρ‚ΡŒ Ρ‡Π΅Ρ€Π΅Π· CDN. Π’ ΠΏΡƒΠ±Π»ΠΈΡ‡Π½ΠΎΠΌ URL Π½Π΅Ρ‚ сСгмСнта `.svg-sprite`: + +```text +https://cdn.example.com/app-icons/ +β”œβ”€β”€ sprite..svg +β”œβ”€β”€ sprite-root-viewbox..svg +└── svg-sprite.manifest.json +``` + +`standalone@server` Ρ‚Π°ΠΊΠΆΠ΅ ΠΌΠΎΠΆΠ½ΠΎ Π·Π°ΠΏΡƒΡΠΊΠ°Ρ‚ΡŒ Ρ‡Π΅Ρ€Π΅Π· JSON, JavaScript ΠΈΠ»ΠΈ TypeScript config. Config ΠΏΠΎΠ΄Ρ…ΠΎΠ΄ΠΈΡ‚ для постоянных настроСк, Π»ΠΎΠΊΠ°Π»ΡŒΠ½Ρ‹Ρ… SVG ΠΈΠ· Π½Π΅ΡΠΊΠΎΠ»ΡŒΠΊΠΈΡ… ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ΠΎΠ² ΠΈ SVG, Π·Π°Π³Ρ€ΡƒΠΆΠ°Π΅ΠΌΡ‹Ρ… ΠΏΠΎ HTTP(S). + +## ИспользованиС спрайта + +Π’ consumer-ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠΈ создайтС ΠΎΠ±Ρ‹Ρ‡Π½Ρ‹ΠΉ config. НапримСр, для React с Vite: + +```text +src/app-icons/ +β”œβ”€β”€ index.ts +└── svg-sprite.config.json +``` + +Π£ΠΊΠ°ΠΆΠΈΡ‚Π΅ consumer mode ΠΈ URL manifest ΠΈΠ· CDN: + +```json +{ + "mode": "react@vite", + "source": "remote", + "input": "https://cdn.example.com/app-icons/svg-sprite.manifest.json" +} +``` + +Π”ΠΎΠ±Π°Π²ΡŒΡ‚Π΅ ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒΡΠΊΡƒΡŽ Ρ‚ΠΎΡ‡ΠΊΡƒ Π²Ρ…ΠΎΠ΄Π°: + +```ts +// src/app-icons/index.ts +export * from './.svg-sprite/index.js' +``` + +ЗапуститС ΠΎΠ±Ρ‹Ρ‡Π½ΡƒΡŽ Π³Π΅Π½Π΅Ρ€Π°Ρ†ΠΈΡŽ: + +```bash +npx --yes @gromlab/svg-sprites src/app-icons/svg-sprite.config.json +``` + +ПослС этого ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ generated-ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ Ρ‚Π°ΠΊ ΠΆΠ΅, ΠΊΠ°ΠΊ со спрайтом ΠΈΠ· Π»ΠΎΠΊΠ°Π»ΡŒΠ½Ρ‹Ρ… SVG: + +```tsx +import { AppIcon } from './app-icons' + +export function SearchButton() { + return +} +``` + +Π’ΠΎΡ‚ ΠΆΠ΅ CDN manifest ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΈΠ²Π°ΡŽΡ‚ всС 29 consumer modes. Π’ ΠΊΠ°ΠΆΠ΄ΠΎΠΌ ΠΈΠ· Π½ΠΈΡ… сохраняСтся Π½Π°Ρ‚ΠΈΠ²Π½Ρ‹ΠΉ API Π²Ρ‹Π±Ρ€Π°Π½Π½ΠΎΠ³ΠΎ framework ΠΈ bundler. + +## Π”Π΅Π±Π°Π³ ΠΈ ΠΏΡ€Π΅Π²ΡŒΡŽ + +`standalone@server` Π½Π΅ создаёт ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½ΡƒΡŽ страницу для просмотра ΠΈΠΊΠΎΠ½ΠΎΠΊ. ΠŸΠΎΠ΄ΠΊΠ»ΡŽΡ‡ΠΈΡ‚Π΅ ΠΎΠΏΡƒΠ±Π»ΠΈΠΊΠΎΠ²Π°Π½Π½Ρ‹ΠΉ спрайт ΠΊ consumer-ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΡŽ ΠΈ ΠΎΡ‚ΠΊΡ€ΠΎΠΉΡ‚Π΅ Π΅Π³ΠΎ Π² SpriteViewer: ΡƒΠ΄Π°Π»Ρ‘Π½Π½Ρ‹ΠΉ Π½Π°Π±ΠΎΡ€ Π±ΡƒΠ΄Π΅Ρ‚ ΠΎΡ‚ΠΎΠ±Ρ€Π°ΠΆΠ°Ρ‚ΡŒΡΡ Ρ‚Π°ΠΊ ΠΆΠ΅, ΠΊΠ°ΠΊ Π»ΠΎΠΊΠ°Π»ΡŒΠ½Ρ‹ΠΉ. diff --git a/skills/svg-sprites-ru/references/docs/ru/guides/standalone-vite.md b/skills/svg-sprites-ru/references/docs/ru/guides/standalone-vite.md new file mode 100644 index 0000000..dce8e9c --- /dev/null +++ b/skills/svg-sprites-ru/references/docs/ru/guides/standalone-vite.md @@ -0,0 +1,114 @@ +# SVG-спрайт для Vite Π±Π΅Π· Ρ„Ρ€Π΅ΠΉΠΌΠ²ΠΎΡ€ΠΊΠ° + +Π˜Π½ΡΡ‚Ρ€ΡƒΠΊΡ†ΠΈΡ ΠΏΠΎ быстрому созданию SVG-спрайта Π² ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠΈ Π½Π° Vite Π±Π΅Π· Ρ„Ρ€Π΅ΠΉΠΌΠ²ΠΎΡ€ΠΊΠ°. + +## ГСнСрация спрайта + +Π’Ρ‹Π±Π΅Ρ€ΠΈΡ‚Π΅ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ для Π±ΡƒΠ΄ΡƒΡ‰Π΅Π³ΠΎ SVG-спрайта, Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€ `assets/app-icons`, ΠΈ создайтС Π² Π½Ρ‘ΠΌ `svg-sprite.config.json`. Π’ `input` ΡƒΠΊΠ°ΠΆΠΈΡ‚Π΅ ΠΏΡƒΡ‚ΡŒ ΠΊ ΡΡƒΡ‰Π΅ΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΠΌ SVG ΠΎΡ‚Π½ΠΎΡΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ Ρ„Π°ΠΉΠ»Π° ΠΊΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ†ΠΈΠΈ. ΠŸΠ΅Ρ€Π΅ΠΌΠ΅Ρ‰Π°Ρ‚ΡŒ ΠΈΠ»ΠΈ ΠΊΠΎΠΏΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ ΠΈΠΊΠΎΠ½ΠΊΠΈ Π½Π΅ трСбуСтся. + +ΠŸΡ€ΠΈΠΌΠ΅Ρ€ ΠΊΠΎΠ½Ρ„ΠΈΠ³Π°: + +```json +{ + "mode": "standalone@vite", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +ΠŸΠ°ΠΊΠ΅Ρ‚ Π½Π΅ Π½ΡƒΠΆΠ½ΠΎ Π΄ΠΎΠ±Π°Π²Π»ΡΡ‚ΡŒ Π² зависимости ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π°: гСнСрация запускаСтся Ρ‡Π΅Ρ€Π΅Π· `npx`. + +Π”ΠΎΠ±Π°Π²ΡŒΡ‚Π΅ ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ Π³Π΅Π½Π΅Ρ€Π°Ρ†ΠΈΠΈ Π² `package.json`. Π‘Π³Π΅Π½Π΅Ρ€ΠΈΡ€ΠΎΠ²Π°Π½Π½Ρ‹Π΅ Ρ„Π°ΠΉΠ»Ρ‹ ΠΏΠΎ ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ ΠΈΡΠΊΠ»ΡŽΡ‡Π΅Π½Ρ‹ ΠΈΠ· Git, поэтому `predev` ΠΈ `prebuild` ΠΏΠ΅Ρ€Π΅ΡΠΎΠ±ΠΈΡ€Π°ΡŽΡ‚ спрайт ΠΏΠ΅Ρ€Π΅Π΄ ΠΊΠ°ΠΆΠ΄Ρ‹ΠΌ запуском ΠΈ сборкой: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "predev": "npm run sprites", + "dev": "vite", + "prebuild": "npm run sprites", + "build": "vite build" + } +} +``` + +## ИспользованиС спрайта + +Π—Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ `name: "app"` создаёт элСмСнт ``. + +Π‘ΠΎΠ·Π΄Π°ΠΉΡ‚Π΅ Ρ‚ΠΎΡ‡ΠΊΡƒ Π²Ρ…ΠΎΠ΄Π° `assets/app-icons/index.ts`: + +```ts +export * from './.svg-sprite/index.js' +``` + +ЗарСгистрируйтС элСмСнт Π² `src/main.ts`: + +```ts +import { defineAppIconElement } from '../assets/app-icons' +import './style.css' + +defineAppIconElement() +``` + +Π˜ΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ ΠΈΠΊΠΎΠ½ΠΊΡƒ Π² HTML: + +```html + +``` + +Π—Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ `icon` β€” имя исходного SVG Π±Π΅Π· Ρ€Π°ΡΡˆΠΈΡ€Π΅Π½ΠΈΡ. Π Π°Π·ΠΌΠ΅Ρ€ ΠΈ Ρ†Π²Π΅Ρ‚Π° Π½Π°ΡΡ‚Ρ€Π°ΠΈΠ²Π°ΡŽΡ‚ΡΡ Ρ‡Π΅Ρ€Π΅Π· CSS: + +```css +app-icon { + font-size: 24px; + color: #334155; + --icon-color-2: #f59e0b; +} +``` + +ΠœΠΎΠ½ΠΎΡ…Ρ€ΠΎΠΌΠ½Π°Ρ ΠΈΠΊΠΎΠ½ΠΊΠ° наслСдуСт `color`, Π° Ρ†Π²Π΅Ρ‚Π° ΠΌΠ½ΠΎΠ³ΠΎΡ†Π²Π΅Ρ‚Π½ΠΎΠΉ ΠΈΠΊΠΎΠ½ΠΊΠΈ ΠΏΠ΅Ρ€Π΅ΠΎΠΏΡ€Π΅Π΄Π΅Π»ΡΡŽΡ‚ΡΡ Ρ‡Π΅Ρ€Π΅Π· `--icon-color-N`. НуТныС ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅ ΠΏΠΎΠΊΠ°Π·Ρ‹Π²Π°Π΅Ρ‚ Viewer. + +Vite сам Π΄ΠΎΠ±Π°Π²ΠΈΡ‚ `sprite.svg` Π² ΠΈΡ‚ΠΎΠ³ΠΎΠ²ΡƒΡŽ сборку. ΠšΠΎΠΏΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ Π΅Π³ΠΎ Π² `public` Π½Π΅ Π½ΡƒΠΆΠ½ΠΎ. + +## Π”Π΅Π±Π°Π³ ΠΈ ΠΏΡ€Π΅Π²ΡŒΡŽ + +Viewer ΠΏΠΎΠΊΠ°Π·Ρ‹Π²Π°Π΅Ρ‚ всС ΠΈΠΊΠΎΠ½ΠΊΠΈ Π½Π° ΠΎΠ΄Π½ΠΎΠΉ страницС, позволяСт ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΈΡ‚ΡŒ ΠΈΡ… ΠΎΡ‚ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅, ΠΈΠ·ΠΌΠ΅Π½ΠΈΡ‚ΡŒ Ρ†Π²Π΅Ρ‚Π° ΠΈ ΠΏΠΎΡΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ связанныС CSS-ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅. Он Π½ΡƒΠΆΠ΅Π½ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ для Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠΈ ΠΈ устанавливаСтся ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½ΠΎ: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +Π‘ΠΎΠ·Π΄Π°ΠΉΡ‚Π΅ `svg-sprite.html` Π² ΠΊΠΎΡ€Π½Π΅ ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π°: + +```html + + + + + Иконки ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π° + + + + + + + + + +``` + +Π‘ΠΎΠ·Π΄Π°ΠΉΡ‚Π΅ `src/svg-sprite-debug.ts`: + +```ts +import '@gromlab/svg-sprites/viewer/element' +import type { SpriteViewerElement } from '@gromlab/svg-sprites/viewer' +import spriteManifest from '../assets/app-icons/.svg-sprite/svg-sprite.manifest.js' + +const viewer = document.querySelector('gromlab-sprite-viewer')! +viewer.sources = [spriteManifest] +``` + +ЗапуститС `npm run dev` ΠΈ ΠΎΡ‚ΠΊΡ€ΠΎΠΉΡ‚Π΅ `/svg-sprite.html`. + +Viewer Π½Π΅ трСбуСтся для Ρ€Π°Π±ΠΎΡ‚Ρ‹ `` ΠΈ Π½Π΅ ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π°Π΅Ρ‚ΡΡ ΠΊ основному ΠΊΠΎΠ΄Ρƒ прилоТСния. diff --git a/skills/svg-sprites-ru/references/docs/ru/guides/standalone-webpack.md b/skills/svg-sprites-ru/references/docs/ru/guides/standalone-webpack.md new file mode 100644 index 0000000..cb14be8 --- /dev/null +++ b/skills/svg-sprites-ru/references/docs/ru/guides/standalone-webpack.md @@ -0,0 +1,111 @@ +# SVG-спрайт для Webpack 5 Π±Π΅Π· Ρ„Ρ€Π΅ΠΉΠΌΠ²ΠΎΡ€ΠΊΠ° + +Π˜Π½ΡΡ‚Ρ€ΡƒΠΊΡ†ΠΈΡ ΠΏΠΎ быстрому созданию SVG-спрайта Π² ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠΈ Π½Π° Webpack 5 Π±Π΅Π· Ρ„Ρ€Π΅ΠΉΠΌΠ²ΠΎΡ€ΠΊΠ°. + +## ГСнСрация спрайта + +Π’Ρ‹Π±Π΅Ρ€ΠΈΡ‚Π΅ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ для Π±ΡƒΠ΄ΡƒΡ‰Π΅Π³ΠΎ SVG-спрайта, Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€ `assets/app-icons`, ΠΈ создайтС Π² Π½Ρ‘ΠΌ `svg-sprite.config.json`. Π’ `input` ΡƒΠΊΠ°ΠΆΠΈΡ‚Π΅ ΠΏΡƒΡ‚ΡŒ ΠΊ ΡΡƒΡ‰Π΅ΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΠΌ SVG ΠΎΡ‚Π½ΠΎΡΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ Ρ„Π°ΠΉΠ»Π° ΠΊΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ†ΠΈΠΈ. ΠŸΠ΅Ρ€Π΅ΠΌΠ΅Ρ‰Π°Ρ‚ΡŒ ΠΈΠ»ΠΈ ΠΊΠΎΠΏΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ ΠΈΠΊΠΎΠ½ΠΊΠΈ Π½Π΅ трСбуСтся. + +ΠŸΡ€ΠΈΠΌΠ΅Ρ€ ΠΊΠΎΠ½Ρ„ΠΈΠ³Π°: + +```json +{ + "mode": "standalone@webpack", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +ΠŸΠ°ΠΊΠ΅Ρ‚ Π½Π΅ Π½ΡƒΠΆΠ½ΠΎ Π΄ΠΎΠ±Π°Π²Π»ΡΡ‚ΡŒ Π² зависимости ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π°: гСнСрация запускаСтся Ρ‡Π΅Ρ€Π΅Π· `npx`. + +Π”ΠΎΠ±Π°Π²ΡŒΡ‚Π΅ ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ Π³Π΅Π½Π΅Ρ€Π°Ρ†ΠΈΠΈ Π² `package.json`. Π‘Π³Π΅Π½Π΅Ρ€ΠΈΡ€ΠΎΠ²Π°Π½Π½Ρ‹Π΅ Ρ„Π°ΠΉΠ»Ρ‹ ΠΏΠΎ ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ ΠΈΡΠΊΠ»ΡŽΡ‡Π΅Π½Ρ‹ ΠΈΠ· Git, поэтому `predev` ΠΈ `prebuild` ΠΏΠ΅Ρ€Π΅ΡΠΎΠ±ΠΈΡ€Π°ΡŽΡ‚ спрайт ΠΏΠ΅Ρ€Π΅Π΄ ΠΊΠ°ΠΆΠ΄Ρ‹ΠΌ запуском ΠΈ сборкой: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "predev": "npm run sprites", + "dev": "webpack serve --mode development", + "prebuild": "npm run sprites", + "build": "webpack --mode production" + } +} +``` + +## ИспользованиС спрайта + +Π—Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ `name: "app"` создаёт элСмСнт ``. + +Π‘ΠΎΠ·Π΄Π°ΠΉΡ‚Π΅ Ρ‚ΠΎΡ‡ΠΊΡƒ Π²Ρ…ΠΎΠ΄Π° `assets/app-icons/index.ts`: + +```ts +export * from './.svg-sprite/index.js' +``` + +ЗарСгистрируйтС элСмСнт Π² основном entry прилоТСния: + +```ts +import { defineAppIconElement } from '../assets/app-icons' +import './style.css' + +defineAppIconElement() +``` + +Π˜ΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ ΠΈΠΊΠΎΠ½ΠΊΡƒ Π² HTML: + +```html + +``` + +Π—Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ `icon` β€” имя исходного SVG Π±Π΅Π· Ρ€Π°ΡΡˆΠΈΡ€Π΅Π½ΠΈΡ. Π Π°Π·ΠΌΠ΅Ρ€ ΠΈ Ρ†Π²Π΅Ρ‚Π° Π½Π°ΡΡ‚Ρ€Π°ΠΈΠ²Π°ΡŽΡ‚ΡΡ Ρ‡Π΅Ρ€Π΅Π· CSS: + +```css +app-icon { + font-size: 24px; + color: #334155; + --icon-color-2: #f59e0b; +} +``` + +ΠœΠΎΠ½ΠΎΡ…Ρ€ΠΎΠΌΠ½Π°Ρ ΠΈΠΊΠΎΠ½ΠΊΠ° наслСдуСт `color`, Π° Ρ†Π²Π΅Ρ‚Π° ΠΌΠ½ΠΎΠ³ΠΎΡ†Π²Π΅Ρ‚Π½ΠΎΠΉ ΠΈΠΊΠΎΠ½ΠΊΠΈ ΠΏΠ΅Ρ€Π΅ΠΎΠΏΡ€Π΅Π΄Π΅Π»ΡΡŽΡ‚ΡΡ Ρ‡Π΅Ρ€Π΅Π· `--icon-color-N`. НуТныС ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅ ΠΏΠΎΠΊΠ°Π·Ρ‹Π²Π°Π΅Ρ‚ Viewer. + +Webpack 5 сам Π΄ΠΎΠ±Π°Π²ΠΈΡ‚ `sprite.svg` Π² ΠΈΡ‚ΠΎΠ³ΠΎΠ²ΡƒΡŽ сборку. + +## Π”Π΅Π±Π°Π³ ΠΈ ΠΏΡ€Π΅Π²ΡŒΡŽ + +Viewer ΠΏΠΎΠΊΠ°Π·Ρ‹Π²Π°Π΅Ρ‚ всС ΠΈΠΊΠΎΠ½ΠΊΠΈ Π½Π° ΠΎΠ΄Π½ΠΎΠΉ страницС, позволяСт ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΈΡ‚ΡŒ ΠΈΡ… ΠΎΡ‚ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅, ΠΈΠ·ΠΌΠ΅Π½ΠΈΡ‚ΡŒ Ρ†Π²Π΅Ρ‚Π° ΠΈ ΠΏΠΎΡΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ связанныС CSS-ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅. Он Π½ΡƒΠΆΠ΅Π½ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ для Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠΈ. + +УстановитС Viewer: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +Π‘ΠΎΠ·Π΄Π°ΠΉΡ‚Π΅ entry `src/svg-sprite-debug.ts`: + +```ts +import '@gromlab/svg-sprites/viewer/element' +import type { SpriteViewerElement } from '@gromlab/svg-sprites/viewer' +import spriteManifest from '../assets/app-icons/.svg-sprite/svg-sprite.manifest.js' + +const viewer = document.createElement('gromlab-sprite-viewer') as SpriteViewerElement +viewer.viewerTitle = 'Иконки ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π°' +viewer.sources = [spriteManifest] +document.body.append(viewer) +``` + +Π”ΠΎΠ±Π°Π²ΡŒΡ‚Π΅ скрипт ΠΊ основному entry Ρ‚ΠΎΠ»ΡŒΠΊΠΎ Π² development-Ρ€Π΅ΠΆΠΈΠΌΠ΅. Π‘ΠΎΡ…Ρ€Π°Π½ΠΈΡ‚Π΅ ΠΎΡΡ‚Π°Π»ΡŒΠ½Ρ‹Π΅ настройки `webpack.config.js`: + +```js +export default (_env, argv) => ({ + // ΠžΡΡ‚Π°Π»ΡŒΠ½Ρ‹Π΅ настройки Webpack. + entry: [ + './src/main.ts', + ...(argv.mode === 'development' ? ['./src/svg-sprite-debug.ts'] : []), + ], +}) +``` + +ЗапуститС `npm run dev`. Viewer появится Π½Π° основной страницС прилоТСния. + +Viewer добавляСтся Ρ‚ΠΎΠ»ΡŒΠΊΠΎ Π² development-сборку ΠΈ Π½Π΅ ΠΏΠΎΠΏΠ°Π΄Π°Π΅Ρ‚ Π² production. diff --git a/skills/svg-sprites-ru/references/docs/ru/guides/standalone.md b/skills/svg-sprites-ru/references/docs/ru/guides/standalone.md new file mode 100644 index 0000000..9b2ecf9 --- /dev/null +++ b/skills/svg-sprites-ru/references/docs/ru/guides/standalone.md @@ -0,0 +1,83 @@ +# SVG-спрайт для сайта Π±Π΅Π· сборщика + +Π‘ΠΎΠ±Π΅Ρ€ΠΈΡ‚Π΅ SVG-ΠΈΠΊΠΎΠ½ΠΊΠΈ Π² ΠΎΠ΄ΠΈΠ½ Ρ„Π°ΠΉΠ» ΠΈ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ ΠΈΡ… Π½Π° HTML-страницС. + +## ГСнСрация спрайта + +Π£ΡΡ‚Π°Π½Π°Π²Π»ΠΈΠ²Π°Ρ‚ΡŒ ΠΏΠ°ΠΊΠ΅Ρ‚ Π² ΠΏΡ€ΠΎΠ΅ΠΊΡ‚ Π½Π΅ Π½ΡƒΠΆΠ½ΠΎ. + +### 1. Π‘ΠΎΠ·Π΄Π°ΠΉΡ‚Π΅ ΠΊΠΎΠ½Ρ„ΠΈΠ³ спрайта + +Π’Ρ‹Π±Π΅Ρ€ΠΈΡ‚Π΅ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ для Π±ΡƒΠ΄ΡƒΡ‰Π΅Π³ΠΎ SVG-спрайта, Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€ `assets/app-icons`, ΠΈ создайтС Π² Π½Ρ‘ΠΌ `svg-sprite.config.json`. Π’ `input` ΡƒΠΊΠ°ΠΆΠΈΡ‚Π΅ ΠΏΡƒΡ‚ΡŒ ΠΊ ΡΡƒΡ‰Π΅ΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΠΌ SVG ΠΎΡ‚Π½ΠΎΡΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ Ρ„Π°ΠΉΠ»Π° ΠΊΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ†ΠΈΠΈ. ΠŸΠ΅Ρ€Π΅ΠΌΠ΅Ρ‰Π°Ρ‚ΡŒ ΠΈΠ»ΠΈ ΠΊΠΎΠΏΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ ΠΈΠΊΠΎΠ½ΠΊΠΈ Π½Π΅ трСбуСтся. + +```json +{ + "mode": "standalone", + "name": "icons", + "input": "../svg-icons/**/*.svg" +} +``` + +### 2. Π‘Π³Π΅Π½Π΅Ρ€ΠΈΡ€ΡƒΠΉΡ‚Π΅ спрайт + +ΠŸΠ΅Ρ€Π΅Π΄Π°ΠΉΡ‚Π΅ ΠΊΠΎΠΌΠ°Π½Π΄Π΅ ΠΏΡƒΡ‚ΡŒ ΠΊ ΠΊΠΎΠ½Ρ„ΠΈΠ³Ρƒ: + +```bash +npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json +``` + +ΠŸΠ°ΠΊΠ΅Ρ‚ собСрёт ΠΈΠΊΠΎΠ½ΠΊΠΈ Π² ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ `.svg-sprite` рядом с ΠΊΠΎΠ½Ρ„ΠΈΠ³ΠΎΠΌ: + +```text +assets/app-icons/.svg-sprite/ +β”œβ”€β”€ sprite.svg +└── svg-sprite.manifest.json +``` + +- `sprite.svg` β€” Π³ΠΎΡ‚ΠΎΠ²Ρ‹ΠΉ спрайт для использования Π½Π° сайтС. +- `svg-sprite.manifest.json` β€” Π΄Π°Π½Π½Ρ‹Π΅ ΠΎΠ± ΠΈΠΊΠΎΠ½ΠΊΠ°Ρ… для Viewer. + +ΠšΠ°Ρ‚Π°Π»ΠΎΠ³ `.svg-sprite` создаётся автоматичСски ΠΈ ΠΏΠΎΠ»Π½ΠΎΡΡ‚ΡŒΡŽ замСняСтся ΠΏΡ€ΠΈ ΠΊΠ°ΠΆΠ΄ΠΎΠΉ Π³Π΅Π½Π΅Ρ€Π°Ρ†ΠΈΠΈ. НС Ρ€Π΅Π΄Π°ΠΊΡ‚ΠΈΡ€ΡƒΠΉΡ‚Π΅ Π΅Π³ΠΎ содСрТимоС Π²Ρ€ΡƒΡ‡Π½ΡƒΡŽ. + +### 3. Π˜ΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ ΠΈΠΊΠΎΠ½ΠΊΡƒ + +Π’ `index.html` ΡƒΠΊΠ°ΠΆΠΈΡ‚Π΅ ΠΏΡƒΡ‚ΡŒ ΠΊ созданному `sprite.svg`. ПослС `#` Π΄ΠΎΠ±Π°Π²ΡŒΡ‚Π΅ имя Π½ΡƒΠΆΠ½ΠΎΠΉ ΠΈΠΊΠΎΠ½ΠΊΠΈ Π±Π΅Π· Ρ€Π°ΡΡˆΠΈΡ€Π΅Π½ΠΈΡ `.svg`: + +```html + + + +``` + +## Π”Π΅Π±Π°Π³ ΠΈ ΠΏΡ€Π΅Π²ΡŒΡŽ + +`sprite.svg` β€” тСхничСский Ρ„Π°ΠΉΠ», Π° Π½Π΅ галСрСя ΠΈΠΊΠΎΠ½ΠΎΠΊ. ΠŸΡ€ΠΈ Π΅Π³ΠΎ ΠΎΡ‚ΠΊΡ€Ρ‹Ρ‚ΠΈΠΈ нСльзя ΡƒΠ΄ΠΎΠ±Π½ΠΎ ΠΏΡ€ΠΎΡΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ вСсь Π½Π°Π±ΠΎΡ€. ΠšΡ€ΠΎΠΌΠ΅ Ρ‚ΠΎΠ³ΠΎ, Π³Ρ€Π°Π΄ΠΈΠ΅Π½Ρ‚Ρ‹, маски, Ρ„ΠΈΠ»ΡŒΡ‚Ρ€Ρ‹ ΠΈ ссылки Π½Π° Π²Π½ΡƒΡ‚Ρ€Π΅Π½Π½ΠΈΠ΅ `id` ΠΌΠΎΠ³ΡƒΡ‚ ΠΎΡ‚ΠΎΠ±Ρ€Π°ΠΆΠ°Ρ‚ΡŒΡΡ с Π°Ρ€Ρ‚Π΅Ρ„Π°ΠΊΡ‚Π°ΠΌΠΈ. + +Для Π²ΠΈΠ·ΡƒΠ°Π»ΡŒΠ½ΠΎΠΉ ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΊΠΈ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ ΠΎΡ„ΠΈΡ†ΠΈΠ°Π»ΡŒΠ½Ρ‹ΠΉ Viewer. Он ΠΏΠΎΠΊΠ°Π·Ρ‹Π²Π°Π΅Ρ‚ всС ΠΈΠΊΠΎΠ½ΠΊΠΈ спрайта ΠΈ ΠΏΠΎΠΌΠΎΠ³Π°Π΅Ρ‚ ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΈΡ‚ΡŒ ΠΈΡ… Ρ†Π²Π΅Ρ‚Π° ΠΈ ΠΎΡ‚ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅. + +Viewer нСобязатСлСн ΠΈ ΠΏΡ€Π΅Π΄Π½Π°Π·Π½Π°Ρ‡Π΅Π½ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ для Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠΈ. Π£ΡΡ‚Π°Π½Π°Π²Π»ΠΈΠ²Π°Ρ‚ΡŒ ΠΏΠ°ΠΊΠ΅Ρ‚ Ρ‡Π΅Ρ€Π΅Π· npm Π½Π΅ Π½ΡƒΠΆΠ½ΠΎ. + +Viewer Ρ€Π°Π±ΠΎΡ‚Π°Π΅Ρ‚ Π½Π°ΠΏΡ€ΡΠΌΡƒΡŽ с Ρ„Π°ΠΉΠ»Π°ΠΌΠΈ ΠΈΠ· `.svg-sprite`. НичСго ΠΊΠΎΠΏΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ Π½Π΅ Π½ΡƒΠΆΠ½ΠΎ. + +### Π”ΠΎΠ±Π°Π²ΡŒΡ‚Π΅ Viewer Π½Π° страницу + +Π”ΠΎΠ±Π°Π²ΡŒΡ‚Π΅ Π² `index.html` module script ΠΈ ΡƒΠΊΠ°ΠΆΠΈΡ‚Π΅ ΠΏΡƒΡ‚ΠΈ ΠΊ generated manifest ΠΈ спрайту: + +```html + + + +``` + +Viewer ΠΌΠΎΠΆΠ½ΠΎ вынСсти Π² ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½Ρ‹ΠΉ HTML-Ρ„Π°ΠΉΠ» Π² ΠΊΠΎΡ€Π½Π΅ сайта, ΠΏΡ€Π΅Π΄Π½Π°Π·Π½Π°Ρ‡Π΅Π½Π½Ρ‹ΠΉ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ для Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠΈ ΠΈ ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΊΠΈ ΠΈΠΊΠΎΠ½ΠΎΠΊ. diff --git a/skills/svg-sprites-ru/references/docs/ru/guides/svelte-vite.md b/skills/svg-sprites-ru/references/docs/ru/guides/svelte-vite.md new file mode 100644 index 0000000..07ed062 --- /dev/null +++ b/skills/svg-sprites-ru/references/docs/ru/guides/svelte-vite.md @@ -0,0 +1,95 @@ +# SVG-спрайт для Svelte Π½Π° Vite + +Π˜Π½ΡΡ‚Ρ€ΡƒΠΊΡ†ΠΈΡ ΠΏΠΎ быстрому созданию SVG-спрайта Π² Svelte-ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠΈ Π½Π° Vite. + +## ГСнСрация спрайта + +Π’Ρ‹Π±Π΅Ρ€ΠΈΡ‚Π΅ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ для Π±ΡƒΠ΄ΡƒΡ‰Π΅Π³ΠΎ SVG-спрайта, Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€ `assets/app-icons`, ΠΈ создайтС Π² Π½Ρ‘ΠΌ `svg-sprite.config.json`. Π’ `input` ΡƒΠΊΠ°ΠΆΠΈΡ‚Π΅ ΠΏΡƒΡ‚ΡŒ ΠΊ ΡΡƒΡ‰Π΅ΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΠΌ SVG ΠΎΡ‚Π½ΠΎΡΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ Ρ„Π°ΠΉΠ»Π° ΠΊΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ†ΠΈΠΈ. ΠŸΠ΅Ρ€Π΅ΠΌΠ΅Ρ‰Π°Ρ‚ΡŒ ΠΈΠ»ΠΈ ΠΊΠΎΠΏΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ ΠΈΠΊΠΎΠ½ΠΊΠΈ Π½Π΅ трСбуСтся. + +ΠŸΡ€ΠΈΠΌΠ΅Ρ€ ΠΊΠΎΠ½Ρ„ΠΈΠ³Π°: + +```json +{ + "mode": "svelte@vite", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +ΠŸΠ°ΠΊΠ΅Ρ‚ Π½Π΅ Π½ΡƒΠΆΠ½ΠΎ Π΄ΠΎΠ±Π°Π²Π»ΡΡ‚ΡŒ Π² зависимости ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π°: гСнСрация запускаСтся Ρ‡Π΅Ρ€Π΅Π· `npx`. + +Π”ΠΎΠ±Π°Π²ΡŒΡ‚Π΅ ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ Π³Π΅Π½Π΅Ρ€Π°Ρ†ΠΈΠΈ Π² `package.json`. Π‘Π³Π΅Π½Π΅Ρ€ΠΈΡ€ΠΎΠ²Π°Π½Π½Ρ‹Π΅ Ρ„Π°ΠΉΠ»Ρ‹ ΠΏΠΎ ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ ΠΈΡΠΊΠ»ΡŽΡ‡Π΅Π½Ρ‹ ΠΈΠ· Git, поэтому `predev` ΠΈ `prebuild` ΠΏΠ΅Ρ€Π΅ΡΠΎΠ±ΠΈΡ€Π°ΡŽΡ‚ спрайт ΠΏΠ΅Ρ€Π΅Π΄ ΠΊΠ°ΠΆΠ΄Ρ‹ΠΌ запуском ΠΈ сборкой: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "predev": "npm run sprites", + "dev": "vite", + "prebuild": "npm run sprites", + "build": "vite build" + } +} +``` + +## ИспользованиС спрайта + +Π—Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ `name: "app"` создаёт Svelte-ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ `AppIcon`. + +Π‘ΠΎΠ·Π΄Π°ΠΉΡ‚Π΅ `assets/app-icons/index.js`: + +```js +export * from './.svg-sprite/index.js' +``` + +Π˜ΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ Π² ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠΈ: + +```svelte + + + +``` + +Бвойство `icon` ΠΏΡ€ΠΈΠ½ΠΈΠΌΠ°Π΅Ρ‚ ΠΈΠΌΠ΅Π½Π° исходных SVG Π±Π΅Π· Ρ€Π°ΡΡˆΠΈΡ€Π΅Π½ΠΈΡ. ΠœΠΎΠ½ΠΎΡ…Ρ€ΠΎΠΌΠ½Π°Ρ ΠΈΠΊΠΎΠ½ΠΊΠ° наслСдуСт `color`, Π° Ρ†Π²Π΅Ρ‚Π° ΠΌΠ½ΠΎΠ³ΠΎΡ†Π²Π΅Ρ‚Π½ΠΎΠΉ ΠΏΠ΅Ρ€Π΅ΠΎΠΏΡ€Π΅Π΄Π΅Π»ΡΡŽΡ‚ΡΡ Ρ‡Π΅Ρ€Π΅Π· `--icon-color-N`. + +Vite сам ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π°Π΅Ρ‚ стили ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚Π° ΠΈ выпускаСт `sprite.svg` ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½Ρ‹ΠΌ production asset. + +## Π”Π΅Π±Π°Π³ ΠΈ ΠΏΡ€Π΅Π²ΡŒΡŽ + +Viewer ΠΏΠΎΠΊΠ°Π·Ρ‹Π²Π°Π΅Ρ‚ всС ΠΈΠΊΠΎΠ½ΠΊΠΈ Π½Π° ΠΎΠ΄Π½ΠΎΠΉ страницС, позволяСт ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΈΡ‚ΡŒ ΠΈΡ… ΠΎΡ‚ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅, ΠΈΠ·ΠΌΠ΅Π½ΠΈΡ‚ΡŒ Ρ†Π²Π΅Ρ‚Π° ΠΈ ΠΏΠΎΡΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ связанныС CSS-ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅. Он Π½ΡƒΠΆΠ΅Π½ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ для Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠΈ ΠΈ устанавливаСтся ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½ΠΎ: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +Π”ΠΎΠ±Π°Π²ΡŒΡ‚Π΅ Viewer Π½Π° страницу ΠΈΠ»ΠΈ Π² ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚, ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅ΠΌΡ‹ΠΉ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ ΠΏΡ€ΠΈ Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ΅: + +```svelte + + + +``` + +ЗапуститС `npm run dev` ΠΈ ΠΎΡ‚ΠΊΡ€ΠΎΠΉΡ‚Π΅ страницу с Viewer. НС ΠΈΠΌΠΏΠΎΡ€Ρ‚ΠΈΡ€ΡƒΠΉΡ‚Π΅ этот ΠΎΡ‚Π»Π°Π΄ΠΎΡ‡Π½Ρ‹ΠΉ ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ ΠΈΠ· production entry. diff --git a/skills/svg-sprites-ru/references/docs/ru/guides/svelte-webpack.md b/skills/svg-sprites-ru/references/docs/ru/guides/svelte-webpack.md new file mode 100644 index 0000000..32ed502 --- /dev/null +++ b/skills/svg-sprites-ru/references/docs/ru/guides/svelte-webpack.md @@ -0,0 +1,105 @@ +# SVG-спрайт для Svelte Π½Π° Webpack 5 + +Π˜Π½ΡΡ‚Ρ€ΡƒΠΊΡ†ΠΈΡ ΠΏΠΎ быстрому созданию SVG-спрайта Π² Svelte-ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠΈ Π½Π° Webpack 5. + +## ГСнСрация спрайта + +Π’Ρ‹Π±Π΅Ρ€ΠΈΡ‚Π΅ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ для Π±ΡƒΠ΄ΡƒΡ‰Π΅Π³ΠΎ SVG-спрайта, Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€ `assets/app-icons`, ΠΈ создайтС Π² Π½Ρ‘ΠΌ `svg-sprite.config.json`. Π’ `input` ΡƒΠΊΠ°ΠΆΠΈΡ‚Π΅ ΠΏΡƒΡ‚ΡŒ ΠΊ ΡΡƒΡ‰Π΅ΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΠΌ SVG ΠΎΡ‚Π½ΠΎΡΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ Ρ„Π°ΠΉΠ»Π° ΠΊΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ†ΠΈΠΈ. ΠŸΠ΅Ρ€Π΅ΠΌΠ΅Ρ‰Π°Ρ‚ΡŒ ΠΈΠ»ΠΈ ΠΊΠΎΠΏΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ ΠΈΠΊΠΎΠ½ΠΊΠΈ Π½Π΅ трСбуСтся. + +ΠŸΡ€ΠΈΠΌΠ΅Ρ€ ΠΊΠΎΠ½Ρ„ΠΈΠ³Π°: + +```json +{ + "mode": "svelte@webpack", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +ΠŸΠ°ΠΊΠ΅Ρ‚ Π½Π΅ Π½ΡƒΠΆΠ½ΠΎ Π΄ΠΎΠ±Π°Π²Π»ΡΡ‚ΡŒ Π² зависимости ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π°: гСнСрация запускаСтся Ρ‡Π΅Ρ€Π΅Π· `npx`. + +Π”ΠΎΠ±Π°Π²ΡŒΡ‚Π΅ ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ Π³Π΅Π½Π΅Ρ€Π°Ρ†ΠΈΠΈ Π² `package.json`: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "predev": "npm run sprites", + "dev": "webpack serve --mode development", + "prebuild": "npm run sprites", + "build": "webpack --mode production" + } +} +``` + +## ИспользованиС спрайта + +Π—Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ `name: "app"` создаёт Svelte-ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ `AppIcon`. + +Π‘ΠΎΠ·Π΄Π°ΠΉΡ‚Π΅ `assets/app-icons/index.js`: + +```js +export * from './.svg-sprite/index.js' +``` + +Π˜ΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ Π² ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠΈ: + +```svelte + + + +``` + +Generated-ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ являСтся Π½Π°Ρ‚ΠΈΠ²Π½Ρ‹ΠΌ `.svelte`-Ρ„Π°ΠΉΠ»ΠΎΠΌ. ΠžΠ±Ρ‹Ρ‡Π½ΠΎΠ΅ ΠΏΡ€Π°Π²ΠΈΠ»ΠΎ `svelte-loader` Π΄ΠΎΠ»ΠΆΠ½ΠΎ ΠΎΠ±Ρ€Π°Π±Π°Ρ‚Ρ‹Π²Π°Ρ‚ΡŒ `.svelte`-Ρ„Π°ΠΉΠ»Ρ‹ Π² `assets`: + +```js +{ + test: /\.svelte$/, + use: { + loader: 'svelte-loader', + options: { emitCss: false }, + }, +} +``` + +Webpack 5 ΠΎΠ±Ρ€Π°Π±Π°Ρ‚Ρ‹Π²Π°Π΅Ρ‚ asset URL ΠΈΠ· ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚Π° ΠΈ выпускаСт `sprite.svg` ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½Ρ‹ΠΌ production asset. + +## Π”Π΅Π±Π°Π³ ΠΈ ΠΏΡ€Π΅Π²ΡŒΡŽ + +Viewer ΠΏΠΎΠΊΠ°Π·Ρ‹Π²Π°Π΅Ρ‚ всС ΠΈΠΊΠΎΠ½ΠΊΠΈ Π½Π° ΠΎΠ΄Π½ΠΎΠΉ страницС, позволяСт ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΈΡ‚ΡŒ ΠΈΡ… ΠΎΡ‚ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅, ΠΈΠ·ΠΌΠ΅Π½ΠΈΡ‚ΡŒ Ρ†Π²Π΅Ρ‚Π° ΠΈ ΠΏΠΎΡΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ связанныС CSS-ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅. Он Π½ΡƒΠΆΠ΅Π½ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ для Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠΈ ΠΈ устанавливаСтся ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½ΠΎ: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +Π”ΠΎΠ±Π°Π²ΡŒΡ‚Π΅ Viewer Π² Svelte-ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚, ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅ΠΌΡ‹ΠΉ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ ΠΏΡ€ΠΈ Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ΅: + +```svelte + + + +``` + +ЗапуститС `npm run dev` ΠΈ ΠΎΡ‚ΠΊΡ€ΠΎΠΉΡ‚Π΅ страницу с Viewer. НС ΠΈΠΌΠΏΠΎΡ€Ρ‚ΠΈΡ€ΡƒΠΉΡ‚Π΅ этот ΠΎΡ‚Π»Π°Π΄ΠΎΡ‡Π½Ρ‹ΠΉ ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ ΠΈΠ· production entry. diff --git a/skills/svg-sprites-ru/references/docs/ru/guides/sveltekit-vite.md b/skills/svg-sprites-ru/references/docs/ru/guides/sveltekit-vite.md new file mode 100644 index 0000000..ccb7815 --- /dev/null +++ b/skills/svg-sprites-ru/references/docs/ru/guides/sveltekit-vite.md @@ -0,0 +1,91 @@ +# SVG-спрайт для SvelteKit Π½Π° Vite + +Π˜Π½ΡΡ‚Ρ€ΡƒΠΊΡ†ΠΈΡ ΠΏΠΎ быстрому созданию SVG-спрайта Π² SvelteKit-ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠΈ Π½Π° Vite. + +## ГСнСрация спрайта + +Π’Ρ‹Π±Π΅Ρ€ΠΈΡ‚Π΅ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ для Π±ΡƒΠ΄ΡƒΡ‰Π΅Π³ΠΎ SVG-спрайта, Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€ `assets/app-icons`, ΠΈ создайтС Π² Π½Ρ‘ΠΌ `svg-sprite.config.json`. Π’ `input` ΡƒΠΊΠ°ΠΆΠΈΡ‚Π΅ ΠΏΡƒΡ‚ΡŒ ΠΊ ΡΡƒΡ‰Π΅ΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΠΌ SVG ΠΎΡ‚Π½ΠΎΡΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ Ρ„Π°ΠΉΠ»Π° ΠΊΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ†ΠΈΠΈ. ΠŸΠ΅Ρ€Π΅ΠΌΠ΅Ρ‰Π°Ρ‚ΡŒ ΠΈΠ»ΠΈ ΠΊΠΎΠΏΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ ΠΈΠΊΠΎΠ½ΠΊΠΈ Π½Π΅ трСбуСтся. + +ΠŸΡ€ΠΈΠΌΠ΅Ρ€ ΠΊΠΎΠ½Ρ„ΠΈΠ³Π°: + +```json +{ + "mode": "sveltekit@vite", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +ΠŸΠ°ΠΊΠ΅Ρ‚ Π½Π΅ Π½ΡƒΠΆΠ½ΠΎ Π΄ΠΎΠ±Π°Π²Π»ΡΡ‚ΡŒ Π² зависимости ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π°: гСнСрация запускаСтся Ρ‡Π΅Ρ€Π΅Π· `npx`. + +Π”ΠΎΠ±Π°Π²ΡŒΡ‚Π΅ ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ Π³Π΅Π½Π΅Ρ€Π°Ρ†ΠΈΠΈ Π² `package.json`. Π‘Π³Π΅Π½Π΅Ρ€ΠΈΡ€ΠΎΠ²Π°Π½Π½Ρ‹Π΅ Ρ„Π°ΠΉΠ»Ρ‹ ΠΏΠΎ ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ ΠΈΡΠΊΠ»ΡŽΡ‡Π΅Π½Ρ‹ ΠΈΠ· Git, поэтому `predev` ΠΈ `prebuild` ΠΏΠ΅Ρ€Π΅ΡΠΎΠ±ΠΈΡ€Π°ΡŽΡ‚ спрайт ΠΏΠ΅Ρ€Π΅Π΄ ΠΊΠ°ΠΆΠ΄Ρ‹ΠΌ запуском ΠΈ сборкой: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "predev": "npm run sprites", + "dev": "vite dev", + "prebuild": "npm run sprites", + "build": "vite build" + } +} +``` + +## ИспользованиС спрайта + +Π—Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ `name: "app"` создаёт SSR-safe Svelte-ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ `AppIcon`. + +Π‘ΠΎΠ·Π΄Π°ΠΉΡ‚Π΅ `assets/app-icons/index.js`: + +```js +export * from './.svg-sprite/index.js' +``` + +Π˜ΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ Π² `src/routes/+page.svelte`: + +```svelte + + + +``` + +Бвойство `icon` ΠΏΡ€ΠΈΠ½ΠΈΠΌΠ°Π΅Ρ‚ ΠΈΠΌΠ΅Π½Π° исходных SVG Π±Π΅Π· Ρ€Π°ΡΡˆΠΈΡ€Π΅Π½ΠΈΡ. Π’ ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚Π΅ Π½Π΅Ρ‚ browser-only ΠΈΠ½ΠΈΡ†ΠΈΠ°Π»ΠΈΠ·Π°Ρ†ΠΈΠΈ, поэтому страница ΠΌΠΎΠΆΠ΅Ρ‚ Ρ€Π΅Π½Π΄Π΅Ρ€ΠΈΡ‚ΡŒΡΡ Π½Π° сСрвСрС. Vite выпускаСт `sprite.svg` ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½Ρ‹ΠΌ production asset. + +## Π”Π΅Π±Π°Π³ ΠΈ ΠΏΡ€Π΅Π²ΡŒΡŽ + +Viewer ΠΏΠΎΠΊΠ°Π·Ρ‹Π²Π°Π΅Ρ‚ всС ΠΈΠΊΠΎΠ½ΠΊΠΈ Π½Π° ΠΎΠ΄Π½ΠΎΠΉ страницС, позволяСт ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΈΡ‚ΡŒ ΠΈΡ… ΠΎΡ‚ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅, ΠΈΠ·ΠΌΠ΅Π½ΠΈΡ‚ΡŒ Ρ†Π²Π΅Ρ‚Π° ΠΈ ΠΏΠΎΡΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ связанныС CSS-ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅. Он Π½ΡƒΠΆΠ΅Π½ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ для Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠΈ ΠΈ устанавливаСтся ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½ΠΎ: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +Π‘ΠΎΠ·Π΄Π°ΠΉΡ‚Π΅ ΠΎΡ‚Π»Π°Π΄ΠΎΡ‡Π½Ρ‹ΠΉ route, Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€ `src/routes/svg-sprite/+page.svelte`. Π—Π°Π³Ρ€ΡƒΠΆΠ°ΠΉΡ‚Π΅ custom element ΠΈΠ· action, Ρ‡Ρ‚ΠΎΠ±Ρ‹ рСгистрация Π²Ρ‹ΠΏΠΎΠ»Π½ΡΠ»Π°ΡΡŒ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ Π² Π±Ρ€Π°ΡƒΠ·Π΅Ρ€Π΅: + +```svelte + + + +``` + +ЗапуститС `npm run dev` ΠΈ ΠΎΡ‚ΠΊΡ€ΠΎΠΉΡ‚Π΅ `/svg-sprite`. Action Π½Π΅ выполняСтся Π²ΠΎ врСмя SSR. diff --git a/skills/svg-sprites-ru/references/docs/ru/guides/vue-vite.md b/skills/svg-sprites-ru/references/docs/ru/guides/vue-vite.md new file mode 100644 index 0000000..fd92974 --- /dev/null +++ b/skills/svg-sprites-ru/references/docs/ru/guides/vue-vite.md @@ -0,0 +1,105 @@ +# SVG-спрайт для Vue Π½Π° Vite + +Π˜Π½ΡΡ‚Ρ€ΡƒΠΊΡ†ΠΈΡ ΠΏΠΎ быстрому созданию SVG-спрайта Π² Vue-ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠΈ Π½Π° Vite. + +## ГСнСрация спрайта + +Π’Ρ‹Π±Π΅Ρ€ΠΈΡ‚Π΅ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ для Π±ΡƒΠ΄ΡƒΡ‰Π΅Π³ΠΎ SVG-спрайта, Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€ `assets/app-icons`, ΠΈ создайтС Π² Π½Ρ‘ΠΌ `svg-sprite.config.json`. Π’ `input` ΡƒΠΊΠ°ΠΆΠΈΡ‚Π΅ ΠΏΡƒΡ‚ΡŒ ΠΊ ΡΡƒΡ‰Π΅ΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΠΌ SVG ΠΎΡ‚Π½ΠΎΡΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ Ρ„Π°ΠΉΠ»Π° ΠΊΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ†ΠΈΠΈ. ΠŸΠ΅Ρ€Π΅ΠΌΠ΅Ρ‰Π°Ρ‚ΡŒ ΠΈΠ»ΠΈ ΠΊΠΎΠΏΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ ΠΈΠΊΠΎΠ½ΠΊΠΈ Π½Π΅ трСбуСтся. + +ΠŸΡ€ΠΈΠΌΠ΅Ρ€ ΠΊΠΎΠ½Ρ„ΠΈΠ³Π°: + +```json +{ + "mode": "vue@vite", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +ΠŸΠ°ΠΊΠ΅Ρ‚ Π½Π΅ Π½ΡƒΠΆΠ½ΠΎ Π΄ΠΎΠ±Π°Π²Π»ΡΡ‚ΡŒ Π² зависимости ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π°: гСнСрация запускаСтся Ρ‡Π΅Ρ€Π΅Π· `npx`. + +Π”ΠΎΠ±Π°Π²ΡŒΡ‚Π΅ ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ Π³Π΅Π½Π΅Ρ€Π°Ρ†ΠΈΠΈ Π² `package.json`. Π‘Π³Π΅Π½Π΅Ρ€ΠΈΡ€ΠΎΠ²Π°Π½Π½Ρ‹Π΅ Ρ„Π°ΠΉΠ»Ρ‹ ΠΏΠΎ ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ ΠΈΡΠΊΠ»ΡŽΡ‡Π΅Π½Ρ‹ ΠΈΠ· Git, поэтому `predev` ΠΈ `prebuild` ΠΏΠ΅Ρ€Π΅ΡΠΎΠ±ΠΈΡ€Π°ΡŽΡ‚ спрайт ΠΏΠ΅Ρ€Π΅Π΄ ΠΊΠ°ΠΆΠ΄Ρ‹ΠΌ запуском ΠΈ сборкой: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "predev": "npm run sprites", + "dev": "vite", + "prebuild": "npm run sprites", + "build": "vue-tsc --noEmit && vite build" + } +} +``` + +## ИспользованиС спрайта + +Π—Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ `name: "app"` создаёт Vue-ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ `AppIcon`. + +Π‘ΠΎΠ·Π΄Π°ΠΉΡ‚Π΅ Ρ‚ΠΎΡ‡ΠΊΡƒ Π²Ρ…ΠΎΠ΄Π° `assets/app-icons/index.ts`: + +```ts +export * from './.svg-sprite/index.js' +``` + +Π˜ΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ Π² ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠΈ: + +```vue + + + +``` + +Бвойство `icon` ΠΏΡ€ΠΈΠ½ΠΈΠΌΠ°Π΅Ρ‚ ΠΈΠΌΠ΅Π½Π° исходных SVG Π±Π΅Π· Ρ€Π°ΡΡˆΠΈΡ€Π΅Π½ΠΈΡ. ΠœΠΎΠ½ΠΎΡ…Ρ€ΠΎΠΌΠ½Π°Ρ ΠΈΠΊΠΎΠ½ΠΊΠ° наслСдуСт `color`, Π° Ρ†Π²Π΅Ρ‚Π° ΠΌΠ½ΠΎΠ³ΠΎΡ†Π²Π΅Ρ‚Π½ΠΎΠΉ ΠΏΠ΅Ρ€Π΅ΠΎΠΏΡ€Π΅Π΄Π΅Π»ΡΡŽΡ‚ΡΡ Ρ‡Π΅Ρ€Π΅Π· `--icon-color-N`. + +Vite сам ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π°Π΅Ρ‚ стили ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚Π° ΠΈ добавляСт `sprite.svg` Π² ΠΈΡ‚ΠΎΠ³ΠΎΠ²ΡƒΡŽ сборку. + +## Π”Π΅Π±Π°Π³ ΠΈ ΠΏΡ€Π΅Π²ΡŒΡŽ + +Viewer ΠΏΠΎΠΊΠ°Π·Ρ‹Π²Π°Π΅Ρ‚ всС ΠΈΠΊΠΎΠ½ΠΊΠΈ Π½Π° ΠΎΠ΄Π½ΠΎΠΉ страницС, позволяСт ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΈΡ‚ΡŒ ΠΈΡ… ΠΎΡ‚ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅, ΠΈΠ·ΠΌΠ΅Π½ΠΈΡ‚ΡŒ Ρ†Π²Π΅Ρ‚Π° ΠΈ ΠΏΠΎΡΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ связанныС CSS-ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅. Он Π½ΡƒΠΆΠ΅Π½ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ для Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠΈ ΠΈ устанавливаСтся ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½ΠΎ: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +Π‘ΠΎΠ·Π΄Π°ΠΉΡ‚Π΅ `svg-sprite.html` Π² ΠΊΠΎΡ€Π½Π΅ ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π°: + +```html + + + + + Иконки ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π° + + + + + + +``` + +Π‘ΠΎΠ·Π΄Π°ΠΉΡ‚Π΅ `src/svg-sprite-debug.ts`: + +```ts +import '@gromlab/svg-sprites/viewer/element' +import type { SpriteViewerElement } from '@gromlab/svg-sprites/viewer' +import spriteManifest from '../assets/app-icons/.svg-sprite/svg-sprite.manifest.js' + +const viewer = document.querySelector('gromlab-sprite-viewer')! +viewer.sources = [spriteManifest] +``` + +ЗапуститС `npm run dev` ΠΈ ΠΎΡ‚ΠΊΡ€ΠΎΠΉΡ‚Π΅ `/svg-sprite.html`. + +Viewer Π½Π΅ трСбуСтся для Ρ€Π°Π±ΠΎΡ‚Ρ‹ `AppIcon` ΠΈ Π½Π΅ ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π°Π΅Ρ‚ΡΡ ΠΊ основному ΠΊΠΎΠ΄Ρƒ прилоТСния. diff --git a/skills/svg-sprites-ru/references/docs/ru/guides/vue-webpack.md b/skills/svg-sprites-ru/references/docs/ru/guides/vue-webpack.md new file mode 100644 index 0000000..3d7441c --- /dev/null +++ b/skills/svg-sprites-ru/references/docs/ru/guides/vue-webpack.md @@ -0,0 +1,126 @@ +# SVG-спрайт для Vue Π½Π° Webpack 5 + +Π˜Π½ΡΡ‚Ρ€ΡƒΠΊΡ†ΠΈΡ ΠΏΠΎ быстрому созданию SVG-спрайта Π² Vue-ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠΈ Π½Π° Webpack 5. + +## ГСнСрация спрайта + +Π’Ρ‹Π±Π΅Ρ€ΠΈΡ‚Π΅ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ для Π±ΡƒΠ΄ΡƒΡ‰Π΅Π³ΠΎ SVG-спрайта, Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€ `assets/app-icons`, ΠΈ создайтС Π² Π½Ρ‘ΠΌ `svg-sprite.config.json`. Π’ `input` ΡƒΠΊΠ°ΠΆΠΈΡ‚Π΅ ΠΏΡƒΡ‚ΡŒ ΠΊ ΡΡƒΡ‰Π΅ΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΠΌ SVG ΠΎΡ‚Π½ΠΎΡΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ Ρ„Π°ΠΉΠ»Π° ΠΊΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ†ΠΈΠΈ. ΠŸΠ΅Ρ€Π΅ΠΌΠ΅Ρ‰Π°Ρ‚ΡŒ ΠΈΠ»ΠΈ ΠΊΠΎΠΏΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ ΠΈΠΊΠΎΠ½ΠΊΠΈ Π½Π΅ трСбуСтся. + +ΠŸΡ€ΠΈΠΌΠ΅Ρ€ ΠΊΠΎΠ½Ρ„ΠΈΠ³Π°: + +```json +{ + "mode": "vue@webpack", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +ΠŸΠ°ΠΊΠ΅Ρ‚ Π½Π΅ Π½ΡƒΠΆΠ½ΠΎ Π΄ΠΎΠ±Π°Π²Π»ΡΡ‚ΡŒ Π² зависимости ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π°: гСнСрация запускаСтся Ρ‡Π΅Ρ€Π΅Π· `npx`. + +Π”ΠΎΠ±Π°Π²ΡŒΡ‚Π΅ ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ Π³Π΅Π½Π΅Ρ€Π°Ρ†ΠΈΠΈ Π² `package.json`. Π‘Π³Π΅Π½Π΅Ρ€ΠΈΡ€ΠΎΠ²Π°Π½Π½Ρ‹Π΅ Ρ„Π°ΠΉΠ»Ρ‹ ΠΏΠΎ ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ ΠΈΡΠΊΠ»ΡŽΡ‡Π΅Π½Ρ‹ ΠΈΠ· Git, поэтому `predev` ΠΈ `prebuild` ΠΏΠ΅Ρ€Π΅ΡΠΎΠ±ΠΈΡ€Π°ΡŽΡ‚ спрайт ΠΏΠ΅Ρ€Π΅Π΄ ΠΊΠ°ΠΆΠ΄Ρ‹ΠΌ запуском ΠΈ сборкой: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "predev": "npm run sprites", + "dev": "webpack serve --mode development", + "prebuild": "npm run sprites", + "build": "webpack --mode production" + } +} +``` + +## ИспользованиС спрайта + +Π—Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ `name: "app"` создаёт Vue-ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ `AppIcon`. Π‘ΠΎΠ·Π΄Π°ΠΉΡ‚Π΅ `assets/app-icons/index.js`: + +```js +export * from './.svg-sprite/index.js' +``` + +Π˜ΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ Π² ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠΈ: + +```vue + + + +``` + +Бвойство `icon` ΠΏΡ€ΠΈΠ½ΠΈΠΌΠ°Π΅Ρ‚ ΠΈΠΌΠ΅Π½Π° исходных SVG Π±Π΅Π· Ρ€Π°ΡΡˆΠΈΡ€Π΅Π½ΠΈΡ. ΠœΠΎΠ½ΠΎΡ…Ρ€ΠΎΠΌΠ½Π°Ρ ΠΈΠΊΠΎΠ½ΠΊΠ° наслСдуСт `color`, Π° Ρ†Π²Π΅Ρ‚Π° ΠΌΠ½ΠΎΠ³ΠΎΡ†Π²Π΅Ρ‚Π½ΠΎΠΉ ΠΏΠ΅Ρ€Π΅ΠΎΠΏΡ€Π΅Π΄Π΅Π»ΡΡŽΡ‚ΡΡ Ρ‡Π΅Ρ€Π΅Π· `--icon-color-N`. + +ΠšΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ CSS Modules. Если ΠΏΡ€ΠΎΠ΅ΠΊΡ‚ Π΅Ρ‰Ρ‘ Π½Π΅ ΠΎΠ±Ρ€Π°Π±Π°Ρ‚Ρ‹Π²Π°Π΅Ρ‚ ΠΈΡ…, установитС `style-loader` ΠΈ `css-loader`, Π·Π°Ρ‚Π΅ΠΌ Π΄ΠΎΠ±Π°Π²ΡŒΡ‚Π΅ ΠΏΡ€Π°Π²ΠΈΠ»ΠΎ с default export: + +```bash +npm install --save-dev style-loader css-loader +``` + +```js +{ + test: /\.module\.css$/i, + use: [ + 'style-loader', + { + loader: 'css-loader', + options: { modules: { namedExport: false } }, + }, + ], +} +``` + +Webpack 5 сам добавляСт `sprite.svg` Π² ΠΈΡ‚ΠΎΠ³ΠΎΠ²ΡƒΡŽ сборку. + +## Π”Π΅Π±Π°Π³ ΠΈ ΠΏΡ€Π΅Π²ΡŒΡŽ + +Viewer ΠΏΠΎΠΊΠ°Π·Ρ‹Π²Π°Π΅Ρ‚ всС ΠΈΠΊΠΎΠ½ΠΊΠΈ Π½Π° ΠΎΠ΄Π½ΠΎΠΉ страницС, позволяСт ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΈΡ‚ΡŒ ΠΈΡ… ΠΎΡ‚ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅, ΠΈΠ·ΠΌΠ΅Π½ΠΈΡ‚ΡŒ Ρ†Π²Π΅Ρ‚Π° ΠΈ ΠΏΠΎΡΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ связанныС CSS-ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅. Он Π½ΡƒΠΆΠ΅Π½ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ для Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠΈ ΠΈ устанавливаСтся ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½ΠΎ: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +Π”ΠΎΠ±Π°Π²ΡŒΡ‚Π΅ Viewer Π² Vue-ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚, ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π°Π΅ΠΌΡ‹ΠΉ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ ΠΏΡ€ΠΈ Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ΅: + +```vue + + + +``` + +НастройтС Vue Loader Ρ‚Π°ΠΊ, Ρ‡Ρ‚ΠΎΠ±Ρ‹ `gromlab-sprite-viewer` считался custom element: + +```js +{ + test: /\.vue$/, + loader: 'vue-loader', + options: { + compilerOptions: { + isCustomElement: (tag) => tag === 'gromlab-sprite-viewer', + }, + }, +} +``` + +ΠŸΠΎΠΊΠ°ΠΆΠΈΡ‚Π΅ ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ Viewer Π½Π° страницС Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠΈ. Viewer Π½Π΅ трСбуСтся для Ρ€Π°Π±ΠΎΡ‚Ρ‹ `AppIcon`. diff --git a/skills/svg-sprites-ru/references/docs/ru/reference/programmatic-api.md b/skills/svg-sprites-ru/references/docs/ru/reference/programmatic-api.md new file mode 100644 index 0000000..8c06a79 --- /dev/null +++ b/skills/svg-sprites-ru/references/docs/ru/reference/programmatic-api.md @@ -0,0 +1,183 @@ +# ΠŸΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½Ρ‹ΠΉ API + +[ИндСкс Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚Π°Ρ†ΠΈΠΈ](../README.md) + +ΠŸΠ°ΠΊΠ΅Ρ‚ распространяСтся ΠΊΠ°ΠΊ ESM ΠΈ прСдоставляСт Π΅Π΄ΠΈΠ½Ρ‹ΠΉ Node.js API Π³Π΅Π½Π΅Ρ€Π°Ρ†ΠΈΠΈ. Framework-neutral Viewer находится Π² `@gromlab/svg-sprites/viewer`, auto-register entry β€” Π² `@gromlab/svg-sprites/viewer/element`, React bridge β€” Π² `@gromlab/svg-sprites/react`. + +## `generateSprite` + +```ts +import { generateSprite } from '@gromlab/svg-sprites' + +const result = await generateSprite( + 'src/ui/file-manager/svg-sprite/svg-sprite.config.ts', +) +``` + +Π Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚ содСрТит имя ΠΈ mode спрайта, количСство ΠΈΠΊΠΎΠ½ΠΎΠΊ ΠΈ Π°Π±ΡΠΎΠ»ΡŽΡ‚Π½Ρ‹Π΅ filesystem paths: + +```ts +result.name +result.mode +result.target +result.iconCount +result.rootDir +result.generatedDir +result.spritePath +result.manifestPath +``` + +Next.js modes Π΄ΠΎΠΏΠΎΠ»Π½ΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ Π²ΠΎΠ·Π²Ρ€Π°Ρ‰Π°ΡŽΡ‚ `router` ΠΈ `bundler`. `standalone@server` +Π²ΠΎΠ·Π²Ρ€Π°Ρ‰Π°Π΅Ρ‚ `target: 'server'`; Π΅Π³ΠΎ `spritePath` ΡƒΠΊΠ°Π·Ρ‹Π²Π°Π΅Ρ‚ Π½Π° стандартный +content-addressed profile, Π° `manifestPath` β€” Π½Π° server manifest. + +Для static standalone mode `result.spritePath` ΠΌΠΎΠΆΠ½ΠΎ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ Π² build-скриптС, +Ρ‡Ρ‚ΠΎΠ±Ρ‹ ΠΎΠΏΡƒΠ±Π»ΠΈΠΊΠΎΠ²Π°Ρ‚ΡŒ SVG ΠΏΠΎ URL прилоТСния: + +```ts +import { copyFile } from 'node:fs/promises' + +const result = await generateSprite('src/sprite/svg-sprite.config.ts', { + mode: 'standalone', +}) +await copyFile(result.spritePath, 'dist/app-icons/sprite.svg') +``` + +`spritePath` являСтся filesystem path, Π° Π½Π΅ browser URL. Deployment-neutral JSON +manifest доступСн Ρ‡Π΅Ρ€Π΅Π· `result.manifestPath` ΠΈ копируСтся нСзависимо ΠΎΡ‚ SVG. + +ΠŸΠ΅Ρ€Π²Ρ‹ΠΉ Π°Ρ€Π³ΡƒΠΌΠ΅Π½Ρ‚ ΠΏΡ€ΠΈΠ½ΠΈΠΌΠ°Π΅Ρ‚ Π°Π±ΡΠΎΠ»ΡŽΡ‚Π½Ρ‹ΠΉ ΠΈΠ»ΠΈ ΠΎΡ‚Π½ΠΎΡΠΈΡ‚Π΅Π»ΡŒΠ½Ρ‹ΠΉ ΠΏΡƒΡ‚ΡŒ ΠΊ config-Ρ„Π°ΠΉΠ»Ρƒ с Π»ΡŽΠ±Ρ‹ΠΌ ΠΈΠΌΠ΅Π½Π΅ΠΌ ΠΈ Ρ€Π°ΡΡˆΠΈΡ€Π΅Π½ΠΈΠ΅ΠΌ `.ts`, `.js` ΠΈΠ»ΠΈ `.json`. ΠšΠ°Ρ‚Π°Π»ΠΎΠ³ вмСсто Ρ„Π°ΠΉΠ»Π° Π²ΠΊΠ»ΡŽΡ‡Π°Π΅Ρ‚ config-less Ρ€Π΅ΠΆΠΈΠΌ: ΠΊΠΎΡ€Π½Π΅ΠΌ sprite-модуля становится этот ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³. + +Π’Ρ‚ΠΎΡ€ΠΎΠΉ Π°Ρ€Π³ΡƒΠΌΠ΅Π½Ρ‚ содСрТит Π½Π΅ΠΎΠ±ΡΠ·Π°Ρ‚Π΅Π»ΡŒΠ½Ρ‹Π΅ overrides ΠΈ всСгда ΠΈΠΌΠ΅Π΅Ρ‚ ΠΏΡ€ΠΈΠΎΡ€ΠΈΡ‚Π΅Ρ‚ Π½Π°Π΄ ΠΊΠΎΠ½Ρ„ΠΈΠ³ΠΎΠΌ: + +```ts +await generateSprite('src/ui/file-manager/svg-sprite/custom-config.json', { + mode: 'react@webpack', + name: 'documents', + input: ['./assets', '../../shared/search.svg'], + transform: { + addTransition: false, + }, + generatedNotice: false, +}) +``` + +ΠŸΠΎΡ€ΡΠ΄ΠΎΠΊ Ρ€Π°Π·Ρ€Π΅ΡˆΠ΅Π½ΠΈΡ настроСк: + +```text +defaults β†’ config β†’ API overrides +``` + +Для ΠΏΠΎΠ»Π½ΠΎΡΡ‚ΡŒΡŽ ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠΉ Π³Π΅Π½Π΅Ρ€Π°Ρ†ΠΈΠΈ ΠΏΠ΅Ρ€Π΅Π΄Π°ΠΉΡ‚Π΅ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ ΠΈ всС ΠΎΠ±ΡΠ·Π°Ρ‚Π΅Π»ΡŒΠ½Ρ‹Π΅ настройки Ρ‡Π΅Ρ€Π΅Π· overrides: + +```ts +await generateSprite('src/ui/file-manager/svg-sprite', { + mode: 'react@vite', + name: 'file-manager', + input: [ + '../../shared/search.svg', + '../../shared/settings.svg', + ], +}) +``` + +## ΠšΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ†ΠΈΡ + +```ts +import { defineSpriteConfig } from '@gromlab/svg-sprites' + +export default defineSpriteConfig({ + mode: 'react@vite', + name: 'file-manager', + description: 'Иконки Ρ„Π°ΠΉΠ»ΠΎΠ²ΠΎΠ³ΠΎ ΠΌΠ΅Π½Π΅Π΄ΠΆΠ΅Ρ€Π°', + input: ['./icons', '../../shared/check.svg'], + transform: { + removeSize: true, + replaceColors: true, + addTransition: true, + }, + generatedNotice: true, +}) +``` + +`input` ΠΏΡ€ΠΈΠ½ΠΈΠΌΠ°Π΅Ρ‚ ΠΎΠ΄Π½Ρƒ ΠΏΠ°ΠΏΠΊΡƒ, SVG-Ρ„Π°ΠΉΠ» ΠΈΠ»ΠΈ glob-ΠΏΠ°Ρ‚Ρ‚Π΅Ρ€Π½ Π»ΠΈΠ±ΠΎ массив, ΠΎΠ±ΡŠΠ΅Π΄ΠΈΠ½ΡΡŽΡ‰ΠΈΠΉ Ρ‚Π°ΠΊΠΈΠ΅ источники. Если ΠΏΠΎΠ»Π΅ Π½Π΅ Π·Π°Π΄Π°Π½ΠΎ, ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ `./icons`; ΠΎΡ‚Π½ΠΎΡΠΈΡ‚Π΅Π»ΡŒΠ½Ρ‹Π΅ ΠΏΡƒΡ‚ΠΈ ΡΡ‡ΠΈΡ‚Π°ΡŽΡ‚ΡΡ ΠΎΡ‚ ΠΏΠ°ΠΏΠΊΠΈ с ΠΊΠΎΠ½Ρ„ΠΈΠ³ΠΎΠΌ. + +`defineSpriteConfig` являСтся identity helper для TypeScript autocomplete. JS ΠΌΠΎΠΆΠ΅Ρ‚ ΡΠΊΡΠΏΠΎΡ€Ρ‚ΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ Ρ‚ΠΎΡ‚ ΠΆΠ΅ ΠΎΠ±ΡŠΠ΅ΠΊΡ‚ Ρ‡Π΅Ρ€Π΅Π· `export default`, Π° JSON содСрТит ΠΎΠ±ΡŠΠ΅ΠΊΡ‚ нСпосрСдствСнно. + +ΠŸΡƒΠ±Π»ΠΈΡ‡Π½Ρ‹Π΅ Ρ‚ΠΈΠΏΡ‹ `ServerSvgInput`, `ServerSpriteManifest`, `ServerSpriteAsset` ΠΈ +`SpriteCompileProfile` ΠΎΠΏΠΈΡΡ‹Π²Π°ΡŽΡ‚ inputs ΠΈ release data для `standalone@server`. +Consumer ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ Ρ‚ΠΎΡ‚ ΠΆΠ΅ API с `source: 'remote'` ΠΈ ΠΎΠ΄Π½ΠΈΠΌ local path ΠΈΠ»ΠΈ HTTP(S) +URL manifest Π² `input`. + +## Π‘ΠΏΠ΅Ρ†ΠΈΠ°Π»ΠΈΠ·ΠΈΡ€ΠΎΠ²Π°Π½Π½Ρ‹Π΅ ΠΎΠ±Ρ‘Ρ€Ρ‚ΠΊΠΈ + +Π‘ΠΏΠ΅Ρ†ΠΈΠ°Π»ΠΈΠ·ΠΈΡ€ΠΎΠ²Π°Π½Π½Ρ‹Π΅ Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΈ доступны ΠΊΠ°ΠΊ ΠΎΠ±Ρ‘Ρ€Ρ‚ΠΊΠΈ Π½Π°Π΄ `generateSprite`: + +```ts +import { generateNextSprite, generateReactSprite } from '@gromlab/svg-sprites' + +await generateReactSprite('path/to/config.ts', 'vite') +await generateNextSprite('path/to/config.ts', { + router: 'app', + bundler: 'turbopack', +}) +``` + +Π―Π²Π½ΠΎ ΠΏΠ΅Ρ€Π΅Π΄Π°Π½Π½Ρ‹ΠΉ target ΠΏΠ΅Ρ€Π΅ΠΊΡ€Ρ‹Π²Π°Π΅Ρ‚ `mode` ΠΈΠ· Ρ„Π°ΠΉΠ»Π°. Для Π½ΠΎΠ²ΠΎΠ³ΠΎ ΠΊΠΎΠ΄Π° ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ `generateSprite`. + +## Config API + +```ts +import { + isSpriteMode, + loadSpriteConfig, + resolveSpriteConfig, + resolveSpriteConfigSource, + validateSpriteConfig, +} from '@gromlab/svg-sprites' +``` + +- `isSpriteMode(value)` провСряСт, являСтся Π»ΠΈ Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΈΠ²Π°Π΅ΠΌΡ‹ΠΌ exact mode. +- `loadSpriteConfig(file)` Π·Π°Π³Ρ€ΡƒΠΆΠ°Π΅Ρ‚ явно ΡƒΠΊΠ°Π·Π°Π½Π½Ρ‹ΠΉ `.ts`, `.js` ΠΈΠ»ΠΈ `.json` Ρ„Π°ΠΉΠ». +- `resolveSpriteConfigSource(source)` Ρ€Π°Π·Ρ€Π΅ΡˆΠ°Π΅Ρ‚ ΠΏΡƒΡ‚ΡŒ ΠΊΠ°ΠΊ config-Ρ„Π°ΠΉΠ» ΠΈΠ»ΠΈ config-less ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³. +- `validateSpriteConfig(value)` выполняСт runtime-Π²Π°Π»ΠΈΠ΄Π°Ρ†ΠΈΡŽ ΠΎΠ±ΡŠΠ΅ΠΊΡ‚Π°. +- `resolveSpriteConfig(root, config, overrides)` ΠΎΠ±ΡŠΠ΅Π΄ΠΈΠ½ΡΠ΅Ρ‚ значСния, добавляСт defaults ΠΈ Ρ€Π°Π·Ρ€Π΅ΡˆΠ°Π΅Ρ‚ ΠΏΡƒΡ‚ΠΈ ΠΎΡ‚Π½ΠΎΡΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ `root`. + +## НизкоуровнСвый compiler + +```ts +import { + compileSprite, + compileSpriteContent, + createShapeTransform, +} from '@gromlab/svg-sprites' +``` + +Π­Ρ‚ΠΈ Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΈ ΠΏΡ€Π΅Π΄Π½Π°Π·Π½Π°Ρ‡Π΅Π½Ρ‹ для собствСнного orchestration. Бтандартная гСнСрация Π΄ΠΎΠ»ΠΆΠ½Π° Π²Ρ‹ΠΏΠΎΠ»Π½ΡΡ‚ΡŒΡΡ Ρ‡Π΅Ρ€Π΅Π· `generateSprite`. + +## Viewer runtime + +```ts +import '@gromlab/svg-sprites/viewer/element' +import type { SpriteViewerElement } from '@gromlab/svg-sprites/viewer' +``` + +Browser entry рСгистрируСт ``. Bare standalone Ρ‚Π°ΠΊΠΆΠ΅ ΠΌΠΎΠΆΠ΅Ρ‚ Π·Π°Π³Ρ€ΡƒΠ·ΠΈΡ‚ΡŒ ΡΠ°ΠΌΠΎΡΡ‚ΠΎΡΡ‚Π΅Π»ΡŒΠ½Ρ‹ΠΉ `dist/viewer-element.js` Π±Π΅Π· bundler. + +Для Ρ€ΡƒΡ‡Π½ΠΎΠΉ рСгистрации ΠΈΠΌΠΏΠΎΡ€Ρ‚ΠΈΡ€ΡƒΠΉΡ‚Π΅ runtime Π±Π΅Π· auto-register entry: + +```ts +import { defineSpriteViewerElement } from '@gromlab/svg-sprites/viewer' + +defineSpriteViewerElement() +``` + +Π­Ρ‚ΠΎΡ‚ entry Ρ‚Π°ΠΊΠΆΠ΅ экспортируСт Ρ‚ΠΈΠΏΡ‹ `SpriteViewerElement`, `SpriteViewerManifest`, `SpriteViewerSource`, `SpriteViewerSources` ΠΈ связанныС Ρ‚ΠΈΠΏΡ‹ manifest ΠΈ loaders. + +React bridge сохраняСт ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚Π½Ρ‹ΠΉ API: + +```tsx +import { SpriteViewer } from '@gromlab/svg-sprites/react' +``` + +`SpriteViewer` ΠΏΡ€ΠΈΠ½ΠΈΠΌΠ°Π΅Ρ‚ generated manifests, remote standalone sources, lazy loaders ΠΈΠ»ΠΈ Ρ€Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚ `import.meta.glob`. React entry содСрТит `'use client'` ΠΈ ΠΏΡ€Π΅Π΄Π½Π°Π·Π½Π°Ρ‡Π΅Π½ для debug-инструмСнтов; production-ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚Ρ‹ ΠΈΠΌΠΏΠΎΡ€Ρ‚ΠΈΡ€ΡƒΡŽΡ‚ΡΡ ΠΈΠ· Π»ΠΎΠΊΠ°Π»ΡŒΠ½Ρ‹Ρ… sprite-ΠΌΠΎΠ΄ΡƒΠ»Π΅ΠΉ прилоТСния. diff --git a/skills/svg-sprites-ru/references/docs/ru/reference/technical.md b/skills/svg-sprites-ru/references/docs/ru/reference/technical.md new file mode 100644 index 0000000..b9957e6 --- /dev/null +++ b/skills/svg-sprites-ru/references/docs/ru/reference/technical.md @@ -0,0 +1,716 @@ +# ВСхничСский справочник + +[ИндСкс Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚Π°Ρ†ΠΈΠΈ](../README.md) + +[ΠšΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ†ΠΈΡ JSON, JavaScript ΠΈ TypeScript](../configuration.md) + +Π‘ΠΏΡ€Π°Π²ΠΎΡ‡Π½ΠΈΠΊ ΠΏΠΎ ΠΊΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ†ΠΈΠΈ, generated API ΠΈ повСдСнию `@gromlab/svg-sprites`. ΠŸΠΎΡˆΠ°Π³ΠΎΠ²ΡƒΡŽ установку смотритС Π² руководствС для вашСго стСка: + +- [Bare standalone](../guides/standalone.md) +- [Standalone + Vite](../guides/standalone-vite.md) +- [Standalone + Webpack 5](../guides/standalone-webpack.md) +- [React + Vite](../guides/react-vite.md) +- [React + Webpack 5](../guides/react-webpack.md) +- [Next.js App Router + Turbopack](../guides/next-app-turbopack.md) +- [Next.js App Router + Webpack](../guides/next-app-webpack.md) +- [Next.js Pages Router + Turbopack](../guides/next-pages-turbopack.md) +- [Next.js Pages Router + Webpack](../guides/next-pages-webpack.md) +- [Vue + Vite](../guides/vue-vite.md) +- [Vue + Webpack](../guides/vue-webpack.md) +- [Nuxt + Vite](../guides/nuxt-vite.md) +- [Nuxt + Webpack](../guides/nuxt-webpack.md) +- [Svelte + Vite](../guides/svelte-vite.md) +- [Svelte + Webpack](../guides/svelte-webpack.md) +- [SvelteKit + Vite](../guides/sveltekit-vite.md) +- [Angular application builder](../guides/angular-application.md) +- [Angular + Webpack](../guides/angular-webpack.md) +- [Astro + Vite](../guides/astro-vite.md) +- [Solid + Vite](../guides/solid-vite.md) +- [Solid + Webpack](../guides/solid-webpack.md) +- [SolidStart + Vite](../guides/solid-start-vite.md) +- [Preact + Vite](../guides/preact-vite.md) +- [Preact + Webpack](../guides/preact-webpack.md) +- [Qwik + Vite](../guides/qwik-vite.md) +- [Lit + Vite](../guides/lit-vite.md) +- [Lit + Webpack](../guides/lit-webpack.md) +- [Alpine.js + Vite](../guides/alpine-vite.md) +- [Alpine.js + Webpack](../guides/alpine-webpack.md) + +## ВрСбования + +- Node.js 18 ΠΈΠ»ΠΈ Π½ΠΎΠ²Π΅Π΅; +- ΠΏΠ°ΠΊΠ΅Ρ‚ распространяСтся ΠΊΠ°ΠΊ ESM ΠΈ ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π°Π΅Ρ‚ΡΡ Ρ‡Π΅Ρ€Π΅Π· `import`; +- React 18 ΠΈΠ»ΠΈ 19 трСбуСтся Ρ‚ΠΎΠ»ΡŒΠΊΠΎ для React/Next generated-ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ΠΎΠ² ΠΈ `@gromlab/svg-sprites/react`; +- для Ρ‚ΠΈΠΏΠΈΠ·Π°Ρ†ΠΈΠΈ package exports ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ TypeScript 5+ с `moduleResolution: "bundler"`, `"node16"` ΠΈΠ»ΠΈ `"nodenext"`. + +Для Π³Π΅Π½Π΅Ρ€Π°Ρ†ΠΈΠΈ Π½Π΅ Π½ΡƒΠΆΠ½Π° dependency ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π°. ЗапускайтС CLI Ρ‡Π΅Ρ€Π΅Π· `npx`: + +```bash +npx --yes @gromlab/svg-sprites path/to/svg-sprite.config.json +``` + +УстанавливайтС ΠΏΠ°ΠΊΠ΅Ρ‚ ΠΊΠ°ΠΊ development dependency, Ρ‚ΠΎΠ»ΡŒΠΊΠΎ Ссли ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Ρƒ Π½ΡƒΠΆΠ½Ρ‹ +Viewer, Ρ‚ΠΈΠΏΡ‹ ΠΊΠΎΠ½Ρ„ΠΈΠ³Π° ΠΈΠ»ΠΈ ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½Ρ‹ΠΉ API: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +## CLI ΠΈ Ρ€Π΅ΠΆΠΈΠΌΡ‹ Π³Π΅Π½Π΅Ρ€Π°Ρ†ΠΈΠΈ + +Для Π³Π΅Π½Π΅Ρ€Π°Ρ†ΠΈΠΈ CLI ΠΏΡ€ΠΈΠ½ΠΈΠΌΠ°Π΅Ρ‚ Ρ€ΠΎΠ²Π½ΠΎ ΠΎΠ΄ΠΈΠ½ ΠΏΡƒΡ‚ΡŒ: явно Π²Ρ‹Π±Ρ€Π°Π½Π½Ρ‹ΠΉ config-Ρ„Π°ΠΉΠ» Π»ΠΈΠ±ΠΎ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ для config-less Π³Π΅Π½Π΅Ρ€Π°Ρ†ΠΈΠΈ: + +```text +svg-sprites [options] +``` + +| Π‘Ρ€Π΅Π΄Π° | Mode | +|---|---| +| Static HTML / собствСнная публикация | `standalone` | +| Standalone + Vite | `standalone@vite` | +| Standalone + Webpack 5 | `standalone@webpack` | +| Server release | `standalone@server` | +| React + Vite | `react@vite` | +| React + Webpack 5 | `react@webpack` | +| Vue + Vite | `vue@vite` | +| Vue + Webpack | `vue@webpack` | +| Nuxt + Vite | `nuxt@vite` | +| Nuxt + Webpack | `nuxt@webpack` | +| Svelte + Vite | `svelte@vite` | +| Svelte + Webpack | `svelte@webpack` | +| SvelteKit + Vite | `sveltekit@vite` | +| Angular application builder | `angular@application` | +| Angular + Webpack | `angular@webpack` | +| Astro + Vite | `astro@vite` | +| Solid + Vite | `solid@vite` | +| Solid + Webpack | `solid@webpack` | +| SolidStart + Vite | `solid-start@vite` | +| Preact + Vite | `preact@vite` | +| Preact + Webpack | `preact@webpack` | +| Qwik + Vite | `qwik@vite` | +| Lit + Vite | `lit@vite` | +| Lit + Webpack | `lit@webpack` | +| Alpine.js + Vite | `alpine@vite` | +| Alpine.js + Webpack | `alpine@webpack` | +| Next.js App Router + Turbopack | `next@app/turbopack` | +| Next.js App Router + Webpack 5 | `next@app/webpack` | +| Next.js Pages Router + Turbopack | `next@pages/turbopack` | +| Next.js Pages Router + Webpack 5 | `next@pages/webpack` | + +Config-Ρ„Π°ΠΉΠ» ΠΌΠΎΠΆΠ΅Ρ‚ ΠΈΠΌΠ΅Ρ‚ΡŒ любоС имя ΠΈ Ρ€Π°ΡΡˆΠΈΡ€Π΅Π½ΠΈΠ΅ `.ts`, `.js` ΠΈΠ»ΠΈ `.json`. CLI Π½Π΅ ΠΈΡ‰Π΅Ρ‚ ΠΊΠΎΠ½Ρ„ΠΈΠ³ ΠΏΠΎ соглашСнию: Ρ„Π°ΠΉΠ» Π½ΡƒΠΆΠ½ΠΎ ΠΏΠ΅Ρ€Π΅Π΄Π°Ρ‚ΡŒ явно. Π’ руководствах ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ Ρ€Π΅ΠΊΠΎΠΌΠ΅Π½Π΄ΡƒΠ΅ΠΌΠΎΠ΅ имя `svg-sprite.config.json`. + +Если ΠΏΠ΅Ρ€Π΅Π΄Π°Π½ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³, всС настройки бСрутся ΠΈΠ· CLI. Если ΠΏΠ΅Ρ€Π΅Π΄Π°Π½ config-Ρ„Π°ΠΉΠ», CLI-ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€Ρ‹ ΠΏΠ΅Ρ€Π΅ΠΊΡ€Ρ‹Π²Π°ΡŽΡ‚ значСния Ρ„Π°ΠΉΠ»Π°. ΠžΠ±Ρ‰ΠΈΠΉ порядок: `defaults β†’ config β†’ CLI`. + +`--help` ΠΈ `-h` выводят справку Π±Π΅Π· ΠΎΠ±ΡΠ·Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎΠ³ΠΎ ΠΏΡƒΡ‚ΠΈ. Для Π³Π΅Π½Π΅Ρ€Π°Ρ†ΠΈΠΈ доступны `--mode`, `--source `, `--name`, `--description`, повторяСмый `--input `, Π° Ρ‚Π°ΠΊΠΆΠ΅ ΠΏΠ°Ρ€Ρ‹ `--remove-size`/`--no-remove-size`, `--replace-colors`/`--no-replace-colors`, `--add-transition`/`--no-add-transition` ΠΈ `--generated-notice`/`--no-generated-notice`. ΠŸΠ΅Ρ€Π΅Π΄Π°Π½Π½Ρ‹Π΅ transform-Ρ„Π»Π°Π³ΠΈ ΠΏΠ΅Ρ€Π΅ΠΊΡ€Ρ‹Π²Π°ΡŽΡ‚ ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½Ρ‹Π΅ поля, Π° хотя Π±Ρ‹ ΠΎΠ΄ΠΈΠ½ `--input` ΠΏΠΎΠ»Π½ΠΎΡΡ‚ΡŒΡŽ замСняСт Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ `input` ΠΈΠ· config. + +Π’ CLI Π·Π°ΠΊΠ»ΡŽΡ‡Π°ΠΉΡ‚Π΅ glob-ΠΏΠ°Ρ‚Ρ‚Π΅Ρ€Π½Ρ‹ Π² ΠΎΠ΄ΠΈΠ½Π°Ρ€Π½Ρ‹Π΅ ΠΊΠ°Π²Ρ‹Ρ‡ΠΊΠΈ, Ρ‡Ρ‚ΠΎΠ±Ρ‹ shell Π½Π΅ раскрыл ΠΈΡ… Π΄ΠΎ запуска Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€Π°: + +```bash +svg-sprites --input './icons/**/*.svg' --input '!./icons/legacy/**' svg-sprite.config.ts +``` + +Mode Π΄ΠΎΠ»ΠΆΠ΅Π½ ΡΠΎΠΎΡ‚Π²Π΅Ρ‚ΡΡ‚Π²ΠΎΠ²Π°Ρ‚ΡŒ способу ΠΏΡƒΠ±Π»ΠΈΠΊΠ°Ρ†ΠΈΠΈ прилоТСния. Bare `standalone` оставляСт ΠΏΡƒΠ±Π»ΠΈΡ‡Π½Ρ‹ΠΉ URL ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΡŽ; Vite ΠΈ Webpack modes Π³Π΅Π½Π΅Ρ€ΠΈΡ€ΡƒΡŽΡ‚ bundler-specific ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅ SVG asset. + +## Единая конфигурация + +ΠšΠ°ΠΆΠ΄Ρ‹ΠΉ config-Ρ„Π°ΠΉΠ» описываСт ΠΎΠ΄ΠΈΠ½ нСзависимый спрайт. + +```ts +import { defineSpriteConfig } from '@gromlab/svg-sprites' + +export default defineSpriteConfig({ + mode: 'next@app/turbopack', + name: 'app', + description: 'ΠžΠ±Ρ‰ΠΈΠ΅ ΠΈΠΊΠΎΠ½ΠΊΠΈ прилоТСния', + input: [ + './local-icons', + '../../assets/icons/*.svg', + '!../../assets/icons/deprecated-*.svg', + ], + transform: { + removeSize: true, + replaceColors: true, + addTransition: true, + }, + generatedNotice: true, +}) +``` + +| ΠžΠΏΡ†ΠΈΡ | Π’ΠΈΠΏ | По ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ | НазначСниС | +|---|---|---|---| +| `mode` | `SpriteMode` | НСт | Π Π΅ΠΆΠΈΠΌ Π³Π΅Π½Π΅Ρ€Π°Ρ†ΠΈΠΈ; ΠΌΠΎΠΆΠ½ΠΎ ΠΏΠ΅Ρ€Π΅Π΄Π°Ρ‚ΡŒ Ρ‡Π΅Ρ€Π΅Π· CLI/API | +| `source` | `local \| remote` | `local` | Π˜ΡΡ…ΠΎΠ΄Π½Ρ‹Π΅ SVG Π»ΠΈΠ±ΠΎ Π³ΠΎΡ‚ΠΎΠ²Ρ‹ΠΉ server manifest | +| `name` | `string` | Выводится ΠΈΠ· ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³Π° | Имя спрайта; Π² modes с ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ΠΎΠΌ Ρ‚Π°ΠΊΠΆΠ΅ Π·Π°Π΄Π°Ρ‘Ρ‚ имя ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚Π° ΠΈ ΠΏΡƒΠ±Π»ΠΈΡ‡Π½Ρ‹Ρ… Ρ‚ΠΈΠΏΠΎΠ² | +| `description` | `string` | НСт | ОписаниС для Ρ‚ΠΈΠΏΠΎΠ² ΠΈ debug manifest | +| `input` | `SpriteInput \| SpriteInput[]` | `./icons` | Π›ΠΎΠΊΠ°Π»ΡŒΠ½Ρ‹Π΅ SVG sources, server HTTP descriptors Π»ΠΈΠ±ΠΎ ΠΎΠ΄ΠΈΠ½ remote manifest Π² зависимости ΠΎΡ‚ mode ΠΈ source | +| `transform` | `TransformOptions` | ВсС Π²ΠΊΠ»ΡŽΡ‡Π΅Π½Ρ‹ | Настройки ΠΏΠΎΠ΄Π³ΠΎΡ‚ΠΎΠ²ΠΊΠΈ SVG | +| `generatedNotice` | `boolean` | `true` | ПолноС ΠΈΠ»ΠΈ ΠΊΠΎΡ€ΠΎΡ‚ΠΊΠΎΠ΅ ΠΏΡ€Π΅Π΄ΡƒΠΏΡ€Π΅ΠΆΠ΄Π΅Π½ΠΈΠ΅ Π² generated-Ρ„Π°ΠΉΠ»Π°Ρ… | + +ΠŸΡ€ΠΈ `source: 'remote'` ΠΏΠΎΠ»Π΅ `input` содСрТит ΠΎΠ΄ΠΈΠ½ local path ΠΈΠ»ΠΈ HTTP(S) URL +manifest, созданного `standalone@server`. Remote consumer config ΠΌΠΎΠΆΠ΅Ρ‚ ΡΠΎΠ΄Π΅Ρ€ΠΆΠ°Ρ‚ΡŒ +Ρ‚ΠΎΠ»ΡŒΠΊΠΎ `mode`, `source` ΠΈ `input`: name, description, transforms ΠΈ generated notice +ΠΏΡ€ΠΎΠ²Π΅Ρ€ΡΡŽΡ‚ΡΡ ΠΈ Π½Π°ΡΠ»Π΅Π΄ΡƒΡŽΡ‚ΡΡ ΠΈΠ· server manifest. Π”ΠΎ codegen Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ скачиваСт profile, +Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΡ‹ΠΉ exact consumer mode, ΠΈ провСряСт Π΅Π³ΠΎ SHA-256 ΠΈ Ρ€Π°Π·ΠΌΠ΅Ρ€. Runtime-зависимости +ΠΎΡ‚ server manifest Π½Π΅Ρ‚. + +### Имя спрайта + +`name` записываСтся Π² kebab-case ΠΈ Π΄ΠΎΠ»ΠΆΠ½ΠΎ Π½Π°Ρ‡ΠΈΠ½Π°Ρ‚ΡŒΡΡ с латинской Π±ΡƒΠΊΠ²Ρ‹: + +```text +app β†’ AppIcon +file-manager β†’ FileManagerIcon +``` + +Если `name` Π½Π΅ Π·Π°Π΄Π°Π½ΠΎ, Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ ΠΏΡ€Π΅ΠΎΠ±Ρ€Π°Π·ΡƒΠ΅Ρ‚ имя ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³Π° Π² kebab-case. Для ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³Π° с ΠΈΠΌΠ΅Π½Π΅ΠΌ `svg-sprite` ΠΈΠ»ΠΈ `svg-sprites` ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ имя Ρ€ΠΎΠ΄ΠΈΡ‚Π΅Π»ΡŒΡΠΊΠΎΠ³ΠΎ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³Π°. + +### Π˜ΡΡ‚ΠΎΡ‡Π½ΠΈΠΊΠΈ ΠΈΠΊΠΎΠ½ΠΎΠΊ + +`SpriteConfig.input` являСтся Π½Π΅ΠΎΠ±ΡΠ·Π°Ρ‚Π΅Π»ΡŒΠ½Ρ‹ΠΌ ΠΈ ΠΈΠΌΠ΅Π΅Ρ‚ Ρ‚ΠΈΠΏ `string | string[]`. Если ΠΏΠΎΠ»Π΅ отсутствуСт, источником слуТит ΠΏΠ°ΠΏΠΊΠ° `./icons` ΠΎΡ‚Π½ΠΎΡΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ ΠΏΠ°ΠΏΠΊΠΈ ΠΊΠΎΠ½Ρ„ΠΈΠ³Π°. Π’ config-less Ρ€Π΅ΠΆΠΈΠΌΠ΅ ΠΎΡ‚Π½ΠΎΡΠΈΡ‚Π΅Π»ΡŒΠ½Ρ‹Π΅ ΠΏΡƒΡ‚ΠΈ ΡΡ‡ΠΈΡ‚Π°ΡŽΡ‚ΡΡ ΠΎΡ‚ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³Π°, ΠΏΠ΅Ρ€Π΅Π΄Π°Π½Π½ΠΎΠ³ΠΎ CLI ΠΈΠ»ΠΈ API. + +КаТдая строка Π±Π΅Π· прСфикса `!` ΠΌΠΎΠΆΠ΅Ρ‚ Π±Ρ‹Ρ‚ΡŒ ΠΏΡƒΡ‚Ρ‘ΠΌ ΠΊ ΠΊΠΎΠ½ΠΊΡ€Π΅Ρ‚Π½ΠΎΠΉ ΠΏΠ°ΠΏΠΊΠ΅, ΠΊΠΎΠ½ΠΊΡ€Π΅Ρ‚Π½ΠΎΠΌΡƒ Ρ„Π°ΠΉΠ»Ρƒ `.svg` ΠΈΠ»ΠΈ glob-ΠΏΠ°Ρ‚Ρ‚Π΅Ρ€Π½ΠΎΠΌ. Папка Π²ΠΊΠ»ΡŽΡ‡Π°Π΅Ρ‚ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ нСпосрСдствСнныС Π΄ΠΎΡ‡Π΅Ρ€Π½ΠΈΠ΅ `*.svg`. Для рСкурсивного ΠΎΠ±Ρ…ΠΎΠ΄Π° Π²Π»ΠΎΠΆΠ΅Π½Π½Ρ‹Ρ… ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ΠΎΠ² ΡƒΠΊΠ°ΠΆΠΈΡ‚Π΅ явный ΠΏΠ°Ρ‚Ρ‚Π΅Ρ€Π½, Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€ `icons/**/*.svg`. + +Массив ΠΎΠ±ΡŠΠ΅Π΄ΠΈΠ½ΡΠ΅Ρ‚ всС Π²ΠΊΠ»ΡŽΡ‡Π°ΡŽΡ‰ΠΈΠ΅ источники. ΠŸΠ°Ρ‚Ρ‚Π΅Ρ€Π½ с прСфиксом `!` глобально ΠΈΡΠΊΠ»ΡŽΡ‡Π°Π΅Ρ‚ совпадСния ΠΈΠ· ΠΎΠ±Ρ‰Π΅Π³ΠΎ Ρ€Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚Π° нСзависимо ΠΎΡ‚ Ρ‚ΠΎΠ³ΠΎ, ΠΊΠ°ΠΊΠΎΠΉ источник ΠΈΡ… Π΄ΠΎΠ±Π°Π²ΠΈΠ». + +ΠŸΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΈΠ²Π°Π΅Ρ‚ΡΡ ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΠΈΠΉ glob-синтаксис: + +| Бинтаксис | Π—Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ | +|---|---| +| `*` | Π›ΡŽΠ±Ρ‹Π΅ символы Π²Π½ΡƒΡ‚Ρ€ΠΈ ΠΎΠ΄Π½ΠΎΠ³ΠΎ сСгмСнта ΠΏΡƒΡ‚ΠΈ | +| `**` | Π›ΡŽΠ±ΠΎΠ΅ число Π²Π»ΠΎΠΆΠ΅Π½Π½Ρ‹Ρ… ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ΠΎΠ² | +| `?` | Один символ Π²Π½ΡƒΡ‚Ρ€ΠΈ сСгмСнта ΠΏΡƒΡ‚ΠΈ | +| `{a,b}` | Одна ΠΈΠ· Π°Π»ΡŒΡ‚Π΅Ρ€Π½Π°Ρ‚ΠΈΠ² | +| `[abc]` | Один символ ΠΈΠ· Π½Π°Π±ΠΎΡ€Π° ΠΈΠ»ΠΈ Π΄ΠΈΠ°ΠΏΠ°Π·ΠΎΠ½Π° | +| `!pattern` | Π˜ΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅ совпадСний ΠΈΠ· всСго ΠΎΠ±ΡŠΠ΅Π΄ΠΈΠ½Ρ‘Π½Π½ΠΎΠ³ΠΎ input | + +ΠšΠ°ΠΆΠ΄Ρ‹ΠΉ Π²ΠΊΠ»ΡŽΡ‡Π°ΡŽΡ‰ΠΈΠΉ источник ΠΈΠ»ΠΈ ΠΏΠ°Ρ‚Ρ‚Π΅Ρ€Π½ Π΄ΠΎΠ»ΠΆΠ΅Π½ Π½Π°ΠΉΡ‚ΠΈ хотя Π±Ρ‹ ΠΎΠ΄ΠΈΠ½ SVG, ΠΈΠ½Π°Ρ‡Π΅ гСнСрация Π·Π°Π²Π΅Ρ€ΡˆΠ°Π΅Ρ‚ΡΡ ошибкой. ΠŸΠΎΠ²Ρ‚ΠΎΡ€ΡΡŽΡ‰ΠΈΠ΅ΡΡ ΠΏΡƒΡ‚ΠΈ ΡƒΠ΄Π°Π»ΡΡŽΡ‚ΡΡ, Π° ΠΈΡ‚ΠΎΠ³ΠΎΠ²Ρ‹ΠΉ список Ρ„Π°ΠΉΠ»ΠΎΠ² Π΄Π΅Ρ‚Π΅Ρ€ΠΌΠΈΠ½ΠΈΡ€ΠΎΠ²Π°Π½Π½ΠΎ сортируСтся. Π Π°Π·Π½Ρ‹Π΅ SVG с ΠΎΠ΄ΠΈΠ½Π°ΠΊΠΎΠ²Ρ‹ΠΌ basename ΠΏΠΎ-ΠΏΡ€Π΅ΠΆΠ½Π΅ΠΌΡƒ ΡΡ‡ΠΈΡ‚Π°ΡŽΡ‚ΡΡ ΠΊΠΎΠ½Ρ„Π»ΠΈΠΊΡ‚ΠΎΠΌ, ΠΏΠΎΡ‚ΠΎΠΌΡƒ Ρ‡Ρ‚ΠΎ basename Π·Π°Π΄Π°Ρ‘Ρ‚ ΠΏΡƒΠ±Π»ΠΈΡ‡Π½ΠΎΠ΅ имя ΠΈΠΊΠΎΠ½ΠΊΠΈ. + +### Server SVG inputs + +`standalone@server` ΠΏΡ€ΠΈΠ½ΠΈΠΌΠ°Π΅Ρ‚ Ρ‚Π΅ ΠΆΠ΅ local strings ΠΈ HTTP(S) descriptors Π² массивС +`input`: + +```ts +{ + name: 'brand-logo', + url: 'https://assets.example.com/brand-logo.svg', + sha256: '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef', +} +``` + +`name` становится ΠΏΡƒΠ±Π»ΠΈΡ‡Π½Ρ‹ΠΌ ΠΈΠΌΠ΅Π½Π΅ΠΌ ΠΈΠΊΠΎΠ½ΠΊΠΈ. ΠΠ΅ΠΎΠ±ΡΠ·Π°Ρ‚Π΅Π»ΡŒΠ½Ρ‹ΠΉ `sha256` провСряСтся ΠΏΠΎ +скачанным Π±Π°ΠΉΡ‚Π°ΠΌ. URL credentials ΠΈ Π°ΠΊΡ‚ΠΈΠ²Π½ΠΎΠ΅ SVG-содСрТимоС, Π²ΠΊΠ»ΡŽΡ‡Π°Ρ scripts, +event handlers, `foreignObject` ΠΈ doctype, Π·Π°ΠΏΡ€Π΅Ρ‰Π΅Π½Ρ‹. Один HTTP source ΠΎΠ³Ρ€Π°Π½ΠΈΡ‡Π΅Π½ +2 MiB, всС источники вмСстС β€” 25 MiB, timeout запроса Ρ€Π°Π²Π΅Π½ 15 сСкундам. Local ΠΈ +HTTP entries ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΡŽΡ‚ Π΅Π΄ΠΈΠ½ΠΎΠ΅ пространство ΠΈΠΌΡ‘Π½, поэтому duplicate icon names +Π·Π°Π²Π΅Ρ€ΡˆΠ°ΡŽΡ‚ Π³Π΅Π½Π΅Ρ€Π°Ρ†ΠΈΡŽ с ошибкой. + +## Generated-ΠΌΠΎΠ΄ΡƒΠ»ΡŒ + +ПослС Π³Π΅Π½Π΅Ρ€Π°Ρ†ΠΈΠΈ React- ΠΈΠ»ΠΈ Next.js-ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ спрайта выглядит Ρ‚Π°ΠΊ: + +```text +app-icons/ +β”œβ”€β”€ .gitignore +β”œβ”€β”€ svg-sprite.config.json +β”œβ”€β”€ index.ts # Π½Π΅ΠΎΠ±ΡΠ·Π°Ρ‚Π΅Π»ΡŒΠ½Ρ‹ΠΉ ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒΡΠΊΠΈΠΉ barrel +└── .svg-sprite/ + β”œβ”€β”€ index.js + β”œβ”€β”€ index.d.ts + β”œβ”€β”€ icon-data.js + β”œβ”€β”€ icon-data.d.ts + β”œβ”€β”€ sprite.svg + β”œβ”€β”€ svg-sprite.manifest.js + β”œβ”€β”€ svg-sprite.manifest.d.ts + └── react/ + β”œβ”€β”€ react-component.js + β”œβ”€β”€ react-component.d.ts + └── react-component.module.css +``` + +| Π€Π°ΠΉΠ» | НазначСниС | +|---|---| +| `.svg-sprite/index.js` | Mode-specific production facade ΠΈ runtime-список ΠΈΠΌΡ‘Π½ | +| `.svg-sprite/index.d.ts` | ΠŸΡƒΠ±Π»ΠΈΡ‡Π½Ρ‹Π΅ Π΄Π΅ΠΊΠ»Π°Ρ€Π°Ρ†ΠΈΠΈ facade, ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚Π° ΠΈ union-Ρ‚ΠΈΠΏΠ° ΠΈΠΌΡ‘Π½ | +| `.svg-sprite/svg-sprite.manifest.js` | Debug metadata ΠΈ URL asset для `SpriteViewer` | +| `.svg-sprite/sprite.svg` | Π‘ΠΎΠ±Ρ€Π°Π½Π½Ρ‹ΠΉ SVG-спрайт | +| `.svg-sprite/react/react-component.js` | Runtime React-ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚Π° Π±Π΅Π· TypeScript ΠΈ JSX | +| `.svg-sprite/react/react-component.d.ts` | Props, style ΠΈ declaration React-ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚Π° | +| `.svg-sprite/react/react-component.module.css` | Π‘Ρ‚ΠΈΠ»ΠΈ ΠΊΠΎΠ½ΠΊΡ€Π΅Ρ‚Π½ΠΎΠΉ React-Ρ€Π΅Π°Π»ΠΈΠ·Π°Ρ†ΠΈΠΈ | +| `.svg-sprite/icon-data.js` | Runtime-список ΠΈΠΌΡ‘Π½ ΠΈ Π²Π½ΡƒΡ‚Ρ€Π΅Π½Π½ΠΈΠ΅ IDs | +| `.svg-sprite/*.d.ts` | TypeScript-Π΄Π΅ΠΊΠ»Π°Ρ€Π°Ρ†ΠΈΠΈ ΡΠΎΠΎΡ‚Π²Π΅Ρ‚ΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΡ… JS-ΠΌΠΎΠ΄ΡƒΠ»Π΅ΠΉ | + +Standalone-ΠΊΠΎΠ½Ρ‚Ρ€Π°ΠΊΡ‚Ρ‹ Π½Π΅ ΡΠΎΠ·Π΄Π°ΡŽΡ‚ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ `react/`. Bare `standalone` содСрТит Ρ‚ΠΎΠ»ΡŒΠΊΠΎ +runtime asset ΠΈ deployment-neutral manifest data: + +```text +.svg-sprite/ +β”œβ”€β”€ sprite.svg +└── svg-sprite.manifest.json +``` + +`standalone@vite` ΠΈ `standalone@webpack` Π΄ΠΎΠΏΠΎΠ»Π½ΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ ΡΠΎΠ·Π΄Π°ΡŽΡ‚ `index.*`, +`icon-data.*` ΠΈ resolved `svg-sprite.manifest.*`. Π˜Ρ… facade содСрТит Π½Π°Ρ‚ΠΈΠ²Π½Ρ‹ΠΉ +generated Web Component Π±Π΅Π· Π²Π½Π΅ΡˆΠ½ΠΈΡ… runtime-зависимостСй. Bare `standalone` +Π½Π°ΠΌΠ΅Ρ€Π΅Π½Π½ΠΎ Π½Π΅ создаёт JavaScript-ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚. + +`standalone@server` создаёт Π³ΠΎΡ‚ΠΎΠ²Ρ‹ΠΉ ΠΊ ΠΏΡƒΠ±Π»ΠΈΠΊΠ°Ρ†ΠΈΠΈ release Π±Π΅Π· JavaScript runtime ΠΈ +`.gitignore`: + +```text +.svg-sprite/ +β”œβ”€β”€ sprite..svg +β”œβ”€β”€ sprite-root-viewbox..svg +└── svg-sprite.manifest.json +``` + +Manifest описываСт ΠΎΠ±Π° compile profiles Ρ‡Π΅Ρ€Π΅Π· relative `href`, ΠΏΠΎΠ»Π½Ρ‹ΠΉ SHA-256 ΠΈ +Ρ€Π°Π·ΠΌΠ΅Ρ€ Π² Π±Π°ΠΉΡ‚Π°Ρ…. ΠŸΡƒΠ±Π»ΠΈΠΊΡƒΠΉΡ‚Π΅ вСсь ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ Π°Ρ‚ΠΎΠΌΠ°Ρ€Π½ΠΎ; consumer Ρ€Π°Π·Ρ€Π΅ΡˆΠ°Π΅Ρ‚ ΠΊΠ°ΠΆΠ΄Ρ‹ΠΉ profile +ΠΎΡ‚Π½ΠΎΡΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ URL ΠΈΠ»ΠΈ local path manifest. + +`.svg-sprite` ΠΏΠΎΠ»Π½ΠΎΡΡ‚ΡŒΡŽ управляСтся Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ΠΎΠΌ ΠΈ ΠΏΡ€ΠΈ ΠΊΠ°ΠΆΠ΄ΠΎΠΉ Π³Π΅Π½Π΅Ρ€Π°Ρ†ΠΈΠΈ замСняСтся Ρ†Π΅Π»ΠΈΠΊΠΎΠΌ. Π›ΡŽΠ±Ρ‹Π΅ Π΄ΠΎΠ±Π°Π²Π»Π΅Π½Π½Ρ‹Π΅ Π² Π½Π΅Π³ΠΎ Ρ„Π°ΠΉΠ»Ρ‹ Π±ΡƒΠ΄ΡƒΡ‚ ΡƒΠ΄Π°Π»Π΅Π½Ρ‹. ΠŸΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒΡΠΊΠΈΠ΅ Ρ„Π°ΠΉΠ»Ρ‹ Ρ€Π°Π·ΠΌΠ΅Ρ‰Π°ΠΉΡ‚Π΅ рядом, Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€ Π² ΠΊΠΎΡ€Π½Π΅Π²ΠΎΠΌ `index.ts`: + +```ts +export * from './.svg-sprite/index.js' +``` + +## Standalone Web Component ΠΈ TypeScript + +Π’ modes `standalone@vite` ΠΈ `standalone@webpack` спрайт с `name: 'app'` +экспортируСт Ρ„ΡƒΠ½ΠΊΡ†ΠΈΡŽ рСгистрации `defineAppIconElement()` ΠΈ tag ``: + +```ts +import { defineAppIconElement } from '@/ui/app-icons' + +defineAppIconElement() +``` + +ПослС рСгистрации элСмСнт ΠΌΠΎΠΆΠ½ΠΎ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ Π² HTML: + +```html + + + +``` + +ΠšΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ Ρ€Π΅Π½Π΄Π΅Ρ€ΠΈΡ‚ `` Π² ΠΎΡ‚ΠΊΡ€Ρ‹Ρ‚ΠΎΠΌ Shadow DOM, сам Π²Ρ‹Π±ΠΈΡ€Π°Π΅Ρ‚ Π²Π½ΡƒΡ‚Ρ€Π΅Π½Π½ΠΈΠΉ +ID ΠΈ `viewBox`, Π° URL asset ΠΏΠΎΠ»ΡƒΡ‡Π°Π΅Ρ‚ Ρ‡Π΅Ρ€Π΅Π· ΡΠΎΠΎΡ‚Π²Π΅Ρ‚ΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΠΉ Vite ΠΈΠ»ΠΈ Webpack +ΠΌΠ΅Ρ…Π°Π½ΠΈΠ·ΠΌ. Π Π°Π·ΠΌΠ΅Ρ€ host ΠΏΠΎ ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ Ρ€Π°Π²Π΅Π½ `1em Γ— 1em`; `class`, `style`, `color` +ΠΈ `--icon-color-N` Π·Π°Π΄Π°ΡŽΡ‚ΡΡ ΠΎΠ±Ρ‹Ρ‡Π½Ρ‹ΠΌ CSS. + +Generated `HTMLElementTagNameMap` Ρ‚ΠΈΠΏΠΈΠ·ΠΈΡ€ΡƒΠ΅Ρ‚ property API: + +```ts +const icon = document.createElement('app-icon') + +icon.icon = 'search' +icon.icon = 'unknown' // ошибка TypeScript +``` + +ЗначСния Π°Ρ‚Ρ€ΠΈΠ±ΡƒΡ‚ΠΎΠ² Π² ΠΎΠ±Ρ‹Ρ‡Π½ΠΎΠΉ HTML-Ρ€Π°Π·ΠΌΠ΅Ρ‚ΠΊΠ΅ TypeScript Π½Π΅ провСряСт. ΠŸΠΎΡΡ‚ΠΎΠΌΡƒ +нСизвСстный `icon="unknown"` Π΄ΠΎΠΏΠΎΠ»Π½ΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ провСряСтся Π² runtime: ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ +скрываСт Π²Π½ΡƒΡ‚Ρ€Π΅Π½Π½ΠΈΠΉ SVG ΠΈ сообщаСт ΠΎΠ± ошибкС, Π½Π΅ создавая fragment +`#undefined`. ΠŸΠΎΠ²Ρ‚ΠΎΡ€Π½Ρ‹ΠΉ Π²Ρ‹Π·ΠΎΠ² `defineAppIconElement()` бСзопасСн для Ρ‚ΠΎΠ³ΠΎ ΠΆΠ΅ +спрайта; ΠΊΠΎΠ½Ρ„Π»ΠΈΠΊΡ‚ с Π΄Ρ€ΡƒΠ³ΠΈΠΌ элСмСнтом ΠΏΠΎΠ΄ tag `` Π·Π°Π²Π΅Ρ€ΡˆΠ°Π΅Ρ‚ΡΡ ошибкой. + +## React-ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ ΠΈ TypeScript + +Π‘ΠΏΡ€Π°ΠΉΡ‚ с `name: 'app'` экспортируСт: + +```ts +export { AppIcon, appIconNames } +export type { AppIconName, AppIconProps, AppIconStyle } +``` + +### ИмСна ΠΈΠΊΠΎΠ½ΠΎΠΊ + +ИмСна SVG-Ρ„Π°ΠΉΠ»ΠΎΠ² становятся допустимыми значСниями `icon`: + +```tsx + + // ошибка TypeScript +``` + +Runtime-список содСрТит Ρ‚Π΅ ΠΆΠ΅ значСния: + +```ts +import { appIconNames } from '@/ui/app-icons' + +// readonly ['search', 'settings', 'user'] +``` + +ИмСна с ΠΏΡ€ΠΎΠ±Π΅Π»Π°ΠΌΠΈ ΠΈ Π΄Ρ€ΡƒΠ³ΠΈΠΌΠΈ нСбСзопасными для SVG ID символами ΠΎΡΡ‚Π°ΡŽΡ‚ΡΡ Ρ‡Π°ΡΡ‚ΡŒΡŽ ΠΏΡƒΠ±Π»ΠΈΡ‡Π½ΠΎΠ³ΠΎ API. Для Π²Π½ΡƒΡ‚Ρ€Π΅Π½Π½Π΅Π³ΠΎ fragment ID Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ создаёт ΡΡ‚Π°Π±ΠΈΠ»ΡŒΠ½Ρ‹ΠΉ бСзопасный hash: + +```text +folder open.svg β†’ icon="folder open" β†’ id="icon-" +``` + +Для Ρ‚Π°ΠΊΠΈΡ… ΠΈΠΌΡ‘Π½ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ generated-ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ ΠΈΠ»ΠΈ `id` ΠΈΠ· debug manifest, Π° Π½Π΅ Ρ„ΠΎΡ€ΠΌΠΈΡ€ΡƒΠΉΡ‚Π΅ fragment ID Π²Ρ€ΡƒΡ‡Π½ΡƒΡŽ. + +### SVG-Π°Ρ‚Ρ€ΠΈΠ±ΡƒΡ‚Ρ‹ + +По ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ Ρ€Π΅Π½Π΄Π΅Ρ€ΠΈΡ‚ `` ΠΈ ΠΏΡ€ΠΈΠ½ΠΈΠΌΠ°Π΅Ρ‚ стандартныС SVG-Π°Ρ‚Ρ€ΠΈΠ±ΡƒΡ‚Ρ‹: + +```tsx + +``` + +ΠšΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ Π½Π΅ добавляСт accessibility-сСмантику автоматичСски. ΠŸΠ΅Ρ€Π΅Π΄Π°Π²Π°ΠΉΡ‚Π΅ подходящиС `aria-*`, `role` ΠΈΠ»ΠΈ подпись Π² зависимости ΠΎΡ‚ назначСния ΠΈΠΊΠΎΠ½ΠΊΠΈ. + +### ΠžΠ±Ρ‘Ρ€Ρ‚ΠΊΠ° + +`wrapped` Ρ€Π΅Π½Π΄Π΅Ρ€ΠΈΡ‚ `` с Π²Π½ΡƒΡ‚Ρ€Π΅Π½Π½ΠΈΠΌ SVG. ΠžΡΡ‚Π°Π»ΡŒΠ½Ρ‹Π΅ props Π² этом Ρ€Π΅ΠΆΠΈΠΌΠ΅ относятся ΠΊ ``: + +```tsx + +``` + +### Π’ΠΈΠΏΠΈΠ·ΠΈΡ€ΠΎΠ²Π°Π½Π½Ρ‹Π΅ CSS-ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅ + +`AppIconStyle` Ρ€Π°ΡΡˆΠΈΡ€ΡΠ΅Ρ‚ `CSSProperties` ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΈΠ²Π°Π΅Ρ‚ свойства Π²ΠΈΠ΄Π° `--icon-color-N`: + +```tsx + +``` + +## ΠœΠ½ΠΎΠΆΠ΅ΡΡ‚Π²Π΅Π½Π½Ρ‹Π΅ спрайты + +ΠšΠ°ΠΆΠ΄Ρ‹ΠΉ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ с ΠΊΠΎΠ½Ρ„ΠΈΠ³ΠΎΠΌ создаёт нСзависимый mode-specific ΠΊΠΎΠ½Ρ‚Ρ€Π°ΠΊΡ‚. Framework modes ΡΠΎΠ·Π΄Π°ΡŽΡ‚ Π½Π°Ρ‚ΠΈΠ²Π½Ρ‹ΠΉ ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ ΠΈ declarations, standalone bundler modes β€” Web Component ΠΈ declarations, Π° bare `standalone` β€” SVG ΠΈ JSON manifest: + +```text +app-icons β†’ AppIcon β†’ ΠΎΠ±Ρ‰ΠΈΠ΅ ΠΈΠΊΠΎΠ½ΠΊΠΈ +analytics-icons β†’ AnalyticsIcon β†’ ΠΈΠΊΠΎΠ½ΠΊΠΈ страницы Π°Π½Π°Π»ΠΈΡ‚ΠΈΠΊΠΈ +editor-icons β†’ EditorIcon β†’ ΠΈΠΊΠΎΠ½ΠΊΠΈ Ρ€Π΅Π΄Π°ΠΊΡ‚ΠΎΡ€Π° +``` + +Один исходный SVG ΠΌΠΎΠΆΠ½ΠΎ Π΄ΠΎΠ±Π°Π²ΠΈΡ‚ΡŒ Ρ‡Π΅Ρ€Π΅Π· `input` Π² нСсколько ΠΊΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ†ΠΈΠΉ. ΠšΠΎΠΏΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ Ρ„Π°ΠΉΠ» Π² ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ΠΈ ΠΊΠ°ΠΆΠ΄ΠΎΠ³ΠΎ спрайта Π½Π΅ трСбуСтся. + +Для Π½Π΅ΡΠΊΠΎΠ»ΡŒΠΊΠΈΡ… спрайтов Π΄ΠΎΠ±Π°Π²ΡŒΡ‚Π΅ ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½ΡƒΡŽ CLI-ΠΊΠΎΠΌΠ°Π½Π΄Ρƒ для ΠΊΠ°ΠΆΠ΄ΠΎΠ³ΠΎ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³Π° ΠΈΠ»ΠΈ ΠΎΠ±ΡŠΠ΅Π΄ΠΈΠ½ΠΈΡ‚Π΅ ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ Π² ΠΎΠ±Ρ‰Π΅ΠΌ npm script. + +## Π€ΠΎΡ€ΠΌΠ°Ρ‚Ρ‹ ΠΈ способы отобраТСния + +ВсС Ρ‚Π΅ΠΊΡƒΡ‰ΠΈΠ΅ modes ΡΠΎΠ·Π΄Π°ΡŽΡ‚ Ρ„ΠΎΡ€ΠΌΠ°Ρ‚ `stack`. + +| Π€ΠΎΡ€ΠΌΠ°Ρ‚ | `` | `` | CSS background | +|---|---:|---:|---:| +| `stack` | Π”Π° | Π”Π° | Π”Π° | + +### Generated-ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ + +Π˜ΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ generated native-ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ ΠΈΠ· guide Π²Ρ‹Π±Ρ€Π°Π½Π½ΠΎΠ³ΠΎ exact mode. Он Π·Π½Π°Π΅Ρ‚ Π²Π½ΡƒΡ‚Ρ€Π΅Π½Π½ΠΈΠ΅ ID, Ρ„ΠΎΡ€ΠΌΠΈΡ€ΡƒΠ΅Ρ‚ URL ΠΈ прСдоставляСт TypeScript API. Для React ΠΈ Next.js это выглядит Ρ‚Π°ΠΊ: + +```tsx + +``` + +Для `standalone@vite` ΠΈ `standalone@webpack` ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ generated Web Component: + +```html + +``` + +### Π’Ρ€ΡƒΡ‡Π½ΡƒΡŽ Ρ‡Π΅Ρ€Π΅Π· `` + +Бпособ получСния `spriteUrl` зависит ΠΎΡ‚ сборщика. + +Static HTML послС ΠΏΡƒΠ±Π»ΠΈΠΊΠ°Ρ†ΠΈΠΈ `.svg-sprite/sprite.svg` ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠ΅ΠΌ: + +```html + +``` + +Standalone Vite/Webpack прСдоставляСт generated `getAppIconHref()` ΠΈ mapping +Π²Π½ΡƒΡ‚Ρ€Π΅Π½Π½ΠΈΡ… IDs. НС конструируйтС fragment ΠΈΠ· нСбСзопасного ΠΈΠΌΠ΅Π½ΠΈ Ρ„Π°ΠΉΠ»Π° Π²Ρ€ΡƒΡ‡Π½ΡƒΡŽ. + +Vite: + +```ts +import spriteUrl from './.svg-sprite/sprite.svg?no-inline' +``` + +Webpack 5, Turbopack ΠΈ Next.js: + +```ts +const spriteUrl = new URL('./.svg-sprite/sprite.svg', import.meta.url).href +``` + +ПослС получСния URL ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ Π΅Π³ΠΎ Π² JSX: + +```tsx + + + +``` + +Для ΠΈΠΌΡ‘Π½, нСбСзопасных ΠΊΠ°ΠΊ SVG ID, ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ Π²Π½ΡƒΡ‚Ρ€Π΅Π½Π½ΠΈΠΉ `id` ΠΈΠ· manifest. + +### Π§Π΅Ρ€Π΅Π· `` + +```tsx +Поиск +``` + +SVG Π²Π½ΡƒΡ‚Ρ€ΠΈ `` ΠΈΠ·ΠΎΠ»ΠΈΡ€ΠΎΠ²Π°Π½ ΠΎΡ‚ CSS страницы. `color` ΠΈ `--icon-color-N` Π½Π° внСшнСм элСмСнтС Π½Π΅ ΠΈΠ·ΠΌΠ΅Π½ΡΡŽΡ‚ Π΅Π³ΠΎ Π²Π½ΡƒΡ‚Ρ€Π΅Π½Π½ΠΈΠ΅ Ρ†Π²Π΅Ρ‚Π°. + +### Π§Π΅Ρ€Π΅Π· CSS + +```css +.icon { + background: url('./.svg-sprite/sprite.svg#search') center / contain no-repeat; +} +``` + +Для ΠΎΠ΄Π½ΠΎΡ†Π²Π΅Ρ‚Π½ΠΎΠ³ΠΎ силуэта ΠΌΠΎΠΆΠ½ΠΎ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ mask: + +```css +.icon { + background-color: currentColor; + mask: url('./.svg-sprite/sprite.svg#search') center / contain no-repeat; +} +``` + +Mask Π½Π΅ сохраняСт исходныС Ρ†Π²Π΅Ρ‚Π°, gradients ΠΈ различия ΠΌΠ΅ΠΆΠ΄Ρƒ `fill` ΠΈ `stroke`. + +ΠŸΡƒΡ‚ΡŒ Π² CSS Ρ€Π°Π·Ρ€Π΅ΡˆΠ°Π΅Ρ‚ΡΡ ΠΎΡ‚Π½ΠΎΡΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ самого CSS-Ρ„Π°ΠΉΠ»Π°. Π’ ΠΏΡ€ΠΈΠΌΠ΅Ρ€Π°Ρ… CSS-Ρ„Π°ΠΉΠ» находится рядом с `svg-sprite.config.ts`. + +## Assets ΠΈ ΠΊΠ΅ΡˆΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠ΅ + +Generated component ΠΈΠ»ΠΈ standalone facade ΠΏΠ΅Ρ€Π΅Π΄Π°Ρ‘Ρ‚ SVG сборщику ΠΊΠ°ΠΊ ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½Ρ‹ΠΉ asset: + +- Vite ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ статичСский ΠΈΠΌΠΏΠΎΡ€Ρ‚ с `?no-inline`; +- Webpack 5, Turbopack ΠΈ Next.js ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΡŽΡ‚ `new URL(..., import.meta.url)`; +- SVG path-Π΄Π°Π½Π½Ρ‹Π΅ Π½Π΅ ΡΠ΅Ρ€ΠΈΠ°Π»ΠΈΠ·ΡƒΡŽΡ‚ΡΡ Π² generated JavaScript. + +Bare `standalone` Π½Π΅ участвуСт Π² asset pipeline: ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠ΅ само ΠΊΠΎΠΏΠΈΡ€ΡƒΠ΅Ρ‚ ΠΈΠ»ΠΈ +ΠΏΡƒΠ±Π»ΠΈΠΊΡƒΠ΅Ρ‚ `sprite.svg` ΠΈ ΠΎΡ‚Π²Π΅Ρ‡Π°Π΅Ρ‚ Π·Π° URL, вСрсионированиС ΠΈ cache policy. + +ΠŸΡ€ΠΈ стандартном ΠΈΠΌΠ΅Π½ΠΎΠ²Π°Π½ΠΈΠΈ assets сборщик добавляСт content hash: + +```text +/assets/sprite-.svg +``` + +Π­Ρ‚ΠΎ позволяСт ΠΊΠ΅ΡˆΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ SVG ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½ΠΎ ΠΎΡ‚ JavaScript. ИзмСнСниС React-ΠΊΠΎΠ΄Π° Π½Π΅ мСняСт содСрТимоС спрайта, Π° ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΠ΅ ΠΈΠΊΠΎΠ½ΠΎΠΊ создаёт Π½ΠΎΠ²ΡƒΡŽ Π²Π΅Ρ€ΡΠΈΡŽ asset. + +HTTP cache headers, CDN ΠΈ `Cache-Control` Π½Π°ΡΡ‚Ρ€Π°ΠΈΠ²Π°ΡŽΡ‚ΡΡ ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠ΅ΠΌ ΠΈΠ»ΠΈ ΠΏΠ»Π°Ρ‚Ρ„ΠΎΡ€ΠΌΠΎΠΉ размСщСния. Для Webpack имя ΠΈΡ‚ΠΎΠ³ΠΎΠ²ΠΎΠ³ΠΎ Ρ„Π°ΠΉΠ»Π° зависит ΠΎΡ‚ `assetModuleFilename` ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π°. + +## Врансформации SVG + +ВсС трансформации Π²ΠΊΠ»ΡŽΡ‡Π΅Π½Ρ‹ ΠΏΠΎ ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ ΠΈ Π½Π°ΡΡ‚Ρ€Π°ΠΈΠ²Π°ΡŽΡ‚ΡΡ нСзависимо: + +| ΠžΠΏΡ†ΠΈΡ | Π§Ρ‚ΠΎ Π΄Π΅Π»Π°Π΅Ρ‚ | +|---|---| +| `removeSize` | УдаляСт `width` ΠΈ `height` с ΠΊΠΎΡ€Π½Π΅Π²ΠΎΠ³ΠΎ ``, сохраняя ΡΡƒΡ‰Π΅ΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΠΉ `viewBox` | +| `replaceColors` | ЗамСняСт Π½Π°ΠΉΠ΄Π΅Π½Π½Ρ‹Π΅ `fill` ΠΈ `stroke` Π½Π° `--icon-color-N` | +| `addTransition` | ДобавляСт transitions для `fill` ΠΈ `stroke` Π² Ρ†Π²Π΅Ρ‚Π½Ρ‹Π΅ элСмСнты ΠΈ generated styles | + +Π§Ρ‚ΠΎΠ±Ρ‹ ΠΎΡ‚ΠΊΠ»ΡŽΡ‡ΠΈΡ‚ΡŒ ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½ΡƒΡŽ ΠΎΠΏΠ΅Ρ€Π°Ρ†ΠΈΡŽ: + +```ts +export default defineSpriteConfig({ + mode: 'next@app/turbopack', + transform: { + removeSize: false, + replaceColors: false, + addTransition: false, + }, +}) +``` + +Π˜ΡΡ…ΠΎΠ΄Π½Ρ‹Π΅ SVG Π½Π΅ ΠΈΠ·ΠΌΠ΅Π½ΡΡŽΡ‚ΡΡ. Врансформации ΠΏΡ€ΠΈΠΌΠ΅Π½ΡΡŽΡ‚ΡΡ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ ΠΊ содСрТимому generated-спрайта. + +## Π£ΠΏΡ€Π°Π²Π»Π΅Π½ΠΈΠ΅ Ρ†Π²Π΅Ρ‚Π°ΠΌΠΈ + +### ΠœΠΎΠ½ΠΎΡ…Ρ€ΠΎΠΌΠ½Ρ‹Π΅ ΠΈΠΊΠΎΠ½ΠΊΠΈ + +Если Π½Π°ΠΉΠ΄Π΅Π½ ΠΎΠ΄ΠΈΠ½ Ρ†Π²Π΅Ρ‚, fallback становится `currentColor`: + +```svg +stroke="var(--icon-color-1, currentColor)" +``` + +Π¦Π²Π΅Ρ‚ задаётся Ρ‡Π΅Ρ€Π΅Π· prop ΠΈΠ»ΠΈ CSS: + +```tsx + +``` + +### ΠœΠ½ΠΎΠ³ΠΎΡ†Π²Π΅Ρ‚Π½Ρ‹Π΅ ΠΈΠΊΠΎΠ½ΠΊΠΈ + +ΠšΠ°ΠΆΠ΄Ρ‹ΠΉ ΡƒΠ½ΠΈΠΊΠ°Π»ΡŒΠ½Ρ‹ΠΉ Ρ†Π²Π΅Ρ‚ ΠΏΠΎΠ»ΡƒΡ‡Π°Π΅Ρ‚ ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½ΡƒΡŽ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½ΡƒΡŽ с исходным fallback: + +```svg +fill="var(--icon-color-1, #798198)" +fill="var(--icon-color-2, #ffffff)" +fill="var(--icon-color-3, #129d9d)" +``` + +МоТно Π·Π°ΠΌΠ΅Π½ΠΈΡ‚ΡŒ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΡ‹Π΅ значСния: + +```css +.icon { + --icon-color-1: #4b5563; + --icon-color-3: #14b8a6; +} +``` + +### ΠžΠ³Ρ€Π°Π½ΠΈΡ‡Π΅Π½ΠΈΡ + +- `none`, `transparent`, `inherit`, `unset` ΠΈ `initial` Π½Π΅ Π·Π°ΠΌΠ΅Π½ΡΡŽΡ‚ΡΡ; +- Π½Π°Π΄Ρ‘ΠΆΠ½Π΅Π΅ всСго ΠΎΠ±Ρ€Π°Π±Π°Ρ‚Ρ‹Π²Π°ΡŽΡ‚ΡΡ Ρ†Π²Π΅Ρ‚Π° Π² Π°Ρ‚Ρ€ΠΈΠ±ΡƒΡ‚Π°Ρ… `fill`, `stroke` ΠΈ inline `style`; +- CSS-классы ΠΈ внСшниС stylesheets Π²Π½ΡƒΡ‚Ρ€ΠΈ SVG Π½Π΅ ΡΠ²Π»ΡΡŽΡ‚ΡΡ основным сцСнариСм трансформации; +- значСния `url(#...)` ΠΌΠΎΠ³ΡƒΡ‚ Π±Ρ‹Ρ‚ΡŒ Π·Π°ΠΌΠ΅Π½Π΅Π½Ρ‹ вмСстС с Ρ†Π²Π΅Ρ‚Π°ΠΌΠΈ, поэтому gradients ΠΈ patterns Ρ‚Ρ€Π΅Π±ΡƒΡŽΡ‚ ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½ΠΎΠ³ΠΎ спрайта с `replaceColors: false`; +- masks, filters ΠΈ слоТныС Π²Π½ΡƒΡ‚Ρ€Π΅Π½Π½ΠΈΠ΅ CSS-ΠΏΡ€Π°Π²ΠΈΠ»Π° Ρ‚Ρ€Π΅Π±ΡƒΡŽΡ‚ Π²ΠΈΠ·ΡƒΠ°Π»ΡŒΠ½ΠΎΠΉ ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΊΠΈ; +- CSS-ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅ страницы доступны Ρ‡Π΅Ρ€Π΅Π· ``, Π½ΠΎ Π½Π΅ Π²Π½ΡƒΡ‚Ρ€ΠΈ `` ΠΈ CSS background. + +Для слоТной ΠΈΠΊΠΎΠ½ΠΊΠΈ ΠΌΠΎΠΆΠ½ΠΎ ΠΎΡ‚ΠΊΠ»ΡŽΡ‡ΠΈΡ‚ΡŒ `replaceColors` Π² ΠΊΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ†ΠΈΠΈ ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½ΠΎΠ³ΠΎ спрайта. + +## SpriteViewer + +Viewer ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ ΠΎΠ΄ΠΈΠ½ Web Component с Shadow DOM для всСх modes. React ΠΈ Π±ΡƒΠ΄ΡƒΡ‰ΠΈΠ΅ framework-ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚Ρ‹ ΡΠ²Π»ΡΡŽΡ‚ΡΡ bridge ΠΊ этому ΠΆΠ΅ элСмСнту, поэтому Π²ΠΈΠ·ΡƒΠ°Π» ΠΈ ΠΏΠΎΠ²Π΅Π΄Π΅Π½ΠΈΠ΅ Π½Π΅ Π΄ΡƒΠ±Π»ΠΈΡ€ΡƒΡŽΡ‚ΡΡ. + +Bare `standalone` ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π°Π΅Ρ‚ ΡΠ°ΠΌΠΎΡΡ‚ΠΎΡΡ‚Π΅Π»ΡŒΠ½Ρ‹ΠΉ browser bundle ΠΈ ΠΏΠ΅Ρ€Π΅Π΄Π°Ρ‘Ρ‚ URL JSON manifest ΠΈ ΠΎΠΏΡƒΠ±Π»ΠΈΠΊΠΎΠ²Π°Π½Π½ΠΎΠ³ΠΎ SVG: + +```html + + + +``` + +`viewer-element.js` Π½Π΅ ΠΈΠΌΠ΅Π΅Ρ‚ Π΄ΠΎΠΏΠΎΠ»Π½ΠΈΡ‚Π΅Π»ΡŒΠ½Ρ‹Ρ… runtime-Ρ„Π°ΠΉΠ»ΠΎΠ² ΠΈ ΠΌΠΎΠΆΠ΅Ρ‚ Π±Ρ‹Ρ‚ΡŒ скопирован с ΠΎΡΡ‚Π°Π»ΡŒΠ½Ρ‹ΠΌΠΈ static assets для self-hosting. + +`standalone@vite` ΠΈ `standalone@webpack` Ρ€Π΅Π³ΠΈΡΡ‚Ρ€ΠΈΡ€ΡƒΡŽΡ‚ Ρ‚ΠΎΡ‚ ΠΆΠ΅ элСмСнт Ρ‡Π΅Ρ€Π΅Π· npm entry ΠΈ ΠΏΠ΅Ρ€Π΅Π΄Π°ΡŽΡ‚ generated JS manifest Ρ‡Π΅Ρ€Π΅Π· свойство `sources`: + +```ts +import '@gromlab/svg-sprites/viewer/element' +import type { SpriteViewerElement } from '@gromlab/svg-sprites/viewer' +import spriteManifest from './svg-sprite/.svg-sprite/svg-sprite.manifest.js' + +const viewer = document.querySelector('gromlab-sprite-viewer')! +viewer.sources = [spriteManifest] +``` + +React ΠΈ Next.js ΡΠΎΡ…Ρ€Π°Π½ΡΡŽΡ‚ ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚Π½Ρ‹ΠΉ API: + +```tsx +import { SpriteViewer } from '@gromlab/svg-sprites/react' +``` + +Он ΠΏΡ€ΠΈΠ½ΠΈΠΌΠ°Π΅Ρ‚ Π³ΠΎΡ‚ΠΎΠ²Ρ‹Π΅ manifests, remote standalone sources, массив lazy loaders ΠΈΠ»ΠΈ record Ρ„ΠΎΡ€ΠΌΠ°Ρ‚Π° `import.meta.glob`. + +Vite: + +```tsx +import { SpriteViewer } from '@gromlab/svg-sprites/react' +import type { SpriteManifestModule } from '@gromlab/svg-sprites/react' + +const sources = import.meta.glob( + '/src/**/svg-sprite/.svg-sprite/svg-sprite.manifest.js', +) + +export const IconsDebugPage = () => ( + +) +``` + +Webpack ΠΈ Next.js: + +```tsx +const sources = [ + () => import('@/ui/app-icons/.svg-sprite/svg-sprite.manifest.js'), + () => import('@/features/analytics/icons/.svg-sprite/svg-sprite.manifest.js'), +] + +export const IconsDebugPage = () => ( + +) +``` + +Viewer ΠΏΠΎΠΊΠ°Π·Ρ‹Π²Π°Π΅Ρ‚ Π³Ρ€ΡƒΠΏΠΏΡ‹, поиск, `viewBox`, CSS-ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅ ΠΈ fallback-Ρ†Π²Π΅Ρ‚Π°. Framework manifests ΠΏΠΎΠ»ΡƒΡ‡Π°ΡŽΡ‚ Π²ΠΊΠ»Π°Π΄ΠΊΡƒ своСго framework, Π° Ρ‚Π°ΠΊΠΆΠ΅ SVG, IMG ΠΈ CSS; standalone manifests ΠΏΠΎΠ»ΡƒΡ‡Π°ΡŽΡ‚ SVG, IMG ΠΈ CSS. Π¦Π²Π΅Ρ‚ΠΎΠ²Ρ‹Π΅ значСния ΠΌΠΎΠΆΠ½ΠΎ ΠΌΠ΅Π½ΡΡ‚ΡŒ Π² интСрфСйсС ΠΈ сразу ΠΏΡ€ΠΎΠ²Π΅Ρ€ΡΡ‚ΡŒ Ρ€Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚. + +### Π’Π΅ΠΌΠ° Viewer + +По ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ `colorTheme="auto"` слСдуСт `prefers-color-scheme`. МоТно ΠΏΠ΅Ρ€Π΅Π΄Π°Ρ‚ΡŒ `light` ΠΈΠ»ΠΈ `dark` явно: + +```tsx + +``` + +Для синхронизации с Ρ‚Π΅ΠΌΠΎΠΉ прилоТСния: + +```tsx + +``` + +`@gromlab/svg-sprites/react` содСрТит `'use client'` ΠΈ Ρ€Π΅Π½Π΄Π΅Ρ€ΠΈΡ‚ Web Component host; Π²Π½ΡƒΡ‚Ρ€Π΅Π½Π½ΠΈΠΉ Shadow DOM создаётся послС Π·Π°Π³Ρ€ΡƒΠ·ΠΊΠΈ browser runtime. Π’ Next.js App Router Ρ€Π°Π·ΠΌΠ΅Ρ‰Π°ΠΉΡ‚Π΅ Viewer Π²Π½ΡƒΡ‚Ρ€ΠΈ ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½ΠΎΠΉ Client Component boundary ΠΈ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ Π½Π° debug-ΠΌΠ°Ρ€ΡˆΡ€ΡƒΡ‚Π΅ ΠΈΠ»ΠΈ Π²ΠΎ Π²Π½ΡƒΡ‚Ρ€Π΅Π½Π½Π΅ΠΌ инструмСнтС. + +## Generated-Ρ„Π°ΠΉΠ»Ρ‹, Git ΠΈ CI + +ВсС modes, ΠΊΡ€ΠΎΠΌΠ΅ bare `standalone`, ΡΠΎΠ·Π΄Π°ΡŽΡ‚ Π»ΠΎΠΊΠ°Π»ΡŒΠ½Ρ‹ΠΉ `.gitignore` для: + +```text +/.svg-sprite/ +``` + +Π›ΠΎΠΊΠ°Π»ΡŒΠ½Ρ‹ΠΉ `.gitignore` слСдуСт ΠΎΠ΄ΠΈΠ½ Ρ€Π°Π· Π΄ΠΎΠ±Π°Π²ΠΈΡ‚ΡŒ Π² Ρ€Π΅ΠΏΠΎΠ·ΠΈΡ‚ΠΎΡ€ΠΈΠΉ. Он ΠΈΡΠΊΠ»ΡŽΡ‡Π°Π΅Ρ‚ ΠΎΡΡ‚Π°Π»ΡŒΠ½Ρ‹Π΅ generated-Ρ„Π°ΠΉΠ»Ρ‹, поэтому Π³Π΅Π½Π΅Ρ€Π°Ρ†ΠΈΡŽ Π½ΡƒΠΆΠ½ΠΎ Π·Π°ΠΏΡƒΡΠΊΠ°Ρ‚ΡŒ ΠΏΠ΅Ρ€Π΅Π΄ ΠΊΠΎΠΌΠ°Π½Π΄Π°ΠΌΠΈ, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ ΠΈΠΌΠΏΠΎΡ€Ρ‚ΠΈΡ€ΡƒΡŽΡ‚ sprite-ΠΌΠΎΠ΄ΡƒΠ»ΡŒ: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites src/ui/app-icons/svg-sprite.config.ts", + "predev": "npm run sprites", + "prebuild": "npm run sprites", + "pretypecheck": "npm run sprites" + } +} +``` + +CI Π΄ΠΎΠ»ΠΆΠ΅Π½ Π²Ρ‹ΠΏΠΎΠ»Π½ΡΡ‚ΡŒ generation script Π΄ΠΎ сборки ΠΈΠ»ΠΈ ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΊΠΈ Ρ‚ΠΈΠΏΠΎΠ². Π›ΠΎΠΊΠ°Π»ΡŒΠ½Π°Ρ установка package Π½Π΅ Π½ΡƒΠΆΠ½Π°, Ссли CI Π½Π΅ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ Viewer, package-Ρ‚ΠΈΠΏΡ‹ config ΠΈΠ»ΠΈ ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½Ρ‹ΠΉ API. + +Bare `standalone` Π½Π΅ создаёт `.gitignore` ΠΈ сохраняСт ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒΡΠΊΠΈΠΉ Ρ„Π°ΠΉΠ». Если послС Π΄Ρ€ΡƒΠ³ΠΎΠ³ΠΎ mode остался управляСмый `.gitignore`, bare mode ΡƒΠ΄Π°Π»ΠΈΡ‚ Π΅Π³ΠΎ. Π’ ΠΎΡΡ‚Π°Π»ΡŒΠ½Ρ‹Ρ… modes Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ откаТСтся ΠΏΠ΅Ρ€Π΅Π·Π°ΠΏΠΈΡΠ°Ρ‚ΡŒ ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒΡΠΊΠΈΠΉ `.gitignore` Π±Π΅Π· generated marker. ΠšΠΎΡ€Π½Π΅Π²ΠΎΠΉ `index.ts` остаётся ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒΡΠΊΠΈΠΌ ΠΈ ΠΌΠΎΠΆΠ΅Ρ‚ ΠΏΠ΅Ρ€Π΅ΡΠΊΡΠΏΠΎΡ€Ρ‚ΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ generated API. + +## Диагностика + +- Для всСх modes, ΠΊΡ€ΠΎΠΌΠ΅ bare `standalone`: Ссли Π½Π΅Ρ‚ `.svg-sprite/index.js`, запуститС generation script Π΄ΠΎ ΠΈΠΌΠΏΠΎΡ€Ρ‚Π° generated-модуля. +- НС Π½Π°ΠΉΠ΄Π΅Π½ источник: ΠΏΠ΅Ρ€Π΅Π΄Π°ΠΉΡ‚Π΅ ΡΡƒΡ‰Π΅ΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΠΉ config-Ρ„Π°ΠΉΠ» ΠΈΠ»ΠΈ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ sprite-модуля. +- НС ΡƒΠΊΠ°Π·Π°Π½ mode: Π΄ΠΎΠ±Π°Π²ΡŒΡ‚Π΅ `mode` Π² config Π»ΠΈΠ±ΠΎ ΠΏΠ΅Ρ€Π΅Π΄Π°ΠΉΡ‚Π΅ `--mode`. +- Иконка отсутствуСт Π² Ρ‚ΠΈΠΏΠ΅: ΠΏΡ€ΠΎΠ²Π΅Ρ€ΡŒΡ‚Π΅ `input`, Ρ€Π°ΡΡˆΠΈΡ€Π΅Π½ΠΈΠ΅ `.svg`, glob-ΠΈΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΡ ΠΈ Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎΡΡ‚ΡŒ `**/*.svg` для Π²Π»ΠΎΠΆΠ΅Π½Π½Ρ‹Ρ… ΠΏΠ°ΠΏΠΎΠΊ. +- ΠšΠΎΠ½Ρ„Π»ΠΈΠΊΡ‚ ΠΈΠΌΠ΅Π½ΠΈ: Π΄Π²Π° Ρ€Π°Π·Π½Ρ‹Ρ… SVG ΠΈΠΌΠ΅ΡŽΡ‚ ΠΎΠ΄ΠΈΠ½Π°ΠΊΠΎΠ²Ρ‹ΠΉ basename; ΠΏΠ΅Ρ€Π΅ΠΈΠΌΠ΅Π½ΡƒΠΉΡ‚Π΅ ΠΎΠ΄ΠΈΠ½ Ρ„Π°ΠΉΠ». +- `Refusing to overwrite a user file`: Π² ΠΊΠΎΡ€Π½Π΅ sprite-модуля находится ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒΡΠΊΠΈΠΉ `.gitignore`, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ Π½Π΅ ΠΌΠΎΠΆΠ΅Ρ‚ Π·Π°ΠΌΠ΅Π½ΠΈΡ‚ΡŒ. +- Иконка Π½Π΅ мСняСт Ρ†Π²Π΅Ρ‚: ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ `` ΠΈΠ»ΠΈ generated-ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ ΠΈ ΠΏΡ€ΠΎΠ²Π΅Ρ€ΡŒΡ‚Π΅ `replaceColors`. +- Webpack Π²Ρ‹Π΄Π°Ρ‘Ρ‚ Π½Π΅Π²Π΅Ρ€Π½Ρ‹ΠΉ URL: ΠΏΡ€ΠΎΠ²Π΅Ρ€ΡŒΡ‚Π΅ Asset Modules, `output.publicPath` ΠΈ SVG loaders. +- Static sprite Π²ΠΎΠ·Π²Ρ€Π°Ρ‰Π°Π΅Ρ‚ 404: ΠΏΡ€ΠΎΠ²Π΅Ρ€ΡŒΡ‚Π΅ post-generation copy ΠΈΠ»ΠΈ server alias ΠΈ Π½Π΅ ΠΏΠ΅Ρ€Π΅Π΄Π°Π²Π°ΠΉΡ‚Π΅ filesystem `spritePath` Π² HTML. +- Viewer Π½Π΅ Π²ΠΈΠ΄ΠΈΡ‚ спрайт: для bundler modes ΠΏΡ€ΠΎΠ²Π΅Ρ€ΡŒΡ‚Π΅ ΠΏΡƒΡ‚ΡŒ ΠΊ `.svg-sprite/svg-sprite.manifest.js`; для bare `standalone` β€” URL ΠΎΠΏΡƒΠ±Π»ΠΈΠΊΠΎΠ²Π°Π½Π½Ρ‹Ρ… `svg-sprite.manifest.json` ΠΈ `sprite.svg`. Π’Ρ‹ΠΏΠΎΠ»Π½ΠΈΡ‚Π΅ Π³Π΅Π½Π΅Ρ€Π°Ρ†ΠΈΡŽ Π΄ΠΎ запуска прилоТСния. +- Build ΠΈ mode Π½Π΅ ΡΠΎΠ²ΠΏΠ°Π΄Π°ΡŽΡ‚: ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ target, ΡΠΎΠΎΡ‚Π²Π΅Ρ‚ΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΠΉ фактичСскому сборщику. + +Для собствСнного orchestration ΠΈ Π½ΠΈΠ·ΠΊΠΎΡƒΡ€ΠΎΠ²Π½Π΅Π²ΠΎΠΉ компиляции смотритС [ΠŸΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½Ρ‹ΠΉ API](programmatic-api.md). diff --git a/skills/svg-sprites/SKILL.md b/skills/svg-sprites/SKILL.md new file mode 100644 index 0000000..a6243d5 --- /dev/null +++ b/skills/svg-sprites/SKILL.md @@ -0,0 +1,359 @@ +--- +name: svg-sprites +description: "Use only when configuring, generating, or troubleshooting @gromlab/svg-sprites. Triggers: @gromlab/svg-sprites, svg-sprite.config.json, defineSpriteConfig, generateSprite, standalone@server, source: remote, ServerSvgInput, exact modes for standalone, React, Next.js, Vue, Nuxt, Svelte, Angular, Astro, Solid, Preact, Qwik, Lit, or Alpine.js, SpriteConfig.input, --input, SpriteViewer, or --icon-color-N. Do NOT use for custom SVG sprites, favicons, raster images, icon fonts, choosing an icon set, or inline SVG without this package." +--- + + + +# @gromlab/svg-sprites + +## What the package does + +`@gromlab/svg-sprites` is a CLI generator that builds SVG sprites from user-provided SVG files. The package does not include its own icon set: it compiles project SVGs into an external sprite asset and creates a typed native component for the selected exact framework and bundler mode. + +The package supports multiple independent sprites in one project. Each explicitly selected config file or config-less directory describes one sprite and gets its own: + +- SVG asset; +- mode-specific manifest data; +- icon name types and production entry `.svg-sprite/index.js` for every mode except bare `standalone`; +- an isolated framework-native component and declarations for framework modes; +- a native Web Component with an explicit registration function for `standalone@vite`/`standalone@webpack`; +- a deployment-neutral JSON manifest without a public URL for bare `standalone`. +- a content-addressed server release with two compile profiles and an integrity manifest for `standalone@server`. + +The project determines how many sprite directories exist and where they live. For example, `name: 'file-manager'` produces `FileManagerIcon`, `FileManagerIconName`, and `fileManagerIconNames`, while another directory with `name: 'navigation'` produces a separate `NavigationIcon`. These are examples of per-sprite APIs, not fixed package exports. + +Generated production runtime and declarations do not import `@gromlab/svg-sprites`. Generation through `npx --yes @gromlab/svg-sprites ` does not add the package to the project. Install it as a development dependency only for the Viewer, package-provided config types, or the programmatic API. + +Any consumer exact mode can use `source: 'remote'` with one local path or HTTP(S) +URL to a manifest produced by `standalone@server`. Generation verifies and downloads +the required profile before the adapter creates its normal local API and asset; the +browser never depends on the server manifest at runtime. + +## Selecting a mode + +Select exactly one supported mode key: + +| Project | Mode key | +|---|---| +| Static HTML / custom publishing | `standalone` | +| Standalone + Vite | `standalone@vite` | +| Standalone + Webpack 5 | `standalone@webpack` | +| Server or CI release | `standalone@server` | +| React + Vite | `react@vite` | +| React + Webpack 5 | `react@webpack` | +| Vue + Vite | `vue@vite` | +| Vue + Webpack | `vue@webpack` | +| Nuxt + Vite | `nuxt@vite` | +| Nuxt + Webpack | `nuxt@webpack` | +| Svelte + Vite | `svelte@vite` | +| Svelte + Webpack | `svelte@webpack` | +| SvelteKit + Vite | `sveltekit@vite` | +| Angular application builder | `angular@application` | +| Angular + Webpack | `angular@webpack` | +| Astro + Vite | `astro@vite` | +| Solid + Vite | `solid@vite` | +| Solid + Webpack | `solid@webpack` | +| SolidStart + Vite | `solid-start@vite` | +| Preact + Vite | `preact@vite` | +| Preact + Webpack | `preact@webpack` | +| Qwik + Vite | `qwik@vite` | +| Lit + Vite | `lit@vite` | +| Lit + Webpack | `lit@webpack` | +| Alpine.js + Vite | `alpine@vite` | +| Alpine.js + Webpack | `alpine@webpack` | +| Next.js App Router + Turbopack | `next@app/turbopack` | +| Next.js App Router + Webpack 5 | `next@app/webpack` | +| Next.js Pages Router + Turbopack | `next@pages/turbopack` | +| Next.js Pages Router + Webpack 5 | `next@pages/webpack` | + +Mode may come from the config, CLI, or programmatic API. Values are applied as `defaults β†’ config β†’ CLI/API overrides`. A mode must exist after merging. + +`name` is optional. When omitted, the generator converts the sprite-module directory name to kebab-case; directories named `svg-sprite` and `svg-sprites` use their parent directory's name. An explicit `name` must already be kebab-case and begin with an ASCII letter. + +The CLI accepts exactly one path. A `.ts`, `.js`, or `.json` file loads that exact config regardless of its name. A directory enables config-less generation with settings supplied through CLI flags. + +```json +{ + "scripts": { + "sprite:": "npx --yes @gromlab/svg-sprites ", + "sprite::cli": "npx --yes @gromlab/svg-sprites --mode " + } +} +``` + +Generation through `npx` does not add the package to the project. Do not invent shortened or generic mode keys, and do not use the removed `legacy` mode. Select one complete key from the table. Use bare `standalone` only when the application publishes the SVG itself, and `standalone@server` only for a centralized release consumed during generation. Create one command per config file or directory when the project has multiple sprites. + +## Inspecting the project + +Establish the project's actual contract before making changes: + +1. Read the root `package.json`, lockfile, and workspace configuration; identify the framework, bundler, and existing commands. +2. Find config files, commands containing `svg-sprites`, and imports of generated components. Config names are arbitrary; use the explicit CLI path and object fields. +3. Determine the framework, router when applicable, and actual bundler from scripts and configuration. For Next.js, separately determine the App/Pages Router and the bundler used by the real `dev`/`build` commands. +4. Check existing `predev`, `prebuild`, `pretypecheck`, and orchestration scripts. Do not overwrite them. +5. For a new sprite, choose a target directory without imposing a particular application layer or architecture. +6. Check TypeScript and alias settings. Package subpath exports require TypeScript 5+ with `moduleResolution: 'bundler'`, `'node16'`, or `'nodenext'`. + +For a regular local consumer, all input paths are relative to the directory containing the explicitly selected config file; in config-less mode they are relative to the supplied directory. Inspect local `input` using this contract: + +- `input?: string | string[]` defaults to `./icons`; +- each string is a folder, an exact SVG file, or a glob; +- a folder is scanned shallowly; nested files are included only by an explicit recursive glob such as `./icons/**/*.svg`; +- an array combines positive sources, while an item prefixed with `!` excludes its matches from the combined set; +- every positive source must resolve to at least one SVG, so a missing or empty folder, an unmatched glob, a missing file, or a non-SVG exact file is an error; +- resolved files are deduplicated and sorted deterministically; +- different files with the same basename are a conflict, even when they came from different sources. + +Branch before applying those rules: + +- `standalone@server` may combine local strings with `{ name, url, sha256? }` HTTP(S) descriptors; `name` is the public icon name and optional `sha256` verifies the downloaded bytes; +- `source: 'remote'` requires exactly one string containing a local manifest path or HTTP(S) manifest URL and does not accept source globs or descriptors; +- a remote consumer config contains only `mode`, `source`, and `input`; name, description, transforms, and generated notice come from the verified server manifest. + +Do not copy a shared SVG into several folders: add its exact path or a suitable glob to `input` in every sprite that needs it. Use `**/*.svg` only when recursive inclusion is intentional. + +## Setting up the integration + +Do not reproduce mode setup from memory. After inspecting the project, select one exact mode and open the corresponding file under `references/docs/en/guides/`. Treat that guide as the base operational contract, then adapt it to the project's existing structure. + +Work in this order: + +1. Identify the source SVG directory and the directory for one sprite module. One config creates one independent sprite; multiple sets require separate config files and unique `name` values. +2. Confirm the framework, router, and bundler against the exact mode. For Next.js, inspect the actual `dev` and `build` scripts, not just the presence of `next.config.*`. +3. Prefer a JSON config when the project does not need package-provided config types. A TypeScript config also loads through the CLI, but the package must be installed when the config imports `defineSpriteConfig` or package types. +4. Resolve every `input` from the config-file directory. Do not reorganize SVGs unnecessarily: use a folder path, exact file, glob, or array of these sources. +5. Add a sprite command with an explicit config path. Preserve existing `dev`, `build`, `typecheck`, and lifecycle hooks; place generation before the first process that imports `.svg-sprite`. +6. Do not run one generation twice through both a concurrent `predev` and `npm run sprites && ...`. For multiple sprites, create separate commands and one aggregate script. +7. If the application imports the sprite-module directory, create a user-owned `index.ts` next to `.svg-sprite`; do not place user files inside the generated directory. +8. Run the first generation before typecheck or application startup, then inspect the mode-specific output and the actual component import. + +For a centralized release, open `references/docs/en/guides/standalone-server.md`. +Generate and publish the complete `.svg-sprite` directory atomically. In each consumer, +retain its own exact framework mode, set `source: 'remote'`, and point `input` to that +manifest. Do not copy server files into a framework output or fetch the manifest from +application runtime. + +Do not add the Viewer automatically. Connect it only when requested or when visual verification of the set, colors, or complex SVGs is needed. Get the production isolation pattern from the exact guide: frameworks, bundlers, and routers use different boundaries. + +Do not copy snippets between exact modes even when their APIs look similar. Asset URLs, generated files, CSS handling, router boundaries, and debug-tool setup differ. + +## Generated directory contract + +For example, after generation a React/Next.js directory has this structure: + +```text +svg-sprite/ +β”œβ”€β”€ icons/ # user-owned sources +β”œβ”€β”€ svg-sprite.config.json # recommended config name +β”œβ”€β”€ index.ts # optional user-owned barrel +β”œβ”€β”€ .gitignore # managed by the generator +└── .svg-sprite/ + β”œβ”€β”€ index.js + β”œβ”€β”€ index.d.ts + β”œβ”€β”€ icon-data.js + β”œβ”€β”€ icon-data.d.ts + β”œβ”€β”€ sprite.svg + β”œβ”€β”€ svg-sprite.manifest.js + β”œβ”€β”€ svg-sprite.manifest.d.ts + └── react/ + β”œβ”€β”€ react-component.js + β”œβ”€β”€ react-component.d.ts + └── react-component.module.css +``` + +Standalone modes do not create `react/`. Bare `standalone` generates `sprite.svg` and `svg-sprite.manifest.json`; `standalone@vite`/`standalone@webpack` additionally generate `index.*`, `icon-data.*`, and a resolved manifest. Their `index.*` also contains a native generated Web Component; bare `standalone` gets no JavaScript runtime and does not create `.gitignore`. + +`standalone@server` generates `sprite..svg`, +`sprite-root-viewbox..svg`, and `svg-sprite.manifest.json`. It has no +consumer facade, browser runtime, Viewer entry, or `.gitignore`. The manifest records +both relative profile URLs, full SHA-256 digests, byte lengths, icon metadata, and +transform settings. + +Edit the source SVGs, selected config, and user-owned `index.ts`. Do not manually change anything in `.svg-sprite`: the next generation will overwrite it. In every mode except bare `standalone`, the generated `.gitignore` is also managed by the generator. To import from the sprite-module root, create a barrel: + +```ts +export * from './.svg-sprite/index.js' +``` + +The generator owns the complete `.svg-sprite` directory and replaces it on every run. Never put user files inside it. The generator also owns `.gitignore` when the selected mode creates it. Bare `standalone` preserves a user-owned `.gitignore`, but removes a managed `.gitignore` left by another mode. Generated paths must not contain symlinks. + +Every exact-mode adapter owns its facade, framework directory, native component runtime, declarations, manifest source, styles, and asset URL. React/Next use `react/`; other framework modes use their own generated contract documented by the matching guide. Standalone bundler modes export Web Component helpers and types; bare `standalone` does not create a facade. Manifest declarations define their types locally and do not import the generator package. + +In bundler modes, the sprite remains a separate asset and SVG path data is not embedded in JavaScript. The content hash depends on bundler settings. Bare `standalone` creates a fixed filename, and the application owns its public name and versioning: + +- Vite-based adapters use a mode-owned static asset import that keeps the sprite external; +- `standalone@vite` uses the same Vite asset mechanism and exports an href helper plus a native Web Component without React; +- `standalone@webpack` uses Webpack Asset Modules and exports the same mode-local Web Component without React; +- Webpack-based adapters and all Next modes use their adapter-owned external asset mechanism, commonly `new URL(..., import.meta.url).href`; +- a custom Webpack SVG loader must not intercept the generated `sprite.svg`; +- in Next mode, the generated component does not contain `'use client'` and works in Server Components, SSR, and SSG; do not add a client boundary solely for an icon; +- the Next build command and mode key must agree: Turbopack with `.../turbopack`, Webpack with `.../webpack`. +- remote consumers still publish through their own adapter's local asset pipeline; do not preserve or construct the server profile URL in generated application code. + +For bundler modes, do not move the generated sprite into `public` or rewrite its URL manually. For bare `standalone`, do not move the managed original: the application may explicitly copy it into deploy output and owns the public URL and stale-copy cleanup. Regenerate with the new complete key when changing mode. + +## Usage, accessibility, and colors + +The component name depends on the specific sprite's `name`. In `standalone@vite` and `standalone@webpack`, `name: 'file-manager'` creates the `` tag and the `defineFileManagerIconElement()` function: + +```ts +import { defineFileManagerIconElement } from './svg-sprite' + +defineFileManagerIconElement() +``` + +```html + +``` + +The native element has no runtime dependencies, selects the generated ID and `viewBox`, obtains the URL through the bundler, and renders `` in Shadow DOM. Its `icon` property is typed with the exact name union, while plain HTML attribute values are validated only at runtime. It defaults to `1em Γ— 1em`; resize the host with CSS. Bare `standalone` does not generate a Web Component. + +In component modes, the same `name: 'file-manager'` creates a native `FileManagerIcon` component. Its syntax and props follow the exact-mode guide. For React/Next.js, `name: 'navigation'` creates `NavigationIcon`. + +Import the component from the root of its sprite directory. `width` and `height` are optional: ordinary CSS classes can control the size. + +```tsx +import { FileManagerIcon } from './svg-sprite' + +export const OpenButton = () => ( + Open + +) +``` + +```css +.icon { + width: 24px; + height: 24px; + color: #4b5563; +} +``` + +`icon` accepts exact source filenames without `.svg`; an unknown name is a TypeScript error. For names that are not safe SVG IDs, the generator preserves the public name but creates an internal stable hash ID, so do not construct a fragment URL from the name manually. + +By default, the component renders `` and accepts standard SVG attributes: optional `width`/`height`, `className`, `style`, `role`, `aria-*`, and event handlers. With `wrapped={true}`, the root becomes a ``, props apply to the span, and the inner SVG fills the wrapper. + +The generated component does not decide semantics for the application and does not add a `title`. For a decorative icon, pass `aria-hidden="true"`; for a standalone meaningful icon, pass `role="img"` and an accessible name through `aria-label`. Do not duplicate the name when adjacent text already announces the action. Put interactivity on a `button` or `a`, not on the icon itself. + +The `removeSize`, `replaceColors`, and `addTransition` transforms are enabled by default. A monochrome icon's only color gets a `currentColor` fallback, so control it with the CSS `color` property. For a multicolor icon, pass typed custom properties: + +```tsx + +``` + +Automatic replacement targets `fill`/`stroke` attributes and inline `style`. The values `none`, `transparent`, `inherit`, `unset`, and `initial` are not replaced. Check CSS classes and external stylesheets, gradients, patterns, filters, and `url(#...)` against the actual output. Page variables work through ``, but do not cross into an external document loaded through `` or `background-image`; a CSS mask preserves only a monochrome silhouette. + +`SpriteViewer` is optional. Install `@gromlab/svg-sprites` as a development dependency only when the project needs the Viewer. It accepts manifests or statically discoverable loaders and provides search, themes, colors, and examples, but production components do not depend on it. + +Open the exact guide before connecting the Viewer. Frameworks, bundlers, and routers require different debug entries or client boundaries. Do not transfer setup between modes. + +## Verifying the result + +After changing a config or SVG, perform these required checks: + +1. Run the exact sprite command. It must exit with code `0` and report the name, icon count, mode, and `.svg-sprite` directory. +2. Inspect the output for the selected exact mode: + - bare `standalone` creates `sprite.svg` and `svg-sprite.manifest.json`; + - `standalone@server` creates two content-addressed SVG profiles and a server manifest whose hashes and relative paths match those files; + - `standalone@vite` and `standalone@webpack` additionally create `index.*`, `icon-data.*`, and a JS manifest, but no `react/` directory; + - framework modes also create their adapter-owned native component runtime, declaration, and styles. +3. For modes with a public facade, inspect `.svg-sprite/index.js`, the adjacent `index.d.ts`, the name list, and the actual import through the user-owned barrel. +4. Inspect the manifest: mode and target must match the selected adapter, and the icon list must match the source SVGs. In bundler modes the URL must use the mode-specific mechanism; the bare JSON manifest intentionally has no public `spriteUrl`. +5. Run the project's existing typecheck when the mode creates types or user-owned TypeScript changed. +6. Run the smallest application command affected by the change: `dev`, build, or a project-specific check. + +Do not run a full production build solely to verify a new icon name. It is required when the bundler target, router, Webpack loader, asset URL, or deployment path changed, or when diagnosing a production-only error. + +Perform visual, Network, and accessibility-tree checks only when a running application and browser tools are available. If those tools are unavailable, do not claim that colors, themes, accessibility, or the asset's HTTP response were verified; explicitly state what remains unchecked. + +Use the Viewer for complex colors, transforms, and broad visual checks. Do not add a debug route for routine generation of one sprite. + +## Diagnostics + +Match the symptom to the relevant check and fix the root cause: + +| Symptom | Likely cause | Action | +|---|---|---| +| `Missing sprite config file or module directory` | The positional path is missing | Pass one config file or a directory for config-less generation. | +| `Expected one config file or module directory` | Multiple paths were passed | Create one command per sprite and combine the scripts. | +| `Sprite mode is required` | Mode is absent from both config and CLI | Add `mode` to the object or pass the full `--mode`. | +| `Unsupported sprite config extension` | The supplied file is not `.ts`, `.js`, or `.json` | Use a supported config format. | +| A positive input source has no SVG matches | A folder is missing or empty, a glob matches nothing, or an exact path is missing or not an SVG | Resolve the source from the config directory and correct `input`; every positive item must produce at least one SVG. | +| Icons from a subdirectory are missing | A folder source was expected to scan recursively | Use an explicit glob such as `./icons/**/*.svg`; folders are shallow. | +| An excluded icon is still present | The exclusion lacks a leading `!`, is not in the `input` array, or is relative to the wrong directory | Add a matching `!` item and resolve it from the config directory. | +| CLI source selection is incomplete | Multiple sources were packed into one `--input` value or an option was omitted | Repeat `--input ` once per source or exclusion. | +| Icon name or SVG ID collision | Two different files have the same basename, or a hash ID collides with a name | Rename one source SVG; do not select a file implicitly. | +| `Refusing to overwrite a user file` | A user-owned `.gitignore` already exists at the sprite-module root where the mode must create one | Do not overwrite it: choose another sprite directory or coordinate moving the existing `.gitignore`. | +| Missing `.svg-sprite/index.js` or name absent from autocomplete | This is expected for bare `standalone`; in other modes generation did not run, the barrel is wrong, or the type server cached an old module | Confirm the exact mode, run the sprite command, check `export * from './.svg-sprite/index.js'`, then typecheck; restart the TypeScript server if necessary. | +| SVG does not load or the URL is wrong | Mode and bundler differ, Webpack `publicPath` is wrong, or a custom loader intercepted the asset | Align mode with the build command, check Asset Modules/`publicPath`, and exclude the generated SVG from the incompatible loader. | +| Next build differs between SSR and browser | The module targets another bundler/router, or the URL was rewritten manually | Restore the generated `new URL(...)`, select the exact Next mode, and regenerate. | +| `color` does not change a multicolor icon | The icon uses several variables or is rendered through ``/CSS background | Use ``/`` and the required `--icon-color-N` properties. | +| Gradient/filter renders incorrectly | Automatic color replacement cannot guarantee complex paint servers | Inspect the generated SVG; disable `replaceColors` for the sprite or simplify the source if necessary. | +| Viewer is empty | The manifest was not generated, the loader is not discoverable by the bundler, or the Client Component boundary is wrong | Generate the sprite first, then compare the manifest import and setup with the exact guide; in the App Router keep `'use client'` only in the Viewer component. | +| Remote manifest is rejected | It is not a `standalone@server` schema, contains an unsafe profile path, or its metadata is inconsistent | Publish the untouched complete server release and point `input` to its JSON manifest. | +| Remote sprite integrity check fails | The SVG is stale, truncated, or was changed independently from the manifest | Republish the manifest and both content-addressed profiles atomically; never overwrite a hashed SVG with different bytes. | + +For an unknown error, record the complete CLI command, mode, config-file or directory path, and first stack/error message. Then reduce it to one sprite without deleting user files or a managed `.gitignore`. + +## Operational reference map + +References are included in the built skill. Open only the documents relevant to the current task, but always open the exact-mode guide before changing an integration. + +### Overview + +- [Package README](./references/README.md) covers capabilities, the primary React/Next.js example, all supported families, and documentation links. + +### Configuration + +- [Configuration](./references/docs/en/configuration.md) covers JSON, JavaScript, and TypeScript configs, config fields, `input`, and CLI invocation. + +### Exact-mode guides + +- [`standalone`](./references/docs/en/guides/standalone.md) covers static HTML and custom SVG publishing. +- [`standalone@vite`](./references/docs/en/guides/standalone-vite.md) covers a vanilla Vite application and the Web Component. +- [`standalone@webpack`](./references/docs/en/guides/standalone-webpack.md) covers a vanilla Webpack 5 application and the Web Component. +- [`standalone@server`](./references/docs/en/guides/standalone-server.md) covers centralized content-addressed releases and remote consumers. +- [`react@vite`](./references/docs/en/guides/react-vite.md) covers React with Vite. +- [`react@webpack`](./references/docs/en/guides/react-webpack.md) covers React with Webpack 5. +- [`vue@vite`](./references/docs/en/guides/vue-vite.md) covers Vue with Vite. +- [`vue@webpack`](./references/docs/en/guides/vue-webpack.md) covers Vue with Webpack. +- [`nuxt@vite`](./references/docs/en/guides/nuxt-vite.md) covers Nuxt with Vite. +- [`nuxt@webpack`](./references/docs/en/guides/nuxt-webpack.md) covers Nuxt with Webpack. +- [`svelte@vite`](./references/docs/en/guides/svelte-vite.md) covers Svelte with Vite. +- [`svelte@webpack`](./references/docs/en/guides/svelte-webpack.md) covers Svelte with Webpack. +- [`sveltekit@vite`](./references/docs/en/guides/sveltekit-vite.md) covers SvelteKit with Vite. +- [`angular@application`](./references/docs/en/guides/angular-application.md) covers the Angular application builder. +- [`angular@webpack`](./references/docs/en/guides/angular-webpack.md) covers Angular with Webpack. +- [`astro@vite`](./references/docs/en/guides/astro-vite.md) covers Astro with Vite. +- [`solid@vite`](./references/docs/en/guides/solid-vite.md) covers Solid with Vite. +- [`solid@webpack`](./references/docs/en/guides/solid-webpack.md) covers Solid with Webpack. +- [`solid-start@vite`](./references/docs/en/guides/solid-start-vite.md) covers SolidStart with Vite. +- [`preact@vite`](./references/docs/en/guides/preact-vite.md) covers Preact with Vite. +- [`preact@webpack`](./references/docs/en/guides/preact-webpack.md) covers Preact with Webpack. +- [`qwik@vite`](./references/docs/en/guides/qwik-vite.md) covers Qwik with Vite. +- [`lit@vite`](./references/docs/en/guides/lit-vite.md) covers Lit with Vite. +- [`lit@webpack`](./references/docs/en/guides/lit-webpack.md) covers Lit with Webpack. +- [`alpine@vite`](./references/docs/en/guides/alpine-vite.md) covers Alpine.js with Vite. +- [`alpine@webpack`](./references/docs/en/guides/alpine-webpack.md) covers Alpine.js with Webpack. +- [`next@app/turbopack`](./references/docs/en/guides/next-app-turbopack.md) covers the Next.js App Router with Turbopack. +- [`next@app/webpack`](./references/docs/en/guides/next-app-webpack.md) covers the Next.js App Router with Webpack. +- [`next@pages/turbopack`](./references/docs/en/guides/next-pages-turbopack.md) covers the Next.js Pages Router with Turbopack. +- [`next@pages/webpack`](./references/docs/en/guides/next-pages-webpack.md) covers the Next.js Pages Router with Webpack. + +### Technical references + +- [Technical reference](./references/docs/en/reference/technical.md) covers requirements, CLI, unified configuration, naming, generated APIs, assets, transforms, colors, Viewer, Git, CI, and troubleshooting. +- [Programmatic API](./references/docs/en/reference/programmatic-api.md) covers `generateSprite`, overrides, config APIs, low-level compilation, and Viewer runtime. + +### Agent-specific reference + +- [Complex SVGs](./references/complex-svg.md) covers gradients, patterns, filters, masks, `url(#...)`, `viewBox`, fragment IDs, and visual diagnostics. diff --git a/skills/svg-sprites/references/README.md b/skills/svg-sprites/references/README.md new file mode 100644 index 0000000..2fa7949 --- /dev/null +++ b/skills/svg-sprites/references/README.md @@ -0,0 +1,303 @@ +# @gromlab/svg-sprites + +πŸ‡¬πŸ‡§ English | [πŸ‡·πŸ‡Ί Русский](https://github.com/gromlab-ru/svg-sprites/blob/master/README_RU.md) + +![npm](https://img.shields.io/npm/v/@gromlab/svg-sprites) ![license](https://img.shields.io/npm/l/@gromlab/svg-sprites) + +`@gromlab/svg-sprites` is a CLI tool for generating SVG sprites in modern web applications. It combines selected SVG icons into one or more external, cacheable sprites and prepares them for use in the UI. + +Each exact mode generates a native typed component for its framework and bundler: Web Component, React, Vue, Svelte, Angular, Astro, Solid, Preact, Qwik, Lit, or Alpine.js. In every case, the SVG remains a separate cacheable asset. + +## An SVG sprite as simple as a regular SVG icon + +One typed React component is generated for the entire sprite. Choose an icon with the `icon` prop, and your editor will autocomplete every available name. + +```tsx + +``` + +The component accepts familiar SVG attributes: dimensions, `color`, `className`, `style`, `aria-*`, and event handlers. If you need an outer container, add `wrapped`. + +```tsx + +``` + +You do not have to work with the sprite directly in your application. Use it like a regular SVG icon while benefiting from a single component, autocomplete, and TypeScript validation for every name. + +## AI-friendly out of the box + +`@gromlab/svg-sprites` is designed to work with AI agents from the start. Add the ready-made skill and ask an agent to configure, migrate, or troubleshoot the package without lengthy instructions or manual documentation research. + +Install the English skill: + +```bash +npx skills add gromlab-ru/svg-sprites --skill svg-sprites +``` + +Install the Russian skill: + +```bash +npx skills add gromlab-ru/svg-sprites --skill svg-sprites-ru +``` + +## From SVG to component in three steps + +The main example uses the Next.js App Router and Turbopack. + +### 1. Specify the icons you need + +Create directories for the source icons and the sprite: + +```text +assets/ +β”œβ”€β”€ app-icons/ +β”‚ └── svg-sprite.config.json +└── svg-icons/ + β”œβ”€β”€ search.svg + └── settings.svg +``` + +Create the sprite configuration: + +```json +{ + "mode": "next@app/turbopack", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +`input` supports directory paths, individual SVG files, and glob patterns. + +### 2. Add a generation script + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "predev": "npm run sprites", + "prebuild": "npm run sprites" + } +} +``` + +Create an entry point for the generated API: + +```ts +// assets/app-icons/index.ts +export * from './.svg-sprite/index.js' +``` + +First run: + +```bash +npm run sprites +``` + +The package will generate `AppIcon`, TypeScript types, and a separate SVG sprite. + +### 3. Use it like a regular icon + +```tsx +// app/page.tsx +import { AppIcon } from '../assets/app-icons' + +export default function SearchButton() { + return ( + + ) +} +``` + +This is a Server Component. The icon does not require a provider, `'use client'`, or manual URL construction. + +## Typed React component with autocomplete + +Each sprite gets its own ready-to-use component. The `icon` prop is derived from the actual SVG names, so your editor shows the exact list of available icons and TypeScript catches typos immediately. + +```tsx + // available icon + // TypeScript error +``` + +After you add a new SVG icon and run generation again, its name automatically appears in the types and autocomplete. There is no need to maintain components, union types, or a name registry manually. + +## Next.js App Router and SSR out of the box + +Generated components work in Server Components, SSR, and SSG without `'use client'`. + +Using an icon does not turn the page into a Client Component, require a provider, or create an additional hydration boundary. + +The same component can be used in `page.tsx`, `layout.tsx`, and both server and client components. + +## Multiple sprites instead of one global sprite + +Your project is not limited to a single icon set. Create independent sprites for shared elements, individual pages, and large UI modules. + +```tsx + + + +``` + +Each set gets its own typed component and SVG asset, so application sections do not load icons they do not need. + +## Store each icon only once + +Each SVG icon is stored once in the source library and can be included in any number of sprites. Shared icons do not need to be copied between pages and modules: a single source updates every set. + +```text +search.svg ─┬─→ AppIcon + β”œβ”€β†’ AnalyticsIcon + └─→ EditorIcon +``` + +Sprites are split for performance, while the source icon library remains unified. + +## Browser caching + +With a standard Vite, Webpack, or Next.js configuration, each sprite is emitted as a separate versioned SVG file. + +As long as the icon set does not change, the browser can reuse its cached copy independently of JavaScript application updates. + +Changes to React components do not require downloading the geometry of every icon again. + +## JavaScript without SVG bloat + +Icon paths remain in external SVG assets and do not add to application chunks. + +```text +React code β†’ JavaScript chunks +SVG icons β†’ separate SVG assets +``` + +JavaScript handles the interface and behavior, while graphics are loaded and cached separately. + +## Built-in SVG transformations + +During generation, the package automatically prepares source SVG files for use in the UI: + +- removes fixed `width` and `height` attributes; +- preserves the existing `viewBox`; +- converts `fill` and `stroke` values to CSS variables; +- adds smooth transitions directly to colored icon elements. + +Each transformation can be configured or disabled independently. + +## Control every color with CSS + +During generation, `fill` and `stroke` colors are automatically converted to `--icon-color-N` CSS variables. + +A monochrome icon inherits `currentColor`: + +```tsx + +``` + +For a multicolor icon, each color can be changed independently: + +```tsx + +``` + +Create themes, states, and hover effects without editing the SVG or making additional copies of the icon. + +## SpriteViewer: every sprite on one debug page + +`SpriteViewer` renders sprites from every supported exact mode in one place. One Web Component owns the visuals, while React also provides a thin bridge to it. + +For each icon, you can see the generated CSS variables and their fallback colors. Change the values directly in the Viewer and see the result immediately. + +It also provides ready-to-use examples for the manifest's framework, ``, ``, and CSS. + +![SpriteViewer](https://raw.githubusercontent.com/gromlab-ru/svg-sprites/master/preview-image.png) + +The Viewer is added only to an internal debug page and does not become part of the generated icon components. + +With bare standalone, the application loads the Viewer as a browser script and HTML element. Bundler and framework modes use the npm Web Component entry; React and Next.js may instead import the bridge from `@gromlab/svg-sprites/react`. + +## 30 exact modes + +The package supports 30 isolated exact modes: `standalone@server` for server-side generation of a universal SVG sprite and 29 consumer modes for modern frameworks and bundlers. + +`standalone@server` lets you generate an SVG sprite ahead of time on a server or in CI/CD and publish it for shared use. The resulting sprite is not tied to a specific framework or bundler and works with every consumer mode. + +The 29 consumer modes cover standalone, React, Next.js, Vue, Nuxt, Svelte, SvelteKit, Angular, Astro, Solid, SolidStart, Preact, Qwik, Lit, and Alpine.js across their supported Vite, Webpack, Turbopack, and application-builder variants. + +All 29 consumer modes can work with sprites generated locally in the project or with universal sprites generated ahead of time on the server through `standalone@server`. The component API and the way icons are used in the application remain the same in both scenarios. + +The integration matrix covers all 30 exact modes. A dedicated producer fixture verifies server-side generation of the universal sprite, while each of the 29 consumer applications generates and renders two independent sprites: one local and one remote. + +All consumer applications pass a production build and Playwright tests, while typed modes are additionally checked by their framework-native toolchain. Every E2E test confirms that both local and remote sprites load and render, checks for browser errors, and verifies both groups in SpriteViewer. + +## Clean Git history + +Bundler and framework modes create a local `.gitignore` that excludes generated files and keeps them from cluttering project history, pull requests, and the codebase. Bare `standalone` leaves the repository policy to the application. + +In bundler and framework modes, the repository contains the source SVG files, configuration, and `.gitignore` rule, while sprites, components, and types are regenerated locally and in CI through `prebuild`. + +## Only icons in production + +Generation can run entirely through `npx`, without adding the package to the project. Install it as a development dependency only when you need the Viewer, config types, or the programmatic API. + +Production components use only local generated code, styles, and the external SVG file. The compiler and CLI are not bundled into the client application, while `SpriteViewer` is imported separately only where a debug page is needed. + +## Documentation + +This README introduces the project's capabilities and demonstrates the primary use case. For setup, choose the guide for your stack. + +### Server-side generation + +- [Standalone + Server](docs/en/guides/standalone-server.md) + +### Consumer quick starts + +- [Bare standalone](docs/en/guides/standalone.md) +- [Standalone + Vite](docs/en/guides/standalone-vite.md) +- [Standalone + Webpack 5](docs/en/guides/standalone-webpack.md) +- [React + Vite](docs/en/guides/react-vite.md) +- [React + Webpack 5](docs/en/guides/react-webpack.md) +- [Vue + Vite](docs/en/guides/vue-vite.md) +- [Vue + Webpack](docs/en/guides/vue-webpack.md) +- [Nuxt + Vite](docs/en/guides/nuxt-vite.md) +- [Nuxt + Webpack](docs/en/guides/nuxt-webpack.md) +- [Svelte + Vite](docs/en/guides/svelte-vite.md) +- [Svelte + Webpack](docs/en/guides/svelte-webpack.md) +- [SvelteKit + Vite](docs/en/guides/sveltekit-vite.md) +- [Angular application builder](docs/en/guides/angular-application.md) +- [Angular + Webpack](docs/en/guides/angular-webpack.md) +- [Astro + Vite](docs/en/guides/astro-vite.md) +- [Solid + Vite](docs/en/guides/solid-vite.md) +- [Solid + Webpack](docs/en/guides/solid-webpack.md) +- [SolidStart + Vite](docs/en/guides/solid-start-vite.md) +- [Preact + Vite](docs/en/guides/preact-vite.md) +- [Preact + Webpack](docs/en/guides/preact-webpack.md) +- [Qwik + Vite](docs/en/guides/qwik-vite.md) +- [Lit + Vite](docs/en/guides/lit-vite.md) +- [Lit + Webpack](docs/en/guides/lit-webpack.md) +- [Alpine.js + Vite](docs/en/guides/alpine-vite.md) +- [Alpine.js + Webpack](docs/en/guides/alpine-webpack.md) +- [Next.js App Router + Turbopack](docs/en/guides/next-app-turbopack.md) +- [Next.js App Router + Webpack](docs/en/guides/next-app-webpack.md) +- [Next.js Pages Router + Turbopack](docs/en/guides/next-pages-turbopack.md) +- [Next.js Pages Router + Webpack](docs/en/guides/next-pages-webpack.md) + +### Technical resources + +- [Documentation index](docs/en/README.md) +- [Configuration](docs/en/configuration.md) +- [Technical reference](docs/en/reference/technical.md) +- [Programmatic API](docs/en/reference/programmatic-api.md) + +## License + +MIT diff --git a/skills/svg-sprites/src/en/references/complex-svg.md b/skills/svg-sprites/references/complex-svg.md similarity index 100% rename from skills/svg-sprites/src/en/references/complex-svg.md rename to skills/svg-sprites/references/complex-svg.md diff --git a/skills/svg-sprites/references/docs/en/README.md b/skills/svg-sprites/references/docs/en/README.md new file mode 100644 index 0000000..ec13211 --- /dev/null +++ b/skills/svg-sprites/references/docs/en/README.md @@ -0,0 +1,56 @@ +# Documentation + +Choose one exact mode guide for setup. The guides are standalone documents and +can also be used unchanged by AI skills. + +The common format for JSON, JavaScript, and TypeScript config files is described in the [configuration guide](configuration.md). + +## Consumer Quick Starts + +| Project | Exact mode | Guide | +|---|---|---| +| Static HTML or custom publishing | `standalone` | [Bare standalone](guides/standalone.md) | +| Vanilla + Vite | `standalone@vite` | [Standalone + Vite](guides/standalone-vite.md) | +| Vanilla + Webpack 5 | `standalone@webpack` | [Standalone + Webpack](guides/standalone-webpack.md) | +| React + Vite | `react@vite` | [React + Vite](guides/react-vite.md) | +| React + Webpack 5 | `react@webpack` | [React + Webpack](guides/react-webpack.md) | +| Vue + Vite | `vue@vite` | [Vue + Vite](guides/vue-vite.md) | +| Vue + Webpack | `vue@webpack` | [Vue + Webpack](guides/vue-webpack.md) | +| Nuxt + Vite | `nuxt@vite` | [Nuxt + Vite](guides/nuxt-vite.md) | +| Nuxt + Webpack | `nuxt@webpack` | [Nuxt + Webpack](guides/nuxt-webpack.md) | +| Svelte + Vite | `svelte@vite` | [Svelte + Vite](guides/svelte-vite.md) | +| Svelte + Webpack | `svelte@webpack` | [Svelte + Webpack](guides/svelte-webpack.md) | +| SvelteKit + Vite | `sveltekit@vite` | [SvelteKit + Vite](guides/sveltekit-vite.md) | +| Angular application builder | `angular@application` | [Angular application builder](guides/angular-application.md) | +| Angular + Webpack | `angular@webpack` | [Angular + Webpack](guides/angular-webpack.md) | +| Astro + Vite | `astro@vite` | [Astro + Vite](guides/astro-vite.md) | +| Solid + Vite | `solid@vite` | [Solid + Vite](guides/solid-vite.md) | +| Solid + Webpack | `solid@webpack` | [Solid + Webpack](guides/solid-webpack.md) | +| SolidStart + Vite | `solid-start@vite` | [SolidStart + Vite](guides/solid-start-vite.md) | +| Preact + Vite | `preact@vite` | [Preact + Vite](guides/preact-vite.md) | +| Preact + Webpack | `preact@webpack` | [Preact + Webpack](guides/preact-webpack.md) | +| Qwik + Vite | `qwik@vite` | [Qwik + Vite](guides/qwik-vite.md) | +| Lit + Vite | `lit@vite` | [Lit + Vite](guides/lit-vite.md) | +| Lit + Webpack | `lit@webpack` | [Lit + Webpack](guides/lit-webpack.md) | +| Alpine.js + Vite | `alpine@vite` | [Alpine.js + Vite](guides/alpine-vite.md) | +| Alpine.js + Webpack | `alpine@webpack` | [Alpine.js + Webpack](guides/alpine-webpack.md) | +| Next.js App Router + Turbopack | `next@app/turbopack` | [App Router + Turbopack](guides/next-app-turbopack.md) | +| Next.js App Router + Webpack | `next@app/webpack` | [App Router + Webpack](guides/next-app-webpack.md) | +| Next.js Pages Router + Turbopack | `next@pages/turbopack` | [Pages Router + Turbopack](guides/next-pages-turbopack.md) | +| Next.js Pages Router + Webpack | `next@pages/webpack` | [Pages Router + Webpack](guides/next-pages-webpack.md) | + +Every consumer guide follows the same order: + +1. Generate the sprite through `npx` without adding the package to the project. +2. Use the sprite in the application. +3. Optionally add the Viewer for debugging and previews. + +## Server-Side Generation + +Use [`standalone@server`](guides/standalone-server.md) to generate a universal SVG sprite on a server or in CI/CD for all consumer modes. + +## Reference + +- [Configuration](configuration.md) +- [Technical reference](reference/technical.md) +- [Programmatic API](reference/programmatic-api.md) diff --git a/skills/svg-sprites/references/docs/en/configuration.md b/skills/svg-sprites/references/docs/en/configuration.md new file mode 100644 index 0000000..7752b73 --- /dev/null +++ b/skills/svg-sprites/references/docs/en/configuration.md @@ -0,0 +1,139 @@ +# Configuration + +Each config file describes one independent sprite. The CLI does not discover config files automatically, so always pass the path explicitly: + +```bash +npx --yes @gromlab/svg-sprites path/to/svg-sprite.config.json +``` + +## JSON + +JSON works for most projects and does not require installing the package locally: + +```json +{ + "mode": "next@app/turbopack", + "name": "app", + "description": "Shared application icons", + "input": [ + "./icons", + "../../assets/icons/**/*.svg", + "!../../assets/icons/deprecated-*.svg" + ], + "transform": { + "removeSize": true, + "replaceColors": true, + "addTransition": true + }, + "generatedNotice": true +} +``` + +| Field | Default | Purpose | +|---|---|---| +| `mode` | None | Exact mode matching the framework and bundler | +| `source` | `local` | `local` for source SVG files or `remote` for a `standalone@server` manifest | +| `name` | Kebab-case module directory name; for `svg-sprite` and `svg-sprites`, the parent directory name | Sprite name; in modes with a component, it also determines the component and type names | +| `description` | None | Description used in types and the Viewer | +| `input` | `./icons` | Directory, SVG file, glob pattern, or array of sources | +| `transform` | All enabled | SVG preparation options | +| `generatedNotice` | `true` | Full or compact warning in generated files | + +Paths and glob patterns in `input` are resolved relative to the config file's directory. A pattern prefixed with `!` excludes matches. + +## Remotely built sprite + +A consumer config for a server manifest only contains the mode, source, and input: + +```json +{ + "mode": "react@vite", + "source": "remote", + "input": "https://assets.example/releases/app/svg-sprite.manifest.json" +} +``` + +`input` accepts one HTTP(S) URL or local manifest path. The name, description, +transforms, and generated notice come from the manifest. The generator downloads +and verifies the matching SVG profile before the adapter creates its normal local +components, types, and bundler asset. + +## Server build + +`standalone@server` combines local paths/globs with HTTP(S) SVG descriptors: + +```js +export default { + mode: 'standalone@server', + name: 'app', + input: [ + './icons/**/*.svg', + { + name: 'remote-logo', + url: 'https://assets.example/logo.svg', + }, + ], +} +``` + +The mode creates two content-addressed SVG profiles and `svg-sprite.manifest.json`. +`sha256` is optional for HTTP inputs; when present, it must be the expected 64-character +hexadecimal SHA-256 digest and the build verifies the received bytes. + +## JavaScript + +A JavaScript config default-exports a plain object: + +```js +export default { + mode: 'react@vite', + name: 'icons', + input: './icons', +} +``` + +Pass the path to the `.js` file to the CLI just like a JSON file: + +```bash +npx --yes @gromlab/svg-sprites path/to/svg-sprite.config.js +``` + +## TypeScript + +To type-check a TypeScript config, install the package as a development dependency: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +Use `defineSpriteConfig`: + +```ts +import { defineSpriteConfig } from '@gromlab/svg-sprites' + +export default defineSpriteConfig({ + mode: 'react@vite', + name: 'icons', + input: './icons', +}) +``` + +Alternatively, use `satisfies` with a type-only import: + +```ts +import type { SpriteConfig } from '@gromlab/svg-sprites' + +export default { + mode: 'react@vite', + name: 'icons', + input: './icons', +} satisfies SpriteConfig +``` + +The CLI loads `.ts` config files directly: + +```bash +npx --yes @gromlab/svg-sprites path/to/svg-sprite.config.ts +``` + +For the complete list of modes, CLI flags, naming rules, and transform options, see the [technical reference](reference/technical.md). diff --git a/skills/svg-sprites/references/docs/en/guides/alpine-vite.md b/skills/svg-sprites/references/docs/en/guides/alpine-vite.md new file mode 100644 index 0000000..9e20b7d --- /dev/null +++ b/skills/svg-sprites/references/docs/en/guides/alpine-vite.md @@ -0,0 +1,91 @@ +# SVG Sprite for Alpine.js with Vite + +A quick guide to creating an SVG sprite in an Alpine.js application built with Vite. + +## Generate the sprite + +Choose a directory for the future SVG sprite, for example `assets/app-icons`, and create `svg-sprite.config.json` inside it. In `input`, specify the path to existing SVG files relative to the configuration file. There is no need to move or copy the icons. + +```json +{ + "mode": "alpine@vite", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +The generator does not need to be added to the application dependencies: run it through `npx`. + +Add generation before development and production builds: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "predev": "npm run sprites", + "dev": "vite", + "prebuild": "npm run sprites", + "build": "vite build" + } +} +``` + +## Use the sprite + +The value `name: "app"` creates the Alpine plugin `appAlpinePlugin`, the `x-app-icon` directive, and the `$appIconHref` magic. + +Create `assets/app-icons/index.js`: + +```js +export * from './.svg-sprite/index.js' +``` + +Register the generated plugin before starting Alpine: + +```js +import Alpine from 'alpinejs' +import { appAlpinePlugin } from '../assets/app-icons/index.js' + +Alpine.plugin(appAlpinePlugin) +Alpine.start() +``` + +Use the reactive directive on an SVG element: + +```html + +``` + +The directive expression resolves to a source SVG file name without the extension. A monochrome icon inherits `color`; override multicolor icon layers with `--icon-color-N`. Vite loads the generated CSS and emits `sprite.svg` as a separate production asset. + +## Debug and preview + +Viewer displays all icons on one page and is only needed during development. Install it separately: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +Add Viewer to a development page: + +```html + + +``` + +Create `src/svg-sprite-debug.js`: + +```js +import '@gromlab/svg-sprites/viewer/element' +import spriteManifest from '../assets/app-icons/.svg-sprite/svg-sprite.manifest.js' + +document.querySelector('gromlab-sprite-viewer').sources = [spriteManifest] +``` + +Run `npm run dev` and open the development page. Viewer is independent from the Alpine plugin. diff --git a/skills/svg-sprites/references/docs/en/guides/alpine-webpack.md b/skills/svg-sprites/references/docs/en/guides/alpine-webpack.md new file mode 100644 index 0000000..dccbd63 --- /dev/null +++ b/skills/svg-sprites/references/docs/en/guides/alpine-webpack.md @@ -0,0 +1,103 @@ +# SVG Sprite for Alpine.js with Webpack 5 + +A quick guide to creating an SVG sprite in an Alpine.js application built with Webpack 5. + +## Generate the sprite + +Choose a directory for the future SVG sprite, for example `assets/app-icons`, and create `svg-sprite.config.json` inside it. In `input`, specify the path to existing SVG files relative to the configuration file. There is no need to move or copy the icons. + +```json +{ + "mode": "alpine@webpack", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +The generator does not need to be added to the application dependencies: run it through `npx`. + +Add generation before development and production builds: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "predev": "npm run sprites", + "dev": "webpack serve --mode development", + "prebuild": "npm run sprites", + "build": "webpack --mode production" + } +} +``` + +## Use the sprite + +The value `name: "app"` creates the Alpine plugin `appAlpinePlugin`, the `x-app-icon` directive, and the `$appIconHref` magic. + +Generated Alpine CSS is imported with the `?inline` query. Add an Asset Module rule to `webpack.config.js`: + +```js +export default { + module: { + rules: [ + { + test: /\.css$/, + resourceQuery: /inline/, + type: 'asset/source', + }, + ], + }, +} +``` + +Create `assets/app-icons/index.js`: + +```js +export * from './.svg-sprite/index.js' +``` + +Register the generated plugin before starting Alpine: + +```js +import Alpine from 'alpinejs' +import { appAlpinePlugin } from '../assets/app-icons/index.js' + +Alpine.plugin(appAlpinePlugin) +Alpine.start() +``` + +Use the reactive directive on an SVG element: + +```html + +``` + +The directive expression resolves to a source SVG file name without the extension. A monochrome icon inherits `color`; override multicolor icon layers with `--icon-color-N`. Webpack 5 emits `sprite.svg` as a separate production asset. + +## Debug and preview + +Viewer displays all icons on one page and is only needed during development. Install it separately: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +Add Viewer to a development entry: + +```js +import '@gromlab/svg-sprites/viewer/element' +import spriteManifest from '../assets/app-icons/.svg-sprite/svg-sprite.manifest.js' + +const viewer = document.createElement('gromlab-sprite-viewer') +viewer.viewerTitle = 'Project icons' +viewer.sources = [spriteManifest] +document.body.append(viewer) +``` + +Include this entry only in development. Viewer is independent from the Alpine plugin. diff --git a/skills/svg-sprites/references/docs/en/guides/angular-application.md b/skills/svg-sprites/references/docs/en/guides/angular-application.md new file mode 100644 index 0000000..965415b --- /dev/null +++ b/skills/svg-sprites/references/docs/en/guides/angular-application.md @@ -0,0 +1,94 @@ +# SVG Sprite for Angular with the Application Builder + +A quick guide to creating an SVG sprite in an Angular application built with `@angular/build:application`. + +## Generate the sprite + +Choose a directory for the future SVG sprite, for example `assets/app-icons`, and create `svg-sprite.config.json` inside it. In `input`, specify the path to existing SVG files relative to the configuration file. There is no need to move or copy the icons. + +```json +{ + "mode": "angular@application", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +The package does not need to be a project dependency. Run generation through `npx` before development and production builds: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "prestart": "npm run sprites", + "start": "ng serve", + "prebuild": "npm run sprites", + "build": "ng build" + } +} +``` + +The application builder emits imported SVG files when its file loader is enabled. Add this option to the build target in `angular.json`: + +```json +{ + "builder": "@angular/build:application", + "options": { + "loader": { ".svg": "file" } + } +} +``` + +## Use the sprite + +Create `assets/app-icons/index.ts`: + +```ts +export * from './.svg-sprite/index' +``` + +Import the generated standalone component. The value `name: "app"` creates `AppIcon` and the selector `app-icon`: + +```ts +import { Component } from '@angular/core' +import { AppIcon } from '../assets/app-icons' + +@Component({ + selector: 'app-root', + standalone: true, + imports: [AppIcon], + template: ` + + `, +}) +export class AppComponent {} +``` + +The `icon` input is typed from source file names. Monochrome icons inherit `color`; use `--icon-color-N` for individual colors. + +## Debug and preview + +Viewer is optional and only needed during development: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +Import `@gromlab/svg-sprites/viewer/element`, add `CUSTOM_ELEMENTS_SCHEMA`, and place `` in the template. Load the generated manifest while omitting framework-only usage metadata: + +```ts +readonly viewerSources = [async () => { + const { default: manifest } = await import( + '../assets/app-icons/.svg-sprite/svg-sprite.manifest.js' + ) + const { usage: _usage, ...viewerManifest } = manifest + return viewerManifest +}] +``` + +The Viewer uses the same production sprite URL as `AppIcon`. diff --git a/skills/svg-sprites/references/docs/en/guides/angular-webpack.md b/skills/svg-sprites/references/docs/en/guides/angular-webpack.md new file mode 100644 index 0000000..1d30c6d --- /dev/null +++ b/skills/svg-sprites/references/docs/en/guides/angular-webpack.md @@ -0,0 +1,93 @@ +# SVG Sprite for Angular with Webpack + +A quick guide to creating an SVG sprite in an Angular application built by the Webpack-based Angular CLI browser builder. + +## Generate the sprite + +Choose a directory for the future SVG sprite, for example `assets/app-icons`, and create `svg-sprite.config.json` inside it. In `input`, specify the path to existing SVG files relative to the configuration file. There is no need to move or copy the icons. + +```json +{ + "mode": "angular@webpack", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +This mode is for a workspace whose build target uses the official Webpack builder: + +```json +{ + "builder": "@angular-devkit/build-angular:browser" +} +``` + +The package does not need to be a project dependency. Generate the sprite through `npx` before each start and build: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "prestart": "npm run sprites", + "start": "ng serve", + "prebuild": "npm run sprites", + "build": "ng build" + } +} +``` + +Webpack resolves the generated `new URL(..., import.meta.url)` expression and emits `sprite.svg` as a production asset. + +## Use the sprite + +Create `assets/app-icons/index.ts`: + +```ts +export * from './.svg-sprite/index' +``` + +Import the generated standalone component. The value `name: "app"` creates `AppIcon` and the selector `app-icon`: + +```ts +import { Component } from '@angular/core' +import { AppIcon } from '../assets/app-icons' + +@Component({ + selector: 'app-root', + standalone: true, + imports: [AppIcon], + template: ` + + `, +}) +export class AppComponent {} +``` + +The `icon` input is typed from source file names. Monochrome icons inherit `color`; use `--icon-color-N` for individual colors. + +## Debug and preview + +Viewer is optional and only needed during development: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +Import `@gromlab/svg-sprites/viewer/element`, add `CUSTOM_ELEMENTS_SCHEMA`, and place `` in the template: + +```ts +readonly viewerSources = [async () => { + const { default: manifest } = await import( + '../assets/app-icons/.svg-sprite/svg-sprite.manifest.js' + ) + const { usage: _usage, ...viewerManifest } = manifest + return viewerManifest +}] +``` + +The Viewer and `AppIcon` share the Webpack-emitted sprite URL. diff --git a/skills/svg-sprites/references/docs/en/guides/astro-vite.md b/skills/svg-sprites/references/docs/en/guides/astro-vite.md new file mode 100644 index 0000000..888aba8 --- /dev/null +++ b/skills/svg-sprites/references/docs/en/guides/astro-vite.md @@ -0,0 +1,92 @@ +# SVG Sprite for Astro with Vite + +A quick guide to creating an SVG sprite in an Astro application built with Vite. + +## Generate the sprite + +Choose a directory for the future SVG sprite, for example `assets/app-icons`, and create `svg-sprite.config.json` inside it. In `input`, specify the path to existing SVG files relative to the configuration file. There is no need to move or copy the icons. + +```json +{ + "mode": "astro@vite", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +The package does not need to be a project dependency. Generate the sprite through `npx` before development and production builds: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "predev": "npm run sprites", + "dev": "astro dev", + "prebuild": "npm run sprites", + "build": "astro check && astro build" + } +} +``` + +## Use the sprite + +Create `assets/app-icons/index.js`: + +```js +export * from './.svg-sprite/index.js' +``` + +Create `assets/app-icons/index.d.ts` for the same typed API: + +```ts +export * from './.svg-sprite/index.js' +``` + +The value `name: "app"` creates the native Astro component `AppIcon`. Use it in a page: + +```astro +--- +import { AppIcon } from '../../assets/app-icons/index.js' +--- + + +``` + +The `icon` prop is typed from source file names. Vite emits `sprite.svg` from the component's static asset import. + +## Debug and preview + +Viewer is optional and only needed during development: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +Add the Viewer to the page and connect the generated manifest in a client script: + +```astro + + + +``` + +The manifest retains Astro usage metadata while Viewer renders the same production sprite. diff --git a/skills/svg-sprites/references/docs/en/guides/lit-vite.md b/skills/svg-sprites/references/docs/en/guides/lit-vite.md new file mode 100644 index 0000000..05c357f --- /dev/null +++ b/skills/svg-sprites/references/docs/en/guides/lit-vite.md @@ -0,0 +1,86 @@ +# SVG Sprite for Lit with Vite + +A quick guide to creating an SVG sprite in a Lit application built with Vite. + +## Generate the sprite + +Choose a directory for the future SVG sprite, for example `assets/app-icons`, and create `svg-sprite.config.json` inside it. In `input`, specify the path to existing SVG files relative to the configuration file. There is no need to move or copy the icons. + +```json +{ + "mode": "lit@vite", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +The generator does not need to be added to the application dependencies: run it through `npx`. + +Add generation before development and production builds: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "predev": "npm run sprites", + "dev": "vite", + "prebuild": "npm run sprites", + "build": "vite build" + } +} +``` + +## Use the sprite + +The value `name: "app"` creates the Lit class `AppIcon`, the `` tag, and the `defineAppIcon` registration function. + +Create `assets/app-icons/index.js`: + +```js +export * from './.svg-sprite/index.js' +``` + +Register the component before rendering it: + +```js +import { defineAppIcon } from '../assets/app-icons/index.js' + +defineAppIcon() + +document.querySelector('#app').innerHTML = ` + +` +``` + +The `icon` property accepts source SVG file names without the extension. A monochrome icon inherits `color`; override multicolor icon layers with `--icon-color-N`. Vite loads the component CSS and emits `sprite.svg` as a separate production asset. + +## Debug and preview + +Viewer displays all icons on one page and is only needed during development. Install it separately: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +Add Viewer to a development page: + +```html + + +``` + +Create `src/svg-sprite-debug.js`: + +```js +import '@gromlab/svg-sprites/viewer/element' +import spriteManifest from '../assets/app-icons/.svg-sprite/svg-sprite.manifest.js' + +document.querySelector('gromlab-sprite-viewer').sources = [spriteManifest] +``` + +Run `npm run dev` and open the development page. Viewer is not required by `AppIcon`. diff --git a/skills/svg-sprites/references/docs/en/guides/lit-webpack.md b/skills/svg-sprites/references/docs/en/guides/lit-webpack.md new file mode 100644 index 0000000..1ce85bb --- /dev/null +++ b/skills/svg-sprites/references/docs/en/guides/lit-webpack.md @@ -0,0 +1,98 @@ +# SVG Sprite for Lit with Webpack 5 + +A quick guide to creating an SVG sprite in a Lit application built with Webpack 5. + +## Generate the sprite + +Choose a directory for the future SVG sprite, for example `assets/app-icons`, and create `svg-sprite.config.json` inside it. In `input`, specify the path to existing SVG files relative to the configuration file. There is no need to move or copy the icons. + +```json +{ + "mode": "lit@webpack", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +The generator does not need to be added to the application dependencies: run it through `npx`. + +Add generation before development and production builds: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "predev": "npm run sprites", + "dev": "webpack serve --mode development", + "prebuild": "npm run sprites", + "build": "webpack --mode production" + } +} +``` + +## Use the sprite + +The value `name: "app"` creates the Lit class `AppIcon`, the `` tag, and the `defineAppIcon` registration function. + +Generated Lit CSS is imported with the `?inline` query. Add an Asset Module rule to `webpack.config.js`: + +```js +export default { + module: { + rules: [ + { + test: /\.css$/, + resourceQuery: /inline/, + type: 'asset/source', + }, + ], + }, +} +``` + +Create `assets/app-icons/index.js`: + +```js +export * from './.svg-sprite/index.js' +``` + +Register the component before rendering it: + +```js +import { defineAppIcon } from '../assets/app-icons/index.js' + +defineAppIcon() + +document.querySelector('#app').innerHTML = ` + +` +``` + +The `icon` property accepts source SVG file names without the extension. A monochrome icon inherits `color`; override multicolor icon layers with `--icon-color-N`. Webpack 5 emits `sprite.svg` as a separate production asset. + +## Debug and preview + +Viewer displays all icons on one page and is only needed during development. Install it separately: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +Add Viewer to a development entry: + +```js +import '@gromlab/svg-sprites/viewer/element' +import spriteManifest from '../assets/app-icons/.svg-sprite/svg-sprite.manifest.js' + +const viewer = document.createElement('gromlab-sprite-viewer') +viewer.viewerTitle = 'Project icons' +viewer.sources = [spriteManifest] +document.body.append(viewer) +``` + +Include this entry only in development. Viewer is not required by `AppIcon`. diff --git a/skills/svg-sprites/references/docs/en/guides/next-app-turbopack.md b/skills/svg-sprites/references/docs/en/guides/next-app-turbopack.md new file mode 100644 index 0000000..3917c65 --- /dev/null +++ b/skills/svg-sprites/references/docs/en/guides/next-app-turbopack.md @@ -0,0 +1,108 @@ +# SVG Sprite for Next.js App Router with Turbopack + +A quick guide to creating an SVG sprite in a Next.js application using App Router and Turbopack. + +## Generate the sprite + +Choose a directory for the future SVG sprite, for example `assets/app-icons`, and create `svg-sprite.config.json` inside it. In `input`, specify the path to existing SVG files relative to the configuration file. There is no need to move or copy the icons. + +Example configuration: + +```json +{ + "mode": "next@app/turbopack", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +The package does not need to be a project dependency: generation runs through `npx`. + +Add generation commands to `package.json`. Generated files are excluded from Git by default, so `predev` and `prebuild` rebuild the sprite before every start and build: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "predev": "npm run sprites", + "dev": "next dev --turbopack", + "prebuild": "npm run sprites", + "build": "next build --turbopack" + } +} +``` + +## Use the sprite + +The value `name: "app"` creates the React component `AppIcon`. + +Create the entry point `assets/app-icons/index.ts`: + +```ts +export * from './.svg-sprite/index.js' +``` + +Use the component in a Server Component: + +```tsx +// app/page.tsx +import { AppIcon } from '../assets/app-icons' + +export default function Page() { + return ( + + ) +} +``` + +`AppIcon` does not need `'use client'`. Turbopack automatically adds `sprite.svg` to the production build, so you do not need to move it to `public`. + +## Debug and preview + +Viewer displays all icons on one page so you can check their rendering, change colors, and inspect the related CSS variables. It is only needed for development and is installed separately: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +Create the Client Component `app/svg-sprite/SvgSpriteViewer.tsx`: + +```tsx +'use client' + +import { SpriteViewer } from '@gromlab/svg-sprites/react' + +const sources = [ + () => import('../../assets/app-icons/.svg-sprite/svg-sprite.manifest.js'), +] as const + +export function SvgSpriteViewer() { + return +} +``` + +Create the route `app/svg-sprite/page.tsx`: + +```tsx +import { notFound } from 'next/navigation' + +import { SvgSpriteViewer } from './SvgSpriteViewer' + +export default function SvgSpritePage() { + if (process.env.NODE_ENV !== 'development') notFound() + + return +} +``` + +Run `npm run dev` and open `/svg-sprite`. In production, the route returns 404. diff --git a/skills/svg-sprites/references/docs/en/guides/next-app-webpack.md b/skills/svg-sprites/references/docs/en/guides/next-app-webpack.md new file mode 100644 index 0000000..9c809cd --- /dev/null +++ b/skills/svg-sprites/references/docs/en/guides/next-app-webpack.md @@ -0,0 +1,108 @@ +# SVG Sprite for Next.js App Router with Webpack + +A quick guide to creating an SVG sprite in a Next.js application using App Router and Webpack. + +## Generate the sprite + +Choose a directory for the future SVG sprite, for example `assets/app-icons`, and create `svg-sprite.config.json` inside it. In `input`, specify the path to existing SVG files relative to the configuration file. There is no need to move or copy the icons. + +Example configuration: + +```json +{ + "mode": "next@app/webpack", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +The package does not need to be a project dependency: generation runs through `npx`. + +Add generation commands to `package.json`. Generated files are excluded from Git by default, so `predev` and `prebuild` rebuild the sprite before every start and build: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "predev": "npm run sprites", + "dev": "next dev --webpack", + "prebuild": "npm run sprites", + "build": "next build --webpack" + } +} +``` + +## Use the sprite + +The value `name: "app"` creates the React component `AppIcon`. + +Create the entry point `assets/app-icons/index.ts`: + +```ts +export * from './.svg-sprite/index.js' +``` + +Use the component in a Server Component: + +```tsx +// app/page.tsx +import { AppIcon } from '../assets/app-icons' + +export default function Page() { + return ( + + ) +} +``` + +`AppIcon` does not need `'use client'`. Next.js automatically adds `sprite.svg` to the production build, so you do not need to move it to `public`. + +## Debug and preview + +Viewer displays all icons on one page so you can check their rendering, change colors, and inspect the related CSS variables. It is only needed for development and is installed separately: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +Create the Client Component `app/svg-sprite/SvgSpriteViewer.tsx`: + +```tsx +'use client' + +import { SpriteViewer } from '@gromlab/svg-sprites/react' + +const sources = [ + () => import('../../assets/app-icons/.svg-sprite/svg-sprite.manifest.js'), +] as const + +export function SvgSpriteViewer() { + return +} +``` + +Create the route `app/svg-sprite/page.tsx`: + +```tsx +import { notFound } from 'next/navigation' + +import { SvgSpriteViewer } from './SvgSpriteViewer' + +export default function SvgSpritePage() { + if (process.env.NODE_ENV !== 'development') notFound() + + return +} +``` + +Run `npm run dev` and open `/svg-sprite`. In production, the route returns 404. diff --git a/skills/svg-sprites/references/docs/en/guides/next-pages-turbopack.md b/skills/svg-sprites/references/docs/en/guides/next-pages-turbopack.md new file mode 100644 index 0000000..de8194b --- /dev/null +++ b/skills/svg-sprites/references/docs/en/guides/next-pages-turbopack.md @@ -0,0 +1,98 @@ +# SVG Sprite for Next.js Pages Router with Turbopack + +A quick guide to creating an SVG sprite in a Next.js application using Pages Router and Turbopack. + +## Generate the sprite + +Choose a directory for the future SVG sprite, for example `assets/app-icons`, and create `svg-sprite.config.json` inside it. In `input`, specify the path to existing SVG files relative to the configuration file. There is no need to move or copy the icons. + +Example configuration: + +```json +{ + "mode": "next@pages/turbopack", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +The package does not need to be a project dependency: generation runs through `npx`. + +Add generation commands to `package.json`. Generated files are excluded from Git by default, so `predev` and `prebuild` rebuild the sprite before every start and build: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "predev": "npm run sprites", + "dev": "next dev --turbopack", + "prebuild": "npm run sprites", + "build": "next build --turbopack" + } +} +``` + +## Use the sprite + +The value `name: "app"` creates the React component `AppIcon`. + +Create the entry point `assets/app-icons/index.ts`: + +```ts +export * from './.svg-sprite/index.js' +``` + +Use the component on a page: + +```tsx +// pages/index.tsx +import { AppIcon } from '../assets/app-icons' + +export default function Page() { + return ( + + ) +} +``` + +The component works with SSR, SSG, and client-side navigation. Turbopack automatically adds `sprite.svg` to the production build, so you do not need to move it to `public`. + +## Debug and preview + +Viewer displays all icons on one page so you can check their rendering, change colors, and inspect the related CSS variables. It is only needed for development and is installed separately: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +Create the page `pages/svg-sprite.tsx`: + +```tsx +import type { GetStaticProps } from 'next' +import { SpriteViewer } from '@gromlab/svg-sprites/react' + +const sources = [ + () => import('../assets/app-icons/.svg-sprite/svg-sprite.manifest.js'), +] as const + +export default function SvgSpritePage() { + return +} + +export const getStaticProps: GetStaticProps = () => + process.env.NODE_ENV === 'development' + ? { props: {} } + : { notFound: true } +``` + +Run `npm run dev` and open `/svg-sprite`. In production, the route returns 404. diff --git a/skills/svg-sprites/references/docs/en/guides/next-pages-webpack.md b/skills/svg-sprites/references/docs/en/guides/next-pages-webpack.md new file mode 100644 index 0000000..f2b4565 --- /dev/null +++ b/skills/svg-sprites/references/docs/en/guides/next-pages-webpack.md @@ -0,0 +1,98 @@ +# SVG Sprite for Next.js Pages Router with Webpack + +A quick guide to creating an SVG sprite in a Next.js application using Pages Router and Webpack. + +## Generate the sprite + +Choose a directory for the future SVG sprite, for example `assets/app-icons`, and create `svg-sprite.config.json` inside it. In `input`, specify the path to existing SVG files relative to the configuration file. There is no need to move or copy the icons. + +Example configuration: + +```json +{ + "mode": "next@pages/webpack", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +The package does not need to be a project dependency: generation runs through `npx`. + +Add generation commands to `package.json`. Generated files are excluded from Git by default, so `predev` and `prebuild` rebuild the sprite before every start and build: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "predev": "npm run sprites", + "dev": "next dev --webpack", + "prebuild": "npm run sprites", + "build": "next build --webpack" + } +} +``` + +## Use the sprite + +The value `name: "app"` creates the React component `AppIcon`. + +Create the entry point `assets/app-icons/index.ts`: + +```ts +export * from './.svg-sprite/index.js' +``` + +Use the component on a page: + +```tsx +// pages/index.tsx +import { AppIcon } from '../assets/app-icons' + +export default function Page() { + return ( + + ) +} +``` + +The component works with SSR, SSG, and client-side navigation. Next.js automatically adds `sprite.svg` to the production build, so you do not need to move it to `public`. + +## Debug and preview + +Viewer displays all icons on one page so you can check their rendering, change colors, and inspect the related CSS variables. It is only needed for development and is installed separately: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +Create the page `pages/svg-sprite.tsx`: + +```tsx +import type { GetStaticProps } from 'next' +import { SpriteViewer } from '@gromlab/svg-sprites/react' + +const sources = [ + () => import('../assets/app-icons/.svg-sprite/svg-sprite.manifest.js'), +] as const + +export default function SvgSpritePage() { + return +} + +export const getStaticProps: GetStaticProps = () => + process.env.NODE_ENV === 'development' + ? { props: {} } + : { notFound: true } +``` + +Run `npm run dev` and open `/svg-sprite`. In production, the route returns 404. diff --git a/skills/svg-sprites/references/docs/en/guides/nuxt-vite.md b/skills/svg-sprites/references/docs/en/guides/nuxt-vite.md new file mode 100644 index 0000000..ede8175 --- /dev/null +++ b/skills/svg-sprites/references/docs/en/guides/nuxt-vite.md @@ -0,0 +1,100 @@ +# SVG Sprite for Nuxt with Vite + +A quick guide to creating an SVG sprite in a Nuxt application built with Vite. + +## Generate the sprite + +Choose a directory for the future SVG sprite, for example `assets/app-icons`, and create `svg-sprite.config.json` inside it. In `input`, specify the path to existing SVG files relative to the configuration file. There is no need to move or copy the icons. + +Example configuration: + +```json +{ + "mode": "nuxt@vite", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +The package does not need to be a project dependency: generation runs through `npx`. + +Add generation commands to `package.json`: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "predev": "npm run sprites", + "dev": "nuxt dev", + "prebuild": "npm run sprites", + "build": "nuxt build" + } +} +``` + +## Use the sprite + +The value `name: "app"` creates the Vue component `AppIcon`. Create `assets/app-icons/index.js`: + +```js +export * from './.svg-sprite/index.js' +``` + +Use the component in a Nuxt page or layout: + +```vue + + + +``` + +`AppIcon` is SSR-safe and does not need a client-only wrapper. Vite emits `sprite.svg` as a separate production asset. + +## Debug and preview + +Viewer displays all icons on one page so you can check their rendering, change colors, and inspect the related CSS variables. It is only needed for development and is installed separately: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +Create `app/components/SvgSpriteViewer.client.vue` so the browser-only Viewer is not evaluated during SSR: + +```vue + + + +``` + +Mark `gromlab-sprite-viewer` as a custom element in `nuxt.config.ts`: + +```ts +export default defineNuxtConfig({ + vue: { + compilerOptions: { + isCustomElement: (tag) => tag === 'gromlab-sprite-viewer', + }, + }, +}) +``` + +Render `` on your development page. Viewer is isolated from the generated `AppIcon` runtime. diff --git a/skills/svg-sprites/references/docs/en/guides/nuxt-webpack.md b/skills/svg-sprites/references/docs/en/guides/nuxt-webpack.md new file mode 100644 index 0000000..4b3ea60 --- /dev/null +++ b/skills/svg-sprites/references/docs/en/guides/nuxt-webpack.md @@ -0,0 +1,113 @@ +# SVG Sprite for Nuxt with Webpack + +A quick guide to creating an SVG sprite in a Nuxt application built with Webpack. + +## Generate the sprite + +Choose a directory for the future SVG sprite, for example `assets/app-icons`, and create `svg-sprite.config.json` inside it. In `input`, specify the path to existing SVG files relative to the configuration file. There is no need to move or copy the icons. + +Example configuration: + +```json +{ + "mode": "nuxt@webpack", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +The package does not need to be a project dependency: generation runs through `npx`. + +Use the Nuxt Webpack builder in `nuxt.config.ts`: + +```bash +npm install --save-dev @nuxt/webpack-builder +``` + +```ts +export default defineNuxtConfig({ + builder: '@nuxt/webpack-builder', +}) +``` + +Add generation commands to `package.json`: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "predev": "npm run sprites", + "dev": "nuxt dev", + "prebuild": "npm run sprites", + "build": "nuxt build" + } +} +``` + +## Use the sprite + +The value `name: "app"` creates the Vue component `AppIcon`. Create `assets/app-icons/index.js`: + +```js +export * from './.svg-sprite/index.js' +``` + +Use the component in a Nuxt page or layout: + +```vue + + + +``` + +`AppIcon` is SSR-safe and does not need a client-only wrapper. Webpack emits `sprite.svg` as a separate production asset. + +## Debug and preview + +Viewer displays all icons on one page so you can check their rendering, change colors, and inspect the related CSS variables. It is only needed for development and is installed separately: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +Create `app/components/SvgSpriteViewer.client.vue` so the browser-only Viewer is not evaluated during SSR: + +```vue + + + +``` + +Extend the existing `nuxt.config.ts` settings so Vue treats the Viewer as a custom element: + +```ts +export default defineNuxtConfig({ + builder: '@nuxt/webpack-builder', + vue: { + compilerOptions: { + isCustomElement: (tag) => tag === 'gromlab-sprite-viewer', + }, + }, +}) +``` + +Render `` on your development page. Viewer is isolated from the generated `AppIcon` runtime. diff --git a/skills/svg-sprites/references/docs/en/guides/preact-vite.md b/skills/svg-sprites/references/docs/en/guides/preact-vite.md new file mode 100644 index 0000000..7fd752b --- /dev/null +++ b/skills/svg-sprites/references/docs/en/guides/preact-vite.md @@ -0,0 +1,75 @@ +# SVG Sprite for Preact with Vite + +A quick guide to creating an SVG sprite in a Preact application built with Vite. + +## Generate the sprite + +Choose a directory for the future SVG sprite, for example `assets/app-icons`, and create `svg-sprite.config.json` inside it. In `input`, specify the path to existing SVG files relative to the configuration file. There is no need to move or copy the icons. + +```json +{ + "mode": "preact@vite", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +The package does not need to be a project dependency. Run it through `npx` before development and production builds: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "predev": "npm run sprites", + "dev": "vite", + "prebuild": "npm run sprites", + "build": "tsc --noEmit && vite build" + } +} +``` + +## Use the sprite + +Create `assets/app-icons/index.js` and `assets/app-icons/index.d.ts` with the same export: + +```js +export * from './.svg-sprite/index.js' +``` + +Use the generated plain-JavaScript Preact component: + +```jsx +import { AppIcon } from '../assets/app-icons/index.js' + +export function SaveIcon() { + return ( + + ) +} +``` + +Vite automatically emits the imported `sprite.svg` as a production asset. + +## Debug and preview + +Install Viewer only for development: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +Mount it from a debug entry: + +```js +import '@gromlab/svg-sprites/viewer/element' + +const viewer = document.createElement('gromlab-sprite-viewer') +viewer.sources = [() => import('../assets/app-icons/.svg-sprite/svg-sprite.manifest.js')] +document.body.append(viewer) +``` diff --git a/skills/svg-sprites/references/docs/en/guides/preact-webpack.md b/skills/svg-sprites/references/docs/en/guides/preact-webpack.md new file mode 100644 index 0000000..2fbd224 --- /dev/null +++ b/skills/svg-sprites/references/docs/en/guides/preact-webpack.md @@ -0,0 +1,75 @@ +# SVG Sprite for Preact with Webpack + +A quick guide to creating an SVG sprite in a Preact application built with Webpack 5. + +## Generate the sprite + +Choose a directory for the future SVG sprite, for example `assets/app-icons`, and create `svg-sprite.config.json` inside it. In `input`, specify the path to existing SVG files relative to the configuration file. There is no need to move or copy the icons. + +```json +{ + "mode": "preact@webpack", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +The package does not need to be a project dependency. Run it through `npx` before Webpack starts or builds: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "predev": "npm run sprites", + "dev": "webpack serve --mode development", + "prebuild": "npm run sprites", + "build": "tsc --noEmit && webpack --mode production" + } +} +``` + +## Use the sprite + +Create `assets/app-icons/index.js` and `assets/app-icons/index.d.ts` with the same export: + +```js +export * from './.svg-sprite/index.js' +``` + +Use the generated Preact component: + +```jsx +import { AppIcon } from '../assets/app-icons/index.js' + +export function SaveIcon() { + return ( + + ) +} +``` + +Webpack Asset Modules emit `sprite.svg` from the generated `new URL(...)` expression. + +## Debug and preview + +Install Viewer only for development: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +Mount it from a development-only entry: + +```js +import '@gromlab/svg-sprites/viewer/element' + +const viewer = document.createElement('gromlab-sprite-viewer') +viewer.sources = [() => import('../assets/app-icons/.svg-sprite/svg-sprite.manifest.js')] +document.body.append(viewer) +``` diff --git a/skills/svg-sprites/references/docs/en/guides/qwik-vite.md b/skills/svg-sprites/references/docs/en/guides/qwik-vite.md new file mode 100644 index 0000000..019f142 --- /dev/null +++ b/skills/svg-sprites/references/docs/en/guides/qwik-vite.md @@ -0,0 +1,82 @@ +# SVG Sprite for Qwik with Vite + +A quick guide to creating an SVG sprite in an SSR Qwik application built with Vite. + +## Generate the sprite + +Choose a directory for the future SVG sprite, for example `assets/app-icons`, and create `svg-sprite.config.json` inside it. In `input`, specify the path to existing SVG files relative to the configuration file. There is no need to move or copy the icons. + +```json +{ + "mode": "qwik@vite", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +The package does not need to be a project dependency. Regenerate through `npx` before Vite starts or builds: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "predev": "npm run sprites", + "dev": "vite --mode ssr", + "prebuild": "npm run sprites", + "build": "tsc --noEmit && vite build" + } +} +``` + +## Use the sprite + +Create `assets/app-icons/index.ts`: + +```ts +export * from './.svg-sprite/index.js' +``` + +The generated component is a Qwik `component$` and is safe during SSR: + +```tsx +import { component$ } from '@builder.io/qwik' +import { AppIcon } from '../assets/app-icons' + +export default component$(() => ( + +)) +``` + +The component uses a static Vite asset import and does not access browser globals during SSR. + +## Debug and preview + +Viewer is browser-only, optional development tooling: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +Load it from a visible task: + +```tsx +import { component$, useSignal, useVisibleTask$ } from '@builder.io/qwik' +import type { SpriteViewerElement } from '@gromlab/svg-sprites/viewer' + +export const IconViewer = component$(() => { + const host = useSignal() + useVisibleTask$(async () => { + await import('@gromlab/svg-sprites/viewer/element') + const viewer = document.createElement('gromlab-sprite-viewer') as SpriteViewerElement + viewer.sources = [() => import('../assets/app-icons/.svg-sprite/svg-sprite.manifest.js')] + host.value?.append(viewer) + }) + return
+}) +``` diff --git a/skills/svg-sprites/references/docs/en/guides/react-vite.md b/skills/svg-sprites/references/docs/en/guides/react-vite.md new file mode 100644 index 0000000..992ba35 --- /dev/null +++ b/skills/svg-sprites/references/docs/en/guides/react-vite.md @@ -0,0 +1,115 @@ +# SVG Sprite for React with Vite + +A quick guide to creating an SVG sprite in a React application built with Vite. + +## Generate the sprite + +Choose a directory for the future SVG sprite, for example `assets/app-icons`, and create `svg-sprite.config.json` inside it. In `input`, specify the path to existing SVG files relative to the configuration file. There is no need to move or copy the icons. + +Example configuration: + +```json +{ + "mode": "react@vite", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +The package does not need to be a project dependency: generation runs through `npx`. + +Add generation commands to `package.json`. Generated files are excluded from Git by default, so `predev` and `prebuild` rebuild the sprite before every start and build: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "predev": "npm run sprites", + "dev": "vite", + "prebuild": "npm run sprites", + "build": "tsc --noEmit && vite build" + } +} +``` + +## Use the sprite + +The value `name: "app"` creates the React component `AppIcon`. + +Create the entry point `assets/app-icons/index.ts`: + +```ts +export * from './.svg-sprite/index.js' +``` + +Use the component in your application: + +```tsx +import { AppIcon } from '../assets/app-icons' + +export function SaveIcon() { + return ( + + ) +} +``` + +The `icon` prop accepts source SVG file names without the extension. A monochrome icon inherits `color`, while colors in a multicolor icon are overridden with `--icon-color-N`. + +Vite automatically includes the component styles and adds `sprite.svg` to the production build. + +## Debug and preview + +Viewer displays all icons on one page so you can check their rendering, change colors, and inspect the related CSS variables. It is only needed for development and is installed separately: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +Create `svg-sprite.html` in the project root: + +```html + + + + + Project icons + + + +
+ + + + + +``` + +Create `src/svg-sprite-debug.tsx`: + +```tsx +import { createRoot } from 'react-dom/client' +import { SpriteViewer } from '@gromlab/svg-sprites/react' + +const sources = [ + () => import('../assets/app-icons/.svg-sprite/svg-sprite.manifest.js'), +] as const + +createRoot(document.getElementById('svg-sprite-viewer')!).render( + , +) +``` + +Run `npm run dev` and open `/svg-sprite.html`. + +The standard Vite production build uses only `index.html` and does not include the Viewer page. diff --git a/skills/svg-sprites/references/docs/en/guides/react-webpack.md b/skills/svg-sprites/references/docs/en/guides/react-webpack.md new file mode 100644 index 0000000..0b661e5 --- /dev/null +++ b/skills/svg-sprites/references/docs/en/guides/react-webpack.md @@ -0,0 +1,132 @@ +# SVG Sprite for React with Webpack 5 + +A quick guide to creating an SVG sprite in a React application built with Webpack 5. + +## Generate the sprite + +Choose a directory for the future SVG sprite, for example `assets/app-icons`, and create `svg-sprite.config.json` inside it. In `input`, specify the path to existing SVG files relative to the configuration file. There is no need to move or copy the icons. + +Example configuration: + +```json +{ + "mode": "react@webpack", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +The package does not need to be a project dependency: generation runs through `npx`. + +Add generation commands to `package.json`. Generated files are excluded from Git by default, so `predev` and `prebuild` rebuild the sprite before every start and build: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "predev": "npm run sprites", + "dev": "webpack serve --mode development", + "prebuild": "npm run sprites", + "build": "webpack --mode production" + } +} +``` + +## Use the sprite + +The value `name: "app"` creates the React component `AppIcon`. + +Create the entry point `assets/app-icons/index.ts`: + +```ts +export * from './.svg-sprite/index.js' +``` + +Use the component in your application: + +```tsx +import { AppIcon } from '../assets/app-icons' + +export function SaveIcon() { + return ( + + ) +} +``` + +The `icon` prop accepts source SVG file names without the extension. A monochrome icon inherits `color`, while colors in a multicolor icon are overridden with `--icon-color-N`. + +The component uses CSS Modules. If the project does not process them yet, install the loaders: + +```bash +npm install --save-dev style-loader css-loader +``` + +Then add a rule with a default export to `webpack.config.js`: + +```js +{ + test: /\.module\.css$/i, + use: [ + 'style-loader', + { + loader: 'css-loader', + options: { modules: { namedExport: false } }, + }, + ], +} +``` + +Webpack 5 automatically adds `sprite.svg` to the production build. + +## Debug and preview + +Viewer displays all icons on one page so you can check their rendering, change colors, and inspect the related CSS variables. It is only needed for development. + +Install Viewer: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +Create the entry `src/svg-sprite-debug.tsx`: + +```tsx +import { createRoot } from 'react-dom/client' +import { SpriteViewer } from '@gromlab/svg-sprites/react' + +const sources = [ + () => import('../assets/app-icons/.svg-sprite/svg-sprite.manifest.js'), +] as const + +const container = document.createElement('div') +document.body.append(container) + +createRoot(container).render( + , +) +``` + +Add the script to the main entry only in development mode. Keep the rest of your `webpack.config.js` settings: + +```js +export default (_env, argv) => ({ + // Other Webpack settings. + entry: [ + './src/main.tsx', + ...(argv.mode === 'development' ? ['./src/svg-sprite-debug.tsx'] : []), + ], +}) +``` + +Run `npm run dev`. Viewer appears on the application's main page and is not included in the production build. diff --git a/skills/svg-sprites/references/docs/en/guides/solid-start-vite.md b/skills/svg-sprites/references/docs/en/guides/solid-start-vite.md new file mode 100644 index 0000000..4aa283c --- /dev/null +++ b/skills/svg-sprites/references/docs/en/guides/solid-start-vite.md @@ -0,0 +1,83 @@ +# SVG Sprite for SolidStart with Vite + +A quick guide to creating an SVG sprite in an SSR SolidStart application built with Vite. + +## Generate the sprite + +Choose a directory for the future SVG sprite, for example `assets/app-icons`, and create `svg-sprite.config.json` inside it. In `input`, specify the path to existing SVG files relative to the configuration file. There is no need to move or copy the icons. + +```json +{ + "mode": "solid-start@vite", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +The package does not need to be a project dependency. Regenerate through `npx` before Vinxi starts or builds: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "predev": "npm run sprites", + "dev": "vinxi dev", + "prebuild": "npm run sprites", + "build": "vinxi build" + } +} +``` + +## Use the sprite + +Create `assets/app-icons/index.ts`: + +```ts +export * from './.svg-sprite/index.js' +``` + +The generated component is safe to render on the server: + +```tsx +import { AppIcon } from '../assets/app-icons' + +export default function Home() { + return ( + + ) +} +``` + +The component uses a static Vite asset import and does not access browser globals during SSR. + +## Debug and preview + +Viewer is browser-only, optional development tooling: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +Load it from `onMount` so it is excluded from server rendering: + +```tsx +import { onMount } from 'solid-js' +import type { SpriteViewerElement } from '@gromlab/svg-sprites/viewer' + +export function IconViewer() { + let host!: HTMLDivElement + onMount(async () => { + await import('@gromlab/svg-sprites/viewer/element') + const viewer = document.createElement('gromlab-sprite-viewer') as SpriteViewerElement + viewer.sources = [() => import('../assets/app-icons/.svg-sprite/svg-sprite.manifest.js')] + host.append(viewer) + }) + return
+} +``` diff --git a/skills/svg-sprites/references/docs/en/guides/solid-vite.md b/skills/svg-sprites/references/docs/en/guides/solid-vite.md new file mode 100644 index 0000000..fa92600 --- /dev/null +++ b/skills/svg-sprites/references/docs/en/guides/solid-vite.md @@ -0,0 +1,83 @@ +# SVG Sprite for Solid with Vite + +A quick guide to creating an SVG sprite in a Solid application built with Vite. + +## Generate the sprite + +Choose a directory for the future SVG sprite, for example `assets/app-icons`, and create `svg-sprite.config.json` inside it. In `input`, specify the path to existing SVG files relative to the configuration file. There is no need to move or copy the icons. + +```json +{ + "mode": "solid@vite", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +The package does not need to be a project dependency. Run it through `npx` and regenerate before development and production builds: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "predev": "npm run sprites", + "dev": "vite", + "prebuild": "npm run sprites", + "build": "tsc --noEmit && vite build" + } +} +``` + +## Use the sprite + +Create `assets/app-icons/index.ts`: + +```ts +export * from './.svg-sprite/index.js' +``` + +The name `app` creates the Solid component `AppIcon`: + +```tsx +import { AppIcon } from '../assets/app-icons' + +export function SaveIcon() { + return ( + + ) +} +``` + +Vite emits `sprite.svg` as a production asset. Monochrome icons inherit `color`; multicolor icons use `--icon-color-N`. + +## Debug and preview + +Viewer is optional and only needed during development: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +Mount it from a debug component after the browser is ready: + +```tsx +import { onMount } from 'solid-js' +import type { SpriteViewerElement } from '@gromlab/svg-sprites/viewer' + +export function IconViewer() { + let host!: HTMLDivElement + onMount(async () => { + await import('@gromlab/svg-sprites/viewer/element') + const viewer = document.createElement('gromlab-sprite-viewer') as SpriteViewerElement + viewer.sources = [() => import('../assets/app-icons/.svg-sprite/svg-sprite.manifest.js')] + host.append(viewer) + }) + return
+} +``` diff --git a/skills/svg-sprites/references/docs/en/guides/solid-webpack.md b/skills/svg-sprites/references/docs/en/guides/solid-webpack.md new file mode 100644 index 0000000..be6cf8a --- /dev/null +++ b/skills/svg-sprites/references/docs/en/guides/solid-webpack.md @@ -0,0 +1,75 @@ +# SVG Sprite for Solid with Webpack + +A quick guide to creating an SVG sprite in a Solid application built with Webpack 5. + +## Generate the sprite + +Choose a directory for the future SVG sprite, for example `assets/app-icons`, and create `svg-sprite.config.json` inside it. In `input`, specify the path to existing SVG files relative to the configuration file. There is no need to move or copy the icons. + +```json +{ + "mode": "solid@webpack", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +The package does not need to be a project dependency. Run it through `npx` before Webpack starts or builds: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "predev": "npm run sprites", + "dev": "webpack serve --mode development", + "prebuild": "npm run sprites", + "build": "tsc --noEmit && webpack --mode production" + } +} +``` + +## Use the sprite + +Create `assets/app-icons/index.js` and `assets/app-icons/index.d.ts` with the same export: + +```js +export * from './.svg-sprite/index.js' +``` + +Use the generated Solid component: + +```jsx +import { AppIcon } from '../assets/app-icons/index.js' + +export function SaveIcon() { + return ( + + ) +} +``` + +Webpack Asset Modules emit `sprite.svg` from the generated `new URL(...)`. Keep `.jsx` processing enabled for the generated Solid component. + +## Debug and preview + +Install Viewer only for development: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +Add it to a development-only entry: + +```js +import '@gromlab/svg-sprites/viewer/element' + +const viewer = document.createElement('gromlab-sprite-viewer') +viewer.sources = [() => import('../assets/app-icons/.svg-sprite/svg-sprite.manifest.js')] +document.body.append(viewer) +``` diff --git a/skills/svg-sprites/references/docs/en/guides/standalone-server.md b/skills/svg-sprites/references/docs/en/guides/standalone-server.md new file mode 100644 index 0000000..4cc1058 --- /dev/null +++ b/skills/svg-sprites/references/docs/en/guides/standalone-server.md @@ -0,0 +1,113 @@ +# Universal SVG Sprite Generated on a Server + +Generate a universal SVG sprite in CI or a server worker for applications that use different frameworks and bundlers. + +## Generate the sprite + +You do not need to install the package in the worker. + +### 1. Prepare the workspace + +Place the source SVGs in the current workspace's `icons` directory: + +```text +. +└── icons/ + β”œβ”€β”€ search.svg + └── settings.svg +``` + +Each filename without the extension becomes an icon name. + +### 2. Run generation + +Pass the mode, sprite name, and SVG path through the CLI: + +```bash +npx --yes @gromlab/svg-sprites \ + --mode standalone@server \ + --name app \ + --input './icons/**/*.svg' \ + . +``` + +This worker workflow does not need a config file. The result appears in `./.svg-sprite`: + +```text +. +β”œβ”€β”€ icons/ +β”‚ β”œβ”€β”€ search.svg +β”‚ └── settings.svg +└── .svg-sprite/ + β”œβ”€β”€ sprite..svg + β”œβ”€β”€ sprite-root-viewbox..svg + └── svg-sprite.manifest.json +``` + +### 3. Publish the result + +Upload the contents of `.svg-sprite` to a dedicated S3 bucket directory: + +```bash +aws s3 sync ./.svg-sprite/ s3://my-bucket/app-icons/ +``` + +The same directory can be served through a CDN. The public URL does not contain a `.svg-sprite` segment: + +```text +https://cdn.example.com/app-icons/ +β”œβ”€β”€ sprite..svg +β”œβ”€β”€ sprite-root-viewbox..svg +└── svg-sprite.manifest.json +``` + +You can also run `standalone@server` through a JSON, JavaScript, or TypeScript config. A config is useful for persistent settings, local SVGs from several directories, and SVGs loaded over HTTP(S). + +## Use the sprite + +Create a regular config in the consumer application. For example, with React and Vite: + +```text +src/app-icons/ +β”œβ”€β”€ index.ts +└── svg-sprite.config.json +``` + +Set the consumer mode and the CDN manifest URL: + +```json +{ + "mode": "react@vite", + "source": "remote", + "input": "https://cdn.example.com/app-icons/svg-sprite.manifest.json" +} +``` + +Add a user-owned entry point: + +```ts +// src/app-icons/index.ts +export * from './.svg-sprite/index.js' +``` + +Run normal generation: + +```bash +npx --yes @gromlab/svg-sprites src/app-icons/svg-sprite.config.json +``` + +Then use the generated component exactly as with a sprite built from local SVGs: + +```tsx +import { AppIcon } from './app-icons' + +export function SearchButton() { + return +} +``` + +The same CDN manifest works with all 29 consumer modes. Each one preserves the native API of its selected framework and bundler. + +## Debug and preview + +`standalone@server` does not create a separate icon preview page. Connect the published sprite to a consumer application and open it in SpriteViewer: the remote set appears in the same way as a local one. diff --git a/skills/svg-sprites/references/docs/en/guides/standalone-vite.md b/skills/svg-sprites/references/docs/en/guides/standalone-vite.md new file mode 100644 index 0000000..22dce51 --- /dev/null +++ b/skills/svg-sprites/references/docs/en/guides/standalone-vite.md @@ -0,0 +1,114 @@ +# SVG Sprite for Vite Without a Framework + +A quick guide to creating an SVG sprite in a Vite application without a framework. + +## Generate the sprite + +Choose a directory for the future SVG sprite, for example `assets/app-icons`, and create `svg-sprite.config.json` inside it. In `input`, specify the path to existing SVG files relative to the configuration file. There is no need to move or copy the icons. + +Example configuration: + +```json +{ + "mode": "standalone@vite", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +The package does not need to be a project dependency: generation runs through `npx`. + +Add generation commands to `package.json`. Generated files are excluded from Git by default, so `predev` and `prebuild` rebuild the sprite before every start and build: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "predev": "npm run sprites", + "dev": "vite", + "prebuild": "npm run sprites", + "build": "vite build" + } +} +``` + +## Use the sprite + +The value `name: "app"` creates the `` element. + +Create the entry point `assets/app-icons/index.ts`: + +```ts +export * from './.svg-sprite/index.js' +``` + +Register the element in `src/main.ts`: + +```ts +import { defineAppIconElement } from '../assets/app-icons' +import './style.css' + +defineAppIconElement() +``` + +Use the icon in HTML: + +```html + +``` + +The `icon` value is the source SVG filename without the extension. Set its size and colors with CSS: + +```css +app-icon { + font-size: 24px; + color: #334155; + --icon-color-2: #f59e0b; +} +``` + +A monochrome icon inherits `color`, while colors in a multicolor icon are overridden with `--icon-color-N`. Viewer shows the variables you need. + +Vite automatically adds `sprite.svg` to the production build. You do not need to copy it to `public`. + +## Debug and preview + +Viewer displays all icons on one page so you can check their rendering, change colors, and inspect the related CSS variables. It is only needed for development and is installed separately: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +Create `svg-sprite.html` in the project root: + +```html + + + + + Project icons + + + + + + + + + +``` + +Create `src/svg-sprite-debug.ts`: + +```ts +import '@gromlab/svg-sprites/viewer/element' +import type { SpriteViewerElement } from '@gromlab/svg-sprites/viewer' +import spriteManifest from '../assets/app-icons/.svg-sprite/svg-sprite.manifest.js' + +const viewer = document.querySelector('gromlab-sprite-viewer')! +viewer.sources = [spriteManifest] +``` + +Run `npm run dev` and open `/svg-sprite.html`. + +Viewer is not required for `` and is not imported by the application's main code. diff --git a/skills/svg-sprites/references/docs/en/guides/standalone-webpack.md b/skills/svg-sprites/references/docs/en/guides/standalone-webpack.md new file mode 100644 index 0000000..a62cbb2 --- /dev/null +++ b/skills/svg-sprites/references/docs/en/guides/standalone-webpack.md @@ -0,0 +1,111 @@ +# SVG Sprite for Webpack 5 Without a Framework + +A quick guide to creating an SVG sprite in a Webpack 5 application without a framework. + +## Generate the sprite + +Choose a directory for the future SVG sprite, for example `assets/app-icons`, and create `svg-sprite.config.json` inside it. In `input`, specify the path to existing SVG files relative to the configuration file. There is no need to move or copy the icons. + +Example configuration: + +```json +{ + "mode": "standalone@webpack", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +The package does not need to be a project dependency: generation runs through `npx`. + +Add generation commands to `package.json`. Generated files are excluded from Git by default, so `predev` and `prebuild` rebuild the sprite before every start and build: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "predev": "npm run sprites", + "dev": "webpack serve --mode development", + "prebuild": "npm run sprites", + "build": "webpack --mode production" + } +} +``` + +## Use the sprite + +The value `name: "app"` creates the `` element. + +Create the entry point `assets/app-icons/index.ts`: + +```ts +export * from './.svg-sprite/index.js' +``` + +Register the element in the application's main entry: + +```ts +import { defineAppIconElement } from '../assets/app-icons' +import './style.css' + +defineAppIconElement() +``` + +Use the icon in HTML: + +```html + +``` + +The `icon` value is the source SVG filename without the extension. Set its size and colors with CSS: + +```css +app-icon { + font-size: 24px; + color: #334155; + --icon-color-2: #f59e0b; +} +``` + +A monochrome icon inherits `color`, while colors in a multicolor icon are overridden with `--icon-color-N`. Viewer shows the variables you need. + +Webpack 5 automatically adds `sprite.svg` to the production build. + +## Debug and preview + +Viewer displays all icons on one page so you can check their rendering, change colors, and inspect the related CSS variables. It is only needed for development. + +Install Viewer: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +Create the entry `src/svg-sprite-debug.ts`: + +```ts +import '@gromlab/svg-sprites/viewer/element' +import type { SpriteViewerElement } from '@gromlab/svg-sprites/viewer' +import spriteManifest from '../assets/app-icons/.svg-sprite/svg-sprite.manifest.js' + +const viewer = document.createElement('gromlab-sprite-viewer') as SpriteViewerElement +viewer.viewerTitle = 'Project icons' +viewer.sources = [spriteManifest] +document.body.append(viewer) +``` + +Add the script to the main entry only in development mode. Keep the rest of your `webpack.config.js` settings: + +```js +export default (_env, argv) => ({ + // Other Webpack settings. + entry: [ + './src/main.ts', + ...(argv.mode === 'development' ? ['./src/svg-sprite-debug.ts'] : []), + ], +}) +``` + +Run `npm run dev`. Viewer appears on the application's main page. + +Viewer is only added to the development build and is not included in production. diff --git a/skills/svg-sprites/references/docs/en/guides/standalone.md b/skills/svg-sprites/references/docs/en/guides/standalone.md new file mode 100644 index 0000000..c06b9bc --- /dev/null +++ b/skills/svg-sprites/references/docs/en/guides/standalone.md @@ -0,0 +1,83 @@ +# SVG Sprite for a Site Without a Bundler + +Combine SVG icons into one file and use them on an HTML page. + +## Generate the sprite + +You do not need to install the package in your project. + +### 1. Create the sprite config + +Choose a directory for the future SVG sprite, for example `assets/app-icons`, and create `svg-sprite.config.json` inside it. In `input`, specify the path to existing SVG files relative to the configuration file. There is no need to move or copy the icons. + +```json +{ + "mode": "standalone", + "name": "icons", + "input": "../svg-icons/**/*.svg" +} +``` + +### 2. Generate the sprite + +Pass the config path to the command: + +```bash +npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json +``` + +The package collects the icons in a `.svg-sprite` directory next to the config: + +```text +assets/app-icons/.svg-sprite/ +β”œβ”€β”€ sprite.svg +└── svg-sprite.manifest.json +``` + +- `sprite.svg` is the finished sprite for use on the site. +- `svg-sprite.manifest.json` contains icon data for Viewer. + +The `.svg-sprite` directory is created automatically and fully replaced on every generation. Do not edit its contents manually. + +### 3. Use an icon + +In `index.html`, point to the generated `sprite.svg`. After `#`, add the icon file name without the `.svg` extension: + +```html + + + +``` + +## Debug and preview + +`sprite.svg` is a technical file, not an icon gallery. Opening it does not provide a convenient view of the whole set. Gradients, masks, filters, and references to internal `id` values may also render with artifacts. + +Use the official Viewer for visual checks. It displays every icon in the sprite and helps you verify its colors and rendering. + +Viewer is optional and intended only for development. You do not need to install the package through npm. + +Viewer works directly with files from `.svg-sprite`. Nothing needs to be copied. + +### Add Viewer to the page + +Add a module script to `index.html` and provide paths to the generated manifest and sprite: + +```html + + + +``` + +You can move Viewer to a separate HTML file in the site root used only for development and icon checks. diff --git a/skills/svg-sprites/references/docs/en/guides/svelte-vite.md b/skills/svg-sprites/references/docs/en/guides/svelte-vite.md new file mode 100644 index 0000000..1e43901 --- /dev/null +++ b/skills/svg-sprites/references/docs/en/guides/svelte-vite.md @@ -0,0 +1,95 @@ +# SVG Sprite for Svelte with Vite + +A quick guide to creating an SVG sprite in a Svelte application built with Vite. + +## Generate the sprite + +Choose a directory for the future SVG sprite, for example `assets/app-icons`, and create `svg-sprite.config.json` inside it. In `input`, specify the path to existing SVG files relative to the configuration file. There is no need to move or copy the icons. + +Example configuration: + +```json +{ + "mode": "svelte@vite", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +The package does not need to be a project dependency: generation runs through `npx`. + +Add generation commands to `package.json`. Generated files are excluded from Git by default, so `predev` and `prebuild` rebuild the sprite before every start and build: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "predev": "npm run sprites", + "dev": "vite", + "prebuild": "npm run sprites", + "build": "vite build" + } +} +``` + +## Use the sprite + +The value `name: "app"` creates the Svelte component `AppIcon`. + +Create `assets/app-icons/index.js`: + +```js +export * from './.svg-sprite/index.js' +``` + +Use the component in your application: + +```svelte + + + +``` + +The `icon` prop accepts source SVG file names without the extension. A monochrome icon inherits `color`, while colors in a multicolor icon are overridden with `--icon-color-N`. + +Vite automatically includes the component styles and emits `sprite.svg` as a separate production asset. + +## Debug and preview + +Viewer displays all icons on one page so you can check their rendering, change colors, and inspect the related CSS variables. It is only needed for development and is installed separately: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +Add Viewer to a development-only Svelte page or component: + +```svelte + + + +``` + +Run `npm run dev` and open the page containing Viewer. Do not import this development component from the production entry. diff --git a/skills/svg-sprites/references/docs/en/guides/svelte-webpack.md b/skills/svg-sprites/references/docs/en/guides/svelte-webpack.md new file mode 100644 index 0000000..13a859b --- /dev/null +++ b/skills/svg-sprites/references/docs/en/guides/svelte-webpack.md @@ -0,0 +1,105 @@ +# SVG Sprite for Svelte with Webpack 5 + +A quick guide to creating an SVG sprite in a Svelte application built with Webpack 5. + +## Generate the sprite + +Choose a directory for the future SVG sprite, for example `assets/app-icons`, and create `svg-sprite.config.json` inside it. In `input`, specify the path to existing SVG files relative to the configuration file. There is no need to move or copy the icons. + +Example configuration: + +```json +{ + "mode": "svelte@webpack", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +The package does not need to be a project dependency: generation runs through `npx`. + +Add generation commands to `package.json`: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "predev": "npm run sprites", + "dev": "webpack serve --mode development", + "prebuild": "npm run sprites", + "build": "webpack --mode production" + } +} +``` + +## Use the sprite + +The value `name: "app"` creates the Svelte component `AppIcon`. + +Create `assets/app-icons/index.js`: + +```js +export * from './.svg-sprite/index.js' +``` + +Use the component in your application: + +```svelte + + + +``` + +The generated component is a native `.svelte` file. The normal `svelte-loader` rule must include `.svelte` files under `assets`: + +```js +{ + test: /\.svelte$/, + use: { + loader: 'svelte-loader', + options: { emitCss: false }, + }, +} +``` + +Webpack 5 processes the component's asset URL and emits `sprite.svg` as a separate production asset. + +## Debug and preview + +Viewer displays all icons on one page so you can check their rendering, change colors, and inspect the related CSS variables. It is only needed for development and is installed separately: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +Add Viewer to a development-only Svelte component: + +```svelte + + + +``` + +Run `npm run dev` and open the page containing Viewer. Do not import this development component from the production entry. diff --git a/skills/svg-sprites/references/docs/en/guides/sveltekit-vite.md b/skills/svg-sprites/references/docs/en/guides/sveltekit-vite.md new file mode 100644 index 0000000..b0efe44 --- /dev/null +++ b/skills/svg-sprites/references/docs/en/guides/sveltekit-vite.md @@ -0,0 +1,91 @@ +# SVG Sprite for SvelteKit with Vite + +A quick guide to creating an SVG sprite in a SvelteKit application built with Vite. + +## Generate the sprite + +Choose a directory for the future SVG sprite, for example `assets/app-icons`, and create `svg-sprite.config.json` inside it. In `input`, specify the path to existing SVG files relative to the configuration file. There is no need to move or copy the icons. + +Example configuration: + +```json +{ + "mode": "sveltekit@vite", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +The package does not need to be a project dependency: generation runs through `npx`. + +Add generation commands to `package.json`. Generated files are excluded from Git by default, so `predev` and `prebuild` rebuild the sprite before every start and build: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "predev": "npm run sprites", + "dev": "vite dev", + "prebuild": "npm run sprites", + "build": "vite build" + } +} +``` + +## Use the sprite + +The value `name: "app"` creates the SSR-safe Svelte component `AppIcon`. + +Create `assets/app-icons/index.js`: + +```js +export * from './.svg-sprite/index.js' +``` + +Use the component in `src/routes/+page.svelte`: + +```svelte + + + +``` + +The `icon` prop accepts source SVG file names without the extension. The component has no browser-only initialization, so the page can be rendered on the server. Vite emits `sprite.svg` as a separate production asset. + +## Debug and preview + +Viewer displays all icons on one page so you can check their rendering, change colors, and inspect the related CSS variables. It is only needed for development and is installed separately: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +Create a development route such as `src/routes/svg-sprite/+page.svelte`. Load the custom element from an action so it is only registered in the browser: + +```svelte + + + +``` + +Run `npm run dev` and open `/svg-sprite`. The action does not run during SSR. diff --git a/skills/svg-sprites/references/docs/en/guides/vue-vite.md b/skills/svg-sprites/references/docs/en/guides/vue-vite.md new file mode 100644 index 0000000..152f14b --- /dev/null +++ b/skills/svg-sprites/references/docs/en/guides/vue-vite.md @@ -0,0 +1,105 @@ +# SVG Sprite for Vue with Vite + +A quick guide to creating an SVG sprite in a Vue application built with Vite. + +## Generate the sprite + +Choose a directory for the future SVG sprite, for example `assets/app-icons`, and create `svg-sprite.config.json` inside it. In `input`, specify the path to existing SVG files relative to the configuration file. There is no need to move or copy the icons. + +Example configuration: + +```json +{ + "mode": "vue@vite", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +The package does not need to be a project dependency: generation runs through `npx`. + +Add generation commands to `package.json`. Generated files are excluded from Git by default, so `predev` and `prebuild` rebuild the sprite before every start and build: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "predev": "npm run sprites", + "dev": "vite", + "prebuild": "npm run sprites", + "build": "vue-tsc --noEmit && vite build" + } +} +``` + +## Use the sprite + +The value `name: "app"` creates the Vue component `AppIcon`. + +Create the entry point `assets/app-icons/index.ts`: + +```ts +export * from './.svg-sprite/index.js' +``` + +Use the component in your application: + +```vue + + + +``` + +The `icon` prop accepts source SVG file names without the extension. A monochrome icon inherits `color`, while colors in a multicolor icon are overridden with `--icon-color-N`. + +Vite automatically includes the component styles and adds `sprite.svg` to the production build. + +## Debug and preview + +Viewer displays all icons on one page so you can check their rendering, change colors, and inspect the related CSS variables. It is only needed for development and is installed separately: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +Create `svg-sprite.html` in the project root: + +```html + + + + + Project icons + + + + + + +``` + +Create `src/svg-sprite-debug.ts`: + +```ts +import '@gromlab/svg-sprites/viewer/element' +import type { SpriteViewerElement } from '@gromlab/svg-sprites/viewer' +import spriteManifest from '../assets/app-icons/.svg-sprite/svg-sprite.manifest.js' + +const viewer = document.querySelector('gromlab-sprite-viewer')! +viewer.sources = [spriteManifest] +``` + +Run `npm run dev` and open `/svg-sprite.html`. + +Viewer is not required by `AppIcon` and is not loaded by the main application code. diff --git a/skills/svg-sprites/references/docs/en/guides/vue-webpack.md b/skills/svg-sprites/references/docs/en/guides/vue-webpack.md new file mode 100644 index 0000000..d37667e --- /dev/null +++ b/skills/svg-sprites/references/docs/en/guides/vue-webpack.md @@ -0,0 +1,126 @@ +# SVG Sprite for Vue with Webpack 5 + +A quick guide to creating an SVG sprite in a Vue application built with Webpack 5. + +## Generate the sprite + +Choose a directory for the future SVG sprite, for example `assets/app-icons`, and create `svg-sprite.config.json` inside it. In `input`, specify the path to existing SVG files relative to the configuration file. There is no need to move or copy the icons. + +Example configuration: + +```json +{ + "mode": "vue@webpack", + "name": "app", + "input": "../svg-icons/**/*.svg" +} +``` + +The package does not need to be a project dependency: generation runs through `npx`. + +Add generation commands to `package.json`. Generated files are excluded from Git by default, so `predev` and `prebuild` rebuild the sprite before every start and build: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites assets/app-icons/svg-sprite.config.json", + "predev": "npm run sprites", + "dev": "webpack serve --mode development", + "prebuild": "npm run sprites", + "build": "webpack --mode production" + } +} +``` + +## Use the sprite + +The value `name: "app"` creates the Vue component `AppIcon`. Create `assets/app-icons/index.js`: + +```js +export * from './.svg-sprite/index.js' +``` + +Use the component in your application: + +```vue + + + +``` + +The `icon` prop accepts source SVG file names without the extension. A monochrome icon inherits `color`, while colors in a multicolor icon are overridden with `--icon-color-N`. + +The component uses CSS Modules. If the project does not process them yet, install `style-loader` and `css-loader`, then add a rule with a default export: + +```bash +npm install --save-dev style-loader css-loader +``` + +```js +{ + test: /\.module\.css$/i, + use: [ + 'style-loader', + { + loader: 'css-loader', + options: { modules: { namedExport: false } }, + }, + ], +} +``` + +Webpack 5 automatically adds `sprite.svg` to the production build. + +## Debug and preview + +Viewer displays all icons on one page so you can check their rendering, change colors, and inspect the related CSS variables. It is only needed for development and is installed separately: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +Add Viewer to a development-only Vue component: + +```vue + + + +``` + +Configure Vue Loader to treat `gromlab-sprite-viewer` as a custom element: + +```js +{ + test: /\.vue$/, + loader: 'vue-loader', + options: { + compilerOptions: { + isCustomElement: (tag) => tag === 'gromlab-sprite-viewer', + }, + }, +} +``` + +Render the Viewer component on your development page. Viewer is not required by `AppIcon`. diff --git a/skills/svg-sprites/references/docs/en/reference/programmatic-api.md b/skills/svg-sprites/references/docs/en/reference/programmatic-api.md new file mode 100644 index 0000000..14c1f52 --- /dev/null +++ b/skills/svg-sprites/references/docs/en/reference/programmatic-api.md @@ -0,0 +1,191 @@ +# Programmatic API + +[Documentation index](../README.md) + +The package is ESM-only and provides one Node.js generation API. The framework-neutral Viewer is available from `@gromlab/svg-sprites/viewer`, its auto-register entry from `@gromlab/svg-sprites/viewer/element`, and the React bridge from `@gromlab/svg-sprites/react`. + +## `generateSprite` + +```ts +import { generateSprite } from '@gromlab/svg-sprites' + +const result = await generateSprite( + 'src/ui/file-manager/svg-sprite/svg-sprite.config.ts', +) +``` + +The result contains the sprite name, exact mode, mode-specific asset target, icon count, and absolute filesystem paths: + +```ts +result.name +result.mode +result.target +result.iconCount +result.rootDir +result.generatedDir +result.spritePath +result.manifestPath +``` + +Next.js modes additionally return `router` and `bundler`. +For bare `standalone`, `target` is `static`; standalone bundler and React modes +return `vite` or `webpack`; Next.js modes return their full exact mode as the +target. `standalone@server` returns `server`; its `spritePath` identifies the +standard content-addressed profile and `manifestPath` identifies the server manifest. + +For static standalone mode, use `result.spritePath` in a build script to publish the +SVG under an application URL: + +```ts +import { copyFile } from 'node:fs/promises' + +const result = await generateSprite('src/sprite/svg-sprite.config.ts', { + mode: 'standalone', +}) +await copyFile(result.spritePath, 'dist/app-icons/sprite.svg') +``` + +`spritePath` is a filesystem path, not a browser URL. A deployment-neutral JSON +manifest is available through `result.manifestPath` and is copied independently. + +The first argument accepts an absolute or relative path to an explicitly selected `.ts`, `.js`, or `.json` config file with any name. Passing a directory enables config-less mode and uses that directory as the sprite module root. + +The second argument contains optional overrides and always takes precedence over the config: + +```ts +await generateSprite('src/ui/file-manager/svg-sprite/custom-config.json', { + mode: 'react@webpack', + name: 'documents', + input: ['./assets', '../../shared/search.svg'], + transform: { + addTransition: false, + }, + generatedNotice: false, +}) +``` + +Configuration is resolved in this order: + +```text +defaults β†’ config β†’ API overrides +``` + +For fully programmatic generation, pass a directory and provide the required `mode` and any other settings as overrides. `name` is optional: when omitted, it is inferred in kebab-case from the directory name, or from the parent directory when the module directory is named `svg-sprite` or `svg-sprites`: + +```ts +await generateSprite('src/ui/file-manager/svg-sprite', { + mode: 'react@vite', + name: 'file-manager', + input: [ + '../../shared/search.svg', + '../../shared/settings.svg', + ], +}) +``` + +## Configuration + +```ts +import { defineSpriteConfig } from '@gromlab/svg-sprites' + +export default defineSpriteConfig({ + mode: 'react@vite', + name: 'file-manager', + description: 'File manager icons', + input: ['./icons', '../../shared/check.svg'], + transform: { + removeSize: true, + replaceColors: true, + addTransition: true, + }, + generatedNotice: true, +}) +``` + +`input` accepts one folder, SVG file, or glob pattern, or an array that combines them. When omitted, it defaults to `./icons`; relative paths start at the config directory. + +`defineSpriteConfig` is an identity helper for TypeScript autocomplete. JavaScript can export the same object with `export default`, while JSON contains the object directly. + +The public `ServerSvgInput`, `ServerSpriteManifest`, `ServerSpriteAsset`, and +`SpriteCompileProfile` types describe `standalone@server` inputs and release data. +A consumer uses the same API with `source: 'remote'` and one local path or HTTP(S) +manifest URL in `input`. + +## Specialized wrappers + +The specialized functions are available as wrappers around `generateSprite`: + +```ts +import { generateNextSprite, generateReactSprite } from '@gromlab/svg-sprites' + +await generateReactSprite('path/to/config.ts', 'vite') +await generateNextSprite('path/to/config.ts', { + router: 'app', + bundler: 'turbopack', +}) +``` + +An explicitly supplied target overrides `mode` from the file. Prefer `generateSprite` in new code. + +## Config API + +```ts +import { + isSpriteMode, + loadSpriteConfig, + resolveSpriteConfig, + resolveSpriteConfigSource, + validateSpriteConfig, +} from '@gromlab/svg-sprites' +``` + +- `isSpriteMode(value)` checks whether a value is a supported exact mode. +- `loadSpriteConfig(file)` loads an explicitly selected `.ts`, `.js`, or `.json` file. +- `resolveSpriteConfigSource(source)` resolves a path as either a config file or a config-less directory. +- `validateSpriteConfig(value)` performs runtime validation. +- `resolveSpriteConfig(root, config, overrides)` merges values, applies defaults, and resolves paths relative to `root`. + +## Low-level compiler + +```ts +import { + compileSprite, + compileSpriteContent, + createShapeTransform, +} from '@gromlab/svg-sprites' +``` + +These functions are intended for custom orchestration. Standard generation should use `generateSprite`. + +## Viewer runtime + +```ts +import '@gromlab/svg-sprites/viewer/element' +import type { SpriteViewerElement } from '@gromlab/svg-sprites/viewer' +``` + +The browser entry registers ``. Bare standalone can also load the self-contained `dist/viewer-element.js` without a bundler. + +For manual registration, import the runtime without the auto-register entry: + +```ts +import { defineSpriteViewerElement } from '@gromlab/svg-sprites/viewer' + +defineSpriteViewerElement() +``` + +Both Viewer entries export the registration function and the same public types: +`SpriteViewerColorTheme`, `SpriteViewerElement`, `SpriteViewerManifest`, +`SpriteViewerManifestColor`, `SpriteViewerManifestIcon`, +`SpriteViewerManifestLoader`, `SpriteViewerManifestModule`, +`SpriteViewerManifestUsage`, `SpriteViewerRemoteSource`, `SpriteViewerSource`, +and `SpriteViewerSources`. Only `@gromlab/svg-sprites/viewer/element` registers the +element as an import side effect. + +The React bridge keeps the component API: + +```tsx +import { SpriteViewer } from '@gromlab/svg-sprites/react' +``` + +`SpriteViewer` accepts generated manifests, remote standalone sources, lazy loaders, or an `import.meta.glob` result. The React entry contains `'use client'` and is intended for debug tools; production components are imported from local sprite modules. diff --git a/skills/svg-sprites/references/docs/en/reference/technical.md b/skills/svg-sprites/references/docs/en/reference/technical.md new file mode 100644 index 0000000..08c8e48 --- /dev/null +++ b/skills/svg-sprites/references/docs/en/reference/technical.md @@ -0,0 +1,717 @@ +# Technical reference + +[Documentation index](../README.md) + +[JSON, JavaScript, and TypeScript configuration](../configuration.md) + +Reference for the configuration, generated API, and behavior of `@gromlab/svg-sprites`. For step-by-step setup instructions, see the guide for your stack: + +- [Bare standalone](../guides/standalone.md) +- [Standalone + Vite](../guides/standalone-vite.md) +- [Standalone + Webpack 5](../guides/standalone-webpack.md) +- [React + Vite](../guides/react-vite.md) +- [React + Webpack 5](../guides/react-webpack.md) +- [Next.js App Router + Turbopack](../guides/next-app-turbopack.md) +- [Next.js App Router + Webpack](../guides/next-app-webpack.md) +- [Next.js Pages Router + Turbopack](../guides/next-pages-turbopack.md) +- [Next.js Pages Router + Webpack](../guides/next-pages-webpack.md) +- [Vue + Vite](../guides/vue-vite.md) +- [Vue + Webpack](../guides/vue-webpack.md) +- [Nuxt + Vite](../guides/nuxt-vite.md) +- [Nuxt + Webpack](../guides/nuxt-webpack.md) +- [Svelte + Vite](../guides/svelte-vite.md) +- [Svelte + Webpack](../guides/svelte-webpack.md) +- [SvelteKit + Vite](../guides/sveltekit-vite.md) +- [Angular application builder](../guides/angular-application.md) +- [Angular + Webpack](../guides/angular-webpack.md) +- [Astro + Vite](../guides/astro-vite.md) +- [Solid + Vite](../guides/solid-vite.md) +- [Solid + Webpack](../guides/solid-webpack.md) +- [SolidStart + Vite](../guides/solid-start-vite.md) +- [Preact + Vite](../guides/preact-vite.md) +- [Preact + Webpack](../guides/preact-webpack.md) +- [Qwik + Vite](../guides/qwik-vite.md) +- [Lit + Vite](../guides/lit-vite.md) +- [Lit + Webpack](../guides/lit-webpack.md) +- [Alpine.js + Vite](../guides/alpine-vite.md) +- [Alpine.js + Webpack](../guides/alpine-webpack.md) + +## Requirements + +- Node.js 18 or newer; +- the package is distributed as ESM and is loaded with `import`; +- React 18 or 19 is required only for React/Next generated components and `@gromlab/svg-sprites/react`; +- for typed package exports, use TypeScript 5+ with `moduleResolution: "bundler"`, `"node16"`, or `"nodenext"`. + +Generation does not require a project dependency. Run the CLI through `npx`: + +```bash +npx --yes @gromlab/svg-sprites path/to/svg-sprite.config.json +``` + +Install the package as a development dependency only when the project needs the +Viewer, config types, or the programmatic API: + +```bash +npm install --save-dev @gromlab/svg-sprites +``` + +## CLI and generation modes + +The CLI accepts exactly one path: an explicitly selected config file or a directory for config-less generation: + +```text +svg-sprites [options] +``` + +| Environment | Mode | +|---|---| +| Static HTML / custom publishing | `standalone` | +| Standalone + Vite | `standalone@vite` | +| Standalone + Webpack 5 | `standalone@webpack` | +| Server release | `standalone@server` | +| React + Vite | `react@vite` | +| React + Webpack 5 | `react@webpack` | +| Vue + Vite | `vue@vite` | +| Vue + Webpack | `vue@webpack` | +| Nuxt + Vite | `nuxt@vite` | +| Nuxt + Webpack | `nuxt@webpack` | +| Svelte + Vite | `svelte@vite` | +| Svelte + Webpack | `svelte@webpack` | +| SvelteKit + Vite | `sveltekit@vite` | +| Angular application builder | `angular@application` | +| Angular + Webpack | `angular@webpack` | +| Astro + Vite | `astro@vite` | +| Solid + Vite | `solid@vite` | +| Solid + Webpack | `solid@webpack` | +| SolidStart + Vite | `solid-start@vite` | +| Preact + Vite | `preact@vite` | +| Preact + Webpack | `preact@webpack` | +| Qwik + Vite | `qwik@vite` | +| Lit + Vite | `lit@vite` | +| Lit + Webpack | `lit@webpack` | +| Alpine.js + Vite | `alpine@vite` | +| Alpine.js + Webpack | `alpine@webpack` | +| Next.js App Router + Turbopack | `next@app/turbopack` | +| Next.js App Router + Webpack 5 | `next@app/webpack` | +| Next.js Pages Router + Turbopack | `next@pages/turbopack` | +| Next.js Pages Router + Webpack 5 | `next@pages/webpack` | + +The config file may have any name and use the `.ts`, `.js`, or `.json` extension. The CLI does not discover it by convention: pass the file explicitly. The recommended name is `svg-sprite.config.json`. + +When a directory is passed, all settings come from CLI options. When a config file is passed, CLI options override the file. The full order is `defaults β†’ config β†’ CLI`. + +`--help` and `-h` print usage information without requiring a path. Generation options are `--mode`, `--source `, `--name`, `--description`, repeatable `--input `, plus the `--remove-size`/`--no-remove-size`, `--replace-colors`/`--no-replace-colors`, `--add-transition`/`--no-add-transition`, and `--generated-notice`/`--no-generated-notice` pairs. Transform flags override individual fields, while supplying at least one `--input` replaces the complete config `input` value. + +Quote CLI glob patterns with single quotes so the shell does not expand them before the generator receives them: + +```bash +svg-sprites --input './icons/**/*.svg' --input '!./icons/legacy/**' svg-sprite.config.ts +``` + +The mode must match the application's publishing strategy. Bare `standalone` leaves the public URL to the application; Vite and Webpack modes generate bundler-specific SVG asset integration. + +## Unified configuration + +Each config file defines one independent sprite. + +```ts +import { defineSpriteConfig } from '@gromlab/svg-sprites' + +export default defineSpriteConfig({ + mode: 'next@app/turbopack', + name: 'app', + description: 'Shared application icons', + input: [ + './local-icons', + '../../assets/icons/*.svg', + '!../../assets/icons/deprecated-*.svg', + ], + transform: { + removeSize: true, + replaceColors: true, + addTransition: true, + }, + generatedNotice: true, +}) +``` + +| Option | Type | Default | Purpose | +|---|---|---|---| +| `mode` | `SpriteMode` | None | Generation mode; may be supplied by CLI/API | +| `source` | `local \| remote` | `local` | Source SVG files or a ready server manifest | +| `name` | `string` | Derived from the directory | Sprite name; in modes with a component, it also determines the component and public type names | +| `description` | `string` | None | Description for types and the debug manifest | +| `input` | `SpriteInput \| SpriteInput[]` | `./icons` | Local SVG sources, server HTTP descriptors, or one remote manifest, depending on mode and source | +| `transform` | `TransformOptions` | All enabled | SVG preparation settings | +| `generatedNotice` | `boolean` | `true` | Full or abbreviated warning in generated files | + +With `source: 'remote'`, `input` contains one local path or HTTP(S) URL to a +manifest produced by `standalone@server`. A remote consumer config may contain +only `mode`, `source`, and `input`: the name, description, transforms, and generated +notice are verified and inherited from the server manifest. Generation downloads +the profile required by the exact consumer mode and verifies its SHA-256 and byte +length before codegen. There is no runtime network dependency on the server manifest. + +### Sprite name + +`name` is written in kebab-case and must start with an ASCII letter: + +```text +app β†’ AppIcon +file-manager β†’ FileManagerIcon +``` + +If `name` is omitted, the generator converts the directory name to kebab-case. For a directory named `svg-sprite` or `svg-sprites`, the parent directory's name is used. + +### Icon sources + +`SpriteConfig.input` is optional and has the type `string | string[]`. When it is omitted, the source is the literal `./icons` folder relative to the config directory. In config-less mode, relative paths start at the directory passed to the CLI or API. + +Each positive string may be a literal folder, a literal `.svg` file, or a glob pattern. A literal folder includes only its immediate `*.svg` children. Use an explicit pattern such as `icons/**/*.svg` to traverse nested directories. + +An array combines all positive sources. A pattern prefixed with `!` excludes its matches from the combined result globally, regardless of which positive source included them. + +Supported glob syntax includes: + +| Syntax | Meaning | +|---|---| +| `*` | Any characters within one path segment | +| `**` | Any number of nested directories | +| `?` | One character within a path segment | +| `{a,b}` | Either alternative | +| `[abc]` | One character from the set or range | +| `!pattern` | Exclude matches from the full combined input | + +Every positive source or pattern must find at least one SVG, otherwise generation fails. Duplicate paths are removed and the final file list is sorted deterministically. Different SVG files with the same basename remain a conflict because the basename defines the public icon name. + +### Server SVG inputs + +`standalone@server` accepts the same local strings plus HTTP(S) descriptors in its +`input` array: + +```ts +{ + name: 'brand-logo', + url: 'https://assets.example.com/brand-logo.svg', + sha256: '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef', +} +``` + +`name` becomes the public icon name. `sha256` is optional and, when present, is +checked against the downloaded bytes. URL credentials and active SVG content such +as scripts, event handlers, `foreignObject`, or a doctype are rejected. One HTTP +source is limited to 2 MiB, all combined sources to 25 MiB, and requests time out +after 15 seconds. Local and HTTP entries share one namespace, so duplicate icon +names fail generation. + +## Generated module + +After generation, a React or Next.js sprite directory looks like this: + +```text +app-icons/ +β”œβ”€β”€ .gitignore +β”œβ”€β”€ svg-sprite.config.json +β”œβ”€β”€ index.ts # optional user-owned barrel +└── .svg-sprite/ + β”œβ”€β”€ index.js + β”œβ”€β”€ index.d.ts + β”œβ”€β”€ icon-data.js + β”œβ”€β”€ icon-data.d.ts + β”œβ”€β”€ sprite.svg + β”œβ”€β”€ svg-sprite.manifest.js + β”œβ”€β”€ svg-sprite.manifest.d.ts + └── react/ + β”œβ”€β”€ react-component.js + β”œβ”€β”€ react-component.d.ts + └── react-component.module.css +``` + +| File | Purpose | +|---|---| +| `.svg-sprite/index.js` | Mode-specific production facade and runtime icon-name list | +| `.svg-sprite/index.d.ts` | Public declarations for the facade, component, and icon-name union | +| `.svg-sprite/svg-sprite.manifest.js` | Debug metadata and the asset URL for `SpriteViewer` | +| `.svg-sprite/sprite.svg` | Compiled SVG sprite | +| `.svg-sprite/react/react-component.js` | React component runtime without TypeScript or JSX | +| `.svg-sprite/react/react-component.d.ts` | React component props, style, and declaration | +| `.svg-sprite/react/react-component.module.css` | Styles for the React implementation | +| `.svg-sprite/icon-data.js` | Runtime icon-name list and internal IDs | +| `.svg-sprite/*.d.ts` | TypeScript declarations for the corresponding JavaScript modules | + +Standalone contracts do not create `react/`. Bare `standalone` contains only the +runtime asset and deployment-neutral manifest data: + +```text +.svg-sprite/ +β”œβ”€β”€ sprite.svg +└── svg-sprite.manifest.json +``` + +`standalone@vite` and `standalone@webpack` additionally create `index.*`, +`icon-data.*`, and a resolved `svg-sprite.manifest.*`. Their facade contains a +native generated Web Component with no external runtime dependencies. Bare +`standalone` intentionally does not generate a JavaScript component. + +`standalone@server` creates a publishable release without JavaScript runtime or +`.gitignore`: + +```text +.svg-sprite/ +β”œβ”€β”€ sprite..svg +β”œβ”€β”€ sprite-root-viewbox..svg +└── svg-sprite.manifest.json +``` + +The manifest identifies both compile profiles by relative `href`, full SHA-256, +and byte length. Publish the complete directory atomically; consumers resolve each +profile relative to the manifest URL or local manifest path. + +The generator fully manages `.svg-sprite` and replaces the whole directory on every generation through a staged write with rollback on replacement failure. Any files added inside it are deleted during the next generation. Keep user-owned files alongside it, for example in a root `index.ts` barrel: + +```ts +export * from './.svg-sprite/index.js' +``` + +## Standalone Web Component and TypeScript + +In `standalone@vite` and `standalone@webpack`, a sprite with `name: 'app'` +exports the `defineAppIconElement()` registration function and the `` +tag: + +```ts +import { defineAppIconElement } from '@/ui/app-icons' + +defineAppIconElement() +``` + +After registration, use the element in HTML: + +```html + + + +``` + +The component renders `` in an open Shadow DOM, selects the internal +ID and `viewBox`, and obtains the asset URL through the corresponding Vite or +Webpack mechanism. The host defaults to `1em Γ— 1em`; set `class`, `style`, +`color`, and `--icon-color-N` with ordinary CSS. + +The generated `HTMLElementTagNameMap` types the property API: + +```ts +const icon = document.createElement('app-icon') + +icon.icon = 'search' +icon.icon = 'unknown' // TypeScript error +``` + +TypeScript does not validate attribute values in plain HTML. Therefore an +unknown `icon="unknown"` is also validated at runtime: the component hides its +inner SVG and reports an error instead of creating a `#undefined` fragment. +Calling `defineAppIconElement()` repeatedly is safe for the same sprite; a +different element already registered as `` causes an error. + +## React component and TypeScript + +A sprite with `name: 'app'` exports: + +```ts +export { AppIcon, appIconNames } +export type { AppIconName, AppIconProps, AppIconStyle } +``` + +### Icon names + +SVG file names become valid `icon` values: + +```tsx + + // TypeScript error +``` + +The runtime list contains the same values: + +```ts +import { appIconNames } from '@/ui/app-icons' + +// readonly ['search', 'settings', 'user'] +``` + +Names containing spaces or other characters that are unsafe in SVG IDs remain part of the public API. For the internal fragment ID, the generator creates a stable, safe hash: + +```text +folder open.svg β†’ icon="folder open" β†’ id="icon-" +``` + +For these names, use the generated component or the `id` from the debug manifest instead of constructing the fragment ID manually. + +### SVG attributes + +By default, the component renders an `` and accepts standard SVG attributes: + +```tsx + +``` + +The component does not add accessibility semantics automatically. Pass appropriate `aria-*` attributes, a `role`, or a label based on the icon's purpose. + +### Wrapper + +`wrapped` renders a `` containing the SVG. In this mode, the remaining props apply to the ``: + +```tsx + +``` + +### Typed CSS custom properties + +`AppIconStyle` extends `CSSProperties` and supports properties in the form `--icon-color-N`: + +```tsx + +``` + +## Multiple sprites + +Each directory with a configuration creates an independent mode-specific contract. Framework modes generate their native component and declarations, standalone bundler modes generate a Web Component and declarations, and bare `standalone` generates an SVG and JSON manifest: + +```text +app-icons β†’ AppIcon β†’ shared icons +analytics-icons β†’ AnalyticsIcon β†’ analytics page icons +editor-icons β†’ EditorIcon β†’ editor icons +``` + +The same source SVG can be added to multiple configurations through `input`. You do not need to copy the file into each sprite directory. + +For multiple sprites, add a separate CLI command for each directory or combine the commands in a shared npm script. + +## Formats and rendering methods + +All current modes generate the `stack` format. + +| Format | `` | `` | CSS background | +|---|---:|---:|---:| +| `stack` | Yes | Yes | Yes | + +### Generated component + +Use the generated native component documented by the selected exact-mode guide. It knows the internal IDs, constructs the URL, and provides a TypeScript API. React and Next.js use it like this: + +```tsx + +``` + +For `standalone@vite` and `standalone@webpack`, use the generated Web Component: + +```html + +``` + +### Manually with `` + +How you obtain `spriteUrl` depends on the bundler. + +Static HTML after the application publishes `.svg-sprite/sprite.svg`: + +```html + +``` + +Standalone Vite/Webpack provides generated `getAppIconHref()` and an internal ID +map. Do not construct fragments from unsafe file names manually. + +Vite: + +```ts +import spriteUrl from './.svg-sprite/sprite.svg?no-inline' +``` + +Webpack 5, Turbopack, and Next.js: + +```ts +const spriteUrl = new URL('./.svg-sprite/sprite.svg', import.meta.url).href +``` + +After obtaining the URL, use it in JSX: + +```tsx + + + +``` + +For names that are unsafe as SVG IDs, use the internal `id` from the manifest. + +### With `` + +```tsx +Search +``` + +An SVG inside `` is isolated from the page's CSS. Setting `color` or `--icon-color-N` on the outer element does not change its internal colors. + +### With CSS + +```css +.icon { + background: url('./.svg-sprite/sprite.svg#search') center / contain no-repeat; +} +``` + +For a single-color silhouette, you can use a mask: + +```css +.icon { + background-color: currentColor; + mask: url('./.svg-sprite/sprite.svg#search') center / contain no-repeat; +} +``` + +A mask does not preserve original colors, gradients, or differences between `fill` and `stroke`. + +The path in CSS is resolved relative to the CSS file itself. In these examples, the CSS file is next to `svg-sprite.config.ts`. + +## Assets and caching + +The generated component or standalone facade passes the SVG to the bundler as a separate asset: + +- Vite uses a static import with `?no-inline`; +- Webpack 5, Turbopack, and Next.js use `new URL(..., import.meta.url)`; +- SVG path data is not serialized into generated JavaScript. + +Bare `standalone` does not participate in an asset pipeline: the application copies +or publishes `sprite.svg` and owns its URL, versioning, and cache policy. + +With standard asset naming, the bundler adds a content hash: + +```text +/assets/sprite-.svg +``` + +This allows the SVG to be cached separately from JavaScript. Changing React code does not change the sprite contents, while changing icons creates a new asset version. + +HTTP cache headers, CDN behavior, and `Cache-Control` are configured by the application or hosting platform. With Webpack, the final file name depends on the project's `assetModuleFilename`. + +## SVG transformations + +All transformations are enabled by default and can be configured independently: + +| Option | Behavior | +|---|---| +| `removeSize` | Removes `width` and `height` from the root `` while preserving an existing `viewBox` | +| `replaceColors` | Replaces detected `fill` and `stroke` values with `--icon-color-N` | +| `addTransition` | Adds transitions for `fill` and `stroke` to colored elements and generated styles | + +To disable an individual operation: + +```ts +export default defineSpriteConfig({ + mode: 'next@app/turbopack', + transform: { + removeSize: false, + replaceColors: false, + addTransition: false, + }, +}) +``` + +Source SVG files are not modified. Transformations apply only to the generated sprite contents. + +## Color management + +### Monochrome icons + +If one color is detected, its fallback becomes `currentColor`: + +```svg +stroke="var(--icon-color-1, currentColor)" +``` + +Set the color through a prop or CSS: + +```tsx + +``` + +### Multicolor icons + +Each unique color gets its own custom property with the original color as its fallback: + +```svg +fill="var(--icon-color-1, #798198)" +fill="var(--icon-color-2, #ffffff)" +fill="var(--icon-color-3, #129d9d)" +``` + +You can override only the values you need: + +```css +.icon { + --icon-color-1: #4b5563; + --icon-color-3: #14b8a6; +} +``` + +### Limitations + +- `none`, `transparent`, `inherit`, `unset`, and `initial` are not replaced; +- colors in `fill`, `stroke`, and inline `style` attributes are handled most reliably; +- CSS classes and external stylesheets inside the SVG are not the primary transformation use case; +- `url(#...)` values may be replaced along with colors, so gradients and patterns require a separate sprite with `replaceColors: false`; +- masks, filters, and complex internal CSS rules require visual verification; +- page CSS custom properties are available through ``, but not inside `` or a CSS background. + +For a complex icon, you can disable `replaceColors` in a separate sprite configuration. + +## SpriteViewer + +The Viewer uses one Shadow DOM Web Component for every mode. React and future framework components are bridges to that same element, so the visuals and behavior are not duplicated. + +Bare `standalone` loads the self-contained browser bundle and supplies the JSON manifest URL and the published SVG URL: + +```html + + + +``` + +`viewer-element.js` has no additional runtime files and can be copied with the other static assets for self-hosting. + +`standalone@vite` and `standalone@webpack` register the same element through an npm entry and pass the generated JS manifest through the `sources` property: + +```ts +import '@gromlab/svg-sprites/viewer/element' +import type { SpriteViewerElement } from '@gromlab/svg-sprites/viewer' +import spriteManifest from './svg-sprite/.svg-sprite/svg-sprite.manifest.js' + +const viewer = document.querySelector('gromlab-sprite-viewer')! +viewer.sources = [spriteManifest] +``` + +React and Next.js keep the component API: + +```tsx +import { SpriteViewer } from '@gromlab/svg-sprites/react' +``` + +It accepts ready-made manifests, remote standalone sources, an array of lazy loaders, or a record in the format returned by `import.meta.glob`. + +Vite: + +```tsx +import { SpriteViewer } from '@gromlab/svg-sprites/react' +import type { SpriteManifestModule } from '@gromlab/svg-sprites/react' + +const sources = import.meta.glob( + '/src/**/svg-sprite/.svg-sprite/svg-sprite.manifest.js', +) + +export const IconsDebugPage = () => ( + +) +``` + +Webpack and Next.js: + +```tsx +const sources = [ + () => import('@/ui/app-icons/.svg-sprite/svg-sprite.manifest.js'), + () => import('@/features/analytics/icons/.svg-sprite/svg-sprite.manifest.js'), +] + +export const IconsDebugPage = () => ( + +) +``` + +The Viewer displays groups, search, `viewBox`, CSS custom properties, and fallback colors. Framework manifests get their framework-specific tab plus SVG, IMG, and CSS; standalone manifests get SVG, IMG, and CSS. You can change color values in the interface and immediately inspect the result. + +### Viewer theme + +By default, `colorTheme="auto"` follows `prefers-color-scheme`. You can explicitly pass `light` or `dark`: + +```tsx + +``` + +To synchronize it with the application theme: + +```tsx + +``` + +`@gromlab/svg-sprites/react` contains `'use client'` and renders the Web Component host; its internal Shadow DOM is created after the browser runtime loads. In the Next.js App Router, place the Viewer inside a separate Client Component boundary and use it only on a debug route or in an internal tool. + +## Generated files, Git, and CI + +Every mode except bare `standalone` creates a local `.gitignore` for: + +```text +/.svg-sprite/ +``` + +Commit the local `.gitignore` to the repository once. It excludes the other generated files, so generation must run before commands that import the sprite module: + +```json +{ + "scripts": { + "sprites": "npx --yes @gromlab/svg-sprites src/ui/app-icons/svg-sprite.config.ts", + "predev": "npm run sprites", + "prebuild": "npm run sprites", + "pretypecheck": "npm run sprites" + } +} +``` + +CI must run generation before building or type-checking. Pin `@gromlab/svg-sprites` to an exact version when the CI toolchain must be reproducible. A local package installation is not required unless CI also uses the Viewer, package config types, or the programmatic API. + +Bare `standalone` does not create a `.gitignore` and preserves a user-owned file. If a managed `.gitignore` remains after another mode, bare mode removes it. In every other mode, the generator refuses to overwrite a user-owned `.gitignore` without a generated marker. The root `index.ts` remains user-owned and may re-export the generated API. + +## Troubleshooting + +- In every mode except bare `standalone`, missing `.svg-sprite/index.js`: run the generation script before importing the generated module. +- Source not found: pass an existing config file or sprite module directory. +- Mode missing: add `mode` to the config or pass `--mode`. +- Icon missing from the type: check `input`, the `.svg` extension, glob exclusions, and whether nested folders require `**/*.svg`. +- Name conflict: two different SVG files have the same basename; rename one of them. +- `Refusing to overwrite a user file`: the sprite module root contains a user-owned `.gitignore` that the generator cannot replace. +- The icon does not change color: use `` or the generated component and check `replaceColors`. +- Webpack emits an incorrect URL: check Asset Modules, `output.publicPath`, and SVG loaders. +- Static sprite returns 404: check the post-generation copy or server alias, and do not put a filesystem `spritePath` into HTML. +- The Viewer cannot find the sprite: in bundler modes, check the path to `.svg-sprite/svg-sprite.manifest.js`; for bare `standalone`, check the published `svg-sprite.manifest.json` and `sprite.svg` URLs. Run generation before starting the application. +- Build and mode do not match: use the target that corresponds to the actual bundler. + +For custom orchestration and low-level compilation, see the [Programmatic API](programmatic-api.md). diff --git a/skills/README.md b/src/skills/README.md similarity index 59% rename from skills/README.md rename to src/skills/README.md index 4f91d79..f731d9a 100644 --- a/skills/README.md +++ b/src/skills/README.md @@ -1,6 +1,6 @@ # AI skills -Π˜ΡΡ…ΠΎΠ΄Π½ΠΈΠΊΠΈ ΠΎΠ±ΡΠ·Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎΠ³ΠΎ контСкста английского ΠΈ русского skills находятся Π² `skills/svg-sprites/src/{en,ru}/`. Π“ΠΎΡ‚ΠΎΠ²Ρ‹Π΅ пСрСносимыС Π°Ρ€Ρ‚Π΅Ρ„Π°ΠΊΡ‚Ρ‹ Π³Π΅Π½Π΅Ρ€ΠΈΡ€ΡƒΡŽΡ‚ΡΡ Π² `skills/artifacts/`, ΠΈΠ³Π½ΠΎΡ€ΠΈΡ€ΡƒΡŽΡ‚ΡΡ Git ΠΈ ΡƒΠΏΠ°ΠΊΠΎΠ²Ρ‹Π²Π°ΡŽΡ‚ΡΡ Π² ZIP Π²ΠΎ врСмя release workflow. +Π˜ΡΡ…ΠΎΠ΄Π½ΠΈΠΊΠΈ ΠΎΠ±ΡΠ·Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎΠ³ΠΎ контСкста английского ΠΈ русского skills находятся Π² `src/skills/svg-sprites/src/{en,ru}/`. Π“ΠΎΡ‚ΠΎΠ²Ρ‹Π΅ пСрСносимыС Π°Ρ€Ρ‚Π΅Ρ„Π°ΠΊΡ‚Ρ‹ Π³Π΅Π½Π΅Ρ€ΠΈΡ€ΡƒΡŽΡ‚ΡΡ Π² ΠΊΠΎΡ€Π½Π΅Π²ΠΎΠΉ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ `skills/`, Π²Π΅Ρ€ΡΠΈΠΎΠ½ΠΈΡ€ΡƒΡŽΡ‚ΡΡ для установки Ρ‡Π΅Ρ€Π΅Π· `npx skills add` ΠΈ ΡƒΠΏΠ°ΠΊΠΎΠ²Ρ‹Π²Π°ΡŽΡ‚ΡΡ Π² ZIP Π²ΠΎ врСмя release workflow. ОбС языковыС вСрсии ΠΈΠΌΠ΅ΡŽΡ‚ ΡΠΈΠΌΠΌΠ΅Ρ‚Ρ€ΠΈΡ‡Π½ΡƒΡŽ single-file структуру: @@ -23,7 +23,7 @@ src/{en,ru}/ ``` -Include Ρ€Π°ΡΠΊΡ€Ρ‹Π²Π°ΡŽΡ‚ΡΡ рСкурсивно, ΠΏΡƒΡ‚ΡŒ считаСтся ΠΎΡ‚Π½ΠΎΡΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ Π²ΠΊΠ»ΡŽΡ‡Π°ΡŽΡ‰Π΅Π³ΠΎ Ρ„Π°ΠΉΠ»Π°. Π¦ΠΈΠΊΠ»Ρ‹, ΠΎΡ‚ΡΡƒΡ‚ΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΠ΅ Ρ„Π°ΠΉΠ»Ρ‹, Π²Ρ‹Ρ…ΠΎΠ΄ Π·Π° `skills/svg-sprites/`, frontmatter Π²ΠΎ Ρ„Ρ€Π°Π³ΠΌΠ΅Π½Ρ‚Π°Ρ… ΠΈ нСраскрытыС include Π·Π°Π²Π΅Ρ€ΡˆΠ°ΡŽΡ‚ сборку ошибкой. Π—Π°Π³ΠΎΠ»ΠΎΠ²ΠΊΠΈ Π½Π΅ ΡΠ΄Π²ΠΈΠ³Π°ΡŽΡ‚ΡΡ автоматичСски: entry содСрТит СдинствСнный `# H1`, inline-Ρ„Ρ€Π°Π³ΠΌΠ΅Π½Ρ‚Ρ‹ Π½Π°Ρ‡ΠΈΠ½Π°ΡŽΡ‚ΡΡ с `##`. +Include Ρ€Π°ΡΠΊΡ€Ρ‹Π²Π°ΡŽΡ‚ΡΡ рСкурсивно, ΠΏΡƒΡ‚ΡŒ считаСтся ΠΎΡ‚Π½ΠΎΡΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ Π²ΠΊΠ»ΡŽΡ‡Π°ΡŽΡ‰Π΅Π³ΠΎ Ρ„Π°ΠΉΠ»Π°. Π¦ΠΈΠΊΠ»Ρ‹, ΠΎΡ‚ΡΡƒΡ‚ΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΠ΅ Ρ„Π°ΠΉΠ»Ρ‹, Π²Ρ‹Ρ…ΠΎΠ΄ Π·Π° `src/skills/svg-sprites/`, frontmatter Π²ΠΎ Ρ„Ρ€Π°Π³ΠΌΠ΅Π½Ρ‚Π°Ρ… ΠΈ нСраскрытыС include Π·Π°Π²Π΅Ρ€ΡˆΠ°ΡŽΡ‚ сборку ошибкой. Π—Π°Π³ΠΎΠ»ΠΎΠ²ΠΊΠΈ Π½Π΅ ΡΠ΄Π²ΠΈΠ³Π°ΡŽΡ‚ΡΡ автоматичСски: entry содСрТит СдинствСнный `# H1`, inline-Ρ„Ρ€Π°Π³ΠΌΠ΅Π½Ρ‚Ρ‹ Π½Π°Ρ‡ΠΈΠ½Π°ΡŽΡ‚ΡΡ с `##`. ## Π›ΠΎΠΊΠ°Π»ΡŒΠ½Π°Ρ сборка @@ -31,4 +31,4 @@ Include Ρ€Π°ΡΠΊΡ€Ρ‹Π²Π°ΡŽΡ‚ΡΡ рСкурсивно, ΠΏΡƒΡ‚ΡŒ считаСтс npm run build:skill ``` -Команда собираСт ΠΈ Π²Π°Π»ΠΈΠ΄ΠΈΡ€ΡƒΠ΅Ρ‚ ΠΎΠ±Π΅ языковыС вСрсии, Π·Π°Ρ‚Π΅ΠΌ записываСт ΠΈΡ… Π² ΠΈΠ³Π½ΠΎΡ€ΠΈΡ€ΡƒΠ΅ΠΌΡ‹ΠΉ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ `skills/artifacts/`. Π‘Π±ΠΎΡ€Ρ‰ΠΈΠΊ провСряСт Ρ‚ΠΎΡ‡Π½Ρ‹ΠΉ список Ρ„Π°ΠΉΠ»ΠΎΠ², бСзопасныС ΠΏΡƒΡ‚ΠΈ, symlink, Markdown fences, Π»ΠΎΠΊΠ°Π»ΡŒΠ½Ρ‹Π΅ ссылки ΠΈ anchors, СдинствСнный H1, frontmatter, Ρ€Π°Π·ΠΌΠ΅Ρ€ основного Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚Π° ΠΈ отсутствиС `TODO`. +Команда собираСт ΠΈ Π²Π°Π»ΠΈΠ΄ΠΈΡ€ΡƒΠ΅Ρ‚ ΠΎΠ±Π΅ языковыС вСрсии, Π·Π°Ρ‚Π΅ΠΌ Π°Ρ‚ΠΎΠΌΠ°Ρ€Π½ΠΎ замСняСт ΠΊΠΎΡ€Π½Π΅Π²ΠΎΠΉ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ `skills/`. Π‘Π±ΠΎΡ€Ρ‰ΠΈΠΊ провСряСт Ρ‚ΠΎΡ‡Π½Ρ‹ΠΉ список Ρ„Π°ΠΉΠ»ΠΎΠ², бСзопасныС ΠΏΡƒΡ‚ΠΈ, symlink, Markdown fences, Π»ΠΎΠΊΠ°Π»ΡŒΠ½Ρ‹Π΅ ссылки ΠΈ anchors, СдинствСнный H1, frontmatter, Ρ€Π°Π·ΠΌΠ΅Ρ€ основного Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚Π° ΠΈ отсутствиС `TODO`. `npm run check:skill` Π΄ΠΎΠΏΠΎΠ»Π½ΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ провСряСт, Ρ‡Ρ‚ΠΎ вСрсионируСмыС Π°Ρ€Ρ‚Π΅Ρ„Π°ΠΊΡ‚Ρ‹ ΡΠΎΠ²ΠΏΠ°Π΄Π°ΡŽΡ‚ с Ρ€Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚ΠΎΠΌ сборки. diff --git a/skills/svg-sprites/build.mjs b/src/skills/svg-sprites/build.mjs similarity index 82% rename from skills/svg-sprites/build.mjs rename to src/skills/svg-sprites/build.mjs index 00e8715..85e8bd4 100644 --- a/skills/svg-sprites/build.mjs +++ b/src/skills/svg-sprites/build.mjs @@ -15,7 +15,9 @@ import { fileURLToPath } from 'node:url' import configs from './skill.config.mjs' const skillDir = path.dirname(fileURLToPath(import.meta.url)) -const artifactsDir = path.resolve(skillDir, '../artifacts') +const repositoryRoot = path.resolve(skillDir, '../../..') +const outputRoot = path.join(repositoryRoot, 'skills') +const temporaryParent = path.join(repositoryRoot, '.tmp') const includePattern = //g const isCheck = process.argv.slice(2).includes('--check') @@ -114,7 +116,7 @@ function renderSkill(config, document) { return [ ...frontmatter, '', - ``, + ``, '', body, '', @@ -168,8 +170,9 @@ function prepareConfig(config) { throw new Error(`Skill documents must be a non-empty array: ${config.name}`) } - const outputDir = path.resolve(skillDir, config.output) - assertInside(artifactsDir, outputDir) + assertSafeRelativePath(config.output) + const outputDir = path.resolve(outputRoot, config.output) + assertInside(outputRoot, outputDir) const documents = config.documents.map((document) => { assertSafeRelativePath(document.entry) @@ -190,7 +193,14 @@ function prepareConfig(config) { targets.add(entry.to) } - return { config, outputDir, documents, copies, expectedFiles: [...targets].sort() } + return { + config, + outputDir, + outputPath: path.relative(outputRoot, outputDir), + documents, + copies, + expectedFiles: [...targets].sort(), + } } function writeArtifactFile(targetDir, relativePath, content) { @@ -305,10 +315,46 @@ function validateArtifact(prepared, skillRoot) { } } +function assertArtifactDirectory(directory) { + if (!existsSync(directory)) { + throw new Error('Generated skills are missing. Run npm run build:skill.') + } + const stats = lstatSync(directory) + if (stats.isSymbolicLink() || !stats.isDirectory()) { + throw new Error(`Skill output must be a directory without symlinks: ${directory}`) + } +} + +function assertArtifactsCurrent(stagedRoot) { + assertArtifactDirectory(outputRoot) + const expectedFiles = listFiles(stagedRoot).sort() + const actualFiles = listFiles(outputRoot).sort() + const expectedSet = new Set(expectedFiles) + const actualSet = new Set(actualFiles) + const missingFiles = expectedFiles.filter((file) => !actualSet.has(file)) + const unexpectedFiles = actualFiles.filter((file) => !expectedSet.has(file)) + const changedFiles = expectedFiles.filter((file) => ( + actualSet.has(file) + && !readFileSync(path.join(stagedRoot, file)).equals(readFileSync(path.join(outputRoot, file))) + )) + + if (missingFiles.length || unexpectedFiles.length || changedFiles.length) { + const details = [ + ...missingFiles.map((file) => `Missing: ${file}`), + ...unexpectedFiles.map((file) => `Unexpected: ${file}`), + ...changedFiles.map((file) => `Changed: ${file}`), + ] + throw new Error(`Generated skills are out of date. Run npm run build:skill.\n${details.join('\n')}`) + } +} + function replaceDirectory(stagedDir, outputDir) { - const backupDir = `${outputDir}.backup-${process.pid}` + const backupDir = path.join(path.dirname(stagedDir), `.skills-backup-${process.pid}`) rmSync(backupDir, { recursive: true, force: true }) - if (existsSync(outputDir)) renameSync(outputDir, backupDir) + if (existsSync(outputDir)) { + assertArtifactDirectory(outputDir) + renameSync(outputDir, backupDir) + } try { renameSync(stagedDir, outputDir) rmSync(backupDir, { recursive: true, force: true }) @@ -339,21 +385,23 @@ for (const [index, prepared] of preparedConfigs.entries()) { } } -mkdirSync(artifactsDir, { recursive: true }) -const temporaryRoot = mkdtempSync(path.join(artifactsDir, '.skills-build-')) +mkdirSync(temporaryParent, { recursive: true }) +const temporaryRoot = mkdtempSync(path.join(temporaryParent, 'skills-build-')) try { for (const prepared of preparedConfigs) { - const stagedDir = path.join(temporaryRoot, prepared.config.name) + const stagedDir = path.join(temporaryRoot, prepared.outputPath) buildSkill(prepared, stagedDir) validateArtifact(prepared, stagedDir) } - for (const prepared of preparedConfigs) { - const stagedDir = path.join(temporaryRoot, prepared.config.name) - if (isCheck) { - console.log(`Skill sources are valid: ${prepared.config.name}`) - } else { - replaceDirectory(stagedDir, prepared.outputDir) + if (isCheck) { + assertArtifactsCurrent(temporaryRoot) + for (const prepared of preparedConfigs) { + console.log(`Skill artifact is up to date: ${prepared.config.name}`) + } + } else { + replaceDirectory(temporaryRoot, outputRoot) + for (const prepared of preparedConfigs) { console.log(`Built skill: ${path.relative(process.cwd(), prepared.outputDir)}`) } } diff --git a/skills/svg-sprites/skill.config.mjs b/src/skills/svg-sprites/skill.config.mjs similarity index 89% rename from skills/svg-sprites/skill.config.mjs rename to src/skills/svg-sprites/skill.config.mjs index 6af3e59..885a876 100644 --- a/skills/svg-sprites/skill.config.mjs +++ b/src/skills/svg-sprites/skill.config.mjs @@ -18,9 +18,9 @@ function documents(language) { } const englishDocumentation = [ - { from: '../../README.md', to: 'references/README.md' }, + { from: '../../../README.md', to: 'references/README.md' }, { - fromDirectory: '../../docs/en', + fromDirectory: '../../../docs/en', toDirectory: 'references/docs/en', extensions: ['.md'], exclude: [ @@ -32,9 +32,9 @@ const englishDocumentation = [ ] const russianDocumentation = [ - { from: '../../README_RU.md', to: 'references/README_RU.md' }, + { from: '../../../README_RU.md', to: 'references/README_RU.md' }, { - fromDirectory: '../../docs/ru', + fromDirectory: '../../../docs/ru', toDirectory: 'references/docs/ru', extensions: ['.md'], exclude: [ @@ -49,7 +49,7 @@ export default [ { name: 'svg-sprites', description: 'Use only when configuring, generating, or troubleshooting @gromlab/svg-sprites. Triggers: @gromlab/svg-sprites, svg-sprite.config.json, defineSpriteConfig, generateSprite, standalone@server, source: remote, ServerSvgInput, exact modes for standalone, React, Next.js, Vue, Nuxt, Svelte, Angular, Astro, Solid, Preact, Qwik, Lit, or Alpine.js, SpriteConfig.input, --input, SpriteViewer, or --icon-color-N. Do NOT use for custom SVG sprites, favicons, raster images, icon fonts, choosing an icon set, or inline SVG without this package.', - output: '../artifacts/svg-sprites', + output: 'svg-sprites', maxSkillBytes: 48_000, documents: documents('en'), copy: englishDocumentation, @@ -57,7 +57,7 @@ export default [ { name: 'svg-sprites-ru', description: 'Π˜ΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ ΠΏΡ€ΠΈ настройкС, ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΠΈ ΠΈΠ»ΠΈ диагностикС @gromlab/svg-sprites. Π’Ρ€ΠΈΠ³Π³Π΅Ρ€Ρ‹: @gromlab/svg-sprites, svg-sprite.config.json, defineSpriteConfig, generateSprite, standalone@server, source: remote, ServerSvgInput, exact modes для standalone, React, Next.js, Vue, Nuxt, Svelte, Angular, Astro, Solid, Preact, Qwik, Lit ΠΈΠ»ΠΈ Alpine.js, SpriteConfig.input, --input, SpriteViewer ΠΈ --icon-color-N. НЕ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉ для самописных SVG-спрайтов, inline SVG, favicon, растровых ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠΉ, icon fonts ΠΈΠ»ΠΈ Π²Ρ‹Π±ΠΎΡ€Π° Π±ΠΈΠ±Π»ΠΈΠΎΡ‚Π΅ΠΊΠΈ ΠΈΠΊΠΎΠ½ΠΎΠΊ.', - output: '../artifacts/svg-sprites-ru', + output: 'svg-sprites-ru', maxSkillBytes: 48_000, documents: documents('ru'), copy: russianDocumentation, diff --git a/skills/svg-sprites/src/en/SKILL.md b/src/skills/svg-sprites/src/en/SKILL.md similarity index 100% rename from skills/svg-sprites/src/en/SKILL.md rename to src/skills/svg-sprites/src/en/SKILL.md diff --git a/src/skills/svg-sprites/src/en/references/complex-svg.md b/src/skills/svg-sprites/src/en/references/complex-svg.md new file mode 100644 index 0000000..4da6218 --- /dev/null +++ b/src/skills/svg-sprites/src/en/references/complex-svg.md @@ -0,0 +1,176 @@ +# Complex SVGs: diagnostics and safe generation + +## When to use this reference + +Use this document when a source contains ``, gradients, patterns, filters, masks, clip paths, internal `` and CSS `background-image` load the SVG as an isolated document, so page variables do not propagate into it. A CSS mask keeps only the silhouette and loses gradients, filters, and color differences. + +External stack-fragment support and paint-server behavior can vary across browsers. For critical complex graphics, when diagnosing runtime behavior and browser tools are available, test the target browsers; if they are incompatible, an SVG sprite may be the wrong delivery mechanism for that illustration. + +## Required verification + +1. Run generation with the correct mode. +2. Run the project's typecheck. +3. Open the generated sprite and find the shape using the ID from the manifest. +4. Statically compare `viewBox`, IDs, `url(#...)`, colors, and inline styles. +5. If the target/pipeline changed or a runtime issue is being diagnosed, build the production bundle and inspect the external hashed SVG. +6. When SpriteViewer and visual tools are available, test default colors and each `--icon-color-N` separately. +7. When browser tools are available and the runtime risk warrants it, test SSR/hydration for Next.js and target browsers for external fragments. +8. Do not claim visual or accessibility equivalence between source and output without the necessary tools and an actual comparison. + +## Common symptoms and actions + +- Icon became entirely `currentColor`: the pipeline detected one color. If the source semantics are more complex, disable `replaceColors` or normalize the source attributes. +- Gradient disappeared: check whether `fill="url(#...)"` was transformed, whether the target ID exists, and whether it collides with another icon. +- Shadow is clipped: inspect the filter region and viewBox; `removeSize` does not expand the area by itself. +- Viewer has no color controls: the color is defined through a class/stylesheet, or `replaceColors: false`; this is expected. +- Transition is duplicated or interferes with animation: an existing inline `transition` is not overwritten, but generated CSS also adds transitions; disable `addTransition` for the sprite. +- `` ignores variables: switch to `` or the generated component; page variables cannot be passed into an isolated SVG document. +- A manual fragment fails for a name containing spaces: use the ID from the manifest. +- One complex icon requires different transforms: move it to a separate sprite; per-icon transform config is not supported. + +For mode-specific execution and verification, return to the exact-mode guide selected from the main `SKILL.md`. diff --git a/skills/svg-sprites/src/ru/SKILL.md b/src/skills/svg-sprites/src/ru/SKILL.md similarity index 100% rename from skills/svg-sprites/src/ru/SKILL.md rename to src/skills/svg-sprites/src/ru/SKILL.md diff --git a/src/skills/svg-sprites/src/ru/references/complex-svg.md b/src/skills/svg-sprites/src/ru/references/complex-svg.md new file mode 100644 index 0000000..1ce110f --- /dev/null +++ b/src/skills/svg-sprites/src/ru/references/complex-svg.md @@ -0,0 +1,176 @@ +# Π‘Π»ΠΎΠΆΠ½Ρ‹Π΅ SVG: диагностика ΠΈ бСзопасная гСнСрация + +## Когда ΠΎΡ‚ΠΊΡ€Ρ‹Π²Π°Ρ‚ΡŒ + +ΠžΡ‚ΠΊΡ€Ρ‹Π²Π°ΠΉ этот Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚, Ссли исходник содСрТит ``, gradients, patterns, filters, masks, clip paths, Π²Π½ΡƒΡ‚Ρ€Π΅Π½Π½ΠΈΠ΅ `` ΠΈ CSS `background-image` Π·Π°Π³Ρ€ΡƒΠΆΠ°ΡŽΡ‚ SVG ΠΊΠ°ΠΊ ΠΈΠ·ΠΎΠ»ΠΈΡ€ΠΎΠ²Π°Π½Π½Ρ‹ΠΉ document, поэтому variables страницы Π²Π½ΡƒΡ‚Ρ€ΡŒ Π½Π΅ ΠΏΠ΅Ρ€Π΅Π΄Π°ΡŽΡ‚ΡΡ. CSS mask оставляСт Ρ‚ΠΎΠ»ΡŒΠΊΠΎ силуэт ΠΈ тСряСт gradients, filters ΠΈ различия Ρ†Π²Π΅Ρ‚ΠΎΠ². + +External stack fragment support ΠΈ ΠΏΠΎΠ²Π΅Π΄Π΅Π½ΠΈΠ΅ paint servers ΠΌΠΎΠ³ΡƒΡ‚ Ρ€Π°Π·Π»ΠΈΡ‡Π°Ρ‚ΡŒΡΡ ΠΌΠ΅ΠΆΠ΄Ρƒ browsers. Для ΠΊΡ€ΠΈΡ‚ΠΈΡ‡Π½ΠΎΠΉ слоТной Π³Ρ€Π°Ρ„ΠΈΠΊΠΈ ΠΏΡ€ΠΈ диагностикС runtime ΠΈ Π½Π°Π»ΠΈΡ‡ΠΈΠΈ browser-инструмСнтов ΠΏΡ€ΠΎΠ²Π΅Ρ€ΡŒ Ρ†Π΅Π»Π΅Π²Ρ‹Π΅ browsers; ΠΏΡ€ΠΈ нСсовмСстимости SVG sprite ΠΌΠΎΠΆΠ΅Ρ‚ Π±Ρ‹Ρ‚ΡŒ нСподходящим способом доставки ΠΈΠΌΠ΅Π½Π½ΠΎ этой ΠΈΠ»Π»ΡŽΡΡ‚Ρ€Π°Ρ†ΠΈΠΈ. + +## ΠžΠ±ΡΠ·Π°Ρ‚Π΅Π»ΡŒΠ½Π°Ρ ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΊΠ° + +1. Запусти Π³Π΅Π½Π΅Ρ€Π°Ρ†ΠΈΡŽ с ΠΏΡ€Π°Π²ΠΈΠ»ΡŒΠ½Ρ‹ΠΌ mode. +2. Запусти typecheck ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π°. +3. ΠžΡ‚ΠΊΡ€ΠΎΠΉ generated sprite ΠΈ Π½Π°ΠΉΠ΄ΠΈ shape ΠΏΠΎ ID ΠΈΠ· manifest. +4. БтатичСски ΡΠ²Π΅Ρ€ΡŒ `viewBox`, IDs, `url(#...)`, colors ΠΈ inline styles. +5. Если мСнялись target/pipeline ΠΈΠ»ΠΈ диагностируСтся runtime, собСри production bundle ΠΈ ΠΏΡ€ΠΎΠ²Π΅Ρ€ΡŒ внСшний hashed SVG. +6. ΠŸΡ€ΠΈ Π½Π°Π»ΠΈΡ‡ΠΈΠΈ SpriteViewer ΠΈ Π²ΠΈΠ·ΡƒΠ°Π»ΡŒΠ½Ρ‹Ρ… инструмСнтов ΠΏΡ€ΠΎΠ²Π΅Ρ€ΡŒ default colors ΠΈ ΠΊΠ°ΠΆΠ΄ΡƒΡŽ `--icon-color-N` ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½ΠΎ. +7. ΠŸΡ€ΠΈ Π½Π°Π»ΠΈΡ‡ΠΈΠΈ browser-инструмСнтов ΠΈ ΡΠΎΠΎΡ‚Π²Π΅Ρ‚ΡΡ‚Π²ΡƒΡŽΡ‰Π΅ΠΌ runtime-рискС ΠΏΡ€ΠΎΠ²Π΅Ρ€ΡŒ SSR/hydration для Next.js ΠΈ Ρ†Π΅Π»Π΅Π²Ρ‹Π΅ browsers для external fragments. +8. НС ΡƒΡ‚Π²Π΅Ρ€ΠΆΠ΄Π°ΠΉ Π²ΠΈΠ·ΡƒΠ°Π»ΡŒΠ½ΡƒΡŽ ΠΈΠ»ΠΈ a11y ΡΠΊΠ²ΠΈΠ²Π°Π»Π΅Π½Ρ‚Π½ΠΎΡΡ‚ΡŒ source ΠΈ Ρ€Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚Π° Π±Π΅Π· доступных инструмСнтов ΠΈ фактичСского сравнСния. + +## Π’ΠΈΠΏΠΎΠ²Ρ‹Π΅ симптомы ΠΈ дСйствия + +- Иконка стала ΠΏΠΎΠ»Π½ΠΎΡΡ‚ΡŒΡŽ `currentColor`: pipeline ΡƒΠ²ΠΈΠ΄Π΅Π» ΠΎΠ΄ΠΈΠ½ Ρ†Π²Π΅Ρ‚. Если исходная сСмантика слоТнСС, ΠΎΡ‚ΠΊΠ»ΡŽΡ‡ΠΈ `replaceColors` ΠΈΠ»ΠΈ Π½ΠΎΡ€ΠΌΠ°Π»ΠΈΠ·ΡƒΠΉ source attributes. +- Gradient исчСз: ΠΏΡ€ΠΎΠ²Π΅Ρ€ΡŒ, Π½Π΅ ΠΏΡ€Π΅ΠΎΠ±Ρ€Π°Π·ΠΎΠ²Π°Π½ Π»ΠΈ `fill="url(#...)"`, сущСствуСт Π»ΠΈ target ID ΠΈ Π½Π΅ ΠΊΠΎΠ½Ρ„Π»ΠΈΠΊΡ‚ΡƒΠ΅Ρ‚ Π»ΠΈ ΠΎΠ½ с Π΄Ρ€ΡƒΠ³ΠΈΠΌ icon. +- Shadow ΠΎΠ±Ρ€Π΅Π·Π°Π½: ΠΏΡ€ΠΎΠ²Π΅Ρ€ΡŒ filter region ΠΈ viewBox; `removeSize` сам ΠΏΠΎ сСбС Π½Π΅ Ρ€Π°ΡΡˆΠΈΡ€ΡΠ΅Ρ‚ ΠΎΠ±Π»Π°ΡΡ‚ΡŒ. +- Π¦Π²Π΅Ρ‚ΠΎΠ²Ρ‹Π΅ controls Viewer ΠΎΡ‚ΡΡƒΡ‚ΡΡ‚Π²ΡƒΡŽΡ‚: Ρ†Π²Π΅Ρ‚ Π·Π°Π΄Π°Π½ Ρ‡Π΅Ρ€Π΅Π· class/stylesheet Π»ΠΈΠ±ΠΎ `replaceColors: false`; это ΠΎΠΆΠΈΠ΄Π°Π΅ΠΌΠΎ. +- Transition дублируСтся ΠΈΠ»ΠΈ ΠΌΠ΅ΡˆΠ°Π΅Ρ‚ animation: ΡΡƒΡ‰Π΅ΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΠΉ inline `transition` Π½Π΅ пСрСзаписываСтся, Π½ΠΎ generated CSS Ρ‚Π°ΠΊΠΆΠ΅ добавляСт transitions; ΠΎΡ‚ΠΊΠ»ΡŽΡ‡ΠΈ `addTransition` для sprite. +- `` ΠΈΠ³Π½ΠΎΡ€ΠΈΡ€ΡƒΠ΅Ρ‚ variables: смСни rendering Π½Π° ``/generated component, Π½Π΅ пытайся ΠΏΠ΅Ρ€Π΅Π΄Π°Ρ‚ΡŒ page variables Π² ΠΈΠ·ΠΎΠ»ΠΈΡ€ΠΎΠ²Π°Π½Π½Ρ‹ΠΉ SVG. +- Π ΡƒΡ‡Π½ΠΎΠΉ fragment Π½Π΅ Ρ€Π°Π±ΠΎΡ‚Π°Π΅Ρ‚ для ΠΈΠΌΠ΅Π½ΠΈ с ΠΏΡ€ΠΎΠ±Π΅Π»ΠΎΠΌ: ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉ ID ΠΈΠ· manifest. +- Один слоТный icon Ρ‚Ρ€Π΅Π±ΡƒΠ΅Ρ‚ ΠΈΠ½Ρ‹Ρ… transforms: вынСси Π΅Π³ΠΎ Π² ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½Ρ‹ΠΉ sprite; per-icon transform config отсутствуСт. + +Для mode-specific запуска ΠΈ ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΊΠΈ Π²Π΅Ρ€Π½ΠΈΡΡŒ ΠΊ exact-mode guide, Π²Ρ‹Π±Ρ€Π°Π½Π½ΠΎΠΌΡƒ Π² основном `SKILL.md`.