@5even7/dlc-ui 0.1.0 → 0.2.1
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/CHANGELOG.md +33 -3
- package/README.md +277 -248
- package/dist/capsule.cjs +421 -103
- package/dist/capsule.mjs +481 -197
- package/dist/color.cjs +342 -37
- package/dist/color.mjs +390 -105
- package/dist/index.cjs +745 -203
- package/dist/index.mjs +923 -457
- package/dist/index.umd.js +745 -203
- package/dist/index.umd.min.js +1 -1
- package/dist/progress.cjs +487 -116
- package/dist/progress.mjs +568 -245
- package/dist/vue2.cjs +1092 -208
- package/dist/vue2.mjs +1280 -501
- package/dist/vue3.cjs +1092 -208
- package/dist/vue3.mjs +1280 -501
- package/package.json +1 -1
- package/styles/base.css +12 -18
- package/styles/capsule.css +34 -81
- package/styles/progress.css +37 -57
- package/types/index.d.ts +97 -81
- package/types/vue3.d.ts +59 -20
package/dist/color.cjs
CHANGED
|
@@ -296,7 +296,7 @@ var PALETTES = {
|
|
|
296
296
|
var CAPSULE_PRESETS = [{
|
|
297
297
|
id: 'original',
|
|
298
298
|
code: 'NC-01',
|
|
299
|
-
name: '
|
|
299
|
+
name: '初光',
|
|
300
300
|
group: 'warm',
|
|
301
301
|
seed: 1.7,
|
|
302
302
|
speed: 0.5,
|
|
@@ -304,7 +304,7 @@ var CAPSULE_PRESETS = [{
|
|
|
304
304
|
}, {
|
|
305
305
|
id: 'ocean',
|
|
306
306
|
code: 'NC-02',
|
|
307
|
-
name: '
|
|
307
|
+
name: '沧溟',
|
|
308
308
|
group: 'cold',
|
|
309
309
|
seed: 8.2,
|
|
310
310
|
speed: 0.48,
|
|
@@ -312,7 +312,7 @@ var CAPSULE_PRESETS = [{
|
|
|
312
312
|
}, {
|
|
313
313
|
id: 'klein',
|
|
314
314
|
code: 'NC-03',
|
|
315
|
-
name: '
|
|
315
|
+
name: '玄夜',
|
|
316
316
|
group: 'cold',
|
|
317
317
|
seed: 14.1,
|
|
318
318
|
speed: 0.49,
|
|
@@ -320,7 +320,7 @@ var CAPSULE_PRESETS = [{
|
|
|
320
320
|
}, {
|
|
321
321
|
id: 'ultraviolet',
|
|
322
322
|
code: 'NC-04',
|
|
323
|
-
name: '
|
|
323
|
+
name: '紫霄',
|
|
324
324
|
group: 'cold',
|
|
325
325
|
seed: 23.4,
|
|
326
326
|
speed: 0.47,
|
|
@@ -328,7 +328,7 @@ var CAPSULE_PRESETS = [{
|
|
|
328
328
|
}, {
|
|
329
329
|
id: 'chrome',
|
|
330
330
|
code: 'NC-05',
|
|
331
|
-
name: '
|
|
331
|
+
name: '银汉',
|
|
332
332
|
group: 'cold',
|
|
333
333
|
seed: 37.8,
|
|
334
334
|
speed: 0.42,
|
|
@@ -336,7 +336,7 @@ var CAPSULE_PRESETS = [{
|
|
|
336
336
|
}, {
|
|
337
337
|
id: 'plus',
|
|
338
338
|
code: 'NC-06',
|
|
339
|
-
name: '
|
|
339
|
+
name: '熔金',
|
|
340
340
|
group: 'warm',
|
|
341
341
|
seed: 51.3,
|
|
342
342
|
speed: 0.5,
|
|
@@ -346,7 +346,7 @@ var CAPSULE_PRESETS = [{
|
|
|
346
346
|
var PROGRESS_PRESETS = [{
|
|
347
347
|
id: 'model-training',
|
|
348
348
|
code: 'NC-10',
|
|
349
|
-
name: '
|
|
349
|
+
name: '星火',
|
|
350
350
|
subtitle: 'SHA 4.5 + 100 2026 TKN',
|
|
351
351
|
group: 'progress',
|
|
352
352
|
initialProgress: 43,
|
|
@@ -355,7 +355,7 @@ var PROGRESS_PRESETS = [{
|
|
|
355
355
|
}, {
|
|
356
356
|
id: 'agent-migration',
|
|
357
357
|
code: 'NC-11',
|
|
358
|
-
name: '
|
|
358
|
+
name: '迁流',
|
|
359
359
|
subtitle: 'TRANSFERRING PROTOCOL',
|
|
360
360
|
group: 'progress',
|
|
361
361
|
initialProgress: 33,
|
|
@@ -364,7 +364,7 @@ var PROGRESS_PRESETS = [{
|
|
|
364
364
|
}, {
|
|
365
365
|
id: 'visual-training',
|
|
366
366
|
code: 'NC-12',
|
|
367
|
-
name: '
|
|
367
|
+
name: '幻境',
|
|
368
368
|
subtitle: 'GENERATING POWER ++',
|
|
369
369
|
group: 'progress',
|
|
370
370
|
initialProgress: 58,
|
|
@@ -373,7 +373,7 @@ var PROGRESS_PRESETS = [{
|
|
|
373
373
|
}, {
|
|
374
374
|
id: 'tide',
|
|
375
375
|
code: 'NC-13',
|
|
376
|
-
name: '
|
|
376
|
+
name: '汐潮',
|
|
377
377
|
subtitle: 'MOON PULL / COAST',
|
|
378
378
|
group: 'progress',
|
|
379
379
|
initialProgress: 30,
|
|
@@ -382,20 +382,18 @@ var PROGRESS_PRESETS = [{
|
|
|
382
382
|
}];
|
|
383
383
|
|
|
384
384
|
[].concat(_toConsumableArray(CAPSULE_PRESETS), _toConsumableArray(PROGRESS_PRESETS));
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* Resolve a preset by its literary name (e.g. '沧溟').
|
|
388
|
+
* Matching is case-insensitive and ignores surrounding whitespace,
|
|
389
|
+
* so '沧溟' and ' 沧溟 ' both work.
|
|
390
|
+
*/
|
|
388
391
|
function getPreset(kind, ref) {
|
|
389
392
|
var list = CAPSULE_PRESETS ;
|
|
390
393
|
if (!list) throw new Error("Unknown preset kind: ".concat(kind, " (use \"capsule\" or \"progress\")"));
|
|
391
|
-
if (ref && _typeof(ref) === 'object') {
|
|
392
|
-
var valid = validatePreset(ref) ;
|
|
393
|
-
if (!valid) throw new Error("Invalid ".concat(kind, " preset object"));
|
|
394
|
-
return ref;
|
|
395
|
-
}
|
|
396
394
|
var key = String(ref).trim().toLowerCase();
|
|
397
395
|
var found = list.find(function (preset) {
|
|
398
|
-
return preset.
|
|
396
|
+
return preset.name.toLowerCase() === key;
|
|
399
397
|
});
|
|
400
398
|
if (!found) throw new Error("Unknown ".concat(kind, " preset: ").concat(ref));
|
|
401
399
|
return found;
|
|
@@ -407,9 +405,212 @@ var DEFAULTS = {
|
|
|
407
405
|
renderer: 'auto',
|
|
408
406
|
respectReducedMotion: true}};
|
|
409
407
|
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
408
|
+
/**
|
|
409
|
+
* Color helpers. `normalizeColor` converts any supported CSS color
|
|
410
|
+
* (hex / named / rgb() / rgba()) into a 6-digit hex string, so renderers can
|
|
411
|
+
* keep working with #rrggbb only. rgba() alpha is intentionally dropped:
|
|
412
|
+
* the WebGL shader has no per-color alpha channel, and the component is
|
|
413
|
+
* opaque by design — use component-level `opacity` for transparency.
|
|
414
|
+
*/
|
|
415
|
+
|
|
416
|
+
var NAMED_COLORS = {
|
|
417
|
+
aliceblue: '#f0f8ff',
|
|
418
|
+
antiquewhite: '#faebd7',
|
|
419
|
+
aqua: '#00ffff',
|
|
420
|
+
aquamarine: '#7fffd4',
|
|
421
|
+
azure: '#f0ffff',
|
|
422
|
+
beige: '#f5f5dc',
|
|
423
|
+
bisque: '#ffe4c4',
|
|
424
|
+
black: '#000000',
|
|
425
|
+
blanchedalmond: '#ffebcd',
|
|
426
|
+
blue: '#0000ff',
|
|
427
|
+
blueviolet: '#8a2be2',
|
|
428
|
+
brown: '#a52a2a',
|
|
429
|
+
burlywood: '#deb887',
|
|
430
|
+
cadetblue: '#5f9ea0',
|
|
431
|
+
chartreuse: '#7fff00',
|
|
432
|
+
chocolate: '#d2691e',
|
|
433
|
+
coral: '#ff7f50',
|
|
434
|
+
cornflowerblue: '#6495ed',
|
|
435
|
+
cornsilk: '#fff8dc',
|
|
436
|
+
crimson: '#dc143c',
|
|
437
|
+
cyan: '#00ffff',
|
|
438
|
+
darkblue: '#00008b',
|
|
439
|
+
darkcyan: '#008b8b',
|
|
440
|
+
darkgoldenrod: '#b8860b',
|
|
441
|
+
darkgray: '#a9a9a9',
|
|
442
|
+
darkgreen: '#006400',
|
|
443
|
+
darkgrey: '#a9a9a9',
|
|
444
|
+
darkkhaki: '#bdb76b',
|
|
445
|
+
darkmagenta: '#8b008b',
|
|
446
|
+
darkolivegreen: '#556b2f',
|
|
447
|
+
darkorange: '#ff8c00',
|
|
448
|
+
darkorchid: '#9932cc',
|
|
449
|
+
darkred: '#8b0000',
|
|
450
|
+
darksalmon: '#e9967a',
|
|
451
|
+
darkseagreen: '#8fbc8f',
|
|
452
|
+
darkslateblue: '#483d8b',
|
|
453
|
+
darkslategray: '#2f4f4f',
|
|
454
|
+
darkslategrey: '#2f4f4f',
|
|
455
|
+
darkturquoise: '#00ced1',
|
|
456
|
+
darkviolet: '#9400d3',
|
|
457
|
+
deeppink: '#ff1493',
|
|
458
|
+
deepskyblue: '#00bfff',
|
|
459
|
+
dimgray: '#696969',
|
|
460
|
+
dimgrey: '#696969',
|
|
461
|
+
dodgerblue: '#1e90ff',
|
|
462
|
+
firebrick: '#b22222',
|
|
463
|
+
floralwhite: '#fffaf0',
|
|
464
|
+
forestgreen: '#228b22',
|
|
465
|
+
fuchsia: '#ff00ff',
|
|
466
|
+
gainsboro: '#dcdcdc',
|
|
467
|
+
ghostwhite: '#f8f8ff',
|
|
468
|
+
gold: '#ffd700',
|
|
469
|
+
goldenrod: '#daa520',
|
|
470
|
+
gray: '#808080',
|
|
471
|
+
green: '#008000',
|
|
472
|
+
greenyellow: '#adff2f',
|
|
473
|
+
grey: '#808080',
|
|
474
|
+
honeydew: '#f0fff0',
|
|
475
|
+
hotpink: '#ff69b4',
|
|
476
|
+
indianred: '#cd5c5c',
|
|
477
|
+
indigo: '#4b0082',
|
|
478
|
+
ivory: '#fffff0',
|
|
479
|
+
khaki: '#f0e68c',
|
|
480
|
+
lavender: '#e6e6fa',
|
|
481
|
+
lavenderblush: '#fff0f5',
|
|
482
|
+
lawngreen: '#7cfc00',
|
|
483
|
+
lemonchiffon: '#fffacd',
|
|
484
|
+
lightblue: '#add8e6',
|
|
485
|
+
lightcoral: '#f08080',
|
|
486
|
+
lightcyan: '#e0ffff',
|
|
487
|
+
lightgoldenrodyellow: '#fafad2',
|
|
488
|
+
lightgray: '#d3d3d3',
|
|
489
|
+
lightgreen: '#90ee90',
|
|
490
|
+
lightgrey: '#d3d3d3',
|
|
491
|
+
lightpink: '#ffb6c1',
|
|
492
|
+
lightsalmon: '#ffa07a',
|
|
493
|
+
lightseagreen: '#20b2aa',
|
|
494
|
+
lightskyblue: '#87cefa',
|
|
495
|
+
lightslategray: '#778899',
|
|
496
|
+
lightslategrey: '#778899',
|
|
497
|
+
lightsteelblue: '#b0c4de',
|
|
498
|
+
lightyellow: '#ffffe0',
|
|
499
|
+
lime: '#00ff00',
|
|
500
|
+
limegreen: '#32cd32',
|
|
501
|
+
linen: '#faf0e6',
|
|
502
|
+
magenta: '#ff00ff',
|
|
503
|
+
maroon: '#800000',
|
|
504
|
+
mediumaquamarine: '#66cdaa',
|
|
505
|
+
mediumblue: '#0000cd',
|
|
506
|
+
mediumorchid: '#ba55d3',
|
|
507
|
+
mediumpurple: '#9370db',
|
|
508
|
+
mediumseagreen: '#3cb371',
|
|
509
|
+
mediumslateblue: '#7b68ee',
|
|
510
|
+
mediumspringgreen: '#00fa9a',
|
|
511
|
+
mediumturquoise: '#48d1cc',
|
|
512
|
+
mediumvioletred: '#c71585',
|
|
513
|
+
midnightblue: '#191970',
|
|
514
|
+
mintcream: '#f5fffa',
|
|
515
|
+
mistyrose: '#ffe4e1',
|
|
516
|
+
moccasin: '#ffe4b5',
|
|
517
|
+
navajowhite: '#ffdead',
|
|
518
|
+
navy: '#000080',
|
|
519
|
+
oldlace: '#fdf5e6',
|
|
520
|
+
olive: '#808000',
|
|
521
|
+
olivedrab: '#6b8e23',
|
|
522
|
+
orange: '#ffa500',
|
|
523
|
+
orangered: '#ff4500',
|
|
524
|
+
orchid: '#da70d6',
|
|
525
|
+
palegoldenrod: '#eee8aa',
|
|
526
|
+
palegreen: '#98fb98',
|
|
527
|
+
paleturquoise: '#afeeee',
|
|
528
|
+
palevioletred: '#db7093',
|
|
529
|
+
papayawhip: '#ffefd5',
|
|
530
|
+
peachpuff: '#ffdab9',
|
|
531
|
+
peru: '#cd853f',
|
|
532
|
+
pink: '#ffc0cb',
|
|
533
|
+
plum: '#dda0dd',
|
|
534
|
+
powderblue: '#b0e0e6',
|
|
535
|
+
purple: '#800080',
|
|
536
|
+
rebeccapurple: '#663399',
|
|
537
|
+
red: '#ff0000',
|
|
538
|
+
rosybrown: '#bc8f8f',
|
|
539
|
+
royalblue: '#4169e1',
|
|
540
|
+
saddlebrown: '#8b4513',
|
|
541
|
+
salmon: '#fa8072',
|
|
542
|
+
sandybrown: '#f4a460',
|
|
543
|
+
seagreen: '#2e8b57',
|
|
544
|
+
seashell: '#fff5ee',
|
|
545
|
+
sienna: '#a0522d',
|
|
546
|
+
silver: '#c0c0c0',
|
|
547
|
+
skyblue: '#87ceeb',
|
|
548
|
+
slateblue: '#6a5acd',
|
|
549
|
+
slategray: '#708090',
|
|
550
|
+
slategrey: '#708090',
|
|
551
|
+
snow: '#fffafa',
|
|
552
|
+
springgreen: '#00ff7f',
|
|
553
|
+
steelblue: '#4682b4',
|
|
554
|
+
tan: '#d2b48c',
|
|
555
|
+
teal: '#008080',
|
|
556
|
+
thistle: '#d8bfd8',
|
|
557
|
+
tomato: '#ff6347',
|
|
558
|
+
turquoise: '#40e0d0',
|
|
559
|
+
violet: '#ee82ee',
|
|
560
|
+
wheat: '#f5deb3',
|
|
561
|
+
white: '#ffffff',
|
|
562
|
+
whitesmoke: '#f5f5f5',
|
|
563
|
+
yellow: '#ffff00',
|
|
564
|
+
yellowgreen: '#9acd32'
|
|
565
|
+
};
|
|
566
|
+
function clampChannel(value) {
|
|
567
|
+
return Math.min(255, Math.max(0, Math.round(value)));
|
|
568
|
+
}
|
|
569
|
+
function normalizeRgbArgs(args) {
|
|
570
|
+
var parts = args.split(/[,\s/]+/).filter(Boolean);
|
|
571
|
+
if (parts.length < 3) return null;
|
|
572
|
+
var to255 = function to255(value) {
|
|
573
|
+
if (typeof value !== 'string' || !value) return null;
|
|
574
|
+
if (value.endsWith('%')) return clampChannel(parseFloat(value) / 100 * 255);
|
|
575
|
+
var number = Number(value);
|
|
576
|
+
return Number.isFinite(number) ? clampChannel(number) : null;
|
|
577
|
+
};
|
|
578
|
+
var red = to255(parts[0]);
|
|
579
|
+
var green = to255(parts[1]);
|
|
580
|
+
var blue = to255(parts[2]);
|
|
581
|
+
if (red === null || green === null || blue === null) return null;
|
|
582
|
+
return "#".concat([red, green, blue].map(function (n) {
|
|
583
|
+
return n.toString(16).padStart(2, '0');
|
|
584
|
+
}).join(''));
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
/**
|
|
588
|
+
* Convert any supported CSS color into `#rrggbb`. Returns null when the
|
|
589
|
+
* value cannot be parsed. Supports: #rgb / #rrggbb (case-insensitive),
|
|
590
|
+
* CSS named colors, rgb() / rgba() with comma or modern space syntax,
|
|
591
|
+
* including percentages. Alpha in rgba() is ignored.
|
|
592
|
+
*/
|
|
593
|
+
function normalizeColor(value) {
|
|
594
|
+
if (typeof value !== 'string') return null;
|
|
595
|
+
var input = value.trim();
|
|
596
|
+
if (!input) return null;
|
|
597
|
+
var lower = input.toLowerCase();
|
|
598
|
+
if (NAMED_COLORS[lower]) return NAMED_COLORS[lower];
|
|
599
|
+
if (/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.test(input)) {
|
|
600
|
+
var hex = input.slice(1).toLowerCase();
|
|
601
|
+
if (hex.length === 3) return "#".concat(hex.split('').map(function (c) {
|
|
602
|
+
return c + c;
|
|
603
|
+
}).join(''));
|
|
604
|
+
return "#".concat(hex);
|
|
605
|
+
}
|
|
606
|
+
var match = input.match(/^rgba?\((.*)\)$/i);
|
|
607
|
+
if (match) return normalizeRgbArgs(match[1]);
|
|
608
|
+
return null;
|
|
609
|
+
}
|
|
610
|
+
function hexToRgb01(color) {
|
|
611
|
+
var hex = normalizeColor(color);
|
|
612
|
+
if (!hex) return [0, 0, 0];
|
|
613
|
+
var value = Number.parseInt(hex.slice(1), 16);
|
|
413
614
|
return [(value >> 16 & 255) / 255, (value >> 8 & 255) / 255, (value & 255) / 255];
|
|
414
615
|
}
|
|
415
616
|
|
|
@@ -487,6 +688,26 @@ var CosmicRenderer = /*#__PURE__*/function () {
|
|
|
487
688
|
this.options.dprCap = cap;
|
|
488
689
|
this.resize();
|
|
489
690
|
}
|
|
691
|
+
}, {
|
|
692
|
+
key: "setMouseColor",
|
|
693
|
+
value: function setMouseColor(enabled) {
|
|
694
|
+
this.options.mouseColor = enabled !== false;
|
|
695
|
+
if (this.options.mouseColor) {
|
|
696
|
+
if (this.onPointerMove) return this;
|
|
697
|
+
_assertClassBrand(_CosmicRenderer_brand, this, _bindEvents).call(this);
|
|
698
|
+
return this;
|
|
699
|
+
}
|
|
700
|
+
if (this.onPointerMove) {
|
|
701
|
+
var target = this.eventTarget;
|
|
702
|
+
target.removeEventListener('pointermove', this.onPointerMove);
|
|
703
|
+
target.removeEventListener('pointerdown', this.onPointerMove);
|
|
704
|
+
target.removeEventListener('pointerleave', this.onPointerLeave);
|
|
705
|
+
this.onPointerMove = null;
|
|
706
|
+
this.onPointerLeave = null;
|
|
707
|
+
}
|
|
708
|
+
this.motionTarget = 0;
|
|
709
|
+
return this;
|
|
710
|
+
}
|
|
490
711
|
}, {
|
|
491
712
|
key: "randomize",
|
|
492
713
|
value: function randomize() {
|
|
@@ -635,6 +856,8 @@ var FallbackRenderer = /*#__PURE__*/function () {
|
|
|
635
856
|
var _this$canvas = this.canvas,
|
|
636
857
|
width = _this$canvas.width,
|
|
637
858
|
height = _this$canvas.height;
|
|
859
|
+
var t = time * (this.preset.speed || 1);
|
|
860
|
+
var phase = (this.preset.seed || 0) * 0.7;
|
|
638
861
|
var gradient = ctx.createLinearGradient(0, 0, width, height);
|
|
639
862
|
gradient.addColorStop(0, this.preset.colors[0]);
|
|
640
863
|
gradient.addColorStop(0.38, this.preset.colors[1]);
|
|
@@ -644,8 +867,8 @@ var FallbackRenderer = /*#__PURE__*/function () {
|
|
|
644
867
|
ctx.fillRect(0, 0, width, height);
|
|
645
868
|
ctx.globalCompositeOperation = 'screen';
|
|
646
869
|
for (var index = 0; index < 6; index += 1) {
|
|
647
|
-
var x = (0.5 + 0.45 * Math.sin(
|
|
648
|
-
var y = (0.5 + 0.4 * Math.cos(
|
|
870
|
+
var x = (0.5 + 0.45 * Math.sin(t * 0.32 + index * 1.7 + phase)) * width;
|
|
871
|
+
var y = (0.5 + 0.4 * Math.cos(t * 0.25 + index + phase)) * height;
|
|
649
872
|
var radius = Math.max(width, height) * (0.08 + index % 3 * 0.04);
|
|
650
873
|
var glow = ctx.createRadialGradient(x, y, 0, x, y, radius);
|
|
651
874
|
glow.addColorStop(0, rgb(this.preset.colors[(index + 1) % 4], 0.24));
|
|
@@ -669,7 +892,12 @@ var FallbackRenderer = /*#__PURE__*/function () {
|
|
|
669
892
|
}
|
|
670
893
|
}, {
|
|
671
894
|
key: "randomize",
|
|
672
|
-
value: function randomize() {
|
|
895
|
+
value: function randomize() {
|
|
896
|
+
if (this.preset) this.preset.seed = Math.random() * 100;
|
|
897
|
+
}
|
|
898
|
+
}, {
|
|
899
|
+
key: "setMouseColor",
|
|
900
|
+
value: function setMouseColor() {}
|
|
673
901
|
}, {
|
|
674
902
|
key: "dispose",
|
|
675
903
|
value: function dispose() {}
|
|
@@ -780,6 +1008,22 @@ function createVisibilityGuard(element) {
|
|
|
780
1008
|
};
|
|
781
1009
|
}
|
|
782
1010
|
|
|
1011
|
+
/**
|
|
1012
|
+
* Run a callback asynchronously, right after the current task and before the
|
|
1013
|
+
* next paint. Used for mount-time events (ready / error) so listeners that
|
|
1014
|
+
* are attached after create() still receive them. Falls back for legacy
|
|
1015
|
+
* browsers that lack queueMicrotask / Promise.
|
|
1016
|
+
*/
|
|
1017
|
+
function nextTick(fn) {
|
|
1018
|
+
if (typeof queueMicrotask === 'function') {
|
|
1019
|
+
queueMicrotask(fn);
|
|
1020
|
+
} else if (typeof Promise !== 'undefined' && typeof Promise.resolve === 'function') {
|
|
1021
|
+
Promise.resolve().then(fn);
|
|
1022
|
+
} else {
|
|
1023
|
+
setTimeout(fn, 0);
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
|
|
783
1027
|
function prefersReducedMotion() {
|
|
784
1028
|
return typeof matchMedia !== 'undefined' && matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
785
1029
|
}
|
|
@@ -803,7 +1047,7 @@ function createColorBackground(host) {
|
|
|
803
1047
|
if (!host || typeof host.appendChild !== 'function') {
|
|
804
1048
|
throw new Error('createColorBackground: host element is required');
|
|
805
1049
|
}
|
|
806
|
-
var preset = _objectSpread2({}, getPreset('capsule', (_options$preset = options.preset) !== null && _options$preset !== void 0 ? _options$preset : '
|
|
1050
|
+
var preset = _objectSpread2({}, getPreset('capsule', (_options$preset = options.preset) !== null && _options$preset !== void 0 ? _options$preset : '初光'));
|
|
807
1051
|
var merged = normalizeOptions({
|
|
808
1052
|
quality: DEFAULTS.capsule.quality,
|
|
809
1053
|
renderer: DEFAULTS.capsule.renderer,
|
|
@@ -812,6 +1056,10 @@ function createColorBackground(host) {
|
|
|
812
1056
|
opacity: 1,
|
|
813
1057
|
fallbackColor: true
|
|
814
1058
|
}, preset, options);
|
|
1059
|
+
var normalizedColors = merged.colors.map(normalizeColor);
|
|
1060
|
+
if (normalizedColors.every(Boolean)) preset.colors = normalizedColors;
|
|
1061
|
+
preset.seed = merged.seed;
|
|
1062
|
+
preset.speed = merged.speed;
|
|
815
1063
|
var computed = getComputedStyle(host);
|
|
816
1064
|
if (computed.position === 'static' || computed.position === '') {
|
|
817
1065
|
host.style.position = 'relative';
|
|
@@ -832,6 +1080,16 @@ function createColorBackground(host) {
|
|
|
832
1080
|
host.appendChild(layer);
|
|
833
1081
|
var emitter = createEmitter();
|
|
834
1082
|
var paused = merged.respectReducedMotion && prefersReducedMotion();
|
|
1083
|
+
var disposed = false;
|
|
1084
|
+
var dirty = {
|
|
1085
|
+
preset: false,
|
|
1086
|
+
seed: false,
|
|
1087
|
+
speed: false,
|
|
1088
|
+
colors: false,
|
|
1089
|
+
opacity: false,
|
|
1090
|
+
fallbackColor: false,
|
|
1091
|
+
mouseColor: false
|
|
1092
|
+
};
|
|
835
1093
|
var renderer;
|
|
836
1094
|
var useWebgl = merged.renderer !== 'canvas2d';
|
|
837
1095
|
if (useWebgl) {
|
|
@@ -843,8 +1101,11 @@ function createColorBackground(host) {
|
|
|
843
1101
|
});
|
|
844
1102
|
} catch (error) {
|
|
845
1103
|
renderer = new FallbackRenderer(canvas, merged);
|
|
846
|
-
|
|
847
|
-
|
|
1104
|
+
nextTick(function () {
|
|
1105
|
+
if (disposed) return;
|
|
1106
|
+
emitter.emit('error', {
|
|
1107
|
+
message: String(error && error.message ? error.message : error)
|
|
1108
|
+
});
|
|
848
1109
|
});
|
|
849
1110
|
}
|
|
850
1111
|
} else {
|
|
@@ -862,8 +1123,11 @@ function createColorBackground(host) {
|
|
|
862
1123
|
}, function () {
|
|
863
1124
|
return paused;
|
|
864
1125
|
});
|
|
865
|
-
|
|
866
|
-
|
|
1126
|
+
nextTick(function () {
|
|
1127
|
+
if (disposed) return;
|
|
1128
|
+
emitter.emit('ready', {
|
|
1129
|
+
preset: _objectSpread2({}, preset)
|
|
1130
|
+
});
|
|
867
1131
|
});
|
|
868
1132
|
return {
|
|
869
1133
|
element: host,
|
|
@@ -874,24 +1138,59 @@ function createColorBackground(host) {
|
|
|
874
1138
|
off: emitter.off,
|
|
875
1139
|
setPreset: function setPreset(ref) {
|
|
876
1140
|
var next = getPreset('capsule', ref);
|
|
1141
|
+
dirty.preset = true;
|
|
877
1142
|
Object.assign(preset, next);
|
|
878
|
-
|
|
1143
|
+
var nextColors = preset.colors.map(normalizeColor);
|
|
1144
|
+
if (nextColors.every(Boolean)) preset.colors = nextColors;
|
|
1145
|
+
renderer.setPreset(_objectSpread2({}, preset));
|
|
879
1146
|
renderer.resize();
|
|
880
1147
|
syncLayerVars();
|
|
881
1148
|
emitter.emit('presetchange', {
|
|
882
|
-
preset: _objectSpread2({},
|
|
1149
|
+
preset: _objectSpread2({}, preset)
|
|
883
1150
|
});
|
|
884
1151
|
return this;
|
|
885
1152
|
},
|
|
886
1153
|
setColors: function setColors(colors) {
|
|
887
|
-
|
|
888
|
-
|
|
1154
|
+
var next = Array.isArray(colors) ? colors.map(normalizeColor) : [];
|
|
1155
|
+
if (next.length !== 4 || next.some(function (color) {
|
|
1156
|
+
return !color;
|
|
1157
|
+
})) return this;
|
|
1158
|
+
dirty.colors = true;
|
|
1159
|
+
preset.colors = next;
|
|
889
1160
|
renderer.setPreset(_objectSpread2(_objectSpread2({}, preset), {}, {
|
|
890
|
-
colors:
|
|
1161
|
+
colors: next
|
|
891
1162
|
}));
|
|
892
1163
|
syncLayerVars();
|
|
893
1164
|
return this;
|
|
894
1165
|
},
|
|
1166
|
+
setSeed: function setSeed(seed) {
|
|
1167
|
+
var value = Number(seed);
|
|
1168
|
+
if (!Number.isFinite(value)) return this;
|
|
1169
|
+
dirty.seed = true;
|
|
1170
|
+
preset.seed = value;
|
|
1171
|
+
renderer.setPreset(_objectSpread2({}, preset));
|
|
1172
|
+
return this;
|
|
1173
|
+
},
|
|
1174
|
+
setSpeed: function setSpeed(speed) {
|
|
1175
|
+
var value = Number(speed);
|
|
1176
|
+
if (!Number.isFinite(value)) return this;
|
|
1177
|
+
dirty.speed = true;
|
|
1178
|
+
preset.speed = value;
|
|
1179
|
+
renderer.setPreset(_objectSpread2({}, preset));
|
|
1180
|
+
return this;
|
|
1181
|
+
},
|
|
1182
|
+
setFallbackColor: function setFallbackColor(value) {
|
|
1183
|
+
dirty.fallbackColor = true;
|
|
1184
|
+
merged.fallbackColor = value;
|
|
1185
|
+
syncLayerVars();
|
|
1186
|
+
return this;
|
|
1187
|
+
},
|
|
1188
|
+
setMouseColor: function setMouseColor(value) {
|
|
1189
|
+
dirty.mouseColor = true;
|
|
1190
|
+
merged.mouseColor = value !== false;
|
|
1191
|
+
if (typeof renderer.setMouseColor === 'function') renderer.setMouseColor(merged.mouseColor);
|
|
1192
|
+
return this;
|
|
1193
|
+
},
|
|
895
1194
|
setQuality: function setQuality(quality) {
|
|
896
1195
|
merged.quality = quality;
|
|
897
1196
|
if (typeof renderer.setDprCap === 'function') renderer.setDprCap(dprCapFor(quality));
|
|
@@ -900,12 +1199,13 @@ function createColorBackground(host) {
|
|
|
900
1199
|
setOpacity: function setOpacity(value) {
|
|
901
1200
|
var opacity = Number(value);
|
|
902
1201
|
if (!Number.isFinite(opacity)) return this;
|
|
1202
|
+
dirty.opacity = true;
|
|
903
1203
|
merged.opacity = Math.min(1, Math.max(0, opacity));
|
|
904
1204
|
layer.style.setProperty('--dlc-color-opacity', String(merged.opacity));
|
|
905
1205
|
return this;
|
|
906
1206
|
},
|
|
907
1207
|
randomize: function randomize() {
|
|
908
|
-
|
|
1208
|
+
this.setSeed(Math.random() * 100);
|
|
909
1209
|
return this;
|
|
910
1210
|
},
|
|
911
1211
|
pause: function pause() {
|
|
@@ -917,12 +1217,17 @@ function createColorBackground(host) {
|
|
|
917
1217
|
return this;
|
|
918
1218
|
},
|
|
919
1219
|
dispose: function dispose() {
|
|
1220
|
+
disposed = true;
|
|
920
1221
|
unsubscribe();
|
|
921
1222
|
visibility.dispose();
|
|
922
1223
|
if (resizeObserver) resizeObserver.disconnect();else window.removeEventListener('resize', renderer.resize);
|
|
923
1224
|
renderer.dispose();
|
|
924
1225
|
layer.remove();
|
|
925
|
-
}
|
|
1226
|
+
},
|
|
1227
|
+
opacity: merged.opacity,
|
|
1228
|
+
fallbackColor: merged.fallbackColor,
|
|
1229
|
+
mouseColor: merged.mouseColor,
|
|
1230
|
+
dirty: dirty
|
|
926
1231
|
};
|
|
927
1232
|
}
|
|
928
1233
|
|