@xenra/dsh-draworld 0.1.40 → 0.1.46
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/README.md +86 -12
- package/client.js +437 -97
- package/index.js +1026 -71
- package/package.json +1 -1
- package/pixelops.js +1288 -0
- package/pixels.js +182 -19
package/client.js
CHANGED
|
@@ -110,6 +110,11 @@ window.__ModuleLoader__.load({
|
|
|
110
110
|
opacity: '不透明度',
|
|
111
111
|
blendNormal: '正常',
|
|
112
112
|
blendMultiply: '正片叠底',
|
|
113
|
+
blendScreen: '滤色',
|
|
114
|
+
blendOverlay: '叠加',
|
|
115
|
+
blendSoftLight: '柔光',
|
|
116
|
+
blendLinearDodge: '线性减淡',
|
|
117
|
+
lockAlphaHint: '锁定透明像素:只在已有内容上画',
|
|
113
118
|
toolBrush: '笔',
|
|
114
119
|
toolEraser: '擦',
|
|
115
120
|
toolLine: '线',
|
|
@@ -259,6 +264,11 @@ window.__ModuleLoader__.load({
|
|
|
259
264
|
opacity: 'Opacity',
|
|
260
265
|
blendNormal: 'Normal',
|
|
261
266
|
blendMultiply: 'Multiply',
|
|
267
|
+
blendScreen: 'Screen',
|
|
268
|
+
blendOverlay: 'Overlay',
|
|
269
|
+
blendSoftLight: 'Soft light',
|
|
270
|
+
blendLinearDodge: 'Linear dodge',
|
|
271
|
+
lockAlphaHint: 'Lock transparent pixels',
|
|
262
272
|
toolBrush: 'Brush',
|
|
263
273
|
toolEraser: 'Erase',
|
|
264
274
|
toolLine: 'Line',
|
|
@@ -920,19 +930,29 @@ window.__ModuleLoader__.load({
|
|
|
920
930
|
g.restore();
|
|
921
931
|
}
|
|
922
932
|
|
|
923
|
-
/**
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
scratch.width = w;
|
|
931
|
-
scratch.height = hgt;
|
|
932
|
-
scratchW = w;
|
|
933
|
-
scratchH = hgt;
|
|
933
|
+
/** 图层合成用的离屏画布池:按 key 复用,层 buffer / clip mask / hue 各用各的。 */
|
|
934
|
+
const scratchPool = new Map();
|
|
935
|
+
const scratchOf = (w, hgt, key = 'default') => {
|
|
936
|
+
let c = scratchPool.get(key);
|
|
937
|
+
if (!c) {
|
|
938
|
+
c = document.createElement('canvas');
|
|
939
|
+
scratchPool.set(key, c);
|
|
934
940
|
}
|
|
935
|
-
|
|
941
|
+
if (c.width !== w || c.height !== hgt) {
|
|
942
|
+
c.width = w;
|
|
943
|
+
c.height = hgt;
|
|
944
|
+
}
|
|
945
|
+
return c;
|
|
946
|
+
};
|
|
947
|
+
const clearCanvas = (c) => {
|
|
948
|
+
const x = c.getContext('2d');
|
|
949
|
+
x.save();
|
|
950
|
+
x.setTransform(1, 0, 0, 1, 0, 0);
|
|
951
|
+
x.globalAlpha = 1;
|
|
952
|
+
x.globalCompositeOperation = 'source-over';
|
|
953
|
+
x.filter = 'none';
|
|
954
|
+
x.clearRect(0, 0, c.width, c.height);
|
|
955
|
+
x.restore();
|
|
936
956
|
};
|
|
937
957
|
|
|
938
958
|
const layersOf = (doc) => {
|
|
@@ -993,13 +1013,14 @@ window.__ModuleLoader__.load({
|
|
|
993
1013
|
ctx.drawImage(img, Number(meta.x) || 0, Number(meta.y) || 0, w, h);
|
|
994
1014
|
}
|
|
995
1015
|
|
|
996
|
-
/**
|
|
1016
|
+
/** 把文档画到画布:v3 层缓冲合成(blend / clipTo / hue / 组显隐)。 */
|
|
997
1017
|
function renderDoc(canvas, doc, opts = {}) {
|
|
998
1018
|
if (!canvas || !doc) return;
|
|
999
1019
|
const w = doc.width || 1024;
|
|
1000
1020
|
const hgt = doc.height || 1024;
|
|
1001
1021
|
if (canvas.width !== w) canvas.width = w;
|
|
1002
|
-
if (canvas.height !== hgt) canvas.height = hgt;
|
|
1022
|
+
if (canvas.height !== hgt) canvas.height = hgt;
|
|
1023
|
+
const g = canvas.getContext('2d');
|
|
1003
1024
|
g.save();
|
|
1004
1025
|
g.globalCompositeOperation = 'source-over';
|
|
1005
1026
|
g.globalAlpha = 1;
|
|
@@ -1010,40 +1031,112 @@ window.__ModuleLoader__.load({
|
|
|
1010
1031
|
}
|
|
1011
1032
|
g.restore();
|
|
1012
1033
|
|
|
1013
|
-
|
|
1034
|
+
const BLEND_CANVAS = {
|
|
1035
|
+
normal: 'source-over',
|
|
1036
|
+
multiply: 'multiply',
|
|
1037
|
+
screen: 'screen',
|
|
1038
|
+
overlay: 'overlay',
|
|
1039
|
+
'soft-light': 'soft-light',
|
|
1040
|
+
'linear-dodge': 'lighter',
|
|
1041
|
+
};
|
|
1042
|
+
const groups = new Map((doc.groups || []).map((item) => [item.id, item]));
|
|
1043
|
+
const allLayers = layersOf(doc);
|
|
1044
|
+
const byId = new Map(allLayers.map((item) => [item.id, item]));
|
|
1045
|
+
const lineLayer = allLayers.find((item) => item.role === 'line' && item.visible !== false && !item.image);
|
|
1046
|
+
const maskCache = new Map();
|
|
1047
|
+
const drawContent = (ctx, layer) => {
|
|
1048
|
+
if (layer.image && layer.image.file) drawImageLayer(ctx, layer.image);
|
|
1049
|
+
for (const s of layer.strokes || []) paintStroke(ctx, s);
|
|
1050
|
+
};
|
|
1051
|
+
const maskOf = (id) => {
|
|
1052
|
+
if (maskCache.has(id)) return maskCache.get(id);
|
|
1053
|
+
const c = scratchOf(w, hgt, `mask:${id}`);
|
|
1054
|
+
clearCanvas(c);
|
|
1055
|
+
const ctx2 = c.getContext('2d');
|
|
1056
|
+
if (typeof id === 'string' && (id.startsWith('role:') || id.startsWith('group:'))) {
|
|
1057
|
+
const isRole = id.startsWith('role:');
|
|
1058
|
+
const key = id.slice(isRole ? 5 : 6);
|
|
1059
|
+
for (const item of allLayers) {
|
|
1060
|
+
if (item.visible === false) continue;
|
|
1061
|
+
if (isRole ? item.role !== key : item.groupId !== key) continue;
|
|
1062
|
+
drawContent(ctx2, item);
|
|
1063
|
+
}
|
|
1064
|
+
} else {
|
|
1065
|
+
const target = byId.get(id);
|
|
1066
|
+
if (target) drawContent(ctx2, target);
|
|
1067
|
+
}
|
|
1068
|
+
maskCache.set(id, c);
|
|
1069
|
+
return c;
|
|
1070
|
+
};
|
|
1071
|
+
for (const layer of allLayers) {
|
|
1014
1072
|
if (layer.visible === false) continue;
|
|
1015
|
-
const
|
|
1073
|
+
const group = layer.groupId ? groups.get(layer.groupId) : null;
|
|
1074
|
+
if (group && group.visible === false) continue;
|
|
1075
|
+
const groupOpacity = group && group.opacity !== undefined ? Math.max(0, Math.min(1, Number(group.opacity))) : 1;
|
|
1076
|
+
const opacity = (layer.opacity === undefined ? 1 : Number(layer.opacity)) * groupOpacity;
|
|
1016
1077
|
if (!opacity) continue;
|
|
1017
|
-
|
|
1078
|
+
if (layer.role === 'grade' && layer.grade) {
|
|
1079
|
+
const tmp = scratchOf(w, hgt, 'grade');
|
|
1080
|
+
clearCanvas(tmp);
|
|
1081
|
+
tmp.getContext('2d').drawImage(canvas, 0, 0);
|
|
1082
|
+
g.save();
|
|
1083
|
+
g.clearRect(0, 0, w, hgt);
|
|
1084
|
+
if ('filter' in g) {
|
|
1085
|
+
const gr = layer.grade;
|
|
1086
|
+
g.filter = `brightness(${Math.max(0, 1 + (Number(gr.brightness) || 0))}) contrast(${Number(gr.contrast === undefined ? 1 : gr.contrast)}) saturate(${Number(gr.saturation === undefined ? 1 : gr.saturation)}) hue-rotate(${Number(gr.hue) || 0}deg)`;
|
|
1087
|
+
}
|
|
1088
|
+
g.drawImage(tmp, 0, 0);
|
|
1089
|
+
g.filter = 'none';
|
|
1090
|
+
g.restore();
|
|
1091
|
+
continue;
|
|
1092
|
+
}
|
|
1093
|
+
const blend = BLEND_CANVAS[layer.blend] ? layer.blend : 'normal';
|
|
1018
1094
|
const strokes = layer.strokes || [];
|
|
1019
|
-
const hasImage = Boolean(layer.image && layer.image.file);
|
|
1020
|
-
// 有橡皮、带透明度或混合模式的层必须走离屏,否则橡皮会把背景也擦穿
|
|
1021
1095
|
const hasEraser = strokes.some((s) => s.mode === 'eraser');
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1096
|
+
const special = opacity < 1 || blend !== 'normal' || layer.clipTo || layer.hue || hasEraser || (layer.role === 'base' && lineLayer);
|
|
1097
|
+
if (!special) {
|
|
1098
|
+
drawContent(g, layer);
|
|
1025
1099
|
continue;
|
|
1026
1100
|
}
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1101
|
+
let buf = scratchOf(w, hgt, `buf:${layer.id}`);
|
|
1102
|
+
clearCanvas(buf);
|
|
1103
|
+
drawContent(buf.getContext('2d'), layer);
|
|
1104
|
+
if (layer.role === 'base' && lineLayer && layer.id !== lineLayer.id) {
|
|
1105
|
+
// 铺底给线稿让位:线在下面,不能被色块整片盖住
|
|
1106
|
+
const mask = maskOf(lineLayer.id);
|
|
1107
|
+
if (mask) {
|
|
1108
|
+
const bctx = buf.getContext('2d');
|
|
1109
|
+
bctx.save();
|
|
1110
|
+
bctx.globalCompositeOperation = 'destination-out';
|
|
1111
|
+
bctx.drawImage(mask, 0, 0);
|
|
1112
|
+
bctx.restore();
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
let src = buf;
|
|
1116
|
+
if (layer.hue) {
|
|
1117
|
+
const hueCan = scratchOf(w, hgt, `hue:${layer.id}`);
|
|
1118
|
+
clearCanvas(hueCan);
|
|
1119
|
+
const hctx = hueCan.getContext('2d');
|
|
1120
|
+
if ('filter' in hctx) hctx.filter = `hue-rotate(${Number(layer.hue)}deg)`;
|
|
1121
|
+
hctx.drawImage(buf, 0, 0);
|
|
1122
|
+
src = hueCan;
|
|
1123
|
+
}
|
|
1124
|
+
if (layer.clipTo) {
|
|
1125
|
+
const mask = maskOf(layer.clipTo);
|
|
1126
|
+
const clipCan = scratchOf(w, hgt, `clip:${layer.id}`);
|
|
1127
|
+
clearCanvas(clipCan);
|
|
1128
|
+
const cctx = clipCan.getContext('2d');
|
|
1129
|
+
cctx.drawImage(src, 0, 0);
|
|
1130
|
+
cctx.globalCompositeOperation = 'destination-in';
|
|
1131
|
+
if (mask) cctx.drawImage(mask, 0, 0);
|
|
1132
|
+
src = clipCan;
|
|
1133
|
+
}
|
|
1037
1134
|
g.save();
|
|
1038
1135
|
g.globalAlpha = opacity;
|
|
1039
|
-
g.globalCompositeOperation = blend;
|
|
1040
|
-
g.drawImage(
|
|
1136
|
+
g.globalCompositeOperation = BLEND_CANVAS[blend] || 'source-over';
|
|
1137
|
+
g.drawImage(src, 0, 0);
|
|
1041
1138
|
g.restore();
|
|
1042
1139
|
}
|
|
1043
|
-
g.save();
|
|
1044
|
-
g.globalCompositeOperation = 'source-over';
|
|
1045
|
-
g.globalAlpha = 1;
|
|
1046
|
-
g.restore();
|
|
1047
1140
|
}
|
|
1048
1141
|
|
|
1049
1142
|
/**
|
|
@@ -1057,6 +1150,13 @@ window.__ModuleLoader__.load({
|
|
|
1057
1150
|
const a = layersOf(prevDoc);
|
|
1058
1151
|
const b = layersOf(nextDoc);
|
|
1059
1152
|
if (a.length !== b.length) return false;
|
|
1153
|
+
// v3:有 clipTo / hue / lockAlpha / 非 normal 混合 / 组参数变化时一律全量重绘
|
|
1154
|
+
for (const l of b) {
|
|
1155
|
+
if (l.clipTo || l.hue || l.lockAlpha) return false;
|
|
1156
|
+
if ((l.blend || 'normal') !== 'normal') return false;
|
|
1157
|
+
}
|
|
1158
|
+
const groups = nextDoc.groups || [];
|
|
1159
|
+
if (groups.some((gr) => gr.visible === false || (gr.opacity !== undefined && Number(gr.opacity) !== 1))) return false;
|
|
1060
1160
|
let changed = -1;
|
|
1061
1161
|
let added = 0;
|
|
1062
1162
|
for (let i = 0; i < b.length; i += 1) {
|
|
@@ -2555,6 +2655,10 @@ window.__ModuleLoader__.load({
|
|
|
2555
2655
|
const [taper, setTaper] = React.useState(true);
|
|
2556
2656
|
const [staleHost, setStaleHost] = React.useState(false);
|
|
2557
2657
|
const [layerDock, setLayerDock] = React.useState(true);
|
|
2658
|
+
const [collapsedGroups, setCollapsedGroups] = React.useState({});
|
|
2659
|
+
// 组菜单:展开哪一组,就显示它那一行的设置(改名 / 组不透明度 / 上下移 / 删除)
|
|
2660
|
+
const [openGroup, setOpenGroup] = React.useState(null);
|
|
2661
|
+
const [checkReport, setCheckReport] = React.useState(null);
|
|
2558
2662
|
// 图层不透明度拖动时先用本地值显示,等宿主回包(700ms 轮询)再对齐,不然滑块会跳
|
|
2559
2663
|
const [optOpacity, setOptOpacity] = React.useState(null);
|
|
2560
2664
|
const [playing, setPlaying] = React.useState(false);
|
|
@@ -2562,6 +2666,9 @@ window.__ModuleLoader__.load({
|
|
|
2562
2666
|
const [updateInfo, setUpdateInfo] = React.useState(null);
|
|
2563
2667
|
const [applying, setApplying] = React.useState(false);
|
|
2564
2668
|
const [applyNote, setApplyNote] = React.useState('');
|
|
2669
|
+
/** 宿主正在大批落笔时的进度(分块写入,面板能边画边看)。 */
|
|
2670
|
+
const [painting, setPainting] = React.useState(null);
|
|
2671
|
+
const paintingRef = React.useRef(null);
|
|
2565
2672
|
|
|
2566
2673
|
/** 一键更新:宿主拿 pluginManager 按 tag 重装(git 安装也能收更新)。 */
|
|
2567
2674
|
const applyUpdate = async () => {
|
|
@@ -2612,7 +2719,7 @@ window.__ModuleLoader__.load({
|
|
|
2612
2719
|
setChecking(false);
|
|
2613
2720
|
}
|
|
2614
2721
|
};
|
|
2615
|
-
const [meta, setMeta] = React.useState({ strokes: 0, redo: 0, layers: [], activeLayer: null, background: '#ffffff', width: 1024, height: 1024 });
|
|
2722
|
+
const [meta, setMeta] = React.useState({ strokes: 0, redo: 0, layers: [], groups: [], activeLayer: null, background: '#ffffff', width: 1024, height: 1024 });
|
|
2616
2723
|
const viewportRef = React.useRef(null);
|
|
2617
2724
|
const viewRef = React.useRef({ scale: 1, x: 0, y: 0 });
|
|
2618
2725
|
const panRef = React.useRef(null);
|
|
@@ -2675,16 +2782,32 @@ window.__ModuleLoader__.load({
|
|
|
2675
2782
|
const layers = (doc.layers || []).map((l) => ({
|
|
2676
2783
|
id: l.id,
|
|
2677
2784
|
name: l.name,
|
|
2785
|
+
role: l.role || 'base',
|
|
2786
|
+
groupId: l.groupId || null,
|
|
2678
2787
|
visible: l.visible !== false,
|
|
2679
2788
|
opacity: l.opacity === undefined ? 1 : l.opacity,
|
|
2680
2789
|
blend: l.blend || 'normal',
|
|
2790
|
+
clipTo: l.clipTo || null,
|
|
2791
|
+
lockAlpha: l.lockAlpha === true,
|
|
2792
|
+
hue: l.hue || 0,
|
|
2793
|
+
grade: l.grade || null,
|
|
2681
2794
|
count: (l.strokes || []).length,
|
|
2682
2795
|
image: Boolean(l.image && l.image.file),
|
|
2796
|
+
ready: (l.strokes || []).length > 0 || Boolean(l.image && l.image.file),
|
|
2683
2797
|
}));
|
|
2684
2798
|
setMeta({
|
|
2685
2799
|
strokes: layers.reduce((n, l) => n + l.count, 0),
|
|
2686
2800
|
redo: (doc.redo || []).length,
|
|
2687
2801
|
layers,
|
|
2802
|
+
groups: (doc.groups || []).map((g) => ({
|
|
2803
|
+
id: g.id,
|
|
2804
|
+
name: g.name,
|
|
2805
|
+
kind: g.kind,
|
|
2806
|
+
visible: g.visible !== false,
|
|
2807
|
+
locked: g.locked === true,
|
|
2808
|
+
opacity: g.opacity === undefined ? 1 : g.opacity,
|
|
2809
|
+
collapsed: g.collapsed === true,
|
|
2810
|
+
})),
|
|
2688
2811
|
activeLayer: doc.activeLayer,
|
|
2689
2812
|
background: doc.background || '#ffffff',
|
|
2690
2813
|
width: doc.width || 1024,
|
|
@@ -2837,6 +2960,8 @@ window.__ModuleLoader__.load({
|
|
|
2837
2960
|
// 宿主有没有 32 支笔刷:旧进程只认 5 支,落笔后笔刷会被丢掉,重画成圆头
|
|
2838
2961
|
setStaleHost(!(Number(body.brushes) >= BRUSHES.length));
|
|
2839
2962
|
setUpdateInfo(body.update || null);
|
|
2963
|
+
setPainting(body.painting || null);
|
|
2964
|
+
paintingRef.current = body.painting || null;
|
|
2840
2965
|
if (body.version) setLocalVer(String(body.version));
|
|
2841
2966
|
const prevDoc = docRef.current;
|
|
2842
2967
|
const prevRev = revRef.current;
|
|
@@ -2862,7 +2987,8 @@ window.__ModuleLoader__.load({
|
|
|
2862
2987
|
} catch {
|
|
2863
2988
|
if (alive) setError(t('syncFailed'));
|
|
2864
2989
|
} finally {
|
|
2865
|
-
|
|
2990
|
+
// 正在落笔就加密轮询,进度条和画布才是「长出来」而不是三跳到底
|
|
2991
|
+
if (alive) timer = setTimeout(tick, paintingRef.current ? 150 : 500);
|
|
2866
2992
|
}
|
|
2867
2993
|
};
|
|
2868
2994
|
tick();
|
|
@@ -3279,6 +3405,10 @@ window.__ModuleLoader__.load({
|
|
|
3279
3405
|
},
|
|
3280
3406
|
h('option', { value: 'normal' }, t('blendNormal')),
|
|
3281
3407
|
h('option', { value: 'multiply' }, t('blendMultiply')),
|
|
3408
|
+
h('option', { value: 'screen' }, t('blendScreen')),
|
|
3409
|
+
h('option', { value: 'overlay' }, t('blendOverlay')),
|
|
3410
|
+
h('option', { value: 'soft-light' }, t('blendSoftLight')),
|
|
3411
|
+
h('option', { value: 'linear-dodge' }, t('blendLinearDodge')),
|
|
3282
3412
|
),
|
|
3283
3413
|
)
|
|
3284
3414
|
: null,
|
|
@@ -3331,6 +3461,44 @@ window.__ModuleLoader__.load({
|
|
|
3331
3461
|
},
|
|
3332
3462
|
}),
|
|
3333
3463
|
),
|
|
3464
|
+
painting
|
|
3465
|
+
? h('div', {
|
|
3466
|
+
style: {
|
|
3467
|
+
position: 'absolute',
|
|
3468
|
+
left: 8,
|
|
3469
|
+
top: 8,
|
|
3470
|
+
display: 'flex',
|
|
3471
|
+
alignItems: 'center',
|
|
3472
|
+
gap: 8,
|
|
3473
|
+
padding: '4px 8px',
|
|
3474
|
+
borderRadius: 6,
|
|
3475
|
+
background: 'rgba(0,0,0,0.5)',
|
|
3476
|
+
color: '#f2f2f2',
|
|
3477
|
+
fontSize: 11,
|
|
3478
|
+
pointerEvents: 'none',
|
|
3479
|
+
},
|
|
3480
|
+
},
|
|
3481
|
+
h('span', null, `✎ ${painting.layer || ''}`),
|
|
3482
|
+
h('div', {
|
|
3483
|
+
style: {
|
|
3484
|
+
width: 92,
|
|
3485
|
+
height: 4,
|
|
3486
|
+
borderRadius: 2,
|
|
3487
|
+
background: 'rgba(255,255,255,0.25)',
|
|
3488
|
+
overflow: 'hidden',
|
|
3489
|
+
},
|
|
3490
|
+
}, h('div', {
|
|
3491
|
+
style: {
|
|
3492
|
+
width: `${Math.min(100, Math.round(((painting.done || 0) / Math.max(1, painting.total || 1)) * 100))}%`,
|
|
3493
|
+
height: '100%',
|
|
3494
|
+
background: 'var(--dsw-alias-brand-primary, #4c8bf5)',
|
|
3495
|
+
transition: 'width 120ms linear',
|
|
3496
|
+
},
|
|
3497
|
+
})),
|
|
3498
|
+
h('span', { style: { fontVariantNumeric: 'tabular-nums' } },
|
|
3499
|
+
`${painting.done || 0}/${painting.total || 0}`),
|
|
3500
|
+
)
|
|
3501
|
+
: null,
|
|
3334
3502
|
h('div', {
|
|
3335
3503
|
title: t('panHint'),
|
|
3336
3504
|
style: {
|
|
@@ -3473,70 +3641,163 @@ window.__ModuleLoader__.load({
|
|
|
3473
3641
|
gap: 3,
|
|
3474
3642
|
},
|
|
3475
3643
|
},
|
|
3476
|
-
|
|
3477
|
-
const
|
|
3478
|
-
|
|
3479
|
-
key
|
|
3480
|
-
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
|
|
3486
|
-
|
|
3487
|
-
|
|
3488
|
-
|
|
3489
|
-
|
|
3490
|
-
|
|
3491
|
-
|
|
3492
|
-
|
|
3493
|
-
|
|
3494
|
-
|
|
3495
|
-
|
|
3496
|
-
|
|
3497
|
-
|
|
3644
|
+
(() => {
|
|
3645
|
+
const byGroup = new Map();
|
|
3646
|
+
for (const l of meta.layers) {
|
|
3647
|
+
const key = l.groupId || 'g_color';
|
|
3648
|
+
if (!byGroup.has(key)) byGroup.set(key, []);
|
|
3649
|
+
byGroup.get(key).push(l);
|
|
3650
|
+
}
|
|
3651
|
+
const layerRow = (l) => {
|
|
3652
|
+
const isActive = l.id === meta.activeLayer;
|
|
3653
|
+
return h('div', {
|
|
3654
|
+
key: l.id,
|
|
3655
|
+
draggable: true,
|
|
3656
|
+
onDragStart: (e) => {
|
|
3657
|
+
e.dataTransfer.setData('text/layer', l.id);
|
|
3658
|
+
e.dataTransfer.effectAllowed = 'move';
|
|
3659
|
+
},
|
|
3660
|
+
// 拖到另一层上 = 落到它所在的组(组内按 role 归位)
|
|
3661
|
+
onDragOver: (e) => e.preventDefault(),
|
|
3662
|
+
onDrop: (e) => {
|
|
3663
|
+
e.preventDefault();
|
|
3664
|
+
e.stopPropagation();
|
|
3665
|
+
const id = e.dataTransfer.getData('text/layer');
|
|
3666
|
+
if (id && id !== l.id) onOp('group.moveLayer', { layer: id, groupId: l.groupId });
|
|
3667
|
+
},
|
|
3668
|
+
onClick: () => onOp('layer.set', { id: l.id, patch: { active: true } }),
|
|
3498
3669
|
style: {
|
|
3499
|
-
|
|
3500
|
-
|
|
3501
|
-
|
|
3670
|
+
display: 'flex',
|
|
3671
|
+
alignItems: 'center',
|
|
3672
|
+
gap: 6,
|
|
3673
|
+
padding: '4px 5px',
|
|
3674
|
+
borderRadius: 7,
|
|
3502
3675
|
cursor: 'pointer',
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
|
|
3676
|
+
border: `1px solid ${isActive ? 'var(--dsw-alias-brand-primary, #4c8bf5)' : 'transparent'}`,
|
|
3677
|
+
background: isActive
|
|
3678
|
+
? 'var(--dsw-alias-button-ghost-active-fill, rgba(76,139,245,0.14))'
|
|
3679
|
+
: 'transparent',
|
|
3680
|
+
opacity: l.visible ? 1 : 0.55,
|
|
3506
3681
|
},
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3682
|
+
},
|
|
3683
|
+
h('button', {
|
|
3684
|
+
type: 'button',
|
|
3685
|
+
title: t('layerVisibility'),
|
|
3686
|
+
style: { border: 'none', background: 'transparent', color: 'var(--dsw-alias-label-secondary, inherit)', cursor: 'pointer', padding: 0, fontSize: 12, flex: '0 0 14px' },
|
|
3687
|
+
onClick: (e) => {
|
|
3688
|
+
e.stopPropagation();
|
|
3689
|
+
onOp('layer.set', { id: l.id, patch: { visible: !l.visible } });
|
|
3690
|
+
},
|
|
3691
|
+
}, l.visible ? '◉' : '○'),
|
|
3692
|
+
h(LayerThumb, { layerId: l.id, sig: `${l.count}:${l.image ? 'img' : 'vec'}`, docRef, rev: revision }),
|
|
3693
|
+
h('div', { style: { flex: '1 1 auto', minWidth: 0 } },
|
|
3694
|
+
h('div', { style: { fontSize: 11.5, fontWeight: isActive ? 600 : 400, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, l.name),
|
|
3695
|
+
h('div', { style: { fontSize: 10, color: 'var(--dsw-alias-label-tertiary, inherit)', display: 'flex', gap: 6, overflow: 'hidden', whiteSpace: 'nowrap' } },
|
|
3696
|
+
h('span', null, l.image ? 'IMG' : `${l.count} ${t('strokes')}`),
|
|
3697
|
+
h('span', null, l.role),
|
|
3698
|
+
l.clipTo ? h('span', null, '↳') : null,
|
|
3699
|
+
l.lockAlpha ? h('span', null, 'α•') : null,
|
|
3700
|
+
l.opacity < 1 ? h('span', null, `${Math.round(l.opacity * 100)}%`) : null,
|
|
3701
|
+
l.blend !== 'normal' ? h('span', null, l.blend) : null,
|
|
3702
|
+
),
|
|
3703
|
+
),
|
|
3704
|
+
);
|
|
3705
|
+
};
|
|
3706
|
+
const rows = [];
|
|
3707
|
+
const groupDefs = (meta.groups || []).slice().reverse();
|
|
3708
|
+
const groupIds = new Set(groupDefs.map((g) => g.id));
|
|
3709
|
+
for (const g of groupDefs) {
|
|
3710
|
+
const items = byGroup.get(g.id) || [];
|
|
3711
|
+
const collapsed = collapsedGroups[g.id] || g.collapsed;
|
|
3712
|
+
const isOpen = openGroup === g.id;
|
|
3713
|
+
const gBtn = { border: 'none', background: 'transparent', cursor: 'pointer', padding: '0 1px', fontSize: 11, color: 'inherit' };
|
|
3714
|
+
rows.push(h('div', {
|
|
3715
|
+
key: `g-${g.id}`,
|
|
3716
|
+
style: { display: 'flex', alignItems: 'center', gap: 4, padding: '3px 4px', fontSize: 10.5, fontWeight: 700, color: 'var(--dsw-alias-label-tertiary, inherit)', borderTop: '1px solid var(--dsw-alias-border-l1, rgba(127,127,127,0.15))', marginTop: 2 },
|
|
3717
|
+
// 层拖到组头 = 移进这一组
|
|
3718
|
+
onDragOver: (e) => { e.preventDefault(); },
|
|
3719
|
+
onDrop: (e) => {
|
|
3720
|
+
e.preventDefault();
|
|
3721
|
+
const id = e.dataTransfer.getData('text/layer');
|
|
3722
|
+
if (id) onOp('group.moveLayer', { layer: id, groupId: g.id });
|
|
3510
3723
|
},
|
|
3511
|
-
},
|
|
3512
|
-
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
|
|
3519
|
-
|
|
3520
|
-
whiteSpace: 'nowrap',
|
|
3724
|
+
},
|
|
3725
|
+
h('button', { type: 'button', style: gBtn, onClick: () => setCollapsedGroups((prev) => ({ ...prev, [g.id]: !collapsed })) }, collapsed ? '▸' : '▾'),
|
|
3726
|
+
h('button', {
|
|
3727
|
+
type: 'button',
|
|
3728
|
+
title: t('layerVisibility'),
|
|
3729
|
+
style: gBtn,
|
|
3730
|
+
onClick: (e) => {
|
|
3731
|
+
e.stopPropagation();
|
|
3732
|
+
onOp('layer.group', { groupId: g.id, visible: !g.visible });
|
|
3521
3733
|
},
|
|
3522
|
-
},
|
|
3523
|
-
h('
|
|
3524
|
-
style: {
|
|
3525
|
-
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
|
|
3734
|
+
}, g.visible ? '◉' : '○'),
|
|
3735
|
+
h('span', {
|
|
3736
|
+
style: { flex: '1 1 auto', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', opacity: g.opacity < 1 ? 0.7 : 1 },
|
|
3737
|
+
}, `${g.name} · ${items.length}${g.opacity < 1 ? ` · ${Math.round(g.opacity * 100)}%` : ''}`),
|
|
3738
|
+
h('button', {
|
|
3739
|
+
type: 'button',
|
|
3740
|
+
style: gBtn,
|
|
3741
|
+
title: '组设置',
|
|
3742
|
+
onClick: (e) => {
|
|
3743
|
+
e.stopPropagation();
|
|
3744
|
+
setOpenGroup(isOpen ? null : g.id);
|
|
3531
3745
|
},
|
|
3746
|
+
}, '⋯'),
|
|
3747
|
+
));
|
|
3748
|
+
if (isOpen) {
|
|
3749
|
+
rows.push(h('div', {
|
|
3750
|
+
key: `gs-${g.id}`,
|
|
3751
|
+
style: { display: 'flex', flexDirection: 'column', gap: 4, padding: '4px 4px 6px 16px', background: 'var(--dsw-alias-bg-layer-3, rgba(127,127,127,0.06))', borderRadius: 6, marginBottom: 2 },
|
|
3532
3752
|
},
|
|
3533
|
-
h('
|
|
3534
|
-
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
|
|
3538
|
-
|
|
3539
|
-
|
|
3753
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: 5, fontSize: 10 } },
|
|
3754
|
+
h('span', { style: { color: 'var(--dsw-alias-label-tertiary, inherit)' } }, '组'),
|
|
3755
|
+
h('input', {
|
|
3756
|
+
type: 'range',
|
|
3757
|
+
min: 0,
|
|
3758
|
+
max: 1,
|
|
3759
|
+
step: 0.05,
|
|
3760
|
+
value: g.opacity,
|
|
3761
|
+
onChange: (e) => onOp('layer.group', { groupId: g.id, opacity: Number(e.target.value) }),
|
|
3762
|
+
style: { flex: '1 1 auto', minWidth: 0, accentColor: 'var(--dsw-alias-brand-primary, #4c8bf5)', height: 12 },
|
|
3763
|
+
}),
|
|
3764
|
+
h('span', { style: { minWidth: 28, textAlign: 'right', fontVariantNumeric: 'tabular-nums' } }, `${Math.round(g.opacity * 100)}%`),
|
|
3765
|
+
),
|
|
3766
|
+
h('div', { style: { display: 'flex', gap: 4 } },
|
|
3767
|
+
h('button', {
|
|
3768
|
+
type: 'button',
|
|
3769
|
+
style: { ...pill, flex: '1 1 auto', padding: '2px 6px', fontSize: 10 },
|
|
3770
|
+
onClick: () => {
|
|
3771
|
+
const name = window.prompt('组名', g.name);
|
|
3772
|
+
if (name && name.trim()) onOp('layer.group', { groupId: g.id, name: name.trim() });
|
|
3773
|
+
},
|
|
3774
|
+
}, '改名'),
|
|
3775
|
+
h('button', {
|
|
3776
|
+
type: 'button',
|
|
3777
|
+
style: { ...pill, flex: '1 1 auto', padding: '2px 6px', fontSize: 10 },
|
|
3778
|
+
onClick: () => onOp('group.move', { groupId: g.id, offset: 1 }),
|
|
3779
|
+
}, '上移'),
|
|
3780
|
+
h('button', {
|
|
3781
|
+
type: 'button',
|
|
3782
|
+
style: { ...pill, flex: '1 1 auto', padding: '2px 6px', fontSize: 10 },
|
|
3783
|
+
onClick: () => onOp('group.move', { groupId: g.id, offset: -1 }),
|
|
3784
|
+
}, '下移'),
|
|
3785
|
+
h('button', {
|
|
3786
|
+
type: 'button',
|
|
3787
|
+
title: g.kind === 'custom' ? '删组(层并到相邻组)' : '骨架组不能删',
|
|
3788
|
+
disabled: g.kind !== 'custom',
|
|
3789
|
+
style: { ...pill, flex: '0 0 auto', padding: '2px 6px', fontSize: 10, opacity: g.kind !== 'custom' ? 0.4 : 1 },
|
|
3790
|
+
onClick: () => onOp('group.remove', { groupId: g.id, force: true }),
|
|
3791
|
+
}, '删组'),
|
|
3792
|
+
),
|
|
3793
|
+
));
|
|
3794
|
+
}
|
|
3795
|
+
if (!collapsed) rows.push(...items.slice().reverse().map(layerRow));
|
|
3796
|
+
}
|
|
3797
|
+
const rest = meta.layers.filter((l) => !groupIds.has(l.groupId || 'g_color')).slice().reverse();
|
|
3798
|
+
rows.push(...rest.map(layerRow));
|
|
3799
|
+
return rows;
|
|
3800
|
+
})(),
|
|
3540
3801
|
),
|
|
3541
3802
|
activeLayer
|
|
3542
3803
|
? h('div', {
|
|
@@ -3584,13 +3845,92 @@ window.__ModuleLoader__.load({
|
|
|
3584
3845
|
},
|
|
3585
3846
|
h('option', { value: 'normal' }, t('blendNormal')),
|
|
3586
3847
|
h('option', { value: 'multiply' }, t('blendMultiply')),
|
|
3848
|
+
h('option', { value: 'screen' }, t('blendScreen')),
|
|
3849
|
+
h('option', { value: 'overlay' }, t('blendOverlay')),
|
|
3850
|
+
h('option', { value: 'soft-light' }, t('blendSoftLight')),
|
|
3851
|
+
h('option', { value: 'linear-dodge' }, t('blendLinearDodge')),
|
|
3852
|
+
),
|
|
3853
|
+
h('div', { style: { display: 'flex', gap: 6, alignItems: 'center', fontSize: 11 } },
|
|
3854
|
+
h('label', { style: { display: 'flex', gap: 3, alignItems: 'center' }, title: t('lockAlphaHint') },
|
|
3855
|
+
h('input', {
|
|
3856
|
+
type: 'checkbox',
|
|
3857
|
+
checked: activeLayer.lockAlpha === true,
|
|
3858
|
+
onChange: (e) => onOp('layer.set', { id: activeLayer.id, patch: { lockAlpha: e.target.checked } }),
|
|
3859
|
+
}),
|
|
3860
|
+
'α•',
|
|
3861
|
+
),
|
|
3862
|
+
h('span', { style: { color: 'var(--dsw-alias-label-tertiary, inherit)' } }, 'hue'),
|
|
3863
|
+
h('input', {
|
|
3864
|
+
type: 'number',
|
|
3865
|
+
min: -180,
|
|
3866
|
+
max: 180,
|
|
3867
|
+
step: 10,
|
|
3868
|
+
value: activeLayer.hue || 0,
|
|
3869
|
+
onChange: (e) => onOp('layer.set', { id: activeLayer.id, patch: { hue: Number(e.target.value) } }),
|
|
3870
|
+
style: { width: 54, boxSizing: 'border-box', borderRadius: 5, border: '1px solid var(--dsw-alias-border-l1, rgba(127,127,127,0.3))', background: 'transparent', color: 'inherit', padding: '1px 3px', font: 'inherit' },
|
|
3871
|
+
}),
|
|
3872
|
+
),
|
|
3873
|
+
h('select', {
|
|
3874
|
+
value: activeLayer.clipTo || '',
|
|
3875
|
+
onChange: (e) => onOp('layer.set', { id: activeLayer.id, patch: { clipTo: e.target.value || null } }),
|
|
3876
|
+
style: { width: '100%', boxSizing: 'border-box', borderRadius: 7, border: '1px solid var(--dsw-alias-border-l1, rgba(127,127,127,0.3))', background: 'var(--dsw-alias-bg-layer-3, rgba(127,127,127,0.1))', color: 'var(--dsw-alias-label-primary, inherit)', padding: '3px 6px', font: 'inherit' },
|
|
3877
|
+
},
|
|
3878
|
+
h('option', { value: '' }, 'clip:无'),
|
|
3879
|
+
h('option', { value: 'role:base' }, 'clip → 固有色(全部部件)'),
|
|
3880
|
+
h('option', { value: 'role:highlight' }, 'clip → 高光'),
|
|
3881
|
+
h('option', { value: 'role:line' }, 'clip → 精线稿'),
|
|
3882
|
+
...meta.layers.filter((l) => l.id !== activeLayer.id).map((l) => h('option', { key: l.id, value: l.id }, `clip → ${l.name}`)),
|
|
3587
3883
|
),
|
|
3884
|
+
activeLayer.role === 'grade'
|
|
3885
|
+
? h('div', { style: { display: 'flex', gap: 4, fontSize: 10 } },
|
|
3886
|
+
...[['brightness', -1, 1, 0.05], ['contrast', 0, 3, 0.05], ['saturation', 0, 3, 0.05], ['hue', -180, 180, 5]].map(([key, min, max, step]) => h('label', { key, style: { flex: '1 1 0', display: 'flex', flexDirection: 'column', gap: 1, color: 'var(--dsw-alias-label-tertiary, inherit)' } },
|
|
3887
|
+
key,
|
|
3888
|
+
h('input', {
|
|
3889
|
+
type: 'number',
|
|
3890
|
+
min,
|
|
3891
|
+
max,
|
|
3892
|
+
step,
|
|
3893
|
+
value: (activeLayer.grade && activeLayer.grade[key]) ?? (key === 'brightness' ? 0 : (key === 'hue' ? 0 : 1)),
|
|
3894
|
+
onChange: (e) => onOp('layer.set', { id: activeLayer.id, patch: { grade: { ...(activeLayer.grade || { brightness: 0, contrast: 1, saturation: 1, hue: 0 }), [key]: Number(e.target.value) } } }),
|
|
3895
|
+
style: { width: '100%', boxSizing: 'border-box', font: 'inherit', padding: '1px 2px', borderRadius: 4, border: '1px solid var(--dsw-alias-border-l1, rgba(127,127,127,0.3))', background: 'transparent', color: 'inherit' },
|
|
3896
|
+
}),
|
|
3897
|
+
)),
|
|
3898
|
+
)
|
|
3899
|
+
: null,
|
|
3900
|
+
h('button', {
|
|
3901
|
+
type: 'button',
|
|
3902
|
+
style: { ...pill, padding: '4px 8px' },
|
|
3903
|
+
onClick: async () => {
|
|
3904
|
+
try {
|
|
3905
|
+
const res = await fetch(`${API}/check`);
|
|
3906
|
+
setCheckReport(await res.json());
|
|
3907
|
+
} catch {
|
|
3908
|
+
setCheckReport({ ok: false, error: '自检失败' });
|
|
3909
|
+
}
|
|
3910
|
+
},
|
|
3911
|
+
}, '自检'),
|
|
3912
|
+
checkReport
|
|
3913
|
+
? h('div', { style: { fontSize: 10, lineHeight: 1.45, color: 'var(--dsw-alias-label-tertiary, inherit)', maxHeight: 96, overflowY: 'auto' } },
|
|
3914
|
+
checkReport.ok
|
|
3915
|
+
? [h('div', { key: 'b' }, `06 固有色覆盖 ${checkReport.baseCoveragePct}%`), ...((checkReport.warnings || []).length ? checkReport.warnings.map((w, i) => h('div', { key: `w${i}`, style: { color: '#d97706' } }, w)) : [h('div', { key: 'ok' }, '没有层超载,可以继续')])]
|
|
3916
|
+
: (checkReport.error || '自检失败'),
|
|
3917
|
+
)
|
|
3918
|
+
: null,
|
|
3588
3919
|
h('div', { style: { display: 'flex', gap: 6 } },
|
|
3589
3920
|
h('button', {
|
|
3590
3921
|
type: 'button',
|
|
3591
3922
|
style: { ...pill, flex: '1 1 auto', padding: '4px 8px' },
|
|
3592
3923
|
onClick: () => onOp('layer.add', { name: null }),
|
|
3593
3924
|
}, `+ ${t('layerAdd')}`),
|
|
3925
|
+
h('button', {
|
|
3926
|
+
type: 'button',
|
|
3927
|
+
title: '新建一个自定义图层组',
|
|
3928
|
+
style: { ...pill, padding: '4px 8px' },
|
|
3929
|
+
onClick: () => {
|
|
3930
|
+
const name = window.prompt('新组名', '图层组');
|
|
3931
|
+
if (name && name.trim()) onOp('group.add', { name: name.trim() });
|
|
3932
|
+
},
|
|
3933
|
+
}, '+ 组'),
|
|
3594
3934
|
meta.layers.length > 1
|
|
3595
3935
|
? h('button', {
|
|
3596
3936
|
type: 'button',
|