@iconify/tools 3.0.0-beta.3 → 3.0.0-beta.4

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.
@@ -53,7 +53,7 @@ function importDir(iconSet, options, getKeyword, files, readFile, done) {
53
53
  (content) => {
54
54
  try {
55
55
  const svg = new svg_index.SVG(content);
56
- svg_cleanup.cleanupSVG(svg);
56
+ svg_cleanup.cleanupSVG(svg, options);
57
57
  iconSet.fromSVG(keyword, svg);
58
58
  } catch (err) {
59
59
  if (options.ignoreImportErrors !== false) {
@@ -1,9 +1,11 @@
1
1
  import { IconSet } from '../icon-set/index.js';
2
+ import { CleanupSVGOptions } from '../svg/cleanup.js';
2
3
  import '@iconify/types';
3
4
  import '@iconify/utils/lib/customisations/defaults';
4
5
  import '../icon-set/types.js';
5
6
  import '../svg/index.js';
6
7
  import '@iconify/utils/lib/icon-set/tree';
8
+ import '../svg/cleanup/bad-tags.js';
7
9
 
8
10
  /**
9
11
  * Entry for file
@@ -31,7 +33,7 @@ type ImportDirectoryKeywordSyncCallback = Callback<ImportDirectoryKeywordCallbac
31
33
  /**
32
34
  * Options
33
35
  */
34
- interface ImportDirectoryOptions<K> {
36
+ interface ImportDirectoryOptions<K> extends CleanupSVGOptions {
35
37
  prefix?: string;
36
38
  includeSubDirs?: boolean;
37
39
  keyword?: K;
@@ -51,7 +51,7 @@ function importDir(iconSet, options, getKeyword, files, readFile, done) {
51
51
  (content) => {
52
52
  try {
53
53
  const svg = new SVG(content);
54
- cleanupSVG(svg);
54
+ cleanupSVG(svg, options);
55
55
  iconSet.fromSVG(keyword, svg);
56
56
  } catch (err) {
57
57
  if (options.ignoreImportErrors !== false) {
@@ -13,7 +13,14 @@ requiredParentTags.set(svg_data_tags.feLightningTags, svg_data_tags.feLightningC
13
13
  requiredParentTags.set(svg_data_tags.filterTag, svg_data_tags.filterChildTags);
14
14
  requiredParentTags.set(svg_data_tags.gradientTags, svg_data_tags.gradientChildTags);
15
15
  requiredParentTags.set(/* @__PURE__ */ new Set(["animateMotion"]), svg_data_tags.animateMotionChildTags);
16
- function checkBadTags(svg) {
16
+ const defaultOptions = {
17
+ keepTitles: false
18
+ };
19
+ function checkBadTags(svg, options) {
20
+ const { keepTitles } = {
21
+ ...defaultOptions,
22
+ ...options
23
+ };
17
24
  svg_parse.parseSVGSync(svg, (item) => {
18
25
  const tagName = item.tagName;
19
26
  const $element = item.$element;
@@ -23,6 +30,14 @@ function checkBadTags(svg) {
23
30
  }
24
31
  return;
25
32
  }
33
+ if (keepTitles && tagName === "title") {
34
+ const content = $element.html();
35
+ if (content?.includes("<") || content?.includes(">")) {
36
+ $element.remove();
37
+ item.testChildren = false;
38
+ }
39
+ return;
40
+ }
26
41
  if (svg_data_tags.unsupportedTags.has(tagName)) {
27
42
  $element.remove();
28
43
  item.testChildren = false;
@@ -2,9 +2,15 @@ import { SVG } from '../index.js';
2
2
  import '@iconify/types';
3
3
  import '@iconify/utils/lib/customisations/defaults';
4
4
 
5
+ /**
6
+ * Options
7
+ */
8
+ interface CheckBadTagsOptions {
9
+ keepTitles?: boolean;
10
+ }
5
11
  /**
6
12
  * Test for bag tags
7
13
  */
8
- declare function checkBadTags(svg: SVG): void;
14
+ declare function checkBadTags(svg: SVG, options?: CheckBadTagsOptions): void;
9
15
 
10
- export { checkBadTags };
16
+ export { CheckBadTagsOptions, checkBadTags };
@@ -11,7 +11,14 @@ requiredParentTags.set(feLightningTags, feLightningChildTags);
11
11
  requiredParentTags.set(filterTag, filterChildTags);
12
12
  requiredParentTags.set(gradientTags, gradientChildTags);
13
13
  requiredParentTags.set(/* @__PURE__ */ new Set(["animateMotion"]), animateMotionChildTags);
14
- function checkBadTags(svg) {
14
+ const defaultOptions = {
15
+ keepTitles: false
16
+ };
17
+ function checkBadTags(svg, options) {
18
+ const { keepTitles } = {
19
+ ...defaultOptions,
20
+ ...options
21
+ };
15
22
  parseSVGSync(svg, (item) => {
16
23
  const tagName = item.tagName;
17
24
  const $element = item.$element;
@@ -21,6 +28,14 @@ function checkBadTags(svg) {
21
28
  }
22
29
  return;
23
30
  }
31
+ if (keepTitles && tagName === "title") {
32
+ const content = $element.html();
33
+ if (content?.includes("<") || content?.includes(">")) {
34
+ $element.remove();
35
+ item.testChildren = false;
36
+ }
37
+ return;
38
+ }
24
39
  if (unsupportedTags.has(tagName)) {
25
40
  $element.remove();
26
41
  item.testChildren = false;
@@ -27,6 +27,7 @@ const knownIgnoredRules = /* @__PURE__ */ new Set([
27
27
  // Illustrator / Inkscape junk
28
28
  "solid*",
29
29
  "paint*",
30
+ "shape*",
30
31
  "color-interpolation-filters",
31
32
  "stop-opacity"
32
33
  ]);
@@ -25,6 +25,7 @@ const knownIgnoredRules = /* @__PURE__ */ new Set([
25
25
  // Illustrator / Inkscape junk
26
26
  "solid*",
27
27
  "paint*",
28
+ "shape*",
28
29
  "color-interpolation-filters",
29
30
  "stop-opacity"
30
31
  ]);
@@ -21,11 +21,11 @@ require('../optimise/svgo.cjs');
21
21
  require('svgo');
22
22
  require('@iconify/utils/lib/svg/id');
23
23
 
24
- function cleanupSVG(svg) {
24
+ function cleanupSVG(svg, options) {
25
25
  svg_cleanup_inlineStyle.cleanupInlineStyle(svg);
26
26
  svg_cleanup_svgoStyle.convertStyleToAttrs(svg);
27
27
  svg_cleanup_rootSvg.cleanupSVGRoot(svg);
28
- svg_cleanup_badTags.checkBadTags(svg);
28
+ svg_cleanup_badTags.checkBadTags(svg, options);
29
29
  svg_cleanup_attribs.removeBadAttributes(svg);
30
30
  svg_cleanup_rootStyle.cleanupRootStyle(svg);
31
31
  }
@@ -1,10 +1,15 @@
1
1
  import { SVG } from './index.js';
2
+ import { CheckBadTagsOptions } from './cleanup/bad-tags.js';
2
3
  import '@iconify/types';
3
4
  import '@iconify/utils/lib/customisations/defaults';
4
5
 
6
+ /**
7
+ * Options
8
+ */
9
+ type CleanupSVGOptions = CheckBadTagsOptions;
5
10
  /**
6
11
  * Clean up SVG before parsing/optimising it
7
12
  */
8
- declare function cleanupSVG(svg: SVG): void;
13
+ declare function cleanupSVG(svg: SVG, options?: CleanupSVGOptions): void;
9
14
 
10
- export { cleanupSVG };
15
+ export { CleanupSVGOptions, cleanupSVG };
@@ -19,11 +19,11 @@ import '../optimise/svgo.mjs';
19
19
  import 'svgo';
20
20
  import '@iconify/utils/lib/svg/id';
21
21
 
22
- function cleanupSVG(svg) {
22
+ function cleanupSVG(svg, options) {
23
23
  cleanupInlineStyle(svg);
24
24
  convertStyleToAttrs(svg);
25
25
  cleanupSVGRoot(svg);
26
- checkBadTags(svg);
26
+ checkBadTags(svg, options);
27
27
  removeBadAttributes(svg);
28
28
  cleanupRootStyle(svg);
29
29
  }
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "type": "module",
4
4
  "description": "Collection of functions for cleaning up and parsing SVG for Iconify project",
5
5
  "author": "Vjacheslav Trushkin",
6
- "version": "3.0.0-beta.3",
6
+ "version": "3.0.0-beta.4",
7
7
  "license": "MIT",
8
8
  "bugs": "https://github.com/iconify/tools/issues",
9
9
  "homepage": "https://github.com/iconify/tools",
@@ -516,10 +516,10 @@
516
516
  "import": "./lib/svg/parse-style.mjs",
517
517
  "types": "./lib/svg/parse-style.d.ts"
518
518
  },
519
- "./lib/tests/load": {
520
- "require": "./lib/tests/load.cjs",
521
- "import": "./lib/tests/load.mjs",
522
- "types": "./lib/tests/load.d.ts"
519
+ "./lib/tests/helpers": {
520
+ "require": "./lib/tests/helpers.cjs",
521
+ "import": "./lib/tests/helpers.mjs",
522
+ "types": "./lib/tests/helpers.d.ts"
523
523
  }
524
524
  },
525
525
  "scripts": {
@@ -527,9 +527,10 @@
527
527
  "lint": "eslint src/**/*.ts",
528
528
  "prebuild": "npm run lint && npm run clean",
529
529
  "build": "unbuild",
530
- "test:jest-cjs": "jest --clearCache --config=jest.config.cjs && jest --runInBand --config=jest.config.cjs",
531
- "test:jest-esm": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --clearCache --config=jest.config.mjs && cross-env NODE_OPTIONS=--experimental-vm-modules npx jest --runInBand --config=jest.config.mjs",
530
+ "test:jest-cjs": "jest --clearCache --config=jest.config.cjs && jest --runInBand --config=jest.config.cjs",
531
+ "test:jest-esm": "cross-env NODE_OPTIONS=--experimental-vm-modules TEST_REMOTE=false jest --clearCache --config=jest.config.mjs && cross-env NODE_OPTIONS=--experimental-vm-modules npx jest --runInBand --config=jest.config.mjs",
532
532
  "test:jasmine": "cross-env NODE_OPTIONS='--experimental-vm-modules --experimental-json-modules' npx jasmine",
533
- "test": "npm run test:jest-cjs && npm run test:jest-esm && npm run test:jasmine"
533
+ "test": "npm run test:jest-cjs && npm run test:jest-esm && npm run test:jasmine",
534
+ "test:ci": "cross-env TEST_REMOTE=false npm run test"
534
535
  }
535
536
  }