@cyberalien/svg-utils 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,17 @@
1
+ # SVG Utils
2
+
3
+ Common functions for working with SVG used by various packages.
4
+
5
+ Usable in any environment.
6
+
7
+ The only dependency is types package with TypeScript definition.
8
+
9
+ ## Documentation
10
+
11
+ n/a
12
+
13
+ ## License
14
+
15
+ The library is released with MIT license.
16
+
17
+ © 2025-PRESENT Vjacheslav Trushkin
@@ -3,7 +3,7 @@ import { ComponentFactorySource } from "../../types/source.js";
3
3
  import { ComponentFactoryOptions } from "../../types/options.js";
4
4
  import { FactoryComponentImports } from "../imports/types.js";
5
5
  interface Options extends Pick<ComponentFactoryOptions, 'cssMode' | 'cssPath' | 'doubleDirsForCSS' | 'mergeCSS'> {
6
- styleInComponent?: boolean;
6
+ styleInComponent?: boolean | 'svelte';
7
7
  }
8
8
  /**
9
9
  * Generate CSS files for component
@@ -14,14 +14,16 @@ function generateCSSFilesForComponent(content, imports, assets, options) {
14
14
  const styleInComponent = (!isModule && options.styleInComponent) ?? false;
15
15
  const mergeCSS = (styleInComponent || options.mergeCSS) ?? false;
16
16
  const embedAnimations = isModule && !mergeCSS;
17
+ const classNamePrefix = styleInComponent === "svelte" ? ":global " : "";
18
+ const keyframesPrefix = styleInComponent === "svelte" ? "-global-" : "";
17
19
  const mergedContent = [];
18
20
  for (const className in classes) {
19
- const baseContent = stringifyCSSSelector(`.${className}`, classes[className]);
21
+ const baseContent = stringifyCSSSelector(`${classNamePrefix}.${className}`, classes[className]);
20
22
  let content$1 = baseContent;
21
23
  if (embedAnimations && keyframes) {
22
24
  for (const animationName in keyframes) if (baseContent.includes(animationName)) {
23
25
  const value = keyframes[animationName];
24
- content$1 += "\n" + (typeof value === "string" ? value : stringifyCSSKeyframes(animationName, value));
26
+ content$1 += "\n" + (typeof value === "string" ? value : stringifyCSSKeyframes(keyframesPrefix + animationName, value));
25
27
  }
26
28
  }
27
29
  if (mergeCSS) {
@@ -38,7 +40,7 @@ function generateCSSFilesForComponent(content, imports, assets, options) {
38
40
  }
39
41
  if (!embedAnimations && keyframes) for (const animationName in keyframes) {
40
42
  const value = keyframes[animationName];
41
- const content$1 = typeof value === "string" ? value : stringifyCSSKeyframes(animationName, value);
43
+ const content$1 = typeof value === "string" ? value : stringifyCSSKeyframes(keyframesPrefix + animationName, value);
42
44
  if (mergeCSS) {
43
45
  mergedContent.push(content$1);
44
46
  continue;
@@ -17,7 +17,7 @@ import { getViewBoxRatio } from "./helpers/content/ratio.js";
17
17
  */
18
18
  function createSvelteComponent(data, options) {
19
19
  const useTS = options.ts ?? false;
20
- const styleInComponent = options.styles ?? false;
20
+ const styleInComponent = options.styles === true ? "svelte" : false;
21
21
  const assets = [];
22
22
  const imports = createFactoryImports();
23
23
  const hasFallback = !!data.fallback;
@@ -93,7 +93,7 @@ ${componentCode.join("\n")}
93
93
  <\/script>
94
94
  ${template}
95
95
  `;
96
- if (styleContent) content += `<style>\n:global {\n${styleContent}\n}\n</style>\n`;
96
+ if (styleContent) content += `<style>\n${styleContent}\n</style>\n`;
97
97
  const types = addSvelteComponentTypes(data, options, assets, props);
98
98
  return {
99
99
  assets,
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "type": "module",
4
4
  "description": "Common functions for working with SVG used by various packages.",
5
5
  "author": "Vjacheslav Trushkin",
6
- "version": "1.0.0",
6
+ "version": "1.0.1",
7
7
  "license": "MIT",
8
8
  "bugs": "https://github.com/cyberalien/svg-utils/issues",
9
9
  "homepage": "https://cyberalien.dev/",