@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/index.cjs
CHANGED
|
@@ -417,9 +417,13 @@ function getPreset(kind, ref) {
|
|
|
417
417
|
var list = kind === 'capsule' ? CAPSULE_PRESETS : kind === 'progress' ? PROGRESS_PRESETS : null;
|
|
418
418
|
if (!list) throw new Error("Unknown preset kind: ".concat(kind, " (use \"capsule\" or \"progress\")"));
|
|
419
419
|
var key = String(ref).trim().toLowerCase();
|
|
420
|
-
var found =
|
|
421
|
-
|
|
422
|
-
|
|
420
|
+
var found = null;
|
|
421
|
+
for (var index = 0; index < list.length; index += 1) {
|
|
422
|
+
if (list[index].name.toLowerCase() === key) {
|
|
423
|
+
found = list[index];
|
|
424
|
+
break;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
423
427
|
if (!found) throw new Error("Unknown ".concat(kind, " preset: ").concat(ref));
|
|
424
428
|
return found;
|
|
425
429
|
}
|
|
@@ -440,7 +444,6 @@ var DEFAULTS = {
|
|
|
440
444
|
min: 0,
|
|
441
445
|
max: 100,
|
|
442
446
|
draggable: true,
|
|
443
|
-
keyboard: true,
|
|
444
447
|
disabled: false,
|
|
445
448
|
readonly: false,
|
|
446
449
|
valueSuffix: '%',
|
|
@@ -631,7 +634,7 @@ function normalizeRgbArgs(args) {
|
|
|
631
634
|
if (parts.length < 3) return null;
|
|
632
635
|
var to255 = function to255(value) {
|
|
633
636
|
if (typeof value !== 'string' || !value) return null;
|
|
634
|
-
if (value.
|
|
637
|
+
if (value.charAt(value.length - 1) === '%') return clampChannel(parseFloat(value) / 100 * 255);
|
|
635
638
|
var number = Number(value);
|
|
636
639
|
return Number.isFinite(number) ? clampChannel(number) : null;
|
|
637
640
|
};
|
|
@@ -639,9 +642,11 @@ function normalizeRgbArgs(args) {
|
|
|
639
642
|
var green = to255(parts[1]);
|
|
640
643
|
var blue = to255(parts[2]);
|
|
641
644
|
if (red === null || green === null || blue === null) return null;
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
+
var hex = function hex(n) {
|
|
646
|
+
var text = n.toString(16);
|
|
647
|
+
return text.length === 1 ? "0".concat(text) : text;
|
|
648
|
+
};
|
|
649
|
+
return "#".concat(hex(red)).concat(hex(green)).concat(hex(blue));
|
|
645
650
|
}
|
|
646
651
|
|
|
647
652
|
/**
|
|
@@ -911,6 +916,7 @@ var FallbackRenderer = /*#__PURE__*/function () {
|
|
|
911
916
|
this.preset = preset;
|
|
912
917
|
this.context = canvas.getContext('2d');
|
|
913
918
|
this.visible = true;
|
|
919
|
+
this.timePhase = 0;
|
|
914
920
|
}
|
|
915
921
|
return _createClass(FallbackRenderer, [{
|
|
916
922
|
key: "resize",
|
|
@@ -931,7 +937,7 @@ var FallbackRenderer = /*#__PURE__*/function () {
|
|
|
931
937
|
var _this$canvas = this.canvas,
|
|
932
938
|
width = _this$canvas.width,
|
|
933
939
|
height = _this$canvas.height;
|
|
934
|
-
var t = time * (this.preset.speed || 1);
|
|
940
|
+
var t = (time + this.timePhase) * (this.preset.speed || 1);
|
|
935
941
|
var phase = (this.preset.seed || 0) * 0.7;
|
|
936
942
|
var gradient = ctx.createLinearGradient(0, 0, width, height);
|
|
937
943
|
gradient.addColorStop(0, this.preset.colors[0]);
|
|
@@ -968,7 +974,10 @@ var FallbackRenderer = /*#__PURE__*/function () {
|
|
|
968
974
|
}, {
|
|
969
975
|
key: "randomize",
|
|
970
976
|
value: function randomize() {
|
|
971
|
-
if (this.preset)
|
|
977
|
+
if (this.preset) {
|
|
978
|
+
this.preset.seed = Math.random() * 100;
|
|
979
|
+
this.timePhase = Math.random() * Math.PI * 2;
|
|
980
|
+
}
|
|
972
981
|
}
|
|
973
982
|
}, {
|
|
974
983
|
key: "setMouseColor",
|
|
@@ -1221,8 +1230,9 @@ function createCapsule(container) {
|
|
|
1221
1230
|
}
|
|
1222
1231
|
if (merged.textRatio !== undefined) {
|
|
1223
1232
|
root.style.setProperty('--hj-text-width', "".concat(merged.textRatio, "%"));
|
|
1224
|
-
|
|
1225
|
-
|
|
1233
|
+
// textRatio 是文字区宽度的唯一权威值:min-width 会阻止其缩小到
|
|
1234
|
+
// 164px 以下(--hj-copy-min-width 的历史默认),这里强制归零。
|
|
1235
|
+
root.style.setProperty('--hj-text-min-width', '0');
|
|
1226
1236
|
}
|
|
1227
1237
|
renderer.resize();
|
|
1228
1238
|
};
|
|
@@ -1346,8 +1356,7 @@ function createCapsule(container) {
|
|
|
1346
1356
|
dirty.textRatio = true;
|
|
1347
1357
|
merged.textRatio = value;
|
|
1348
1358
|
root.style.setProperty('--hj-text-width', "".concat(value, "%"));
|
|
1349
|
-
|
|
1350
|
-
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');
|
|
1359
|
+
root.style.setProperty('--hj-text-min-width', '0');
|
|
1351
1360
|
return this;
|
|
1352
1361
|
},
|
|
1353
1362
|
setCssVars: function setCssVars(vars) {
|
|
@@ -1366,8 +1375,14 @@ function createCapsule(container) {
|
|
|
1366
1375
|
return this;
|
|
1367
1376
|
},
|
|
1368
1377
|
setSize: function setSize(width, height) {
|
|
1369
|
-
if (width !== undefined)
|
|
1370
|
-
|
|
1378
|
+
if (width !== undefined) {
|
|
1379
|
+
parseSize(width); // 非法尺寸直接抛错前先校验,避免污染内部状态
|
|
1380
|
+
merged.width = width;
|
|
1381
|
+
}
|
|
1382
|
+
if (height !== undefined) {
|
|
1383
|
+
parseSize(height);
|
|
1384
|
+
merged.height = height;
|
|
1385
|
+
}
|
|
1371
1386
|
applySize();
|
|
1372
1387
|
return this;
|
|
1373
1388
|
},
|
|
@@ -1396,8 +1411,12 @@ function createCapsule(container) {
|
|
|
1396
1411
|
renderer.dispose();
|
|
1397
1412
|
root.remove();
|
|
1398
1413
|
},
|
|
1399
|
-
textRatio
|
|
1400
|
-
|
|
1414
|
+
get textRatio() {
|
|
1415
|
+
return merged.textRatio;
|
|
1416
|
+
},
|
|
1417
|
+
get cssVars() {
|
|
1418
|
+
return merged.cssVars;
|
|
1419
|
+
},
|
|
1401
1420
|
dirty: dirty
|
|
1402
1421
|
};
|
|
1403
1422
|
}
|
|
@@ -1693,8 +1712,12 @@ function drawCloud(context, x, y, radiusX, radiusY, color, alpha) {
|
|
|
1693
1712
|
context.translate(x, y);
|
|
1694
1713
|
context.scale(1, radiusY / radiusX);
|
|
1695
1714
|
var gradient = context.createRadialGradient(0, 0, 0, 0, 0, radiusX);
|
|
1696
|
-
|
|
1697
|
-
|
|
1715
|
+
var alphaHex = function alphaHex(value) {
|
|
1716
|
+
var text = Math.round(value).toString(16);
|
|
1717
|
+
return text.length === 1 ? "0".concat(text) : text;
|
|
1718
|
+
};
|
|
1719
|
+
gradient.addColorStop(0, "".concat(color).concat(alphaHex(alpha * 255)));
|
|
1720
|
+
gradient.addColorStop(0.46, "".concat(color).concat(alphaHex(alpha * 0.42 * 255)));
|
|
1698
1721
|
gradient.addColorStop(1, "".concat(color, "00"));
|
|
1699
1722
|
context.fillStyle = gradient;
|
|
1700
1723
|
context.fillRect(-radiusX, -radiusX, radiusX * 2, radiusX * 2);
|
|
@@ -2144,6 +2167,11 @@ var ProgressCapsuleController = /*#__PURE__*/function () {
|
|
|
2144
2167
|
}, {
|
|
2145
2168
|
key: "setRange",
|
|
2146
2169
|
value: function setRange(min, max) {
|
|
2170
|
+
if (min > max) {
|
|
2171
|
+
var swap = min;
|
|
2172
|
+
min = max;
|
|
2173
|
+
max = swap;
|
|
2174
|
+
}
|
|
2147
2175
|
this.min = min;
|
|
2148
2176
|
this.max = max;
|
|
2149
2177
|
var clamped = clamp(this.value, this.min, this.max);
|
|
@@ -2361,32 +2389,6 @@ var ProgressCapsuleController = /*#__PURE__*/function () {
|
|
|
2361
2389
|
this.root.addEventListener('pointerup', this.handlers.pointerup);
|
|
2362
2390
|
this.root.addEventListener('pointercancel', this.handlers.pointercancel);
|
|
2363
2391
|
}
|
|
2364
|
-
if (this.options.keyboard !== false) {
|
|
2365
|
-
this.handlers.keydown = function (event) {
|
|
2366
|
-
var step = (_this3.max - _this3.min) * 0.02;
|
|
2367
|
-
var actions = {
|
|
2368
|
-
ArrowLeft: -step,
|
|
2369
|
-
ArrowDown: -step,
|
|
2370
|
-
ArrowRight: step,
|
|
2371
|
-
ArrowUp: step,
|
|
2372
|
-
PageDown: -step * 5,
|
|
2373
|
-
PageUp: step * 5
|
|
2374
|
-
};
|
|
2375
|
-
if (event.key === 'Home') {
|
|
2376
|
-
event.preventDefault();
|
|
2377
|
-
_this3.setProgress(_this3.min, 'keyboard');
|
|
2378
|
-
} else if (event.key === 'End') {
|
|
2379
|
-
event.preventDefault();
|
|
2380
|
-
_this3.setProgress(_this3.max, 'keyboard');
|
|
2381
|
-
} else if (actions[event.key]) {
|
|
2382
|
-
event.preventDefault();
|
|
2383
|
-
_this3.setProgress(_this3.value + actions[event.key], 'keyboard');
|
|
2384
|
-
} else {
|
|
2385
|
-
return;
|
|
2386
|
-
}
|
|
2387
|
-
};
|
|
2388
|
-
this.root.addEventListener('keydown', this.handlers.keydown);
|
|
2389
|
-
}
|
|
2390
2392
|
}
|
|
2391
2393
|
}, {
|
|
2392
2394
|
key: "update",
|
|
@@ -2433,7 +2435,7 @@ var ProgressCapsuleController = /*#__PURE__*/function () {
|
|
|
2433
2435
|
* Mount a fluid progress capsule into `container`.
|
|
2434
2436
|
*
|
|
2435
2437
|
* Options: preset (id/code/name or object), width, height, value, min, max,
|
|
2436
|
-
* draggable,
|
|
2438
|
+
* draggable, colors, edgeStyle, textRatio (0-100, text region
|
|
2437
2439
|
* width in percent), text (HTML string or DOM nodes for the text slot),
|
|
2438
2440
|
* colorContent (HTML string or DOM nodes for the color slot),
|
|
2439
2441
|
* showValue (show/hide the right-side percentage), quality,
|
|
@@ -2447,6 +2449,11 @@ function createProgressCapsule(container) {
|
|
|
2447
2449
|
}
|
|
2448
2450
|
var preset = _objectSpread2({}, getPreset('progress', (_options$preset = options.preset) !== null && _options$preset !== void 0 ? _options$preset : '星火'));
|
|
2449
2451
|
var merged = normalizeOptions(DEFAULTS.progress, preset, options);
|
|
2452
|
+
if (merged.min > merged.max) {
|
|
2453
|
+
var swap = merged.min;
|
|
2454
|
+
merged.min = merged.max;
|
|
2455
|
+
merged.max = swap;
|
|
2456
|
+
}
|
|
2450
2457
|
var normalizedColors = merged.colors.map(normalizeColor);
|
|
2451
2458
|
if (normalizedColors.every(Boolean)) preset.colors = normalizedColors;
|
|
2452
2459
|
preset.edgeStyle = merged.edgeStyle;
|
|
@@ -2458,7 +2465,6 @@ function createProgressCapsule(container) {
|
|
|
2458
2465
|
var readonly = merged.readonly === true || merged.readonly === '' || merged.readonly === 'true';
|
|
2459
2466
|
var locked = disabled || readonly;
|
|
2460
2467
|
var effectiveDraggable = locked ? false : merged.draggable !== false;
|
|
2461
|
-
var effectiveKeyboard = locked ? false : merged.keyboard !== false;
|
|
2462
2468
|
var dirty = {
|
|
2463
2469
|
preset: false,
|
|
2464
2470
|
colors: false,
|
|
@@ -2470,7 +2476,6 @@ function createProgressCapsule(container) {
|
|
|
2470
2476
|
var root = document.createElement('div');
|
|
2471
2477
|
root.className = 'hj-capsule-root hj-progress-root';
|
|
2472
2478
|
root.setAttribute('role', 'slider');
|
|
2473
|
-
root.setAttribute('tabindex', '0');
|
|
2474
2479
|
root.setAttribute('data-draggable', String(effectiveDraggable));
|
|
2475
2480
|
if (disabled) {
|
|
2476
2481
|
root.setAttribute('aria-disabled', 'true');
|
|
@@ -2480,6 +2485,7 @@ function createProgressCapsule(container) {
|
|
|
2480
2485
|
root.setAttribute('aria-readonly', 'true');
|
|
2481
2486
|
root.classList.add('is-readonly');
|
|
2482
2487
|
}
|
|
2488
|
+
if (locked) root.setAttribute('tabindex', '-1');
|
|
2483
2489
|
root.setAttribute('aria-valuemin', String((_merged$min = merged.min) !== null && _merged$min !== void 0 ? _merged$min : 0));
|
|
2484
2490
|
root.setAttribute('aria-valuemax', String((_merged$max = merged.max) !== null && _merged$max !== void 0 ? _merged$max : 100));
|
|
2485
2491
|
root.setAttribute('aria-valuenow', String(preset.initialProgress));
|
|
@@ -2491,7 +2497,6 @@ function createProgressCapsule(container) {
|
|
|
2491
2497
|
}));
|
|
2492
2498
|
};
|
|
2493
2499
|
updateAria();
|
|
2494
|
-
if (!effectiveKeyboard) root.setAttribute('tabindex', '-1');
|
|
2495
2500
|
var canvas = document.createElement('canvas');
|
|
2496
2501
|
canvas.className = 'hj-progress-canvas';
|
|
2497
2502
|
canvas.setAttribute('aria-hidden', 'true');
|
|
@@ -2558,8 +2563,7 @@ function createProgressCapsule(container) {
|
|
|
2558
2563
|
preset: preset,
|
|
2559
2564
|
emitter: emitter,
|
|
2560
2565
|
options: _objectSpread2(_objectSpread2({}, merged), {}, {
|
|
2561
|
-
draggable: effectiveDraggable
|
|
2562
|
-
keyboard: effectiveKeyboard
|
|
2566
|
+
draggable: effectiveDraggable
|
|
2563
2567
|
}),
|
|
2564
2568
|
copy: copy,
|
|
2565
2569
|
dirty: dirty
|
|
@@ -2719,8 +2723,14 @@ function createProgressCapsule(container) {
|
|
|
2719
2723
|
return this;
|
|
2720
2724
|
},
|
|
2721
2725
|
setSize: function setSize(width, height) {
|
|
2722
|
-
if (width !== undefined)
|
|
2723
|
-
|
|
2726
|
+
if (width !== undefined) {
|
|
2727
|
+
parseSize(width);
|
|
2728
|
+
merged.width = width;
|
|
2729
|
+
}
|
|
2730
|
+
if (height !== undefined) {
|
|
2731
|
+
parseSize(height);
|
|
2732
|
+
merged.height = height;
|
|
2733
|
+
}
|
|
2724
2734
|
applySize();
|
|
2725
2735
|
controller.resizeCanvas();
|
|
2726
2736
|
return this;
|
|
@@ -2751,8 +2761,12 @@ function createProgressCapsule(container) {
|
|
|
2751
2761
|
controller.dispose();
|
|
2752
2762
|
root.remove();
|
|
2753
2763
|
},
|
|
2754
|
-
textRatio
|
|
2755
|
-
|
|
2764
|
+
get textRatio() {
|
|
2765
|
+
return merged.textRatio;
|
|
2766
|
+
},
|
|
2767
|
+
get cssVars() {
|
|
2768
|
+
return merged.cssVars;
|
|
2769
|
+
},
|
|
2756
2770
|
dirty: dirty
|
|
2757
2771
|
};
|
|
2758
2772
|
}
|
|
@@ -2957,9 +2971,15 @@ function createColorBackground(host) {
|
|
|
2957
2971
|
renderer.dispose();
|
|
2958
2972
|
layer.remove();
|
|
2959
2973
|
},
|
|
2960
|
-
opacity
|
|
2961
|
-
|
|
2962
|
-
|
|
2974
|
+
get opacity() {
|
|
2975
|
+
return merged.opacity;
|
|
2976
|
+
},
|
|
2977
|
+
get fallbackColor() {
|
|
2978
|
+
return merged.fallbackColor;
|
|
2979
|
+
},
|
|
2980
|
+
get mouseColor() {
|
|
2981
|
+
return merged.mouseColor;
|
|
2982
|
+
},
|
|
2963
2983
|
dirty: dirty
|
|
2964
2984
|
};
|
|
2965
2985
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -176,9 +176,13 @@ function getPreset(kind, ref) {
|
|
|
176
176
|
const list = kind === 'capsule' ? CAPSULE_PRESETS : kind === 'progress' ? PROGRESS_PRESETS : null;
|
|
177
177
|
if (!list) throw new Error(`Unknown preset kind: ${kind} (use "capsule" or "progress")`);
|
|
178
178
|
const key = String(ref).trim().toLowerCase();
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
179
|
+
let found = null;
|
|
180
|
+
for (let index = 0; index < list.length; index += 1) {
|
|
181
|
+
if (list[index].name.toLowerCase() === key) {
|
|
182
|
+
found = list[index];
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
182
186
|
if (!found) throw new Error(`Unknown ${kind} preset: ${ref}`);
|
|
183
187
|
return found;
|
|
184
188
|
}
|
|
@@ -197,9 +201,8 @@ const DEFAULTS = {
|
|
|
197
201
|
width: 454,
|
|
198
202
|
height: 104,
|
|
199
203
|
min: 0,
|
|
200
|
-
max: 100,
|
|
204
|
+
max: 100,
|
|
201
205
|
draggable: true,
|
|
202
|
-
keyboard: true,
|
|
203
206
|
disabled: false,
|
|
204
207
|
readonly: false,
|
|
205
208
|
valueSuffix: '%',
|
|
@@ -392,7 +395,7 @@ function normalizeRgbArgs(args) {
|
|
|
392
395
|
if (parts.length < 3) return null;
|
|
393
396
|
const to255 = (value) => {
|
|
394
397
|
if (typeof value !== 'string' || !value) return null;
|
|
395
|
-
if (value.
|
|
398
|
+
if (value.charAt(value.length - 1) === '%') return clampChannel((parseFloat(value) / 100) * 255);
|
|
396
399
|
const number = Number(value);
|
|
397
400
|
return Number.isFinite(number) ? clampChannel(number) : null;
|
|
398
401
|
};
|
|
@@ -400,7 +403,11 @@ function normalizeRgbArgs(args) {
|
|
|
400
403
|
const green = to255(parts[1]);
|
|
401
404
|
const blue = to255(parts[2]);
|
|
402
405
|
if (red === null || green === null || blue === null) return null;
|
|
403
|
-
|
|
406
|
+
const hex = (n) => {
|
|
407
|
+
const text = n.toString(16);
|
|
408
|
+
return text.length === 1 ? `0${text}` : text;
|
|
409
|
+
};
|
|
410
|
+
return `#${hex(red)}${hex(green)}${hex(blue)}`;
|
|
404
411
|
}
|
|
405
412
|
|
|
406
413
|
/**
|
|
@@ -763,12 +770,13 @@ function rgb(color, alpha = 1) {
|
|
|
763
770
|
}
|
|
764
771
|
|
|
765
772
|
class FallbackRenderer {
|
|
766
|
-
constructor(canvas, preset) {
|
|
767
|
-
this.canvas = canvas;
|
|
768
|
-
this.preset = preset;
|
|
769
|
-
this.context = canvas.getContext('2d');
|
|
770
|
-
this.visible = true;
|
|
771
|
-
|
|
773
|
+
constructor(canvas, preset) {
|
|
774
|
+
this.canvas = canvas;
|
|
775
|
+
this.preset = preset;
|
|
776
|
+
this.context = canvas.getContext('2d');
|
|
777
|
+
this.visible = true;
|
|
778
|
+
this.timePhase = 0;
|
|
779
|
+
}
|
|
772
780
|
|
|
773
781
|
resize() {
|
|
774
782
|
const rect = this.canvas.getBoundingClientRect();
|
|
@@ -784,7 +792,7 @@ class FallbackRenderer {
|
|
|
784
792
|
drawNebula(time) {
|
|
785
793
|
const ctx = this.context;
|
|
786
794
|
const { width, height } = this.canvas;
|
|
787
|
-
const t = time * (this.preset.speed || 1);
|
|
795
|
+
const t = (time + this.timePhase) * (this.preset.speed || 1);
|
|
788
796
|
const phase = (this.preset.seed || 0) * 0.7;
|
|
789
797
|
const gradient = ctx.createLinearGradient(0, 0, width, height);
|
|
790
798
|
gradient.addColorStop(0, this.preset.colors[0]);
|
|
@@ -819,7 +827,10 @@ class FallbackRenderer {
|
|
|
819
827
|
}
|
|
820
828
|
|
|
821
829
|
randomize() {
|
|
822
|
-
if (this.preset)
|
|
830
|
+
if (this.preset) {
|
|
831
|
+
this.preset.seed = Math.random() * 100;
|
|
832
|
+
this.timePhase = Math.random() * Math.PI * 2;
|
|
833
|
+
}
|
|
823
834
|
}
|
|
824
835
|
setMouseColor() {}
|
|
825
836
|
dispose() {}
|
|
@@ -1054,10 +1065,9 @@ function createCapsule(container, options = {}) {
|
|
|
1054
1065
|
for (const name of Object.keys(vars)) root.style.setProperty(name, vars[name]);
|
|
1055
1066
|
if (merged.textRatio !== undefined) {
|
|
1056
1067
|
root.style.setProperty('--hj-text-width', `${merged.textRatio}%`);
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
else root.style.removeProperty('--hj-text-min-width');
|
|
1068
|
+
// textRatio 是文字区宽度的唯一权威值:min-width 会阻止其缩小到
|
|
1069
|
+
// 164px 以下(--hj-copy-min-width 的历史默认),这里强制归零。
|
|
1070
|
+
root.style.setProperty('--hj-text-min-width', '0');
|
|
1061
1071
|
}
|
|
1062
1072
|
renderer.resize();
|
|
1063
1073
|
};
|
|
@@ -1156,10 +1166,7 @@ function createCapsule(container, options = {}) {
|
|
|
1156
1166
|
dirty.textRatio = true;
|
|
1157
1167
|
merged.textRatio = value;
|
|
1158
1168
|
root.style.setProperty('--hj-text-width', `${value}%`);
|
|
1159
|
-
|
|
1160
|
-
if (value === 0) root.style.setProperty('--hj-text-min-width', '0');
|
|
1161
|
-
else if (userMinWidth) root.style.setProperty('--hj-text-min-width', userMinWidth);
|
|
1162
|
-
else root.style.removeProperty('--hj-text-min-width');
|
|
1169
|
+
root.style.setProperty('--hj-text-min-width', '0');
|
|
1163
1170
|
return this;
|
|
1164
1171
|
},
|
|
1165
1172
|
setCssVars(vars) {
|
|
@@ -1175,11 +1182,17 @@ function createCapsule(container, options = {}) {
|
|
|
1175
1182
|
return this;
|
|
1176
1183
|
},
|
|
1177
1184
|
setSize(width, height) {
|
|
1178
|
-
if (width !== undefined)
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1185
|
+
if (width !== undefined) {
|
|
1186
|
+
parseSize(width); // 非法尺寸直接抛错前先校验,避免污染内部状态
|
|
1187
|
+
merged.width = width;
|
|
1188
|
+
}
|
|
1189
|
+
if (height !== undefined) {
|
|
1190
|
+
parseSize(height);
|
|
1191
|
+
merged.height = height;
|
|
1192
|
+
}
|
|
1193
|
+
applySize();
|
|
1194
|
+
return this;
|
|
1195
|
+
},
|
|
1183
1196
|
randomize() {
|
|
1184
1197
|
this.setSeed(Math.random() * 100);
|
|
1185
1198
|
return this;
|
|
@@ -1206,8 +1219,8 @@ function createCapsule(container, options = {}) {
|
|
|
1206
1219
|
renderer.dispose();
|
|
1207
1220
|
root.remove();
|
|
1208
1221
|
},
|
|
1209
|
-
textRatio
|
|
1210
|
-
cssVars
|
|
1222
|
+
get textRatio() { return merged.textRatio; },
|
|
1223
|
+
get cssVars() { return merged.cssVars; },
|
|
1211
1224
|
dirty
|
|
1212
1225
|
};
|
|
1213
1226
|
}
|
|
@@ -1692,13 +1705,17 @@ const PALETTES = {
|
|
|
1692
1705
|
'tide': ['#0a2239', '#2e9bff', '#7fe3ff', '#eaf9ff']
|
|
1693
1706
|
};
|
|
1694
1707
|
|
|
1695
|
-
function drawCloud(context, x, y, radiusX, radiusY, color, alpha) {
|
|
1696
|
-
context.save();
|
|
1697
|
-
context.translate(x, y);
|
|
1698
|
-
context.scale(1, radiusY / radiusX);
|
|
1699
|
-
const gradient = context.createRadialGradient(0, 0, 0, 0, 0, radiusX);
|
|
1700
|
-
|
|
1701
|
-
|
|
1708
|
+
function drawCloud(context, x, y, radiusX, radiusY, color, alpha) {
|
|
1709
|
+
context.save();
|
|
1710
|
+
context.translate(x, y);
|
|
1711
|
+
context.scale(1, radiusY / radiusX);
|
|
1712
|
+
const gradient = context.createRadialGradient(0, 0, 0, 0, 0, radiusX);
|
|
1713
|
+
const alphaHex = (value) => {
|
|
1714
|
+
const text = Math.round(value).toString(16);
|
|
1715
|
+
return text.length === 1 ? `0${text}` : text;
|
|
1716
|
+
};
|
|
1717
|
+
gradient.addColorStop(0, `${color}${alphaHex(alpha * 255)}`);
|
|
1718
|
+
gradient.addColorStop(0.46, `${color}${alphaHex(alpha * 0.42 * 255)}`);
|
|
1702
1719
|
gradient.addColorStop(1, `${color}00`);
|
|
1703
1720
|
context.fillStyle = gradient;
|
|
1704
1721
|
context.fillRect(-radiusX, -radiusX, radiusX * 2, radiusX * 2);
|
|
@@ -2128,9 +2145,14 @@ class ProgressCapsuleController {
|
|
|
2128
2145
|
ctx.restore();
|
|
2129
2146
|
}
|
|
2130
2147
|
|
|
2131
|
-
setRange(min, max) {
|
|
2132
|
-
|
|
2133
|
-
|
|
2148
|
+
setRange(min, max) {
|
|
2149
|
+
if (min > max) {
|
|
2150
|
+
const swap = min;
|
|
2151
|
+
min = max;
|
|
2152
|
+
max = swap;
|
|
2153
|
+
}
|
|
2154
|
+
this.min = min;
|
|
2155
|
+
this.max = max;
|
|
2134
2156
|
const clamped = clamp(this.value, this.min, this.max);
|
|
2135
2157
|
if (clamped !== this.value) this.setProgress(clamped, 'prop');
|
|
2136
2158
|
}
|
|
@@ -2325,33 +2347,7 @@ class ProgressCapsuleController {
|
|
|
2325
2347
|
this.root.addEventListener('pointercancel', this.handlers.pointercancel);
|
|
2326
2348
|
}
|
|
2327
2349
|
|
|
2328
|
-
|
|
2329
|
-
this.handlers.keydown = (event) => {
|
|
2330
|
-
const step = (this.max - this.min) * 0.02;
|
|
2331
|
-
const actions = {
|
|
2332
|
-
ArrowLeft: -step,
|
|
2333
|
-
ArrowDown: -step,
|
|
2334
|
-
ArrowRight: step,
|
|
2335
|
-
ArrowUp: step,
|
|
2336
|
-
PageDown: -step * 5,
|
|
2337
|
-
PageUp: step * 5
|
|
2338
|
-
};
|
|
2339
|
-
if (event.key === 'Home') {
|
|
2340
|
-
event.preventDefault();
|
|
2341
|
-
this.setProgress(this.min, 'keyboard');
|
|
2342
|
-
} else if (event.key === 'End') {
|
|
2343
|
-
event.preventDefault();
|
|
2344
|
-
this.setProgress(this.max, 'keyboard');
|
|
2345
|
-
} else if (actions[event.key]) {
|
|
2346
|
-
event.preventDefault();
|
|
2347
|
-
this.setProgress(this.value + actions[event.key], 'keyboard');
|
|
2348
|
-
} else {
|
|
2349
|
-
return;
|
|
2350
|
-
}
|
|
2351
|
-
};
|
|
2352
|
-
this.root.addEventListener('keydown', this.handlers.keydown);
|
|
2353
|
-
}
|
|
2354
|
-
}
|
|
2350
|
+
}
|
|
2355
2351
|
|
|
2356
2352
|
update(delta, paused) {
|
|
2357
2353
|
if (!paused) this.flowTime += delta;
|
|
@@ -2389,7 +2385,7 @@ class ProgressCapsuleController {
|
|
|
2389
2385
|
* Mount a fluid progress capsule into `container`.
|
|
2390
2386
|
*
|
|
2391
2387
|
* Options: preset (id/code/name or object), width, height, value, min, max,
|
|
2392
|
-
* draggable,
|
|
2388
|
+
* draggable, colors, edgeStyle, textRatio (0-100, text region
|
|
2393
2389
|
* width in percent), text (HTML string or DOM nodes for the text slot),
|
|
2394
2390
|
* colorContent (HTML string or DOM nodes for the color slot),
|
|
2395
2391
|
* showValue (show/hide the right-side percentage), quality,
|
|
@@ -2402,6 +2398,11 @@ function createProgressCapsule(container, options = {}) {
|
|
|
2402
2398
|
|
|
2403
2399
|
const preset = { ...getPreset('progress', options.preset ?? '星火') };
|
|
2404
2400
|
const merged = normalizeOptions(DEFAULTS.progress, preset, options);
|
|
2401
|
+
if (merged.min > merged.max) {
|
|
2402
|
+
const swap = merged.min;
|
|
2403
|
+
merged.min = merged.max;
|
|
2404
|
+
merged.max = swap;
|
|
2405
|
+
}
|
|
2405
2406
|
const normalizedColors = merged.colors.map(normalizeColor);
|
|
2406
2407
|
if (normalizedColors.every(Boolean)) preset.colors = normalizedColors;
|
|
2407
2408
|
preset.edgeStyle = merged.edgeStyle;
|
|
@@ -2413,7 +2414,6 @@ function createProgressCapsule(container, options = {}) {
|
|
|
2413
2414
|
const readonly = merged.readonly === true || merged.readonly === '' || merged.readonly === 'true';
|
|
2414
2415
|
const locked = disabled || readonly;
|
|
2415
2416
|
const effectiveDraggable = locked ? false : merged.draggable !== false;
|
|
2416
|
-
const effectiveKeyboard = locked ? false : merged.keyboard !== false;
|
|
2417
2417
|
const dirty = {
|
|
2418
2418
|
preset: false,
|
|
2419
2419
|
colors: false,
|
|
@@ -2426,7 +2426,6 @@ function createProgressCapsule(container, options = {}) {
|
|
|
2426
2426
|
const root = document.createElement('div');
|
|
2427
2427
|
root.className = 'hj-capsule-root hj-progress-root';
|
|
2428
2428
|
root.setAttribute('role', 'slider');
|
|
2429
|
-
root.setAttribute('tabindex', '0');
|
|
2430
2429
|
root.setAttribute('data-draggable', String(effectiveDraggable));
|
|
2431
2430
|
if (disabled) {
|
|
2432
2431
|
root.setAttribute('aria-disabled', 'true');
|
|
@@ -2436,6 +2435,7 @@ function createProgressCapsule(container, options = {}) {
|
|
|
2436
2435
|
root.setAttribute('aria-readonly', 'true');
|
|
2437
2436
|
root.classList.add('is-readonly');
|
|
2438
2437
|
}
|
|
2438
|
+
if (locked) root.setAttribute('tabindex', '-1');
|
|
2439
2439
|
root.setAttribute('aria-valuemin', String(merged.min ?? 0));
|
|
2440
2440
|
root.setAttribute('aria-valuemax', String(merged.max ?? 100));
|
|
2441
2441
|
root.setAttribute('aria-valuenow', String(preset.initialProgress));
|
|
@@ -2446,8 +2446,6 @@ function createProgressCapsule(container, options = {}) {
|
|
|
2446
2446
|
);
|
|
2447
2447
|
};
|
|
2448
2448
|
updateAria();
|
|
2449
|
-
if (!effectiveKeyboard) root.setAttribute('tabindex', '-1');
|
|
2450
|
-
|
|
2451
2449
|
const canvas = document.createElement('canvas');
|
|
2452
2450
|
canvas.className = 'hj-progress-canvas';
|
|
2453
2451
|
canvas.setAttribute('aria-hidden', 'true');
|
|
@@ -2509,7 +2507,7 @@ function createProgressCapsule(container, options = {}) {
|
|
|
2509
2507
|
valueElement,
|
|
2510
2508
|
preset,
|
|
2511
2509
|
emitter,
|
|
2512
|
-
options: { ...merged, draggable: effectiveDraggable
|
|
2510
|
+
options: { ...merged, draggable: effectiveDraggable },
|
|
2513
2511
|
copy,
|
|
2514
2512
|
dirty
|
|
2515
2513
|
});
|
|
@@ -2650,10 +2648,16 @@ function createProgressCapsule(container, options = {}) {
|
|
|
2650
2648
|
controller.resizeCanvas();
|
|
2651
2649
|
return this;
|
|
2652
2650
|
},
|
|
2653
|
-
setSize(width, height) {
|
|
2654
|
-
if (width !== undefined)
|
|
2655
|
-
|
|
2656
|
-
|
|
2651
|
+
setSize(width, height) {
|
|
2652
|
+
if (width !== undefined) {
|
|
2653
|
+
parseSize(width);
|
|
2654
|
+
merged.width = width;
|
|
2655
|
+
}
|
|
2656
|
+
if (height !== undefined) {
|
|
2657
|
+
parseSize(height);
|
|
2658
|
+
merged.height = height;
|
|
2659
|
+
}
|
|
2660
|
+
applySize();
|
|
2657
2661
|
controller.resizeCanvas();
|
|
2658
2662
|
return this;
|
|
2659
2663
|
},
|
|
@@ -2683,8 +2687,8 @@ function createProgressCapsule(container, options = {}) {
|
|
|
2683
2687
|
controller.dispose();
|
|
2684
2688
|
root.remove();
|
|
2685
2689
|
},
|
|
2686
|
-
textRatio
|
|
2687
|
-
cssVars
|
|
2690
|
+
get textRatio() { return merged.textRatio; },
|
|
2691
|
+
get cssVars() { return merged.cssVars; },
|
|
2688
2692
|
dirty
|
|
2689
2693
|
};
|
|
2690
2694
|
}
|
|
@@ -2904,9 +2908,9 @@ function createColorBackground(host, options = {}) {
|
|
|
2904
2908
|
renderer.dispose();
|
|
2905
2909
|
layer.remove();
|
|
2906
2910
|
},
|
|
2907
|
-
opacity
|
|
2908
|
-
fallbackColor
|
|
2909
|
-
mouseColor
|
|
2911
|
+
get opacity() { return merged.opacity; },
|
|
2912
|
+
get fallbackColor() { return merged.fallbackColor; },
|
|
2913
|
+
get mouseColor() { return merged.mouseColor; },
|
|
2910
2914
|
dirty
|
|
2911
2915
|
};
|
|
2912
2916
|
}
|