@bendyline/squisq 1.0.1 → 1.1.0
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.
- package/dist/MediaProvider-wpSe21B3.d.ts +66 -0
- package/dist/__tests__/contentContainer.test.d.ts +2 -0
- package/dist/__tests__/contentContainer.test.d.ts.map +1 -0
- package/dist/__tests__/contentContainer.test.js +234 -0
- package/dist/__tests__/contentContainer.test.js.map +1 -0
- package/dist/chunk-4CRBS35L.js +292 -0
- package/dist/chunk-4CRBS35L.js.map +1 -0
- package/dist/storage/ContentContainer.d.ts +87 -0
- package/dist/storage/ContentContainer.d.ts.map +1 -0
- package/dist/storage/ContentContainer.js +122 -0
- package/dist/storage/ContentContainer.js.map +1 -0
- package/dist/storage/MediaProviderFromContainer.d.ts +21 -0
- package/dist/storage/MediaProviderFromContainer.d.ts.map +1 -0
- package/dist/storage/MediaProviderFromContainer.js +79 -0
- package/dist/storage/MediaProviderFromContainer.js.map +1 -0
- package/dist/storage/index.d.ts +3 -0
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/index.js +2 -0
- package/dist/storage/index.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/contentContainer.test.ts +282 -0
- package/src/storage/ContentContainer.ts +200 -0
- package/src/storage/MediaProviderFromContainer.ts +92 -0
- package/src/storage/index.ts +3 -0
- package/dist/chunk-VJN7UB2Z.js +0 -145
- package/dist/chunk-VJN7UB2Z.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/storage/MemoryStorageAdapter.ts","../src/storage/LocalStorageAdapter.ts","../src/storage/LocalForageAdapter.ts","../src/storage/ContentContainer.ts","../src/storage/MediaProviderFromContainer.ts"],"sourcesContent":["/**\n * In-memory storage adapter for testing and SSR environments.\n * Data does not persist across page reloads.\n */\n\nimport type { StorageAdapter } from './Storage.js';\n\nexport class MemoryStorageAdapter implements StorageAdapter {\n readonly supportsEnumeration = true;\n private store = new Map<string, string>();\n\n async get<T>(key: string): Promise<T | null> {\n const val = this.store.get(key);\n if (val === undefined) return null;\n try {\n return JSON.parse(val) as T;\n } catch {\n return null;\n }\n }\n\n async set<T>(key: string, value: T): Promise<void> {\n this.store.set(key, JSON.stringify(value));\n }\n\n async remove(key: string): Promise<void> {\n this.store.delete(key);\n }\n\n async clear(): Promise<void> {\n this.store.clear();\n }\n\n async keys(): Promise<string[]> {\n return Array.from(this.store.keys());\n }\n}\n","/**\n * localStorage adapter for web browsers.\n * Supports a configurable key prefix to namespace stored data.\n */\n\nimport type { StorageAdapter } from './Storage.js';\n\nexport class LocalStorageAdapter implements StorageAdapter {\n readonly supportsEnumeration = true;\n private prefix: string;\n\n constructor(prefix = '') {\n this.prefix = prefix;\n }\n\n async get<T>(key: string): Promise<T | null> {\n try {\n const raw = localStorage.getItem(this.prefix + key);\n if (raw === null) return null;\n return JSON.parse(raw) as T;\n } catch {\n return null;\n }\n }\n\n async set<T>(key: string, value: T): Promise<void> {\n localStorage.setItem(this.prefix + key, JSON.stringify(value));\n }\n\n async remove(key: string): Promise<void> {\n localStorage.removeItem(this.prefix + key);\n }\n\n async clear(): Promise<void> {\n const keysToRemove: string[] = [];\n for (let i = 0; i < localStorage.length; i++) {\n const k = localStorage.key(i);\n if (k && k.startsWith(this.prefix)) {\n keysToRemove.push(k);\n }\n }\n for (const k of keysToRemove) {\n localStorage.removeItem(k);\n }\n }\n\n async keys(): Promise<string[]> {\n const result: string[] = [];\n for (let i = 0; i < localStorage.length; i++) {\n const k = localStorage.key(i);\n if (k && k.startsWith(this.prefix)) {\n result.push(k.slice(this.prefix.length));\n }\n }\n return result;\n }\n}\n","/**\n * LocalForage adapter - IndexedDB storage with automatic fallbacks.\n *\n * Uses localforage which provides IndexedDB storage with automatic\n * fallbacks to WebSQL and localStorage. This allows storing much more\n * data than raw localStorage (which is limited to ~5MB).\n *\n * Unlike LocalStorageAdapter, this adapter can store binary data\n * (ArrayBuffer, Blob, Uint8Array) natively without JSON serialization.\n *\n * Ported from qualla-internal/shared/services/StorageAdapters.ts with\n * configurable store name and key prefix.\n */\n\nimport localforage from 'localforage';\nimport type { StorageAdapter } from './Storage.js';\n\nexport interface LocalForageAdapterOptions {\n /** IndexedDB database name (default: 'squisq') */\n name?: string;\n /** IndexedDB object store name (default: 'data') */\n storeName?: string;\n /** Key prefix for namespacing (default: '') */\n prefix?: string;\n /** Human-readable description (default: 'Squisq storage') */\n description?: string;\n}\n\nexport class LocalForageAdapter implements StorageAdapter {\n readonly supportsEnumeration = true;\n private store: LocalForage;\n private prefix: string;\n\n constructor(options: LocalForageAdapterOptions = {}) {\n const {\n name = 'squisq',\n storeName = 'data',\n prefix = '',\n description = 'Squisq storage',\n } = options;\n\n this.prefix = prefix;\n this.store = localforage.createInstance({ name, storeName, description });\n }\n\n async get<T>(key: string): Promise<T | null> {\n try {\n const value = await this.store.getItem<T>(this.prefix + key);\n return value;\n } catch (e: unknown) {\n console.warn('[Storage] get (IndexedDB) failed:', key, e);\n return null;\n }\n }\n\n async set<T>(key: string, value: T): Promise<void> {\n try {\n await this.store.setItem(this.prefix + key, value);\n } catch (e: unknown) {\n console.error('[Storage] set (IndexedDB) failed:', key, e);\n throw e;\n }\n }\n\n async remove(key: string): Promise<void> {\n try {\n await this.store.removeItem(this.prefix + key);\n } catch (e: unknown) {\n console.warn('[Storage] remove (IndexedDB) failed:', key, e);\n }\n }\n\n async clear(): Promise<void> {\n try {\n if (this.prefix) {\n // Only remove keys with our prefix\n const keys = await this.store.keys();\n const keysToRemove = keys.filter((k) => k.startsWith(this.prefix));\n await Promise.all(keysToRemove.map((k) => this.store.removeItem(k)));\n } else {\n // No prefix — clear the entire store\n await this.store.clear();\n }\n } catch (e: unknown) {\n console.error('[Storage] clear (IndexedDB) failed:', e);\n }\n }\n\n async keys(): Promise<string[]> {\n try {\n const allKeys = await this.store.keys();\n if (this.prefix) {\n return allKeys\n .filter((k) => k.startsWith(this.prefix))\n .map((k) => k.slice(this.prefix.length));\n }\n return allKeys;\n } catch (e: unknown) {\n console.warn('[Storage] keys (IndexedDB) failed:', e);\n return [];\n }\n }\n}\n","/**\n * ContentContainer — virtual file system for document containers.\n *\n * A Squisq document is more than just markdown: it's a container of files\n * including the primary markdown document, images, audio, timing data, and\n * other media. ContentContainer provides an abstract async file system\n * interface for reading, writing, and listing these files.\n *\n * Paths are forward-slash separated strings relative to the container root\n * (e.g., 'images/hero.jpg', 'index.md'). No leading slash.\n *\n * Implementations:\n * - MemoryContentContainer — in-memory Map (for zip import, tests, transient use)\n * - SlotContentContainer — backed by IndexedDB slot storage (in the site package)\n */\n\n/**\n * Metadata about a file in a ContentContainer.\n */\nexport interface ContentEntry {\n /** Relative path within the container (e.g., 'images/hero.jpg') */\n path: string;\n /** MIME type (e.g., 'image/jpeg') */\n mimeType: string;\n /** File size in bytes */\n size: number;\n}\n\n/**\n * Abstract async file system for document containers.\n *\n * All paths are forward-slash separated, relative to the container root,\n * with no leading slash. Example: 'images/hero.jpg', 'index.md'.\n */\nexport interface ContentContainer {\n /** Read a file's binary content. Returns null if the file does not exist. */\n readFile(path: string): Promise<ArrayBuffer | null>;\n\n /** Write a file. Creates or overwrites. */\n writeFile(path: string, data: ArrayBuffer | Uint8Array, mimeType?: string): Promise<void>;\n\n /** Remove a file. No-op if the file does not exist. */\n removeFile(path: string): Promise<void>;\n\n /**\n * List files in the container.\n * @param prefix — Optional path prefix to filter by (e.g., 'images/')\n */\n listFiles(prefix?: string): Promise<ContentEntry[]>;\n\n /** Check whether a file exists. */\n exists(path: string): Promise<boolean>;\n\n /**\n * Find the primary markdown document path.\n *\n * Discovery order: index.md → doc.md → document.md → first *.md at root.\n * Returns null if no markdown file is found at the root level.\n */\n getDocumentPath(): Promise<string | null>;\n\n /**\n * Convenience: read the primary markdown document as a UTF-8 string.\n * Returns null if no markdown file is found.\n */\n readDocument(): Promise<string | null>;\n\n /**\n * Convenience: write a markdown document.\n * @param markdown — The markdown content\n * @param filename — Filename to use (defaults to 'index.md')\n */\n writeDocument(markdown: string, filename?: string): Promise<void>;\n}\n\n// ============================================\n// Well-known markdown filenames in priority order\n// ============================================\n\nconst MARKDOWN_PRIORITY = ['index.md', 'doc.md', 'document.md'];\n\n/**\n * Find the primary markdown path from a list of file entries.\n * Exported for reuse by other ContentContainer implementations.\n */\nexport function findDocumentPath(entries: ContentEntry[]): string | null {\n // Only consider root-level files (no '/' in path)\n const rootFiles = entries.filter((e) => !e.path.includes('/'));\n\n for (const name of MARKDOWN_PRIORITY) {\n if (rootFiles.some((e) => e.path.toLowerCase() === name)) {\n return name;\n }\n }\n\n // Fallback: first .md file at root\n const firstMd = rootFiles.find((e) => e.path.toLowerCase().endsWith('.md'));\n return firstMd?.path ?? null;\n}\n\n// ============================================\n// MemoryContentContainer\n// ============================================\n\ninterface MemoryFile {\n data: ArrayBuffer;\n mimeType: string;\n}\n\n/**\n * In-memory ContentContainer backed by a Map.\n *\n * Used for zip import (deserialize into memory), tests, and transient operations.\n */\nexport class MemoryContentContainer implements ContentContainer {\n private files = new Map<string, MemoryFile>();\n\n async readFile(path: string): Promise<ArrayBuffer | null> {\n return this.files.get(path)?.data ?? null;\n }\n\n async writeFile(path: string, data: ArrayBuffer | Uint8Array, mimeType?: string): Promise<void> {\n const buffer = data instanceof ArrayBuffer ? data : data.slice().buffer;\n this.files.set(path, {\n data: buffer,\n mimeType: mimeType ?? guessMimeType(path),\n });\n }\n\n async removeFile(path: string): Promise<void> {\n this.files.delete(path);\n }\n\n async listFiles(prefix?: string): Promise<ContentEntry[]> {\n const entries: ContentEntry[] = [];\n for (const [path, file] of this.files) {\n if (prefix && !path.startsWith(prefix)) continue;\n entries.push({\n path,\n mimeType: file.mimeType,\n size: file.data.byteLength,\n });\n }\n return entries;\n }\n\n async exists(path: string): Promise<boolean> {\n return this.files.has(path);\n }\n\n async getDocumentPath(): Promise<string | null> {\n return findDocumentPath(await this.listFiles());\n }\n\n async readDocument(): Promise<string | null> {\n const docPath = await this.getDocumentPath();\n if (!docPath) return null;\n const data = await this.readFile(docPath);\n if (!data) return null;\n return new TextDecoder().decode(data);\n }\n\n async writeDocument(markdown: string, filename?: string): Promise<void> {\n const name = filename ?? 'index.md';\n const data = new TextEncoder().encode(markdown);\n await this.writeFile(name, data, 'text/markdown');\n }\n}\n\n// ============================================\n// MIME type guessing\n// ============================================\n\nconst EXTENSION_MIME_MAP: Record<string, string> = {\n '.md': 'text/markdown',\n '.txt': 'text/plain',\n '.json': 'application/json',\n '.jpg': 'image/jpeg',\n '.jpeg': 'image/jpeg',\n '.png': 'image/png',\n '.gif': 'image/gif',\n '.svg': 'image/svg+xml',\n '.webp': 'image/webp',\n '.avif': 'image/avif',\n '.mp4': 'video/mp4',\n '.webm': 'video/webm',\n '.mp3': 'audio/mpeg',\n '.wav': 'audio/wav',\n '.ogg': 'audio/ogg',\n '.css': 'text/css',\n '.html': 'text/html',\n '.js': 'application/javascript',\n};\n\nfunction guessMimeType(path: string): string {\n const dot = path.lastIndexOf('.');\n if (dot === -1) return 'application/octet-stream';\n const ext = path.slice(dot).toLowerCase();\n return EXTENSION_MIME_MAP[ext] ?? 'application/octet-stream';\n}\n","/**\n * MediaProviderFromContainer — bridges ContentContainer to MediaProvider.\n *\n * Creates a MediaProvider that resolves relative paths by reading binary data\n * from a ContentContainer and generating blob URLs. Blob URLs are cached and\n * revoked on dispose().\n *\n * This allows any ContentContainer (memory, slot-backed, zip-loaded) to be\n * used with existing rendering components (DocPlayer, ImageLayer, VideoLayer)\n * that consume MediaProvider.\n */\n\nimport type { MediaProvider, MediaEntry } from '../schemas/MediaProvider.js';\nimport type { ContentContainer } from './ContentContainer.js';\n\n/**\n * Create a MediaProvider backed by a ContentContainer.\n *\n * @param container — The ContentContainer to read/write media from\n * @returns A MediaProvider that resolves paths to blob URLs\n */\nexport function createMediaProviderFromContainer(container: ContentContainer): MediaProvider {\n const blobUrlCache = new Map<string, string>();\n\n return {\n async resolveUrl(relativePath: string): Promise<string> {\n const cached = blobUrlCache.get(relativePath);\n if (cached) return cached;\n\n const data = await container.readFile(relativePath);\n if (!data) return relativePath;\n\n const entries = await container.listFiles();\n const entry = entries.find((e) => e.path === relativePath);\n const mimeType = entry?.mimeType ?? 'application/octet-stream';\n\n const blob = new Blob([data], { type: mimeType });\n const url = URL.createObjectURL(blob);\n blobUrlCache.set(relativePath, url);\n return url;\n },\n\n async listMedia(): Promise<MediaEntry[]> {\n const entries = await container.listFiles();\n return entries\n .filter((e) => !e.path.toLowerCase().endsWith('.md'))\n .map((e) => ({\n name: e.path,\n mimeType: e.mimeType,\n size: e.size,\n }));\n },\n\n async addMedia(\n name: string,\n data: ArrayBuffer | Blob | Uint8Array,\n mimeType: string,\n ): Promise<string> {\n // Invalidate any cached blob URL for this path before overwriting\n const cached = blobUrlCache.get(name);\n if (cached) {\n URL.revokeObjectURL(cached);\n blobUrlCache.delete(name);\n }\n\n let buffer: ArrayBuffer | Uint8Array;\n if (data instanceof Blob) {\n buffer = await data.arrayBuffer();\n } else {\n buffer = data;\n }\n await container.writeFile(name, buffer, mimeType);\n return name;\n },\n\n async removeMedia(relativePath: string): Promise<void> {\n const cached = blobUrlCache.get(relativePath);\n if (cached) {\n URL.revokeObjectURL(cached);\n blobUrlCache.delete(relativePath);\n }\n await container.removeFile(relativePath);\n },\n\n dispose(): void {\n for (const url of blobUrlCache.values()) {\n URL.revokeObjectURL(url);\n }\n blobUrlCache.clear();\n },\n };\n}\n"],"mappings":";AAOO,IAAM,uBAAN,MAAqD;AAAA,EAArD;AACL,SAAS,sBAAsB;AAC/B,SAAQ,QAAQ,oBAAI,IAAoB;AAAA;AAAA,EAExC,MAAM,IAAO,KAAgC;AAC3C,UAAM,MAAM,KAAK,MAAM,IAAI,GAAG;AAC9B,QAAI,QAAQ,OAAW,QAAO;AAC9B,QAAI;AACF,aAAO,KAAK,MAAM,GAAG;AAAA,IACvB,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF;AAAA,EAEA,MAAM,IAAO,KAAa,OAAyB;AACjD,SAAK,MA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S,aAAa,IAAI,IAAI;AACpC,UAAI,QAAQ;AACV,YAAI,gBAAgB,MAAM;AAC1B,qBAAa,OAAO,IAAI;AAAA,MAC1B;AAEA,UAAI;AACJ,UAAI,gBAAgB,MAAM;AACxB,iBAAS,MAAM,KAAK,YAAY;AAAA,MAClC,OAAO;AACL,iBAAS;AAAA,MACX;AACA,YAAM,UAAU,UAAU,MAAM,QAAQ,QAAQ;AAChD,aAAO;AAAA,IACT;AAAA,IAEA,MAAM,YAAY,cAAqC;AACrD,YAAM,SAAS,aAAa,IAAI,YAAY;AAC5C,UAAI,QAAQ;AACV,YAAI,gBAAgB,MAAM;AAC1B,qBAAa,OAAO,YAAY;AAAA,MAClC;AACA,YAAM,UAAU,WAAW,YAAY;AAAA,IACzC;AAAA,IAEA,UAAgB;AACd,iBAAW,OAAO,aAAa,OAAO,GAAG;AACvC,YAAI,gBAAgB,GAAG;AAAA,MACzB;AACA,mBAAa,MAAM;AAAA,IACrB;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ContentContainer — virtual file system for document containers.
|
|
3
|
+
*
|
|
4
|
+
* A Squisq document is more than just markdown: it's a container of files
|
|
5
|
+
* including the primary markdown document, images, audio, timing data, and
|
|
6
|
+
* other media. ContentContainer provides an abstract async file system
|
|
7
|
+
* interface for reading, writing, and listing these files.
|
|
8
|
+
*
|
|
9
|
+
* Paths are forward-slash separated strings relative to the container root
|
|
10
|
+
* (e.g., 'images/hero.jpg', 'index.md'). No leading slash.
|
|
11
|
+
*
|
|
12
|
+
* Implementations:
|
|
13
|
+
* - MemoryContentContainer — in-memory Map (for zip import, tests, transient use)
|
|
14
|
+
* - SlotContentContainer — backed by IndexedDB slot storage (in the site package)
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Metadata about a file in a ContentContainer.
|
|
18
|
+
*/
|
|
19
|
+
export interface ContentEntry {
|
|
20
|
+
/** Relative path within the container (e.g., 'images/hero.jpg') */
|
|
21
|
+
path: string;
|
|
22
|
+
/** MIME type (e.g., 'image/jpeg') */
|
|
23
|
+
mimeType: string;
|
|
24
|
+
/** File size in bytes */
|
|
25
|
+
size: number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Abstract async file system for document containers.
|
|
29
|
+
*
|
|
30
|
+
* All paths are forward-slash separated, relative to the container root,
|
|
31
|
+
* with no leading slash. Example: 'images/hero.jpg', 'index.md'.
|
|
32
|
+
*/
|
|
33
|
+
export interface ContentContainer {
|
|
34
|
+
/** Read a file's binary content. Returns null if the file does not exist. */
|
|
35
|
+
readFile(path: string): Promise<ArrayBuffer | null>;
|
|
36
|
+
/** Write a file. Creates or overwrites. */
|
|
37
|
+
writeFile(path: string, data: ArrayBuffer | Uint8Array, mimeType?: string): Promise<void>;
|
|
38
|
+
/** Remove a file. No-op if the file does not exist. */
|
|
39
|
+
removeFile(path: string): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* List files in the container.
|
|
42
|
+
* @param prefix — Optional path prefix to filter by (e.g., 'images/')
|
|
43
|
+
*/
|
|
44
|
+
listFiles(prefix?: string): Promise<ContentEntry[]>;
|
|
45
|
+
/** Check whether a file exists. */
|
|
46
|
+
exists(path: string): Promise<boolean>;
|
|
47
|
+
/**
|
|
48
|
+
* Find the primary markdown document path.
|
|
49
|
+
*
|
|
50
|
+
* Discovery order: index.md → doc.md → document.md → first *.md at root.
|
|
51
|
+
* Returns null if no markdown file is found at the root level.
|
|
52
|
+
*/
|
|
53
|
+
getDocumentPath(): Promise<string | null>;
|
|
54
|
+
/**
|
|
55
|
+
* Convenience: read the primary markdown document as a UTF-8 string.
|
|
56
|
+
* Returns null if no markdown file is found.
|
|
57
|
+
*/
|
|
58
|
+
readDocument(): Promise<string | null>;
|
|
59
|
+
/**
|
|
60
|
+
* Convenience: write a markdown document.
|
|
61
|
+
* @param markdown — The markdown content
|
|
62
|
+
* @param filename — Filename to use (defaults to 'index.md')
|
|
63
|
+
*/
|
|
64
|
+
writeDocument(markdown: string, filename?: string): Promise<void>;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Find the primary markdown path from a list of file entries.
|
|
68
|
+
* Exported for reuse by other ContentContainer implementations.
|
|
69
|
+
*/
|
|
70
|
+
export declare function findDocumentPath(entries: ContentEntry[]): string | null;
|
|
71
|
+
/**
|
|
72
|
+
* In-memory ContentContainer backed by a Map.
|
|
73
|
+
*
|
|
74
|
+
* Used for zip import (deserialize into memory), tests, and transient operations.
|
|
75
|
+
*/
|
|
76
|
+
export declare class MemoryContentContainer implements ContentContainer {
|
|
77
|
+
private files;
|
|
78
|
+
readFile(path: string): Promise<ArrayBuffer | null>;
|
|
79
|
+
writeFile(path: string, data: ArrayBuffer | Uint8Array, mimeType?: string): Promise<void>;
|
|
80
|
+
removeFile(path: string): Promise<void>;
|
|
81
|
+
listFiles(prefix?: string): Promise<ContentEntry[]>;
|
|
82
|
+
exists(path: string): Promise<boolean>;
|
|
83
|
+
getDocumentPath(): Promise<string | null>;
|
|
84
|
+
readDocument(): Promise<string | null>;
|
|
85
|
+
writeDocument(markdown: string, filename?: string): Promise<void>;
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=ContentContainer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContentContainer.d.ts","sourceRoot":"","sources":["../../src/storage/ContentContainer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,mEAAmE;IACnE,IAAI,EAAE,MAAM,CAAC;IACb,qCAAqC;IACrC,QAAQ,EAAE,MAAM,CAAC;IACjB,yBAAyB;IACzB,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB;IAC/B,6EAA6E;IAC7E,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,C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,YAAY,EAAE,CAAC;IAanD,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAItC,eAAe,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAIzC,YAAY,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAQtC,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAKxE"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ContentContainer — virtual file system for document containers.
|
|
3
|
+
*
|
|
4
|
+
* A Squisq document is more than just markdown: it's a container of files
|
|
5
|
+
* including the primary markdown document, images, audio, timing data, and
|
|
6
|
+
* other media. ContentContainer provides an abstract async file system
|
|
7
|
+
* interface for reading, writing, and listing these files.
|
|
8
|
+
*
|
|
9
|
+
* Paths are forward-slash separated strings relative to the container root
|
|
10
|
+
* (e.g., 'images/hero.jpg', 'index.md'). No leading slash.
|
|
11
|
+
*
|
|
12
|
+
* Implementations:
|
|
13
|
+
* - MemoryContentContainer — in-memory Map (for zip import, tests, transient use)
|
|
14
|
+
* - SlotContentContainer — backed by IndexedDB slot storage (in the site package)
|
|
15
|
+
*/
|
|
16
|
+
// ============================================
|
|
17
|
+
// Well-known markdown filenames in priority order
|
|
18
|
+
// ============================================
|
|
19
|
+
const MARKDOWN_PRIORITY = ['index.md', 'doc.md', 'document.md'];
|
|
20
|
+
/**
|
|
21
|
+
* Find the primary markdown path from a list of file entries.
|
|
22
|
+
* Exported for reuse by other ContentContainer implementations.
|
|
23
|
+
*/
|
|
24
|
+
export function findDocumentPath(entries) {
|
|
25
|
+
// Only consider root-level files (no '/' in path)
|
|
26
|
+
const rootFiles = entries.filter((e) => !e.path.includes('/'));
|
|
27
|
+
for (const name of MARKDOWN_PRIORITY) {
|
|
28
|
+
if (rootFiles.some((e) => e.path.toLowerCase() === name)) {
|
|
29
|
+
return name;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
// Fallback: first .md file at root
|
|
33
|
+
const firstMd = rootFiles.find((e) => e.path.toLowerCase().endsWith('.md'));
|
|
34
|
+
return firstMd?.path ?? null;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* In-memory ContentContainer backed by a Map.
|
|
38
|
+
*
|
|
39
|
+
* Used for zip import (deserialize into memory), tests, and transient operations.
|
|
40
|
+
*/
|
|
41
|
+
export class MemoryContentContainer {
|
|
42
|
+
constructor() {
|
|
43
|
+
this.files = new Map();
|
|
44
|
+
}
|
|
45
|
+
async readFile(path) {
|
|
46
|
+
return this.files.get(path)?.data ?? null;
|
|
47
|
+
}
|
|
48
|
+
async writeFile(path, data, mimeType) {
|
|
49
|
+
const buffer = data instanceof ArrayBuffer ? data : data.slice().buffer;
|
|
50
|
+
this.files.set(path, {
|
|
51
|
+
data: buffer,
|
|
52
|
+
mimeType: mimeType ?? guessMimeType(path),
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
async removeFile(path) {
|
|
56
|
+
this.files.delete(path);
|
|
57
|
+
}
|
|
58
|
+
async listFiles(prefix) {
|
|
59
|
+
const entries = [];
|
|
60
|
+
for (const [path, file] of this.files) {
|
|
61
|
+
if (prefix && !path.startsWith(prefix))
|
|
62
|
+
continue;
|
|
63
|
+
entries.push({
|
|
64
|
+
path,
|
|
65
|
+
mimeType: file.mimeType,
|
|
66
|
+
size: file.data.byteLength,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
return entries;
|
|
70
|
+
}
|
|
71
|
+
async exists(path) {
|
|
72
|
+
return this.files.has(path);
|
|
73
|
+
}
|
|
74
|
+
async getDocumentPath() {
|
|
75
|
+
return findDocumentPath(await this.listFiles());
|
|
76
|
+
}
|
|
77
|
+
async readDocument() {
|
|
78
|
+
const docPath = await this.getDocumentPath();
|
|
79
|
+
if (!docPath)
|
|
80
|
+
return null;
|
|
81
|
+
const data = await this.readFile(docPath);
|
|
82
|
+
if (!data)
|
|
83
|
+
return null;
|
|
84
|
+
return new TextDecoder().decode(data);
|
|
85
|
+
}
|
|
86
|
+
async writeDocument(markdown, filename) {
|
|
87
|
+
const name = filename ?? 'index.md';
|
|
88
|
+
const data = new TextEncoder().encode(markdown);
|
|
89
|
+
await this.writeFile(name, data, 'text/markdown');
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
// ============================================
|
|
93
|
+
// MIME type guessing
|
|
94
|
+
// ============================================
|
|
95
|
+
const EXTENSION_MIME_MAP = {
|
|
96
|
+
'.md': 'text/markdown',
|
|
97
|
+
'.txt': 'text/plain',
|
|
98
|
+
'.json': 'application/json',
|
|
99
|
+
'.jpg': 'image/jpeg',
|
|
100
|
+
'.jpeg': 'image/jpeg',
|
|
101
|
+
'.png': 'image/png',
|
|
102
|
+
'.gif': 'image/gif',
|
|
103
|
+
'.svg': 'image/svg+xml',
|
|
104
|
+
'.webp': 'image/webp',
|
|
105
|
+
'.avif': 'image/avif',
|
|
106
|
+
'.mp4': 'video/mp4',
|
|
107
|
+
'.webm': 'video/webm',
|
|
108
|
+
'.mp3': 'audio/mpeg',
|
|
109
|
+
'.wav': 'audio/wav',
|
|
110
|
+
'.ogg': 'audio/ogg',
|
|
111
|
+
'.css': 'text/css',
|
|
112
|
+
'.html': 'text/html',
|
|
113
|
+
'.js': 'application/javascript',
|
|
114
|
+
};
|
|
115
|
+
function guessMimeType(path) {
|
|
116
|
+
const dot = path.lastIndexOf('.');
|
|
117
|
+
if (dot === -1)
|
|
118
|
+
return 'application/octet-stream';
|
|
119
|
+
const ext = path.slice(dot).toLowerCase();
|
|
120
|
+
return EXTENSION_MIME_MAP[ext] ?? 'application/octet-stream';
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=ContentContainer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContentContainer.js","sourceRoot":"","sources":["../../src/storage/ContentContainer.ts"],"names":[],"mappings":"AAAA;;;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ainer — bridges ContentContainer to MediaProvider.
|
|
3
|
+
*
|
|
4
|
+
* Creates a MediaProvider that resolves relative paths by reading binary data
|
|
5
|
+
* from a ContentContainer and generating blob URLs. Blob URLs are cached and
|
|
6
|
+
* revoked on dispose().
|
|
7
|
+
*
|
|
8
|
+
* This allows any ContentContainer (memory, slot-backed, zip-loaded) to be
|
|
9
|
+
* used with existing rendering components (DocPlayer, ImageLayer, VideoLayer)
|
|
10
|
+
* that consume MediaProvider.
|
|
11
|
+
*/
|
|
12
|
+
import type { MediaProvider } from '../schemas/MediaProvider.js';
|
|
13
|
+
import type { ContentContainer } from './ContentContainer.js';
|
|
14
|
+
/**
|
|
15
|
+
* Create a MediaProvider backed by a ContentContainer.
|
|
16
|
+
*
|
|
17
|
+
* @param container — The ContentContainer to read/write media from
|
|
18
|
+
* @returns A MediaProvider that resolves paths to blob URLs
|
|
19
|
+
*/
|
|
20
|
+
export declare function createMediaProviderFromContainer(container: ContentContainer): MediaProvider;
|
|
21
|
+
//# sourceMappingURL=MediaProviderFromContainer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MediaProviderFromContainer.d.ts","sourceRoot":"","sources":["../../src/storage/MediaProviderFromContainer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAc,MAAM,6BAA6B,CAAC;AAC7E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE9D;;;;;GAKG;AACH,wBAAgB,gCAAgC,CAAC,SAAS,EAAE,gBAAgB,GAAG,aAAa,CAsE3F"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MediaProviderFromContainer — bridges ContentContainer to MediaProvider.
|
|
3
|
+
*
|
|
4
|
+
* Creates a MediaProvider that resolves relative paths by reading binary data
|
|
5
|
+
* from a ContentContainer and generating blob URLs. Blob URLs are cached and
|
|
6
|
+
* revoked on dispose().
|
|
7
|
+
*
|
|
8
|
+
* This allows any ContentContainer (memory, slot-backed, zip-loaded) to be
|
|
9
|
+
* used with existing rendering components (DocPlayer, ImageLayer, VideoLayer)
|
|
10
|
+
* that consume MediaProvider.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Create a MediaProvider backed by a ContentContainer.
|
|
14
|
+
*
|
|
15
|
+
* @param container — The ContentContainer to read/write media from
|
|
16
|
+
* @returns A MediaProvider that resolves paths to blob URLs
|
|
17
|
+
*/
|
|
18
|
+
export function createMediaProviderFromContainer(container) {
|
|
19
|
+
const blobUrlCache = new Map();
|
|
20
|
+
return {
|
|
21
|
+
async resolveUrl(relativePath) {
|
|
22
|
+
const cached = blobUrlCache.get(relativePath);
|
|
23
|
+
if (cached)
|
|
24
|
+
return cached;
|
|
25
|
+
const data = await container.readFile(relativePath);
|
|
26
|
+
if (!data)
|
|
27
|
+
return relativePath;
|
|
28
|
+
const entries = await container.listFiles();
|
|
29
|
+
const entry = entries.find((e) => e.path === relativePath);
|
|
30
|
+
const mimeType = entry?.mimeType ?? 'application/octet-stream';
|
|
31
|
+
const blob = new Blob([data], { type: mimeType });
|
|
32
|
+
const url = URL.createObjectURL(blob);
|
|
33
|
+
blobUrlCache.set(relativePath, url);
|
|
34
|
+
return url;
|
|
35
|
+
},
|
|
36
|
+
async listMedia() {
|
|
37
|
+
const entries = await container.listFiles();
|
|
38
|
+
return entries
|
|
39
|
+
.filter((e) => !e.path.toLowerCase().endsWith('.md'))
|
|
40
|
+
.map((e) => ({
|
|
41
|
+
name: e.path,
|
|
42
|
+
mimeType: e.mimeType,
|
|
43
|
+
size: e.size,
|
|
44
|
+
}));
|
|
45
|
+
},
|
|
46
|
+
async addMedia(name, data, mimeType) {
|
|
47
|
+
// Invalidate any cached blob URL for this path before overwriting
|
|
48
|
+
const cached = blobUrlCache.get(name);
|
|
49
|
+
if (cached) {
|
|
50
|
+
URL.revokeObjectURL(cached);
|
|
51
|
+
blobUrlCache.delete(name);
|
|
52
|
+
}
|
|
53
|
+
let buffer;
|
|
54
|
+
if (data instanceof Blob) {
|
|
55
|
+
buffer = await data.arrayBuffer();
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
buffer = data;
|
|
59
|
+
}
|
|
60
|
+
await container.writeFile(name, buffer, mimeType);
|
|
61
|
+
return name;
|
|
62
|
+
},
|
|
63
|
+
async removeMedia(relativePath) {
|
|
64
|
+
const cached = blobUrlCache.get(relativePath);
|
|
65
|
+
if (cached) {
|
|
66
|
+
URL.revokeObjectURL(cached);
|
|
67
|
+
blobUrlCache.delete(relativePath);
|
|
68
|
+
}
|
|
69
|
+
await container.removeFile(relativePath);
|
|
70
|
+
},
|
|
71
|
+
dispose() {
|
|
72
|
+
for (const url of blobUrlCache.values()) {
|
|
73
|
+
URL.revokeObjectURL(url);
|
|
74
|
+
}
|
|
75
|
+
blobUrlCache.clear();
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=MediaProviderFromContainer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MediaProviderFromContainer.js","sourceRoot":"","sources":["../../src/storage/MediaProviderFromContainer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAKH;;;;;GAKG;AACH,MAAM,UAAU,gCAAgC,CAAC,SAA2B;IAC1E,MAAM,YAAY,GAAG,IAAI,GAAG,EAAkB,CAAC;IAE/C,OAAO;QACL,KAAK,CAAC,UAAU,CAAC,YAAoB;YACnC,MAAM,MAAM,GAAG,YAAY,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;YAC9C,IAAI,MAAM;gBAAE,OAAO,MAAM,CAAC;YAE1B,MAAM,IAAI,GAAG,MAAM,SAAS,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;YACpD,IAAI,CAAC,IAAI;gBAAE,OAAO,YAAY,CAAC;YAE/B,MAAM,OAAO,GAAG,MAAM,SAAS,CAAC,SAAS,EAAE,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AAI,EAAE,CAAC;gBACzB,MAAM,GAAG,MAAM,IAAI,CAAC,WAAW,EAAE,CAAC;YACpC,CAAC;iBAAM,CAAC;gBACN,MAAM,GAAG,IAAI,CAAC;YAChB,CAAC;YACD,MAAM,SAAS,CAAC,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;YAClD,OAAO,IAAI,CAAC;QACd,CAAC;QAED,KAAK,CAAC,WAAW,CAAC,YAAoB;YACpC,MAAM,MAAM,GAAG,YAAY,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;YAC9C,IAAI,MAAM,EAAE,CAAC;gBACX,GAAG,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;gBAC5B,YAAY,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;YACpC,CAAC;YACD,MAAM,SAAS,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;QAC3C,CAAC;QAED,OAAO;YACL,KAAK,MAAM,GAAG,IAAI,YAAY,CAAC,MAAM,EAAE,EAAE,CAAC;gBACxC,GAAG,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;YAC3B,CAAC;YACD,YAAY,CAAC,KAAK,EAAE,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/storage/index.d.ts
CHANGED
|
@@ -3,4 +3,7 @@ export { MemoryStorageAdapter } from './MemoryStorageAdapter.js';
|
|
|
3
3
|
export { LocalStorageAdapter } from './LocalStorageAdapter.js';
|
|
4
4
|
export { LocalForageAdapter } from './LocalForageAdapter.js';
|
|
5
5
|
export type { LocalForageAdapterOptions } from './LocalForageAdapter.js';
|
|
6
|
+
export type { ContentContainer, ContentEntry } from './ContentContainer.js';
|
|
7
|
+
export { MemoryContentContainer, findDocumentPath } from './ContentContainer.js';
|
|
8
|
+
export { createMediaProviderFromContainer } from './MediaProviderFromContainer.js';
|
|
6
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/storage/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,YAAY,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/storage/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,YAAY,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AACzE,YAAY,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAC5E,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACjF,OAAO,EAAE,gCAAgC,EAAE,MAAM,iCAAiC,CAAC"}
|
package/dist/storage/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export { MemoryStorageAdapter } from './MemoryStorageAdapter.js';
|
|
2
2
|
export { LocalStorageAdapter } from './LocalStorageAdapter.js';
|
|
3
3
|
export { LocalForageAdapter } from './LocalForageAdapter.js';
|
|
4
|
+
export { MemoryContentContainer, findDocumentPath } from './ContentContainer.js';
|
|
5
|
+
export { createMediaProviderFromContainer } from './MediaProviderFromContainer.js';
|
|
4
6
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/storage/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/storage/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAG7D,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACjF,OAAO,EAAE,gCAAgC,EAAE,MAAM,iCAAiC,CAAC"}
|