Skip to content

Turn any idea, plan, or codebase into a beautiful interactive diagram. An agent skill for Claude Code, Codex, and more.

build(viewer): refresh artifacts for WebM failure recovery

To3akaRinfe2cc31eadfe
diff --git a/archify.zip b/archify.zip
index be5cde98..2ac0ac75 100644
Binary files a/archify.zip and b/archify.zip differ
diff --git a/archify/examples/dataflow-product-analytics.html b/archify/examples/dataflow-product-analytics.html
index d454321b..83db25a4 100644
--- a/archify/examples/dataflow-product-analytics.html
+++ b/archify/examples/dataflow-product-analytics.html
@@ -6659,7 +6659,6 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
var vb = svg.viewBox.baseVal;
var scale = Math.min(1, 1280 / vb.width);
var data = serializeSvg(scale);
- var sourceUrl = URL.createObjectURL(new Blob([data.svgString], { type: 'image/svg+xml;charset=utf-8' }));
function createMotionScene(root) {
var rootMatrix = root.getCTM ? root.getCTM() : null;
@@ -6811,73 +6810,99 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
var motionScene = createMotionScene(svg);
return new Promise(function (resolve, reject) {
- var backgroundImage = new Image();
- backgroundImage.onload = function () {
- var canvas = document.createElement('canvas');
- canvas.width = Math.max(2, Math.round(data.width / 2) * 2);
- canvas.height = Math.max(2, Math.round(data.height / 2) * 2);
- var ctx = canvas.getContext('2d');
- var stream = canvas.captureStream(fps);
- var mime = motionMimeType();
- var recorder;
- try {
- recorder = new MediaRecorder(stream, { mimeType: mime, videoBitsPerSecond: 6000000 });
- } catch (err) {
- URL.revokeObjectURL(sourceUrl);
- stream.getTracks().forEach(function (track) { track.stop(); });
- reject(err);
- return;
- }
- var chunks = [];
- var raf = 0;
- var stopped = false;
- var startedAt = performance.now();
- function cleanup() {
- if (stopped) return;
- stopped = true;
- cancelAnimationFrame(raf);
- URL.revokeObjectURL(sourceUrl);
- stream.getTracks().forEach(function (track) { track.stop(); });
+ var sourceUrl = null;
+ var backgroundImage = null;
+ var stream = null;
+ var recorder = null;
+ var raf = 0;
+ var durationTimer = 0;
+ var flushTimer = 0;
+ var settled = false;
+
+ function finish(error, blob) {
+ if (settled) return;
+ // 先锁定终态:停止录制和释放流可能产生晚到的编码事件。
+ settled = true;
+ cancelAnimationFrame(raf);
+ clearTimeout(durationTimer);
+ clearTimeout(flushTimer);
+ if (backgroundImage) {
+ backgroundImage.onload = null;
+ backgroundImage.onerror = null;
}
- function draw(now) {
- var elapsed = Math.max(0, ((Number(now) || performance.now()) - startedAt) / 1000);
- drawMotionFrame(ctx, backgroundImage, motionScene, elapsed);
- raf = requestAnimationFrame(draw);
+ if (recorder) {
+ recorder.ondataavailable = null;
+ recorder.onerror = null;
+ recorder.onstop = null;
+ try { if (recorder.state !== 'inactive') recorder.stop(); } catch (_) {}
}
- recorder.ondataavailable = function (event) {
- if (event.data && event.data.size) chunks.push(event.data);
- };
- recorder.onerror = function (event) {
- cleanup();
- reject(event.error || exportError('viewer.export.error.mediaRecorder'));
+ if (stream) stream.getTracks().forEach(function (track) { track.stop(); });
+ if (sourceUrl) URL.revokeObjectURL(sourceUrl);
+ if (blob) resolve(blob);
+ else reject(error);
+ }
+
+ try {
+ sourceUrl = URL.createObjectURL(new Blob([data.svgString], { type: 'image/svg+xml;charset=utf-8' }));
+ backgroundImage = new Image();
+ backgroundImage.onload = function () {
+ if (settled) return;
+ try {
+ var canvas = document.createElement('canvas');
+ canvas.width = Math.max(2, Math.round(data.width / 2) * 2);
+ canvas.height = Math.max(2, Math.round(data.height / 2) * 2);
+ var ctx = canvas.getContext('2d');
+ if (!ctx) throw exportError('viewer.export.error.contextUnavailable', { label: 'WebM' });
+ stream = canvas.captureStream(fps);
+ var mime = motionMimeType();
+ recorder = new MediaRecorder(stream, { mimeType: mime, videoBitsPerSecond: 6000000 });
+ var chunks = [];
+ var startedAt = performance.now();
+ function draw(now) {
+ if (settled) return;
+ try {
+ var elapsed = Math.max(0, ((Number(now) || performance.now()) - startedAt) / 1000);
+ drawMotionFrame(ctx, backgroundImage, motionScene, elapsed);
+ raf = requestAnimationFrame(draw);
+ } catch (error) { finish(error); }
+ }
+ recorder.ondataavailable = function (event) {
+ if (!settled && event.data && event.data.size) chunks.push(event.data);
+ };
+ recorder.onerror = function (event) {
+ finish(event.error || exportError('viewer.export.error.mediaRecorder'));
+ };
+ recorder.onstop = function () {
+ if (settled) return;
+ try {
+ var blob = new Blob(chunks, { type: recorder.mimeType || mime });
+ if (!blob.size) throw exportError('viewer.export.error.emptyWebm');
+ finish(null, blob);
+ } catch (error) { finish(error); }
+ };
+ drawMotionFrame(ctx, backgroundImage, motionScene, 0);
+ recorder.start(250);
+ if (settled) return;
+ startedAt = performance.now();
+ raf = requestAnimationFrame(draw);
+ durationTimer = setTimeout(function () {
+ if (settled || recorder.state === 'inactive') return;
+ // 保留最佳努力的编码器 flush;失败后仍通过 stop 收集最后的片段。
+ try { recorder.requestData(); } catch (_) {}
+ if (settled) return;
+ flushTimer = setTimeout(function () {
+ if (settled) return;
+ try { if (recorder.state !== 'inactive') recorder.stop(); }
+ catch (error) { finish(error); }
+ }, 120);
+ }, duration);
+ } catch (error) { finish(error); }
};
- recorder.onstop = function () {
- cleanup();
- var blob = new Blob(chunks, { type: recorder.mimeType || mime });
- if (!blob.size) reject(exportError('viewer.export.error.emptyWebm'));
- else resolve(blob);
+ backgroundImage.onerror = function () {
+ finish(exportError('viewer.export.error.webmBackground'));
};
- drawMotionFrame(ctx, backgroundImage, motionScene, 0);
- recorder.start(250);
- startedAt = performance.now();
- raf = requestAnimationFrame(draw);
- setTimeout(function () {
- if (recorder.state === 'inactive') return;
- // Chromium normally emits the final chunk during stop(), but
- // some embedded browser shells need an explicit encoder flush
- // first. Keep the short grace window bounded and harmless for
- // browsers that already delivered timeslice chunks.
- try { recorder.requestData(); } catch (_) {}
- setTimeout(function () {
- if (recorder.state !== 'inactive') recorder.stop();
- }, 120);
- }, duration);
- };
- backgroundImage.onerror = function () {
- URL.revokeObjectURL(sourceUrl);
- reject(exportError('viewer.export.error.webmBackground'));
- };
- backgroundImage.src = sourceUrl;
+ backgroundImage.src = sourceUrl;
+ } catch (error) { finish(error); }
});
}
diff --git a/archify/examples/lifecycle-agent-run.html b/archify/examples/lifecycle-agent-run.html
index 5b600983..bbcea1cb 100644
--- a/archify/examples/lifecycle-agent-run.html
+++ b/archify/examples/lifecycle-agent-run.html
@@ -6604,7 +6604,6 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
var vb = svg.viewBox.baseVal;
var scale = Math.min(1, 1280 / vb.width);
var data = serializeSvg(scale);
- var sourceUrl = URL.createObjectURL(new Blob([data.svgString], { type: 'image/svg+xml;charset=utf-8' }));
function createMotionScene(root) {
var rootMatrix = root.getCTM ? root.getCTM() : null;
@@ -6756,73 +6755,99 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
var motionScene = createMotionScene(svg);
return new Promise(function (resolve, reject) {
- var backgroundImage = new Image();
- backgroundImage.onload = function () {
- var canvas = document.createElement('canvas');
- canvas.width = Math.max(2, Math.round(data.width / 2) * 2);
- canvas.height = Math.max(2, Math.round(data.height / 2) * 2);
- var ctx = canvas.getContext('2d');
- var stream = canvas.captureStream(fps);
- var mime = motionMimeType();
- var recorder;
- try {
- recorder = new MediaRecorder(stream, { mimeType: mime, videoBitsPerSecond: 6000000 });
- } catch (err) {
- URL.revokeObjectURL(sourceUrl);
- stream.getTracks().forEach(function (track) { track.stop(); });
- reject(err);
- return;
- }
- var chunks = [];
- var raf = 0;
- var stopped = false;
- var startedAt = performance.now();
- function cleanup() {
- if (stopped) return;
- stopped = true;
- cancelAnimationFrame(raf);
- URL.revokeObjectURL(sourceUrl);
- stream.getTracks().forEach(function (track) { track.stop(); });
+ var sourceUrl = null;
+ var backgroundImage = null;
+ var stream = null;
+ var recorder = null;
+ var raf = 0;
+ var durationTimer = 0;
+ var flushTimer = 0;
+ var settled = false;
+
+ function finish(error, blob) {
+ if (settled) return;
+ // 先锁定终态:停止录制和释放流可能产生晚到的编码事件。
+ settled = true;
+ cancelAnimationFrame(raf);
+ clearTimeout(durationTimer);
+ clearTimeout(flushTimer);
+ if (backgroundImage) {
+ backgroundImage.onload = null;
+ backgroundImage.onerror = null;
}
- function draw(now) {
- var elapsed = Math.max(0, ((Number(now) || performance.now()) - startedAt) / 1000);
- drawMotionFrame(ctx, backgroundImage, motionScene, elapsed);
- raf = requestAnimationFrame(draw);
+ if (recorder) {
+ recorder.ondataavailable = null;
+ recorder.onerror = null;
+ recorder.onstop = null;
+ try { if (recorder.state !== 'inactive') recorder.stop(); } catch (_) {}
}
- recorder.ondataavailable = function (event) {
- if (event.data && event.data.size) chunks.push(event.data);
- };
- recorder.onerror = function (event) {
- cleanup();
- reject(event.error || exportError('viewer.export.error.mediaRecorder'));
+ if (stream) stream.getTracks().forEach(function (track) { track.stop(); });
+ if (sourceUrl) URL.revokeObjectURL(sourceUrl);
+ if (blob) resolve(blob);
+ else reject(error);
+ }
+
+ try {
+ sourceUrl = URL.createObjectURL(new Blob([data.svgString], { type: 'image/svg+xml;charset=utf-8' }));
+ backgroundImage = new Image();
+ backgroundImage.onload = function () {
+ if (settled) return;
+ try {
+ var canvas = document.createElement('canvas');
+ canvas.width = Math.max(2, Math.round(data.width / 2) * 2);
+ canvas.height = Math.max(2, Math.round(data.height / 2) * 2);
+ var ctx = canvas.getContext('2d');
+ if (!ctx) throw exportError('viewer.export.error.contextUnavailable', { label: 'WebM' });
+ stream = canvas.captureStream(fps);
+ var mime = motionMimeType();
+ recorder = new MediaRecorder(stream, { mimeType: mime, videoBitsPerSecond: 6000000 });
+ var chunks = [];
+ var startedAt = performance.now();
+ function draw(now) {
+ if (settled) return;
+ try {
+ var elapsed = Math.max(0, ((Number(now) || performance.now()) - startedAt) / 1000);
+ drawMotionFrame(ctx, backgroundImage, motionScene, elapsed);
+ raf = requestAnimationFrame(draw);
+ } catch (error) { finish(error); }
+ }
+ recorder.ondataavailable = function (event) {
+ if (!settled && event.data && event.data.size) chunks.push(event.data);
+ };
+ recorder.onerror = function (event) {
+ finish(event.error || exportError('viewer.export.error.mediaRecorder'));
+ };
+ recorder.onstop = function () {
+ if (settled) return;
+ try {
+ var blob = new Blob(chunks, { type: recorder.mimeType || mime });
+ if (!blob.size) throw exportError('viewer.export.error.emptyWebm');
+ finish(null, blob);
+ } catch (error) { finish(error); }
+ };
+ drawMotionFrame(ctx, backgroundImage, motionScene, 0);
+ recorder.start(250);
+ if (settled) return;
+ startedAt = performance.now();
+ raf = requestAnimationFrame(draw);
+ durationTimer = setTimeout(function () {
+ if (settled || recorder.state === 'inactive') return;
+ // 保留最佳努力的编码器 flush;失败后仍通过 stop 收集最后的片段。
+ try { recorder.requestData(); } catch (_) {}
+ if (settled) return;
+ flushTimer = setTimeout(function () {
+ if (settled) return;
+ try { if (recorder.state !== 'inactive') recorder.stop(); }
+ catch (error) { finish(error); }
+ }, 120);
+ }, duration);
+ } catch (error) { finish(error); }
};
- recorder.onstop = function () {
- cleanup();
- var blob = new Blob(chunks, { type: recorder.mimeType || mime });
- if (!blob.size) reject(exportError('viewer.export.error.emptyWebm'));
- else resolve(blob);
+ backgroundImage.onerror = function () {
+ finish(exportError('viewer.export.error.webmBackground'));
};
- drawMotionFrame(ctx, backgroundImage, motionScene, 0);
- recorder.start(250);
- startedAt = performance.now();
- raf = requestAnimationFrame(draw);
- setTimeout(function () {
- if (recorder.state === 'inactive') return;
- // Chromium normally emits the final chunk during stop(), but
- // some embedded browser shells need an explicit encoder flush
- // first. Keep the short grace window bounded and harmless for
- // browsers that already delivered timeslice chunks.
- try { recorder.requestData(); } catch (_) {}
- setTimeout(function () {
- if (recorder.state !== 'inactive') recorder.stop();
- }, 120);
- }, duration);
- };
- backgroundImage.onerror = function () {
- URL.revokeObjectURL(sourceUrl);
- reject(exportError('viewer.export.error.webmBackground'));
- };
- backgroundImage.src = sourceUrl;
+ backgroundImage.src = sourceUrl;
+ } catch (error) { finish(error); }
});
}
diff --git a/archify/examples/sequence-cache-miss-request.html b/archify/examples/sequence-cache-miss-request.html
index 321c769d..ecea17f6 100644
--- a/archify/examples/sequence-cache-miss-request.html
+++ b/archify/examples/sequence-cache-miss-request.html
@@ -6674,7 +6674,6 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
var vb = svg.viewBox.baseVal;
var scale = Math.min(1, 1280 / vb.width);
var data = serializeSvg(scale);
- var sourceUrl = URL.createObjectURL(new Blob([data.svgString], { type: 'image/svg+xml;charset=utf-8' }));
function createMotionScene(root) {
var rootMatrix = root.getCTM ? root.getCTM() : null;
@@ -6826,73 +6825,99 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
var motionScene = createMotionScene(svg);
return new Promise(function (resolve, reject) {
- var backgroundImage = new Image();
- backgroundImage.onload = function () {
- var canvas = document.createElement('canvas');
- canvas.width = Math.max(2, Math.round(data.width / 2) * 2);
- canvas.height = Math.max(2, Math.round(data.height / 2) * 2);
- var ctx = canvas.getContext('2d');
- var stream = canvas.captureStream(fps);
- var mime = motionMimeType();
- var recorder;
- try {
- recorder = new MediaRecorder(stream, { mimeType: mime, videoBitsPerSecond: 6000000 });
- } catch (err) {
- URL.revokeObjectURL(sourceUrl);
- stream.getTracks().forEach(function (track) { track.stop(); });
- reject(err);
- return;
- }
- var chunks = [];
- var raf = 0;
- var stopped = false;
- var startedAt = performance.now();
- function cleanup() {
- if (stopped) return;
- stopped = true;
- cancelAnimationFrame(raf);
- URL.revokeObjectURL(sourceUrl);
- stream.getTracks().forEach(function (track) { track.stop(); });
+ var sourceUrl = null;
+ var backgroundImage = null;
+ var stream = null;
+ var recorder = null;
+ var raf = 0;
+ var durationTimer = 0;
+ var flushTimer = 0;
+ var settled = false;
+
+ function finish(error, blob) {
+ if (settled) return;
+ // 先锁定终态:停止录制和释放流可能产生晚到的编码事件。
+ settled = true;
+ cancelAnimationFrame(raf);
+ clearTimeout(durationTimer);
+ clearTimeout(flushTimer);
+ if (backgroundImage) {
+ backgroundImage.onload = null;
+ backgroundImage.onerror = null;
}
- function draw(now) {
- var elapsed = Math.max(0, ((Number(now) || performance.now()) - startedAt) / 1000);
- drawMotionFrame(ctx, backgroundImage, motionScene, elapsed);
- raf = requestAnimationFrame(draw);
+ if (recorder) {
+ recorder.ondataavailable = null;
+ recorder.onerror = null;
+ recorder.onstop = null;
+ try { if (recorder.state !== 'inactive') recorder.stop(); } catch (_) {}
}
- recorder.ondataavailable = function (event) {
- if (event.data && event.data.size) chunks.push(event.data);
- };
- recorder.onerror = function (event) {
- cleanup();
- reject(event.error || exportError('viewer.export.error.mediaRecorder'));
+ if (stream) stream.getTracks().forEach(function (track) { track.stop(); });
+ if (sourceUrl) URL.revokeObjectURL(sourceUrl);
+ if (blob) resolve(blob);
+ else reject(error);
+ }
+
+ try {
+ sourceUrl = URL.createObjectURL(new Blob([data.svgString], { type: 'image/svg+xml;charset=utf-8' }));
+ backgroundImage = new Image();
+ backgroundImage.onload = function () {
+ if (settled) return;
+ try {
+ var canvas = document.createElement('canvas');
+ canvas.width = Math.max(2, Math.round(data.width / 2) * 2);
+ canvas.height = Math.max(2, Math.round(data.height / 2) * 2);
+ var ctx = canvas.getContext('2d');
+ if (!ctx) throw exportError('viewer.export.error.contextUnavailable', { label: 'WebM' });
+ stream = canvas.captureStream(fps);
+ var mime = motionMimeType();
+ recorder = new MediaRecorder(stream, { mimeType: mime, videoBitsPerSecond: 6000000 });
+ var chunks = [];
+ var startedAt = performance.now();
+ function draw(now) {
+ if (settled) return;
+ try {
+ var elapsed = Math.max(0, ((Number(now) || performance.now()) - startedAt) / 1000);
+ drawMotionFrame(ctx, backgroundImage, motionScene, elapsed);
+ raf = requestAnimationFrame(draw);
+ } catch (error) { finish(error); }
+ }
+ recorder.ondataavailable = function (event) {
+ if (!settled && event.data && event.data.size) chunks.push(event.data);
+ };
+ recorder.onerror = function (event) {
+ finish(event.error || exportError('viewer.export.error.mediaRecorder'));
+ };
+ recorder.onstop = function () {
+ if (settled) return;
+ try {
+ var blob = new Blob(chunks, { type: recorder.mimeType || mime });
+ if (!blob.size) throw exportError('viewer.export.error.emptyWebm');
+ finish(null, blob);
+ } catch (error) { finish(error); }
+ };
+ drawMotionFrame(ctx, backgroundImage, motionScene, 0);
+ recorder.start(250);
+ if (settled) return;
+ startedAt = performance.now();
+ raf = requestAnimationFrame(draw);
+ durationTimer = setTimeout(function () {
+ if (settled || recorder.state === 'inactive') return;
+ // 保留最佳努力的编码器 flush;失败后仍通过 stop 收集最后的片段。
+ try { recorder.requestData(); } catch (_) {}
+ if (settled) return;
+ flushTimer = setTimeout(function () {
+ if (settled) return;
+ try { if (recorder.state !== 'inactive') recorder.stop(); }
+ catch (error) { finish(error); }
+ }, 120);
+ }, duration);
+ } catch (error) { finish(error); }
};
- recorder.onstop = function () {
- cleanup();
- var blob = new Blob(chunks, { type: recorder.mimeType || mime });
- if (!blob.size) reject(exportError('viewer.export.error.emptyWebm'));
- else resolve(blob);
+ backgroundImage.onerror = function () {
+ finish(exportError('viewer.export.error.webmBackground'));
};
- drawMotionFrame(ctx, backgroundImage, motionScene, 0);
- recorder.start(250);
- startedAt = performance.now();
- raf = requestAnimationFrame(draw);
- setTimeout(function () {
- if (recorder.state === 'inactive') return;
- // Chromium normally emits the final chunk during stop(), but
- // some embedded browser shells need an explicit encoder flush
- // first. Keep the short grace window bounded and harmless for
- // browsers that already delivered timeslice chunks.
- try { recorder.requestData(); } catch (_) {}
- setTimeout(function () {
- if (recorder.state !== 'inactive') recorder.stop();
- }, 120);
- }, duration);
- };
- backgroundImage.onerror = function () {
- URL.revokeObjectURL(sourceUrl);
- reject(exportError('viewer.export.error.webmBackground'));
- };
- backgroundImage.src = sourceUrl;
+ backgroundImage.src = sourceUrl;
+ } catch (error) { finish(error); }
});
}
diff --git a/archify/examples/web-app-rendered.html b/archify/examples/web-app-rendered.html
index 56513c18..ef9438ce 100644
--- a/archify/examples/web-app-rendered.html
+++ b/archify/examples/web-app-rendered.html
@@ -6647,7 +6647,6 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
var vb = svg.viewBox.baseVal;
var scale = Math.min(1, 1280 / vb.width);
var data = serializeSvg(scale);
- var sourceUrl = URL.createObjectURL(new Blob([data.svgString], { type: 'image/svg+xml;charset=utf-8' }));
function createMotionScene(root) {
var rootMatrix = root.getCTM ? root.getCTM() : null;
@@ -6799,73 +6798,99 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
var motionScene = createMotionScene(svg);
return new Promise(function (resolve, reject) {
- var backgroundImage = new Image();
- backgroundImage.onload = function () {
- var canvas = document.createElement('canvas');
- canvas.width = Math.max(2, Math.round(data.width / 2) * 2);
- canvas.height = Math.max(2, Math.round(data.height / 2) * 2);
- var ctx = canvas.getContext('2d');
- var stream = canvas.captureStream(fps);
- var mime = motionMimeType();
- var recorder;
- try {
- recorder = new MediaRecorder(stream, { mimeType: mime, videoBitsPerSecond: 6000000 });
- } catch (err) {
- URL.revokeObjectURL(sourceUrl);
- stream.getTracks().forEach(function (track) { track.stop(); });
- reject(err);
- return;
- }
- var chunks = [];
- var raf = 0;
- var stopped = false;
- var startedAt = performance.now();
- function cleanup() {
- if (stopped) return;
- stopped = true;
- cancelAnimationFrame(raf);
- URL.revokeObjectURL(sourceUrl);
- stream.getTracks().forEach(function (track) { track.stop(); });
+ var sourceUrl = null;
+ var backgroundImage = null;
+ var stream = null;
+ var recorder = null;
+ var raf = 0;
+ var durationTimer = 0;
+ var flushTimer = 0;
+ var settled = false;
+
+ function finish(error, blob) {
+ if (settled) return;
+ // 先锁定终态:停止录制和释放流可能产生晚到的编码事件。
+ settled = true;
+ cancelAnimationFrame(raf);
+ clearTimeout(durationTimer);
+ clearTimeout(flushTimer);
+ if (backgroundImage) {
+ backgroundImage.onload = null;
+ backgroundImage.onerror = null;
}
- function draw(now) {
- var elapsed = Math.max(0, ((Number(now) || performance.now()) - startedAt) / 1000);
- drawMotionFrame(ctx, backgroundImage, motionScene, elapsed);
- raf = requestAnimationFrame(draw);
+ if (recorder) {
+ recorder.ondataavailable = null;
+ recorder.onerror = null;
+ recorder.onstop = null;
+ try { if (recorder.state !== 'inactive') recorder.stop(); } catch (_) {}
}
- recorder.ondataavailable = function (event) {
- if (event.data && event.data.size) chunks.push(event.data);
- };
- recorder.onerror = function (event) {
- cleanup();
- reject(event.error || exportError('viewer.export.error.mediaRecorder'));
+ if (stream) stream.getTracks().forEach(function (track) { track.stop(); });
+ if (sourceUrl) URL.revokeObjectURL(sourceUrl);
+ if (blob) resolve(blob);
+ else reject(error);
+ }
+
+ try {
+ sourceUrl = URL.createObjectURL(new Blob([data.svgString], { type: 'image/svg+xml;charset=utf-8' }));
+ backgroundImage = new Image();
+ backgroundImage.onload = function () {
+ if (settled) return;
+ try {
+ var canvas = document.createElement('canvas');
+ canvas.width = Math.max(2, Math.round(data.width / 2) * 2);
+ canvas.height = Math.max(2, Math.round(data.height / 2) * 2);
+ var ctx = canvas.getContext('2d');
+ if (!ctx) throw exportError('viewer.export.error.contextUnavailable', { label: 'WebM' });
+ stream = canvas.captureStream(fps);
+ var mime = motionMimeType();
+ recorder = new MediaRecorder(stream, { mimeType: mime, videoBitsPerSecond: 6000000 });
+ var chunks = [];
+ var startedAt = performance.now();
+ function draw(now) {
+ if (settled) return;
+ try {
+ var elapsed = Math.max(0, ((Number(now) || performance.now()) - startedAt) / 1000);
+ drawMotionFrame(ctx, backgroundImage, motionScene, elapsed);
+ raf = requestAnimationFrame(draw);
+ } catch (error) { finish(error); }
+ }
+ recorder.ondataavailable = function (event) {
+ if (!settled && event.data && event.data.size) chunks.push(event.data);
+ };
+ recorder.onerror = function (event) {
+ finish(event.error || exportError('viewer.export.error.mediaRecorder'));
+ };
+ recorder.onstop = function () {
+ if (settled) return;
+ try {
+ var blob = new Blob(chunks, { type: recorder.mimeType || mime });
+ if (!blob.size) throw exportError('viewer.export.error.emptyWebm');
+ finish(null, blob);
+ } catch (error) { finish(error); }
+ };
+ drawMotionFrame(ctx, backgroundImage, motionScene, 0);
+ recorder.start(250);
+ if (settled) return;
+ startedAt = performance.now();
+ raf = requestAnimationFrame(draw);
+ durationTimer = setTimeout(function () {
+ if (settled || recorder.state === 'inactive') return;
+ // 保留最佳努力的编码器 flush;失败后仍通过 stop 收集最后的片段。
+ try { recorder.requestData(); } catch (_) {}
+ if (settled) return;
+ flushTimer = setTimeout(function () {
+ if (settled) return;
+ try { if (recorder.state !== 'inactive') recorder.stop(); }
+ catch (error) { finish(error); }
+ }, 120);
+ }, duration);
+ } catch (error) { finish(error); }
};
- recorder.onstop = function () {
- cleanup();
- var blob = new Blob(chunks, { type: recorder.mimeType || mime });
- if (!blob.size) reject(exportError('viewer.export.error.emptyWebm'));
- else resolve(blob);
+ backgroundImage.onerror = function () {
+ finish(exportError('viewer.export.error.webmBackground'));
};
- drawMotionFrame(ctx, backgroundImage, motionScene, 0);
- recorder.start(250);
- startedAt = performance.now();
- raf = requestAnimationFrame(draw);
- setTimeout(function () {
- if (recorder.state === 'inactive') return;
- // Chromium normally emits the final chunk during stop(), but
- // some embedded browser shells need an explicit encoder flush
- // first. Keep the short grace window bounded and harmless for
- // browsers that already delivered timeslice chunks.
- try { recorder.requestData(); } catch (_) {}
- setTimeout(function () {
- if (recorder.state !== 'inactive') recorder.stop();
- }, 120);
- }, duration);
- };
- backgroundImage.onerror = function () {
- URL.revokeObjectURL(sourceUrl);
- reject(exportError('viewer.export.error.webmBackground'));
- };
- backgroundImage.src = sourceUrl;
+ backgroundImage.src = sourceUrl;
+ } catch (error) { finish(error); }
});
}
diff --git a/archify/examples/workflow-agent-tool-call-rendered.html b/archify/examples/workflow-agent-tool-call-rendered.html
index c64d9d52..b68df2f5 100644
--- a/archify/examples/workflow-agent-tool-call-rendered.html
+++ b/archify/examples/workflow-agent-tool-call-rendered.html
@@ -6665,7 +6665,6 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
var vb = svg.viewBox.baseVal;
var scale = Math.min(1, 1280 / vb.width);
var data = serializeSvg(scale);
- var sourceUrl = URL.createObjectURL(new Blob([data.svgString], { type: 'image/svg+xml;charset=utf-8' }));
function createMotionScene(root) {
var rootMatrix = root.getCTM ? root.getCTM() : null;
@@ -6817,73 +6816,99 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
var motionScene = createMotionScene(svg);
return new Promise(function (resolve, reject) {
- var backgroundImage = new Image();
- backgroundImage.onload = function () {
- var canvas = document.createElement('canvas');
- canvas.width = Math.max(2, Math.round(data.width / 2) * 2);
- canvas.height = Math.max(2, Math.round(data.height / 2) * 2);
- var ctx = canvas.getContext('2d');
- var stream = canvas.captureStream(fps);
- var mime = motionMimeType();
- var recorder;
- try {
- recorder = new MediaRecorder(stream, { mimeType: mime, videoBitsPerSecond: 6000000 });
- } catch (err) {
- URL.revokeObjectURL(sourceUrl);
- stream.getTracks().forEach(function (track) { track.stop(); });
- reject(err);
- return;
- }
- var chunks = [];
- var raf = 0;
- var stopped = false;
- var startedAt = performance.now();
- function cleanup() {
- if (stopped) return;
- stopped = true;
- cancelAnimationFrame(raf);
- URL.revokeObjectURL(sourceUrl);
- stream.getTracks().forEach(function (track) { track.stop(); });
+ var sourceUrl = null;
+ var backgroundImage = null;
+ var stream = null;
+ var recorder = null;
+ var raf = 0;
+ var durationTimer = 0;
+ var flushTimer = 0;
+ var settled = false;
+
+ function finish(error, blob) {
+ if (settled) return;
+ // 先锁定终态:停止录制和释放流可能产生晚到的编码事件。
+ settled = true;
+ cancelAnimationFrame(raf);
+ clearTimeout(durationTimer);
+ clearTimeout(flushTimer);
+ if (backgroundImage) {
+ backgroundImage.onload = null;
+ backgroundImage.onerror = null;
}
- function draw(now) {
- var elapsed = Math.max(0, ((Number(now) || performance.now()) - startedAt) / 1000);
- drawMotionFrame(ctx, backgroundImage, motionScene, elapsed);
- raf = requestAnimationFrame(draw);
+ if (recorder) {
+ recorder.ondataavailable = null;
+ recorder.onerror = null;
+ recorder.onstop = null;
+ try { if (recorder.state !== 'inactive') recorder.stop(); } catch (_) {}
}
- recorder.ondataavailable = function (event) {
- if (event.data && event.data.size) chunks.push(event.data);
- };
- recorder.onerror = function (event) {
- cleanup();
- reject(event.error || exportError('viewer.export.error.mediaRecorder'));
+ if (stream) stream.getTracks().forEach(function (track) { track.stop(); });
+ if (sourceUrl) URL.revokeObjectURL(sourceUrl);
+ if (blob) resolve(blob);
+ else reject(error);
+ }
+
+ try {
+ sourceUrl = URL.createObjectURL(new Blob([data.svgString], { type: 'image/svg+xml;charset=utf-8' }));
+ backgroundImage = new Image();
+ backgroundImage.onload = function () {
+ if (settled) return;
+ try {
+ var canvas = document.createElement('canvas');
+ canvas.width = Math.max(2, Math.round(data.width / 2) * 2);
+ canvas.height = Math.max(2, Math.round(data.height / 2) * 2);
+ var ctx = canvas.getContext('2d');
+ if (!ctx) throw exportError('viewer.export.error.contextUnavailable', { label: 'WebM' });
+ stream = canvas.captureStream(fps);
+ var mime = motionMimeType();
+ recorder = new MediaRecorder(stream, { mimeType: mime, videoBitsPerSecond: 6000000 });
+ var chunks = [];
+ var startedAt = performance.now();
+ function draw(now) {
+ if (settled) return;
+ try {
+ var elapsed = Math.max(0, ((Number(now) || performance.now()) - startedAt) / 1000);
+ drawMotionFrame(ctx, backgroundImage, motionScene, elapsed);
+ raf = requestAnimationFrame(draw);
+ } catch (error) { finish(error); }
+ }
+ recorder.ondataavailable = function (event) {
+ if (!settled && event.data && event.data.size) chunks.push(event.data);
+ };
+ recorder.onerror = function (event) {
+ finish(event.error || exportError('viewer.export.error.mediaRecorder'));
+ };
+ recorder.onstop = function () {
+ if (settled) return;
+ try {
+ var blob = new Blob(chunks, { type: recorder.mimeType || mime });
+ if (!blob.size) throw exportError('viewer.export.error.emptyWebm');
+ finish(null, blob);
+ } catch (error) { finish(error); }
+ };
+ drawMotionFrame(ctx, backgroundImage, motionScene, 0);
+ recorder.start(250);
+ if (settled) return;
+ startedAt = performance.now();
+ raf = requestAnimationFrame(draw);
+ durationTimer = setTimeout(function () {
+ if (settled || recorder.state === 'inactive') return;
+ // 保留最佳努力的编码器 flush;失败后仍通过 stop 收集最后的片段。
+ try { recorder.requestData(); } catch (_) {}
+ if (settled) return;
+ flushTimer = setTimeout(function () {
+ if (settled) return;
+ try { if (recorder.state !== 'inactive') recorder.stop(); }
+ catch (error) { finish(error); }
+ }, 120);
+ }, duration);
+ } catch (error) { finish(error); }
};
- recorder.onstop = function () {
- cleanup();
- var blob = new Blob(chunks, { type: recorder.mimeType || mime });
- if (!blob.size) reject(exportError('viewer.export.error.emptyWebm'));
- else resolve(blob);
+ backgroundImage.onerror = function () {
+ finish(exportError('viewer.export.error.webmBackground'));
};
- drawMotionFrame(ctx, backgroundImage, motionScene, 0);
- recorder.start(250);
- startedAt = performance.now();
- raf = requestAnimationFrame(draw);
- setTimeout(function () {
- if (recorder.state === 'inactive') return;
- // Chromium normally emits the final chunk during stop(), but
- // some embedded browser shells need an explicit encoder flush
- // first. Keep the short grace window bounded and harmless for
- // browsers that already delivered timeslice chunks.
- try { recorder.requestData(); } catch (_) {}
- setTimeout(function () {
- if (recorder.state !== 'inactive') recorder.stop();
- }, 120);
- }, duration);
- };
- backgroundImage.onerror = function () {
- URL.revokeObjectURL(sourceUrl);
- reject(exportError('viewer.export.error.webmBackground'));
- };
- backgroundImage.src = sourceUrl;
+ backgroundImage.src = sourceUrl;
+ } catch (error) { finish(error); }
});
}
diff --git a/docs/gallery.html b/docs/gallery.html
index 8a55d76c..8afd56e8 100644
--- a/docs/gallery.html
+++ b/docs/gallery.html
@@ -298,7 +298,7 @@
<div class="receipt-cell"><span class="receipt-label">Artifact</span><span class="receipt-value ok">9/9 pass</span></div>
<div class="receipt-cell"><span class="receipt-label">Composition</span><span class="receipt-value ok" title="0 crossings · 0 border runs · 0 micro segments · 0 cramped turns">SHOWCASE · PASS</span></div>
<div class="receipt-cell"><span class="receipt-label">Graph</span><span class="receipt-value">12N · 11E</span></div>
- <div class="receipt-cell"><span class="receipt-label">SHA-256</span><span class="receipt-value" title="7d086f7f0af593759c56dd82e0b952bcb1a27a64f960cfc7226f905aa2d010dc">7d086f7f0af5</span></div>
+ <div class="receipt-cell"><span class="receipt-label">SHA-256</span><span class="receipt-value" title="72d8efc3a8896783caee0023519d659bda63ad99fadc05ce524da24ebd143b82">72d8efc3a889</span></div>
</div>
<div class="card-actions">
<a class="card-link primary" href="gallery/artifacts/agent-tool-call.workflow.html#focus=planner" target="_blank" rel="noopener" data-en="Explore focus ↗" data-zh="探索聚焦路径 ↗">Explore focus ↗</a>
@@ -328,7 +328,7 @@
<div class="receipt-cell"><span class="receipt-label">Artifact</span><span class="receipt-value ok">9/9 pass</span></div>
<div class="receipt-cell"><span class="receipt-label">Composition</span><span class="receipt-value ok" title="0 crossings · 0 border runs · 0 micro segments · 0 cramped turns">SHOWCASE · PASS</span></div>
<div class="receipt-cell"><span class="receipt-label">Graph</span><span class="receipt-value">12N · 12E</span></div>
- <div class="receipt-cell"><span class="receipt-label">SHA-256</span><span class="receipt-value" title="46bc35a5978fd96e842104527342ccb524b0e9d5cadb1dfbc5dac38d7095bc41">46bc35a5978f</span></div>
+ <div class="receipt-cell"><span class="receipt-label">SHA-256</span><span class="receipt-value" title="54688ab28407718c1b8f76781511f92f87a7cdcb0fdae61a089bd39c65913e7e">54688ab28407</span></div>
</div>
<div class="card-actions">
<a class="card-link primary" href="gallery/artifacts/production-deployment.architecture.html#focus=gateway" target="_blank" rel="noopener" data-en="Explore focus ↗" data-zh="探索聚焦路径 ↗">Explore focus ↗</a>
@@ -357,7 +357,7 @@
<div class="receipt-cell"><span class="receipt-label">Artifact</span><span class="receipt-value ok">9/9 pass</span></div>
<div class="receipt-cell"><span class="receipt-label">Composition</span><span class="receipt-value ok" title="0 crossings · 0 border runs · 0 micro segments · 0 cramped turns">SHOWCASE · PASS</span></div>
<div class="receipt-cell"><span class="receipt-label">Graph</span><span class="receipt-value">7N · 12E</span></div>
- <div class="receipt-cell"><span class="receipt-label">SHA-256</span><span class="receipt-value" title="590cf92f58921658398953fbf28795cbf054053bf89c2e9f23acd0c827693a53">590cf92f5892</span></div>
+ <div class="receipt-cell"><span class="receipt-label">SHA-256</span><span class="receipt-value" title="a94388fe099db0582aa6e3fa2bf771ad619b3ae65736de5aa020fb8ed5d13830">a94388fe099d</span></div>
</div>
<div class="card-actions">
<a class="card-link primary" href="gallery/artifacts/cache-miss.sequence.html#focus=redis" target="_blank" rel="noopener" data-en="Explore focus ↗" data-zh="探索聚焦路径 ↗">Explore focus ↗</a>
@@ -386,7 +386,7 @@
<div class="receipt-cell"><span class="receipt-label">Artifact</span><span class="receipt-value ok">9/9 pass</span></div>
<div class="receipt-cell"><span class="receipt-label">Composition</span><span class="receipt-value ok" title="0 crossings · 0 border runs · 0 micro segments · 0 cramped turns">SHOWCASE · PASS</span></div>
<div class="receipt-cell"><span class="receipt-label">Graph</span><span class="receipt-value">10N · 10E</span></div>
- <div class="receipt-cell"><span class="receipt-label">SHA-256</span><span class="receipt-value" title="6a3fc44eb7b266bde68b92159b32db8ba08f9fab5e513d612da53e1a29988c82">6a3fc44eb7b2</span></div>
+ <div class="receipt-cell"><span class="receipt-label">SHA-256</span><span class="receipt-value" title="411d9bd097b6a8094e261c276f20a51535b60ef6d9d645a718cc39d934140c4a">411d9bd097b6</span></div>
</div>
<div class="card-actions">
<a class="card-link primary" href="gallery/artifacts/release-delivery.workflow.html#focus=approval" target="_blank" rel="noopener" data-en="Explore focus ↗" data-zh="探索聚焦路径 ↗">Explore focus ↗</a>
@@ -415,7 +415,7 @@
<div class="receipt-cell"><span class="receipt-label">Artifact</span><span class="receipt-value ok">9/9 pass</span></div>
<div class="receipt-cell"><span class="receipt-label">Composition</span><span class="receipt-value ok" title="0 crossings · 0 border runs · 0 micro segments · 0 cramped turns">SHOWCASE · PASS</span></div>
<div class="receipt-cell"><span class="receipt-label">Graph</span><span class="receipt-value">11N · 10E</span></div>
- <div class="receipt-cell"><span class="receipt-label">SHA-256</span><span class="receipt-value" title="fdfa06be4f0d9728f844ccfde5910fa4b4ed8f2d268be41e05b7a95535fd834b">fdfa06be4f0d</span></div>
+ <div class="receipt-cell"><span class="receipt-label">SHA-256</span><span class="receipt-value" title="7df016f9173c363aac707a12311e56917d4f95d342cbfc4a88152a24155a7dc3">7df016f9173c</span></div>
</div>
<div class="card-actions">
<a class="card-link primary" href="gallery/artifacts/incident-response.workflow.html#focus=triage" target="_blank" rel="noopener" data-en="Explore focus ↗" data-zh="探索聚焦路径 ↗">Explore focus ↗</a>
@@ -444,7 +444,7 @@
<div class="receipt-cell"><span class="receipt-label">Artifact</span><span class="receipt-value ok">9/9 pass</span></div>
<div class="receipt-cell"><span class="receipt-label">Composition</span><span class="receipt-value ok" title="0 crossings · 0 border runs · 0 micro segments · 0 cramped turns">SHOWCASE · PASS</span></div>
<div class="receipt-cell"><span class="receipt-label">Graph</span><span class="receipt-value">10N · 10E</span></div>
- <div class="receipt-cell"><span class="receipt-label">SHA-256</span><span class="receipt-value" title="498dad656e49542b27fd4c08d83adf0e50809255517fee1bf21a86f172103fd0">498dad656e49</span></div>
+ <div class="receipt-cell"><span class="receipt-label">SHA-256</span><span class="receipt-value" title="605d6544b1cc65d1a05fcad25af8b2786b11aea1cb2ed4f0630388e1fab9fba4">605d6544b1cc</span></div>
</div>
<div class="card-actions">
<a class="card-link primary" href="gallery/artifacts/product-analytics.dataflow.html#focus=consent" target="_blank" rel="noopener" data-en="Explore focus ↗" data-zh="探索聚焦路径 ↗">Explore focus ↗</a>
@@ -473,7 +473,7 @@
<div class="receipt-cell"><span class="receipt-label">Artifact</span><span class="receipt-value ok">9/9 pass</span></div>
<div class="receipt-cell"><span class="receipt-label">Composition</span><span class="receipt-value ok" title="0 crossings · 0 border runs · 0 micro segments · 0 cramped turns">SHOWCASE · PASS</span></div>
<div class="receipt-cell"><span class="receipt-label">Graph</span><span class="receipt-value">7N · 14E</span></div>
- <div class="receipt-cell"><span class="receipt-label">SHA-256</span><span class="receipt-value" title="48f43ccbe702462a339ae3fd4743c38ac90fac261a24ff90a0853db01a38f8f5">48f43ccbe702</span></div>
+ <div class="receipt-cell"><span class="receipt-label">SHA-256</span><span class="receipt-value" title="e9f5b8b6c28315c51ae3c823cd0c1cee25db18a05efc265b3f393cf3560b6b58">e9f5b8b6c283</span></div>
</div>
<div class="card-actions">
<a class="card-link primary" href="gallery/artifacts/async-job-roundtrip.sequence.html#focus=queue" target="_blank" rel="noopener" data-en="Explore focus ↗" data-zh="探索聚焦路径 ↗">Explore focus ↗</a>
@@ -502,7 +502,7 @@
<div class="receipt-cell"><span class="receipt-label">Artifact</span><span class="receipt-value ok">9/9 pass</span></div>
<div class="receipt-cell"><span class="receipt-label">Composition</span><span class="receipt-value ok" title="0 crossings · 0 border runs · 0 micro segments · 0 cramped turns">SHOWCASE · PASS</span></div>
<div class="receipt-cell"><span class="receipt-label">Graph</span><span class="receipt-value">12N · 12E</span></div>
- <div class="receipt-cell"><span class="receipt-label">SHA-256</span><span class="receipt-value" title="8cdd38dc599f78bc6f8dca392b38dcb76b3159efdc3a734a9a8b814d82e358c7">8cdd38dc599f</span></div>
+ <div class="receipt-cell"><span class="receipt-label">SHA-256</span><span class="receipt-value" title="0a8c47fcb3c2f4277b49ca40a4683b240aacaa6e987a5e000bf2b414686175d5">0a8c47fcb3c2</span></div>
</div>
<div class="card-actions">
<a class="card-link primary" href="gallery/artifacts/event-stream.dataflow.html#focus=orders" target="_blank" rel="noopener" data-en="Explore focus ↗" data-zh="探索聚焦路径 ↗">Explore focus ↗</a>
@@ -531,7 +531,7 @@
<div class="receipt-cell"><span class="receipt-label">Artifact</span><span class="receipt-value ok">9/9 pass</span></div>
<div class="receipt-cell"><span class="receipt-label">Composition</span><span class="receipt-value ok" title="0 crossings · 0 border runs · 0 micro segments · 0 cramped turns">SHOWCASE · PASS</span></div>
<div class="receipt-cell"><span class="receipt-label">Graph</span><span class="receipt-value">10N · 6E</span></div>
- <div class="receipt-cell"><span class="receipt-label">SHA-256</span><span class="receipt-value" title="99dfa39c258ed8009c1b312dde565fad3f81eaf9ffa181fcd0dd6cc818722040">99dfa39c258e</span></div>
+ <div class="receipt-cell"><span class="receipt-label">SHA-256</span><span class="receipt-value" title="9488f6b081c7a88f841f5fe3a01bed83b0458e0ee9075ab2ff5e6d8131af88d0">9488f6b081c7</span></div>
</div>
<div class="card-actions">
<a class="card-link primary" href="gallery/artifacts/agent-run.lifecycle.html#focus=approval" target="_blank" rel="noopener" data-en="Explore focus ↗" data-zh="探索聚焦路径 ↗">Explore focus ↗</a>
@@ -560,7 +560,7 @@
<div class="receipt-cell"><span class="receipt-label">Artifact</span><span class="receipt-value ok">9/9 pass</span></div>
<div class="receipt-cell"><span class="receipt-label">Composition</span><span class="receipt-value ok" title="0 crossings · 0 border runs · 0 micro segments · 0 cramped turns">SHOWCASE · PASS</span></div>
<div class="receipt-cell"><span class="receipt-label">Graph</span><span class="receipt-value">11N · 11E</span></div>
- <div class="receipt-cell"><span class="receipt-label">SHA-256</span><span class="receipt-value" title="24279a5e329c5e0de5e1f8ecefd3d0f799e1381f9cb9779abe4db5c8cae8d3f7">24279a5e329c</span></div>
+ <div class="receipt-cell"><span class="receipt-label">SHA-256</span><span class="receipt-value" title="d9a574f8b331b8df3152936c7c5439a63035fd18337464fa1ccce7bdf81095e9">d9a574f8b331</span></div>
</div>
<div class="card-actions">
<a class="card-link primary" href="gallery/artifacts/deployment-release.lifecycle.html#focus=live" target="_blank" rel="noopener" data-en="Explore focus ↗" data-zh="探索聚焦路径 ↗">Explore focus ↗</a>
@@ -589,7 +589,7 @@
<div class="receipt-cell"><span class="receipt-label">Artifact</span><span class="receipt-value ok">9/9 pass</span></div>
<div class="receipt-cell"><span class="receipt-label">Composition</span><span class="receipt-value ok" title="0 crossings · 0 border runs · 0 micro segments · 0 cramped turns">SHOWCASE · PASS</span></div>
<div class="receipt-cell"><span class="receipt-label">Graph</span><span class="receipt-value">10N · 9E</span></div>
- <div class="receipt-cell"><span class="receipt-label">SHA-256</span><span class="receipt-value" title="3ed638ac7f2ce0e99b3e2ff3c520b703d368eca7fbd223e9ee94d54e257c189a">3ed638ac7f2c</span></div>
+ <div class="receipt-cell"><span class="receipt-label">SHA-256</span><span class="receipt-value" title="74eccc0a70e150ca46b071f0c9fefc13f99ba272cc1835172e0751080693f66f">74eccc0a70e1</span></div>
</div>
<div class="card-actions">
<a class="card-link primary" href="gallery/artifacts/web-app.architecture.html#focus=api" target="_blank" rel="noopener" data-en="Explore focus ↗" data-zh="探索聚焦路径 ↗">Explore focus ↗</a>
@@ -667,8 +667,8 @@ receipt 99 checks / 11 artifacts / deterministic hashes</pre>
"engineeringProfile": null,
"nodeCount": 12,
"edgeCount": 11,
- "artifactBytes": 767776,
- "artifactSha256": "7d086f7f0af593759c56dd82e0b952bcb1a27a64f960cfc7226f905aa2d010dc",
+ "artifactBytes": 768975,
+ "artifactSha256": "72d8efc3a8896783caee0023519d659bda63ad99fadc05ce524da24ebd143b82",
"sourceBytes": 4939,
"sourceSha256": "d67965d50872c97e4ff3476271e645bf19fab6b3ab44e111bdb44b063e3aa36f",
"checks": [
@@ -802,8 +802,8 @@ receipt 99 checks / 11 artifacts / deterministic hashes</pre>
"engineeringProfile": "deployment-ownership",
"nodeCount": 12,
"edgeCount": 12,
- "artifactBytes": 770503,
- "artifactSha256": "46bc35a5978fd96e842104527342ccb524b0e9d5cadb1dfbc5dac38d7095bc41",
+ "artifactBytes": 771702,
+ "artifactSha256": "54688ab28407718c1b8f76781511f92f87a7cdcb0fdae61a089bd39c65913e7e",
"sourceBytes": 4734,
"sourceSha256": "cb54bad2dfd0c2d02aa5b496bde6839789a0f07f23062343c4458b8d38806c13",
"checks": [
@@ -935,8 +935,8 @@ receipt 99 checks / 11 artifacts / deterministic hashes</pre>
"engineeringProfile": null,
"nodeCount": 7,
"edgeCount": 12,
- "artifactBytes": 762316,
- "artifactSha256": "590cf92f58921658398953fbf28795cbf054053bf89c2e9f23acd0c827693a53",
+ "artifactBytes": 763515,
+ "artifactSha256": "a94388fe099db0582aa6e3fa2bf771ad619b3ae65736de5aa020fb8ed5d13830",
"sourceBytes": 3805,
"sourceSha256": "f8486daa803fff6c295cecca4604c561fbbf9acb2e83326022b5a87639e8afe6",
"checks": [
@@ -1069,8 +1069,8 @@ receipt 99 checks / 11 artifacts / deterministic hashes</pre>
"engineeringProfile": null,
"nodeCount": 10,
"edgeCount": 10,
- "artifactBytes": 763290,
- "artifactSha256": "6a3fc44eb7b266bde68b92159b32db8ba08f9fab5e513d612da53e1a29988c82",
+ "artifactBytes": 764489,
+ "artifactSha256": "411d9bd097b6a8094e261c276f20a51535b60ef6d9d645a718cc39d934140c4a",
"sourceBytes": 4510,
"sourceSha256": "dbd5c174af66296caec372e7214cf4df7158b50a563508e16826b95ab8d1cd6c",
"checks": [
@@ -1209,8 +1209,8 @@ receipt 99 checks / 11 artifacts / deterministic hashes</pre>
"engineeringProfile": null,
"nodeCount": 11,
"edgeCount": 10,
- "artifactBytes": 760610,
- "artifactSha256": "fdfa06be4f0d9728f844ccfde5910fa4b4ed8f2d268be41e05b7a95535fd834b",
+ "artifactBytes": 761809,
+ "artifactSha256": "7df016f9173c363aac707a12311e56917d4f95d342cbfc4a88152a24155a7dc3",
"sourceBytes": 4723,
"sourceSha256": "630be98449925d2716ecb8439f404b2bff5fe65ba905b0ad0baea6d96890c526",
"checks": [
@@ -1395,8 +1395,8 @@ receipt 99 checks / 11 artifacts / deterministic hashes</pre>
"engineeringProfile": null,
"nodeCount": 10,
"edgeCount": 10,
- "artifactBytes": 764610,
- "artifactSha256": "498dad656e49542b27fd4c08d83adf0e50809255517fee1bf21a86f172103fd0",
+ "artifactBytes": 765809,
+ "artifactSha256": "605d6544b1cc65d1a05fcad25af8b2786b11aea1cb2ed4f0630388e1fab9fba4",
"sourceBytes": 5035,
"sourceSha256": "8a635db9e51a5b1a8d2955b9d66f5b9a450e0a298432ce8f2e2f0be11f372e05",
"checks": [
@@ -1530,8 +1530,8 @@ receipt 99 checks / 11 artifacts / deterministic hashes</pre>
"engineeringProfile": null,
"nodeCount": 7,
"edgeCount": 14,
- "artifactBytes": 761402,
- "artifactSha256": "48f43ccbe702462a339ae3fd4743c38ac90fac261a24ff90a0853db01a38f8f5",
+ "artifactBytes": 762601,
+ "artifactSha256": "e9f5b8b6c28315c51ae3c823cd0c1cee25db18a05efc265b3f393cf3560b6b58",
"sourceBytes": 3766,
"sourceSha256": "b8c6c52f1763ede2933c77deb8da59b3e06917bc41d27e66df896136456b859a",
"checks": [
@@ -1682,8 +1682,8 @@ receipt 99 checks / 11 artifacts / deterministic hashes</pre>
"engineeringProfile": null,
"nodeCount": 12,
"edgeCount": 12,
- "artifactBytes": 768530,
- "artifactSha256": "8cdd38dc599f78bc6f8dca392b38dcb76b3159efdc3a734a9a8b814d82e358c7",
+ "artifactBytes": 769729,
+ "artifactSha256": "0a8c47fcb3c2f4277b49ca40a4683b240aacaa6e987a5e000bf2b414686175d5",
"sourceBytes": 4769,
"sourceSha256": "3bdd77674282009c7c68d588cf8a3c495bc98a3be1b9c45327fd1801a6f83a23",
"checks": [
@@ -1834,8 +1834,8 @@ receipt 99 checks / 11 artifacts / deterministic hashes</pre>
"engineeringProfile": null,
"nodeCount": 10,
"edgeCount": 6,
- "artifactBytes": 758920,
- "artifactSha256": "99dfa39c258ed8009c1b312dde565fad3f81eaf9ffa181fcd0dd6cc818722040",
+ "artifactBytes": 760119,
+ "artifactSha256": "9488f6b081c7a88f841f5fe3a01bed83b0458e0ee9075ab2ff5e6d8131af88d0",
"sourceBytes": 3405,
"sourceSha256": "230242a7557663877766c43a9fe7cffe8b4fb66e4866457dccd24c63175b4917",
"checks": [
@@ -2005,8 +2005,8 @@ receipt 99 checks / 11 artifacts / deterministic hashes</pre>
"engineeringProfile": null,
"nodeCount": 11,
"edgeCount": 11,
- "artifactBytes": 765975,
- "artifactSha256": "24279a5e329c5e0de5e1f8ecefd3d0f799e1381f9cb9779abe4db5c8cae8d3f7",
+ "artifactBytes": 767174,
+ "artifactSha256": "d9a574f8b331b8df3152936c7c5439a63035fd18337464fa1ccce7bdf81095e9",
"sourceBytes": 3507,
"sourceSha256": "f565a8acfebdb21453e2bccd82d3760b4736e38fe194fb2f0804b57817eba813",
"checks": [
@@ -2127,8 +2127,8 @@ receipt 99 checks / 11 artifacts / deterministic hashes</pre>
"engineeringProfile": null,
"nodeCount": 10,
"edgeCount": 9,
- "artifactBytes": 762316,
- "artifactSha256": "3ed638ac7f2ce0e99b3e2ff3c520b703d368eca7fbd223e9ee94d54e257c189a",
+ "artifactBytes": 763515,
+ "artifactSha256": "74eccc0a70e150ca46b071f0c9fefc13f99ba272cc1835172e0751080693f66f",
"sourceBytes": 3197,
"sourceSha256": "95e051b27a9e4a3307e194c0f666fca4af51470be7e2228d400ff48aea5b353b",
"checks": [
diff --git a/docs/gallery/artifacts/agent-run.lifecycle.html b/docs/gallery/artifacts/agent-run.lifecycle.html
index 5b600983..bbcea1cb 100644
--- a/docs/gallery/artifacts/agent-run.lifecycle.html
+++ b/docs/gallery/artifacts/agent-run.lifecycle.html
@@ -6604,7 +6604,6 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
var vb = svg.viewBox.baseVal;
var scale = Math.min(1, 1280 / vb.width);
var data = serializeSvg(scale);
- var sourceUrl = URL.createObjectURL(new Blob([data.svgString], { type: 'image/svg+xml;charset=utf-8' }));
function createMotionScene(root) {
var rootMatrix = root.getCTM ? root.getCTM() : null;
@@ -6756,73 +6755,99 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
var motionScene = createMotionScene(svg);
return new Promise(function (resolve, reject) {
- var backgroundImage = new Image();
- backgroundImage.onload = function () {
- var canvas = document.createElement('canvas');
- canvas.width = Math.max(2, Math.round(data.width / 2) * 2);
- canvas.height = Math.max(2, Math.round(data.height / 2) * 2);
- var ctx = canvas.getContext('2d');
- var stream = canvas.captureStream(fps);
- var mime = motionMimeType();
- var recorder;
- try {
- recorder = new MediaRecorder(stream, { mimeType: mime, videoBitsPerSecond: 6000000 });
- } catch (err) {
- URL.revokeObjectURL(sourceUrl);
- stream.getTracks().forEach(function (track) { track.stop(); });
- reject(err);
- return;
- }
- var chunks = [];
- var raf = 0;
- var stopped = false;
- var startedAt = performance.now();
- function cleanup() {
- if (stopped) return;
- stopped = true;
- cancelAnimationFrame(raf);
- URL.revokeObjectURL(sourceUrl);
- stream.getTracks().forEach(function (track) { track.stop(); });
+ var sourceUrl = null;
+ var backgroundImage = null;
+ var stream = null;
+ var recorder = null;
+ var raf = 0;
+ var durationTimer = 0;
+ var flushTimer = 0;
+ var settled = false;
+
+ function finish(error, blob) {
+ if (settled) return;
+ // 先锁定终态:停止录制和释放流可能产生晚到的编码事件。
+ settled = true;
+ cancelAnimationFrame(raf);
+ clearTimeout(durationTimer);
+ clearTimeout(flushTimer);
+ if (backgroundImage) {
+ backgroundImage.onload = null;
+ backgroundImage.onerror = null;
}
- function draw(now) {
- var elapsed = Math.max(0, ((Number(now) || performance.now()) - startedAt) / 1000);
- drawMotionFrame(ctx, backgroundImage, motionScene, elapsed);
- raf = requestAnimationFrame(draw);
+ if (recorder) {
+ recorder.ondataavailable = null;
+ recorder.onerror = null;
+ recorder.onstop = null;
+ try { if (recorder.state !== 'inactive') recorder.stop(); } catch (_) {}
}
- recorder.ondataavailable = function (event) {
- if (event.data && event.data.size) chunks.push(event.data);
- };
- recorder.onerror = function (event) {
- cleanup();
- reject(event.error || exportError('viewer.export.error.mediaRecorder'));
+ if (stream) stream.getTracks().forEach(function (track) { track.stop(); });
+ if (sourceUrl) URL.revokeObjectURL(sourceUrl);
+ if (blob) resolve(blob);
+ else reject(error);
+ }
+
+ try {
+ sourceUrl = URL.createObjectURL(new Blob([data.svgString], { type: 'image/svg+xml;charset=utf-8' }));
+ backgroundImage = new Image();
+ backgroundImage.onload = function () {
+ if (settled) return;
+ try {
+ var canvas = document.createElement('canvas');
+ canvas.width = Math.max(2, Math.round(data.width / 2) * 2);
+ canvas.height = Math.max(2, Math.round(data.height / 2) * 2);
+ var ctx = canvas.getContext('2d');
+ if (!ctx) throw exportError('viewer.export.error.contextUnavailable', { label: 'WebM' });
+ stream = canvas.captureStream(fps);
+ var mime = motionMimeType();
+ recorder = new MediaRecorder(stream, { mimeType: mime, videoBitsPerSecond: 6000000 });
+ var chunks = [];
+ var startedAt = performance.now();
+ function draw(now) {
+ if (settled) return;
+ try {
+ var elapsed = Math.max(0, ((Number(now) || performance.now()) - startedAt) / 1000);
+ drawMotionFrame(ctx, backgroundImage, motionScene, elapsed);
+ raf = requestAnimationFrame(draw);
+ } catch (error) { finish(error); }
+ }
+ recorder.ondataavailable = function (event) {
+ if (!settled && event.data && event.data.size) chunks.push(event.data);
+ };
+ recorder.onerror = function (event) {
+ finish(event.error || exportError('viewer.export.error.mediaRecorder'));
+ };
+ recorder.onstop = function () {
+ if (settled) return;
+ try {
+ var blob = new Blob(chunks, { type: recorder.mimeType || mime });
+ if (!blob.size) throw exportError('viewer.export.error.emptyWebm');
+ finish(null, blob);
+ } catch (error) { finish(error); }
+ };
+ drawMotionFrame(ctx, backgroundImage, motionScene, 0);
+ recorder.start(250);
+ if (settled) return;
+ startedAt = performance.now();
+ raf = requestAnimationFrame(draw);
+ durationTimer = setTimeout(function () {
+ if (settled || recorder.state === 'inactive') return;
+ // 保留最佳努力的编码器 flush;失败后仍通过 stop 收集最后的片段。
+ try { recorder.requestData(); } catch (_) {}
+ if (settled) return;
+ flushTimer = setTimeout(function () {
+ if (settled) return;
+ try { if (recorder.state !== 'inactive') recorder.stop(); }
+ catch (error) { finish(error); }
+ }, 120);
+ }, duration);
+ } catch (error) { finish(error); }
};
- recorder.onstop = function () {
- cleanup();
- var blob = new Blob(chunks, { type: recorder.mimeType || mime });
- if (!blob.size) reject(exportError('viewer.export.error.emptyWebm'));
- else resolve(blob);
+ backgroundImage.onerror = function () {
+ finish(exportError('viewer.export.error.webmBackground'));
};
- drawMotionFrame(ctx, backgroundImage, motionScene, 0);
- recorder.start(250);
- startedAt = performance.now();
- raf = requestAnimationFrame(draw);
- setTimeout(function () {
- if (recorder.state === 'inactive') return;
- // Chromium normally emits the final chunk during stop(), but
- // some embedded browser shells need an explicit encoder flush
- // first. Keep the short grace window bounded and harmless for
- // browsers that already delivered timeslice chunks.
- try { recorder.requestData(); } catch (_) {}
- setTimeout(function () {
- if (recorder.state !== 'inactive') recorder.stop();
- }, 120);
- }, duration);
- };
- backgroundImage.onerror = function () {
- URL.revokeObjectURL(sourceUrl);
- reject(exportError('viewer.export.error.webmBackground'));
- };
- backgroundImage.src = sourceUrl;
+ backgroundImage.src = sourceUrl;
+ } catch (error) { finish(error); }
});
}
diff --git a/docs/gallery/artifacts/agent-tool-call.workflow.html b/docs/gallery/artifacts/agent-tool-call.workflow.html
index c64d9d52..b68df2f5 100644
--- a/docs/gallery/artifacts/agent-tool-call.workflow.html
+++ b/docs/gallery/artifacts/agent-tool-call.workflow.html
@@ -6665,7 +6665,6 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
var vb = svg.viewBox.baseVal;
var scale = Math.min(1, 1280 / vb.width);
var data = serializeSvg(scale);
- var sourceUrl = URL.createObjectURL(new Blob([data.svgString], { type: 'image/svg+xml;charset=utf-8' }));
function createMotionScene(root) {
var rootMatrix = root.getCTM ? root.getCTM() : null;
@@ -6817,73 +6816,99 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
var motionScene = createMotionScene(svg);
return new Promise(function (resolve, reject) {
- var backgroundImage = new Image();
- backgroundImage.onload = function () {
- var canvas = document.createElement('canvas');
- canvas.width = Math.max(2, Math.round(data.width / 2) * 2);
- canvas.height = Math.max(2, Math.round(data.height / 2) * 2);
- var ctx = canvas.getContext('2d');
- var stream = canvas.captureStream(fps);
- var mime = motionMimeType();
- var recorder;
- try {
- recorder = new MediaRecorder(stream, { mimeType: mime, videoBitsPerSecond: 6000000 });
- } catch (err) {
- URL.revokeObjectURL(sourceUrl);
- stream.getTracks().forEach(function (track) { track.stop(); });
- reject(err);
- return;
- }
- var chunks = [];
- var raf = 0;
- var stopped = false;
- var startedAt = performance.now();
- function cleanup() {
- if (stopped) return;
- stopped = true;
- cancelAnimationFrame(raf);
- URL.revokeObjectURL(sourceUrl);
- stream.getTracks().forEach(function (track) { track.stop(); });
+ var sourceUrl = null;
+ var backgroundImage = null;
+ var stream = null;
+ var recorder = null;
+ var raf = 0;
+ var durationTimer = 0;
+ var flushTimer = 0;
+ var settled = false;
+
+ function finish(error, blob) {
+ if (settled) return;
+ // 先锁定终态:停止录制和释放流可能产生晚到的编码事件。
+ settled = true;
+ cancelAnimationFrame(raf);
+ clearTimeout(durationTimer);
+ clearTimeout(flushTimer);
+ if (backgroundImage) {
+ backgroundImage.onload = null;
+ backgroundImage.onerror = null;
}
- function draw(now) {
- var elapsed = Math.max(0, ((Number(now) || performance.now()) - startedAt) / 1000);
- drawMotionFrame(ctx, backgroundImage, motionScene, elapsed);
- raf = requestAnimationFrame(draw);
+ if (recorder) {
+ recorder.ondataavailable = null;
+ recorder.onerror = null;
+ recorder.onstop = null;
+ try { if (recorder.state !== 'inactive') recorder.stop(); } catch (_) {}
}
- recorder.ondataavailable = function (event) {
- if (event.data && event.data.size) chunks.push(event.data);
- };
- recorder.onerror = function (event) {
- cleanup();
- reject(event.error || exportError('viewer.export.error.mediaRecorder'));
+ if (stream) stream.getTracks().forEach(function (track) { track.stop(); });
+ if (sourceUrl) URL.revokeObjectURL(sourceUrl);
+ if (blob) resolve(blob);
+ else reject(error);
+ }
+
+ try {
+ sourceUrl = URL.createObjectURL(new Blob([data.svgString], { type: 'image/svg+xml;charset=utf-8' }));
+ backgroundImage = new Image();
+ backgroundImage.onload = function () {
+ if (settled) return;
+ try {
+ var canvas = document.createElement('canvas');
+ canvas.width = Math.max(2, Math.round(data.width / 2) * 2);
+ canvas.height = Math.max(2, Math.round(data.height / 2) * 2);
+ var ctx = canvas.getContext('2d');
+ if (!ctx) throw exportError('viewer.export.error.contextUnavailable', { label: 'WebM' });
+ stream = canvas.captureStream(fps);
+ var mime = motionMimeType();
+ recorder = new MediaRecorder(stream, { mimeType: mime, videoBitsPerSecond: 6000000 });
+ var chunks = [];
+ var startedAt = performance.now();
+ function draw(now) {
+ if (settled) return;
+ try {
+ var elapsed = Math.max(0, ((Number(now) || performance.now()) - startedAt) / 1000);
+ drawMotionFrame(ctx, backgroundImage, motionScene, elapsed);
+ raf = requestAnimationFrame(draw);
+ } catch (error) { finish(error); }
+ }
+ recorder.ondataavailable = function (event) {
+ if (!settled && event.data && event.data.size) chunks.push(event.data);
+ };
+ recorder.onerror = function (event) {
+ finish(event.error || exportError('viewer.export.error.mediaRecorder'));
+ };
+ recorder.onstop = function () {
+ if (settled) return;
+ try {
+ var blob = new Blob(chunks, { type: recorder.mimeType || mime });
+ if (!blob.size) throw exportError('viewer.export.error.emptyWebm');
+ finish(null, blob);
+ } catch (error) { finish(error); }
+ };
+ drawMotionFrame(ctx, backgroundImage, motionScene, 0);
+ recorder.start(250);
+ if (settled) return;
+ startedAt = performance.now();
+ raf = requestAnimationFrame(draw);
+ durationTimer = setTimeout(function () {
+ if (settled || recorder.state === 'inactive') return;
+ // 保留最佳努力的编码器 flush;失败后仍通过 stop 收集最后的片段。
+ try { recorder.requestData(); } catch (_) {}
+ if (settled) return;
+ flushTimer = setTimeout(function () {
+ if (settled) return;
+ try { if (recorder.state !== 'inactive') recorder.stop(); }
+ catch (error) { finish(error); }
+ }, 120);
+ }, duration);
+ } catch (error) { finish(error); }
};
- recorder.onstop = function () {
- cleanup();
- var blob = new Blob(chunks, { type: recorder.mimeType || mime });
- if (!blob.size) reject(exportError('viewer.export.error.emptyWebm'));
- else resolve(blob);
+ backgroundImage.onerror = function () {
+ finish(exportError('viewer.export.error.webmBackground'));
};
- drawMotionFrame(ctx, backgroundImage, motionScene, 0);
- recorder.start(250);
- startedAt = performance.now();
- raf = requestAnimationFrame(draw);
- setTimeout(function () {
- if (recorder.state === 'inactive') return;
- // Chromium normally emits the final chunk during stop(), but
- // some embedded browser shells need an explicit encoder flush
- // first. Keep the short grace window bounded and harmless for
- // browsers that already delivered timeslice chunks.
- try { recorder.requestData(); } catch (_) {}
- setTimeout(function () {
- if (recorder.state !== 'inactive') recorder.stop();
- }, 120);
- }, duration);
- };
- backgroundImage.onerror = function () {
- URL.revokeObjectURL(sourceUrl);
- reject(exportError('viewer.export.error.webmBackground'));
- };
- backgroundImage.src = sourceUrl;
+ backgroundImage.src = sourceUrl;
+ } catch (error) { finish(error); }
});
}
diff --git a/docs/gallery/artifacts/async-job-roundtrip.sequence.html b/docs/gallery/artifacts/async-job-roundtrip.sequence.html
index 8fd87153..db7b53f5 100644
--- a/docs/gallery/artifacts/async-job-roundtrip.sequence.html
+++ b/docs/gallery/artifacts/async-job-roundtrip.sequence.html
@@ -6686,7 +6686,6 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
var vb = svg.viewBox.baseVal;
var scale = Math.min(1, 1280 / vb.width);
var data = serializeSvg(scale);
- var sourceUrl = URL.createObjectURL(new Blob([data.svgString], { type: 'image/svg+xml;charset=utf-8' }));
function createMotionScene(root) {
var rootMatrix = root.getCTM ? root.getCTM() : null;
@@ -6838,73 +6837,99 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
var motionScene = createMotionScene(svg);
return new Promise(function (resolve, reject) {
- var backgroundImage = new Image();
- backgroundImage.onload = function () {
- var canvas = document.createElement('canvas');
- canvas.width = Math.max(2, Math.round(data.width / 2) * 2);
- canvas.height = Math.max(2, Math.round(data.height / 2) * 2);
- var ctx = canvas.getContext('2d');
- var stream = canvas.captureStream(fps);
- var mime = motionMimeType();
- var recorder;
- try {
- recorder = new MediaRecorder(stream, { mimeType: mime, videoBitsPerSecond: 6000000 });
- } catch (err) {
- URL.revokeObjectURL(sourceUrl);
- stream.getTracks().forEach(function (track) { track.stop(); });
- reject(err);
- return;
- }
- var chunks = [];
- var raf = 0;
- var stopped = false;
- var startedAt = performance.now();
- function cleanup() {
- if (stopped) return;
- stopped = true;
- cancelAnimationFrame(raf);
- URL.revokeObjectURL(sourceUrl);
- stream.getTracks().forEach(function (track) { track.stop(); });
+ var sourceUrl = null;
+ var backgroundImage = null;
+ var stream = null;
+ var recorder = null;
+ var raf = 0;
+ var durationTimer = 0;
+ var flushTimer = 0;
+ var settled = false;
+
+ function finish(error, blob) {
+ if (settled) return;
+ // 先锁定终态:停止录制和释放流可能产生晚到的编码事件。
+ settled = true;
+ cancelAnimationFrame(raf);
+ clearTimeout(durationTimer);
+ clearTimeout(flushTimer);
+ if (backgroundImage) {
+ backgroundImage.onload = null;
+ backgroundImage.onerror = null;
}
- function draw(now) {
- var elapsed = Math.max(0, ((Number(now) || performance.now()) - startedAt) / 1000);
- drawMotionFrame(ctx, backgroundImage, motionScene, elapsed);
- raf = requestAnimationFrame(draw);
+ if (recorder) {
+ recorder.ondataavailable = null;
+ recorder.onerror = null;
+ recorder.onstop = null;
+ try { if (recorder.state !== 'inactive') recorder.stop(); } catch (_) {}
}
- recorder.ondataavailable = function (event) {
- if (event.data && event.data.size) chunks.push(event.data);
- };
- recorder.onerror = function (event) {
- cleanup();
- reject(event.error || exportError('viewer.export.error.mediaRecorder'));
+ if (stream) stream.getTracks().forEach(function (track) { track.stop(); });
+ if (sourceUrl) URL.revokeObjectURL(sourceUrl);
+ if (blob) resolve(blob);
+ else reject(error);
+ }
+
+ try {
+ sourceUrl = URL.createObjectURL(new Blob([data.svgString], { type: 'image/svg+xml;charset=utf-8' }));
+ backgroundImage = new Image();
+ backgroundImage.onload = function () {
+ if (settled) return;
+ try {
+ var canvas = document.createElement('canvas');
+ canvas.width = Math.max(2, Math.round(data.width / 2) * 2);
+ canvas.height = Math.max(2, Math.round(data.height / 2) * 2);
+ var ctx = canvas.getContext('2d');
+ if (!ctx) throw exportError('viewer.export.error.contextUnavailable', { label: 'WebM' });
+ stream = canvas.captureStream(fps);
+ var mime = motionMimeType();
+ recorder = new MediaRecorder(stream, { mimeType: mime, videoBitsPerSecond: 6000000 });
+ var chunks = [];
+ var startedAt = performance.now();
+ function draw(now) {
+ if (settled) return;
+ try {
+ var elapsed = Math.max(0, ((Number(now) || performance.now()) - startedAt) / 1000);
+ drawMotionFrame(ctx, backgroundImage, motionScene, elapsed);
+ raf = requestAnimationFrame(draw);
+ } catch (error) { finish(error); }
+ }
+ recorder.ondataavailable = function (event) {
+ if (!settled && event.data && event.data.size) chunks.push(event.data);
+ };
+ recorder.onerror = function (event) {
+ finish(event.error || exportError('viewer.export.error.mediaRecorder'));
+ };
+ recorder.onstop = function () {
+ if (settled) return;
+ try {
+ var blob = new Blob(chunks, { type: recorder.mimeType || mime });
+ if (!blob.size) throw exportError('viewer.export.error.emptyWebm');
+ finish(null, blob);
+ } catch (error) { finish(error); }
+ };
+ drawMotionFrame(ctx, backgroundImage, motionScene, 0);
+ recorder.start(250);
+ if (settled) return;
+ startedAt = performance.now();
+ raf = requestAnimationFrame(draw);
+ durationTimer = setTimeout(function () {
+ if (settled || recorder.state === 'inactive') return;
+ // 保留最佳努力的编码器 flush;失败后仍通过 stop 收集最后的片段。
+ try { recorder.requestData(); } catch (_) {}
+ if (settled) return;
+ flushTimer = setTimeout(function () {
+ if (settled) return;
+ try { if (recorder.state !== 'inactive') recorder.stop(); }
+ catch (error) { finish(error); }
+ }, 120);
+ }, duration);
+ } catch (error) { finish(error); }
};
- recorder.onstop = function () {
- cleanup();
- var blob = new Blob(chunks, { type: recorder.mimeType || mime });
- if (!blob.size) reject(exportError('viewer.export.error.emptyWebm'));
- else resolve(blob);
+ backgroundImage.onerror = function () {
+ finish(exportError('viewer.export.error.webmBackground'));
};
- drawMotionFrame(ctx, backgroundImage, motionScene, 0);
- recorder.start(250);
- startedAt = performance.now();
- raf = requestAnimationFrame(draw);
- setTimeout(function () {
- if (recorder.state === 'inactive') return;
- // Chromium normally emits the final chunk during stop(), but
- // some embedded browser shells need an explicit encoder flush
- // first. Keep the short grace window bounded and harmless for
- // browsers that already delivered timeslice chunks.
- try { recorder.requestData(); } catch (_) {}
- setTimeout(function () {
- if (recorder.state !== 'inactive') recorder.stop();
- }, 120);
- }, duration);
- };
- backgroundImage.onerror = function () {
- URL.revokeObjectURL(sourceUrl);
- reject(exportError('viewer.export.error.webmBackground'));
- };
- backgroundImage.src = sourceUrl;
+ backgroundImage.src = sourceUrl;
+ } catch (error) { finish(error); }
});
}
diff --git a/docs/gallery/artifacts/cache-miss.sequence.html b/docs/gallery/artifacts/cache-miss.sequence.html
index 321c769d..ecea17f6 100644
--- a/docs/gallery/artifacts/cache-miss.sequence.html
+++ b/docs/gallery/artifacts/cache-miss.sequence.html
@@ -6674,7 +6674,6 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
var vb = svg.viewBox.baseVal;
var scale = Math.min(1, 1280 / vb.width);
var data = serializeSvg(scale);
- var sourceUrl = URL.createObjectURL(new Blob([data.svgString], { type: 'image/svg+xml;charset=utf-8' }));
function createMotionScene(root) {
var rootMatrix = root.getCTM ? root.getCTM() : null;
@@ -6826,73 +6825,99 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
var motionScene = createMotionScene(svg);
return new Promise(function (resolve, reject) {
- var backgroundImage = new Image();
- backgroundImage.onload = function () {
- var canvas = document.createElement('canvas');
- canvas.width = Math.max(2, Math.round(data.width / 2) * 2);
- canvas.height = Math.max(2, Math.round(data.height / 2) * 2);
- var ctx = canvas.getContext('2d');
- var stream = canvas.captureStream(fps);
- var mime = motionMimeType();
- var recorder;
- try {
- recorder = new MediaRecorder(stream, { mimeType: mime, videoBitsPerSecond: 6000000 });
- } catch (err) {
- URL.revokeObjectURL(sourceUrl);
- stream.getTracks().forEach(function (track) { track.stop(); });
- reject(err);
- return;
- }
- var chunks = [];
- var raf = 0;
- var stopped = false;
- var startedAt = performance.now();
- function cleanup() {
- if (stopped) return;
- stopped = true;
- cancelAnimationFrame(raf);
- URL.revokeObjectURL(sourceUrl);
- stream.getTracks().forEach(function (track) { track.stop(); });
+ var sourceUrl = null;
+ var backgroundImage = null;
+ var stream = null;
+ var recorder = null;
+ var raf = 0;
+ var durationTimer = 0;
+ var flushTimer = 0;
+ var settled = false;
+
+ function finish(error, blob) {
+ if (settled) return;
+ // 先锁定终态:停止录制和释放流可能产生晚到的编码事件。
+ settled = true;
+ cancelAnimationFrame(raf);
+ clearTimeout(durationTimer);
+ clearTimeout(flushTimer);
+ if (backgroundImage) {
+ backgroundImage.onload = null;
+ backgroundImage.onerror = null;
}
- function draw(now) {
- var elapsed = Math.max(0, ((Number(now) || performance.now()) - startedAt) / 1000);
- drawMotionFrame(ctx, backgroundImage, motionScene, elapsed);
- raf = requestAnimationFrame(draw);
+ if (recorder) {
+ recorder.ondataavailable = null;
+ recorder.onerror = null;
+ recorder.onstop = null;
+ try { if (recorder.state !== 'inactive') recorder.stop(); } catch (_) {}
}
- recorder.ondataavailable = function (event) {
- if (event.data && event.data.size) chunks.push(event.data);
- };
- recorder.onerror = function (event) {
- cleanup();
- reject(event.error || exportError('viewer.export.error.mediaRecorder'));
+ if (stream) stream.getTracks().forEach(function (track) { track.stop(); });
+ if (sourceUrl) URL.revokeObjectURL(sourceUrl);
+ if (blob) resolve(blob);
+ else reject(error);
+ }
+
+ try {
+ sourceUrl = URL.createObjectURL(new Blob([data.svgString], { type: 'image/svg+xml;charset=utf-8' }));
+ backgroundImage = new Image();
+ backgroundImage.onload = function () {
+ if (settled) return;
+ try {
+ var canvas = document.createElement('canvas');
+ canvas.width = Math.max(2, Math.round(data.width / 2) * 2);
+ canvas.height = Math.max(2, Math.round(data.height / 2) * 2);
+ var ctx = canvas.getContext('2d');
+ if (!ctx) throw exportError('viewer.export.error.contextUnavailable', { label: 'WebM' });
+ stream = canvas.captureStream(fps);
+ var mime = motionMimeType();
+ recorder = new MediaRecorder(stream, { mimeType: mime, videoBitsPerSecond: 6000000 });
+ var chunks = [];
+ var startedAt = performance.now();
+ function draw(now) {
+ if (settled) return;
+ try {
+ var elapsed = Math.max(0, ((Number(now) || performance.now()) - startedAt) / 1000);
+ drawMotionFrame(ctx, backgroundImage, motionScene, elapsed);
+ raf = requestAnimationFrame(draw);
+ } catch (error) { finish(error); }
+ }
+ recorder.ondataavailable = function (event) {
+ if (!settled && event.data && event.data.size) chunks.push(event.data);
+ };
+ recorder.onerror = function (event) {
+ finish(event.error || exportError('viewer.export.error.mediaRecorder'));
+ };
+ recorder.onstop = function () {
+ if (settled) return;
+ try {
+ var blob = new Blob(chunks, { type: recorder.mimeType || mime });
+ if (!blob.size) throw exportError('viewer.export.error.emptyWebm');
+ finish(null, blob);
+ } catch (error) { finish(error); }
+ };
+ drawMotionFrame(ctx, backgroundImage, motionScene, 0);
+ recorder.start(250);
+ if (settled) return;
+ startedAt = performance.now();
+ raf = requestAnimationFrame(draw);
+ durationTimer = setTimeout(function () {
+ if (settled || recorder.state === 'inactive') return;
+ // 保留最佳努力的编码器 flush;失败后仍通过 stop 收集最后的片段。
+ try { recorder.requestData(); } catch (_) {}
+ if (settled) return;
+ flushTimer = setTimeout(function () {
+ if (settled) return;
+ try { if (recorder.state !== 'inactive') recorder.stop(); }
+ catch (error) { finish(error); }
+ }, 120);
+ }, duration);
+ } catch (error) { finish(error); }
};
- recorder.onstop = function () {
- cleanup();
- var blob = new Blob(chunks, { type: recorder.mimeType || mime });
- if (!blob.size) reject(exportError('viewer.export.error.emptyWebm'));
- else resolve(blob);
+ backgroundImage.onerror = function () {
+ finish(exportError('viewer.export.error.webmBackground'));
};
- drawMotionFrame(ctx, backgroundImage, motionScene, 0);
- recorder.start(250);
- startedAt = performance.now();
- raf = requestAnimationFrame(draw);
- setTimeout(function () {
- if (recorder.state === 'inactive') return;
- // Chromium normally emits the final chunk during stop(), but
- // some embedded browser shells need an explicit encoder flush
- // first. Keep the short grace window bounded and harmless for
- // browsers that already delivered timeslice chunks.
- try { recorder.requestData(); } catch (_) {}
- setTimeout(function () {
- if (recorder.state !== 'inactive') recorder.stop();
- }, 120);
- }, duration);
- };
- backgroundImage.onerror = function () {
- URL.revokeObjectURL(sourceUrl);
- reject(exportError('viewer.export.error.webmBackground'));
- };
- backgroundImage.src = sourceUrl;
+ backgroundImage.src = sourceUrl;
+ } catch (error) { finish(error); }
});
}
diff --git a/docs/gallery/artifacts/deployment-release.lifecycle.html b/docs/gallery/artifacts/deployment-release.lifecycle.html
index ae7f46c1..d07fdd25 100644
--- a/docs/gallery/artifacts/deployment-release.lifecycle.html
+++ b/docs/gallery/artifacts/deployment-release.lifecycle.html
@@ -6677,7 +6677,6 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
var vb = svg.viewBox.baseVal;
var scale = Math.min(1, 1280 / vb.width);
var data = serializeSvg(scale);
- var sourceUrl = URL.createObjectURL(new Blob([data.svgString], { type: 'image/svg+xml;charset=utf-8' }));
function createMotionScene(root) {
var rootMatrix = root.getCTM ? root.getCTM() : null;
@@ -6829,73 +6828,99 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
var motionScene = createMotionScene(svg);
return new Promise(function (resolve, reject) {
- var backgroundImage = new Image();
- backgroundImage.onload = function () {
- var canvas = document.createElement('canvas');
- canvas.width = Math.max(2, Math.round(data.width / 2) * 2);
- canvas.height = Math.max(2, Math.round(data.height / 2) * 2);
- var ctx = canvas.getContext('2d');
- var stream = canvas.captureStream(fps);
- var mime = motionMimeType();
- var recorder;
- try {
- recorder = new MediaRecorder(stream, { mimeType: mime, videoBitsPerSecond: 6000000 });
- } catch (err) {
- URL.revokeObjectURL(sourceUrl);
- stream.getTracks().forEach(function (track) { track.stop(); });
- reject(err);
- return;
- }
- var chunks = [];
- var raf = 0;
- var stopped = false;
- var startedAt = performance.now();
- function cleanup() {
- if (stopped) return;
- stopped = true;
- cancelAnimationFrame(raf);
- URL.revokeObjectURL(sourceUrl);
- stream.getTracks().forEach(function (track) { track.stop(); });
+ var sourceUrl = null;
+ var backgroundImage = null;
+ var stream = null;
+ var recorder = null;
+ var raf = 0;
+ var durationTimer = 0;
+ var flushTimer = 0;
+ var settled = false;
+
+ function finish(error, blob) {
+ if (settled) return;
+ // 先锁定终态:停止录制和释放流可能产生晚到的编码事件。
+ settled = true;
+ cancelAnimationFrame(raf);
+ clearTimeout(durationTimer);
+ clearTimeout(flushTimer);
+ if (backgroundImage) {
+ backgroundImage.onload = null;
+ backgroundImage.onerror = null;
}
- function draw(now) {
- var elapsed = Math.max(0, ((Number(now) || performance.now()) - startedAt) / 1000);
- drawMotionFrame(ctx, backgroundImage, motionScene, elapsed);
- raf = requestAnimationFrame(draw);
+ if (recorder) {
+ recorder.ondataavailable = null;
+ recorder.onerror = null;
+ recorder.onstop = null;
+ try { if (recorder.state !== 'inactive') recorder.stop(); } catch (_) {}
}
- recorder.ondataavailable = function (event) {
- if (event.data && event.data.size) chunks.push(event.data);
- };
- recorder.onerror = function (event) {
- cleanup();
- reject(event.error || exportError('viewer.export.error.mediaRecorder'));
+ if (stream) stream.getTracks().forEach(function (track) { track.stop(); });
+ if (sourceUrl) URL.revokeObjectURL(sourceUrl);
+ if (blob) resolve(blob);
+ else reject(error);
+ }
+
+ try {
+ sourceUrl = URL.createObjectURL(new Blob([data.svgString], { type: 'image/svg+xml;charset=utf-8' }));
+ backgroundImage = new Image();
+ backgroundImage.onload = function () {
+ if (settled) return;
+ try {
+ var canvas = document.createElement('canvas');
+ canvas.width = Math.max(2, Math.round(data.width / 2) * 2);
+ canvas.height = Math.max(2, Math.round(data.height / 2) * 2);
+ var ctx = canvas.getContext('2d');
+ if (!ctx) throw exportError('viewer.export.error.contextUnavailable', { label: 'WebM' });
+ stream = canvas.captureStream(fps);
+ var mime = motionMimeType();
+ recorder = new MediaRecorder(stream, { mimeType: mime, videoBitsPerSecond: 6000000 });
+ var chunks = [];
+ var startedAt = performance.now();
+ function draw(now) {
+ if (settled) return;
+ try {
+ var elapsed = Math.max(0, ((Number(now) || performance.now()) - startedAt) / 1000);
+ drawMotionFrame(ctx, backgroundImage, motionScene, elapsed);
+ raf = requestAnimationFrame(draw);
+ } catch (error) { finish(error); }
+ }
+ recorder.ondataavailable = function (event) {
+ if (!settled && event.data && event.data.size) chunks.push(event.data);
+ };
+ recorder.onerror = function (event) {
+ finish(event.error || exportError('viewer.export.error.mediaRecorder'));
+ };
+ recorder.onstop = function () {
+ if (settled) return;
+ try {
+ var blob = new Blob(chunks, { type: recorder.mimeType || mime });
+ if (!blob.size) throw exportError('viewer.export.error.emptyWebm');
+ finish(null, blob);
+ } catch (error) { finish(error); }
+ };
+ drawMotionFrame(ctx, backgroundImage, motionScene, 0);
+ recorder.start(250);
+ if (settled) return;
+ startedAt = performance.now();
+ raf = requestAnimationFrame(draw);
+ durationTimer = setTimeout(function () {
+ if (settled || recorder.state === 'inactive') return;
+ // 保留最佳努力的编码器 flush;失败后仍通过 stop 收集最后的片段。
+ try { recorder.requestData(); } catch (_) {}
+ if (settled) return;
+ flushTimer = setTimeout(function () {
+ if (settled) return;
+ try { if (recorder.state !== 'inactive') recorder.stop(); }
+ catch (error) { finish(error); }
+ }, 120);
+ }, duration);
+ } catch (error) { finish(error); }
};
- recorder.onstop = function () {
- cleanup();
- var blob = new Blob(chunks, { type: recorder.mimeType || mime });
- if (!blob.size) reject(exportError('viewer.export.error.emptyWebm'));
- else resolve(blob);
+ backgroundImage.onerror = function () {
+ finish(exportError('viewer.export.error.webmBackground'));
};
- drawMotionFrame(ctx, backgroundImage, motionScene, 0);
- recorder.start(250);
- startedAt = performance.now();
- raf = requestAnimationFrame(draw);
- setTimeout(function () {
- if (recorder.state === 'inactive') return;
- // Chromium normally emits the final chunk during stop(), but
- // some embedded browser shells need an explicit encoder flush
- // first. Keep the short grace window bounded and harmless for
- // browsers that already delivered timeslice chunks.
- try { recorder.requestData(); } catch (_) {}
- setTimeout(function () {
- if (recorder.state !== 'inactive') recorder.stop();
- }, 120);
- }, duration);
- };
- backgroundImage.onerror = function () {
- URL.revokeObjectURL(sourceUrl);
- reject(exportError('viewer.export.error.webmBackground'));
- };
- backgroundImage.src = sourceUrl;
+ backgroundImage.src = sourceUrl;
+ } catch (error) { finish(error); }
});
}
diff --git a/docs/gallery/artifacts/event-stream.dataflow.html b/docs/gallery/artifacts/event-stream.dataflow.html
index ce3fb620..7cba0fc6 100644
--- a/docs/gallery/artifacts/event-stream.dataflow.html
+++ b/docs/gallery/artifacts/event-stream.dataflow.html
@@ -6698,7 +6698,6 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
var vb = svg.viewBox.baseVal;
var scale = Math.min(1, 1280 / vb.width);
var data = serializeSvg(scale);
- var sourceUrl = URL.createObjectURL(new Blob([data.svgString], { type: 'image/svg+xml;charset=utf-8' }));
function createMotionScene(root) {
var rootMatrix = root.getCTM ? root.getCTM() : null;
@@ -6850,73 +6849,99 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
var motionScene = createMotionScene(svg);
return new Promise(function (resolve, reject) {
- var backgroundImage = new Image();
- backgroundImage.onload = function () {
- var canvas = document.createElement('canvas');
- canvas.width = Math.max(2, Math.round(data.width / 2) * 2);
- canvas.height = Math.max(2, Math.round(data.height / 2) * 2);
- var ctx = canvas.getContext('2d');
- var stream = canvas.captureStream(fps);
- var mime = motionMimeType();
- var recorder;
- try {
- recorder = new MediaRecorder(stream, { mimeType: mime, videoBitsPerSecond: 6000000 });
- } catch (err) {
- URL.revokeObjectURL(sourceUrl);
- stream.getTracks().forEach(function (track) { track.stop(); });
- reject(err);
- return;
- }
- var chunks = [];
- var raf = 0;
- var stopped = false;
- var startedAt = performance.now();
- function cleanup() {
- if (stopped) return;
- stopped = true;
- cancelAnimationFrame(raf);
- URL.revokeObjectURL(sourceUrl);
- stream.getTracks().forEach(function (track) { track.stop(); });
+ var sourceUrl = null;
+ var backgroundImage = null;
+ var stream = null;
+ var recorder = null;
+ var raf = 0;
+ var durationTimer = 0;
+ var flushTimer = 0;
+ var settled = false;
+
+ function finish(error, blob) {
+ if (settled) return;
+ // 先锁定终态:停止录制和释放流可能产生晚到的编码事件。
+ settled = true;
+ cancelAnimationFrame(raf);
+ clearTimeout(durationTimer);
+ clearTimeout(flushTimer);
+ if (backgroundImage) {
+ backgroundImage.onload = null;
+ backgroundImage.onerror = null;
}
- function draw(now) {
- var elapsed = Math.max(0, ((Number(now) || performance.now()) - startedAt) / 1000);
- drawMotionFrame(ctx, backgroundImage, motionScene, elapsed);
- raf = requestAnimationFrame(draw);
+ if (recorder) {
+ recorder.ondataavailable = null;
+ recorder.onerror = null;
+ recorder.onstop = null;
+ try { if (recorder.state !== 'inactive') recorder.stop(); } catch (_) {}
}
- recorder.ondataavailable = function (event) {
- if (event.data && event.data.size) chunks.push(event.data);
- };
- recorder.onerror = function (event) {
- cleanup();
- reject(event.error || exportError('viewer.export.error.mediaRecorder'));
+ if (stream) stream.getTracks().forEach(function (track) { track.stop(); });
+ if (sourceUrl) URL.revokeObjectURL(sourceUrl);
+ if (blob) resolve(blob);
+ else reject(error);
+ }
+
+ try {
+ sourceUrl = URL.createObjectURL(new Blob([data.svgString], { type: 'image/svg+xml;charset=utf-8' }));
+ backgroundImage = new Image();
+ backgroundImage.onload = function () {
+ if (settled) return;
+ try {
+ var canvas = document.createElement('canvas');
+ canvas.width = Math.max(2, Math.round(data.width / 2) * 2);
+ canvas.height = Math.max(2, Math.round(data.height / 2) * 2);
+ var ctx = canvas.getContext('2d');
+ if (!ctx) throw exportError('viewer.export.error.contextUnavailable', { label: 'WebM' });
+ stream = canvas.captureStream(fps);
+ var mime = motionMimeType();
+ recorder = new MediaRecorder(stream, { mimeType: mime, videoBitsPerSecond: 6000000 });
+ var chunks = [];
+ var startedAt = performance.now();
+ function draw(now) {
+ if (settled) return;
+ try {
+ var elapsed = Math.max(0, ((Number(now) || performance.now()) - startedAt) / 1000);
+ drawMotionFrame(ctx, backgroundImage, motionScene, elapsed);
+ raf = requestAnimationFrame(draw);
+ } catch (error) { finish(error); }
+ }
+ recorder.ondataavailable = function (event) {
+ if (!settled && event.data && event.data.size) chunks.push(event.data);
+ };
+ recorder.onerror = function (event) {
+ finish(event.error || exportError('viewer.export.error.mediaRecorder'));
+ };
+ recorder.onstop = function () {
+ if (settled) return;
+ try {
+ var blob = new Blob(chunks, { type: recorder.mimeType || mime });
+ if (!blob.size) throw exportError('viewer.export.error.emptyWebm');
+ finish(null, blob);
+ } catch (error) { finish(error); }
+ };
+ drawMotionFrame(ctx, backgroundImage, motionScene, 0);
+ recorder.start(250);
+ if (settled) return;
+ startedAt = performance.now();
+ raf = requestAnimationFrame(draw);
+ durationTimer = setTimeout(function () {
+ if (settled || recorder.state === 'inactive') return;
+ // 保留最佳努力的编码器 flush;失败后仍通过 stop 收集最后的片段。
+ try { recorder.requestData(); } catch (_) {}
+ if (settled) return;
+ flushTimer = setTimeout(function () {
+ if (settled) return;
+ try { if (recorder.state !== 'inactive') recorder.stop(); }
+ catch (error) { finish(error); }
+ }, 120);
+ }, duration);
+ } catch (error) { finish(error); }
};
- recorder.onstop = function () {
- cleanup();
- var blob = new Blob(chunks, { type: recorder.mimeType || mime });
- if (!blob.size) reject(exportError('viewer.export.error.emptyWebm'));
- else resolve(blob);
+ backgroundImage.onerror = function () {
+ finish(exportError('viewer.export.error.webmBackground'));
};
- drawMotionFrame(ctx, backgroundImage, motionScene, 0);
- recorder.start(250);
- startedAt = performance.now();
- raf = requestAnimationFrame(draw);
- setTimeout(function () {
- if (recorder.state === 'inactive') return;
- // Chromium normally emits the final chunk during stop(), but
- // some embedded browser shells need an explicit encoder flush
- // first. Keep the short grace window bounded and harmless for
- // browsers that already delivered timeslice chunks.
- try { recorder.requestData(); } catch (_) {}
- setTimeout(function () {
- if (recorder.state !== 'inactive') recorder.stop();
- }, 120);
- }, duration);
- };
- backgroundImage.onerror = function () {
- URL.revokeObjectURL(sourceUrl);
- reject(exportError('viewer.export.error.webmBackground'));
- };
- backgroundImage.src = sourceUrl;
+ backgroundImage.src = sourceUrl;
+ } catch (error) { finish(error); }
});
}
diff --git a/docs/gallery/artifacts/incident-response.workflow.html b/docs/gallery/artifacts/incident-response.workflow.html
index ed2a1adf..49996111 100644
--- a/docs/gallery/artifacts/incident-response.workflow.html
+++ b/docs/gallery/artifacts/incident-response.workflow.html
@@ -6625,7 +6625,6 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
var vb = svg.viewBox.baseVal;
var scale = Math.min(1, 1280 / vb.width);
var data = serializeSvg(scale);
- var sourceUrl = URL.createObjectURL(new Blob([data.svgString], { type: 'image/svg+xml;charset=utf-8' }));
function createMotionScene(root) {
var rootMatrix = root.getCTM ? root.getCTM() : null;
@@ -6777,73 +6776,99 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
var motionScene = createMotionScene(svg);
return new Promise(function (resolve, reject) {
- var backgroundImage = new Image();
- backgroundImage.onload = function () {
- var canvas = document.createElement('canvas');
- canvas.width = Math.max(2, Math.round(data.width / 2) * 2);
- canvas.height = Math.max(2, Math.round(data.height / 2) * 2);
- var ctx = canvas.getContext('2d');
- var stream = canvas.captureStream(fps);
- var mime = motionMimeType();
- var recorder;
- try {
- recorder = new MediaRecorder(stream, { mimeType: mime, videoBitsPerSecond: 6000000 });
- } catch (err) {
- URL.revokeObjectURL(sourceUrl);
- stream.getTracks().forEach(function (track) { track.stop(); });
- reject(err);
- return;
- }
- var chunks = [];
- var raf = 0;
- var stopped = false;
- var startedAt = performance.now();
- function cleanup() {
- if (stopped) return;
- stopped = true;
- cancelAnimationFrame(raf);
- URL.revokeObjectURL(sourceUrl);
- stream.getTracks().forEach(function (track) { track.stop(); });
+ var sourceUrl = null;
+ var backgroundImage = null;
+ var stream = null;
+ var recorder = null;
+ var raf = 0;
+ var durationTimer = 0;
+ var flushTimer = 0;
+ var settled = false;
+
+ function finish(error, blob) {
+ if (settled) return;
+ // 先锁定终态:停止录制和释放流可能产生晚到的编码事件。
+ settled = true;
+ cancelAnimationFrame(raf);
+ clearTimeout(durationTimer);
+ clearTimeout(flushTimer);
+ if (backgroundImage) {
+ backgroundImage.onload = null;
+ backgroundImage.onerror = null;
}
- function draw(now) {
- var elapsed = Math.max(0, ((Number(now) || performance.now()) - startedAt) / 1000);
- drawMotionFrame(ctx, backgroundImage, motionScene, elapsed);
- raf = requestAnimationFrame(draw);
+ if (recorder) {
+ recorder.ondataavailable = null;
+ recorder.onerror = null;
+ recorder.onstop = null;
+ try { if (recorder.state !== 'inactive') recorder.stop(); } catch (_) {}
}
- recorder.ondataavailable = function (event) {
- if (event.data && event.data.size) chunks.push(event.data);
- };
- recorder.onerror = function (event) {
- cleanup();
- reject(event.error || exportError('viewer.export.error.mediaRecorder'));
+ if (stream) stream.getTracks().forEach(function (track) { track.stop(); });
+ if (sourceUrl) URL.revokeObjectURL(sourceUrl);
+ if (blob) resolve(blob);
+ else reject(error);
+ }
+
+ try {
+ sourceUrl = URL.createObjectURL(new Blob([data.svgString], { type: 'image/svg+xml;charset=utf-8' }));
+ backgroundImage = new Image();
+ backgroundImage.onload = function () {
+ if (settled) return;
+ try {
+ var canvas = document.createElement('canvas');
+ canvas.width = Math.max(2, Math.round(data.width / 2) * 2);
+ canvas.height = Math.max(2, Math.round(data.height / 2) * 2);
+ var ctx = canvas.getContext('2d');
+ if (!ctx) throw exportError('viewer.export.error.contextUnavailable', { label: 'WebM' });
+ stream = canvas.captureStream(fps);
+ var mime = motionMimeType();
+ recorder = new MediaRecorder(stream, { mimeType: mime, videoBitsPerSecond: 6000000 });
+ var chunks = [];
+ var startedAt = performance.now();
+ function draw(now) {
+ if (settled) return;
+ try {
+ var elapsed = Math.max(0, ((Number(now) || performance.now()) - startedAt) / 1000);
+ drawMotionFrame(ctx, backgroundImage, motionScene, elapsed);
+ raf = requestAnimationFrame(draw);
+ } catch (error) { finish(error); }
+ }
+ recorder.ondataavailable = function (event) {
+ if (!settled && event.data && event.data.size) chunks.push(event.data);
+ };
+ recorder.onerror = function (event) {
+ finish(event.error || exportError('viewer.export.error.mediaRecorder'));
+ };
+ recorder.onstop = function () {
+ if (settled) return;
+ try {
+ var blob = new Blob(chunks, { type: recorder.mimeType || mime });
+ if (!blob.size) throw exportError('viewer.export.error.emptyWebm');
+ finish(null, blob);
+ } catch (error) { finish(error); }
+ };
+ drawMotionFrame(ctx, backgroundImage, motionScene, 0);
+ recorder.start(250);
+ if (settled) return;
+ startedAt = performance.now();
+ raf = requestAnimationFrame(draw);
+ durationTimer = setTimeout(function () {
+ if (settled || recorder.state === 'inactive') return;
+ // 保留最佳努力的编码器 flush;失败后仍通过 stop 收集最后的片段。
+ try { recorder.requestData(); } catch (_) {}
+ if (settled) return;
+ flushTimer = setTimeout(function () {
+ if (settled) return;
+ try { if (recorder.state !== 'inactive') recorder.stop(); }
+ catch (error) { finish(error); }
+ }, 120);
+ }, duration);
+ } catch (error) { finish(error); }
};
- recorder.onstop = function () {
- cleanup();
- var blob = new Blob(chunks, { type: recorder.mimeType || mime });
- if (!blob.size) reject(exportError('viewer.export.error.emptyWebm'));
- else resolve(blob);
+ backgroundImage.onerror = function () {
+ finish(exportError('viewer.export.error.webmBackground'));
};
- drawMotionFrame(ctx, backgroundImage, motionScene, 0);
- recorder.start(250);
- startedAt = performance.now();
- raf = requestAnimationFrame(draw);
- setTimeout(function () {
- if (recorder.state === 'inactive') return;
- // Chromium normally emits the final chunk during stop(), but
- // some embedded browser shells need an explicit encoder flush
- // first. Keep the short grace window bounded and harmless for
- // browsers that already delivered timeslice chunks.
- try { recorder.requestData(); } catch (_) {}
- setTimeout(function () {
- if (recorder.state !== 'inactive') recorder.stop();
- }, 120);
- }, duration);
- };
- backgroundImage.onerror = function () {
- URL.revokeObjectURL(sourceUrl);
- reject(exportError('viewer.export.error.webmBackground'));
- };
- backgroundImage.src = sourceUrl;
+ backgroundImage.src = sourceUrl;
+ } catch (error) { finish(error); }
});
}
diff --git a/docs/gallery/artifacts/product-analytics.dataflow.html b/docs/gallery/artifacts/product-analytics.dataflow.html
index d454321b..83db25a4 100644
--- a/docs/gallery/artifacts/product-analytics.dataflow.html
+++ b/docs/gallery/artifacts/product-analytics.dataflow.html
@@ -6659,7 +6659,6 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
var vb = svg.viewBox.baseVal;
var scale = Math.min(1, 1280 / vb.width);
var data = serializeSvg(scale);
- var sourceUrl = URL.createObjectURL(new Blob([data.svgString], { type: 'image/svg+xml;charset=utf-8' }));
function createMotionScene(root) {
var rootMatrix = root.getCTM ? root.getCTM() : null;
@@ -6811,73 +6810,99 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
var motionScene = createMotionScene(svg);
return new Promise(function (resolve, reject) {
- var backgroundImage = new Image();
- backgroundImage.onload = function () {
- var canvas = document.createElement('canvas');
- canvas.width = Math.max(2, Math.round(data.width / 2) * 2);
- canvas.height = Math.max(2, Math.round(data.height / 2) * 2);
- var ctx = canvas.getContext('2d');
- var stream = canvas.captureStream(fps);
- var mime = motionMimeType();
- var recorder;
- try {
- recorder = new MediaRecorder(stream, { mimeType: mime, videoBitsPerSecond: 6000000 });
- } catch (err) {
- URL.revokeObjectURL(sourceUrl);
- stream.getTracks().forEach(function (track) { track.stop(); });
- reject(err);
- return;
- }
- var chunks = [];
- var raf = 0;
- var stopped = false;
- var startedAt = performance.now();
- function cleanup() {
- if (stopped) return;
- stopped = true;
- cancelAnimationFrame(raf);
- URL.revokeObjectURL(sourceUrl);
- stream.getTracks().forEach(function (track) { track.stop(); });
+ var sourceUrl = null;
+ var backgroundImage = null;
+ var stream = null;
+ var recorder = null;
+ var raf = 0;
+ var durationTimer = 0;
+ var flushTimer = 0;
+ var settled = false;
+
+ function finish(error, blob) {
+ if (settled) return;
+ // 先锁定终态:停止录制和释放流可能产生晚到的编码事件。
+ settled = true;
+ cancelAnimationFrame(raf);
+ clearTimeout(durationTimer);
+ clearTimeout(flushTimer);
+ if (backgroundImage) {
+ backgroundImage.onload = null;
+ backgroundImage.onerror = null;
}
- function draw(now) {
- var elapsed = Math.max(0, ((Number(now) || performance.now()) - startedAt) / 1000);
- drawMotionFrame(ctx, backgroundImage, motionScene, elapsed);
- raf = requestAnimationFrame(draw);
+ if (recorder) {
+ recorder.ondataavailable = null;
+ recorder.onerror = null;
+ recorder.onstop = null;
+ try { if (recorder.state !== 'inactive') recorder.stop(); } catch (_) {}
}
- recorder.ondataavailable = function (event) {
- if (event.data && event.data.size) chunks.push(event.data);
- };
- recorder.onerror = function (event) {
- cleanup();
- reject(event.error || exportError('viewer.export.error.mediaRecorder'));
+ if (stream) stream.getTracks().forEach(function (track) { track.stop(); });
+ if (sourceUrl) URL.revokeObjectURL(sourceUrl);
+ if (blob) resolve(blob);
+ else reject(error);
+ }
+
+ try {
+ sourceUrl = URL.createObjectURL(new Blob([data.svgString], { type: 'image/svg+xml;charset=utf-8' }));
+ backgroundImage = new Image();
+ backgroundImage.onload = function () {
+ if (settled) return;
+ try {
+ var canvas = document.createElement('canvas');
+ canvas.width = Math.max(2, Math.round(data.width / 2) * 2);
+ canvas.height = Math.max(2, Math.round(data.height / 2) * 2);
+ var ctx = canvas.getContext('2d');
+ if (!ctx) throw exportError('viewer.export.error.contextUnavailable', { label: 'WebM' });
+ stream = canvas.captureStream(fps);
+ var mime = motionMimeType();
+ recorder = new MediaRecorder(stream, { mimeType: mime, videoBitsPerSecond: 6000000 });
+ var chunks = [];
+ var startedAt = performance.now();
+ function draw(now) {
+ if (settled) return;
+ try {
+ var elapsed = Math.max(0, ((Number(now) || performance.now()) - startedAt) / 1000);
+ drawMotionFrame(ctx, backgroundImage, motionScene, elapsed);
+ raf = requestAnimationFrame(draw);
+ } catch (error) { finish(error); }
+ }
+ recorder.ondataavailable = function (event) {
+ if (!settled && event.data && event.data.size) chunks.push(event.data);
+ };
+ recorder.onerror = function (event) {
+ finish(event.error || exportError('viewer.export.error.mediaRecorder'));
+ };
+ recorder.onstop = function () {
+ if (settled) return;
+ try {
+ var blob = new Blob(chunks, { type: recorder.mimeType || mime });
+ if (!blob.size) throw exportError('viewer.export.error.emptyWebm');
+ finish(null, blob);
+ } catch (error) { finish(error); }
+ };
+ drawMotionFrame(ctx, backgroundImage, motionScene, 0);
+ recorder.start(250);
+ if (settled) return;
+ startedAt = performance.now();
+ raf = requestAnimationFrame(draw);
+ durationTimer = setTimeout(function () {
+ if (settled || recorder.state === 'inactive') return;
+ // 保留最佳努力的编码器 flush;失败后仍通过 stop 收集最后的片段。
+ try { recorder.requestData(); } catch (_) {}
+ if (settled) return;
+ flushTimer = setTimeout(function () {
+ if (settled) return;
+ try { if (recorder.state !== 'inactive') recorder.stop(); }
+ catch (error) { finish(error); }
+ }, 120);
+ }, duration);
+ } catch (error) { finish(error); }
};
- recorder.onstop = function () {
- cleanup();
- var blob = new Blob(chunks, { type: recorder.mimeType || mime });
- if (!blob.size) reject(exportError('viewer.export.error.emptyWebm'));
- else resolve(blob);
+ backgroundImage.onerror = function () {
+ finish(exportError('viewer.export.error.webmBackground'));
};
- drawMotionFrame(ctx, backgroundImage, motionScene, 0);
- recorder.start(250);
- startedAt = performance.now();
- raf = requestAnimationFrame(draw);
- setTimeout(function () {
- if (recorder.state === 'inactive') return;
- // Chromium normally emits the final chunk during stop(), but
- // some embedded browser shells need an explicit encoder flush
- // first. Keep the short grace window bounded and harmless for
- // browsers that already delivered timeslice chunks.
- try { recorder.requestData(); } catch (_) {}
- setTimeout(function () {
- if (recorder.state !== 'inactive') recorder.stop();
- }, 120);
- }, duration);
- };
- backgroundImage.onerror = function () {
- URL.revokeObjectURL(sourceUrl);
- reject(exportError('viewer.export.error.webmBackground'));
- };
- backgroundImage.src = sourceUrl;
+ backgroundImage.src = sourceUrl;
+ } catch (error) { finish(error); }
});
}
diff --git a/docs/gallery/artifacts/production-deployment.architecture.html b/docs/gallery/artifacts/production-deployment.architecture.html
index 8385e07a..6aae4d31 100644
--- a/docs/gallery/artifacts/production-deployment.architecture.html
+++ b/docs/gallery/artifacts/production-deployment.architecture.html
@@ -6702,7 +6702,6 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
var vb = svg.viewBox.baseVal;
var scale = Math.min(1, 1280 / vb.width);
var data = serializeSvg(scale);
- var sourceUrl = URL.createObjectURL(new Blob([data.svgString], { type: 'image/svg+xml;charset=utf-8' }));
function createMotionScene(root) {
var rootMatrix = root.getCTM ? root.getCTM() : null;
@@ -6854,73 +6853,99 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
var motionScene = createMotionScene(svg);
return new Promise(function (resolve, reject) {
- var backgroundImage = new Image();
- backgroundImage.onload = function () {
- var canvas = document.createElement('canvas');
- canvas.width = Math.max(2, Math.round(data.width / 2) * 2);
- canvas.height = Math.max(2, Math.round(data.height / 2) * 2);
- var ctx = canvas.getContext('2d');
- var stream = canvas.captureStream(fps);
- var mime = motionMimeType();
- var recorder;
- try {
- recorder = new MediaRecorder(stream, { mimeType: mime, videoBitsPerSecond: 6000000 });
- } catch (err) {
- URL.revokeObjectURL(sourceUrl);
- stream.getTracks().forEach(function (track) { track.stop(); });
- reject(err);
- return;
- }
- var chunks = [];
- var raf = 0;
- var stopped = false;
- var startedAt = performance.now();
- function cleanup() {
- if (stopped) return;
- stopped = true;
- cancelAnimationFrame(raf);
- URL.revokeObjectURL(sourceUrl);
- stream.getTracks().forEach(function (track) { track.stop(); });
+ var sourceUrl = null;
+ var backgroundImage = null;
+ var stream = null;
+ var recorder = null;
+ var raf = 0;
+ var durationTimer = 0;
+ var flushTimer = 0;
+ var settled = false;
+
+ function finish(error, blob) {
+ if (settled) return;
+ // 先锁定终态:停止录制和释放流可能产生晚到的编码事件。
+ settled = true;
+ cancelAnimationFrame(raf);
+ clearTimeout(durationTimer);
+ clearTimeout(flushTimer);
+ if (backgroundImage) {
+ backgroundImage.onload = null;
+ backgroundImage.onerror = null;
}
- function draw(now) {
- var elapsed = Math.max(0, ((Number(now) || performance.now()) - startedAt) / 1000);
- drawMotionFrame(ctx, backgroundImage, motionScene, elapsed);
- raf = requestAnimationFrame(draw);
+ if (recorder) {
+ recorder.ondataavailable = null;
+ recorder.onerror = null;
+ recorder.onstop = null;
+ try { if (recorder.state !== 'inactive') recorder.stop(); } catch (_) {}
}
- recorder.ondataavailable = function (event) {
- if (event.data && event.data.size) chunks.push(event.data);
- };
- recorder.onerror = function (event) {
- cleanup();
- reject(event.error || exportError('viewer.export.error.mediaRecorder'));
+ if (stream) stream.getTracks().forEach(function (track) { track.stop(); });
+ if (sourceUrl) URL.revokeObjectURL(sourceUrl);
+ if (blob) resolve(blob);
+ else reject(error);
+ }
+
+ try {
+ sourceUrl = URL.createObjectURL(new Blob([data.svgString], { type: 'image/svg+xml;charset=utf-8' }));
+ backgroundImage = new Image();
+ backgroundImage.onload = function () {
+ if (settled) return;
+ try {
+ var canvas = document.createElement('canvas');
+ canvas.width = Math.max(2, Math.round(data.width / 2) * 2);
+ canvas.height = Math.max(2, Math.round(data.height / 2) * 2);
+ var ctx = canvas.getContext('2d');
+ if (!ctx) throw exportError('viewer.export.error.contextUnavailable', { label: 'WebM' });
+ stream = canvas.captureStream(fps);
+ var mime = motionMimeType();
+ recorder = new MediaRecorder(stream, { mimeType: mime, videoBitsPerSecond: 6000000 });
+ var chunks = [];
+ var startedAt = performance.now();
+ function draw(now) {
+ if (settled) return;
+ try {
+ var elapsed = Math.max(0, ((Number(now) || performance.now()) - startedAt) / 1000);
+ drawMotionFrame(ctx, backgroundImage, motionScene, elapsed);
+ raf = requestAnimationFrame(draw);
+ } catch (error) { finish(error); }
+ }
+ recorder.ondataavailable = function (event) {
+ if (!settled && event.data && event.data.size) chunks.push(event.data);
+ };
+ recorder.onerror = function (event) {
+ finish(event.error || exportError('viewer.export.error.mediaRecorder'));
+ };
+ recorder.onstop = function () {
+ if (settled) return;
+ try {
+ var blob = new Blob(chunks, { type: recorder.mimeType || mime });
+ if (!blob.size) throw exportError('viewer.export.error.emptyWebm');
+ finish(null, blob);
+ } catch (error) { finish(error); }
+ };
+ drawMotionFrame(ctx, backgroundImage, motionScene, 0);
+ recorder.start(250);
+ if (settled) return;
+ startedAt = performance.now();
+ raf = requestAnimationFrame(draw);
+ durationTimer = setTimeout(function () {
+ if (settled || recorder.state === 'inactive') return;
+ // 保留最佳努力的编码器 flush;失败后仍通过 stop 收集最后的片段。
+ try { recorder.requestData(); } catch (_) {}
+ if (settled) return;
+ flushTimer = setTimeout(function () {
+ if (settled) return;
+ try { if (recorder.state !== 'inactive') recorder.stop(); }
+ catch (error) { finish(error); }
+ }, 120);
+ }, duration);
+ } catch (error) { finish(error); }
};
- recorder.onstop = function () {
- cleanup();
- var blob = new Blob(chunks, { type: recorder.mimeType || mime });
- if (!blob.size) reject(exportError('viewer.export.error.emptyWebm'));
- else resolve(blob);
+ backgroundImage.onerror = function () {
+ finish(exportError('viewer.export.error.webmBackground'));
};
- drawMotionFrame(ctx, backgroundImage, motionScene, 0);
- recorder.start(250);
- startedAt = performance.now();
- raf = requestAnimationFrame(draw);
- setTimeout(function () {
- if (recorder.state === 'inactive') return;
- // Chromium normally emits the final chunk during stop(), but
- // some embedded browser shells need an explicit encoder flush
- // first. Keep the short grace window bounded and harmless for
- // browsers that already delivered timeslice chunks.
- try { recorder.requestData(); } catch (_) {}
- setTimeout(function () {
- if (recorder.state !== 'inactive') recorder.stop();
- }, 120);
- }, duration);
- };
- backgroundImage.onerror = function () {
- URL.revokeObjectURL(sourceUrl);
- reject(exportError('viewer.export.error.webmBackground'));
- };
- backgroundImage.src = sourceUrl;
+ backgroundImage.src = sourceUrl;
+ } catch (error) { finish(error); }
});
}
diff --git a/docs/gallery/artifacts/release-delivery.workflow.html b/docs/gallery/artifacts/release-delivery.workflow.html
index a014a157..9392e5c2 100644
--- a/docs/gallery/artifacts/release-delivery.workflow.html
+++ b/docs/gallery/artifacts/release-delivery.workflow.html
@@ -6651,7 +6651,6 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
var vb = svg.viewBox.baseVal;
var scale = Math.min(1, 1280 / vb.width);
var data = serializeSvg(scale);
- var sourceUrl = URL.createObjectURL(new Blob([data.svgString], { type: 'image/svg+xml;charset=utf-8' }));
function createMotionScene(root) {
var rootMatrix = root.getCTM ? root.getCTM() : null;
@@ -6803,73 +6802,99 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
var motionScene = createMotionScene(svg);
return new Promise(function (resolve, reject) {
- var backgroundImage = new Image();
- backgroundImage.onload = function () {
- var canvas = document.createElement('canvas');
- canvas.width = Math.max(2, Math.round(data.width / 2) * 2);
- canvas.height = Math.max(2, Math.round(data.height / 2) * 2);
- var ctx = canvas.getContext('2d');
- var stream = canvas.captureStream(fps);
- var mime = motionMimeType();
- var recorder;
- try {
- recorder = new MediaRecorder(stream, { mimeType: mime, videoBitsPerSecond: 6000000 });
- } catch (err) {
- URL.revokeObjectURL(sourceUrl);
- stream.getTracks().forEach(function (track) { track.stop(); });
- reject(err);
- return;
- }
- var chunks = [];
- var raf = 0;
- var stopped = false;
- var startedAt = performance.now();
- function cleanup() {
- if (stopped) return;
- stopped = true;
- cancelAnimationFrame(raf);
- URL.revokeObjectURL(sourceUrl);
- stream.getTracks().forEach(function (track) { track.stop(); });
+ var sourceUrl = null;
+ var backgroundImage = null;
+ var stream = null;
+ var recorder = null;
+ var raf = 0;
+ var durationTimer = 0;
+ var flushTimer = 0;
+ var settled = false;
+
+ function finish(error, blob) {
+ if (settled) return;
+ // 先锁定终态:停止录制和释放流可能产生晚到的编码事件。
+ settled = true;
+ cancelAnimationFrame(raf);
+ clearTimeout(durationTimer);
+ clearTimeout(flushTimer);
+ if (backgroundImage) {
+ backgroundImage.onload = null;
+ backgroundImage.onerror = null;
}
- function draw(now) {
- var elapsed = Math.max(0, ((Number(now) || performance.now()) - startedAt) / 1000);
- drawMotionFrame(ctx, backgroundImage, motionScene, elapsed);
- raf = requestAnimationFrame(draw);
+ if (recorder) {
+ recorder.ondataavailable = null;
+ recorder.onerror = null;
+ recorder.onstop = null;
+ try { if (recorder.state !== 'inactive') recorder.stop(); } catch (_) {}
}
- recorder.ondataavailable = function (event) {
- if (event.data && event.data.size) chunks.push(event.data);
- };
- recorder.onerror = function (event) {
- cleanup();
- reject(event.error || exportError('viewer.export.error.mediaRecorder'));
+ if (stream) stream.getTracks().forEach(function (track) { track.stop(); });
+ if (sourceUrl) URL.revokeObjectURL(sourceUrl);
+ if (blob) resolve(blob);
+ else reject(error);
+ }
+
+ try {
+ sourceUrl = URL.createObjectURL(new Blob([data.svgString], { type: 'image/svg+xml;charset=utf-8' }));
+ backgroundImage = new Image();
+ backgroundImage.onload = function () {
+ if (settled) return;
+ try {
+ var canvas = document.createElement('canvas');
+ canvas.width = Math.max(2, Math.round(data.width / 2) * 2);
+ canvas.height = Math.max(2, Math.round(data.height / 2) * 2);
+ var ctx = canvas.getContext('2d');
+ if (!ctx) throw exportError('viewer.export.error.contextUnavailable', { label: 'WebM' });
+ stream = canvas.captureStream(fps);
+ var mime = motionMimeType();
+ recorder = new MediaRecorder(stream, { mimeType: mime, videoBitsPerSecond: 6000000 });
+ var chunks = [];
+ var startedAt = performance.now();
+ function draw(now) {
+ if (settled) return;
+ try {
+ var elapsed = Math.max(0, ((Number(now) || performance.now()) - startedAt) / 1000);
+ drawMotionFrame(ctx, backgroundImage, motionScene, elapsed);
+ raf = requestAnimationFrame(draw);
+ } catch (error) { finish(error); }
+ }
+ recorder.ondataavailable = function (event) {
+ if (!settled && event.data && event.data.size) chunks.push(event.data);
+ };
+ recorder.onerror = function (event) {
+ finish(event.error || exportError('viewer.export.error.mediaRecorder'));
+ };
+ recorder.onstop = function () {
+ if (settled) return;
+ try {
+ var blob = new Blob(chunks, { type: recorder.mimeType || mime });
+ if (!blob.size) throw exportError('viewer.export.error.emptyWebm');
+ finish(null, blob);
+ } catch (error) { finish(error); }
+ };
+ drawMotionFrame(ctx, backgroundImage, motionScene, 0);
+ recorder.start(250);
+ if (settled) return;
+ startedAt = performance.now();
+ raf = requestAnimationFrame(draw);
+ durationTimer = setTimeout(function () {
+ if (settled || recorder.state === 'inactive') return;
+ // 保留最佳努力的编码器 flush;失败后仍通过 stop 收集最后的片段。
+ try { recorder.requestData(); } catch (_) {}
+ if (settled) return;
+ flushTimer = setTimeout(function () {
+ if (settled) return;
+ try { if (recorder.state !== 'inactive') recorder.stop(); }
+ catch (error) { finish(error); }
+ }, 120);
+ }, duration);
+ } catch (error) { finish(error); }
};
- recorder.onstop = function () {
- cleanup();
- var blob = new Blob(chunks, { type: recorder.mimeType || mime });
- if (!blob.size) reject(exportError('viewer.export.error.emptyWebm'));
- else resolve(blob);
+ backgroundImage.onerror = function () {
+ finish(exportError('viewer.export.error.webmBackground'));
};
- drawMotionFrame(ctx, backgroundImage, motionScene, 0);
- recorder.start(250);
- startedAt = performance.now();
- raf = requestAnimationFrame(draw);
- setTimeout(function () {
- if (recorder.state === 'inactive') return;
- // Chromium normally emits the final chunk during stop(), but
- // some embedded browser shells need an explicit encoder flush
- // first. Keep the short grace window bounded and harmless for
- // browsers that already delivered timeslice chunks.
- try { recorder.requestData(); } catch (_) {}
- setTimeout(function () {
- if (recorder.state !== 'inactive') recorder.stop();
- }, 120);
- }, duration);
- };
- backgroundImage.onerror = function () {
- URL.revokeObjectURL(sourceUrl);
- reject(exportError('viewer.export.error.webmBackground'));
- };
- backgroundImage.src = sourceUrl;
+ backgroundImage.src = sourceUrl;
+ } catch (error) { finish(error); }
});
}
diff --git a/docs/gallery/artifacts/web-app.architecture.html b/docs/gallery/artifacts/web-app.architecture.html
index 56513c18..ef9438ce 100644
--- a/docs/gallery/artifacts/web-app.architecture.html
+++ b/docs/gallery/artifacts/web-app.architecture.html
@@ -6647,7 +6647,6 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
var vb = svg.viewBox.baseVal;
var scale = Math.min(1, 1280 / vb.width);
var data = serializeSvg(scale);
- var sourceUrl = URL.createObjectURL(new Blob([data.svgString], { type: 'image/svg+xml;charset=utf-8' }));
function createMotionScene(root) {
var rootMatrix = root.getCTM ? root.getCTM() : null;
@@ -6799,73 +6798,99 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
var motionScene = createMotionScene(svg);
return new Promise(function (resolve, reject) {
- var backgroundImage = new Image();
- backgroundImage.onload = function () {
- var canvas = document.createElement('canvas');
- canvas.width = Math.max(2, Math.round(data.width / 2) * 2);
- canvas.height = Math.max(2, Math.round(data.height / 2) * 2);
- var ctx = canvas.getContext('2d');
- var stream = canvas.captureStream(fps);
- var mime = motionMimeType();
- var recorder;
- try {
- recorder = new MediaRecorder(stream, { mimeType: mime, videoBitsPerSecond: 6000000 });
- } catch (err) {
- URL.revokeObjectURL(sourceUrl);
- stream.getTracks().forEach(function (track) { track.stop(); });
- reject(err);
- return;
- }
- var chunks = [];
- var raf = 0;
- var stopped = false;
- var startedAt = performance.now();
- function cleanup() {
- if (stopped) return;
- stopped = true;
- cancelAnimationFrame(raf);
- URL.revokeObjectURL(sourceUrl);
- stream.getTracks().forEach(function (track) { track.stop(); });
+ var sourceUrl = null;
+ var backgroundImage = null;
+ var stream = null;
+ var recorder = null;
+ var raf = 0;
+ var durationTimer = 0;
+ var flushTimer = 0;
+ var settled = false;
+
+ function finish(error, blob) {
+ if (settled) return;
+ // 先锁定终态:停止录制和释放流可能产生晚到的编码事件。
+ settled = true;
+ cancelAnimationFrame(raf);
+ clearTimeout(durationTimer);
+ clearTimeout(flushTimer);
+ if (backgroundImage) {
+ backgroundImage.onload = null;
+ backgroundImage.onerror = null;
}
- function draw(now) {
- var elapsed = Math.max(0, ((Number(now) || performance.now()) - startedAt) / 1000);
- drawMotionFrame(ctx, backgroundImage, motionScene, elapsed);
- raf = requestAnimationFrame(draw);
+ if (recorder) {
+ recorder.ondataavailable = null;
+ recorder.onerror = null;
+ recorder.onstop = null;
+ try { if (recorder.state !== 'inactive') recorder.stop(); } catch (_) {}
}
- recorder.ondataavailable = function (event) {
- if (event.data && event.data.size) chunks.push(event.data);
- };
- recorder.onerror = function (event) {
- cleanup();
- reject(event.error || exportError('viewer.export.error.mediaRecorder'));
+ if (stream) stream.getTracks().forEach(function (track) { track.stop(); });
+ if (sourceUrl) URL.revokeObjectURL(sourceUrl);
+ if (blob) resolve(blob);
+ else reject(error);
+ }
+
+ try {
+ sourceUrl = URL.createObjectURL(new Blob([data.svgString], { type: 'image/svg+xml;charset=utf-8' }));
+ backgroundImage = new Image();
+ backgroundImage.onload = function () {
+ if (settled) return;
+ try {
+ var canvas = document.createElement('canvas');
+ canvas.width = Math.max(2, Math.round(data.width / 2) * 2);
+ canvas.height = Math.max(2, Math.round(data.height / 2) * 2);
+ var ctx = canvas.getContext('2d');
+ if (!ctx) throw exportError('viewer.export.error.contextUnavailable', { label: 'WebM' });
+ stream = canvas.captureStream(fps);
+ var mime = motionMimeType();
+ recorder = new MediaRecorder(stream, { mimeType: mime, videoBitsPerSecond: 6000000 });
+ var chunks = [];
+ var startedAt = performance.now();
+ function draw(now) {
+ if (settled) return;
+ try {
+ var elapsed = Math.max(0, ((Number(now) || performance.now()) - startedAt) / 1000);
+ drawMotionFrame(ctx, backgroundImage, motionScene, elapsed);
+ raf = requestAnimationFrame(draw);
+ } catch (error) { finish(error); }
+ }
+ recorder.ondataavailable = function (event) {
+ if (!settled && event.data && event.data.size) chunks.push(event.data);
+ };
+ recorder.onerror = function (event) {
+ finish(event.error || exportError('viewer.export.error.mediaRecorder'));
+ };
+ recorder.onstop = function () {
+ if (settled) return;
+ try {
+ var blob = new Blob(chunks, { type: recorder.mimeType || mime });
+ if (!blob.size) throw exportError('viewer.export.error.emptyWebm');
+ finish(null, blob);
+ } catch (error) { finish(error); }
+ };
+ drawMotionFrame(ctx, backgroundImage, motionScene, 0);
+ recorder.start(250);
+ if (settled) return;
+ startedAt = performance.now();
+ raf = requestAnimationFrame(draw);
+ durationTimer = setTimeout(function () {
+ if (settled || recorder.state === 'inactive') return;
+ // 保留最佳努力的编码器 flush;失败后仍通过 stop 收集最后的片段。
+ try { recorder.requestData(); } catch (_) {}
+ if (settled) return;
+ flushTimer = setTimeout(function () {
+ if (settled) return;
+ try { if (recorder.state !== 'inactive') recorder.stop(); }
+ catch (error) { finish(error); }
+ }, 120);
+ }, duration);
+ } catch (error) { finish(error); }
};
- recorder.onstop = function () {
- cleanup();
- var blob = new Blob(chunks, { type: recorder.mimeType || mime });
- if (!blob.size) reject(exportError('viewer.export.error.emptyWebm'));
- else resolve(blob);
+ backgroundImage.onerror = function () {
+ finish(exportError('viewer.export.error.webmBackground'));
};
- drawMotionFrame(ctx, backgroundImage, motionScene, 0);
- recorder.start(250);
- startedAt = performance.now();
- raf = requestAnimationFrame(draw);
- setTimeout(function () {
- if (recorder.state === 'inactive') return;
- // Chromium normally emits the final chunk during stop(), but
- // some embedded browser shells need an explicit encoder flush
- // first. Keep the short grace window bounded and harmless for
- // browsers that already delivered timeslice chunks.
- try { recorder.requestData(); } catch (_) {}
- setTimeout(function () {
- if (recorder.state !== 'inactive') recorder.stop();
- }, 120);
- }, duration);
- };
- backgroundImage.onerror = function () {
- URL.revokeObjectURL(sourceUrl);
- reject(exportError('viewer.export.error.webmBackground'));
- };
- backgroundImage.src = sourceUrl;
+ backgroundImage.src = sourceUrl;
+ } catch (error) { finish(error); }
});
}
diff --git a/docs/gallery/manifest.json b/docs/gallery/manifest.json
index 5cbd5875..431bf806 100644
--- a/docs/gallery/manifest.json
+++ b/docs/gallery/manifest.json
@@ -19,8 +19,8 @@
"engineeringProfile": null,
"nodeCount": 12,
"edgeCount": 11,
- "artifactBytes": 767776,
- "artifactSha256": "7d086f7f0af593759c56dd82e0b952bcb1a27a64f960cfc7226f905aa2d010dc",
+ "artifactBytes": 768975,
+ "artifactSha256": "72d8efc3a8896783caee0023519d659bda63ad99fadc05ce524da24ebd143b82",
"sourceBytes": 4939,
"sourceSha256": "d67965d50872c97e4ff3476271e645bf19fab6b3ab44e111bdb44b063e3aa36f",
"checks": [
@@ -154,8 +154,8 @@
"engineeringProfile": "deployment-ownership",
"nodeCount": 12,
"edgeCount": 12,
- "artifactBytes": 770503,
- "artifactSha256": "46bc35a5978fd96e842104527342ccb524b0e9d5cadb1dfbc5dac38d7095bc41",
+ "artifactBytes": 771702,
+ "artifactSha256": "54688ab28407718c1b8f76781511f92f87a7cdcb0fdae61a089bd39c65913e7e",
"sourceBytes": 4734,
"sourceSha256": "cb54bad2dfd0c2d02aa5b496bde6839789a0f07f23062343c4458b8d38806c13",
"checks": [
@@ -287,8 +287,8 @@
"engineeringProfile": null,
"nodeCount": 7,
"edgeCount": 12,
- "artifactBytes": 762316,
- "artifactSha256": "590cf92f58921658398953fbf28795cbf054053bf89c2e9f23acd0c827693a53",
+ "artifactBytes": 763515,
+ "artifactSha256": "a94388fe099db0582aa6e3fa2bf771ad619b3ae65736de5aa020fb8ed5d13830",
"sourceBytes": 3805,
"sourceSha256": "f8486daa803fff6c295cecca4604c561fbbf9acb2e83326022b5a87639e8afe6",
"checks": [
@@ -421,8 +421,8 @@
"engineeringProfile": null,
"nodeCount": 10,
"edgeCount": 10,
- "artifactBytes": 763290,
- "artifactSha256": "6a3fc44eb7b266bde68b92159b32db8ba08f9fab5e513d612da53e1a29988c82",
+ "artifactBytes": 764489,
+ "artifactSha256": "411d9bd097b6a8094e261c276f20a51535b60ef6d9d645a718cc39d934140c4a",
"sourceBytes": 4510,
"sourceSha256": "dbd5c174af66296caec372e7214cf4df7158b50a563508e16826b95ab8d1cd6c",
"checks": [
@@ -561,8 +561,8 @@
"engineeringProfile": null,
"nodeCount": 11,
"edgeCount": 10,
- "artifactBytes": 760610,
- "artifactSha256": "fdfa06be4f0d9728f844ccfde5910fa4b4ed8f2d268be41e05b7a95535fd834b",
+ "artifactBytes": 761809,
+ "artifactSha256": "7df016f9173c363aac707a12311e56917d4f95d342cbfc4a88152a24155a7dc3",
"sourceBytes": 4723,
"sourceSha256": "630be98449925d2716ecb8439f404b2bff5fe65ba905b0ad0baea6d96890c526",
"checks": [
@@ -747,8 +747,8 @@
"engineeringProfile": null,
"nodeCount": 10,
"edgeCount": 10,
- "artifactBytes": 764610,
- "artifactSha256": "498dad656e49542b27fd4c08d83adf0e50809255517fee1bf21a86f172103fd0",
+ "artifactBytes": 765809,
+ "artifactSha256": "605d6544b1cc65d1a05fcad25af8b2786b11aea1cb2ed4f0630388e1fab9fba4",
"sourceBytes": 5035,
"sourceSha256": "8a635db9e51a5b1a8d2955b9d66f5b9a450e0a298432ce8f2e2f0be11f372e05",
"checks": [
@@ -882,8 +882,8 @@
"engineeringProfile": null,
"nodeCount": 7,
"edgeCount": 14,
- "artifactBytes": 761402,
- "artifactSha256": "48f43ccbe702462a339ae3fd4743c38ac90fac261a24ff90a0853db01a38f8f5",
+ "artifactBytes": 762601,
+ "artifactSha256": "e9f5b8b6c28315c51ae3c823cd0c1cee25db18a05efc265b3f393cf3560b6b58",
"sourceBytes": 3766,
"sourceSha256": "b8c6c52f1763ede2933c77deb8da59b3e06917bc41d27e66df896136456b859a",
"checks": [
@@ -1034,8 +1034,8 @@
"engineeringProfile": null,
"nodeCount": 12,
"edgeCount": 12,
- "artifactBytes": 768530,
- "artifactSha256": "8cdd38dc599f78bc6f8dca392b38dcb76b3159efdc3a734a9a8b814d82e358c7",
+ "artifactBytes": 769729,
+ "artifactSha256": "0a8c47fcb3c2f4277b49ca40a4683b240aacaa6e987a5e000bf2b414686175d5",
"sourceBytes": 4769,
"sourceSha256": "3bdd77674282009c7c68d588cf8a3c495bc98a3be1b9c45327fd1801a6f83a23",
"checks": [
@@ -1186,8 +1186,8 @@
"engineeringProfile": null,
"nodeCount": 10,
"edgeCount": 6,
- "artifactBytes": 758920,
- "artifactSha256": "99dfa39c258ed8009c1b312dde565fad3f81eaf9ffa181fcd0dd6cc818722040",
+ "artifactBytes": 760119,
+ "artifactSha256": "9488f6b081c7a88f841f5fe3a01bed83b0458e0ee9075ab2ff5e6d8131af88d0",
"sourceBytes": 3405,
"sourceSha256": "230242a7557663877766c43a9fe7cffe8b4fb66e4866457dccd24c63175b4917",
"checks": [
@@ -1357,8 +1357,8 @@
"engineeringProfile": null,
"nodeCount": 11,
"edgeCount": 11,
- "artifactBytes": 765975,
- "artifactSha256": "24279a5e329c5e0de5e1f8ecefd3d0f799e1381f9cb9779abe4db5c8cae8d3f7",
+ "artifactBytes": 767174,
+ "artifactSha256": "d9a574f8b331b8df3152936c7c5439a63035fd18337464fa1ccce7bdf81095e9",
"sourceBytes": 3507,
"sourceSha256": "f565a8acfebdb21453e2bccd82d3760b4736e38fe194fb2f0804b57817eba813",
"checks": [
@@ -1479,8 +1479,8 @@
"engineeringProfile": null,
"nodeCount": 10,
"edgeCount": 9,
- "artifactBytes": 762316,
- "artifactSha256": "3ed638ac7f2ce0e99b3e2ff3c520b703d368eca7fbd223e9ee94d54e257c189a",
+ "artifactBytes": 763515,
+ "artifactSha256": "74eccc0a70e150ca46b071f0c9fefc13f99ba272cc1835172e0751080693f66f",
"sourceBytes": 3197,
"sourceSha256": "95e051b27a9e4a3307e194c0f666fca4af51470be7e2228d400ff48aea5b353b",
"checks": [
diff --git a/examples/dataflow-product-analytics.html b/examples/dataflow-product-analytics.html
index d454321b..83db25a4 100644
--- a/examples/dataflow-product-analytics.html
+++ b/examples/dataflow-product-analytics.html
@@ -6659,7 +6659,6 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
var vb = svg.viewBox.baseVal;
var scale = Math.min(1, 1280 / vb.width);
var data = serializeSvg(scale);
- var sourceUrl = URL.createObjectURL(new Blob([data.svgString], { type: 'image/svg+xml;charset=utf-8' }));
function createMotionScene(root) {
var rootMatrix = root.getCTM ? root.getCTM() : null;
@@ -6811,73 +6810,99 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
var motionScene = createMotionScene(svg);
return new Promise(function (resolve, reject) {
- var backgroundImage = new Image();
- backgroundImage.onload = function () {
- var canvas = document.createElement('canvas');
- canvas.width = Math.max(2, Math.round(data.width / 2) * 2);
- canvas.height = Math.max(2, Math.round(data.height / 2) * 2);
- var ctx = canvas.getContext('2d');
- var stream = canvas.captureStream(fps);
- var mime = motionMimeType();
- var recorder;
- try {
- recorder = new MediaRecorder(stream, { mimeType: mime, videoBitsPerSecond: 6000000 });
- } catch (err) {
- URL.revokeObjectURL(sourceUrl);
- stream.getTracks().forEach(function (track) { track.stop(); });
- reject(err);
- return;
- }
- var chunks = [];
- var raf = 0;
- var stopped = false;
- var startedAt = performance.now();
- function cleanup() {
- if (stopped) return;
- stopped = true;
- cancelAnimationFrame(raf);
- URL.revokeObjectURL(sourceUrl);
- stream.getTracks().forEach(function (track) { track.stop(); });
+ var sourceUrl = null;
+ var backgroundImage = null;
+ var stream = null;
+ var recorder = null;
+ var raf = 0;
+ var durationTimer = 0;
+ var flushTimer = 0;
+ var settled = false;
+
+ function finish(error, blob) {
+ if (settled) return;
+ // 先锁定终态:停止录制和释放流可能产生晚到的编码事件。
+ settled = true;
+ cancelAnimationFrame(raf);
+ clearTimeout(durationTimer);
+ clearTimeout(flushTimer);
+ if (backgroundImage) {
+ backgroundImage.onload = null;
+ backgroundImage.onerror = null;
}
- function draw(now) {
- var elapsed = Math.max(0, ((Number(now) || performance.now()) - startedAt) / 1000);
- drawMotionFrame(ctx, backgroundImage, motionScene, elapsed);
- raf = requestAnimationFrame(draw);
+ if (recorder) {
+ recorder.ondataavailable = null;
+ recorder.onerror = null;
+ recorder.onstop = null;
+ try { if (recorder.state !== 'inactive') recorder.stop(); } catch (_) {}
}
- recorder.ondataavailable = function (event) {
- if (event.data && event.data.size) chunks.push(event.data);
- };
- recorder.onerror = function (event) {
- cleanup();
- reject(event.error || exportError('viewer.export.error.mediaRecorder'));
+ if (stream) stream.getTracks().forEach(function (track) { track.stop(); });
+ if (sourceUrl) URL.revokeObjectURL(sourceUrl);
+ if (blob) resolve(blob);
+ else reject(error);
+ }
+
+ try {
+ sourceUrl = URL.createObjectURL(new Blob([data.svgString], { type: 'image/svg+xml;charset=utf-8' }));
+ backgroundImage = new Image();
+ backgroundImage.onload = function () {
+ if (settled) return;
+ try {
+ var canvas = document.createElement('canvas');
+ canvas.width = Math.max(2, Math.round(data.width / 2) * 2);
+ canvas.height = Math.max(2, Math.round(data.height / 2) * 2);
+ var ctx = canvas.getContext('2d');
+ if (!ctx) throw exportError('viewer.export.error.contextUnavailable', { label: 'WebM' });
+ stream = canvas.captureStream(fps);
+ var mime = motionMimeType();
+ recorder = new MediaRecorder(stream, { mimeType: mime, videoBitsPerSecond: 6000000 });
+ var chunks = [];
+ var startedAt = performance.now();
+ function draw(now) {
+ if (settled) return;
+ try {
+ var elapsed = Math.max(0, ((Number(now) || performance.now()) - startedAt) / 1000);
+ drawMotionFrame(ctx, backgroundImage, motionScene, elapsed);
+ raf = requestAnimationFrame(draw);
+ } catch (error) { finish(error); }
+ }
+ recorder.ondataavailable = function (event) {
+ if (!settled && event.data && event.data.size) chunks.push(event.data);
+ };
+ recorder.onerror = function (event) {
+ finish(event.error || exportError('viewer.export.error.mediaRecorder'));
+ };
+ recorder.onstop = function () {
+ if (settled) return;
+ try {
+ var blob = new Blob(chunks, { type: recorder.mimeType || mime });
+ if (!blob.size) throw exportError('viewer.export.error.emptyWebm');
+ finish(null, blob);
+ } catch (error) { finish(error); }
+ };
+ drawMotionFrame(ctx, backgroundImage, motionScene, 0);
+ recorder.start(250);
+ if (settled) return;
+ startedAt = performance.now();
+ raf = requestAnimationFrame(draw);
+ durationTimer = setTimeout(function () {
+ if (settled || recorder.state === 'inactive') return;
+ // 保留最佳努力的编码器 flush;失败后仍通过 stop 收集最后的片段。
+ try { recorder.requestData(); } catch (_) {}
+ if (settled) return;
+ flushTimer = setTimeout(function () {
+ if (settled) return;
+ try { if (recorder.state !== 'inactive') recorder.stop(); }
+ catch (error) { finish(error); }
+ }, 120);
+ }, duration);
+ } catch (error) { finish(error); }
};
- recorder.onstop = function () {
- cleanup();
- var blob = new Blob(chunks, { type: recorder.mimeType || mime });
- if (!blob.size) reject(exportError('viewer.export.error.emptyWebm'));
- else resolve(blob);
+ backgroundImage.onerror = function () {
+ finish(exportError('viewer.export.error.webmBackground'));
};
- drawMotionFrame(ctx, backgroundImage, motionScene, 0);
- recorder.start(250);
- startedAt = performance.now();
- raf = requestAnimationFrame(draw);
- setTimeout(function () {
- if (recorder.state === 'inactive') return;
- // Chromium normally emits the final chunk during stop(), but
- // some embedded browser shells need an explicit encoder flush
- // first. Keep the short grace window bounded and harmless for
- // browsers that already delivered timeslice chunks.
- try { recorder.requestData(); } catch (_) {}
- setTimeout(function () {
- if (recorder.state !== 'inactive') recorder.stop();
- }, 120);
- }, duration);
- };
- backgroundImage.onerror = function () {
- URL.revokeObjectURL(sourceUrl);
- reject(exportError('viewer.export.error.webmBackground'));
- };
- backgroundImage.src = sourceUrl;
+ backgroundImage.src = sourceUrl;
+ } catch (error) { finish(error); }
});
}
diff --git a/examples/lifecycle-agent-run.html b/examples/lifecycle-agent-run.html
index 5b600983..bbcea1cb 100644
--- a/examples/lifecycle-agent-run.html
+++ b/examples/lifecycle-agent-run.html
@@ -6604,7 +6604,6 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
var vb = svg.viewBox.baseVal;
var scale = Math.min(1, 1280 / vb.width);
var data = serializeSvg(scale);
- var sourceUrl = URL.createObjectURL(new Blob([data.svgString], { type: 'image/svg+xml;charset=utf-8' }));
function createMotionScene(root) {
var rootMatrix = root.getCTM ? root.getCTM() : null;
@@ -6756,73 +6755,99 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
var motionScene = createMotionScene(svg);
return new Promise(function (resolve, reject) {
- var backgroundImage = new Image();
- backgroundImage.onload = function () {
- var canvas = document.createElement('canvas');
- canvas.width = Math.max(2, Math.round(data.width / 2) * 2);
- canvas.height = Math.max(2, Math.round(data.height / 2) * 2);
- var ctx = canvas.getContext('2d');
- var stream = canvas.captureStream(fps);
- var mime = motionMimeType();
- var recorder;
- try {
- recorder = new MediaRecorder(stream, { mimeType: mime, videoBitsPerSecond: 6000000 });
- } catch (err) {
- URL.revokeObjectURL(sourceUrl);
- stream.getTracks().forEach(function (track) { track.stop(); });
- reject(err);
- return;
- }
- var chunks = [];
- var raf = 0;
- var stopped = false;
- var startedAt = performance.now();
- function cleanup() {
- if (stopped) return;
- stopped = true;
- cancelAnimationFrame(raf);
- URL.revokeObjectURL(sourceUrl);
- stream.getTracks().forEach(function (track) { track.stop(); });
+ var sourceUrl = null;
+ var backgroundImage = null;
+ var stream = null;
+ var recorder = null;
+ var raf = 0;
+ var durationTimer = 0;
+ var flushTimer = 0;
+ var settled = false;
+
+ function finish(error, blob) {
+ if (settled) return;
+ // 先锁定终态:停止录制和释放流可能产生晚到的编码事件。
+ settled = true;
+ cancelAnimationFrame(raf);
+ clearTimeout(durationTimer);
+ clearTimeout(flushTimer);
+ if (backgroundImage) {
+ backgroundImage.onload = null;
+ backgroundImage.onerror = null;
}
- function draw(now) {
- var elapsed = Math.max(0, ((Number(now) || performance.now()) - startedAt) / 1000);
- drawMotionFrame(ctx, backgroundImage, motionScene, elapsed);
- raf = requestAnimationFrame(draw);
+ if (recorder) {
+ recorder.ondataavailable = null;
+ recorder.onerror = null;
+ recorder.onstop = null;
+ try { if (recorder.state !== 'inactive') recorder.stop(); } catch (_) {}
}
- recorder.ondataavailable = function (event) {
- if (event.data && event.data.size) chunks.push(event.data);
- };
- recorder.onerror = function (event) {
- cleanup();
- reject(event.error || exportError('viewer.export.error.mediaRecorder'));
+ if (stream) stream.getTracks().forEach(function (track) { track.stop(); });
+ if (sourceUrl) URL.revokeObjectURL(sourceUrl);
+ if (blob) resolve(blob);
+ else reject(error);
+ }
+
+ try {
+ sourceUrl = URL.createObjectURL(new Blob([data.svgString], { type: 'image/svg+xml;charset=utf-8' }));
+ backgroundImage = new Image();
+ backgroundImage.onload = function () {
+ if (settled) return;
+ try {
+ var canvas = document.createElement('canvas');
+ canvas.width = Math.max(2, Math.round(data.width / 2) * 2);
+ canvas.height = Math.max(2, Math.round(data.height / 2) * 2);
+ var ctx = canvas.getContext('2d');
+ if (!ctx) throw exportError('viewer.export.error.contextUnavailable', { label: 'WebM' });
+ stream = canvas.captureStream(fps);
+ var mime = motionMimeType();
+ recorder = new MediaRecorder(stream, { mimeType: mime, videoBitsPerSecond: 6000000 });
+ var chunks = [];
+ var startedAt = performance.now();
+ function draw(now) {
+ if (settled) return;
+ try {
+ var elapsed = Math.max(0, ((Number(now) || performance.now()) - startedAt) / 1000);
+ drawMotionFrame(ctx, backgroundImage, motionScene, elapsed);
+ raf = requestAnimationFrame(draw);
+ } catch (error) { finish(error); }
+ }
+ recorder.ondataavailable = function (event) {
+ if (!settled && event.data && event.data.size) chunks.push(event.data);
+ };
+ recorder.onerror = function (event) {
+ finish(event.error || exportError('viewer.export.error.mediaRecorder'));
+ };
+ recorder.onstop = function () {
+ if (settled) return;
+ try {
+ var blob = new Blob(chunks, { type: recorder.mimeType || mime });
+ if (!blob.size) throw exportError('viewer.export.error.emptyWebm');
+ finish(null, blob);
+ } catch (error) { finish(error); }
+ };
+ drawMotionFrame(ctx, backgroundImage, motionScene, 0);
+ recorder.start(250);
+ if (settled) return;
+ startedAt = performance.now();
+ raf = requestAnimationFrame(draw);
+ durationTimer = setTimeout(function () {
+ if (settled || recorder.state === 'inactive') return;
+ // 保留最佳努力的编码器 flush;失败后仍通过 stop 收集最后的片段。
+ try { recorder.requestData(); } catch (_) {}
+ if (settled) return;
+ flushTimer = setTimeout(function () {
+ if (settled) return;
+ try { if (recorder.state !== 'inactive') recorder.stop(); }
+ catch (error) { finish(error); }
+ }, 120);
+ }, duration);
+ } catch (error) { finish(error); }
};
- recorder.onstop = function () {
- cleanup();
- var blob = new Blob(chunks, { type: recorder.mimeType || mime });
- if (!blob.size) reject(exportError('viewer.export.error.emptyWebm'));
- else resolve(blob);
+ backgroundImage.onerror = function () {
+ finish(exportError('viewer.export.error.webmBackground'));
};
- drawMotionFrame(ctx, backgroundImage, motionScene, 0);
- recorder.start(250);
- startedAt = performance.now();
- raf = requestAnimationFrame(draw);
- setTimeout(function () {
- if (recorder.state === 'inactive') return;
- // Chromium normally emits the final chunk during stop(), but
- // some embedded browser shells need an explicit encoder flush
- // first. Keep the short grace window bounded and harmless for
- // browsers that already delivered timeslice chunks.
- try { recorder.requestData(); } catch (_) {}
- setTimeout(function () {
- if (recorder.state !== 'inactive') recorder.stop();
- }, 120);
- }, duration);
- };
- backgroundImage.onerror = function () {
- URL.revokeObjectURL(sourceUrl);
- reject(exportError('viewer.export.error.webmBackground'));
- };
- backgroundImage.src = sourceUrl;
+ backgroundImage.src = sourceUrl;
+ } catch (error) { finish(error); }
});
}
diff --git a/examples/sequence-cache-miss-request.html b/examples/sequence-cache-miss-request.html
index 321c769d..ecea17f6 100644
--- a/examples/sequence-cache-miss-request.html
+++ b/examples/sequence-cache-miss-request.html
@@ -6674,7 +6674,6 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
var vb = svg.viewBox.baseVal;
var scale = Math.min(1, 1280 / vb.width);
var data = serializeSvg(scale);
- var sourceUrl = URL.createObjectURL(new Blob([data.svgString], { type: 'image/svg+xml;charset=utf-8' }));
function createMotionScene(root) {
var rootMatrix = root.getCTM ? root.getCTM() : null;
@@ -6826,73 +6825,99 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
var motionScene = createMotionScene(svg);
return new Promise(function (resolve, reject) {
- var backgroundImage = new Image();
- backgroundImage.onload = function () {
- var canvas = document.createElement('canvas');
- canvas.width = Math.max(2, Math.round(data.width / 2) * 2);
- canvas.height = Math.max(2, Math.round(data.height / 2) * 2);
- var ctx = canvas.getContext('2d');
- var stream = canvas.captureStream(fps);
- var mime = motionMimeType();
- var recorder;
- try {
- recorder = new MediaRecorder(stream, { mimeType: mime, videoBitsPerSecond: 6000000 });
- } catch (err) {
- URL.revokeObjectURL(sourceUrl);
- stream.getTracks().forEach(function (track) { track.stop(); });
- reject(err);
- return;
- }
- var chunks = [];
- var raf = 0;
- var stopped = false;
- var startedAt = performance.now();
- function cleanup() {
- if (stopped) return;
- stopped = true;
- cancelAnimationFrame(raf);
- URL.revokeObjectURL(sourceUrl);
- stream.getTracks().forEach(function (track) { track.stop(); });
+ var sourceUrl = null;
+ var backgroundImage = null;
+ var stream = null;
+ var recorder = null;
+ var raf = 0;
+ var durationTimer = 0;
+ var flushTimer = 0;
+ var settled = false;
+
+ function finish(error, blob) {
+ if (settled) return;
+ // 先锁定终态:停止录制和释放流可能产生晚到的编码事件。
+ settled = true;
+ cancelAnimationFrame(raf);
+ clearTimeout(durationTimer);
+ clearTimeout(flushTimer);
+ if (backgroundImage) {
+ backgroundImage.onload = null;
+ backgroundImage.onerror = null;
}
- function draw(now) {
- var elapsed = Math.max(0, ((Number(now) || performance.now()) - startedAt) / 1000);
- drawMotionFrame(ctx, backgroundImage, motionScene, elapsed);
- raf = requestAnimationFrame(draw);
+ if (recorder) {
+ recorder.ondataavailable = null;
+ recorder.onerror = null;
+ recorder.onstop = null;
+ try { if (recorder.state !== 'inactive') recorder.stop(); } catch (_) {}
}
- recorder.ondataavailable = function (event) {
- if (event.data && event.data.size) chunks.push(event.data);
- };
- recorder.onerror = function (event) {
- cleanup();
- reject(event.error || exportError('viewer.export.error.mediaRecorder'));
+ if (stream) stream.getTracks().forEach(function (track) { track.stop(); });
+ if (sourceUrl) URL.revokeObjectURL(sourceUrl);
+ if (blob) resolve(blob);
+ else reject(error);
+ }
+
+ try {
+ sourceUrl = URL.createObjectURL(new Blob([data.svgString], { type: 'image/svg+xml;charset=utf-8' }));
+ backgroundImage = new Image();
+ backgroundImage.onload = function () {
+ if (settled) return;
+ try {
+ var canvas = document.createElement('canvas');
+ canvas.width = Math.max(2, Math.round(data.width / 2) * 2);
+ canvas.height = Math.max(2, Math.round(data.height / 2) * 2);
+ var ctx = canvas.getContext('2d');
+ if (!ctx) throw exportError('viewer.export.error.contextUnavailable', { label: 'WebM' });
+ stream = canvas.captureStream(fps);
+ var mime = motionMimeType();
+ recorder = new MediaRecorder(stream, { mimeType: mime, videoBitsPerSecond: 6000000 });
+ var chunks = [];
+ var startedAt = performance.now();
+ function draw(now) {
+ if (settled) return;
+ try {
+ var elapsed = Math.max(0, ((Number(now) || performance.now()) - startedAt) / 1000);
+ drawMotionFrame(ctx, backgroundImage, motionScene, elapsed);
+ raf = requestAnimationFrame(draw);
+ } catch (error) { finish(error); }
+ }
+ recorder.ondataavailable = function (event) {
+ if (!settled && event.data && event.data.size) chunks.push(event.data);
+ };
+ recorder.onerror = function (event) {
+ finish(event.error || exportError('viewer.export.error.mediaRecorder'));
+ };
+ recorder.onstop = function () {
+ if (settled) return;
+ try {
+ var blob = new Blob(chunks, { type: recorder.mimeType || mime });
+ if (!blob.size) throw exportError('viewer.export.error.emptyWebm');
+ finish(null, blob);
+ } catch (error) { finish(error); }
+ };
+ drawMotionFrame(ctx, backgroundImage, motionScene, 0);
+ recorder.start(250);
+ if (settled) return;
+ startedAt = performance.now();
+ raf = requestAnimationFrame(draw);
+ durationTimer = setTimeout(function () {
+ if (settled || recorder.state === 'inactive') return;
+ // 保留最佳努力的编码器 flush;失败后仍通过 stop 收集最后的片段。
+ try { recorder.requestData(); } catch (_) {}
+ if (settled) return;
+ flushTimer = setTimeout(function () {
+ if (settled) return;
+ try { if (recorder.state !== 'inactive') recorder.stop(); }
+ catch (error) { finish(error); }
+ }, 120);
+ }, duration);
+ } catch (error) { finish(error); }
};
- recorder.onstop = function () {
- cleanup();
- var blob = new Blob(chunks, { type: recorder.mimeType || mime });
- if (!blob.size) reject(exportError('viewer.export.error.emptyWebm'));
- else resolve(blob);
+ backgroundImage.onerror = function () {
+ finish(exportError('viewer.export.error.webmBackground'));
};
- drawMotionFrame(ctx, backgroundImage, motionScene, 0);
- recorder.start(250);
- startedAt = performance.now();
- raf = requestAnimationFrame(draw);
- setTimeout(function () {
- if (recorder.state === 'inactive') return;
- // Chromium normally emits the final chunk during stop(), but
- // some embedded browser shells need an explicit encoder flush
- // first. Keep the short grace window bounded and harmless for
- // browsers that already delivered timeslice chunks.
- try { recorder.requestData(); } catch (_) {}
- setTimeout(function () {
- if (recorder.state !== 'inactive') recorder.stop();
- }, 120);
- }, duration);
- };
- backgroundImage.onerror = function () {
- URL.revokeObjectURL(sourceUrl);
- reject(exportError('viewer.export.error.webmBackground'));
- };
- backgroundImage.src = sourceUrl;
+ backgroundImage.src = sourceUrl;
+ } catch (error) { finish(error); }
});
}
diff --git a/examples/web-app-rendered.html b/examples/web-app-rendered.html
index 56513c18..ef9438ce 100644
--- a/examples/web-app-rendered.html
+++ b/examples/web-app-rendered.html
@@ -6647,7 +6647,6 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
var vb = svg.viewBox.baseVal;
var scale = Math.min(1, 1280 / vb.width);
var data = serializeSvg(scale);
- var sourceUrl = URL.createObjectURL(new Blob([data.svgString], { type: 'image/svg+xml;charset=utf-8' }));
function createMotionScene(root) {
var rootMatrix = root.getCTM ? root.getCTM() : null;
@@ -6799,73 +6798,99 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
var motionScene = createMotionScene(svg);
return new Promise(function (resolve, reject) {
- var backgroundImage = new Image();
- backgroundImage.onload = function () {
- var canvas = document.createElement('canvas');
- canvas.width = Math.max(2, Math.round(data.width / 2) * 2);
- canvas.height = Math.max(2, Math.round(data.height / 2) * 2);
- var ctx = canvas.getContext('2d');
- var stream = canvas.captureStream(fps);
- var mime = motionMimeType();
- var recorder;
- try {
- recorder = new MediaRecorder(stream, { mimeType: mime, videoBitsPerSecond: 6000000 });
- } catch (err) {
- URL.revokeObjectURL(sourceUrl);
- stream.getTracks().forEach(function (track) { track.stop(); });
- reject(err);
- return;
- }
- var chunks = [];
- var raf = 0;
- var stopped = false;
- var startedAt = performance.now();
- function cleanup() {
- if (stopped) return;
- stopped = true;
- cancelAnimationFrame(raf);
- URL.revokeObjectURL(sourceUrl);
- stream.getTracks().forEach(function (track) { track.stop(); });
+ var sourceUrl = null;
+ var backgroundImage = null;
+ var stream = null;
+ var recorder = null;
+ var raf = 0;
+ var durationTimer = 0;
+ var flushTimer = 0;
+ var settled = false;
+
+ function finish(error, blob) {
+ if (settled) return;
+ // 先锁定终态:停止录制和释放流可能产生晚到的编码事件。
+ settled = true;
+ cancelAnimationFrame(raf);
+ clearTimeout(durationTimer);
+ clearTimeout(flushTimer);
+ if (backgroundImage) {
+ backgroundImage.onload = null;
+ backgroundImage.onerror = null;
}
- function draw(now) {
- var elapsed = Math.max(0, ((Number(now) || performance.now()) - startedAt) / 1000);
- drawMotionFrame(ctx, backgroundImage, motionScene, elapsed);
- raf = requestAnimationFrame(draw);
+ if (recorder) {
+ recorder.ondataavailable = null;
+ recorder.onerror = null;
+ recorder.onstop = null;
+ try { if (recorder.state !== 'inactive') recorder.stop(); } catch (_) {}
}
- recorder.ondataavailable = function (event) {
- if (event.data && event.data.size) chunks.push(event.data);
- };
- recorder.onerror = function (event) {
- cleanup();
- reject(event.error || exportError('viewer.export.error.mediaRecorder'));
+ if (stream) stream.getTracks().forEach(function (track) { track.stop(); });
+ if (sourceUrl) URL.revokeObjectURL(sourceUrl);
+ if (blob) resolve(blob);
+ else reject(error);
+ }
+
+ try {
+ sourceUrl = URL.createObjectURL(new Blob([data.svgString], { type: 'image/svg+xml;charset=utf-8' }));
+ backgroundImage = new Image();
+ backgroundImage.onload = function () {
+ if (settled) return;
+ try {
+ var canvas = document.createElement('canvas');
+ canvas.width = Math.max(2, Math.round(data.width / 2) * 2);
+ canvas.height = Math.max(2, Math.round(data.height / 2) * 2);
+ var ctx = canvas.getContext('2d');
+ if (!ctx) throw exportError('viewer.export.error.contextUnavailable', { label: 'WebM' });
+ stream = canvas.captureStream(fps);
+ var mime = motionMimeType();
+ recorder = new MediaRecorder(stream, { mimeType: mime, videoBitsPerSecond: 6000000 });
+ var chunks = [];
+ var startedAt = performance.now();
+ function draw(now) {
+ if (settled) return;
+ try {
+ var elapsed = Math.max(0, ((Number(now) || performance.now()) - startedAt) / 1000);
+ drawMotionFrame(ctx, backgroundImage, motionScene, elapsed);
+ raf = requestAnimationFrame(draw);
+ } catch (error) { finish(error); }
+ }
+ recorder.ondataavailable = function (event) {
+ if (!settled && event.data && event.data.size) chunks.push(event.data);
+ };
+ recorder.onerror = function (event) {
+ finish(event.error || exportError('viewer.export.error.mediaRecorder'));
+ };
+ recorder.onstop = function () {
+ if (settled) return;
+ try {
+ var blob = new Blob(chunks, { type: recorder.mimeType || mime });
+ if (!blob.size) throw exportError('viewer.export.error.emptyWebm');
+ finish(null, blob);
+ } catch (error) { finish(error); }
+ };
+ drawMotionFrame(ctx, backgroundImage, motionScene, 0);
+ recorder.start(250);
+ if (settled) return;
+ startedAt = performance.now();
+ raf = requestAnimationFrame(draw);
+ durationTimer = setTimeout(function () {
+ if (settled || recorder.state === 'inactive') return;
+ // 保留最佳努力的编码器 flush;失败后仍通过 stop 收集最后的片段。
+ try { recorder.requestData(); } catch (_) {}
+ if (settled) return;
+ flushTimer = setTimeout(function () {
+ if (settled) return;
+ try { if (recorder.state !== 'inactive') recorder.stop(); }
+ catch (error) { finish(error); }
+ }, 120);
+ }, duration);
+ } catch (error) { finish(error); }
};
- recorder.onstop = function () {
- cleanup();
- var blob = new Blob(chunks, { type: recorder.mimeType || mime });
- if (!blob.size) reject(exportError('viewer.export.error.emptyWebm'));
- else resolve(blob);
+ backgroundImage.onerror = function () {
+ finish(exportError('viewer.export.error.webmBackground'));
};
- drawMotionFrame(ctx, backgroundImage, motionScene, 0);
- recorder.start(250);
- startedAt = performance.now();
- raf = requestAnimationFrame(draw);
- setTimeout(function () {
- if (recorder.state === 'inactive') return;
- // Chromium normally emits the final chunk during stop(), but
- // some embedded browser shells need an explicit encoder flush
- // first. Keep the short grace window bounded and harmless for
- // browsers that already delivered timeslice chunks.
- try { recorder.requestData(); } catch (_) {}
- setTimeout(function () {
- if (recorder.state !== 'inactive') recorder.stop();
- }, 120);
- }, duration);
- };
- backgroundImage.onerror = function () {
- URL.revokeObjectURL(sourceUrl);
- reject(exportError('viewer.export.error.webmBackground'));
- };
- backgroundImage.src = sourceUrl;
+ backgroundImage.src = sourceUrl;
+ } catch (error) { finish(error); }
});
}
diff --git a/examples/web-app.html b/examples/web-app.html
index 56513c18..ef9438ce 100644
--- a/examples/web-app.html
+++ b/examples/web-app.html
@@ -6647,7 +6647,6 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
var vb = svg.viewBox.baseVal;
var scale = Math.min(1, 1280 / vb.width);
var data = serializeSvg(scale);
- var sourceUrl = URL.createObjectURL(new Blob([data.svgString], { type: 'image/svg+xml;charset=utf-8' }));
function createMotionScene(root) {
var rootMatrix = root.getCTM ? root.getCTM() : null;
@@ -6799,73 +6798,99 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
var motionScene = createMotionScene(svg);
return new Promise(function (resolve, reject) {
- var backgroundImage = new Image();
- backgroundImage.onload = function () {
- var canvas = document.createElement('canvas');
- canvas.width = Math.max(2, Math.round(data.width / 2) * 2);
- canvas.height = Math.max(2, Math.round(data.height / 2) * 2);
- var ctx = canvas.getContext('2d');
- var stream = canvas.captureStream(fps);
- var mime = motionMimeType();
- var recorder;
- try {
- recorder = new MediaRecorder(stream, { mimeType: mime, videoBitsPerSecond: 6000000 });
- } catch (err) {
- URL.revokeObjectURL(sourceUrl);
- stream.getTracks().forEach(function (track) { track.stop(); });
- reject(err);
- return;
- }
- var chunks = [];
- var raf = 0;
- var stopped = false;
- var startedAt = performance.now();
- function cleanup() {
- if (stopped) return;
- stopped = true;
- cancelAnimationFrame(raf);
- URL.revokeObjectURL(sourceUrl);
- stream.getTracks().forEach(function (track) { track.stop(); });
+ var sourceUrl = null;
+ var backgroundImage = null;
+ var stream = null;
+ var recorder = null;
+ var raf = 0;
+ var durationTimer = 0;
+ var flushTimer = 0;
+ var settled = false;
+
+ function finish(error, blob) {
+ if (settled) return;
+ // 先锁定终态:停止录制和释放流可能产生晚到的编码事件。
+ settled = true;
+ cancelAnimationFrame(raf);
+ clearTimeout(durationTimer);
+ clearTimeout(flushTimer);
+ if (backgroundImage) {
+ backgroundImage.onload = null;
+ backgroundImage.onerror = null;
}
- function draw(now) {
- var elapsed = Math.max(0, ((Number(now) || performance.now()) - startedAt) / 1000);
- drawMotionFrame(ctx, backgroundImage, motionScene, elapsed);
- raf = requestAnimationFrame(draw);
+ if (recorder) {
+ recorder.ondataavailable = null;
+ recorder.onerror = null;
+ recorder.onstop = null;
+ try { if (recorder.state !== 'inactive') recorder.stop(); } catch (_) {}
}
- recorder.ondataavailable = function (event) {
- if (event.data && event.data.size) chunks.push(event.data);
- };
- recorder.onerror = function (event) {
- cleanup();
- reject(event.error || exportError('viewer.export.error.mediaRecorder'));
+ if (stream) stream.getTracks().forEach(function (track) { track.stop(); });
+ if (sourceUrl) URL.revokeObjectURL(sourceUrl);
+ if (blob) resolve(blob);
+ else reject(error);
+ }
+
+ try {
+ sourceUrl = URL.createObjectURL(new Blob([data.svgString], { type: 'image/svg+xml;charset=utf-8' }));
+ backgroundImage = new Image();
+ backgroundImage.onload = function () {
+ if (settled) return;
+ try {
+ var canvas = document.createElement('canvas');
+ canvas.width = Math.max(2, Math.round(data.width / 2) * 2);
+ canvas.height = Math.max(2, Math.round(data.height / 2) * 2);
+ var ctx = canvas.getContext('2d');
+ if (!ctx) throw exportError('viewer.export.error.contextUnavailable', { label: 'WebM' });
+ stream = canvas.captureStream(fps);
+ var mime = motionMimeType();
+ recorder = new MediaRecorder(stream, { mimeType: mime, videoBitsPerSecond: 6000000 });
+ var chunks = [];
+ var startedAt = performance.now();
+ function draw(now) {
+ if (settled) return;
+ try {
+ var elapsed = Math.max(0, ((Number(now) || performance.now()) - startedAt) / 1000);
+ drawMotionFrame(ctx, backgroundImage, motionScene, elapsed);
+ raf = requestAnimationFrame(draw);
+ } catch (error) { finish(error); }
+ }
+ recorder.ondataavailable = function (event) {
+ if (!settled && event.data && event.data.size) chunks.push(event.data);
+ };
+ recorder.onerror = function (event) {
+ finish(event.error || exportError('viewer.export.error.mediaRecorder'));
+ };
+ recorder.onstop = function () {
+ if (settled) return;
+ try {
+ var blob = new Blob(chunks, { type: recorder.mimeType || mime });
+ if (!blob.size) throw exportError('viewer.export.error.emptyWebm');
+ finish(null, blob);
+ } catch (error) { finish(error); }
+ };
+ drawMotionFrame(ctx, backgroundImage, motionScene, 0);
+ recorder.start(250);
+ if (settled) return;
+ startedAt = performance.now();
+ raf = requestAnimationFrame(draw);
+ durationTimer = setTimeout(function () {
+ if (settled || recorder.state === 'inactive') return;
+ // 保留最佳努力的编码器 flush;失败后仍通过 stop 收集最后的片段。
+ try { recorder.requestData(); } catch (_) {}
+ if (settled) return;
+ flushTimer = setTimeout(function () {
+ if (settled) return;
+ try { if (recorder.state !== 'inactive') recorder.stop(); }
+ catch (error) { finish(error); }
+ }, 120);
+ }, duration);
+ } catch (error) { finish(error); }
};
- recorder.onstop = function () {
- cleanup();
- var blob = new Blob(chunks, { type: recorder.mimeType || mime });
- if (!blob.size) reject(exportError('viewer.export.error.emptyWebm'));
- else resolve(blob);
+ backgroundImage.onerror = function () {
+ finish(exportError('viewer.export.error.webmBackground'));
};
- drawMotionFrame(ctx, backgroundImage, motionScene, 0);
- recorder.start(250);
- startedAt = performance.now();
- raf = requestAnimationFrame(draw);
- setTimeout(function () {
- if (recorder.state === 'inactive') return;
- // Chromium normally emits the final chunk during stop(), but
- // some embedded browser shells need an explicit encoder flush
- // first. Keep the short grace window bounded and harmless for
- // browsers that already delivered timeslice chunks.
- try { recorder.requestData(); } catch (_) {}
- setTimeout(function () {
- if (recorder.state !== 'inactive') recorder.stop();
- }, 120);
- }, duration);
- };
- backgroundImage.onerror = function () {
- URL.revokeObjectURL(sourceUrl);
- reject(exportError('viewer.export.error.webmBackground'));
- };
- backgroundImage.src = sourceUrl;
+ backgroundImage.src = sourceUrl;
+ } catch (error) { finish(error); }
});
}
diff --git a/examples/workflow-agent-tool-call-rendered.html b/examples/workflow-agent-tool-call-rendered.html
index c64d9d52..b68df2f5 100644
--- a/examples/workflow-agent-tool-call-rendered.html
+++ b/examples/workflow-agent-tool-call-rendered.html
@@ -6665,7 +6665,6 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
var vb = svg.viewBox.baseVal;
var scale = Math.min(1, 1280 / vb.width);
var data = serializeSvg(scale);
- var sourceUrl = URL.createObjectURL(new Blob([data.svgString], { type: 'image/svg+xml;charset=utf-8' }));
function createMotionScene(root) {
var rootMatrix = root.getCTM ? root.getCTM() : null;
@@ -6817,73 +6816,99 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
var motionScene = createMotionScene(svg);
return new Promise(function (resolve, reject) {
- var backgroundImage = new Image();
- backgroundImage.onload = function () {
- var canvas = document.createElement('canvas');
- canvas.width = Math.max(2, Math.round(data.width / 2) * 2);
- canvas.height = Math.max(2, Math.round(data.height / 2) * 2);
- var ctx = canvas.getContext('2d');
- var stream = canvas.captureStream(fps);
- var mime = motionMimeType();
- var recorder;
- try {
- recorder = new MediaRecorder(stream, { mimeType: mime, videoBitsPerSecond: 6000000 });
- } catch (err) {
- URL.revokeObjectURL(sourceUrl);
- stream.getTracks().forEach(function (track) { track.stop(); });
- reject(err);
- return;
- }
- var chunks = [];
- var raf = 0;
- var stopped = false;
- var startedAt = performance.now();
- function cleanup() {
- if (stopped) return;
- stopped = true;
- cancelAnimationFrame(raf);
- URL.revokeObjectURL(sourceUrl);
- stream.getTracks().forEach(function (track) { track.stop(); });
+ var sourceUrl = null;
+ var backgroundImage = null;
+ var stream = null;
+ var recorder = null;
+ var raf = 0;
+ var durationTimer = 0;
+ var flushTimer = 0;
+ var settled = false;
+
+ function finish(error, blob) {
+ if (settled) return;
+ // 先锁定终态:停止录制和释放流可能产生晚到的编码事件。
+ settled = true;
+ cancelAnimationFrame(raf);
+ clearTimeout(durationTimer);
+ clearTimeout(flushTimer);
+ if (backgroundImage) {
+ backgroundImage.onload = null;
+ backgroundImage.onerror = null;
}
- function draw(now) {
- var elapsed = Math.max(0, ((Number(now) || performance.now()) - startedAt) / 1000);
- drawMotionFrame(ctx, backgroundImage, motionScene, elapsed);
- raf = requestAnimationFrame(draw);
+ if (recorder) {
+ recorder.ondataavailable = null;
+ recorder.onerror = null;
+ recorder.onstop = null;
+ try { if (recorder.state !== 'inactive') recorder.stop(); } catch (_) {}
}
- recorder.ondataavailable = function (event) {
- if (event.data && event.data.size) chunks.push(event.data);
- };
- recorder.onerror = function (event) {
- cleanup();
- reject(event.error || exportError('viewer.export.error.mediaRecorder'));
+ if (stream) stream.getTracks().forEach(function (track) { track.stop(); });
+ if (sourceUrl) URL.revokeObjectURL(sourceUrl);
+ if (blob) resolve(blob);
+ else reject(error);
+ }
+
+ try {
+ sourceUrl = URL.createObjectURL(new Blob([data.svgString], { type: 'image/svg+xml;charset=utf-8' }));
+ backgroundImage = new Image();
+ backgroundImage.onload = function () {
+ if (settled) return;
+ try {
+ var canvas = document.createElement('canvas');
+ canvas.width = Math.max(2, Math.round(data.width / 2) * 2);
+ canvas.height = Math.max(2, Math.round(data.height / 2) * 2);
+ var ctx = canvas.getContext('2d');
+ if (!ctx) throw exportError('viewer.export.error.contextUnavailable', { label: 'WebM' });
+ stream = canvas.captureStream(fps);
+ var mime = motionMimeType();
+ recorder = new MediaRecorder(stream, { mimeType: mime, videoBitsPerSecond: 6000000 });
+ var chunks = [];
+ var startedAt = performance.now();
+ function draw(now) {
+ if (settled) return;
+ try {
+ var elapsed = Math.max(0, ((Number(now) || performance.now()) - startedAt) / 1000);
+ drawMotionFrame(ctx, backgroundImage, motionScene, elapsed);
+ raf = requestAnimationFrame(draw);
+ } catch (error) { finish(error); }
+ }
+ recorder.ondataavailable = function (event) {
+ if (!settled && event.data && event.data.size) chunks.push(event.data);
+ };
+ recorder.onerror = function (event) {
+ finish(event.error || exportError('viewer.export.error.mediaRecorder'));
+ };
+ recorder.onstop = function () {
+ if (settled) return;
+ try {
+ var blob = new Blob(chunks, { type: recorder.mimeType || mime });
+ if (!blob.size) throw exportError('viewer.export.error.emptyWebm');
+ finish(null, blob);
+ } catch (error) { finish(error); }
+ };
+ drawMotionFrame(ctx, backgroundImage, motionScene, 0);
+ recorder.start(250);
+ if (settled) return;
+ startedAt = performance.now();
+ raf = requestAnimationFrame(draw);
+ durationTimer = setTimeout(function () {
+ if (settled || recorder.state === 'inactive') return;
+ // 保留最佳努力的编码器 flush;失败后仍通过 stop 收集最后的片段。
+ try { recorder.requestData(); } catch (_) {}
+ if (settled) return;
+ flushTimer = setTimeout(function () {
+ if (settled) return;
+ try { if (recorder.state !== 'inactive') recorder.stop(); }
+ catch (error) { finish(error); }
+ }, 120);
+ }, duration);
+ } catch (error) { finish(error); }
};
- recorder.onstop = function () {
- cleanup();
- var blob = new Blob(chunks, { type: recorder.mimeType || mime });
- if (!blob.size) reject(exportError('viewer.export.error.emptyWebm'));
- else resolve(blob);
+ backgroundImage.onerror = function () {
+ finish(exportError('viewer.export.error.webmBackground'));
};
- drawMotionFrame(ctx, backgroundImage, motionScene, 0);
- recorder.start(250);
- startedAt = performance.now();
- raf = requestAnimationFrame(draw);
- setTimeout(function () {
- if (recorder.state === 'inactive') return;
- // Chromium normally emits the final chunk during stop(), but
- // some embedded browser shells need an explicit encoder flush
- // first. Keep the short grace window bounded and harmless for
- // browsers that already delivered timeslice chunks.
- try { recorder.requestData(); } catch (_) {}
- setTimeout(function () {
- if (recorder.state !== 'inactive') recorder.stop();
- }, 120);
- }, duration);
- };
- backgroundImage.onerror = function () {
- URL.revokeObjectURL(sourceUrl);
- reject(exportError('viewer.export.error.webmBackground'));
- };
- backgroundImage.src = sourceUrl;
+ backgroundImage.src = sourceUrl;
+ } catch (error) { finish(error); }
});
}
diff --git a/viewer/README.md b/viewer/README.md
index 44aa7396..0dfd9c24 100644
--- a/viewer/README.md
+++ b/viewer/README.md
@@ -110,9 +110,10 @@ are part of the interface, not normalized by the extraction.
| Auto-theme probes | Detached after computed-style sampling, including finally on failure |
| Download URL/anchor | Anchor appended/clicked/removed synchronously; URL revoked after 1000ms |
| Raster/card SVG URL | Lives until Image load/draw or error; revoked before toBlob completion, with existing catch cleanup |
-| Recording background URL | Survives background loading and recording; released on image error, recorder-constructor failure or recorder cleanup |
-| Recording tracks/rAF | Constructor failure stops created tracks; recorder error/stop uses existing guarded cleanup to stop tracks and cancel the frame callback |
-| Recording/toast timers | Preserve existing bounded callbacks and state checks; extraction adds no cancellation protocol or shared busy flag |
+| 录制背景 URL | 从背景加载持续到录制结束,由下文说明的统一终态在成功或失败后释放 |
+| 录制 tracks/rAF | 统一终态停止已创建的 tracks 并取消动画帧回调,晚到事件不重复清理 |
+| 录制定时器 | 统一终态取消录制时长和最终 flush 定时器,防止失败后再次操作编码器 |
+| Toast 定时器 | 保留既有有界回调和状态检查,不增加共享 busy 状态或取消协议 |
recordWebm retains duration/fps options, defaults, minimums, MIME selection,
geometry-driven scene and encoder flush timing. This table describes existing