@5even7/dlc-ui 0.2.2 → 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 +17 -0
- package/README.md +4 -4
- package/dist/capsule.cjs +37 -13
- package/dist/capsule.mjs +46 -20
- package/dist/color.cjs +28 -12
- package/dist/color.mjs +28 -16
- package/dist/index.cjs +97 -58
- package/dist/index.mjs +100 -75
- package/dist/index.umd.js +97 -58
- package/dist/index.umd.min.js +1 -1
- package/dist/progress.cjs +64 -49
- package/dist/progress.mjs +64 -57
- package/dist/vue2.cjs +119 -75
- package/dist/vue2.mjs +115 -85
- package/dist/vue3.cjs +119 -75
- package/dist/vue3.mjs +115 -85
- package/package.json +1 -1
- package/styles/base.css +12 -4
- package/styles/progress.css +4 -0
- package/types/index.d.ts +2 -2
package/dist/index.umd.js
CHANGED
|
@@ -421,9 +421,13 @@
|
|
|
421
421
|
var list = kind === 'capsule' ? CAPSULE_PRESETS : kind === 'progress' ? PROGRESS_PRESETS : null;
|
|
422
422
|
if (!list) throw new Error("Unknown preset kind: ".concat(kind, " (use \"capsule\" or \"progress\")"));
|
|
423
423
|
var key = String(ref).trim().toLowerCase();
|
|
424
|
-
var found =
|
|
425
|
-
|
|
426
|
-
|
|
424
|
+
var found = null;
|
|
425
|
+
for (var index = 0; index < list.length; index += 1) {
|
|
426
|
+
if (list[index].name.toLowerCase() === key) {
|
|
427
|
+
found = list[index];
|
|
428
|
+
break;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
427
431
|
if (!found) throw new Error("Unknown ".concat(kind, " preset: ").concat(ref));
|
|
428
432
|
return found;
|
|
429
433
|
}
|
|
@@ -444,8 +448,8 @@
|
|
|
444
448
|
min: 0,
|
|
445
449
|
max: 100,
|
|
446
450
|
draggable: true,
|
|
447
|
-
keyboard: true,
|
|
448
451
|
disabled: false,
|
|
452
|
+
readonly: false,
|
|
449
453
|
valueSuffix: '%',
|
|
450
454
|
edgeStyle: 'flow',
|
|
451
455
|
quality: 'auto',
|
|
@@ -634,7 +638,7 @@
|
|
|
634
638
|
if (parts.length < 3) return null;
|
|
635
639
|
var to255 = function to255(value) {
|
|
636
640
|
if (typeof value !== 'string' || !value) return null;
|
|
637
|
-
if (value.
|
|
641
|
+
if (value.charAt(value.length - 1) === '%') return clampChannel(parseFloat(value) / 100 * 255);
|
|
638
642
|
var number = Number(value);
|
|
639
643
|
return Number.isFinite(number) ? clampChannel(number) : null;
|
|
640
644
|
};
|
|
@@ -642,9 +646,11 @@
|
|
|
642
646
|
var green = to255(parts[1]);
|
|
643
647
|
var blue = to255(parts[2]);
|
|
644
648
|
if (red === null || green === null || blue === null) return null;
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
649
|
+
var hex = function hex(n) {
|
|
650
|
+
var text = n.toString(16);
|
|
651
|
+
return text.length === 1 ? "0".concat(text) : text;
|
|
652
|
+
};
|
|
653
|
+
return "#".concat(hex(red)).concat(hex(green)).concat(hex(blue));
|
|
648
654
|
}
|
|
649
655
|
|
|
650
656
|
/**
|
|
@@ -914,6 +920,7 @@
|
|
|
914
920
|
this.preset = preset;
|
|
915
921
|
this.context = canvas.getContext('2d');
|
|
916
922
|
this.visible = true;
|
|
923
|
+
this.timePhase = 0;
|
|
917
924
|
}
|
|
918
925
|
return _createClass(FallbackRenderer, [{
|
|
919
926
|
key: "resize",
|
|
@@ -934,7 +941,7 @@
|
|
|
934
941
|
var _this$canvas = this.canvas,
|
|
935
942
|
width = _this$canvas.width,
|
|
936
943
|
height = _this$canvas.height;
|
|
937
|
-
var t = time * (this.preset.speed || 1);
|
|
944
|
+
var t = (time + this.timePhase) * (this.preset.speed || 1);
|
|
938
945
|
var phase = (this.preset.seed || 0) * 0.7;
|
|
939
946
|
var gradient = ctx.createLinearGradient(0, 0, width, height);
|
|
940
947
|
gradient.addColorStop(0, this.preset.colors[0]);
|
|
@@ -971,7 +978,10 @@
|
|
|
971
978
|
}, {
|
|
972
979
|
key: "randomize",
|
|
973
980
|
value: function randomize() {
|
|
974
|
-
if (this.preset)
|
|
981
|
+
if (this.preset) {
|
|
982
|
+
this.preset.seed = Math.random() * 100;
|
|
983
|
+
this.timePhase = Math.random() * Math.PI * 2;
|
|
984
|
+
}
|
|
975
985
|
}
|
|
976
986
|
}, {
|
|
977
987
|
key: "setMouseColor",
|
|
@@ -1224,6 +1234,8 @@
|
|
|
1224
1234
|
}
|
|
1225
1235
|
if (merged.textRatio !== undefined) {
|
|
1226
1236
|
root.style.setProperty('--hj-text-width', "".concat(merged.textRatio, "%"));
|
|
1237
|
+
var userMinWidth = merged.cssVars && merged.cssVars['--hj-text-min-width'];
|
|
1238
|
+
if (merged.textRatio === 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');
|
|
1227
1239
|
}
|
|
1228
1240
|
renderer.resize();
|
|
1229
1241
|
};
|
|
@@ -1347,6 +1359,8 @@
|
|
|
1347
1359
|
dirty.textRatio = true;
|
|
1348
1360
|
merged.textRatio = value;
|
|
1349
1361
|
root.style.setProperty('--hj-text-width', "".concat(value, "%"));
|
|
1362
|
+
var userMinWidth = merged.cssVars && merged.cssVars['--hj-text-min-width'];
|
|
1363
|
+
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');
|
|
1350
1364
|
return this;
|
|
1351
1365
|
},
|
|
1352
1366
|
setCssVars: function setCssVars(vars) {
|
|
@@ -1365,8 +1379,14 @@
|
|
|
1365
1379
|
return this;
|
|
1366
1380
|
},
|
|
1367
1381
|
setSize: function setSize(width, height) {
|
|
1368
|
-
if (width !== undefined)
|
|
1369
|
-
|
|
1382
|
+
if (width !== undefined) {
|
|
1383
|
+
parseSize(width); // 非法尺寸直接抛错前先校验,避免污染内部状态
|
|
1384
|
+
merged.width = width;
|
|
1385
|
+
}
|
|
1386
|
+
if (height !== undefined) {
|
|
1387
|
+
parseSize(height);
|
|
1388
|
+
merged.height = height;
|
|
1389
|
+
}
|
|
1370
1390
|
applySize();
|
|
1371
1391
|
return this;
|
|
1372
1392
|
},
|
|
@@ -1395,8 +1415,12 @@
|
|
|
1395
1415
|
renderer.dispose();
|
|
1396
1416
|
root.remove();
|
|
1397
1417
|
},
|
|
1398
|
-
textRatio
|
|
1399
|
-
|
|
1418
|
+
get textRatio() {
|
|
1419
|
+
return merged.textRatio;
|
|
1420
|
+
},
|
|
1421
|
+
get cssVars() {
|
|
1422
|
+
return merged.cssVars;
|
|
1423
|
+
},
|
|
1400
1424
|
dirty: dirty
|
|
1401
1425
|
};
|
|
1402
1426
|
}
|
|
@@ -1692,8 +1716,12 @@
|
|
|
1692
1716
|
context.translate(x, y);
|
|
1693
1717
|
context.scale(1, radiusY / radiusX);
|
|
1694
1718
|
var gradient = context.createRadialGradient(0, 0, 0, 0, 0, radiusX);
|
|
1695
|
-
|
|
1696
|
-
|
|
1719
|
+
var alphaHex = function alphaHex(value) {
|
|
1720
|
+
var text = Math.round(value).toString(16);
|
|
1721
|
+
return text.length === 1 ? "0".concat(text) : text;
|
|
1722
|
+
};
|
|
1723
|
+
gradient.addColorStop(0, "".concat(color).concat(alphaHex(alpha * 255)));
|
|
1724
|
+
gradient.addColorStop(0.46, "".concat(color).concat(alphaHex(alpha * 0.42 * 255)));
|
|
1697
1725
|
gradient.addColorStop(1, "".concat(color, "00"));
|
|
1698
1726
|
context.fillStyle = gradient;
|
|
1699
1727
|
context.fillRect(-radiusX, -radiusX, radiusX * 2, radiusX * 2);
|
|
@@ -2143,6 +2171,11 @@
|
|
|
2143
2171
|
}, {
|
|
2144
2172
|
key: "setRange",
|
|
2145
2173
|
value: function setRange(min, max) {
|
|
2174
|
+
if (min > max) {
|
|
2175
|
+
var swap = min;
|
|
2176
|
+
min = max;
|
|
2177
|
+
max = swap;
|
|
2178
|
+
}
|
|
2146
2179
|
this.min = min;
|
|
2147
2180
|
this.max = max;
|
|
2148
2181
|
var clamped = clamp(this.value, this.min, this.max);
|
|
@@ -2278,6 +2311,14 @@
|
|
|
2278
2311
|
value: function beginDrag(event) {
|
|
2279
2312
|
if (event.button !== undefined && event.button !== 0) return;
|
|
2280
2313
|
event.preventDefault();
|
|
2314
|
+
// preventDefault 会吞掉点击聚焦,主动聚焦让键盘方向键立即可用。
|
|
2315
|
+
try {
|
|
2316
|
+
this.root.focus({
|
|
2317
|
+
preventScroll: true
|
|
2318
|
+
});
|
|
2319
|
+
} catch (_unused) {
|
|
2320
|
+
this.root.focus();
|
|
2321
|
+
}
|
|
2281
2322
|
this.dragging = true;
|
|
2282
2323
|
this.pendingPointer = null;
|
|
2283
2324
|
this._dragRaf = 0;
|
|
@@ -2285,7 +2326,7 @@
|
|
|
2285
2326
|
try {
|
|
2286
2327
|
var _this$root$setPointer, _this$root;
|
|
2287
2328
|
(_this$root$setPointer = (_this$root = this.root).setPointerCapture) === null || _this$root$setPointer === void 0 || _this$root$setPointer.call(_this$root, event.pointerId);
|
|
2288
|
-
} catch (
|
|
2329
|
+
} catch (_unused2) {}
|
|
2289
2330
|
this.emitter.emit('dragstart', {
|
|
2290
2331
|
value: this.value
|
|
2291
2332
|
});
|
|
@@ -2325,7 +2366,7 @@
|
|
|
2325
2366
|
if ((event === null || event === void 0 ? void 0 : event.pointerId) !== undefined && (_this$root$hasPointer = (_this$root2 = this.root).hasPointerCapture) !== null && _this$root$hasPointer !== void 0 && _this$root$hasPointer.call(_this$root2, event.pointerId)) {
|
|
2326
2367
|
this.root.releasePointerCapture(event.pointerId);
|
|
2327
2368
|
}
|
|
2328
|
-
} catch (
|
|
2369
|
+
} catch (_unused3) {}
|
|
2329
2370
|
this.emitter.emit('dragend', {
|
|
2330
2371
|
value: this.value
|
|
2331
2372
|
});
|
|
@@ -2352,32 +2393,6 @@
|
|
|
2352
2393
|
this.root.addEventListener('pointerup', this.handlers.pointerup);
|
|
2353
2394
|
this.root.addEventListener('pointercancel', this.handlers.pointercancel);
|
|
2354
2395
|
}
|
|
2355
|
-
if (this.options.keyboard !== false) {
|
|
2356
|
-
this.handlers.keydown = function (event) {
|
|
2357
|
-
var step = (_this3.max - _this3.min) * 0.02;
|
|
2358
|
-
var actions = {
|
|
2359
|
-
ArrowLeft: -step,
|
|
2360
|
-
ArrowDown: -step,
|
|
2361
|
-
ArrowRight: step,
|
|
2362
|
-
ArrowUp: step,
|
|
2363
|
-
PageDown: -step * 5,
|
|
2364
|
-
PageUp: step * 5
|
|
2365
|
-
};
|
|
2366
|
-
if (event.key === 'Home') {
|
|
2367
|
-
event.preventDefault();
|
|
2368
|
-
_this3.setProgress(_this3.min, 'keyboard');
|
|
2369
|
-
} else if (event.key === 'End') {
|
|
2370
|
-
event.preventDefault();
|
|
2371
|
-
_this3.setProgress(_this3.max, 'keyboard');
|
|
2372
|
-
} else if (actions[event.key]) {
|
|
2373
|
-
event.preventDefault();
|
|
2374
|
-
_this3.setProgress(_this3.value + actions[event.key], 'keyboard');
|
|
2375
|
-
} else {
|
|
2376
|
-
return;
|
|
2377
|
-
}
|
|
2378
|
-
};
|
|
2379
|
-
this.root.addEventListener('keydown', this.handlers.keydown);
|
|
2380
|
-
}
|
|
2381
2396
|
}
|
|
2382
2397
|
}, {
|
|
2383
2398
|
key: "update",
|
|
@@ -2424,7 +2439,7 @@
|
|
|
2424
2439
|
* Mount a fluid progress capsule into `container`.
|
|
2425
2440
|
*
|
|
2426
2441
|
* Options: preset (id/code/name or object), width, height, value, min, max,
|
|
2427
|
-
* draggable,
|
|
2442
|
+
* draggable, colors, edgeStyle, textRatio (0-100, text region
|
|
2428
2443
|
* width in percent), text (HTML string or DOM nodes for the text slot),
|
|
2429
2444
|
* colorContent (HTML string or DOM nodes for the color slot),
|
|
2430
2445
|
* showValue (show/hide the right-side percentage), quality,
|
|
@@ -2438,6 +2453,11 @@
|
|
|
2438
2453
|
}
|
|
2439
2454
|
var preset = _objectSpread2({}, getPreset('progress', (_options$preset = options.preset) !== null && _options$preset !== void 0 ? _options$preset : '星火'));
|
|
2440
2455
|
var merged = normalizeOptions(DEFAULTS.progress, preset, options);
|
|
2456
|
+
if (merged.min > merged.max) {
|
|
2457
|
+
var swap = merged.min;
|
|
2458
|
+
merged.min = merged.max;
|
|
2459
|
+
merged.max = swap;
|
|
2460
|
+
}
|
|
2441
2461
|
var normalizedColors = merged.colors.map(normalizeColor);
|
|
2442
2462
|
if (normalizedColors.every(Boolean)) preset.colors = normalizedColors;
|
|
2443
2463
|
preset.edgeStyle = merged.edgeStyle;
|
|
@@ -2446,8 +2466,9 @@
|
|
|
2446
2466
|
// Vue 的裸布尔属性(<ProgressCapsule disabled />)会传成空字符串,
|
|
2447
2467
|
// 这里统一按 true 处理。
|
|
2448
2468
|
var disabled = merged.disabled === true || merged.disabled === '' || merged.disabled === 'true';
|
|
2449
|
-
var
|
|
2450
|
-
var
|
|
2469
|
+
var readonly = merged.readonly === true || merged.readonly === '' || merged.readonly === 'true';
|
|
2470
|
+
var locked = disabled || readonly;
|
|
2471
|
+
var effectiveDraggable = locked ? false : merged.draggable !== false;
|
|
2451
2472
|
var dirty = {
|
|
2452
2473
|
preset: false,
|
|
2453
2474
|
colors: false,
|
|
@@ -2459,12 +2480,16 @@
|
|
|
2459
2480
|
var root = document.createElement('div');
|
|
2460
2481
|
root.className = 'hj-capsule-root hj-progress-root';
|
|
2461
2482
|
root.setAttribute('role', 'slider');
|
|
2462
|
-
root.setAttribute('tabindex', '0');
|
|
2463
2483
|
root.setAttribute('data-draggable', String(effectiveDraggable));
|
|
2464
2484
|
if (disabled) {
|
|
2465
2485
|
root.setAttribute('aria-disabled', 'true');
|
|
2466
2486
|
root.classList.add('is-disabled');
|
|
2467
2487
|
}
|
|
2488
|
+
if (readonly) {
|
|
2489
|
+
root.setAttribute('aria-readonly', 'true');
|
|
2490
|
+
root.classList.add('is-readonly');
|
|
2491
|
+
}
|
|
2492
|
+
if (locked) root.setAttribute('tabindex', '-1');
|
|
2468
2493
|
root.setAttribute('aria-valuemin', String((_merged$min = merged.min) !== null && _merged$min !== void 0 ? _merged$min : 0));
|
|
2469
2494
|
root.setAttribute('aria-valuemax', String((_merged$max = merged.max) !== null && _merged$max !== void 0 ? _merged$max : 100));
|
|
2470
2495
|
root.setAttribute('aria-valuenow', String(preset.initialProgress));
|
|
@@ -2476,7 +2501,6 @@
|
|
|
2476
2501
|
}));
|
|
2477
2502
|
};
|
|
2478
2503
|
updateAria();
|
|
2479
|
-
if (!effectiveKeyboard) root.setAttribute('tabindex', '-1');
|
|
2480
2504
|
var canvas = document.createElement('canvas');
|
|
2481
2505
|
canvas.className = 'hj-progress-canvas';
|
|
2482
2506
|
canvas.setAttribute('aria-hidden', 'true');
|
|
@@ -2543,8 +2567,7 @@
|
|
|
2543
2567
|
preset: preset,
|
|
2544
2568
|
emitter: emitter,
|
|
2545
2569
|
options: _objectSpread2(_objectSpread2({}, merged), {}, {
|
|
2546
|
-
draggable: effectiveDraggable
|
|
2547
|
-
keyboard: effectiveKeyboard
|
|
2570
|
+
draggable: effectiveDraggable
|
|
2548
2571
|
}),
|
|
2549
2572
|
copy: copy,
|
|
2550
2573
|
dirty: dirty
|
|
@@ -2704,8 +2727,14 @@
|
|
|
2704
2727
|
return this;
|
|
2705
2728
|
},
|
|
2706
2729
|
setSize: function setSize(width, height) {
|
|
2707
|
-
if (width !== undefined)
|
|
2708
|
-
|
|
2730
|
+
if (width !== undefined) {
|
|
2731
|
+
parseSize(width);
|
|
2732
|
+
merged.width = width;
|
|
2733
|
+
}
|
|
2734
|
+
if (height !== undefined) {
|
|
2735
|
+
parseSize(height);
|
|
2736
|
+
merged.height = height;
|
|
2737
|
+
}
|
|
2709
2738
|
applySize();
|
|
2710
2739
|
controller.resizeCanvas();
|
|
2711
2740
|
return this;
|
|
@@ -2736,8 +2765,12 @@
|
|
|
2736
2765
|
controller.dispose();
|
|
2737
2766
|
root.remove();
|
|
2738
2767
|
},
|
|
2739
|
-
textRatio
|
|
2740
|
-
|
|
2768
|
+
get textRatio() {
|
|
2769
|
+
return merged.textRatio;
|
|
2770
|
+
},
|
|
2771
|
+
get cssVars() {
|
|
2772
|
+
return merged.cssVars;
|
|
2773
|
+
},
|
|
2741
2774
|
dirty: dirty
|
|
2742
2775
|
};
|
|
2743
2776
|
}
|
|
@@ -2942,9 +2975,15 @@
|
|
|
2942
2975
|
renderer.dispose();
|
|
2943
2976
|
layer.remove();
|
|
2944
2977
|
},
|
|
2945
|
-
opacity
|
|
2946
|
-
|
|
2947
|
-
|
|
2978
|
+
get opacity() {
|
|
2979
|
+
return merged.opacity;
|
|
2980
|
+
},
|
|
2981
|
+
get fallbackColor() {
|
|
2982
|
+
return merged.fallbackColor;
|
|
2983
|
+
},
|
|
2984
|
+
get mouseColor() {
|
|
2985
|
+
return merged.mouseColor;
|
|
2986
|
+
},
|
|
2948
2987
|
dirty: dirty
|
|
2949
2988
|
};
|
|
2950
2989
|
}
|