commit d4252b9fe9ddfde4b2d16698a6cd608888283bc0 Author: yutent Date: Tue Jan 14 14:28:42 2025 +0800 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..52cf7cd --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +__pycache__ +*.txt + +._* + +.Spotlight-V100 +.Trashes +.DS_Store +.AppleDouble +.LSOverride \ No newline at end of file diff --git a/calendar.desktop b/calendar.desktop new file mode 100644 index 0000000..5071b96 --- /dev/null +++ b/calendar.desktop @@ -0,0 +1,9 @@ +[Desktop Entry] +Name=Calendar +Comment[zh_CN]=中文万年历 +Exec=calendar +Icon=calendar +Terminal=false +X-MultipleArgs=false +Type=Application +Categories=Utils; \ No newline at end of file diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..2ca9080 --- /dev/null +++ b/debian/control @@ -0,0 +1,12 @@ +Package: calendar +Version: {{version}} +Section: utils +Architecture: all +Priority: optional +Maintainer: Yutent +Installed-Size: {{size}} +Depends: python3-webengine-gtk3 (>=0.4.0) +Homepage: https://git.wkit.fun/appcat/calendar +Author: yutent +Description: 万年历 + 简单纯粹的万年历功能, 带有农历, 节气, 节日等功能, 可以自定义节假日。 diff --git a/src/source/_window.py b/src/source/_window.py new file mode 100644 index 0000000..e2df448 --- /dev/null +++ b/src/source/_window.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 + +import gi + +gi.require_version('Gtk', '3.0') + +from gi.repository import Gtk + +class Window(Gtk.Window): + def __init__(self, title = 'Untitled window', width = 840, height = 520): + Gtk.Window.__init__(self, title = title) + self.set_default_size(width, height) + self.resize(width, height) + self.set_wmclass('Hosts-Switch', 'Hosts-Switch') + self.set_title('Hosts-Switch') + self.set_icon_name('hosts-switch') + + + def toggle_visible(self, icon): + if self.is_visible(): + self.hide() + else: + self.present() \ No newline at end of file diff --git a/src/source/calendar.py b/src/source/calendar.py new file mode 100644 index 0000000..f7ba9a0 --- /dev/null +++ b/src/source/calendar.py @@ -0,0 +1,67 @@ +#!/usr/bin/python3 + +import gi, os, sys + +gi.require_version('Gtk', '3.0') + +from gi.repository import Gtk, Gdk, GLib, Gio, GObject, GdkPixbuf + +from webengine.gtk3 import WebEngine, create_setting, create_hmr_server +from _window import Window + +APP_ID = 'fun.wkit.hosts-switch' +__dir__ = os.path.dirname(os.path.realpath(__file__)) + +web_root = os.path.join(__dir__, './webapp') +home_dir = os.getenv('HOME') +config_dir = os.path.join(home_dir, '.config/hosts-switch') + + +if not os.path.isdir(config_dir): + os.mkdir(config_dir) + + +class Application(Gtk.Application): + def __init__(self): + + Gtk.Application.__init__(self, application_id = APP_ID) + + self.window = Window() + + web = WebEngine(self.window) + web.set_root(web_root) + + if os.getenv('RUN_ENV') == 'development': + setting = create_setting({"devtools": True}) + hmr = create_hmr_server() + web.use(setting).use(hmr) + + web.connect('quit', self.quit_all) + web.load() + + self.window.add(web) + + + + def do_activate(self): + + self.set_app_menu(None) + self.set_menubar(None) + + self.add_window(self.window) + self.window.show_all() + + + def quit_all(self, widget): + self.remove_window(self.window) + + + + +if __name__ == "__main__": + try: + app = Application() + app.run(sys.argv) + except Exception as err: + print(err) + diff --git a/src/webui/app.js b/src/webui/app.js new file mode 100644 index 0000000..7ff2e36 --- /dev/null +++ b/src/webui/app.js @@ -0,0 +1,41 @@ +/** + * {} + * @author yutent + * @date 2023/07/20 14:19:13 + */ + +import 'es.shim' +import { html, css, Component } from 'wkit' +import { createApp, createRouter } from 'wkitd' + +import store from './store.js' +import './components/home.js' + +import { noop } from './utils/index.js' + +createApp({ + data: { + input: '', + img: '', + content: '' + }, + styles: [ + css` + :host { + display: flex; + width: 100%; + height: 100vh; + } + ` + ], + methods: { + quit() { + native.quit() + } + }, + render() { + return html` ` + } +}) + .use(store) + .mount() diff --git a/src/webui/index.html b/src/webui/index.html new file mode 100644 index 0000000..7891349 --- /dev/null +++ b/src/webui/index.html @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/webui/lib/es.shim.js b/src/webui/lib/es.shim.js new file mode 100644 index 0000000..6857185 --- /dev/null +++ b/src/webui/lib/es.shim.js @@ -0,0 +1 @@ +(()=>{Set.prototype.union||(Object.defineProperty(Set.prototype,"union",{value(e){let t=new Set([...this]);if(e.size!==void 0&&e.has!==void 0&&e.keys!==void 0)for(let r of e.keys())t.add(r);return t}}),Object.defineProperty(Set.prototype,"difference",{value(e){let t=new Set;for(let r of this)e.has(r)||t.add(r);return t}}),Object.defineProperty(Set.prototype,"symmetricDifference",{value(e){let t=this.difference(e);for(let r of e)this.has(r)||t.add(r);return t}}),Object.defineProperty(Set.prototype,"intersection",{value(e){let t=new Set;for(let r of this)e.has(r)&&t.add(r);return t}}),Object.defineProperty(Set.prototype,"isSubsetOf",{value(e){for(let t of this)if(!e.has(t))return!1;return!0}}),Object.defineProperty(Set.prototype,"isSupersetOf",{value(e){for(let t of e)if(!this.has(t))return!1;return!0}}),Object.defineProperty(Set.prototype,"isDisjointFrom",{value(e){for(let t of this)if(e.has(t))return!1;return!0}})),Set.prototype.equals||Object.defineProperty(Set.prototype,"equals",{value(e){return this.size===e.size&&this.isSubsetOf(e)}}),Object.defineProperty(Array.prototype,"flat",{value(e=1,t=[]){for(let r of this)Array.isArray(r)&&e>0?r.flat(e-1,t):t.push(r);return t},writable:!0}),Object.defineProperty(Array.prototype,"flatMap",{value(e){return this.map(e).flat()},writable:!0}),Array.prototype.at||Object.defineProperty(Array.prototype,"at",{value(e){let t=+e;return t<0&&(t+=this.length),this[t]}}),Array.prototype.findLast||(Object.defineProperty(Array.prototype,"findLast",{value(e){let t=this.length;for(;t>0;){let r=this[--t];if(e(r,t))return r}}}),Object.defineProperty(Array.prototype,"findLastIndex",{value(e){let t=this.length;for(;t>0;){let r=this[--t];if(e(r,t))return t}return-1}})),Array.prototype.toSorted||(Object.defineProperty(Array.prototype,"toSorted",{value(e){return[...this].sort(e)}}),Object.defineProperty(Array.prototype,"toReversed",{value(){return[...this].reverse()}}),Object.defineProperty(Array.prototype,"toSpliced",{value(...e){return[...this].splice(...e)}}),Object.defineProperty(Array.prototype,"with",{value(e,t){let r=+e,o=[...this];return r<0&&(r+=o.length),o[r]=t,o}})),Array.prototype.group||(Object.defineProperty(Array.prototype,"group",{value(e){let t={};if(typeof e=="function"){for(let r of this){let o=e(r);t[o]?t[o].push(r):t[o]=[r]}return t}else throw Error("argument callback must be a function.")}}),Object.defineProperty(Array.prototype,"groupToMap",{value(e){let t=new Map;if(typeof e=="function"){for(let r of this){let o=e(r);t.has(o)?t.get(o).push(r):t.set(o,[r])}return t}else throw Error("argument callback must be a function.")}})),Object.empty||Object.defineProperty(Object,"empty",{value(e){try{for(let t in e)return!1}catch{}return!0}}),Object.groupBy||Object.defineProperty(Object,"groupBy",{value(e,t){return e.group(t)}}),Object.hasOwn||Object.defineProperty(Object,"hasOwn",{value(e,t){return e===null?!1:e.hasOwnProperty(t)}}),Object.prototype.toParams||Object.defineProperty(Object.prototype,"toParams",{value(){let e="";for(let t in this)this[t]!==void 0&&(e+=`&${t}=${this[t]}`);return e.slice(1)}}),Map.groupBy||Object.defineProperty(Map,"groupBy",{value(e,t){return e.groupToMap(t)}});function i(e,t){if(e+="",t+="",e===t)return 0;{e=e.split("."),t=t.split(".");let r=Math.max(e.length,t.length);for(let o=0;on)return 1;if(p=o?e=0:e=o+e),p===1)return this.slice(0,e);{t-=0;let n=this.slice(0,e),l=this.slice(e+t);return n+r+l}}}),String.prototype.htmlspecialchars||Object.defineProperty(String.prototype,"htmlspecialchars",{value(e){let t=this.replace(/&(?!\w+;)/g,"&").replace(//g,">");return e==="ENT_QUOTES"?t.replace(/"/g,""").replace(/'/g,"'"):e==="ENT_NOQUOTES"?t:t.replace(/"/g,""")}}),String.prototype.tohtml||Object.defineProperty(String.prototype,"tohtml",{value(){return this.replace(/</gi,"<").replace(/>/gi,">").replace(/"/gi,'"').replace(/"/g,'"').replace(/'/g,"'").replace(/&/gi,"&")}}),String.prototype.xss||Object.defineProperty(String.prototype,"xss",{value(){let e=this.htmlspecialchars("ENT_QUOTES");return e=e.replace(/(document\.cookie)|(document\.write)|(\.parentNode)|(window\.location)|(\.innerHTML)/g,"").replace(/(%0[0-8bcef])|(%1[0-9a-f])/g,""),e}}),String.prototype.escape||Object.defineProperty(String.prototype,"escape",{value(){return this.replace(/('|"|&|\\|\}|\{|\(|\)|;|=|\,|&)/g,"\\$1")}}),String.prototype.at||Object.defineProperty(String.prototype,"at",{value(e){let t=+e;return t<0&&(t+=this.length),this[t]}}),String.prototype.toJson||Object.defineProperty(String.prototype,"toJson",{value(){let e=this.replace(/^\?/,""),t=decodeURIComponent(e).split("&").filter(o=>o).map(o=>o.split("=")),r={};for(let o of t)r[o[0]]=o[1]||"";return r}}),String.prototype.lt||(Object.defineProperty(String.prototype,"lt",{value(e){return i(this,e)===-1}}),Object.defineProperty(String.prototype,"lte",{value(e){return i(this,e)<1}}),Object.defineProperty(String.prototype,"gt",{value(e){return i(this,e)===1}}),Object.defineProperty(String.prototype,"gte",{value(e){return i(this,e)>-1}}),Object.defineProperty(String.prototype,"eq",{value(e){return i(this,e)===0}}));var a=Number.prototype.toFixed;Object.defineProperty(Number.prototype,"toFixed",{value(e){return a.call(this+Number.EPSILON,e)},writable:!0}),Number.parse||Object.defineProperty(Number,"parse",{value(e){return typeof e=="number"||typeof e=="string"?(e+="",e.startsWith("0")&&!e.startsWith("0.")?e==="0"?0:e:(isFinite(e)&&e>=Number.MIN_SAFE_INTEGER&&e<=Number.MAX_SAFE_INTEGER&&(e=+e),e)):e}}),Number.fromString||Object.defineProperty(Number,"fromString",{value(e){return+e||0}}),Date.isDate||Object.defineProperty(Date,"isDate",{value(e){return!!(e&&typeof e=="object"&&e.getTime)}}),Date.prototype.getFullWeek||(Object.defineProperty(Date.prototype,"getFullWeek",{value(){let e=this.getFullYear(),t=new Date(e,0,1),r=t.getDay(),o=(this-t)/24/360/1e3;return Math.ceil((o+r)/7)}}),Object.defineProperty(Date.prototype,"getWeek",{value(){let e=this.getDate(),t=this.getMonth(),r=this.getFullYear(),o=new Date(r,t,1).getDay();return Math.ceil((e+o)/7)}})),Date.prototype.format||Object.defineProperty(Date.prototype,"format",{value(e){let t={fullyear:this.getFullYear(),year:this.getYear(),fullweek:this.getFullWeek(),week:this.getWeek(),month:this.getMonth()+1,date:this.getDate(),day:this.getDay(),hours:this.getHours(),minutes:this.getMinutes(),seconds:this.getSeconds()},r=null;e=e||"Y-m-d H:i:s",t.g=t.hours>12?t.hours-12:t.hours,r={Y:t.fullyear,y:t.year,m:t.month<10?"0"+t.month:t.month,n:t.month,d:t.date<10?"0"+t.date:t.date,j:t.date,H:t.hours<10?"0"+t.hours:t.hours,h:t.g<10?"0"+t.g:t.g,G:t.hours,g:t.g,i:t.minutes<10?"0"+t.minutes:t.minutes,s:t.seconds<10?"0"+t.seconds:t.seconds,W:t.fullweek,w:t.week,D:t.day};for(let o in r)e=e.replace(new RegExp(o,"g"),r[o]);return e}}),Promise.defer||(Promise.defer=function(){let e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}),Promise.withResolvers||(Promise.withResolvers=Promise.defer)})(); diff --git a/src/webui/lib/wkit.js b/src/webui/lib/wkit.js new file mode 100644 index 0000000..7f010ab --- /dev/null +++ b/src/webui/lib/wkit.js @@ -0,0 +1,3 @@ +var x=Object.create(null);["autofocus","autoplay","async","allowTransparency","checked","controls","declare","disabled","defer","defaultChecked","defaultSelected","contentEditable","isMap","loop","multiple","noHref","noResize","noShade","open","readOnly","selected","loading"].forEach(function(t){x[t.toLowerCase()]=t});var M="keep-alive",mt="keepAlive",J=Symbol("wc_path"),m=Symbol("wc-nothing"),X=Symbol("finalized"),A=Symbol("props"),v=Symbol("changed_props"),N=Symbol("mounted"),O=Symbol("pending"),yt="* {box-sizing: border-box;margin: 0;padding: 0;}::before,::after {box-sizing: border-box;}::selection {background: var(--selection-background, var(--color-plain-a));color: var(--selection-color, inherit);}";function G(t){switch(t){case Number:return 0;case Boolean:return!1;case Object:return{};case Array:return[];default:return""}}function bt(t){switch(typeof t){case"number":return{type:Number,default:t};case"boolean":return{type:Boolean,default:t};case"object":return Array.isArray(t)?{type:Array,default:t}:{type:Object,default:t};case"string":let e=String,s=!0;return t.includes("!")&&(t.startsWith("str!")?t=t.slice(4):t.startsWith("num!")?(e=Number,t=+t.slice(4)||0):t.startsWith("bool!")&&(e=Boolean,t=t.slice(5),t=t!=="false"&&t!==""),s=!1),{type:e,default:t,attribute:s};default:return{type:null,default:""}}}function gt(t){if(t&&typeof t=="object"&&t.hasOwnProperty("type"))return Object.assign({attribute:!0,default:G(t.type)},t);switch(t){case Number:t={type:Number};break;case Boolean:t={type:Boolean};break;case Object:t={type:Object};break;case Array:t={type:Array};break;case String:t={type:String};break;default:t=bt(t);break}return t.default=t.hasOwnProperty("default")?t.default:G(t.type),t.attribute=t.hasOwnProperty("attribute")?t.attribute:!0,t}function B(t,e){switch(e.type){case Number:return t===null?null:+t||0;case Boolean:return t===!1?!1:t!==null;case Object:if(typeof t=="object")return t;try{return JSON.parse(t)}catch{return{}}case Array:if(typeof t=="object")return t;try{return JSON.parse(t)}catch{return[]}case null:return t;default:return t==null?null:t+""}}var K=CSSStyleSheet;document.adoptedStyleSheets||(K=class{elem=document.createElement("style");replaceSync(t){this.elem.textContent=t.replace(/\s+/g," ")}});function vt(t,...e){let s="",n=Array.from(t);for(;n.length;)s+=n.shift()+(e.shift()||"");return s}function $t(t,e=""){let s=new K;typeof e=="string"?e=[e]:e=e.flat(1/0),e=(yt+e.join(" ")).trim(),s.replaceSync(e),t.adoptedStyleSheets?t.adoptedStyleSheets=[s]:t.appendChild(s.elem)}function Q(t=200,e=[],s=!1){s===!1&&this.style.display==="none"&&(this.style.display="");let n=this.animate(e,{duration:t,direction:s?"reverse":"normal",fill:"forwards"});return new Promise(r=>{n.addEventListener("finish",i=>{s&&(this.style.display="none"),n.cancel(),r()},{once:!0})})}var E={fade:[{opacity:0},{opacity:1}],scale:[{transform:"scale(0)"},{transform:"scale(1)"}],"micro-bounce":[{opacity:0,transform:"scale(0.8)"},{transform:"scale(1.05)",opacity:1},{transform:"scale(1)"}],slide:[{opacity:0,transform:"translateY(-50px)"},{opacity:1,transform:"translateY(0)"}],bounce:[{transform:"scale(0)"},{transform:"scale(1.2)"},{transform:"scale(1)"}],rotate:[{transform:"rotate(0)"},{transform:"rotate(360deg)"}]};function $(){}function q(t,e,s){let n=s?"querySelectorAll":"querySelector";return e?e[n](t):document.body[n](t)}function wt(t,e){return q(t,e,!0)}var y=function(){let t=[],e=document.createTextNode(""),s=!1;function n(){for(;t.length>0;){let r=t.shift();try{r()}catch(i){console.error(i)}}}return new MutationObserver(n).observe(e,{characterData:!0}),function(r){t.push(r),s=!s,e.data=s}}();function xt(...t){let e=0,s=0,n=1,r=[];switch(t.length){case 1:s=t[0];break;case 2:case 3:[e,s,n=1]=t,n=Math.abs(n)||1;break}e>s&&([e,s]=[s,e]);for(let i=e;is.toUpperCase())}function At(t){try{let e=t.getBoundingClientRect();if(e.width||e.height||t.getClientRects().length){let s=t.ownerDocument,n=s.documentElement,r=s.defaultView;return{top:e.top+r.pageYOffset-n.clientTop,left:e.left+r.pageXOffset-n.clientLeft}}}catch{return{left:0,top:0}}}function j(t,e="",s,n,r=!1){let i=e.split(","),o,l=t&&t.host===t,a=l?t:null;if(!t||!e)return console.error("Argument Error: function bind's arg 1 must be a document obejct");if(typeof s=="function"?(r=n||!1,n=s,s=null):(typeof s!="string"&&(s=null),n=n||$),l===!1){let h=t;for(;h&&h!==document.body&&h!==document;){if(h.ownHost){l=!0,a=h.ownHost;break}h=h.parentNode}}return s?o=function(h){let p=q(s,t),u=h.target;if(p)for(;u!==t;)if(p.contains(u)){n(h);break}else u=u.parentNode}:o=n,i.forEach(function(h){if(h=h.trim(),l){a.$events[h]??=[];let p=a.$events[h];if(p.length){let u=p.findIndex(c=>c.el===t&&c.listener===o&&c.options===r);if(u>-1){let c=p[u];p.splice(u,1),t.removeEventListener(h,c.listener,c.options)}}p.push({el:t,listener:o,options:r})}t.addEventListener(h,o,r)}),o}function C(t,e="",s=$,n=!1){e.split(",").forEach(function(r){t.removeEventListener(r.trim(),s,n)})}function Nt(t,e=$){return j(document,"mousedown",s=>{let n=s.composedPath?s.composedPath():s.path;if(n){for(;n.length>3;)if(n.shift()===t)return}else{let r=s.explicitOriginalTarget||s.target;if(t===r||t.contains(r)||t.root&&t.root.contains(r))return}e(s)})}function St(t=$){C(document,"mousedown",t)}function tt(t,e="click",s={},n){let r=new Event(e,{bubbles:!n,cancelable:!0});Object.assign(r,s),t.dispatchEvent(r)}var W="{{$wkit$}}",b=`{{^wkit${String(Math.random()).slice(-8)}^}}`,et="?"+b,kt=`<${et}>`,P=t=>t===null||typeof t!="object"&&typeof t!="function",H=Array.isArray,_t=t=>t?H(t)||typeof t[Symbol.iterator]=="function":!1,I=`[ +\f\r]`,Ot=`[^ +\f\r"'\`<>=]`,Et=`[^\\s"'>=/]`,S=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,st=1,D=2,jt=3,nt=/-->/g,rt=/>/g,w=new RegExp(`>|${I}(?:(${Et}+)(${I}*=${I}*(?:${Ot}|("|')|))|$)`,"g"),Ct=0,it=1,Pt=2,ot=3,at=/'/g,lt=/"/g,ht=/^(?:script|style|textarea|title)$/i,Tt=1,T=2,Y=1,L=2,Lt=5,Z=6,Vt=7,ut=new Map,g=document.createTreeWalker(document,129,null,!1);function zt(t,e){let s=t.length-1,n=[],r=e===T?"":"",i,o=S;for(let a=0;a"?(o=i??S,p=-1):d[it]===void 0?p=-2:(p=o.lastIndex-d[Pt].length,u=d[it],o=d[ot]===void 0?w:d[ot]==='"'?lt:at):o===lt||o===at?o=w:o===nt||o===rt?o=S:(o=w,i=void 0);let _=o===w&&t[a+1].startsWith("/>")?" ":"";r+=o===S?h+kt:p>=0?(n.push(u),h.slice(0,p)+W+h.slice(p)+b+_):h+b+(p===-2?(n.push(void 0),a):_)}let l=r+(t[s]||"")+(e===T?"":"");if(!H(t)||!t.hasOwnProperty("raw"))throw new Error("invalid html ast");return[l,n]}function ct(t=""){let e=document.createElement("template");return e.innerHTML=t,e}function k(t=""){return document.createComment(t)}var Mt=class{parts=[];constructor({strings:t,values:e,__dom_type__:s},n){let r,i=0,o=0,l=t.length-1,a=this.parts,[h,p]=zt(t,s);if(this.el=ct(h),g.currentNode=this.el.content,s===T){let u=this.el.content,c=u.firstChild;c.remove(),u.append(...c.childNodes)}for(;(r=g.nextNode())!==null&&a.length0){r.textContent="";for(let d=0;dthis.#l())}#e(e,s=this.endNode){return this.startNode.parentNode.insertBefore(e,s)}#s(e){this.#t!==e&&(this.#r(),this.#t=this.#e(e))}#n(e){if(this.#t!==m&&P(this.#t)){let s=this.startNode.nextSibling;s.data=e}else this.#s(document.createTextNode(e));this.#t=e}#i(e){let{values:s,__dom_type__:n}=e,r=typeof n=="number"?this.#o(e):(n.el===void 0&&(n.el=ct(n.h)),n);if(this.#t?.$template===r)this.#t.update(s);else{let i=new Bt(r,this),o=i.clone(this.options);i.update(s),this.#s(o),this.#t=i}}#o(e){let s=e.strings.join(),n=ut.get(s);return n===void 0&&(n=new Mt(e,this.options),ut.set(s,n)),n}#a(e){H(this.#t)||(this.#t=[],this.#r());let s=this.#t,n=0,r;for(let i of e)n===s.length?s.push(r=new ft(this.#e(k()),this.#e(k()),this,this.options)):r=s[n],r.$setValue(i),n++;nr!==null)}}},V=class{type=Y;#t=m;constructor(t,e,s,n,r,i={}){this.element=t,this.name=e,this.decorates=n,this.$parent=r,this.options=i,(s.length>2||s[0]!==""||s[1]!=="")&&(this.#t=Array(s.length-1).fill(null),this.strings=s)}get tagName(){return this.element.tagName}$setValue(t,e){let s=this.strings,n=!1;if(typeof t=="function"&&(t=t(this.element)),s===void 0)n=!P(t)||t!==this.#t,n&&(this.#t=t);else{let r=t;t=s[0];for(let i=0;ia.stopPropagation();break;case"prevent":this.#e=a=>a.preventDefault();break;case"self":this.#n=a=>a.target===s;break;case"capture":case"once":case"passive":r[l]=!0;break}let o=t!==this.#t;if(this.#t){for(let l=-1,a;a=i[++l];)if(a.el===s){o=o||r.capture!==a.capture||r.once!==a.once||r.passive!==a.passive,o&&(a.el.removeEventListener(n,a.listener,a.options),i[l]=null);break}}i=i.filter(l=>l!==null),e.$events[n]=i,t&&o&&(s.addEventListener(n,this,r),this.#t=t,i.push({el:s,listener:this,options:r}))}handleEvent(t){this.#s(t),this.#e(t),this.#n(t)!==!1&&this.#t.call(this.options.host,t)}},Wt=class{type=Z;constructor(t,e,s){this.element=t,this.$parent=e,this.options=s}$setValue(){}};function Ht(t,e,s={}){let n=e[J];return n===void 0&&(n=new dt(e.insertBefore(k(),null),null,void 0,s),e[J]=n),n.$setValue(t,!0),n}function F(t,...e){return{__dom_type__:Tt,strings:t,values:e}}function It(t,e=[]){let s=e.length?t.split("%s"):[t];return s.raw=!0,F(s,...e)}function Dt(t,...e){return{__dom_type__:T,strings:t,values:e}}function pt(t,...e){try{t&&t.apply(this,e)}catch(s){console.error(s)}}function Yt(t={}){let e="";for(let s in t)t[s]&&(e+=" "+s);return e.slice(1)}function Zt(t={}){let e="";for(let s in t)(t[s]||t[s]===0)&&(e+=R(s)+":"+t[s]+";");return e}function Ft(t,e="",s=""){return t?e:s}function Jt(t,e=[],s=""){for(let[n,r]of e)if(t===n)return r;return s}function Xt(t,e){let s=n=>{Function("o","v",`o.${t} = v`)(this,n.target.value),this.$requestUpdate()};return e&&!e.__live__&&(j(e,"input",s),this.$events.input??=[],this.$events.input.push({el:e,listener:s,options:!1}),e.__live__=!0),Function("o",`return o.${t}`)(this)}var Gt=class extends HTMLElement{static get observedAttributes(){let t=[];return this.finalize(),this.parseAnim(),this[A].forEach((e,s)=>{t.push(e.attrName)}),t.concat(this.watches||[],M)}static parseAnim(){if(this.hasOwnProperty("animation")){let{type:t="fade",duration:e,custom:s,immediate:n=!1}=this.animation,r=E[t]||E.fade;s&&(r=s),Object.defineProperty(this.prototype,"$animate",{value(i){if(this[N])return Q.call(this,e,r,i)}}),this.prototype.$animate.immediate=n,delete this.animation}}static finalize(){if(this[X])return!1;if(this[X]=!0,this[A]=new Map,this.hasOwnProperty("props"))for(let t in this.props){if(t===M||t===mt)continue;let e=gt(this.props[t]),s=t.toLowerCase();e.attrName=s,x[s]?t=x[s]:(e.attrName=R(t),t=U(t)),this[A].set(t,e)}delete this.props}static reg(t="",e="wc"){let s=e+"-"+t;customElements.get(s)||customElements.define(s,this)}keepAlive=!1;removed=!1;constructor(){super(),this[O]=!1,this[N]=!1,this[v]=new Map,this.host=this,this.root=this.shadowRoot||this.attachShadow({mode:"open"}),this.root.ownHost=this,Object.defineProperty(this,"$refs",{value:Object.create(null)}),Object.defineProperty(this,"$events",{value:Object.create(null)});for(let[t,e]of this.constructor[A])this.#t(t,e),this[v].set(t,this[t]);y(t=>this.created())}#t(t,e){let s=Symbol(t),n;if(e.type===Array||e.type===Object){let r=this.#e(null,e,t);n={get(){return r},set(i){r=this.#e(B(i,e),e,t),this.$requestUpdate(t)}}}else n={get(){return this[s]},set(r){let i=this[s];r=B(r,e),i!==r&&(this[s]=r,this.$requestUpdate(t),pt.call(this,e.observer,r,i))}},this[s]=e.default;Object.defineProperty(this,t,n)}#e(t,e={},s){return new Proxy(t||e.default,{get:(n,r,i)=>{let o=Reflect.get(n,r,i);return typeof o=="object"?this.#e(o,{},s):o},set:(n,r,i,o)=>{let l=n[r];return Reflect.set(n,r,i,o),this.$requestUpdate(s),pt.call(this,e.observer,i,l),!0}})}#s(){for(let[t,e]of this[v])this.#i(t,e);this[v].clear(),this.$requestUpdate()}#n(t){return this.constructor[A].get(t)}connectedCallback(){this.$animate&&(this.style.display="none"),this.removed=!1,this.#s(),$t(this.root,this.constructor.styles)}disconnectedCallback(){if(this.keepAlive)y(t=>this.deactivated());else{if(this[N]=!1,!document.body?.contains(this)){let t=this.$events;if(t)for(let e in t){for(let s of t[e])C(s.el,e,s.listener,s.options);delete t[e]}this.removed=!0}y(t=>this.unmounted())}}attributeChangedCallback(t,e,s){if(e!==s){if(t===M){this.keepAlive=s!==null;return}this.#o(t,s,e)}}#i(t,e){let s=this.#n(t)||{},n=s.attrName;if(s.attribute===!1||s.type===null){this.removeAttribute(n);return}switch(s.type){case Number:case String:e===null?this.removeAttribute(n):this.setAttribute(n,e);break;case Boolean:e===null||e===!1?this.removeAttribute(n):this.setAttribute(n,"");break}}#o(t,e,s){let n=x[t],r,i;if(n&&(t=n),i=U(t),r=this.#n(i),r&&(e=B(e,r),r.attribute===!1||r.type===null)){if(e===null)return;if(e===this[i]){this.removeAttribute(t);return}}this[i]=e}$requestUpdate(t){t!==void 0&&(this[v].set(t,this[t]),this.#i(t,this[t])),this[O]===!1&&(this[O]=!0,y(e=>this.#a()))}#a(){let t=this[v];this.#h(),this.#r(t),this.#l()}#r(t){this[N]===!1?(this[N]=!0,this.$animate?.immediate&&this.$animate(),y(e=>{this.keepAlive&&this.activated(),this.mounted(),this.$requestUpdate()})):y(e=>this.updated(t))}#l(){this[v].clear(),this[O]=!1}#h(){try{let t=this.render();Ht(t,this.root,{host:this})}catch(t){console.error(t)}}created(){}mounted(){}activated(){}deactivated(){}unmounted(){}updated(){}render(){return F``}$on(t,e,s){return j(this,t,e,s)}$off(t,e,s){C(this,t,e,s)}$emit(t,e={},s=!1){return tt(this,t,e,s)}};export{q as $,wt as $$,Gt as Component,j as bind,U as camelize,Yt as classMap,St as clearOutsideClick,vt as css,tt as fire,F as html,R as hyphen,Xt as live,y as nextTick,At as offset,Nt as outsideClick,xt as range,It as raw,Zt as styleMap,Dt as svg,C as unbind,Ft as when,Jt as which}; diff --git a/src/webui/lib/wkitd.js b/src/webui/lib/wkitd.js new file mode 100644 index 0000000..605aaa8 --- /dev/null +++ b/src/webui/lib/wkitd.js @@ -0,0 +1,56 @@ +import"wkit";var c=Symbol("router"),d=Symbol("router-view"),m=Symbol("store"),g=new Set,f=new Map,$=new Set,I=class extends WeakMap{broadcast(){for(let t of g){if(t.removed){this.deassign(t);continue}t.$requestUpdate()}}assign(t){g.add(t)}deassign(t){g.delete(t)}},H=new I;Object.defineProperty(window,"wkitd",{get(){return H},set(t){console.error("Can not set readonly property wkitd of window")},enumerable:!1});import{html as x,css as M,Component as j}from"wkit";var z=encodeURIComponent,A=decodeURIComponent;function w(){}function L(t,r,e){Object.defineProperty(t,r,{get(){return e}})}function b(t,r,e){var o;if(Array.isArray(r))r.forEach(function(n,s){o=t?`${t}[${Array.isArray(n)?s:""}]`:s,typeof n=="object"?b(o,n,e):e(o,n)});else for(let n in r)o=t?`${t}[${n}]`:n,typeof r[n]=="object"?b(o,r[n],e):e(o,r[n])}function v(t=""){let r=new URLSearchParams(t),e=Object.create(null);for(let[o,n]of r.entries()){let s=A(o),i=A(n),a=0;if(/(\w+)\[(\w*?)\]/.test(s)){let l=RegExp.$1,p=RegExp.$2;s=l,!p||+p==+p?(i=[i],a|=2):(a|=1,i={[p]:i})}e[s]?a&2?e[s]=e[s].concat(i):a&1?Object.assign(e[s],i):(Array.isArray(e[i])||(e[s]=[e[s]]),e[s].push(i)):e[s]=i}return e}function k(t={}){if(t===null)return"";if(typeof t=="string"||typeof t=="number"||typeof t=="boolean")return t;let r=[];return typeof t=="object"&&b("",t,function(e,o){r.push(e+"="+z(o))}),r.join("&")}import{Component as q}from"wkit";import{bind as X}from"wkit";var Z=/^(#!|#)[\/]+?/,_=/(\/[^/]*)(:[\$@~\\!A-Za-z0-9_=\-]+)(\?)?/g,y="hash",N="history",S=class{type=y;#t=new Map;#r=new Set;#o=!1;#e=Object.create(null);#s=null;#i;constructor(t=y){this.type=t,X(window,"popstate",this.#a.bind(this))}get route(){return this.#e}get views(){return Array.from(this.#r)}#a(t){this.#o&&this.#p()}#l(t){if(t.path==="!")t.regexp=null;else{let r=[],e;if(t.path.includes("?")&&t.path.at(-1)!=="?")throw new SyntaxError(`The exp "?" can only be used in the last. + + ${JSON.stringify(t)} +`);e=t.path.replace(_,function(o,n,s,i=""){return r.push(s.slice(1)),n==="/"&&(n="/?"),n+"([\\$\\!@~A-Za-z0-9_=\\-]+)"+i}),e="^"+e+"$",t.regexp=new RegExp(e),t.vars=r}return t}#h(t){if(t.path!=="!"&&t.path[0]!=="/"){console.error('route path must start with "/"');return}t.path=t.path.replace(/^[\/]+|[\/]+$|\s+/g,"/"),this.#t.set(t.path,this.#l(t)),this.#r.add(t.name)}#p(){let t=this.type===y,r=window.wkitd.get(d),e=location.hash||"#/",o=t?e:location.href.replace(location.origin,"").replace(e,""),n="";if(o.includes("?")&&([o,n]=o.split("?")),o=o.replace(Z,"/"),o==="/index.html"&&(o="/"),!r||o===this.#e.path)return n!==k(this.#e.query)?(this.#e.query=v(n),this.#c()):void 0;for(let[s,i]of this.#t){let a=o.match(i.regexp);if(a){let l=Object.create(null);for(let u=1;u{this.#n(p)}):this.#n(p)}}if(this.#t.get("!")){let s=this.#t.get("!");r.current=s.name,this.#e={path:o,name:s.name,params:{},query:{}},this.#n(this.#e)}else this.#s&&(this.#n(this.#s),this.#s=null)}#n(t){let r=window.wkitd.get(d),e=this.#t.get(t.raw);r.current=t.name,this.#e=t,e&&typeof e.component=="function"&&(customElements.get(t.name)||(e.component(),delete e.component)),this.#c()}#c(){if(this.#o)for(let t of $)t(this.route)}init(){this.#o=!0,this.#a()}beforeEach(t=w){this.#i=t}addRoute(t){Array.isArray(t)?t.forEach(r=>{this.#h(r)}):this.#h(t),this.#o&&this.#a()}go(t=0){history.go(t)}back(){this.go(-1)}forward(){this.go(1)}push(t={path:"",query:{}},r=!1){let e="",o="";typeof t=="string"?e=t.trim():(o=k(t.query||""),e=t.path+(o?`?${o}`:"")),!(!e&&e===location.hash.slice(1))&&(this.#s=t,this.type===y?r?location.replace(e.replace(/^\//,"#/")):location.hash=e:(r?window.history.replaceState({path:e},null,e+o):window.history.pushState({path:e},null,e+o),this.#p()))}replace(t={path:"",query:{}}){this.push(t,!0)}};function O(){return()=>new S}function T(){return()=>new S(N)}import{Component as R,html as B,css as E,raw as C}from"wkit";import{Component as U}from"wkit";function P(t,r=["$store"]){return t===null?t:new Proxy(t,{get(e,o,n){let s=Reflect.get(e,o,n);return typeof s=="object"?P(s,r.concat(o)):s},set(e,o,n,s){let i=r.concat(o).join(".");return e[o]===n||(Reflect.set(e,o,n,s),f.get(i)&&f.get(i).forEach(a=>{a(n)}),window.wkitd.broadcast()),!0}})}function W(t,r=w){if(t.startsWith("$store.")){let e=f.get(t);e?e.add(r):(e=new Set,e.add(r),f.set(t,e))}else if(t.startsWith("$route"))$.add(r),r(window.wkitd.get(c).route);else return console.error("watch() only work on $store and $route")}function D(t={}){let r=!1;return function(){Object.defineProperty(U.prototype,"$store",{get(){return window.wkitd.assign(this),window.wkitd.get(m)},set(e){if(r)return console.error("Can not set readonly property $store of Component");window.wkitd.set(m,P(e)),r=!0}}),U.prototype.$store=t}}var G=class extends R{static props={transition:!1};static styles=E` + :host { + display: block; + } + `;get current(){return this.#t}set current(t){let r=this.#t,e=this.$refs;if(this.#t=t,this.keepAlive){if(r){let o=e[r];o?(o.removed=!0,o.deactivated(),o.remove()):this.$requestUpdate()}else this.$requestUpdate();if(t){let o=e[t];o?(this.root.appendChild(o),o.$requestUpdate(),this.transition&&o.$animate(),o.removed=!1,o.activated()):this.$requestUpdate()}}else this.$requestUpdate()}#t="";#r=[];created(){window.wkitd.set(d,this)}sync(t){this.#r=t}render(){let t={immediate:!0,custom:[{transform:"translateX(-32px)",opacity:0},{transform:"translateX(0)",opacity:1}]},r=this.current;if(r)return this.transition?C(`<${r} ref="${r}" ${this.keepAlive?"keep-alive":""} #animation="%s">`,[t]):C(`<${r} ref="${r}" ${this.keepAlive?"keep-alive":""}>`)}},J=class extends R{static props={to:{type:null},disabled:!1};static styles=E` + :host { + display: inline-flex; + align-items: center; + -webkit-user-select: none; + user-select: none; + } + a { + display: flex; + align-items: center; + justify-content: center; + gap: var(--router-link-gap, 0); + width: 100%; + height: 100%; + color: inherit; + text-decoration: inherit; + cursor: pointer; + } + + :host([disabled]) a { + opacity: 0.6; + cursor: not-allowed; + } + `;#t={path:""};#r="";#o(){let t=this.$router.type;this.disabled||(t==="hash"?location.hash=this.#r:this.$router.push(this.#t))}#e(){let t,r,e;if(typeof this.to=="string"){let o=this.to.split("?");t=o[0],e=o[1]||"",r=v(e)}else t=this.to.path||"",r=this.to.query||{},e=typeof r=="string"?r.replaceAll("?",""):k(r);t="/"+t.replace(/^\/+/,""),this.#t={path:t,query:r},e&&(t+="?"+e),this.#r=t}activated(){this.mounted()}deactivated(){this.unmounted()}mounted(){W("$route",t=>{this.removed||this.classList.toggle("active",t.path===this.#t.path)})}unmounted(){$.delete(this)}render(){return this.#e(),B``}};G.reg("view","router"),J.reg("link","router");function K({history:t=O(),routes:r=[]}={}){let e=t();window.wkitd.set(c,e),e.addRoute(r);function o(){Object.defineProperty(q.prototype,"$router",{get(){return e}}),Object.defineProperty(q.prototype,"$route",{get(){return e.route}})}return o.beforeEach=e.beforeEach.bind(e),o}var h=class extends j{};function V({data:t={},styles:r=[],methods:e={},mounted:o=w,render:n}={}){return new function(){h.props=t,h.styles=r,Object.assign(h.prototype,e,{mounted:o,created(){L(j.prototype,"$app",this)}}),this.use=function(s=w,...i){return s.apply(h.prototype,i),this},this.mount=function(){let s=window.wkitd.get(c);n?h.prototype.render=n:s?h.prototype.render=function(){return x``}:(h.styles=M` + :host { + font-family: monospace; + color: #647889; + } + .code { + margin: 16px 0; + background: #f7f8fb; + } + `,h.prototype.render=function(){return x` +

It works!!!

+ + If you don't use router, you may define the + render property. + +
+
  createApp({
+
    render() {
+
      return html\`<wc-home></wc-home>\`
+
    }
+
  })
+
  .mount()
+
+ `}),s&&(h.prototype.mounted=function(...i){let a=window.wkitd.get(d);if(a)a.sync(s.views),s.init(),o.call(this,...i);else throw new Error(' not found, "Router" works Unexpected.')}),h.reg("app","v")}}}function F(){return window.wkitd.get(m)}function Q(){return window.wkitd.get(c)}function Y(){return window.wkitd.get(c)?.route}export{V as createApp,K as createRouter,D as createStore,O as createWebHashHistory,T as createWebHistory,Y as getCurrentPage,Q as getRouter,F as getStore,W as watch}; diff --git a/src/webui/store.js b/src/webui/store.js new file mode 100644 index 0000000..5ff3f17 --- /dev/null +++ b/src/webui/store.js @@ -0,0 +1,15 @@ +/** + * {} + * @author yutent + * @date 2023/09/04 11:11:51 + */ + +import { createStore } from 'wkitd' + +export default createStore({ + HOST_DATA: {}, + activeDomain: localStorage.getItem('last_domain') || '', //当前选中的域名 + domains: [], + records: [], + tmp_records: [] +})