@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/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
> **发版规则**:默认每次发布只递增补丁号(0.x.y → 0.x.(y+1),即 +0.01);除非手动明确指定新版本号,否则不升次版本。
|
|
4
4
|
|
|
5
|
+
## 0.2.5 - 2026-08-08
|
|
6
|
+
|
|
7
|
+
- 修复:胶囊 `textRatio` 小于 164px(历史 `--hj-copy-min-width` 默认)时文字区不跟随缩小的 bug;现在 `textRatio` 是文字区宽度的唯一权威值,0~100 全范围生效。
|
|
8
|
+
|
|
9
|
+
## 0.2.4 - 2026-08-08
|
|
10
|
+
|
|
11
|
+
- 移除 Progress `keyboard` 属性与键盘控制(拖动/受控 value 已覆盖主要场景)。
|
|
12
|
+
- 兼容性修复:legacy/IE11 路径补齐 `Array.prototype.find`、`String.prototype.endsWith`、`String.prototype.padStart` 缺失导致的崩溃(源码层也改为 ES5 写法)。
|
|
13
|
+
- 控制器暴露值改为实时 getter(`textRatio` / `cssVars` / `opacity` / `fallbackColor` / `mouseColor`),热更新后读取不再过期,Vue 重建时状态继承更准确。
|
|
14
|
+
- `setSize` 先校验再赋值,非法尺寸不再污染内部状态或抛进 Vue 更新流程。
|
|
15
|
+
- `setRange` 与创建时的 `min/max` 在 min>max 时自动交换。
|
|
16
|
+
- 结构属性连续变化时,重建后补一次插槽搬运(B3)。
|
|
17
|
+
- Canvas2D 降级的 `randomize()` 额外随机相位,变化更明显;README 注明降级路径 `mouseColor` 不生效。
|
|
18
|
+
|
|
5
19
|
## 0.2.3 - 2026-08-08
|
|
6
20
|
|
|
7
21
|
- 修复:Vue wrapper 重建组件(如 showValue 开关)后插槽内容丢失的问题(插槽容器改为整体搬入文字区/颜色区)。
|
package/README.md
CHANGED
|
@@ -155,9 +155,9 @@ export default {
|
|
|
155
155
|
|
|
156
156
|
两个组件共有:`preset`、`width`、`height`(数字=px,或 `px/%/vw/vh/vmin/vmax/em/rem` 字符串)、`colors`(4 个颜色,支持 `#rgb` / `#rrggbb` / CSS 命名色 / `rgb()` / `rgba()`,统一归一化为小写 6 位十六进制;`rgba()` 的 alpha 会被忽略,透明请用组件级 `opacity`)、`textRatio`(文字区宽度占比 0~100,默认胶囊 39 / 进度条 54)、`label`(覆盖默认 aria-label,胶囊另带 `role="img"`)、`quality`(`auto/low/medium/high`)、`renderer`(`auto/webgl2/canvas2d`)、`respectReducedMotion`、`cssVars`。
|
|
157
157
|
|
|
158
|
-
胶囊专属:`seed`、`speed`、`mouseColor`(颜色随鼠标旋涡,默认 `true`,关闭不影响 click
|
|
158
|
+
胶囊专属:`seed`、`speed`、`mouseColor`(颜色随鼠标旋涡,默认 `true`,关闭不影响 click/悬浮/长按等事件;Canvas2D 降级路径下 `mouseColor` 不生效)。
|
|
159
159
|
|
|
160
|
-
进度条专属:`value`、`min`、`max`(value 的合法区间,默认 0~100;**水线归一化到 [min, max]
|
|
160
|
+
进度条专属:`value`、`min`、`max`(value 的合法区间,默认 0~100;**水线归一化到 [min, max]**,右侧数字仍显示原始 value)、`draggable`、`disabled`(禁用交互并置灰)、`readonly`(禁用交互但不置灰)、`edgeStyle`(`flow/tide`)、`valueSuffix`(右侧数字后缀,默认 `%`)、`showValue`(是否显示右侧百分比数字,默认 `true`,`false` 只隐藏数字、不影响无障碍信息)。
|
|
161
161
|
|
|
162
162
|
插槽内容属性(H5/工厂):`text`、`colorContent`,支持 HTML 字符串或 DOM 节点(数组);Vue 组件请用默认插槽 / `#color` 插槽。**注意:字符串走 innerHTML,不要传入不可信/用户直接输入的内容(XSS 风险)。**
|
|
163
163
|
|
|
@@ -237,7 +237,7 @@ createProgressCapsule(el, {
|
|
|
237
237
|
| capsule | `pointerenter` / `pointerleave` | `{ event, preset }` |
|
|
238
238
|
| capsule | `error` | `{ message }`(WebGL2 不可用降级时触发) |
|
|
239
239
|
| progress | `ready` / `presetchange` | `{ preset }` |
|
|
240
|
-
| progress | `change` | `{ value, source }`,source ∈ `drag/
|
|
240
|
+
| progress | `change` | `{ value, source }`,source ∈ `drag/prop` |
|
|
241
241
|
| progress | `dragstart` / `dragend` | `{ value }` |
|
|
242
242
|
| progress | `error` | `{ message }` |
|
|
243
243
|
|
package/dist/capsule.cjs
CHANGED
|
@@ -413,9 +413,13 @@ function getPreset(kind, ref) {
|
|
|
413
413
|
var list = CAPSULE_PRESETS ;
|
|
414
414
|
if (!list) throw new Error("Unknown preset kind: ".concat(kind, " (use \"capsule\" or \"progress\")"));
|
|
415
415
|
var key = String(ref).trim().toLowerCase();
|
|
416
|
-
var found =
|
|
417
|
-
|
|
418
|
-
|
|
416
|
+
var found = null;
|
|
417
|
+
for (var index = 0; index < list.length; index += 1) {
|
|
418
|
+
if (list[index].name.toLowerCase() === key) {
|
|
419
|
+
found = list[index];
|
|
420
|
+
break;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
419
423
|
if (!found) throw new Error("Unknown ".concat(kind, " preset: ").concat(ref));
|
|
420
424
|
return found;
|
|
421
425
|
}
|
|
@@ -606,7 +610,7 @@ function normalizeRgbArgs(args) {
|
|
|
606
610
|
if (parts.length < 3) return null;
|
|
607
611
|
var to255 = function to255(value) {
|
|
608
612
|
if (typeof value !== 'string' || !value) return null;
|
|
609
|
-
if (value.
|
|
613
|
+
if (value.charAt(value.length - 1) === '%') return clampChannel(parseFloat(value) / 100 * 255);
|
|
610
614
|
var number = Number(value);
|
|
611
615
|
return Number.isFinite(number) ? clampChannel(number) : null;
|
|
612
616
|
};
|
|
@@ -614,9 +618,11 @@ function normalizeRgbArgs(args) {
|
|
|
614
618
|
var green = to255(parts[1]);
|
|
615
619
|
var blue = to255(parts[2]);
|
|
616
620
|
if (red === null || green === null || blue === null) return null;
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
621
|
+
var hex = function hex(n) {
|
|
622
|
+
var text = n.toString(16);
|
|
623
|
+
return text.length === 1 ? "0".concat(text) : text;
|
|
624
|
+
};
|
|
625
|
+
return "#".concat(hex(red)).concat(hex(green)).concat(hex(blue));
|
|
620
626
|
}
|
|
621
627
|
|
|
622
628
|
/**
|
|
@@ -871,6 +877,7 @@ var FallbackRenderer = /*#__PURE__*/function () {
|
|
|
871
877
|
this.preset = preset;
|
|
872
878
|
this.context = canvas.getContext('2d');
|
|
873
879
|
this.visible = true;
|
|
880
|
+
this.timePhase = 0;
|
|
874
881
|
}
|
|
875
882
|
return _createClass(FallbackRenderer, [{
|
|
876
883
|
key: "resize",
|
|
@@ -891,7 +898,7 @@ var FallbackRenderer = /*#__PURE__*/function () {
|
|
|
891
898
|
var _this$canvas = this.canvas,
|
|
892
899
|
width = _this$canvas.width,
|
|
893
900
|
height = _this$canvas.height;
|
|
894
|
-
var t = time * (this.preset.speed || 1);
|
|
901
|
+
var t = (time + this.timePhase) * (this.preset.speed || 1);
|
|
895
902
|
var phase = (this.preset.seed || 0) * 0.7;
|
|
896
903
|
var gradient = ctx.createLinearGradient(0, 0, width, height);
|
|
897
904
|
gradient.addColorStop(0, this.preset.colors[0]);
|
|
@@ -928,7 +935,10 @@ var FallbackRenderer = /*#__PURE__*/function () {
|
|
|
928
935
|
}, {
|
|
929
936
|
key: "randomize",
|
|
930
937
|
value: function randomize() {
|
|
931
|
-
if (this.preset)
|
|
938
|
+
if (this.preset) {
|
|
939
|
+
this.preset.seed = Math.random() * 100;
|
|
940
|
+
this.timePhase = Math.random() * Math.PI * 2;
|
|
941
|
+
}
|
|
932
942
|
}
|
|
933
943
|
}, {
|
|
934
944
|
key: "setMouseColor",
|
|
@@ -1174,8 +1184,9 @@ function createCapsule(container) {
|
|
|
1174
1184
|
}
|
|
1175
1185
|
if (merged.textRatio !== undefined) {
|
|
1176
1186
|
root.style.setProperty('--hj-text-width', "".concat(merged.textRatio, "%"));
|
|
1177
|
-
|
|
1178
|
-
|
|
1187
|
+
// textRatio 是文字区宽度的唯一权威值:min-width 会阻止其缩小到
|
|
1188
|
+
// 164px 以下(--hj-copy-min-width 的历史默认),这里强制归零。
|
|
1189
|
+
root.style.setProperty('--hj-text-min-width', '0');
|
|
1179
1190
|
}
|
|
1180
1191
|
renderer.resize();
|
|
1181
1192
|
};
|
|
@@ -1299,8 +1310,7 @@ function createCapsule(container) {
|
|
|
1299
1310
|
dirty.textRatio = true;
|
|
1300
1311
|
merged.textRatio = value;
|
|
1301
1312
|
root.style.setProperty('--hj-text-width', "".concat(value, "%"));
|
|
1302
|
-
|
|
1303
|
-
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');
|
|
1313
|
+
root.style.setProperty('--hj-text-min-width', '0');
|
|
1304
1314
|
return this;
|
|
1305
1315
|
},
|
|
1306
1316
|
setCssVars: function setCssVars(vars) {
|
|
@@ -1319,8 +1329,14 @@ function createCapsule(container) {
|
|
|
1319
1329
|
return this;
|
|
1320
1330
|
},
|
|
1321
1331
|
setSize: function setSize(width, height) {
|
|
1322
|
-
if (width !== undefined)
|
|
1323
|
-
|
|
1332
|
+
if (width !== undefined) {
|
|
1333
|
+
parseSize(width); // 非法尺寸直接抛错前先校验,避免污染内部状态
|
|
1334
|
+
merged.width = width;
|
|
1335
|
+
}
|
|
1336
|
+
if (height !== undefined) {
|
|
1337
|
+
parseSize(height);
|
|
1338
|
+
merged.height = height;
|
|
1339
|
+
}
|
|
1324
1340
|
applySize();
|
|
1325
1341
|
return this;
|
|
1326
1342
|
},
|
|
@@ -1349,8 +1365,12 @@ function createCapsule(container) {
|
|
|
1349
1365
|
renderer.dispose();
|
|
1350
1366
|
root.remove();
|
|
1351
1367
|
},
|
|
1352
|
-
textRatio
|
|
1353
|
-
|
|
1368
|
+
get textRatio() {
|
|
1369
|
+
return merged.textRatio;
|
|
1370
|
+
},
|
|
1371
|
+
get cssVars() {
|
|
1372
|
+
return merged.cssVars;
|
|
1373
|
+
},
|
|
1354
1374
|
dirty: dirty
|
|
1355
1375
|
};
|
|
1356
1376
|
}
|
package/dist/capsule.mjs
CHANGED
|
@@ -130,9 +130,13 @@ function getPreset(kind, ref) {
|
|
|
130
130
|
const list = CAPSULE_PRESETS ;
|
|
131
131
|
if (!list) throw new Error(`Unknown preset kind: ${kind} (use "capsule" or "progress")`);
|
|
132
132
|
const key = String(ref).trim().toLowerCase();
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
133
|
+
let found = null;
|
|
134
|
+
for (let index = 0; index < list.length; index += 1) {
|
|
135
|
+
if (list[index].name.toLowerCase() === key) {
|
|
136
|
+
found = list[index];
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
136
140
|
if (!found) throw new Error(`Unknown ${kind} preset: ${ref}`);
|
|
137
141
|
return found;
|
|
138
142
|
}
|
|
@@ -325,7 +329,7 @@ function normalizeRgbArgs(args) {
|
|
|
325
329
|
if (parts.length < 3) return null;
|
|
326
330
|
const to255 = (value) => {
|
|
327
331
|
if (typeof value !== 'string' || !value) return null;
|
|
328
|
-
if (value.
|
|
332
|
+
if (value.charAt(value.length - 1) === '%') return clampChannel((parseFloat(value) / 100) * 255);
|
|
329
333
|
const number = Number(value);
|
|
330
334
|
return Number.isFinite(number) ? clampChannel(number) : null;
|
|
331
335
|
};
|
|
@@ -333,7 +337,11 @@ function normalizeRgbArgs(args) {
|
|
|
333
337
|
const green = to255(parts[1]);
|
|
334
338
|
const blue = to255(parts[2]);
|
|
335
339
|
if (red === null || green === null || blue === null) return null;
|
|
336
|
-
|
|
340
|
+
const hex = (n) => {
|
|
341
|
+
const text = n.toString(16);
|
|
342
|
+
return text.length === 1 ? `0${text}` : text;
|
|
343
|
+
};
|
|
344
|
+
return `#${hex(red)}${hex(green)}${hex(blue)}`;
|
|
337
345
|
}
|
|
338
346
|
|
|
339
347
|
/**
|
|
@@ -680,12 +688,13 @@ function rgb(color, alpha = 1) {
|
|
|
680
688
|
}
|
|
681
689
|
|
|
682
690
|
class FallbackRenderer {
|
|
683
|
-
constructor(canvas, preset) {
|
|
684
|
-
this.canvas = canvas;
|
|
685
|
-
this.preset = preset;
|
|
686
|
-
this.context = canvas.getContext('2d');
|
|
687
|
-
this.visible = true;
|
|
688
|
-
|
|
691
|
+
constructor(canvas, preset) {
|
|
692
|
+
this.canvas = canvas;
|
|
693
|
+
this.preset = preset;
|
|
694
|
+
this.context = canvas.getContext('2d');
|
|
695
|
+
this.visible = true;
|
|
696
|
+
this.timePhase = 0;
|
|
697
|
+
}
|
|
689
698
|
|
|
690
699
|
resize() {
|
|
691
700
|
const rect = this.canvas.getBoundingClientRect();
|
|
@@ -701,7 +710,7 @@ class FallbackRenderer {
|
|
|
701
710
|
drawNebula(time) {
|
|
702
711
|
const ctx = this.context;
|
|
703
712
|
const { width, height } = this.canvas;
|
|
704
|
-
const t = time * (this.preset.speed || 1);
|
|
713
|
+
const t = (time + this.timePhase) * (this.preset.speed || 1);
|
|
705
714
|
const phase = (this.preset.seed || 0) * 0.7;
|
|
706
715
|
const gradient = ctx.createLinearGradient(0, 0, width, height);
|
|
707
716
|
gradient.addColorStop(0, this.preset.colors[0]);
|
|
@@ -736,7 +745,10 @@ class FallbackRenderer {
|
|
|
736
745
|
}
|
|
737
746
|
|
|
738
747
|
randomize() {
|
|
739
|
-
if (this.preset)
|
|
748
|
+
if (this.preset) {
|
|
749
|
+
this.preset.seed = Math.random() * 100;
|
|
750
|
+
this.timePhase = Math.random() * Math.PI * 2;
|
|
751
|
+
}
|
|
740
752
|
}
|
|
741
753
|
setMouseColor() {}
|
|
742
754
|
dispose() {}
|
|
@@ -962,10 +974,9 @@ function createCapsule(container, options = {}) {
|
|
|
962
974
|
for (const name of Object.keys(vars)) root.style.setProperty(name, vars[name]);
|
|
963
975
|
if (merged.textRatio !== undefined) {
|
|
964
976
|
root.style.setProperty('--hj-text-width', `${merged.textRatio}%`);
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
else root.style.removeProperty('--hj-text-min-width');
|
|
977
|
+
// textRatio 是文字区宽度的唯一权威值:min-width 会阻止其缩小到
|
|
978
|
+
// 164px 以下(--hj-copy-min-width 的历史默认),这里强制归零。
|
|
979
|
+
root.style.setProperty('--hj-text-min-width', '0');
|
|
969
980
|
}
|
|
970
981
|
renderer.resize();
|
|
971
982
|
};
|
|
@@ -1064,10 +1075,7 @@ function createCapsule(container, options = {}) {
|
|
|
1064
1075
|
dirty.textRatio = true;
|
|
1065
1076
|
merged.textRatio = value;
|
|
1066
1077
|
root.style.setProperty('--hj-text-width', `${value}%`);
|
|
1067
|
-
|
|
1068
|
-
if (value === 0) root.style.setProperty('--hj-text-min-width', '0');
|
|
1069
|
-
else if (userMinWidth) root.style.setProperty('--hj-text-min-width', userMinWidth);
|
|
1070
|
-
else root.style.removeProperty('--hj-text-min-width');
|
|
1078
|
+
root.style.setProperty('--hj-text-min-width', '0');
|
|
1071
1079
|
return this;
|
|
1072
1080
|
},
|
|
1073
1081
|
setCssVars(vars) {
|
|
@@ -1083,11 +1091,17 @@ function createCapsule(container, options = {}) {
|
|
|
1083
1091
|
return this;
|
|
1084
1092
|
},
|
|
1085
1093
|
setSize(width, height) {
|
|
1086
|
-
if (width !== undefined)
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1094
|
+
if (width !== undefined) {
|
|
1095
|
+
parseSize(width); // 非法尺寸直接抛错前先校验,避免污染内部状态
|
|
1096
|
+
merged.width = width;
|
|
1097
|
+
}
|
|
1098
|
+
if (height !== undefined) {
|
|
1099
|
+
parseSize(height);
|
|
1100
|
+
merged.height = height;
|
|
1101
|
+
}
|
|
1102
|
+
applySize();
|
|
1103
|
+
return this;
|
|
1104
|
+
},
|
|
1091
1105
|
randomize() {
|
|
1092
1106
|
this.setSeed(Math.random() * 100);
|
|
1093
1107
|
return this;
|
|
@@ -1114,8 +1128,8 @@ function createCapsule(container, options = {}) {
|
|
|
1114
1128
|
renderer.dispose();
|
|
1115
1129
|
root.remove();
|
|
1116
1130
|
},
|
|
1117
|
-
textRatio
|
|
1118
|
-
cssVars
|
|
1131
|
+
get textRatio() { return merged.textRatio; },
|
|
1132
|
+
get cssVars() { return merged.cssVars; },
|
|
1119
1133
|
dirty
|
|
1120
1134
|
};
|
|
1121
1135
|
}
|
package/dist/color.cjs
CHANGED
|
@@ -392,9 +392,13 @@ function getPreset(kind, ref) {
|
|
|
392
392
|
var list = CAPSULE_PRESETS ;
|
|
393
393
|
if (!list) throw new Error("Unknown preset kind: ".concat(kind, " (use \"capsule\" or \"progress\")"));
|
|
394
394
|
var key = String(ref).trim().toLowerCase();
|
|
395
|
-
var found =
|
|
396
|
-
|
|
397
|
-
|
|
395
|
+
var found = null;
|
|
396
|
+
for (var index = 0; index < list.length; index += 1) {
|
|
397
|
+
if (list[index].name.toLowerCase() === key) {
|
|
398
|
+
found = list[index];
|
|
399
|
+
break;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
398
402
|
if (!found) throw new Error("Unknown ".concat(kind, " preset: ").concat(ref));
|
|
399
403
|
return found;
|
|
400
404
|
}
|
|
@@ -571,7 +575,7 @@ function normalizeRgbArgs(args) {
|
|
|
571
575
|
if (parts.length < 3) return null;
|
|
572
576
|
var to255 = function to255(value) {
|
|
573
577
|
if (typeof value !== 'string' || !value) return null;
|
|
574
|
-
if (value.
|
|
578
|
+
if (value.charAt(value.length - 1) === '%') return clampChannel(parseFloat(value) / 100 * 255);
|
|
575
579
|
var number = Number(value);
|
|
576
580
|
return Number.isFinite(number) ? clampChannel(number) : null;
|
|
577
581
|
};
|
|
@@ -579,9 +583,11 @@ function normalizeRgbArgs(args) {
|
|
|
579
583
|
var green = to255(parts[1]);
|
|
580
584
|
var blue = to255(parts[2]);
|
|
581
585
|
if (red === null || green === null || blue === null) return null;
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
586
|
+
var hex = function hex(n) {
|
|
587
|
+
var text = n.toString(16);
|
|
588
|
+
return text.length === 1 ? "0".concat(text) : text;
|
|
589
|
+
};
|
|
590
|
+
return "#".concat(hex(red)).concat(hex(green)).concat(hex(blue));
|
|
585
591
|
}
|
|
586
592
|
|
|
587
593
|
/**
|
|
@@ -836,6 +842,7 @@ var FallbackRenderer = /*#__PURE__*/function () {
|
|
|
836
842
|
this.preset = preset;
|
|
837
843
|
this.context = canvas.getContext('2d');
|
|
838
844
|
this.visible = true;
|
|
845
|
+
this.timePhase = 0;
|
|
839
846
|
}
|
|
840
847
|
return _createClass(FallbackRenderer, [{
|
|
841
848
|
key: "resize",
|
|
@@ -856,7 +863,7 @@ var FallbackRenderer = /*#__PURE__*/function () {
|
|
|
856
863
|
var _this$canvas = this.canvas,
|
|
857
864
|
width = _this$canvas.width,
|
|
858
865
|
height = _this$canvas.height;
|
|
859
|
-
var t = time * (this.preset.speed || 1);
|
|
866
|
+
var t = (time + this.timePhase) * (this.preset.speed || 1);
|
|
860
867
|
var phase = (this.preset.seed || 0) * 0.7;
|
|
861
868
|
var gradient = ctx.createLinearGradient(0, 0, width, height);
|
|
862
869
|
gradient.addColorStop(0, this.preset.colors[0]);
|
|
@@ -893,7 +900,10 @@ var FallbackRenderer = /*#__PURE__*/function () {
|
|
|
893
900
|
}, {
|
|
894
901
|
key: "randomize",
|
|
895
902
|
value: function randomize() {
|
|
896
|
-
if (this.preset)
|
|
903
|
+
if (this.preset) {
|
|
904
|
+
this.preset.seed = Math.random() * 100;
|
|
905
|
+
this.timePhase = Math.random() * Math.PI * 2;
|
|
906
|
+
}
|
|
897
907
|
}
|
|
898
908
|
}, {
|
|
899
909
|
key: "setMouseColor",
|
|
@@ -1224,9 +1234,15 @@ function createColorBackground(host) {
|
|
|
1224
1234
|
renderer.dispose();
|
|
1225
1235
|
layer.remove();
|
|
1226
1236
|
},
|
|
1227
|
-
opacity
|
|
1228
|
-
|
|
1229
|
-
|
|
1237
|
+
get opacity() {
|
|
1238
|
+
return merged.opacity;
|
|
1239
|
+
},
|
|
1240
|
+
get fallbackColor() {
|
|
1241
|
+
return merged.fallbackColor;
|
|
1242
|
+
},
|
|
1243
|
+
get mouseColor() {
|
|
1244
|
+
return merged.mouseColor;
|
|
1245
|
+
},
|
|
1230
1246
|
dirty: dirty
|
|
1231
1247
|
};
|
|
1232
1248
|
}
|
package/dist/color.mjs
CHANGED
|
@@ -109,9 +109,13 @@ function getPreset(kind, ref) {
|
|
|
109
109
|
const list = CAPSULE_PRESETS ;
|
|
110
110
|
if (!list) throw new Error(`Unknown preset kind: ${kind} (use "capsule" or "progress")`);
|
|
111
111
|
const key = String(ref).trim().toLowerCase();
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
112
|
+
let found = null;
|
|
113
|
+
for (let index = 0; index < list.length; index += 1) {
|
|
114
|
+
if (list[index].name.toLowerCase() === key) {
|
|
115
|
+
found = list[index];
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
115
119
|
if (!found) throw new Error(`Unknown ${kind} preset: ${ref}`);
|
|
116
120
|
return found;
|
|
117
121
|
}
|
|
@@ -290,7 +294,7 @@ function normalizeRgbArgs(args) {
|
|
|
290
294
|
if (parts.length < 3) return null;
|
|
291
295
|
const to255 = (value) => {
|
|
292
296
|
if (typeof value !== 'string' || !value) return null;
|
|
293
|
-
if (value.
|
|
297
|
+
if (value.charAt(value.length - 1) === '%') return clampChannel((parseFloat(value) / 100) * 255);
|
|
294
298
|
const number = Number(value);
|
|
295
299
|
return Number.isFinite(number) ? clampChannel(number) : null;
|
|
296
300
|
};
|
|
@@ -298,7 +302,11 @@ function normalizeRgbArgs(args) {
|
|
|
298
302
|
const green = to255(parts[1]);
|
|
299
303
|
const blue = to255(parts[2]);
|
|
300
304
|
if (red === null || green === null || blue === null) return null;
|
|
301
|
-
|
|
305
|
+
const hex = (n) => {
|
|
306
|
+
const text = n.toString(16);
|
|
307
|
+
return text.length === 1 ? `0${text}` : text;
|
|
308
|
+
};
|
|
309
|
+
return `#${hex(red)}${hex(green)}${hex(blue)}`;
|
|
302
310
|
}
|
|
303
311
|
|
|
304
312
|
/**
|
|
@@ -645,12 +653,13 @@ function rgb(color, alpha = 1) {
|
|
|
645
653
|
}
|
|
646
654
|
|
|
647
655
|
class FallbackRenderer {
|
|
648
|
-
constructor(canvas, preset) {
|
|
649
|
-
this.canvas = canvas;
|
|
650
|
-
this.preset = preset;
|
|
651
|
-
this.context = canvas.getContext('2d');
|
|
652
|
-
this.visible = true;
|
|
653
|
-
|
|
656
|
+
constructor(canvas, preset) {
|
|
657
|
+
this.canvas = canvas;
|
|
658
|
+
this.preset = preset;
|
|
659
|
+
this.context = canvas.getContext('2d');
|
|
660
|
+
this.visible = true;
|
|
661
|
+
this.timePhase = 0;
|
|
662
|
+
}
|
|
654
663
|
|
|
655
664
|
resize() {
|
|
656
665
|
const rect = this.canvas.getBoundingClientRect();
|
|
@@ -666,7 +675,7 @@ class FallbackRenderer {
|
|
|
666
675
|
drawNebula(time) {
|
|
667
676
|
const ctx = this.context;
|
|
668
677
|
const { width, height } = this.canvas;
|
|
669
|
-
const t = time * (this.preset.speed || 1);
|
|
678
|
+
const t = (time + this.timePhase) * (this.preset.speed || 1);
|
|
670
679
|
const phase = (this.preset.seed || 0) * 0.7;
|
|
671
680
|
const gradient = ctx.createLinearGradient(0, 0, width, height);
|
|
672
681
|
gradient.addColorStop(0, this.preset.colors[0]);
|
|
@@ -701,7 +710,10 @@ class FallbackRenderer {
|
|
|
701
710
|
}
|
|
702
711
|
|
|
703
712
|
randomize() {
|
|
704
|
-
if (this.preset)
|
|
713
|
+
if (this.preset) {
|
|
714
|
+
this.preset.seed = Math.random() * 100;
|
|
715
|
+
this.timePhase = Math.random() * Math.PI * 2;
|
|
716
|
+
}
|
|
705
717
|
}
|
|
706
718
|
setMouseColor() {}
|
|
707
719
|
dispose() {}
|
|
@@ -1035,9 +1047,9 @@ function createColorBackground(host, options = {}) {
|
|
|
1035
1047
|
renderer.dispose();
|
|
1036
1048
|
layer.remove();
|
|
1037
1049
|
},
|
|
1038
|
-
opacity
|
|
1039
|
-
fallbackColor
|
|
1040
|
-
mouseColor
|
|
1050
|
+
get opacity() { return merged.opacity; },
|
|
1051
|
+
get fallbackColor() { return merged.fallbackColor; },
|
|
1052
|
+
get mouseColor() { return merged.mouseColor; },
|
|
1041
1053
|
dirty
|
|
1042
1054
|
};
|
|
1043
1055
|
}
|