diff --git a/packages/ibm-products-web-components/.storybook/main.ts b/packages/ibm-products-web-components/.storybook/main.ts index 89486e35d0..af240786b1 100644 --- a/packages/ibm-products-web-components/.storybook/main.ts +++ b/packages/ibm-products-web-components/.storybook/main.ts @@ -1,6 +1,5 @@ import { mergeConfig } from 'vite'; import { litStyleLoader, litTemplateLoader } from '@mordech/vite-lit-loader'; -import viteSVGResultCarbonIconLoader from '../tools/vite-svg-result-carbon-icon-loader'; const glob = require('fast-glob'); const stories = glob.sync( [ @@ -36,11 +35,7 @@ const config = { }, async viteFinal(config) { return mergeConfig(config, { - plugins: [ - litStyleLoader(), - litTemplateLoader(), - viteSVGResultCarbonIconLoader(), - ], + plugins: [litStyleLoader(), litTemplateLoader()], }); }, }; diff --git a/packages/ibm-products-web-components/tools/svg-result-carbon-icon-loader.js b/packages/ibm-products-web-components/tools/svg-result-carbon-icon-loader.js deleted file mode 100644 index bc3dd676c3..0000000000 --- a/packages/ibm-products-web-components/tools/svg-result-carbon-icon-loader.js +++ /dev/null @@ -1,25 +0,0 @@ -/** - * @license - * - * Copyright IBM Corp. 2019, 2023 - * - * This source code is licensed under the Apache-2.0 license found in the - * LICENSE file in the root directory of this source tree. - */ - -import createSVGResultFromCarbonIcon from './svg-result-carbon-icon'; - -/** - * A Vite loader to generate `lit-html`'s `SVGResult` from an icon descriptor from `@carbon/icons`. - * - * @returns {string} The massaged module content. - */ -export default function svgResultCarbonIconLoader() { - const descriptor = require(this.resourcePath); // eslint-disable-line global-require - return ` - import { svg } from 'lit'; - import spread from '@carbon/web-components/es/globals/directives/spread.js'; - const svgResultCarbonIcon = ${createSVGResultFromCarbonIcon(descriptor)}; - export default svgResultCarbonIcon; - `; -} diff --git a/packages/ibm-products-web-components/tools/svg-result-carbon-icon.js b/packages/ibm-products-web-components/tools/svg-result-carbon-icon.js deleted file mode 100644 index d5486c0884..0000000000 --- a/packages/ibm-products-web-components/tools/svg-result-carbon-icon.js +++ /dev/null @@ -1,42 +0,0 @@ -/** - * @license - * - * Copyright IBM Corp. 2019, 2024 - * - * This source code is licensed under the Apache-2.0 license found in the - * LICENSE file in the root directory of this source tree. - */ - -import { getAttributes, formatAttributes } from '@carbon/icon-helpers'; - -// TODO: update @carbon/icon-helpers with this version of toString -const toString = (descriptor) => { - if (typeof descriptor === 'string') { - return descriptor; - } - const { elem = 'svg', attrs = {}, content = [] } = descriptor; - const children = content.map(toString).join(''); - if (elem !== 'svg') { - return `<${elem} ${formatAttributes(attrs)}>${children}`; - } - return `<${elem} ${formatAttributes( - getAttributes(attrs) - )}>${children}`; -}; - -/** - * Function that takes a valid @carbon/icons style icon descriptor and returns a lit-html svg instance - * - * @param {object} descriptor Object representation of an SVG icon as generated by @carbon/icons - */ -const icon = (descriptor) => { - descriptor.attrs = getAttributes( - Object.assign(descriptor.attrs ?? {}, { - '...': '${spread(attrs)}', // eslint-disable-line no-template-curly-in-string - }) - ); - descriptor?.content?.unshift('${children}'); // eslint-disable-line no-template-curly-in-string - return `({ children, ...attrs } = {}) => svg\`${toString(descriptor)}\``; -}; - -export default icon; diff --git a/packages/ibm-products-web-components/tools/vite-svg-result-carbon-icon-loader.ts b/packages/ibm-products-web-components/tools/vite-svg-result-carbon-icon-loader.ts deleted file mode 100644 index 0c7029a514..0000000000 --- a/packages/ibm-products-web-components/tools/vite-svg-result-carbon-icon-loader.ts +++ /dev/null @@ -1,63 +0,0 @@ -/** - * @license - * - * Copyright IBM Corp. 2019, 2025 - * - * This source code is licensed under the Apache-2.0 license found in the - * LICENSE file in the root directory of this source tree. - */ - -import createSVGResultFromCarbonIcon from './svg-result-carbon-icon'; - -/** - * A Vite plugin to generate `lit-html`'s `SVGResult` from an icon descriptor from `@carbon/icons`. - * - * @returns {string} The massaged module content. - */ -export default function svgResultCarbonIconLoader() { - const svgRegex = /@carbon[\\/]icons[\\/]/i; - - const paths = new Map(); - - return { - name: 'svg-result-carbon-icon-loader', - enforce: 'pre', - - resolveId(id: string): string | null { - if (id.match(svgRegex)) { - paths.set(id, id); - return id; - } else { - return null; - } - }, - - async load(id: string): Promise { - let outcome: string | undefined; - if (!id.match(svgRegex)) { - return outcome; - } - return ``; - }, - - async transform(src: string, id: string) { - if (!paths.has(id)) { - return null; - } - - const outcome: string | undefined = src; - if (!id.match(svgRegex)) { - return outcome; - } - const descriptor = require(id); - return ` - import { svg } from 'lit'; - import spread from '@carbon/web-components/es/globals/directives/spread.js'; - const svgResultCarbonIcon = ${createSVGResultFromCarbonIcon( - descriptor - )}; - export default svgResultCarbonIcon; - `; - }, - }; -}