@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/CHANGELOG.md +14 -0
- package/README.md +3 -3
- package/dist/capsule.cjs +37 -17
- package/dist/capsule.mjs +42 -28
- package/dist/color.cjs +28 -12
- package/dist/color.mjs +28 -16
- package/dist/index.cjs +79 -59
- package/dist/index.mjs +86 -82
- package/dist/index.umd.js +79 -59
- package/dist/index.umd.min.js +1 -1
- package/dist/progress.cjs +46 -46
- package/dist/progress.mjs +54 -56
- package/dist/vue2.cjs +89 -66
- package/dist/vue2.mjs +90 -86
- package/dist/vue3.cjs +89 -66
- package/dist/vue3.mjs +90 -86
- package/package.json +1 -1
- package/types/index.d.ts +1 -2
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
|
-
|
|
151
|
-
|
|
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.
|
|
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
|
-
|
|
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
|
-
|
|
983
|
-
|
|
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
|
-
|
|
1431
|
-
|
|
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
|
-
|
|
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,
|
|
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
|
|
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)
|
|
1953
|
-
|
|
1954
|
-
|
|
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
|
|
1985
|
-
cssVars
|
|
1982
|
+
get textRatio() { return merged.textRatio; },
|
|
1983
|
+
get cssVars() { return merged.cssVars; },
|
|
1986
1984
|
dirty
|
|
1987
1985
|
};
|
|
1988
1986
|
}
|
package/dist/vue2.cjs
CHANGED
|
@@ -416,9 +416,13 @@ function getPreset(kind, ref) {
|
|
|
416
416
|
var list = kind === 'capsule' ? CAPSULE_PRESETS : kind === 'progress' ? PROGRESS_PRESETS : null;
|
|
417
417
|
if (!list) throw new Error("Unknown preset kind: ".concat(kind, " (use \"capsule\" or \"progress\")"));
|
|
418
418
|
var key = String(ref).trim().toLowerCase();
|
|
419
|
-
var found =
|
|
420
|
-
|
|
421
|
-
|
|
419
|
+
var found = null;
|
|
420
|
+
for (var index = 0; index < list.length; index += 1) {
|
|
421
|
+
if (list[index].name.toLowerCase() === key) {
|
|
422
|
+
found = list[index];
|
|
423
|
+
break;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
422
426
|
if (!found) throw new Error("Unknown ".concat(kind, " preset: ").concat(ref));
|
|
423
427
|
return found;
|
|
424
428
|
}
|
|
@@ -439,7 +443,6 @@ var DEFAULTS = {
|
|
|
439
443
|
min: 0,
|
|
440
444
|
max: 100,
|
|
441
445
|
draggable: true,
|
|
442
|
-
keyboard: true,
|
|
443
446
|
disabled: false,
|
|
444
447
|
readonly: false,
|
|
445
448
|
valueSuffix: '%',
|
|
@@ -630,7 +633,7 @@ function normalizeRgbArgs(args) {
|
|
|
630
633
|
if (parts.length < 3) return null;
|
|
631
634
|
var to255 = function to255(value) {
|
|
632
635
|
if (typeof value !== 'string' || !value) return null;
|
|
633
|
-
if (value.
|
|
636
|
+
if (value.charAt(value.length - 1) === '%') return clampChannel(parseFloat(value) / 100 * 255);
|
|
634
637
|
var number = Number(value);
|
|
635
638
|
return Number.isFinite(number) ? clampChannel(number) : null;
|
|
636
639
|
};
|
|
@@ -638,9 +641,11 @@ function normalizeRgbArgs(args) {
|
|
|
638
641
|
var green = to255(parts[1]);
|
|
639
642
|
var blue = to255(parts[2]);
|
|
640
643
|
if (red === null || green === null || blue === null) return null;
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
+
var hex = function hex(n) {
|
|
645
|
+
var text = n.toString(16);
|
|
646
|
+
return text.length === 1 ? "0".concat(text) : text;
|
|
647
|
+
};
|
|
648
|
+
return "#".concat(hex(red)).concat(hex(green)).concat(hex(blue));
|
|
644
649
|
}
|
|
645
650
|
|
|
646
651
|
/**
|
|
@@ -905,6 +910,7 @@ var FallbackRenderer = /*#__PURE__*/function () {
|
|
|
905
910
|
this.preset = preset;
|
|
906
911
|
this.context = canvas.getContext('2d');
|
|
907
912
|
this.visible = true;
|
|
913
|
+
this.timePhase = 0;
|
|
908
914
|
}
|
|
909
915
|
return _createClass(FallbackRenderer, [{
|
|
910
916
|
key: "resize",
|
|
@@ -925,7 +931,7 @@ var FallbackRenderer = /*#__PURE__*/function () {
|
|
|
925
931
|
var _this$canvas = this.canvas,
|
|
926
932
|
width = _this$canvas.width,
|
|
927
933
|
height = _this$canvas.height;
|
|
928
|
-
var t = time * (this.preset.speed || 1);
|
|
934
|
+
var t = (time + this.timePhase) * (this.preset.speed || 1);
|
|
929
935
|
var phase = (this.preset.seed || 0) * 0.7;
|
|
930
936
|
var gradient = ctx.createLinearGradient(0, 0, width, height);
|
|
931
937
|
gradient.addColorStop(0, this.preset.colors[0]);
|
|
@@ -962,7 +968,10 @@ var FallbackRenderer = /*#__PURE__*/function () {
|
|
|
962
968
|
}, {
|
|
963
969
|
key: "randomize",
|
|
964
970
|
value: function randomize() {
|
|
965
|
-
if (this.preset)
|
|
971
|
+
if (this.preset) {
|
|
972
|
+
this.preset.seed = Math.random() * 100;
|
|
973
|
+
this.timePhase = Math.random() * Math.PI * 2;
|
|
974
|
+
}
|
|
966
975
|
}
|
|
967
976
|
}, {
|
|
968
977
|
key: "setMouseColor",
|
|
@@ -1208,8 +1217,9 @@ function createCapsule(container) {
|
|
|
1208
1217
|
}
|
|
1209
1218
|
if (merged.textRatio !== undefined) {
|
|
1210
1219
|
root.style.setProperty('--hj-text-width', "".concat(merged.textRatio, "%"));
|
|
1211
|
-
|
|
1212
|
-
|
|
1220
|
+
// textRatio 是文字区宽度的唯一权威值:min-width 会阻止其缩小到
|
|
1221
|
+
// 164px 以下(--hj-copy-min-width 的历史默认),这里强制归零。
|
|
1222
|
+
root.style.setProperty('--hj-text-min-width', '0');
|
|
1213
1223
|
}
|
|
1214
1224
|
renderer.resize();
|
|
1215
1225
|
};
|
|
@@ -1333,8 +1343,7 @@ function createCapsule(container) {
|
|
|
1333
1343
|
dirty.textRatio = true;
|
|
1334
1344
|
merged.textRatio = value;
|
|
1335
1345
|
root.style.setProperty('--hj-text-width', "".concat(value, "%"));
|
|
1336
|
-
|
|
1337
|
-
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');
|
|
1346
|
+
root.style.setProperty('--hj-text-min-width', '0');
|
|
1338
1347
|
return this;
|
|
1339
1348
|
},
|
|
1340
1349
|
setCssVars: function setCssVars(vars) {
|
|
@@ -1353,8 +1362,14 @@ function createCapsule(container) {
|
|
|
1353
1362
|
return this;
|
|
1354
1363
|
},
|
|
1355
1364
|
setSize: function setSize(width, height) {
|
|
1356
|
-
if (width !== undefined)
|
|
1357
|
-
|
|
1365
|
+
if (width !== undefined) {
|
|
1366
|
+
parseSize(width); // 非法尺寸直接抛错前先校验,避免污染内部状态
|
|
1367
|
+
merged.width = width;
|
|
1368
|
+
}
|
|
1369
|
+
if (height !== undefined) {
|
|
1370
|
+
parseSize(height);
|
|
1371
|
+
merged.height = height;
|
|
1372
|
+
}
|
|
1358
1373
|
applySize();
|
|
1359
1374
|
return this;
|
|
1360
1375
|
},
|
|
@@ -1383,8 +1398,12 @@ function createCapsule(container) {
|
|
|
1383
1398
|
renderer.dispose();
|
|
1384
1399
|
root.remove();
|
|
1385
1400
|
},
|
|
1386
|
-
textRatio
|
|
1387
|
-
|
|
1401
|
+
get textRatio() {
|
|
1402
|
+
return merged.textRatio;
|
|
1403
|
+
},
|
|
1404
|
+
get cssVars() {
|
|
1405
|
+
return merged.cssVars;
|
|
1406
|
+
},
|
|
1388
1407
|
dirty: dirty
|
|
1389
1408
|
};
|
|
1390
1409
|
}
|
|
@@ -1680,8 +1699,12 @@ function drawCloud(context, x, y, radiusX, radiusY, color, alpha) {
|
|
|
1680
1699
|
context.translate(x, y);
|
|
1681
1700
|
context.scale(1, radiusY / radiusX);
|
|
1682
1701
|
var gradient = context.createRadialGradient(0, 0, 0, 0, 0, radiusX);
|
|
1683
|
-
|
|
1684
|
-
|
|
1702
|
+
var alphaHex = function alphaHex(value) {
|
|
1703
|
+
var text = Math.round(value).toString(16);
|
|
1704
|
+
return text.length === 1 ? "0".concat(text) : text;
|
|
1705
|
+
};
|
|
1706
|
+
gradient.addColorStop(0, "".concat(color).concat(alphaHex(alpha * 255)));
|
|
1707
|
+
gradient.addColorStop(0.46, "".concat(color).concat(alphaHex(alpha * 0.42 * 255)));
|
|
1685
1708
|
gradient.addColorStop(1, "".concat(color, "00"));
|
|
1686
1709
|
context.fillStyle = gradient;
|
|
1687
1710
|
context.fillRect(-radiusX, -radiusX, radiusX * 2, radiusX * 2);
|
|
@@ -2131,6 +2154,11 @@ var ProgressCapsuleController = /*#__PURE__*/function () {
|
|
|
2131
2154
|
}, {
|
|
2132
2155
|
key: "setRange",
|
|
2133
2156
|
value: function setRange(min, max) {
|
|
2157
|
+
if (min > max) {
|
|
2158
|
+
var swap = min;
|
|
2159
|
+
min = max;
|
|
2160
|
+
max = swap;
|
|
2161
|
+
}
|
|
2134
2162
|
this.min = min;
|
|
2135
2163
|
this.max = max;
|
|
2136
2164
|
var clamped = clamp(this.value, this.min, this.max);
|
|
@@ -2348,32 +2376,6 @@ var ProgressCapsuleController = /*#__PURE__*/function () {
|
|
|
2348
2376
|
this.root.addEventListener('pointerup', this.handlers.pointerup);
|
|
2349
2377
|
this.root.addEventListener('pointercancel', this.handlers.pointercancel);
|
|
2350
2378
|
}
|
|
2351
|
-
if (this.options.keyboard !== false) {
|
|
2352
|
-
this.handlers.keydown = function (event) {
|
|
2353
|
-
var step = (_this3.max - _this3.min) * 0.02;
|
|
2354
|
-
var actions = {
|
|
2355
|
-
ArrowLeft: -step,
|
|
2356
|
-
ArrowDown: -step,
|
|
2357
|
-
ArrowRight: step,
|
|
2358
|
-
ArrowUp: step,
|
|
2359
|
-
PageDown: -step * 5,
|
|
2360
|
-
PageUp: step * 5
|
|
2361
|
-
};
|
|
2362
|
-
if (event.key === 'Home') {
|
|
2363
|
-
event.preventDefault();
|
|
2364
|
-
_this3.setProgress(_this3.min, 'keyboard');
|
|
2365
|
-
} else if (event.key === 'End') {
|
|
2366
|
-
event.preventDefault();
|
|
2367
|
-
_this3.setProgress(_this3.max, 'keyboard');
|
|
2368
|
-
} else if (actions[event.key]) {
|
|
2369
|
-
event.preventDefault();
|
|
2370
|
-
_this3.setProgress(_this3.value + actions[event.key], 'keyboard');
|
|
2371
|
-
} else {
|
|
2372
|
-
return;
|
|
2373
|
-
}
|
|
2374
|
-
};
|
|
2375
|
-
this.root.addEventListener('keydown', this.handlers.keydown);
|
|
2376
|
-
}
|
|
2377
2379
|
}
|
|
2378
2380
|
}, {
|
|
2379
2381
|
key: "update",
|
|
@@ -2420,7 +2422,7 @@ var ProgressCapsuleController = /*#__PURE__*/function () {
|
|
|
2420
2422
|
* Mount a fluid progress capsule into `container`.
|
|
2421
2423
|
*
|
|
2422
2424
|
* Options: preset (id/code/name or object), width, height, value, min, max,
|
|
2423
|
-
* draggable,
|
|
2425
|
+
* draggable, colors, edgeStyle, textRatio (0-100, text region
|
|
2424
2426
|
* width in percent), text (HTML string or DOM nodes for the text slot),
|
|
2425
2427
|
* colorContent (HTML string or DOM nodes for the color slot),
|
|
2426
2428
|
* showValue (show/hide the right-side percentage), quality,
|
|
@@ -2434,6 +2436,11 @@ function createProgressCapsule(container) {
|
|
|
2434
2436
|
}
|
|
2435
2437
|
var preset = _objectSpread2({}, getPreset('progress', (_options$preset = options.preset) !== null && _options$preset !== void 0 ? _options$preset : '星火'));
|
|
2436
2438
|
var merged = normalizeOptions(DEFAULTS.progress, preset, options);
|
|
2439
|
+
if (merged.min > merged.max) {
|
|
2440
|
+
var swap = merged.min;
|
|
2441
|
+
merged.min = merged.max;
|
|
2442
|
+
merged.max = swap;
|
|
2443
|
+
}
|
|
2437
2444
|
var normalizedColors = merged.colors.map(normalizeColor);
|
|
2438
2445
|
if (normalizedColors.every(Boolean)) preset.colors = normalizedColors;
|
|
2439
2446
|
preset.edgeStyle = merged.edgeStyle;
|
|
@@ -2445,7 +2452,6 @@ function createProgressCapsule(container) {
|
|
|
2445
2452
|
var readonly = merged.readonly === true || merged.readonly === '' || merged.readonly === 'true';
|
|
2446
2453
|
var locked = disabled || readonly;
|
|
2447
2454
|
var effectiveDraggable = locked ? false : merged.draggable !== false;
|
|
2448
|
-
var effectiveKeyboard = locked ? false : merged.keyboard !== false;
|
|
2449
2455
|
var dirty = {
|
|
2450
2456
|
preset: false,
|
|
2451
2457
|
colors: false,
|
|
@@ -2457,7 +2463,6 @@ function createProgressCapsule(container) {
|
|
|
2457
2463
|
var root = document.createElement('div');
|
|
2458
2464
|
root.className = 'hj-capsule-root hj-progress-root';
|
|
2459
2465
|
root.setAttribute('role', 'slider');
|
|
2460
|
-
root.setAttribute('tabindex', '0');
|
|
2461
2466
|
root.setAttribute('data-draggable', String(effectiveDraggable));
|
|
2462
2467
|
if (disabled) {
|
|
2463
2468
|
root.setAttribute('aria-disabled', 'true');
|
|
@@ -2467,6 +2472,7 @@ function createProgressCapsule(container) {
|
|
|
2467
2472
|
root.setAttribute('aria-readonly', 'true');
|
|
2468
2473
|
root.classList.add('is-readonly');
|
|
2469
2474
|
}
|
|
2475
|
+
if (locked) root.setAttribute('tabindex', '-1');
|
|
2470
2476
|
root.setAttribute('aria-valuemin', String((_merged$min = merged.min) !== null && _merged$min !== void 0 ? _merged$min : 0));
|
|
2471
2477
|
root.setAttribute('aria-valuemax', String((_merged$max = merged.max) !== null && _merged$max !== void 0 ? _merged$max : 100));
|
|
2472
2478
|
root.setAttribute('aria-valuenow', String(preset.initialProgress));
|
|
@@ -2478,7 +2484,6 @@ function createProgressCapsule(container) {
|
|
|
2478
2484
|
}));
|
|
2479
2485
|
};
|
|
2480
2486
|
updateAria();
|
|
2481
|
-
if (!effectiveKeyboard) root.setAttribute('tabindex', '-1');
|
|
2482
2487
|
var canvas = document.createElement('canvas');
|
|
2483
2488
|
canvas.className = 'hj-progress-canvas';
|
|
2484
2489
|
canvas.setAttribute('aria-hidden', 'true');
|
|
@@ -2545,8 +2550,7 @@ function createProgressCapsule(container) {
|
|
|
2545
2550
|
preset: preset,
|
|
2546
2551
|
emitter: emitter,
|
|
2547
2552
|
options: _objectSpread2(_objectSpread2({}, merged), {}, {
|
|
2548
|
-
draggable: effectiveDraggable
|
|
2549
|
-
keyboard: effectiveKeyboard
|
|
2553
|
+
draggable: effectiveDraggable
|
|
2550
2554
|
}),
|
|
2551
2555
|
copy: copy,
|
|
2552
2556
|
dirty: dirty
|
|
@@ -2706,8 +2710,14 @@ function createProgressCapsule(container) {
|
|
|
2706
2710
|
return this;
|
|
2707
2711
|
},
|
|
2708
2712
|
setSize: function setSize(width, height) {
|
|
2709
|
-
if (width !== undefined)
|
|
2710
|
-
|
|
2713
|
+
if (width !== undefined) {
|
|
2714
|
+
parseSize(width);
|
|
2715
|
+
merged.width = width;
|
|
2716
|
+
}
|
|
2717
|
+
if (height !== undefined) {
|
|
2718
|
+
parseSize(height);
|
|
2719
|
+
merged.height = height;
|
|
2720
|
+
}
|
|
2711
2721
|
applySize();
|
|
2712
2722
|
controller.resizeCanvas();
|
|
2713
2723
|
return this;
|
|
@@ -2738,8 +2748,12 @@ function createProgressCapsule(container) {
|
|
|
2738
2748
|
controller.dispose();
|
|
2739
2749
|
root.remove();
|
|
2740
2750
|
},
|
|
2741
|
-
textRatio
|
|
2742
|
-
|
|
2751
|
+
get textRatio() {
|
|
2752
|
+
return merged.textRatio;
|
|
2753
|
+
},
|
|
2754
|
+
get cssVars() {
|
|
2755
|
+
return merged.cssVars;
|
|
2756
|
+
},
|
|
2743
2757
|
dirty: dirty
|
|
2744
2758
|
};
|
|
2745
2759
|
}
|
|
@@ -2944,9 +2958,15 @@ function createColorBackground(host) {
|
|
|
2944
2958
|
renderer.dispose();
|
|
2945
2959
|
layer.remove();
|
|
2946
2960
|
},
|
|
2947
|
-
opacity
|
|
2948
|
-
|
|
2949
|
-
|
|
2961
|
+
get opacity() {
|
|
2962
|
+
return merged.opacity;
|
|
2963
|
+
},
|
|
2964
|
+
get fallbackColor() {
|
|
2965
|
+
return merged.fallbackColor;
|
|
2966
|
+
},
|
|
2967
|
+
get mouseColor() {
|
|
2968
|
+
return merged.mouseColor;
|
|
2969
|
+
},
|
|
2950
2970
|
dirty: dirty
|
|
2951
2971
|
};
|
|
2952
2972
|
}
|
|
@@ -2999,17 +3019,23 @@ function makeWrapper(_ref) {
|
|
|
2999
3019
|
this.applyAttrs();
|
|
3000
3020
|
},
|
|
3001
3021
|
recreate: function recreate() {
|
|
3022
|
+
var _this2 = this;
|
|
3002
3023
|
var extraState = this.runtimeState();
|
|
3003
3024
|
if (this.controller) this.controller.dispose();
|
|
3004
3025
|
this.mountController(extraState);
|
|
3026
|
+
// 结构属性连续变化时,插槽内容可能在重建后才被 Vue 写入容器,
|
|
3027
|
+
// 补一次搬运确保不丢。
|
|
3028
|
+
this.$nextTick(function () {
|
|
3029
|
+
return _this2.moveSlots();
|
|
3030
|
+
});
|
|
3005
3031
|
},
|
|
3006
3032
|
scheduleRecreate: function scheduleRecreate() {
|
|
3007
|
-
var
|
|
3033
|
+
var _this3 = this;
|
|
3008
3034
|
if (this._recreateQueued) return;
|
|
3009
3035
|
this._recreateQueued = true;
|
|
3010
3036
|
this.$nextTick(function () {
|
|
3011
|
-
|
|
3012
|
-
|
|
3037
|
+
_this3._recreateQueued = false;
|
|
3038
|
+
_this3.recreate();
|
|
3013
3039
|
});
|
|
3014
3040
|
},
|
|
3015
3041
|
moveSlots: function moveSlots() {
|
|
@@ -3179,7 +3205,7 @@ function makeCapsuleWrapper(createCapsule, render) {
|
|
|
3179
3205
|
function makeProgressWrapper(createProgressCapsule, render) {
|
|
3180
3206
|
return makeWrapper({
|
|
3181
3207
|
name: 'ProgressCapsule',
|
|
3182
|
-
props: ['preset', 'width', 'height', 'value', 'min', 'max', 'draggable', '
|
|
3208
|
+
props: ['preset', 'width', 'height', 'value', 'min', 'max', 'draggable', 'disabled', 'readonly', 'edgeStyle', 'colors', 'textRatio', 'label', 'showValue', 'valueSuffix', 'quality', 'renderer', 'respectReducedMotion', 'cssVars'],
|
|
3183
3209
|
events: PROGRESS_EVENTS,
|
|
3184
3210
|
create: createProgressCapsule,
|
|
3185
3211
|
render: render,
|
|
@@ -3220,9 +3246,6 @@ function makeProgressWrapper(createProgressCapsule, render) {
|
|
|
3220
3246
|
draggable: function draggable() {
|
|
3221
3247
|
this.scheduleRecreate();
|
|
3222
3248
|
},
|
|
3223
|
-
keyboard: function keyboard() {
|
|
3224
|
-
this.scheduleRecreate();
|
|
3225
|
-
},
|
|
3226
3249
|
renderer: function renderer() {
|
|
3227
3250
|
this.scheduleRecreate();
|
|
3228
3251
|
}
|