@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/progress.cjs CHANGED
@@ -403,9 +403,13 @@ function getPreset(kind, ref) {
403
403
  var list = PROGRESS_PRESETS ;
404
404
  if (!list) throw new Error("Unknown preset kind: ".concat(kind, " (use \"capsule\" or \"progress\")"));
405
405
  var key = String(ref).trim().toLowerCase();
406
- var found = list.find(function (preset) {
407
- return preset.name.toLowerCase() === key;
408
- });
406
+ var found = null;
407
+ for (var index = 0; index < list.length; index += 1) {
408
+ if (list[index].name.toLowerCase() === key) {
409
+ found = list[index];
410
+ break;
411
+ }
412
+ }
409
413
  if (!found) throw new Error("Unknown ".concat(kind, " preset: ").concat(ref));
410
414
  return found;
411
415
  }
@@ -417,7 +421,6 @@ var DEFAULTS = {
417
421
  min: 0,
418
422
  max: 100,
419
423
  draggable: true,
420
- keyboard: true,
421
424
  disabled: false,
422
425
  readonly: false,
423
426
  valueSuffix: '%',
@@ -608,7 +611,7 @@ function normalizeRgbArgs(args) {
608
611
  if (parts.length < 3) return null;
609
612
  var to255 = function to255(value) {
610
613
  if (typeof value !== 'string' || !value) return null;
611
- if (value.endsWith('%')) return clampChannel(parseFloat(value) / 100 * 255);
614
+ if (value.charAt(value.length - 1) === '%') return clampChannel(parseFloat(value) / 100 * 255);
612
615
  var number = Number(value);
613
616
  return Number.isFinite(number) ? clampChannel(number) : null;
614
617
  };
@@ -616,9 +619,11 @@ function normalizeRgbArgs(args) {
616
619
  var green = to255(parts[1]);
617
620
  var blue = to255(parts[2]);
618
621
  if (red === null || green === null || blue === null) return null;
619
- return "#".concat([red, green, blue].map(function (n) {
620
- return n.toString(16).padStart(2, '0');
621
- }).join(''));
622
+ var hex = function hex(n) {
623
+ var text = n.toString(16);
624
+ return text.length === 1 ? "0".concat(text) : text;
625
+ };
626
+ return "#".concat(hex(red)).concat(hex(green)).concat(hex(blue));
622
627
  }
623
628
 
624
629
  /**
@@ -1050,8 +1055,12 @@ function drawCloud(context, x, y, radiusX, radiusY, color, alpha) {
1050
1055
  context.translate(x, y);
1051
1056
  context.scale(1, radiusY / radiusX);
1052
1057
  var gradient = context.createRadialGradient(0, 0, 0, 0, 0, radiusX);
1053
- gradient.addColorStop(0, "".concat(color).concat(Math.round(alpha * 255).toString(16).padStart(2, '0')));
1054
- gradient.addColorStop(0.46, "".concat(color).concat(Math.round(alpha * 0.42 * 255).toString(16).padStart(2, '0')));
1058
+ var alphaHex = function alphaHex(value) {
1059
+ var text = Math.round(value).toString(16);
1060
+ return text.length === 1 ? "0".concat(text) : text;
1061
+ };
1062
+ gradient.addColorStop(0, "".concat(color).concat(alphaHex(alpha * 255)));
1063
+ gradient.addColorStop(0.46, "".concat(color).concat(alphaHex(alpha * 0.42 * 255)));
1055
1064
  gradient.addColorStop(1, "".concat(color, "00"));
1056
1065
  context.fillStyle = gradient;
1057
1066
  context.fillRect(-radiusX, -radiusX, radiusX * 2, radiusX * 2);
@@ -1517,6 +1526,11 @@ var ProgressCapsuleController = /*#__PURE__*/function () {
1517
1526
  }, {
1518
1527
  key: "setRange",
1519
1528
  value: function setRange(min, max) {
1529
+ if (min > max) {
1530
+ var swap = min;
1531
+ min = max;
1532
+ max = swap;
1533
+ }
1520
1534
  this.min = min;
1521
1535
  this.max = max;
1522
1536
  var clamped = clamp(this.value, this.min, this.max);
@@ -1734,32 +1748,6 @@ var ProgressCapsuleController = /*#__PURE__*/function () {
1734
1748
  this.root.addEventListener('pointerup', this.handlers.pointerup);
1735
1749
  this.root.addEventListener('pointercancel', this.handlers.pointercancel);
1736
1750
  }
1737
- if (this.options.keyboard !== false) {
1738
- this.handlers.keydown = function (event) {
1739
- var step = (_this3.max - _this3.min) * 0.02;
1740
- var actions = {
1741
- ArrowLeft: -step,
1742
- ArrowDown: -step,
1743
- ArrowRight: step,
1744
- ArrowUp: step,
1745
- PageDown: -step * 5,
1746
- PageUp: step * 5
1747
- };
1748
- if (event.key === 'Home') {
1749
- event.preventDefault();
1750
- _this3.setProgress(_this3.min, 'keyboard');
1751
- } else if (event.key === 'End') {
1752
- event.preventDefault();
1753
- _this3.setProgress(_this3.max, 'keyboard');
1754
- } else if (actions[event.key]) {
1755
- event.preventDefault();
1756
- _this3.setProgress(_this3.value + actions[event.key], 'keyboard');
1757
- } else {
1758
- return;
1759
- }
1760
- };
1761
- this.root.addEventListener('keydown', this.handlers.keydown);
1762
- }
1763
1751
  }
1764
1752
  }, {
1765
1753
  key: "update",
@@ -1806,7 +1794,7 @@ var ProgressCapsuleController = /*#__PURE__*/function () {
1806
1794
  * Mount a fluid progress capsule into `container`.
1807
1795
  *
1808
1796
  * Options: preset (id/code/name or object), width, height, value, min, max,
1809
- * draggable, keyboard, colors, edgeStyle, textRatio (0-100, text region
1797
+ * draggable, colors, edgeStyle, textRatio (0-100, text region
1810
1798
  * width in percent), text (HTML string or DOM nodes for the text slot),
1811
1799
  * colorContent (HTML string or DOM nodes for the color slot),
1812
1800
  * showValue (show/hide the right-side percentage), quality,
@@ -1820,6 +1808,11 @@ function createProgressCapsule(container) {
1820
1808
  }
1821
1809
  var preset = _objectSpread2({}, getPreset('progress', (_options$preset = options.preset) !== null && _options$preset !== void 0 ? _options$preset : '星火'));
1822
1810
  var merged = normalizeOptions(DEFAULTS.progress, preset, options);
1811
+ if (merged.min > merged.max) {
1812
+ var swap = merged.min;
1813
+ merged.min = merged.max;
1814
+ merged.max = swap;
1815
+ }
1823
1816
  var normalizedColors = merged.colors.map(normalizeColor);
1824
1817
  if (normalizedColors.every(Boolean)) preset.colors = normalizedColors;
1825
1818
  preset.edgeStyle = merged.edgeStyle;
@@ -1831,7 +1824,6 @@ function createProgressCapsule(container) {
1831
1824
  var readonly = merged.readonly === true || merged.readonly === '' || merged.readonly === 'true';
1832
1825
  var locked = disabled || readonly;
1833
1826
  var effectiveDraggable = locked ? false : merged.draggable !== false;
1834
- var effectiveKeyboard = locked ? false : merged.keyboard !== false;
1835
1827
  var dirty = {
1836
1828
  preset: false,
1837
1829
  colors: false,
@@ -1843,7 +1835,6 @@ function createProgressCapsule(container) {
1843
1835
  var root = document.createElement('div');
1844
1836
  root.className = 'hj-capsule-root hj-progress-root';
1845
1837
  root.setAttribute('role', 'slider');
1846
- root.setAttribute('tabindex', '0');
1847
1838
  root.setAttribute('data-draggable', String(effectiveDraggable));
1848
1839
  if (disabled) {
1849
1840
  root.setAttribute('aria-disabled', 'true');
@@ -1853,6 +1844,7 @@ function createProgressCapsule(container) {
1853
1844
  root.setAttribute('aria-readonly', 'true');
1854
1845
  root.classList.add('is-readonly');
1855
1846
  }
1847
+ if (locked) root.setAttribute('tabindex', '-1');
1856
1848
  root.setAttribute('aria-valuemin', String((_merged$min = merged.min) !== null && _merged$min !== void 0 ? _merged$min : 0));
1857
1849
  root.setAttribute('aria-valuemax', String((_merged$max = merged.max) !== null && _merged$max !== void 0 ? _merged$max : 100));
1858
1850
  root.setAttribute('aria-valuenow', String(preset.initialProgress));
@@ -1864,7 +1856,6 @@ function createProgressCapsule(container) {
1864
1856
  }));
1865
1857
  };
1866
1858
  updateAria();
1867
- if (!effectiveKeyboard) root.setAttribute('tabindex', '-1');
1868
1859
  var canvas = document.createElement('canvas');
1869
1860
  canvas.className = 'hj-progress-canvas';
1870
1861
  canvas.setAttribute('aria-hidden', 'true');
@@ -1931,8 +1922,7 @@ function createProgressCapsule(container) {
1931
1922
  preset: preset,
1932
1923
  emitter: emitter,
1933
1924
  options: _objectSpread2(_objectSpread2({}, merged), {}, {
1934
- draggable: effectiveDraggable,
1935
- keyboard: effectiveKeyboard
1925
+ draggable: effectiveDraggable
1936
1926
  }),
1937
1927
  copy: copy,
1938
1928
  dirty: dirty
@@ -2092,8 +2082,14 @@ function createProgressCapsule(container) {
2092
2082
  return this;
2093
2083
  },
2094
2084
  setSize: function setSize(width, height) {
2095
- if (width !== undefined) merged.width = width;
2096
- if (height !== undefined) merged.height = height;
2085
+ if (width !== undefined) {
2086
+ parseSize(width);
2087
+ merged.width = width;
2088
+ }
2089
+ if (height !== undefined) {
2090
+ parseSize(height);
2091
+ merged.height = height;
2092
+ }
2097
2093
  applySize();
2098
2094
  controller.resizeCanvas();
2099
2095
  return this;
@@ -2124,8 +2120,12 @@ function createProgressCapsule(container) {
2124
2120
  controller.dispose();
2125
2121
  root.remove();
2126
2122
  },
2127
- textRatio: merged.textRatio,
2128
- cssVars: merged.cssVars,
2123
+ get textRatio() {
2124
+ return merged.textRatio;
2125
+ },
2126
+ get cssVars() {
2127
+ return merged.cssVars;
2128
+ },
2129
2129
  dirty: dirty
2130
2130
  };
2131
2131
  }
package/dist/progress.mjs CHANGED
@@ -147,9 +147,13 @@ function getPreset(kind, ref) {
147
147
  const list = PROGRESS_PRESETS ;
148
148
  if (!list) throw new Error(`Unknown preset kind: ${kind} (use "capsule" or "progress")`);
149
149
  const key = String(ref).trim().toLowerCase();
150
- const found = list.find(
151
- (preset) => preset.name.toLowerCase() === key
152
- );
150
+ let found = null;
151
+ for (let index = 0; index < list.length; index += 1) {
152
+ if (list[index].name.toLowerCase() === key) {
153
+ found = list[index];
154
+ break;
155
+ }
156
+ }
153
157
  if (!found) throw new Error(`Unknown ${kind} preset: ${ref}`);
154
158
  return found;
155
159
  }
@@ -159,9 +163,8 @@ const DEFAULTS = {
159
163
  width: 454,
160
164
  height: 104,
161
165
  min: 0,
162
- max: 100,
166
+ max: 100,
163
167
  draggable: true,
164
- keyboard: true,
165
168
  disabled: false,
166
169
  readonly: false,
167
170
  valueSuffix: '%',
@@ -354,7 +357,7 @@ function normalizeRgbArgs(args) {
354
357
  if (parts.length < 3) return null;
355
358
  const to255 = (value) => {
356
359
  if (typeof value !== 'string' || !value) return null;
357
- if (value.endsWith('%')) return clampChannel((parseFloat(value) / 100) * 255);
360
+ if (value.charAt(value.length - 1) === '%') return clampChannel((parseFloat(value) / 100) * 255);
358
361
  const number = Number(value);
359
362
  return Number.isFinite(number) ? clampChannel(number) : null;
360
363
  };
@@ -362,7 +365,11 @@ function normalizeRgbArgs(args) {
362
365
  const green = to255(parts[1]);
363
366
  const blue = to255(parts[2]);
364
367
  if (red === null || green === null || blue === null) return null;
365
- return `#${[red, green, blue].map((n) => n.toString(16).padStart(2, '0')).join('')}`;
368
+ const hex = (n) => {
369
+ const text = n.toString(16);
370
+ return text.length === 1 ? `0${text}` : text;
371
+ };
372
+ return `#${hex(red)}${hex(green)}${hex(blue)}`;
366
373
  }
367
374
 
368
375
  /**
@@ -974,13 +981,17 @@ const PALETTES = {
974
981
  'tide': ['#0a2239', '#2e9bff', '#7fe3ff', '#eaf9ff']
975
982
  };
976
983
 
977
- function drawCloud(context, x, y, radiusX, radiusY, color, alpha) {
978
- context.save();
979
- context.translate(x, y);
980
- context.scale(1, radiusY / radiusX);
981
- const gradient = context.createRadialGradient(0, 0, 0, 0, 0, radiusX);
982
- gradient.addColorStop(0, `${color}${Math.round(alpha * 255).toString(16).padStart(2, '0')}`);
983
- gradient.addColorStop(0.46, `${color}${Math.round(alpha * 0.42 * 255).toString(16).padStart(2, '0')}`);
984
+ function drawCloud(context, x, y, radiusX, radiusY, color, alpha) {
985
+ context.save();
986
+ context.translate(x, y);
987
+ context.scale(1, radiusY / radiusX);
988
+ const gradient = context.createRadialGradient(0, 0, 0, 0, 0, radiusX);
989
+ const alphaHex = (value) => {
990
+ const text = Math.round(value).toString(16);
991
+ return text.length === 1 ? `0${text}` : text;
992
+ };
993
+ gradient.addColorStop(0, `${color}${alphaHex(alpha * 255)}`);
994
+ gradient.addColorStop(0.46, `${color}${alphaHex(alpha * 0.42 * 255)}`);
984
995
  gradient.addColorStop(1, `${color}00`);
985
996
  context.fillStyle = gradient;
986
997
  context.fillRect(-radiusX, -radiusX, radiusX * 2, radiusX * 2);
@@ -1426,9 +1437,14 @@ class ProgressCapsuleController {
1426
1437
  ctx.restore();
1427
1438
  }
1428
1439
 
1429
- setRange(min, max) {
1430
- this.min = min;
1431
- this.max = max;
1440
+ setRange(min, max) {
1441
+ if (min > max) {
1442
+ const swap = min;
1443
+ min = max;
1444
+ max = swap;
1445
+ }
1446
+ this.min = min;
1447
+ this.max = max;
1432
1448
  const clamped = clamp(this.value, this.min, this.max);
1433
1449
  if (clamped !== this.value) this.setProgress(clamped, 'prop');
1434
1450
  }
@@ -1623,33 +1639,7 @@ class ProgressCapsuleController {
1623
1639
  this.root.addEventListener('pointercancel', this.handlers.pointercancel);
1624
1640
  }
1625
1641
 
1626
- if (this.options.keyboard !== false) {
1627
- this.handlers.keydown = (event) => {
1628
- const step = (this.max - this.min) * 0.02;
1629
- const actions = {
1630
- ArrowLeft: -step,
1631
- ArrowDown: -step,
1632
- ArrowRight: step,
1633
- ArrowUp: step,
1634
- PageDown: -step * 5,
1635
- PageUp: step * 5
1636
- };
1637
- if (event.key === 'Home') {
1638
- event.preventDefault();
1639
- this.setProgress(this.min, 'keyboard');
1640
- } else if (event.key === 'End') {
1641
- event.preventDefault();
1642
- this.setProgress(this.max, 'keyboard');
1643
- } else if (actions[event.key]) {
1644
- event.preventDefault();
1645
- this.setProgress(this.value + actions[event.key], 'keyboard');
1646
- } else {
1647
- return;
1648
- }
1649
- };
1650
- this.root.addEventListener('keydown', this.handlers.keydown);
1651
- }
1652
- }
1642
+ }
1653
1643
 
1654
1644
  update(delta, paused) {
1655
1645
  if (!paused) this.flowTime += delta;
@@ -1687,7 +1677,7 @@ class ProgressCapsuleController {
1687
1677
  * Mount a fluid progress capsule into `container`.
1688
1678
  *
1689
1679
  * Options: preset (id/code/name or object), width, height, value, min, max,
1690
- * draggable, keyboard, colors, edgeStyle, textRatio (0-100, text region
1680
+ * draggable, colors, edgeStyle, textRatio (0-100, text region
1691
1681
  * width in percent), text (HTML string or DOM nodes for the text slot),
1692
1682
  * colorContent (HTML string or DOM nodes for the color slot),
1693
1683
  * showValue (show/hide the right-side percentage), quality,
@@ -1700,6 +1690,11 @@ function createProgressCapsule(container, options = {}) {
1700
1690
 
1701
1691
  const preset = { ...getPreset('progress', options.preset ?? '星火') };
1702
1692
  const merged = normalizeOptions(DEFAULTS.progress, preset, options);
1693
+ if (merged.min > merged.max) {
1694
+ const swap = merged.min;
1695
+ merged.min = merged.max;
1696
+ merged.max = swap;
1697
+ }
1703
1698
  const normalizedColors = merged.colors.map(normalizeColor);
1704
1699
  if (normalizedColors.every(Boolean)) preset.colors = normalizedColors;
1705
1700
  preset.edgeStyle = merged.edgeStyle;
@@ -1711,7 +1706,6 @@ function createProgressCapsule(container, options = {}) {
1711
1706
  const readonly = merged.readonly === true || merged.readonly === '' || merged.readonly === 'true';
1712
1707
  const locked = disabled || readonly;
1713
1708
  const effectiveDraggable = locked ? false : merged.draggable !== false;
1714
- const effectiveKeyboard = locked ? false : merged.keyboard !== false;
1715
1709
  const dirty = {
1716
1710
  preset: false,
1717
1711
  colors: false,
@@ -1724,7 +1718,6 @@ function createProgressCapsule(container, options = {}) {
1724
1718
  const root = document.createElement('div');
1725
1719
  root.className = 'hj-capsule-root hj-progress-root';
1726
1720
  root.setAttribute('role', 'slider');
1727
- root.setAttribute('tabindex', '0');
1728
1721
  root.setAttribute('data-draggable', String(effectiveDraggable));
1729
1722
  if (disabled) {
1730
1723
  root.setAttribute('aria-disabled', 'true');
@@ -1734,6 +1727,7 @@ function createProgressCapsule(container, options = {}) {
1734
1727
  root.setAttribute('aria-readonly', 'true');
1735
1728
  root.classList.add('is-readonly');
1736
1729
  }
1730
+ if (locked) root.setAttribute('tabindex', '-1');
1737
1731
  root.setAttribute('aria-valuemin', String(merged.min ?? 0));
1738
1732
  root.setAttribute('aria-valuemax', String(merged.max ?? 100));
1739
1733
  root.setAttribute('aria-valuenow', String(preset.initialProgress));
@@ -1744,8 +1738,6 @@ function createProgressCapsule(container, options = {}) {
1744
1738
  );
1745
1739
  };
1746
1740
  updateAria();
1747
- if (!effectiveKeyboard) root.setAttribute('tabindex', '-1');
1748
-
1749
1741
  const canvas = document.createElement('canvas');
1750
1742
  canvas.className = 'hj-progress-canvas';
1751
1743
  canvas.setAttribute('aria-hidden', 'true');
@@ -1807,7 +1799,7 @@ function createProgressCapsule(container, options = {}) {
1807
1799
  valueElement,
1808
1800
  preset,
1809
1801
  emitter,
1810
- options: { ...merged, draggable: effectiveDraggable, keyboard: effectiveKeyboard },
1802
+ options: { ...merged, draggable: effectiveDraggable },
1811
1803
  copy,
1812
1804
  dirty
1813
1805
  });
@@ -1948,10 +1940,16 @@ function createProgressCapsule(container, options = {}) {
1948
1940
  controller.resizeCanvas();
1949
1941
  return this;
1950
1942
  },
1951
- setSize(width, height) {
1952
- if (width !== undefined) merged.width = width;
1953
- if (height !== undefined) merged.height = height;
1954
- applySize();
1943
+ setSize(width, height) {
1944
+ if (width !== undefined) {
1945
+ parseSize(width);
1946
+ merged.width = width;
1947
+ }
1948
+ if (height !== undefined) {
1949
+ parseSize(height);
1950
+ merged.height = height;
1951
+ }
1952
+ applySize();
1955
1953
  controller.resizeCanvas();
1956
1954
  return this;
1957
1955
  },
@@ -1981,8 +1979,8 @@ function createProgressCapsule(container, options = {}) {
1981
1979
  controller.dispose();
1982
1980
  root.remove();
1983
1981
  },
1984
- textRatio: merged.textRatio,
1985
- cssVars: merged.cssVars,
1982
+ get textRatio() { return merged.textRatio; },
1983
+ get cssVars() { return merged.cssVars; },
1986
1984
  dirty
1987
1985
  };
1988
1986
  }