Resolve default image sizes atomically with creation history and recovery

This commit is contained in:
2026-11-09 00:25:18 +08:00
parent fa7dad44e7
commit 5919eb0453
20 changed files with 456 additions and 40 deletions
+4 -2
View File
@@ -1,4 +1,5 @@
import type {ImageDecodeState} from './image-decoder.ts';
import type { DefaultImageSizing } from './default-image-size.ts';
import type { Change, CoreSnapshot, Document, ElementRecord, Id, OperationIntent, Registry } from '../canvas-core/types.ts';
import { historyTransitionChanges } from '../canvas-core/history-transition.ts';
import { ancestors } from '../canvas-core/document.ts';
@@ -7,7 +8,7 @@ import type { OperationStatus } from './scheduler.ts';
import { readMap, readSet } from '../canvas-core/values.ts';
export type StoredAsset = { readonly id: Id; readonly url: string; readonly width: number; readonly height: number; readonly bytes: number; readonly mime_type: string };
export type ResourceRecord = { readonly id: Id; readonly operationId: Id; readonly name: string; readonly mimeType: string; readonly byteLength: number; readonly image?:ImageDecodeState; readonly digest?: string; readonly retirement?: {readonly version:1;readonly unreferencedAt:number;readonly purgedAt?:number}; readonly stored?: StoredAsset };
export type ResourceRecord = { readonly id: Id; readonly operationId: Id; readonly name: string; readonly mimeType: string; readonly byteLength: number; readonly sizing?: DefaultImageSizing; readonly image?:ImageDecodeState; readonly digest?: string; readonly retirement?: {readonly version:1;readonly unreferencedAt:number;readonly purgedAt?:number}; readonly stored?: StoredAsset };
export type DisplayHandle = { readonly url: string; release(): void };
export type AssetPort = {
sourceURL(resourceId: Id): string;
@@ -16,7 +17,7 @@ export type AssetPort = {
query(request: FrozenRequest, signal: AbortSignal): Promise<OperationStatus>;
accept(request: FrozenRequest, status: OperationStatus, resource: ResourceRecord): StoredAsset;
};
export type StagedFile = { readonly bytes: Blob; readonly name: string };
export type StagedFile = { readonly bytes: Blob; readonly name: string; readonly defaultSize?: boolean };
export type ResourceHandle = { readonly id: Id; readonly src: string };
export const maxResourceBytes = 20 * 1024 * 1024;
@@ -105,6 +106,7 @@ export function resourcePins(snapshot: CoreSnapshot, ledger: LedgerSnapshot, reg
else changes(record.intent.changes, `operation:${record.intent.id}`);
}
const pending=[...ledger.operations.values()].filter(record=>record.phase!=='resolved'),earliest=pending.reduce((value,record)=>Math.min(value,record.intent.sequence),Infinity);
for (const record of ledger.operations.values()) if (record.intent.historyEffect && record.intent.historyEffect.version !== 1) complete = false;
for(const record of ledger.operations.values())if(record.intent.sequence>=earliest&&record.intent.historyTransition){
if(record.intent.historyTransition.version!==1){complete=false;continue;}
changes(historyTransitionChanges(record.intent.historyTransition),`history-transition:${record.intent.id}`);