* Handle S2 illustrations. * * Resolves the SVG and wraps it with createIllustration from Icon.tsx.
()
| 83 | * Resolves the SVG and wraps it with createIllustration from Icon.tsx. |
| 84 | */ |
| 85 | function illustrationPlugin(): Plugin { |
| 86 | const VIRTUAL_PREFIX = '\0s2-illustration:'; |
| 87 | return { |
| 88 | name: 'illustration-loader', |
| 89 | enforce: 'pre', |
| 90 | resolveId(source, importer) { |
| 91 | if (source.startsWith('illustration:')) { |
| 92 | const svgPath = source.replace('illustration:', ''); |
| 93 | if (importer) { |
| 94 | const dir = path.dirname(importer); |
| 95 | const resolvedPath = path.resolve(dir, svgPath); |
| 96 | return VIRTUAL_PREFIX + resolvedPath; |
| 97 | } |
| 98 | } |
| 99 | return null; |
| 100 | }, |
| 101 | load(id) { |
| 102 | if (id.startsWith(VIRTUAL_PREFIX)) { |
| 103 | const svgPath = id.slice(VIRTUAL_PREFIX.length).replaceAll('\\', '/'); |
| 104 | return [ |
| 105 | `import {createIllustration} from '${path.resolve(s2Dir, 'src/Icon.tsx').replaceAll('\\', '/')}';`, |
| 106 | `import SvgComponent from '${svgPath}';`, |
| 107 | `export default /*#__PURE__*/ createIllustration(SvgComponent);` |
| 108 | ].join('\n'); |
| 109 | } |
| 110 | return null; |
| 111 | } |
| 112 | }; |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * Handle S2 workflow icons. |
no outgoing calls
no test coverage detected