Skip to content

Commit d302a5f

Browse files
authored
Merge pull request #20 from Pascal-Institute/develop
merge
2 parents 9b0533c + 5a1a61b commit d302a5f

File tree

7 files changed

+117
-122
lines changed

7 files changed

+117
-122
lines changed

css/styles.css

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ select#extensionComboBox {
6868
background: none;
6969
}
7070

71-
.deleteBtn {
71+
#deleteBtn {
7272
width: 24px;
7373
height: 24px;
7474
border: none;
@@ -87,6 +87,12 @@ select#extensionComboBox {
8787
transform: translateY(1px);
8888
}
8989

90+
#nameSpan {
91+
position: absolute;
92+
top: 8px;
93+
left: 8px;
94+
}
95+
9096
.mainColorBox {
9197
width: 24px;
9298
height: 86px;

imgkit/index.js

Lines changed: 79 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@ const sharp = require("sharp");
22
const bmp = require("sharp-bmp");
33
const ico = require("sharp-ico");
44
var path = require("path");
5-
const { channel } = require("diagnostics_channel");
6-
7-
// class ImageLayerQueue {
8-
// static imageLayerQueue = [];
9-
// static num = 0;
10-
// }
115

126
const imageLayerQueue = [];
137

@@ -31,14 +25,6 @@ class ImageLayer {
3125
this.i = -1;
3226
this.showImageOnly = false;
3327

34-
document.getElementById("undoBtn").addEventListener("click", (event) => {
35-
this.undoPreviewImg();
36-
});
37-
38-
document.getElementById("redoBtn").addEventListener("click", (event) => {
39-
this.redoPreviewImg();
40-
});
41-
4228
//initialize
4329
this.imgPanel = document.createElement("div");
4430
this.imgPanel.className = "imgPanel";
@@ -51,10 +37,9 @@ class ImageLayer {
5137
this.canvas.id = "default";
5238

5339
this.deleteBtn = document.createElement("button");
54-
this.deleteBtn.className = "deleteBtn";
40+
this.deleteBtn.id = "deleteBtn";
5541
const img = document.createElement("img");
5642
img.src = "assets/close.ico";
57-
console.log(img.src);
5843
img.style.width = "100%";
5944
img.style.height = "100%";
6045
img.style.objectFit = "contain";
@@ -78,8 +63,14 @@ class ImageLayer {
7863

7964
this.deleteBtn.addEventListener("click", deleteImagePanel);
8065

66+
this.nameSpan = document.createElement("span");
67+
this.nameSpan.id = "nameSpan";
68+
8169
document.addEventListener("keydown", (event) => {
82-
if (event.key === "Delete" && document.activeElement === this.imgPanel) {
70+
if (
71+
(event.ctrlKey && event.key === "d") ||
72+
(event.key === "Delete" && document.activeElement === this.imgPanel)
73+
) {
8374
deleteImagePanel();
8475
}
8576
});
@@ -99,52 +90,22 @@ class ImageLayer {
9990
this.mainColor3.className = "mainColor3";
10091
this.mainColor3.className = "colorBox";
10192

102-
this.mainColor1.addEventListener("click", (event) => {
103-
const text = document.createElement("textarea");
104-
this.imgPanel.appendChild(text);
105-
text.value = this.mainColor1.title;
106-
text.select();
107-
document.execCommand("Copy");
108-
this.imgPanel.removeChild(text);
109-
110-
document
111-
.getElementById("copy_msg")
112-
.animate([{ opacity: "1" }, { opacity: "0" }], {
113-
duration: 1800,
114-
iterations: 1,
115-
});
116-
});
93+
[this.mainColor1, this.mainColor2, this.mainColor3].forEach((mainColor) => {
94+
mainColor.addEventListener("click", (event) => {
95+
const text = document.createElement("textarea");
96+
this.imgPanel.appendChild(text);
97+
text.value = this.mainColor1.title;
98+
text.select();
99+
document.execCommand("Copy");
100+
this.imgPanel.removeChild(text);
117101

118-
this.mainColor2.addEventListener("click", (event) => {
119-
const text = document.createElement("textarea");
120-
this.imgPanel.appendChild(text);
121-
text.value = this.mainColor2.title;
122-
text.select();
123-
document.execCommand("Copy");
124-
this.imgPanel.removeChild(text);
125-
126-
document
127-
.getElementById("copy_msg")
128-
.animate([{ opacity: "1" }, { opacity: "0" }], {
129-
duration: 1800,
130-
iterations: 1,
131-
});
132-
});
133-
134-
this.mainColor3.addEventListener("click", (event) => {
135-
const text = document.createElement("textarea");
136-
this.imgPanel.appendChild(text);
137-
text.value = this.mainColor3.title;
138-
text.select();
139-
document.execCommand("Copy");
140-
this.imgPanel.removeChild(text);
141-
142-
document
143-
.getElementById("copy_msg")
144-
.animate([{ opacity: "1" }, { opacity: "0" }], {
145-
duration: 1800,
146-
iterations: 1,
147-
});
102+
document
103+
.getElementById("copy_msg")
104+
.animate([{ opacity: "1" }, { opacity: "0" }], {
105+
duration: 1800,
106+
iterations: 1,
107+
});
108+
});
148109
});
149110

150111
//
@@ -154,8 +115,6 @@ class ImageLayer {
154115
this.extensionComboBox = document.createElement("select");
155116
this.extensionComboBox.id = "extensionComboBox";
156117

157-
this.defaultOption = document.createElement("option");
158-
this.defaultOption.value = "default";
159118
this.pngOption = document.createElement("option");
160119
this.pngOption.value = "png";
161120
this.pngOption.innerText = "png";
@@ -306,6 +265,7 @@ class ImageLayer {
306265

307266
this.imgPanel.appendChild(this.canvas);
308267
this.imgPanel.appendChild(this.deleteBtn);
268+
this.imgPanel.appendChild(this.nameSpan);
309269
this.imgPanel.appendChild(this.mainColorBox);
310270
this.imgPanel.appendChild(this.imgInfoText);
311271
this.imgPanel.appendChild(this.extensionComboBox);
@@ -314,7 +274,6 @@ class ImageLayer {
314274
this.mainColorBox.appendChild(this.mainColor2);
315275
this.mainColorBox.appendChild(this.mainColor3);
316276

317-
this.extensionComboBox.appendChild(this.defaultOption);
318277
this.extensionComboBox.appendChild(this.pngOption);
319278
this.extensionComboBox.appendChild(this.jpgOption);
320279
this.extensionComboBox.appendChild(this.jpegOption);
@@ -335,16 +294,11 @@ class ImageLayer {
335294
bmp.sharpToBmp(sharp(this.buffer), this.filepath).then(async (info) => {
336295
const fs = require("fs").promises;
337296
const buf = await fs.readFile(this.filepath);
338-
const pngBuffer = await bmp.sharpFromBmp(buf).png().toBuffer();
339-
const outputInfo = {
340-
format: "png", // 여기 확장자 바꿔줘야 화면에서 잘 뜸
341-
size: pngBuffer.length,
342-
width: info.width,
343-
height: info.height,
344-
channels: 4, // PNG RGBA
345-
premultiplied: false,
346-
};
347-
this.updatePreviewImg(pngBuffer, outputInfo);
297+
const pngBuffer = await sharpList[0]
298+
.png()
299+
.toBuffer((err, buf, info) => {
300+
this.updatePreviewImg(buf, info);
301+
});
348302
});
349303

350304
document
@@ -359,17 +313,12 @@ class ImageLayer {
359313
.then(async (info) => {
360314
const fs = require("fs").promises;
361315
const buf = await fs.readFile(this.filepath);
362-
const sharpList = ico.sharpsFromIco(buf); // Sharp[] 배열 반환
363-
const pngBuffer = await sharpList[0].png().toBuffer();
364-
const outputInfo = {
365-
format: "png", // 여기 확장자 바꿔줘야 화면에서 잘 뜸
366-
size: pngBuffer.length,
367-
width: info.width,
368-
height: info.height,
369-
channels: 4, // PNG RGBA
370-
premultiplied: false,
371-
};
372-
this.updatePreviewImg(pngBuffer, outputInfo);
316+
const sharpList = ico.sharpsFromIco(buf);
317+
const pngBuffer = await sharpList[0]
318+
.png()
319+
.toBuffer((err, buf, info) => {
320+
this.updatePreviewImg(buf, info);
321+
});
373322
});
374323

375324
document
@@ -381,6 +330,7 @@ class ImageLayer {
381330
} else {
382331
sharp(this.buffer)
383332
.toFormat(this.extension)
333+
.png()
384334
.toBuffer((err, buf, info) => {
385335
this.updatePreviewImg(buf, info);
386336
document
@@ -411,12 +361,14 @@ class ImageLayer {
411361

412362
updateSio() {
413363
if (this.showImageOnly) {
414-
document.getElementById("showImageOnlyCheckBox").checked = true;
364+
this.deleteBtn.style.visibility = "hidden";
365+
this.nameSpan.style.visibility = "hidden";
415366
this.mainColorBox.style.visibility = "hidden";
416367
this.imgInfoText.style.visibility = "hidden";
417368
this.extensionComboBox.style.visibility = "hidden";
418369
} else {
419-
document.getElementById("showImageOnlyCheckBox").checked = false;
370+
this.deleteBtn.style.visibility = "visible";
371+
this.nameSpan.style.visibility = "visible";
420372
this.mainColorBox.style.visibility = "visible";
421373
this.imgInfoText.style.visibility = "visible";
422374
this.extensionComboBox.style.visibility = "visible";
@@ -457,6 +409,28 @@ class ImageLayer {
457409
this.bufferQueue.push(buf);
458410
this.infoQueue.push(info);
459411
this.extensionQueue.push(this.extension);
412+
413+
setTimeout(() => {
414+
const panels = document.querySelectorAll(".imgPanel"); // imgPanel 클래스 이름 확인 필요
415+
let maxRight = 0;
416+
let maxBottom = 0;
417+
418+
panels.forEach((panel) => {
419+
const rect = panel.getBoundingClientRect();
420+
const right = rect.left + rect.width + window.scrollX;
421+
const bottom = rect.top + rect.height + window.scrollY;
422+
423+
if (right > maxRight) maxRight = right;
424+
if (bottom > maxBottom) maxBottom = bottom;
425+
});
426+
427+
if (maxRight > document.body.scrollWidth) {
428+
document.body.style.width = maxRight + 50 + "px"; // 여유 공간 포함
429+
}
430+
if (maxBottom > document.body.scrollHeight) {
431+
document.body.style.height = maxBottom + 50 + "px";
432+
}
433+
}, 100); // 100ms 후에 실행
460434
}
461435

462436
updateImgInfoText(info) {
@@ -550,13 +524,29 @@ class ImageLayer {
550524
}
551525
this.filepath = filepath;
552526
this.extension = path.extname(this.filepath).replace(".", "");
553-
527+
this.nameSpan.textContent = path
528+
.basename(this.filepath)
529+
.replace("." + this.extension, "");
554530
if (this.extension === "tiff" || this.extension === "tif") {
555531
sharp(filepath)
556532
.toFormat("png")
557533
.toBuffer((err, buf, info) => {
558534
this.updatePreviewImg(buf, info);
559535
});
536+
} else if (this.extension === "ico") {
537+
ico
538+
.sharpsFromIco(this.filepath)
539+
.png()
540+
.toBuffer((err, buf, info) => {
541+
this.updatePreviewImg(buf, info);
542+
});
543+
} else if (this.extension === "bmp") {
544+
bmp
545+
.sharpFromBmp(this.filepath)
546+
.png()
547+
.toBuffer((err, buf, info) => {
548+
this.updatePreviewImg(buf, info);
549+
});
560550
} else {
561551
sharp(filepath).toBuffer((err, buf, info) => {
562552
this.updatePreviewImg(buf, info);

package-lock.json

Lines changed: 17 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)