@5even7/dlc-ui 0.2.3 → 0.2.4

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/vue3.cjs CHANGED
@@ -418,9 +418,13 @@ function getPreset(kind, ref) {
418
418
  var list = kind === 'capsule' ? CAPSULE_PRESETS : kind === 'progress' ? PROGRESS_PRESETS : null;
419
419
  if (!list) throw new Error("Unknown preset kind: ".concat(kind, " (use \"capsule\" or \"progress\")"));
420
420
  var key = String(ref).trim().toLowerCase();
421
- var found = list.find(function (preset) {
422
- return preset.name.toLowerCase() === key;
423
- });
421
+ var found = null;
422
+ for (var index = 0; index < list.length; index += 1) {
423
+ if (list[index].name.toLowerCase() === key) {
424
+ found = list[index];
425
+ break;
426
+ }
427
+ }
424
428
  if (!found) throw new Error("Unknown ".concat(kind, " preset: ").concat(ref));
425
429
  return found;
426
430
  }
@@ -441,7 +445,6 @@ var DEFAULTS = {
441
445
  min: 0,
442
446
  max: 100,
443
447
  draggable: true,
444
- keyboard: true,
445
448
  disabled: false,
446
449
  readonly: false,
447
450
  valueSuffix: '%',
@@ -632,7 +635,7 @@ function normalizeRgbArgs(args) {
632
635
  if (parts.length < 3) return null;
633
636
  var to255 = function to255(value) {
634
637
  if (typeof value !== 'string' || !value) return null;
635
- if (value.endsWith('%')) return clampChannel(parseFloat(value) / 100 * 255);
638
+ if (value.charAt(value.length - 1) === '%') return clampChannel(parseFloat(value) / 100 * 255);
636
639
  var number = Number(value);
637
640
  return Number.isFinite(number) ? clampChannel(number) : null;
638
641
  };
@@ -640,9 +643,11 @@ function normalizeRgbArgs(args) {
640
643
  var green = to255(parts[1]);
641
644
  var blue = to255(parts[2]);
642
645
  if (red === null || green === null || blue === null) return null;
643
- return "#".concat([red, green, blue].map(function (n) {
644
- return n.toString(16).padStart(2, '0');
645
- }).join(''));
646
+ var hex = function hex(n) {
647
+ var text = n.toString(16);
648
+ return text.length === 1 ? "0".concat(text) : text;
649
+ };
650
+ return "#".concat(hex(red)).concat(hex(green)).concat(hex(blue));
646
651
  }
647
652
 
648
653
  /**
@@ -907,6 +912,7 @@ var FallbackRenderer = /*#__PURE__*/function () {
907
912
  this.preset = preset;
908
913
  this.context = canvas.getContext('2d');
909
914
  this.visible = true;
915
+ this.timePhase = 0;
910
916
  }
911
917
  return _createClass(FallbackRenderer, [{
912
918
  key: "resize",
@@ -927,7 +933,7 @@ var FallbackRenderer = /*#__PURE__*/function () {
927
933
  var _this$canvas = this.canvas,
928
934
  width = _this$canvas.width,
929
935
  height = _this$canvas.height;
930
- var t = time * (this.preset.speed || 1);
936
+ var t = (time + this.timePhase) * (this.preset.speed || 1);
931
937
  var phase = (this.preset.seed || 0) * 0.7;
932
938
  var gradient = ctx.createLinearGradient(0, 0, width, height);
933
939
  gradient.addColorStop(0, this.preset.colors[0]);
@@ -964,7 +970,10 @@ var FallbackRenderer = /*#__PURE__*/function () {
964
970
  }, {
965
971
  key: "randomize",
966
972
  value: function randomize() {
967
- if (this.preset) this.preset.seed = Math.random() * 100;
973
+ if (this.preset) {
974
+ this.preset.seed = Math.random() * 100;
975
+ this.timePhase = Math.random() * Math.PI * 2;
976
+ }
968
977
  }
969
978
  }, {
970
979
  key: "setMouseColor",
@@ -1355,8 +1364,14 @@ function createCapsule(container) {
1355
1364
  return this;
1356
1365
  },
1357
1366
  setSize: function setSize(width, height) {
1358
- if (width !== undefined) merged.width = width;
1359
- if (height !== undefined) merged.height = height;
1367
+ if (width !== undefined) {
1368
+ parseSize(width); // 非法尺寸直接抛错前先校验,避免污染内部状态
1369
+ merged.width = width;
1370
+ }
1371
+ if (height !== undefined) {
1372
+ parseSize(height);
1373
+ merged.height = height;
1374
+ }
1360
1375
  applySize();
1361
1376
  return this;
1362
1377
  },
@@ -1385,8 +1400,12 @@ function createCapsule(container) {
1385
1400
  renderer.dispose();
1386
1401
  root.remove();
1387
1402
  },
1388
- textRatio: merged.textRatio,
1389
- cssVars: merged.cssVars,
1403
+ get textRatio() {
1404
+ return merged.textRatio;
1405
+ },
1406
+ get cssVars() {
1407
+ return merged.cssVars;
1408
+ },
1390
1409
  dirty: dirty
1391
1410
  };
1392
1411
  }
@@ -1682,8 +1701,12 @@ function drawCloud(context, x, y, radiusX, radiusY, color, alpha) {
1682
1701
  context.translate(x, y);
1683
1702
  context.scale(1, radiusY / radiusX);
1684
1703
  var gradient = context.createRadialGradient(0, 0, 0, 0, 0, radiusX);
1685
- gradient.addColorStop(0, "".concat(color).concat(Math.round(alpha * 255).toString(16).padStart(2, '0')));
1686
- gradient.addColorStop(0.46, "".concat(color).concat(Math.round(alpha * 0.42 * 255).toString(16).padStart(2, '0')));
1704
+ var alphaHex = function alphaHex(value) {
1705
+ var text = Math.round(value).toString(16);
1706
+ return text.length === 1 ? "0".concat(text) : text;
1707
+ };
1708
+ gradient.addColorStop(0, "".concat(color).concat(alphaHex(alpha * 255)));
1709
+ gradient.addColorStop(0.46, "".concat(color).concat(alphaHex(alpha * 0.42 * 255)));
1687
1710
  gradient.addColorStop(1, "".concat(color, "00"));
1688
1711
  context.fillStyle = gradient;
1689
1712
  context.fillRect(-radiusX, -radiusX, radiusX * 2, radiusX * 2);
@@ -2133,6 +2156,11 @@ var ProgressCapsuleController = /*#__PURE__*/function () {
2133
2156
  }, {
2134
2157
  key: "setRange",
2135
2158
  value: function setRange(min, max) {
2159
+ if (min > max) {
2160
+ var swap = min;
2161
+ min = max;
2162
+ max = swap;
2163
+ }
2136
2164
  this.min = min;
2137
2165
  this.max = max;
2138
2166
  var clamped = clamp(this.value, this.min, this.max);
@@ -2350,32 +2378,6 @@ var ProgressCapsuleController = /*#__PURE__*/function () {
2350
2378
  this.root.addEventListener('pointerup', this.handlers.pointerup);
2351
2379
  this.root.addEventListener('pointercancel', this.handlers.pointercancel);
2352
2380
  }
2353
- if (this.options.keyboard !== false) {
2354
- this.handlers.keydown = function (event) {
2355
- var step = (_this3.max - _this3.min) * 0.02;
2356
- var actions = {
2357
- ArrowLeft: -step,
2358
- ArrowDown: -step,
2359
- ArrowRight: step,
2360
- ArrowUp: step,
2361
- PageDown: -step * 5,
2362
- PageUp: step * 5
2363
- };
2364
- if (event.key === 'Home') {
2365
- event.preventDefault();
2366
- _this3.setProgress(_this3.min, 'keyboard');
2367
- } else if (event.key === 'End') {
2368
- event.preventDefault();
2369
- _this3.setProgress(_this3.max, 'keyboard');
2370
- } else if (actions[event.key]) {
2371
- event.preventDefault();
2372
- _this3.setProgress(_this3.value + actions[event.key], 'keyboard');
2373
- } else {
2374
- return;
2375
- }
2376
- };
2377
- this.root.addEventListener('keydown', this.handlers.keydown);
2378
- }
2379
2381
  }
2380
2382
  }, {
2381
2383
  key: "update",
@@ -2422,7 +2424,7 @@ var ProgressCapsuleController = /*#__PURE__*/function () {
2422
2424
  * Mount a fluid progress capsule into `container`.
2423
2425
  *
2424
2426
  * Options: preset (id/code/name or object), width, height, value, min, max,
2425
- * draggable, keyboard, colors, edgeStyle, textRatio (0-100, text region
2427
+ * draggable, colors, edgeStyle, textRatio (0-100, text region
2426
2428
  * width in percent), text (HTML string or DOM nodes for the text slot),
2427
2429
  * colorContent (HTML string or DOM nodes for the color slot),
2428
2430
  * showValue (show/hide the right-side percentage), quality,
@@ -2436,6 +2438,11 @@ function createProgressCapsule(container) {
2436
2438
  }
2437
2439
  var preset = _objectSpread2({}, getPreset('progress', (_options$preset = options.preset) !== null && _options$preset !== void 0 ? _options$preset : '星火'));
2438
2440
  var merged = normalizeOptions(DEFAULTS.progress, preset, options);
2441
+ if (merged.min > merged.max) {
2442
+ var swap = merged.min;
2443
+ merged.min = merged.max;
2444
+ merged.max = swap;
2445
+ }
2439
2446
  var normalizedColors = merged.colors.map(normalizeColor);
2440
2447
  if (normalizedColors.every(Boolean)) preset.colors = normalizedColors;
2441
2448
  preset.edgeStyle = merged.edgeStyle;
@@ -2447,7 +2454,6 @@ function createProgressCapsule(container) {
2447
2454
  var readonly = merged.readonly === true || merged.readonly === '' || merged.readonly === 'true';
2448
2455
  var locked = disabled || readonly;
2449
2456
  var effectiveDraggable = locked ? false : merged.draggable !== false;
2450
- var effectiveKeyboard = locked ? false : merged.keyboard !== false;
2451
2457
  var dirty = {
2452
2458
  preset: false,
2453
2459
  colors: false,
@@ -2459,7 +2465,6 @@ function createProgressCapsule(container) {
2459
2465
  var root = document.createElement('div');
2460
2466
  root.className = 'hj-capsule-root hj-progress-root';
2461
2467
  root.setAttribute('role', 'slider');
2462
- root.setAttribute('tabindex', '0');
2463
2468
  root.setAttribute('data-draggable', String(effectiveDraggable));
2464
2469
  if (disabled) {
2465
2470
  root.setAttribute('aria-disabled', 'true');
@@ -2469,6 +2474,7 @@ function createProgressCapsule(container) {
2469
2474
  root.setAttribute('aria-readonly', 'true');
2470
2475
  root.classList.add('is-readonly');
2471
2476
  }
2477
+ if (locked) root.setAttribute('tabindex', '-1');
2472
2478
  root.setAttribute('aria-valuemin', String((_merged$min = merged.min) !== null && _merged$min !== void 0 ? _merged$min : 0));
2473
2479
  root.setAttribute('aria-valuemax', String((_merged$max = merged.max) !== null && _merged$max !== void 0 ? _merged$max : 100));
2474
2480
  root.setAttribute('aria-valuenow', String(preset.initialProgress));
@@ -2480,7 +2486,6 @@ function createProgressCapsule(container) {
2480
2486
  }));
2481
2487
  };
2482
2488
  updateAria();
2483
- if (!effectiveKeyboard) root.setAttribute('tabindex', '-1');
2484
2489
  var canvas = document.createElement('canvas');
2485
2490
  canvas.className = 'hj-progress-canvas';
2486
2491
  canvas.setAttribute('aria-hidden', 'true');
@@ -2547,8 +2552,7 @@ function createProgressCapsule(container) {
2547
2552
  preset: preset,
2548
2553
  emitter: emitter,
2549
2554
  options: _objectSpread2(_objectSpread2({}, merged), {}, {
2550
- draggable: effectiveDraggable,
2551
- keyboard: effectiveKeyboard
2555
+ draggable: effectiveDraggable
2552
2556
  }),
2553
2557
  copy: copy,
2554
2558
  dirty: dirty
@@ -2708,8 +2712,14 @@ function createProgressCapsule(container) {
2708
2712
  return this;
2709
2713
  },
2710
2714
  setSize: function setSize(width, height) {
2711
- if (width !== undefined) merged.width = width;
2712
- if (height !== undefined) merged.height = height;
2715
+ if (width !== undefined) {
2716
+ parseSize(width);
2717
+ merged.width = width;
2718
+ }
2719
+ if (height !== undefined) {
2720
+ parseSize(height);
2721
+ merged.height = height;
2722
+ }
2713
2723
  applySize();
2714
2724
  controller.resizeCanvas();
2715
2725
  return this;
@@ -2740,8 +2750,12 @@ function createProgressCapsule(container) {
2740
2750
  controller.dispose();
2741
2751
  root.remove();
2742
2752
  },
2743
- textRatio: merged.textRatio,
2744
- cssVars: merged.cssVars,
2753
+ get textRatio() {
2754
+ return merged.textRatio;
2755
+ },
2756
+ get cssVars() {
2757
+ return merged.cssVars;
2758
+ },
2745
2759
  dirty: dirty
2746
2760
  };
2747
2761
  }
@@ -2946,9 +2960,15 @@ function createColorBackground(host) {
2946
2960
  renderer.dispose();
2947
2961
  layer.remove();
2948
2962
  },
2949
- opacity: merged.opacity,
2950
- fallbackColor: merged.fallbackColor,
2951
- mouseColor: merged.mouseColor,
2963
+ get opacity() {
2964
+ return merged.opacity;
2965
+ },
2966
+ get fallbackColor() {
2967
+ return merged.fallbackColor;
2968
+ },
2969
+ get mouseColor() {
2970
+ return merged.mouseColor;
2971
+ },
2952
2972
  dirty: dirty
2953
2973
  };
2954
2974
  }
@@ -3001,17 +3021,23 @@ function makeWrapper(_ref) {
3001
3021
  this.applyAttrs();
3002
3022
  },
3003
3023
  recreate: function recreate() {
3024
+ var _this2 = this;
3004
3025
  var extraState = this.runtimeState();
3005
3026
  if (this.controller) this.controller.dispose();
3006
3027
  this.mountController(extraState);
3028
+ // 结构属性连续变化时,插槽内容可能在重建后才被 Vue 写入容器,
3029
+ // 补一次搬运确保不丢。
3030
+ this.$nextTick(function () {
3031
+ return _this2.moveSlots();
3032
+ });
3007
3033
  },
3008
3034
  scheduleRecreate: function scheduleRecreate() {
3009
- var _this2 = this;
3035
+ var _this3 = this;
3010
3036
  if (this._recreateQueued) return;
3011
3037
  this._recreateQueued = true;
3012
3038
  this.$nextTick(function () {
3013
- _this2._recreateQueued = false;
3014
- _this2.recreate();
3039
+ _this3._recreateQueued = false;
3040
+ _this3.recreate();
3015
3041
  });
3016
3042
  },
3017
3043
  moveSlots: function moveSlots() {
@@ -3181,7 +3207,7 @@ function makeCapsuleWrapper(createCapsule, render) {
3181
3207
  function makeProgressWrapper(createProgressCapsule, render) {
3182
3208
  return makeWrapper({
3183
3209
  name: 'ProgressCapsule',
3184
- props: ['preset', 'width', 'height', 'value', 'min', 'max', 'draggable', 'keyboard', 'disabled', 'readonly', 'edgeStyle', 'colors', 'textRatio', 'label', 'showValue', 'valueSuffix', 'quality', 'renderer', 'respectReducedMotion', 'cssVars'],
3210
+ props: ['preset', 'width', 'height', 'value', 'min', 'max', 'draggable', 'disabled', 'readonly', 'edgeStyle', 'colors', 'textRatio', 'label', 'showValue', 'valueSuffix', 'quality', 'renderer', 'respectReducedMotion', 'cssVars'],
3185
3211
  events: PROGRESS_EVENTS,
3186
3212
  create: createProgressCapsule,
3187
3213
  render: render,
@@ -3222,9 +3248,6 @@ function makeProgressWrapper(createProgressCapsule, render) {
3222
3248
  draggable: function draggable() {
3223
3249
  this.scheduleRecreate();
3224
3250
  },
3225
- keyboard: function keyboard() {
3226
- this.scheduleRecreate();
3227
- },
3228
3251
  renderer: function renderer() {
3229
3252
  this.scheduleRecreate();
3230
3253
  }
package/dist/vue3.mjs CHANGED
@@ -177,9 +177,13 @@ function getPreset(kind, ref) {
177
177
  const list = kind === 'capsule' ? CAPSULE_PRESETS : kind === 'progress' ? PROGRESS_PRESETS : null;
178
178
  if (!list) throw new Error(`Unknown preset kind: ${kind} (use "capsule" or "progress")`);
179
179
  const key = String(ref).trim().toLowerCase();
180
- const found = list.find(
181
- (preset) => preset.name.toLowerCase() === key
182
- );
180
+ let found = null;
181
+ for (let index = 0; index < list.length; index += 1) {
182
+ if (list[index].name.toLowerCase() === key) {
183
+ found = list[index];
184
+ break;
185
+ }
186
+ }
183
187
  if (!found) throw new Error(`Unknown ${kind} preset: ${ref}`);
184
188
  return found;
185
189
  }
@@ -198,9 +202,8 @@ const DEFAULTS = {
198
202
  width: 454,
199
203
  height: 104,
200
204
  min: 0,
201
- max: 100,
205
+ max: 100,
202
206
  draggable: true,
203
- keyboard: true,
204
207
  disabled: false,
205
208
  readonly: false,
206
209
  valueSuffix: '%',
@@ -393,7 +396,7 @@ function normalizeRgbArgs(args) {
393
396
  if (parts.length < 3) return null;
394
397
  const to255 = (value) => {
395
398
  if (typeof value !== 'string' || !value) return null;
396
- if (value.endsWith('%')) return clampChannel((parseFloat(value) / 100) * 255);
399
+ if (value.charAt(value.length - 1) === '%') return clampChannel((parseFloat(value) / 100) * 255);
397
400
  const number = Number(value);
398
401
  return Number.isFinite(number) ? clampChannel(number) : null;
399
402
  };
@@ -401,7 +404,11 @@ function normalizeRgbArgs(args) {
401
404
  const green = to255(parts[1]);
402
405
  const blue = to255(parts[2]);
403
406
  if (red === null || green === null || blue === null) return null;
404
- return `#${[red, green, blue].map((n) => n.toString(16).padStart(2, '0')).join('')}`;
407
+ const hex = (n) => {
408
+ const text = n.toString(16);
409
+ return text.length === 1 ? `0${text}` : text;
410
+ };
411
+ return `#${hex(red)}${hex(green)}${hex(blue)}`;
405
412
  }
406
413
 
407
414
  /**
@@ -758,12 +765,13 @@ function rgb(color, alpha = 1) {
758
765
  }
759
766
 
760
767
  class FallbackRenderer {
761
- constructor(canvas, preset) {
762
- this.canvas = canvas;
763
- this.preset = preset;
764
- this.context = canvas.getContext('2d');
765
- this.visible = true;
766
- }
768
+ constructor(canvas, preset) {
769
+ this.canvas = canvas;
770
+ this.preset = preset;
771
+ this.context = canvas.getContext('2d');
772
+ this.visible = true;
773
+ this.timePhase = 0;
774
+ }
767
775
 
768
776
  resize() {
769
777
  const rect = this.canvas.getBoundingClientRect();
@@ -779,7 +787,7 @@ class FallbackRenderer {
779
787
  drawNebula(time) {
780
788
  const ctx = this.context;
781
789
  const { width, height } = this.canvas;
782
- const t = time * (this.preset.speed || 1);
790
+ const t = (time + this.timePhase) * (this.preset.speed || 1);
783
791
  const phase = (this.preset.seed || 0) * 0.7;
784
792
  const gradient = ctx.createLinearGradient(0, 0, width, height);
785
793
  gradient.addColorStop(0, this.preset.colors[0]);
@@ -814,7 +822,10 @@ class FallbackRenderer {
814
822
  }
815
823
 
816
824
  randomize() {
817
- if (this.preset) this.preset.seed = Math.random() * 100;
825
+ if (this.preset) {
826
+ this.preset.seed = Math.random() * 100;
827
+ this.timePhase = Math.random() * Math.PI * 2;
828
+ }
818
829
  }
819
830
  setMouseColor() {}
820
831
  dispose() {}
@@ -1161,11 +1172,17 @@ function createCapsule(container, options = {}) {
1161
1172
  return this;
1162
1173
  },
1163
1174
  setSize(width, height) {
1164
- if (width !== undefined) merged.width = width;
1165
- if (height !== undefined) merged.height = height;
1166
- applySize();
1167
- return this;
1168
- },
1175
+ if (width !== undefined) {
1176
+ parseSize(width); // 非法尺寸直接抛错前先校验,避免污染内部状态
1177
+ merged.width = width;
1178
+ }
1179
+ if (height !== undefined) {
1180
+ parseSize(height);
1181
+ merged.height = height;
1182
+ }
1183
+ applySize();
1184
+ return this;
1185
+ },
1169
1186
  randomize() {
1170
1187
  this.setSeed(Math.random() * 100);
1171
1188
  return this;
@@ -1192,8 +1209,8 @@ function createCapsule(container, options = {}) {
1192
1209
  renderer.dispose();
1193
1210
  root.remove();
1194
1211
  },
1195
- textRatio: merged.textRatio,
1196
- cssVars: merged.cssVars,
1212
+ get textRatio() { return merged.textRatio; },
1213
+ get cssVars() { return merged.cssVars; },
1197
1214
  dirty
1198
1215
  };
1199
1216
  }
@@ -1678,13 +1695,17 @@ const PALETTES = {
1678
1695
  'tide': ['#0a2239', '#2e9bff', '#7fe3ff', '#eaf9ff']
1679
1696
  };
1680
1697
 
1681
- function drawCloud(context, x, y, radiusX, radiusY, color, alpha) {
1682
- context.save();
1683
- context.translate(x, y);
1684
- context.scale(1, radiusY / radiusX);
1685
- const gradient = context.createRadialGradient(0, 0, 0, 0, 0, radiusX);
1686
- gradient.addColorStop(0, `${color}${Math.round(alpha * 255).toString(16).padStart(2, '0')}`);
1687
- gradient.addColorStop(0.46, `${color}${Math.round(alpha * 0.42 * 255).toString(16).padStart(2, '0')}`);
1698
+ function drawCloud(context, x, y, radiusX, radiusY, color, alpha) {
1699
+ context.save();
1700
+ context.translate(x, y);
1701
+ context.scale(1, radiusY / radiusX);
1702
+ const gradient = context.createRadialGradient(0, 0, 0, 0, 0, radiusX);
1703
+ const alphaHex = (value) => {
1704
+ const text = Math.round(value).toString(16);
1705
+ return text.length === 1 ? `0${text}` : text;
1706
+ };
1707
+ gradient.addColorStop(0, `${color}${alphaHex(alpha * 255)}`);
1708
+ gradient.addColorStop(0.46, `${color}${alphaHex(alpha * 0.42 * 255)}`);
1688
1709
  gradient.addColorStop(1, `${color}00`);
1689
1710
  context.fillStyle = gradient;
1690
1711
  context.fillRect(-radiusX, -radiusX, radiusX * 2, radiusX * 2);
@@ -2114,9 +2135,14 @@ class ProgressCapsuleController {
2114
2135
  ctx.restore();
2115
2136
  }
2116
2137
 
2117
- setRange(min, max) {
2118
- this.min = min;
2119
- this.max = max;
2138
+ setRange(min, max) {
2139
+ if (min > max) {
2140
+ const swap = min;
2141
+ min = max;
2142
+ max = swap;
2143
+ }
2144
+ this.min = min;
2145
+ this.max = max;
2120
2146
  const clamped = clamp(this.value, this.min, this.max);
2121
2147
  if (clamped !== this.value) this.setProgress(clamped, 'prop');
2122
2148
  }
@@ -2311,33 +2337,7 @@ class ProgressCapsuleController {
2311
2337
  this.root.addEventListener('pointercancel', this.handlers.pointercancel);
2312
2338
  }
2313
2339
 
2314
- if (this.options.keyboard !== false) {
2315
- this.handlers.keydown = (event) => {
2316
- const step = (this.max - this.min) * 0.02;
2317
- const actions = {
2318
- ArrowLeft: -step,
2319
- ArrowDown: -step,
2320
- ArrowRight: step,
2321
- ArrowUp: step,
2322
- PageDown: -step * 5,
2323
- PageUp: step * 5
2324
- };
2325
- if (event.key === 'Home') {
2326
- event.preventDefault();
2327
- this.setProgress(this.min, 'keyboard');
2328
- } else if (event.key === 'End') {
2329
- event.preventDefault();
2330
- this.setProgress(this.max, 'keyboard');
2331
- } else if (actions[event.key]) {
2332
- event.preventDefault();
2333
- this.setProgress(this.value + actions[event.key], 'keyboard');
2334
- } else {
2335
- return;
2336
- }
2337
- };
2338
- this.root.addEventListener('keydown', this.handlers.keydown);
2339
- }
2340
- }
2340
+ }
2341
2341
 
2342
2342
  update(delta, paused) {
2343
2343
  if (!paused) this.flowTime += delta;
@@ -2375,7 +2375,7 @@ class ProgressCapsuleController {
2375
2375
  * Mount a fluid progress capsule into `container`.
2376
2376
  *
2377
2377
  * Options: preset (id/code/name or object), width, height, value, min, max,
2378
- * draggable, keyboard, colors, edgeStyle, textRatio (0-100, text region
2378
+ * draggable, colors, edgeStyle, textRatio (0-100, text region
2379
2379
  * width in percent), text (HTML string or DOM nodes for the text slot),
2380
2380
  * colorContent (HTML string or DOM nodes for the color slot),
2381
2381
  * showValue (show/hide the right-side percentage), quality,
@@ -2388,6 +2388,11 @@ function createProgressCapsule(container, options = {}) {
2388
2388
 
2389
2389
  const preset = { ...getPreset('progress', options.preset ?? '星火') };
2390
2390
  const merged = normalizeOptions(DEFAULTS.progress, preset, options);
2391
+ if (merged.min > merged.max) {
2392
+ const swap = merged.min;
2393
+ merged.min = merged.max;
2394
+ merged.max = swap;
2395
+ }
2391
2396
  const normalizedColors = merged.colors.map(normalizeColor);
2392
2397
  if (normalizedColors.every(Boolean)) preset.colors = normalizedColors;
2393
2398
  preset.edgeStyle = merged.edgeStyle;
@@ -2399,7 +2404,6 @@ function createProgressCapsule(container, options = {}) {
2399
2404
  const readonly = merged.readonly === true || merged.readonly === '' || merged.readonly === 'true';
2400
2405
  const locked = disabled || readonly;
2401
2406
  const effectiveDraggable = locked ? false : merged.draggable !== false;
2402
- const effectiveKeyboard = locked ? false : merged.keyboard !== false;
2403
2407
  const dirty = {
2404
2408
  preset: false,
2405
2409
  colors: false,
@@ -2412,7 +2416,6 @@ function createProgressCapsule(container, options = {}) {
2412
2416
  const root = document.createElement('div');
2413
2417
  root.className = 'hj-capsule-root hj-progress-root';
2414
2418
  root.setAttribute('role', 'slider');
2415
- root.setAttribute('tabindex', '0');
2416
2419
  root.setAttribute('data-draggable', String(effectiveDraggable));
2417
2420
  if (disabled) {
2418
2421
  root.setAttribute('aria-disabled', 'true');
@@ -2422,6 +2425,7 @@ function createProgressCapsule(container, options = {}) {
2422
2425
  root.setAttribute('aria-readonly', 'true');
2423
2426
  root.classList.add('is-readonly');
2424
2427
  }
2428
+ if (locked) root.setAttribute('tabindex', '-1');
2425
2429
  root.setAttribute('aria-valuemin', String(merged.min ?? 0));
2426
2430
  root.setAttribute('aria-valuemax', String(merged.max ?? 100));
2427
2431
  root.setAttribute('aria-valuenow', String(preset.initialProgress));
@@ -2432,8 +2436,6 @@ function createProgressCapsule(container, options = {}) {
2432
2436
  );
2433
2437
  };
2434
2438
  updateAria();
2435
- if (!effectiveKeyboard) root.setAttribute('tabindex', '-1');
2436
-
2437
2439
  const canvas = document.createElement('canvas');
2438
2440
  canvas.className = 'hj-progress-canvas';
2439
2441
  canvas.setAttribute('aria-hidden', 'true');
@@ -2495,7 +2497,7 @@ function createProgressCapsule(container, options = {}) {
2495
2497
  valueElement,
2496
2498
  preset,
2497
2499
  emitter,
2498
- options: { ...merged, draggable: effectiveDraggable, keyboard: effectiveKeyboard },
2500
+ options: { ...merged, draggable: effectiveDraggable },
2499
2501
  copy,
2500
2502
  dirty
2501
2503
  });
@@ -2636,10 +2638,16 @@ function createProgressCapsule(container, options = {}) {
2636
2638
  controller.resizeCanvas();
2637
2639
  return this;
2638
2640
  },
2639
- setSize(width, height) {
2640
- if (width !== undefined) merged.width = width;
2641
- if (height !== undefined) merged.height = height;
2642
- applySize();
2641
+ setSize(width, height) {
2642
+ if (width !== undefined) {
2643
+ parseSize(width);
2644
+ merged.width = width;
2645
+ }
2646
+ if (height !== undefined) {
2647
+ parseSize(height);
2648
+ merged.height = height;
2649
+ }
2650
+ applySize();
2643
2651
  controller.resizeCanvas();
2644
2652
  return this;
2645
2653
  },
@@ -2669,8 +2677,8 @@ function createProgressCapsule(container, options = {}) {
2669
2677
  controller.dispose();
2670
2678
  root.remove();
2671
2679
  },
2672
- textRatio: merged.textRatio,
2673
- cssVars: merged.cssVars,
2680
+ get textRatio() { return merged.textRatio; },
2681
+ get cssVars() { return merged.cssVars; },
2674
2682
  dirty
2675
2683
  };
2676
2684
  }
@@ -2890,9 +2898,9 @@ function createColorBackground(host, options = {}) {
2890
2898
  renderer.dispose();
2891
2899
  layer.remove();
2892
2900
  },
2893
- opacity: merged.opacity,
2894
- fallbackColor: merged.fallbackColor,
2895
- mouseColor: merged.mouseColor,
2901
+ get opacity() { return merged.opacity; },
2902
+ get fallbackColor() { return merged.fallbackColor; },
2903
+ get mouseColor() { return merged.mouseColor; },
2896
2904
  dirty
2897
2905
  };
2898
2906
  }
@@ -2928,6 +2936,9 @@ function makeWrapper({ name, props, events, create, render, methods, watch }) {
2928
2936
  const extraState = this.runtimeState();
2929
2937
  if (this.controller) this.controller.dispose();
2930
2938
  this.mountController(extraState);
2939
+ // 结构属性连续变化时,插槽内容可能在重建后才被 Vue 写入容器,
2940
+ // 补一次搬运确保不丢。
2941
+ this.$nextTick(() => this.moveSlots());
2931
2942
  },
2932
2943
  scheduleRecreate() {
2933
2944
  if (this._recreateQueued) return;
@@ -3077,7 +3088,7 @@ function makeProgressWrapper(createProgressCapsule, render) {
3077
3088
  name: 'ProgressCapsule',
3078
3089
  props: [
3079
3090
  'preset', 'width', 'height', 'value', 'min', 'max',
3080
- 'draggable', 'keyboard', 'disabled', 'readonly', 'edgeStyle', 'colors', 'textRatio', 'label', 'showValue', 'valueSuffix',
3091
+ 'draggable', 'disabled', 'readonly', 'edgeStyle', 'colors', 'textRatio', 'label', 'showValue', 'valueSuffix',
3081
3092
  'quality', 'renderer', 'respectReducedMotion', 'cssVars'
3082
3093
  ],
3083
3094
  events: PROGRESS_EVENTS,
@@ -3120,9 +3131,6 @@ function makeProgressWrapper(createProgressCapsule, render) {
3120
3131
  draggable() {
3121
3132
  this.scheduleRecreate();
3122
3133
  },
3123
- keyboard() {
3124
- this.scheduleRecreate();
3125
- },
3126
3134
  renderer() {
3127
3135
  this.scheduleRecreate();
3128
3136
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@5even7/dlc-ui",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/types/index.d.ts CHANGED
@@ -59,7 +59,6 @@ export interface ProgressOptions {
59
59
  min?: number;
60
60
  max?: number;
61
61
  draggable?: boolean;
62
- keyboard?: boolean;
63
62
  disabled?: boolean;
64
63
  readonly?: boolean;
65
64
  valueSuffix?: string;
@@ -181,7 +180,7 @@ export declare function getPreset(kind: 'capsule' | 'progress', ref: string): Ca
181
180
 
182
181
  export declare const DEFAULTS: {
183
182
  capsule: Required<Pick<CapsuleOptions, 'width' | 'height' | 'quality' | 'respectReducedMotion' | 'mouseColor' | 'renderer' | 'textRatio'>>;
184
- progress: Required<Pick<ProgressOptions, 'width' | 'height' | 'min' | 'max' | 'draggable' | 'keyboard' | 'disabled' | 'readonly' | 'valueSuffix' | 'edgeStyle' | 'quality' | 'respectReducedMotion' | 'renderer' | 'textRatio' | 'showValue'>>;
183
+ progress: Required<Pick<ProgressOptions, 'width' | 'height' | 'min' | 'max' | 'draggable' | 'disabled' | 'readonly' | 'valueSuffix' | 'edgeStyle' | 'quality' | 'respectReducedMotion' | 'renderer' | 'textRatio' | 'showValue'>>;
185
184
  };
186
185
 
187
186
  export declare const COPY: Copy;