@cyber-dash-tech/revela 0.4.2 → 0.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/pptx/export.ts +20 -17
  2. package/package.json +1 -1
@@ -169,6 +169,19 @@ function isLocalImageRef(ref: string): boolean {
169
169
  return IMAGE_EXTS.has(extname(pathPart).toLowerCase())
170
170
  }
171
171
 
172
+ export function extractImageAssetRefsForPptx(htmlContent: string): string[] {
173
+ const assetRefPattern = /\bsrc\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))|url\(\s*(?:"([^"]*)"|'([^']*)'|([^\s)]+))\s*\)/g
174
+ const refs = new Set<string>()
175
+ let match: RegExpExecArray | null
176
+
177
+ while ((match = assetRefPattern.exec(htmlContent)) !== null) {
178
+ const ref = match.slice(1).find((value): value is string => value !== undefined)
179
+ if (ref) refs.add(ref.trim())
180
+ }
181
+
182
+ return Array.from(refs)
183
+ }
184
+
172
185
  async function toDataUrlFromRef(ref: string, baseDir: string): Promise<string | null> {
173
186
  if (!ref || ref.startsWith("data:") || ref.startsWith("blob:") || ref.startsWith("#")) {
174
187
  return null
@@ -195,21 +208,15 @@ async function toDataUrlFromRef(ref: string, baseDir: string): Promise<string |
195
208
  }
196
209
  }
197
210
 
198
- async function inlineImageAssets(htmlContent: string, htmlFilePath: string): Promise<string> {
211
+ export async function inlineImageAssets(htmlContent: string, htmlFilePath: string): Promise<string> {
199
212
  const baseDir = dirname(resolve(htmlFilePath))
200
- const urlPattern = /(?:src=["']|url\(["']?)([^"')>\s]+)/g
201
- const refs = new Set<string>()
202
- let match: RegExpExecArray | null
203
-
204
- while ((match = urlPattern.exec(htmlContent)) !== null) {
205
- refs.add(match[1])
206
- }
213
+ const refs = extractImageAssetRefsForPptx(htmlContent)
207
214
 
208
- if (refs.size === 0) return htmlContent
215
+ if (refs.length === 0) return htmlContent
209
216
 
210
217
  const replacements = new Map<string, string>()
211
218
  await Promise.allSettled(
212
- Array.from(refs).map(async (ref) => {
219
+ refs.map(async (ref) => {
213
220
  const dataUrl = await toDataUrlFromRef(ref, baseDir)
214
221
  if (dataUrl) replacements.set(ref, dataUrl)
215
222
  })
@@ -224,13 +231,9 @@ async function inlineImageAssets(htmlContent: string, htmlFilePath: string): Pro
224
231
  }
225
232
 
226
233
  async function localizeExternalImages(htmlContent: string, tmpDir: string): Promise<LocalizeExternalImagesResult> {
227
- const urlPattern = /(?:src=["']|url\(["']?)(https?:\/\/[^"')>\s]+)/g
228
- const uniqueUrls = new Set<string>()
229
- let match: RegExpExecArray | null
230
-
231
- while ((match = urlPattern.exec(htmlContent)) !== null) {
232
- uniqueUrls.add(match[1])
233
- }
234
+ const uniqueUrls = new Set(
235
+ extractImageAssetRefsForPptx(htmlContent).filter((ref) => ref.startsWith("http://") || ref.startsWith("https://"))
236
+ )
234
237
 
235
238
  if (uniqueUrls.size === 0) {
236
239
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cyber-dash-tech/revela",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
4
4
  "description": "OpenCode plugin that turns AI into an HTML slide deck generator",
5
5
  "type": "module",
6
6
  "main": "./index.ts",