@cyberalien/svg-utils 0.1.5 → 0.1.6

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.
@@ -2,10 +2,13 @@ import { GeneratedAssetFile } from "../../types/component.js";
2
2
  import { ComponentFactorySource } from "../../types/source.js";
3
3
  import { ComponentFactoryOptions } from "../../types/options.js";
4
4
  import { FactoryComponentImports } from "../imports/types.js";
5
+ interface Options extends Pick<ComponentFactoryOptions, 'cssMode' | 'cssPath' | 'doubleDirsForCSS' | 'mergeCSS'> {
6
+ styleInComponent?: boolean;
7
+ }
5
8
  /**
6
9
  * Generate CSS files for component
7
10
  *
8
11
  * Adds imports to imports object, adds assets
9
12
  */
10
- declare function generateCSSFilesForComponent(content: ComponentFactorySource, imports: FactoryComponentImports, assets: GeneratedAssetFile[], options: Pick<ComponentFactoryOptions, 'cssMode' | 'cssPath' | 'doubleDirsForCSS' | 'mergeCSS'>): void;
13
+ declare function generateCSSFilesForComponent(content: ComponentFactorySource, imports: FactoryComponentImports, assets: GeneratedAssetFile[], options: Options): string | undefined;
11
14
  export { generateCSSFilesForComponent };
@@ -11,7 +11,8 @@ function generateCSSFilesForComponent(content, imports, assets, options) {
11
11
  const { classes, keyframes } = content;
12
12
  if (!classes) return;
13
13
  const isModule = options.cssMode === "module";
14
- const mergeCSS = options.mergeCSS ?? false;
14
+ const styleInComponent = (!isModule && options.styleInComponent) ?? false;
15
+ const mergeCSS = (styleInComponent || options.mergeCSS) ?? false;
15
16
  const embedAnimations = isModule && !mergeCSS;
16
17
  const mergedContent = [];
17
18
  for (const className in classes) {
@@ -51,12 +52,16 @@ function generateCSSFilesForComponent(content, imports, assets, options) {
51
52
  else imports.css.add(filename.import);
52
53
  }
53
54
  if (mergeCSS && mergedContent.length) {
54
- assets.push({
55
- ...mergeCSS,
56
- content: mergedContent.join("\n\n")
57
- });
58
- if (isModule) imports.modules[mergeCSS.import] = "css";
59
- else imports.css.add(mergeCSS.import);
55
+ const content$1 = mergedContent.join("\n");
56
+ if (typeof mergeCSS == "object") {
57
+ assets.push({
58
+ ...mergeCSS,
59
+ content: content$1
60
+ });
61
+ if (isModule) imports.modules[mergeCSS.import] = "css";
62
+ else imports.css.add(mergeCSS.import);
63
+ }
64
+ return styleInComponent ? content$1 : void 0;
60
65
  }
61
66
  }
62
67
 
@@ -3,6 +3,7 @@ import { FactoryIconData } from "./types/data.js";
3
3
  import { ComponentFactoryOptions } from "./types/options.js";
4
4
  interface VueOptions extends ComponentFactoryOptions {
5
5
  ts?: boolean;
6
+ styles?: boolean;
6
7
  }
7
8
  /**
8
9
  * Create Vue component code
@@ -15,13 +15,17 @@ import { makeSquareViewBox } from "../svg/viewbox/square.js";
15
15
  */
16
16
  function createVueComponent(data, options) {
17
17
  const useTS = options.ts ?? false;
18
+ const styleInComponent = options.styles ?? false;
18
19
  const assets = [];
19
20
  const imports = createFactoryImports();
20
21
  const hasFallback = !!data.fallback;
21
22
  if (hasFallback) imports.named["@iconify/css-vue"] = new Set(["Icon"]);
22
23
  const vueNamedImports = /* @__PURE__ */ new Set();
23
24
  imports.named["vue"] = vueNamedImports;
24
- generateCSSFilesForComponent(data.icon, imports, assets, options);
25
+ const styleContent = generateCSSFilesForComponent(data.icon, imports, assets, {
26
+ ...options,
27
+ styleInComponent
28
+ });
25
29
  const componentCode = [];
26
30
  const sizeProps = getComponentSizeValues(options, data.viewBox);
27
31
  const props = {};
@@ -79,12 +83,13 @@ ${stringifyFactoryPropTypes(props)}
79
83
  componentCode.unshift(`const props = defineProps${tsCode}(${JSON.stringify(usedProps)});\n`);
80
84
  }
81
85
  const template = `<template><${hasFallback ? "Icon" : "svg"} ${stringifyFactoryProps(props, ":{prop}=\"{value}\"")} /></template>`;
82
- const content = `<script setup${useTS ? " lang=\"ts\"" : ""}>
86
+ let content = `<script setup${useTS ? " lang=\"ts\"" : ""}>
83
87
  ${stringifyFactoryImports(imports)}
84
88
  ${componentCode.join("\n")}
85
89
  <\/script>
86
90
  ${template}
87
91
  `;
92
+ if (styleContent) content += `<style>\n${styleContent}\n</style>\n`;
88
93
  const types = addVueComponentTypes(data, options, assets, props);
89
94
  return {
90
95
  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": "0.1.5",
6
+ "version": "0.1.6",
7
7
  "license": "MIT",
8
8
  "bugs": "https://github.com/cyberalien/svg-utils/issues",
9
9
  "homepage": "https://cyberalien.dev/",