@@ -13,6 +13,7 @@ import { type Template } from 'shared/domain/template'
13
13
import { type Note } from 'shared/domain/note'
14
14
import { type Card } from 'shared/domain/card'
15
15
import { objEntries } from 'shared/utility'
16
+ import { parseHtml } from 'shared-dom/utility'
16
17
17
18
export const appExpose = {
18
19
ping : ( ) => { } ,
@@ -32,11 +33,10 @@ export const appExpose = {
32
33
[ rt . nook ] : { remoteTemplateId : rt . id , uploadDate : now } ,
33
34
} ,
34
35
} satisfies Template
35
- const dp = new DOMParser ( )
36
36
if ( template . templateType . tag === 'standard' ) {
37
37
await Promise . all (
38
38
template . templateType . templates . map ( async ( t ) => {
39
- const { imgSrcs, front, back } = getTemplateImages ( t , dp )
39
+ const { imgSrcs, front, back } = getTemplateImages ( t )
40
40
t . front = serializer . serializeToString ( front )
41
41
t . back = serializer . serializeToString ( back )
42
42
return await downloadImages ( imgSrcs )
@@ -45,7 +45,6 @@ export const appExpose = {
45
45
} else {
46
46
const { imgSrcs, front, back } = getTemplateImages (
47
47
template . templateType . template ,
48
- dp ,
49
48
)
50
49
await downloadImages ( imgSrcs )
51
50
template . templateType . template . front =
@@ -73,7 +72,7 @@ export const appExpose = {
73
72
[ nook , { remoteNoteId : rn . id , uploadDate : now } ] ,
74
73
] ) ,
75
74
} satisfies Note
76
- await downloadImages ( getNoteImages ( n . fieldValues , new DOMParser ( ) ) )
75
+ await downloadImages ( getNoteImages ( n . fieldValues ) )
77
76
await C . db . upsertNote ( n )
78
77
const ords = noteOrds . bind ( C ) ( n , template )
79
78
const cards = ords . map ( ( i ) => {
@@ -100,10 +99,10 @@ export const appExpose = {
100
99
// highTODO needs security on the origin
101
100
Comlink . expose ( appExpose , Comlink . windowEndpoint ( self . parent ) )
102
101
103
- function getNoteImages ( fieldValues : Record < string , string > , dp : DOMParser ) {
102
+ function getNoteImages ( fieldValues : Record < string , string > ) {
104
103
const imgSrcs = new Map < MediaId , string > ( )
105
104
for ( const [ f , v ] of objEntries ( fieldValues ) ) {
106
- const doc = dp . parseFromString ( v , 'text/html' )
105
+ const doc = parseHtml ( v )
107
106
Array . from ( doc . images ) . forEach ( ( i ) => {
108
107
mutate ( i , imgSrcs )
109
108
} )
@@ -128,10 +127,10 @@ function mutate(img: HTMLImageElement, imgSrcs: Map<MediaId, string>) {
128
127
}
129
128
}
130
129
131
- function getTemplateImages ( ct : ChildTemplate , dp : DOMParser ) {
130
+ function getTemplateImages ( ct : ChildTemplate ) {
132
131
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 )
135
134
Array . from ( front . images ) . forEach ( ( i ) => {
136
135
mutate ( i , imgSrcs )
137
136
} )
0 commit comments