@@ -318,119 +318,104 @@ function createShapeWrapper(size, shape, src, borderColor) {
318318 const innerDiv = document . createElement ( 'div' ) ;
319319 const img = document . createElement ( 'img' ) ;
320320
321- // Outer div (border)
321+ // --- 1. SETUP OUTER DIV ---
322322 outerDiv . style . width = size + 'px' ;
323-
324- // NEW: Calculate height for rectangle
325- if ( shape === 'rectangle' ) {
326- const currentW = parseInt ( document . getElementById ( 'imageSize' ) . value ) ;
327- const currentH = parseInt ( document . getElementById ( 'rectHeight' ) . value ) ;
328- // Calculate ratio so it works for both Preview and Download
329- const ratio = currentH / currentW ;
330- outerDiv . style . height = ( size * ratio ) + 'px' ;
331- } else {
332- outerDiv . style . height = size + 'px' ;
333- }
334-
335- outerDiv . style . background = borderColor ;
336323 outerDiv . style . display = 'flex' ;
337324 outerDiv . style . justifyContent = 'center' ;
338325 outerDiv . style . alignItems = 'center' ;
339326 outerDiv . style . position = 'relative' ;
340327 outerDiv . style . overflow = 'hidden' ;
341-
342- // Inner div (holds image with adjustment)
343- innerDiv . style . width = '92%' ;
344- innerDiv . style . height = '92%' ;
345- innerDiv . style . position = 'relative' ;
328+
329+ // Calculate height for rectangle (Safe Version for Download)
330+ if ( shape === 'rectangle' ) {
331+ const sizeEl = document . getElementById ( 'imageSize' ) ;
332+ const rectEl = document . getElementById ( 'rectHeight' ) ;
333+
334+ let wVal = sizeEl ? parseInt ( sizeEl . value ) : 150 ;
335+ let hVal = rectEl ? parseInt ( rectEl . value ) : 150 ;
336+
337+ // Safety: Prevent crashes if numbers are missing
338+ if ( isNaN ( wVal ) || wVal <= 0 ) wVal = 150 ;
339+ if ( isNaN ( hVal ) || hVal <= 0 ) hVal = 150 ;
340+
341+ const ratio = hVal / wVal ;
342+ outerDiv . style . height = ( size * ratio ) + 'px' ;
343+ } else {
344+ outerDiv . style . height = size + 'px' ;
345+ }
346+
347+ // --- 2. SETUP INNER DIV & IMAGE ---
348+ innerDiv . style . width = '100%' ;
349+ innerDiv . style . height = '100%' ;
346350 innerDiv . style . overflow = 'hidden' ;
351+ innerDiv . style . display = 'flex' ;
352+ innerDiv . style . justifyContent = 'center' ;
353+ innerDiv . style . alignItems = 'center' ;
347354
348- // Image with position adjustment
349355 img . src = src ;
350356 img . style . width = '100%' ;
351357 img . style . height = '100%' ;
352358 img . style . objectFit = 'cover' ;
353- img . style . transform = `translate(${ imageOffsetX } %, ${ imageOffsetY } %) scale(${ imageZoom } )` ;
359+
360+ // Apply transformations
361+ let zoomVal = 1 ;
362+ if ( typeof imageZoom !== 'undefined' ) {
363+ zoomVal = imageZoom . value || imageZoom ;
364+ }
365+ const offX = ( typeof imageOffsetX !== 'undefined' ) ? imageOffsetX : 0 ;
366+ const offY = ( typeof imageOffsetY !== 'undefined' ) ? imageOffsetY : 0 ;
367+
368+ img . style . transform = `translate(${ offX } %, ${ offY } %) scale(${ zoomVal } )` ;
354369 img . style . transition = 'transform 0.2s' ;
355370 img . crossOrigin = 'anonymous' ;
356-
357- // Apply shape
358- if ( shape === 'circle' ) {
371+
372+ // --- 3. APPLY SHAPE LOGIC ---
373+ if ( shape === 'square' || shape === 'rectangle' ) {
374+ outerDiv . style . background = 'transparent' ;
375+ const borderThick = Math . round ( size * 0.04 ) ;
376+ outerDiv . style . border = `${ borderThick } px solid ${ borderColor } ` ;
377+ outerDiv . style . boxSizing = 'border-box' ;
378+ outerDiv . style . borderRadius = '0' ;
379+ outerDiv . style . shapeOutside = 'none' ; // Square doesn't need shape curve
380+
381+ } else if ( shape === 'circle' ) {
382+ outerDiv . style . background = 'transparent' ;
383+ const borderThick = Math . round ( size * 0.04 ) ;
384+ outerDiv . style . border = `${ borderThick } px solid ${ borderColor } ` ;
385+ outerDiv . style . boxSizing = 'border-box' ;
359386 outerDiv . style . borderRadius = '50%' ;
360- outerDiv . style . shapeOutside = 'circle(50%)' ;
387+
388+ // FIX: Tell text to wrap around the circle!
389+ outerDiv . style . shapeOutside = 'circle(50%)' ;
390+
361391 innerDiv . style . borderRadius = '50%' ;
362392 img . style . borderRadius = '50%' ;
363- // Apply shape
364- if ( shape === 'circle' ) {
365- outerDiv . style . borderRadius = '50%' ;
366- outerDiv . style . shapeOutside = 'circle(50%)' ;
367- outerDiv . style . clipPath = 'circle(50%)' ;
368-
369- innerDiv . style . borderRadius = '50%' ;
370- innerDiv . style . clipPath = 'circle(50%)' ;
371-
372- img . style . borderRadius = '50%' ;
373-
374- } else if ( shape === 'square' || shape === 'rectangle' ) {
375- // 1. Reset standard shape properties
376- outerDiv . style . borderRadius = '0' ;
377- outerDiv . style . shapeOutside = 'none' ;
378- outerDiv . style . clipPath = 'none' ;
379-
380- innerDiv . style . borderRadius = '0' ;
381- innerDiv . style . clipPath = 'none' ;
382-
383- img . style . borderRadius = '0' ;
384- img . style . clipPath = 'none' ;
385-
386- // 2. FIX: Remove the background color
387- outerDiv . style . background = 'transparent' ;
388-
389- // 3. FIX: Add a real border
390- var borderThick = Math . round ( size * 0.04 ) ;
391-
392- outerDiv . style . border = borderThick + 'px solid ' + borderColor ;
393- outerDiv . style . boxSizing = 'border-box' ;
394-
395- // 4. Make sure inner content fills the space
396- innerDiv . style . width = '100%' ;
397- innerDiv . style . height = '100%' ;
393+ outerDiv . style . clipPath = 'none' ;
398394
399- } else {
400- // Logic for Hexadecagon and Flower
401- // (We put this in an ELSE so it doesn't overwrite the others!)
402- const poly = shape === 'hexadecagon' ? hexadecagonPoly : flowerPoly ;
403- outerDiv . style . clipPath = poly ;
404- outerDiv . style . shapeOutside = poly ;
405- innerDiv . style . clipPath = poly ;
406- img . style . clipPath = poly ;
407- }
408- // Logic for Hexadecagon and Flower
409- const poly = shape === 'hexadecagon' ? hexadecagonPoly : flowerPoly ;
410- outerDiv . style . clipPath = poly ;
411- outerDiv . style . shapeOutside = poly ;
412- innerDiv . style . clipPath = poly ;
413- img . style . clipPath = poly ;
395+ } else {
396+ // Polygons
397+ outerDiv . style . background = borderColor ;
398+ outerDiv . style . border = 'none' ;
399+ innerDiv . style . width = '92%' ;
400+ innerDiv . style . height = '92%' ;
401+
402+ const p16 = 'polygon(30% 0%, 70% 0%, 100% 30%, 100% 70%, 70% 100%, 30% 100%, 0% 70%, 0% 30%)' ;
403+ const pFlower = 'circle(50%)' ;
404+ const polyStr = ( shape === 'hexadecagon' )
405+ ? ( ( typeof hexadecagonPoly !== 'undefined' ) ? hexadecagonPoly : p16 )
406+ : ( ( typeof flowerPoly !== 'undefined' ) ? flowerPoly : pFlower ) ;
407+
408+ outerDiv . style . clipPath = polyStr ;
409+ outerDiv . style . shapeOutside = polyStr ;
410+ innerDiv . style . clipPath = polyStr ;
414411 }
415-
412+
416413 innerDiv . appendChild ( img ) ;
417414 outerDiv . appendChild ( innerDiv ) ;
415+
418416 return outerDiv ;
419417}
420418
421- // ============================================
422- // MODAL HANDLING
423- // ============================================
424-
425- downloadBtn . addEventListener ( 'click' , ( ) => sizeModal . classList . add ( 'show' ) ) ;
426- closeModal . addEventListener ( 'click' , ( ) => sizeModal . classList . remove ( 'show' ) ) ;
427-
428- sizeModal . addEventListener ( 'click' , ( e ) => {
429- if ( e . target === sizeModal ) {
430- sizeModal . classList . remove ( 'show' ) ;
431- }
432- } ) ;
433-
434419// ============================================
435420// DOWNLOAD SIZE SELECTION
436421// ============================================
@@ -575,4 +560,28 @@ console.error = function(...args) {
575560 return ;
576561 }
577562 originalError . apply ( console , args ) ;
578- } ;
563+ } ;
564+ // ============================================
565+ // RESTORE DOWNLOAD BUTTON CLICK
566+ // ============================================
567+
568+ // 1. Open the modal when Download is clicked
569+ if ( downloadBtn ) {
570+ downloadBtn . addEventListener ( 'click' , ( ) => {
571+ if ( sizeModal ) sizeModal . classList . add ( 'show' ) ;
572+ } ) ;
573+ }
574+
575+ // 2. Close modal when 'X' is clicked
576+ if ( closeModal ) {
577+ closeModal . addEventListener ( 'click' , ( ) => {
578+ sizeModal . classList . remove ( 'show' ) ;
579+ } ) ;
580+ }
581+
582+ // 3. Close modal when clicking outside the box
583+ window . addEventListener ( 'click' , ( e ) => {
584+ if ( e . target === sizeModal ) {
585+ sizeModal . classList . remove ( 'show' ) ;
586+ }
587+ } ) ;
0 commit comments