@@ -13,6 +13,7 @@ import { type Template } from 'shared/domain/template'
1313import { type Note } from 'shared/domain/note'
1414import { type Card } from 'shared/domain/card'
1515import { objEntries } from 'shared/utility'
16+ import { parseHtml } from 'shared-dom/utility'
1617
1718export const appExpose = {
1819 ping : ( ) => { } ,
@@ -32,11 +33,10 @@ export const appExpose = {
3233 [ rt . nook ] : { remoteTemplateId : rt . id , uploadDate : now } ,
3334 } ,
3435 } satisfies Template
35- const dp = new DOMParser ( )
3636 if ( template . templateType . tag === 'standard' ) {
3737 await Promise . all (
3838 template . templateType . templates . map ( async ( t ) => {
39- const { imgSrcs, front, back } = getTemplateImages ( t , dp )
39+ const { imgSrcs, front, back } = getTemplateImages ( t )
4040 t . front = serializer . serializeToString ( front )
4141 t . back = serializer . serializeToString ( back )
4242 return await downloadImages ( imgSrcs )
@@ -45,7 +45,6 @@ export const appExpose = {
4545 } else {
4646 const { imgSrcs, front, back } = getTemplateImages (
4747 template . templateType . template ,
48- dp ,
4948 )
5049 await downloadImages ( imgSrcs )
5150 template . templateType . template . front =
@@ -73,7 +72,7 @@ export const appExpose = {
7372 [ nook , { remoteNoteId : rn . id , uploadDate : now } ] ,
7473 ] ) ,
7574 } satisfies Note
76- await downloadImages ( getNoteImages ( n . fieldValues , new DOMParser ( ) ) )
75+ await downloadImages ( getNoteImages ( n . fieldValues ) )
7776 await C . db . upsertNote ( n )
7877 const ords = noteOrds . bind ( C ) ( n , template )
7978 const cards = ords . map ( ( i ) => {
@@ -100,10 +99,10 @@ export const appExpose = {
10099// highTODO needs security on the origin
101100Comlink . expose ( appExpose , Comlink . windowEndpoint ( self . parent ) )
102101
103- function getNoteImages ( fieldValues : Record < string , string > , dp : DOMParser ) {
102+ function getNoteImages ( fieldValues : Record < string , string > ) {
104103 const imgSrcs = new Map < MediaId , string > ( )
105104 for ( const [ f , v ] of objEntries ( fieldValues ) ) {
106- const doc = dp . parseFromString ( v , 'text/html' )
105+ const doc = parseHtml ( v )
107106 Array . from ( doc . images ) . forEach ( ( i ) => {
108107 mutate ( i , imgSrcs )
109108 } )
@@ -128,10 +127,10 @@ function mutate(img: HTMLImageElement, imgSrcs: Map<MediaId, string>) {
128127 }
129128}
130129
131- function getTemplateImages ( ct : ChildTemplate , dp : DOMParser ) {
130+ function getTemplateImages ( ct : ChildTemplate ) {
132131 const imgSrcs = new Map < MediaId , string > ( )
133- const front = dp . parseFromString ( ct . front , 'text/html' )
134- const back = dp . parseFromString ( ct . back , 'text/html' )
132+ const front = parseHtml ( ct . front )
133+ const back = parseHtml ( ct . back )
135134 Array . from ( front . images ) . forEach ( ( i ) => {
136135 mutate ( i , imgSrcs )
137136 } )
0 commit comments