@@ -186,28 +186,44 @@ function getChunkProto(template: InternalTemplate): ChunkProto {
186186 return ( template . _p = resolveChunkProto ( template . _s as string [ ] ) )
187187}
188188
189- function resolveChunkProto ( rawStrings : TemplateStringsArray | string [ ] ) : ChunkProto {
189+ function resolveChunkProto (
190+ rawStrings : TemplateStringsArray | string [ ] ,
191+ svg ?: boolean
192+ ) : ChunkProto {
190193 const doc = document
191- let memoByRef = chunkMemoByRef . get ( rawStrings )
194+ let memoByRef = svg ? undefined : chunkMemoByRef . get ( rawStrings )
192195 const cachedByRef = memoByRef ?. get ( doc )
193196 if ( cachedByRef ) return cachedByRef
194197
195198 const signature = rawStrings . join ( delimiterComment )
199+ const cacheKey = svg ? `${ delimiter } ${ signature } ` : signature
196200 let signatureMemo = chunkMemo . get ( doc )
197201 if ( ! signatureMemo ) {
198202 signatureMemo = { }
199203 chunkMemo . set ( doc , signatureMemo )
200204 }
201- const cached = signatureMemo [ signature ]
205+ const cached = signatureMemo [ cacheKey ]
202206 if ( cached ) {
203- memoByRef ??= new WeakMap < Document , ChunkProto > ( )
204- memoByRef . set ( doc , cached )
205- chunkMemoByRef . set ( rawStrings , memoByRef )
207+ if ( ! svg ) {
208+ memoByRef ??= new WeakMap < Document , ChunkProto > ( )
209+ memoByRef . set ( doc , cached )
210+ chunkMemoByRef . set ( rawStrings , memoByRef )
211+ }
206212 return cached
207213 }
208214
209215 const template = document . createElement ( 'template' )
210- template . innerHTML = signature
216+ if ( svg ) {
217+ template . innerHTML = `<svg xmlns="http://www.w3.org/2000/svg">${ signature } </svg>`
218+ const root = template . content . firstChild as SVGElement | null
219+ if ( root ) {
220+ const content = template . content
221+ while ( root . firstChild ) content . appendChild ( root . firstChild )
222+ content . removeChild ( root )
223+ }
224+ } else {
225+ template . innerHTML = signature
226+ }
211227 const paths = createPaths ( template . content )
212228 normalizeNodePlaceholders ( template . content )
213229 const expressions = rawStrings . length - 1
@@ -222,13 +238,15 @@ function resolveChunkProto(rawStrings: TemplateStringsArray | string[]): ChunkPr
222238 const created = {
223239 template,
224240 paths,
225- g : signature ,
241+ g : cacheKey ,
226242 expressions,
227243 }
228- memoByRef ??= new WeakMap < Document , ChunkProto > ( )
229- memoByRef . set ( doc , created )
230- chunkMemoByRef . set ( rawStrings , memoByRef )
231- signatureMemo [ signature ] = created
244+ if ( ! svg ) {
245+ memoByRef ??= new WeakMap < Document , ChunkProto > ( )
246+ memoByRef . set ( doc , created )
247+ chunkMemoByRef . set ( rawStrings , memoByRef )
248+ }
249+ signatureMemo [ cacheKey ] = created
232250 return created
233251}
234252
@@ -409,6 +427,19 @@ export function html(
409427 return template
410428}
411429
430+ export function svg (
431+ strings : TemplateStringsArray | string [ ] ,
432+ ...expSlots : ArrowExpression [ ]
433+ ) : ArrowTemplate
434+ export function svg (
435+ strings : TemplateStringsArray | string [ ] ,
436+ ...expSlots : ArrowExpression [ ]
437+ ) : ArrowTemplate {
438+ const template = html ( strings , ...expSlots ) as InternalTemplate
439+ template . _p = resolveChunkProto ( strings , true )
440+ return template
441+ }
442+
412443function ensureChunk ( this : InternalTemplate ) {
413444 let chunk = this . _h
414445 if ( ! chunk ) {
0 commit comments