@dicebear/core 5.0.0-alpha.2 → 5.0.0-alpha.24

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.
package/dist/index.js DELETED
@@ -1,530 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var type = "object";
6
- var $schema = "http://json-schema.org/draft-07/schema#";
7
- var title = "Options";
8
- var properties$1 = {
9
- seed: {
10
- type: "string"
11
- },
12
- dataUri: {
13
- type: "boolean",
14
- "default": false
15
- },
16
- flip: {
17
- type: "boolean",
18
- "default": false
19
- },
20
- rotate: {
21
- type: "integer",
22
- minimum: 0,
23
- maximum: 360,
24
- "default": 0
25
- },
26
- scale: {
27
- type: "integer",
28
- minimum: 0,
29
- maximum: 200,
30
- "default": 100
31
- },
32
- radius: {
33
- type: "integer",
34
- minimum: 0,
35
- maximum: 50,
36
- "default": 0
37
- },
38
- size: {
39
- type: "integer",
40
- minimum: 1
41
- },
42
- backgroundColor: {
43
- type: "array",
44
- items: {
45
- anyOf: [
46
- {
47
- type: "string",
48
- pattern: "^#([a-fA-F0-9]{3}|[a-fA-F0-9]{4}|[a-fA-F0-9]{6}|[a-fA-F0-9]{8})$"
49
- },
50
- {
51
- type: "string",
52
- pattern: "^[0-9a-zA-Z]+$"
53
- }
54
- ]
55
- }
56
- },
57
- translateX: {
58
- type: "integer",
59
- minimum: -100,
60
- maximum: 100,
61
- "default": 0
62
- },
63
- translateY: {
64
- type: "integer",
65
- minimum: -100,
66
- maximum: 100,
67
- "default": 0
68
- },
69
- clip: {
70
- type: "boolean",
71
- "default": true
72
- }
73
- };
74
- var additionalProperties = false;
75
- var untypedSchema = {
76
- type: type,
77
- $schema: $schema,
78
- title: title,
79
- properties: properties$1,
80
- additionalProperties: additionalProperties
81
- };
82
-
83
- function xml(attr) {
84
- return attr.replace(/&/g, '&amp;').replace(/'/g, '&apos;').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
85
- }
86
-
87
- var _escape = /*#__PURE__*/Object.freeze({
88
- __proto__: null,
89
- xml: xml
90
- });
91
-
92
- function properties(schema) {
93
- var _schema$properties;
94
-
95
- return (_schema$properties = schema.properties) !== null && _schema$properties !== void 0 ? _schema$properties : {};
96
- }
97
- function defaults(schema) {
98
- let result = {};
99
- let props = properties(schema);
100
- Object.keys(props).forEach(key => {
101
- let val = props[key];
102
-
103
- if (typeof val === 'object' && undefined !== val.default) {
104
- result[key] = val.default;
105
- }
106
- });
107
- return result;
108
- }
109
-
110
- var schema$1 = /*#__PURE__*/Object.freeze({
111
- __proto__: null,
112
- properties: properties,
113
- defaults: defaults
114
- });
115
-
116
- function merge(style, options) {
117
- let result = { ...{
118
- seed: Math.random().toString()
119
- },
120
- ...defaults(untypedSchema),
121
- ...defaults(style.schema),
122
- ...options
123
- };
124
- return result;
125
- }
126
-
127
- var options = /*#__PURE__*/Object.freeze({
128
- __proto__: null,
129
- merge: merge
130
- });
131
-
132
- const MIN = -2147483648;
133
- const MAX = 2147483647;
134
-
135
- function xorshift(value) {
136
- value ^= value << 13;
137
- value ^= value >> 17;
138
- value ^= value << 5;
139
- return value;
140
- }
141
-
142
- function hashSeed(seed) {
143
- let hash = 0;
144
-
145
- for (let i = 0; i < seed.length; i++) {
146
- hash = (hash << 5) - hash + seed.charCodeAt(i) | 0;
147
- hash = xorshift(hash);
148
- }
149
-
150
- return hash;
151
- }
152
-
153
- function randomSeed() {
154
- return MIN + Math.floor((MAX - MIN) * Math.random()).toString();
155
- }
156
-
157
- function create(seed) {
158
- var _seed;
159
-
160
- seed = (_seed = seed) !== null && _seed !== void 0 ? _seed : randomSeed();
161
- let value = hashSeed(seed) || 1;
162
-
163
- const next = () => value = xorshift(value);
164
-
165
- const integer = (min, max) => {
166
- return Math.floor((next() - MIN) / (MAX - MIN) * (max + 1 - min) + min);
167
- };
168
-
169
- return {
170
- seed,
171
-
172
- bool() {
173
- let likelihood = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 50;
174
- return integer(0, 100) < likelihood;
175
- },
176
-
177
- integer(min, max) {
178
- return integer(min, max);
179
- },
180
-
181
- pick(arr) {
182
- return arr[integer(0, arr.length - 1)];
183
- }
184
-
185
- };
186
- }
187
-
188
- var prng = /*#__PURE__*/Object.freeze({
189
- __proto__: null,
190
- create: create
191
- });
192
-
193
- const ccLicenses = {
194
- by: {
195
- permits: ['Reproduction', 'Distribution', 'DerivativeWorks'],
196
- requires: ['Notice', 'Attribution'],
197
- prohibits: []
198
- },
199
- 'by-sa': {
200
- permits: ['Reproduction', 'Distribution', 'DerivativeWorks'],
201
- requires: ['Notice', 'Attribution', 'ShareAlike'],
202
- prohibits: []
203
- },
204
- 'by-nd': {
205
- permits: ['Reproduction', 'Distribution'],
206
- requires: ['Notice', 'Attribution'],
207
- prohibits: []
208
- },
209
- 'by-nc': {
210
- permits: ['Reproduction', 'Distribution', 'DerivativeWorks'],
211
- requires: ['Notice', 'Attribution'],
212
- prohibits: ['CommercialUse']
213
- },
214
- 'by-nc-sa': {
215
- permits: ['Reproduction', 'Distribution', 'DerivativeWorks'],
216
- requires: ['Notice', 'Attribution', 'ShareAlike'],
217
- prohibits: ['CommercialUse']
218
- },
219
- 'by-nc-nd': {
220
- permits: ['Reproduction', 'Distribution'],
221
- requires: ['Notice', 'Attribution'],
222
- prohibits: ['CommercialUse']
223
- },
224
- zero: {
225
- permits: ['Reproduction', 'Distribution', 'DerivativeWorks'],
226
- requires: [],
227
- prohibits: []
228
- }
229
- };
230
- function createGroup(_ref) {
231
- let {
232
- children,
233
- x,
234
- y
235
- } = _ref;
236
- return "<g transform=\"translate(".concat(x, ", ").concat(y, ")\">").concat(children, "</g>");
237
- }
238
- function getXmlnsAttributes() {
239
- return {
240
- 'xmlns:dc': 'http://purl.org/dc/elements/1.1/',
241
- 'xmlns:cc': 'http://creativecommons.org/ns#',
242
- 'xmlns:rdf': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
243
- 'xmlns:svg': 'http://www.w3.org/2000/svg',
244
- xmlns: 'http://www.w3.org/2000/svg'
245
- };
246
- }
247
- function getMetadata(style) {
248
- return "\n<metadata>\n<rdf:RDF>\n<cc:Work>\n<dc:format>image/svg+xml</dc:format>\n<dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\" />\n".concat(getMetadataWorkTitle(style), "\n").concat(getMetadataWorkCreator(style), "\n").concat(getMetadataWorkSource(style), "\n").concat(getMetadataWorkLicense(style), "\n").concat(getMetadataWorkContributor(style), "\n</cc:Work>\n").concat(getMetadataLicense(style), "\n</rdf:RDF>\n</metadata>\n");
249
- }
250
- function getMetadataWorkTitle(style) {
251
- if (style.meta.title) {
252
- return "<dc:title>".concat(style.meta.title, "</dc:title>");
253
- }
254
-
255
- return '';
256
- }
257
- function getMetadataWorkCreator(style) {
258
- if (style.meta.creator) {
259
- let creators = Array.isArray(style.meta.creator) ? style.meta.creator : [style.meta.creator];
260
- return "\n<dc:creator>\n".concat(getMetadataWorkAgents(creators), "\n</dc:creator>\n");
261
- }
262
-
263
- return '';
264
- }
265
- function getMetadataWorkSource(style) {
266
- if (style.meta.source) {
267
- return "<dc:source>".concat(style.meta.source, "</dc:source>");
268
- }
269
-
270
- return '';
271
- }
272
- function getMetadataWorkLicense(style) {
273
- if (style.meta.license) {
274
- return "<cc:license rdf:resource=\"".concat(style.meta.license.url, "\" />");
275
- }
276
-
277
- return '';
278
- }
279
- function getMetadataWorkContributor(style) {
280
- if (style.meta.contributor) {
281
- let contributors = Array.isArray(style.meta.contributor) ? style.meta.contributor : [style.meta.contributor];
282
- return "\n<dc:contributor>\n".concat(getMetadataWorkAgents(contributors), "\n</dc:contributor>\n");
283
- }
284
-
285
- return '';
286
- }
287
- function getMetadataWorkAgents(agents) {
288
- return agents.map(agent => "\n<cc:Agent>\n<dc:title>".concat(agent, "</dc:title>\n</cc:Agent>\n"));
289
- }
290
- function getMetadataLicense(style) {
291
- var _style$meta$license;
292
-
293
- let match = (_style$meta$license = style.meta.license) === null || _style$meta$license === void 0 ? void 0 : _style$meta$license.url.match(/^https?:\/\/creativecommons.org\/(?:licenses|publicdomain)\/([a-z\-]+)\/\d.\d\//);
294
-
295
- if (match) {
296
- let license = ccLicenses[match[1]];
297
-
298
- if (license) {
299
- var _style$meta$license2;
300
-
301
- let result = "";
302
- license.permits.forEach(permits => {
303
- result += "<cc:permits rdf:resource=\"https://creativecommons.org/ns#".concat(permits, "\" />");
304
- });
305
- license.requires.forEach(requires => {
306
- result += "<cc:requires rdf:resource=\"https://creativecommons.org/ns#".concat(requires, "\" />");
307
- });
308
- license.prohibits.forEach(prohibits => {
309
- result += "<cc:prohibits rdf:resource=\"https://creativecommons.org/ns#".concat(prohibits, "\" />");
310
- });
311
- return "\n<cc:License rdf:about=\"".concat((_style$meta$license2 = style.meta.license) === null || _style$meta$license2 === void 0 ? void 0 : _style$meta$license2.url, "\">\n").concat(result, "\n</cc:License>\n");
312
- }
313
- }
314
-
315
- return '';
316
- }
317
- function getViewBox(result) {
318
- let viewBox = result.attributes['viewBox'].split(' ');
319
- let x = parseInt(viewBox[0]);
320
- let y = parseInt(viewBox[1]);
321
- let width = parseInt(viewBox[2]);
322
- let height = parseInt(viewBox[3]);
323
- return {
324
- x,
325
- y,
326
- width,
327
- height
328
- };
329
- }
330
- function addBackgroundColor(result, backgroundColor) {
331
- let {
332
- width,
333
- height,
334
- x,
335
- y
336
- } = getViewBox(result);
337
- return "\n<rect fill=\"".concat(backgroundColor, "\" width=\"").concat(width, "\" height=\"").concat(height, "\" x=\"").concat(x, "\" y=\"").concat(y, "\" />\n").concat(result.body, "\n");
338
- }
339
- function addScale(result, scale) {
340
- let {
341
- width,
342
- height,
343
- x,
344
- y
345
- } = getViewBox(result);
346
- let percent = scale ? (scale - 100) / 100 : 0;
347
- let translateX = (width / 2 + x) * percent * -1;
348
- let translateY = (height / 2 + y) * percent * -1;
349
- return "\n<g transform=\"translate(".concat(translateX, " ").concat(translateY, ") scale(").concat(scale / 100, ")\">\n").concat(result.body, "\n</g>\n");
350
- }
351
- function addTranslate(result, x, y) {
352
- let viewBox = getViewBox(result);
353
- let translateX = (viewBox.width + viewBox.x * 2) * ((x !== null && x !== void 0 ? x : 0) / 100);
354
- let translateY = (viewBox.height + viewBox.y * 2) * ((y !== null && y !== void 0 ? y : 0) / 100);
355
- return "\n<g transform=\"translate(".concat(translateX, " ").concat(translateY, ")\">\n").concat(result.body, "\n</g>\n");
356
- }
357
- function addRotate(result, rotate) {
358
- let {
359
- width,
360
- height,
361
- x,
362
- y
363
- } = getViewBox(result);
364
- return "\n<g transform=\"rotate(".concat(rotate, ", ").concat(width / 2 + x, ", ").concat(height / 2 + y, ")\">\n").concat(result.body, "\n</g>\n");
365
- }
366
- function addFlip(result) {
367
- let {
368
- width,
369
- x
370
- } = getViewBox(result);
371
- return "\n<g transform=\"scale(-1 1) translate(".concat(width * -1 - x * 2, " 0)\">\n").concat(result.body, "\n</g>\n");
372
- }
373
- function addViewboxMask(result, radius) {
374
- let {
375
- width,
376
- height,
377
- x,
378
- y
379
- } = getViewBox(result);
380
- let rx = radius ? width * radius / 100 : 0;
381
- let ry = radius ? height * radius / 100 : 0;
382
- return "\n<mask id=\"viewboxMask\">\n<rect width=\"".concat(width, "\" height=\"").concat(height, "\" rx=\"").concat(rx, "\" ry=\"").concat(ry, "\" x=\"").concat(x, "\" y=\"").concat(y, "\" fill=\"#fff\" />\n</mask>\n<g mask=\"url(#viewboxMask)\">").concat(result.body, "</g>\n");
383
- }
384
- function createAttrString(attributes) {
385
- attributes = { ...getXmlnsAttributes(),
386
- ...attributes
387
- };
388
- return Object.keys(attributes).map(attr => "".concat(xml(attr), "=\"").concat(xml(attributes[attr]), "\"")).join(' ');
389
- }
390
- function removeWhitespace(svg) {
391
- return svg // Remove spaces at both ends of the string
392
- .trim() // Remove breaking lines
393
- .replace(/\n/g, ' ') // Remove space between tags
394
- .replace(/>\s+</g, '><') // Reduce whitespace
395
- .replace(/\s{2,}/g, ' ') // Create self closing tags
396
- .replace(/<([^\/>]+)><\/[^>]+>/gi, '<$1/>') // Remove whitespace before tag close
397
- .replace(/\s(\/?>)/g, '$1');
398
- }
399
- function convertToDataUri(svg) {
400
- return "data:image/svg+xml;utf8,".concat(encodeURIComponent(svg));
401
- }
402
-
403
- var svg = /*#__PURE__*/Object.freeze({
404
- __proto__: null,
405
- createGroup: createGroup,
406
- getXmlnsAttributes: getXmlnsAttributes,
407
- getMetadata: getMetadata,
408
- getMetadataWorkTitle: getMetadataWorkTitle,
409
- getMetadataWorkCreator: getMetadataWorkCreator,
410
- getMetadataWorkSource: getMetadataWorkSource,
411
- getMetadataWorkLicense: getMetadataWorkLicense,
412
- getMetadataWorkContributor: getMetadataWorkContributor,
413
- getMetadataWorkAgents: getMetadataWorkAgents,
414
- getMetadataLicense: getMetadataLicense,
415
- getViewBox: getViewBox,
416
- addBackgroundColor: addBackgroundColor,
417
- addScale: addScale,
418
- addTranslate: addTranslate,
419
- addRotate: addRotate,
420
- addFlip: addFlip,
421
- addViewboxMask: addViewboxMask,
422
- createAttrString: createAttrString,
423
- removeWhitespace: removeWhitespace,
424
- convertToDataUri: convertToDataUri
425
- });
426
-
427
- var index = /*#__PURE__*/Object.freeze({
428
- __proto__: null,
429
- escape: _escape,
430
- options: options,
431
- prng: prng,
432
- svg: svg,
433
- schema: schema$1
434
- });
435
-
436
- function createAvatar(style) {
437
- var _options$backgroundCo;
438
-
439
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
440
- options = merge(style, options);
441
- const prng = create(options.seed);
442
- const result = style.create({
443
- prng: prng,
444
- options
445
- });
446
- const backgroundColor = prng.pick((_options$backgroundCo = options.backgroundColor) !== null && _options$backgroundCo !== void 0 ? _options$backgroundCo : []);
447
-
448
- if (options.size) {
449
- result.attributes.width = options.size.toString();
450
- result.attributes.height = options.size.toString();
451
- }
452
-
453
- if (options.scale !== undefined && options.scale !== 100) {
454
- result.body = addScale(result, options.scale);
455
- }
456
-
457
- if (options.flip) {
458
- result.body = addFlip(result);
459
- }
460
-
461
- if (options.rotate) {
462
- result.body = addRotate(result, options.rotate);
463
- }
464
-
465
- if (options.translateX || options.translateY) {
466
- result.body = addTranslate(result, options.translateX, options.translateY);
467
- }
468
-
469
- if (backgroundColor && backgroundColor !== 'transparent') {
470
- result.body = addBackgroundColor(result, backgroundColor);
471
- }
472
-
473
- if (options.radius || options.clip) {
474
- var _options$radius;
475
-
476
- result.body = addViewboxMask(result, (_options$radius = options.radius) !== null && _options$radius !== void 0 ? _options$radius : 0);
477
- }
478
-
479
- let avatar = removeWhitespace("\n<svg ".concat(createAttrString(result.attributes), ">\n").concat(getMetadata(style), "\n").concat(result.body, "\n</svg>\n"));
480
- return options.dataUri ? convertToDataUri(avatar) : avatar;
481
- }
482
- function createPreview(style, options, property) {
483
- var _style$preview, _options$backgroundCo2;
484
-
485
- options = merge(style, options);
486
- const prng = create(options.seed);
487
- let result = (_style$preview = style.preview) === null || _style$preview === void 0 ? void 0 : _style$preview.call(style, {
488
- prng,
489
- options,
490
- property
491
- });
492
- const backgroundColor = prng.pick((_options$backgroundCo2 = options.backgroundColor) !== null && _options$backgroundCo2 !== void 0 ? _options$backgroundCo2 : []);
493
- const hasBackgroundColor = backgroundColor && backgroundColor !== 'transparent';
494
- const isBackgroundVisible = property === 'backgroundColor';
495
-
496
- if (undefined === result) {
497
- if (hasBackgroundColor && isBackgroundVisible) {
498
- result = {
499
- attributes: {
500
- viewBox: "0 0 1 1",
501
- fill: 'none',
502
- 'shape-rendering': 'auto'
503
- },
504
- body: ""
505
- };
506
- } else {
507
- return undefined;
508
- }
509
- }
510
-
511
- if (hasBackgroundColor && isBackgroundVisible) {
512
- result.body = addBackgroundColor(result, backgroundColor);
513
- }
514
-
515
- let avatar = removeWhitespace("\n<svg ".concat(createAttrString(result.attributes), ">\n").concat(getMetadata(style), "\n").concat(result.body, "\n</svg>\n"));
516
- return options.dataUri ? convertToDataUri(avatar) : avatar;
517
- }
518
-
519
- /*!
520
- * DiceBear (@dicebear/core)
521
- *
522
- * Code licensed under MIT (https://github.com/dicebear/dicebear/blob/main/LICENSE)
523
- * Copyright (c) 2021 Florian Körner
524
- */
525
- const schema = untypedSchema;
526
-
527
- exports.createAvatar = createAvatar;
528
- exports.createPreview = createPreview;
529
- exports.schema = schema;
530
- exports.utils = index;
package/dist/index.umd.js DELETED
@@ -1,8 +0,0 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).DiceBear={})}(this,(function(t){"use strict";var e={type:"object",$schema:"http://json-schema.org/draft-07/schema#",title:"Options",properties:{seed:{type:"string"},dataUri:{type:"boolean",default:!1},flip:{type:"boolean",default:!1},rotate:{type:"integer",minimum:0,maximum:360,default:0},scale:{type:"integer",minimum:0,maximum:200,default:100},radius:{type:"integer",minimum:0,maximum:50,default:0},size:{type:"integer",minimum:1},backgroundColor:{type:"array",items:{anyOf:[{type:"string",pattern:"^#([a-fA-F0-9]{3}|[a-fA-F0-9]{4}|[a-fA-F0-9]{6}|[a-fA-F0-9]{8})$"},{type:"string",pattern:"^[0-9a-zA-Z]+$"}]}},translateX:{type:"integer",minimum:-100,maximum:100,default:0},translateY:{type:"integer",minimum:-100,maximum:100,default:0},clip:{type:"boolean",default:!0}},additionalProperties:!1};function r(t){return t.replace(/&/g,"&amp;").replace(/'/g,"&apos;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}var n=Object.freeze({__proto__:null,xml:r});function o(t){var e;return null!==(e=t.properties)&&void 0!==e?e:{}}function c(t){let e={},r=o(t);return Object.keys(r).forEach((t=>{let n=r[t];"object"==typeof n&&void 0!==n.default&&(e[t]=n.default)})),e}var a=Object.freeze({__proto__:null,properties:o,defaults:c});function i(t,r){return{seed:Math.random().toString(),...c(e),...c(t.schema),...r}}var s=Object.freeze({__proto__:null,merge:i});const u=-2147483648,l=2147483647;function d(t){return t^=t<<13,t^=t>>17,t^=t<<5}function p(t){var e;let r=function(t){let e=0;for(let r=0;r<t.length;r++)e=(e<<5)-e+t.charCodeAt(r)|0,e=d(e);return e}(t=null!==(e=t)&&void 0!==e?e:u+Math.floor((l-u)*Math.random()).toString())||1;const n=(t,e)=>Math.floor(((r=d(r))-u)/(l-u)*(e+1-t)+t);return{seed:t,bool(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:50;return n(0,100)<t},integer:(t,e)=>n(t,e),pick:t=>t[n(0,t.length-1)]}}var m=Object.freeze({__proto__:null,create:p});const f={by:{permits:["Reproduction","Distribution","DerivativeWorks"],requires:["Notice","Attribution"],prohibits:[]},"by-sa":{permits:["Reproduction","Distribution","DerivativeWorks"],requires:["Notice","Attribution","ShareAlike"],prohibits:[]},"by-nd":{permits:["Reproduction","Distribution"],requires:["Notice","Attribution"],prohibits:[]},"by-nc":{permits:["Reproduction","Distribution","DerivativeWorks"],requires:["Notice","Attribution"],prohibits:["CommercialUse"]},"by-nc-sa":{permits:["Reproduction","Distribution","DerivativeWorks"],requires:["Notice","Attribution","ShareAlike"],prohibits:["CommercialUse"]},"by-nc-nd":{permits:["Reproduction","Distribution"],requires:["Notice","Attribution"],prohibits:["CommercialUse"]},zero:{permits:["Reproduction","Distribution","DerivativeWorks"],requires:[],prohibits:[]}};function g(){return{"xmlns:dc":"http://purl.org/dc/elements/1.1/","xmlns:cc":"http://creativecommons.org/ns#","xmlns:rdf":"http://www.w3.org/1999/02/22-rdf-syntax-ns#","xmlns:svg":"http://www.w3.org/2000/svg",xmlns:"http://www.w3.org/2000/svg"}}function b(t){return'\n<metadata>\n<rdf:RDF>\n<cc:Work>\n<dc:format>image/svg+xml</dc:format>\n<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" />\n'.concat(h(t),"\n").concat(v(t),"\n").concat(y(t),"\n").concat(w(t),"\n").concat(x(t),"\n</cc:Work>\n").concat(_(t),"\n</rdf:RDF>\n</metadata>\n")}function h(t){return t.meta.title?"<dc:title>".concat(t.meta.title,"</dc:title>"):""}function v(t){if(t.meta.creator){let e=Array.isArray(t.meta.creator)?t.meta.creator:[t.meta.creator];return"\n<dc:creator>\n".concat(k(e),"\n</dc:creator>\n")}return""}function y(t){return t.meta.source?"<dc:source>".concat(t.meta.source,"</dc:source>"):""}function w(t){return t.meta.license?'<cc:license rdf:resource="'.concat(t.meta.license.url,'" />'):""}function x(t){if(t.meta.contributor){let e=Array.isArray(t.meta.contributor)?t.meta.contributor:[t.meta.contributor];return"\n<dc:contributor>\n".concat(k(e),"\n</dc:contributor>\n")}return""}function k(t){return t.map((t=>"\n<cc:Agent>\n<dc:title>".concat(t,"</dc:title>\n</cc:Agent>\n")))}function _(t){var e;let r=null===(e=t.meta.license)||void 0===e?void 0:e.url.match(/^https?:\/\/creativecommons.org\/(?:licenses|publicdomain)\/([a-z\-]+)\/\d.\d\//);if(r){let e=f[r[1]];if(e){var n;let r="";return e.permits.forEach((t=>{r+='<cc:permits rdf:resource="https://creativecommons.org/ns#'.concat(t,'" />')})),e.requires.forEach((t=>{r+='<cc:requires rdf:resource="https://creativecommons.org/ns#'.concat(t,'" />')})),e.prohibits.forEach((t=>{r+='<cc:prohibits rdf:resource="https://creativecommons.org/ns#'.concat(t,'" />')})),'\n<cc:License rdf:about="'.concat(null===(n=t.meta.license)||void 0===n?void 0:n.url,'">\n').concat(r,"\n</cc:License>\n")}}return""}function A(t){let e=t.attributes.viewBox.split(" ");return{x:parseInt(e[0]),y:parseInt(e[1]),width:parseInt(e[2]),height:parseInt(e[3])}}function D(t,e){let{width:r,height:n,x:o,y:c}=A(t);return'\n<rect fill="'.concat(e,'" width="').concat(r,'" height="').concat(n,'" x="').concat(o,'" y="').concat(c,'" />\n').concat(t.body,"\n")}function M(t,e){let{width:r,height:n,x:o,y:c}=A(t),a=e?(e-100)/100:0,i=(n/2+c)*a*-1;return'\n<g transform="translate('.concat((r/2+o)*a*-1," ").concat(i,") scale(").concat(e/100,')">\n').concat(t.body,"\n</g>\n")}function j(t,e,r){let n=A(t),o=(n.width+2*n.x)*((null!=e?e:0)/100),c=(n.height+2*n.y)*((null!=r?r:0)/100);return'\n<g transform="translate('.concat(o," ").concat(c,')">\n').concat(t.body,"\n</g>\n")}function W(t,e){let{width:r,height:n,x:o,y:c}=A(t);return'\n<g transform="rotate('.concat(e,", ").concat(r/2+o,", ").concat(n/2+c,')">\n').concat(t.body,"\n</g>\n")}function z(t){let{width:e,x:r}=A(t);return'\n<g transform="scale(-1 1) translate('.concat(-1*e-2*r,' 0)">\n').concat(t.body,"\n</g>\n")}function C(t,e){let{width:r,height:n,x:o,y:c}=A(t),a=e?r*e/100:0,i=e?n*e/100:0;return'\n<mask id="viewboxMask">\n<rect width="'.concat(r,'" height="').concat(n,'" rx="').concat(a,'" ry="').concat(i,'" x="').concat(o,'" y="').concat(c,'" fill="#fff" />\n</mask>\n<g mask="url(#viewboxMask)">').concat(t.body,"</g>\n")}function O(t){return t={"xmlns:dc":"http://purl.org/dc/elements/1.1/","xmlns:cc":"http://creativecommons.org/ns#","xmlns:rdf":"http://www.w3.org/1999/02/22-rdf-syntax-ns#","xmlns:svg":"http://www.w3.org/2000/svg",xmlns:"http://www.w3.org/2000/svg",...t},Object.keys(t).map((e=>"".concat(r(e),'="').concat(r(t[e]),'"'))).join(" ")}function R(t){return t.trim().replace(/\n/g," ").replace(/>\s+</g,"><").replace(/\s{2,}/g," ").replace(/<([^\/>]+)><\/[^>]+>/gi,"<$1/>").replace(/\s(\/?>)/g,"$1")}function q(t){return"data:image/svg+xml;utf8,".concat(encodeURIComponent(t))}var S=Object.freeze({__proto__:null,createGroup:function(t){let{children:e,x:r,y:n}=t;return'<g transform="translate('.concat(r,", ").concat(n,')">').concat(e,"</g>")},getXmlnsAttributes:g,getMetadata:b,getMetadataWorkTitle:h,getMetadataWorkCreator:v,getMetadataWorkSource:y,getMetadataWorkLicense:w,getMetadataWorkContributor:x,getMetadataWorkAgents:k,getMetadataLicense:_,getViewBox:A,addBackgroundColor:D,addScale:M,addTranslate:j,addRotate:W,addFlip:z,addViewboxMask:C,createAttrString:O,removeWhitespace:R,convertToDataUri:q}),U=Object.freeze({__proto__:null,escape:n,options:s,prng:m,svg:S,schema:a});
2
- /*!
3
- * DiceBear (@dicebear/core)
4
- *
5
- * Code licensed under MIT (https://github.com/dicebear/dicebear/blob/main/LICENSE)
6
- * Copyright (c) 2021 Florian Körner
7
- */
8
- const F=e;t.createAvatar=function(t){var e;let r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};r=i(t,r);const n=p(r.seed),o=t.create({prng:n,options:r}),c=n.pick(null!==(e=r.backgroundColor)&&void 0!==e?e:[]);var a;r.size&&(o.attributes.width=r.size.toString(),o.attributes.height=r.size.toString()),void 0!==r.scale&&100!==r.scale&&(o.body=M(o,r.scale)),r.flip&&(o.body=z(o)),r.rotate&&(o.body=W(o,r.rotate)),(r.translateX||r.translateY)&&(o.body=j(o,r.translateX,r.translateY)),c&&"transparent"!==c&&(o.body=D(o,c)),(r.radius||r.clip)&&(o.body=C(o,null!==(a=r.radius)&&void 0!==a?a:0));let s=R("\n<svg ".concat(O(o.attributes),">\n").concat(b(t),"\n").concat(o.body,"\n</svg>\n"));return r.dataUri?q(s):s},t.createPreview=function(t,e,r){var n,o;const c=p((e=i(t,e)).seed);let a=null===(n=t.preview)||void 0===n?void 0:n.call(t,{prng:c,options:e,property:r});const s=c.pick(null!==(o=e.backgroundColor)&&void 0!==o?o:[]),u=s&&"transparent"!==s,l="backgroundColor"===r;if(void 0===a){if(!u||!l)return;a={attributes:{viewBox:"0 0 1 1",fill:"none","shape-rendering":"auto"},body:""}}u&&l&&(a.body=D(a,s));let d=R("\n<svg ".concat(O(a.attributes),">\n").concat(b(t),"\n").concat(a.body,"\n</svg>\n"));return e.dataUri?q(d):d},t.schema=F,t.utils=U,Object.defineProperty(t,"__esModule",{value:!0})}));
package/dist/options.d.ts DELETED
@@ -1,18 +0,0 @@
1
- /**
2
- * This file was automatically generated by json-schema-to-typescript.
3
- * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
4
- * and run json-schema-to-typescript to regenerate this file.
5
- */
6
- export interface Options {
7
- seed?: string;
8
- dataUri?: boolean;
9
- flip?: boolean;
10
- rotate?: number;
11
- scale?: number;
12
- radius?: number;
13
- size?: number;
14
- backgroundColor?: (string | string)[];
15
- translateX?: number;
16
- translateY?: number;
17
- clip?: boolean;
18
- }
@@ -1 +0,0 @@
1
- export declare function xml(attr: string): string;
@@ -1,5 +0,0 @@
1
- export * as escape from './escape';
2
- export * as options from './options';
3
- export * as prng from './prng';
4
- export * as svg from './svg';
5
- export * as schema from './schema';
@@ -1,2 +0,0 @@
1
- import type { Style, StyleOptions } from '../types';
2
- export declare function merge<O extends {}>(style: Style<O>, options: StyleOptions<O>): StyleOptions<O>;
@@ -1,5 +0,0 @@
1
- import { StyleSchema } from '../types';
2
- export declare function properties(schema: StyleSchema): {
3
- [key: string]: import("json-schema").JSONSchema7Definition;
4
- };
5
- export declare function defaults(schema: StyleSchema): Record<string, unknown>;
@@ -1,39 +0,0 @@
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 {};