limaodada commited on
Commit
7bbe85d
·
verified ·
1 Parent(s): 6a5bf2b

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +120 -135
index.html CHANGED
@@ -2,105 +2,93 @@
2
  <html lang="zh-CN">
3
  <head>
4
  <meta charset="UTF-8">
5
- <title>BeadMaster Pro v6.0 - 高精重制版</title>
6
  <style>
7
- :root { --bg: #1e1e20; --panel: #2b2b2e; --accent: #6366f1; --text: #e0e0e0; --border: #3f3f46; --ruler-bg: #252526; --list-hover: #3e3e42; }
8
  body { margin: 0; overflow: hidden; background: var(--bg); color: var(--text); font-family: 'Segoe UI', Roboto, sans-serif; user-select: none; }
9
 
10
- /* 布局框架 */
11
  #app { display: flex; width: 100vw; height: 100vh; }
12
  .sidebar { width: 64px; background: var(--panel); border-right: 1px solid var(--border); display: flex; flex-direction: column; align-items: center; padding-top: 15px; gap: 10px; z-index: 50; }
13
  .panels { width: 300px; background: var(--panel); border-left: 1px solid var(--border); display: flex; flex-direction: column; z-index: 50; }
14
- #canvas-wrapper { flex: 1; position: relative; overflow: hidden; background: #121214; display: flex; flex-direction: column; }
15
 
16
- /* 标尺与画布 */
17
- #ruler-top-bar { height: 30px; background: var(--ruler-bg); border-bottom: 1px solid var(--border); display: flex; z-index: 40; }
18
- #corner-box { width: 30px; height: 30px; background: var(--ruler-bg); border-right: 1px solid var(--border); color: #666; font-size: 10px; display: flex; justify-content: center; align-items: center; flex-shrink: 0; }
19
  #ruler-top { flex: 1; position: relative; overflow: hidden; }
20
  #main-area { flex: 1; display: flex; position: relative; overflow: hidden; }
21
- #ruler-left { width: 30px; background: var(--ruler-bg); border-right: 1px solid var(--border); position: relative; overflow: hidden; z-index: 40; flex-shrink: 0; }
22
  #viewport { flex: 1; position: relative; overflow: hidden; cursor: crosshair; z-index: 10; }
23
  canvas { display: block; }
24
 
25
  /* 顶部栏 */
26
- .topbar { height: 48px; background: var(--panel); border-bottom: 1px solid var(--border); display: flex; align-items: center; padding: 0 15px; gap: 12px; z-index: 45; }
27
 
28
- /* 控件样式 */
29
- .tool-btn { width: 40px; height: 40px; border-radius: 6px; border: none; background: transparent; color: #aaa; cursor: pointer; font-size: 20px; transition: 0.2s; display:flex; justify-content:center; align-items:center; }
30
- .tool-btn:hover { background: #3e3e42; color: white; }
31
- .tool-btn.active { background: var(--accent); color: white; box-shadow: 0 2px 8px rgba(99,102,241,0.4); }
32
 
33
- .action-btn { padding: 6px 12px; background: #3e3e42; border: 1px solid var(--border); color: white; border-radius: 4px; cursor: pointer; font-size: 12px; display: flex; align-items: center; gap: 5px; white-space: nowrap; }
34
- .action-btn:hover { background: #4e4e52; }
35
- .primary { background: var(--accent); border-color: var(--accent); }
 
 
 
36
 
37
- input[type="number"] { background: #18181b; border: 1px solid #3f3f46; color: white; width: 45px; padding: 4px; border-radius: 4px; text-align: center; font-size: 12px; }
38
- select { background: #18181b; border: 1px solid #3f3f46; color: white; padding: 4px; border-radius: 4px; outline: none; font-size: 12px; }
39
 
40
- /* 缩放滑块 */
41
- input[type=range] { width: 80px; accent-color: var(--accent); }
42
-
43
- /* 标签文字 */
44
- .label { font-size: 11px; color: #888; }
45
 
46
  /* 右侧面板 */
47
- .panel-header { padding: 12px; border-bottom: 1px solid var(--border); font-weight: bold; font-size: 13px; display: flex; justify-content: space-between; align-items: center; }
48
  #material-list { flex: 1; overflow-y: auto; padding: 5px 0; }
49
- .material-item { display: flex; align-items: center; padding: 6px 12px; gap: 8px; border-bottom: 1px solid #333; font-size: 12px; cursor: pointer; }
50
- .material-item:hover { background: var(--list-hover); }
51
- .material-item.active { background: #3e3e42; border-left: 3px solid var(--accent); }
52
- .list-swatch { width: 20px; height: 20px; border-radius: 3px; border: 1px solid rgba(255,255,255,0.2); flex-shrink: 0; }
53
  .list-info { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
54
- .list-count { font-family: monospace; font-weight: bold; color: var(--accent); }
55
- #total-stats { padding: 12px; border-top: 1px solid var(--border); background: #18181b; font-size: 12px; display: flex; justify-content: space-between; font-weight: bold; }
56
 
57
  /* 裁剪弹窗 */
58
- .modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.85); z-index: 100; display: none; justify-content: center; align-items: center; }
59
- .modal-content { background: var(--panel); padding: 20px; border-radius: 8px; width: 80vw; height: 80vh; display: flex; flex-direction: column; gap: 10px; border: 1px solid var(--border); }
60
- #crop-container { flex: 1; background: #000; position: relative; overflow: hidden; display: flex; justify-content: center; align-items: center; border: 1px solid #333; }
61
- #crop-img { max-width: 100%; max-height: 100%; display: block; box-shadow: 0 0 20px rgba(0,0,0,0.5); }
62
- #crop-box { position: absolute; border: 2px dashed #fff; box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5); cursor: move; display: none; }
63
- .resize-handle { position: absolute; right: -6px; bottom: -6px; width: 12px; height: 12px; background: var(--accent); cursor: nwse-resize; border: 1px solid white; }
64
 
65
- /* 弹窗底部控制栏 */
66
- .modal-footer { display:flex; justify-content:space-between; color:white; align-items: center; background: #2b2b2e; padding: 10px; border-radius: 6px; }
67
- .control-group { display: flex; gap: 15px; align-items: center; }
68
- .input-group { display: flex; flex-direction: column; gap: 2px; }
69
- .input-label { font-size: 11px; color: #aaa; }
70
- .input-field { background: #18181b; border: 1px solid #555; color: white; padding: 4px 8px; border-radius: 4px; width: 60px; text-align: center; }
71
  </style>
72
  </head>
73
  <body>
74
 
75
  <div class="modal-overlay" id="cropModal">
76
  <div class="modal-content">
77
- <h3 style="margin:0; color: white;">✂️ 图片导入与采样设置</h3>
78
-
79
  <div id="crop-container" onmousedown="startCropDrag(event)">
80
  <img id="crop-img">
81
  <div id="crop-box">
82
  <div class="resize-handle" onmousedown="startCropResize(event)"></div>
83
  </div>
84
  </div>
85
-
86
  <div class="modal-footer">
87
- <div class="control-group">
88
- <div class="input-group">
89
- <span class="input-label">生成宽度 (珠子数)</span>
90
- <input type="number" id="targetWidthInput" class="input-field" value="50" min="10" max="200" title="数值越大,细节越清晰,豆子越多">
91
- </div>
92
- <div class="input-group">
93
- <span class="input-label">色彩处理</span>
94
- <label style="font-size:13px; cursor:pointer; display:flex; align-items:center; gap:5px; margin-top:5px;">
95
- <input type="checkbox" id="ditherCheck" checked>
96
- <span>开启融合 (Dithering)</span>
97
- </label>
98
- </div>
99
  </div>
100
-
101
- <div class="control-group">
102
- <div style="font-size:12px; color:#aaa; max-width: 200px;">💡 提示: 觉得转换后太粗?请调大"生成宽度"。拖拽白框选择区域。</div>
103
- <button class="action-btn primary" onclick="confirmCrop()" style="padding: 8px 20px; font-size: 14px;">✅ 开始转换</button>
104
  <button class="action-btn" onclick="closeModal()">取消</button>
105
  </div>
106
  </div>
@@ -109,9 +97,9 @@
109
 
110
  <div id="app">
111
  <div class="sidebar">
112
- <div style="height: 48px; display: flex; align-items: center; font-weight: bold; color: var(--accent);">BMP</div>
113
  <button class="tool-btn active" id="t-pencil" onclick="setTool('pencil')" title="画笔 (P)">✏️</button>
114
- <button class="tool-btn" id="t-eraser" onclick="setTool('eraser')" title="橡皮 (E)">🧹</button>
115
  <button class="tool-btn" id="t-bucket" onclick="setTool('bucket')" title="油漆桶 (G)">🪣</button>
116
  <button class="tool-btn" id="t-picker" onclick="setTool('picker')" title="吸管 (I)">🧪</button>
117
  <button class="tool-btn" id="t-move" onclick="setTool('move')" title="抓手 (Space)">✋</button>
@@ -119,45 +107,52 @@
119
 
120
  <div style="flex:1; display: flex; flex-direction: column;">
121
  <div class="topbar">
122
- <label class="action-btn primary">
123
- 📁 导入
124
  <input type="file" id="fileInput" accept="image/*" style="display:none" onchange="handleFile(this)">
125
  </label>
126
 
127
- <div style="width:1px; height:20px; background:var(--border);"></div>
128
 
129
- <div>
130
- <div class="label">打印规格</div>
131
- <select id="beadSizeSelect">
132
- <option value="5">5mm (标准豆)</option>
133
- <option value="2.6">2.6mm (迷你豆)</option>
134
- </select>
135
  </div>
136
 
137
- <div>
138
- <div class="label">画布尺寸 (珠)</div>
139
- <div style="display:flex; align-items:center; gap:2px;">
140
- <input type="number" id="gridW" value="50" onchange="resizeGrid()">
141
- <span style="font-size:10px; color:#666">x</span>
142
- <input type="number" id="gridH" value="50" onchange="resizeGrid()">
 
 
143
  </div>
144
  </div>
145
 
146
- <div style="width:1px; height:20px; background:var(--border);"></div>
147
 
148
- <div>
149
- <div class="label">视图缩放</div>
150
- <input type="range" id="zoomSlider" min="5" max="100" value="25" oninput="handleZoomSlider(this.value)">
 
 
 
 
 
 
 
 
151
  </div>
152
 
153
  <div style="flex:1;"></div>
154
 
155
  <select id="shapeSelect" onchange="draw()">
156
- <option value="circle">🔵 圆形</option>
157
- <option value="square">⬛ 方块</option>
158
  </select>
159
 
160
- <button class="action-btn" onclick="exportImageWithRuler()">💾 导出带标尺图纸</button>
161
  <button class="action-btn" onclick="clearCanvas()">🗑️</button>
162
  </div>
163
 
@@ -178,11 +173,11 @@
178
  <div class="panels">
179
  <div class="panel-header">
180
  <span>📦 材料清单</span>
181
- <button class="action-btn" style="padding: 2px 6px;" onclick="copyList()">复制</button>
182
  </div>
183
  <div id="material-list"></div>
184
  <div id="total-stats">
185
- <span>总计:</span>
186
  <span id="total-beads-count">0</span>
187
  </div>
188
  <div style="padding:10px; font-size:11px; color:#666; border-top:1px solid var(--border); background: #18181b;">
@@ -195,22 +190,22 @@
195
  <script>
196
  // --- 数据 ---
197
  const PALETTE = [
198
- {id:'A01', hex:'#111111', name:'夜黑'}, {id:'A02', hex:'#FFFFFF', name:'纯白'},
199
- {id:'B01', hex:'#FF0000', name:'正红'}, {id:'B02', hex:'#FF6B6B', name:'西瓜红'},
200
- {id:'C01', hex:'#00FF00', name:'鲜绿'}, {id:'C02', hex:'#2ECC71', name:'草绿'},
201
- {id:'D01', hex:'#0000FF', name:'深蓝'}, {id:'D02', hex:'#3498DB', name:'天蓝'},
202
- {id:'E01', hex:'#FFFF00', name:'柠檬黄'}, {id:'E02', hex:'#F1C40F', name:'金黄'},
203
- {id:'F01', hex:'#FFA500', name:'亮橙'}, {id:'F02', hex:'#E67E22', name:'焦糖'},
204
- {id:'G01', hex:'#9B59B6', name:'紫罗兰'}, {id:'G02', hex:'#8E44AD', name:'深紫'},
205
- {id:'H01', hex:'#FFC0CB', name:'浅粉'}, {id:'H02', hex:'#FF69B4', name:'热粉'},
206
- {id:'J01', hex:'#95A5A6', name:'水泥灰'}, {id:'J02', hex:'#7F8C8D', name:'深灰'},
207
- {id:'K01', hex:'#A52A2A', name:'红棕'}, {id:'K02', hex:'#D35400', name:'南瓜'},
208
- {id:'L01', hex:'#F0E68C', name:'卡其'}, {id:'L02', hex:'#E6E6FA', name:'薰衣草'},
209
- {id:'M01', hex:'#40E0D0', name:'绿松石'},{id:'M02', hex:'#FFD700', name:'金色'}
210
  ];
211
 
212
  const state = {
213
- gridW: 50, gridH: 50,
214
  pixels: {},
215
  scale: 25,
216
  offsetX: 50, offsetY: 50,
@@ -232,7 +227,6 @@ const materialListEl = document.getElementById('material-list');
232
  const totalBeadsEl = document.getElementById('total-beads-count');
233
  const zoomSlider = document.getElementById('zoomSlider');
234
 
235
- // --- 初始化 ---
236
  function init() {
237
  window.addEventListener('resize', resizeAll);
238
  resizeAll();
@@ -252,7 +246,7 @@ function handleZoomSlider(val) {
252
 
253
  function applyZoom(newScale, cx, cy) {
254
  const oldScale = state.scale;
255
- state.scale = Math.max(5, Math.min(100, newScale));
256
  zoomSlider.value = state.scale;
257
  const rect = viewport.getBoundingClientRect();
258
  const mx = cx - rect.left;
@@ -289,10 +283,7 @@ function updateMaterialList() {
289
  });
290
  }
291
 
292
- function selectColor(idx) {
293
- state.curColorIdx = idx; updateMaterialList(); setTool('pencil');
294
- }
295
-
296
  function copyList() {
297
  let text = "--- 拼豆材料清单 ---\n";
298
  const counts = {};
@@ -305,8 +296,8 @@ function copyList() {
305
  function resizeAll() {
306
  const vw = viewport.clientWidth; const vh = viewport.clientHeight;
307
  cvs.width = vw; cvs.height = vh;
308
- rulerTop.width = vw; rulerTop.height = 30;
309
- rulerLeft.width = 30; rulerLeft.height = vh;
310
  draw();
311
  }
312
 
@@ -314,17 +305,17 @@ function draw() {
314
  state.shape = document.getElementById('shapeSelect').value;
315
  const s = state.scale; const ox = state.offsetX; const oy = state.offsetY;
316
 
317
- ctx.fillStyle = '#121214'; ctx.fillRect(0, 0, cvs.width, cvs.height);
318
  ctx.save(); ctx.translate(ox, oy);
319
 
320
- // 网格
321
- ctx.beginPath(); ctx.lineWidth = 1; ctx.strokeStyle = '#2a2a2d';
322
  for(let i=0; i<=state.gridW; i++) { ctx.moveTo(i*s, 0); ctx.lineTo(i*s, state.gridH*s); }
323
  for(let i=0; i<=state.gridH; i++) { ctx.moveTo(0, i*s); ctx.lineTo(state.gridW*s, i*s); }
324
  ctx.stroke();
325
 
326
  // 豆子
327
- const showId = s > 20;
328
  for(let key in state.pixels) {
329
  const [x, y] = key.split(',').map(Number);
330
  const p = PALETTE[state.pixels[key]];
@@ -342,8 +333,8 @@ function draw() {
342
  }
343
  }
344
 
345
- // 粗线
346
- ctx.beginPath(); ctx.lineWidth = 2; ctx.strokeStyle = '#555';
347
  for(let i=0; i<=state.gridW; i+=10) { ctx.moveTo(i*s, 0); ctx.lineTo(i*s, state.gridH*s); }
348
  for(let i=0; i<=state.gridH; i+=10) { ctx.moveTo(0, i*s); ctx.lineTo(state.gridW*s, i*s); }
349
  ctx.stroke();
@@ -356,24 +347,24 @@ function draw() {
356
 
357
  function drawRulers() {
358
  const s = state.scale; const ox = state.offsetX; const oy = state.offsetY;
359
- const ctxT = ctxRTop; ctxT.clearRect(0,0,rulerTop.width,30);
360
- ctxT.fillStyle = '#999'; ctxT.font = '10px Arial'; ctxT.textAlign = 'center'; ctxT.beginPath(); ctxT.strokeStyle = '#555';
361
  const startX = Math.max(0, Math.floor(-ox / s)); const endX = Math.min(state.gridW, Math.ceil((cvs.width - ox) / s));
362
  for(let i=startX; i<=endX; i++) {
363
  const sx = ox + i * s;
364
- if(i % 10 === 0) { ctxT.moveTo(sx, 15); ctxT.lineTo(sx, 30); ctxT.fillText(i, sx, 12); }
365
- else if (i % 5 === 0 && s>10) { ctxT.moveTo(sx, 22); ctxT.lineTo(sx, 30); }
366
  }
367
  ctxT.stroke();
368
- const ctxL = ctxRLeft; ctxL.clearRect(0,0,30,rulerLeft.height);
369
- ctxL.fillStyle = '#999'; ctxL.font = '10px Arial'; ctxL.textAlign = 'center'; ctxL.textBaseline = 'middle'; ctxL.beginPath(); ctxL.strokeStyle = '#555';
370
  const startY = Math.max(0, Math.floor(-oy / s)); const endY = Math.min(state.gridH, Math.ceil((cvs.height - oy) / s));
371
  for(let i=startY; i<=endY; i++) {
372
  const sy = oy + i * s;
373
  if(i % 10 === 0) {
374
- ctxL.moveTo(15, sy); ctxL.lineTo(30, sy);
375
  ctxL.save(); ctxL.translate(12, sy); ctxL.rotate(-Math.PI/2); ctxL.fillText(i, 0, 0); ctxL.restore();
376
- } else if (i % 5 === 0 && s>10) { ctxL.moveTo(22, sy); ctxL.lineTo(30, sy); }
377
  }
378
  ctxL.stroke();
379
  }
@@ -414,12 +405,12 @@ function resizeGrid() { state.gridW = parseInt(document.getElementById('gridW').
414
  function updateInfo(e) { document.getElementById('info-zoom').innerText = `Zoom: ${state.scale}px`; if(e) { const rect = viewport.getBoundingClientRect(); const x = Math.floor((e.clientX - rect.left - state.offsetX) / state.scale); const y = Math.floor((e.clientY - rect.top - state.offsetY) / state.scale); if(x>=0 && x<state.gridW && y>=0 && y<state.gridH) document.getElementById('info-coord').innerText = `XY: (${x}, ${y})`; } }
415
  function clearCanvas() { if(confirm('确定清空画布吗?')) { state.pixels={}; draw(); } }
416
 
417
- // --- V6.0 核心修复:导出带标尺 ---
418
  function exportImageWithRuler() {
419
  const beadSizeMM = parseFloat(document.getElementById('beadSizeSelect').value);
420
  const pxPerMM = 11.8; // 300 DPI
421
  const unit = Math.round(beadSizeMM * pxPerMM);
422
- const margin = unit * 2; // 留出边缘画标尺
423
 
424
  const expCvs = document.createElement('canvas');
425
  expCvs.width = state.gridW * unit + margin;
@@ -430,7 +421,7 @@ function exportImageWithRuler() {
430
  eCtx.fillStyle = 'white'; eCtx.fillRect(0, 0, expCvs.width, expCvs.height);
431
 
432
  // 绘制标尺文字
433
- eCtx.fillStyle = '#000'; eCtx.font = `${unit*0.5}px Arial`; eCtx.textAlign = 'center'; eCtx.textBaseline = 'middle';
434
 
435
  // 顶标尺
436
  for(let i=0; i<=state.gridW; i++) {
@@ -449,7 +440,6 @@ function exportImageWithRuler() {
449
  }
450
  }
451
 
452
- // 偏移绘图区域
453
  eCtx.translate(margin, margin);
454
 
455
  // 绘制豆子
@@ -463,25 +453,23 @@ function exportImageWithRuler() {
463
  eCtx.fillStyle = '#fff'; eCtx.beginPath(); eCtx.arc(x*unit + unit/2, y*unit + unit/2, unit*0.15, 0, Math.PI*2); eCtx.fill();
464
  } else { eCtx.fillRect(x*unit, y*unit, unit, unit); }
465
 
466
- // 文字
467
  eCtx.fillStyle = getContrastColor(p.hex) === '#fff' ? '#fff' : '#000';
468
  eCtx.font = `bold ${unit*0.35}px Arial`; eCtx.textAlign = 'center'; eCtx.textBaseline = 'middle';
469
  eCtx.fillText(p.id, x*unit + unit/2, y*unit + unit/2);
470
  }
471
 
472
- // 网格线
473
  eCtx.strokeStyle = '#ccc'; eCtx.lineWidth = 2;
474
  for(let i=0; i<=state.gridW; i++) { eCtx.moveTo(i*unit, 0); eCtx.lineTo(i*unit, state.gridH*unit); }
475
  for(let i=0; i<=state.gridH; i++) { eCtx.moveTo(0, i*unit); eCtx.lineTo(state.gridW*unit, i*unit); }
476
  eCtx.stroke();
477
 
478
  const link = document.createElement('a');
479
- link.download = `拼豆图纸_${beadSizeMM}mm_带标尺.png`;
480
  link.href = expCvs.toDataURL();
481
  link.click();
482
  }
483
 
484
- // --- 裁剪与导入逻辑 (V6.0 支持自定义精度) ---
485
  const modal = document.getElementById('cropModal');
486
  const cropImg = document.getElementById('crop-img');
487
  const cropBox = document.getElementById('crop-box');
@@ -497,8 +485,6 @@ function handleFile(input) {
497
  cropBox.style.display = 'block';
498
  cropBox.style.left = '50px'; cropBox.style.top = '50px';
499
  cropBox.style.width = '100px'; cropBox.style.height = '100px';
500
- // 重置输入建议
501
- document.getElementById('targetWidthInput').value = 50;
502
  }
503
  };
504
  reader.readAsDataURL(input.files[0]);
@@ -526,11 +512,10 @@ function confirmCrop() {
526
  const cw = cropBox.offsetWidth * factor;
527
  const ch = cropBox.offsetHeight * factor;
528
 
529
- // V6.0 核心逻辑:使用用户输入的生成宽度
530
- const targetW = parseInt(document.getElementById('targetWidthInput').value) || 50;
531
  const targetH = Math.floor(targetW * (ch / cw));
532
 
533
- // 更新全局画布尺寸
534
  document.getElementById('gridW').value = targetW;
535
  document.getElementById('gridH').value = targetH;
536
  state.gridW = targetW; state.gridH = targetH;
 
2
  <html lang="zh-CN">
3
  <head>
4
  <meta charset="UTF-8">
5
+ <title>BeadMaster Pro v7.0 - 精度控制版</title>
6
  <style>
7
+ :root { --bg: #18181b; --panel: #27272a; --accent: #6366f1; --success: #22c55e; --text: #f4f4f5; --border: #3f3f46; --ruler-bg: #202022; }
8
  body { margin: 0; overflow: hidden; background: var(--bg); color: var(--text); font-family: 'Segoe UI', Roboto, sans-serif; user-select: none; }
9
 
10
+ /* 布局 */
11
  #app { display: flex; width: 100vw; height: 100vh; }
12
  .sidebar { width: 64px; background: var(--panel); border-right: 1px solid var(--border); display: flex; flex-direction: column; align-items: center; padding-top: 15px; gap: 10px; z-index: 50; }
13
  .panels { width: 300px; background: var(--panel); border-left: 1px solid var(--border); display: flex; flex-direction: column; z-index: 50; }
14
+ #canvas-wrapper { flex: 1; position: relative; overflow: hidden; background: #09090b; display: flex; flex-direction: column; }
15
 
16
+ /* 标尺 */
17
+ #ruler-top-bar { height: 32px; background: var(--ruler-bg); border-bottom: 1px solid var(--border); display: flex; z-index: 40; }
18
+ #corner-box { width: 32px; height: 32px; background: var(--ruler-bg); border-right: 1px solid var(--border); color: #888; font-size: 10px; display: flex; justify-content: center; align-items: center; flex-shrink: 0; }
19
  #ruler-top { flex: 1; position: relative; overflow: hidden; }
20
  #main-area { flex: 1; display: flex; position: relative; overflow: hidden; }
21
+ #ruler-left { width: 32px; background: var(--ruler-bg); border-right: 1px solid var(--border); position: relative; overflow: hidden; z-index: 40; flex-shrink: 0; }
22
  #viewport { flex: 1; position: relative; overflow: hidden; cursor: crosshair; z-index: 10; }
23
  canvas { display: block; }
24
 
25
  /* 顶部栏 */
26
+ .topbar { height: 50px; background: var(--panel); border-bottom: 1px solid var(--border); display: flex; align-items: center; padding: 0 15px; gap: 15px; z-index: 45; }
27
 
28
+ /* 控件 */
29
+ .tool-btn { width: 42px; height: 42px; border-radius: 8px; border: none; background: transparent; color: #a1a1aa; cursor: pointer; font-size: 22px; transition: 0.2s; display:flex; justify-content:center; align-items:center; }
30
+ .tool-btn:hover { background: #3f3f46; color: white; }
31
+ .tool-btn.active { background: var(--accent); color: white; box-shadow: 0 0 10px rgba(99,102,241,0.3); }
32
 
33
+ .action-btn { padding: 8px 16px; background: #3f3f46; border: 1px solid var(--border); color: white; border-radius: 6px; cursor: pointer; font-size: 13px; display: flex; align-items: center; gap: 6px; white-space: nowrap; font-weight: 500; }
34
+ .action-btn:hover { background: #52525b; }
35
+ .btn-green { background: var(--success); border-color: var(--success); } /* 绿色导入按钮 */
36
+ .btn-green:hover { background: #16a34a; }
37
+ .btn-blue { background: var(--accent); border-color: var(--accent); }
38
+ .btn-blue:hover { background: #4f46e5; }
39
 
40
+ .control-group { display: flex; flex-direction: column; gap: 2px; }
41
+ .control-label { font-size: 10px; color: #a1a1aa; text-transform: uppercase; letter-spacing: 0.5px; }
42
 
43
+ input[type="number"] { background: #18181b; border: 1px solid #52525b; color: white; width: 50px; padding: 4px; border-radius: 4px; text-align: center; font-size: 13px; font-weight: bold; }
44
+ select { background: #18181b; border: 1px solid #52525b; color: white; padding: 4px; border-radius: 4px; outline: none; font-size: 12px; }
45
+ input[type=range] { width: 80px; accent-color: var(--accent); cursor: pointer; }
 
 
46
 
47
  /* 右侧面板 */
48
+ .panel-header { padding: 15px; border-bottom: 1px solid var(--border); font-weight: bold; font-size: 14px; display: flex; justify-content: space-between; align-items: center; background: #202022; }
49
  #material-list { flex: 1; overflow-y: auto; padding: 5px 0; }
50
+ .material-item { display: flex; align-items: center; padding: 8px 15px; gap: 10px; border-bottom: 1px solid #333; font-size: 13px; cursor: pointer; transition: 0.2s; }
51
+ .material-item:hover { background: #3f3f46; }
52
+ .material-item.active { background: #312e81; border-left: 3px solid var(--accent); }
53
+ .list-swatch { width: 22px; height: 22px; border-radius: 4px; border: 1px solid rgba(255,255,255,0.2); flex-shrink: 0; }
54
  .list-info { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
55
+ .list-count { font-family: monospace; font-weight: bold; color: var(--accent); font-size: 14px; }
56
+ #total-stats { padding: 15px; border-top: 1px solid var(--border); background: #202022; font-size: 13px; display: flex; justify-content: space-between; font-weight: bold; color: var(--success); }
57
 
58
  /* 裁剪弹窗 */
59
+ .modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.9); z-index: 100; display: none; justify-content: center; align-items: center; backdrop-filter: blur(5px); }
60
+ .modal-content { background: var(--panel); padding: 20px; border-radius: 12px; width: 80vw; height: 85vh; display: flex; flex-direction: column; gap: 15px; border: 1px solid var(--border); box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5); }
61
+ #crop-container { flex: 1; background: #000; position: relative; overflow: hidden; display: flex; justify-content: center; align-items: center; border: 1px solid #3f3f46; border-radius: 4px; }
62
+ #crop-img { max-width: 100%; max-height: 100%; display: block; }
63
+ #crop-box { position: absolute; border: 2px dashed #fff; box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.6); cursor: move; display: none; }
64
+ .resize-handle { position: absolute; right: -8px; bottom: -8px; width: 16px; height: 16px; background: var(--accent); cursor: nwse-resize; border: 2px solid white; border-radius: 50%; }
65
 
66
+ .modal-footer { display:flex; justify-content:space-between; align-items: center; background: #202022; padding: 15px; border-radius: 8px; border: 1px solid var(--border); }
67
+ .checkbox-label { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; user-select: none; }
68
+ .checkbox-label input { width: 16px; height: 16px; accent-color: var(--success); }
 
 
 
69
  </style>
70
  </head>
71
  <body>
72
 
73
  <div class="modal-overlay" id="cropModal">
74
  <div class="modal-content">
75
+ <h3 style="margin:0; color: white;">✂️ 1. 选择区域 (拖拽白框)</h3>
 
76
  <div id="crop-container" onmousedown="startCropDrag(event)">
77
  <img id="crop-img">
78
  <div id="crop-box">
79
  <div class="resize-handle" onmousedown="startCropResize(event)"></div>
80
  </div>
81
  </div>
 
82
  <div class="modal-footer">
83
+ <div style="display: flex; gap: 20px;">
84
+ <label class="checkbox-label">
85
+ <input type="checkbox" id="ditherCheck" checked>
86
+ <span>色彩融合 (让照片更逼真)</span>
87
+ </label>
 
 
 
 
 
 
 
88
  </div>
89
+ <div style="display: flex; gap: 10px; align-items: center;">
90
+ <span style="font-size: 12px; color: #888;">即将使用顶部设定的精度进行转换</span>
91
+ <button class="action-btn btn-green" onclick="confirmCrop()">✅ 确认生成</button>
 
92
  <button class="action-btn" onclick="closeModal()">取消</button>
93
  </div>
94
  </div>
 
97
 
98
  <div id="app">
99
  <div class="sidebar">
100
+ <div style="height: 50px; display: flex; align-items: center; font-weight: 900; color: var(--accent); font-size: 14px;">v7.0</div>
101
  <button class="tool-btn active" id="t-pencil" onclick="setTool('pencil')" title="画笔 (P)">✏️</button>
102
+ <button class="tool-btn" id="t-eraser" onclick="setTool('eraser')" title="橡皮 (E)">🧼</button>
103
  <button class="tool-btn" id="t-bucket" onclick="setTool('bucket')" title="油漆桶 (G)">🪣</button>
104
  <button class="tool-btn" id="t-picker" onclick="setTool('picker')" title="吸管 (I)">🧪</button>
105
  <button class="tool-btn" id="t-move" onclick="setTool('move')" title="抓手 (Space)">✋</button>
 
107
 
108
  <div style="flex:1; display: flex; flex-direction: column;">
109
  <div class="topbar">
110
+ <label class="action-btn btn-green">
111
+ <b>📁 导入图片</b>
112
  <input type="file" id="fileInput" accept="image/*" style="display:none" onchange="handleFile(this)">
113
  </label>
114
 
115
+ <div style="width:1px; height:24px; background:var(--border);"></div>
116
 
117
+ <div class="control-group">
118
+ <div class="control-label" style="color: var(--success);">🎯 采样精度 (总宽)</div>
119
+ <input type="number" id="targetRes" value="60" min="10" max="300" title="觉得粗就调大这个数,觉得太复杂就调小">
 
 
 
120
  </div>
121
 
122
+ <div style="width:1px; height:24px; background:var(--border);"></div>
123
+
124
+ <div class="control-group">
125
+ <div class="control-label">当前画布格数</div>
126
+ <div style="display:flex; align-items:center; gap:4px;">
127
+ <input type="number" id="gridW" value="60" onchange="resizeGrid()" title="横向格数">
128
+ <span style="color:#666">x</span>
129
+ <input type="number" id="gridH" value="60" onchange="resizeGrid()" title="纵向格数">
130
  </div>
131
  </div>
132
 
133
+ <div style="width:1px; height:24px; background:var(--border);"></div>
134
 
135
+ <div class="control-group">
136
+ <div class="control-label">打印规格</div>
137
+ <select id="beadSizeSelect">
138
+ <option value="5">5mm (标准)</option>
139
+ <option value="2.6">2.6mm (迷你)</option>
140
+ </select>
141
+ </div>
142
+
143
+ <div class="control-group">
144
+ <div class="control-label">视图缩放</div>
145
+ <input type="range" id="zoomSlider" min="5" max="150" value="25" oninput="handleZoomSlider(this.value)">
146
  </div>
147
 
148
  <div style="flex:1;"></div>
149
 
150
  <select id="shapeSelect" onchange="draw()">
151
+ <option value="circle">🔵 圆形豆</option>
152
+ <option value="square">⬛ 像素块</option>
153
  </select>
154
 
155
+ <button class="action-btn btn-blue" onclick="exportImageWithRuler()">💾 导出带标尺图纸</button>
156
  <button class="action-btn" onclick="clearCanvas()">🗑️</button>
157
  </div>
158
 
 
173
  <div class="panels">
174
  <div class="panel-header">
175
  <span>📦 材料清单</span>
176
+ <button class="action-btn" style="padding: 2px 8px; font-size: 11px;" onclick="copyList()">复制文字</button>
177
  </div>
178
  <div id="material-list"></div>
179
  <div id="total-stats">
180
+ <span>总颗粒:</span>
181
  <span id="total-beads-count">0</span>
182
  </div>
183
  <div style="padding:10px; font-size:11px; color:#666; border-top:1px solid var(--border); background: #18181b;">
 
190
  <script>
191
  // --- 数据 ---
192
  const PALETTE = [
193
+ {id:'A01', hex:'#0f0f12', name:'夜黑'}, {id:'A02', hex:'#FFFFFF', name:'纯白'},
194
+ {id:'B01', hex:'#e11d48', name:'正红'}, {id:'B02', hex:'#fb7185', name:'西瓜红'},
195
+ {id:'C01', hex:'#16a34a', name:'鲜绿'}, {id:'C02', hex:'#4ade80', name:'草绿'},
196
+ {id:'D01', hex:'#1d4ed8', name:'深蓝'}, {id:'D02', hex:'#38bdf8', name:'天蓝'},
197
+ {id:'E01', hex:'#facc15', name:'柠檬黄'}, {id:'E02', hex:'#fbbf24', name:'金黄'},
198
+ {id:'F01', hex:'#f97316', name:'亮橙'}, {id:'F02', hex:'#c2410c', name:'焦糖'},
199
+ {id:'G01', hex:'#9333ea', name:'紫罗兰'}, {id:'G02', hex:'#7e22ce', name:'深紫'},
200
+ {id:'H01', hex:'#f472b6', name:'浅粉'}, {id:'H02', hex:'#db2777', name:'热粉'},
201
+ {id:'J01', hex:'#9ca3af', name:'水泥灰'}, {id:'J02', hex:'#4b5563', name:'深灰'},
202
+ {id:'K01', hex:'#7f1d1d', name:'红棕'}, {id:'K02', hex:'#ea580c', name:'南瓜'},
203
+ {id:'L01', hex:'#fde047', name:'卡其'}, {id:'L02', hex:'#c084fc', name:'薰衣草'},
204
+ {id:'M01', hex:'#2dd4bf', name:'绿松石'},{id:'M02', hex:'#f59e0b', name:'金色'}
205
  ];
206
 
207
  const state = {
208
+ gridW: 60, gridH: 60,
209
  pixels: {},
210
  scale: 25,
211
  offsetX: 50, offsetY: 50,
 
227
  const totalBeadsEl = document.getElementById('total-beads-count');
228
  const zoomSlider = document.getElementById('zoomSlider');
229
 
 
230
  function init() {
231
  window.addEventListener('resize', resizeAll);
232
  resizeAll();
 
246
 
247
  function applyZoom(newScale, cx, cy) {
248
  const oldScale = state.scale;
249
+ state.scale = Math.max(5, Math.min(150, newScale));
250
  zoomSlider.value = state.scale;
251
  const rect = viewport.getBoundingClientRect();
252
  const mx = cx - rect.left;
 
283
  });
284
  }
285
 
286
+ function selectColor(idx) { state.curColorIdx = idx; updateMaterialList(); setTool('pencil'); }
 
 
 
287
  function copyList() {
288
  let text = "--- 拼豆材料清单 ---\n";
289
  const counts = {};
 
296
  function resizeAll() {
297
  const vw = viewport.clientWidth; const vh = viewport.clientHeight;
298
  cvs.width = vw; cvs.height = vh;
299
+ rulerTop.width = vw; rulerTop.height = 32;
300
+ rulerLeft.width = 32; rulerLeft.height = vh;
301
  draw();
302
  }
303
 
 
305
  state.shape = document.getElementById('shapeSelect').value;
306
  const s = state.scale; const ox = state.offsetX; const oy = state.offsetY;
307
 
308
+ ctx.fillStyle = '#09090b'; ctx.fillRect(0, 0, cvs.width, cvs.height);
309
  ctx.save(); ctx.translate(ox, oy);
310
 
311
+ // 网格线
312
+ ctx.beginPath(); ctx.lineWidth = 1; ctx.strokeStyle = '#27272a';
313
  for(let i=0; i<=state.gridW; i++) { ctx.moveTo(i*s, 0); ctx.lineTo(i*s, state.gridH*s); }
314
  for(let i=0; i<=state.gridH; i++) { ctx.moveTo(0, i*s); ctx.lineTo(state.gridW*s, i*s); }
315
  ctx.stroke();
316
 
317
  // 豆子
318
+ const showId = s > 22;
319
  for(let key in state.pixels) {
320
  const [x, y] = key.split(',').map(Number);
321
  const p = PALETTE[state.pixels[key]];
 
333
  }
334
  }
335
 
336
+ // 大格线(每10格)
337
+ ctx.beginPath(); ctx.lineWidth = 2; ctx.strokeStyle = '#52525b';
338
  for(let i=0; i<=state.gridW; i+=10) { ctx.moveTo(i*s, 0); ctx.lineTo(i*s, state.gridH*s); }
339
  for(let i=0; i<=state.gridH; i+=10) { ctx.moveTo(0, i*s); ctx.lineTo(state.gridW*s, i*s); }
340
  ctx.stroke();
 
347
 
348
  function drawRulers() {
349
  const s = state.scale; const ox = state.offsetX; const oy = state.offsetY;
350
+ const ctxT = ctxRTop; ctxT.clearRect(0,0,rulerTop.width,32);
351
+ ctxT.fillStyle = '#a1a1aa'; ctxT.font = '11px Arial'; ctxT.textAlign = 'center'; ctxT.beginPath(); ctxT.strokeStyle = '#52525b';
352
  const startX = Math.max(0, Math.floor(-ox / s)); const endX = Math.min(state.gridW, Math.ceil((cvs.width - ox) / s));
353
  for(let i=startX; i<=endX; i++) {
354
  const sx = ox + i * s;
355
+ if(i % 10 === 0) { ctxT.moveTo(sx, 16); ctxT.lineTo(sx, 32); ctxT.fillText(i, sx, 12); }
356
+ else if (i % 5 === 0 && s>10) { ctxT.moveTo(sx, 24); ctxT.lineTo(sx, 32); }
357
  }
358
  ctxT.stroke();
359
+ const ctxL = ctxRLeft; ctxL.clearRect(0,0,32,rulerLeft.height);
360
+ ctxL.fillStyle = '#a1a1aa'; ctxL.font = '11px Arial'; ctxL.textAlign = 'center'; ctxL.textBaseline = 'middle'; ctxL.beginPath(); ctxL.strokeStyle = '#52525b';
361
  const startY = Math.max(0, Math.floor(-oy / s)); const endY = Math.min(state.gridH, Math.ceil((cvs.height - oy) / s));
362
  for(let i=startY; i<=endY; i++) {
363
  const sy = oy + i * s;
364
  if(i % 10 === 0) {
365
+ ctxL.moveTo(16, sy); ctxL.lineTo(32, sy);
366
  ctxL.save(); ctxL.translate(12, sy); ctxL.rotate(-Math.PI/2); ctxL.fillText(i, 0, 0); ctxL.restore();
367
+ } else if (i % 5 === 0 && s>10) { ctxL.moveTo(24, sy); ctxL.lineTo(32, sy); }
368
  }
369
  ctxL.stroke();
370
  }
 
405
  function updateInfo(e) { document.getElementById('info-zoom').innerText = `Zoom: ${state.scale}px`; if(e) { const rect = viewport.getBoundingClientRect(); const x = Math.floor((e.clientX - rect.left - state.offsetX) / state.scale); const y = Math.floor((e.clientY - rect.top - state.offsetY) / state.scale); if(x>=0 && x<state.gridW && y>=0 && y<state.gridH) document.getElementById('info-coord').innerText = `XY: (${x}, ${y})`; } }
406
  function clearCanvas() { if(confirm('确定清空画布吗?')) { state.pixels={}; draw(); } }
407
 
408
+ // --- V7.0 导出图纸(带清晰XY轴) ---
409
  function exportImageWithRuler() {
410
  const beadSizeMM = parseFloat(document.getElementById('beadSizeSelect').value);
411
  const pxPerMM = 11.8; // 300 DPI
412
  const unit = Math.round(beadSizeMM * pxPerMM);
413
+ const margin = unit * 3; // 留出更多空间画标尺
414
 
415
  const expCvs = document.createElement('canvas');
416
  expCvs.width = state.gridW * unit + margin;
 
421
  eCtx.fillStyle = 'white'; eCtx.fillRect(0, 0, expCvs.width, expCvs.height);
422
 
423
  // 绘制标尺文字
424
+ eCtx.fillStyle = '#000'; eCtx.font = `bold ${unit*0.8}px Arial`; eCtx.textAlign = 'center'; eCtx.textBaseline = 'middle';
425
 
426
  // 顶标尺
427
  for(let i=0; i<=state.gridW; i++) {
 
440
  }
441
  }
442
 
 
443
  eCtx.translate(margin, margin);
444
 
445
  // 绘制豆子
 
453
  eCtx.fillStyle = '#fff'; eCtx.beginPath(); eCtx.arc(x*unit + unit/2, y*unit + unit/2, unit*0.15, 0, Math.PI*2); eCtx.fill();
454
  } else { eCtx.fillRect(x*unit, y*unit, unit, unit); }
455
 
 
456
  eCtx.fillStyle = getContrastColor(p.hex) === '#fff' ? '#fff' : '#000';
457
  eCtx.font = `bold ${unit*0.35}px Arial`; eCtx.textAlign = 'center'; eCtx.textBaseline = 'middle';
458
  eCtx.fillText(p.id, x*unit + unit/2, y*unit + unit/2);
459
  }
460
 
 
461
  eCtx.strokeStyle = '#ccc'; eCtx.lineWidth = 2;
462
  for(let i=0; i<=state.gridW; i++) { eCtx.moveTo(i*unit, 0); eCtx.lineTo(i*unit, state.gridH*unit); }
463
  for(let i=0; i<=state.gridH; i++) { eCtx.moveTo(0, i*unit); eCtx.lineTo(state.gridW*unit, i*unit); }
464
  eCtx.stroke();
465
 
466
  const link = document.createElement('a');
467
+ link.download = `拼豆图纸_${beadSizeMM}mm_带坐标.png`;
468
  link.href = expCvs.toDataURL();
469
  link.click();
470
  }
471
 
472
+ // --- 裁剪与导入逻辑 (V7.0 读取顶部精度) ---
473
  const modal = document.getElementById('cropModal');
474
  const cropImg = document.getElementById('crop-img');
475
  const cropBox = document.getElementById('crop-box');
 
485
  cropBox.style.display = 'block';
486
  cropBox.style.left = '50px'; cropBox.style.top = '50px';
487
  cropBox.style.width = '100px'; cropBox.style.height = '100px';
 
 
488
  }
489
  };
490
  reader.readAsDataURL(input.files[0]);
 
512
  const cw = cropBox.offsetWidth * factor;
513
  const ch = cropBox.offsetHeight * factor;
514
 
515
+ // V7.0: 核心逻辑 - 直接读取顶部工具栏的设置
516
+ const targetW = parseInt(document.getElementById('targetRes').value) || 60;
517
  const targetH = Math.floor(targetW * (ch / cw));
518
 
 
519
  document.getElementById('gridW').value = targetW;
520
  document.getElementById('gridH').value = targetH;
521
  state.gridW = targetW; state.gridH = targetH;