@dicebear/core 5.0.0-alpha.0 → 5.0.0-alpha.13

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,3 +1,3 @@
1
- import type { Style, StyleOptions } from './types';
2
- export declare function createAvatar<O extends {}>(style: Style<O>, options?: StyleOptions<O>): string;
3
- export declare function createPreview<O extends {}>(style: Style<O>, options: StyleOptions<O>, property: keyof StyleOptions<O>): string | undefined;
1
+ import type { Style, StyleOptions } from './types.js';
2
+ export declare function createAvatar<O extends {}>(style: Style<O>, options?: StyleOptions<O>): string;
3
+ export declare function createPreview<O extends {}>(style: Style<O>, options: StyleOptions<O>, property: keyof StyleOptions<O>): string | undefined;
package/lib/core.js ADDED
@@ -0,0 +1,70 @@
1
+ import * as svgUtils from './utils/svg.js';
2
+ import { merge as mergeOptions } from './utils/options.js';
3
+ import { create as createPrng } from './utils/prng.js';
4
+ import { convertToDataUri } from './utils/svg.js';
5
+ export function createAvatar(style, options = {}) {
6
+ var _a, _b;
7
+ options = mergeOptions(style, options);
8
+ const prng = createPrng(options.seed);
9
+ const result = style.create({ prng: prng, options });
10
+ const backgroundColor = prng.pick((_a = options.backgroundColor) !== null && _a !== void 0 ? _a : []);
11
+ if (options.size) {
12
+ result.attributes.width = options.size.toString();
13
+ result.attributes.height = options.size.toString();
14
+ }
15
+ if (options.scale !== undefined && options.scale !== 100) {
16
+ result.body = svgUtils.addScale(result, options.scale);
17
+ }
18
+ if (options.flip) {
19
+ result.body = svgUtils.addFlip(result);
20
+ }
21
+ if (options.rotate) {
22
+ result.body = svgUtils.addRotate(result, options.rotate);
23
+ }
24
+ if (options.translateX || options.translateY) {
25
+ result.body = svgUtils.addTranslate(result, options.translateX, options.translateY);
26
+ }
27
+ if (backgroundColor && backgroundColor !== 'transparent') {
28
+ result.body = svgUtils.addBackgroundColor(result, backgroundColor);
29
+ }
30
+ if (options.radius || options.clip) {
31
+ result.body = svgUtils.addViewboxMask(result, (_b = options.radius) !== null && _b !== void 0 ? _b : 0);
32
+ }
33
+ let avatar = `<svg ${svgUtils.createAttrString(result.attributes)}>` +
34
+ `${svgUtils.getMetadata(style)}` +
35
+ `${result.body}` +
36
+ `</svg>`;
37
+ return options.dataUri ? convertToDataUri(avatar) : avatar;
38
+ }
39
+ export function createPreview(style, options, property) {
40
+ var _a, _b;
41
+ options = mergeOptions(style, options);
42
+ const prng = createPrng(options.seed);
43
+ let result = (_a = style.preview) === null || _a === void 0 ? void 0 : _a.call(style, { prng, options, property });
44
+ const backgroundColor = prng.pick((_b = options.backgroundColor) !== null && _b !== void 0 ? _b : []);
45
+ const hasBackgroundColor = backgroundColor && backgroundColor !== 'transparent';
46
+ const isBackgroundVisible = property === 'backgroundColor';
47
+ if (undefined === result) {
48
+ if (hasBackgroundColor && isBackgroundVisible) {
49
+ result = {
50
+ attributes: {
51
+ viewBox: `0 0 1 1`,
52
+ fill: 'none',
53
+ 'shape-rendering': 'auto',
54
+ },
55
+ body: ``,
56
+ };
57
+ }
58
+ else {
59
+ return undefined;
60
+ }
61
+ }
62
+ if (hasBackgroundColor && isBackgroundVisible) {
63
+ result.body = svgUtils.addBackgroundColor(result, backgroundColor);
64
+ }
65
+ let avatar = `<svg ${svgUtils.createAttrString(result.attributes)}>` +
66
+ `${svgUtils.getMetadata(style)}` +
67
+ `${result.body}` +
68
+ `</svg>`;
69
+ return options.dataUri ? convertToDataUri(avatar) : avatar;
70
+ }
package/lib/index.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ /*!
2
+ * DiceBear (@dicebear/core)
3
+ *
4
+ * Code licensed under MIT (https://github.com/dicebear/dicebear/blob/main/LICENSE)
5
+ * Copyright (c) 2021 Florian Körner
6
+ */
7
+ export * from './core.js';
8
+ export * from './schema.js';
9
+ export * from './types.js';
package/lib/index.js ADDED
@@ -0,0 +1,9 @@
1
+ /*!
2
+ * DiceBear (@dicebear/core)
3
+ *
4
+ * Code licensed under MIT (https://github.com/dicebear/dicebear/blob/main/LICENSE)
5
+ * Copyright (c) 2021 Florian Körner
6
+ */
7
+ export * from './core.js';
8
+ export * from './schema.js';
9
+ export * from './types.js';
@@ -0,0 +1,2 @@
1
+ import { JSONSchema7 } from 'json-schema';
2
+ export declare const schema: JSONSchema7;
package/lib/schema.js ADDED
@@ -0,0 +1,76 @@
1
+ export const schema = {
2
+ type: 'object',
3
+ $schema: 'http://json-schema.org/draft-07/schema#',
4
+ title: 'Options',
5
+ properties: {
6
+ seed: {
7
+ type: 'string',
8
+ examples: ['Jane Doe', 'John Doe'],
9
+ },
10
+ dataUri: {
11
+ type: 'boolean',
12
+ default: false,
13
+ examples: [true, false],
14
+ },
15
+ flip: {
16
+ type: 'boolean',
17
+ default: false,
18
+ examples: [true, false],
19
+ },
20
+ rotate: {
21
+ type: 'integer',
22
+ minimum: 0,
23
+ maximum: 360,
24
+ default: 0,
25
+ examples: [0, 45, 90, 135, 180, 225, 270, 315],
26
+ },
27
+ scale: {
28
+ type: 'integer',
29
+ minimum: 0,
30
+ maximum: 200,
31
+ default: 100,
32
+ examples: [50, 100, 150],
33
+ },
34
+ radius: {
35
+ type: 'integer',
36
+ minimum: 0,
37
+ maximum: 50,
38
+ default: 0,
39
+ examples: [0, 10, 20, 30, 40, 50],
40
+ },
41
+ size: {
42
+ type: 'integer',
43
+ minimum: 1,
44
+ examples: [128, 256, 512, 1024],
45
+ },
46
+ backgroundColor: {
47
+ type: 'array',
48
+ uniqueItems: true,
49
+ items: {
50
+ type: 'string',
51
+ pattern: '^([0-9a-zA-Z]+|#[a-fA-F0-9]{3}|#[a-fA-F0-9]{4}|#[a-fA-F0-9]{6}|#[a-fA-F0-9]{8})$',
52
+ },
53
+ examples: ['#FFD5DC', '#FFDFBF', '#C0EADE', '#B6E3F4', '#D1D4F9'],
54
+ },
55
+ translateX: {
56
+ type: 'integer',
57
+ minimum: -100,
58
+ maximum: 100,
59
+ default: 0,
60
+ examples: [-50, -25, 0, 25, 50],
61
+ },
62
+ translateY: {
63
+ type: 'integer',
64
+ minimum: -100,
65
+ maximum: 100,
66
+ default: 0,
67
+ examples: [-50, -25, 0, 25, 50],
68
+ },
69
+ clip: {
70
+ type: 'boolean',
71
+ default: true,
72
+ examples: [true, false],
73
+ },
74
+ },
75
+ additionalProperties: false,
76
+ };
@@ -1,54 +1,66 @@
1
- import type { JSONSchema7 } from 'json-schema';
2
- import type { Options } from './options';
3
- export interface Prng {
4
- seed: string;
5
- bool(likelihood?: number): boolean;
6
- integer(min: number, max: number): number;
7
- pick<T>(arr: T[]): T;
8
- }
9
- export declare type StyleSchema = JSONSchema7;
10
- export declare type StyleOptions<O extends {}> = Partial<O & Options>;
11
- export interface StyleCreateProps<O> {
12
- prng: Prng;
13
- options: StyleOptions<O>;
14
- }
15
- export declare type StyleCreate<O extends {}> = (props: StyleCreateProps<O>) => StyleCreateResult;
16
- export interface StyleCreateResultAttributes {
17
- viewBox: string;
18
- [key: string]: string;
19
- }
20
- export interface StyleCreateResult {
21
- attributes: StyleCreateResultAttributes;
22
- body: string;
23
- }
24
- export interface StylePreviewProps<O> {
25
- prng: Prng;
26
- options: StyleOptions<O>;
27
- property: keyof StyleOptions<O>;
28
- }
29
- export declare type StylePreview<O extends {}> = (props: StylePreviewProps<O>) => StylePreviewResult;
30
- export interface StylePreviewResultAttributes {
31
- viewBox: string;
32
- [key: string]: string;
33
- }
34
- export declare type StylePreviewResult = undefined | {
35
- attributes: StyleCreateResultAttributes;
36
- head?: string;
37
- body: string;
38
- };
39
- export interface StyleMeta {
40
- title?: string;
41
- creator?: string | string[];
42
- source?: string;
43
- license?: {
44
- name: string;
45
- url: string;
46
- };
47
- contributor?: string | string[];
48
- }
49
- export interface Style<O extends {}> {
50
- meta: StyleMeta;
51
- schema: StyleSchema;
52
- create: StyleCreate<O>;
53
- preview?: StylePreview<O>;
54
- }
1
+ import { JSONSchema7 } from 'json-schema';
2
+ export interface Options {
3
+ seed?: string;
4
+ dataUri?: boolean;
5
+ flip?: boolean;
6
+ rotate?: number;
7
+ scale?: number;
8
+ radius?: number;
9
+ size?: number;
10
+ backgroundColor?: string[];
11
+ translateX?: number;
12
+ translateY?: number;
13
+ clip?: boolean;
14
+ }
15
+ export interface Prng {
16
+ seed: string;
17
+ bool(likelihood?: number): boolean;
18
+ integer(min: number, max: number): number;
19
+ pick<T>(arr: T[]): T;
20
+ }
21
+ export declare type StyleSchema = JSONSchema7;
22
+ export declare type StyleOptions<O extends {}> = Partial<O & Options>;
23
+ export interface StyleCreateProps<O> {
24
+ prng: Prng;
25
+ options: StyleOptions<O>;
26
+ }
27
+ export declare type StyleCreate<O extends {}> = (props: StyleCreateProps<O>) => StyleCreateResult;
28
+ export interface StyleCreateResultAttributes {
29
+ viewBox: string;
30
+ [key: string]: string;
31
+ }
32
+ export interface StyleCreateResult {
33
+ attributes: StyleCreateResultAttributes;
34
+ body: string;
35
+ }
36
+ export interface StylePreviewProps<O> {
37
+ prng: Prng;
38
+ options: StyleOptions<O>;
39
+ property: keyof StyleOptions<O>;
40
+ }
41
+ export declare type StylePreview<O extends {}> = (props: StylePreviewProps<O>) => StylePreviewResult;
42
+ export interface StylePreviewResultAttributes {
43
+ viewBox: string;
44
+ [key: string]: string;
45
+ }
46
+ export declare type StylePreviewResult = undefined | {
47
+ attributes: StyleCreateResultAttributes;
48
+ head?: string;
49
+ body: string;
50
+ };
51
+ export interface StyleMeta {
52
+ title?: string;
53
+ creator?: string | string[];
54
+ source?: string;
55
+ license?: {
56
+ name: string;
57
+ url: string;
58
+ };
59
+ contributor?: string | string[];
60
+ }
61
+ export interface Style<O extends {}> {
62
+ meta: StyleMeta;
63
+ schema: StyleSchema;
64
+ create: StyleCreate<O>;
65
+ preview?: StylePreview<O>;
66
+ }
package/lib/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -1 +1 @@
1
- export declare function xml(attr: string): string;
1
+ export declare function xml(attr: string): string;
@@ -0,0 +1,8 @@
1
+ export function xml(attr) {
2
+ return attr
3
+ .replace(/&/g, '&amp;')
4
+ .replace(/'/g, '&apos;')
5
+ .replace(/"/g, '&quot;')
6
+ .replace(/</g, '&lt;')
7
+ .replace(/>/g, '&gt;');
8
+ }
@@ -0,0 +1,3 @@
1
+ import type { Style, StyleOptions, StyleSchema } from '../types.js';
2
+ export declare function defaults(schema: StyleSchema): Record<string, unknown>;
3
+ export declare function merge<O extends {}>(style: Style<O>, options: StyleOptions<O>): StyleOptions<O>;
@@ -0,0 +1,32 @@
1
+ import { schema } from '../schema.js';
2
+ export function defaults(schema) {
3
+ var _a;
4
+ let result = {};
5
+ let props = (_a = schema.properties) !== null && _a !== void 0 ? _a : {};
6
+ Object.keys(props).forEach((key) => {
7
+ let val = props[key];
8
+ if (typeof val === 'object' && undefined !== val.default) {
9
+ if (Array.isArray(val.default)) {
10
+ result[key] = [...val.default];
11
+ }
12
+ else if (typeof val.default === 'object') {
13
+ result[key] = { ...val.default };
14
+ }
15
+ else {
16
+ result[key] = val.default;
17
+ }
18
+ }
19
+ });
20
+ return result;
21
+ }
22
+ export function merge(style, options) {
23
+ let result = {
24
+ ...{
25
+ seed: Math.random().toString(),
26
+ },
27
+ ...defaults(schema),
28
+ ...defaults(style.schema),
29
+ ...options,
30
+ };
31
+ return result;
32
+ }
@@ -1,2 +1,2 @@
1
- import type { Prng } from '../types';
2
- export declare function create(seed?: string): Prng;
1
+ import type { Prng } from '../types.js';
2
+ export declare function create(seed?: string): Prng;
@@ -0,0 +1,39 @@
1
+ const MIN = -2147483648;
2
+ const MAX = 2147483647;
3
+ function xorshift(value) {
4
+ value ^= value << 13;
5
+ value ^= value >> 17;
6
+ value ^= value << 5;
7
+ return value;
8
+ }
9
+ function hashSeed(seed) {
10
+ let hash = 0;
11
+ for (let i = 0; i < seed.length; i++) {
12
+ hash = ((hash << 5) - hash + seed.charCodeAt(i)) | 0;
13
+ hash = xorshift(hash);
14
+ }
15
+ return hash;
16
+ }
17
+ function randomSeed() {
18
+ return MIN + Math.floor((MAX - MIN) * Math.random()).toString();
19
+ }
20
+ export function create(seed) {
21
+ seed = seed !== null && seed !== void 0 ? seed : randomSeed();
22
+ let value = hashSeed(seed) || 1;
23
+ const next = () => (value = xorshift(value));
24
+ const integer = (min, max) => {
25
+ return Math.floor(((next() - MIN) / (MAX - MIN)) * (max + 1 - min) + min);
26
+ };
27
+ return {
28
+ seed,
29
+ bool(likelihood = 50) {
30
+ return integer(0, 100) <= likelihood;
31
+ },
32
+ integer(min, max) {
33
+ return integer(min, max);
34
+ },
35
+ pick(arr) {
36
+ return arr[integer(0, arr.length - 1)];
37
+ },
38
+ };
39
+ }
@@ -1,39 +1,37 @@
1
- import type { Options } from '../options';
2
- import type { Style, StyleCreateResult, StyleCreateResultAttributes } from '../types';
3
- declare type CreateGroupProps = {
4
- children: string;
5
- x: number;
6
- y: number;
7
- };
8
- export declare function createGroup({ children, x, y }: CreateGroupProps): string;
9
- export declare function getXmlnsAttributes(): {
10
- 'xmlns:dc': string;
11
- 'xmlns:cc': string;
12
- 'xmlns:rdf': string;
13
- 'xmlns:svg': string;
14
- xmlns: string;
15
- };
16
- export declare function getMetadata<O extends Options>(style: Style<O>): string;
17
- export declare function getMetadataWorkTitle<O extends Options>(style: Style<O>): string;
18
- export declare function getMetadataWorkCreator<O extends Options>(style: Style<O>): string;
19
- export declare function getMetadataWorkSource<O extends Options>(style: Style<O>): string;
20
- export declare function getMetadataWorkLicense<O extends Options>(style: Style<O>): string;
21
- export declare function getMetadataWorkContributor<O extends Options>(style: Style<O>): string;
22
- export declare function getMetadataWorkAgents(agents: string[]): string[];
23
- export declare function getMetadataLicense<O extends Options>(style: Style<O>): string;
24
- export declare function getViewBox(result: StyleCreateResult): {
25
- x: number;
26
- y: number;
27
- width: number;
28
- height: number;
29
- };
30
- export declare function addBackgroundColor(result: StyleCreateResult, backgroundColor: string): string;
31
- export declare function addScale(result: StyleCreateResult, scale: number): string;
32
- export declare function addTranslate(result: StyleCreateResult, x?: number, y?: number): string;
33
- export declare function addRotate(result: StyleCreateResult, rotate: number): string;
34
- export declare function addFlip(result: StyleCreateResult): string;
35
- export declare function addViewboxMask(result: StyleCreateResult, radius: number): string;
36
- export declare function createAttrString(attributes: StyleCreateResultAttributes): string;
37
- export declare function removeWhitespace(svg: string): string;
38
- export declare function convertToDataUri(svg: string): string;
39
- export {};
1
+ import type { Options, Style, StyleCreateResult, StyleCreateResultAttributes } from '../types.js';
2
+ declare type CreateGroupProps = {
3
+ children: string;
4
+ x: number;
5
+ y: number;
6
+ };
7
+ export declare function createGroup({ children, x, y }: CreateGroupProps): string;
8
+ export declare function getXmlnsAttributes(): {
9
+ 'xmlns:dc': string;
10
+ 'xmlns:cc': string;
11
+ 'xmlns:rdf': string;
12
+ 'xmlns:svg': string;
13
+ xmlns: string;
14
+ };
15
+ export declare function getMetadata<O extends Options>(style: Style<O>): string;
16
+ export declare function getMetadataWorkTitle<O extends Options>(style: Style<O>): string;
17
+ export declare function getMetadataWorkCreator<O extends Options>(style: Style<O>): string;
18
+ export declare function getMetadataWorkSource<O extends Options>(style: Style<O>): string;
19
+ export declare function getMetadataWorkLicense<O extends Options>(style: Style<O>): string;
20
+ export declare function getMetadataWorkContributor<O extends Options>(style: Style<O>): string;
21
+ export declare function getMetadataWorkAgents(agents: string[]): string[];
22
+ export declare function getMetadataLicense<O extends Options>(style: Style<O>): string;
23
+ export declare function getViewBox(result: StyleCreateResult): {
24
+ x: number;
25
+ y: number;
26
+ width: number;
27
+ height: number;
28
+ };
29
+ export declare function addBackgroundColor(result: StyleCreateResult, backgroundColor: string): string;
30
+ export declare function addScale(result: StyleCreateResult, scale: number): string;
31
+ export declare function addTranslate(result: StyleCreateResult, x?: number, y?: number): string;
32
+ export declare function addRotate(result: StyleCreateResult, rotate: number): string;
33
+ export declare function addFlip(result: StyleCreateResult): string;
34
+ export declare function addViewboxMask(result: StyleCreateResult, radius: number): string;
35
+ export declare function createAttrString(attributes: StyleCreateResultAttributes): string;
36
+ export declare function convertToDataUri(svg: string): string;
37
+ export {};
@@ -0,0 +1,178 @@
1
+ import * as escape from './escape.js';
2
+ const ccLicenses = {
3
+ by: {
4
+ permits: ['Reproduction', 'Distribution', 'DerivativeWorks'],
5
+ requires: ['Notice', 'Attribution'],
6
+ prohibits: [],
7
+ },
8
+ 'by-sa': {
9
+ permits: ['Reproduction', 'Distribution', 'DerivativeWorks'],
10
+ requires: ['Notice', 'Attribution', 'ShareAlike'],
11
+ prohibits: [],
12
+ },
13
+ 'by-nd': {
14
+ permits: ['Reproduction', 'Distribution'],
15
+ requires: ['Notice', 'Attribution'],
16
+ prohibits: [],
17
+ },
18
+ 'by-nc': {
19
+ permits: ['Reproduction', 'Distribution', 'DerivativeWorks'],
20
+ requires: ['Notice', 'Attribution'],
21
+ prohibits: ['CommercialUse'],
22
+ },
23
+ 'by-nc-sa': {
24
+ permits: ['Reproduction', 'Distribution', 'DerivativeWorks'],
25
+ requires: ['Notice', 'Attribution', 'ShareAlike'],
26
+ prohibits: ['CommercialUse'],
27
+ },
28
+ 'by-nc-nd': {
29
+ permits: ['Reproduction', 'Distribution'],
30
+ requires: ['Notice', 'Attribution'],
31
+ prohibits: ['CommercialUse'],
32
+ },
33
+ zero: {
34
+ permits: ['Reproduction', 'Distribution', 'DerivativeWorks'],
35
+ requires: [],
36
+ prohibits: [],
37
+ },
38
+ };
39
+ export function createGroup({ children, x, y }) {
40
+ return `<g transform="translate(${x}, ${y})">${children}</g>`;
41
+ }
42
+ export function getXmlnsAttributes() {
43
+ return {
44
+ 'xmlns:dc': 'http://purl.org/dc/elements/1.1/',
45
+ 'xmlns:cc': 'http://creativecommons.org/ns#',
46
+ 'xmlns:rdf': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
47
+ 'xmlns:svg': 'http://www.w3.org/2000/svg',
48
+ xmlns: 'http://www.w3.org/2000/svg',
49
+ };
50
+ }
51
+ export function getMetadata(style) {
52
+ return (`<metadata>` +
53
+ `<rdf:RDF>` +
54
+ `<cc:Work>` +
55
+ `<dc:format>image/svg+xml</dc:format>` +
56
+ `<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" />` +
57
+ `${getMetadataWorkTitle(style)}` +
58
+ `${getMetadataWorkCreator(style)}` +
59
+ `${getMetadataWorkSource(style)}` +
60
+ `${getMetadataWorkLicense(style)}` +
61
+ `${getMetadataWorkContributor(style)}` +
62
+ `</cc:Work>` +
63
+ `${getMetadataLicense(style)}` +
64
+ `</rdf:RDF>` +
65
+ `</metadata>`);
66
+ }
67
+ export function getMetadataWorkTitle(style) {
68
+ if (style.meta.title) {
69
+ return `<dc:title>${style.meta.title}</dc:title>`;
70
+ }
71
+ return '';
72
+ }
73
+ export function getMetadataWorkCreator(style) {
74
+ if (style.meta.creator) {
75
+ let creators = Array.isArray(style.meta.creator) ? style.meta.creator : [style.meta.creator];
76
+ return `<dc:creator>${getMetadataWorkAgents(creators)}</dc:creator>`;
77
+ }
78
+ return '';
79
+ }
80
+ export function getMetadataWorkSource(style) {
81
+ if (style.meta.source) {
82
+ return `<dc:source>${style.meta.source}</dc:source>`;
83
+ }
84
+ return '';
85
+ }
86
+ export function getMetadataWorkLicense(style) {
87
+ if (style.meta.license) {
88
+ return `<cc:license rdf:resource="${style.meta.license.url}" />`;
89
+ }
90
+ return '';
91
+ }
92
+ export function getMetadataWorkContributor(style) {
93
+ if (style.meta.contributor) {
94
+ let contributors = Array.isArray(style.meta.contributor) ? style.meta.contributor : [style.meta.contributor];
95
+ return `<dc:contributor>${getMetadataWorkAgents(contributors)}</dc:contributor>`;
96
+ }
97
+ return '';
98
+ }
99
+ export function getMetadataWorkAgents(agents) {
100
+ return agents.map((agent) => `<cc:Agent><dc:title>${agent}</dc:title></cc:Agent>`);
101
+ }
102
+ export function getMetadataLicense(style) {
103
+ var _a, _b;
104
+ let match = (_a = style.meta.license) === null || _a === void 0 ? void 0 : _a.url.match(/^https?:\/\/creativecommons.org\/(?:licenses|publicdomain)\/([a-z\-]+)\/\d.\d\//);
105
+ if (match) {
106
+ let license = ccLicenses[match[1]];
107
+ if (license) {
108
+ let result = ``;
109
+ license.permits.forEach((permits) => {
110
+ result += `<cc:permits rdf:resource="https://creativecommons.org/ns#${permits}" />`;
111
+ });
112
+ license.requires.forEach((requires) => {
113
+ result += `<cc:requires rdf:resource="https://creativecommons.org/ns#${requires}" />`;
114
+ });
115
+ license.prohibits.forEach((prohibits) => {
116
+ result += `<cc:prohibits rdf:resource="https://creativecommons.org/ns#${prohibits}" />`;
117
+ });
118
+ return `<cc:License rdf:about="${(_b = style.meta.license) === null || _b === void 0 ? void 0 : _b.url}">${result}</cc:License>`;
119
+ }
120
+ }
121
+ return '';
122
+ }
123
+ export function getViewBox(result) {
124
+ let viewBox = result.attributes['viewBox'].split(' ');
125
+ let x = parseInt(viewBox[0]);
126
+ let y = parseInt(viewBox[1]);
127
+ let width = parseInt(viewBox[2]);
128
+ let height = parseInt(viewBox[3]);
129
+ return {
130
+ x,
131
+ y,
132
+ width,
133
+ height,
134
+ };
135
+ }
136
+ export function addBackgroundColor(result, backgroundColor) {
137
+ let { width, height, x, y } = getViewBox(result);
138
+ return `<rect fill="${backgroundColor}" width="${width}" height="${height}" x="${x}" y="${y}" />${result.body}`;
139
+ }
140
+ export function addScale(result, scale) {
141
+ let { width, height, x, y } = getViewBox(result);
142
+ let percent = scale ? (scale - 100) / 100 : 0;
143
+ let translateX = (width / 2 + x) * percent * -1;
144
+ let translateY = (height / 2 + y) * percent * -1;
145
+ return `<g transform="translate(${translateX} ${translateY}) scale(${scale / 100})">${result.body}</g>`;
146
+ }
147
+ export function addTranslate(result, x, y) {
148
+ let viewBox = getViewBox(result);
149
+ let translateX = (viewBox.width + viewBox.x * 2) * ((x !== null && x !== void 0 ? x : 0) / 100);
150
+ let translateY = (viewBox.height + viewBox.y * 2) * ((y !== null && y !== void 0 ? y : 0) / 100);
151
+ return `<g transform="translate(${translateX} ${translateY})">${result.body}</g>`;
152
+ }
153
+ export function addRotate(result, rotate) {
154
+ let { width, height, x, y } = getViewBox(result);
155
+ return `<g transform="rotate(${rotate}, ${width / 2 + x}, ${height / 2 + y})">${result.body}</g>`;
156
+ }
157
+ export function addFlip(result) {
158
+ let { width, x } = getViewBox(result);
159
+ return `<g transform="scale(-1 1) translate(${width * -1 - x * 2} 0)">${result.body}</g>`;
160
+ }
161
+ export function addViewboxMask(result, radius) {
162
+ let { width, height, x, y } = getViewBox(result);
163
+ let rx = radius ? (width * radius) / 100 : 0;
164
+ let ry = radius ? (height * radius) / 100 : 0;
165
+ return (`<mask id="viewboxMask">` +
166
+ `<rect width="${width}" height="${height}" rx="${rx}" ry="${ry}" x="${x}" y="${y}" fill="#fff" />` +
167
+ `</mask>` +
168
+ `<g mask="url(#viewboxMask)">${result.body}</g>`);
169
+ }
170
+ export function createAttrString(attributes) {
171
+ attributes = { ...getXmlnsAttributes(), ...attributes };
172
+ return Object.keys(attributes)
173
+ .map((attr) => `${escape.xml(attr)}="${escape.xml(attributes[attr])}"`)
174
+ .join(' ');
175
+ }
176
+ export function convertToDataUri(svg) {
177
+ return `data:image/svg+xml;utf8,${encodeURIComponent(svg)}`;
178
+ }