dsh-jianji 1.0.20 → 1.0.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -4
- package/dist/assets/index-BWhLFINV.css +1 -0
- package/dist/assets/index-DmdVTaGL.js +476 -0
- package/dist/assets/{web-BIeLSzhk.js → web-CxgP9YLV.js} +1 -1
- package/dist/assets/{web-CWQD6I14.js → web-DpkysRre.js} +1 -1
- package/dist/index.html +76 -14
- package/package.json +2 -2
- package/plugin/schema.js +11 -0
- package/plugin/store.js +14 -2
- package/plugin/tools.js +3 -3
- package/dist/assets/index-CEuy4H5z.js +0 -449
- package/dist/assets/index-CQ8SzVCZ.css +0 -1
|
@@ -1,449 +0,0 @@
|
|
|
1
|
-
(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),t.credentials=e.crossOrigin===`use-credentials`?`include`:e.crossOrigin===`anonymous`?`omit`:`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var e;(function(e){e.Unimplemented=`UNIMPLEMENTED`,e.Unavailable=`UNAVAILABLE`})(e||={});var t=class extends Error{constructor(e,t,n){super(e),this.message=e,this.code=t,this.data=n}},n=e=>e?.androidBridge?`android`:e?.webkit?.messageHandlers?.bridge?`ios`:`web`,r=r=>{let i=r.CapacitorCustomPlatform||null,a=r.Capacitor||{},o=a.Plugins=a.Plugins||{},s=()=>i===null?n(r):i.name,c=()=>s()!==`web`,l=e=>!!(f.get(e)?.platforms.has(s())||u(e)),u=e=>a.PluginHeaders?.find(t=>t.name===e),d=e=>r.console.error(e),f=new Map;return a.convertFileSrc||=e=>e,a.getPlatform=s,a.handleError=d,a.isNativePlatform=c,a.isPluginAvailable=l,a.registerPlugin=(n,r={})=>{let c=f.get(n);if(c)return console.warn(`Capacitor plugin "${n}" already registered. Cannot register plugins twice.`),c.proxy;let l=s(),d=u(n),p,ee=async()=>(!p&&l in r?p=p=typeof r[l]==`function`?await r[l]():r[l]:i!==null&&!p&&`web`in r&&(p=p=typeof r.web==`function`?await r.web():r.web),p),te=(r,i)=>{if(d){let e=d?.methods.find(e=>i===e.name);if(e)return e.rtype===`promise`?e=>a.nativePromise(n,i.toString(),e):(e,t)=>a.nativeCallback(n,i.toString(),e,t);if(r)return r[i]?.bind(r)}else if(r)return r[i]?.bind(r);else throw new t(`"${n}" plugin is not implemented on ${l}`,e.Unimplemented)},ne=r=>{let i,a=(...a)=>{let o=ee().then(o=>{let s=te(o,r);if(s){let e=s(...a);return i=e?.remove,e}throw new t(`"${n}.${r}()" is not implemented on ${l}`,e.Unimplemented)});return r===`addListener`&&(o.remove=async()=>i()),o};return a.toString=()=>`${r.toString()}() { [capacitor code] }`,Object.defineProperty(a,"name",{value:r,writable:!1,configurable:!1}),a},m=ne(`addListener`),re=ne(`removeListener`),ie=(e,t)=>{let n=m({eventName:e},t),r=async()=>{let r=await n;re({eventName:e,callbackId:r},t)},i=new Promise(e=>n.then(()=>e({remove:r})));return i.remove=async()=>{console.warn(`Using addListener() without 'await' is deprecated.`),await r()},i},h=new Proxy({},{get(e,t){switch(t){case`$$typeof`:return;case`toJSON`:return()=>({});case`addListener`:return d?ie:m;case`removeListener`:return re;default:return ne(t)}}});return o[n]=h,f.set(n,{name:n,proxy:h,platforms:new Set([...Object.keys(r),...d?[l]:[]])}),h},a.Exception=t,a.DEBUG=!!a.DEBUG,a.isLoggingEnabled=!!a.isLoggingEnabled,a},i=(e=>e.Capacitor=r(e))(typeof globalThis<`u`?globalThis:typeof self<`u`?self:typeof window<`u`?window:typeof global<`u`?global:{}),a=i.registerPlugin,o=class{constructor(){this.listeners={},this.retainedEventArguments={},this.windowListeners={}}addListener(e,t){let n=!1;this.listeners[e]||(this.listeners[e]=[],n=!0),this.listeners[e].push(t);let r=this.windowListeners[e];return r&&!r.registered&&this.addWindowListener(r),n&&this.sendRetainedArgumentsForEvent(e),Promise.resolve({remove:async()=>this.removeListener(e,t)})}async removeAllListeners(){this.listeners={};for(let e in this.windowListeners)this.removeWindowListener(this.windowListeners[e]);this.windowListeners={}}notifyListeners(e,t,n){let r=this.listeners[e];if(r)r.forEach(e=>e(t));else if(n){let n=this.retainedEventArguments[e];n||=[],n.push(t),this.retainedEventArguments[e]=n}}hasListeners(e){return!!this.listeners[e]?.length}registerWindowListener(e,t){this.windowListeners[t]={registered:!1,windowEventName:e,pluginEventName:t,handler:e=>{this.notifyListeners(t,e)}}}unimplemented(t=`not implemented`){return new i.Exception(t,e.Unimplemented)}unavailable(t=`not available`){return new i.Exception(t,e.Unavailable)}async removeListener(e,t){let n=this.listeners[e];if(!n)return;let r=n.indexOf(t);r!==-1&&this.listeners[e].splice(r,1),this.listeners[e].length||this.removeWindowListener(this.windowListeners[e])}addWindowListener(e){window.addEventListener(e.windowEventName,e.handler),e.registered=!0}removeWindowListener(e){e&&(window.removeEventListener(e.windowEventName,e.handler),e.registered=!1)}sendRetainedArgumentsForEvent(e){let t=this.retainedEventArguments[e];t&&(delete this.retainedEventArguments[e],t.forEach(t=>{this.notifyListeners(e,t)}))}},s=e=>encodeURIComponent(e).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape),c=e=>e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent),l=class extends o{async getCookies(){let e=document.cookie,t={};return e.split(`;`).forEach(e=>{if(e.length<=0)return;let[n,r]=e.replace(/=/,`CAP_COOKIE`).split(`CAP_COOKIE`);n=c(n).trim(),r=c(r).trim(),t[n]=r}),t}async setCookie(e){try{let t=s(e.key),n=s(e.value),r=e.expires?`; expires=${e.expires.replace(`expires=`,``)}`:``,i=(e.path||`/`).replace(`path=`,``),a=e.url!=null&&e.url.length>0?`domain=${e.url}`:``;document.cookie=`${t}=${n||``}${r}; path=${i}; ${a};`}catch(e){return Promise.reject(e)}}async deleteCookie(e){try{document.cookie=`${e.key}=; Max-Age=0`}catch(e){return Promise.reject(e)}}async clearCookies(){try{let e=document.cookie.split(`;`)||[];for(let t of e)document.cookie=t.replace(/^ +/,``).replace(/=.*/,`=;expires=${new Date().toUTCString()};path=/`)}catch(e){return Promise.reject(e)}}async clearAllCookies(){try{await this.clearCookies()}catch(e){return Promise.reject(e)}}};a(`CapacitorCookies`,{web:()=>new l});var u=async e=>new Promise((t,n)=>{let r=new FileReader;r.onload=()=>{let e=r.result;t(e.indexOf(`,`)>=0?e.split(`,`)[1]:e)},r.onerror=e=>n(e),r.readAsDataURL(e)}),d=(e={})=>{let t=Object.keys(e);return Object.keys(e).map(e=>e.toLocaleLowerCase()).reduce((n,r,i)=>(n[r]=e[t[i]],n),{})},f=(e,t=!0)=>e?Object.entries(e).reduce((e,n)=>{let[r,i]=n,a,o;return Array.isArray(i)?(o=``,i.forEach(e=>{a=t?encodeURIComponent(e):e,o+=`${r}=${a}&`}),o.slice(0,-1)):(a=t?encodeURIComponent(i):i,o=`${r}=${a}`),`${e}&${o}`},``).substr(1):null,p=(e,t={})=>{let n=Object.assign({method:e.method||`GET`,headers:e.headers},t),r=d(e.headers)[`content-type`]||``;if(typeof e.data==`string`)n.body=e.data;else if(r.includes(`application/x-www-form-urlencoded`)){let t=new URLSearchParams;for(let[n,r]of Object.entries(e.data||{}))t.set(n,r);n.body=t.toString()}else if(r.includes(`multipart/form-data`)||e.data instanceof FormData){let t=new FormData;if(e.data instanceof FormData)e.data.forEach((e,n)=>{t.append(n,e)});else for(let n of Object.keys(e.data))t.append(n,e.data[n]);n.body=t;let r=new Headers(n.headers);r.delete(`content-type`),n.headers=r}else(r.includes(`application/json`)||typeof e.data==`object`)&&(n.body=JSON.stringify(e.data));return n},ee=class extends o{async request(e){let t=p(e,e.webFetchExtra),n=f(e.params,e.shouldEncodeUrlParams),r=n?`${e.url}?${n}`:e.url,i=await fetch(r,t),a=i.headers.get(`content-type`)||``,{responseType:o=`text`}=i.ok?e:{};a.includes(`application/json`)&&(o=`json`);let s,c;switch(o){case`arraybuffer`:case`blob`:c=await i.blob(),s=await u(c);break;case`json`:s=await i.json();break;default:s=await i.text()}let l={};return i.headers.forEach((e,t)=>{l[t]=e}),{data:s,headers:l,status:i.status,url:i.url}}async get(e){return this.request(Object.assign(Object.assign({},e),{method:`GET`}))}async post(e){return this.request(Object.assign(Object.assign({},e),{method:`POST`}))}async put(e){return this.request(Object.assign(Object.assign({},e),{method:`PUT`}))}async patch(e){return this.request(Object.assign(Object.assign({},e),{method:`PATCH`}))}async delete(e){return this.request(Object.assign(Object.assign({},e),{method:`DELETE`}))}},te=a(`CapacitorHttp`,{web:()=>new ee}),ne;(function(e){e.Dark=`DARK`,e.Light=`LIGHT`,e.Default=`DEFAULT`})(ne||={});var m;(function(e){e.StatusBar=`StatusBar`,e.NavigationBar=`NavigationBar`})(m||={});var re=class extends o{async setStyle(){this.unavailable(`not available for web`)}async setAnimation(){this.unavailable(`not available for web`)}async show(){this.unavailable(`not available for web`)}async hide(){this.unavailable(`not available for web`)}},ie=a(`SystemBars`,{web:()=>new re}),h=`modulepreload`,ae=function(e,t){return new URL(e,t).href},oe={},se=function(e){return e.pathname.endsWith(`.css`)},ce=function(e,t,n){if(t in e)return e[t];let r=n();if(!r){e[t]=void 0;return}let i=r.then(()=>{e[t]=void 0},n=>{throw e[t]=void 0,n});return e[t]=i,i},le=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e,i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?new URL(import.meta.resolve(e)):new URL(e,import.meta.url)}r=o(t.map(t=>{t=ae(t,n);let r=s(t),i=se(r);return ce(oe,r.href,()=>{if(e===void 0){e={all:new Set,styles:new Set};let t=document.getElementsByTagName(`link`);for(let n=t.length-1;n>=0;n--){let r=t[n];e.all.add(r.href),r.rel===`stylesheet`&&e.styles.add(r.href)}}if((i?e.styles:e.all).has(r.href))return;let t=document.createElement(`link`);if(t.rel=i?`stylesheet`:h,i||(t.as=`script`),t.crossOrigin=``,t.href=r.href,a&&t.setAttribute(`nonce`,a),document.head.appendChild(t),i)return new Promise((e,n)=>{t.addEventListener(`load`,e),t.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${r}`)))})})}).filter(e=>e!==void 0))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},ue=a(`App`,{web:()=>le(()=>import(`./web-BIeLSzhk.js`).then(e=>new e.AppWeb),[],import.meta.url)}),de;(function(e){e[e.Sunday=1]=`Sunday`,e[e.Monday=2]=`Monday`,e[e.Tuesday=3]=`Tuesday`,e[e.Wednesday=4]=`Wednesday`,e[e.Thursday=5]=`Thursday`,e[e.Friday=6]=`Friday`,e[e.Saturday=7]=`Saturday`})(de||={});var g=a(`LocalNotifications`,{web:()=>le(()=>import(`./web-CWQD6I14.js`).then(e=>new e.LocalNotificationsWeb),[],import.meta.url)}),_=`jianji.notifications.v1`,fe=`jianji.notificationIds.v1`,pe=9,me=i.isNativePlatform()&&i.getPlatform()===`android`,v=!1,he=null,ge=null;function _e(e,t){try{let n=localStorage.getItem(e);return n?JSON.parse(n):t}catch{return t}}function y(e,t){localStorage.setItem(e,JSON.stringify(t))}function ve(e){return String(e.title||``).trim()||String(e.notes||``).split(/\r?\n/).find(Boolean)?.trim()||`待办提醒`}function b(e){let t=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e||``);if(!t)return null;let n=new Date(Number(t[1]),Number(t[2])-1,Number(t[3]),pe,0,0,0);return Number.isNaN(n.getTime())?null:n}function ye(e){let t=2166136261;for(let n=0;n<e.length;n+=1)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return(t>>>0)%2e9+1}function be(){let e=_e(_,{});return{enabled:!!e.enabled,permission:String(e.permission||`unknown`)}}async function xe(){if(!me)return{supported:!1,enabled:!1,permission:`unsupported`};try{let e=await g.checkPermissions();return{supported:!0,...be(),permission:e.display}}catch{return{supported:!0,...be(),permission:`unknown`}}}async function Se(){if(!me)throw Error(`系统通知仅在 Android APK 中可用`);let e=await g.checkPermissions();if((e.display===`prompt`||e.display===`prompt-with-rationale`)&&(e=await g.requestPermissions()),e.display!==`granted`)throw y(_,{enabled:!1,permission:e.display}),Error(`通知权限未开启,请在 Android 系统设置中允许简记发送通知`);return await g.createChannel({id:`due-reminders`,name:`截止日提醒`,description:`待办到达截止日时的提醒`,importance:4,visibility:1,vibration:!0,lights:!0,lightColor:`#315f6b`}),y(_,{enabled:!0,permission:e.display}),e.display}async function Ce(){if(y(_,{enabled:!1,permission:`disabled`}),!me)return;let e=_e(fe,[]);Array.isArray(e)&&e.length&&await S(e),y(fe,[])}async function we(e){clearTimeout(ge),ge=setTimeout(()=>x(e),250)}async function x(e){if(!me)return{scheduled:0,reason:`unsupported`};if(!be().enabled)return{scheduled:0,reason:`disabled`};let t=await g.checkPermissions();if(t.display!==`granted`)return y(_,{enabled:!1,permission:t.display}),{scheduled:0,reason:`permission-denied`};let n=_e(fe,[]);Array.isArray(n)&&n.length&&await S(n);let r=Date.now(),i=e.filter(e=>!e.deletedAt&&e.status!==`done`&&e.dueDate).map(e=>({task:e,at:b(e.dueDate)})).filter(({at:e})=>e&&e.getTime()>r).sort((e,t)=>e.at-t.at).slice(0,100).map(({task:e,at:t})=>({id:ye(e.id),title:ve(e),body:`今天是截止日期,记得完成这项待办。`,schedule:{at:t,allowWhileIdle:!0},channelId:`due-reminders`,isExactNotification:!0,isExactMandatory:!1,smallIcon:`ic_stat_jianji`,iconColor:`#315f6b`,extra:{taskId:e.id}}));return i.length&&await g.schedule({notifications:i}),y(fe,i.map(e=>e.id)),{scheduled:i.length,reason:`ok`}}async function S(e){let t=e.map(Number).filter(Number.isFinite);t.length&&await Promise.all([g.cancel({notifications:t.map(e=>({id:e}))}).catch(()=>{}),g.removeDeliveredNotificationsById({ids:t}).catch(()=>{})])}function Te(e){he=e,me&&!v&&(v=!0,g.addListener(`localNotificationActionPerformed`,e=>{let t=e.notification.extra?.taskId;t&&typeof he==`function`&&he(t)}).catch(()=>{}))}var C=a(`AppUpdater`),w=i.getPlatform()===`android`,Ee=`2022-11-28`;function T(e,t=!1){return e.status===404?t?`未找到 Release,请检查发布状态和令牌权限`:`无法访问更新仓库,请填写 GitHub 只读令牌或确认仓库公开`:e.status===401?`GitHub 令牌无效或已过期`:e.status===403||e.status===429?`GitHub API 请求受限,请稍后重试`:`无法获取最新版本(GitHub ${e.status})`}function E(e){return e?{Authorization:`Bearer ${e}`}:{}}async function De(e,t=``){if(w){let n=await te.request({url:e,method:`GET`,headers:{Accept:`application/vnd.github+json`,"X-GitHub-Api-Version":Ee,"User-Agent":`Jianji-Android-Updater`,...E(t)}});if(n.status<200||n.status>=300)throw Error(T(n,!!t));return typeof n.data==`string`?JSON.parse(n.data):n.data}let n=await fetch(e,{cache:`no-store`,headers:{Accept:`application/vnd.github+json`,"X-GitHub-Api-Version":Ee,...E(t)}});if(!n.ok)throw Error(T(n,!!t));return n.json()}async function Oe(e,t=``){if(w){let n=await te.request({url:e,method:`GET`,headers:{Accept:`application/octet-stream`,"User-Agent":`Jianji-Android-Updater`,...E(t)}});if(n.status<200||n.status>=300)throw Error(T(n,!!t));return typeof n.data==`string`?n.data:String(n.data??``)}let n=await fetch(e,{cache:`no-store`,headers:{Accept:`application/octet-stream`,...E(t)}});if(!n.ok)throw Error(T(n,!!t));return n.text()}function ke(e){let t=String(e||``).trim().replace(/^v/i,``).match(/^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/);return t?{parts:t.slice(1,4).map(Number),prerelease:t[4]?t[4].split(`.`):[]}:null}function Ae(e,t){if(!e.length&&!t.length)return 0;if(!e.length)return 1;if(!t.length)return-1;let n=Math.max(e.length,t.length);for(let r=0;r<n;r+=1){if(e[r]===void 0)return-1;if(t[r]===void 0)return 1;if(e[r]===t[r])continue;let n=/^\d+$/.test(e[r]),i=/^\d+$/.test(t[r]);return n&&i?Number(e[r])-Number(t[r]):n===i?e[r].localeCompare(t[r]):n?-1:1}return 0}function je(e,t){let n=ke(e),r=ke(t);if(!n||!r)return 0;for(let e=0;e<3;e+=1){let t=n.parts[e]-r.parts[e];if(t)return t}return Ae(n.prerelease,r.prerelease)}function Me(e){let t=typeof e.digest==`string`?e.digest.trim().toLowerCase():``;return t.startsWith(`sha256:`)?t.slice(7):``}function Ne(e){return String(e||``).match(/\b[a-f0-9]{64}\b/i)?.[0]?.toLowerCase()||``}async function Pe(e){if(!w)return{versionName:e,versionCode:0,canInstallPackages:!1,nativeInstaller:!1};try{let t=await C.getInfo();return{versionName:String(t.versionName||e),versionCode:Number(t.versionCode||0),canInstallPackages:!!t.canInstallPackages,nativeInstaller:!0}}catch{return{versionName:e,versionCode:0,canInstallPackages:!1,nativeInstaller:!1}}}function Fe(e,t,n){if(!e||e.draft||e.prerelease)return null;let r=String(e.tag_name||``).trim();if(!ke(r))return null;let i=Array.isArray(e.assets)?e.assets:[],a=i.find(e=>e&&e.state===`uploaded`&&String(e.name||``).toLowerCase()===`jianji.apk`)||i.find(e=>e&&e.state===`uploaded`&&String(e.name||``).toLowerCase().endsWith(`.apk`));if(!a)return null;let o=!!n,s=String(a.url||``),c=String(a.browser_download_url||``),l=o?s:c;if(!(o?/^https:\/\/api\.github\.com\/repos\/[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+\/releases\/assets\/\d+$/i.test(l):/^https:\/\/github\.com\//i.test(l)))return null;let u=Me(a),d=i.find(e=>e&&e.state===`uploaded`&&String(e.name||``)===`${a.name}.sha256`),f=o&&d?.url?d.url:d?.browser_download_url||``;return{id:Number(e.id||0),version:r,name:String(e.name||r).slice(0,180),notes:String(e.body||``).trim().slice(0,12e3),publishedAt:e.published_at||``,releaseUrl:e.html_url||`https://github.com/${t}/releases`,assetName:String(a.name||`jianji.apk`),downloadUrl:l,checksumUrl:f,requiresAuth:o,size:Number(a.size||0),sha256:u}}function Ie(e){if(!/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/.test(e))throw Error(`应用更新仓库配置无效`)}async function Le(e,t=``){if(!e||e.sha256||!e.checksumUrl)return e;try{let n=Ne(await Oe(e.checksumUrl,t));return n?{...e,sha256:n}:e}catch{return e}}async function Re(e,t=``){Ie(e);let n=String(t||``).trim(),r=[];for(let t=1;t<=50;t+=1){let i=await De(`https://api.github.com/repos/${e}/releases?per_page=100&page=${t}`,n);if(!Array.isArray(i))throw Error(`GitHub Release 数据格式无效`);if(r.push(...i),i.length<100)break}let i=new Set,a=r.map(t=>Fe(t,e,n)).filter(e=>e&&!i.has(e.version)&&i.add(e.version)).sort((e,t)=>je(t.version,e.version));if(!a.length)throw Error(`尚未找到可安装的 Release 版本`);return a}async function ze(e,t=``){if(!w)throw Error(`当前平台不支持后台下载 Android APK`);let n=await Le(e,t);return C.startDownload({url:n.downloadUrl,expectedSha256:n.sha256||``,accessToken:t||``,versionName:n.version,size:Number(n.size||0)})}async function Be(){return w?C.getDownloadState():null}async function Ve(){if(!w)throw Error(`当前平台不支持应用内安装 Android APK`);return C.installDownloadedUpdate()}async function He(){if(!w)throw Error(`当前平台不支持导出 Android 安装包`);return C.exportDownloadedUpdate()}async function Ue(){if(!w)throw Error(`当前平台不支持打开 Android 卸载页面`);return C.openAppUninstall()}async function We(){return w?C.cancelDownload():null}async function Ge(){return w?(await C.openInstallSettings(),!0):!1}function Ke(){return w}var qe=a(`WidgetBridge`),Je=500,Ye=new Set([`todo`,`doing`,`held`]),D=i.isNativePlatform()&&i.getPlatform()===`android`,Xe=null;function O(e=new Date){return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`}function Ze(e){return String(e||``).split(/\r?\n/).map(e=>e.trim()).find(Boolean)||``}function k(e){let t=String(e.title||``).trim()||Ze(e.notes)||`未命名待办`;return{id:String(e.id||``),title:t.slice(0,180),dueDate:/^\d{4}-\d{2}-\d{2}$/.test(e.dueDate||``)?e.dueDate:``,status:Ye.has(e.status)?e.status:`todo`,pinned:!!e.pinned,order:Number.isFinite(e.order)?e.order:0}}function A(e,t){return e.dueDate&&e.dueDate<t?0:e.dueDate===t?1:e.status===`doing`?2:e.pinned?3:4}function j(e,t,n){let r=A(e,n)-A(t,n);return r||(r<=1&&e.dueDate!==t.dueDate?e.dueDate.localeCompare(t.dueDate):e.pinned===t.pinned?e.order===t.order?e.title.localeCompare(t.title,`zh-CN`):e.order-t.order:e.pinned?-1:1)}function M(e,t=new Date){let n=O(t),r=Array.isArray(e)?e.filter(e=>e&&!e.deletedAt&&String(e.id||``)):[],i=r.filter(e=>e.status!==`done`).map(k).sort((e,t)=>j(e,t,n)),a=i.slice(0,Je);return{version:1,generatedAt:new Date().toISOString(),today:n,complete:a.length===i.length,counts:{open:i.length,overdue:i.filter(e=>e.dueDate&&e.dueDate<n).length,today:i.filter(e=>e.dueDate===n).length,total:r.length},tasks:a}}async function Qe(e){if(!D)return!1;clearTimeout(Xe),Xe=null;let t=JSON.stringify(M(e));return await qe.sync({snapshot:t}),!0}function $e(e,t=120){D&&(clearTimeout(Xe),Xe=setTimeout(()=>{Xe=null,Qe(e).catch(()=>{})},t))}(async()=>{let e=i.isNativePlatform(),t=window.parent!==window&&location.pathname.startsWith(`/jianji/app`),n=new URL(`../api/`,location.href),r=new URL(`events`,n);document.body.classList.toggle(`is-dsh-plugin`,t),e&&ie.setStyle({style:ne.Default}).catch(()=>{});let a=`1.0.20`,o=`LeonidasLux/jianji`,s=`jianji.tasks.v1`,c=`jianji.connection.v1`,l=`jianji.updater.v1`,u=`jianji.updateRelease.v1`,d=`jianji.updateHistory.v1`,f=`jianji.updateDismissed.v1`,p=`jianji.updateExported.v1`,ee=`jianji.ui.v1`,m=7776e6,re=[300,800,1500],h=C(),ae=new Map,oe=!1,se=0,ce=0,le=null,de=!1,g=!1,_=null,fe=``,pe=``,v=null,he=[`records`,`all`,`inspirations`],ge=[`all`,`inbox`,`doing`,`held`,`done`],_e=[`一`,`二`,`三`,`四`,`五`,`六`,`日`],y=[`todo`,`doing`,`held`,`done`],ve=[{view:`all`,label:`全部`,tone:`all`},{view:`inbox`,label:`新建`,tone:`todo`},{view:`doing`,label:`进行中`,tone:`doing`},{view:`held`,label:`搁置`,tone:`held`},{view:`done`,label:`已完成`,tone:`done`}],b={todo:{label:`新建`,icon:`plus`},doing:{label:`进行中`,icon:`play`},held:{label:`搁置`,icon:`pause`},done:{label:`已完成`,icon:`check-circle`}},ye={records:{title:`记录`,copy:`保存完整笔记、文章片段与随笔,不必进入待办流程。`},inspirations:{title:`灵感`,copy:`按主题收拢一闪而过的念头,让同一方向的想法慢慢长成体系。`},inbox:{title:`新建`,copy:`刚记录的事情会先放在这里。`,status:`todo`},all:{title:`全部`,copy:`集中查看全部待办,也可以按状态筛选。`,status:`todo`},doing:{title:`进行中`,copy:`保持工作区干净,只关注正在推进的事。`,status:`doing`},held:{title:`搁置`,copy:`暂时不做,但不要忘记为什么停下来。`,status:`held`},done:{title:`已完成`,copy:`完成过的事,也是一种进度。`,status:`done`}},be={sortSelect:[{value:`manual`,label:`手动`},{value:`due`,label:`截止日期`},{value:`updated`,label:`最近更新`}],createStatusInput:y.map(e=>({value:e,label:b[e].label,status:e}))},x={items:[],records:[],inspirations:[],view:`records`,sort:`manual`,mobileLayout:`list`,mosaicLanes:new Set,search:``,tagFilter:``,commonTags:[],commonTagRecords:[],commonTagsUpdatedAt:``,commonTagsDeviceId:``,selectedId:null,recordEditingId:null,inspirationEditingId:null,draft:null,draftTaskId:null,draftDirty:!1,draftAfter:null,createTags:[],dirty:!1,syncState:`local`,syncMessage:`仅保存在本机`,lastSyncedAt:``,syncing:!1,syncQueued:!1,deferredInstallPrompt:null,undo:null,toastTimer:null,toastExitTimer:null,pointerDragId:null,pointerDropId:null,openMenuId:null,settingsOpen:!1,settingsHistoryPushed:!1,confirmCallback:null,confirmCancelCallback:null,reminderStatus:`unknown`,reminderUpdating:!1,updateInfo:null,latestUpdate:null,updateTarget:null,releaseHistory:[],updateChecking:!1,updateHistoryOpen:!1,updateHistoryLoading:!1,updateRefreshing:!1,updateDownload:null,updatePollTimer:null,updateNoticeVersion:``,readyUpdateNoticeDismissedVersion:``,exportedUpdateVersion:``,statsOpen:!1,statsView:`overview`,statsYear:new Date().getFullYear(),statsSelectedDate:``,statsHistoryPushed:!1},S={appShell:document.getElementById(`appShell`),viewTitle:document.getElementById(`viewTitle`),viewSummary:document.getElementById(`viewSummary`),headerDate:document.getElementById(`headerDate`),listCount:document.getElementById(`listCount`),taskGroups:document.getElementById(`taskGroups`),taskScroll:document.getElementById(`taskScroll`),tagFilterWrap:document.getElementById(`tagFilterWrap`),tagFilter:document.getElementById(`tagFilter`),searchInput:document.getElementById(`searchInput`),searchLabel:document.getElementById(`searchLabel`),searchBox:document.getElementById(`searchBox`),statusFilter:document.getElementById(`statusFilter`),sortSelect:document.getElementById(`sortSelect`),layoutToggle:document.getElementById(`layoutToggle`),desktopCreateButton:document.getElementById(`desktopCreateButton`),desktopSyncDot:document.getElementById(`desktopSyncDot`),desktopSyncLabel:document.getElementById(`desktopSyncLabel`),mobileSyncBadge:document.getElementById(`mobileSyncBadge`),mobileMenuButton:document.getElementById(`mobileMenuButton`),mobileSearchPanel:document.getElementById(`mobileSearchPanel`),mobileSearchInput:document.getElementById(`mobileSearchInput`),mobileSearchLabel:document.getElementById(`mobileSearchLabel`),mobileSearchButton:document.getElementById(`mobileSearchButton`),mobileSearchClose:document.getElementById(`mobileSearchClose`),mobileRecordButton:document.getElementById(`mobileRecordButton`),mobileInspirationButton:document.getElementById(`mobileInspirationButton`),mobileCreateButton:document.getElementById(`mobileCreateButton`),syncButton:document.getElementById(`syncButton`),mobileSyncButton:document.getElementById(`mobileSyncButton`),heatmapButton:document.getElementById(`heatmapButton`),settingsButton:document.getElementById(`settingsButton`),mobileSettingsButton:document.getElementById(`mobileSettingsButton`),mobileInstallButton:document.getElementById(`mobileInstallButton`),inspector:document.getElementById(`inspector`),inspectorContent:document.getElementById(`inspectorContent`),inspectorClose:document.getElementById(`inspectorClose`),settingsPage:document.getElementById(`settingsPage`),settingsPageScroll:document.getElementById(`settingsPageScroll`),settingsForm:document.getElementById(`settingsForm`),repoInput:document.getElementById(`repoInput`),branchInput:document.getElementById(`branchInput`),pathInput:document.getElementById(`pathInput`),tokenInput:document.getElementById(`tokenInput`),autoSyncInput:document.getElementById(`autoSyncInput`),remindersEnabledInput:document.getElementById(`remindersEnabledInput`),notificationStatusHint:document.getElementById(`notificationStatusHint`),settingsError:document.getElementById(`settingsError`),settingsSyncMeta:document.getElementById(`settingsSyncMeta`),closeSettingsButton:document.getElementById(`closeSettingsButton`),cancelSettingsButton:document.getElementById(`cancelSettingsButton`),saveSettingsButton:document.getElementById(`saveSettingsButton`),disconnectButton:document.getElementById(`disconnectButton`),commonTagSettingsList:document.getElementById(`commonTagSettingsList`),commonTagInput:document.getElementById(`commonTagInput`),addCommonTagButton:document.getElementById(`addCommonTagButton`),aboutButton:document.getElementById(`aboutButton`),aboutDialog:document.getElementById(`aboutDialog`),aboutVersionLabel:document.getElementById(`aboutVersionLabel`),aboutUpdateFeedback:document.getElementById(`aboutUpdateFeedback`),closeAboutIconButton:document.getElementById(`closeAboutIconButton`),closeAboutButton:document.getElementById(`closeAboutButton`),appVersionLabel:document.getElementById(`appVersionLabel`),updateStatusHint:document.getElementById(`updateStatusHint`),updateTokenInput:document.getElementById(`updateTokenInput`),checkUpdateButton:document.getElementById(`checkUpdateButton`),updateDownloadRow:document.getElementById(`updateDownloadRow`),updateDownloadLabel:document.getElementById(`updateDownloadLabel`),updateDownloadDetail:document.getElementById(`updateDownloadDetail`),updateProgressTrack:document.getElementById(`updateProgressTrack`),updateProgressBar:document.getElementById(`updateProgressBar`),updateDownloadAction:document.getElementById(`updateDownloadAction`),updateUninstallAction:document.getElementById(`updateUninstallAction`),toggleUpdateHistoryButton:document.getElementById(`toggleUpdateHistoryButton`),updateHistoryHint:document.getElementById(`updateHistoryHint`),updateHistoryPanel:document.getElementById(`updateHistoryPanel`),updateHistoryList:document.getElementById(`updateHistoryList`),updateNotice:document.getElementById(`updateNotice`),updateNoticeTitle:document.getElementById(`updateNoticeTitle`),updateNoticeDetail:document.getElementById(`updateNoticeDetail`),updateNoticeAction:document.getElementById(`updateNoticeAction`),updateNoticeClose:document.getElementById(`updateNoticeClose`),updateNoticeIcon:document.getElementById(`updateNoticeIcon`),updateDialog:document.getElementById(`updateDialog`),updateDialogTitle:document.getElementById(`updateDialogTitle`),updateDialogCopy:document.getElementById(`updateDialogCopy`),updateReleaseVersion:document.getElementById(`updateReleaseVersion`),updateReleaseMeta:document.getElementById(`updateReleaseMeta`),updateReleaseNotes:document.getElementById(`updateReleaseNotes`),updateError:document.getElementById(`updateError`),closeUpdateButton:document.getElementById(`closeUpdateButton`),laterUpdateButton:document.getElementById(`laterUpdateButton`),installUpdateButton:document.getElementById(`installUpdateButton`),confirmDialog:document.getElementById(`confirmDialog`),confirmTitle:document.getElementById(`confirmTitle`),confirmMessage:document.getElementById(`confirmMessage`),confirmCancelButton:document.getElementById(`confirmCancelButton`),confirmAcceptButton:document.getElementById(`confirmAcceptButton`),dispatchDialog:document.getElementById(`dispatchDialog`),dispatchDialogTask:document.getElementById(`dispatchDialogTask`),dispatchPromptInput:document.getElementById(`dispatchPromptInput`),dispatchError:document.getElementById(`dispatchError`),dispatchCloseButton:document.getElementById(`dispatchCloseButton`),dispatchCancelButton:document.getElementById(`dispatchCancelButton`),dispatchConfirmButton:document.getElementById(`dispatchConfirmButton`),savePromptDialog:document.getElementById(`savePromptDialog`),continueEditingButton:document.getElementById(`continueEditingButton`),discardDraftButton:document.getElementById(`discardDraftButton`),saveAndLeaveButton:document.getElementById(`saveAndLeaveButton`),createDialog:document.getElementById(`createDialog`),createTaskForm:document.getElementById(`createTaskForm`),createTitleInput:document.getElementById(`createTitleInput`),createBodyInput:document.getElementById(`createBodyInput`),createStatusInput:document.getElementById(`createStatusInput`),createDueInput:document.getElementById(`createDueInput`),createTagList:document.getElementById(`createTagList`),createTaskError:document.getElementById(`createTaskError`),createCloseButton:document.getElementById(`createCloseButton`),createCancelButton:document.getElementById(`createCancelButton`),createSaveButton:document.getElementById(`createSaveButton`),appPicker:document.getElementById(`appPicker`),appPickerClose:document.getElementById(`appPickerClose`),appPickerTitle:document.getElementById(`appPickerTitle`),appPickerBody:document.getElementById(`appPickerBody`),recordDialog:document.getElementById(`recordDialog`),recordDialogTitle:document.getElementById(`recordDialogTitle`),recordDialogCopy:document.getElementById(`recordDialogCopy`),recordDialogMeta:document.getElementById(`recordDialogMeta`),recordForm:document.getElementById(`recordForm`),recordTitleInput:document.getElementById(`recordTitleInput`),recordBodyInput:document.getElementById(`recordBodyInput`),recordError:document.getElementById(`recordError`),recordCloseButton:document.getElementById(`recordCloseButton`),recordCancelButton:document.getElementById(`recordCancelButton`),recordSaveButton:document.getElementById(`recordSaveButton`),recordDeleteButton:document.getElementById(`recordDeleteButton`),inspirationDialog:document.getElementById(`inspirationDialog`),inspirationDialogTitle:document.getElementById(`inspirationDialogTitle`),inspirationDialogCopy:document.getElementById(`inspirationDialogCopy`),inspirationDialogMeta:document.getElementById(`inspirationDialogMeta`),inspirationForm:document.getElementById(`inspirationForm`),inspirationTopicInput:document.getElementById(`inspirationTopicInput`),inspirationBodyInput:document.getElementById(`inspirationBodyInput`),inspirationError:document.getElementById(`inspirationError`),inspirationCloseButton:document.getElementById(`inspirationCloseButton`),inspirationCancelButton:document.getElementById(`inspirationCancelButton`),inspirationSaveButton:document.getElementById(`inspirationSaveButton`),inspirationDeleteButton:document.getElementById(`inspirationDeleteButton`),recordDrawer:document.getElementById(`recordDrawer`),recordDrawerCloseButton:document.getElementById(`recordDrawerCloseButton`),drawerHeatmapGrid:document.getElementById(`drawerHeatmapGrid`),drawerHeatmapHelpButton:document.getElementById(`drawerHeatmapHelpButton`),drawerStatsButton:document.getElementById(`drawerStatsButton`),drawerRecordCount:document.getElementById(`drawerRecordCount`),drawerRecordDays:document.getElementById(`drawerRecordDays`),drawerRecordTags:document.getElementById(`drawerRecordTags`),heatmapHelpDialog:document.getElementById(`heatmapHelpDialog`),closeHeatmapHelpButton:document.getElementById(`closeHeatmapHelpButton`),heatmapLearnMoreButton:document.getElementById(`heatmapLearnMoreButton`),statsPage:document.getElementById(`statsPage`),statsPageScroll:document.getElementById(`statsPageScroll`),statsPageContent:document.getElementById(`statsPageContent`),statsPageTitle:document.getElementById(`statsPageTitle`),statsPageCopy:document.getElementById(`statsPageCopy`),statsBackButton:document.getElementById(`statsBackButton`),statsCloseButton:document.getElementById(`statsCloseButton`),toast:document.getElementById(`toast`),toastMessage:document.getElementById(`toastMessage`),toastAction:document.getElementById(`toastAction`)};function C(){try{let e=localStorage.getItem(`jianji.device.v1`);if(e)return e;let t=crypto.randomUUID?crypto.randomUUID():`device-${Date.now()}-${Math.random().toString(16).slice(2)}`;return localStorage.setItem(`jianji.device.v1`,t),t}catch{return`device-${Date.now()}-${Math.random().toString(16).slice(2)}`}}function w(e){try{return localStorage.getItem(e)}catch{return ae.get(e)||null}}function Ee(e,t){try{localStorage.setItem(e,t)}catch{ae.set(e,t)}}function T(e,t){try{let n=w(e);return n?JSON.parse(n):t}catch{return t}}function E(e,t){Ee(e,JSON.stringify(t))}function De(e,t={}){return fetch(new URL(e,n),{cache:`no-store`,...t,headers:{Accept:`application/json`,"X-Jianji-Request":`1`,...t.body?{"Content-Type":`application/json`}:{},...t.headers||{}}})}function Oe(e){return{schemaVersion:6,items:Array.isArray(e?.items)?e.items:[],records:Array.isArray(e?.records)?e.records:[],inspirations:Array.isArray(e?.inspirations)?e.inspirations:[],commonTags:M(e?.commonTags,50),commonTagRecords:N(e?.commonTagRecords),commonTagsUpdatedAt:String(e?.commonTagsUpdatedAt||``),commonTagsDeviceId:String(e?.commonTagsDeviceId||``),dirty:!!e?.dirty,lastSyncedAt:String(e?.lastSyncedAt||``)}}function ke(){return Oe({items:x.items,records:x.records,inspirations:x.inspirations,commonTags:x.commonTags,commonTagRecords:x.commonTagRecords,commonTagsUpdatedAt:x.commonTagsUpdatedAt,commonTagsDeviceId:x.commonTagsDeviceId,dirty:x.dirty,lastSyncedAt:x.lastSyncedAt})}function Ae(e){if(!e||typeof e!=`object`)return!1;let t=Oe(e);return E(s,t),x.items=t.items.filter(ot).map(ct),x.records=t.records.filter(lt).map(ut),x.inspirations=t.inspirations.filter(dt).map(mt),x.commonTags=t.commonTags,x.commonTagRecords=t.commonTagRecords,x.commonTagsUpdatedAt=t.commonTagsUpdatedAt,x.commonTagsDeviceId=t.commonTagsDeviceId,x.dirty=t.dirty,x.lastSyncedAt=t.lastSyncedAt,se=Number(e.revision)||se,!0}async function Me(){let e=await De(`state`);if(!e.ok)throw Error(await qe(e,`读取 DSH 数据失败`));let t=await e.json();se=Number(t.revision)||0,se>0&&Ae(t)}async function Ne({force:e=!1}={}){if(!(!t||g||!e&&(de||le))){g=!0;try{let t=await De(`state`);if(!t.ok)throw Error(await qe(t,`读取 DSH 数据失败`));let n=await t.json(),r=Number(n.revision)||0;if(!e&&r===se)return;Ae(n),U()}catch(e){console.warn(`读取 DSH 简记数据失败`,e)}finally{g=!1}}}async function Fe(){if(!t||!oe||!ce||de)return;let e=ce;de=!0;try{let t=await De(`state`,{method:`POST`,body:JSON.stringify(ke())});if(!t.ok)throw Error(await qe(t,`保存 DSH 数据失败`));let n=await t.json();e===ce&&(Ae(n),$n())}catch(e){console.warn(`保存 DSH 简记数据失败`,e),X(`error`,`保存到 DSH 失败,本机数据仍保留`)}finally{de=!1,e!==ce&&Ie()}}function Ie(e=!1){t&&oe&&(ce+=1,clearTimeout(le),e?(le=null,Fe()):le=setTimeout(()=>{le=null,Fe()},120))}function Le(){t&&typeof EventSource==`function`&&(_?.close(),_=new EventSource(r),_.onmessage=e=>{try{let t=JSON.parse(e.data);(Number(t.revision)||0)!==se&&Ne()}catch{}},_.onerror=()=>{Ne()},window.addEventListener(`focus`,()=>{Ne()}),document.addEventListener(`visibilitychange`,()=>{document.hidden||Ne()}))}async function qe(e,t){try{let t=await e.json();if(t&&typeof t.message==`string`&&t.message.trim())return t.message}catch{}return`${t}(${e.status})`}function Je(e){t&&window.parent!==window&&window.parent.postMessage(e,`*`)}function Ye(e){return typeof structuredClone==`function`?structuredClone(e):JSON.parse(JSON.stringify(e))}function D(){return new Date().toISOString()}function Xe(e){return new Promise(t=>setTimeout(t,e))}function O(e=new Date){return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`}function Ze(e){let t=new Date;return t.setHours(12,0,0,0),t.setDate(t.getDate()+e),O(t)}function k(e){if(!e)return null;let[t,n,r]=e.split(`-`).map(Number);return!t||!n||!r?null:new Date(t,n-1,r,12,0,0,0)}function A(e){return String(e||``).trim().replace(/^#+/,``).replace(/\s+/g,` `).slice(0,20)}function j(e){return A(e).toLocaleLowerCase(`zh-CN`)}function M(e,t=8){if(!Array.isArray(e))return[];let n=[],r=new Set;return e.forEach(e=>{let i=A(e),a=j(i);!i||r.has(a)||n.length>=t||(r.add(a),n.push(i))}),n}function et(e){let t=A(e?.value??e?.tag);return t?{value:t,updatedAt:String(e?.updatedAt||``),deletedAt:String(e?.deletedAt||``),deviceId:String(e?.deviceId||``)}:null}function N(e){if(!Array.isArray(e))return[];let t=new Map;e.forEach(e=>{let n=et(e);if(!n)return;let r=j(n.value),i=t.get(r),a=i?Ua(n,i):1;(!i||a>0||a===0&&n.deletedAt&&!i.deletedAt)&&t.set(r,n)});let n=Date.now()-m;return[...t.values()].filter(e=>{if(!e.deletedAt)return!0;let t=new Date(e.deletedAt).getTime();return Number.isFinite(t)&&t>n})}function tt(e,t=``,n=``){return M(e,50).map(e=>({value:e,updatedAt:String(t||``),deletedAt:``,deviceId:String(n||``)}))}function nt(e){return M(N(e).filter(e=>!e.deletedAt).map(e=>e.value),50)}function rt(e){return M(e.flatMap(e=>Array.isArray(e.tags)?e.tags:[]),50)}function it(){return[]}function at(){let e=T(s,null);if(e&&Array.isArray(e.items)){x.items=e.items.filter(ot).map(ct),x.records=Array.isArray(e.records)?e.records.filter(lt).map(ut):[],x.inspirations=Array.isArray(e.inspirations)?e.inspirations.filter(dt).map(mt):[];let t=Object.hasOwn(e,`commonTags`),n=Object.hasOwn(e,`commonTagRecords`);if(x.commonTags=M(e.commonTags,50),x.commonTagRecords=N(e.commonTagRecords),x.commonTagsUpdatedAt=t?String(e.commonTagsUpdatedAt||``):``,x.commonTagsDeviceId=t?String(e.commonTagsDeviceId||``):``,x.dirty=!!e.dirty,x.lastSyncedAt=e.lastSyncedAt||``,!t){let e=rt(x.items.filter(e=>!e.deletedAt));e.length&&(x.commonTags=e,x.commonTagsUpdatedAt=D(),x.commonTagsDeviceId=h,x.dirty=!0)}n?x.commonTags=nt(x.commonTagRecords):x.commonTagRecords=tt(x.commonTags,x.commonTagsUpdatedAt,x.commonTagsDeviceId),t&&n&&Number(e.schemaVersion)===6||Tr(!1)}else x.items=it(),x.records=[],x.inspirations=[],x.commonTags=[],x.commonTagRecords=[],x.commonTagsUpdatedAt=``,x.commonTagsDeviceId=``,x.dirty=!1,Tr(!1);let t=T(ee,{});x.view=ye[t.view]?t.view:`records`,x.sort=[`manual`,`due`,`updated`].includes(t.sort)?t.sort:`manual`,x.mobileLayout=t.mobileLayout===`cards`?`cards`:`list`,x.mosaicLanes=new Set(Array.isArray(t.mosaicLanes)?t.mosaicLanes.filter(e=>y.includes(e)):[]),window.innerWidth<=760&&!he.includes(x.view)&&(x.view=`records`)}function P(){E(ee,{view:x.view,sort:x.sort,mobileLayout:x.mobileLayout,mosaicLanes:[...x.mosaicLanes]})}function ot(e){return e&&typeof e.id==`string`&&typeof e.title==`string`}function st(e){if(!e||typeof e!=`object`)return null;let t=String(e.sessionId||``),n=String(e.workspaceId||``);return!t||!n?null:{sessionId:t,workspaceId:n,prompt:String(e.prompt||``).slice(0,8e3),dispatchedAt:String(e.dispatchedAt||``)}}function ct(e){let t=String(e.id||``).replace(/[^a-zA-Z0-9_-]/g,``).slice(0,120)||`task-${Date.now()}-${Math.random().toString(16).slice(2)}`,n=b[e.status]?e.status:`todo`;return{id:t,title:String(e.title||``).slice(0,180),notes:String(e.notes||``).slice(0,4e3),status:n,completedAt:n===`done`?String(e.completedAt||e.updatedAt||e.createdAt||D()):``,dueDate:/^\d{4}-\d{2}-\d{2}$/.test(e.dueDate||``)?e.dueDate:``,tags:M(e.tags,8),pinned:!!e.pinned,order:Number.isFinite(e.order)?e.order:0,createdAt:e.createdAt||D(),updatedAt:e.updatedAt||D(),deletedAt:e.deletedAt||``,deviceId:e.deviceId||h,dispatch:st(e.dispatch)}}function lt(e){return e&&typeof e.id==`string`&&typeof e.body==`string`}function ut(e){return{id:String(e.id||``).replace(/[^a-zA-Z0-9_-]/g,``).slice(0,120)||`record-${Date.now()}-${Math.random().toString(16).slice(2)}`,title:String(e.title||``).slice(0,180),body:String(e.body||``).slice(0,2e4),createdAt:e.createdAt||D(),updatedAt:e.updatedAt||D(),deletedAt:e.deletedAt||``,deviceId:e.deviceId||h}}function dt(e){return e&&typeof e.id==`string`&&typeof e.topic==`string`&&typeof e.body==`string`}function ft(e){return String(e||``).trim().replace(/\s+/g,` `).slice(0,120)}function pt(e){return ft(e).toLocaleLowerCase(`zh-CN`)}function mt(e){return{id:String(e.id||``).replace(/[^a-zA-Z0-9_-]/g,``).slice(0,120)||`inspiration-${Date.now()}-${Math.random().toString(16).slice(2)}`,topic:ft(e.topic)||`未命名主题`,body:String(e.body||``).slice(0,4e3),createdAt:e.createdAt||D(),updatedAt:e.updatedAt||D(),deletedAt:e.deletedAt||``,deviceId:e.deviceId||h}}function ht(){let e=T(c,{});return{repo:String(e.repo||``),branch:String(e.branch||`master`),path:String(e.path||`todos.json`),token:String(e.token||``),autoSync:e.autoSync!==!1}}let F=ht();function gt(){let e=T(l,{});return{token:String(e.token||``)}}let I=gt();function _t(e){I={token:String(e.token||``).trim()},E(l,I)}function vt(e){F={repo:e.repo||``,branch:e.branch||`master`,path:e.path||`todos.json`,token:e.token||``,autoSync:e.autoSync!==!1},E(c,F)}function L(e){return String(e).replaceAll(`&`,`&`).replaceAll(`<`,`<`).replaceAll(`>`,`>`).replaceAll(`"`,`"`).replaceAll(`'`,`'`)}function R(e){return`<svg class="od-icon" aria-hidden="true"><use href="#icon-${e}"></use></svg>`}function yt(e){let t=e.dataset.pickerType||``;return{type:t,title:e.dataset.pickerTitle||`选择`,options:t===`select`?[...be[e.id]||[]]:[]}}function bt(e){let t=k(e);return t?e===O()?`今天 · ${t.getMonth()+1}月${t.getDate()}日`:e===Ze(1)?`明天 · ${t.getMonth()+1}月${t.getDate()}日`:new Intl.DateTimeFormat(`zh-CN`,{year:`numeric`,month:`long`,day:`numeric`}).format(t):`选择日期`}function xt(e){return e?.dataset.value||``}function St(e,t,{dispatch:n=!1}={}){if(!e)return;let r=String(t||``),i=xt(e)!==r,a=yt(e),o=e.querySelector(`[data-picker-label]`),s=e.querySelector(`.picker-status-marker`),c=r;a.type===`date`?(c=bt(r),e.classList.toggle(`is-placeholder`,!r)):(c=a.options.find(e=>e.value===r)?.label||r,s&&(s.dataset.status=r)),e.dataset.value=r,o&&(o.textContent=c),e.setAttribute(`aria-label`,`${a.title}:${c}`),e.title=a.type===`date`&&r?wt(r):`${a.title}:${c}`,n&&i&&e.dispatchEvent(new Event(`change`,{bubbles:!0}))}function Ct(e){St(e,xt(e))}function wt(e){let t=k(e);return t?new Intl.DateTimeFormat(`zh-CN`,{year:`numeric`,month:`long`,day:`numeric`,weekday:`long`}).format(t):``}function Tt(e){return new Intl.DateTimeFormat(`zh-CN`,{year:`numeric`,month:`long`}).format(e)}function Et(){let{options:e}=v.config,t=xt(v.trigger);S.appPickerBody.innerHTML=`
|
|
2
|
-
<div class="app-picker-options" id="appPickerOptions" role="listbox" aria-label="${L(v.config.title)}">
|
|
3
|
-
${e.map((e,n)=>`
|
|
4
|
-
<button class="app-picker-option" id="appPickerOption-${n}" type="button" role="option" aria-selected="${e.value===t}" data-picker-value="${L(e.value)}">
|
|
5
|
-
<span class="app-picker-option-copy">
|
|
6
|
-
${e.status?`<span class="picker-status-marker" data-status="${e.status}" aria-hidden="true"></span>`:``}
|
|
7
|
-
<span>${L(e.label)}</span>
|
|
8
|
-
</span>
|
|
9
|
-
<span class="app-picker-option-check" aria-hidden="true">${e.value===t?R(`check`):``}</span>
|
|
10
|
-
</button>`).join(``)}
|
|
11
|
-
</div>`,requestAnimationFrame(()=>{(S.appPickerBody.querySelector(`.app-picker-option[aria-selected="true"]`)||S.appPickerBody.querySelector(`.app-picker-option`))?.focus()})}function Dt({focusMonth:e=``}={}){let t=xt(v.trigger),n=v.cursor,r=new Date(n.getFullYear(),n.getMonth(),1,12),i=Qt(r,-((r.getDay()+6)%7)),a=O(),o=Array.from({length:42},(e,n)=>{let o=Qt(i,n),s=O(o);return{key:s,date:o,outside:o.getMonth()!==r.getMonth(),today:s===a,selected:s===t}});S.appPickerBody.innerHTML=`
|
|
12
|
-
<div class="app-picker-calendar">
|
|
13
|
-
<div class="app-picker-month">
|
|
14
|
-
<button class="app-picker-month-nav" type="button" data-picker-month="-1" aria-label="上个月">${R(`chevron-left`)}</button>
|
|
15
|
-
<strong>${Tt(r)}</strong>
|
|
16
|
-
<button class="app-picker-month-nav" type="button" data-picker-month="1" aria-label="下个月">${R(`chevron-right`)}</button>
|
|
17
|
-
</div>
|
|
18
|
-
<div class="app-picker-weekdays" aria-hidden="true">
|
|
19
|
-
${_e.map(e=>`<span>${e}</span>`).join(``)}
|
|
20
|
-
</div>
|
|
21
|
-
<div class="app-picker-days" role="grid" aria-label="${Tt(r)}">
|
|
22
|
-
${o.map(e=>`
|
|
23
|
-
<button class="app-picker-day${e.outside?` is-outside`:``}${e.today?` is-today`:``}${e.selected?` is-selected`:``}" type="button" data-picker-date="${e.key}" aria-label="${wt(e.key)}" aria-pressed="${e.selected}">
|
|
24
|
-
${e.date.getDate()}
|
|
25
|
-
</button>`).join(``)}
|
|
26
|
-
</div>
|
|
27
|
-
<div class="app-picker-quick" aria-label="快捷选择日期">
|
|
28
|
-
<button type="button" data-picker-date="${O()}">今天</button>
|
|
29
|
-
<button type="button" data-picker-date="${Ze(1)}">明天</button>
|
|
30
|
-
<button type="button" data-picker-date="${Ze(7)}">一周后</button>
|
|
31
|
-
<button class="is-clear" type="button" data-picker-clear>清除</button>
|
|
32
|
-
</div>
|
|
33
|
-
</div>`,requestAnimationFrame(()=>{e?S.appPickerBody.querySelector(`[data-picker-month="${e}"]`)?.focus():(S.appPickerBody.querySelector(`.app-picker-day.is-selected`)||S.appPickerBody.querySelector(`.app-picker-day.is-today`)||S.appPickerBody.querySelector(`.app-picker-day`))?.focus()})}function Ot(){v&&(S.appPickerTitle.textContent=v.config.title,S.appPicker.classList.toggle(`is-date`,v.config.type===`date`),S.appPicker.classList.toggle(`is-select`,v.config.type===`select`),v.config.type===`date`?Dt():Et())}function kt(){if(!v||!S.appPicker.open)return;if(window.innerWidth<=760){S.appPicker.classList.add(`is-sheet`),S.appPicker.style.removeProperty(`left`),S.appPicker.style.removeProperty(`top`),S.appPicker.style.removeProperty(`width`);return}S.appPicker.classList.remove(`is-sheet`);let e=v.trigger.getBoundingClientRect(),t=v.config.type===`date`?344:Math.max(240,Math.min(300,e.width));S.appPicker.style.width=`${t}px`,S.appPicker.style.left=`12px`,S.appPicker.style.top=`12px`;let n=S.appPicker.getBoundingClientRect(),r=e.left;r+t>window.innerWidth-12&&(r=e.right-t),r=Math.max(12,Math.min(r,window.innerWidth-t-12));let i=e.bottom+8;i+n.height>window.innerHeight-12&&(i=e.top-n.height-8),i=Math.max(12,Math.min(i,window.innerHeight-n.height-12)),S.appPicker.style.left=`${r}px`,S.appPicker.style.top=`${i}px`}function At(e){if(!e)return;if(S.appPicker.open&&v?.trigger===e){jt();return}let t=yt(e);t.type&&(v={trigger:e,config:t,cursor:k(xt(e))||V()},e.setAttribute(`aria-expanded`,`true`),Ot(),typeof S.appPicker.showModal==`function`?S.appPicker.showModal():S.appPicker.setAttribute(`open`,``),kt())}function jt(){S.appPicker.open?S.appPicker.close():S.appPicker.removeAttribute(`open`)}function Mt(e){if(!v)return;let t=v.trigger;St(t,e,{dispatch:!0}),jt()}function Nt(e){v&&v.config.type===`date`&&(v.cursor=new Date(v.cursor.getFullYear(),v.cursor.getMonth()+e,1,12),Dt({focusMonth:e>0?`1`:`-1`}),kt())}function Pt(){let e=Date.now()-m;return x.items.filter(t=>!t.deletedAt||new Date(t.deletedAt).getTime()>e)}function z(){return Pt().filter(e=>!e.deletedAt)}function Ft(){let e=Date.now()-m;return x.records.filter(t=>!t.deletedAt||new Date(t.deletedAt).getTime()>e)}function It(){return Ft().filter(e=>!e.deletedAt)}function Lt(){let e=Date.now()-m;return x.inspirations.filter(t=>!t.deletedAt||new Date(t.deletedAt).getTime()>e)}function Rt(){return Lt().filter(e=>!e.deletedAt)}function zt(){return z().find(e=>e.id===x.selectedId)||null}function Bt(e){if(!x.search)return!0;let t=x.search.trim().toLocaleLowerCase(`zh-CN`);return!t||[e.title,e.notes,e.tags.join(` `)].some(e=>String(e).toLocaleLowerCase(`zh-CN`).includes(t))}function Vt(e){if(!x.search)return!0;let t=x.search.trim().toLocaleLowerCase(`zh-CN`);return!t||[e.title,e.body].some(e=>String(e).toLocaleLowerCase(`zh-CN`).includes(t))}function Ht(e=!0){return It().filter(t=>!e||Vt(t)).sort((e,t)=>new Date(t.updatedAt)-new Date(e.updatedAt))}function Ut(e){if(!x.search)return!0;let t=x.search.trim().toLocaleLowerCase(`zh-CN`);return!t||[e.topic,e.body].some(e=>String(e).toLocaleLowerCase(`zh-CN`).includes(t))}function Wt(e=!0){return Rt().filter(t=>!e||Ut(t)).sort((e,t)=>new Date(t.updatedAt)-new Date(e.updatedAt))}function Gt(){let e=new Map;return Wt().forEach(t=>{let n=pt(t.topic),r=e.get(n);r||(r={key:n,topic:t.topic,items:[],updatedAt:t.updatedAt},e.set(n,r)),r.items.push(t),new Date(t.updatedAt)>new Date(r.updatedAt)&&(r.updatedAt=t.updatedAt)}),[...e.values()].map(e=>({...e,items:e.items.sort((e,t)=>new Date(t.updatedAt)-new Date(e.updatedAt))})).sort((e,t)=>new Date(t.updatedAt)-new Date(e.updatedAt))}function Kt(e=x.view){return ge.includes(e)}function qt(e){return!x.tagFilter||e.tags.includes(x.tagFilter)}function Jt(e){let t=j(e);return!!t&&x.commonTags.some(e=>j(e)===t)}function B(e=x.view,t=!0,n=!0){return z().filter(t=>e===`all`?!0:e===`inbox`?t.status===`todo`:t.status===e).filter(e=>!t||Bt(e)).filter(e=>!n||qt(e))}function Yt(e){let t=[...e];return x.sort===`due`?t.sort((e,t)=>e.pinned===t.pinned?!e.dueDate&&t.dueDate?1:e.dueDate&&!t.dueDate?-1:e.dueDate.localeCompare(t.dueDate)||e.order-t.order:e.pinned?-1:1):x.sort===`updated`?t.sort((e,t)=>e.pinned===t.pinned?new Date(t.updatedAt)-new Date(e.updatedAt):e.pinned?-1:1):t.sort((e,t)=>e.pinned===t.pinned?e.order-t.order||new Date(e.createdAt)-new Date(t.createdAt):e.pinned?-1:1)}function Xt(){let e=B();if(x.view===`all`)return y.map(t=>({status:t,items:Yt(e.filter(e=>e.status===t))})).filter(e=>e.items.length);let t=x.view===`inbox`?`todo`:x.view;return e.length?[{status:t,items:Yt(e)}]:[]}function Zt(){let e=new Intl.DateTimeFormat(`zh-CN`,{month:`long`,day:`numeric`,weekday:`long`}).format(new Date);S.headerDate.textContent=e}function V(e=new Date){let t=(e instanceof Date,new Date(e));return Number.isNaN(t.getTime())?null:(t.setHours(12,0,0,0),t)}function Qt(e,t){let n=V(e);return n.setDate(n.getDate()+t),n}function $t(e=new Date){let t=V(e),n=(t.getDay()+6)%7;return t.setDate(t.getDate()-n),t}function en(e,t){let n=V(e),r=V(t);return Math.round((r-n)/864e5)}function tn(){return[...It().map(e=>({kind:`record`,id:e.id,createdAt:e.createdAt,item:e})),...Rt().map(e=>({kind:`inspiration`,id:e.id,createdAt:e.createdAt,item:e})),...z().map(e=>({kind:`task`,id:e.id,createdAt:e.createdAt,item:e}))].filter(e=>V(e.createdAt)).sort((e,t)=>new Date(t.createdAt)-new Date(e.createdAt))}function nn(e=tn()){let t=new Map;return e.forEach(e=>{let n=V(e.createdAt);if(!n)return;let r=O(n);t.has(r)||t.set(r,[]),t.get(r).push(e)}),t}function rn(e){return e?Math.min(4,e):0}function an(e){return[...String(e||``).matchAll(/#([\p{L}\p{N}_-]{1,20})/gu)].map(e=>e[1])}function on(e){if(e.kind===`task`){let t=Array.isArray(e.item.tags)?e.item.tags:[];return[...new Set([...t,...an(`${e.item.title||``} ${e.item.notes||``}`)])]}return[...new Set(an(e.kind===`inspiration`?`${e.item.topic||``} ${e.item.body||``}`:e.item.body))]}function sn(e){return e.kind===`task`?`${e.item.title||``}${e.item.notes||``}`.replace(/\s/g,``).length:e.kind===`inspiration`?`${e.item.topic||``}${e.item.body||``}`.replace(/\s/g,``).length:String(e.item.body||``).replace(/\s/g,``).length}function cn(e=tn()){let t=nn(e),n=new Set;e.forEach(e=>{on(e).forEach(e=>n.add(e))});let r=e.map(e=>V(e.createdAt)).filter(Boolean).sort((e,t)=>e-t),i=r.length?en(r[0],V()):0;return{contentCount:e.length,spanDays:Math.max(0,i),tagCount:n.size,grouped:t}}function ln(e,t=new Date){let n=V(t),r=O(n),i=Qt($t(n),-(e-1)*7);return Array.from({length:e},(e,t)=>Array.from({length:7},(e,n)=>{let a=Qt(i,t*7+n);return{date:a,key:O(a),isFuture:O(a)>r}}))}function un(e){let t=k(e);return t?`${t.getFullYear()}/${String(t.getMonth()+1).padStart(2,`0`)}/${String(t.getDate()).padStart(2,`0`)}`:``}function dn(e){let t=k(e);return t?new Intl.DateTimeFormat(`zh-CN`,{year:`numeric`,month:`long`,day:`numeric`}).format(t):``}function fn(e,t=nn(),n=``){let r=e.map(e=>{let t=e.find(e=>e.date.getDate()===1);return t?`${t.date.getMonth()+1}月`:``});return`
|
|
34
|
-
<div class="heatmap-grid-layout">
|
|
35
|
-
<div class="heatmap-weeks">
|
|
36
|
-
${e.map(e=>`
|
|
37
|
-
<div class="heatmap-week">
|
|
38
|
-
${e.map(e=>{let r=(t.get(e.key)||[]).length,i=rn(r),a=r?`${r} 项内容`:`没有内容`;return`
|
|
39
|
-
<button
|
|
40
|
-
class="heatmap-cell level-${i}${e.isFuture?` is-future`:``}${e.key===O()?` is-today`:``}${e.key===n?` is-selected`:``}"
|
|
41
|
-
type="button"
|
|
42
|
-
data-heatmap-date="${e.key}"
|
|
43
|
-
aria-label="${dn(e.key)},${a}"
|
|
44
|
-
${e.key===n?`aria-current="date"`:``}
|
|
45
|
-
${e.isFuture?`disabled`:``}
|
|
46
|
-
></button>`}).join(``)}
|
|
47
|
-
</div>`).join(``)}
|
|
48
|
-
</div>
|
|
49
|
-
<div class="heatmap-weekdays" aria-hidden="true">
|
|
50
|
-
${_e.map(e=>`<span>${e}</span>`).join(``)}
|
|
51
|
-
</div>
|
|
52
|
-
</div>
|
|
53
|
-
<div class="heatmap-months-layout" aria-hidden="true">
|
|
54
|
-
<div class="heatmap-months">
|
|
55
|
-
${r.map(e=>`<span>${e}</span>`).join(``)}
|
|
56
|
-
</div>
|
|
57
|
-
<span class="heatmap-months-spacer"></span>
|
|
58
|
-
</div>
|
|
59
|
-
<div class="heatmap-tooltip" role="status" hidden></div>
|
|
60
|
-
`}function pn(){let e=cn();S.drawerRecordCount.textContent=String(e.contentCount),S.drawerRecordDays.textContent=String(e.spanDays),S.drawerRecordTags.textContent=String(e.tagCount),S.drawerHeatmapGrid.innerHTML=fn(ln(17),e.grouped)}function mn(){document.querySelectorAll(`.heatmap-tooltip`).forEach(e=>{e.hidden=!0}),document.querySelectorAll(`.heatmap-cell[aria-expanded='true']`).forEach(e=>{e.removeAttribute(`aria-expanded`)})}function hn(e){let t=e.closest(`.heatmap-grid-shell`),n=t?.querySelector(`.heatmap-tooltip`),r=e.dataset.heatmapDate;if(!t||!n||!r)return;mn();let i=nn().get(r)||[];n.innerHTML=`
|
|
61
|
-
<strong>${i.length?`${i.length} 项内容`:`没有内容`}</strong>
|
|
62
|
-
<span>${un(r)}</span>
|
|
63
|
-
`,n.hidden=!1,e.setAttribute(`aria-expanded`,`true`);let a=t.getBoundingClientRect(),o=e.getBoundingClientRect(),s=o.left-a.left+o.width/2,c=Math.max(82,t.clientWidth-82),l=Math.min(c,Math.max(82,s)),u=o.bottom-a.top+8,d=o.top-a.top-n.offsetHeight-8,f=u+n.offsetHeight<=t.clientHeight?u:Math.max(0,d);n.style.left=`${l}px`,n.style.top=`${f}px`}function gn(e){let t=[...e.keys()].sort();if(!t.length)return 0;let n=1,r=1;for(let e=1;e<t.length;e+=1)r=en(k(t[e-1]),k(t[e]))===1?r+1:1,n=Math.max(n,r);return n}function _n(e){let t=tn().filter(t=>{let n=V(t.createdAt);return n&&n.getFullYear()===e}),n=nn(t);return{entries:t,grouped:n,activeDays:n.size,characterCount:t.reduce((e,t)=>e+sn(t),0),longestStreak:gn(n)}}function vn(){return`
|
|
64
|
-
<div class="heatmap-legend" aria-label="颜色越深,当天创建的内容越多">
|
|
65
|
-
<span>少</span>
|
|
66
|
-
<span class="heatmap-legend-cell level-0" aria-hidden="true"></span>
|
|
67
|
-
<span class="heatmap-legend-cell level-1" aria-hidden="true"></span>
|
|
68
|
-
<span class="heatmap-legend-cell level-2" aria-hidden="true"></span>
|
|
69
|
-
<span class="heatmap-legend-cell level-3" aria-hidden="true"></span>
|
|
70
|
-
<span class="heatmap-legend-cell level-4" aria-hidden="true"></span>
|
|
71
|
-
<span>多</span>
|
|
72
|
-
</div>`}function yn(e){return e.kind===`task`?tr(e.item):e.kind===`inspiration`?String(e.item.topic||``).trim()||`未命名主题`:String(e.item.title||``).trim()||String(e.item.body||``).split(/\r?\n/).map(e=>e.trim()).find(Boolean)||`未命名记录`}function bn(e){if(e.kind===`task`){let t=String(e.item.title||``).trim(),n=String(e.item.notes||``).trim();return n?t?n:n.split(/\r?\n/).slice(1).join(` `):``}if(e.kind===`inspiration`)return String(e.item.body||``).trim();let t=String(e.item.title||``).trim(),n=String(e.item.body||``).trim();return t?n:n.split(/\r?\n/).slice(1).join(` `)}function xn(e){let t=new Date(e);return Number.isNaN(t.getTime())?``:`${String(t.getHours()).padStart(2,`0`)}:${String(t.getMinutes()).padStart(2,`0`)}`}function Sn(e){let t=k(e);if(!t)return``;let n={month:`long`,day:`numeric`,weekday:`long`};return t.getFullYear()!==new Date().getFullYear()&&(n.year=`numeric`),new Intl.DateTimeFormat(`zh-CN`,n).format(t)}function Cn(e){let t=yn(e),n=bn(e),r=on(e),i=e.kind===`task`,a=e.kind===`inspiration`,o=[i?er(e.item.status):``,...r.slice(0,6).map(e=>`<span class="stats-content-tag">#${L(e)}</span>`)].filter(Boolean).join(``);return`
|
|
73
|
-
<li>
|
|
74
|
-
<article class="stats-day-item" data-content-kind="${e.kind}">
|
|
75
|
-
<div class="stats-day-item-head">
|
|
76
|
-
<span class="stats-day-item-type">
|
|
77
|
-
${R(i?`check-circle`:a?`sparkles`:`note`)}
|
|
78
|
-
${i?`待办`:a?`灵感`:`记录`}
|
|
79
|
-
</span>
|
|
80
|
-
<time datetime="${L(e.createdAt)}">${xn(e.createdAt)}</time>
|
|
81
|
-
</div>
|
|
82
|
-
<h4 class="stats-day-item-title">${L(t)}</h4>
|
|
83
|
-
${n?`<p class="stats-day-item-preview">${L(n)}</p>`:``}
|
|
84
|
-
${o?`<div class="stats-day-item-meta">${o}</div>`:``}
|
|
85
|
-
</article>
|
|
86
|
-
</li>`}function wn(){let e=document.getElementById(`statsDayContent`);if(!e)return;let t=x.statsSelectedDate&&nn().get(x.statsSelectedDate)||[];e.innerHTML=t.length?`
|
|
87
|
-
<section class="stats-day-content-card" aria-labelledby="statsDayContentTitle">
|
|
88
|
-
<header class="stats-day-content-head">
|
|
89
|
-
<div>
|
|
90
|
-
<p>当天内容</p>
|
|
91
|
-
<h3 id="statsDayContentTitle">${Sn(x.statsSelectedDate)}</h3>
|
|
92
|
-
</div>
|
|
93
|
-
<span>${t.length} 项</span>
|
|
94
|
-
</header>
|
|
95
|
-
<ul class="stats-day-list">
|
|
96
|
-
${t.map(Cn).join(``)}
|
|
97
|
-
</ul>
|
|
98
|
-
</section>`:``}function Tn(e){let t=e.dataset.heatmapDate;if(!t)return;let n=nn().get(t)||[];document.querySelectorAll(`#statsPage .heatmap-cell.is-selected`).forEach(e=>{e.classList.remove(`is-selected`),e.removeAttribute(`aria-current`)}),n.length?(x.statsSelectedDate=t,e.classList.add(`is-selected`),e.setAttribute(`aria-current`,`date`),mn(),wn(),requestAnimationFrame(()=>{document.getElementById(`statsDayContent`)?.scrollIntoView({block:`nearest`,behavior:`smooth`})})):(x.statsSelectedDate=``,wn(),hn(e))}function En(){let e=V(),t=O(e),n=$t(e),r=t.slice(0,7),i=`${e.getFullYear()}-01-01`,a=tn(),o=nn(a),s=[...o.keys()],c=s.filter(e=>e>=O(n)&&e<=t).length,l=s.filter(e=>e.startsWith(r)).length,u=a.filter(e=>{let n=V(e.createdAt);return n&&O(n)>=i&&O(n)<=t}).length,d=Math.max(1,en(k(i),e)+1),f=u?(u/d).toFixed(1):`0.0`,p=ln(53,e);S.statsPageTitle.textContent=`记录热力图`,S.statsPageCopy.textContent=`回顾记录、灵感与待办的创建趋势。`,S.statsPageContent.innerHTML=`
|
|
99
|
-
<section class="stats-card stats-overview-card" aria-labelledby="overviewHeatmapTitle">
|
|
100
|
-
<header class="stats-card-head">
|
|
101
|
-
<h3 class="stats-card-title" id="overviewHeatmapTitle">记录热力图</h3>
|
|
102
|
-
<span class="stats-range-label">近 1 年</span>
|
|
103
|
-
</header>
|
|
104
|
-
<div class="stats-overview-chart">
|
|
105
|
-
<div class="heatmap-grid-shell">
|
|
106
|
-
${fn(p,o,x.statsSelectedDate)}
|
|
107
|
-
</div>
|
|
108
|
-
</div>
|
|
109
|
-
<div class="stats-heatmap-footer">
|
|
110
|
-
<span>横向滑动查看</span>
|
|
111
|
-
${vn()}
|
|
112
|
-
</div>
|
|
113
|
-
<div class="stats-kpi-grid" aria-label="内容统计">
|
|
114
|
-
<div class="stats-kpi">
|
|
115
|
-
<strong>${gn(o)}<small>天</small></strong>
|
|
116
|
-
<span>连续创建</span>
|
|
117
|
-
</div>
|
|
118
|
-
<div class="stats-kpi">
|
|
119
|
-
<strong>${c}<small>天</small></strong>
|
|
120
|
-
<span>本周活跃</span>
|
|
121
|
-
</div>
|
|
122
|
-
<div class="stats-kpi">
|
|
123
|
-
<strong>${l}<small>天</small></strong>
|
|
124
|
-
<span>本月活跃</span>
|
|
125
|
-
</div>
|
|
126
|
-
<div class="stats-kpi">
|
|
127
|
-
<strong>${f}</strong>
|
|
128
|
-
<span>日均创建</span>
|
|
129
|
-
</div>
|
|
130
|
-
</div>
|
|
131
|
-
<button class="stats-all-records-button" type="button" data-stats-action="all-records">
|
|
132
|
-
查看全年热力图
|
|
133
|
-
<svg class="od-icon" aria-hidden="true"><use href="#icon-chevron-right"></use></svg>
|
|
134
|
-
</button>
|
|
135
|
-
</section>
|
|
136
|
-
<div class="stats-day-content" id="statsDayContent" aria-live="polite"></div>
|
|
137
|
-
`,wn()}function Dn(e,t,n){let r=new Date(e,t,1,12),i=new Date(e,t+1,0,12),a=$t(r),o=Qt($t(i),6),s=[];for(let e=a;e<=o;e=Qt(e,1)){if(e.getMonth()!==t){s.push(`<span class="annual-month-cell is-blank" aria-hidden="true"></span>`);continue}let r=O(e),i=(n.get(r)||[]).length;s.push(`<span class="annual-month-cell level-${rn(i)}" aria-hidden="true"></span>`)}return`<div class="annual-month-heatmap">${s.join(``)}</div>`}function On(){let e=new Date().getFullYear(),t=tn().map(e=>V(e.createdAt)).filter(Boolean).map(e=>e.getFullYear()),n=t.length?Math.min(...t):e,r=Math.min(n,e),i=e;x.statsYear=Math.min(i,Math.max(r,x.statsYear));let a=_n(x.statsYear);S.statsPageTitle.textContent=`记录热力图`,S.statsPageCopy.textContent=`按月回顾记录、灵感与待办的创建轨迹。`,S.statsPageContent.innerHTML=`
|
|
138
|
-
<section class="annual-stats-card" aria-label="${x.statsYear} 年记录概览">
|
|
139
|
-
<div class="annual-year-switch">
|
|
140
|
-
<button type="button" data-stats-year-step="-1" aria-label="查看上一年" ${x.statsYear<=r?`disabled`:``}>
|
|
141
|
-
<svg class="od-icon" aria-hidden="true"><use href="#icon-chevron-left"></use></svg>
|
|
142
|
-
</button>
|
|
143
|
-
<strong>${x.statsYear}</strong>
|
|
144
|
-
<button type="button" data-stats-year-step="1" aria-label="查看下一年" ${x.statsYear>=i?`disabled`:``}>
|
|
145
|
-
<svg class="od-icon" aria-hidden="true"><use href="#icon-chevron-right"></use></svg>
|
|
146
|
-
</button>
|
|
147
|
-
</div>
|
|
148
|
-
<div class="annual-kpi-grid">
|
|
149
|
-
<div class="annual-kpi"><strong>${a.entries.length}</strong><span>内容</span></div>
|
|
150
|
-
<div class="annual-kpi"><strong>${a.activeDays}</strong><span>活跃天</span></div>
|
|
151
|
-
<div class="annual-kpi"><strong>${a.characterCount.toLocaleString(`zh-CN`)}</strong><span>总字数</span></div>
|
|
152
|
-
<div class="annual-kpi"><strong>${a.longestStreak}天</strong><span>最长连续</span></div>
|
|
153
|
-
</div>
|
|
154
|
-
</section>
|
|
155
|
-
<div class="annual-month-grid">
|
|
156
|
-
${Array.from({length:12},(e,t)=>`
|
|
157
|
-
<section class="annual-month-card" aria-label="${t+1}月">
|
|
158
|
-
<h3>${t+1}月</h3>
|
|
159
|
-
${Dn(x.statsYear,t,a.grouped)}
|
|
160
|
-
</section>`).join(``)}
|
|
161
|
-
</div>
|
|
162
|
-
`}function kn({resetScroll:e=!1}={}){x.statsOpen&&(x.statsView===`year`?On():En(),x.statsView!==`year`&&requestAnimationFrame(()=>{let e=S.statsPageContent.querySelector(`.stats-overview-chart`);e&&(e.scrollLeft=e.scrollWidth)}),e&&(S.statsPageScroll.scrollTop=0))}function An(e){x.statsOpen=e,e?(S.statsPage.open||(typeof S.statsPage.showModal==`function`?S.statsPage.showModal():S.statsPage.setAttribute(`open`,``)),oa(),kn({resetScroll:!0}),S.statsPageScroll.scrollTop=0,requestAnimationFrame(()=>S.statsBackButton.focus())):(S.statsPage.open?S.statsPage.close():S.statsPage.removeAttribute(`open`),mn(),Y())}function jn(e=`overview`){Ln(),Fn(!1),x.statsView=e===`year`?`year`:`overview`,x.statsYear=new Date().getFullYear(),x.statsSelectedDate=``,An(!0),location.hash!==`#statistics`&&(history.pushState({jianjiPage:`statistics`},``,`#statistics`),x.statsHistoryPushed=!0)}function Mn(){x.statsOpen&&(An(!1),location.hash===`#statistics`&&(x.statsHistoryPushed?(x.statsHistoryPushed=!1,history.back()):history.replaceState(history.state,``,`${location.pathname}${location.search}`)))}function Nn(){x.statsView===`year`?(x.statsView=`overview`,kn({resetScroll:!0}),S.statsBackButton.focus()):Mn()}function Pn(){pn(),S.recordDrawer.open||(typeof S.recordDrawer.showModal==`function`?S.recordDrawer.showModal():S.recordDrawer.setAttribute(`open`,``)),requestAnimationFrame(()=>S.recordDrawerCloseButton.focus())}function Fn(e=!0){mn(),S.recordDrawer.open?S.recordDrawer.close():S.recordDrawer.removeAttribute(`open`),e&&requestAnimationFrame(()=>S.mobileMenuButton.focus())}function In(){S.heatmapHelpDialog.open||(typeof S.heatmapHelpDialog.showModal==`function`?S.heatmapHelpDialog.showModal():S.heatmapHelpDialog.setAttribute(`open`,``),requestAnimationFrame(()=>S.closeHeatmapHelpButton.focus()))}function Ln(){S.heatmapHelpDialog.open?S.heatmapHelpDialog.close():S.heatmapHelpDialog.removeAttribute(`open`)}function Rn(e){let t=k(e);return t?e===O()?`今天`:e===Ze(1)?`明天`:e===Ze(-1)?`昨天`:new Intl.DateTimeFormat(`zh-CN`,{month:`numeric`,day:`numeric`}).format(t):``}function zn(e){return!!(e.dueDate&&e.status!==`done`&&e.dueDate<O())}function Bn(){return{records:Ht(!1).length,inspirations:Wt(!1).length,inbox:B(`inbox`,!1,!1).length,all:B(`all`,!1,!1).length,doing:B(`doing`,!1,!1).length,held:B(`held`,!1,!1).length,done:B(`done`,!1,!1).length}}function Vn(){let e=Bn();document.querySelectorAll(`[data-count]`).forEach(t=>{t.textContent=String(e[t.dataset.count]||0)})}function Hn(){if(S.statusFilter.hidden=!Kt()||window.innerWidth<=760,S.statusFilter.hidden)return;let e=Bn();S.statusFilter.innerHTML=ve.map(t=>`
|
|
163
|
-
<button
|
|
164
|
-
class="status-filter-item"
|
|
165
|
-
type="button"
|
|
166
|
-
data-filter-view="${t.view}"
|
|
167
|
-
data-tone="${t.tone}"
|
|
168
|
-
aria-pressed="${x.view===t.view}"
|
|
169
|
-
>
|
|
170
|
-
<span class="status-filter-dot" aria-hidden="true"></span>
|
|
171
|
-
<span>${t.label}</span>
|
|
172
|
-
<span class="status-filter-count">${e[t.view]}</span>
|
|
173
|
-
</button>
|
|
174
|
-
`).join(``)}function Un(){Kt()?x.tagFilter&&(B(x.view,!1,!1).some(e=>e.tags.includes(x.tagFilter))||(x.tagFilter=``)):x.tagFilter=``}function Wn(){if(!Kt()){S.tagFilterWrap.hidden=!0,S.tagFilter.innerHTML=``;return}let e=B(x.view,!1,!1),t=new Map;e.forEach(e=>{e.tags.forEach(e=>t.set(e,(t.get(e)||0)+1))});let n=[...t.entries()].sort((e,t)=>t[1]-e[1]||e[0].localeCompare(t[0],`zh-CN`));S.tagFilterWrap.hidden=n.length===0,n.length?S.tagFilter.innerHTML=`
|
|
175
|
-
<button class="tag-filter-item" type="button" data-tag-filter="" aria-pressed="${!x.tagFilter}">
|
|
176
|
-
<span>全部</span>
|
|
177
|
-
</button>
|
|
178
|
-
${n.map(([e])=>`
|
|
179
|
-
<button class="tag-filter-item" type="button" data-tag-filter="${L(e)}" aria-pressed="${x.tagFilter===e}">
|
|
180
|
-
<span>#${L(e)}</span>
|
|
181
|
-
</button>`).join(``)}
|
|
182
|
-
`:S.tagFilter.innerHTML=``}function Gn(e){let t=e&&e!==x.tagFilter?e:``;t!==x.tagFilter&&(x.tagFilter=t,x.openMenuId=null,H(),S.taskScroll.scrollTop=0)}function Kn(){if(!S.commonTagSettingsList)return;x.commonTags.length?S.commonTagSettingsList.innerHTML=`
|
|
183
|
-
<ul class="settings-tag-cloud">
|
|
184
|
-
${x.commonTags.map(e=>`
|
|
185
|
-
<li class="settings-tag-chip">
|
|
186
|
-
<span class="settings-tag-name">#${L(e)}</span>
|
|
187
|
-
<button class="settings-tag-remove" type="button" data-remove-common-tag="${L(e)}" aria-label="从常用标签中移除 ${L(e)}">
|
|
188
|
-
${R(`close`)}
|
|
189
|
-
</button>
|
|
190
|
-
</li>`).join(``)}
|
|
191
|
-
</ul>`:S.commonTagSettingsList.innerHTML=`
|
|
192
|
-
<div class="settings-tag-empty">
|
|
193
|
-
${R(`tag`)}
|
|
194
|
-
<span>还没有常用标签</span>
|
|
195
|
-
</div>`;let e=x.commonTags.length>=50;S.commonTagInput.disabled=e,S.addCommonTagButton.disabled=e,S.commonTagInput.placeholder=e?`最多保存 50 个常用标签`:`输入标签名称`}function qn(e,t){let n=D(),r=N(x.commonTagRecords),i=new Map(r.map(e=>[j(e.value),e]));!i.size&&e.length&&tt(e,x.commonTagsUpdatedAt,x.commonTagsDeviceId).forEach(e=>i.set(j(e.value),e));let a=new Set(t.map(j));return e.forEach(e=>{let t=j(e);if(a.has(t))return;let r=i.get(t);i.set(t,{value:r?.value||e,updatedAt:n,deletedAt:n,deviceId:h})}),t.forEach(e=>{let t=j(e),r=i.get(t);r?(r.deletedAt||r.value!==e)&&i.set(t,{value:e,updatedAt:n,deletedAt:``,deviceId:h}):i.set(t,{value:e,updatedAt:n,deletedAt:``,deviceId:h})}),N([...i.values()])}function Jn(e,t={}){let n=M(x.commonTags,50),r=M(e,50);return JSON.stringify(r)!==JSON.stringify(x.commonTags)&&(x.commonTagRecords=qn(n,r),x.commonTags=r,x.commonTagsUpdatedAt=D(),x.commonTagsDeviceId=h,Tr(!0),Kn(),S.createDialog.open&&ri(),S.inspector.open&&zt()&&br(),$a(),t.message&&Z(t.message,t.undo||null),!0)}function Yn(e,t={}){let n=[];return e.forEach(e=>{let t=A(e);t&&!Jt(t)&&!n.some(e=>j(e)===j(t))&&n.push(t)}),n.length?x.commonTags.length+n.length>50?(Z(`最多保存 50 个常用标签`,null),!1):Jn([...x.commonTags,...n],t):!1}function Xn(e){let t=j(e),n=x.commonTags.find(e=>j(e)===t);if(!n)return;let r=[...x.commonTags];Jn(x.commonTags.filter(e=>j(e)!==t),{message:`已从常用标签移除 #${n}`,undo:()=>{Jn(r),$a()}})}function Zn(){let e=A(S.commonTagInput.value);e?Jt(e)?(Z(`#${e} 已在常用标签中`,null),S.commonTagInput.select()):(Yn([e])&&(S.commonTagInput.value=``,Z(`已添加常用标签 #${e}`,null)),S.commonTagInput.focus()):S.commonTagInput.focus()}function Qn(){Vn();let e=window.innerWidth>760&&Kt();document.querySelectorAll(`[data-view]`).forEach(t=>{let n=t.closest(`.desktop-primary-nav`)&&t.dataset.view===`all`&&e;t.dataset.view===x.view||n?t.setAttribute(`aria-current`,`page`):t.removeAttribute(`aria-current`)}),document.querySelectorAll(`[data-dock-view]`).forEach(e=>{let t=e.dataset.dockView;(t===`all`?Kt():x.view===t)?e.setAttribute(`aria-current`,`page`):e.removeAttribute(`aria-current`)})}function $n(){let e=ye[x.view],t=x.view===`records`,n=x.view===`inspirations`,r=window.innerWidth>760&&Kt(),i=ve.find(e=>e.view===x.view);S.viewTitle.textContent=r?`待办`:e.title;let a=t?Ht().length:n?Wt().length:B().length;S.viewSummary.textContent=x.search?`搜索“${x.search}” · ${a} 项结果`:x.tagFilter?`仅显示标签 #${x.tagFilter} 的待办。`:r&&x.view!==`all`&&i?`仅显示“${i.label}”状态的待办。`:e.copy;let o=n?Gt().length:0;S.listCount.textContent=n?`${o} 个主题 · ${a} 条灵感`:`${a} ${t?`条`:`项`}`;let s=t?`搜索记录`:n?`搜索灵感`:`搜索待办`;S.searchLabel.textContent=s,S.searchInput.placeholder=s,S.mobileSearchLabel.textContent=s,S.mobileSearchInput.placeholder=n?`输入主题或灵感内容`:`输入标题或正文`,S.mobileSearchPanel.setAttribute(`aria-label`,s);let c=S.sortSelect.closest(`.sort-control`);c&&(c.hidden=t||n),S.layoutToggle.hidden=t||n,S.desktopCreateButton.innerHTML=t?`${R(`note`)}<span>新建记录</span>`:n?`${R(`sparkles`)}<span>记录灵感</span>`:`${R(`plus`)}<span>新建待办</span>`,Qn(),Hn(),Wn()}function er(e){return`<span class="status-chip" data-status="${e}"><span class="status-dot"></span>${b[e].label}</span>`}function tr(e){return String(e.title||``).trim()||String(e.notes||``).trim().split(/\r?\n/).find(Boolean)||`未填写正文`}function nr(e,n=`list`){let r=e.dueDate?Rn(e.dueDate):``,i=e.dueDate===O()?` is-today`:zn(e)?` is-overdue`:``,a=e.tags.map(e=>`<span class="tag-chip">${L(e)}</span>`).join(``),o=e.dispatch?.sessionId?`<span class="dispatch-chip">${R(`play`)}DSH</span>`:``,s=e.status===`done`,c=s?ir(e.completedAt):``,l=!x.search,u=window.innerWidth<=760,d=e.id===x.openMenuId,f=!!String(e.title||``).trim(),p=!!String(e.notes||``).trim();return`
|
|
196
|
-
<li>
|
|
197
|
-
<article class="task-row${n===`card`?` task-card`:``}${e.id===x.selectedId?` is-selected`:``}" data-id="${e.id}" data-status="${e.status}">
|
|
198
|
-
${u?`<button class="drag-handle" type="button" data-drag-handle aria-label="按住拖动排序" ${l?``:`disabled`}>${R(`drag`)}</button>`:``}
|
|
199
|
-
<button class="task-main" type="button" data-action="select-task" aria-label="查看 ${L(tr(e))} 的详情">
|
|
200
|
-
${f?`<span class="task-title">${L(e.title)}</span>`:``}
|
|
201
|
-
${p?`<span class="task-body-preview${f?``:` is-main`}">${L(e.notes)}</span>`:f?``:`<span class="task-title">未填写正文</span>`}
|
|
202
|
-
<span class="task-meta">
|
|
203
|
-
${e.pinned?`<span class="pin-chip">${R(`pin`)}置顶</span>`:``}
|
|
204
|
-
${s&&c?`<time class="completed-chip" datetime="${L(e.completedAt)}">${R(`check`)}完成于 ${c}</time>`:er(e.status)}
|
|
205
|
-
${o}
|
|
206
|
-
${r?`<span class="due-chip${i}">${R(`calendar`)}${r}</span>`:``}
|
|
207
|
-
${a}
|
|
208
|
-
</span>
|
|
209
|
-
</button>
|
|
210
|
-
<div class="row-menu-wrap">
|
|
211
|
-
<button class="row-menu-button" type="button" data-action="toggle-row-menu" aria-label="更多操作" aria-expanded="${d}">
|
|
212
|
-
${R(`more`)}
|
|
213
|
-
</button>
|
|
214
|
-
<div class="row-menu" data-row-menu ${d?``:`hidden`}>
|
|
215
|
-
<button class="menu-item" type="button" data-menu-action="toggle-pin">${R(`pin`)}${e.pinned?`取消置顶`:`置顶`}</button>
|
|
216
|
-
${t?`<button class="menu-item" type="button" data-menu-action="dispatch">${R(`play`)}${e.dispatch?.sessionId?`重新派发 DSH`:`派发给 DSH`}</button>`:``}
|
|
217
|
-
<p class="menu-caption">更改状态</p>
|
|
218
|
-
${rr(e,`todo`,`plus`)}
|
|
219
|
-
${rr(e,`doing`,`play`)}
|
|
220
|
-
${rr(e,`held`,`pause`)}
|
|
221
|
-
${rr(e,`done`,`check-circle`)}
|
|
222
|
-
<div class="menu-separator"></div>
|
|
223
|
-
<button class="menu-item is-danger" type="button" data-menu-action="delete">${R(`trash`)}删除</button>
|
|
224
|
-
</div>
|
|
225
|
-
</div>
|
|
226
|
-
</article>
|
|
227
|
-
</li>`}function rr(e,t,n){let r=e.status===t;return`<button class="menu-item" type="button" data-tone="${t}" data-menu-action="status" data-status="${t}">${R(n)}${b[t].label}${r?` · 当前`:``}</button>`}function ir(e){let t=new Date(e);if(Number.isNaN(t.getTime()))return``;let n=new Date;return`${t.getFullYear()===n.getFullYear()?``:`${t.getFullYear()}年`}${t.getMonth()+1}月${t.getDate()}日 ${String(t.getHours()).padStart(2,`0`)}:${String(t.getMinutes()).padStart(2,`0`)}`}function ar(e){let t=e.title.trim(),n=e.body.trim(),r=n.split(/\r?\n/).map(e=>e.trim()).filter(Boolean),i=r[0]||`未命名记录`,a=t?n:r.slice(1).join(` `),o=t||i,s=ir(e.updatedAt);return`
|
|
228
|
-
<li>
|
|
229
|
-
<article class="record-card" data-record-id="${e.id}">
|
|
230
|
-
<button class="record-main" type="button" data-action="open-record" data-record-id="${e.id}" aria-label="打开记录:${L(o)}">
|
|
231
|
-
<span class="record-title">${L(o)}</span>
|
|
232
|
-
${a?`<span class="record-preview">${L(a)}</span>`:``}
|
|
233
|
-
<span class="record-footer">
|
|
234
|
-
<span class="record-meta">
|
|
235
|
-
${s?`<time datetime="${L(e.updatedAt)}">${s}</time><span class="record-meta-separator" aria-hidden="true">·</span>`:``}
|
|
236
|
-
<span>${e.body.trim().length} 字</span>
|
|
237
|
-
</span>
|
|
238
|
-
<span class="record-open-hint">继续写 ${R(`chevron-right`)}</span>
|
|
239
|
-
</span>
|
|
240
|
-
</button>
|
|
241
|
-
</article>
|
|
242
|
-
</li>`}function or(){let e=Ht(),t=!!x.search;S.taskGroups.classList.remove(`is-board`),S.taskGroups.classList.remove(`is-inspirations`),S.taskGroups.classList.add(`is-records`),S.taskScroll.classList.remove(`is-board-view`),e.length?(S.taskGroups.innerHTML=`<ul class="record-list">${e.map(ar).join(``)}</ul>`,$n()):(S.taskGroups.innerHTML=`
|
|
243
|
-
<div class="empty-state record-empty">
|
|
244
|
-
<span class="empty-mark">${R(t?`search`:`note`)}</span>
|
|
245
|
-
<h3 class="empty-title">${t?`没有找到匹配的记录`:`还没有留下记录`}</h3>
|
|
246
|
-
<p class="empty-copy">${t?`换个关键词,或在右上角清除搜索。`:`完整笔记、文章片段和随笔都可以放在这里,不必急着整理成待办。`}</p>
|
|
247
|
-
${t?``:`<button class="secondary-button record-empty-action" type="button" data-action="create-record">${R(`plus`)}新建记录</button>`}
|
|
248
|
-
</div>`,$n())}function sr(e,t){return`
|
|
249
|
-
<li>
|
|
250
|
-
<button
|
|
251
|
-
class="inspiration-idea"
|
|
252
|
-
type="button"
|
|
253
|
-
data-action="open-inspiration"
|
|
254
|
-
data-inspiration-id="${L(e.id)}"
|
|
255
|
-
aria-label="编辑灵感:${L(e.body.slice(0,80))}"
|
|
256
|
-
>
|
|
257
|
-
<span class="inspiration-idea-index" aria-hidden="true">${String(t+1).padStart(2,`0`)}</span>
|
|
258
|
-
<span class="inspiration-idea-copy">
|
|
259
|
-
<span class="inspiration-idea-text">${L(e.body)}</span>
|
|
260
|
-
</span>
|
|
261
|
-
<svg class="od-icon inspiration-idea-chevron" aria-hidden="true"><use href="#icon-chevron-right"></use></svg>
|
|
262
|
-
</button>
|
|
263
|
-
</li>`}function cr(e){return`
|
|
264
|
-
<section class="inspiration-topic" data-topic-key="${L(e.key)}">
|
|
265
|
-
<header class="inspiration-topic-head">
|
|
266
|
-
<span class="inspiration-topic-mark" aria-hidden="true">${R(`sparkles`)}</span>
|
|
267
|
-
<div class="inspiration-topic-heading">
|
|
268
|
-
<h3 class="inspiration-topic-title">${L(e.topic)}</h3>
|
|
269
|
-
<span class="inspiration-topic-meta">${e.items.length} 条灵感</span>
|
|
270
|
-
</div>
|
|
271
|
-
<button
|
|
272
|
-
class="inspiration-topic-add"
|
|
273
|
-
type="button"
|
|
274
|
-
data-action="add-inspiration"
|
|
275
|
-
data-topic="${L(e.topic)}"
|
|
276
|
-
aria-label="在 ${L(e.topic)} 主题下添加灵感"
|
|
277
|
-
>
|
|
278
|
-
${R(`plus`)}
|
|
279
|
-
<span>添加</span>
|
|
280
|
-
</button>
|
|
281
|
-
</header>
|
|
282
|
-
<ul class="inspiration-idea-list">
|
|
283
|
-
${e.items.map(sr).join(``)}
|
|
284
|
-
</ul>
|
|
285
|
-
</section>`}function lr(){let e=Gt(),t=!!x.search,n=e.reduce((e,t)=>e+t.items.length,0);S.taskGroups.classList.remove(`is-board`,`is-records`),S.taskGroups.classList.add(`is-inspirations`),S.taskScroll.classList.remove(`is-board-view`),e.length?(S.taskGroups.innerHTML=`
|
|
286
|
-
${t?``:`
|
|
287
|
-
<section class="inspiration-overview" aria-label="灵感概览">
|
|
288
|
-
<span class="inspiration-overview-mark" aria-hidden="true">${R(`sparkles`)}</span>
|
|
289
|
-
<span class="inspiration-overview-copy">
|
|
290
|
-
<span class="inspiration-overview-kicker">灵感地图</span>
|
|
291
|
-
<strong>先给念头一个主题,再让它慢慢长大。</strong>
|
|
292
|
-
</span>
|
|
293
|
-
<span class="inspiration-overview-stats">
|
|
294
|
-
<span><strong>${e.length}</strong> 个主题</span>
|
|
295
|
-
<span><strong>${n}</strong> 条灵感</span>
|
|
296
|
-
</span>
|
|
297
|
-
</section>`}
|
|
298
|
-
<div class="inspiration-topic-grid">
|
|
299
|
-
${e.map(cr).join(``)}
|
|
300
|
-
</div>`,$n()):(S.taskGroups.innerHTML=`
|
|
301
|
-
<div class="empty-state inspiration-empty">
|
|
302
|
-
<span class="empty-mark">${R(t?`search`:`sparkles`)}</span>
|
|
303
|
-
<h3 class="empty-title">${t?`没有找到匹配的灵感`:`灵感还没有落点`}</h3>
|
|
304
|
-
<p class="empty-copy">${t?`换个关键词,主题和灵感内容都会一起搜索。`:`先建立一个主题,再把零散念头一条条放进去。同一方向的想法会自然聚在一起。`}</p>
|
|
305
|
-
${t?``:`<button class="secondary-button inspiration-empty-action" type="button" data-action="create-inspiration">${R(`sparkles`)}记录第一条灵感</button>`}
|
|
306
|
-
</div>`,$n())}function H(){if(Un(),x.view===`records`){or();return}if(x.view===`inspirations`){lr();return}S.taskGroups.classList.remove(`is-records`),S.taskGroups.classList.remove(`is-inspirations`);let e=B(),t=window.innerWidth>760,n=!!x.search,r=!!x.tagFilter;if(S.taskGroups.classList.toggle(`is-board`,t),S.taskScroll.classList.toggle(`is-board-view`,t),S.layoutToggle.setAttribute(`aria-pressed`,String(x.mobileLayout===`cards`)),S.layoutToggle.setAttribute(`aria-label`,x.mobileLayout===`cards`?`切换为列表`:`切换为双列卡片`),S.layoutToggle.innerHTML=`${R(x.mobileLayout===`cards`?`layout-list`:`layout-grid`)}<span>${x.mobileLayout===`cards`?`列表`:`双列`}</span>`,!e.length)S.taskGroups.innerHTML=`
|
|
307
|
-
<div class="empty-state">
|
|
308
|
-
<span class="empty-mark">${R(n?`search`:r?`list`:`check`)}</span>
|
|
309
|
-
<h3 class="empty-title">${n?`没有找到匹配的待办`:r?`没有标签 #${L(x.tagFilter)} 的待办`:`这里已经清空`}</h3>
|
|
310
|
-
<p class="empty-copy">${n?`换个关键词,或在右上角清除搜索。`:r?`可以切换其他标签,或选择“全部”。`:ur()}</p>
|
|
311
|
-
</div>`,$n();else{if(t)S.taskGroups.innerHTML=`
|
|
312
|
-
<div class="board-grid">
|
|
313
|
-
${y.map(t=>{let n=Yt(e.filter(e=>e.status===t)),r=x.mosaicLanes.has(t);return`
|
|
314
|
-
<section class="board-lane${x.mosaicLanes.has(t)?` is-mosaic`:``}" data-tone="${t}" data-lane-status="${t}" aria-label="${b[t].label}泳道">
|
|
315
|
-
<header class="board-lane-head">
|
|
316
|
-
<span class="board-lane-title">${R(b[t].icon)}${b[t].label}</span>
|
|
317
|
-
<span class="board-lane-head-actions">
|
|
318
|
-
<span class="board-lane-count">${n.length}</span>
|
|
319
|
-
<button class="lane-mosaic-toggle" type="button" data-action="toggle-lane-mosaic" data-status="${t}" aria-pressed="${r}" aria-label="${r?`还原`:`为`}${b[t].label}泳道内容${r?``:`打马赛克`}">${R(`mosaic`)}</button>
|
|
320
|
-
</span>
|
|
321
|
-
</header>
|
|
322
|
-
<div class="board-lane-body" data-lane-drop="${t}">
|
|
323
|
-
${n.length?`<ul class="task-list board-list">${n.map(e=>nr(e,`card`)).join(``)}</ul>`:`<div class="lane-empty">${R(`drag`)}拖到这里</div>`}
|
|
324
|
-
</div>
|
|
325
|
-
</section>`}).join(``)}
|
|
326
|
-
</div>`;else{let e=Xt(),t=x.mobileLayout===`cards`?`task-list task-card-grid`:`task-list`;S.taskGroups.innerHTML=e.map(e=>`
|
|
327
|
-
<section class="task-group" aria-label="${e.status?b[e.status].label:ye[x.view].title}">
|
|
328
|
-
${e.status?`<h3 class="group-heading" data-tone="${e.status}">${R(b[e.status].icon)}${b[e.status].label}<span class="group-count">${e.items.length}</span></h3>`:``}
|
|
329
|
-
<ul class="${t}">${e.items.map(e=>nr(e,x.mobileLayout===`cards`?`card`:`list`)).join(``)}</ul>
|
|
330
|
-
</section>`).join(``)}$n()}}function ur(){return x.view===`inbox`?`新建状态是空的。把脑海里的事情写进上方的输入框。`:x.view===`doing`?`没有正在推进的事项。从新建中选择一件开始。`:x.view===`held`?`没有搁置事项。`:x.view===`done`?`还没有完成记录。`:`还什么都没有。写下第一件要做的事。`}function dr(e,t){let n=M(e,8),r=t===`detail`?`detailTagEntry`:`createTagEntry`;return`
|
|
331
|
-
<div class="tag-editor" data-tag-editor="${t}">
|
|
332
|
-
<div class="tag-editor-block">
|
|
333
|
-
<div class="tag-editor-heading">
|
|
334
|
-
<span class="tag-editor-label">${n.length?`已选择`:`选择标签`}</span>
|
|
335
|
-
<button
|
|
336
|
-
class="tag-temp-trigger"
|
|
337
|
-
type="button"
|
|
338
|
-
data-tag-action="show-entry"
|
|
339
|
-
data-tag-context="${t}"
|
|
340
|
-
${n.length>=8?`disabled`:``}
|
|
341
|
-
>
|
|
342
|
-
${R(`plus`)}临时标签
|
|
343
|
-
</button>
|
|
344
|
-
</div>
|
|
345
|
-
<div class="tag-editor-list">
|
|
346
|
-
${n.length?n.map(e=>`
|
|
347
|
-
<span class="tag-editor-chip${Jt(e)?``:` is-temporary`}">
|
|
348
|
-
<span>#${L(e)}</span>
|
|
349
|
-
<button
|
|
350
|
-
type="button"
|
|
351
|
-
data-remove-editor-tag="${L(e)}"
|
|
352
|
-
data-tag-context="${t}"
|
|
353
|
-
aria-label="移除标签 ${L(e)}"
|
|
354
|
-
>${R(`close`)}</button>
|
|
355
|
-
</span>`).join(``):`<span class="tag-editor-placeholder">还没有选择标签</span>`}
|
|
356
|
-
</div>
|
|
357
|
-
<div class="tag-entry-row" data-tag-entry-row hidden>
|
|
358
|
-
<input
|
|
359
|
-
id="${r}"
|
|
360
|
-
class="tag-entry"
|
|
361
|
-
type="text"
|
|
362
|
-
placeholder="输入临时标签后按 Enter"
|
|
363
|
-
aria-label="临时标签"
|
|
364
|
-
maxlength="20"
|
|
365
|
-
autocomplete="off"
|
|
366
|
-
>
|
|
367
|
-
<button class="tag-entry-add" type="button" data-tag-action="add-entry" data-tag-context="${t}">添加</button>
|
|
368
|
-
</div>
|
|
369
|
-
</div>
|
|
370
|
-
<div class="tag-editor-block tag-common-block">
|
|
371
|
-
<span class="tag-editor-label">常用标签</span>
|
|
372
|
-
<div class="tag-option-list" role="group" aria-label="常用标签">
|
|
373
|
-
${x.commonTags.length?x.commonTags.map(e=>`
|
|
374
|
-
<button
|
|
375
|
-
class="tag-option-button"
|
|
376
|
-
type="button"
|
|
377
|
-
data-toggle-editor-tag="${L(e)}"
|
|
378
|
-
data-tag-context="${t}"
|
|
379
|
-
aria-pressed="${n.some(t=>j(t)===j(e))}"
|
|
380
|
-
>#${L(e)}</button>`).join(``):`<span class="tag-editor-placeholder">暂无常用标签,可在设置中添加</span>`}
|
|
381
|
-
</div>
|
|
382
|
-
</div>
|
|
383
|
-
</div>`}function fr(e){return document.getElementById(e===`detail`?`detailTagEditor`:`createTagList`)}function pr(e){return e===`detail`?x.draft?x.draft.tags:[]:x.createTags}function mr(e,t=``){let n=fr(e);n&&(n.innerHTML=dr(pr(e),e),e===`detail`&&Sr(),t&&requestAnimationFrame(()=>{let n=fr(e)?.querySelector(`[data-toggle-editor-tag="${CSS.escape(t)}"]`);n&&n.focus()}))}function hr(e){let t=fr(e)?.querySelector(`[data-tag-entry-row]`);t&&(t.hidden=!1,t.querySelector(`input`)?.focus())}function gr(e,t,{requestCommon:n=!0}={}){let r=A(t),i=pr(e);if(!r)return{added:!1,tag:``,shouldAsk:!1};if(i.some(e=>j(e)===j(r)))return mr(e),{added:!1,tag:r,shouldAsk:!1};if(i.length>=8)return Z(`最多添加 8 个标签`,null),{added:!1,tag:r,shouldAsk:!1};i.push(r),e===`detail`&&x.draft&&(x.draftDirty=!0),mr(e);let a=n&&!Jt(r);return a&&requestAnimationFrame(()=>yr([r])),{added:!0,tag:r,shouldAsk:a}}function _r(e,t){let n=pr(e),r=j(t),i=n.some(e=>j(e)===r);if(!i&&n.length>=8)Z(`最多添加 8 个标签`,null);else{if(i){let t=n.filter(e=>j(e)!==r);e===`detail`&&x.draft?x.draft.tags=t:x.createTags=t}else n.push(A(t)),e===`detail`&&x.draft?x.draft.tags=n:x.createTags=n;e===`detail`&&(x.draftDirty=!0),mr(e,t)}}function vr(e,t){let n=j(t),r=pr(e).filter(e=>j(e)!==n);e===`detail`&&x.draft?(x.draft.tags=r,x.draftDirty=!0):x.createTags=r,mr(e)}function yr(e){let t=M(e,50).filter(e=>!Jt(e));if(!t.length||S.confirmDialog.open)return;let n=t.slice(0,3).map(e=>`#${e}`).join(`、`);to(`保存为常用标签?`,`${t.length>3?`${n} 等 ${t.length} 个标签`:n} 已作为临时标签选中。是否同时保存为常用标签,之后直接选择?`,()=>{Yn(t,{message:`已保存常用标签:${n}`})},{acceptLabel:`保存为常用`,cancelLabel:`仅本次使用`,acceptTone:`primary`})}function br(){let e=zt();if(!e){x.draft=null,x.draftTaskId=null,x.draftDirty=!1,S.inspectorContent.innerHTML=`
|
|
384
|
-
<div class="inspector-empty">
|
|
385
|
-
${R(`note`)}
|
|
386
|
-
<p>选择一条待办,可以补充备注、日期和标签,也可以调整状态。</p>
|
|
387
|
-
</div>`,window.innerWidth<=1180&&ni();return}x.draftTaskId===e.id&&x.draft||(x.draft={title:e.title,notes:e.notes,status:e.status,dueDate:e.dueDate,tags:[...e.tags]},x.draftTaskId=e.id,x.draftDirty=!1);let n=x.draft,r=xr(),i=new Date(e.createdAt),a=Number.isNaN(i.getTime())?``:new Intl.DateTimeFormat(`zh-CN`,{year:`numeric`,month:`numeric`,day:`numeric`}).format(i),o=e.status===`done`?ir(e.completedAt):``;S.inspectorContent.innerHTML=`
|
|
388
|
-
<form class="detail-form" id="detailForm" novalidate>
|
|
389
|
-
<div class="field">
|
|
390
|
-
<label class="field-label" for="detailTitle">标题(可选)</label>
|
|
391
|
-
<input id="detailTitle" data-draft-field="title" type="text" value="${L(n.title)}" maxlength="180">
|
|
392
|
-
</div>
|
|
393
|
-
<div class="field">
|
|
394
|
-
<label class="field-label" for="detailNotes">正文(必填)</label>
|
|
395
|
-
<textarea id="detailNotes" data-draft-field="notes" maxlength="4000" required>${L(n.notes)}</textarea>
|
|
396
|
-
</div>
|
|
397
|
-
<div class="field">
|
|
398
|
-
<span class="field-label">状态</span>
|
|
399
|
-
<div class="status-editor" role="group" aria-label="待办状态">
|
|
400
|
-
${y.map(e=>`
|
|
401
|
-
<button class="status-option" type="button" data-draft-status="${e}" data-tone="${e}" aria-pressed="${n.status===e}">
|
|
402
|
-
${R(b[e].icon)}${b[e].label}
|
|
403
|
-
</button>`).join(``)}
|
|
404
|
-
</div>
|
|
405
|
-
</div>
|
|
406
|
-
<div class="field">
|
|
407
|
-
<label class="field-label" for="detailDue">截止日期</label>
|
|
408
|
-
<button class="picker-trigger field-picker-trigger date-picker-trigger${n.dueDate?``:` is-placeholder`}" id="detailDue" data-draft-field="dueDate" data-picker-type="date" data-picker-title="截止日期" data-value="${n.dueDate}" type="button" role="combobox" aria-haspopup="dialog" aria-expanded="false" aria-controls="appPickerBody" aria-label="截止日期:${bt(n.dueDate)}">
|
|
409
|
-
<svg class="od-icon picker-leading-icon" aria-hidden="true"><use href="#icon-calendar"></use></svg>
|
|
410
|
-
<span class="picker-trigger-value" data-picker-label>${bt(n.dueDate)}</span>
|
|
411
|
-
<svg class="od-icon picker-chevron" aria-hidden="true"><use href="#icon-down"></use></svg>
|
|
412
|
-
</button>
|
|
413
|
-
</div>
|
|
414
|
-
<div class="field">
|
|
415
|
-
<span class="field-label">标签</span>
|
|
416
|
-
<div id="detailTagEditor">${dr(n.tags,`detail`)}</div>
|
|
417
|
-
<span class="field-hint">常用标签可直接点选;临时标签不会自动加入常用标签。</span>
|
|
418
|
-
</div>
|
|
419
|
-
<div class="detail-actions">
|
|
420
|
-
<button class="quiet-button detail-delete" type="button" data-detail-action="delete">${R(`trash`)}删除</button>
|
|
421
|
-
${t?`<div class="detail-dsh-actions">
|
|
422
|
-
${e.dispatch?.sessionId?`<button class="secondary-button detail-dispatch-open" type="button" data-detail-action="open-dsh">${R(`chevron-right`)}在 DSH 中查看</button>`:``}
|
|
423
|
-
<button class="secondary-button detail-dispatch-button" type="button" data-detail-action="dispatch">${R(`play`)}${e.dispatch?.sessionId?`重新派发`:`派发给 DSH`}</button>
|
|
424
|
-
</div>`:``}
|
|
425
|
-
<div class="detail-save-group">
|
|
426
|
-
<span class="detail-save-state" id="detailSaveState">${r?`尚未保存`:`已保存`}</span>
|
|
427
|
-
<button class="primary-button detail-save-button" id="detailSaveButton" type="button" data-detail-action="save" ${r?``:`disabled`}>
|
|
428
|
-
${R(`save`)}保存
|
|
429
|
-
</button>
|
|
430
|
-
</div>
|
|
431
|
-
</div>
|
|
432
|
-
${a?`<p class="detail-created">创建于 ${a}</p>`:``}
|
|
433
|
-
${o?`<p class="detail-created detail-completed">完成于 ${o}</p>`:``}
|
|
434
|
-
</form>`,Ct(document.getElementById(`detailDue`))}function xr(){let e=zt(),t=x.draft;if(!e||!t||x.draftTaskId!==e.id)return!1;let n=document.getElementById(`detailTagEntry`),r=!!(n&&n.value.trim());return t.title!==e.title||t.notes!==e.notes||t.status!==e.status||t.dueDate!==e.dueDate||t.tags.join(`\0`)!==e.tags.join(`\0`)||r}function Sr(){x.draftDirty=xr();let e=document.getElementById(`detailSaveState`),t=document.getElementById(`detailSaveButton`);e&&(e.textContent=x.draftDirty?`尚未保存`:`已保存`),t&&(t.disabled=!x.draftDirty)}function Cr(e,t){x.draft&&(x.draft[e]=t,Sr())}function wr(e={}){let t=zt();if(!t||!x.draft)return!1;if(!x.draft.notes.trim()){Z(`请填写正文后再保存`,null);let e=document.getElementById(`detailNotes`);return e&&e.focus(),!1}let n=document.getElementById(`detailTagEntry`),r=n?A(n.value):``,i=!1,a=r&&x.draft.tags.some(e=>j(e)===j(r));if(r&&!a&&x.draft.tags.length<8?(x.draft.tags.push(r),i=!0):r&&!a&&Z(`最多添加 8 个标签`,null),n&&(n.value=``),!xr())return Sr(),typeof e.after==`function`&&e.after(),!0;let o={title:x.draft.title.trim(),notes:x.draft.notes,status:x.draft.status,dueDate:x.draft.dueDate,tags:[...x.draft.tags]};return x.draft=o,x.draftDirty=!1,W(`修改已保存`,()=>{Dr(t,o.status),Object.assign(t,{...o,tags:[...o.tags]}),Er(t)},{undo:!1,render:()=>{H(),Pa(),we(x.items).catch(()=>{}),i?br():Sr()}}),i&&!Jt(r)&&setTimeout(()=>yr([r]),0),typeof e.after==`function`&&e.after(),!0}function Tr(e=!0){e&&(x.dirty=!0),E(s,ke()),Ie(),$e(x.items)}function U(){H(),br(),Pa(),Kn(),we(x.items).catch(()=>{}),S.recordDrawer.open&&pn(),x.statsOpen&&kn()}function W(e,t,n={}){let r={items:Ye(x.items),records:Ye(x.records),inspirations:Ye(x.inspirations)};t(),Tr(!0),typeof n.render==`function`?n.render():U(),e&&Z(e,n.undo===!1?null:()=>{n.undoScope===`records`?x.records=r.records:n.undoScope===`inspirations`?x.inspirations=r.inspirations:x.items=r.items,Tr(!0),U(),$a()}),$a()}function Er(e){e.updatedAt=D(),e.deviceId=h}function Dr(e,t){let n=e.status===`done`;e.status=t,t===`done`?n&&e.completedAt||(e.completedAt=D()):e.completedAt=``}function Or(e){e.updatedAt=D(),e.deviceId=h}function kr(e){e.updatedAt=D(),e.deviceId=h}function Ar({title:e=``,body:t,dueDate:n=``,tags:r=[],status:i=``}){let a=String(e).trim().slice(0,180),o=String(t||``).trim();if(!o)return!1;let s=M(r,8),c=b[i]?i:ye[x.view].status||`todo`,l=Math.min(...z().filter(e=>e.status===c).map(e=>e.order),0),u={id:crypto.randomUUID?crypto.randomUUID():`task-${Date.now()}-${Math.random().toString(16).slice(2)}`,title:a,notes:o.slice(0,4e3),status:c,dueDate:n,tags:s,pinned:!1,order:l-100,createdAt:D(),updatedAt:D(),completedAt:c===`done`?D():``,deletedAt:``,deviceId:h};return W(`已添加待办`,()=>{x.items.push(u)}),!0}function jr({title:e=``,body:t}){let n=String(t||``).trim();if(!n)return null;let r={id:crypto.randomUUID?crypto.randomUUID():`record-${Date.now()}-${Math.random().toString(16).slice(2)}`,title:String(e||``).trim().slice(0,180),body:n.slice(0,2e4),createdAt:D(),updatedAt:D(),deletedAt:``,deviceId:h};return W(`记录已保存`,()=>{x.records.push(r)},{undoScope:`records`}),r}function Mr({topic:e=``,body:t}){let n=String(t||``).trim(),r=ft(e);if(!r||!n)return null;let i=Rt().find(e=>pt(e.topic)===pt(r))?.topic,a={id:crypto.randomUUID?crypto.randomUUID():`inspiration-${Date.now()}-${Math.random().toString(16).slice(2)}`,topic:i||r,body:n.slice(0,4e3),createdAt:D(),updatedAt:D(),deletedAt:``,deviceId:h};return W(`灵感已收进主题`,()=>{x.inspirations.push(a)},{undoScope:`inspirations`}),a}function Nr(e){let t=[];return{body:e.replace(/(?:^|\s)#([\p{L}\p{N}_-]+)/gu,(e,n)=>{let r=A(n);return r&&!t.some(e=>j(e)===j(r))&&t.push(r),``}).replace(/\s{2,}/g,` `).trim(),tags:M(t,8)}}function Pr(e,t,n=`已移至${b[t].label}`){let r=z().find(t=>t.id===e);r&&r.status!==t&&(x.selectedId===e&&x.draft&&(x.draft.status=t),W(n,()=>{Dr(r,t),Er(r)}),x.selectedId===e&&ei())}function Fr(e){let t=z().find(t=>t.id===e);if(!t)return;let n=t.status===`done`;x.selectedId===e&&x.draft&&(x.draft.status=n?`todo`:`done`),W(n?`已恢复为新建`:`已完成`,()=>{Dr(t,n?`todo`:`done`),Er(t)})}function Ir(e){let t=z().find(t=>t.id===e);t&&(!x.draftDirty||x.selectedId!==e||wr())&&(fe=e,pe=``,S.dispatchDialogTask.textContent=tr(t),S.dispatchPromptInput.value=``,S.dispatchError.hidden=!0,S.dispatchError.textContent=``,S.dispatchConfirmButton.disabled=!1,S.dispatchConfirmButton.innerHTML=`${R(`play`)}<span>派发并开始</span>`,typeof S.dispatchDialog.showModal==`function`?(S.dispatchDialog.showModal(),requestAnimationFrame(()=>S.dispatchPromptInput.focus())):S.dispatchDialog.setAttribute(`open`,``))}function Lr(){fe=``,pe=``,S.dispatchDialog.open?S.dispatchDialog.close():S.dispatchDialog.removeAttribute(`open`)}function Rr(){let e=z().find(e=>e.id===fe);if(!e||!t)return;pe=crypto.randomUUID?crypto.randomUUID():`dispatch-${Date.now()}-${Math.random().toString(16).slice(2)}`;let n=S.dispatchPromptInput.value.trim();S.dispatchError.hidden=!0,S.dispatchConfirmButton.disabled=!0,S.dispatchConfirmButton.textContent=`正在创建 DSH 会话…`,Je({type:`jianji:dispatch`,requestId:pe,task:Ye(e),prompt:n})}async function zr(e){if(pe&&e.requestId===pe){if(!e.ok)S.dispatchError.textContent=String(e.message||`派发失败,请重试`),S.dispatchError.hidden=!1,S.dispatchConfirmButton.disabled=!1,S.dispatchConfirmButton.innerHTML=`${R(`play`)}<span>重试派发</span>`;else try{let t=await De(`dispatch`,{method:`POST`,body:JSON.stringify({taskId:fe,sessionId:e.sessionId,workspaceId:e.workspaceId,prompt:e.prompt})});if(!t.ok)throw Error(await qe(t,`保存派发状态失败`));let n=await t.json(),r=x.items.findIndex(e=>e.id===n.task?.id);r>=0&&(x.items[r]=ct(n.task)),E(s,ke()),Lr(),U(),Z(`已派发给 DSH`,null),Ne({force:!0})}catch(e){S.dispatchError.textContent=e instanceof Error?e.message:`保存派发状态失败`,S.dispatchError.hidden=!1,S.dispatchConfirmButton.disabled=!1,S.dispatchConfirmButton.innerHTML=`${R(`play`)}<span>重试保存</span>`}}}function Br(e){t&&e.source===window.parent&&e.data&&typeof e.data==`object`&&e.data.type===`jianji:dispatch-result`&&zr(e.data)}function Vr(e){e?.dispatch?.sessionId&&Je({type:`jianji:open-session`,sessionId:e.dispatch.sessionId})}function Hr(e){let t=z().find(t=>t.id===e);t&&W(t.pinned?`已取消置顶`:`已置顶`,()=>{t.pinned=!t.pinned,Er(t)})}function Ur(e){let t=z().find(t=>t.id===e);t&&(W(`已删除待办`,()=>{t.deletedAt=D(),t.updatedAt=D(),t.deviceId=h,x.selectedId===e&&(x.selectedId=null)}),ni())}function Wr(e,t){let n=z().find(t=>t.id===e);if(!n)return;let r=Yt(z().filter(e=>e.status===n.status)),i=r[r.findIndex(t=>t.id===e)+t];i?W(`顺序已调整`,()=>{let e=n.order;n.order=i.order,i.order=e,Er(n),Er(i)}):Z(t<0?`已经是第一项`:`已经是最后一项`,null)}function Gr(e,t){if(!e||!t||e===t)return;let n=z().find(t=>t.id===e),r=z().find(e=>e.id===t);if(!n||!r)return;let i=n.status,a=Yt(z()),o=a.findIndex(t=>t.id===e),s=a.findIndex(e=>e.id===t);o<0||s<0||(x.selectedId===e&&x.draft&&(x.draft.status=r.status),W(i===r.status?`顺序已调整`:`已移至${b[r.status].label}`,()=>{let[e]=a.splice(o,1);Dr(e,r.status);let n=a.findIndex(e=>e.id===t);a.splice(n<0?a.length:n,0,e);let i=new Set;a.forEach((e,t)=>{let n=t*100;e.order!==n&&(e.order=n,i.add(e))}),i.add(e),i.forEach(Er)},{undo:!1}))}function Kr(e,t){let n=z().find(t=>t.id===e);if(!n||n.status===t)return;let r=z().filter(e=>e.status===t).map(e=>e.order);x.selectedId===e&&x.draft&&(x.draft.status=t),W(`已移至${b[t].label}`,()=>{Dr(n,t),n.order=(r.length?Math.max(...r):0)+100,Er(n)},{undo:!1})}function qr(e,t=``){ye[e]&&(e!==x.view||x.search||x.tagFilter)&&Xr(()=>{if(x.view=e,x.search=``,x.tagFilter=``,S.searchInput.value=``,S.mobileSearchInput.value=``,S.mobileSearchPanel.hidden=!0,S.searchBox.classList.remove(`is-open`),P(),U(),S.taskScroll.scrollTop=0,t){let e=t===`next`?`view-enter-next`:`view-enter-prev`;S.taskGroups.classList.add(e),setTimeout(()=>S.taskGroups.classList.remove(e),380)}})}function Jr(e){ge.includes(e)&&e!==x.view&&Xr(()=>{x.view=e,x.tagFilter=``,P(),U(),S.taskScroll.scrollTop=0})}function Yr(e){x.selectedId===e?ei():Xr(()=>{x.selectedId=e,H(),br(),ei()})}function Xr(e){xr()?S.savePromptDialog.open||(x.draftAfter=e,typeof S.savePromptDialog.showModal==`function`?(S.savePromptDialog.showModal(),requestAnimationFrame(()=>S.continueEditingButton.focus())):S.savePromptDialog.setAttribute(`open`,``)):typeof e==`function`&&e()}function Zr(){S.savePromptDialog.open&&S.savePromptDialog.close()}function Qr(){x.draft=null,x.draftTaskId=null,x.draftDirty=!1,Zr(),br();let e=x.draftAfter;x.draftAfter=null,typeof e==`function`&&e()}function $r(){let e=x.draftAfter;wr()?(Zr(),x.draftAfter=null,typeof e==`function`&&e()):(x.draftAfter=null,Zr(),requestAnimationFrame(()=>{let e=document.getElementById(`detailTitle`);e&&e.focus()}))}function ei(){S.inspector.open||(typeof S.inspector.showModal==`function`?S.inspector.showModal():S.inspector.setAttribute(`open`,``))}function ti(){Xr(ni)}function ni(){S.inspector.open&&S.inspector.close()}function ri(){S.createTagList.innerHTML=dr(x.createTags,`create`)}function ii(e,t={}){return gr(`create`,e,t)}function ai(){S.mobileSearchPanel.hidden||wi(),S.createTitleInput.value=``,S.createBodyInput.value=``,St(S.createStatusInput,ye[x.view].status||`todo`),St(S.createDueInput,``),x.createTags=[],ri(),S.createTaskError.hidden=!0,typeof S.createDialog.showModal==`function`?(S.createDialog.showModal(),requestAnimationFrame(()=>S.createBodyInput.focus())):S.createDialog.setAttribute(`open`,``)}function oi(){S.createDialog.open&&S.createDialog.close()}function si(){let e=S.createBodyInput.value.trim();if(!e){S.createTaskError.textContent=`请填写正文后再创建待办。`,S.createTaskError.hidden=!1,S.createBodyInput.focus();return}let t=Nr(e);if(!t.body){S.createTaskError.textContent=`正文不能只包含标签。`,S.createTaskError.hidden=!1,S.createBodyInput.focus();return}let n=document.getElementById(`createTagEntry`),r=n&&n.value.trim()?ii(n.value,{requestCommon:!1}):{added:!1,tag:``};x.view===`records`&&(x.view=`all`,x.search=``,x.tagFilter=``,S.searchInput.value=``,S.mobileSearchInput.value=``,P());let i=M([...x.createTags,...t.tags],8),a=M(t.tags,8).filter(e=>!Jt(e)&&!x.createTags.some(t=>j(t)===j(e))&&i.some(t=>j(t)===j(e)));if(Ar({title:S.createTitleInput.value,body:t.body,dueDate:xt(S.createDueInput),tags:i,status:xt(S.createStatusInput)})){S.createTaskError.hidden=!0,oi();let e=M([...r.added?[r.tag]:[],...a],50).filter(e=>!Jt(e));e.length&&setTimeout(()=>yr(e),0)}}function ci(e=``){S.recordError.textContent=e,S.recordError.hidden=!e}function li(e=null){Xr(()=>{let t=e?It().find(t=>t.id===e):null;e&&!t?Z(`这条记录已不存在`,null):(x.recordEditingId=t?.id||null,S.recordDialogTitle.textContent=t?`编辑记录`:`新建记录`,S.recordDialogCopy.textContent=t?`修改会保存在本机,并同步到已连接的其他设备。`:`保存一段完整文字、笔记或随笔。`,S.recordTitleInput.value=t?.title||``,S.recordBodyInput.value=t?.body||``,S.recordDeleteButton.hidden=!t,S.recordDialogMeta.textContent=t?`最后修改 ${ir(t.updatedAt)}`:``,S.recordSaveButton.querySelector(`span`).textContent=t?`保存修改`:`保存记录`,ci(),oi(),ni(),S.mobileSearchPanel.hidden||wi(),typeof S.recordDialog.showModal==`function`?S.recordDialog.showModal():S.recordDialog.setAttribute(`open`,``),requestAnimationFrame(()=>S.recordBodyInput.focus()))})}function ui(){S.recordDialog.open&&S.recordDialog.close(),x.recordEditingId=null,ci()}function di(){x.view=`records`,x.search=``,x.tagFilter=``,S.searchInput.value=``,S.mobileSearchInput.value=``,S.mobileSearchPanel.hidden=!0,S.searchBox.classList.remove(`is-open`),P()}function fi(){let e=S.recordTitleInput.value.trim(),t=S.recordBodyInput.value.trim();if(!t){ci(`先写下一点内容,再保存记录。`),S.recordBodyInput.focus();return}let n=x.recordEditingId?It().find(e=>e.id===x.recordEditingId):null;if(n){if(n.title===e&&n.body===t){ui();return}W(`记录已更新`,()=>{n.title=e.slice(0,180),n.body=t.slice(0,2e4),Or(n)},{undoScope:`records`})}else if(di(),!jr({title:e,body:t})){ci(`记录保存失败,请重试。`);return}ui()}function pi(e){let t=It().find(t=>t.id===e);t&&(W(`记录已删除`,()=>{t.deletedAt=D(),Or(t)},{undoScope:`records`}),ui())}function mi(){let e=x.recordEditingId?It().find(e=>e.id===x.recordEditingId):null;e&&to(`删除这条记录`,`删除后会同步到已连接的仓库,可在提示消失前撤销。`,()=>pi(e.id))}function hi(e=``){S.inspirationError.textContent=e,S.inspirationError.hidden=!e}function gi({topic:e=``,id:t=``}={}){Xr(()=>{let n=t?Rt().find(e=>e.id===t):null;if(t&&!n){Z(`这条灵感已不存在`,null);return}x.inspirationEditingId=n?.id||null;let r=n?.topic||ft(e);S.inspirationDialogTitle.textContent=n?`编辑灵感`:`记录灵感`,S.inspirationDialogCopy.textContent=n?`可以调整主题,或继续打磨这次的想法。`:r?`继续补充「${r}」主题下的想法。`:`先给它一个主题,再写下这次想到的内容。`,S.inspirationTopicInput.value=r,S.inspirationBodyInput.value=n?.body||``,S.inspirationDeleteButton.hidden=!n,S.inspirationDialogMeta.textContent=n?`最后修改 ${ir(n.updatedAt)}`:``,S.inspirationSaveButton.querySelector(`span`).textContent=n?`保存修改`:`收进主题`,hi(),oi(),ui(),ni(),S.mobileSearchPanel.hidden||wi(),typeof S.inspirationDialog.showModal==`function`?S.inspirationDialog.showModal():S.inspirationDialog.setAttribute(`open`,``),requestAnimationFrame(()=>{r?S.inspirationBodyInput.focus():S.inspirationTopicInput.focus()})})}function _i(){S.inspirationDialog.open?S.inspirationDialog.close():S.inspirationDialog.removeAttribute(`open`),x.inspirationEditingId=null,hi()}function vi(){x.view=`inspirations`,x.search=``,x.tagFilter=``,S.searchInput.value=``,S.mobileSearchInput.value=``,S.mobileSearchPanel.hidden=!0,S.searchBox.classList.remove(`is-open`),P()}function yi(){let e=ft(S.inspirationTopicInput.value),t=S.inspirationBodyInput.value.trim();if(!e){hi(`先填写灵感所属的主题。`),S.inspirationTopicInput.focus();return}if(!t){hi(`再写下一点灵感内容。`),S.inspirationBodyInput.focus();return}let n=x.inspirationEditingId?Rt().find(e=>e.id===x.inspirationEditingId):null;if(n){let r=Rt().find(t=>t.id!==n.id&&pt(t.topic)===pt(e))?.topic||e;if(n.topic===r&&n.body===t){_i();return}W(`灵感已更新`,()=>{n.topic=r,n.body=t.slice(0,4e3),kr(n)},{undoScope:`inspirations`})}else if(vi(),!Mr({topic:e,body:t})){hi(`灵感保存失败,请重试。`);return}_i()}function bi(e){let t=Rt().find(t=>t.id===e);t&&(W(`灵感已删除`,()=>{t.deletedAt=D(),kr(t)},{undoScope:`inspirations`}),_i())}function xi(){let e=x.inspirationEditingId?Rt().find(e=>e.id===x.inspirationEditingId):null;e&&to(`删除这条灵感`,`删除后会同步到已连接的仓库,可在提示消失前撤销。`,()=>bi(e.id))}function Si(){x.view===`records`?li():x.view===`inspirations`?gi():ai()}function Ci(){S.mobileSearchPanel.hidden=!1,S.mobileSearchInput.value=x.search,Y(),requestAnimationFrame(()=>S.mobileSearchInput.focus())}function wi(e=!0){S.mobileSearchPanel.hidden=!0,e&&(x.search=``,S.mobileSearchInput.value=``,S.searchInput.value=``,H()),Y()}async function Ti(){Oi(),S.repoInput.value=F.repo,S.branchInput.value=F.branch,S.pathInput.value=F.path,S.tokenInput.value=F.token,S.autoSyncInput.checked=F.autoSync,S.settingsError.hidden=!0,S.settingsError.textContent=``,Oa(),Kn(),ki();let e=x.settingsOpen;Ei(!0),!e&&location.hash!==`#settings`&&(history.pushState({jianjiPage:`settings`},``,`#settings`),x.settingsHistoryPushed=!0)}function Ei(e){x.settingsOpen=e,e?(S.settingsPage.open||(typeof S.settingsPage.showModal==`function`?S.settingsPage.showModal():S.settingsPage.setAttribute(`open`,``)),oa()):(S.settingsPage.open?S.settingsPage.close():S.settingsPage.removeAttribute(`open`),Y()),e?(S.mobileSearchPanel.hidden=!0,S.searchBox.classList.remove(`is-open`),S.settingsPageScroll.scrollTop=0):Oi()}function Di(){S.updateTokenInput.value=I.token,Fi(),q(),fa({announce:!1}),S.aboutDialog.open||(typeof S.aboutDialog.showModal==`function`?S.aboutDialog.showModal():S.aboutDialog.setAttribute(`open`,``)),requestAnimationFrame(()=>S.closeAboutIconButton.focus())}function Oi(){S.aboutDialog.open&&S.aboutDialog.close()}async function ki(){if(S.remindersEnabledInput&&S.notificationStatusHint){if(S.remindersEnabledInput.disabled=!0,!me)S.remindersEnabledInput.checked=!1,S.notificationStatusHint.textContent=`电脑端使用应用内提示;Android APK 安装后可开启系统通知`;else try{let e=await xe();x.reminderStatus=e.permission;let t=e.permission===`granted`;S.remindersEnabledInput.checked=e.enabled&&t,S.remindersEnabledInput.disabled=x.reminderUpdating,e.enabled&&t?S.notificationStatusHint.textContent=`已开启 · 截止日当天 09:00`:e.permission===`denied`?S.notificationStatusHint.textContent=`权限已关闭,请在 Android 系统设置中允许简记通知`:S.notificationStatusHint.textContent=`开启后由 Android 弹出通知权限请求`}catch{x.reminderStatus=`error`,S.remindersEnabledInput.checked=!1,S.remindersEnabledInput.disabled=!1,S.notificationStatusHint.textContent=`无法读取通知权限,请稍后重试`}}}async function Ai(){if(!me||x.reminderUpdating){ki();return}x.reminderUpdating=!0,S.remindersEnabledInput.disabled=!0;let e=S.remindersEnabledInput.checked;try{e?(await Se(),await we(x.items),Z(`已开启截止日提醒`,null)):(await Ce(),Z(`已关闭截止日提醒`,null))}catch(e){Z(e instanceof Error?e.message:`通知设置失败`,null)}finally{x.reminderUpdating=!1,ki()}}function ji(){x.settingsOpen&&(Ei(!1),location.hash===`#settings`&&(x.settingsHistoryPushed?(x.settingsHistoryPushed=!1,history.back()):history.replaceState(history.state,``,`${location.pathname}${location.search}`)))}function Mi(){return S.heatmapHelpDialog.open?(Ln(),!0):S.recordDrawer.open?(Fn(),!0):x.statsOpen?(Nn(),!0):S.savePromptDialog.open?(x.draftAfter=null,Zr(),!0):S.confirmDialog.open?(ro(),!0):S.updateDialog.open?(wa(),!0):S.aboutDialog.open?(Oi(),!0):S.createDialog.open?(oi(),!0):S.recordDialog.open?(ui(),!0):S.inspector.open?(ti(),!0):x.openMenuId?(x.openMenuId=null,H(),!0):S.mobileSearchPanel.hidden?x.settingsOpen?(ji(),!0):!1:(wi(),!0)}function Ni(){e&&ue.addListener(`backButton`,({canGoBack:e})=>{Mi()||(e?history.back():ue.exitApp().catch(()=>{}))}).catch(()=>{})}function Pi(){location.hash===`#statistics`?(x.settingsOpen&&Ei(!1),x.statsOpen||(x.statsView=`overview`,x.statsYear=new Date().getFullYear(),x.statsSelectedDate=``,An(!0))):(x.statsOpen&&(An(!1),x.statsHistoryPushed=!1),location.hash===`#settings`?x.settingsOpen||Ti():(x.settingsOpen&&Ei(!1),x.settingsHistoryPushed=!1))}function G(e){S.updateStatusHint.textContent=e}function Fi(){S.aboutUpdateFeedback.hidden=!0,S.aboutUpdateFeedback.textContent=``,S.aboutUpdateFeedback.dataset.tone=``}function Ii(e,t=`error`){S.aboutDialog.open?(S.aboutUpdateFeedback.textContent=e,S.aboutUpdateFeedback.dataset.tone=t,S.aboutUpdateFeedback.hidden=!1):Z(e,null)}function Li(e){let t=[],n=new Date(e.publishedAt);return Number.isNaN(n.getTime())||t.push(`发布于 ${new Intl.DateTimeFormat(`zh-CN`,{year:`numeric`,month:`long`,day:`numeric`}).format(n)}`),e.size>0&&t.push(`${(e.size/1024/1024).toFixed(1)} MB`),t.join(` · `)}function Ri(e){let t=new Date(e);return Number.isNaN(t.getTime())?``:new Intl.DateTimeFormat(`zh-CN`,{year:`numeric`,month:`2-digit`,day:`2-digit`}).format(t)}function zi(e){return String(e||`本次发布未提供更新说明。`).split(/\r?\n/).map(e=>{let t=e.match(/^#{1,6}\s+(.+)$/);if(t)return`<div class="release-note-heading">${L(t[1])}</div>`;let n=e.match(/^\s*[-*]\s+(.+)$/);return n?`<div class="release-note-item">${L(n[1])}</div>`:e.trim()?`<div class="release-note-line">${L(e)}</div>`:`<div class="release-note-gap"></div>`}).join(``)}function K(e){let t=typeof e==`string`?e:e?.version;if(!t)return`same`;let n=je(t,x.updateInfo?.versionName||a);return n>0?`upgrade`:n<0?`downgrade`:`same`}function Bi(e){return{upgrade:`升级`,downgrade:`降级`,same:`重新安装`}[K(e)]}function Vi(e){return Array.isArray(e)?e.filter(e=>e&&/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/.test(String(e.version||``).replace(/^v/i,``))&&typeof e.downloadUrl==`string`&&/^https:\/\//i.test(e.downloadUrl)):[]}function Hi(e){let t=Vi(e);return x.releaseHistory=t,E(d,t),q(),t}function Ui(){return Vi(T(d,[]))}function Wi(){let e=T(p,{});return typeof e.version==`string`?e.version:``}function Gi(e){x.exportedUpdateVersion=e,E(p,{version:e}),da(),q()}function Ki(e){let t=K(e);return t===`upgrade`?{label:`可升级`,className:`is-new`}:t===`same`?{label:`当前版本`,className:`is-current`}:{label:`历史版本`,className:``}}function qi(e){let t=x.updateDownload;if(t?.version===e.version&&t.phase===`downloaded`)return K(e)===`downgrade`?`导出降级包`:`立即安装`;if(t?.version===e.version&&J(t))return`下载中`;let n=K(e);return n===`upgrade`?`直接升级`:n===`downgrade`?`下载降级包`:`重新安装`}function Ji(e){return x.releaseHistory.find(t=>t.version===e)||(x.latestUpdate?.version===e?x.latestUpdate:null)||(x.updateTarget?.version===e?x.updateTarget:null)}function q(){if(!S.updateHistoryList)return;let e=x.updateInfo?.versionName||a;if(S.updateHistoryPanel.hidden=!x.updateHistoryOpen,S.toggleUpdateHistoryButton.textContent=x.updateHistoryOpen?`收起`:`展开`,x.updateHistoryLoading?S.updateHistoryHint.textContent=`正在读取 GitHub Release…`:x.releaseHistory.length?S.updateHistoryHint.textContent=`共 ${x.releaseHistory.length} 个可安装版本 · 当前 v${String(e).replace(/^v/i,``)}`:S.updateHistoryHint.textContent=`查看每个版本的更新内容和安装包`,!x.updateHistoryOpen)return;if(x.updateHistoryLoading&&!x.releaseHistory.length){S.updateHistoryList.innerHTML=`<p class="update-history-empty">正在读取历史版本…</p>`;return}if(!x.releaseHistory.length){S.updateHistoryList.innerHTML=`<p class="update-history-empty">还没有历史版本数据,请先检查更新。</p>`;return}let t=J()?x.updateDownload.version:``;S.updateHistoryList.innerHTML=x.releaseHistory.map(e=>{let n=Ki(e),r=e.notes||`本次发布未提供更新说明。`,i=!!(t&&t!==e.version),a=qi(e);return`
|
|
435
|
-
<article class="version-history-item" data-version="${L(e.version)}">
|
|
436
|
-
<div class="version-history-head">
|
|
437
|
-
<div class="version-history-identity">
|
|
438
|
-
<span class="version-history-version">v${L(String(e.version).replace(/^v/i,``))}</span>
|
|
439
|
-
<span class="version-history-badge ${n.className}">${n.label}</span>
|
|
440
|
-
</div>
|
|
441
|
-
<time class="version-history-date" datetime="${L(e.publishedAt||``)}">${L(Ri(e.publishedAt))}</time>
|
|
442
|
-
</div>
|
|
443
|
-
<div class="version-history-notes">${zi(r)}</div>
|
|
444
|
-
<div class="version-history-actions">
|
|
445
|
-
<button class="quiet-button version-history-action" type="button" data-version-action="details">查看详情</button>
|
|
446
|
-
<button class="secondary-button version-history-action" type="button" data-version-action="install" ${i?`disabled`:``}>${a}</button>
|
|
447
|
-
</div>
|
|
448
|
-
</article>
|
|
449
|
-
`}).join(``)}function Yi(e){x.updateHistoryOpen=!!e,q(),x.updateHistoryOpen&&!x.releaseHistory.length&&!x.updateHistoryLoading&&Xi()}async function Xi({quiet:e=!1}={}){if(x.updateHistoryLoading)return x.releaseHistory;x.updateHistoryLoading=!0,q();try{let e=await Re(o,I.token);return Hi(e),e}catch(t){let n=t instanceof Error?t.message:`历史版本读取失败`;return S.updateHistoryHint.textContent=`历史版本读取失败,可稍后重试`,e||Z(n,null),x.releaseHistory.length||(S.updateHistoryList.innerHTML=`<p class="update-history-empty">无法读取历史版本,请检查网络或 GitHub 令牌。</p>`),x.releaseHistory}finally{x.updateHistoryLoading=!1,q()}}function Zi(e){S.updateError.textContent=e,S.updateError.hidden=!1}function Qi(){S.updateError.textContent=``,S.updateError.hidden=!0}function $i(e){return!e||typeof e!=`object`?null:{version:String(e.version||``),phase:String(e.phase||`idle`),active:!!e.active,bytesDownloaded:Math.max(0,Number(e.bytesDownloaded)||0),totalBytes:Math.max(0,Number(e.totalBytes)||0),percent:Number.isFinite(Number(e.percent))?Number(e.percent):null,error:String(e.error||``),canInstallPackages:!!e.canInstallPackages}}function J(e=x.updateDownload){return!!(e&&(e.active||[`queued`,`downloading`,`verifying`,`retrying`].includes(e.phase)))}function ea(e=x.updateDownload){return e?Number.isFinite(e.percent)?Math.max(0,Math.min(100,e.percent)):e.totalBytes>0?Math.max(0,Math.min(100,e.bytesDownloaded*100/e.totalBytes)):null:null}function ta(e){let t=Number(e||0);return t<1024?`${Math.max(0,Math.round(t))} B`:t<1048576?`${(t/1024).toFixed(1)} KB`:`${(t/1024/1024).toFixed(1)} MB`}function na(e){e?E(u,e):Ee(u,``)}function ra(){let e=T(u,null);return!e||!e.version||!e.downloadUrl?null:e}function ia(){let e=T(f,{});return typeof e.version==`string`?e.version:``}function aa(e){let t=ia();return!!t&&je(e,t)<=0}function oa(){S.updateNotice.hidden=!0,x.updateNoticeVersion=``}function Y(e=x.updateTarget||x.latestUpdate){let t=x.updateDownload,n=t?.phase===`downloaded`?Ji(t.version)||{version:t.version}:null,r=!!(n&&K(n)!==`downgrade`),i=r?n:e;if(!i||x.settingsOpen||!S.mobileSearchPanel.hidden||x.search||J()||r&&x.readyUpdateNoticeDismissedVersion===i.version||!r&&t?.phase===`downloaded`&&t.version===i.version||!r&&aa(i.version)){oa();return}if(r){S.updateNotice.classList.add(`is-ready`),S.updateNoticeIcon?.setAttribute(`href`,`#icon-check`),S.updateNoticeTitle.textContent=`简记 ${i.version} 已下载`,S.updateNoticeDetail.textContent=K(i)===`same`?`安装包已通过校验,点击按钮可重新安装`:`新版本安装包已通过校验,点击按钮完成更新`,S.updateNoticeAction.textContent=`立即更新`,S.updateNotice.hidden=!1,x.updateNoticeVersion=i.version;return}let o=x.updateInfo?.versionName||a,s=t?.phase===`failed`;S.updateNotice.classList.remove(`is-ready`),S.updateNoticeIcon?.setAttribute(`href`,`#icon-download`),S.updateNoticeTitle.textContent=`发现新版本 ${i.version}`,S.updateNoticeDetail.textContent=s?`上次下载未完成,点击重试更新`:`当前 v${String(o).replace(/^v/i,``)},确认后将后台下载`,S.updateNoticeAction.textContent=s?`重试`:`更新`,S.updateNotice.hidden=!1,x.updateNoticeVersion=i.version}function sa(){let e=x.updateNoticeVersion||x.latestUpdate?.version||``;e&&x.updateDownload?.phase===`downloaded`&&x.updateDownload.version===e?x.readyUpdateNoticeDismissedVersion=e:e&&E(f,{version:e}),oa()}function ca(e,t=!1){S.installUpdateButton.disabled=t,S.closeUpdateButton.disabled=!1,S.laterUpdateButton.disabled=!1,S.installUpdateButton.querySelector(`span`).textContent=e;let n=S.installUpdateButton.querySelector(`use`);n&&n.setAttribute(`href`,e===`立即安装`?`#icon-check`:`#icon-download`)}function la(){clearTimeout(x.updatePollTimer),x.updatePollTimer=null}function ua(){la(),Ke()&&J()&&(x.updatePollTimer=setTimeout(()=>{x.updatePollTimer=null,fa({announce:!0})},1e3))}function da(){q();let e=x.updateDownload,t=x.updateTarget||x.latestUpdate,n=J(e),r=e?.phase===`downloaded`,i=e?.phase===`failed`,o=e?.phase===`retrying`,s=ea(e),c=s===null?null:Math.round(s),l=e?.version||t?.version||``,u=Ji(l)||{version:l},d=K(u),f=!!l&&x.exportedUpdateVersion===l,p=!!(t||n||r||i||o);if(S.updateDownloadRow.hidden=!p,S.updateUninstallAction.hidden=!(r&&d===`downgrade`&&f),S.updateProgressTrack.hidden=!p||!n&&!r&&!(i&&e?.bytesDownloaded>0),S.updateProgressBar.style.width=`${s===null?0:s}%`,S.updateProgressTrack.setAttribute(`aria-valuenow`,String(c===null?0:c)),!p){let e=K(t);ca(Ke()?e===`downgrade`?`下载降级包`:e===`same`?`重新安装`:`后台下载`:`前往下载 APK`,!t),x.updateChecking||G(`尚未发现可用更新`),Y();return}if(n){let t=e.phase===`queued`?`等待系统开始下载`:e.phase===`verifying`?`正在校验安装包`:e.phase===`retrying`?`网络中断,等待自动重试${e.error?`:${e.error}`:``}`:c===null?`已下载 ${ta(e.bytesDownloaded)}`:`${c}% · ${ta(e.bytesDownloaded)} / ${ta(e.totalBytes)}`;S.updateDownloadLabel.textContent=`后台下载 ${l}`,S.updateDownloadDetail.textContent=t,S.updateDownloadAction.textContent=`取消`,ca(`后台下载中`,!0),G(`后台下载 ${l} · ${t}`),S.updateDialog.open&&(S.updateDialogCopy.textContent=`正在后台下载 ${l},可以关闭此窗口。`),Y();return}if(r){S.updateDownloadLabel.textContent=`${l} 已下载`,d===`downgrade`?(S.updateDownloadDetail.textContent=f?`降级包已导出;请先卸载当前版本,再从保存位置安装`:`Android 不允许直接覆盖降级,请先导出安装包`,S.updateDownloadAction.textContent=f?`重新导出`:`导出降级包`,ca(f?`卸载当前版本`:`导出降级包`),G(f?`${l} 安装包已导出,可卸载当前版本`:`${l} 已下载,降级前需导出安装包`)):(S.updateDownloadDetail.textContent=`安装包已通过校验,等待系统安装`,S.updateDownloadAction.textContent=`立即安装`,ca(`立即安装`),G(`${l} 已下载,等待安装`)),S.updateDialog.open&&(S.updateDialogCopy.textContent=d===`downgrade`?f?`${l} 降级包已导出。卸载当前版本后,请从保存位置完成安装。`:`${l} 已下载并通过校验。请先导出安装包,再卸载当前版本。`:`${l} 已下载并通过校验,点击立即安装。`),Y();return}if(i){S.updateDownloadLabel.textContent=`${l} 下载失败`,S.updateDownloadDetail.textContent=e.error||`请检查网络后重试`,S.updateDownloadAction.textContent=`重试`,ca(`重试下载`,!t),G(`${l} 下载失败,可重试`),S.updateDialog.open&&(S.updateDialogCopy.textContent=`后台下载暂时失败,可以稍后重试。`),Y();return}S.updateDownloadLabel.textContent=`发现新版本 ${l}`;let ee=Bi(u);if(S.updateDownloadLabel.textContent=`${ee}版本 ${l}`,S.updateDownloadDetail.textContent=d===`downgrade`?`降级包下载后需先导出,再卸载当前版本安装`:`开始后可关闭弹窗,下载会在后台继续`,S.updateDownloadAction.textContent=d===`downgrade`?`下载降级包`:`后台下载`,ca(Ke()?d===`downgrade`?`下载降级包`:d===`same`?`重新安装`:`后台下载`:`前往下载 APK`),G(`${ee}版本 ${l},可后台下载`),S.updateDialog.open){let e=x.updateInfo?.versionName||a;S.updateDialogCopy.textContent=d===`downgrade`?`当前 v${e},可下载 ${l} 降级包。系统不支持直接覆盖降级。`:d===`same`?`当前已安装 v${e},可重新下载并覆盖安装。`:`当前 v${e},可升级到 ${l}。开始后可关闭窗口。`}Y()}async function fa({announce:e=!0}={}){if(!Ke()||x.updateRefreshing)return x.updateDownload;x.updateRefreshing=!0;let t=x.updateDownload;try{let n=$i(await Be());return x.updateDownload=n&&![`idle`,`cancelled`].includes(n.phase)?n:null,da(),e&&x.updateDownload?.phase===`failed`&&t?.phase!==`failed`&&Z(x.updateDownload.error||`后台下载失败,可在设置中重试`,null),x.updateDownload}catch{return e&&G(`无法读取后台下载状态,请稍后重试`),x.updateDownload}finally{x.updateRefreshing=!1,ua()}}function pa(e){if(e.requiresAuth){let e=`私有仓库的 APK 需要在 Android 应用内下载安装。`;return Zi(e),Z(e,null),!1}let t=document.createElement(`a`);return t.href=e.downloadUrl,t.target=`_blank`,t.rel=`noopener noreferrer`,t.click(),Z(`已打开 GitHub 下载页`,null),!0}async function ma(e){if(!e||J())return!1;if(x.updateTarget=e,x.readyUpdateNoticeDismissedVersion=``,Qi(),!Ke())return pa(e);G(`正在创建 ${e.version} 的后台下载任务`);try{let t=await ze(e,I.token);return x.updateDownload=$i(t),da(),wa(),Z(`已开始后台下载,完成后会在首页提示更新`,null),ua(),!0}catch(e){let t=e instanceof Error?e.message:`无法开始后台下载,请稍后重试`;return Zi(t),G(`无法开始后台下载,可重试`),S.updateDialog.open||Z(t,null),!1}}async function ha(){if(!S.updateNoticeAction.disabled){if(x.updateDownload?.phase===`downloaded`){S.updateNoticeAction.disabled=!0,S.updateNoticeAction.textContent=`正在打开…`;try{await ya()}finally{S.updateNoticeAction.disabled=!1,S.updateNotice.hidden||(S.updateNoticeAction.textContent=`立即更新`)}}else if(x.latestUpdate){S.updateNoticeAction.disabled=!0,S.updateNoticeAction.textContent=`准备中…`;try{await ma(x.latestUpdate)&&oa()}finally{S.updateNoticeAction.disabled=!1,S.updateNotice.hidden||(S.updateNoticeAction.textContent=x.updateDownload?.phase===`failed`?`重试`:`更新`)}}}}async function ga(){if(J())try{let e=await We();x.updateDownload=$i(e),la(),da(),Z(`已取消后台下载`,null)}catch(e){Z(e instanceof Error?e.message:`取消下载失败,请稍后重试`,null)}}async function _a(){let e=x.updateDownload;if(e?.phase!==`downloaded`||K(e.version)!==`downgrade`)return!1;Qi();try{return(await He())?.exported?(Gi(e.version),G(`${e.version} 降级包已导出,可卸载当前版本`),Z(`降级包已导出;卸载当前版本后,请从保存位置安装`,null),!0):(G(`已取消导出,降级包仍保留在应用内`),!1)}catch(e){let t=e instanceof Error?e.message:`导出降级包失败,请重试`;return Zi(t),G(`导出降级包失败,可重试`),S.updateDialog.open||Z(t,null),!1}}function va(){let e=x.updateDownload;e&&e.phase===`downloaded`&&K(e.version)===`downgrade`&&(x.exportedUpdateVersion===e.version?to(`卸载当前版本并安装降级包`,`系统不允许直接覆盖安装低版本,必须卸载当前版本的简记。卸载会清除本机数据;如已配置 Gitee 同步,重装后可恢复。请确认降级包已保存到可访问位置。`,async()=>{try{await Ue(),G(`已打开系统卸载页面,卸载后请安装导出的降级包`)}catch(e){let t=e instanceof Error?e.message:`无法打开系统卸载页面`;Zi(t),Z(t,null)}}):_a())}async function ya(){let e=x.updateDownload,t=e?.phase===`downloaded`?Ji(e.version)||{version:e.version}:x.updateTarget||x.latestUpdate;if(!J(e)){if(!t)await Da({manual:!0,prompt:`dialog`});else if(e?.phase!==`downloaded`||e.version!==t.version)await ma(t);else if(K(t)===`downgrade`)x.exportedUpdateVersion===e.version?va():_a();else{Qi();try{await Ve(),G(`${e.version} 安装包已就绪,等待系统安装`),Z(`请按系统提示完成安装`,null)}catch(t){let n=t?.code||t?.data?.code;if(n===`INSTALL_PERMISSION_REQUIRED`)try{await Ge(),Zi(`请在系统页面允许“简记”安装应用,然后返回并点击“立即安装”。`),G(`等待开启安装未知应用权限`)}catch{Zi(`无法打开安装权限设置,请在 Android 系统设置中允许简记安装未知应用。`)}else if(n===`DOWNGRADE_REQUIRES_UNINSTALL`)Zi(`Android 不允许直接覆盖安装低版本,请先导出降级包并卸载当前版本。`),G(`${e.version} 安装包已下载,等待导出降级包`);else{let e=t instanceof Error?t.message:`无法启动系统安装器,请重试`;Zi(e),G(`安装包已下载,可重新尝试安装`),S.updateDialog.open||Z(e,null)}}}}}function ba(){if(!J())return ya()}function xa(){let e=x.updateDownload;if(J(e))return ga();if(e?.phase===`downloaded`)return K(e.version)===`downgrade`?x.exportedUpdateVersion===e.version?va():_a():ya();let t=x.updateTarget||x.latestUpdate;return t?ma(t):Da({manual:!0})}async function Sa(e){let t=e.target.closest(`[data-version-action]`);if(!t)return;let n=Ji(t.closest(`[data-version]`)?.dataset.version||``);if(!n){Z(`无法找到该历史版本,请刷新后重试`,null);return}if(t.dataset.versionAction===`details`){Ca(n);return}if(t.dataset.versionAction!==`install`)return;x.updateTarget=n;let r=x.updateDownload;r?.version===n.version&&r.phase===`downloaded`?await ya():await ma(n)}function Ca(e){if(!e)return;Oi(),x.updateTarget=e;let t=x.updateInfo?.versionName||a,n=K(e);S.updateDialogTitle.textContent=n===`upgrade`?`发现新版本`:`版本详情`,S.updateDialogCopy.textContent=n===`upgrade`?`当前 v${t},可升级到 ${e.version}。`:n===`downgrade`?`当前 v${t},${e.version} 为较低版本。Android 需要先卸载当前版本才能降级安装。`:`当前已安装 v${t},可重新下载并覆盖安装。`,S.updateReleaseVersion.textContent=e.version,S.updateReleaseMeta.textContent=Li(e),S.updateReleaseNotes.innerHTML=zi(e.notes),Qi(),da(),S.updateDialog.open||(typeof S.updateDialog.showModal==`function`?S.updateDialog.showModal():S.updateDialog.setAttribute(`open`,``))}function wa(){S.updateDialog.open&&S.updateDialog.close()}async function Ta(){let e=await Pe(a);x.updateInfo=e,x.releaseHistory=Ui(),x.exportedUpdateVersion=Wi(),S.updateTokenInput.value=I.token;let t=`v${String(e.versionName).replace(/^v/i,``)}`;S.appVersionLabel.textContent=`当前版本 ${t}`,S.aboutVersionLabel.textContent=t;let n=ra();if(x.latestUpdate=n&&je(n.version,e.versionName)>0?n:null,x.latestUpdate||na(null),await fa({announce:!1}),x.updateDownload?.version&&je(e.versionName,x.updateDownload.version)===0){try{await We()}catch{}x.updateDownload=null}q(),da(),!x.latestUpdate&&!x.updateDownload&&(Ke()&&!e.nativeInstaller?G(`此版本需手动安装一次,以启用应用内更新`):Ke()?G(`启动时会自动检查 GitHub Release`):G(`发现新版后可下载 Android APK`))}function Ea(){return _t({token:S.updateTokenInput.value}),Da({manual:!0,prompt:`dialog`})}async function Da({manual:e=!1,prompt:t=e?`dialog`:`notice`}={}){if(x.updateChecking)return null;if(e&&Fi(),!navigator.onLine)return G(`当前离线,联网后可检查更新`),e&&Ii(`当前离线,无法检查更新`,`error`),null;x.updateChecking=!0,S.checkUpdateButton.disabled=!0,S.checkUpdateButton.textContent=`检查中…`,e&&G(`正在检查 GitHub Release`);try{let n=await Re(o,I.token);Hi(n),e&&(x.updateHistoryOpen=!0,q());let r=n[0],i=x.updateInfo?.versionName||a;return je(r.version,i)<=0?(x.latestUpdate=null,x.updateTarget=null,na(null),oa(),da(),x.updateDownload||G(`已是最新版本`),e&&Ii(`当前已是最新版本 v${String(i).replace(/^v/i,``)}`,`success`),null):(x.latestUpdate=r,x.updateTarget=r,na(r),da(),t===`dialog`?Ca(r):t===`notice`&&Y(r),r)}catch(t){let n=t instanceof Error?t.message:`检查更新失败,请稍后重试`;return x.updateDownload?da():G(I.token?`令牌已保存,但 Release 检查失败`:/未找到|无法访问/.test(n)?`私有仓库请填写 GitHub 只读令牌`:`检查更新失败,可稍后重试`),e&&Ii(n,`error`),null}finally{x.updateChecking=!1,S.checkUpdateButton.disabled=!1,S.checkUpdateButton.textContent=`检查更新`}}function Oa(){if(!F.repo){S.settingsSyncMeta.textContent=`尚未连接仓库`,S.disconnectButton.disabled=!0;return}let e=x.lastSyncedAt?new Intl.DateTimeFormat(`zh-CN`,{hour:`2-digit`,minute:`2-digit`}).format(new Date(x.lastSyncedAt)):`尚未完成`;S.settingsSyncMeta.textContent=`上次同步:${e}`,S.disconnectButton.disabled=!1}function ka(e){let t=e.trim().replace(/\.git$/,``).replace(/\/$/,``),n=t.match(/gitee\.com[/:]([^/]+)\/([^/]+)/i);if(n)return{owner:n[1],repo:n[2]};let r=t.match(/^([^/\s]+)\/([^/\s]+)$/);return r?{owner:r[1],repo:r[2]}:null}function Aa(e){return ka(e.repo)?!/^[^\s]+$/.test(e.branch)||e.branch.includes(`..`)?`请填写有效的分支名称。`:!/^[^/].*\.json$/i.test(e.path)||e.path.includes(`..`)?`数据文件必须是仓库内的 JSON 路径。`:e.token?``:`请填写 Gitee 私人令牌。`:`请填写有效的 Gitee 仓库地址。`}async function ja(){let e={repo:S.repoInput.value.trim(),branch:S.branchInput.value.trim()||`master`,path:S.pathInput.value.trim().replace(/^\/+/,``)||`todos.json`,token:S.tokenInput.value.trim(),autoSync:S.autoSyncInput.checked},t=Aa(e);t?Ma(t):(vt(e),S.settingsError.hidden=!0,await Za({manual:!0}),x.syncState!==`error`&&ji())}function Ma(e){S.settingsError.textContent=e,S.settingsError.hidden=!1}function Na(){to(`断开 Gitee 仓库`,`本机待办不会被删除,之后仍可重新连接并继续同步。`,()=>{vt({repo:``,branch:`master`,path:`todos.json`,token:``,autoSync:!0}),X(`local`,`仅保存在本机`),Oa(),S.repoInput.value=``,S.tokenInput.value=``,ji(),Z(`已断开仓库,本机数据仍保留`,null)})}function X(e,t){x.syncState=e,x.syncMessage=t,Pa(),Oa()}function Pa(){let e=x.syncMessage,t=``;F.repo?navigator.onLine?x.syncState===`syncing`?(e=`正在同步`,t=`is-syncing`):x.syncState===`synced`?(e=x.dirty?`有修改待同步`:`已同步`,t=`is-synced`):x.syncState===`error`?(e=`同步失败`,t=`is-error`):e=`已连接`:(e=`离线,修改待同步`,t=`is-error`):e=`仅保存在本机`,S.desktopSyncLabel.textContent=e,S.syncButton.setAttribute(`aria-label`,`同步状态:${e},点击立即同步`),S.desktopSyncDot.className=`sync-dot ${t}`,S.mobileSyncButton.className=`mobile-sync ${t}`,S.mobileSyncButton.setAttribute(`aria-label`,`同步状态:${e},点击立即同步`),S.mobileSyncButton.title=e,S.mobileSyncBadge.hidden=t!==`is-error`}function Fa(e){let t=new TextEncoder().encode(e),n=``;for(let e=0;e<t.length;e+=8192)n+=String.fromCharCode(...t.subarray(e,e+8192));return btoa(n)}function Ia(e){let t=atob(e.replace(/\s/g,``)),n=Uint8Array.from(t,e=>e.charCodeAt(0));return new TextDecoder().decode(n)}function La(e,t,n=!1){let r=ka(F.repo);if(!r)throw Error(`仓库地址无效`);let i=e.split(`/`).map(encodeURIComponent).join(`/`),a=n?`&_=${Date.now()}`:``;return`repos/${encodeURIComponent(r.owner)}/${encodeURIComponent(r.repo)}/contents/${i}?ref=${encodeURIComponent(t)}${a}`}async function Ra(n,r={},i=F.branch){let a;if(e){let e=`https://gitee.com/api/v5/${n}`;try{let t=await te.request({url:e,method:r.method||`GET`,headers:{Accept:`application/json`,Authorization:`token ${F.token}`,...r.body?{"Content-Type":`application/json`}:{}},data:r.body||void 0}),n=typeof t.data==`string`?t.data:JSON.stringify(t.data??``);a=new Response(n,{status:t.status,headers:t.headers||{}})}catch{throw Error(`无法连接 Gitee,请检查网络与仓库权限`)}}else{let e=[`localhost`,`127.0.0.1`,`::1`].includes(location.hostname),i=t?new URL(`../api/gitee/`,location.href).href:e?`/api/gitee/`:`https://gitee.com/api/v5/`;a=await fetch(`${i}${n}`,{method:r.method||`GET`,cache:`no-store`,headers:{Accept:`application/json`,Authorization:`token ${F.token}`,...r.body?{"Content-Type":`application/json`}:{}},body:r.body?JSON.stringify(r.body):void 0})}if(a.status===401||a.status===403)throw Error(`令牌无效或没有该仓库的读写权限`);if(!a.ok&&a.status!==404){let e=``;try{let t=await a.json();e=t.message||t.error||``}catch{}let t=Error(e||`Gitee 请求失败(${a.status})`);throw t.giteeStatus=a.status,t}return a}async function za({cacheBust:e=!1}={}){let t=await Ra(La(F.path,F.branch,e));if(t.status===404||t.status===204)return{exists:!1,data:null,sha:``};let n=await t.text();if(!n.trim())return{exists:!1,data:null,sha:``};let r;try{r=JSON.parse(n)}catch{throw Error(`远端数据文件返回内容无法解析`)}if(Array.isArray(r)){if(!r.length)return{exists:!1,data:null,sha:``};throw Error(`远端路径指向目录,请填写 JSON 文件路径`)}if(!r||typeof r!=`object`)throw Error(`远端数据文件格式不正确`);let i=typeof r.sha==`string`?r.sha:``;if(Number(r.size)===0||Object.hasOwn(r,`content`)&&typeof r.content==`string`&&!r.content.trim())return{exists:!1,data:null,sha:i};if(typeof r.content!=`string`)throw Error(`远端数据文件格式不正确`);let a;try{a=Ia(r.content).trim()}catch{throw Error(`远端数据文件无法解码,请先检查数据文件`)}if(!a)return{exists:!1,data:null,sha:i};let o;try{o=JSON.parse(a)}catch{throw Error(`远端 JSON 无法解析,请先检查数据文件`)}if(!o||!Array.isArray(o.items))throw Error(`远端数据缺少待办列表`);return{exists:!0,data:o,sha:i}}function Ba(e){let t=e&&e.message?e.message:``;return/文件名已存在|文件已存在|already exists|file exists/i.test(t)}async function Va(){let e=await za({cacheBust:!0});for(let t of re){if(e.sha)return e;await Xe(t),e=await za({cacheBust:!0})}return e}async function Ha(e){let t=ka(F.repo);if(!t)throw Error(`仓库地址无效`);let n=F.path.split(`/`).map(encodeURIComponent).join(`/`),r={content:Fa(JSON.stringify({schemaVersion:6,revision:Date.now(),updatedAt:D(),items:x.items,records:x.records,inspirations:x.inspirations,commonTags:x.commonTags,commonTagRecords:x.commonTagRecords,commonTagsUpdatedAt:x.commonTagsUpdatedAt,commonTagsDeviceId:x.commonTagsDeviceId},null,2)),message:`update todos ${new Date().toISOString()}`,branch:F.branch};e&&(r.sha=e);let i=await Ra(`repos/${encodeURIComponent(t.owner)}/${encodeURIComponent(t.repo)}/contents/${n}`,{method:e?`PUT`:`POST`,body:r});if(!i.ok)throw Error(`写入仓库失败(${i.status})`)}function Ua(e,t){let n=new Date(e.updatedAt||0).getTime(),r=new Date(t.updatedAt||0).getTime();return n===r?String(e.deviceId||``).localeCompare(String(t.deviceId||``)):n-r}function Wa(e,t){let n=new Map;[...t,...e].filter(ot).map(ct).forEach(e=>{let t=n.get(e.id);(!t||Ua(e,t)>0)&&n.set(e.id,e)});let r=Date.now()-m;return[...n.values()].filter(e=>!e.deletedAt||new Date(e.deletedAt).getTime()>r)}function Ga(e,t){let n=new Map;[...t,...e].filter(lt).map(ut).forEach(e=>{let t=n.get(e.id);(!t||Ua(e,t)>0)&&n.set(e.id,e)});let r=Date.now()-m;return[...n.values()].filter(e=>!e.deletedAt||new Date(e.deletedAt).getTime()>r)}function Ka(e,t){let n=new Map;[...t,...e].filter(dt).map(mt).forEach(e=>{let t=n.get(e.id);(!t||Ua(e,t)>0)&&n.set(e.id,e)});let r=Date.now()-m;return[...n.values()].filter(e=>!e.deletedAt||new Date(e.deletedAt).getTime()>r)}function qa(e){let t=M(x.commonTags,50),n=M(e?.commonTags,50),r=N(x.commonTagRecords),i=N(e?.commonTagRecords),a=String(e?.commonTagsUpdatedAt||``),o=String(e?.commonTagsDeviceId||``),s=N([...i,...tt(n,a,o),...r,...tt(t,x.commonTagsUpdatedAt,x.commonTagsDeviceId)]),c=s.reduce((e,t)=>e?Ua(t,e)>0?t:e:t,null);return{commonTags:nt(s),commonTagRecords:s,commonTagsUpdatedAt:c?.updatedAt||``,commonTagsDeviceId:c?.deviceId||``}}function Ja(e){return N(e).sort((e,t)=>j(e.value).localeCompare(j(t.value),`zh-CN`))}function Ya(e){return{items:e?.items||[],records:e?.records||[],inspirations:e?.inspirations||[],commonTags:M(e?.commonTags,50).sort((e,t)=>j(e).localeCompare(j(t),`zh-CN`)),commonTagRecords:Ja(e?.commonTagRecords),commonTagsUpdatedAt:String(e?.commonTagsUpdatedAt||``),commonTagsDeviceId:String(e?.commonTagsDeviceId||``)}}function Xa(e){let t=qa(e.data);return{items:Wa(x.items,e.data?e.data.items:[]),records:Ga(x.records,e.data&&Array.isArray(e.data.records)?e.data.records:[]),inspirations:Ka(x.inspirations,e.data&&Array.isArray(e.data.inspirations)?e.data.inspirations:[]),...t}}async function Za({manual:e=!1}={}){if(x.syncing)x.syncQueued=!0;else if(!F.repo||!F.token)e&&Ti(),X(`local`,`仅保存在本机`);else if(!navigator.onLine)X(`error`,`当前离线,恢复网络后会自动同步`),e&&Z(`当前离线,修改已保存在本机`,null);else{x.syncing=!0,X(`syncing`,`正在同步`);try{let t=await za({cacheBust:!0}),n=Xa(t),r=x.dirty,i=JSON.stringify(Ya(n)),a=t.exists?JSON.stringify(Ya(t.data)):``,o=!t.exists||r||i!==a;x.items=n.items,x.records=n.records,x.inspirations=n.inspirations,x.commonTags=n.commonTags,x.commonTagRecords=n.commonTagRecords,x.commonTagsUpdatedAt=n.commonTagsUpdatedAt,x.commonTagsDeviceId=n.commonTagsDeviceId,o?Tr(!0):(x.dirty=!1,Tr(!1));let s=t.sha,c=0;for(;o&&c<4;)try{await Ha(s),x.dirty=!1;break}catch(e){if(c+=1,c>=4)throw e;if(t=Ba(e)?await Va():await za({cacheBust:!0}),n=Xa(t),x.items=n.items,x.records=n.records,x.inspirations=n.inspirations,x.commonTags=n.commonTags,x.commonTagRecords=n.commonTagRecords,x.commonTagsUpdatedAt=n.commonTagsUpdatedAt,x.commonTagsDeviceId=n.commonTagsDeviceId,s=t.sha,t.exists&&JSON.stringify(Ya(n))===JSON.stringify(Ya(t.data))){x.dirty=!1;break}}x.lastSyncedAt=D(),Tr(!1),X(`synced`,`已同步`),U(),e&&Z(`同步完成`,null)}catch(t){let n=t&&t.message?t.message:`同步失败,请稍后重试`,r=Ba(t)?`远端数据文件已存在,但暂时无法读取,请稍后重试`:/failed to fetch|networkerror|load failed/i.test(n)?`无法连接 Gitee,请检查网络与仓库权限`:n;X(`error`,r),e&&Z(r,null)}finally{x.syncing=!1,x.syncQueued&&(x.syncQueued=!1,$a())}}}let Qa=null;function $a(){F.repo&&F.token&&F.autoSync&&navigator.onLine&&(clearTimeout(Qa),Qa=setTimeout(()=>Za(),1200))}function Z(e,t){clearTimeout(x.toastTimer),clearTimeout(x.toastExitTimer),S.toastMessage.textContent=e,x.undo=t,S.toastAction.hidden=typeof t!=`function`,S.toast.hidden=!1,S.toast.classList.remove(`is-visible`,`is-leaving`),S.toast.offsetWidth,S.toast.classList.add(`is-visible`),x.toastTimer=setTimeout(eo,t?6e3:3600)}function eo(){S.toast.hidden||(clearTimeout(x.toastTimer),clearTimeout(x.toastExitTimer),S.toast.classList.remove(`is-visible`),S.toast.classList.add(`is-leaving`),x.toastExitTimer=setTimeout(()=>{S.toast.hidden=!0,S.toast.classList.remove(`is-leaving`),x.undo=null},280))}function to(e,t,n,r={}){S.confirmTitle.textContent=e,S.confirmMessage.textContent=t,S.confirmCancelButton.textContent=r.cancelLabel||`取消`,S.confirmAcceptButton.textContent=r.acceptLabel||`确认`,S.confirmCancelButton.className=r.cancelTone===`quiet`?`quiet-button`:`secondary-button`,S.confirmAcceptButton.className=r.acceptTone===`primary`?`primary-button`:`danger-button`,x.confirmCallback=n,x.confirmCancelCallback=r.onCancel||null,typeof S.confirmDialog.showModal==`function`?(S.confirmDialog.showModal(),requestAnimationFrame(()=>S.confirmCancelButton.focus())):S.confirmDialog.setAttribute(`open`,``)}function no(e){let t=e?x.confirmCallback:x.confirmCancelCallback;x.confirmCallback=null,x.confirmCancelCallback=null,S.confirmDialog.open?S.confirmDialog.close():S.confirmDialog.removeAttribute(`open`),S.confirmCancelButton.textContent=`取消`,S.confirmAcceptButton.textContent=`确认`,S.confirmCancelButton.className=`secondary-button`,S.confirmAcceptButton.className=`danger-button`,typeof t==`function`&&t()}function ro(){no(!1)}function io(){no(!0)}function ao(){x.deferredInstallPrompt?(x.deferredInstallPrompt.prompt(),x.deferredInstallPrompt.userChoice.finally(()=>{x.deferredInstallPrompt=null,oo()})):Z(/iphone|ipad|ipod/i.test(navigator.userAgent)?`在 Safari 分享菜单中选择“添加到主屏幕”`:`请使用浏览器菜单中的“安装应用”或“添加到主屏幕”`,null)}function oo(){let t=window.innerWidth<=760&&!e&&(!!x.deferredInstallPrompt||/iphone|ipad|ipod/i.test(navigator.userAgent));S.mobileInstallButton.hidden=!t}function so(e){Xr(()=>{z().find(t=>t.id===e)?(x.view=`all`,x.search=``,x.tagFilter=``,S.searchInput.value=``,S.mobileSearchInput.value=``,x.selectedId=e,P(),U(),ei()):Z(`提醒对应的待办已被删除`,null)})}let co=``,lo=0;function uo(e){let t=``;try{let n=new URL(e);n.protocol===`com.jianji.todo:`&&n.hostname===`task`&&(t=decodeURIComponent(n.pathname.replace(/^\/+/,``)))}catch{}if(!t)return;let n=Date.now();t===co&&n-lo<2500||(co=t,lo=n,so(t))}function fo(){e&&(ue.addListener(`appUrlOpen`,({url:e})=>{uo(e)}).catch(()=>{}),ue.getLaunchUrl().then(e=>uo(e&&e.url)).catch(()=>{}))}function po(e){x.openMenuId=x.openMenuId===e?null:e,H(),x.openMenuId&&requestAnimationFrame(()=>{let t=document.querySelector(`.task-row[data-id="${CSS.escape(e)}"]`),n=t&&t.querySelector(`[data-action='toggle-row-menu']`);n&&n.focus()})}function mo(e,t){requestAnimationFrame(()=>{let n=document.querySelector(`.task-row[data-id="${CSS.escape(e)}"]`),r=n?n.querySelector(t):null;r?r.focus():window.innerWidth<=760?S.mobileCreateButton.focus():S.desktopCreateButton.focus()})}document.querySelectorAll(`[data-view]`).forEach(e=>{e.addEventListener(`click`,()=>qr(e.dataset.view))}),S.statusFilter.addEventListener(`click`,e=>{let t=e.target.closest(`[data-filter-view]`);t&&Jr(t.dataset.filterView)}),S.tagFilter.addEventListener(`click`,e=>{let t=e.target.closest(`[data-tag-filter]`);t&&Gn(t.dataset.tagFilter||``)});let Q=null,ho=null,go=0,_o=window.matchMedia(`(prefers-reduced-motion: reduce)`);function vo(e){let t=he.indexOf(x.view);if(t<0)return{direction:``,view:``};let n=e<0?`next`:`prev`,r=n===`next`?t+1:t-1;return{direction:n,view:he[r]||``}}function yo(){clearTimeout(ho),S.taskGroups.classList.remove(`is-swiping`);let e=_o.matches?0:320;S.taskGroups.style.transition=`transform ${e}ms cubic-bezier(.22,.85,.24,1), opacity ${Math.min(160,e)}ms ease-out`,S.taskGroups.style.transform=`translate3d(0, 0, 0) scale(1)`,S.taskGroups.style.opacity=`1`,ho=setTimeout(()=>{S.taskGroups.style.transition=``,S.taskGroups.style.transform=``,S.taskGroups.style.opacity=``},e+20)}function bo(e,t){clearTimeout(ho),S.taskGroups.classList.remove(`is-swiping`);let n=_o.matches?0:180,r=_o.matches?0:Math.max(120,n-40),i=Math.min(150,window.innerWidth*.36),a=t===`next`?-1:1;S.taskGroups.style.transition=`transform ${n}ms cubic-bezier(.4,0,.8,.2), opacity ${r}ms ease-in`,S.taskGroups.style.transform=`translate3d(${a*i}px, 0, 0) scale(.99)`,S.taskGroups.style.opacity=`0`,ho=setTimeout(()=>{S.taskGroups.style.transition=``,S.taskGroups.style.transform=``,S.taskGroups.style.opacity=``,qr(e,t)},n+10)}function xo(){clearTimeout(ho),S.taskGroups.classList.remove(`is-swiping`),S.taskGroups.style.transition=``,S.taskGroups.style.transform=``,S.taskGroups.style.opacity=``}S.taskScroll.addEventListener(`touchstart`,e=>{e.touches.length===1?e.target.closest(`[data-drag-handle],.row-menu-wrap,.tag-filter-wrap`)?Q=null:(xo(),Q={x:e.touches[0].clientX,y:e.touches[0].clientY,startedAt:Date.now(),active:!1,vertical:!1,offset:0}):Q=null},{passive:!0}),S.taskScroll.addEventListener(`touchmove`,e=>{if(!Q||Q.vertical||e.touches.length!==1)return;let t=e.touches[0].clientX-Q.x,n=e.touches[0].clientY-Q.y;if(!Q.active){if(Math.abs(t)<8&&Math.abs(n)<8)return;if(Math.abs(n)>Math.abs(t)*1.12){Q.vertical=!0;return}Q.active=!0,S.taskGroups.classList.add(`is-swiping`)}e.preventDefault();let r=vo(t).view?.92:.14,i=Math.min(132,window.innerWidth*.34),a=Math.max(-i,Math.min(i,t*r));Q.offset=a;let o=Math.min(1,Math.abs(a)/i);S.taskGroups.style.transform=`translate3d(${a}px, 0, 0) scale(${1-o*.006})`,S.taskGroups.style.opacity=String(1-o*.06)},{passive:!1}),S.taskScroll.addEventListener(`touchend`,e=>{let t=Q;if(Q=null,!t||!t.active||e.changedTouches.length!==1){yo();return}let n=e.changedTouches[0].clientX-t.x,r=Date.now()-t.startedAt,i=Math.min(82,Math.max(54,window.innerWidth*.16)),a=vo(n),o=!!a.view&&(Math.abs(n)>=i||r<320&&Math.abs(n)>=34);go=Date.now()+380,o?bo(a.view,a.direction):yo()},{passive:!1}),S.taskScroll.addEventListener(`touchcancel`,()=>{Q=null,yo()}),S.searchInput.addEventListener(`input`,()=>{x.search=S.searchInput.value,S.mobileSearchInput.value=x.search,H(),Y()}),S.searchInput.addEventListener(`keydown`,e=>{e.key===`Escape`&&(S.searchInput.value=``,S.mobileSearchInput.value=``,x.search=``,S.searchBox.classList.remove(`is-open`),H(),Y(),S.desktopCreateButton.focus())}),S.mobileSearchButton.addEventListener(`click`,()=>{S.mobileSearchPanel.hidden?Ci():wi()}),S.mobileSearchClose.addEventListener(`click`,()=>wi()),S.mobileSearchInput.addEventListener(`input`,()=>{x.search=S.mobileSearchInput.value,S.searchInput.value=x.search,H(),Y()}),S.mobileSearchInput.addEventListener(`keydown`,e=>{e.key===`Escape`&&wi()}),S.mobileCreateButton.addEventListener(`click`,ai),S.mobileRecordButton.addEventListener(`click`,()=>li()),S.mobileInspirationButton.addEventListener(`click`,()=>gi()),S.desktopCreateButton.addEventListener(`click`,Si),[S.createCloseButton,S.createCancelButton].forEach(e=>{e.addEventListener(`click`,oi)}),S.createTaskForm.addEventListener(`submit`,e=>{e.preventDefault(),si()}),S.createSaveButton.addEventListener(`click`,si),S.createTagList.addEventListener(`click`,e=>{jo(e)}),S.createTagList.addEventListener(`keydown`,e=>{Mo(e)}),[S.createTitleInput,S.createBodyInput].forEach(e=>{e.addEventListener(`input`,()=>{S.createTaskError.hidden=!0})}),[S.recordCloseButton,S.recordCancelButton].forEach(e=>{e.addEventListener(`click`,ui)}),S.recordForm.addEventListener(`submit`,e=>{e.preventDefault(),fi()}),S.recordSaveButton.addEventListener(`click`,fi),S.recordDeleteButton.addEventListener(`click`,mi),[S.recordTitleInput,S.recordBodyInput].forEach(e=>{e.addEventListener(`input`,()=>ci())}),S.recordDialog.addEventListener(`cancel`,e=>{e.preventDefault(),ui()}),[S.inspirationCloseButton,S.inspirationCancelButton].forEach(e=>{e.addEventListener(`click`,_i)}),S.inspirationForm.addEventListener(`submit`,e=>{e.preventDefault(),yi()}),S.inspirationSaveButton.addEventListener(`click`,yi),S.inspirationDeleteButton.addEventListener(`click`,xi),[S.inspirationTopicInput,S.inspirationBodyInput].forEach(e=>{e.addEventListener(`input`,()=>hi())}),S.inspirationDialog.addEventListener(`cancel`,e=>{e.preventDefault(),_i()}),S.sortSelect.addEventListener(`change`,()=>{x.sort=xt(S.sortSelect),P(),H()}),document.addEventListener(`click`,e=>{let t=e.target.closest(`[data-picker-type]`);t&&!t.disabled&&(e.preventDefault(),At(t))}),document.addEventListener(`keydown`,e=>{let t=e.target.closest(`[data-picker-type]`);t&&[`ArrowDown`,`ArrowUp`].includes(e.key)&&(e.preventDefault(),At(t))}),S.appPickerClose.addEventListener(`click`,jt),S.appPicker.addEventListener(`cancel`,e=>{e.preventDefault(),jt()}),S.appPicker.addEventListener(`close`,()=>{let e=v?.trigger;e&&e.setAttribute(`aria-expanded`,`false`),v=null,requestAnimationFrame(()=>{e?.isConnected&&e.focus()})}),S.appPicker.addEventListener(`click`,e=>{if(e.target===S.appPicker){jt();return}let t=e.target.closest(`[data-picker-month]`);if(t){Nt(Number(t.dataset.pickerMonth));return}let n=e.target.closest(`[data-picker-value]`);if(n){Mt(n.dataset.pickerValue);return}if(e.target.closest(`[data-picker-clear]`)){Mt(``);return}let r=e.target.closest(`[data-picker-date]`);r&&Mt(r.dataset.pickerDate)}),S.appPicker.addEventListener(`keydown`,e=>{let t=[...S.appPickerBody.querySelectorAll(`[data-picker-value]`)];if(t.length&&[`ArrowDown`,`ArrowUp`,`Home`,`End`].includes(e.key)){e.preventDefault();let n=Math.max(0,t.indexOf(document.activeElement)),r=n;e.key===`ArrowDown`&&(r=Math.min(t.length-1,n+1)),e.key===`ArrowUp`&&(r=Math.max(0,n-1)),e.key===`Home`&&(r=0),e.key===`End`&&(r=t.length-1),t[r].focus();return}let n=e.target.closest(`[data-picker-date]`);if(!n||![`ArrowLeft`,`ArrowRight`,`ArrowUp`,`ArrowDown`].includes(e.key))return;e.preventDefault();let r=e.key===`ArrowLeft`?-1:e.key===`ArrowRight`?1:e.key===`ArrowUp`?-7:7,i=Qt(k(n.dataset.pickerDate),r);S.appPickerBody.querySelector(`[data-picker-date="${O(i)}"]`)?.focus()}),S.layoutToggle.addEventListener(`click`,()=>{x.mobileLayout=x.mobileLayout===`cards`?`list`:`cards`,P(),H()}),S.taskGroups.addEventListener(`click`,e=>{if(Date.now()<go){e.preventDefault(),e.stopImmediatePropagation();return}let t=e.target.closest(`[data-action='create-inspiration'],[data-action='add-inspiration'],[data-action='open-inspiration']`);if(t){let e=t.dataset.action;e===`create-inspiration`&&gi(),e===`add-inspiration`&&gi({topic:t.dataset.topic||``}),e===`open-inspiration`&&gi({id:t.dataset.inspirationId||``});return}let n=e.target.closest(`[data-action='open-record'],[data-action='create-record']`);if(n){n.dataset.action===`create-record`?li():li(n.dataset.recordId);return}let r=e.target.closest(`[data-action='toggle-lane-mosaic']`);if(r){let e=r.dataset.status;x.mosaicLanes.has(e)?x.mosaicLanes.delete(e):x.mosaicLanes.add(e),P(),H(),requestAnimationFrame(()=>{document.querySelector(`[data-action="toggle-lane-mosaic"][data-status="${e}"]`)?.focus()});return}let i=e.target.closest(`.task-row`);if(!i)return;let a=i.dataset.id,o=e.target.closest(`[data-action]`);if(o){let e=o.dataset.action;e===`select-task`&&Yr(a),e===`toggle-row-menu`&&po(a);return}let s=e.target.closest(`[data-menu-action]`);if(s){let e=s.dataset.menuAction;if(e===`dispatch`){x.openMenuId=null,H(),Ir(a);return}e===`status`&&Pr(a,s.dataset.status),e===`toggle-pin`&&Hr(a),e===`delete`&&Ur(a),x.openMenuId=null,H(),mo(a,`[data-action='toggle-row-menu']`)}});let $={id:``,pointerId:null,captureTarget:null,sourceRow:null,ghost:null,startX:0,startY:0,offsetX:0,offsetY:0,active:!1,targetId:``,targetStatus:``};function So(){document.querySelectorAll(`.is-drop-target,.is-lane-drop`).forEach(e=>{e.classList.remove(`is-drop-target`,`is-lane-drop`)}),$.targetId=``,$.targetStatus=``}function Co(e){if(!$.ghost)return;let t=e.clientX-$.offsetX,n=e.clientY-$.offsetY;$.ghost.style.transform=`translate3d(${t}px, ${n}px, 0)`}function wo(e){if($.active||!$.sourceRow)return;let t=$.sourceRow.getBoundingClientRect(),n=document.createElement(`div`),r=$.sourceRow.cloneNode(!0);n.className=`task-drag-ghost board-list`,n.style.width=`${t.width}px`,n.setAttribute(`aria-hidden`,`true`),n.inert=!0,r.classList.add(`task-drag-ghost-card`),r.classList.remove(`is-selected`),r.removeAttribute(`data-id`),r.querySelectorAll(`[id]`).forEach(e=>e.removeAttribute(`id`)),n.append(r),document.body.append(n),$.ghost=n,$.active=!0,$.sourceRow.classList.add(`is-drag-origin`),document.body.classList.add(`is-task-dragging`),$.sourceRow.hasPointerCapture($.pointerId)||$.sourceRow.setPointerCapture($.pointerId),Co(e)}function To(e,t){let n=document.elementFromPoint(e,t),r=n?n.closest(`.board-lane`):null,i=n?n.closest(`.task-row`):null;So(),r&&r.querySelector(`[data-lane-drop]`)&&(r.classList.add(`is-lane-drop`),$.targetStatus=r.dataset.laneStatus||``,i&&i!==$.sourceRow&&i.closest(`.board-lane`)===r&&(i.classList.add(`is-drop-target`),$.targetId=i.dataset.id||``))}function Eo(e){requestAnimationFrame(()=>{let t=document.querySelector(`.task-row[data-id="${CSS.escape(e)}"]`);if(!t)return;let n=t.closest(`.board-lane`);t.classList.add(`is-jelly-landing`),n?.classList.add(`is-jelly-landing`),setTimeout(()=>{t.classList.remove(`is-jelly-landing`),n?.classList.remove(`is-jelly-landing`)},760)})}function Do({animateReturn:e=!1}={}){let t=$.sourceRow;$.captureTarget?.hasPointerCapture?.($.pointerId)&&$.captureTarget.releasePointerCapture($.pointerId),So(),$.ghost?.remove(),t?.classList.remove(`is-drag-origin`),document.body.classList.remove(`is-task-dragging`),e&&t?.isConnected&&(t.classList.add(`is-jelly-return`),setTimeout(()=>t.classList.remove(`is-jelly-return`),460)),$.id=``,$.pointerId=null,$.captureTarget=null,$.sourceRow=null,$.ghost=null,$.active=!1,$.targetId=``,$.targetStatus=``}function Oo(e=!1){let t=$.id,n=$.targetId,r=$.targetStatus,i=$.active;Do({animateReturn:!e&&i&&!n&&!r}),!e&&i&&(go=Date.now()+380),!e&&i&&t&&(n?Gr(t,n):r&&Kr(t,r),Eo(t))}function ko(e){if(!$.id)return;let t=Math.hypot(e.clientX-$.startX,e.clientY-$.startY);if(!$.active&&t<5)return;e.preventDefault(),wo(e),Co(e);let n=document.elementFromPoint(e.clientX,e.clientY)?.closest(`.board-lane-body`)||$.sourceRow?.closest(`.board-lane-body`),r=n?.getBoundingClientRect();r&&e.clientY<r.top+56&&n.scrollBy({top:-14}),r&&e.clientY>r.bottom-56&&n.scrollBy({top:14}),To(e.clientX,e.clientY)}S.taskGroups.addEventListener(`pointerdown`,e=>{if(e.pointerType!==`touch`){let t=e.target.closest(`.task-row`);if(e.isPrimary===!1||e.button!==0||window.innerWidth<=760||!t?.closest(`.board-lane`))return;let n=t.getBoundingClientRect();$.id=t.dataset.id,$.pointerId=e.pointerId,$.captureTarget=t,$.sourceRow=t,$.startX=e.clientX,$.startY=e.clientY,$.offsetX=e.clientX-n.left,$.offsetY=e.clientY-n.top;return}let t=e.target.closest(`[data-drag-handle]`),n=t?t.closest(`.task-row`):null;n&&!t.disabled&&(e.preventDefault(),x.pointerDragId=n.dataset.id,x.pointerDropId=null,n.classList.add(`is-pointer-dragging`),t.setPointerCapture(e.pointerId))}),window.addEventListener(`pointermove`,e=>{if($.id){ko(e);return}if(!x.pointerDragId)return;e.preventDefault();let t=S.taskScroll.getBoundingClientRect();e.clientY<t.top+56&&S.taskScroll.scrollBy({top:-14}),e.clientY>t.bottom-56&&S.taskScroll.scrollBy({top:14});let n=document.elementFromPoint(e.clientX,e.clientY),r=z().find(e=>e.id===x.pointerDragId),i=n?n.closest(`.task-row`):null,a=i?z().find(e=>e.id===i.dataset.id):null;document.querySelectorAll(`.is-drop-target`).forEach(e=>e.classList.remove(`is-drop-target`)),x.pointerDropId=null,a&&r&&a.id!==r.id&&a.status===r.status&&(i.classList.add(`is-drop-target`),x.pointerDropId=a.id)});function Ao(){document.querySelectorAll(`.is-pointer-dragging,.is-drop-target`).forEach(e=>{e.classList.remove(`is-pointer-dragging`,`is-drop-target`)}),x.pointerDragId=null,x.pointerDropId=null}window.addEventListener(`pointerup`,e=>{if($.id){Oo(e.type===`pointercancel`);return}let t=x.pointerDragId,n=x.pointerDropId;Ao(),t&&n&&Gr(t,n)}),window.addEventListener(`pointercancel`,()=>{$.id?Oo(!0):Ao()}),window.addEventListener(`blur`,()=>{$.id&&Oo(!0)});function jo(e){let t=e.target.closest(`[data-tag-action]`);if(t){let e=t.dataset.tagContext===`detail`?`detail`:`create`;if(t.dataset.tagAction===`show-entry`)hr(e);else if(t.dataset.tagAction===`add-entry`){let t=fr(e)?.querySelector(`[data-tag-entry-row] input`);gr(e,t?t.value:``)}return!0}let n=e.target.closest(`[data-toggle-editor-tag]`);if(n)return _r(n.dataset.tagContext===`detail`?`detail`:`create`,n.dataset.toggleEditorTag),!0;let r=e.target.closest(`[data-remove-editor-tag]`);return r?(vr(r.dataset.tagContext===`detail`?`detail`:`create`,r.dataset.removeEditorTag),!0):!1}function Mo(e){let t=e.target.id===`detailTagEntry`,n=e.target.id===`createTagEntry`;if(!t&&!n)return;let r=t?`detail`:`create`;if(e.key===`Enter`||e.key===`,`){e.preventDefault(),gr(r,e.target.value);return}let i=pr(r);e.key===`Backspace`&&!e.target.value&&i.length&&(e.preventDefault(),vr(r,i[i.length-1]))}if(S.inspectorContent.addEventListener(`click`,e=>{if(jo(e))return;let t=e.target.closest(`[data-draft-status]`);if(t&&x.draft){x.draft.status=t.dataset.draftStatus,S.inspectorContent.querySelectorAll(`[data-draft-status]`).forEach(e=>{e.setAttribute(`aria-pressed`,String(e===t))}),Sr(),t.focus();return}let n=e.target.closest(`[data-detail-action]`);n&&(n.dataset.detailAction===`save`&&wr()&&ni(),n.dataset.detailAction===`delete`&&x.selectedId&&to(`删除这条待办`,`删除会同步到已连接的仓库,可在提示消失前撤销。`,()=>Ur(x.selectedId)),n.dataset.detailAction===`dispatch`&&x.selectedId&&Ir(x.selectedId),n.dataset.detailAction===`open-dsh`&&Vr(zt()))}),S.inspectorContent.addEventListener(`submit`,e=>{e.preventDefault()}),S.inspectorContent.addEventListener(`input`,e=>{if(e.target.id===`detailTagEntry`){Sr();return}let t=e.target.dataset.draftField;t&&Cr(t,e.target.value)}),S.inspectorContent.addEventListener(`change`,e=>{let t=e.target.dataset.draftField;t&&Cr(t,e.target.dataset.value??e.target.value)}),S.inspectorContent.addEventListener(`keydown`,e=>{Mo(e)}),[S.syncButton,S.mobileSyncButton].forEach(e=>{e.addEventListener(`click`,()=>Za({manual:!0}))}),S.heatmapButton.addEventListener(`click`,()=>jn(`overview`)),S.settingsButton.addEventListener(`click`,Ti),S.mobileSettingsButton.addEventListener(`click`,()=>{Fn(!1),Ti()}),S.mobileMenuButton.addEventListener(`click`,Pn),S.recordDrawerCloseButton.addEventListener(`click`,()=>Fn()),S.recordDrawer.addEventListener(`click`,e=>{e.target===S.recordDrawer&&Fn()}),S.recordDrawer.addEventListener(`cancel`,e=>{e.preventDefault(),Fn()}),S.drawerHeatmapHelpButton.addEventListener(`click`,In),S.drawerStatsButton.addEventListener(`click`,()=>jn(`overview`)),S.closeHeatmapHelpButton.addEventListener(`click`,Ln),S.heatmapLearnMoreButton.addEventListener(`click`,()=>jn(`overview`)),S.heatmapHelpDialog.addEventListener(`cancel`,e=>{e.preventDefault(),Ln()}),S.statsBackButton.addEventListener(`click`,Nn),S.statsCloseButton.addEventListener(`click`,Mn),S.statsPage.addEventListener(`cancel`,e=>{e.preventDefault(),Nn()}),S.statsPageContent.addEventListener(`click`,e=>{if(e.target.closest(`[data-stats-action='all-records']`)){x.statsView=`year`,x.statsYear=new Date().getFullYear(),x.statsSelectedDate=``,kn({resetScroll:!0}),S.statsBackButton.focus();return}let t=e.target.closest(`[data-stats-year-step]`);t&&!t.disabled&&(x.statsYear+=Number(t.dataset.statsYearStep),kn({resetScroll:!0}),S.statsBackButton.focus())}),S.remindersEnabledInput?.addEventListener(`change`,Ai),S.updateTokenInput.addEventListener(`change`,()=>{_t({token:S.updateTokenInput.value}),G(I.token?`GitHub 只读令牌已保存`:`GitHub 只读令牌已清除`)}),S.checkUpdateButton.addEventListener(`click`,Ea),S.toggleUpdateHistoryButton.addEventListener(`click`,()=>{Yi(!x.updateHistoryOpen)}),S.updateHistoryList.addEventListener(`click`,Sa),[S.closeUpdateButton,S.laterUpdateButton].forEach(e=>{e.addEventListener(`click`,()=>wa())}),S.installUpdateButton.addEventListener(`click`,ba),S.updateDownloadAction.addEventListener(`click`,xa),S.updateUninstallAction.addEventListener(`click`,va),S.updateNoticeAction.addEventListener(`click`,ha),S.updateNoticeClose.addEventListener(`click`,sa),S.settingsForm.addEventListener(`submit`,e=>{e.preventDefault()}),S.addCommonTagButton.addEventListener(`click`,Zn),S.commonTagInput.addEventListener(`keydown`,e=>{e.key===`Enter`&&(e.preventDefault(),Zn())}),S.commonTagSettingsList.addEventListener(`click`,e=>{let t=e.target.closest(`[data-remove-common-tag]`);t&&Xn(t.dataset.removeCommonTag)}),[S.closeSettingsButton,S.cancelSettingsButton].forEach(e=>{e.addEventListener(`click`,ji)}),S.settingsPage.addEventListener(`cancel`,e=>{e.preventDefault(),ji()}),S.saveSettingsButton.addEventListener(`click`,ja),S.disconnectButton.addEventListener(`click`,Na),S.mobileInstallButton.addEventListener(`click`,ao),S.inspectorClose.addEventListener(`click`,ti),S.aboutButton.addEventListener(`click`,Di),[S.closeAboutIconButton,S.closeAboutButton].forEach(e=>{e.addEventListener(`click`,Oi)}),S.aboutDialog.addEventListener(`cancel`,e=>{e.preventDefault(),Oi()}),S.inspector.addEventListener(`cancel`,e=>{e.preventDefault(),ti()}),S.continueEditingButton.addEventListener(`click`,()=>{x.draftAfter=null,Zr()}),S.discardDraftButton.addEventListener(`click`,Qr),S.saveAndLeaveButton.addEventListener(`click`,$r),S.savePromptDialog.addEventListener(`cancel`,()=>{x.draftAfter=null}),S.dispatchCloseButton.addEventListener(`click`,Lr),S.dispatchCancelButton.addEventListener(`click`,Lr),S.dispatchConfirmButton.addEventListener(`click`,Rr),S.dispatchDialog.addEventListener(`cancel`,e=>{e.preventDefault(),Lr()}),window.addEventListener(`message`,Br),S.toastAction.addEventListener(`click`,()=>{let e=x.undo;x.undo=null,eo(),typeof e==`function`&&e()}),S.confirmCancelButton.addEventListener(`click`,ro),S.confirmAcceptButton.addEventListener(`click`,io),S.confirmDialog.addEventListener(`cancel`,e=>{e.preventDefault(),ro()}),S.searchBox.addEventListener(`click`,()=>{window.innerWidth<=760&&!S.searchBox.classList.contains(`is-open`)&&(S.searchBox.classList.add(`is-open`),requestAnimationFrame(()=>S.searchInput.focus()))}),document.addEventListener(`click`,e=>{let t=e.target.closest(`.heatmap-cell[data-heatmap-date]`);t?.closest(`#statsPage`)?Tn(t):t?hn(t):e.target.closest(`.heatmap-tooltip`)||mn(),x.openMenuId&&!e.target.closest(`.row-menu-wrap`)&&(x.openMenuId=null,H())}),document.addEventListener(`keydown`,e=>{if(S.updateDialog.open||S.confirmDialog.open||S.dispatchDialog.open||S.savePromptDialog.open||S.inspector.open||S.createDialog.open||S.recordDialog.open||S.inspirationDialog.open||S.recordDrawer.open||S.heatmapHelpDialog.open||S.aboutDialog.open||S.statsPage.open||S.settingsPage.open)return;if(x.statsOpen){e.key===`Escape`&&(e.preventDefault(),Nn());return}if(x.settingsOpen){e.key===`Escape`&&(e.preventDefault(),ji());return}let t=/input|textarea|select/i.test(document.activeElement.tagName);if(e.key===`/`&&!t&&(e.preventDefault(),window.innerWidth<=760?Ci():(S.searchBox.classList.add(`is-open`),S.searchInput.focus())),e.key!==`n`&&e.key!==`N`||t||e.metaKey||e.ctrlKey||e.altKey||(e.preventDefault(),Si()),(e.key===`x`||e.key===`X`)&&!t&&x.selectedId&&(e.preventDefault(),Fr(x.selectedId)),e.key===`Escape`){if(!S.mobileSearchPanel.hidden){wi();return}x.openMenuId&&(x.openMenuId=null,H()),ti()}!t&&x.selectedId&&e.altKey&&(e.key===`ArrowUp`||e.key===`ArrowDown`)&&(e.preventDefault(),Wr(x.selectedId,e.key===`ArrowUp`?-1:1))}),window.addEventListener(`online`,()=>{X(F.repo?`synced`:`local`,F.repo?`网络已恢复`:`仅保存在本机`),$a(),fa({announce:!1})}),window.addEventListener(`offline`,()=>{X(`error`,`当前离线,修改待同步`)}),window.addEventListener(`hashchange`,Pi),Ni(),window.addEventListener(`beforeunload`,e=>{xr()&&(e.preventDefault(),e.returnValue=``)}),document.addEventListener(`visibilitychange`,()=>{document.hidden||(we(x.items).catch(()=>{}),Qe(x.items).catch(()=>{}),x.dirty&&$a(),fa({announce:!0}))}),window.addEventListener(`beforeinstallprompt`,e=>{window.innerWidth>760||(e.preventDefault(),x.deferredInstallPrompt=e,oo())}),window.addEventListener(`appinstalled`,()=>{x.deferredInstallPrompt=null,oo(),Z(`简记已安装到设备`,null)}),window.addEventListener(`resize`,()=>{let e=Kt()&&window.innerWidth>760;!e&&!he.includes(x.view)&&(x.view=`records`,P(),U()),S.taskGroups.classList.contains(`is-board`)!==e&&H(),window.innerWidth>760&&S.searchBox.classList.remove(`is-open`),S.appPicker.open&&kt()}),t)try{await Me()}catch(e){console.warn(`连接 DSH 简记存储失败,将先使用本机数据`,e)}at(),oe=!0,$e(x.items),St(S.sortSelect,x.sort),Ct(S.createStatusInput),Ct(S.createDueInput),Zt(),Te(so),U(),fo(),Pi(),oo(),Le(),t&&se===0&&Ie(!0),t||Ta().finally(()=>{setTimeout(()=>Da({manual:!1,prompt:`notice`}),1200)}),!e&&!t&&`serviceWorker`in navigator&&location.protocol!==`file:`&&window.addEventListener(`load`,()=>navigator.serviceWorker.register(`./sw.js`).catch(()=>{})),F.repo&&F.token&&(X(`synced`,`等待同步`),setTimeout(()=>Za(),400))})();export{o as t};
|