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