@5even7/dlc-ui 0.2.3 → 0.2.5

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.umd.js CHANGED
@@ -421,9 +421,13 @@
421
421
  var list = kind === 'capsule' ? CAPSULE_PRESETS : kind === 'progress' ? PROGRESS_PRESETS : null;
422
422
  if (!list) throw new Error("Unknown preset kind: ".concat(kind, " (use \"capsule\" or \"progress\")"));
423
423
  var key = String(ref).trim().toLowerCase();
424
- var found = list.find(function (preset) {
425
- return preset.name.toLowerCase() === key;
426
- });
424
+ var found = null;
425
+ for (var index = 0; index < list.length; index += 1) {
426
+ if (list[index].name.toLowerCase() === key) {
427
+ found = list[index];
428
+ break;
429
+ }
430
+ }
427
431
  if (!found) throw new Error("Unknown ".concat(kind, " preset: ").concat(ref));
428
432
  return found;
429
433
  }
@@ -444,7 +448,6 @@
444
448
  min: 0,
445
449
  max: 100,
446
450
  draggable: true,
447
- keyboard: true,
448
451
  disabled: false,
449
452
  readonly: false,
450
453
  valueSuffix: '%',
@@ -635,7 +638,7 @@
635
638
  if (parts.length < 3) return null;
636
639
  var to255 = function to255(value) {
637
640
  if (typeof value !== 'string' || !value) return null;
638
- if (value.endsWith('%')) return clampChannel(parseFloat(value) / 100 * 255);
641
+ if (value.charAt(value.length - 1) === '%') return clampChannel(parseFloat(value) / 100 * 255);
639
642
  var number = Number(value);
640
643
  return Number.isFinite(number) ? clampChannel(number) : null;
641
644
  };
@@ -643,9 +646,11 @@
643
646
  var green = to255(parts[1]);
644
647
  var blue = to255(parts[2]);
645
648
  if (red === null || green === null || blue === null) return null;
646
- return "#".concat([red, green, blue].map(function (n) {
647
- return n.toString(16).padStart(2, '0');
648
- }).join(''));
649
+ var hex = function hex(n) {
650
+ var text = n.toString(16);
651
+ return text.length === 1 ? "0".concat(text) : text;
652
+ };
653
+ return "#".concat(hex(red)).concat(hex(green)).concat(hex(blue));
649
654
  }
650
655
 
651
656
  /**
@@ -915,6 +920,7 @@
915
920
  this.preset = preset;
916
921
  this.context = canvas.getContext('2d');
917
922
  this.visible = true;
923
+ this.timePhase = 0;
918
924
  }
919
925
  return _createClass(FallbackRenderer, [{
920
926
  key: "resize",
@@ -935,7 +941,7 @@
935
941
  var _this$canvas = this.canvas,
936
942
  width = _this$canvas.width,
937
943
  height = _this$canvas.height;
938
- var t = time * (this.preset.speed || 1);
944
+ var t = (time + this.timePhase) * (this.preset.speed || 1);
939
945
  var phase = (this.preset.seed || 0) * 0.7;
940
946
  var gradient = ctx.createLinearGradient(0, 0, width, height);
941
947
  gradient.addColorStop(0, this.preset.colors[0]);
@@ -972,7 +978,10 @@
972
978
  }, {
973
979
  key: "randomize",
974
980
  value: function randomize() {
975
- if (this.preset) this.preset.seed = Math.random() * 100;
981
+ if (this.preset) {
982
+ this.preset.seed = Math.random() * 100;
983
+ this.timePhase = Math.random() * Math.PI * 2;
984
+ }
976
985
  }
977
986
  }, {
978
987
  key: "setMouseColor",
@@ -1225,8 +1234,9 @@
1225
1234
  }
1226
1235
  if (merged.textRatio !== undefined) {
1227
1236
  root.style.setProperty('--hj-text-width', "".concat(merged.textRatio, "%"));
1228
- var userMinWidth = merged.cssVars && merged.cssVars['--hj-text-min-width'];
1229
- if (merged.textRatio === 0) root.style.setProperty('--hj-text-min-width', '0');else if (userMinWidth) root.style.setProperty('--hj-text-min-width', userMinWidth);else root.style.removeProperty('--hj-text-min-width');
1237
+ // textRatio 是文字区宽度的唯一权威值:min-width 会阻止其缩小到
1238
+ // 164px 以下(--hj-copy-min-width 的历史默认),这里强制归零。
1239
+ root.style.setProperty('--hj-text-min-width', '0');
1230
1240
  }
1231
1241
  renderer.resize();
1232
1242
  };
@@ -1350,8 +1360,7 @@
1350
1360
  dirty.textRatio = true;
1351
1361
  merged.textRatio = value;
1352
1362
  root.style.setProperty('--hj-text-width', "".concat(value, "%"));
1353
- var userMinWidth = merged.cssVars && merged.cssVars['--hj-text-min-width'];
1354
- if (value === 0) root.style.setProperty('--hj-text-min-width', '0');else if (userMinWidth) root.style.setProperty('--hj-text-min-width', userMinWidth);else root.style.removeProperty('--hj-text-min-width');
1363
+ root.style.setProperty('--hj-text-min-width', '0');
1355
1364
  return this;
1356
1365
  },
1357
1366
  setCssVars: function setCssVars(vars) {
@@ -1370,8 +1379,14 @@
1370
1379
  return this;
1371
1380
  },
1372
1381
  setSize: function setSize(width, height) {
1373
- if (width !== undefined) merged.width = width;
1374
- if (height !== undefined) merged.height = height;
1382
+ if (width !== undefined) {
1383
+ parseSize(width); // 非法尺寸直接抛错前先校验,避免污染内部状态
1384
+ merged.width = width;
1385
+ }
1386
+ if (height !== undefined) {
1387
+ parseSize(height);
1388
+ merged.height = height;
1389
+ }
1375
1390
  applySize();
1376
1391
  return this;
1377
1392
  },
@@ -1400,8 +1415,12 @@
1400
1415
  renderer.dispose();
1401
1416
  root.remove();
1402
1417
  },
1403
- textRatio: merged.textRatio,
1404
- cssVars: merged.cssVars,
1418
+ get textRatio() {
1419
+ return merged.textRatio;
1420
+ },
1421
+ get cssVars() {
1422
+ return merged.cssVars;
1423
+ },
1405
1424
  dirty: dirty
1406
1425
  };
1407
1426
  }
@@ -1697,8 +1716,12 @@
1697
1716
  context.translate(x, y);
1698
1717
  context.scale(1, radiusY / radiusX);
1699
1718
  var gradient = context.createRadialGradient(0, 0, 0, 0, 0, radiusX);
1700
- gradient.addColorStop(0, "".concat(color).concat(Math.round(alpha * 255).toString(16).padStart(2, '0')));
1701
- gradient.addColorStop(0.46, "".concat(color).concat(Math.round(alpha * 0.42 * 255).toString(16).padStart(2, '0')));
1719
+ var alphaHex = function alphaHex(value) {
1720
+ var text = Math.round(value).toString(16);
1721
+ return text.length === 1 ? "0".concat(text) : text;
1722
+ };
1723
+ gradient.addColorStop(0, "".concat(color).concat(alphaHex(alpha * 255)));
1724
+ gradient.addColorStop(0.46, "".concat(color).concat(alphaHex(alpha * 0.42 * 255)));
1702
1725
  gradient.addColorStop(1, "".concat(color, "00"));
1703
1726
  context.fillStyle = gradient;
1704
1727
  context.fillRect(-radiusX, -radiusX, radiusX * 2, radiusX * 2);
@@ -2148,6 +2171,11 @@
2148
2171
  }, {
2149
2172
  key: "setRange",
2150
2173
  value: function setRange(min, max) {
2174
+ if (min > max) {
2175
+ var swap = min;
2176
+ min = max;
2177
+ max = swap;
2178
+ }
2151
2179
  this.min = min;
2152
2180
  this.max = max;
2153
2181
  var clamped = clamp(this.value, this.min, this.max);
@@ -2365,32 +2393,6 @@
2365
2393
  this.root.addEventListener('pointerup', this.handlers.pointerup);
2366
2394
  this.root.addEventListener('pointercancel', this.handlers.pointercancel);
2367
2395
  }
2368
- if (this.options.keyboard !== false) {
2369
- this.handlers.keydown = function (event) {
2370
- var step = (_this3.max - _this3.min) * 0.02;
2371
- var actions = {
2372
- ArrowLeft: -step,
2373
- ArrowDown: -step,
2374
- ArrowRight: step,
2375
- ArrowUp: step,
2376
- PageDown: -step * 5,
2377
- PageUp: step * 5
2378
- };
2379
- if (event.key === 'Home') {
2380
- event.preventDefault();
2381
- _this3.setProgress(_this3.min, 'keyboard');
2382
- } else if (event.key === 'End') {
2383
- event.preventDefault();
2384
- _this3.setProgress(_this3.max, 'keyboard');
2385
- } else if (actions[event.key]) {
2386
- event.preventDefault();
2387
- _this3.setProgress(_this3.value + actions[event.key], 'keyboard');
2388
- } else {
2389
- return;
2390
- }
2391
- };
2392
- this.root.addEventListener('keydown', this.handlers.keydown);
2393
- }
2394
2396
  }
2395
2397
  }, {
2396
2398
  key: "update",
@@ -2437,7 +2439,7 @@
2437
2439
  * Mount a fluid progress capsule into `container`.
2438
2440
  *
2439
2441
  * Options: preset (id/code/name or object), width, height, value, min, max,
2440
- * draggable, keyboard, colors, edgeStyle, textRatio (0-100, text region
2442
+ * draggable, colors, edgeStyle, textRatio (0-100, text region
2441
2443
  * width in percent), text (HTML string or DOM nodes for the text slot),
2442
2444
  * colorContent (HTML string or DOM nodes for the color slot),
2443
2445
  * showValue (show/hide the right-side percentage), quality,
@@ -2451,6 +2453,11 @@
2451
2453
  }
2452
2454
  var preset = _objectSpread2({}, getPreset('progress', (_options$preset = options.preset) !== null && _options$preset !== void 0 ? _options$preset : '星火'));
2453
2455
  var merged = normalizeOptions(DEFAULTS.progress, preset, options);
2456
+ if (merged.min > merged.max) {
2457
+ var swap = merged.min;
2458
+ merged.min = merged.max;
2459
+ merged.max = swap;
2460
+ }
2454
2461
  var normalizedColors = merged.colors.map(normalizeColor);
2455
2462
  if (normalizedColors.every(Boolean)) preset.colors = normalizedColors;
2456
2463
  preset.edgeStyle = merged.edgeStyle;
@@ -2462,7 +2469,6 @@
2462
2469
  var readonly = merged.readonly === true || merged.readonly === '' || merged.readonly === 'true';
2463
2470
  var locked = disabled || readonly;
2464
2471
  var effectiveDraggable = locked ? false : merged.draggable !== false;
2465
- var effectiveKeyboard = locked ? false : merged.keyboard !== false;
2466
2472
  var dirty = {
2467
2473
  preset: false,
2468
2474
  colors: false,
@@ -2474,7 +2480,6 @@
2474
2480
  var root = document.createElement('div');
2475
2481
  root.className = 'hj-capsule-root hj-progress-root';
2476
2482
  root.setAttribute('role', 'slider');
2477
- root.setAttribute('tabindex', '0');
2478
2483
  root.setAttribute('data-draggable', String(effectiveDraggable));
2479
2484
  if (disabled) {
2480
2485
  root.setAttribute('aria-disabled', 'true');
@@ -2484,6 +2489,7 @@
2484
2489
  root.setAttribute('aria-readonly', 'true');
2485
2490
  root.classList.add('is-readonly');
2486
2491
  }
2492
+ if (locked) root.setAttribute('tabindex', '-1');
2487
2493
  root.setAttribute('aria-valuemin', String((_merged$min = merged.min) !== null && _merged$min !== void 0 ? _merged$min : 0));
2488
2494
  root.setAttribute('aria-valuemax', String((_merged$max = merged.max) !== null && _merged$max !== void 0 ? _merged$max : 100));
2489
2495
  root.setAttribute('aria-valuenow', String(preset.initialProgress));
@@ -2495,7 +2501,6 @@
2495
2501
  }));
2496
2502
  };
2497
2503
  updateAria();
2498
- if (!effectiveKeyboard) root.setAttribute('tabindex', '-1');
2499
2504
  var canvas = document.createElement('canvas');
2500
2505
  canvas.className = 'hj-progress-canvas';
2501
2506
  canvas.setAttribute('aria-hidden', 'true');
@@ -2562,8 +2567,7 @@
2562
2567
  preset: preset,
2563
2568
  emitter: emitter,
2564
2569
  options: _objectSpread2(_objectSpread2({}, merged), {}, {
2565
- draggable: effectiveDraggable,
2566
- keyboard: effectiveKeyboard
2570
+ draggable: effectiveDraggable
2567
2571
  }),
2568
2572
  copy: copy,
2569
2573
  dirty: dirty
@@ -2723,8 +2727,14 @@
2723
2727
  return this;
2724
2728
  },
2725
2729
  setSize: function setSize(width, height) {
2726
- if (width !== undefined) merged.width = width;
2727
- if (height !== undefined) merged.height = height;
2730
+ if (width !== undefined) {
2731
+ parseSize(width);
2732
+ merged.width = width;
2733
+ }
2734
+ if (height !== undefined) {
2735
+ parseSize(height);
2736
+ merged.height = height;
2737
+ }
2728
2738
  applySize();
2729
2739
  controller.resizeCanvas();
2730
2740
  return this;
@@ -2755,8 +2765,12 @@
2755
2765
  controller.dispose();
2756
2766
  root.remove();
2757
2767
  },
2758
- textRatio: merged.textRatio,
2759
- cssVars: merged.cssVars,
2768
+ get textRatio() {
2769
+ return merged.textRatio;
2770
+ },
2771
+ get cssVars() {
2772
+ return merged.cssVars;
2773
+ },
2760
2774
  dirty: dirty
2761
2775
  };
2762
2776
  }
@@ -2961,9 +2975,15 @@
2961
2975
  renderer.dispose();
2962
2976
  layer.remove();
2963
2977
  },
2964
- opacity: merged.opacity,
2965
- fallbackColor: merged.fallbackColor,
2966
- mouseColor: merged.mouseColor,
2978
+ get opacity() {
2979
+ return merged.opacity;
2980
+ },
2981
+ get fallbackColor() {
2982
+ return merged.fallbackColor;
2983
+ },
2984
+ get mouseColor() {
2985
+ return merged.mouseColor;
2986
+ },
2967
2987
  dirty: dirty
2968
2988
  };
2969
2989
  }