@cyberalien/svg-utils 1.0.4 → 1.0.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.
@@ -1,4 +1,5 @@
1
1
  import { GeneratedAssetPath } from "../../types/options.js";
2
+ declare const defaultHelpersDirectory = "helpers";
2
3
  /**
3
4
  * Generate asset filename based on options
4
5
  *
@@ -7,4 +8,4 @@ import { GeneratedAssetPath } from "../../types/options.js";
7
8
  * @returns Asset path
8
9
  */
9
10
  declare function getGeneratedAssetFilename(filename: string, rootPath: GeneratedAssetPath): GeneratedAssetPath;
10
- export { getGeneratedAssetFilename };
11
+ export { defaultHelpersDirectory, getGeneratedAssetFilename };
@@ -1,3 +1,4 @@
1
+ const defaultHelpersDirectory = "helpers";
1
2
  /**
2
3
  * Generate asset filename based on options
3
4
  *
@@ -13,4 +14,4 @@ function getGeneratedAssetFilename(filename, rootPath) {
13
14
  };
14
15
  }
15
16
 
16
- export { getGeneratedAssetFilename };
17
+ export { defaultHelpersDirectory, getGeneratedAssetFilename };
@@ -5,5 +5,5 @@ import { ComponentFactoryFileSystemOptions, GeneratedAssetPath } from "../../typ
5
5
  * @param options Factory options
6
6
  * @returns Asset path
7
7
  */
8
- declare function getFactoryRelativeRootPath(options: Pick<ComponentFactoryFileSystemOptions, 'doubleDirsForComponents' | 'prefixDirsForComponents'>): GeneratedAssetPath;
8
+ declare function getFactoryRelativeRootPath(options: Pick<ComponentFactoryFileSystemOptions, 'doubleDirsForComponents' | 'prefixDirsForComponents'>, pathPrefix?: string): GeneratedAssetPath;
9
9
  export { getFactoryRelativeRootPath };
@@ -4,13 +4,13 @@
4
4
  * @param options Factory options
5
5
  * @returns Asset path
6
6
  */
7
- function getFactoryRelativeRootPath(options) {
7
+ function getFactoryRelativeRootPath(options, pathPrefix) {
8
8
  const { prefixDirsForComponents } = options;
9
9
  const prefixDir = prefixDirsForComponents ? typeof prefixDirsForComponents === "string" ? prefixDirsForComponents : "prefix" : "";
10
10
  const parentCount = (prefixDir ? prefixDir.split("/").length : 0) + (options.doubleDirsForComponents ? 1 : 0);
11
11
  return {
12
12
  import: parentCount ? "../".repeat(parentCount - 1) + ".." : ".",
13
- filename: ""
13
+ filename: pathPrefix ?? ""
14
14
  };
15
15
  }
16
16
 
@@ -11,8 +11,9 @@ function getGeneratedComponentTypesFilename(icon, content, options) {
11
11
  length: 8
12
12
  })}.d.ts`, options.rootPath);
13
13
  const filename = getGeneratedComponentFilename(icon, ".d.ts", options);
14
+ const rootPath = options.rootPath.filename;
14
15
  return {
15
- filename,
16
+ filename: `${rootPath ? rootPath + "/" : ""}${filename}`,
16
17
  import: `./${filename.split("/").pop()}`
17
18
  };
18
19
  }
@@ -4,5 +4,5 @@ import { FactoryComponentImports } from "../imports/types.js";
4
4
  /**
5
5
  * Adds getSizeProps() function to assets
6
6
  */
7
- declare function addSizeFunctionAsset(imports: FactoryComponentImports, assets: GeneratedAssetFile[], options: Pick<ComponentFactoryOptions, 'rootPath'>): string;
7
+ declare function addSizeFunctionAsset(imports: FactoryComponentImports, assets: GeneratedAssetFile[], options: Pick<ComponentFactoryOptions, 'rootPath' | 'helpersDirectory'>): string;
8
8
  export { addSizeFunctionAsset };
@@ -1,4 +1,4 @@
1
- import { getGeneratedAssetFilename } from "../filenames/asset.js";
1
+ import { defaultHelpersDirectory, getGeneratedAssetFilename } from "../filenames/asset.js";
2
2
 
3
3
  const functionName = "getSizeProps";
4
4
  const functionContent = `
@@ -9,7 +9,7 @@ const precision = 100;
9
9
 
10
10
  function calculateSize(size, ratio) {
11
11
  if (ratio === 1) {
12
- return value;
12
+ return size;
13
13
  }
14
14
 
15
15
  const oldParts = size.split(unitsSplit);
@@ -67,7 +67,7 @@ export { ${functionName} };
67
67
  * Adds getSizeProps() function to assets
68
68
  */
69
69
  function addSizeFunctionAsset(imports, assets, options) {
70
- const filename = getGeneratedAssetFilename("helpers/size.js", options.rootPath);
70
+ const filename = getGeneratedAssetFilename(`${options.helpersDirectory ?? defaultHelpersDirectory}/size.js`, options.rootPath);
71
71
  imports.named[filename.import] = new Set([functionName]);
72
72
  assets.push({
73
73
  ...filename,
@@ -2,5 +2,5 @@ import { ComponentFactoryFileSystemOptions } from "../types/options.js";
2
2
  /**
3
3
  * Generate file system options
4
4
  */
5
- declare function componentFactoryFileSystemOptions(base: Partial<ComponentFactoryFileSystemOptions>): ComponentFactoryFileSystemOptions;
5
+ declare function componentFactoryFileSystemOptions(base: Partial<ComponentFactoryFileSystemOptions>, pathPrefix?: string): ComponentFactoryFileSystemOptions;
6
6
  export { componentFactoryFileSystemOptions };
@@ -4,14 +4,14 @@ import { getFactoryRelativeRootPath } from "../helpers/filenames/path.js";
4
4
  /**
5
5
  * Generate file system options
6
6
  */
7
- function componentFactoryFileSystemOptions(base) {
7
+ function componentFactoryFileSystemOptions(base, pathPrefix) {
8
8
  const doubleDirsForCSS = base.doubleDirsForCSS ?? true;
9
9
  const prefixDirsForComponents = base.prefixDirsForComponents ?? false;
10
10
  const doubleDirsForComponents = base.doubleDirsForComponents ?? true;
11
11
  const rootPath = base.rootPath ?? getFactoryRelativeRootPath({
12
12
  doubleDirsForComponents,
13
13
  prefixDirsForComponents
14
- });
14
+ }, pathPrefix);
15
15
  return {
16
16
  doubleDirsForCSS,
17
17
  prefixDirsForComponents,
@@ -15,6 +15,7 @@ interface ComponentFactoryFileSystemOptions {
15
15
  doubleDirsForComponents: boolean;
16
16
  rootPath: GeneratedAssetPath;
17
17
  cssPath: GeneratedAssetPath;
18
+ helpersDirectory?: string;
18
19
  sharedTypes?: boolean;
19
20
  }
20
21
  /**
@@ -82,7 +82,7 @@ function createVueComponent(data, options) {
82
82
  const usedProps = getUsedFactoryProps(props);
83
83
  if (usedProps.length) {
84
84
  const tsCode = useTS ? `<{\n${stringifyFactoryPropTypes(props)}\n}>` : "";
85
- componentCode.unshift(`const props = defineProps${tsCode}(${JSON.stringify(usedProps)});\n`);
85
+ componentCode.unshift(`const props = defineProps${tsCode}(${tsCode ? "" : JSON.stringify(usedProps)});\n`);
86
86
  }
87
87
  const template = `<template><${hasFallback ? "Icon" : "svg"} ${stringifyFactoryProps(props, ":{prop}=\"{value}\"")} /></template>`;
88
88
  let content = `<script setup${useTS ? " lang=\"ts\"" : ""}>
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.4",
6
+ "version": "1.0.6",
7
7
  "license": "MIT",
8
8
  "bugs": "https://github.com/cyberalien/svg-utils/issues",
9
9
  "homepage": "https://cyberalien.dev/",