Skip to content

Commit 9c4508e

Browse files
committed
fix local register
1 parent 0997618 commit 9c4508e

1 file changed

Lines changed: 27 additions & 31 deletions

File tree

src/api/snapdom.js

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,13 @@ snapdom.capture = async (el, context, _token) => {
9797

9898
// ——— 1) Core exports por defecto ———
9999
const coreExports = {
100-
img: async (ctx, opts) => toImg(url, { ...ctx, ...(opts || {}) }),
101-
svg: async (ctx, opts) => toSvg(url, { ...ctx, ...(opts || {}) }),
102-
canvas: async (ctx, opts) => toCanvas(url, { ...ctx, ...(opts || {}) }),
103-
blob: async (ctx, opts) => toBlob(url, { ...ctx, ...(opts || {}) }),
104-
png: async (ctx, opts) => rasterize(url, { ...ctx, ...(opts || {}), format: 'png' }),
105-
jpeg: async (ctx, opts) => rasterize(url, { ...ctx, ...(opts || {}), format: 'jpeg' }),
106-
webp: async (ctx, opts) => rasterize(url, { ...ctx, ...(opts || {}), format: 'webp' }),
100+
img: async (ctx, opts) => toImg(url, { ...ctx, ...(opts || {}) }),
101+
svg: async (ctx, opts) => toSvg(url, { ...ctx, ...(opts || {}) }),
102+
canvas: async (ctx, opts) => toCanvas(url, { ...ctx, ...(opts || {}) }),
103+
blob: async (ctx, opts) => toBlob(url, { ...ctx, ...(opts || {}) }),
104+
png: async (ctx, opts) => rasterize(url, { ...ctx, ...(opts || {}), format: 'png' }),
105+
jpeg: async (ctx, opts) => rasterize(url, { ...ctx, ...(opts || {}), format: 'jpeg' }),
106+
webp: async (ctx, opts) => rasterize(url, { ...ctx, ...(opts || {}), format: 'webp' }),
107107
download: async (ctx, opts) => download(url, { ...ctx, ...(opts || {}) }),
108108
}
109109

@@ -132,25 +132,21 @@ snapdom.capture = async (el, context, _token) => {
132132
// ——— Runner unificado con beforeExport/afterExport y cola por sesión ———
133133
let afterSnapFired = false
134134
let _exportQueue = Promise.resolve()
135-
136135
async function runExport(type, opts) {
137136
const job = async () => {
138137
const work = exportsMap[type]
139138
if (!work) throw new Error(`[snapdom] Unknown export type: ${type}`)
140139
const nextOpts = normalizeExportOptions(type, opts)
141140
const ctx = { ...context, export: { type, options: nextOpts, url } }
142-
143141
await runHook('beforeExport', ctx)
144-
const result = await work(ctx, nextOpts)
145-
await runHook('afterExport', ctx, result)
146-
142+
const result2 = await work(ctx, nextOpts)
143+
await runHook('afterExport', ctx, result2)
147144
if (!afterSnapFired) {
148145
afterSnapFired = true
149146
await runHook('afterSnap', context)
150147
}
151-
return result
148+
return result2
152149
}
153-
154150
return _exportQueue = _exportQueue.then(job)
155151
}
156152

@@ -161,13 +157,13 @@ snapdom.capture = async (el, context, _token) => {
161157
to: (type, opts) => runExport(type, opts),
162158

163159
// Métodos “clásicos” que los tests esperan:
164-
toImg: (opts) => runExport('img', opts),
165-
toSvg: (opts) => runExport('svg', opts),
160+
toImg: (opts) => runExport('img', opts),
161+
toSvg: (opts) => runExport('svg', opts),
166162
toCanvas: (opts) => runExport('canvas', opts),
167-
toBlob: (opts) => runExport('blob', opts),
168-
toPng: (opts) => runExport('png', opts),
169-
toJpg: (opts) => runExport('jpg', opts), // ← alias requerido por los tests
170-
toWebp: (opts) => runExport('webp', opts),
163+
toBlob: (opts) => runExport('blob', opts),
164+
toPng: (opts) => runExport('png', opts),
165+
toJpg: (opts) => runExport('jpg', opts), // ← alias requerido por los tests
166+
toWebp: (opts) => runExport('webp', opts),
171167
download: (opts) => runExport('download', opts) // ← método directo (no toDownload)
172168
}
173169

@@ -287,20 +283,20 @@ async function safariWarmup(element, baseOptions) {
287283
img.src = url
288284
document.body.appendChild(img)
289285

290-
;(async () => {
291-
try { if (typeof img.decode === 'function') await img.decode() } catch { /* noop */ }
286+
; (async () => {
287+
try { if (typeof img.decode === 'function') await img.decode() } catch { /* noop */ }
292288

293-
const start = performance.now()
294-
while (!(img.complete && img.naturalWidth > 0) && performance.now() - start < 900) {
295-
// ~3–4 ticks worst-case
289+
const start = performance.now()
290+
while (!(img.complete && img.naturalWidth > 0) && performance.now() - start < 900) {
291+
// ~3–4 ticks worst-case
296292

297-
await new Promise(r => setTimeout(r, 50))
298-
}
293+
await new Promise(r => setTimeout(r, 50))
294+
}
299295

300-
await new Promise(r => requestAnimationFrame(r))
301-
try { img.remove() } catch { /* noop */ }
302-
resolve()
303-
})()
296+
await new Promise(r => requestAnimationFrame(r))
297+
try { img.remove() } catch { /* noop */ }
298+
resolve()
299+
})()
304300
})
305301
}
306302

0 commit comments

Comments
 (0)