Capability first · transport second

MarkdownMedia.js

Stores complete local image records separately from Markdown and hydrates their stable references in rendered views.

SDK 0.97.1Runtime 0.8.12Protocol arcane/1
On this page

Overview

Stores complete local image records separately from Markdown and hydrates their stable references in rendered views.

  • Artifact
    MarkdownMedia.js · esm
  • Classification
    public first party
  • Availability
    Browser/native WebView with Blob, DOM, object URLs, and application-owned DBOPFS for storage operations
  • Normalization
    Pure record decoding preserves complete content and singleton record layers. Hydration starts independent reads, removes unresolved local image sources before insertion, preserves successful siblings after an image failure, and owns cancellation, display URLs, and retained print resources.

Import and lifecycle

JavaScript
import * as module from '/node_modules/arcane-os/runtime/arcane/modules/MarkdownMedia.js';

Import starts no storage or rendering work. Saving lazily opens the existing app DBOPFS database and completes one JSON-compatible image write. Hydration reads independent local references concurrently, owns temporary display URLs, and retains print resources through the returned release callbacks. Destruction cancels display readiness without deleting records or claiming to cancel an already-started storage read.

Application-facing behavior: saveMarkdownMedia({blob,tableName,fileName}), parseMarkdownMediaReference(reference), decodeMarkdownMediaRecord(value), readMarkdownMedia(reference), and hydrateMarkdownMedia(root,{signal}) returning ready/destroy/retain.

Protocol and host implementation

arcane-media references, complete mediaType/dataUrl records, and DBOPFS This detail does not widen the application-facing API or grant authority.

Exports, signatures, parameters, and results

BindingFormDeclaration or signatureParameter syntax
parseMarkdownMediaReferencefunctionfunction parseMarkdownMediaReference(reference)reference
saveMarkdownMediafunctionasync function saveMarkdownMedia({ blob, tableName = 'markdown-media', fileName = `${crypto.randomUUID()}.json` }){ blob, tableName = 'markdown-media', fileName = `${crypto.randomUUID()}.json` }
decodeMarkdownMediaRecordfunctionfunction decodeMarkdownMediaRecord(value)value
readMarkdownMediafunctionasync function readMarkdownMedia(reference)reference
hydrateMarkdownMediafunctionfunction hydrateMarkdownMedia(root, {signal} = {})root, {signal} = {}

Parameter meanings and results

saveMarkdownMedia({blob,tableName="markdown-media",fileName=UUID+".json"}) resolves {reference,tableName,fileName,mediaType} after saving the complete {mediaType,dataUrl} record. parseMarkdownMediaReference(reference) returns {tableName,fileName} or null for ordinary URLs. decodeMarkdownMediaRecord(value) synchronously returns a Blob for a complete {dataUrl,mediaType?} record or its JSON text, unwrapping nested single-record arrays without selecting from multiple records. Unrecognized content, including unreadable JSON text, returns null; recognized records with unreadable encoding throw. Omitted mediaType keeps the empty Blob type. It changes no input and performs no storage or network work. readMarkdownMedia(reference) loads and decodes the complete local Blob, preserving stored-JSON parse errors and reporting unreadable records as errors rather than null. hydrateMarkdownMedia(root,{signal}={}) returns {ready,destroy,retain}; local IMG sources are removed synchronously before asynchronous reads and decode, and ordinary URLs/source content remain unchanged. Use a detached root before insertion. retain returns an idempotent print-resource release callback; destroyed owners preserve URLs until every holder releases.

Events, side effects, and errors

Source-literal CustomEvent dispatches

No source-literal CustomEvent dispatch is part of this artifact.

Lifecycle and event flow

This artifact has no additional documented lifecycle event flow.

Direct coded failures

This artifact directly assigns no stable coded failure.

Exported Error subclasses

This artifact exports no Error subclass.

Documented failure behavior

  • Complete encoding, DBOPFS, reference parsing, and image decoding errors propagate. Missing local records reject with NotFoundError. decodeMarkdownMediaRecord returns null for unrecognized content; recognized unreadable data URLs throw TypeError or the platform decoding error.
  • Hydration ready rejects AggregateError with complete failures [{image,reference,reason}] while preserving successfully displayed siblings. Abort or destroy settles display readiness promptly and prevents late assignment.

Availability and capabilities

Browser/native WebView with Blob, DOM, object URLs, and application-owned DBOPFS for storage operations. Pure record decoding preserves complete content and singleton record layers. Hydration starts independent reads, removes unresolved local image sources before insertion, preserves successful siblings after an image failure, and owns cancellation, display URLs, and retained print resources.

Browser/native WebView app-scoped DBOPFS, Blob, FileReader, object URLs, and IMG decoding; no Core capability or provider execution. Applications own filenames, entry associations, save-only retry, cleanup and backup/export selection. No migration.

Contract example

JavaScript
import {saveMarkdownMedia} from 'arcane-os/modules/MarkdownMedia.js';

const mural = new Blob([
    '<svg xmlns="http://www.w3.org/2000/svg" width="240" height="80"><text x="10" y="45">Octopus parking only</text></svg>'
], {type:'image/svg+xml'});
const {reference} = await saveMarkdownMedia({blob:mural});
// editor is the ready shared Markdown Editor; its usual save flow remains in charge.
editor.insertMarkdown('![Octopus parking only](' + reference + ')');

No direct Core call is claimed for this artifact. Any injected provider or consuming module retains its own documented authority.