@digital-ai/dot-illustrations 2.0.24 → 2.0.25
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/demo/index.html +7 -5
- package/demo/script.js +37 -15
- package/package.json +1 -1
package/demo/index.html
CHANGED
|
@@ -66,15 +66,17 @@
|
|
|
66
66
|
<h2 class="text-xl font-semibold mb-4 w-full text-center text-gray-900 dark:text-gray-100">Illustration preview</h2>
|
|
67
67
|
<div id="modal-image" class="mb-4"></div>
|
|
68
68
|
<div class="w-full flex flex-col gap-2 mb-2">
|
|
69
|
-
<
|
|
69
|
+
<div class="text-base font-semibold text-center text-gray-800 dark:text-gray-100 mb-1" id="modal-illustration-name"></div>
|
|
70
|
+
</div>
|
|
71
|
+
<div class="w-full flex flex-col gap-2 mb-2">
|
|
72
|
+
<label class="text-xs font-medium text-gray-500 dark:text-gray-400" for="modal-dot-code">Dot Code</label>
|
|
70
73
|
<div class="flex flex-row items-center gap-2">
|
|
71
|
-
<
|
|
72
|
-
<button id="modal-copy-
|
|
74
|
+
<textarea id="modal-dot-code" class="flex-1 px-2 py-1 border border-gray-300 dark:border-gray-700 rounded bg-gray-100 dark:bg-gray-800 text-gray-900 dark:text-white text-xs font-mono resize-none" rows="2" readonly></textarea>
|
|
75
|
+
<button id="modal-copy-dot-code" class="button flex items-center justify-center px-2 py-1 text-xs text-gray-400 border border-gray-300 dark:border-gray-700 rounded bg-white dark:bg-gray-800 font-normal hover:bg-blue-100 dark:hover:bg-blue-900 transition relative text-center" title="Copy Dot Code">Copy Dot Code</button>
|
|
73
76
|
</div>
|
|
74
77
|
</div>
|
|
75
|
-
<div id="modal-description" class="w-full text-center text-sm text-gray-700 dark:text-gray-300 mb-4"></div>
|
|
76
78
|
<div class="w-full flex flex-col gap-2 mb-2">
|
|
77
|
-
<label class="text-xs font-medium text-gray-500 dark:text-gray-400" for="modal-code">Code</label>
|
|
79
|
+
<label class="text-xs font-medium text-gray-500 dark:text-gray-400" for="modal-code">HTML Code</label>
|
|
78
80
|
<div class="flex flex-row items-center gap-2">
|
|
79
81
|
<textarea id="modal-code" class="flex-1 px-2 py-1 border border-gray-300 dark:border-gray-700 rounded bg-gray-100 dark:bg-gray-800 text-gray-900 dark:text-white text-xs font-mono resize-none" rows="2" readonly></textarea>
|
|
80
82
|
<button id="modal-copy-code" class="button flex items-center justify-center px-2 py-1 text-xs text-gray-400 border border-gray-300 dark:border-gray-700 rounded bg-white dark:bg-gray-800 font-normal hover:bg-blue-100 dark:hover:bg-blue-900 transition relative text-center">Copy Code</button>
|
package/demo/script.js
CHANGED
|
@@ -70,18 +70,19 @@ const origCopyText = window.copyText;
|
|
|
70
70
|
window.copyText = function(button) {
|
|
71
71
|
var parentDiv = button.closest('.copy-container');
|
|
72
72
|
var copyText = parentDiv.querySelector('.iconID');
|
|
73
|
-
var
|
|
74
|
-
|
|
73
|
+
var illustrationId = copyText.textContent;
|
|
74
|
+
var dotCode = `<DotIllustration illustrationId=\"${illustrationId}\" />`;
|
|
75
|
+
navigator.clipboard.writeText(dotCode).then(function() {
|
|
75
76
|
var tooltip = button.querySelector('.tooltiptext');
|
|
76
|
-
tooltip.innerHTML = "Copied
|
|
77
|
+
tooltip.innerHTML = "Copied Dot Code";
|
|
77
78
|
tooltip.style.visibility = 'visible';
|
|
78
79
|
setTimeout(function() {
|
|
79
|
-
tooltip.innerHTML = "Copy
|
|
80
|
+
tooltip.innerHTML = "Copy Dot Code";
|
|
80
81
|
tooltip.style.visibility = 'hidden';
|
|
81
82
|
}, 2000);
|
|
82
|
-
showToast('Copied
|
|
83
|
+
showToast('Copied Dot Code: ' + dotCode);
|
|
83
84
|
}, function(err) {
|
|
84
|
-
console.error('Failed to copy
|
|
85
|
+
console.error('Failed to copy dot code: ', err);
|
|
85
86
|
});
|
|
86
87
|
}
|
|
87
88
|
|
|
@@ -199,7 +200,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
|
199
200
|
const modalIdInput = document.getElementById('modal-id-input');
|
|
200
201
|
const modalDescription = document.getElementById('modal-description');
|
|
201
202
|
const modalCode = document.getElementById('modal-code');
|
|
202
|
-
const modalCopyId = document.getElementById('modal-copy-id');
|
|
203
203
|
const modalCopyCode = document.getElementById('modal-copy-code');
|
|
204
204
|
const modalClose = document.getElementById('modal-close');
|
|
205
205
|
const modalCloseBottom = document.getElementById('modal-close-bottom');
|
|
@@ -219,11 +219,35 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
|
219
219
|
}
|
|
220
220
|
const svgPath = `illustrations/${themeClass}/${categoryFolder}/${illustration}.svg`;
|
|
221
221
|
modalImage.innerHTML = `<span class=\"dot-illustration\"><img src=\"${svgPath}\" class=\"${illustration} ${themeClass} ${categoryClass}\" style=\"width:286px;height:286px;object-fit:contain;\"/></span>`;
|
|
222
|
-
|
|
222
|
+
// Set the illustration name
|
|
223
|
+
const modalIllustrationName = document.getElementById('modal-illustration-name');
|
|
224
|
+
if (modalIllustrationName) modalIllustrationName.textContent = illustration;
|
|
225
|
+
// Set the Dot Code textarea value
|
|
226
|
+
const dotCodeString = `<DotIllustration illustrationId=\"${illustration}\" />`;
|
|
227
|
+
const modalDotCode = document.getElementById('modal-dot-code');
|
|
228
|
+
if (modalDotCode) modalDotCode.value = dotCodeString;
|
|
229
|
+
// Show the HTML code snippet in the modal
|
|
223
230
|
const codeString = `<span class=\"dot-illustration\"><img src=\"${svgPath}\" class=\"${illustration} ${themeClass} ${categoryClass}\"/></span>`;
|
|
224
231
|
modalCode.value = codeString;
|
|
225
232
|
modal.classList.add('active');
|
|
226
233
|
modal.classList.remove('hidden');
|
|
234
|
+
// Attach Copy Dot Code button event listener each time modal opens
|
|
235
|
+
const modalCopyDotCode = document.getElementById('modal-copy-dot-code');
|
|
236
|
+
if (modalCopyDotCode) {
|
|
237
|
+
modalCopyDotCode.onclick = function() {
|
|
238
|
+
if (modalDotCode) {
|
|
239
|
+
navigator.clipboard.writeText(modalDotCode.value).then(function() {
|
|
240
|
+
modalCopyDotCode.textContent = 'Copied!';
|
|
241
|
+
showToast('Copied Dot Code: ' + modalDotCode.value);
|
|
242
|
+
setTimeout(() => {
|
|
243
|
+
modalCopyDotCode.textContent = 'Copy Dot Code';
|
|
244
|
+
}, 2000);
|
|
245
|
+
}, function(err) {
|
|
246
|
+
console.error('Failed to copy dot code: ', err);
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
}
|
|
227
251
|
}
|
|
228
252
|
function closeModal() {
|
|
229
253
|
modal.classList.remove('active');
|
|
@@ -233,10 +257,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
|
233
257
|
modalCloseBottom.addEventListener('click', closeModal);
|
|
234
258
|
modal.addEventListener('click', (e) => { if (e.target === modal) closeModal(); });
|
|
235
259
|
document.addEventListener('keydown', (e) => { if (modal.classList.contains('active') && e.key === 'Escape') closeModal(); });
|
|
236
|
-
modalCopyId.addEventListener('click', () => {
|
|
237
|
-
navigator.clipboard.writeText(modalIdInput.value);
|
|
238
|
-
showToast('Copied ID: ' + modalIdInput.value);
|
|
239
|
-
});
|
|
240
260
|
modalCopyCode.addEventListener('click', () => {
|
|
241
261
|
navigator.clipboard.writeText(modalCode.value);
|
|
242
262
|
showToast('Copied code: ' + modalCode.value);
|
|
@@ -279,6 +299,8 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
|
279
299
|
const isFav = favs.includes(illustration);
|
|
280
300
|
const div = document.createElement("div");
|
|
281
301
|
div.setAttribute("class", "copy-container relative group flex flex-col items-center justify-between bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-xl shadow-lg p-2 md:p-3 transition-transform duration-200 hover:scale-105 hover:shadow-2xl h-[302px] w-full justify-center");
|
|
302
|
+
// Show the HTML code snippet in the card
|
|
303
|
+
const codeString = `<span class=\"dot-illustration\"><img src=\"${svgPath}\" class=\"${illustration} ${themeClass} ${categoryClass}\"/></span>`;
|
|
282
304
|
div.innerHTML = `
|
|
283
305
|
<button class="absolute top-2 right-2 z-10 p-1 rounded-full bg-white/80 dark:bg-gray-800/80 hover:bg-yellow-100 dark:hover:bg-yellow-300 transition" title="Toggle favourite" onclick="event.stopPropagation(); window.toggleFavourite && window.toggleFavourite('${illustration}')">
|
|
284
306
|
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="${isFav ? 'gold' : 'none'}" viewBox="0 0 24 24" stroke="gold">
|
|
@@ -293,15 +315,15 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
|
293
315
|
</div>
|
|
294
316
|
<div class="button-group flex flex-row items-center justify-center gap-2 mt-2">
|
|
295
317
|
<button id="CopyID" class="button flex items-center justify-center min-w-[80px] px-1.5 py-0.5 text-[11px] text-gray-400 border border-gray-300 dark:border-gray-700 rounded bg-white dark:bg-gray-800 font-normal hover:bg-blue-100 dark:hover:bg-blue-900 transition relative text-center" onmouseover="showTooltip(this)" onmouseout="hideTooltip(this)" onclick="copyText(this)">
|
|
296
|
-
Copy
|
|
297
|
-
<span class="tooltiptext left-1/2 -translate-x-1/2 bottom-10 shadow-md">Copy
|
|
318
|
+
Copy Dot Code
|
|
319
|
+
<span class="tooltiptext left-1/2 -translate-x-1/2 bottom-10 shadow-md">Copy Dot Code</span>
|
|
298
320
|
</button>
|
|
299
321
|
<button class="button flex items-center justify-center min-w-[80px] px-1.5 py-0.5 text-[11px] text-gray-400 border border-gray-300 dark:border-gray-700 rounded bg-white dark:bg-gray-800 font-normal hover:bg-blue-100 dark:hover:bg-blue-900 transition relative text-center" onmouseover="showTooltip(this)" onmouseout="hideTooltip(this)" onclick="copyCode(this)">
|
|
300
322
|
Copy Code
|
|
301
323
|
<span class="tooltiptext left-1/2 -translate-x-1/2 bottom-10 shadow-md">Copy Code</span>
|
|
302
324
|
</button>
|
|
303
325
|
</div>
|
|
304
|
-
<pre class="codeBlock"><code class="codeBlock"
|
|
326
|
+
<pre class="codeBlock"><code class="codeBlock">${codeString}</code></pre>
|
|
305
327
|
`;
|
|
306
328
|
list.appendChild(div);
|
|
307
329
|
});
|
package/package.json
CHANGED