Skip to content

Commit c6b45b1

Browse files
committed
chore: #179 rebuild napi types, update tests
1 parent d2dd408 commit c6b45b1

File tree

5 files changed

+931
-812
lines changed

5 files changed

+931
-812
lines changed

packages/napi/index.d.ts

Lines changed: 134 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,69 @@
11
/* auto-generated by NAPI-RS */
22
/* eslint-disable */
3-
export declare class PreservePattern {
4-
regex: string
5-
constructor(regex: string)
6-
}
3+
/**
4+
* Converts a JSON value of SVGO's `Config["plugins"]` into [`Jobs`].
5+
*
6+
* Note that this will deduplicate any plugins listed.
7+
*
8+
* # Errors
9+
*
10+
* If a config file cannot be deserialized into jobs. This may fail even if
11+
* the config is valid for SVGO, such as if
12+
*
13+
* - The config contains custom plugins
14+
* - The plugin parameters are incompatible with OXVG
15+
* - The underlying deserialization process fails
16+
*
17+
* If you believe an errors should be fixed, please raise an issue
18+
* [here](https://github.com/noahbald/oxvg/issues)
19+
*/
20+
export declare function convertSvgoConfig(config?: Array<any> | undefined | null): Jobs
721

822
/**
9-
* Remove attributes based on whether it matches a pattern.
23+
* Returns the given config with omitted options replaced with the config provided by `extends`.
24+
* I.e. acts like `{ ...extends, ...config }`
25+
*/
26+
export declare function extend(extend: Extends, config?: Jobs | undefined | null): Jobs
27+
28+
/**
29+
* Optimise an SVG document using the provided config
1030
*
11-
* The patterns syntax is `[ element* : attribute* : value* ]`; where
31+
* # Errors
32+
* - If the document fails to parse
33+
* - If any of the optimisations fail
34+
* - If the optimised document fails to serialize
1235
*
13-
* - A regular expression matching an element's name. An asterisk or omission matches all.
14-
* - A regular expression matching an attribute's name.
15-
* - A regular expression matching an attribute's value. An asterisk or omission matches all.
36+
* # Examples
1637
*
17-
* # Example
38+
* Optimise svg with the default configuration
1839
*
19-
* Match `fill` attribute in `<path>` elements
40+
* ```js
41+
* import { optimise } from "@oxvg/napi";
2042
*
21-
* ```ignore
22-
* use oxvg_optimiser::{Jobs, RemoveAttrs};
43+
* const result = optimise(`<svg />`);
44+
* ```
2345
*
24-
* let mut remove_attrs = RemoveAttrs::default();
25-
* remove_attrs.attrs = vec![String::from("path:fill")];
26-
* let jobs = Jobs {
27-
* remove_attrs: Some(remove_attrs),
28-
* ..Jobs::none()
29-
* };
46+
* Or, provide your own config
47+
*
48+
* ```js
49+
* import { optimise } from "@oxvg/napi";
50+
*
51+
* // Only optimise path data
52+
* const result = optimise(`<svg />`, { convertPathData: {} });
3053
* ```
31-
* # Correctness
3254
*
33-
* Removing attributes may visually change the document if they're
34-
* presentation attributes or selected with CSS.
55+
* Or, extend a preset
3556
*
36-
* # Errors
57+
* ```js
58+
* import { optimise, extend, Extends } from "@oxvg/napi";
3759
*
38-
* If the regex fails to parse.
60+
* const result = optimise(
61+
* `<svg />`,
62+
* extend(Extends.Default, { convertPathData: { removeUseless: false } }),
63+
* );
64+
* ```
3965
*/
40-
export declare class RemoveAttrs {
41-
/** A list of patterns that match attributes. */
42-
attrs: Array<string>
43-
/**
44-
* The seperator for different parts of the pattern. By default this is `":"`.
45-
*
46-
* You may need to use this if you need to match attributes with a `:` (i.e. prefixed attributes).
47-
*/
48-
elemSeparator: string
49-
/** Whether to ignore attributes set to `currentColor` */
50-
preserveCurrentColor: boolean
51-
/** Instantiates and instance of remove attributes with the given configuration options. */
52-
constructor(attrs: Array<string>, elemSeparator: string, preserveCurrentColor: boolean)
53-
}
54-
66+
export declare function optimise(svg: string, config?: Jobs | undefined | null): string
5567
/**
5668
* Adds attributes to SVG elements in the document. This is not an optimisation
5769
* and will increase the size of SVG documents.
@@ -344,10 +356,10 @@ export interface CollapseGroups {
344356
field0: boolean
345357
}
346358

347-
export declare const enum ConvertCase {
348-
Upper = 0,
349-
Lower = 1
350-
}
359+
export type ConvertCase =
360+
| { type: 'Upper' }
361+
| { type: 'Lower' }
362+
| { type: 'Napi' }
351363

352364
/**
353365
* Converts color references to their shortest equivalent.
@@ -428,7 +440,6 @@ export interface ConvertOneStopGradients {
428440
* # Correctness
429441
*
430442
* Rounding errors may result in slight visual differences.
431-
*
432443
*/
433444
export interface ConvertPathData {
434445
/** Whether to remove redundant path commands. */
@@ -523,25 +534,6 @@ export interface ConvertStyleToAttrs {
523534
keepImportant: boolean
524535
}
525536

526-
/**
527-
* Converts a JSON value of SVGO's `Config["plugins"]` into [`Jobs`].
528-
*
529-
* Note that this will deduplicate any plugins listed.
530-
*
531-
* # Errors
532-
*
533-
* If a config file cannot be deserialized into jobs. This may fail even if
534-
* the config is valid for SVGO, such as if
535-
*
536-
* - The config contains custom plugins
537-
* - The plugin parameters are incompatible with OXVG
538-
* - The underlying deserialization process fails
539-
*
540-
* If you believe an errors should be fixed, please raise an issue
541-
* [here](https://github.com/noahbald/oxvg/issues)
542-
*/
543-
export declare function convertSvgoConfig(config?: Array<any> | undefined | null): Jobs
544-
545537
/**
546538
* Merge transforms and convert to shortest form.
547539
*
@@ -578,28 +570,12 @@ export interface ConvertTransform {
578570
collapseIntoOne: boolean
579571
}
580572

581-
/**
582-
* Returns the given config with omitted options replaced with the config provided by `extends`.
583-
* I.e. acts like `{ ...extends, ...config }`
584-
*/
585-
export declare function extend(extend: Extends, config?: Jobs | undefined | null): Jobs
586-
587573
/** A preset which the specified jobs can overwrite */
588-
export declare const enum Extends {
589-
/** A preset that contains no jobs. */
590-
None = 'None',
591-
/**
592-
* The default preset.
593-
* Uses [`oxvg_optimiser::Jobs::default`]
594-
*/
595-
Default = 'Default',
596-
/**
597-
* The correctness preset. Produces a preset that is less likely to
598-
* visually change the document.
599-
* Uses [`oxvg_optimiser::Jobs::correctness`]
600-
*/
601-
Safe = 'Safe'
602-
}
574+
export type Extends =
575+
| { type: 'None' }
576+
| { type: 'Default' }
577+
| { type: 'Safe' }
578+
| { type: 'Napi' }
603579

604580
/**
605581
* Merges styles from a `<style>` element to the `style` attribute of matching elements.
@@ -699,14 +675,6 @@ export interface Jobs {
699675
removeXlink?: RemoveXlink
700676
}
701677

702-
/** When running calculations against arcs, the level of error tolerated */
703-
export interface MakeArcs {
704-
/** When calculating tolerance, controls the bound compared to error */
705-
threshold: number
706-
/** When calculating tolerance, controls the bound compared to the radius */
707-
tolerance: number
708-
}
709-
710678
/**
711679
* Merge multipe paths into one
712680
*
@@ -810,46 +778,6 @@ export interface MoveGroupAttrsToElems {
810778
field0: boolean
811779
}
812780

813-
/**
814-
* Optimise an SVG document using the provided config
815-
*
816-
* # Errors
817-
* - If the document fails to parse
818-
* - If any of the optimisations fail
819-
* - If the optimised document fails to serialize
820-
*
821-
* # Examples
822-
*
823-
* Optimise svg with the default configuration
824-
*
825-
* ```js
826-
* import { optimise } from "@oxvg/napi";
827-
*
828-
* const result = optimise(`<svg />`);
829-
* ```
830-
*
831-
* Or, provide your own config
832-
*
833-
* ```js
834-
* import { optimise } from "@oxvg/napi";
835-
*
836-
* // Only optimise path data
837-
* const result = optimise(`<svg />`, { convertPathData: {} });
838-
* ```
839-
*
840-
* Or, extend a preset
841-
*
842-
* ```js
843-
* import { optimise, extend, Extends } from "@oxvg/napi";
844-
*
845-
* const result = optimise(
846-
* `<svg />`,
847-
* extend(Extends.Default, { convertPathData: { removeUseless: false } }),
848-
* );
849-
* ```
850-
*/
851-
export declare function optimise(svg: string, config?: Jobs | undefined | null): string
852-
853781
/**
854782
* Runs a series of checks to more confidently be sure the document won't break
855783
* due to unsupported/unstable features.
@@ -869,16 +797,8 @@ export interface Precheck {
869797
precleanChecks: boolean
870798
}
871799

872-
/** How many decimal points to round path command arguments */
873-
export type Precision =
874-
| { type: 'None' }
875-
| { type: 'Disabled' }
876-
| { type: 'Enabled', field0: number }
877-
878800
/** Various types of ways prefixes can be generated for an id. */
879801
export type PrefixGenerator =
880-
| { type: 'Generator', field0: (info?: PrefixGeneratorInfo) => string }
881-
| { type: 'Generator', field0: Generator }
882802
| { type: 'Prefix', field0: string }
883803
| { type: 'None' }
884804
| { type: 'Default' }
@@ -899,6 +819,10 @@ export interface PrefixGeneratorInfo {
899819
*
900820
* See [`super::CleanupIds`] for more details.
901821
*
822+
* # Differences to SVGO
823+
*
824+
* Custom generator functions are not supported.
825+
*
902826
* # Correctness
903827
*
904828
* Prefixing ids on inlined SVGs may affect scripting and CSS.
@@ -920,6 +844,10 @@ export interface PrefixIds {
920844
prefixClassNames: boolean
921845
}
922846

847+
export interface PreservePattern {
848+
regex: string
849+
}
850+
923851
/**
924852
* Removes attributes from elements that match a selector.
925853
*
@@ -936,6 +864,51 @@ export interface RemoveAttributesBySelector {
936864
field0: Array<Selector>
937865
}
938866

867+
/**
868+
* Remove attributes based on whether it matches a pattern.
869+
*
870+
* The patterns syntax is `[ element* : attribute* : value* ]`; where
871+
*
872+
* - A regular expression matching an element's name. An asterisk or omission matches all.
873+
* - A regular expression matching an attribute's name.
874+
* - A regular expression matching an attribute's value. An asterisk or omission matches all.
875+
*
876+
* # Example
877+
*
878+
* Match `fill` attribute in `<path>` elements
879+
*
880+
* ```ignore
881+
* use oxvg_optimiser::{Jobs, RemoveAttrs};
882+
*
883+
* let mut remove_attrs = RemoveAttrs::default();
884+
* remove_attrs.attrs = vec![String::from("path:fill")];
885+
* let jobs = Jobs {
886+
* remove_attrs: Some(remove_attrs),
887+
* ..Jobs::none()
888+
* };
889+
* ```
890+
* # Correctness
891+
*
892+
* Removing attributes may visually change the document if they're
893+
* presentation attributes or selected with CSS.
894+
*
895+
* # Errors
896+
*
897+
* If the regex fails to parse.
898+
*/
899+
export interface RemoveAttrs {
900+
/** A list of patterns that match attributes. */
901+
attrs: Array<string>
902+
/**
903+
* The seperator for different parts of the pattern. By default this is `":"`.
904+
*
905+
* You may need to use this if you need to match attributes with a `:` (i.e. prefixed attributes).
906+
*/
907+
elemSeparator: string
908+
/** Whether to ignore attributes set to `currentColor` */
909+
preserveCurrentColor: boolean
910+
}
911+
939912
/**
940913
* Removes XML comments from the document.
941914
*
@@ -1356,11 +1329,11 @@ export interface RemoveUnknownsAndDefaults {
13561329
keepRoleAttr: boolean
13571330
}
13581331

1359-
export declare const enum RemoveUnused {
1360-
False = 0,
1361-
True = 1,
1362-
Force = 2
1363-
}
1332+
export type RemoveUnused =
1333+
| { type: 'False' }
1334+
| { type: 'True' }
1335+
| { type: 'Force' }
1336+
| { type: 'Napi' }
13641337

13651338
/**
13661339
* Removes `xmlns` prefixed elements that are never referenced by a qualified name.
@@ -1564,9 +1537,20 @@ export interface SortDefsChildren {
15641537
}
15651538

15661539
/** The method for ordering xmlns attributes */
1567-
export declare const enum XMLNSOrder {
1568-
/** Sort xmlns attributes alphabetically */
1569-
Alphabetical = 0,
1570-
/** Keep xmlns attributes at the front of the list */
1571-
Front = 1
1540+
export type XMLNSOrder =
1541+
| { type: 'Alphabetical' }
1542+
| { type: 'Front' }
1543+
| { type: 'Napi' }
1544+
/** When running calculations against arcs, the level of error tolerated */
1545+
export interface MakeArcs {
1546+
/** When calculating tolerance, controls the bound compared to error */
1547+
threshold: number
1548+
/** When calculating tolerance, controls the bound compared to the radius */
1549+
tolerance: number
15721550
}
1551+
1552+
/** How many decimal points to round path command arguments */
1553+
export type Precision =
1554+
| { type: 'None' }
1555+
| { type: 'Disabled' }
1556+
| { type: 'Enabled', field0: number }

0 commit comments

Comments
 (0)