@@ -196,8 +196,8 @@ export default class PgInputPixelEditor extends HTMLElement {
196196 this . #baseLayerContext. fillStyle = WHITE ;
197197 this . #baseLayerContext. fillRect ( x * totalSize , y * totalSize , this . size + 1 , this . size + 1 ) ;
198198 this . #baseLayerContext. fillStyle = '#DDD' ;
199- this . #baseLayerContext. fillRect ( x * totalSize + 5 , y * totalSize , 5 , 5 ) ;
200- this . #baseLayerContext. fillRect ( x * totalSize , y * totalSize + 5 , 5 , 5 ) ;
199+ this . #baseLayerContext. fillRect ( x * totalSize + Math . ceil ( this . size / 2 ) , y * totalSize , Math . floor ( this . size / 2 ) , Math . floor ( this . size / 2 ) ) ;
200+ this . #baseLayerContext. fillRect ( x * totalSize , y * totalSize + Math . floor ( this . size / 2 ) , Math . ceil ( this . size / 2 ) , Math . ceil ( this . size / 2 ) ) ;
201201 }
202202 }
203203 } else {
@@ -807,6 +807,9 @@ export default class PgInputPixelEditor extends HTMLElement {
807807 }
808808
809809 async open ( json : File ) {
810+ if ( typeof json !== 'object' ) {
811+ return [ 'json must be type object' ] ;
812+ }
810813 const errors : string [ ] = [ ] ;
811814 // Validate 6 properties exist
812815 const keys = Object . keys ( json ) ;
@@ -816,6 +819,20 @@ export default class PgInputPixelEditor extends HTMLElement {
816819 errors . push ( `JSON key '${ key } ' required.` ) ;
817820 }
818821 } ) ;
822+ // Set props
823+ this . width = json . width ;
824+ this . height = json . height ;
825+ this . transparent = json . transparent ;
826+ this . #colors = json . colors ;
827+ this . #layers = json . layers ;
828+ this . #data = json . data ;
829+ if ( json . undo ) {
830+ this . #undoHistory = json . undo ;
831+ }
832+ if ( json . redo ) {
833+ this . #redoHistory = json . redo ;
834+ }
835+ this . #init( ) ;
819836 }
820837
821838}
0 commit comments