@@ -18,6 +18,12 @@ let sizes = [
1818 width : 62 ,
1919 height : 29 ,
2020 index : 1
21+ } ,
22+ {
23+ name : "monitoni_price_64mm_100mm" ,
24+ width : 100 ,
25+ height : 64 ,
26+ index : 2
2127 }
2228] ;
2329
@@ -47,6 +53,7 @@ async function DOMContentLoadedEvent() {
4753 const formattedDate = `${ year } -${ month } -${ day } ` ;
4854
4955 setUpSize ( )
56+ updateLabLineBreaks ( )
5057
5158 document . getElementById ( 'date' ) . value = formattedDate // set date default
5259 // buttons
@@ -56,9 +63,10 @@ async function DOMContentLoadedEvent() {
5663 } ) ;
5764 //
5865
59- document . getElementById ( 'sizeChange' ) . addEventListener ( 'click ' , function ( ) {
66+ document . getElementById ( 'sizeChange' ) . addEventListener ( 'change ' , function ( event ) {
6067 console . log ( "change size" )
61- setUpSize ( ) ;
68+ let selectedIndex = parseInt ( event . target . value ) ;
69+ setUpSize ( selectedIndex ) ;
6270 } ) ;
6371
6472 let urlText = document . getElementById ( "url" ) ;
@@ -77,7 +85,7 @@ async function DOMContentLoadedEvent() {
7785
7886 const delegate = ( selector ) => ( cb ) => ( e ) => e . target . matches ( selector ) && cb ( e ) ;
7987
80- const inputDelegate = delegate ( 'input[type=text]' ) ;
88+ const inputDelegate = delegate ( 'input[type=text], textarea ' ) ;
8189
8290 [ 'input' , 'change' ] . forEach ( function ( evt ) {
8391 document . body . addEventListener ( evt , inputDelegate ( ( el ) => {
@@ -91,6 +99,43 @@ async function DOMContentLoadedEvent() {
9199 }
92100 ) ) ;
93101 } ) ;
102+
103+ window . addEventListener ( 'resize' , ( ) => {
104+ updateLabLineBreaks ( ) ;
105+ if ( url ) {
106+ updateQRCode ( url ) ;
107+ }
108+ } ) ;
109+ }
110+
111+ function updateLabLineBreaks ( ) {
112+ const labText = document . querySelector ( '.lab b' ) ;
113+ if ( ! labText ) {
114+ return ;
115+ }
116+
117+ const variants = [
118+ 'PHYSICAL COMPUTING LAB' , // 1 line
119+ 'PHYSICAL<br>COMPUTING<br>LAB' // 3 lines (fallback)
120+ ] ;
121+
122+ for ( let variant of variants ) {
123+ labText . innerHTML = variant ;
124+ // Force layout recalculation multiple times to ensure browser recalculates
125+ labText . offsetHeight ;
126+ labText . offsetHeight ;
127+
128+ // Check if content is overflowing visually
129+ const isOverflowing = labText . scrollWidth > labText . clientWidth ||
130+ labText . scrollHeight > labText . clientHeight ;
131+
132+ if ( ! isOverflowing ) {
133+ return ; // This variant fits, we're done
134+ }
135+ }
136+
137+ // Fallback to last variant if nothing else fits
138+ labText . innerHTML = variants [ variants . length - 1 ] ;
94139}
95140
96141function updateQRCode ( text ) {
@@ -104,8 +149,17 @@ function updateQRCode(text) {
104149
105150 url = text ;
106151 let QRCode = require ( 'qrcode' )
152+
153+ let qrWidth = 145 ;
154+ if ( currentSize . name === 'monitoni_price_64mm_100mm' ) {
155+ const qrContainer = document . querySelector ( '.monitoni_price_64mm_100mm .header' ) ;
156+ if ( qrContainer ) {
157+ qrWidth = Math . floor ( qrContainer . clientWidth - 24 ) ;
158+ }
159+ }
160+
107161 QRCode . toCanvas ( canvas , text , {
108- width : 145 , margin : 0
162+ width : qrWidth , margin : 0
109163 } , function ( error ) {
110164 console . log ( 'no QR code generated' ) ;
111165 } )
@@ -116,24 +170,22 @@ function goToUrl() {
116170 window . open ( url , '' , 'width=800, height=400' ) ;
117171}
118172
119- function setUpSize ( ) {
173+ function setUpSize ( index ) {
120174
121- let index = currentSize . index ;
122- index ++ ;
123-
124-
125- if ( index >= sizes . length ) {
126- index = 0 ;
175+ // If no index provided, use the current size index
176+ if ( index === undefined ) {
177+ index = currentSize . index ;
127178 }
128179
129180 currentSize = sizes [ index ] ;
130181
131182 //remove old style
132183 document . getElementById ( "labelContainer" ) . classList . remove ( 'large_62mm_100mm' ) ;
133184 document . getElementById ( "labelContainer" ) . classList . remove ( 'small_29mm_62mm' ) ;
185+ document . getElementById ( "labelContainer" ) . classList . remove ( 'monitoni_price_64mm_100mm' ) ;
134186
135187
136- let label = document . getElementById ( 'sizeLabel' ) ;
188+ let label = document . getElementById ( 'sizeLabel' ) ;
137189 label . innerHTML = '' ;
138190 label . innerHTML = currentSize . name ;
139191 // change size
@@ -143,6 +195,14 @@ function setUpSize() {
143195 // add new style
144196
145197 document . getElementById ( "labelContainer" ) . classList . add ( currentSize . name ) ;
198+
199+ updateLabLineBreaks ( ) ;
200+
201+ // Update QR code size for the new format
202+ let urlText = document . getElementById ( "url" ) ;
203+ if ( urlText && urlText . value ) {
204+ updateQRCode ( urlText . value ) ;
205+ }
146206}
147207
148208function printCanvas ( ) {
0 commit comments