Files
image-workbench-desktop/src/canvas-v3.js
T

70 lines
2.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/* canvas-v3.js —— Canvas 静态渲染迁移的特性开关(2026-12-01,Phase 0)
*
* 默认关闭;开启后只改变 data-canvas-v3 与后续渲染器选择,不影响数据格式。
* 目标架构见 docs/plans/canvas-v3-long-term.md。
*/
;(function (global) {
'use strict'
const KEY = 'iwb_canvas_v3'
const ATTR = 'canvasV3'
// src 内不直调 localStorage:统一走 IWBStorageLocal 门面(桌面端会落到资料目录底座)。
function store () {
try {
const S = global.IWBStorageLocal
return (S && typeof S.getStore === 'function') ? S.getStore() : null
} catch (e) { return null }
}
// 2026-12-01:Canvas V3 实验停止。旧用户即使 localStorage 里还留着 '1',也必须回 DOM。
// 保留代码仅用于后续研究;产品路径不再进入 Canvas V3。
function isEnabled () {
return false
}
function syncRoot (on) {
try {
if (typeof document !== 'undefined' && document.documentElement) {
document.documentElement.dataset[ATTR] = on ? 'on' : 'off'
}
} catch (e) { /* ignore */ }
}
function setEnabled (on) {
const next = false // kill switch:不再允许开启
try {
const s = store()
if (s && typeof s.rawSet === 'function') s.rawSet(KEY, '0')
} catch (e) { /* ignore */ }
syncRoot(next)
try {
if (typeof window !== 'undefined' && typeof window.dispatchEvent === 'function' && typeof CustomEvent === 'function') {
window.dispatchEvent(new CustomEvent('iwb:canvas-v3', { detail: { enabled: next } }))
}
} catch (e) { /* ignore */ }
return next
}
function init () {
syncRoot(false)
try { const s = store(); if (s && typeof s.rawSet === 'function') s.rawSet(KEY, '0') } catch (e) { /* ignore */ }
return false
}
function stats () {
const on = isEnabled()
let dom = -1
try { dom = document.getElementsByTagName('*').length } catch (e) { /* ignore */ }
let node = null
try {
const L = global.IWBCanvasV3NodeLayer
if (L && typeof L.stats === 'function') node = L.stats()
} catch (e) { /* ignore */ }
return { enabled: on, dom, node }
}
// P2 第一批:ref 图片节点 + prompt/textout 文本类节点。
const TYPES = ['ref', 'prompt', 'textout', 'combine', 'batch', 'relay', 'gen', 'out', 'layer']
global.IWBCanvasV3 = { KEY, TYPES, isEnabled, setEnabled, init, stats }
})(typeof window !== 'undefined' ? window : globalThis)