Skip to content

Commit ca35387

Browse files
committed
refactor(snapdom): streamline plugin exports by consolidating export functions into a loop for improved maintainability
1 parent 9df1149 commit ca35387

1 file changed

Lines changed: 5 additions & 33 deletions

File tree

src/api/snapdom.js

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -135,40 +135,12 @@ snapdom.capture = async (el, context, _token) => {
135135

136136
// ——— 2) Exports declarados por plugins ———
137137
// Fachada reutilizable “silenciosa” (sin hooks) para uso en defineExports()
138-
const _pluginExports = {
139-
svg: async (opts) => {
140-
const { toSvg } = await import('../exporters/toImg.js')
141-
return toSvg(url, { ...context, ...(opts || {}), [INTERNAL_EXPORT_TOKEN]: true })
142-
},
143-
canvas:async (opts) => {
144-
const { toCanvas } = await import('../exporters/toCanvas.js')
145-
return toCanvas(url, { ...context, ...(opts || {}), [INTERNAL_EXPORT_TOKEN]: true })
146-
},
147-
png: async (opts) => {
148-
const { rasterize } = await import('../modules/rasterize.js')
149-
return rasterize(url, { ...context, ...(opts || {}), format: 'png', [INTERNAL_EXPORT_TOKEN]: true })
150-
},
151-
jpeg: async (opts) => {
152-
const { rasterize } = await import('../modules/rasterize.js')
153-
return rasterize(url, { ...context, ...(opts || {}), format: 'jpeg', [INTERNAL_EXPORT_TOKEN]: true })
154-
},
155-
jpg: async (opts) => {
156-
const { rasterize } = await import('../modules/rasterize.js')
157-
return rasterize(url, { ...context, ...(opts || {}), format: 'jpeg', [INTERNAL_EXPORT_TOKEN]: true })
158-
},
159-
webp: async (opts) => {
160-
const { rasterize } = await import('../modules/rasterize.js')
161-
return rasterize(url, { ...context, ...(opts || {}), format: 'webp', [INTERNAL_EXPORT_TOKEN]: true })
162-
},
163-
blob: async (opts) => {
164-
const { toBlob } = await import('../exporters/toBlob.js')
165-
return toBlob(url, { ...context, ...(opts || {}), [INTERNAL_EXPORT_TOKEN]: true })
166-
},
167-
img: async (opts) => {
168-
const { toImg } = await import('../exporters/toImg.js')
169-
return toImg(url, { ...context, ...(opts || {}), [INTERNAL_EXPORT_TOKEN]: true })
170-
},
138+
const _pluginExports = {}
139+
for (const k of ['img', 'svg', 'canvas', 'blob', 'png', 'jpeg', 'webp']) {
140+
_pluginExports[k] = async (opts) =>
141+
coreExports[k](context, { ...(opts || {}), [INTERNAL_EXPORT_TOKEN]: true })
171142
}
143+
_pluginExports.jpg = _pluginExports.jpeg
172144

173145
// Contexto extendido para defineExports (incluye URL y la fachada para reuso)
174146
const _defineCtx = { ...context, export: { url }, exports: _pluginExports }

0 commit comments

Comments
 (0)