|
72 | 72 | .ver { font-size: 11.5px; color: var(--muted); background: var(--accent-soft); padding: 2px 8px; border-radius: 999px; } |
73 | 73 | .crumb { flex: 1; min-width: 0; color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: center; } |
74 | 74 | .actions { display: flex; gap: 10px; align-items: center; } |
| 75 | +/* ===== M/R/X 三版切换器 ===== */ |
| 76 | +.ed-switch { display: inline-flex; gap: 2px; padding: 3px; border: 1px solid var(--line); border-radius: 999px; background: rgba(255, 252, 245, .6); } |
| 77 | +.ed-switch .ed-btn { min-width: 28px; padding: 5px 9px; border: none; border-radius: 999px; background: transparent; color: var(--dim); font-size: 12px; font-weight: 800; letter-spacing: .5px; cursor: pointer; transition: background .15s, color .15s; } |
| 78 | +.ed-switch .ed-btn:hover { color: var(--accent-strong); } |
| 79 | +.ed-switch .ed-btn.on { background: linear-gradient(140deg, #e2b878, #b38545); color: #fff; box-shadow: 0 3px 10px rgba(179, 133, 69, .35); } |
75 | 80 | .menu-wrap { position: relative; } |
76 | 81 | .menu { |
77 | 82 | position: absolute; right: 0; top: calc(100% + 8px); min-width: 250px; z-index: 40; |
|
396 | 401 | </div> |
397 | 402 | <div class="crumb" id="crumb" title="当前文件">—</div> |
398 | 403 | <div class="actions"> |
| 404 | + <div class="ed-switch" id="edSwitch" title="切换 HIC 版本:M 轻量(仅 HIC 内核)/ R 标准(+Python 编译)/ X 全能(+Python +C++ 编译)。切换后预览与导出页面均按所选版本编译"> |
| 405 | + <button type="button" class="ed-btn" data-ed="m">M</button> |
| 406 | + <button type="button" class="ed-btn" data-ed="r">R</button> |
| 407 | + <button type="button" class="ed-btn on" data-ed="x">X</button> |
| 408 | + </div> |
399 | 409 | <button id="btnLive" class="btn ghost live" title="观看实时转译:立即把当前页面 HIC 代码转译为 HTML">✓ 实时转译</button> |
400 | 410 | <div class="menu-wrap"> |
401 | 411 | <button id="btnExport" class="btn solid">导出 ▾</button> |
@@ -2264,6 +2274,7 @@ <h1>HiCode <span class="dim">· HIC 语言在线开发</span></h1> |
2264 | 2274 | addPage: $("addPage"), |
2265 | 2275 | btnLive: $("btnLive"), |
2266 | 2276 | btnExport: $("btnExport"), |
| 2277 | + edSwitch: $("edSwitch"), |
2267 | 2278 | fileImg: $("fileImg"), |
2268 | 2279 | fileHc: $("fileHc"), |
2269 | 2280 | fileApp: $("fileApp"), |
@@ -2325,6 +2336,47 @@ <h1>HiCode <span class="dim">· HIC 语言在线开发</span></h1> |
2325 | 2336 | }); |
2326 | 2337 | } |
2327 | 2338 |
|
| 2339 | + /* ---- 三版切换(M 轻量 / R 标准 / X 全能) ---- */ |
| 2340 | + // 网页端可随时切换版本:切换后引擎可编译语言、预览与导出页面均按所选版本执行 |
| 2341 | + const ED_NAME = { m: "M·轻量版", r: "R·标准版", x: "X·全能版" }; |
| 2342 | + const ED_DESC = { m: "仅 HIC 内核", r: "内核 + Python 编译", x: "内核 + Python + C++ 编译" }; |
| 2343 | + function edNorm(ed) { |
| 2344 | + const c = String(ed || "").toLowerCase()[0]; |
| 2345 | + return (c === "m" || c === "r" || c === "x") ? c : "x"; |
| 2346 | + } |
| 2347 | + function currentEdition() { return state.edition || "x"; } |
| 2348 | + // 把当前版本应用到:引擎(HC.setEdition)、全局标记(window.HIC_EDITION)、 |
| 2349 | + // 顶栏版本徽标、切换器高亮、代码片段按钮(+ Python / + C++)显隐 |
| 2350 | + function applyEditionUI() { |
| 2351 | + const ed = currentEdition(); |
| 2352 | + if (typeof HC !== "undefined" && HC.setEdition) HC.setEdition(ed); |
| 2353 | + try { window.HIC_EDITION = ed; } catch (e) {} |
| 2354 | + const VT = document.getElementById("verTag"); |
| 2355 | + if (VT) VT.textContent = "v3.66 · " + ED_NAME[ed]; |
| 2356 | + if (el.edSwitch) Array.prototype.forEach.call(el.edSwitch.querySelectorAll(".ed-btn"), function (b) { |
| 2357 | + b.classList.toggle("on", b.getAttribute("data-ed") === ed); |
| 2358 | + }); |
| 2359 | + Array.prototype.forEach.call(document.querySelectorAll(".snippet"), function (b) { |
| 2360 | + const needEd = (b.getAttribute("data-ed") || "").toLowerCase(); |
| 2361 | + if (!needEd) return; |
| 2362 | + let visible = false; |
| 2363 | + if (needEd === "rx") visible = (ed === "r" || ed === "x"); |
| 2364 | + else if (needEd === "x") visible = (ed === "x"); |
| 2365 | + b.style.display = visible ? "" : "none"; |
| 2366 | + }); |
| 2367 | + } |
| 2368 | + function setEdition(ed, silent) { |
| 2369 | + const v = edNorm(ed); |
| 2370 | + if (v === state.edition) return; |
| 2371 | + state.edition = v; |
| 2372 | + try { localStorage.setItem("HIC_EDITION_PREF", v); } catch (e) {} |
| 2373 | + applyEditionUI(); |
| 2374 | + if (!silent) { |
| 2375 | + logConsole("output", "已切换到 " + ED_NAME[v] + "(" + ED_DESC[v] + ");预览与导出页面将按此版本编译"); |
| 2376 | + doLive(); |
| 2377 | + } |
| 2378 | + } |
| 2379 | + |
2328 | 2380 | /* ---- 首页引导 ---- */ |
2329 | 2381 | function showHome() { |
2330 | 2382 | saveNow(); |
@@ -3024,16 +3076,14 @@ <h1>HiCode <span class="dim">· HIC 语言在线开发</span></h1> |
3024 | 3076 | }); |
3025 | 3077 | // 可下载文件上传 |
3026 | 3078 | el.fileApp.onchange = onFileApp; |
| 3079 | + // 三版切换器:M 轻量 / R 标准 / X 全能(切换后立即按新版本重新转译) |
| 3080 | + if (el.edSwitch) el.edSwitch.addEventListener("click", function (e) { |
| 3081 | + const b = e.target.closest ? e.target.closest("[data-ed]") : null; |
| 3082 | + if (b) setEdition(b.getAttribute("data-ed")); |
| 3083 | + }); |
3027 | 3084 | // 快捷代码片段:触发区域 / use / 下载文件 / 原生HTML / 编译语言块 |
3028 | | - const _ed = (window.HIC_EDITION || "").toLowerCase(); // m=仅HIC r=+py x=+py+cpp |
| 3085 | + // (「+ Python / + C++」按钮随版本显隐由 applyEditionUI 统一处理) |
3029 | 3086 | Array.prototype.forEach.call(document.querySelectorAll(".snippet"), function (b) { |
3030 | | - const needEd = (b.getAttribute("data-ed") || "").toLowerCase(); |
3031 | | - if (needEd) { |
3032 | | - let ok = false; |
3033 | | - if (needEd === "rx") ok = (_ed === "r" || _ed === "x"); |
3034 | | - else if (needEd === "x") ok = (_ed === "x"); |
3035 | | - if (!ok) { b.style.display = "none"; } |
3036 | | - } |
3037 | 3087 | b.onclick = function () { |
3038 | 3088 | const snip = b.getAttribute("data-snip"); |
3039 | 3089 | const code = el.code, s = code.selectionStart; |
@@ -3063,15 +3113,22 @@ <h1>HiCode <span class="dim">· HIC 语言在线开发</span></h1> |
3063 | 3113 | function boot() { |
3064 | 3114 | bind(); |
3065 | 3115 | bindNoBarPref(); |
3066 | | - // 三版发布:按 HIC_EDITION 设置引擎可编译语言并在顶栏显示版本号 |
3067 | | - const ed = (window.HIC_EDITION || "x").toLowerCase(); |
3068 | | - if (HC.setEdition) HC.setEdition(ed); |
3069 | | - const ED_NAME = { m: "M·轻量版", r: "R·标准版", x: "X·全能版" }[ed] || "X·全能版"; |
3070 | | - const VT = document.getElementById("verTag"); |
3071 | | - if (VT) VT.textContent = "v3.66 · " + ED_NAME; |
| 3116 | + // 三版发布:网页端可直接切换 M/R/X。优先级: |
| 3117 | + // ① URL 参数 ?edition=m|r|x(下载页「在线体验三版」直达) |
| 3118 | + // ② localStorage 记忆的上次选择 |
| 3119 | + // ③ 离线单文件在 <head> 注入的 window.HIC_EDITION(发布形态固定档位) |
| 3120 | + // ④ 默认 X 全能版 |
| 3121 | + let ed = ""; |
| 3122 | + try { |
| 3123 | + const q = new URLSearchParams(window.location.search || "").get("edition"); |
| 3124 | + ed = q || localStorage.getItem("HIC_EDITION_PREF") || ""; |
| 3125 | + } catch (e) { ed = ""; } |
| 3126 | + if (!ed && window.HIC_EDITION) ed = String(window.HIC_EDITION); |
| 3127 | + state.edition = edNorm(ed || "x"); |
| 3128 | + applyEditionUI(); |
3072 | 3129 | // 轻量编辑器:语法高亮 + 行号 + 自动缩进 + 括号补全 |
3073 | 3130 | if (window.HICED) window.hiced = HICED.create(el.code); |
3074 | | - if (typeof HC !== "undefined" && HC.APP) logConsole("output", "HiCode " + HC.APP.version + " " + ED_NAME + "(HIC " + (ed === "m" ? "仅 HIC 内核" : ed === "r" ? "内核 + Python" : "内核 + Python + C++") + ")已启动 · 就绪"); |
| 3131 | + if (typeof HC !== "undefined" && HC.APP) logConsole("output", "HiCode " + HC.APP.version + " " + ED_NAME[currentEdition()] + "(HIC " + ED_DESC[currentEdition()] + ")已启动 · 就绪"); |
3075 | 3132 | else logConsole("output", "HiCode IDE 已启动 · 就绪"); |
3076 | 3133 | if (!Store.hasAnyProject()) { showHome(); return; } |
3077 | 3134 | showHome(); // 默认先回首页引导;也可自动恢复 |
|
0 commit comments