@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/CHANGELOG.md +10 -0
- package/README.md +3 -3
- package/dist/capsule.cjs +33 -13
- package/dist/capsule.mjs +38 -20
- package/dist/color.cjs +28 -12
- package/dist/color.mjs +28 -16
- package/dist/index.cjs +75 -55
- package/dist/index.mjs +82 -74
- package/dist/index.umd.js +75 -55
- package/dist/index.umd.min.js +1 -1
- package/dist/progress.cjs +46 -46
- package/dist/progress.mjs +54 -56
- package/dist/vue2.cjs +85 -62
- package/dist/vue2.mjs +86 -78
- package/dist/vue3.cjs +85 -62
- package/dist/vue3.mjs +86 -78
- 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",
|
|
@@ -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() {}
|
|
@@ -1175,11 +1186,17 @@ function createCapsule(container, options = {}) {
|
|
|
1175
1186
|
return this;
|
|
1176
1187
|
},
|
|
1177
1188
|
setSize(width, height) {
|
|
1178
|
-
if (width !== undefined)
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1189
|
+
if (width !== undefined) {
|
|
1190
|
+
parseSize(width); // 非法尺寸直接抛错前先校验,避免污染内部状态
|
|
1191
|
+
merged.width = width;
|
|
1192
|
+
}
|
|
1193
|
+
if (height !== undefined) {
|
|
1194
|
+
parseSize(height);
|
|
1195
|
+
merged.height = height;
|
|
1196
|
+
}
|
|
1197
|
+
applySize();
|
|
1198
|
+
return this;
|
|
1199
|
+
},
|
|
1183
1200
|
randomize() {
|
|
1184
1201
|
this.setSeed(Math.random() * 100);
|
|
1185
1202
|
return this;
|
|
@@ -1206,8 +1223,8 @@ function createCapsule(container, options = {}) {
|
|
|
1206
1223
|
renderer.dispose();
|
|
1207
1224
|
root.remove();
|
|
1208
1225
|
},
|
|
1209
|
-
textRatio
|
|
1210
|
-
cssVars
|
|
1226
|
+
get textRatio() { return merged.textRatio; },
|
|
1227
|
+
get cssVars() { return merged.cssVars; },
|
|
1211
1228
|
dirty
|
|
1212
1229
|
};
|
|
1213
1230
|
}
|
|
@@ -1692,13 +1709,17 @@ const PALETTES = {
|
|
|
1692
1709
|
'tide': ['#0a2239', '#2e9bff', '#7fe3ff', '#eaf9ff']
|
|
1693
1710
|
};
|
|
1694
1711
|
|
|
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
|
-
|
|
1712
|
+
function drawCloud(context, x, y, radiusX, radiusY, color, alpha) {
|
|
1713
|
+
context.save();
|
|
1714
|
+
context.translate(x, y);
|
|
1715
|
+
context.scale(1, radiusY / radiusX);
|
|
1716
|
+
const gradient = context.createRadialGradient(0, 0, 0, 0, 0, radiusX);
|
|
1717
|
+
const alphaHex = (value) => {
|
|
1718
|
+
const text = Math.round(value).toString(16);
|
|
1719
|
+
return text.length === 1 ? `0${text}` : text;
|
|
1720
|
+
};
|
|
1721
|
+
gradient.addColorStop(0, `${color}${alphaHex(alpha * 255)}`);
|
|
1722
|
+
gradient.addColorStop(0.46, `${color}${alphaHex(alpha * 0.42 * 255)}`);
|
|
1702
1723
|
gradient.addColorStop(1, `${color}00`);
|
|
1703
1724
|
context.fillStyle = gradient;
|
|
1704
1725
|
context.fillRect(-radiusX, -radiusX, radiusX * 2, radiusX * 2);
|
|
@@ -2128,9 +2149,14 @@ class ProgressCapsuleController {
|
|
|
2128
2149
|
ctx.restore();
|
|
2129
2150
|
}
|
|
2130
2151
|
|
|
2131
|
-
setRange(min, max) {
|
|
2132
|
-
|
|
2133
|
-
|
|
2152
|
+
setRange(min, max) {
|
|
2153
|
+
if (min > max) {
|
|
2154
|
+
const swap = min;
|
|
2155
|
+
min = max;
|
|
2156
|
+
max = swap;
|
|
2157
|
+
}
|
|
2158
|
+
this.min = min;
|
|
2159
|
+
this.max = max;
|
|
2134
2160
|
const clamped = clamp(this.value, this.min, this.max);
|
|
2135
2161
|
if (clamped !== this.value) this.setProgress(clamped, 'prop');
|
|
2136
2162
|
}
|
|
@@ -2325,33 +2351,7 @@ class ProgressCapsuleController {
|
|
|
2325
2351
|
this.root.addEventListener('pointercancel', this.handlers.pointercancel);
|
|
2326
2352
|
}
|
|
2327
2353
|
|
|
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
|
-
}
|
|
2354
|
+
}
|
|
2355
2355
|
|
|
2356
2356
|
update(delta, paused) {
|
|
2357
2357
|
if (!paused) this.flowTime += delta;
|
|
@@ -2389,7 +2389,7 @@ class ProgressCapsuleController {
|
|
|
2389
2389
|
* Mount a fluid progress capsule into `container`.
|
|
2390
2390
|
*
|
|
2391
2391
|
* Options: preset (id/code/name or object), width, height, value, min, max,
|
|
2392
|
-
* draggable,
|
|
2392
|
+
* draggable, colors, edgeStyle, textRatio (0-100, text region
|
|
2393
2393
|
* width in percent), text (HTML string or DOM nodes for the text slot),
|
|
2394
2394
|
* colorContent (HTML string or DOM nodes for the color slot),
|
|
2395
2395
|
* showValue (show/hide the right-side percentage), quality,
|
|
@@ -2402,6 +2402,11 @@ function createProgressCapsule(container, options = {}) {
|
|
|
2402
2402
|
|
|
2403
2403
|
const preset = { ...getPreset('progress', options.preset ?? '星火') };
|
|
2404
2404
|
const merged = normalizeOptions(DEFAULTS.progress, preset, options);
|
|
2405
|
+
if (merged.min > merged.max) {
|
|
2406
|
+
const swap = merged.min;
|
|
2407
|
+
merged.min = merged.max;
|
|
2408
|
+
merged.max = swap;
|
|
2409
|
+
}
|
|
2405
2410
|
const normalizedColors = merged.colors.map(normalizeColor);
|
|
2406
2411
|
if (normalizedColors.every(Boolean)) preset.colors = normalizedColors;
|
|
2407
2412
|
preset.edgeStyle = merged.edgeStyle;
|
|
@@ -2413,7 +2418,6 @@ function createProgressCapsule(container, options = {}) {
|
|
|
2413
2418
|
const readonly = merged.readonly === true || merged.readonly === '' || merged.readonly === 'true';
|
|
2414
2419
|
const locked = disabled || readonly;
|
|
2415
2420
|
const effectiveDraggable = locked ? false : merged.draggable !== false;
|
|
2416
|
-
const effectiveKeyboard = locked ? false : merged.keyboard !== false;
|
|
2417
2421
|
const dirty = {
|
|
2418
2422
|
preset: false,
|
|
2419
2423
|
colors: false,
|
|
@@ -2426,7 +2430,6 @@ function createProgressCapsule(container, options = {}) {
|
|
|
2426
2430
|
const root = document.createElement('div');
|
|
2427
2431
|
root.className = 'hj-capsule-root hj-progress-root';
|
|
2428
2432
|
root.setAttribute('role', 'slider');
|
|
2429
|
-
root.setAttribute('tabindex', '0');
|
|
2430
2433
|
root.setAttribute('data-draggable', String(effectiveDraggable));
|
|
2431
2434
|
if (disabled) {
|
|
2432
2435
|
root.setAttribute('aria-disabled', 'true');
|
|
@@ -2436,6 +2439,7 @@ function createProgressCapsule(container, options = {}) {
|
|
|
2436
2439
|
root.setAttribute('aria-readonly', 'true');
|
|
2437
2440
|
root.classList.add('is-readonly');
|
|
2438
2441
|
}
|
|
2442
|
+
if (locked) root.setAttribute('tabindex', '-1');
|
|
2439
2443
|
root.setAttribute('aria-valuemin', String(merged.min ?? 0));
|
|
2440
2444
|
root.setAttribute('aria-valuemax', String(merged.max ?? 100));
|
|
2441
2445
|
root.setAttribute('aria-valuenow', String(preset.initialProgress));
|
|
@@ -2446,8 +2450,6 @@ function createProgressCapsule(container, options = {}) {
|
|
|
2446
2450
|
);
|
|
2447
2451
|
};
|
|
2448
2452
|
updateAria();
|
|
2449
|
-
if (!effectiveKeyboard) root.setAttribute('tabindex', '-1');
|
|
2450
|
-
|
|
2451
2453
|
const canvas = document.createElement('canvas');
|
|
2452
2454
|
canvas.className = 'hj-progress-canvas';
|
|
2453
2455
|
canvas.setAttribute('aria-hidden', 'true');
|
|
@@ -2509,7 +2511,7 @@ function createProgressCapsule(container, options = {}) {
|
|
|
2509
2511
|
valueElement,
|
|
2510
2512
|
preset,
|
|
2511
2513
|
emitter,
|
|
2512
|
-
options: { ...merged, draggable: effectiveDraggable
|
|
2514
|
+
options: { ...merged, draggable: effectiveDraggable },
|
|
2513
2515
|
copy,
|
|
2514
2516
|
dirty
|
|
2515
2517
|
});
|
|
@@ -2650,10 +2652,16 @@ function createProgressCapsule(container, options = {}) {
|
|
|
2650
2652
|
controller.resizeCanvas();
|
|
2651
2653
|
return this;
|
|
2652
2654
|
},
|
|
2653
|
-
setSize(width, height) {
|
|
2654
|
-
if (width !== undefined)
|
|
2655
|
-
|
|
2656
|
-
|
|
2655
|
+
setSize(width, height) {
|
|
2656
|
+
if (width !== undefined) {
|
|
2657
|
+
parseSize(width);
|
|
2658
|
+
merged.width = width;
|
|
2659
|
+
}
|
|
2660
|
+
if (height !== undefined) {
|
|
2661
|
+
parseSize(height);
|
|
2662
|
+
merged.height = height;
|
|
2663
|
+
}
|
|
2664
|
+
applySize();
|
|
2657
2665
|
controller.resizeCanvas();
|
|
2658
2666
|
return this;
|
|
2659
2667
|
},
|
|
@@ -2683,8 +2691,8 @@ function createProgressCapsule(container, options = {}) {
|
|
|
2683
2691
|
controller.dispose();
|
|
2684
2692
|
root.remove();
|
|
2685
2693
|
},
|
|
2686
|
-
textRatio
|
|
2687
|
-
cssVars
|
|
2694
|
+
get textRatio() { return merged.textRatio; },
|
|
2695
|
+
get cssVars() { return merged.cssVars; },
|
|
2688
2696
|
dirty
|
|
2689
2697
|
};
|
|
2690
2698
|
}
|
|
@@ -2904,9 +2912,9 @@ function createColorBackground(host, options = {}) {
|
|
|
2904
2912
|
renderer.dispose();
|
|
2905
2913
|
layer.remove();
|
|
2906
2914
|
},
|
|
2907
|
-
opacity
|
|
2908
|
-
fallbackColor
|
|
2909
|
-
mouseColor
|
|
2915
|
+
get opacity() { return merged.opacity; },
|
|
2916
|
+
get fallbackColor() { return merged.fallbackColor; },
|
|
2917
|
+
get mouseColor() { return merged.mouseColor; },
|
|
2910
2918
|
dirty
|
|
2911
2919
|
};
|
|
2912
2920
|
}
|