(function (root) { 'use strict' const ratios = [ ['1:1', '1024x1024', '2048x2048', '2864x2864'], ['2:3', '832x1248', '1536x2304', '2048x3072'], ['3:2', '1248x832', '2304x1536', '3072x2048'], ['3:4', '880x1168', '2016x2688', '2448x3264'], ['4:3', '1184x880', '2688x2016', '2688x2016'], ['4:5', '912x1136', '1632x2032', '2048x2560'], ['5:4', '1136x896', '2032x1632', '2560x2048'], ['16:9', '1360x752', '2048x1152', '3840x2160'], ['9:16', '768x1360', '1440x2560', '2160x3840'], ['21:9', '1552x656', '2688x1152', '3840x1648'], ['9:21', '656x1520', '1152x2688', '1648x3840'], ] const table = Object.create(null) for (const row of ratios) table[row[0]] = { '1K': row[1], '2K': row[2], '4K': row[3] } const keys = ['1K', '2K', '4K'] const legacy = { '标准': '1K', '高清': '2K', '1K': '1K', '2K': '2K', '4K': '4K' } function normalizeResolution(value) { return legacy[String(value || '').trim()] || '1K' } function getSize(ratio, resolution) { const row = table[String(ratio || '')]; return row ? row[normalizeResolution(resolution)] : null } function getBillingTier(size) { const m = /^(\d+)x(\d+)$/.exec(String(size || '').trim()) if (!m) return 'unknown' const pixels = Number(m[1]) * Number(m[2]) return pixels <= 1048576 ? '1K' : pixels > 4194304 ? '4K' : '2K' } function validateSize(size) { if (String(size || '').trim().toLowerCase() === 'auto') return null const m = /^(\d+)x(\d+)$/.exec(String(size || '').trim()) if (!m) return '尺寸格式应为 WxH,如 1024x1024' const w = Number(m[1]), h = Number(m[2]) if (!w || !h) return '宽高必须是正整数' if (Math.max(w, h) > 3840) return '最大边长不能超过 3840px' // 渠道实测支持 3:1 内的任意整数尺寸;不在客户端强加 16 对齐或像素总量限制。 if (Math.max(w, h) / Math.min(w, h) > 3) return '长边与短边的比例不能超过 3:1' if (w * h > 8294400) return '像素总量不能超过 8294400(约 4K 档位)' return null } root.IWBGenerationSizePolicy = Object.freeze({ ratios, keys, normalizeResolution, getSize, getBillingTier, validateSize }) })(typeof window !== 'undefined' ? window : globalThis)