|
1 | 1 | import { setFontValues } from './utils/fonts'; |
2 | 2 | import { getRandomTheme } from './utils/themes'; |
3 | | -import * as htmlToImage from 'html-to-image'; |
4 | | -import { toPng, toJpeg, toBlob, toPixelData, toSvg } from 'html-to-image'; |
5 | | -import domtoimage from 'dom-to-image'; |
| 3 | +import { snapdom } from '@zumer/snapdom'; |
6 | 4 |
|
7 | 5 | /* ************** Elements ************** */ |
8 | 6 |
|
@@ -30,136 +28,52 @@ document.querySelector('.how-to-section video.demo').onended = (e) => e.target.c |
30 | 28 | /* ************** Header image buttons ************** */ |
31 | 29 |
|
32 | 30 | // Download button |
33 | | -// document.querySelector('.download-button') |
34 | | -// .addEventListener('click', () => { |
35 | | -// html2canvas( |
36 | | -// document.querySelector('#github-header-image'), |
37 | | -// { |
38 | | -// // removeContainer: true, |
39 | | -// // backgroundColor: null, |
40 | | -// letterRendering: true, |
41 | | -// // logging: true, |
42 | | -// // useCORS: true, |
43 | | -// foreignObjectRendering: false, |
44 | | -// // onclone: (document, element) => { |
45 | | -// // // const title = element.querySelector('.title').style.letterSpacing = '0.10rem'; |
46 | | -// // const title = element.querySelector('.title') |
47 | | -// // if (getComputedStyle(title).getPropertyValue("font-family") === 'Ubuntu') { |
48 | | -// // title.style.letterSpacing = '1px'; |
49 | | -// // } |
50 | | -// // if (getComputedStyle(title).getPropertyValue("font-family") === 'Martel') { |
51 | | -// // title.style.letterSpacing = '2px'; |
52 | | -// // } |
53 | | -// // if (getComputedStyle(title).getPropertyValue("font-family") === 'MavenPro') { |
54 | | -// // title.style.letterSpacing = '0.2rem'; |
55 | | -// // } |
56 | | -// // // title.style.letterSpacing = '2px'; |
57 | | -// // // console.log("🚀 ~ title:", title) |
58 | | -// // // const title = element.querySelector('.subtitle').style.style.letterSpacing = '5px'; |
59 | | -// // } |
60 | | -// // widtH: (headerImage.clientWidth * 2), |
61 | | -// // height: (headerImage.style.height * 2) |
62 | | -// }) |
63 | | -// .then(function (canvas) { |
64 | | -// // for testing |
65 | | -// const container = document.querySelector('.header-image-container') |
66 | | - |
67 | | -// const prevImage = container.children[1]; |
68 | | -// if (prevImage) container.removeChild(prevImage); |
69 | | - |
70 | | -// container.appendChild(canvas); |
71 | | - |
72 | | -// // let imageURL = canvas.toDataURL("image/png"); |
73 | | -// // let a = document.createElement("a"); |
74 | | -// // a.href = imageURL; |
75 | | -// // a.download = 'github-header-image'; |
76 | | -// // a.click(); |
77 | | -// }); |
78 | | -// }) |
79 | | - |
80 | | -// document.querySelector('.download-button') |
81 | | -// .addEventListener('click', () => { |
82 | | -// htmlToImage |
83 | | -// .toPng(document.querySelector('#github-header-image')) |
84 | | -// .then((dataUrl) => { |
85 | | -// const img = new Image(); |
86 | | -// img.src = dataUrl; |
87 | | -// img.width = 900 |
88 | | -// document.querySelector('.header-image-container').appendChild(img); |
89 | | -// }) |
90 | | -// .catch((err) => { |
91 | | -// console.error('oops, something went wrong!', err); |
92 | | -// }); |
93 | | -// }) |
94 | | - |
95 | 31 | document.querySelector('.download-button') |
96 | 32 | .addEventListener('click', async () => { |
97 | 33 | document.querySelector('.download-button img').src = './images/icons/loading.gif' |
98 | 34 |
|
99 | 35 | try { |
100 | 36 | const el = document.querySelector('#github-header-image'); |
101 | | - |
102 | | - if (window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1') { |
103 | | - console.log('Running on localhost! Appending image instead of downloading ...'); |
104 | | - const png = await snapdom.toPng(el, { embedFonts: true }); |
105 | | - const container = document.querySelector('.header-image-container') |
106 | | - |
107 | | - const prevImage = container.children[1]; |
108 | | - if (prevImage) container.removeChild(prevImage); |
109 | | - |
110 | | - container.appendChild(png); |
111 | | - } else { |
112 | | - await snapdom.download(el, { |
113 | | - embedFonts: true, |
114 | | - format: 'png', |
115 | | - filename: 'github-header-banner', |
116 | | - scale: 2 |
117 | | - }); |
118 | | - } |
| 37 | + await snapdom.download(el, { |
| 38 | + embedFonts: true, |
| 39 | + format: 'png', |
| 40 | + filename: 'github-header-banner', |
| 41 | + scale: 2 |
| 42 | + }); |
119 | 43 | document.querySelector('.download-button img').src = './images/icons/download.svg' |
120 | 44 | } catch (error) { |
121 | 45 | console.error('Image capture or download failed:', error); |
122 | 46 | } |
123 | 47 | }) |
124 | 48 |
|
125 | | -// document.addEventListener("DOMContentLoaded", (event) => { |
126 | | -// const displayButton = document.querySelector('.display-button'); |
127 | | - |
128 | | -// if (displayButton && (window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1')) { |
129 | | -// displayButton.style.display = "block"; // or "flex", "grid", etc. |
130 | | -// console.log('Running on localhost! display appending image option ...'); |
| 49 | +document.addEventListener("DOMContentLoaded", (event) => { |
| 50 | + const displayButton = document.querySelector('.display-button'); |
| 51 | + const testFontsTab = document.querySelector('.tablinks[data-name="test-fonts-section"]'); |
131 | 52 |
|
132 | | -// document.querySelector('.display-button') |
133 | | -// .addEventListener('click', async () => { |
134 | | -// const el = document.querySelector('#github-header-image'); |
135 | | -// const png = await snapdom.toPng(el, { embedFonts: true }); |
136 | | -// const container = document.querySelector('.header-image-container') |
| 53 | + if (window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1') { |
| 54 | + if (displayButton) { |
137 | 55 |
|
138 | | -// const prevImage = container.children[1]; |
139 | | -// if (prevImage) container.removeChild(prevImage); |
| 56 | + displayButton.style.display = "block"; // or "flex", "grid", etc. |
| 57 | + console.log('Running on localhost! display appending image option ...'); |
140 | 58 |
|
141 | | -// container.appendChild(png); |
142 | | -// }) |
143 | | -// } |
| 59 | + document.querySelector('.display-button') |
| 60 | + .addEventListener('click', async () => { |
| 61 | + const el = document.querySelector('#github-header-image'); |
| 62 | + const png = await snapdom.toPng(el, { embedFonts: true }); |
| 63 | + const container = document.querySelector('.header-image-container') |
144 | 64 |
|
145 | | -// }); |
| 65 | + const prevImage = container.children[1]; |
| 66 | + if (prevImage) container.removeChild(prevImage); |
146 | 67 |
|
| 68 | + container.appendChild(png); |
| 69 | + }) |
| 70 | + } |
| 71 | + if (testFontsTab) { |
| 72 | + testFontsTab.style.display = "block" |
| 73 | + } |
| 74 | + } |
147 | 75 |
|
148 | | -// document.querySelector('.download-button') |
149 | | -// .addEventListener('click', () => { |
150 | | -// var node = document.getElementById('github-header-image'); |
151 | | - |
152 | | -// domtoimage.toPng(node) |
153 | | -// .then(function (dataUrl) { |
154 | | -// console.log("🚀 ~ dataUrl:", dataUrl) |
155 | | -// var img = new Image(); |
156 | | -// img.src = dataUrl; |
157 | | -// document.querySelector('.header-image-container').appendChild(img); |
158 | | -// }) |
159 | | -// .catch(function (error) { |
160 | | -// console.error('oops, something went wrong!', error); |
161 | | -// }); |
162 | | -// }) |
| 76 | +}); |
163 | 77 |
|
164 | 78 | // Toogle Dark Mode button |
165 | 79 | document.querySelector('.dark-mode-button') |
|
0 commit comments