@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/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,23 @@
|
|
|
2
2
|
|
|
3
3
|
> **发版规则**:默认每次发布只递增补丁号(0.x.y → 0.x.(y+1),即 +0.01);除非手动明确指定新版本号,否则不升次版本。
|
|
4
4
|
|
|
5
|
+
## 0.2.4 - 2026-08-08
|
|
6
|
+
|
|
7
|
+
- 移除 Progress `keyboard` 属性与键盘控制(拖动/受控 value 已覆盖主要场景)。
|
|
8
|
+
- 兼容性修复:legacy/IE11 路径补齐 `Array.prototype.find`、`String.prototype.endsWith`、`String.prototype.padStart` 缺失导致的崩溃(源码层也改为 ES5 写法)。
|
|
9
|
+
- 控制器暴露值改为实时 getter(`textRatio` / `cssVars` / `opacity` / `fallbackColor` / `mouseColor`),热更新后读取不再过期,Vue 重建时状态继承更准确。
|
|
10
|
+
- `setSize` 先校验再赋值,非法尺寸不再污染内部状态或抛进 Vue 更新流程。
|
|
11
|
+
- `setRange` 与创建时的 `min/max` 在 min>max 时自动交换。
|
|
12
|
+
- 结构属性连续变化时,重建后补一次插槽搬运(B3)。
|
|
13
|
+
- Canvas2D 降级的 `randomize()` 额外随机相位,变化更明显;README 注明降级路径 `mouseColor` 不生效。
|
|
14
|
+
|
|
15
|
+
## 0.2.3 - 2026-08-08
|
|
16
|
+
|
|
17
|
+
- 修复:Vue wrapper 重建组件(如 showValue 开关)后插槽内容丢失的问题(插槽容器改为整体搬入文字区/颜色区)。
|
|
18
|
+
- 修复:进度条点击后无法直接使用键盘方向键的问题(拖动开始时自动聚焦)。
|
|
19
|
+
- 修复:胶囊 `textRatio=0` 时文字区仍因最小宽度 164px 占位的问题,现 0 即完全隐藏。
|
|
20
|
+
- 新增 Progress `readonly` 属性:与 disabled 行为一致但不置灰(`aria-readonly`)。
|
|
21
|
+
|
|
5
22
|
## 0.2.2 - 2026-08-08
|
|
6
23
|
|
|
7
24
|
- 修复:Progress 的 `setLabel()` 对 const 变量重新赋值,导致打包产物被 esbuild 拒绝、文档站无法构建的问题;label 热更新恢复正常。
|
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
|
|
|
@@ -181,7 +181,7 @@ dlc-color 背景层(`createColorBackground(host, options)`):`preset`、`co
|
|
|
181
181
|
## 属性 vs cssVars 边界
|
|
182
182
|
|
|
183
183
|
- **内容(文字/图片/按钮)**:只归插槽管,组件不施加任何样式;
|
|
184
|
-
- **文字区宽度**:只归 `textRatio` 属性管(唯一入口,写入 `--hj-text-width
|
|
184
|
+
- **文字区宽度**:只归 `textRatio` 属性管(唯一入口,写入 `--hj-text-width`;`0` 即隐藏文字区);
|
|
185
185
|
- **区域外观(背景/内边距/圆角/左侧距)**:只归 cssVars 管;
|
|
186
186
|
- **星云颜料**:只归 `colors` 属性管(与 `#color` 插槽无关,前者改画布颜料,后者放你的覆盖内容);
|
|
187
187
|
- 旧的 `--hj-copy-*`、`--hj-progress-copy-*` 变量保留为**兼容别名**,只兜底不优先。
|
|
@@ -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,6 +1184,8 @@ function createCapsule(container) {
|
|
|
1174
1184
|
}
|
|
1175
1185
|
if (merged.textRatio !== undefined) {
|
|
1176
1186
|
root.style.setProperty('--hj-text-width', "".concat(merged.textRatio, "%"));
|
|
1187
|
+
var userMinWidth = merged.cssVars && merged.cssVars['--hj-text-min-width'];
|
|
1188
|
+
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');
|
|
1177
1189
|
}
|
|
1178
1190
|
renderer.resize();
|
|
1179
1191
|
};
|
|
@@ -1297,6 +1309,8 @@ function createCapsule(container) {
|
|
|
1297
1309
|
dirty.textRatio = true;
|
|
1298
1310
|
merged.textRatio = value;
|
|
1299
1311
|
root.style.setProperty('--hj-text-width', "".concat(value, "%"));
|
|
1312
|
+
var userMinWidth = merged.cssVars && merged.cssVars['--hj-text-min-width'];
|
|
1313
|
+
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');
|
|
1300
1314
|
return this;
|
|
1301
1315
|
},
|
|
1302
1316
|
setCssVars: function setCssVars(vars) {
|
|
@@ -1315,8 +1329,14 @@ function createCapsule(container) {
|
|
|
1315
1329
|
return this;
|
|
1316
1330
|
},
|
|
1317
1331
|
setSize: function setSize(width, height) {
|
|
1318
|
-
if (width !== undefined)
|
|
1319
|
-
|
|
1332
|
+
if (width !== undefined) {
|
|
1333
|
+
parseSize(width); // 非法尺寸直接抛错前先校验,避免污染内部状态
|
|
1334
|
+
merged.width = width;
|
|
1335
|
+
}
|
|
1336
|
+
if (height !== undefined) {
|
|
1337
|
+
parseSize(height);
|
|
1338
|
+
merged.height = height;
|
|
1339
|
+
}
|
|
1320
1340
|
applySize();
|
|
1321
1341
|
return this;
|
|
1322
1342
|
},
|
|
@@ -1345,8 +1365,12 @@ function createCapsule(container) {
|
|
|
1345
1365
|
renderer.dispose();
|
|
1346
1366
|
root.remove();
|
|
1347
1367
|
},
|
|
1348
|
-
textRatio
|
|
1349
|
-
|
|
1368
|
+
get textRatio() {
|
|
1369
|
+
return merged.textRatio;
|
|
1370
|
+
},
|
|
1371
|
+
get cssVars() {
|
|
1372
|
+
return merged.cssVars;
|
|
1373
|
+
},
|
|
1350
1374
|
dirty: dirty
|
|
1351
1375
|
};
|
|
1352
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,6 +974,10 @@ 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}%`);
|
|
977
|
+
const userMinWidth = merged.cssVars && merged.cssVars['--hj-text-min-width'];
|
|
978
|
+
if (merged.textRatio === 0) root.style.setProperty('--hj-text-min-width', '0');
|
|
979
|
+
else if (userMinWidth) root.style.setProperty('--hj-text-min-width', userMinWidth);
|
|
980
|
+
else root.style.removeProperty('--hj-text-min-width');
|
|
965
981
|
}
|
|
966
982
|
renderer.resize();
|
|
967
983
|
};
|
|
@@ -1060,6 +1076,10 @@ function createCapsule(container, options = {}) {
|
|
|
1060
1076
|
dirty.textRatio = true;
|
|
1061
1077
|
merged.textRatio = value;
|
|
1062
1078
|
root.style.setProperty('--hj-text-width', `${value}%`);
|
|
1079
|
+
const userMinWidth = merged.cssVars && merged.cssVars['--hj-text-min-width'];
|
|
1080
|
+
if (value === 0) root.style.setProperty('--hj-text-min-width', '0');
|
|
1081
|
+
else if (userMinWidth) root.style.setProperty('--hj-text-min-width', userMinWidth);
|
|
1082
|
+
else root.style.removeProperty('--hj-text-min-width');
|
|
1063
1083
|
return this;
|
|
1064
1084
|
},
|
|
1065
1085
|
setCssVars(vars) {
|
|
@@ -1075,11 +1095,17 @@ function createCapsule(container, options = {}) {
|
|
|
1075
1095
|
return this;
|
|
1076
1096
|
},
|
|
1077
1097
|
setSize(width, height) {
|
|
1078
|
-
if (width !== undefined)
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1098
|
+
if (width !== undefined) {
|
|
1099
|
+
parseSize(width); // 非法尺寸直接抛错前先校验,避免污染内部状态
|
|
1100
|
+
merged.width = width;
|
|
1101
|
+
}
|
|
1102
|
+
if (height !== undefined) {
|
|
1103
|
+
parseSize(height);
|
|
1104
|
+
merged.height = height;
|
|
1105
|
+
}
|
|
1106
|
+
applySize();
|
|
1107
|
+
return this;
|
|
1108
|
+
},
|
|
1083
1109
|
randomize() {
|
|
1084
1110
|
this.setSeed(Math.random() * 100);
|
|
1085
1111
|
return this;
|
|
@@ -1106,8 +1132,8 @@ function createCapsule(container, options = {}) {
|
|
|
1106
1132
|
renderer.dispose();
|
|
1107
1133
|
root.remove();
|
|
1108
1134
|
},
|
|
1109
|
-
textRatio
|
|
1110
|
-
cssVars
|
|
1135
|
+
get textRatio() { return merged.textRatio; },
|
|
1136
|
+
get cssVars() { return merged.cssVars; },
|
|
1111
1137
|
dirty
|
|
1112
1138
|
};
|
|
1113
1139
|
}
|
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
|
}
|