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