diff --git a/scripts/theme-fuc/app.test.mjs b/scripts/theme-fuc/app.test.mjs index 6e54b54a..7534f353 100644 --- a/scripts/theme-fuc/app.test.mjs +++ b/scripts/theme-fuc/app.test.mjs @@ -30,6 +30,8 @@ globalThis.fetch=async(url,options={})=>{ }; const append=document.head.append.bind(document.head); document.head.append=node=>{append(node);if(node.tagName==='SCRIPT')queueMicrotask(()=>{try{window.eval(requireFile(node.src));node.onload?.();}catch(error){node.onerror?.(error);}});if(node.tagName==='LINK')queueMicrotask(()=>node.onload?.());}; +const insertBefore=document.head.insertBefore.bind(document.head); +document.head.insertBefore=(node,before)=>{const result=insertBefore(node,before);if(node.tagName==='LINK')queueMicrotask(()=>node.onload?.());return result;}; const {readFileSync}=await import('node:fs');const requireFile=url=>readFileSync(new URL(url),'utf8'); const until=async predicate=>{for(let n=0;n<200;n++){if(predicate())return;await new Promise(resolve=>setTimeout(resolve,10));}throw Error('DOM state did not settle');}; const go=async route=>{location.hash='/'+route;await until(()=>document.body.dataset.nativePage===route);}; diff --git a/scripts/theme-fuc/dom.test.mjs b/scripts/theme-fuc/dom.test.mjs index 1c0b4026..74a55c0e 100644 --- a/scripts/theme-fuc/dom.test.mjs +++ b/scripts/theme-fuc/dom.test.mjs @@ -10,6 +10,28 @@ const {paymentForm,showPayment}=await import('../../theme/Fuc/assets/payments.mj const {richText}=await import('../../theme/Fuc/assets/content.mjs'); const {copyText}=await import('../../theme/Fuc/assets/clipboard.mjs'); const native=await import('../../theme/Fuc/assets/native.mjs');await native.nativeReady; +test('user navigation keeps active shared CSS and its dark/bridge overrides attached',async()=>{ + const append=document.head.append.bind(document.head),insert=document.head.insertBefore.bind(document.head),moved=[]; + document.head.append=node=>{if(node.isConnected&&node.tagName==='LINK')moved.push(node);append(node);if(node.tagName==='LINK')queueMicrotask(()=>node.onload?.());}; + document.head.insertBefore=(node,before)=>{if(node.isConnected&&node.tagName==='LINK')moved.push(node);const result=insert(node,before);if(node.tagName==='LINK')queueMicrotask(()=>node.onload?.());return result;}; + globalThis.innerWidth=1280; + try { + await native.prepareNativeMode('user','plans');native.nativeMode('user','plans'); + const common=[...document.querySelectorAll('[data-fuc-native]')].filter(n=>!n.href.includes('/page/shop.css')); + const dark=document.getElementById('native-dark'),bridge=document.getElementById('native-bridge');moved.length=0; + await native.prepareNativeMode('user','wallet');native.nativeMode('user','wallet'); + assert.ok(common.length>5);assert.ok(common.every(n=>n.isConnected&&n.media==='all')); + assert.equal(document.getElementById('native-dark'),dark);assert.equal(document.getElementById('native-bridge'),bridge); + assert.deepEqual(moved,[],'reparenting loaded LINKs can unload CSS and flash an unstyled page'); + const before=[...document.querySelectorAll('[data-fuc-native]')]; + const changing=native.prepareNativeMode('auth','login');assert.ok(before.every(n=>n.isConnected&&n.media==='all')); + await changing;native.nativeMode('auth','login'); + assert.ok(before.every(n=>!n.isConnected)); + const styles=JSON.parse(await fs.readFile(new URL('../../theme/Fuc/assets/native/styles.json',import.meta.url),'utf8')); + assert.deepEqual([...document.querySelectorAll('[data-fuc-native]')].map(n=>n.href.split('/native/')[1].split('?')[0]),styles.login.map(p=>p.split('?')[0])); + assert.equal([...document.querySelectorAll('link[rel=stylesheet]')].at(-1),bridge,'overrides keep their position after the native CSS'); + }finally{document.head.append=append;document.head.insertBefore=insert;} +}); test('wallet-funded checkout and history show package value instead of zero online remainder',()=>{ const order={trade_no:'synthetic-wallet-order',status:3,total_amount:0,balance_amount:10000,surplus_amount:0,surplus_credit:0,period:'month_price',plan:{name:'Synthetic plan'},created_at:1}; const context={user:{},sub:{},data:order,methods:[],config:{}}; diff --git a/theme/Fuc/assets/app.mjs b/theme/Fuc/assets/app.mjs index 48cbd4bd..7f9a3e09 100644 --- a/theme/Fuc/assets/app.mjs +++ b/theme/Fuc/assets/app.mjs @@ -1,13 +1,13 @@ -import {applyPalette} from './palettes.mjs?v=0.12.2'; -import {subscriptionUrl as makeSubscriptionUrl,importUrl} from './subscription.mjs?v=0.12.2'; -import {interactionsReady,paintInteractions,disposeInteractions,showModal,hideModals,toggleCollapse,selectTab,toggleDropdown,notify,scrollTop,scrollSection,toggleMenu,updateMenu,paintScrollTop,authFeedback,confirmSubscriptionReset} from './interactions.mjs?v=0.12.2'; -import {richText} from './content.mjs?v=0.12.2'; -import {copyText} from './clipboard.mjs?v=0.12.2'; -import {createCaptcha} from './captcha.mjs?v=0.12.2'; -import {showPayment,mountCard} from './payments.mjs?v=0.12.2'; -import {beginPageProgress,finishPageProgress} from './progress.mjs?v=0.12.2'; -import {nativeReady,prepareNativeMode,nativeMode,fillPurchaseModal,nativeHeader,nativeFooter,nativeDashboard,nativeHome,nativeAuth,nativeSecondary,paintNativeChart,paintNativeHome} from './native.mjs?v=0.12.2'; -import {escape as e, money, bytes, date, list, groupedList, periods, orderStates, soldOut, safeUrl, createApi, routeFromHash,canPurchase} from './core.mjs?v=0.12.2'; +import {applyPalette} from './palettes.mjs?v=0.12.3'; +import {subscriptionUrl as makeSubscriptionUrl,importUrl} from './subscription.mjs?v=0.12.3'; +import {interactionsReady,paintInteractions,disposeInteractions,showModal,hideModals,toggleCollapse,selectTab,toggleDropdown,notify,scrollTop,scrollSection,toggleMenu,updateMenu,paintScrollTop,authFeedback,confirmSubscriptionReset} from './interactions.mjs?v=0.12.3'; +import {richText} from './content.mjs?v=0.12.3'; +import {copyText} from './clipboard.mjs?v=0.12.3'; +import {createCaptcha} from './captcha.mjs?v=0.12.3'; +import {showPayment,mountCard} from './payments.mjs?v=0.12.3'; +import {beginPageProgress,finishPageProgress} from './progress.mjs?v=0.12.3'; +import {nativeReady,prepareNativeMode,nativeMode,fillPurchaseModal,nativeHeader,nativeFooter,nativeDashboard,nativeHome,nativeAuth,nativeSecondary,paintNativeChart,paintNativeHome} from './native.mjs?v=0.12.3'; +import {escape as e, money, bytes, date, list, groupedList, periods, orderStates, soldOut, safeUrl, createApi, routeFromHash,canPurchase} from './core.mjs?v=0.12.3'; const settings = window.fucSettings || {}; const root = document.querySelector('#app'); const preview = settings.preview === true; diff --git a/theme/Fuc/assets/content.mjs b/theme/Fuc/assets/content.mjs index 85a4f1e5..29c0167a 100644 --- a/theme/Fuc/assets/content.mjs +++ b/theme/Fuc/assets/content.mjs @@ -1,4 +1,4 @@ -import {marked,DOMPurify} from './vendor/richtext.mjs?v=0.12.2'; +import {marked,DOMPurify} from './vendor/richtext.mjs?v=0.12.3'; export function richText(value) { const html=marked.parse(String(value||''),{async:false}); return '
'+DOMPurify.sanitize(html,{ALLOWED_TAGS:['p','br','strong','b','em','i','ul','ol','li','h1','h2','h3','h4','h5','h6','blockquote','code','pre','a','img','table','thead','tbody','tr','th','td','hr','details','summary','div','span'],ALLOWED_ATTR:['href','src','alt','title','colspan','rowspan'],ALLOW_DATA_ATTR:false})+'
'; diff --git a/theme/Fuc/assets/interactions.mjs b/theme/Fuc/assets/interactions.mjs index 18fa51c8..1ef62046 100644 --- a/theme/Fuc/assets/interactions.mjs +++ b/theme/Fuc/assets/interactions.mjs @@ -1,12 +1,12 @@ // FUC's original UI plugins, driven only by the XB theme's event bindings. -import {loadScript} from './captcha.mjs?v=0.12.2'; +import {loadScript} from './captcha.mjs?v=0.12.3'; const base=new URL('./native/',import.meta.url).href; let landingUI; -export const interactionsReady=loadScript(base+'widgets.min.js?v=0.12.2').then(()=>loadScript(base+'sweetalert2.min.js?v=0.12.2')).then(()=>loadScript(base+'smooth-scroll.min.js?v=0.12.2')).then(async()=>{ +export const interactionsReady=loadScript(base+'widgets.min.js?v=0.12.3').then(()=>loadScript(base+'sweetalert2.min.js?v=0.12.3')).then(()=>loadScript(base+'smooth-scroll.min.js?v=0.12.3')).then(async()=>{ const userUI=window.bootstrap; // The source landing page uses Bootstrap 5; keep its data APIs separate from user Bootstrap 4. document.body.setAttribute('data-bs-no-jquery',''); - try{await loadScript(base+'landing-bootstrap5.min.js?v=0.12.2');landingUI=window.bootstrap;} + try{await loadScript(base+'landing-bootstrap5.min.js?v=0.12.3');landingUI=window.bootstrap;} finally{window.bootstrap=userUI;document.body.removeAttribute('data-bs-no-jquery');} // Delegated data APIs would duplicate the theme's explicit XB action handlers. window.jQuery(document).off('.bs.modal.data-api .bs.collapse.data-api .bs.tab.data-api .bs.dropdown.data-api'); diff --git a/theme/Fuc/assets/native.mjs b/theme/Fuc/assets/native.mjs index cdac417f..c56b442f 100644 --- a/theme/Fuc/assets/native.mjs +++ b/theme/Fuc/assets/native.mjs @@ -1,12 +1,12 @@ -import {getPalette,applyPalette} from './palettes.mjs?v=0.12.2'; -import {escape as e,money,bytes,date,safeUrl,soldOut,trafficSummary,canPurchase,orderAmount} from './core.mjs?v=0.12.2'; +import {getPalette,applyPalette} from './palettes.mjs?v=0.12.3'; +import {escape as e,money,bytes,date,safeUrl,soldOut,trafficSummary,canPurchase,orderAmount} from './core.mjs?v=0.12.3'; const base = new URL('./native/',import.meta.url).href; let templates = {},sourceStyles={}; -const styleReady=fetch(base+'styles.json?v=0.12.2').then(r=>r.json()).then(v=>sourceStyles=v); -export const nativeReady = Promise.all(['footer','header','index','home','login','register','forget','reset','plans','myplan','wallet','invite','profile','tickets','ticket','servers','notices','knowledge','article','faq','orders','purchase','checkout','planlog','walletlog','afflog'].map(async name=>{const r=await fetch(`${base}${name}.html?v=0.12.2`);if(!r.ok)throw Error('原版模板加载失败');templates[name]=await r.text();})).then(()=>styleReady); +const styleReady=fetch(base+'styles.json?v=0.12.3').then(r=>r.json()).then(v=>sourceStyles=v); +export const nativeReady = Promise.all(['footer','header','index','home','login','register','forget','reset','plans','myplan','wallet','invite','profile','tickets','ticket','servers','notices','knowledge','article','faq','orders','purchase','checkout','planlog','walletlog','afflog'].map(async name=>{const r=await fetch(`${base}${name}.html?v=0.12.3`);if(!r.ok)throw Error('原版模板加载失败');templates[name]=await r.text();})).then(()=>styleReady); let nativeSwiper=null,swiperLibrary=null; export async function paintNativeHome(){if(!document.querySelector('.native-public .swiper-container'))return;if(!window.Swiper){if(!swiperLibrary)swiperLibrary=new Promise((resolve,reject)=>{const s=document.createElement('script');s.src=base+'assets/cool/swiper.min.js';s.onload=resolve;s.onerror=reject;document.head.append(s);});await swiperLibrary;}const el=document.querySelector('.native-public .swiper-container');if(!el)return;if(nativeSwiper){try{nativeSwiper.destroy(true,true);}catch{}}el.querySelectorAll('.swiper-slide').forEach(n=>{n.style.removeProperty('display');n.style.removeProperty('width');});el.querySelector('.swiper-wrapper')?.removeAttribute('style');nativeSwiper=new window.Swiper(el,{direction:'horizontal',loop:true,autoplay:{delay:5000,disableOnInteraction:true},navigation:{nextEl:'.swiper-button-next',prevEl:'.swiper-button-prev'}});} -let currentMode='',styleSequence=0,chartData=null,chartInstance=null,chartLibrary=null; +let currentMode='',currentStyleMode='',styleSequence=0,chartData=null,chartInstance=null,chartLibrary=null; export async function paintNativeChart(){if(!chartData||!document.getElementById('donut-chart')||document.getElementById('donut-chart').hidden)return;if(!window.ApexCharts){if(!chartLibrary)chartLibrary=new Promise((resolve,reject)=>{const s=document.createElement('script');s.src=base+'theme/cool/assets/vendors/js/charts/apexcharts.min.js';s.onload=resolve;s.onerror=reject;document.head.append(s);});await chartLibrary;}const target=document.getElementById('donut-chart');if(!target)return;if(chartInstance){try{chartInstance.destroy();}catch{}}target.innerHTML='';chartInstance=new window.ApexCharts(target,{chart:{height:350,type:'donut'},legend:{show:true,position:'bottom'},labels:['可用','历史使用',chartData.todayKnown?'今日使用':'今日使用(未提供)'],series:chartData.series,colors:['#7D72F1','#FF9F43','#EA5455'],dataLabels:{enabled:true,formatter:val=>parseInt(val)+'%'},plotOptions:{pie:{donut:{labels:{show:true,name:{fontSize:'2rem',fontFamily:'Nunito'},value:{fontSize:'1rem',fontFamily:'Nunito',formatter:val=>parseInt(val)+'%'}}}}}});await chartInstance.render();} export async function prepareNativeMode(mode,page='') { const key=mode==='home'?'home':mode==='auth'?(page||'login'):(page||document.body.dataset.nativePage||'dashboard'); @@ -14,13 +14,24 @@ export async function prepareNativeMode(mode,page='') { const palette=getPalette(),signature=key+':'+palette; if(currentMode===signature)return; const seq=++styleSequence; + const overrides=[['native-dark','theme/cool/assets/css/theme/dark-layout.css'],['native-bridge','bridge.css?v=0.12.3']].map(([id,path])=>{ + let n=document.getElementById(id);if(n)return n; + n=document.createElement('link');n.id=id;n.rel='stylesheet';n.href=base+path;n.media='not all'; + n.ready=new Promise((resolve,reject)=>{n.onload=resolve;n.onerror=()=>{n.remove();reject(Error('原版样式加载失败'));};});document.head.append(n);return n; + }); const paths=(mode==='user'?[...sourceStyles.header,...(sourceStyles[sourcePage]||[])]:sourceStyles[sourcePage]||[]).map(p=>p.replace('theme/style-purple.css','theme/style-'+palette+'.css')); - const existing=new Map([...document.querySelectorAll('[data-fuc-native]')].map(n=>[n.href,n])); - const links=paths.map(path=>{const url=new URL(path,base);url.searchParams.set('theme_v','0.12.2');const href=url.href;if(existing.has(href))return existing.get(href);const n=document.createElement('link');n.rel='stylesheet';n.href=href;n.media='not all';n.dataset.fucNative='true';n.ready=new Promise((resolve,reject)=>{n.onload=resolve;n.onerror=()=>reject(Error('原版样式加载失败'));});document.head.append(n);return n;}); - await Promise.all(links.map(n=>n.ready));if(seq!==styleSequence)return; + const existing=new Map([...document.querySelectorAll('[data-fuc-native]')].filter(n=>n.media==='all').map(n=>[n.href,n])); + // Moving an active link can unload its CSS in Chromium. Keep common user CSS + // in place; mode changes load a fresh ordered set while the old page stays styled. + const reuse=currentStyleMode===mode; + const links=paths.map(path=>{const url=new URL(path,base);url.searchParams.set('theme_v','0.12.3');const href=url.href;if(reuse&&existing.has(href))return existing.get(href);const n=document.createElement('link');n.rel='stylesheet';n.href=href;n.media='not all';n.dataset.fucNative='true';n.ready=new Promise((resolve,reject)=>{n.onload=resolve;n.onerror=()=>{n.remove();reject(Error('原版样式加载失败'));};});document.head.insertBefore(n,document.getElementById('native-dark')||document.getElementById('native-bridge'));return n;}); + await Promise.all([...links,...overrides].map(n=>n.ready));if(seq!==styleSequence)return; + const activating=[...links,...overrides].some(n=>n.media!=='all'); + [...links,...overrides].forEach(n=>{n.media='all';}); + if(activating)await new Promise(resolve=>window.requestAnimationFrame?window.requestAnimationFrame(resolve):setTimeout(resolve,0)); + if(seq!==styleSequence)return; document.querySelectorAll('[data-fuc-native]').forEach(n=>{if(!links.includes(n))n.remove();}); - links.forEach(n=>{n.media='all';document.head.append(n);}); - currentMode=signature; + currentMode=signature;currentStyleMode=mode; } // Original app.js selects one menu/navbar scheme after the template's two classes. function syncNativeMenu(root){ @@ -35,8 +46,8 @@ export function nativeMode(mode, page='') { if(mode!=='home'&&nativeSwiper){try{nativeSwiper.destroy(true,true);}catch{}nativeSwiper=null;} if((mode!=='user'||key!=='dashboard')&&chartInstance){try{chartInstance.destroy();}catch{}chartInstance=null;} if(currentMode!==key+':'+getPalette())void prepareNativeMode(mode,page); - let dark=document.getElementById('native-dark');if(!dark){dark=document.createElement('link');dark.id='native-dark';dark.rel='stylesheet';dark.href=base+'theme/cool/assets/css/theme/dark-layout.css';document.head.append(dark);}dark.disabled=mode!=='user'||document.documentElement.dataset.color!=='dark';document.head.append(dark); - let bridge=document.getElementById('native-bridge');if(!bridge){bridge=document.createElement('link');bridge.id='native-bridge';bridge.rel='stylesheet';bridge.href=base+'bridge.css?v=0.12.2';}document.head.append(bridge); + let dark=document.getElementById('native-dark');if(!dark){dark=document.createElement('link');dark.id='native-dark';dark.rel='stylesheet';dark.href=base+'theme/cool/assets/css/theme/dark-layout.css';document.head.append(dark);}dark.disabled=mode!=='user'||document.documentElement.dataset.color!=='dark'; + let bridge=document.getElementById('native-bridge');if(!bridge){bridge=document.createElement('link');bridge.id='native-bridge';bridge.rel='stylesheet';bridge.href=base+'bridge.css?v=0.12.3';document.head.append(bridge);} document.body.className=mode==='home'?'native-public':mode==='auth'?'vertical-layout vertical-menu-modern 1-column navbar-floating footer-static bg-full-screen-image blank-page':`vertical-layout ${innerWidth>=1200?'vertical-menu-modern menu-expanded':'vertical-overlay-menu'} navbar-floating footer-static ${document.documentElement.dataset.color==='dark'?'dark-layout':''}`; if(mode==='user'&&innerWidth>=1200&&localStorage.getItem('fuc_menuToggle')==='close'){document.body.classList.remove('menu-expanded');document.body.classList.add('menu-collapsed');}document.body.dataset.nativeMode=mode;document.body.dataset.menu=innerWidth>=1200?'vertical-menu-modern':'vertical-overlay-menu';document.body.classList.add(window.Pace?.running?'pace-running':'pace-done');syncNativeMenu(document); } diff --git a/theme/Fuc/assets/payments.mjs b/theme/Fuc/assets/payments.mjs index 17ba03e3..b755b418 100644 --- a/theme/Fuc/assets/payments.mjs +++ b/theme/Fuc/assets/payments.mjs @@ -1,6 +1,6 @@ -import {paymentResult,safeUrl} from './core.mjs?v=0.12.2'; -import QRCode from './vendor/qrcode.mjs?v=0.12.2'; -import {loadScript} from './captcha.mjs?v=0.12.2'; +import {paymentResult,safeUrl} from './core.mjs?v=0.12.3'; +import QRCode from './vendor/qrcode.mjs?v=0.12.3'; +import {loadScript} from './captcha.mjs?v=0.12.3'; export async function mountCard(api,id,container) { const key=await api('user/comm/getStripePublicKey',{id}); if(typeof key!=='string'||!key.startsWith('pk_'))throw Error('银行卡支付未配置有效公钥'); diff --git a/theme/Fuc/assets/subscription.mjs b/theme/Fuc/assets/subscription.mjs index 0b839f9e..39ab12c3 100644 --- a/theme/Fuc/assets/subscription.mjs +++ b/theme/Fuc/assets/subscription.mjs @@ -1,4 +1,4 @@ -import {safeUrl} from './core.mjs?v=0.12.2'; +import {safeUrl} from './core.mjs?v=0.12.3'; // Use XB's public subscription filters; do not invent per-format backend routes. export function subscriptionUrl(raw,client='general') { diff --git a/theme/Fuc/config.json b/theme/Fuc/config.json index 85c2ca3f..f7165fc9 100644 --- a/theme/Fuc/config.json +++ b/theme/Fuc/config.json @@ -1,7 +1,7 @@ { "name": "Fuc", "description": "直接复用新版FUC原始用户模板、样式、图标及素材,接入XB接口;XB管理员后台保持原样。", - "version": "0.12.2", + "version": "0.12.3", "images": "", "configs": [ { diff --git a/theme/Fuc/dashboard.blade.php b/theme/Fuc/dashboard.blade.php index e7192c66..6915d814 100644 --- a/theme/Fuc/dashboard.blade.php +++ b/theme/Fuc/dashboard.blade.php @@ -10,7 +10,7 @@
- +