From 5605aa94d203099ebd14955e4141377e7141fe1c Mon Sep 17 00:00:00 2001 From: defaultkavy Date: Fri, 11 Oct 2024 23:05:28 +0800 Subject: [PATCH] v0.6.0 new: post favorite. new: User.favorites Map. new: ClientUser.init(), fetch client user fav data on start up. --- dist/assets/index-8i15BK3r.js | 1 - dist/assets/index-B0cSv4EX.js | 1 + dist/assets/index-C3nfTvuP.css | 1 - dist/assets/index-GbkvssuE.css | 1 + dist/index.html | 4 ++-- package.json | 6 +++++- server.ts | 20 +++++++++++++++++ src/component/IonIcon/$IonIcon.ts | 5 +++++ src/route/post/$post_route.ts | 36 ++++++++++++++++++++++++++++--- src/route/post/_$post_route.scss | 27 +++++++++++++++++++++++ src/structure/Booru.ts | 10 +++++++-- src/structure/ClientUser.ts | 21 ++++++++++++++++++ src/structure/Favorite.ts | 32 +++++++++++++++++++++++++++ src/structure/Post.ts | 26 ++++++++++++++++++++-- src/structure/User.ts | 1 + vite.config.ts | 8 +++++++ 16 files changed, 188 insertions(+), 12 deletions(-) delete mode 100644 dist/assets/index-8i15BK3r.js create mode 100644 dist/assets/index-B0cSv4EX.js delete mode 100644 dist/assets/index-C3nfTvuP.css create mode 100644 dist/assets/index-GbkvssuE.css create mode 100644 server.ts create mode 100644 src/structure/Favorite.ts diff --git a/dist/assets/index-8i15BK3r.js b/dist/assets/index-8i15BK3r.js deleted file mode 100644 index a5e20b2..0000000 --- a/dist/assets/index-8i15BK3r.js +++ /dev/null @@ -1 +0,0 @@ -var Nt=Object.defineProperty;var yt=r=>{throw TypeError(r)};var Dt=(r,e,t)=>e in r?Nt(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var h=(r,e,t)=>Dt(r,typeof e!="symbol"?e+"":e,t),wt=(r,e,t)=>e.has(r)||yt("Cannot "+t);var M=(r,e,t)=>(wt(r,e,"read from private field"),t?t.call(r):e.get(r)),B=(r,e,t)=>e.has(r)?yt("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(r):e.set(r,t),Q=(r,e,t,s)=>(wt(r,e,"write to private field"),s?s.call(r,t):e.set(r,t),t);(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))s(i);new MutationObserver(i=>{for(const n of i)if(n.type==="childList")for(const a of n.addedNodes)a.tagName==="LINK"&&a.rel==="modulepreload"&&s(a)}).observe(document,{childList:!0,subtree:!0});function t(i){const n={};return i.integrity&&(n.integrity=i.integrity),i.referrerPolicy&&(n.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?n.credentials="include":i.crossOrigin==="anonymous"?n.credentials="omit":n.credentials="same-origin",n}function s(i){if(i.ep)return;i.ep=!0;const n=t(i);fetch(i.href,n)}})();class G{constructor(){h(this,"__hidden",!1);h(this,"domEvents",{});h(this,"parent");h(this,"events",new et)}on(e,t,s){e=_.orArrayResolve(e);for(const i of e){this.domEvents[i]||(this.domEvents[i]=new Map);const n=a=>{t(a,this)};this.domEvents[i].set(t,n),this.events.on(i,t),this.dom.addEventListener(i,n,s)}return this}off(e,t,s){var n;const i=(n=this.domEvents[e])==null?void 0:n.get(t);return i&&this.dom.removeEventListener(e,i,s),this.events.off(e,t),this}once(e,t,s){const i=n=>{this.dom.removeEventListener(e,i,s),t(n,this)};return this.dom.addEventListener(e,i,s),this.events.once(e,t),this}hide(e,t=!0){return _.fluent(this,arguments,()=>this.__hidden,()=>{var s;if(e!==void 0)return e instanceof I?(this.__hidden=e.value,e.use(this,"hide")):this.__hidden=e,t&&((s=this.parent)==null||s.children.render()),this})}remove(){var e;return(e=this.parent)==null||e.children.remove(this).render(),this}replace(e){var t;return(t=this.parent)==null||t.children.replace(this,e).render(),this}contains(e){return e?e instanceof G?this.dom.contains(e.dom):e instanceof EventTarget?this.dom.contains(_(e).dom):this.dom.contains(e):!1}self(e){return e(this),this}inDOM(){return document.contains(this.dom)}isElement(){return this instanceof R}get element(){return this instanceof R?this:null}}class R extends G{constructor(t,s){super();h(this,"dom");h(this,"static_classes",new Set);this.dom=this.createDom(t,s),this.dom.$=this,this.setOptions(s)}createDom(t,s){return s!=null&&s.dom?s.dom:t==="svg"?document.createElementNS("http://www.w3.org/2000/svg","svg"):document.createElement((s==null?void 0:s.tagname)??t)}setOptions(t){return this.id(t==null?void 0:t.id),t&&t.class&&this.class(...t.class),this}id(t){return $.fluent(this,arguments,()=>this.dom.id,()=>$.set(this.dom,"id",t))}class(...t){return $.fluent(this,arguments,()=>this.dom.classList,()=>{this.dom.classList.forEach(s=>this.static_classes.has(s)??this.dom.classList.remove(s)),this.dom.classList.add(...t.detype())})}addClass(...t){return $.fluent(this,arguments,()=>this,()=>{this.dom.classList.add(...t.detype())})}removeClass(...t){return $.fluent(this,arguments,()=>this,()=>{this.dom.classList.remove(...t.detype())})}staticClass(...t){return $.fluent(this,arguments,()=>this.static_classes,()=>{this.removeClass(...this.static_classes),this.static_classes.clear(),this.addStaticClass(...t)})}addStaticClass(...t){return $.fluent(this,arguments,()=>this,()=>{t.detype().forEach(s=>this.static_classes.add(s)),this.addClass(...t)})}removeStaticClass(...t){return $.fluent(this,arguments,()=>this,()=>{t.detype().forEach(s=>this.static_classes.delete(s)),this.removeClass(...t)})}css(t){return $.fluent(this,arguments,()=>this.dom.style,()=>{Object.assign(this.dom.style,t)})}attribute(t,s){return arguments.length?arguments.length===1?t===void 0?null:this.dom.getAttribute(t):arguments.length===2?t?(s===null?this.dom.removeAttribute(t):s!==void 0&&this.dom.setAttribute(t,`${s}`),this):this:this:null}tabIndex(t){return $.fluent(this,arguments,()=>this.dom.tabIndex,()=>$.set(this.dom,"tabIndex",t))}focus(){return this.dom.focus(),this}blur(){return this.dom.blur(),this}animate(t,s,i){const n=this.dom.animate(t,s);return i&&(n.onfinish=()=>i(n)),n}getAnimations(t){return this.dom.getAnimations(t)}get dataset(){return this.dom.dataset}domRect(t){const s=this.dom.getBoundingClientRect();if(!t)return s;const i=t instanceof R?t.dom.getBoundingClientRect():t;return{...s,top:s.top-i.top,left:s.left-i.left,right:s.right-i.left,bottom:s.bottom-i.top,x:s.x-i.x,y:s.y-i.y}}}class Y extends G{constructor(t){super();h(this,"dom");this.dom=t,this.dom.$=this}domRect(t){const s={bottom:innerHeight,height:innerHeight,left:0,right:innerWidth,top:0,width:innerWidth,x:0,y:0};if(!t)return s;const i=t instanceof R?t.dom.getBoundingClientRect():t;return{...s,top:s.top-i.top,left:s.left-i.left,right:s.right-i.left,bottom:s.bottom-i.top,x:s.x-i.x,y:s.y-i.y}}static from(t){return t.$ instanceof Y?t.$:new Y(t)}}const Ht="modulepreload",Vt=function(r){return"/"+r},bt={},Wt=function(e,t,s){let i=Promise.resolve();if(t&&t.length>0){document.getElementsByTagName("link");const a=document.querySelector("meta[property=csp-nonce]"),o=(a==null?void 0:a.nonce)||(a==null?void 0:a.getAttribute("nonce"));i=Promise.allSettled(t.map(l=>{if(l=Vt(l),l in bt)return;bt[l]=!0;const d=l.endsWith(".css"),u=d?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${l}"]${u}`))return;const m=document.createElement("link");if(m.rel=d?"stylesheet":Ht,d||(m.as="script"),m.crossOrigin="",m.href=l,o&&m.setAttribute("nonce",o),document.head.appendChild(m),d)return new Promise((w,c)=>{m.addEventListener("load",w),m.addEventListener("error",()=>c(new Error(`Unable to preload CSS for ${l}`)))})}))}function n(a){const o=new Event("vite:preloadError",{cancelable:!0});if(o.payload=a,window.dispatchEvent(o),!o.defaultPrevented)throw a}return i.then(a=>{for(const o of a||[])o.status==="rejected"&&n(o.reason);return e().catch(n)})};class jt{constructor(e){h(this,"$container");h(this,"childList",new Set);this.$container=e}add(e,t=-1){if(t===-1||this.childList.size-1===t)this.childList.add(e);else{const s=[...this.childList];s.splice(t,0,e),this.childList.clear(),s.forEach(i=>this.childList.add(i))}e.parent=this.$container}remove(e){return this.childList.has(e)?(this.childList.delete(e),e.parent=void 0,this):this}removeAll(e=!0){this.childList.forEach(t=>this.remove(t)),e&&this.render()}replace(e,t){const s=this.array;return s.splice(s.indexOf(e),1,t),e.remove(),this.childList.clear(),s.forEach(i=>this.childList.add(i)),t.parent=this.$container,this}render(){const[e,t]=[this.array.map(i=>i.dom),Array.from(this.dom.childNodes)],s=[];for(;t.length||e.length;){const[i,n]=[t.at(0),e.at(0)];n?i?n!==i?(n.$.__hidden||(this.dom.insertBefore(n,i),s.push(n)),e.shift()):(n.$.__hidden&&this.dom.removeChild(n),e.shift(),t.shift()):(n.$.__hidden||this.dom.append(n),e.shift()):(i&&!s.includes(i)&&i.remove(),t.shift())}}indexOf(e){return this.array.indexOf(e)}get array(){return[...this.childList.values()]}get dom(){return this.$container.dom}}class I{constructor(e,t){h(this,"_value");h(this,"attributes",new Map);h(this,"linkStates",new Set);h(this,"options",{});this.set(e),t&&(this.options=t)}set(e){this._value=e,e instanceof I&&e.linkStates.add(this),this.update(),this.linkStates.forEach(t=>t.update())}static toJSON(e){const t={};for(let[s,i]of Object.entries(e))i instanceof I?i=i.toJSON():i instanceof Object&&I.toJSON(i),Object.assign(t,{[s]:i});return t}update(){for(const[e,t]of this.attributes.entries())for(const s of t)e[s]instanceof Function?this.options.format?e[s](this.options.format(this.value)):e[s](this.value):s in e&&(e[s]=this.value)}use(e,t){const s=this.attributes.get(e);s?s.add(t):this.attributes.set(e,new Set().add(t))}convert(e){return new I(this,{format:e})}get value(){return this._value instanceof I?this._value.value:this._value}toString(){return this.options.format?this.options.format(this.value):this.value instanceof Object?JSON.stringify(this.toJSON()):`${this.value}`}toJSON(){return this.value instanceof I?this.value.toJSON():this.value instanceof Object?I.toJSON(this.value):this.toString()}}class K extends G{constructor(t){super();h(this,"dom");this.dom=new Text(t),this.dom.$=this}content(t){return $.fluent(this,arguments,()=>this.dom.textContent,()=>$.set(this.dom,"textContent",t))}}class Z extends R{constructor(e,t){super(e,t)}autocapitalize(e){return $.fluent(this,arguments,()=>this.dom.autocapitalize,()=>$.set(this.dom,"autocapitalize",e))}innerText(e){return $.fluent(this,arguments,()=>this.dom.innerText,()=>$.set(this.dom,"innerText",e))}title(e){return $.fluent(this,arguments,()=>this.dom.title,()=>$.set(this.dom,"title",e))}dir(e){return $.fluent(this,arguments,()=>this.dom.dir,()=>$.set(this.dom,"dir",e))}translate(e){return $.fluent(this,arguments,()=>this.dom.translate,()=>$.set(this.dom,"translate",e))}popover(e){return $.fluent(this,arguments,()=>this.dom.popover,()=>$.set(this.dom,"popover",e))}spellcheck(e){return $.fluent(this,arguments,()=>this.dom.spellcheck,()=>$.set(this.dom,"spellcheck",e))}inert(e){return $.fluent(this,arguments,()=>this.dom.inert,()=>$.set(this.dom,"inert",e))}lang(e){return $.fluent(this,arguments,()=>this.dom.lang,()=>$.set(this.dom,"lang",e))}draggable(e){return $.fluent(this,arguments,()=>this.dom.draggable,()=>$.set(this.dom,"draggable",e))}hidden(e){return $.fluent(this,arguments,()=>this.dom.hidden,()=>$.set(this.dom,"hidden",e))}click(){return this.dom.click(),this}attachInternals(){return this.dom.attachInternals()}hidePopover(){return this.dom.hidePopover(),this}showPopover(){return this.dom.showPopover(),this}togglePopover(){return this.dom.togglePopover(),this}get accessKeyLabel(){return this.dom.accessKeyLabel}get offsetHeight(){return this.dom.offsetHeight}get offsetLeft(){return this.dom.offsetLeft}get offsetParent(){return $(this.dom.offsetParent)}get offsetTop(){return this.dom.offsetTop}get offsetWidth(){return this.dom.offsetWidth}}class p extends Z{constructor(t,s){super(t,s);h(this,"children",new jt(this));h(this,"__position_cursor",0)}content(t){return $.fluent(this,arguments,()=>this,()=>{this.children.removeAll(!1),this.insert(t)})}insert(t,s=-1){return $.fluent(this,arguments,()=>this,async()=>{if(t instanceof Function){let i=t(this);i instanceof Promise?t=await i:t=i}else t instanceof Promise&&(t=await t);t=$.orArrayResolve(t),this.__position_cursor=s<0?this.children.array.length+s:s;for(const i of t)if(i!=null){if(i instanceof Array)this.insert(i,this.__position_cursor);else if(typeof i=="string")this.children.add(new K(i),s);else if(i instanceof I){const n=new K(i.toString());i.use(n,"content"),this.children.add(n,s)}else if(i instanceof Promise){const n=(await Wt(async()=>{const{$Async:o}=await Promise.resolve().then(()=>Qt);return{$Async:o}},void 0)).$Async,a=new n().await(i);this.children.add(a,s)}else this.children.add(i,s);this.__position_cursor+=1}this.children.render()})}clear(){return this.children.removeAll(),this}$(t){return $(this.dom.querySelector(t))}$all(t){return Array.from(this.dom.querySelectorAll(t)).map(s=>$(s))}get scrollHeight(){return this.dom.scrollHeight}get scrollWidth(){return this.dom.scrollWidth}scrollTop(t){return $.fluent(this,arguments,()=>this.dom.scrollTop,()=>$.set(this.dom,"scrollTop",t))}scrollLeft(t){return $.fluent(this,arguments,()=>this.dom.scrollLeft,()=>$.set(this.dom,"scrollLeft",t))}}class Ft extends p{constructor(e){super("a",e),this.dom.addEventListener("click",t=>{$.anchorHandler&&this.href()&&(t.preventDefault(),$.anchorHandler(this,t))})}href(e){return $.fluent(this,arguments,()=>this.dom.href,()=>$.set(this.dom,"href",e))}target(e){return $.fluent(this,arguments,()=>this.dom.target??void 0,()=>{e&&(this.dom.target=e)})}}class Ut extends R{constructor(e,t){super(e,t)}}var O;(r=>{function e(o,l,d,u){return l.length?(u(),o):d()}r.fluent=e;function t(o){return o instanceof Array?o:[o]}r.orArrayResolve=t;function s(o,l){return t(l).forEach(d=>{Object.getOwnPropertyNames(d.prototype).forEach(u=>{u!=="constructor"&&Object.defineProperty(o.prototype,u,Object.getOwnPropertyDescriptor(d.prototype,u)||Object.create(null))})}),o}r.mixin=s;function i(o,l,d){d!==void 0&&(o[l]=d)}r.set=i;function n(o){return new I(o)}r.state=n;function a(o){if(o.$)return o.$;if(o.nodeName.toLowerCase()==="body")return new p("body",{dom:o});if(o.nodeName.toLowerCase()==="#document")return Y.from(o);if(o instanceof HTMLElement){const l=$.TagNameElementMap[o.tagName.toLowerCase()],d=l===p?new l(o.tagName,{dom:o}):new l({dom:o});if(d instanceof p)for(const u of Array.from(d.dom.childNodes))d.children.add($(u));return d}else if(o instanceof Text){const l=new K(o.textContent??"");return l.dom=o,l}else if(o instanceof SVGElement&&o.tagName.toLowerCase()==="svg")return new Ut("svg",{dom:o});throw`$NODE.FROM: NOT SUPPORT TARGET ELEMENT TYPE (${o.nodeName})`}r.from=a})(O||(O={}));class A{static create(...e){const t=class{};return Object.getOwnPropertyNames(A.prototype).forEach(s=>{s!=="constructor"&&e.includes(s)&&Object.defineProperty(t.prototype,s,Object.getOwnPropertyDescriptor(A.prototype,s)||Object.create(null))}),t}disabled(e){return $.fluent(this,arguments,()=>this.dom.disabled,()=>$.set(this.dom,"disabled",e))}checkValidity(){return this.dom.checkValidity()}reportValidity(){return this.dom.reportValidity()}formAction(e){return $.fluent(this,arguments,()=>this.dom.formAction,()=>$.set(this.dom,"formAction",e))}formEnctype(e){return $.fluent(this,arguments,()=>this.dom.formEnctype,()=>$.set(this.dom,"formEnctype",e))}formMethod(e){return $.fluent(this,arguments,()=>this.dom.formMethod,()=>$.set(this.dom,"formMethod",e))}formNoValidate(e){return $.fluent(this,arguments,()=>this.dom.formNoValidate,()=>$.set(this.dom,"formNoValidate",e))}formTarget(e){return $.fluent(this,arguments,()=>this.dom.formTarget,()=>$.set(this.dom,"formTarget",e))}autocomplete(e){return $.fluent(this,arguments,()=>this.dom.autocomplete,()=>$.set(this.dom,"autocomplete",e))}name(e){return $.fluent(this,arguments,()=>this.dom.name,()=>$.set(this.dom,"name",e))}maxLength(e){return $.fluent(this,arguments,()=>this.dom.maxLength,()=>$.set(this.dom,"maxLength",e))}minLength(e){return $.fluent(this,arguments,()=>this.dom.minLength,()=>$.set(this.dom,"minLength",e))}required(e){return $.fluent(this,arguments,()=>this.dom.required,()=>$.set(this.dom,"required",e))}label(e){return $.fluent(this,arguments,()=>this.dom.label,()=>$.set(this.dom,"label",e))}get form(){return this.dom.form?$(this.dom.form):null}get validationMessage(){return this.dom.validationMessage}get validity(){return this.dom.validity}get willValidate(){return this.dom.willValidate}}class mt extends p{constructor(e){super("button",e)}type(e){return $.fluent(this,arguments,()=>this.dom.type,()=>$.set(this.dom,"type",e))}}O.mixin(mt,A.create("disabled","checkValidity","formAction","formEnctype","formMethod","formNoValidate","formTarget","reportValidity"));class St extends p{constructor(e){super("form",e)}action(e){return $.fluent(this,arguments,()=>this.dom.formAction,()=>$.set(this.dom,"formAction",e))}enctype(e){return $.fluent(this,arguments,()=>this.dom.formEnctype,()=>$.set(this.dom,"formEnctype",e))}method(e){return $.fluent(this,arguments,()=>this.dom.formMethod,()=>$.set(this.dom,"formMethod",e))}noValidate(e){return $.fluent(this,arguments,()=>this.dom.formNoValidate,()=>$.set(this.dom,"formNoValidate",e))}acceptCharset(e){return $.fluent(this,arguments,()=>this.dom.acceptCharset,()=>$.set(this.dom,"acceptCharset",e))}target(e){return $.fluent(this,arguments,()=>this.dom.formTarget,()=>$.set(this.dom,"formTarget",e))}requestSubmit(){return this.dom.requestSubmit(),this}reset(){return this.dom.reset(),this}submit(){return this.dom.submit(),this}get length(){return this.dom.length}get elements(){return Array.from(this.dom.elements).map(e=>$(e))}}O.mixin(St,A.create("checkValidity","reportValidity","autocomplete"));class N extends Z{constructor(e){super("input",e)}value(e){return $.fluent(this,arguments,()=>this.type()==="number"?Number(this.dom.value):this.dom.value,()=>$.set(this.dom,"value",e,t=>{this.on("input",()=>{t.attributes.has(this.dom)!==!1&&(typeof t.value=="string"&&t.set(`${this.value()}`),typeof t.value=="number"&&t.set(Number(this.value())))})}))}type(e){return $.fluent(this,arguments,()=>this.dom.type,()=>$.set(this.dom,"type",e))}capture(e){return $.fluent(this,arguments,()=>this.dom.capture,()=>$.set(this.dom,"capture",e))}alt(e){return $.fluent(this,arguments,()=>this.dom.alt,()=>$.set(this.dom,"alt",e))}height(e){return $.fluent(this,arguments,()=>this.dom.height,()=>$.set(this.dom,"height",e))}width(e){return $.fluent(this,arguments,()=>this.dom.width,()=>$.set(this.dom,"width",e))}defaultValue(e){return $.fluent(this,arguments,()=>this.dom.defaultValue,()=>$.set(this.dom,"defaultValue",e))}dirName(e){return $.fluent(this,arguments,()=>this.dom.dirName,()=>$.set(this.dom,"dirName",e))}pattern(e){return $.fluent(this,arguments,()=>this.dom.pattern,()=>$.set(this.dom,"pattern",e))}placeholder(e){return $.fluent(this,arguments,()=>this.dom.placeholder,()=>$.set(this.dom,"placeholder",e))}readOnly(e){return $.fluent(this,arguments,()=>this.dom.readOnly,()=>$.set(this.dom,"readOnly",e))}selectionDirection(e){return $.fluent(this,arguments,()=>this.dom.selectionDirection,()=>$.set(this.dom,"selectionDirection",e))}selectionEnd(e){return $.fluent(this,arguments,()=>this.dom.selectionEnd,()=>$.set(this.dom,"selectionEnd",e))}selectionStart(e){return $.fluent(this,arguments,()=>this.dom.selectionStart,()=>$.set(this.dom,"selectionStart",e))}size(e){return $.fluent(this,arguments,()=>this.dom.size,()=>$.set(this.dom,"size",e))}src(e){return $.fluent(this,arguments,()=>this.dom.src,()=>$.set(this.dom,"src",e))}inputMode(e){return $.fluent(this,arguments,()=>this.dom.inputMode,()=>$.set(this.dom,"inputMode",e))}valueAsDate(e){return $.fluent(this,arguments,()=>this.dom.valueAsDate,()=>$.set(this.dom,"valueAsDate",e))}valueAsNumber(e){return $.fluent(this,arguments,()=>this.dom.valueAsNumber,()=>$.set(this.dom,"valueAsNumber",e))}webkitdirectory(e){return $.fluent(this,arguments,()=>this.dom.webkitdirectory,()=>$.set(this.dom,"webkitdirectory",e))}select(){return this.dom.select(),this}setCustomValidity(e){return this.dom.setCustomValidity(e),this}setRangeText(e,t,s,i){return typeof t=="number"&&typeof s=="number"&&this.dom.setRangeText(e,t,s,i),this.dom.setRangeText(e),this}setSelectionRange(e,t,s){return this.dom.setSelectionRange(e,t,s),this}showPicker(){return this.dom.showPicker(),this}get files(){return this.dom.files}get webkitEntries(){return this.dom.webkitEntries}get labels(){return Array.from(this.dom.labels??[]).map(e=>$(e))}}O.mixin(N,A.create("checkValidity","reportValidity","autocomplete","name","form","required","validationMessage","validity","willValidate","formAction","formEnctype","formMethod","formNoValidate","formTarget"));class Gt extends N{constructor(e){super(e),this.type("number")}static from(e){return $.mixin(N,this)}stepDown(){return this.dom.stepDown(),this}stepUp(){return this.dom.stepUp(),this}max(e){return $.fluent(this,arguments,()=>this.dom.max===""?null:parseInt(this.dom.min),()=>$.set(this.dom,"max",e==null?void 0:e.toString()))}min(e){return $.fluent(this,arguments,()=>this.dom.min===""?null:parseInt(this.dom.min),()=>$.set(this.dom,"min",e==null?void 0:e.toString()))}step(e){return $.fluent(this,arguments,()=>Number(this.dom.step),()=>$.set(this.dom,"step",e==null?void 0:e.toString()))}}class zt extends N{constructor(e){super(e),this.type("radio")}static from(e){return $.mixin(N,this)}checked(e){return $.fluent(this,arguments,()=>this.dom.checked,()=>$.set(this.dom,"checked",e))}defaultChecked(e){return $.fluent(this,arguments,()=>this.dom.defaultChecked,()=>$.set(this.dom,"defaultChecked",e))}}class Kt extends N{constructor(e){super(e),this.type("file")}static from(e){return $.mixin(N,this)}multiple(e){return $.fluent(this,arguments,()=>this.dom.multiple,()=>$.set(this.dom,"multiple",e))}accept(...e){return $.fluent(this,arguments,()=>this.dom.accept.split(","),()=>this.dom.accept=e.toString())}}O.mixin(N,[Gt,zt,Kt]);class It extends p{constructor(e){super("label",e)}for(e){return $.fluent(this,arguments,()=>this.dom.htmlFor,()=>{$.set(this.dom,"htmlFor",e)})}get control(){return this.dom.control}}O.mixin(It,A.create("form"));class Xt extends Z{constructor(e){super("img",e)}async load(e){return new Promise(t=>{const s=this.once("load",()=>{t(s)});typeof e=="string"?s.src(e):e.then(i=>s.src(i))})}static resize(e,t){return new Promise(s=>{const i=new Image;if(i.addEventListener("load",()=>{const n=document.createElement("canvas"),a=n.getContext("2d");if(!a)throw"$Image.resize: context undefined";const o=i.width/i.height,[l,d,u]=[o>1,o<1,o===1],m=t instanceof Array?t[0]:d?t:t*o,w=t instanceof Array?t[1]:l?t:t/o;n.height=w,n.width=m,a.drawImage(i,0,0,m,w),s(n.toDataURL())},{once:!0}),e instanceof File){const n=new FileReader;n.addEventListener("load",()=>i.src=n.result),n.readAsDataURL(e)}else i.src=e})}alt(e){return $.fluent(this,arguments,()=>this.dom.alt,()=>$.set(this.dom,"alt",e))}crossOrigin(e){return $.fluent(this,arguments,()=>this.dom.crossOrigin,()=>$.set(this.dom,"crossOrigin",e))}decoding(e){return $.fluent(this,arguments,()=>this.dom.decoding,()=>$.set(this.dom,"decoding",e))}height(e){return $.fluent(this,arguments,()=>this.dom.height,()=>$.set(this.dom,"height",e))}isMap(e){return $.fluent(this,arguments,()=>this.dom.isMap,()=>$.set(this.dom,"isMap",e))}loading(e){return $.fluent(this,arguments,()=>this.dom.loading,()=>$.set(this.dom,"loading",e))}referrerPolicy(e){return $.fluent(this,arguments,()=>this.dom.referrerPolicy,()=>$.set(this.dom,"referrerPolicy",e))}sizes(e){return $.fluent(this,arguments,()=>this.dom.sizes,()=>$.set(this.dom,"sizes",e))}src(e){return $.fluent(this,arguments,()=>this.dom.src,()=>$.set(this.dom,"src",e))}srcset(e){return $.fluent(this,arguments,()=>this.dom.srcset,()=>$.set(this.dom,"srcset",e))}useMap(e){return $.fluent(this,arguments,()=>this.dom.useMap,()=>$.set(this.dom,"useMap",e))}width(e){return $.fluent(this,arguments,()=>this.dom.width,()=>$.set(this.dom,"width",e))}decode(){return this.dom.decode()}get complete(){return this.dom.complete}get currentSrc(){return this.dom.currentSrc}get naturalHeight(){return this.dom.naturalHeight}get naturalWidth(){return this.dom.naturalWidth}get x(){return this.dom.x}get y(){return this.dom.y}}class qt extends p{constructor(e){super("canvas",e)}height(e){return $.fluent(this,arguments,()=>this.dom.height,()=>{$.set(this.dom,"height",e)})}width(e){return $.fluent(this,arguments,()=>this.dom.width,()=>{$.set(this.dom,"width",e)})}captureStream(e){return this.dom.captureStream(e)}getContext(e,t){return this.dom.getContext(e)}toBlob(e,t,s){return this.dom.toBlob(e,t,s),this}toDataURL(e,t){return this.dom.toDataURL(e,t)}transferControlToOffscreen(){return this.dom.transferControlToOffscreen()}}class Bt extends p{constructor(e){super("dialog",e)}open(e){return $.fluent(this,arguments,()=>this.dom.open,()=>$.set(this.dom,"open",e))}returnValue(e){return $.fluent(this,arguments,()=>this.dom.returnValue,()=>$.set(this.dom,"returnValue",e))}close(){return this.dom.close(),this}show(){return this.dom.show(),this}showModal(){return this.dom.showModal(),this}}class Ot extends p{constructor(e){super("select")}add(e){return this.insert(e),this}item(e){return $(this.dom.item(e))}namedItem(e){return $(this.dom.namedItem(e))}multiple(e){return $.fluent(this,arguments,()=>this.dom.multiple,()=>$.set(this.dom,"multiple",e))}get length(){return this.dom.length}get size(){return this.dom.size}get options(){return Array.from(this.dom.options).map(e=>$(e))}get selectedIndex(){return this.dom.selectedIndex}get selectedOptions(){return Array.from(this.dom.selectedOptions).map(e=>$(e))}value(e){return $.fluent(this,arguments,()=>this.dom.value,()=>$.set(this.dom,"value",e,t=>{this.on("input",()=>{t.attributes.has(this.dom)!==!1&&(typeof t.value=="string"&&t.set(`${this.value()}`),typeof t.value=="number"&&t.set(Number(this.value())))})}))}get labels(){return Array.from(this.dom.labels??[]).map(e=>$(e))}}O.mixin(Ot,A.create("checkValidity","reportValidity","autocomplete","name","form","required","disabled","validationMessage","validity","willValidate"));class xt extends p{constructor(e){super("option",e)}defaultSelected(e){return $.fluent(this,arguments,()=>this.dom.defaultSelected,()=>$.set(this.dom,"defaultSelected",e))}selected(e){return $.fluent(this,arguments,()=>this.dom.selected,()=>$.set(this.dom,"selected",e))}text(e){return $.fluent(this,arguments,()=>this.dom.text,()=>$.set(this.dom,"text",e))}value(e){return $.fluent(this,arguments,()=>this.dom.value,()=>$.set(this.dom,"value",e))}get form(){return this.dom.form?$(this.dom.form):null}get index(){return this.dom.index}}O.mixin(xt,A.create("form","disabled","label"));class Mt extends p{constructor(e){super("optgroup",e)}disabled(e){return $.fluent(this,arguments,()=>this.dom.disabled,()=>$.set(this.dom,"disabled",e))}}O.mixin(Mt,A.create("disabled","label"));class Et extends p{constructor(e){super("textarea",e)}cols(e){return $.fluent(this,arguments,()=>this.dom.cols,()=>$.set(this.dom,"cols",e))}wrap(e){return $.fluent(this,arguments,()=>this.dom.wrap,()=>$.set(this.dom,"wrap",e))}value(e){return $.fluent(this,arguments,()=>this.dom.value,()=>$.set(this.dom,"value",e))}defaultValue(e){return $.fluent(this,arguments,()=>this.dom.defaultValue,()=>$.set(this.dom,"defaultValue",e))}dirName(e){return $.fluent(this,arguments,()=>this.dom.dirName,()=>$.set(this.dom,"dirName",e))}placeholder(e){return $.fluent(this,arguments,()=>this.dom.placeholder,()=>$.set(this.dom,"placeholder",e))}readOnly(e){return $.fluent(this,arguments,()=>this.dom.readOnly,()=>$.set(this.dom,"readOnly",e))}selectionDirection(e){return $.fluent(this,arguments,()=>this.dom.selectionDirection,()=>$.set(this.dom,"selectionDirection",e))}selectionEnd(e){return $.fluent(this,arguments,()=>this.dom.selectionEnd,()=>$.set(this.dom,"selectionEnd",e))}selectionStart(e){return $.fluent(this,arguments,()=>this.dom.selectionStart,()=>$.set(this.dom,"selectionStart",e))}type(e){return $.fluent(this,arguments,()=>this.dom.type,()=>$.set(this.dom,"type",e))}inputMode(e){return $.fluent(this,arguments,()=>this.dom.inputMode,()=>$.set(this.dom,"inputMode",e))}select(){return this.dom.select(),this}setCustomValidity(e){return this.dom.setCustomValidity(e),this}setRangeText(e,t,s,i){return typeof t=="number"&&typeof s=="number"&&this.dom.setRangeText(e,t,s,i),this.dom.setRangeText(e),this}setSelectionRange(e,t,s){return this.dom.setSelectionRange(e,t,s),this}get labels(){return Array.from(this.dom.labels??[]).map(e=>$(e))}}O.mixin(Et,A.create("checkValidity","reportValidity","autocomplete","name","form","required","disabled","minLength","maxLength","validationMessage","validity","willValidate"));var tt;class Pt extends p{constructor(t){super("async",t);B(this,tt,!1)}await(t){return t instanceof Function?t(this).then(s=>this._loaded(s)):t.then(s=>this._loaded(s)),this}_loaded(t){if(Q(this,tt,!0),typeof t=="string")this.replace(new K(t));else if(t instanceof I){const s=new K(t.toString());t.use(s,"content"),this.replace(s)}else t==null?this.replace(new K(String(t))):this.replace(t);this.dom.dispatchEvent(new Event("load"))}get loaded(){return M(this,tt)}}tt=new WeakMap;const Qt=Object.freeze(Object.defineProperty({__proto__:null,$Async:Pt},Symbol.toStringTag,{value:"Module"}));class Jt extends R{constructor(e,t){super(e,t)}autoplay(e){return $.fluent(this,arguments,()=>this.dom.autoplay,()=>$.set(this.dom,"autoplay",e))}get buffered(){return this.dom.buffered}controls(e){return $.fluent(this,arguments,()=>this.dom.controls,()=>$.set(this.dom,"controls",e))}crossOrigin(e){return $.fluent(this,arguments,()=>this.dom.crossOrigin,()=>$.set(this.dom,"crossOrigin",e))}get currentSrc(){return this.dom.currentSrc}currentTime(e){return $.fluent(this,arguments,()=>this.dom.currentTime,()=>$.set(this.dom,"currentTime",e))}defaultMuted(e){return $.fluent(this,arguments,()=>this.dom.defaultMuted,()=>$.set(this.dom,"defaultMuted",e))}defaultPlaybackRate(e){return $.fluent(this,arguments,()=>this.dom.defaultPlaybackRate,()=>$.set(this.dom,"defaultPlaybackRate",e))}disableRemotePlayback(e){return $.fluent(this,arguments,()=>this.dom.disableRemotePlayback,()=>$.set(this.dom,"disableRemotePlayback",e))}get duration(){return this.dom.duration}get ended(){return this.dom.ended}get error(){return this.dom.error}loop(e){return $.fluent(this,arguments,()=>this.dom.loop,()=>$.set(this.dom,"loop",e))}mediaKeys(e){return $.fluent(this,arguments,()=>this.dom.mediaKeys,()=>$.set(this.dom,"setMediaKeys",[e]))}muted(e){return $.fluent(this,arguments,()=>this.dom.muted,()=>$.set(this.dom,"muted",e))}get networkState(){return this.dom.networkState}get paused(){return this.dom.paused}playbackRate(e){return $.fluent(this,arguments,()=>this.dom.playbackRate,()=>$.set(this.dom,"playbackRate",e))}get played(){return this.dom.played}preload(e){return $.fluent(this,arguments,()=>this.dom.preload,()=>$.set(this.dom,"preload",e))}preservesPitch(e){return $.fluent(this,arguments,()=>this.dom.preservesPitch,()=>$.set(this.dom,"preservesPitch",e))}get readyState(){return this.dom.readyState}get remote(){return this.dom.remote}get seekable(){return this.dom.seekable}get seeking(){return this.dom.seeking}sinkId(e){return $.fluent(this,arguments,()=>this.dom.sinkId,()=>$.set(this.dom,"setSinkId",[e]))}src(e){return $.fluent(this,arguments,()=>this.dom.src,()=>$.set(this.dom,"src",e))}srcObject(e){return $.fluent(this,arguments,()=>this.dom.srcObject,()=>$.set(this.dom,"srcObject",e))}get textTracks(){return this.dom.textTracks}volume(e){return $.fluent(this,arguments,()=>this.dom.volume,()=>$.set(this.dom,"volume",e))}addTextTrack(e,t,s){return this.dom.addTextTrack(e,t,s)}canPlayType(e){return this.dom.canPlayType(e)}fastSeek(e){return this.dom.fastSeek(e),this}load(){return this.dom.load(),this}pause(){return this.dom.pause(),this}async play(){return await this.dom.play(),this}get isPlaying(){return this.currentTime()>0&&!this.paused&&!this.ended&&this.readyState>2}}class Yt extends Jt{constructor(e){super("video",e)}disablePictureInPicture(e){return $.fluent(this,arguments,()=>this.dom.disablePictureInPicture,()=>$.set(this.dom,"disablePictureInPicture",e))}height(e){return $.fluent(this,arguments,()=>this.dom.height,()=>$.set(this.dom,"height",e))}width(e){return $.fluent(this,arguments,()=>this.dom.width,()=>$.set(this.dom,"width",e))}playsInline(e){return $.fluent(this,arguments,()=>this.dom.playsInline,()=>$.set(this.dom,"playsInline",e))}poster(e){return $.fluent(this,arguments,()=>this.dom.poster,()=>$.set(this.dom,"poster",e))}get videoHeight(){return this.dom.videoHeight}get videoWidth(){return this.dom.videoWidth}cancelVideoFrameCallback(e){return this.dom.cancelVideoFrameCallback(e),this}getVideoPlaybackQuality(){return this.dom.getVideoPlaybackQuality()}requestPictureInPicture(){return this.dom.requestPictureInPicture()}requestVideoFrameCallback(e){return this.dom.requestVideoFrameCallback(e)}}function _(r){if(typeof r>"u"||r===null||r instanceof G)return r;if(typeof r=="string"){if(r.startsWith("::"))return Array.from(document.querySelectorAll(r.replace(/^::/,""))).map(e=>_(e));if(r.startsWith(":"))return _(document.querySelector(r.replace(/^:/,"")));if(r in _.TagNameElementMap){const e=_.TagNameElementMap[r];return e===Z?new Z(r):e===p?new p(r):new e}else return new p(r)}if(r instanceof Node)return r.$?r.$:O.from(r);throw`$: NOT SUPPORT TARGET ELEMENT TYPE ('${r}')`}(r=>{r.anchorHandler=null,r.TagNameElementMap={html:p,head:p,document:Y,body:p,a:Ft,p,pre:p,code:p,blockquote:p,strong:p,h1:p,h2:p,h3:p,h4:p,h5:p,h6:p,div:p,ol:p,ul:p,dl:p,li:p,input:N,label:It,button:mt,form:St,img:Xt,dialog:Bt,canvas:qt,select:Ot,option:xt,optgroup:Mt,textarea:Et,video:Yt,async:Pt};function e(c,f,g,T){return f.length?(T(),c):g()}r.fluent=e;function t(c){return c instanceof Array?c:[c]}r.orArrayResolve=t;function s(c,f){return O.mixin(c,f)}r.mixin=s;function i(c,f,g,T){if(g!==void 0){if(g instanceof I){g.use(c,f),c[f]instanceof Function?c[f](...g.value):c[f]=g.value,T&&T(g);return}c[f]instanceof Function?c[f](...g):c[f]=g}}r.set=i;function n(c,f){return new I(c,f)}r.state=n;async function a(c,f){return new Promise(g=>{const T=new FileReader;T.onload=S=>{const b=r("img");if(b.once("load",x=>{const W=r("canvas"),j=W.getContext("2d"),D=b.height()/b.width(),[L,z]=[D>1?f/D:f,D>1?f:f*D];W.height(z).width(L),j==null||j.drawImage(b.dom,0,0,L,z),g(W.toDataURL(c.type))}),!S.target)throw"$.resize(): e.target is null";b.src(S.target.result)},T.readAsDataURL(c)})}r.resize=a;function o(c=1){return parseInt(getComputedStyle(document.documentElement).fontSize)*c}r.rem=o;function l(c){const f=new DOMParser().parseFromString(c,"text/html").body;return Array.from(f.children).map(g=>r(g))}r.html=l;function d(c,f,g){if(typeof f=="number")return Array(f).fill("").map(S=>{const b=T(c)?c[0](...c.slice(1)):r(c);return g&&g(b),b});{const S=[];for(const b of f){const x=c instanceof Function?c(...b):T(c)?c[0](...c.slice(1)):r(c);b instanceof Function?b(x):(b instanceof G||typeof b=="string")&&x.content(b),S.push(x)}return S}function T(S){return S instanceof Array&&S[0]instanceof Function}}r.builder=d;function u(c,f){return Object.assign(r.TagNameElementMap,{[c]:f}),r.TagNameElementMap}r.registerTagName=u;function m(...c){return new et}r.events=m;function w(c){return c()}r.call=w})(_||(_={}));globalThis.$=_;class et{constructor(){h(this,"eventMap",new Map)}fire(e,...t){var s;return(s=this.eventMap.get(e))==null||s.forEach(i=>i(...t)),this}on(e,t){const s=this.eventMap.get(e)??this.eventMap.set(e,new Set).get(e);return s==null||s.add(t),this}off(e,t){var s;return(s=this.eventMap.get(e))==null||s.delete(t),this}once(e,t){const s=(...n)=>{var a;(a=this.eventMap.get(e))==null||a.delete(s),t(...n)},i=this.eventMap.get(e)??this.eventMap.set(e,new Set).get(e);return i==null||i.add(s),this}}Array.prototype.detype=function(...r){return this.filter(e=>{if(r.length)for(const t of r)return typeof e!=typeof t;else return e!==void 0})};Object.defineProperties(Set.prototype,{array:{get:function(){return Array.from(this)}}});Set.prototype.sort=function(r){return this.array.sort(r)};class At extends p{constructor(t){super("layout",t);h(this,"_property",{ROW_MAX_HEIGHT:200,GAP:0,IS_RENDERING:!1,RENDER_REQUEST:!1,COLUNM:1,TYPE:"justified",ROOT:null,ITEM_PROPERTIES:new Map});this.css({display:"block",position:"relative"}),new ResizeObserver(s=>{this.inDOM()&&(this.render(),this.dom.dispatchEvent(new Event("resize")))}).observe(this.dom),document.addEventListener("scroll",s=>{s.target===this.root().dom&&this.scrollCompute()},{passive:!0}),new IntersectionObserver(s=>{this.inDOM()&&this.render()}).observe(this.dom)}type(t){return $.fluent(this,arguments,()=>this._property.TYPE,()=>$.set(this._property,"TYPE",t))}maxHeight(t){return $.fluent(this,arguments,()=>this._property.ROW_MAX_HEIGHT,()=>$.set(this._property,"ROW_MAX_HEIGHT",t))}column(t){return $.fluent(this,arguments,()=>this._property.COLUNM,()=>$.set(this._property,"COLUNM",t))}gap(t){return $.fluent(this,arguments,()=>this._property.GAP,()=>$.set(this._property,"GAP",t))}root(t){return $.fluent(this,arguments,()=>this._property.ROOT??$(document),()=>$.set(this._property,"ROOT",t))}get COL_WIDTH(){return(this.offsetWidth-this._property.GAP*(this._property.COLUNM-1))/this._property.COLUNM}justifiedCompute(){const t=[],s=this.offsetWidth;for(const i of this.children.array){const n=$(i);if(!(n instanceof R))continue;const a=n.attribute("layout-item-ratio"),o=a?parseFloat(a):n.dom.offsetWidth/n.dom.offsetHeight,l={$node:n,ratio:o};let d=t.at(-1);(!d||d.heightu+=c.ratio);const m=u+o,w=(s-this._property.GAP*d.items.length)/m;d.items.push(l),d.ratio=m,d.height=w}return t}waterfallCompute(){const t=[],s=this.COL_WIDTH,i=()=>{if(t.lengthn.height-a.height)[0]};for(const n of this.children.array){const a=$(n);if(!(a instanceof R))continue;const o=a.attribute("layout-item-ratio"),l=o?parseFloat(o):a.dom.offsetWidth/a.dom.offsetHeight,d={$node:a,ratio:l},u=i();let m=0;u.items.forEach(f=>m+=f.ratio);const w=s/(u.height+s/l),c=s/w;u.items.push(d),u.ratio=w,u.height=c}return t}render(){if(!this.inDOM())return this;if(this._property.ITEM_PROPERTIES.clear(),this._property.TYPE==="justified"){const t=this.justifiedCompute();let s=0;for(const i of t){let n=0;i.height>this._property.ROW_MAX_HEIGHT&&(i.height=this._property.ROW_MAX_HEIGHT);for(const a of i.items){const o=a.ratio*i.height;a.$node.css({position:"absolute",height:`${i.height}px`,width:`${o}px`,top:`${s}px`,left:`${n}px`}),a.$node.attribute("layout-item-ratio",a.ratio),this._property.ITEM_PROPERTIES.set(a.$node,{height:i.height,width:o,top:s,left:n,ratio:a.ratio,$node:a.$node}),n+=i.height*a.ratio+this._property.GAP}s+=i.height+this._property.GAP}this.css({height:`${s}px`})}else if(this._property.TYPE="waterfall"){const t=this.waterfallCompute(),s=this.COL_WIDTH;let i=0;for(const n of t){let a=0;for(const o of n.items){const l=s/o.ratio;o.$node.css({position:"absolute",height:`${l}px`,width:`${s}px`,top:`${a}px`,left:`${i}px`}),o.$node.attribute("layout-item-ratio",o.ratio),this._property.ITEM_PROPERTIES.set(o.$node,{height:l,width:s,top:a,left:i,ratio:o.ratio,$node:o.$node}),a+=l+this._property.GAP}i+=s+this._property.GAP}if(t.length){const n=t.sort((a,o)=>o.height-a.height)[0];this.css({height:`${n.height+n.items.length*this._property.GAP}px`})}else this.css({height:""})}return this.scrollCompute(),this}scrollCompute(){if(this.inDOM()===!1)return;const t=document.documentElement.scrollTop-this.dom.offsetTop;this._property.ITEM_PROPERTIES.forEach((s,i)=>{const n=s.top;s.top+s.height>t&&n{this.contentId=t,this.events.fire("rendered",{$view:this,previousContent:i,nextContent:s})},o=()=>{this.events.fire("afterSwitch",{$view:this,previousId:t})};return this.events.fire("beforeSwitch",{$view:this,preventDefault:()=>n=!0,targetId:t,previousContent:i,nextContent:s,switched:o,rendered:a}),n||(this.content(s),a(),o()),this}get currentContent(){if(this.contentId)return this.viewCache.get(this.contentId)}}$.registerTagName("view",Lt);var H;const y=class y extends Lt{constructor(t){super({tagname:"router",...t});B(this,H,"");h(this,"routes",new Map);y.routers.add(this)}base(t){return $.fluent(this,arguments,()=>M(this,H),()=>{Q(this,H,t??M(this,H))})}map(t){t=$.orArrayResolve(t);for(const s of t)s instanceof Array?this.map(s):this.routes.set(s.path(),s);return this.resolve(),this}resolve(){return new Promise(t=>{if(!location.pathname.startsWith(M(this,H)))return t(2);const s=location.pathname.replace(M(this,H),"/").replace("//","/"),i=s.split("/").map(f=>`/${f}`),n=location.search,a=new Map(n.replace("?","").split("&").map(f=>f.split("="))),l=(()=>{const f=[];for(const[g,T]of this.routes){const S=$.orArrayResolve(g);for(const b of S){let x=0,W={},j={};const D=b.split("/").map(L=>`/${L}`);if(!(i.length{const vt=a.get($t);vt!==void 0&&x++,Object.assign(j,{[$t]:vt})}),z.startsWith("/:")){x++,Object.assign(W,{[z.replace("/:","")]:i[L].replace("/","")});continue}else if(b.startsWith("#")&&b===location.hash){x++;continue}else if(z===i[L]){x++;continue}else break}f.push({deep:x,$route:T,params:W,query:j,routePath:b,pathId:Object.keys(j).length!==0?s+n:Object.keys(W).length!==0?s:S[0]})}}}return f.sort((g,T)=>T.deep-g.deep).at(0)})();if(!l)return t(1);const{$route:d,params:u,pathId:m,query:w}=l;if(m===this.contentId)return t(0);this.events.once("rendered",({nextContent:f,previousContent:g})=>{g==null||g.events.fire("afterShift",{$route:g}),f.events.fire("rendered",{$route:f}),t(0)});const c=this.viewCache.get(m)??d.build({params:u,query:w});this.viewCache.has(m)||this.setView(m,c),this.events.once("beforeSwitch",()=>{var f;c.events.fire("beforeShift",{$route:c}),(f=this.currentContent)==null||f.events.fire("beforeShift",{$route:this.currentContent})}),this.events.once("afterSwitch",()=>c.events.fire("afterShift",{$route:c})),this.switchView(m)})}static init(){if(!history.state||!("index"in history.state)){const t={index:y.historyIndex};history.replaceState(t,"")}else y.historyIndex=history.state.index;return y.navigationDirection=0,y.resolve(),window.addEventListener("popstate",()=>y.popstate()),window.addEventListener("scroll",()=>{this.setScrollHistory(this.historyIndex,location.href,document.documentElement.scrollTop)},{passive:!0}),history.scrollRestoration="manual",this}static open(t,s){return t===void 0?this:(t=this.urlResolver(t),t.href===this.url.href?this:t.origin!==this.url.origin?(window.open(t,s),this):(y.clearForwardScrollHistory(),y.historyIndex++,history.pushState(y.historyState,"",t),y.stateChange(0),y.resolve(),this))}static back(){return this.historyIndex--,history.back(),this}static replace(t){return t===void 0?this:(t=this.urlResolver(t),history.replaceState(y.historyState,"",t),this.stateChange(2),this.setScrollHistory(this.historyIndex,location.href,0),y.resolve(),this)}static urlResolver(t){return t instanceof URL?t:(t.startsWith("/")&&(t=`${location.origin}${t}`),t.startsWith("#")&&(t=`${location.origin}${location.pathname}${t}`),new URL(t))}static popstate(){const t=history.state.index>y.historyIndex?0:history.state.indext.resolve())),this.scrollRestoration(),this.setScrollHistory(this.historyIndex,location.href,document.documentElement.scrollTop)}static get historyState(){return{index:y.historyIndex}}static stateChange(t){const s=this.url,i=new URL(location.href);this.url=i,y.events.fire("stateChange",{beforeURL:s,afterURL:i,direction:t}),y.navigationDirection=t}static setScrollHistory(t,s,i){const n=this.getScrollHistory();if(!n)return sessionStorage.setItem(this.scrollHistoryKey,JSON.stringify({[t]:{url:s,value:i}}));n[t]={url:s,value:i},sessionStorage.setItem(this.scrollHistoryKey,JSON.stringify(n))}static getScrollHistory(){const t=sessionStorage.getItem(this.scrollHistoryKey);if(t)return JSON.parse(t)}static clearForwardScrollHistory(){const t=this.getScrollHistory();if(t)for(const s in t)Number(s)>this.historyIndex&&delete t[s],sessionStorage.setItem(this.scrollHistoryKey,JSON.stringify(t))}static scrollRestoration(){const t=this.getScrollHistory();if(t&&t[this.historyIndex])document.documentElement.scrollTop=t[this.historyIndex].value??0;else if(location.hash.length){const s=$(document.body).$(location.hash);s&&(document.documentElement.scrollTop=s.dom.offsetTop)}else document.documentElement.scrollTop=0}};H=new WeakMap,h(y,"routers",new Set),h(y,"events",new et),h(y,"navigationDirection"),h(y,"historyIndex",0),h(y,"url",new URL(location.href)),h(y,"scrollHistoryKey","$ROUTER_SCROLL_HISTORY");let P=y;var F=(r=>(r[r.Forward=0]="Forward",r[r.Back=1]="Back",r[r.Replace=2]="Replace",r))(F||{});P.init();var q,V;const pt=class pt extends p{constructor(t){super("route",t);B(this,q,"");B(this,V);h(this,"rendered",!1)}path(t){return $.fluent(this,arguments,()=>M(this,q),()=>Q(this,q,t??M(this,q)))}builder(t){return Q(this,V,t),this}render(t){return M(this,V)&&this.content(M(this,V).call(this,{$route:this,params:t.params,query:t.query})),this.rendered=!0,this}build(t){return new pt({dom:this.dom.cloneNode()}).self(s=>{M(this,V)&&s.builder(M(this,V)).render({params:t.params,query:t.query})})}};q=new WeakMap,V=new WeakMap;let lt=pt;$.registerTagName("router",P);$.registerTagName("route",lt);Object.assign($,{open(r,e){return P.open(r,e)},replace(r){return P.replace(r)},back(){return P.back()}});class ut{constructor(e,t,s=!0){h(this,"name$",$.state("..."));h(this,"post_upload_count$",$.state(0));h(this,"level$",$.state(10));h(this,"level_string$",$.state("..."));h(this,"booru");this.booru=e,Object.assign(this,t),s&&this.update$()}static async fetch(e,t){var n;let s;if(typeof t=="string"){const a=(await e.fetch(`/users.json?search[name]=${t}`)).at(0);if(!a)throw"User Not Found";return s=a}else s=await e.fetch(`/users/${t}.json`);const i=((n=e.users.get(s.id))==null?void 0:n.update(s))??new this(e,s);return e.users.set(i.id,i),i}static async fetchMultiple(e,t,s=200){let i="";if(t)for(const[o,l]of Object.entries(t))if(l instanceof Array)i+=`&search[${o}]=${l}`;else if(l instanceof Object)for(const[d,u]of Object.entries(l))i+=`&search[${o}${d}]=${u}`;else i+=`&search[${o}]=${l}`;return(await e.fetch(`/users.json?limit=${s}${i}`)).map(o=>{const l=new this(e,o);return e.users.set(l.id,l),l})}update(e){return Object.assign(this,e),this.update$(),this}update$(){this.name$.set(this.name),this.post_upload_count$.set(this.post_upload_count),this.level$.set(this.level),this.level_string$.set(this.level_string)}get booruURL(){return`${this.booru.origin}/users/${this.id}`}get url(){return`/users/${this.id}`}}class it extends ut{constructor(t,s,i){super(t,i,!1);h(this,"apiKey");h(this,"favorite_count$",$.state(0));h(this,"forum_post_count$",$.state(0));this.apiKey=s,this.update$()}update$(){var t,s;super.update$(),(t=this.forum_post_count$)==null||t.set(this.forum_post_count),(s=this.favorite_count$)==null||s.set(this.favorite_count)}static get storageUserData(){const t=localStorage.getItem("user_data");return t?JSON.parse(t):null}static set storageUserData(t){localStorage.setItem("user_data",JSON.stringify(t))}}const C=class C{constructor(e){h(this,"user");h(this,"posts",new Map);h(this,"tags",new Map);h(this,"users",new Map);Object.assign(this,e),this.origin.endsWith("/")&&(this.origin=this.origin.slice(0,-1)),C.manager.set(this.name,this)}static set(e){this.used=e,this.name$.set(e.name),this.storageAPI=e.name;const t=it.storageUserData;return t&&e.login(t.username,t.apiKey),this.events.fire("set"),this}static get storageAPI(){return localStorage.getItem("booru_api")}static set storageAPI(e){e?localStorage.setItem("booru_api",e):localStorage.removeItem("booru_api")}async fetch(e){const t=this.user?`${e.includes("?")?"&":"?"}login=${this.user.name}&api_key=${this.user.apiKey}`:"",s=await fetch(`${this.origin}${e}${t}`).then(i=>i.json());if(s.success===!1)throw s.message;return s}async login(e,t){const s=await this.fetch(`/profile.json?login=${e}&api_key=${t}`);return this.user=new it(this,t,s),C.events.fire("login",this.user),this.user}logout(){return this.user=void 0,it.storageUserData=null,C.events.fire("logout"),this}};h(C,"used"),h(C,"events",new et),h(C,"name$",$.state(C.name)),h(C,"manager",new Map);let v=C;class Zt{constructor(e,t){h(this,"post_count$",$.state(0));h(this,"name$",$.state(""));h(this,"booru");this.booru=e,Object.assign(this,t),this.$update()}static async fetch(e,t){var n;const s=await e.fetch(`/tags/${t}.json`),i=((n=e.tags.get(s.id))==null?void 0:n.update(s))??new this(e,s);return e.tags.set(i.id,i),i}static async fetchMultiple(e,t,s=1e3){let i="";if(t)for(const[o,l]of Object.entries(t))if(l instanceof Array)i+=`&search[${o}]=${l}`;else if(l instanceof Object)for(const[d,u]of Object.entries(l))i+=`&search[${o}${d}]=${u}`;else i+=`&search[${o}]=${l}`;return(await e.fetch(`/tags.json?limit=${s}${i}`)).map(o=>{var d;const l=((d=e.tags.get(o.id))==null?void 0:d.update(o))??new this(e,o);return e.tags.set(l.id,l),l})}update(e){return Object.assign(this,e),this.$update(),this}$update(){this.post_count$.set(this.post_count),this.name$.set(this.name)}}var U=(r=>(r[r.General=0]="General",r[r.Artist=1]="Artist",r[r.Copyright=3]="Copyright",r[r.Character=4]="Character",r[r.Meta=5]="Meta",r))(U||{});const ft=1e3,nt=ft*60,ot=nt*60,at=ot*24,te=at*7,st=new Intl.RelativeTimeFormat("en",{style:"long"});function ee(r){r=Math.floor(r);const e=r/ft,t=r/nt,s=r/ot,i=r/at,n=r%1e3,a=Math.floor(r%6e4/1e3),o=Math.floor(r%36e5/6e4),l=Math.floor(r%(36e5*24)/36e5),d=a.toString().padStart(2,"0"),u=o.toString().padStart(2,"0"),m=l.toString().padStart(2,"0");return{seconds:e,minutes:t,hours:s,days:i,mil:n,s:a,min:o,h:l,ss:d,mm:u,hh:m}}function se(r,e=Date.now()){const t=r-e,s=Math.abs(t);if(sthis.update$()),this}static async fetchMultiple(t,s,i=20,n){let a="";if(s){if(typeof s=="string")a=s;else for(const[u,m]of Object.entries(s))if(m!==void 0){if(u==="tags"){a+=`${m}`;continue}a.at(-1)!=="="&&(a+=" "),a+=`${u}:${m}`}}const o=await t.fetch(`/posts.json?limit=${i}&tags=${a}${n?`&page=${n}`:""}&_method=get`);if(!(o instanceof Array))return[];const l=o.map(u=>{var w;const m=((w=t.posts.get(u.id))==null?void 0:w.update(u))??new this(t,u.id,u);return t.posts.set(m.id,m),m});if(!l.length)return l;const d=[...new Set(o.map(u=>[u.approver_id,u.uploader_id].detype(null)).flat())];return ut.fetchMultiple(t,{id:d}).then(()=>l.forEach(u=>u.update$())),l}update$(){var t,s,i,n;this.uploader$.set(((t=this.uploader)==null?void 0:t.name$)??((s=this.uploader_id)==null?void 0:s.toString())),this.approver$.set(((i=this.approver)==null?void 0:i.name$)??((n=this.approver_id)==null?void 0:n.toString())??"None"),this.created_date$.set(se(+new Date(this.created_at))),this.favorites$.set(this.fav_count),this.score$.set(this.score),this.file_size$.set(ie(this.file_size)),this.file_ext$.set(this.file_ext),this.file_url$.set(this.file_url),this.source$.set(this.source),this.dimension$.set(`${this.image_width}x${this.image_height}`),this.url$.set(`${this.url}`),this.isUgoria&&this.webm_url$.set(this.large_file_url),this.createdDate=new Date(this.created_at),this.fire("update")}update(t){return Object.assign(this,t),this.update$(),this}async fetchTags(){return await this.ready,await Zt.fetchMultiple(this.booru,{name:{_space:this.tag_string}})}get pathname(){return`/posts/${this.id}`}get uploader(){return this.booru.users.get(this.uploader_id)}get approver(){return this.approver_id?this.booru.users.get(this.approver_id):null}get isVideo(){return this.file_ext==="mp4"||this.file_ext==="webm"||this.file_ext==="zip"}get isGif(){return this.file_ext==="gif"}get isUgoria(){return this.file_ext==="zip"}get hasSound(){return this.tag_string_meta.includes("sound")}get tags(){const t=this.tag_string.split(" ");return[...this.booru.tags.values()].filter(s=>t.includes(s.name))}get previewURL(){var t,s;return((s=(t=this.media_asset.variants)==null?void 0:t.find(i=>i.file_ext==="webp"))==null?void 0:s.url)??this.large_file_url}get url(){return`${this.booru.origin}/posts/${this.id}`}get isFileSource(){return this.source.startsWith("file://")}}class kt{constructor(e){Object.assign(this,e)}static async fetch(e,t){const s=await e.fetch(`/artist_commentaries/${t}.json`);return new this(s)}static async fetchMultiple(e,t,s=200){let i="";if(t)for(const[o,l]of Object.entries(t))if(l instanceof Array)i+=`&search[${o}]=${l}`;else if(l instanceof Object)for(const[d,u]of Object.entries(l))i+=`&search[${o}${d}]=${u}`;else i+=`&search[${o}]=${l}`;return(await e.fetch(`/artist_commentaries.json?limit=${s}${i}`)).map(o=>{const l=new this(o);return this.manager.set(l.id,l),l})}}h(kt,"manager",new Map);const re=new Intl.NumberFormat("en",{notation:"compact"});function J(r){return re.format(r)}const ne=$("route").path("/posts/:id").id("post").builder(({$route:r,params:e})=>{if(!Number(e.id))return $("h1").content("404: POST NOT FOUND");const t=X.get(v.used,+e.id);return[$("div").class("viewer").content(async()=>(await t.ready,t.isVideo?$("video").height(t.image_height).width(t.image_width).src(t.file_ext==="zip"?t.large_file_url:t.file_url).controls(!0).autoplay(!0).loop(!0).disablePictureInPicture(!0):$("img").src(t.large_file_url))),$("div").class("content").content([$("h3").content("Artist's Commentary"),$("section").class("commentary").content(async s=>{const i=(await kt.fetchMultiple(v.used,{post:{_id:t.id}})).at(0);return[i?[i.original_title?$("h3").content(i.original_title):null,$("pre").content(i.original_description)]:"No commentary"]})]),$("div").class("sidebar").self(s=>{let i=0;addEventListener("scroll",()=>{s.inDOM()&&(i=document.documentElement.scrollTop)},{passive:!0}),r.on("beforeShift",()=>{innerWidth>800&&s.css({position:"absolute",top:`calc(${i}px + var(--nav-height) + var(--padding))`})}).on("afterShift",()=>s.css({position:"",top:""}))}).content([$("section").class("post-info").content([new E("id").name("Post").content(`#${e.id}`),new E("uploader").name("Uploader").content(t.uploader$),new E("approver").name("Approver").content(t.approver$),new E("date").name("Date").content(t.created_date$),new E("size").name("Size").content([t.file_size$,t.dimension$]),new E("file-type").name("File Type").content(t.file_ext$),$("div").class("inline").content([new E("favorites").name("Favorites").content(t.favorites$),new E("score").name("Score").content(t.score$)]),new E("file-url").name("File").content([$("a").href(t.file_url$).content(t.file_url$.convert(s=>s.replace("https://",""))).target("_blank"),$("ion-icon").name("clipboard").on("click",(s,i)=>ht(i,t.source))]),new E("source-url").name("Source").content([$("a").href(t.source$).content(t.source$.convert(s=>s.replace("https://",""))).target("_blank"),$("ion-icon").name("clipboard").on("click",(s,i)=>ht(i,t.source))]),new E("booru-url").name(v.name$).content([$("a").href(t.url$).content(t.url$.convert(s=>s.replace("https://",""))).target("_blank"),$("ion-icon").name("clipboard").on("click",(s,i)=>ht(i,t.source))]),new E("booru-url").name("Webm").hide(!0).self(async s=>{await t.ready,t.isUgoria&&s.content($("a").href(t.webm_url$).content(t.webm_url$.convert(i=>i.replace("https://",""))).target("_blank")).hide(!1)})]),$("div").class("post-tags").content(async s=>{const i=await t.fetchTags(),[n,a,o,l,d]=[i.filter(m=>m.category===U.Artist),i.filter(m=>m.category===U.Character),i.filter(m=>m.category===U.General),i.filter(m=>m.category===U.Meta),i.filter(m=>m.category===U.Copyright)];return[u("Artist",n),u("Character",a),u("Copyright",d),u("Meta",l),u("General",o)];function u(m,w){return w.length?[$("h3").content(m),$("section").content([w.map(c=>$("div").class("tag").content([$("a").class("tag-name").content(c.name).href(`/posts?tags=${c.name}`),$("span").class("tag-post-count").content(c.post_count$.convert(J))]))])]:null}})])]});function ht(r,e){r.name("checkmark"),navigator.clipboard.writeText(e),setTimeout(()=>r.name("clipboard"),3e3)}class E extends p{constructor(t){super("div");h(this,"$name",$("span").class("property-name"));h(this,"$values",$("div").class("property-values"));this.staticClass("property").attribute("property-id",t),super.content([this.$name,this.$values.hide(!0)])}name(t){return this.$name.content(t),this}content(t){this.$values.hide(!1);const s=$.orArrayResolve(t);return this.$values.content(s.map(i=>$("span").staticClass("property-value").content(i))),this}}class oe extends p{constructor(t){super("post-tile");h(this,"post");h(this,"$video");h(this,"duration$",$.state(""));this.post=t,this.$video=this.post.isVideo?$("video").width(this.post.image_width).height(this.post.image_height).disablePictureInPicture(!0).loop(!0).muted(!0).hide(!0).on("mousedown",s=>s.preventDefault()):null,this.attribute("filetype",this.post.file_ext),this.durationUpdate(),this.build()}build(){var s,i;let t;(s=this.$video)==null||s.on("playing",(n,a)=>{t=setInterval(()=>{this.durationUpdate()},500)}),(i=this.$video)==null||i.on("pause",()=>{clearInterval(t),this.durationUpdate()}),this.class("loading").content([this.post.isVideo?$("div").class("video-detail").content([this.post.hasSound?$("ion-icon").name("volume-medium-outline"):null,this.post.isUgoria?$("ion-icon").name("images-outline"):null,$("span").class("duration").content(this.duration$)]):null,this.post.isGif?$("div").class("gif-detail").content([$("span").content("GIF")]):null,$("a").href(this.post.pathname).content(()=>[this.$video,$("img").draggable(!1).css({opacity:"0"}).width(this.post.image_width).height(this.post.image_height).src(this.post.previewURL).loading("lazy").on("mousedown",n=>n.preventDefault()).once("load",(n,a)=>{a.src(this.post.previewURL).on(["mouseenter","touchstart"],()=>{this.post.isGif&&a.src(this.post.large_file_url)},{passive:!0}).on(["mouseleave","touchend","touchcancel"],()=>{this.post.isGif&&a.src(this.post.previewURL)},{passive:!0}).animate({opacity:[0,1]},{duration:300,fill:"both"}),this.removeClass("loading")})]).on(["mouseenter","touchstart"],()=>{var n,a;(n=this.$video)!=null&&n.isPlaying||(a=this.$video)==null||a.src(this.post.large_file_url).hide(!1).play().catch(o=>{})},{passive:!0}).on(["mouseleave","touchend","touchcancel"],()=>{var n;(n=this.$video)==null||n.pause().currentTime(0).hide(!0)},{passive:!0})])}durationUpdate(){if(!this.$video)return;const t=ee(this.post.media_asset.duration*1e3-this.$video.currentTime()*1e3);this.duration$.set(Number(t.hh)>0?`${t.hh}:${t.mm}:${t.ss}`:`${t.mm}:${t.ss}`)}}class _t extends At{constructor(t){super();h(this,"posts",new Set);h(this,"$posts",new Map);h(this,"orderMap",new Map);h(this,"tags");h(this,"finished",!1);h(this,"limit",100);this.tags=t==null?void 0:t.tags,this.addStaticClass("post-grid"),this.type("waterfall").gap(10),this.init()}async init(){setInterval(()=>{this.inDOM()&&document.documentElement.scrollTop===0&&this.getPost("newer")},1e4),v.events.on("set",()=>{this.removeAll(),this.finished&&(this.finished=!1,this.events.fire("startLoad"),this.loader())}),this.on("resize",()=>this.resize()),this.events.fire("startLoad"),this.loader()}async loader(){if(!this.inDOM())return setTimeout(()=>this.loader(),100);for(;this.inDOM()&&document.documentElement.scrollHeight<=innerHeight*2;)if(!(await this.getPost("older")).length)return;document.documentElement.scrollTop+innerHeight>document.documentElement.scrollHeight-innerHeight*2&&!(await this.getPost("older")).length||setTimeout(()=>this.loader(),100)}resize(){const t=Math.round(this.dom.clientWidth/300);this.column(t>=2?t:2)}addPost(t){t=$.orArrayResolve(t);for(const i of t){if(!i.file_url||this.posts.has(i))continue;const n=new oe(i);this.$posts.set(i,n),this.posts.add(i)}const s=[...this.orderMap.values()].map(i=>this.$posts.get(i));return this.content(s).render(),this}removeAll(){return this.posts.clear(),this.$posts.clear(),this.animate({opacity:[1,0]},{duration:300,easing:"ease"},()=>this.clear().render()),this}async getPost(t){const s=this.tags?decodeURIComponent(this.tags).split("+"):void 0,i=[],n=[];let a=this.limit;if(s)for(const u of s)u.startsWith("ordfav:")||u.startsWith("order:")?n.push(u):u.startsWith("limit:")?a=Number(u.split(":")[1]):i.push(u);if(n.length){if(n.length>1)return this.events.fire("post_error",`Error: These query can't be used together [${n}].`),[];const u=n[0];if(u.startsWith("ordfav:")){const m=u.split(":")[1],w=i.length?`&search[post_tags_match]=${i.toString().replaceAll(",","+")}`:"",c=this.orderKeyList.length?t==="newer"?`&search[id]=>${this.orderKeyList.at(0)}`:`&search[id]=<${this.orderKeyList.at(-1)}`:void 0,f=await v.used.fetch(`/favorites.json?search[user_name]=${m}${c??""}${w}&limit=${a}`),g=await X.fetchMultiple(v.used,{tags:`id:${f.map(S=>S.post_id).toString()}`}),T=new Map;for(const S of f){const b=g.find(x=>x.id===S.post_id);b&&T.set(S.id,b)}return this.orderMap=new Map(t==="newer"?[...T,...this.orderMap]:[...this.orderMap,...T]),this.addPost(g),g}if(u.startsWith("order:")){const m=this.orderKeyList.length?t==="newer"?1:this.orderMap.size/a+1:void 0,w=await X.fetchMultiple(v.used,{tags:this.tags},a,m),c=new Map(w.map(f=>[f.id,f]));return c.forEach((f,g)=>{this.orderMap.has(g)&&c.delete(g)}),this.orderMap=new Map(t==="newer"?[...c,...this.orderMap]:[...this.orderMap,...c]),this.addPost(w),w}}const o=this.orderKeyList.length?t==="newer"?`a${this.orderKeyList.at(0)}`:`b${this.orderKeyList.at(-1)}`:void 0,l=await X.fetchMultiple(v.used,{tags:this.tags},a,o),d=new Map(l.map(u=>[u.id,u]));return this.orderMap=new Map(t==="newer"?[...d,...this.orderMap]:[...this.orderMap,...d]),this.addPost(l),l.length||(this.finished=!0,this.posts.size?this.events.fire("endPost"):this.events.fire("noPost")),l}get orderKeyList(){return[...this.orderMap.keys()]}}class Ct{static async fetch(e,t,s=20){if(!t.length)return this.searchQuery.map(a=>new Tt(a));const i=await e.fetch(`/autocomplete.json?search[query]=${t}&search[type]=tag_query&version=1&limit=${s}`);return[...t.length?this.searchQuery.filter(a=>a.value.startsWith(t)&&a.value!==t):this.searchQuery,...i].map(a=>new Tt(a))}}h(Ct,"searchQuery",[{value:"user:",label:"user:"},{value:"approver:",label:"approver:"},{value:"-approver:",label:"-approver:"},{value:"order:",label:"order:"},{value:"ordfav:",label:"ordfav:"},{value:"ordfavgroup:",label:"ordfavgroup:"},{value:"search:",label:"search:"},{value:"favgroup:",label:"favgroup:"},{value:"-favgroup:",label:"-favgroup:"},{value:"favcount:",label:"favcount:"},{value:"id:",label:"id:"},{value:"tagcount:",label:"tagcount:"},{value:"gentags:",label:"gentags:"},{value:"arttags:",label:"arttags:"},{value:"chartags:",label:"chartags:"},{value:"copytags:",label:"copytags:"},{value:"metatags:",label:"metatags:"},{value:"score:",label:"score:"},{value:"upvote:",label:"upvote:"},{value:"downvote:",label:"downvote:"},{value:"disapproved:",label:"disapproved:"},{value:"md5:",label:"md5:"},{value:"width:",label:"width:"},{value:"height:",label:"height:"},{value:"ratio:",label:"ratio:"},{value:"mpixels:",label:"mpixels:"},{value:"filesize:",label:"filesize:"},{value:"duration:",label:"duration:"},{value:"is:",label:"is:"},{value:"has:",label:"has:"},{value:"pool:",label:"pool:"},{value:"-pool:",label:"-pool:"},{value:"ordpool:",label:"ordpool:"},{value:"random:",label:"random:"},{value:"limit:",label:"limit:"},{value:"date:",label:"date:"},{value:"commenter:",label:"commenter:"},{value:"note:",label:"note:"},{value:"noter:",label:"noter:"},{value:"noteupdater:",label:"noteupdater:"},{value:"status:",label:"status:"},{value:"-status:",label:"-status:"},{value:"rating:",label:"rating:"},{value:"-rating:",label:"-rating:"},{value:"source:",label:"source:"},{value:"-source:",label:"-source:"},{value:"pixiv:",label:"pixiv:"},{value:"parent:",label:"parent:"},{value:"child:",label:"child:"},{value:"flagger:",label:"flagger:"},{value:"appealer:",label:"appealer:"},{value:"commentary:",label:"commentary:"},{value:"commentaryupdater:",label:"commentaryupdater:"}].map(e=>({type:"query",...e})));class Tt{constructor(e){Object.assign(this,e)}isTag(){return this.type==="tag"||this.type==="tag-autocorrect"||this.type==="tag-alias"||this.type==="tag-word"}isTagAutocorrect(){return this.type==="tag-autocorrect"}isTagAntecedent(){return!!this.antecedent}isTagWord(){return this.type==="tag-word"}isUser(){return this.type==="user"}}class ae extends p{constructor(){super("searchbar");h(this,"$tagInput",new ue(this));h(this,"$selectionList",new he);h(this,"typingTimer",null);h(this,"$filter",$("div").class("filter"));this.build(),window.addEventListener("keyup",t=>{!this.inDOM()&&t.key==="/"&&this.open(),this.inDOM()&&t.key==="Escape"&&this.close()})}build(){this.content([$("div").class("input-container").content([this.$tagInput.on("input",()=>this.inputHandler()).on("keydown",t=>this.keyHandler(t)),$("ion-icon").name("close-circle-outline").title("Clear Input").on("click",()=>this.$tagInput.clearAll())]).on("click",t=>{t.target===this.$tagInput.dom&&this.$tagInput.addTag().input()}),$("div").class("selection-list-container").content([this.$selectionList]),this.$filter.on("click",()=>{location.hash==="#search"&&this.close()})])}open(){return $.open(location.href+"#search"),this}close(){return $.back(),this}activate(){return this.hide(!1),this.$filter.animate({opacity:[0,.5]},{duration:300,easing:"ease"}),this.$tagInput.input(),this}inactivate(){return this.animate({opacity:[.5,0]},{duration:300,easing:"ease"},()=>this.hide(!0)),this}keyHandler(t){var n,a;const s=()=>{t.preventDefault(),this.$tagInput.addTag().input()},i=o=>{const l=this.$tagInput.children.indexOf(this.$tagInput.$inputor);if(this.$tagInput.$input.value().at(-1)===":")return this.getSearchSuggestions();const d=this.$tagInput.children.array.at(l+1);this.$tagInput.addTag(o.value()),d?this.$tagInput.editTag(d):this.$tagInput.input()};switch(t.key){case"ArrowUp":{t.preventDefault(),this.$selectionList.focusPrevSelection(),this.$tagInput.value((n=this.$selectionList.focused)==null?void 0:n.value());break}case"ArrowDown":{t.preventDefault(),this.$selectionList.focusNextSelection(),this.$tagInput.value((a=this.$selectionList.focused)==null?void 0:a.value());break}case" ":s();break;case"Enter":{t.preventDefault(),this.$selectionList.focused?i(this.$selectionList.focused):(this.$tagInput.addTag(),this.search());break}case"Tab":{t.preventDefault();const o=this.$tagInput.children.indexOf(this.$tagInput.$inputor);if(t.shiftKey){o-1>=0&&this.$tagInput.editTag(this.$tagInput.children.array.at(o-1));break}if(this.$selectionList.focused)i(this.$selectionList.focused);else{const l=this.$tagInput.children.array.at(o+1);l?this.$tagInput.editTag(l):this.$tagInput.addTag().input()}break}case"Backspace":{const o=this.$tagInput.children.indexOf(this.$tagInput.$inputor);o!==0&&!this.$tagInput.$input.value().length&&(t.preventDefault(),this.$tagInput.editTag(this.$tagInput.children.array.at(o-1)));break}}}inputHandler(){this.typingTimer&&(clearTimeout(this.typingTimer),this.typingTimer=null),this.typingTimer=setTimeout(async()=>{this.typingTimer=null,this.getSearchSuggestions()},200)}async getSearchSuggestions(){const t=this.$tagInput.$input.value(),s=await Ct.fetch(v.used,t,20);this.$selectionList.clearSelections().addSelections(s.map(i=>new le().value(i.value).content([$("div").class("selection-label").content([i.isTagAntecedent()?$("span").class("tag-antecedent").self(n=>n.dom.innerHTML=i.antecedent.replaceAll(t,`${t}`)):null,$("div").class("label-container").content([i.isTagAntecedent()?$("ion-icon").name("arrow-forward-outline"):null,$("span").class("label").self(n=>n.dom.innerHTML=i.label.replaceAll(t,`${t}`))])]),i.isTag()?$("div").class("tag-detail").content([$("span").class("tag-post-count").content(J(i.post_count)),$("span").class("tag-category").content(U[i.category])]):null,i.isUser()?$("span").class("user-level").content(i.level):null]).on("click",()=>{this.$tagInput.addTag(i.value).input()})))}search(){return $.replace(`/posts?tags=${this.$tagInput.query.replace(":","%3A")}`),this.$tagInput.clearAll(),this.inactivate(),this}checkURL(t,s){if((t==null?void 0:t.hash)==="#search"&&this.inactivate(),s.hash==="#search"&&this.activate(),`${t==null?void 0:t.pathname}${t==null?void 0:t.search}`==`${s.pathname}${s.search}`)return;const i=s.searchParams.get("tags");this.$tagInput.clearAll(),i==null||i.split(" ").forEach(n=>this.$tagInput.addTag(n))}}class he extends p{constructor(){super("selection-list");h(this,"focused",null);h(this,"selections",new Set)}addSelections(t){t=$.orArrayResolve(t);for(const s of t)this.selections.add(s);return this.insert(t),this}clearSelections(){return this.focused=null,this.selections.clear(),this.clear(),this}focusSelection(t){return this.blurSelection(),this.focused=t,t.focus(),t.offsetTopthis.scrollTop()+this.offsetHeight&&this.scrollTop(t.offsetTop+t.offsetHeight-this.offsetHeight),this}blurSelection(){var t;return(t=this.focused)==null||t.blur(),this.focused=null,this}focusNextSelection(){const t=this.selections.array,s=t.at(0);if(this.focused){const i=t.at(t.indexOf(this.focused)+1);i?this.focusSelection(i):s&&this.focusSelection(s)}else s&&this.focusSelection(s)}focusPrevSelection(){const t=this.selections.array;if(this.focused){const s=t.at(t.indexOf(this.focused)-1);s&&this.focusSelection(s)}else{const s=t.at(0);s&&this.focusSelection(s)}}}class le extends p{constructor(){super("selection");h(this,"property",{value:""})}value(t){return $.fluent(this,arguments,()=>this.property.value,()=>$.set(this.property,"value",t))}focus(){return this.addClass("active"),this}blur(){return this.removeClass("active"),this}}class ue extends p{constructor(t){super("tag-input");h(this,"$input",$("input").type("text"));h(this,"$sizer",$("span").class("sizer"));h(this,"$inputor",$("div").class("input-wrapper").content([this.$sizer,this.$input.on("input",()=>{this.$sizer.content(this.$input.value())})]));h(this,"tags",new Set);h(this,"$seachbar");this.$seachbar=t}input(){return this.insert(this.$inputor),this.$input.focus(),this.$seachbar.$selectionList.clearSelections(),this.$seachbar.getSearchSuggestions(),this}addTag(t){if(t=t??this.$input.value(),!t.length)return this;const s=new ce(t);return s.on("click",()=>this.editTag(s)),this.tags.add(s),this.value(""),this.$input.inDOM()?this.$inputor.replace(s):this.insert(s),this}editTag(t){return this.addTag(),this.tags.delete(t),t.replace(this.$inputor),this.value(t.name),this.$input.focus(),this.$seachbar.getSearchSuggestions(),this}clearAll(){return this.value(""),this.tags.clear(),this.clear(),this}value(t){return t===void 0?this:(this.$input.value(t),this.$sizer.content(t),this)}focus(){return this.$input.focus(),this}get query(){return this.tags.array.map(t=>t.name).toString().replace(",","+")}}class ce extends p{constructor(t){super("tag");h(this,"name");this.name=t,this.build()}build(){this.content(this.name)}}class de extends p{constructor(){super("ion-icon")}name(e){return this.attribute("name",e),this}size(e){return this.attribute("size",e),this}}class me extends mt{constructor(){super();h(this,"$icon",$("ion-icon"));h(this,"$label",$("span"));this.addStaticClass("icon"),this.build()}build(){super.content([this.$icon.hide(!0),this.$label])}content(t){return this.$label.content(t),this}icon(t){return this.$icon.name(t).hide(!1),this}link(t,s=!1){return this.on("click",()=>s?$.replace(t):$.open(t)),this}}const fe=$("route").id("login").path("/login").builder(()=>{const[r,e]=[$.state(""),$.state("")];return[$("div").class("login-container").content([$("h1").content("Login"),$("div").class("username","input-container").content([$("label").for("username").content("Username"),$("input").type("text").id("username").value(r)]),$("div").class("api-key","input-container").content([$("label").for("api-key").content("API Key"),$("input").type("password").id("api-key").value(e)]),$("icon-button").content("Login").on("click",async()=>{await v.used.login(r.value,e.value),v.used.user&&(it.storageUserData={apiKey:e.value,username:r.value},r.set(""),e.set(""),$.replace("/"))}),$("icon-button").content("Create Account").icon("open-outline").on("click",()=>$.open("https://danbooru.donmai.us/users/new","_blank"))])]});class pe extends p{constructor(){super("drawer");h(this,"$filter",$("div").class("filter"));h(this,"$container",$("div").class("drawer-container"));this.hide(!0),this.build()}build(){this.content([this.$container.content([$("div").class("user-info").hide(!0).self(t=>[v.events.on("login",s=>{t.content([$("div").content([$("h3").class("username").content(s.name$),$("div").class("user-detail").content([$("span").class("userid").content(`ID: ${s.id}`),$("span").class("level").content(["Level: ",s.level_string$])])]),$("div").class("user-nav").content([$("icon-button").title("Uploaded Posts").icon("image").content(s.post_upload_count$.convert(J)).link(`/posts?tags=user:${s.name}`,!0),$("icon-button").title("Favorites").icon("heart").content(s.favorite_count$.convert(J)).link(`/posts?tags=ordfav:${s.name}`,!0),$("icon-button").title("Forum Posts").icon("document-text").content(s.forum_post_count$.convert(J)).hide(!0)])]).hide(!1)}).on("logout",()=>{t.clear().hide(!0)})]),$("div").class("nav").content([$("div").class("login").content([$("icon-button").icon("log-in-outline").content("Login").link("/login",!0)]).self(t=>v.events.on("login",()=>t.hide(!0)).on("logout",()=>t.hide(!1))),$("div").class("logout").hide(!0).content([$("icon-button").icon("log-in-outline").content("Logout").on("dblclick",()=>v.used.logout())]).self(t=>v.events.on("login",()=>t.hide(!1)).on("logout",()=>t.hide(!0)))])]),this.$filter.on("click",()=>$.back())])}open(){this.hide(!1),this.$container.animate({transform:["translateX(100%)","translateX(0%)"]},{fill:"both",duration:300,easing:"ease"}),this.$filter.animate({opacity:[0,1]},{fill:"both",duration:300,easing:"ease"})}close(){this.$container.animate({transform:["translateX(0%)","translateX(100%)"]},{fill:"both",duration:300,easing:"ease"},()=>this.hide(!0)),this.$filter.animate({opacity:[1,0]},{fill:"both",duration:300,easing:"ease"})}checkURL(t,s){(t==null?void 0:t.hash)==="#drawer"&&this.close(),s.hash==="#drawer"&&this.open()}}$.registerTagName("ion-icon",de);$.registerTagName("icon-button",me);$.anchorHandler=r=>{$.open(r.href(),r.target())};const[ct,ge]=[new v({origin:"https://danbooru.donmai.us",name:"Danbooru"}),new v({origin:"https://safebooru.donmai.us",name:"Safebooru"}),new v({origin:"https://testbooru.donmai.us",name:"Testbooru"})];v.set(v.manager.get(v.storageAPI??"")??ct);const rt=new ae().hide(!0),dt=new pe;$(document.body).content([$("nav").content([$("a").class("title").href("/").content([$("h1").class("booru-name").content(v.name$),$("h2").class("app").content([$("span").class("app-name").content("Viewer"),$("span").class("version").content("v0.5.1")])]),$("div").class("searchbar").content(["Search in ",v.name$]).self(r=>P.events.on("stateChange",({beforeURL:e,afterURL:t})=>{e.hash==="#search"&&r.hide(!1),t.hash==="#search"&&r.hide(!0)})).on("click",()=>rt.open()),$("div").class("buttons").content([$("ion-icon").class("search").name("search-outline").title("Search").self(r=>P.events.on("stateChange",({beforeURL:e,afterURL:t})=>{e.hash==="#search"&&r.hide(!1),t.hash==="#search"&&r.hide(!0)})).on("click",()=>rt.open()),$("ion-icon").class("switch").name("swap-horizontal").title("Switch Booru").on("click",()=>{v.used===ct?v.set(ge):v.set(ct)}),$("ion-icon").class("open").name("open-outline").title("Open in Original Site").on("click",()=>$.open(location.href.replace(location.origin,v.used.origin))),$("ion-icon").class("menu").name("menu-outline").title("Menu").hide(!1).self(r=>{v.events.on("login",()=>r.hide(!0)).on("logout",()=>r.hide(!1))}).on("click",()=>$.open(location.href+"#drawer")),$("div").class("account").hide(!0).title("Menu").self(r=>{v.events.on("login",e=>{r.content(e.name$.convert(t=>{var s;return((s=t.at(0))==null?void 0:s.toUpperCase())??""})).hide(!1)}).on("logout",()=>r.hide(!0))}).on("click",()=>dt.open())])]),rt,dt,$("router").base("/").map([$("route").id("posts").path(["/","/posts"]).builder(()=>new _t),$("route").id("posts").path("/posts?tags").builder(({query:r})=>{const e=new _t({tags:r.tags});return[$("header").content([$("h2").content("Posts"),$("div").class("tags").self(t=>{r.tags.split("+").forEach(s=>{t.insert($("a").class("tag").content(decodeURIComponent(s)).href(`posts?tags=${s}`))})})]),$("div").class("no-post").hide(!0).self(t=>{t.on("startLoad",()=>t.hide(!0)),e.on("noPost",()=>t.hide(!1).content("No Posts")).on("post_error",s=>t.hide(!1).content(s))}),e]}),ne,fe]).on("beforeSwitch",r=>{r.preventDefault();function s(){var a;const n=$.call(()=>{switch(P.navigationDirection){case F.Forward:return["translateX(2%)","translateX(0%)"];case F.Back:return["translateX(-2%)","translateX(0%)"];case F.Replace:return""}});r.$view.content(r.nextContent),r.rendered(),(a=r.nextContent.element)==null||a.class("animated").animate({opacity:[0,1],transform:n},{duration:300,easing:"ease"},()=>{var o;r.switched(),(o=r.nextContent.element)==null||o.removeClass("animated")})}function i(){var a,o;const n=$.call(()=>{switch(P.navigationDirection){case F.Forward:return["translateX(0%)","translateX(-2%)"];case F.Back:return["translateX(0%)","translateX(2%)"];case F.Replace:return""}});(o=(a=r.previousContent)==null?void 0:a.element)==null||o.class("animated").animate({opacity:[1,0],transform:n},{duration:300,easing:"ease"},()=>{var l,d;(d=(l=r.previousContent)==null?void 0:l.element)==null||d.removeClass("animated"),s()})}r.previousContent?i():s()})]);P.events.on("stateChange",({beforeURL:r,afterURL:e})=>Rt(r,e));Rt(void 0,new URL(location.href));function Rt(r,e){rt.checkURL(r,e),dt.checkURL(r,e)} diff --git a/dist/assets/index-B0cSv4EX.js b/dist/assets/index-B0cSv4EX.js new file mode 100644 index 0000000..3506e2c --- /dev/null +++ b/dist/assets/index-B0cSv4EX.js @@ -0,0 +1 @@ +var Dt=Object.defineProperty;var bt=r=>{throw TypeError(r)};var Ht=(r,e,t)=>e in r?Dt(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var h=(r,e,t)=>Ht(r,typeof e!="symbol"?e+"":e,t),wt=(r,e,t)=>e.has(r)||bt("Cannot "+t);var M=(r,e,t)=>(wt(r,e,"read from private field"),t?t.call(r):e.get(r)),J=(r,e,t)=>e.has(r)?bt("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(r):e.set(r,t),Y=(r,e,t,s)=>(wt(r,e,"write to private field"),s?s.call(r,t):e.set(r,t),t);(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))s(i);new MutationObserver(i=>{for(const n of i)if(n.type==="childList")for(const a of n.addedNodes)a.tagName==="LINK"&&a.rel==="modulepreload"&&s(a)}).observe(document,{childList:!0,subtree:!0});function t(i){const n={};return i.integrity&&(n.integrity=i.integrity),i.referrerPolicy&&(n.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?n.credentials="include":i.crossOrigin==="anonymous"?n.credentials="omit":n.credentials="same-origin",n}function s(i){if(i.ep)return;i.ep=!0;const n=t(i);fetch(i.href,n)}})();class z{constructor(){h(this,"__hidden",!1);h(this,"domEvents",{});h(this,"parent");h(this,"events",new Q)}on(e,t,s){e=_.orArrayResolve(e);for(const i of e){this.domEvents[i]||(this.domEvents[i]=new Map);const n=a=>{t(a,this)};this.domEvents[i].set(t,n),this.events.on(i,t),this.dom.addEventListener(i,n,s)}return this}off(e,t,s){var n;const i=(n=this.domEvents[e])==null?void 0:n.get(t);return i&&this.dom.removeEventListener(e,i,s),this.events.off(e,t),this}once(e,t,s){const i=n=>{this.dom.removeEventListener(e,i,s),t(n,this)};return this.dom.addEventListener(e,i,s),this.events.once(e,t),this}hide(e,t=!0){return _.fluent(this,arguments,()=>this.__hidden,()=>{var s;if(e!==void 0)return e instanceof I?(this.__hidden=e.value,e.use(this,"hide")):this.__hidden=e,t&&((s=this.parent)==null||s.children.render()),this})}remove(){var e;return(e=this.parent)==null||e.children.remove(this).render(),this}replace(e){var t;return(t=this.parent)==null||t.children.replace(this,e).render(),this}contains(e){return e?e instanceof z?this.dom.contains(e.dom):e instanceof EventTarget?this.dom.contains(_(e).dom):this.dom.contains(e):!1}self(e){return e(this),this}inDOM(){return document.contains(this.dom)}isElement(){return this instanceof R}get element(){return this instanceof R?this:null}}class R extends z{constructor(t,s){super();h(this,"dom");h(this,"static_classes",new Set);this.dom=this.createDom(t,s),this.dom.$=this,this.setOptions(s)}createDom(t,s){return s!=null&&s.dom?s.dom:t==="svg"?document.createElementNS("http://www.w3.org/2000/svg","svg"):document.createElement((s==null?void 0:s.tagname)??t)}setOptions(t){return this.id(t==null?void 0:t.id),t&&t.class&&this.class(...t.class),this}id(t){return $.fluent(this,arguments,()=>this.dom.id,()=>$.set(this.dom,"id",t))}class(...t){return $.fluent(this,arguments,()=>this.dom.classList,()=>{this.dom.classList.forEach(s=>this.static_classes.has(s)??this.dom.classList.remove(s)),this.dom.classList.add(...t.detype())})}addClass(...t){return $.fluent(this,arguments,()=>this,()=>{this.dom.classList.add(...t.detype())})}removeClass(...t){return $.fluent(this,arguments,()=>this,()=>{this.dom.classList.remove(...t.detype())})}staticClass(...t){return $.fluent(this,arguments,()=>this.static_classes,()=>{this.removeClass(...this.static_classes),this.static_classes.clear(),this.addStaticClass(...t)})}addStaticClass(...t){return $.fluent(this,arguments,()=>this,()=>{t.detype().forEach(s=>this.static_classes.add(s)),this.addClass(...t)})}removeStaticClass(...t){return $.fluent(this,arguments,()=>this,()=>{t.detype().forEach(s=>this.static_classes.delete(s)),this.removeClass(...t)})}css(t){return $.fluent(this,arguments,()=>this.dom.style,()=>{Object.assign(this.dom.style,t)})}attribute(t,s){return arguments.length?arguments.length===1?t===void 0?null:this.dom.getAttribute(t):arguments.length===2?t?(s===null?this.dom.removeAttribute(t):s!==void 0&&this.dom.setAttribute(t,`${s}`),this):this:this:null}tabIndex(t){return $.fluent(this,arguments,()=>this.dom.tabIndex,()=>$.set(this.dom,"tabIndex",t))}focus(){return this.dom.focus(),this}blur(){return this.dom.blur(),this}animate(t,s,i){const n=this.dom.animate(t,s);return i&&(n.onfinish=()=>i(n)),n}getAnimations(t){return this.dom.getAnimations(t)}get dataset(){return this.dom.dataset}domRect(t){const s=this.dom.getBoundingClientRect();if(!t)return s;const i=t instanceof R?t.dom.getBoundingClientRect():t;return{...s,top:s.top-i.top,left:s.left-i.left,right:s.right-i.left,bottom:s.bottom-i.top,x:s.x-i.x,y:s.y-i.y}}}class tt extends z{constructor(t){super();h(this,"dom");this.dom=t,this.dom.$=this}domRect(t){const s={bottom:innerHeight,height:innerHeight,left:0,right:innerWidth,top:0,width:innerWidth,x:0,y:0};if(!t)return s;const i=t instanceof R?t.dom.getBoundingClientRect():t;return{...s,top:s.top-i.top,left:s.left-i.left,right:s.right-i.left,bottom:s.bottom-i.top,x:s.x-i.x,y:s.y-i.y}}static from(t){return t.$ instanceof tt?t.$:new tt(t)}}const Ft="modulepreload",Vt=function(r){return"/"+r},_t={},jt=function(e,t,s){let i=Promise.resolve();if(t&&t.length>0){document.getElementsByTagName("link");const a=document.querySelector("meta[property=csp-nonce]"),o=(a==null?void 0:a.nonce)||(a==null?void 0:a.getAttribute("nonce"));i=Promise.allSettled(t.map(l=>{if(l=Vt(l),l in _t)return;_t[l]=!0;const d=l.endsWith(".css"),c=d?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${l}"]${c}`))return;const p=document.createElement("link");if(p.rel=d?"stylesheet":Ft,d||(p.as="script"),p.crossOrigin="",p.href=l,o&&p.setAttribute("nonce",o),document.head.appendChild(p),d)return new Promise((g,u)=>{p.addEventListener("load",g),p.addEventListener("error",()=>u(new Error(`Unable to preload CSS for ${l}`)))})}))}function n(a){const o=new Event("vite:preloadError",{cancelable:!0});if(o.payload=a,window.dispatchEvent(o),!o.defaultPrevented)throw a}return i.then(a=>{for(const o of a||[])o.status==="rejected"&&n(o.reason);return e().catch(n)})};class Wt{constructor(e){h(this,"$container");h(this,"childList",new Set);this.$container=e}add(e,t=-1){if(t===-1||this.childList.size-1===t)this.childList.add(e);else{const s=[...this.childList];s.splice(t,0,e),this.childList.clear(),s.forEach(i=>this.childList.add(i))}e.parent=this.$container}remove(e){return this.childList.has(e)?(this.childList.delete(e),e.parent=void 0,this):this}removeAll(e=!0){this.childList.forEach(t=>this.remove(t)),e&&this.render()}replace(e,t){const s=this.array;return s.splice(s.indexOf(e),1,t),e.remove(),this.childList.clear(),s.forEach(i=>this.childList.add(i)),t.parent=this.$container,this}render(){const[e,t]=[this.array.map(i=>i.dom),Array.from(this.dom.childNodes)],s=[];for(;t.length||e.length;){const[i,n]=[t.at(0),e.at(0)];n?i?n!==i?(n.$.__hidden||(this.dom.insertBefore(n,i),s.push(n)),e.shift()):(n.$.__hidden&&this.dom.removeChild(n),e.shift(),t.shift()):(n.$.__hidden||this.dom.append(n),e.shift()):(i&&!s.includes(i)&&i.remove(),t.shift())}}indexOf(e){return this.array.indexOf(e)}get array(){return[...this.childList.values()]}get dom(){return this.$container.dom}}class I{constructor(e,t){h(this,"_value");h(this,"attributes",new Map);h(this,"linkStates",new Set);h(this,"options",{});this.set(e),t&&(this.options=t)}set(e){this._value=e,e instanceof I&&e.linkStates.add(this),this.update(),this.linkStates.forEach(t=>t.update())}static toJSON(e){const t={};for(let[s,i]of Object.entries(e))i instanceof I?i=i.toJSON():i instanceof Object&&I.toJSON(i),Object.assign(t,{[s]:i});return t}update(){for(const[e,t]of this.attributes.entries())for(const s of t)e[s]instanceof Function?this.options.format?e[s](this.options.format(this.value)):e[s](this.value):s in e&&(e[s]=this.value)}use(e,t){const s=this.attributes.get(e);s?s.add(t):this.attributes.set(e,new Set().add(t))}convert(e){return new I(this,{format:e})}get value(){return this._value instanceof I?this._value.value:this._value}toString(){return this.options.format?this.options.format(this.value):this.value instanceof Object?JSON.stringify(this.toJSON()):`${this.value}`}toJSON(){return this.value instanceof I?this.value.toJSON():this.value instanceof Object?I.toJSON(this.value):this.toString()}}class X extends z{constructor(t){super();h(this,"dom");this.dom=new Text(t),this.dom.$=this}content(t){return $.fluent(this,arguments,()=>this.dom.textContent,()=>$.set(this.dom,"textContent",t))}}class et extends R{constructor(e,t){super(e,t)}autocapitalize(e){return $.fluent(this,arguments,()=>this.dom.autocapitalize,()=>$.set(this.dom,"autocapitalize",e))}innerText(e){return $.fluent(this,arguments,()=>this.dom.innerText,()=>$.set(this.dom,"innerText",e))}title(e){return $.fluent(this,arguments,()=>this.dom.title,()=>$.set(this.dom,"title",e))}dir(e){return $.fluent(this,arguments,()=>this.dom.dir,()=>$.set(this.dom,"dir",e))}translate(e){return $.fluent(this,arguments,()=>this.dom.translate,()=>$.set(this.dom,"translate",e))}popover(e){return $.fluent(this,arguments,()=>this.dom.popover,()=>$.set(this.dom,"popover",e))}spellcheck(e){return $.fluent(this,arguments,()=>this.dom.spellcheck,()=>$.set(this.dom,"spellcheck",e))}inert(e){return $.fluent(this,arguments,()=>this.dom.inert,()=>$.set(this.dom,"inert",e))}lang(e){return $.fluent(this,arguments,()=>this.dom.lang,()=>$.set(this.dom,"lang",e))}draggable(e){return $.fluent(this,arguments,()=>this.dom.draggable,()=>$.set(this.dom,"draggable",e))}hidden(e){return $.fluent(this,arguments,()=>this.dom.hidden,()=>$.set(this.dom,"hidden",e))}click(){return this.dom.click(),this}attachInternals(){return this.dom.attachInternals()}hidePopover(){return this.dom.hidePopover(),this}showPopover(){return this.dom.showPopover(),this}togglePopover(){return this.dom.togglePopover(),this}get accessKeyLabel(){return this.dom.accessKeyLabel}get offsetHeight(){return this.dom.offsetHeight}get offsetLeft(){return this.dom.offsetLeft}get offsetParent(){return $(this.dom.offsetParent)}get offsetTop(){return this.dom.offsetTop}get offsetWidth(){return this.dom.offsetWidth}}class f extends et{constructor(t,s){super(t,s);h(this,"children",new Wt(this));h(this,"__position_cursor",0)}content(t){return $.fluent(this,arguments,()=>this,()=>{this.children.removeAll(!1),this.insert(t)})}insert(t,s=-1){return $.fluent(this,arguments,()=>this,async()=>{if(t instanceof Function){let i=t(this);i instanceof Promise?t=await i:t=i}else t instanceof Promise&&(t=await t);t=$.orArrayResolve(t),this.__position_cursor=s<0?this.children.array.length+s:s;for(const i of t)if(i!=null){if(i instanceof Array)this.insert(i,this.__position_cursor);else if(typeof i=="string")this.children.add(new X(i),s);else if(i instanceof I){const n=new X(i.toString());i.use(n,"content"),this.children.add(n,s)}else if(i instanceof Promise){const n=(await jt(async()=>{const{$Async:o}=await Promise.resolve().then(()=>Jt);return{$Async:o}},void 0)).$Async,a=new n().await(i);this.children.add(a,s)}else this.children.add(i,s);this.__position_cursor+=1}this.children.render()})}clear(){return this.children.removeAll(),this}$(t){return $(this.dom.querySelector(t))}$all(t){return Array.from(this.dom.querySelectorAll(t)).map(s=>$(s))}get scrollHeight(){return this.dom.scrollHeight}get scrollWidth(){return this.dom.scrollWidth}scrollTop(t){return $.fluent(this,arguments,()=>this.dom.scrollTop,()=>$.set(this.dom,"scrollTop",t))}scrollLeft(t){return $.fluent(this,arguments,()=>this.dom.scrollLeft,()=>$.set(this.dom,"scrollLeft",t))}}class Ut extends f{constructor(e){super("a",e),this.dom.addEventListener("click",t=>{$.anchorHandler&&this.href()&&(t.preventDefault(),$.anchorHandler(this,t))})}href(e){return $.fluent(this,arguments,()=>this.dom.href,()=>$.set(this.dom,"href",e))}target(e){return $.fluent(this,arguments,()=>this.dom.target??void 0,()=>{e&&(this.dom.target=e)})}}class Gt extends R{constructor(e,t){super(e,t)}}var O;(r=>{function e(o,l,d,c){return l.length?(c(),o):d()}r.fluent=e;function t(o){return o instanceof Array?o:[o]}r.orArrayResolve=t;function s(o,l){return t(l).forEach(d=>{Object.getOwnPropertyNames(d.prototype).forEach(c=>{c!=="constructor"&&Object.defineProperty(o.prototype,c,Object.getOwnPropertyDescriptor(d.prototype,c)||Object.create(null))})}),o}r.mixin=s;function i(o,l,d){d!==void 0&&(o[l]=d)}r.set=i;function n(o){return new I(o)}r.state=n;function a(o){if(o.$)return o.$;if(o.nodeName.toLowerCase()==="body")return new f("body",{dom:o});if(o.nodeName.toLowerCase()==="#document")return tt.from(o);if(o instanceof HTMLElement){const l=$.TagNameElementMap[o.tagName.toLowerCase()],d=l===f?new l(o.tagName,{dom:o}):new l({dom:o});if(d instanceof f)for(const c of Array.from(d.dom.childNodes))d.children.add($(c));return d}else if(o instanceof Text){const l=new X(o.textContent??"");return l.dom=o,l}else if(o instanceof SVGElement&&o.tagName.toLowerCase()==="svg")return new Gt("svg",{dom:o});throw`$NODE.FROM: NOT SUPPORT TARGET ELEMENT TYPE (${o.nodeName})`}r.from=a})(O||(O={}));class A{static create(...e){const t=class{};return Object.getOwnPropertyNames(A.prototype).forEach(s=>{s!=="constructor"&&e.includes(s)&&Object.defineProperty(t.prototype,s,Object.getOwnPropertyDescriptor(A.prototype,s)||Object.create(null))}),t}disabled(e){return $.fluent(this,arguments,()=>this.dom.disabled,()=>$.set(this.dom,"disabled",e))}checkValidity(){return this.dom.checkValidity()}reportValidity(){return this.dom.reportValidity()}formAction(e){return $.fluent(this,arguments,()=>this.dom.formAction,()=>$.set(this.dom,"formAction",e))}formEnctype(e){return $.fluent(this,arguments,()=>this.dom.formEnctype,()=>$.set(this.dom,"formEnctype",e))}formMethod(e){return $.fluent(this,arguments,()=>this.dom.formMethod,()=>$.set(this.dom,"formMethod",e))}formNoValidate(e){return $.fluent(this,arguments,()=>this.dom.formNoValidate,()=>$.set(this.dom,"formNoValidate",e))}formTarget(e){return $.fluent(this,arguments,()=>this.dom.formTarget,()=>$.set(this.dom,"formTarget",e))}autocomplete(e){return $.fluent(this,arguments,()=>this.dom.autocomplete,()=>$.set(this.dom,"autocomplete",e))}name(e){return $.fluent(this,arguments,()=>this.dom.name,()=>$.set(this.dom,"name",e))}maxLength(e){return $.fluent(this,arguments,()=>this.dom.maxLength,()=>$.set(this.dom,"maxLength",e))}minLength(e){return $.fluent(this,arguments,()=>this.dom.minLength,()=>$.set(this.dom,"minLength",e))}required(e){return $.fluent(this,arguments,()=>this.dom.required,()=>$.set(this.dom,"required",e))}label(e){return $.fluent(this,arguments,()=>this.dom.label,()=>$.set(this.dom,"label",e))}get form(){return this.dom.form?$(this.dom.form):null}get validationMessage(){return this.dom.validationMessage}get validity(){return this.dom.validity}get willValidate(){return this.dom.willValidate}}class ft extends f{constructor(e){super("button",e)}type(e){return $.fluent(this,arguments,()=>this.dom.type,()=>$.set(this.dom,"type",e))}}O.mixin(ft,A.create("disabled","checkValidity","formAction","formEnctype","formMethod","formNoValidate","formTarget","reportValidity"));class It extends f{constructor(e){super("form",e)}action(e){return $.fluent(this,arguments,()=>this.dom.formAction,()=>$.set(this.dom,"formAction",e))}enctype(e){return $.fluent(this,arguments,()=>this.dom.formEnctype,()=>$.set(this.dom,"formEnctype",e))}method(e){return $.fluent(this,arguments,()=>this.dom.formMethod,()=>$.set(this.dom,"formMethod",e))}noValidate(e){return $.fluent(this,arguments,()=>this.dom.formNoValidate,()=>$.set(this.dom,"formNoValidate",e))}acceptCharset(e){return $.fluent(this,arguments,()=>this.dom.acceptCharset,()=>$.set(this.dom,"acceptCharset",e))}target(e){return $.fluent(this,arguments,()=>this.dom.formTarget,()=>$.set(this.dom,"formTarget",e))}requestSubmit(){return this.dom.requestSubmit(),this}reset(){return this.dom.reset(),this}submit(){return this.dom.submit(),this}get length(){return this.dom.length}get elements(){return Array.from(this.dom.elements).map(e=>$(e))}}O.mixin(It,A.create("checkValidity","reportValidity","autocomplete"));class D extends et{constructor(e){super("input",e)}value(e){return $.fluent(this,arguments,()=>this.type()==="number"?Number(this.dom.value):this.dom.value,()=>$.set(this.dom,"value",e,t=>{this.on("input",()=>{t.attributes.has(this.dom)!==!1&&(typeof t.value=="string"&&t.set(`${this.value()}`),typeof t.value=="number"&&t.set(Number(this.value())))})}))}type(e){return $.fluent(this,arguments,()=>this.dom.type,()=>$.set(this.dom,"type",e))}capture(e){return $.fluent(this,arguments,()=>this.dom.capture,()=>$.set(this.dom,"capture",e))}alt(e){return $.fluent(this,arguments,()=>this.dom.alt,()=>$.set(this.dom,"alt",e))}height(e){return $.fluent(this,arguments,()=>this.dom.height,()=>$.set(this.dom,"height",e))}width(e){return $.fluent(this,arguments,()=>this.dom.width,()=>$.set(this.dom,"width",e))}defaultValue(e){return $.fluent(this,arguments,()=>this.dom.defaultValue,()=>$.set(this.dom,"defaultValue",e))}dirName(e){return $.fluent(this,arguments,()=>this.dom.dirName,()=>$.set(this.dom,"dirName",e))}pattern(e){return $.fluent(this,arguments,()=>this.dom.pattern,()=>$.set(this.dom,"pattern",e))}placeholder(e){return $.fluent(this,arguments,()=>this.dom.placeholder,()=>$.set(this.dom,"placeholder",e))}readOnly(e){return $.fluent(this,arguments,()=>this.dom.readOnly,()=>$.set(this.dom,"readOnly",e))}selectionDirection(e){return $.fluent(this,arguments,()=>this.dom.selectionDirection,()=>$.set(this.dom,"selectionDirection",e))}selectionEnd(e){return $.fluent(this,arguments,()=>this.dom.selectionEnd,()=>$.set(this.dom,"selectionEnd",e))}selectionStart(e){return $.fluent(this,arguments,()=>this.dom.selectionStart,()=>$.set(this.dom,"selectionStart",e))}size(e){return $.fluent(this,arguments,()=>this.dom.size,()=>$.set(this.dom,"size",e))}src(e){return $.fluent(this,arguments,()=>this.dom.src,()=>$.set(this.dom,"src",e))}inputMode(e){return $.fluent(this,arguments,()=>this.dom.inputMode,()=>$.set(this.dom,"inputMode",e))}valueAsDate(e){return $.fluent(this,arguments,()=>this.dom.valueAsDate,()=>$.set(this.dom,"valueAsDate",e))}valueAsNumber(e){return $.fluent(this,arguments,()=>this.dom.valueAsNumber,()=>$.set(this.dom,"valueAsNumber",e))}webkitdirectory(e){return $.fluent(this,arguments,()=>this.dom.webkitdirectory,()=>$.set(this.dom,"webkitdirectory",e))}select(){return this.dom.select(),this}setCustomValidity(e){return this.dom.setCustomValidity(e),this}setRangeText(e,t,s,i){return typeof t=="number"&&typeof s=="number"&&this.dom.setRangeText(e,t,s,i),this.dom.setRangeText(e),this}setSelectionRange(e,t,s){return this.dom.setSelectionRange(e,t,s),this}showPicker(){return this.dom.showPicker(),this}get files(){return this.dom.files}get webkitEntries(){return this.dom.webkitEntries}get labels(){return Array.from(this.dom.labels??[]).map(e=>$(e))}}O.mixin(D,A.create("checkValidity","reportValidity","autocomplete","name","form","required","validationMessage","validity","willValidate","formAction","formEnctype","formMethod","formNoValidate","formTarget"));class zt extends D{constructor(e){super(e),this.type("number")}static from(e){return $.mixin(D,this)}stepDown(){return this.dom.stepDown(),this}stepUp(){return this.dom.stepUp(),this}max(e){return $.fluent(this,arguments,()=>this.dom.max===""?null:parseInt(this.dom.min),()=>$.set(this.dom,"max",e==null?void 0:e.toString()))}min(e){return $.fluent(this,arguments,()=>this.dom.min===""?null:parseInt(this.dom.min),()=>$.set(this.dom,"min",e==null?void 0:e.toString()))}step(e){return $.fluent(this,arguments,()=>Number(this.dom.step),()=>$.set(this.dom,"step",e==null?void 0:e.toString()))}}class Kt extends D{constructor(e){super(e),this.type("radio")}static from(e){return $.mixin(D,this)}checked(e){return $.fluent(this,arguments,()=>this.dom.checked,()=>$.set(this.dom,"checked",e))}defaultChecked(e){return $.fluent(this,arguments,()=>this.dom.defaultChecked,()=>$.set(this.dom,"defaultChecked",e))}}class Xt extends D{constructor(e){super(e),this.type("file")}static from(e){return $.mixin(D,this)}multiple(e){return $.fluent(this,arguments,()=>this.dom.multiple,()=>$.set(this.dom,"multiple",e))}accept(...e){return $.fluent(this,arguments,()=>this.dom.accept.split(","),()=>this.dom.accept=e.toString())}}O.mixin(D,[zt,Kt,Xt]);class Ot extends f{constructor(e){super("label",e)}for(e){return $.fluent(this,arguments,()=>this.dom.htmlFor,()=>{$.set(this.dom,"htmlFor",e)})}get control(){return this.dom.control}}O.mixin(Ot,A.create("form"));class qt extends et{constructor(e){super("img",e)}async load(e){return new Promise(t=>{const s=this.once("load",()=>{t(s)});typeof e=="string"?s.src(e):e.then(i=>s.src(i))})}static resize(e,t){return new Promise(s=>{const i=new Image;if(i.addEventListener("load",()=>{const n=document.createElement("canvas"),a=n.getContext("2d");if(!a)throw"$Image.resize: context undefined";const o=i.width/i.height,[l,d,c]=[o>1,o<1,o===1],p=t instanceof Array?t[0]:d?t:t*o,g=t instanceof Array?t[1]:l?t:t/o;n.height=g,n.width=p,a.drawImage(i,0,0,p,g),s(n.toDataURL())},{once:!0}),e instanceof File){const n=new FileReader;n.addEventListener("load",()=>i.src=n.result),n.readAsDataURL(e)}else i.src=e})}alt(e){return $.fluent(this,arguments,()=>this.dom.alt,()=>$.set(this.dom,"alt",e))}crossOrigin(e){return $.fluent(this,arguments,()=>this.dom.crossOrigin,()=>$.set(this.dom,"crossOrigin",e))}decoding(e){return $.fluent(this,arguments,()=>this.dom.decoding,()=>$.set(this.dom,"decoding",e))}height(e){return $.fluent(this,arguments,()=>this.dom.height,()=>$.set(this.dom,"height",e))}isMap(e){return $.fluent(this,arguments,()=>this.dom.isMap,()=>$.set(this.dom,"isMap",e))}loading(e){return $.fluent(this,arguments,()=>this.dom.loading,()=>$.set(this.dom,"loading",e))}referrerPolicy(e){return $.fluent(this,arguments,()=>this.dom.referrerPolicy,()=>$.set(this.dom,"referrerPolicy",e))}sizes(e){return $.fluent(this,arguments,()=>this.dom.sizes,()=>$.set(this.dom,"sizes",e))}src(e){return $.fluent(this,arguments,()=>this.dom.src,()=>$.set(this.dom,"src",e))}srcset(e){return $.fluent(this,arguments,()=>this.dom.srcset,()=>$.set(this.dom,"srcset",e))}useMap(e){return $.fluent(this,arguments,()=>this.dom.useMap,()=>$.set(this.dom,"useMap",e))}width(e){return $.fluent(this,arguments,()=>this.dom.width,()=>$.set(this.dom,"width",e))}decode(){return this.dom.decode()}get complete(){return this.dom.complete}get currentSrc(){return this.dom.currentSrc}get naturalHeight(){return this.dom.naturalHeight}get naturalWidth(){return this.dom.naturalWidth}get x(){return this.dom.x}get y(){return this.dom.y}}class Bt extends f{constructor(e){super("canvas",e)}height(e){return $.fluent(this,arguments,()=>this.dom.height,()=>{$.set(this.dom,"height",e)})}width(e){return $.fluent(this,arguments,()=>this.dom.width,()=>{$.set(this.dom,"width",e)})}captureStream(e){return this.dom.captureStream(e)}getContext(e,t){return this.dom.getContext(e)}toBlob(e,t,s){return this.dom.toBlob(e,t,s),this}toDataURL(e,t){return this.dom.toDataURL(e,t)}transferControlToOffscreen(){return this.dom.transferControlToOffscreen()}}class Qt extends f{constructor(e){super("dialog",e)}open(e){return $.fluent(this,arguments,()=>this.dom.open,()=>$.set(this.dom,"open",e))}returnValue(e){return $.fluent(this,arguments,()=>this.dom.returnValue,()=>$.set(this.dom,"returnValue",e))}close(){return this.dom.close(),this}show(){return this.dom.show(),this}showModal(){return this.dom.showModal(),this}}class xt extends f{constructor(e){super("select")}add(e){return this.insert(e),this}item(e){return $(this.dom.item(e))}namedItem(e){return $(this.dom.namedItem(e))}multiple(e){return $.fluent(this,arguments,()=>this.dom.multiple,()=>$.set(this.dom,"multiple",e))}get length(){return this.dom.length}get size(){return this.dom.size}get options(){return Array.from(this.dom.options).map(e=>$(e))}get selectedIndex(){return this.dom.selectedIndex}get selectedOptions(){return Array.from(this.dom.selectedOptions).map(e=>$(e))}value(e){return $.fluent(this,arguments,()=>this.dom.value,()=>$.set(this.dom,"value",e,t=>{this.on("input",()=>{t.attributes.has(this.dom)!==!1&&(typeof t.value=="string"&&t.set(`${this.value()}`),typeof t.value=="number"&&t.set(Number(this.value())))})}))}get labels(){return Array.from(this.dom.labels??[]).map(e=>$(e))}}O.mixin(xt,A.create("checkValidity","reportValidity","autocomplete","name","form","required","disabled","validationMessage","validity","willValidate"));class Mt extends f{constructor(e){super("option",e)}defaultSelected(e){return $.fluent(this,arguments,()=>this.dom.defaultSelected,()=>$.set(this.dom,"defaultSelected",e))}selected(e){return $.fluent(this,arguments,()=>this.dom.selected,()=>$.set(this.dom,"selected",e))}text(e){return $.fluent(this,arguments,()=>this.dom.text,()=>$.set(this.dom,"text",e))}value(e){return $.fluent(this,arguments,()=>this.dom.value,()=>$.set(this.dom,"value",e))}get form(){return this.dom.form?$(this.dom.form):null}get index(){return this.dom.index}}O.mixin(Mt,A.create("form","disabled","label"));class Et extends f{constructor(e){super("optgroup",e)}disabled(e){return $.fluent(this,arguments,()=>this.dom.disabled,()=>$.set(this.dom,"disabled",e))}}O.mixin(Et,A.create("disabled","label"));class Pt extends f{constructor(e){super("textarea",e)}cols(e){return $.fluent(this,arguments,()=>this.dom.cols,()=>$.set(this.dom,"cols",e))}wrap(e){return $.fluent(this,arguments,()=>this.dom.wrap,()=>$.set(this.dom,"wrap",e))}value(e){return $.fluent(this,arguments,()=>this.dom.value,()=>$.set(this.dom,"value",e))}defaultValue(e){return $.fluent(this,arguments,()=>this.dom.defaultValue,()=>$.set(this.dom,"defaultValue",e))}dirName(e){return $.fluent(this,arguments,()=>this.dom.dirName,()=>$.set(this.dom,"dirName",e))}placeholder(e){return $.fluent(this,arguments,()=>this.dom.placeholder,()=>$.set(this.dom,"placeholder",e))}readOnly(e){return $.fluent(this,arguments,()=>this.dom.readOnly,()=>$.set(this.dom,"readOnly",e))}selectionDirection(e){return $.fluent(this,arguments,()=>this.dom.selectionDirection,()=>$.set(this.dom,"selectionDirection",e))}selectionEnd(e){return $.fluent(this,arguments,()=>this.dom.selectionEnd,()=>$.set(this.dom,"selectionEnd",e))}selectionStart(e){return $.fluent(this,arguments,()=>this.dom.selectionStart,()=>$.set(this.dom,"selectionStart",e))}type(e){return $.fluent(this,arguments,()=>this.dom.type,()=>$.set(this.dom,"type",e))}inputMode(e){return $.fluent(this,arguments,()=>this.dom.inputMode,()=>$.set(this.dom,"inputMode",e))}select(){return this.dom.select(),this}setCustomValidity(e){return this.dom.setCustomValidity(e),this}setRangeText(e,t,s,i){return typeof t=="number"&&typeof s=="number"&&this.dom.setRangeText(e,t,s,i),this.dom.setRangeText(e),this}setSelectionRange(e,t,s){return this.dom.setSelectionRange(e,t,s),this}get labels(){return Array.from(this.dom.labels??[]).map(e=>$(e))}}O.mixin(Pt,A.create("checkValidity","reportValidity","autocomplete","name","form","required","disabled","minLength","maxLength","validationMessage","validity","willValidate"));var st;class At extends f{constructor(t){super("async",t);J(this,st,!1)}await(t){return t instanceof Function?t(this).then(s=>this._loaded(s)):t.then(s=>this._loaded(s)),this}_loaded(t){if(Y(this,st,!0),typeof t=="string")this.replace(new X(t));else if(t instanceof I){const s=new X(t.toString());t.use(s,"content"),this.replace(s)}else t==null?this.replace(new X(String(t))):this.replace(t);this.dom.dispatchEvent(new Event("load"))}get loaded(){return M(this,st)}}st=new WeakMap;const Jt=Object.freeze(Object.defineProperty({__proto__:null,$Async:At},Symbol.toStringTag,{value:"Module"}));class Yt extends R{constructor(e,t){super(e,t)}autoplay(e){return $.fluent(this,arguments,()=>this.dom.autoplay,()=>$.set(this.dom,"autoplay",e))}get buffered(){return this.dom.buffered}controls(e){return $.fluent(this,arguments,()=>this.dom.controls,()=>$.set(this.dom,"controls",e))}crossOrigin(e){return $.fluent(this,arguments,()=>this.dom.crossOrigin,()=>$.set(this.dom,"crossOrigin",e))}get currentSrc(){return this.dom.currentSrc}currentTime(e){return $.fluent(this,arguments,()=>this.dom.currentTime,()=>$.set(this.dom,"currentTime",e))}defaultMuted(e){return $.fluent(this,arguments,()=>this.dom.defaultMuted,()=>$.set(this.dom,"defaultMuted",e))}defaultPlaybackRate(e){return $.fluent(this,arguments,()=>this.dom.defaultPlaybackRate,()=>$.set(this.dom,"defaultPlaybackRate",e))}disableRemotePlayback(e){return $.fluent(this,arguments,()=>this.dom.disableRemotePlayback,()=>$.set(this.dom,"disableRemotePlayback",e))}get duration(){return this.dom.duration}get ended(){return this.dom.ended}get error(){return this.dom.error}loop(e){return $.fluent(this,arguments,()=>this.dom.loop,()=>$.set(this.dom,"loop",e))}mediaKeys(e){return $.fluent(this,arguments,()=>this.dom.mediaKeys,()=>$.set(this.dom,"setMediaKeys",[e]))}muted(e){return $.fluent(this,arguments,()=>this.dom.muted,()=>$.set(this.dom,"muted",e))}get networkState(){return this.dom.networkState}get paused(){return this.dom.paused}playbackRate(e){return $.fluent(this,arguments,()=>this.dom.playbackRate,()=>$.set(this.dom,"playbackRate",e))}get played(){return this.dom.played}preload(e){return $.fluent(this,arguments,()=>this.dom.preload,()=>$.set(this.dom,"preload",e))}preservesPitch(e){return $.fluent(this,arguments,()=>this.dom.preservesPitch,()=>$.set(this.dom,"preservesPitch",e))}get readyState(){return this.dom.readyState}get remote(){return this.dom.remote}get seekable(){return this.dom.seekable}get seeking(){return this.dom.seeking}sinkId(e){return $.fluent(this,arguments,()=>this.dom.sinkId,()=>$.set(this.dom,"setSinkId",[e]))}src(e){return $.fluent(this,arguments,()=>this.dom.src,()=>$.set(this.dom,"src",e))}srcObject(e){return $.fluent(this,arguments,()=>this.dom.srcObject,()=>$.set(this.dom,"srcObject",e))}get textTracks(){return this.dom.textTracks}volume(e){return $.fluent(this,arguments,()=>this.dom.volume,()=>$.set(this.dom,"volume",e))}addTextTrack(e,t,s){return this.dom.addTextTrack(e,t,s)}canPlayType(e){return this.dom.canPlayType(e)}fastSeek(e){return this.dom.fastSeek(e),this}load(){return this.dom.load(),this}pause(){return this.dom.pause(),this}async play(){return await this.dom.play(),this}get isPlaying(){return this.currentTime()>0&&!this.paused&&!this.ended&&this.readyState>2}}class Zt extends Yt{constructor(e){super("video",e)}disablePictureInPicture(e){return $.fluent(this,arguments,()=>this.dom.disablePictureInPicture,()=>$.set(this.dom,"disablePictureInPicture",e))}height(e){return $.fluent(this,arguments,()=>this.dom.height,()=>$.set(this.dom,"height",e))}width(e){return $.fluent(this,arguments,()=>this.dom.width,()=>$.set(this.dom,"width",e))}playsInline(e){return $.fluent(this,arguments,()=>this.dom.playsInline,()=>$.set(this.dom,"playsInline",e))}poster(e){return $.fluent(this,arguments,()=>this.dom.poster,()=>$.set(this.dom,"poster",e))}get videoHeight(){return this.dom.videoHeight}get videoWidth(){return this.dom.videoWidth}cancelVideoFrameCallback(e){return this.dom.cancelVideoFrameCallback(e),this}getVideoPlaybackQuality(){return this.dom.getVideoPlaybackQuality()}requestPictureInPicture(){return this.dom.requestPictureInPicture()}requestVideoFrameCallback(e){return this.dom.requestVideoFrameCallback(e)}}function _(r){if(typeof r>"u"||r===null||r instanceof z)return r;if(typeof r=="string"){if(r.startsWith("::"))return Array.from(document.querySelectorAll(r.replace(/^::/,""))).map(e=>_(e));if(r.startsWith(":"))return _(document.querySelector(r.replace(/^:/,"")));if(r in _.TagNameElementMap){const e=_.TagNameElementMap[r];return e===et?new et(r):e===f?new f(r):new e}else return new f(r)}if(r instanceof Node)return r.$?r.$:O.from(r);throw`$: NOT SUPPORT TARGET ELEMENT TYPE ('${r}')`}(r=>{r.anchorHandler=null,r.TagNameElementMap={html:f,head:f,document:tt,body:f,a:Ut,p:f,pre:f,code:f,blockquote:f,strong:f,h1:f,h2:f,h3:f,h4:f,h5:f,h6:f,div:f,ol:f,ul:f,dl:f,li:f,input:D,label:Ot,button:ft,form:It,img:qt,dialog:Qt,canvas:Bt,select:xt,option:Mt,optgroup:Et,textarea:Pt,video:Zt,async:At};function e(u,m,v,T){return m.length?(T(),u):v()}r.fluent=e;function t(u){return u instanceof Array?u:[u]}r.orArrayResolve=t;function s(u,m){return O.mixin(u,m)}r.mixin=s;function i(u,m,v,T){if(v!==void 0){if(v instanceof I){v.use(u,m),u[m]instanceof Function?u[m](...v.value):u[m]=v.value,T&&T(v);return}u[m]instanceof Function?u[m](...v):u[m]=v}}r.set=i;function n(u,m){return new I(u,m)}r.state=n;async function a(u,m){return new Promise(v=>{const T=new FileReader;T.onload=S=>{const w=r("img");if(w.once("load",x=>{const j=r("canvas"),W=j.getContext("2d"),H=w.height()/w.width(),[L,K]=[H>1?m/H:m,H>1?m:m*H];j.height(K).width(L),W==null||W.drawImage(w.dom,0,0,L,K),v(j.toDataURL(u.type))}),!S.target)throw"$.resize(): e.target is null";w.src(S.target.result)},T.readAsDataURL(u)})}r.resize=a;function o(u=1){return parseInt(getComputedStyle(document.documentElement).fontSize)*u}r.rem=o;function l(u){const m=new DOMParser().parseFromString(u,"text/html").body;return Array.from(m.children).map(v=>r(v))}r.html=l;function d(u,m,v){if(typeof m=="number")return Array(m).fill("").map(S=>{const w=T(u)?u[0](...u.slice(1)):r(u);return v&&v(w),w});{const S=[];for(const w of m){const x=u instanceof Function?u(...w):T(u)?u[0](...u.slice(1)):r(u);w instanceof Function?w(x):(w instanceof z||typeof w=="string")&&x.content(w),S.push(x)}return S}function T(S){return S instanceof Array&&S[0]instanceof Function}}r.builder=d;function c(u,m){return Object.assign(r.TagNameElementMap,{[u]:m}),r.TagNameElementMap}r.registerTagName=c;function p(...u){return new Q}r.events=p;function g(u){return u()}r.call=g})(_||(_={}));globalThis.$=_;class Q{constructor(){h(this,"eventMap",new Map)}fire(e,...t){var s;return(s=this.eventMap.get(e))==null||s.forEach(i=>i(...t)),this}on(e,t){const s=this.eventMap.get(e)??this.eventMap.set(e,new Set).get(e);return s==null||s.add(t),this}off(e,t){var s;return(s=this.eventMap.get(e))==null||s.delete(t),this}once(e,t){const s=(...n)=>{var a;(a=this.eventMap.get(e))==null||a.delete(s),t(...n)},i=this.eventMap.get(e)??this.eventMap.set(e,new Set).get(e);return i==null||i.add(s),this}}Array.prototype.detype=function(...r){return this.filter(e=>{if(r.length)for(const t of r)return typeof e!=typeof t;else return e!==void 0})};Object.defineProperties(Set.prototype,{array:{get:function(){return Array.from(this)}}});Set.prototype.sort=function(r){return this.array.sort(r)};class Lt extends f{constructor(t){super("layout",t);h(this,"_property",{ROW_MAX_HEIGHT:200,GAP:0,IS_RENDERING:!1,RENDER_REQUEST:!1,COLUNM:1,TYPE:"justified",ROOT:null,ITEM_PROPERTIES:new Map});this.css({display:"block",position:"relative"}),new ResizeObserver(s=>{this.inDOM()&&(this.render(),this.dom.dispatchEvent(new Event("resize")))}).observe(this.dom),document.addEventListener("scroll",s=>{s.target===this.root().dom&&this.scrollCompute()},{passive:!0}),new IntersectionObserver(s=>{this.inDOM()&&this.render()}).observe(this.dom)}type(t){return $.fluent(this,arguments,()=>this._property.TYPE,()=>$.set(this._property,"TYPE",t))}maxHeight(t){return $.fluent(this,arguments,()=>this._property.ROW_MAX_HEIGHT,()=>$.set(this._property,"ROW_MAX_HEIGHT",t))}column(t){return $.fluent(this,arguments,()=>this._property.COLUNM,()=>$.set(this._property,"COLUNM",t))}gap(t){return $.fluent(this,arguments,()=>this._property.GAP,()=>$.set(this._property,"GAP",t))}root(t){return $.fluent(this,arguments,()=>this._property.ROOT??$(document),()=>$.set(this._property,"ROOT",t))}get COL_WIDTH(){return(this.offsetWidth-this._property.GAP*(this._property.COLUNM-1))/this._property.COLUNM}justifiedCompute(){const t=[],s=this.offsetWidth;for(const i of this.children.array){const n=$(i);if(!(n instanceof R))continue;const a=n.attribute("layout-item-ratio"),o=a?parseFloat(a):n.dom.offsetWidth/n.dom.offsetHeight,l={$node:n,ratio:o};let d=t.at(-1);(!d||d.heightc+=u.ratio);const p=c+o,g=(s-this._property.GAP*d.items.length)/p;d.items.push(l),d.ratio=p,d.height=g}return t}waterfallCompute(){const t=[],s=this.COL_WIDTH,i=()=>{if(t.lengthn.height-a.height)[0]};for(const n of this.children.array){const a=$(n);if(!(a instanceof R))continue;const o=a.attribute("layout-item-ratio"),l=o?parseFloat(o):a.dom.offsetWidth/a.dom.offsetHeight,d={$node:a,ratio:l},c=i();let p=0;c.items.forEach(m=>p+=m.ratio);const g=s/(c.height+s/l),u=s/g;c.items.push(d),c.ratio=g,c.height=u}return t}render(){if(!this.inDOM())return this;if(this._property.ITEM_PROPERTIES.clear(),this._property.TYPE==="justified"){const t=this.justifiedCompute();let s=0;for(const i of t){let n=0;i.height>this._property.ROW_MAX_HEIGHT&&(i.height=this._property.ROW_MAX_HEIGHT);for(const a of i.items){const o=a.ratio*i.height;a.$node.css({position:"absolute",height:`${i.height}px`,width:`${o}px`,top:`${s}px`,left:`${n}px`}),a.$node.attribute("layout-item-ratio",a.ratio),this._property.ITEM_PROPERTIES.set(a.$node,{height:i.height,width:o,top:s,left:n,ratio:a.ratio,$node:a.$node}),n+=i.height*a.ratio+this._property.GAP}s+=i.height+this._property.GAP}this.css({height:`${s}px`})}else if(this._property.TYPE="waterfall"){const t=this.waterfallCompute(),s=this.COL_WIDTH;let i=0;for(const n of t){let a=0;for(const o of n.items){const l=s/o.ratio;o.$node.css({position:"absolute",height:`${l}px`,width:`${s}px`,top:`${a}px`,left:`${i}px`}),o.$node.attribute("layout-item-ratio",o.ratio),this._property.ITEM_PROPERTIES.set(o.$node,{height:l,width:s,top:a,left:i,ratio:o.ratio,$node:o.$node}),a+=l+this._property.GAP}i+=s+this._property.GAP}if(t.length){const n=t.sort((a,o)=>o.height-a.height)[0];this.css({height:`${n.height+n.items.length*this._property.GAP}px`})}else this.css({height:""})}return this.scrollCompute(),this}scrollCompute(){if(this.inDOM()===!1)return;const t=document.documentElement.scrollTop-this.dom.offsetTop;this._property.ITEM_PROPERTIES.forEach((s,i)=>{const n=s.top;s.top+s.height>t&&n{this.contentId=t,this.events.fire("rendered",{$view:this,previousContent:i,nextContent:s})},o=()=>{this.events.fire("afterSwitch",{$view:this,previousId:t})};return this.events.fire("beforeSwitch",{$view:this,preventDefault:()=>n=!0,targetId:t,previousContent:i,nextContent:s,switched:o,rendered:a}),n||(this.content(s),a(),o()),this}get currentContent(){if(this.contentId)return this.viewCache.get(this.contentId)}}$.registerTagName("view",kt);var F;const b=class b extends kt{constructor(t){super({tagname:"router",...t});J(this,F,"");h(this,"routes",new Map);b.routers.add(this)}base(t){return $.fluent(this,arguments,()=>M(this,F),()=>{Y(this,F,t??M(this,F))})}map(t){t=$.orArrayResolve(t);for(const s of t)s instanceof Array?this.map(s):this.routes.set(s.path(),s);return this.resolve(),this}resolve(){return new Promise(t=>{if(!location.pathname.startsWith(M(this,F)))return t(2);const s=location.pathname.replace(M(this,F),"/").replace("//","/"),i=s.split("/").map(m=>`/${m}`),n=location.search,a=new Map(n.replace("?","").split("&").map(m=>m.split("="))),l=(()=>{const m=[];for(const[v,T]of this.routes){const S=$.orArrayResolve(v);for(const w of S){let x=0,j={},W={};const H=w.split("/").map(L=>`/${L}`);if(!(i.length{const yt=a.get(vt);yt!==void 0&&x++,Object.assign(W,{[vt]:yt})}),K.startsWith("/:")){x++,Object.assign(j,{[K.replace("/:","")]:i[L].replace("/","")});continue}else if(w.startsWith("#")&&w===location.hash){x++;continue}else if(K===i[L]){x++;continue}else break}m.push({deep:x,$route:T,params:j,query:W,routePath:w,pathId:Object.keys(W).length!==0?s+n:Object.keys(j).length!==0?s:S[0]})}}}return m.sort((v,T)=>T.deep-v.deep).at(0)})();if(!l)return t(1);const{$route:d,params:c,pathId:p,query:g}=l;if(p===this.contentId)return t(0);this.events.once("rendered",({nextContent:m,previousContent:v})=>{v==null||v.events.fire("afterShift",{$route:v}),m.events.fire("rendered",{$route:m}),t(0)});const u=this.viewCache.get(p)??d.build({params:c,query:g});this.viewCache.has(p)||this.setView(p,u),this.events.once("beforeSwitch",()=>{var m;u.events.fire("beforeShift",{$route:u}),(m=this.currentContent)==null||m.events.fire("beforeShift",{$route:this.currentContent})}),this.events.once("afterSwitch",()=>u.events.fire("afterShift",{$route:u})),this.switchView(p)})}static init(){if(!history.state||!("index"in history.state)){const t={index:b.historyIndex};history.replaceState(t,"")}else b.historyIndex=history.state.index;return b.navigationDirection=0,b.resolve(),window.addEventListener("popstate",()=>b.popstate()),window.addEventListener("scroll",()=>{this.setScrollHistory(this.historyIndex,location.href,document.documentElement.scrollTop)},{passive:!0}),history.scrollRestoration="manual",this}static open(t,s){return t===void 0?this:(t=this.urlResolver(t),t.href===this.url.href?this:t.origin!==this.url.origin?(window.open(t,s),this):(b.clearForwardScrollHistory(),b.historyIndex++,history.pushState(b.historyState,"",t),b.stateChange(0),b.resolve(),this))}static back(){return this.historyIndex--,history.back(),this}static replace(t){return t===void 0?this:(t=this.urlResolver(t),history.replaceState(b.historyState,"",t),this.stateChange(2),this.setScrollHistory(this.historyIndex,location.href,0),b.resolve(),this)}static urlResolver(t){return t instanceof URL?t:(t.startsWith("/")&&(t=`${location.origin}${t}`),t.startsWith("#")&&(t=`${location.origin}${location.pathname}${t}`),new URL(t))}static popstate(){const t=history.state.index>b.historyIndex?0:history.state.indext.resolve())),this.scrollRestoration(),this.setScrollHistory(this.historyIndex,location.href,document.documentElement.scrollTop)}static get historyState(){return{index:b.historyIndex}}static stateChange(t){const s=this.url,i=new URL(location.href);this.url=i,b.events.fire("stateChange",{beforeURL:s,afterURL:i,direction:t}),b.navigationDirection=t}static setScrollHistory(t,s,i){const n=this.getScrollHistory();if(!n)return sessionStorage.setItem(this.scrollHistoryKey,JSON.stringify({[t]:{url:s,value:i}}));n[t]={url:s,value:i},sessionStorage.setItem(this.scrollHistoryKey,JSON.stringify(n))}static getScrollHistory(){const t=sessionStorage.getItem(this.scrollHistoryKey);if(t)return JSON.parse(t)}static clearForwardScrollHistory(){const t=this.getScrollHistory();if(t)for(const s in t)Number(s)>this.historyIndex&&delete t[s],sessionStorage.setItem(this.scrollHistoryKey,JSON.stringify(t))}static scrollRestoration(){const t=this.getScrollHistory();if(t&&t[this.historyIndex])document.documentElement.scrollTop=t[this.historyIndex].value??0;else if(location.hash.length){const s=$(document.body).$(location.hash);s&&(document.documentElement.scrollTop=s.dom.offsetTop)}else document.documentElement.scrollTop=0}};F=new WeakMap,h(b,"routers",new Set),h(b,"events",new Q),h(b,"navigationDirection"),h(b,"historyIndex",0),h(b,"url",new URL(location.href)),h(b,"scrollHistoryKey","$ROUTER_SCROLL_HISTORY");let P=b;var U=(r=>(r[r.Forward=0]="Forward",r[r.Back=1]="Back",r[r.Replace=2]="Replace",r))(U||{});P.init();var B,V;const gt=class gt extends f{constructor(t){super("route",t);J(this,B,"");J(this,V);h(this,"rendered",!1)}path(t){return $.fluent(this,arguments,()=>M(this,B),()=>Y(this,B,t??M(this,B)))}builder(t){return Y(this,V,t),this}render(t){return M(this,V)&&this.content(M(this,V).call(this,{$route:this,params:t.params,query:t.query})),this.rendered=!0,this}build(t){return new gt({dom:this.dom.cloneNode()}).self(s=>{M(this,V)&&s.builder(M(this,V)).render({params:t.params,query:t.query})})}};B=new WeakMap,V=new WeakMap;let ut=gt;$.registerTagName("router",P);$.registerTagName("route",ut);Object.assign($,{open(r,e){return P.open(r,e)},replace(r){return P.replace(r)},back(){return P.back()}});class te{constructor(e,t){h(this,"booru");Object.assign(this,t),this.booru=e}static async fetchUserFavorites(e,t,s,i=100,n){return(await e.fetch(`/favorites.json?${s}&${`search[user_id]=${t.id}`}&limit=${i}&page=${n}`)).map(o=>(t.favorites.add(o.post_id),o.post_id))}update(e){return Object.assign(this,e),this}}class ct{constructor(e,t,s=!0){h(this,"name$",$.state("..."));h(this,"post_upload_count$",$.state(0));h(this,"level$",$.state(10));h(this,"level_string$",$.state("..."));h(this,"booru");h(this,"favorites",new Set);this.booru=e,Object.assign(this,t),s&&this.update$()}static async fetch(e,t){var n;let s;if(typeof t=="string"){const a=(await e.fetch(`/users.json?search[name]=${t}`)).at(0);if(!a)throw"User Not Found";return s=a}else s=await e.fetch(`/users/${t}.json`);const i=((n=e.users.get(s.id))==null?void 0:n.update(s))??new this(e,s);return e.users.set(i.id,i),i}static async fetchMultiple(e,t,s=200){let i="";if(t)for(const[o,l]of Object.entries(t))if(l instanceof Array)i+=`&search[${o}]=${l}`;else if(l instanceof Object)for(const[d,c]of Object.entries(l))i+=`&search[${o}${d}]=${c}`;else i+=`&search[${o}]=${l}`;return(await e.fetch(`/users.json?limit=${s}${i}`)).map(o=>{const l=new this(e,o);return e.users.set(l.id,l),l})}update(e){return Object.assign(this,e),this.update$(),this}update$(){this.name$.set(this.name),this.post_upload_count$.set(this.post_upload_count),this.level$.set(this.level),this.level_string$.set(this.level_string)}get booruURL(){return`${this.booru.origin}/users/${this.id}`}get url(){return`/users/${this.id}`}}const ht=class ht extends ct{constructor(t,s,i){super(t,i,!1);h(this,"apiKey");h(this,"favorite_count$",$.state(0));h(this,"forum_post_count$",$.state(0));this.apiKey=s,this.update$()}update$(){var t,s;super.update$(),(t=this.forum_post_count$)==null||t.set(this.forum_post_count),(s=this.favorite_count$)==null||s.set(this.favorite_count)}async init(){await this.fetchFavorites()}async fetchFavorites(){const t=Array.from(this.favorites.keys()).at(-1),s=await te.fetchUserFavorites(this.booru,this,"",1e3,t?`b${t}`:1);return ht.events.fire("favoriteUpdate",this),s.length>=1e3&&this.fetchFavorites(),s}static get storageUserData(){const t=localStorage.getItem("user_data");return t?JSON.parse(t):null}static set storageUserData(t){localStorage.setItem("user_data",JSON.stringify(t))}};h(ht,"events",new Q);let N=ht;const C=class C{constructor(e){h(this,"user");h(this,"posts",new Map);h(this,"tags",new Map);h(this,"users",new Map);h(this,"favorites",new Map);Object.assign(this,e),this.origin.endsWith("/")&&(this.origin=this.origin.slice(0,-1)),C.manager.set(this.name,this)}static set(e){this.used=e,this.name$.set(e.name),this.storageAPI=e.name;const t=N.storageUserData;return t&&e.login(t.username,t.apiKey),this.events.fire("set"),this}static get storageAPI(){return localStorage.getItem("booru_api")}static set storageAPI(e){e?localStorage.setItem("booru_api",e):localStorage.removeItem("booru_api")}async fetch(e,t="GET"){const s=this.user?`${e.includes("?")?"&":"?"}login=${this.user.name}&api_key=${this.user.apiKey}`:"",i=await fetch(`${this.origin}${e}${s}`,{method:t}).then(n=>n.json());if(i.success===!1)throw i.message;return i}async login(e,t){const s=await this.fetch(`/profile.json?login=${e}&api_key=${t}`);return this.user=new N(this,t,s),this.user.init(),C.events.fire("login",this.user),this.user}logout(){return this.user=void 0,N.storageUserData=null,C.events.fire("logout"),this}};h(C,"used"),h(C,"events",new Q),h(C,"name$",$.state(C.name)),h(C,"manager",new Map);let y=C;class ee{constructor(e,t){h(this,"post_count$",$.state(0));h(this,"name$",$.state(""));h(this,"booru");this.booru=e,Object.assign(this,t),this.$update()}static async fetch(e,t){var n;const s=await e.fetch(`/tags/${t}.json`),i=((n=e.tags.get(s.id))==null?void 0:n.update(s))??new this(e,s);return e.tags.set(i.id,i),i}static async fetchMultiple(e,t,s=1e3){let i="";if(t)for(const[o,l]of Object.entries(t))if(l instanceof Array)i+=`&search[${o}]=${l}`;else if(l instanceof Object)for(const[d,c]of Object.entries(l))i+=`&search[${o}${d}]=${c}`;else i+=`&search[${o}]=${l}`;return(await e.fetch(`/tags.json?limit=${s}${i}`)).map(o=>{var d;const l=((d=e.tags.get(o.id))==null?void 0:d.update(o))??new this(e,o);return e.tags.set(l.id,l),l})}update(e){return Object.assign(this,e),this.$update(),this}$update(){this.post_count$.set(this.post_count),this.name$.set(this.name)}}var G=(r=>(r[r.General=0]="General",r[r.Artist=1]="Artist",r[r.Copyright=3]="Copyright",r[r.Character=4]="Character",r[r.Meta=5]="Meta",r))(G||{});const pt=1e3,nt=pt*60,ot=nt*60,at=ot*24,se=at*7,it=new Intl.RelativeTimeFormat("en",{style:"long"});function ie(r){r=Math.floor(r);const e=r/pt,t=r/nt,s=r/ot,i=r/at,n=r%1e3,a=Math.floor(r%6e4/1e3),o=Math.floor(r%36e5/6e4),l=Math.floor(r%(36e5*24)/36e5),d=a.toString().padStart(2,"0"),c=o.toString().padStart(2,"0"),p=l.toString().padStart(2,"0");return{seconds:e,minutes:t,hours:s,days:i,mil:n,s:a,min:o,h:l,ss:d,mm:c,hh:p}}function re(r,e=Date.now()){const t=r-e,s=Math.abs(t);if(sthis.update$()),this}static async fetchMultiple(t,s,i=20,n){let a="";if(s){if(typeof s=="string")a=s;else for(const[c,p]of Object.entries(s))if(p!==void 0){if(c==="tags"){a+=`${p}`;continue}a.at(-1)!=="="&&(a+=" "),a+=`${c}:${p}`}}const o=await t.fetch(`/posts.json?limit=${i}&tags=${a}${n?`&page=${n}`:""}&_method=get`);if(!(o instanceof Array))return[];const l=o.map(c=>{var g;const p=((g=t.posts.get(c.id))==null?void 0:g.update(c))??new this(t,c.id,c);return t.posts.set(p.id,p),p});if(!l.length)return l;const d=[...new Set(o.map(c=>[c.approver_id,c.uploader_id].detype(null)).flat())];return ct.fetchMultiple(t,{id:d}).then(()=>l.forEach(c=>c.update$())),l}update$(){var t,s,i,n;this.uploader$.set(((t=this.uploader)==null?void 0:t.name$)??((s=this.uploader_id)==null?void 0:s.toString())),this.approver$.set(((i=this.approver)==null?void 0:i.name$)??((n=this.approver_id)==null?void 0:n.toString())??"None"),this.created_date$.set(re(+new Date(this.created_at))),this.favcount$.set(this.fav_count),this.score$.set(this.score),this.file_size$.set(ne(this.file_size)),this.file_ext$.set(this.file_ext),this.file_url$.set(this.file_url),this.source$.set(this.source),this.dimension$.set(`${this.image_width}x${this.image_height}`),this.url$.set(`${this.url}`),this.isUgoria&&this.webm_url$.set(this.large_file_url),this.createdDate=new Date(this.created_at),this.fire("update")}update(t){return Object.assign(this,t),this.update$(),this}async fetchTags(){return await this.ready,await ee.fetchMultiple(this.booru,{name:{_space:this.tag_string}})}async createFavorite(){if(!this.booru.user)return;const t=await this.booru.fetch(`/favorites.json?post_id=${this.id}`,"POST");return this.update(t),this.booru.user.favorites.add(t.id),N.events.fire("favoriteUpdate",this.booru.user),t.id}async deleteFavorite(){!this.booru.user||await fetch(`/api/favorites/${this.id}?login=${this.booru.user.name}&api_key=${this.booru.user.apiKey}&origin=${this.booru.origin}`,{method:"DELETE"}).then(s=>s.json())===!1||(this.fav_count--,this.favcount$.set(this.fav_count),this.booru.user.favorites.delete(this.id),N.events.fire("favoriteUpdate",this.booru.user))}get pathname(){return`/posts/${this.id}`}get uploader(){return this.booru.users.get(this.uploader_id)}get approver(){return this.approver_id?this.booru.users.get(this.approver_id):null}get isVideo(){return this.file_ext==="mp4"||this.file_ext==="webm"||this.file_ext==="zip"}get isGif(){return this.file_ext==="gif"}get isUgoria(){return this.file_ext==="zip"}get hasSound(){return this.tag_string_meta.includes("sound")}get tags(){const t=this.tag_string.split(" ");return[...this.booru.tags.values()].filter(s=>t.includes(s.name))}get previewURL(){var t,s;return((s=(t=this.media_asset.variants)==null?void 0:t.find(i=>i.file_ext==="webp"))==null?void 0:s.url)??this.large_file_url}get url(){return`${this.booru.origin}/posts/${this.id}`}get isFileSource(){return this.source.startsWith("file://")}}class Ct{constructor(e){Object.assign(this,e)}static async fetch(e,t){const s=await e.fetch(`/artist_commentaries/${t}.json`);return new this(s)}static async fetchMultiple(e,t,s=200){let i="";if(t)for(const[o,l]of Object.entries(t))if(l instanceof Array)i+=`&search[${o}]=${l}`;else if(l instanceof Object)for(const[d,c]of Object.entries(l))i+=`&search[${o}${d}]=${c}`;else i+=`&search[${o}]=${l}`;return(await e.fetch(`/artist_commentaries.json?limit=${s}${i}`)).map(o=>{const l=new this(o);return this.manager.set(l.id,l),l})}}h(Ct,"manager",new Map);const oe=new Intl.NumberFormat("en",{notation:"compact"});function Z(r){return oe.format(r)}const ae=$("route").path("/posts/:id").id("post").builder(({$route:r,params:e})=>{if(!Number(e.id))return $("h1").content("404: POST NOT FOUND");const t=q.get(y.used,+e.id),s=$("div").class("viewer-panel").content([$("div").class("panel").content([$("ion-icon").name("heart-outline").self(i=>{var n;N.events.on("favoriteUpdate",a=>{a.favorites.has(t.id)?i.name("heart"):i.name("heart-outline")}),(n=y.used.user)!=null&&n.favorites.has(t.id)&&i.name("heart")}).on("click",()=>{var i;(i=y.used.user)!=null&&i.favorites.has(t.id)?t.deleteFavorite():t.createFavorite()})]),$("div").class("overlay")]).hide(!0);return[$("div").class("viewer").content(async()=>(await t.ready,[s,t.isVideo?$("video").height(t.image_height).width(t.image_width).src(t.file_ext==="zip"?t.large_file_url:t.file_url).controls(!0).autoplay(!0).loop(!0).disablePictureInPicture(!0):$("img").src(t.large_file_url)])).on("pointermove",i=>{(i.pointerType==="mouse"||i.pointerType==="pen")&&s.hide(!1)}).on("pointerup",i=>{console.debug(i.movementX),i.pointerType==="touch"&&s.hide(!s.hide())}).on("mouseleave",()=>{s.hide(!0)}),$("div").class("content").content([$("h3").content("Artist's Commentary"),$("section").class("commentary").content(async i=>{const n=(await Ct.fetchMultiple(y.used,{post:{_id:t.id}})).at(0);return[n?[n.original_title?$("h3").content(n.original_title):null,$("pre").content(n.original_description)]:"No commentary"]})]),$("div").class("sidebar").self(i=>{let n=0;addEventListener("scroll",()=>{i.inDOM()&&(n=document.documentElement.scrollTop)},{passive:!0}),r.on("beforeShift",()=>{innerWidth>800&&i.css({position:"absolute",top:`calc(${n}px + var(--nav-height) + var(--padding))`})}).on("afterShift",()=>i.css({position:"",top:""}))}).content([$("section").class("post-info").content([new E("id").name("Post").content(`#${e.id}`),new E("uploader").name("Uploader").content(t.uploader$),new E("approver").name("Approver").content(t.approver$),new E("date").name("Date").content(t.created_date$),new E("size").name("Size").content([t.file_size$,t.dimension$]),new E("file-type").name("File Type").content(t.file_ext$),$("div").class("inline").content([new E("favorites").name("Favorites").content(t.favcount$),new E("score").name("Score").content(t.score$)]),new E("file-url").name("File").content([$("a").href(t.file_url$).content(t.file_url$.convert(i=>i.replace("https://",""))).target("_blank"),$("ion-icon").name("clipboard").on("click",(i,n)=>lt(n,t.source))]),new E("source-url").name("Source").content([$("a").href(t.source$).content(t.source$.convert(i=>i.replace("https://",""))).target("_blank"),$("ion-icon").name("clipboard").on("click",(i,n)=>lt(n,t.source))]),new E("booru-url").name(y.name$).content([$("a").href(t.url$).content(t.url$.convert(i=>i.replace("https://",""))).target("_blank"),$("ion-icon").name("clipboard").on("click",(i,n)=>lt(n,t.source))]),new E("booru-url").name("Webm").hide(!0).self(async i=>{await t.ready,t.isUgoria&&i.content($("a").href(t.webm_url$).content(t.webm_url$.convert(n=>n.replace("https://",""))).target("_blank")).hide(!1)})]),$("div").class("post-tags").content(async i=>{const n=await t.fetchTags(),[a,o,l,d,c]=[n.filter(g=>g.category===G.Artist),n.filter(g=>g.category===G.Character),n.filter(g=>g.category===G.General),n.filter(g=>g.category===G.Meta),n.filter(g=>g.category===G.Copyright)];return[p("Artist",a),p("Character",o),p("Copyright",c),p("Meta",d),p("General",l)];function p(g,u){return u.length?[$("h3").content(g),$("section").content([u.map(m=>$("div").class("tag").content([$("a").class("tag-name").content(m.name).href(`/posts?tags=${m.name}`),$("span").class("tag-post-count").content(m.post_count$.convert(Z))]))])]:null}})])]});function lt(r,e){r.name("checkmark"),navigator.clipboard.writeText(e),setTimeout(()=>r.name("clipboard"),3e3)}class E extends f{constructor(t){super("div");h(this,"$name",$("span").class("property-name"));h(this,"$values",$("div").class("property-values"));this.staticClass("property").attribute("property-id",t),super.content([this.$name,this.$values.hide(!0)])}name(t){return this.$name.content(t),this}content(t){this.$values.hide(!1);const s=$.orArrayResolve(t);return this.$values.content(s.map(i=>$("span").staticClass("property-value").content(i))),this}}class he extends f{constructor(t){super("post-tile");h(this,"post");h(this,"$video");h(this,"duration$",$.state(""));this.post=t,this.$video=this.post.isVideo?$("video").width(this.post.image_width).height(this.post.image_height).disablePictureInPicture(!0).loop(!0).muted(!0).hide(!0).on("mousedown",s=>s.preventDefault()):null,this.attribute("filetype",this.post.file_ext),this.durationUpdate(),this.build()}build(){var s,i;let t;(s=this.$video)==null||s.on("playing",(n,a)=>{t=setInterval(()=>{this.durationUpdate()},500)}),(i=this.$video)==null||i.on("pause",()=>{clearInterval(t),this.durationUpdate()}),this.class("loading").content([this.post.isVideo?$("div").class("video-detail").content([this.post.hasSound?$("ion-icon").name("volume-medium-outline"):null,this.post.isUgoria?$("ion-icon").name("images-outline"):null,$("span").class("duration").content(this.duration$)]):null,this.post.isGif?$("div").class("gif-detail").content([$("span").content("GIF")]):null,$("a").href(this.post.pathname).content(()=>[this.$video,$("img").draggable(!1).css({opacity:"0"}).width(this.post.image_width).height(this.post.image_height).src(this.post.previewURL).loading("lazy").on("mousedown",n=>n.preventDefault()).once("load",(n,a)=>{a.src(this.post.previewURL).on(["mouseenter","touchstart"],()=>{this.post.isGif&&a.src(this.post.large_file_url)},{passive:!0}).on(["mouseleave","touchend","touchcancel"],()=>{this.post.isGif&&a.src(this.post.previewURL)},{passive:!0}).animate({opacity:[0,1]},{duration:300,fill:"both"}),this.removeClass("loading")})]).on(["mouseenter","touchstart"],()=>{var n,a;(n=this.$video)!=null&&n.isPlaying||(a=this.$video)==null||a.src(this.post.large_file_url).hide(!1).play().catch(o=>{})},{passive:!0}).on(["mouseleave","touchend","touchcancel"],()=>{var n;(n=this.$video)==null||n.pause().currentTime(0).hide(!0)},{passive:!0})])}durationUpdate(){if(!this.$video)return;const t=ie(this.post.media_asset.duration*1e3-this.$video.currentTime()*1e3);this.duration$.set(Number(t.hh)>0?`${t.hh}:${t.mm}:${t.ss}`:`${t.mm}:${t.ss}`)}}class Tt extends Lt{constructor(t){super();h(this,"posts",new Set);h(this,"$posts",new Map);h(this,"orderMap",new Map);h(this,"tags");h(this,"finished",!1);h(this,"limit",100);this.tags=t==null?void 0:t.tags,this.addStaticClass("post-grid"),this.type("waterfall").gap(10),this.init()}async init(){setInterval(()=>{this.inDOM()&&document.documentElement.scrollTop===0&&this.getPost("newer")},1e4),y.events.on("set",()=>{this.removeAll(),this.finished&&(this.finished=!1,this.events.fire("startLoad"),this.loader())}),this.on("resize",()=>this.resize()),this.events.fire("startLoad"),this.loader()}async loader(){if(!this.inDOM())return setTimeout(()=>this.loader(),100);for(;this.inDOM()&&document.documentElement.scrollHeight<=innerHeight*2;)if(!(await this.getPost("older")).length)return;document.documentElement.scrollTop+innerHeight>document.documentElement.scrollHeight-innerHeight*2&&!(await this.getPost("older")).length||setTimeout(()=>this.loader(),100)}resize(){const t=Math.round(this.dom.clientWidth/300);this.column(t>=2?t:2)}addPost(t){t=$.orArrayResolve(t);for(const i of t){if(!i.file_url||this.posts.has(i))continue;const n=new he(i);this.$posts.set(i,n),this.posts.add(i)}const s=[...this.orderMap.values()].map(i=>this.$posts.get(i));return this.content(s).render(),this}removeAll(){return this.posts.clear(),this.$posts.clear(),this.animate({opacity:[1,0]},{duration:300,easing:"ease"},()=>this.clear().render()),this}async getPost(t){const s=this.tags?decodeURIComponent(this.tags).split("+"):void 0,i=[],n=[];let a=this.limit;if(s)for(const c of s)c.startsWith("ordfav:")||c.startsWith("order:")?n.push(c):c.startsWith("limit:")?a=Number(c.split(":")[1]):i.push(c);if(n.length){if(n.length>1)return this.events.fire("post_error",`Error: These query can't be used together [${n}].`),[];const c=n[0];if(c.startsWith("ordfav:")){const p=c.split(":")[1],g=i.length?`&search[post_tags_match]=${i.toString().replaceAll(",","+")}`:"",u=this.orderKeyList.length?t==="newer"?`&search[id]=>${this.orderKeyList.at(0)}`:`&search[id]=<${this.orderKeyList.at(-1)}`:void 0,m=await y.used.fetch(`/favorites.json?search[user_name]=${p}${u??""}${g}&limit=${a}`),v=await q.fetchMultiple(y.used,{tags:`id:${m.map(S=>S.post_id).toString()}`}),T=new Map;for(const S of m){const w=v.find(x=>x.id===S.post_id);w&&T.set(S.id,w)}return this.orderMap=new Map(t==="newer"?[...T,...this.orderMap]:[...this.orderMap,...T]),this.addPost(v),v}if(c.startsWith("order:")){const p=this.orderKeyList.length?t==="newer"?1:this.orderMap.size/a+1:void 0,g=await q.fetchMultiple(y.used,{tags:this.tags},a,p),u=new Map(g.map(m=>[m.id,m]));return u.forEach((m,v)=>{this.orderMap.has(v)&&u.delete(v)}),this.orderMap=new Map(t==="newer"?[...u,...this.orderMap]:[...this.orderMap,...u]),this.addPost(g),g}}const o=this.orderKeyList.length?t==="newer"?`a${this.orderKeyList.at(0)}`:`b${this.orderKeyList.at(-1)}`:void 0,l=await q.fetchMultiple(y.used,{tags:this.tags},a,o),d=new Map(l.map(c=>[c.id,c]));return this.orderMap=new Map(t==="newer"?[...d,...this.orderMap]:[...this.orderMap,...d]),this.addPost(l),l.length||(this.finished=!0,this.posts.size?this.events.fire("endPost"):this.events.fire("noPost")),l}get orderKeyList(){return[...this.orderMap.keys()]}}class Rt{static async fetch(e,t,s=20){if(!t.length)return this.searchQuery.map(a=>new St(a));const i=await e.fetch(`/autocomplete.json?search[query]=${t}&search[type]=tag_query&version=1&limit=${s}`);return[...t.length?this.searchQuery.filter(a=>a.value.startsWith(t)&&a.value!==t):this.searchQuery,...i].map(a=>new St(a))}}h(Rt,"searchQuery",[{value:"user:",label:"user:"},{value:"approver:",label:"approver:"},{value:"-approver:",label:"-approver:"},{value:"order:",label:"order:"},{value:"ordfav:",label:"ordfav:"},{value:"ordfavgroup:",label:"ordfavgroup:"},{value:"search:",label:"search:"},{value:"favgroup:",label:"favgroup:"},{value:"-favgroup:",label:"-favgroup:"},{value:"favcount:",label:"favcount:"},{value:"id:",label:"id:"},{value:"tagcount:",label:"tagcount:"},{value:"gentags:",label:"gentags:"},{value:"arttags:",label:"arttags:"},{value:"chartags:",label:"chartags:"},{value:"copytags:",label:"copytags:"},{value:"metatags:",label:"metatags:"},{value:"score:",label:"score:"},{value:"upvote:",label:"upvote:"},{value:"downvote:",label:"downvote:"},{value:"disapproved:",label:"disapproved:"},{value:"md5:",label:"md5:"},{value:"width:",label:"width:"},{value:"height:",label:"height:"},{value:"ratio:",label:"ratio:"},{value:"mpixels:",label:"mpixels:"},{value:"filesize:",label:"filesize:"},{value:"duration:",label:"duration:"},{value:"is:",label:"is:"},{value:"has:",label:"has:"},{value:"pool:",label:"pool:"},{value:"-pool:",label:"-pool:"},{value:"ordpool:",label:"ordpool:"},{value:"random:",label:"random:"},{value:"limit:",label:"limit:"},{value:"date:",label:"date:"},{value:"commenter:",label:"commenter:"},{value:"note:",label:"note:"},{value:"noter:",label:"noter:"},{value:"noteupdater:",label:"noteupdater:"},{value:"status:",label:"status:"},{value:"-status:",label:"-status:"},{value:"rating:",label:"rating:"},{value:"-rating:",label:"-rating:"},{value:"source:",label:"source:"},{value:"-source:",label:"-source:"},{value:"pixiv:",label:"pixiv:"},{value:"parent:",label:"parent:"},{value:"child:",label:"child:"},{value:"flagger:",label:"flagger:"},{value:"appealer:",label:"appealer:"},{value:"commentary:",label:"commentary:"},{value:"commentaryupdater:",label:"commentaryupdater:"}].map(e=>({type:"query",...e})));class St{constructor(e){Object.assign(this,e)}isTag(){return this.type==="tag"||this.type==="tag-autocorrect"||this.type==="tag-alias"||this.type==="tag-word"}isTagAutocorrect(){return this.type==="tag-autocorrect"}isTagAntecedent(){return!!this.antecedent}isTagWord(){return this.type==="tag-word"}isUser(){return this.type==="user"}}class le extends f{constructor(){super("searchbar");h(this,"$tagInput",new de(this));h(this,"$selectionList",new ue);h(this,"typingTimer",null);h(this,"$filter",$("div").class("filter"));this.build(),window.addEventListener("keyup",t=>{!this.inDOM()&&t.key==="/"&&this.open(),this.inDOM()&&t.key==="Escape"&&this.close()})}build(){this.content([$("div").class("input-container").content([this.$tagInput.on("input",()=>this.inputHandler()).on("keydown",t=>this.keyHandler(t)),$("ion-icon").name("close-circle-outline").title("Clear Input").on("click",()=>this.$tagInput.clearAll())]).on("click",t=>{t.target===this.$tagInput.dom&&this.$tagInput.addTag().input()}),$("div").class("selection-list-container").content([this.$selectionList]),this.$filter.on("click",()=>{location.hash==="#search"&&this.close()})])}open(){return $.open(location.href+"#search"),this}close(){return $.back(),this}activate(){return this.hide(!1),this.$filter.animate({opacity:[0,.5]},{duration:300,easing:"ease"}),this.$tagInput.input(),this}inactivate(){return this.animate({opacity:[.5,0]},{duration:300,easing:"ease"},()=>this.hide(!0)),this}keyHandler(t){var n,a;const s=()=>{t.preventDefault(),this.$tagInput.addTag().input()},i=o=>{const l=this.$tagInput.children.indexOf(this.$tagInput.$inputor);if(this.$tagInput.$input.value().at(-1)===":")return this.getSearchSuggestions();const d=this.$tagInput.children.array.at(l+1);this.$tagInput.addTag(o.value()),d?this.$tagInput.editTag(d):this.$tagInput.input()};switch(t.key){case"ArrowUp":{t.preventDefault(),this.$selectionList.focusPrevSelection(),this.$tagInput.value((n=this.$selectionList.focused)==null?void 0:n.value());break}case"ArrowDown":{t.preventDefault(),this.$selectionList.focusNextSelection(),this.$tagInput.value((a=this.$selectionList.focused)==null?void 0:a.value());break}case" ":s();break;case"Enter":{t.preventDefault(),this.$selectionList.focused?i(this.$selectionList.focused):(this.$tagInput.addTag(),this.search());break}case"Tab":{t.preventDefault();const o=this.$tagInput.children.indexOf(this.$tagInput.$inputor);if(t.shiftKey){o-1>=0&&this.$tagInput.editTag(this.$tagInput.children.array.at(o-1));break}if(this.$selectionList.focused)i(this.$selectionList.focused);else{const l=this.$tagInput.children.array.at(o+1);l?this.$tagInput.editTag(l):this.$tagInput.addTag().input()}break}case"Backspace":{const o=this.$tagInput.children.indexOf(this.$tagInput.$inputor);o!==0&&!this.$tagInput.$input.value().length&&(t.preventDefault(),this.$tagInput.editTag(this.$tagInput.children.array.at(o-1)));break}}}inputHandler(){this.typingTimer&&(clearTimeout(this.typingTimer),this.typingTimer=null),this.typingTimer=setTimeout(async()=>{this.typingTimer=null,this.getSearchSuggestions()},200)}async getSearchSuggestions(){const t=this.$tagInput.$input.value(),s=await Rt.fetch(y.used,t,20);this.$selectionList.clearSelections().addSelections(s.map(i=>new ce().value(i.value).content([$("div").class("selection-label").content([i.isTagAntecedent()?$("span").class("tag-antecedent").self(n=>n.dom.innerHTML=i.antecedent.replaceAll(t,`${t}`)):null,$("div").class("label-container").content([i.isTagAntecedent()?$("ion-icon").name("arrow-forward-outline"):null,$("span").class("label").self(n=>n.dom.innerHTML=i.label.replaceAll(t,`${t}`))])]),i.isTag()?$("div").class("tag-detail").content([$("span").class("tag-post-count").content(Z(i.post_count)),$("span").class("tag-category").content(G[i.category])]):null,i.isUser()?$("span").class("user-level").content(i.level):null]).on("click",()=>{this.$tagInput.addTag(i.value).input()})))}search(){return $.replace(`/posts?tags=${this.$tagInput.query.replace(":","%3A")}`),this.$tagInput.clearAll(),this.inactivate(),this}checkURL(t,s){if((t==null?void 0:t.hash)==="#search"&&this.inactivate(),s.hash==="#search"&&this.activate(),`${t==null?void 0:t.pathname}${t==null?void 0:t.search}`==`${s.pathname}${s.search}`)return;const i=s.searchParams.get("tags");this.$tagInput.clearAll(),i==null||i.split(" ").forEach(n=>this.$tagInput.addTag(n))}}class ue extends f{constructor(){super("selection-list");h(this,"focused",null);h(this,"selections",new Set)}addSelections(t){t=$.orArrayResolve(t);for(const s of t)this.selections.add(s);return this.insert(t),this}clearSelections(){return this.focused=null,this.selections.clear(),this.clear(),this}focusSelection(t){return this.blurSelection(),this.focused=t,t.focus(),t.offsetTopthis.scrollTop()+this.offsetHeight&&this.scrollTop(t.offsetTop+t.offsetHeight-this.offsetHeight),this}blurSelection(){var t;return(t=this.focused)==null||t.blur(),this.focused=null,this}focusNextSelection(){const t=this.selections.array,s=t.at(0);if(this.focused){const i=t.at(t.indexOf(this.focused)+1);i?this.focusSelection(i):s&&this.focusSelection(s)}else s&&this.focusSelection(s)}focusPrevSelection(){const t=this.selections.array;if(this.focused){const s=t.at(t.indexOf(this.focused)-1);s&&this.focusSelection(s)}else{const s=t.at(0);s&&this.focusSelection(s)}}}class ce extends f{constructor(){super("selection");h(this,"property",{value:""})}value(t){return $.fluent(this,arguments,()=>this.property.value,()=>$.set(this.property,"value",t))}focus(){return this.addClass("active"),this}blur(){return this.removeClass("active"),this}}class de extends f{constructor(t){super("tag-input");h(this,"$input",$("input").type("text"));h(this,"$sizer",$("span").class("sizer"));h(this,"$inputor",$("div").class("input-wrapper").content([this.$sizer,this.$input.on("input",()=>{this.$sizer.content(this.$input.value())})]));h(this,"tags",new Set);h(this,"$seachbar");this.$seachbar=t}input(){return this.insert(this.$inputor),this.$input.focus(),this.$seachbar.$selectionList.clearSelections(),this.$seachbar.getSearchSuggestions(),this}addTag(t){if(t=t??this.$input.value(),!t.length)return this;const s=new me(t);return s.on("click",()=>this.editTag(s)),this.tags.add(s),this.value(""),this.$input.inDOM()?this.$inputor.replace(s):this.insert(s),this}editTag(t){return this.addTag(),this.tags.delete(t),t.replace(this.$inputor),this.value(t.name),this.$input.focus(),this.$seachbar.getSearchSuggestions(),this}clearAll(){return this.value(""),this.tags.clear(),this.clear(),this}value(t){return t===void 0?this:(this.$input.value(t),this.$sizer.content(t),this)}focus(){return this.$input.focus(),this}get query(){return this.tags.array.map(t=>t.name).toString().replace(",","+")}}class me extends f{constructor(t){super("tag");h(this,"name");this.name=t,this.build()}build(){this.content(this.name)}}class fe extends f{constructor(){super("ion-icon")}name(e){return this.attribute("name",e),this}size(e){return this.attribute("size",e),this}link(e,t=!1){return this.on("click",()=>t?$.replace(e):$.open(e)),this}}class pe extends ft{constructor(){super();h(this,"$icon",$("ion-icon"));h(this,"$label",$("span"));this.addStaticClass("icon"),this.build()}build(){super.content([this.$icon.hide(!0),this.$label])}content(t){return this.$label.content(t),this}icon(t){return this.$icon.name(t).hide(!1),this}link(t,s=!1){return this.on("click",()=>s?$.replace(t):$.open(t)),this}}const ge=$("route").id("login").path("/login").builder(()=>{const[r,e]=[$.state(""),$.state("")];return[$("div").class("login-container").content([$("h1").content("Login"),$("div").class("username","input-container").content([$("label").for("username").content("Username"),$("input").type("text").id("username").value(r)]),$("div").class("api-key","input-container").content([$("label").for("api-key").content("API Key"),$("input").type("password").id("api-key").value(e)]),$("icon-button").content("Login").on("click",async()=>{await y.used.login(r.value,e.value),y.used.user&&(N.storageUserData={apiKey:e.value,username:r.value},r.set(""),e.set(""),$.replace("/"))}),$("icon-button").content("Create Account").icon("open-outline").on("click",()=>$.open("https://danbooru.donmai.us/users/new","_blank"))])]});class $e extends f{constructor(){super("drawer");h(this,"$filter",$("div").class("filter"));h(this,"$container",$("div").class("drawer-container"));this.hide(!0),this.build()}build(){this.content([this.$container.content([$("div").class("user-info").hide(!0).self(t=>[y.events.on("login",s=>{t.content([$("div").content([$("h3").class("username").content(s.name$),$("div").class("user-detail").content([$("span").class("userid").content(`ID: ${s.id}`),$("span").class("level").content(["Level: ",s.level_string$])])]),$("div").class("user-nav").content([$("icon-button").title("Uploaded Posts").icon("image").content(s.post_upload_count$.convert(Z)).link(`/posts?tags=user:${s.name}`,!0),$("icon-button").title("Favorites").icon("heart").content(s.favorite_count$.convert(Z)).link(`/posts?tags=ordfav:${s.name}`,!0),$("icon-button").title("Forum Posts").icon("document-text").content(s.forum_post_count$.convert(Z)).hide(!0)])]).hide(!1)}).on("logout",()=>{t.clear().hide(!0)})]),$("div").class("nav").content([$("div").class("login").content([$("icon-button").icon("log-in-outline").content("Login").link("/login",!0)]).self(t=>y.events.on("login",()=>t.hide(!0)).on("logout",()=>t.hide(!1))),$("div").class("logout").hide(!0).content([$("icon-button").icon("log-in-outline").content("Logout").on("dblclick",()=>y.used.logout())]).self(t=>y.events.on("login",()=>t.hide(!1)).on("logout",()=>t.hide(!0)))])]),this.$filter.on("click",()=>$.back())])}open(){this.hide(!1),this.$container.animate({transform:["translateX(100%)","translateX(0%)"]},{fill:"both",duration:300,easing:"ease"}),this.$filter.animate({opacity:[0,1]},{fill:"both",duration:300,easing:"ease"})}close(){this.$container.animate({transform:["translateX(0%)","translateX(100%)"]},{fill:"both",duration:300,easing:"ease"},()=>this.hide(!0)),this.$filter.animate({opacity:[1,0]},{fill:"both",duration:300,easing:"ease"})}checkURL(t,s){(t==null?void 0:t.hash)==="#drawer"&&this.close(),s.hash==="#drawer"&&this.open()}}$.registerTagName("ion-icon",fe);$.registerTagName("icon-button",pe);$.anchorHandler=r=>{$.open(r.href(),r.target())};const[dt,ve]=[new y({origin:"https://danbooru.donmai.us",name:"Danbooru"}),new y({origin:"https://safebooru.donmai.us",name:"Safebooru"}),new y({origin:"https://testbooru.donmai.us",name:"Testbooru"})];y.set(y.manager.get(y.storageAPI??"")??dt);const rt=new le().hide(!0),mt=new $e;$(document.body).content([$("nav").content([$("a").class("title").href("/").content([$("h1").class("booru-name").content(y.name$),$("h2").class("app").content([$("span").class("app-name").content("Viewer"),$("span").class("version").content("v0.6.0")])]),$("div").class("searchbar").content(["Search in ",y.name$]).self(r=>P.events.on("stateChange",({beforeURL:e,afterURL:t})=>{e.hash==="#search"&&r.hide(!1),t.hash==="#search"&&r.hide(!0)})).on("click",()=>rt.open()),$("div").class("buttons").content([$("ion-icon").class("search").name("search-outline").title("Search").self(r=>P.events.on("stateChange",({beforeURL:e,afterURL:t})=>{e.hash==="#search"&&r.hide(!1),t.hash==="#search"&&r.hide(!0)})).on("click",()=>rt.open()),$("ion-icon").class("switch").name("swap-horizontal").title("Switch Booru").on("click",()=>{y.used===dt?y.set(ve):y.set(dt)}),$("ion-icon").class("open").name("open-outline").title("Open in Original Site").on("click",()=>$.open(location.href.replace(location.origin,y.used.origin))),$("ion-icon").class("menu").name("menu-outline").title("Menu").hide(!1).self(r=>{y.events.on("login",()=>r.hide(!0)).on("logout",()=>r.hide(!1))}).on("click",()=>$.open(location.href+"#drawer")),$("div").class("account").hide(!0).title("Menu").self(r=>{y.events.on("login",e=>{r.content(e.name$.convert(t=>{var s;return((s=t.at(0))==null?void 0:s.toUpperCase())??""})).hide(!1)}).on("logout",()=>r.hide(!0))}).on("click",()=>mt.open())])]),rt,mt,$("router").base("/").map([$("route").id("posts").path(["/","/posts"]).builder(()=>new Tt),$("route").id("posts").path("/posts?tags").builder(({query:r})=>{const e=new Tt({tags:r.tags});return[$("header").content([$("h2").content("Posts"),$("div").class("tags").self(t=>{r.tags.split("+").forEach(s=>{t.insert($("a").class("tag").content(decodeURIComponent(s)).href(`posts?tags=${s}`))})})]),$("div").class("no-post").hide(!0).self(t=>{t.on("startLoad",()=>t.hide(!0)),e.on("noPost",()=>t.hide(!1).content("No Posts")).on("post_error",s=>t.hide(!1).content(s))}),e]}),ae,ge]).on("beforeSwitch",r=>{r.preventDefault();function s(){var a;const n=$.call(()=>{switch(P.navigationDirection){case U.Forward:return["translateX(2%)","translateX(0%)"];case U.Back:return["translateX(-2%)","translateX(0%)"];case U.Replace:return""}});r.$view.content(r.nextContent),r.rendered(),(a=r.nextContent.element)==null||a.class("animated").animate({opacity:[0,1],transform:n},{duration:300,easing:"ease"},()=>{var o;r.switched(),(o=r.nextContent.element)==null||o.removeClass("animated")})}function i(){var a,o;const n=$.call(()=>{switch(P.navigationDirection){case U.Forward:return["translateX(0%)","translateX(-2%)"];case U.Back:return["translateX(0%)","translateX(2%)"];case U.Replace:return""}});(o=(a=r.previousContent)==null?void 0:a.element)==null||o.class("animated").animate({opacity:[1,0],transform:n},{duration:300,easing:"ease"},()=>{var l,d;(d=(l=r.previousContent)==null?void 0:l.element)==null||d.removeClass("animated"),s()})}r.previousContent?i():s()})]);P.events.on("stateChange",({beforeURL:r,afterURL:e})=>Nt(r,e));Nt(void 0,new URL(location.href));function Nt(r,e){rt.checkURL(r,e),mt.checkURL(r,e)} diff --git a/dist/assets/index-C3nfTvuP.css b/dist/assets/index-C3nfTvuP.css deleted file mode 100644 index d463cfe..0000000 --- a/dist/assets/index-C3nfTvuP.css +++ /dev/null @@ -1 +0,0 @@ -layout.post-grid{margin-top:.4rem}post-tile{display:block;transition:.3s all ease;position:relative;transition:all .3s ease;border-radius:var(--border-radius-medium);overflow:hidden;-webkit-tap-highlight-color:transparent;-webkit-user-select:none;user-select:none}@media (hover: hover){post-tile:hover{transform:scale(1.02);z-index:1;box-shadow:0 0 10px color-mix(in srgb,var(--secondary-color-1) 50%,transparent)}}post-tile.loading{transition:none}post-tile:active{transform:scale(.95)}post-tile div.video-detail,post-tile div.gif-detail{position:absolute;background-color:var(--secondary-color-3);color:var(--primary-color);bottom:.3rem;right:.3rem;padding:.2em .4em;height:1rem;border-radius:var(--border-radius-small);font-size:12px;display:flex;align-items:center;gap:.2rem;z-index:2}post-tile div.video-detail ion-icon,post-tile div.gif-detail ion-icon{font-size:1.4rem}post-tile div.video-detail ion-icon[name=images-outline],post-tile div.gif-detail ion-icon[name=images-outline]{padding:.1rem;font-size:1rem}post-tile div.video-detail span.duration,post-tile div.gif-detail span.duration{text-transform:uppercase;z-index:2}post-tile a{background-color:transparent;padding:0;border-radius:0}post-tile a img{height:100%;width:100%;vertical-align:top;background-color:var(--secondary-color-1)}post-tile a video{height:100%;width:100%;object-fit:cover;position:absolute;z-index:1}searchbar{display:flex;align-items:center;flex-direction:column;width:100%;z-index:200;position:fixed;height:100%}searchbar div.input-container{margin-top:.4rem;background-color:color-mix(in srgb,var(--secondary-color-2) 100%,transparent);border-radius:var(--border-radius-small);font-size:1rem;width:500px;padding:.4rem;max-width:calc(100% - 2rem);box-sizing:border-box;z-index:201;display:flex;align-items:center;border:1px solid var(--secondary-color-4)}searchbar div.input-container:focus-within{outline:none}searchbar div.input-container tag-input{display:flex;gap:.4rem;width:100%;overflow:hidden;padding-inline:.4rem;box-sizing:border-box;cursor:text}searchbar div.input-container tag-input tag{display:inline-block;padding:.2rem .4rem;background-color:var(--secondary-color-4);color:var(--secondary-color-9);border-radius:var(--border-radius-small);cursor:pointer}searchbar div.input-container ion-icon{font-size:20px;color:var(--secondary-color-4);cursor:pointer}searchbar div.input-container ion-icon:hover{color:var(--secondary-color-9)}searchbar div.selection-list-container{overflow:hidden;border-radius:var(--border-radius-small);background-color:var(--secondary-color-1);z-index:201;max-width:calc(100% - 2rem);width:500px}searchbar div.selection-list-container selection-list{display:block;max-height:40vh;overflow-y:scroll;overflow-x:hidden;position:relative}searchbar div.selection-list-container selection-list::-webkit-scrollbar{width:4px}searchbar div.selection-list-container selection-list selection{display:flex;justify-content:space-between;align-items:center;padding:.4rem 1rem;cursor:pointer;gap:1rem}searchbar div.selection-list-container selection-list selection:hover{background-color:color-mix(in srgb,var(--secondary-color-3) 50%,transparent)}searchbar div.selection-list-container selection-list selection.active{background-color:var(--secondary-color-3)}searchbar div.selection-list-container selection-list selection div.selection-label{display:flex;flex-wrap:wrap;gap:.5rem}searchbar div.selection-list-container selection-list selection div.selection-label .label-container{display:flex;gap:.5rem;align-items:center}searchbar div.selection-list-container selection-list selection div.selection-label .label-container ion-icon{font-size:1rem}searchbar div.selection-list-container selection-list selection div.tag-detail{display:flex;align-items:center;gap:.5rem}searchbar div.selection-list-container selection-list selection div.tag-detail .tag-post-count{font-size:.8rem}searchbar div.selection-list-container selection-list selection .tag-category,searchbar div.selection-list-container selection-list selection .user-level{padding:.1rem .4rem;border-radius:var(--border-radius-small);font-size:.9rem;background-color:var(--secondary-color-4);color:var(--secondary-color-9)}searchbar div.filter{background-color:var(--secondary-color-1);opacity:.5;position:fixed;top:0;height:100%;width:100%;z-index:199}.input-wrapper{color:var(--primary-color);border:1px solid var(--secondary-color-9);border-radius:var(--border-radius-small);position:relative;box-sizing:border-box;line-height:1em;font-size:14px;padding:4px 8px;display:inline-block;max-width:100%;text-overflow:ellipsis}.input-wrapper span.sizer{font-family:inherit;white-space:pre;height:1em;display:inline-block;font-size:inherit;line-height:inherit;box-sizing:border-box;position:relative;opacity:0;min-width:2px;-webkit-user-select:none;user-select:none;vertical-align:top}.input-wrapper input{height:100%;text-overflow:ellipsis;font-family:inherit;background:none;color:inherit;top:0;left:0;font-size:inherit;line-height:inherit;padding:inherit;position:absolute;box-sizing:border-box;width:100%;border:none;outline:none}button.icon{display:flex;justify-content:center;align-items:center;gap:.4rem;padding:.8rem 1.2rem}button.icon ion-icon{font-size:1.4rem;color:inherit}button.icon.vertical{flex-direction:column}drawer{position:fixed;top:0;left:0;display:flex;z-index:300;height:100%;width:100%;box-sizing:border-box;justify-content:end;align-items:center;padding:1rem}drawer div.drawer-container{width:300px;max-width:70%;height:100%;background-color:var(--secondary-color-1);border-radius:var(--border-radius-large);z-index:1;overflow:hidden}drawer div.drawer-container div.user-info{background-color:var(--secondary-color-2);padding:2rem}drawer div.drawer-container div.user-info .username{margin:0;color:var(--secondary-color-9);cursor:pointer}drawer div.drawer-container div.user-info div.user-detail{display:flex;gap:.5rem;margin-top:.2rem}drawer div.drawer-container div.user-info div.user-detail span{font-size:.8rem;color:var(--primary-color-dark);display:block;cursor:pointer}drawer div.drawer-container div.user-info div.user-nav{display:grid;grid-template-columns:1fr 1fr 1fr;gap:1rem;margin-top:1rem}drawer div.drawer-container div.nav{padding:2rem;display:flex;gap:1rem;flex-direction:column}drawer div.filter{position:absolute;top:0;left:0;height:100%;width:100%;background:linear-gradient(90deg,color-mix(in srgb,var(--secondary-color-1) 50%,transparent),color-mix(in srgb,var(--secondary-color-0) 70%,transparent))}#post{padding:0;padding-top:var(--nav-height)}#post section{background-color:#2f2f45;border-radius:var(--border-radius-large);padding:20px}#post div.viewer{height:calc(100vh - 2rem - var(--nav-height));display:flex;justify-content:center;align-items:center;background-color:#000;border-radius:var(--border-radius-large);overflow:hidden;width:calc(100vw - 300px - 4rem);margin:1rem}@media (max-width: 800px){#post div.viewer{width:100%;height:calc(100vh - var(--nav-height));border-radius:0;margin:0}}#post div.viewer img{max-width:100%;max-height:100%}#post div.viewer video{max-width:100%;max-height:100%;-webkit-user-drag:none;transition:all .3s ease}#post div.content{width:calc(100vw - 300px - 2rem);display:flex;flex-direction:column;padding:1rem;box-sizing:border-box}@media (max-width: 800px){#post div.content{width:100%}}#post div.content::-webkit-scrollbar{background-color:#000;width:4px}#post div.content::-webkit-scrollbar-thumb{background-color:#aeaeec;border-radius:2px}#post div.content>h3{padding-left:1rem;margin-block:1rem}#post div.content section.commentary *{text-wrap:wrap;word-break:break-word}#post div.sidebar{--padding: 1rem;position:fixed;top:calc(var(--nav-height) + var(--padding));right:var(--padding);display:flex;flex-direction:column;gap:.4rem;width:300px;overflow:scroll;overflow-x:hidden;height:calc(100vh - 2rem - var(--nav-height));border-radius:var(--border-radius-large)}@media (max-width: 800px){#post div.sidebar{position:static;width:100%;overflow:visible;height:100%;padding:1rem;box-sizing:border-box}}#post div.sidebar::-webkit-scrollbar{background-color:#000;width:0px}#post div.sidebar::-webkit-scrollbar-thumb{background-color:#aeaeec}#post div.sidebar h3{padding-left:1rem;margin-block:.6rem}#post div.sidebar .post-info{background-color:#2f2f45;border-radius:var(--border-radius-large);padding:20px;display:flex;flex-direction:column;gap:.4rem}#post div.sidebar .post-info .buttons{display:grid;grid-template-columns:1fr 1fr 1fr;gap:1rem;margin-top:1rem}#post div.sidebar div.property{display:flex;gap:.6rem;align-items:center;width:100%}#post div.sidebar div.property span.property-name{flex-shrink:0}#post div.sidebar div.property div.property-values{display:flex;gap:.4rem;width:100%;overflow:hidden}#post div.sidebar div.property div.property-values span.property-value{padding:.2rem .4rem;background-color:var(--secondary-color-1);color:var(--primary-color-dark);border-radius:var(--border-radius-small);justify-content:space-between;flex-shrink:1;display:flex;align-items:center;overflow:hidden}#post div.sidebar div.property div.property-values span.property-value:has(ion-icon){flex-shrink:0}#post div.sidebar div.property div.property-values span.property-value *{display:block;overflow:hidden;text-wrap:nowrap;text-overflow:ellipsis;flex-shrink:1}#post div.sidebar div.property div.property-values span.property-value ion-icon{font-size:1rem;padding:4px;box-sizing:border-box}#post div.sidebar div.inline{display:flex;gap:1rem}#post div.sidebar div.post-tags{display:flex;flex-direction:column;gap:.2rem}#post div.sidebar div.post-tags div.tag{align-items:center}#post div.sidebar div.post-tags div.tag a.tag-name{word-break:break-word;text-decoration:none}#post div.sidebar div.post-tags div.tag span.tag-post-count{background-color:var(--secondary-color-3);color:var(--secondary-color-8);padding:0 4px;border-radius:var(--border-radius-small);font-size:12px;margin-left:.4rem}route#login{display:flex;justify-content:center;align-items:center;margin-top:5rem}route#login .login-container{padding:2rem;border:1px solid var(--secondary-color-9);border-radius:var(--border-radius-large);display:flex;flex-direction:column;justify-content:center;gap:1rem;max-width:400px;width:100%;box-sizing:border-box}route#login .login-container h1{margin:0}route#login .login-container .input-container{display:flex;flex-direction:column;gap:.5rem}route#login .login-container .input-container input{display:block}:root{--primary-color: #d1d1ee;--primary-color-dark: #9696b3;--primary-color-darker: #72728d;--secondary-color-9: #aeaeec;--secondary-color-8: #9a9ad6;--secondary-color-7: #7c7cb8;--secondary-color-6: #646497;--secondary-color-5: #545486;--secondary-color-4: #424268;--secondary-color-3: #3b3b66;--secondary-color-2: #24243b;--secondary-color-1: #1e1e2c;--secondary-color-0: #07070c;--shadow-color: #09090e50;--border-radius-small: .4rem;--border-radius-medium: .8rem;--border-radius-large: 1.2rem;--nav-height: 50px}html{overflow-x:hidden;font-size:14px}html ::-webkit-scrollbar{background-color:var(--secondary-color-1);width:8px}html ::-webkit-scrollbar-thumb{background-color:#aeaeec;border-radius:2px}body{overflow-x:hidden;background-color:var(--secondary-color-1);color:var(--primary-color);margin:0;font-family:Microsoft Yahei}nav{display:flex;width:100%;height:var(--nav-height);position:fixed;top:0;z-index:100;background-color:color-mix(in srgb,var(--secondary-color-1) 70%,transparent);justify-content:space-between;align-items:center;padding-inline:1rem;box-sizing:border-box;-webkit-backdrop-filter:blur(3px);backdrop-filter:blur(3px)}nav a.title{display:flex;align-items:center;gap:.4rem;text-decoration:none}nav a.title .booru-name{color:var(--secondary-color-9);margin:0}nav a.title .app{display:flex;align-items:center;border-radius:var(--border-radius-small);margin:0;gap:.4rem}nav a.title .app .version{color:var(--secondary-color-1);background-color:var(--secondary-color-9);padding:.2em .4em;border-radius:var(--border-radius-small);font-size:.8rem;font-weight:700}nav a.title .app .app-name{display:none;font-size:1rem;color:var(--secondary-color-9)}nav div.searchbar{padding:.4rem 10%;max-width:500px;background-color:color-mix(in srgb,var(--secondary-color-2) 30%,transparent);border:1px solid var(--primary-color-darker);border-radius:var(--border-radius-small);color:var(--primary-color-dark);transition:.3s all ease;cursor:pointer}nav div.searchbar:hover{color:var(--primary-color)}nav div.buttons{display:flex;align-items:center;gap:1rem}nav div.buttons ion-icon{transition:all .3s ease;border-radius:1rem;padding:.4rem}nav div.buttons ion-icon:hover{background-color:color-mix(in srgb,var(--secondary-color-3) 50%,transparent)}nav div.buttons ion-icon.search{display:none}nav div.buttons div.account{height:2rem;width:2rem;display:flex;justify-content:center;align-items:center;border-radius:2rem;font-weight:bolder;color:var(--secondary-color-9);background-color:var(--secondary-color-4);-webkit-user-select:none;user-select:none;cursor:pointer}@media (max-width: 800px){nav div.searchbar{display:none}nav div.buttons ion-icon.search{display:inline-block}}router{display:block;position:relative}router route{display:block;position:relative;padding-inline:1rem;padding-top:var(--nav-height)}route#posts header{margin-bottom:1rem}route#posts header h2{margin:0}route#posts header div.tags{display:flex;flex-wrap:wrap;gap:.5rem}button{background-color:var(--secondary-color-4);color:var(--secondary-color-9);padding:.8rem 1.2rem;border-radius:1rem;border:none;cursor:pointer}button:hover{background-color:var(--secondary-color-6);color:var(--primary-color)}ion-icon{font-size:24px;color:var(--primary-color);cursor:pointer}ion-icon:hover{color:var(--secondary-color-9)}a{text-decoration:none;color:var(--secondary-color-9)}input{background-color:var(--secondary-color-2);border-radius:var(--border-radius-small);border:1px solid var(--secondary-color-3);font-size:.9rem;padding:.8rem 1.2rem;color:var(--primary-color);outline:none}input:focus{border-color:var(--secondary-color-9)} diff --git a/dist/assets/index-GbkvssuE.css b/dist/assets/index-GbkvssuE.css new file mode 100644 index 0000000..68dd883 --- /dev/null +++ b/dist/assets/index-GbkvssuE.css @@ -0,0 +1 @@ +layout.post-grid{margin-top:.4rem}post-tile{display:block;transition:.3s all ease;position:relative;transition:all .3s ease;border-radius:var(--border-radius-medium);overflow:hidden;-webkit-tap-highlight-color:transparent;-webkit-user-select:none;user-select:none}@media (hover: hover){post-tile:hover{transform:scale(1.02);z-index:1;box-shadow:0 0 10px color-mix(in srgb,var(--secondary-color-1) 50%,transparent)}}post-tile.loading{transition:none}post-tile:active{transform:scale(.95)}post-tile div.video-detail,post-tile div.gif-detail{position:absolute;background-color:var(--secondary-color-3);color:var(--primary-color);bottom:.3rem;right:.3rem;padding:.2em .4em;height:1rem;border-radius:var(--border-radius-small);font-size:12px;display:flex;align-items:center;gap:.2rem;z-index:2}post-tile div.video-detail ion-icon,post-tile div.gif-detail ion-icon{font-size:1.4rem}post-tile div.video-detail ion-icon[name=images-outline],post-tile div.gif-detail ion-icon[name=images-outline]{padding:.1rem;font-size:1rem}post-tile div.video-detail span.duration,post-tile div.gif-detail span.duration{text-transform:uppercase;z-index:2}post-tile a{background-color:transparent;padding:0;border-radius:0}post-tile a img{height:100%;width:100%;vertical-align:top;background-color:var(--secondary-color-1)}post-tile a video{height:100%;width:100%;object-fit:cover;position:absolute;z-index:1}searchbar{display:flex;align-items:center;flex-direction:column;width:100%;z-index:200;position:fixed;height:100%}searchbar div.input-container{margin-top:.4rem;background-color:color-mix(in srgb,var(--secondary-color-2) 100%,transparent);border-radius:var(--border-radius-small);font-size:1rem;width:500px;padding:.4rem;max-width:calc(100% - 2rem);box-sizing:border-box;z-index:201;display:flex;align-items:center;border:1px solid var(--secondary-color-4)}searchbar div.input-container:focus-within{outline:none}searchbar div.input-container tag-input{display:flex;gap:.4rem;width:100%;overflow:hidden;padding-inline:.4rem;box-sizing:border-box;cursor:text}searchbar div.input-container tag-input tag{display:inline-block;padding:.2rem .4rem;background-color:var(--secondary-color-4);color:var(--secondary-color-9);border-radius:var(--border-radius-small);cursor:pointer}searchbar div.input-container ion-icon{font-size:20px;color:var(--secondary-color-4);cursor:pointer}searchbar div.input-container ion-icon:hover{color:var(--secondary-color-9)}searchbar div.selection-list-container{overflow:hidden;border-radius:var(--border-radius-small);background-color:var(--secondary-color-1);z-index:201;max-width:calc(100% - 2rem);width:500px}searchbar div.selection-list-container selection-list{display:block;max-height:40vh;overflow-y:scroll;overflow-x:hidden;position:relative}searchbar div.selection-list-container selection-list::-webkit-scrollbar{width:4px}searchbar div.selection-list-container selection-list selection{display:flex;justify-content:space-between;align-items:center;padding:.4rem 1rem;cursor:pointer;gap:1rem}searchbar div.selection-list-container selection-list selection:hover{background-color:color-mix(in srgb,var(--secondary-color-3) 50%,transparent)}searchbar div.selection-list-container selection-list selection.active{background-color:var(--secondary-color-3)}searchbar div.selection-list-container selection-list selection div.selection-label{display:flex;flex-wrap:wrap;gap:.5rem}searchbar div.selection-list-container selection-list selection div.selection-label .label-container{display:flex;gap:.5rem;align-items:center}searchbar div.selection-list-container selection-list selection div.selection-label .label-container ion-icon{font-size:1rem}searchbar div.selection-list-container selection-list selection div.tag-detail{display:flex;align-items:center;gap:.5rem}searchbar div.selection-list-container selection-list selection div.tag-detail .tag-post-count{font-size:.8rem}searchbar div.selection-list-container selection-list selection .tag-category,searchbar div.selection-list-container selection-list selection .user-level{padding:.1rem .4rem;border-radius:var(--border-radius-small);font-size:.9rem;background-color:var(--secondary-color-4);color:var(--secondary-color-9)}searchbar div.filter{background-color:var(--secondary-color-1);opacity:.5;position:fixed;top:0;height:100%;width:100%;z-index:199}.input-wrapper{color:var(--primary-color);border:1px solid var(--secondary-color-9);border-radius:var(--border-radius-small);position:relative;box-sizing:border-box;line-height:1em;font-size:14px;padding:4px 8px;display:inline-block;max-width:100%;text-overflow:ellipsis}.input-wrapper span.sizer{font-family:inherit;white-space:pre;height:1em;display:inline-block;font-size:inherit;line-height:inherit;box-sizing:border-box;position:relative;opacity:0;min-width:2px;-webkit-user-select:none;user-select:none;vertical-align:top}.input-wrapper input{height:100%;text-overflow:ellipsis;font-family:inherit;background:none;color:inherit;top:0;left:0;font-size:inherit;line-height:inherit;padding:inherit;position:absolute;box-sizing:border-box;width:100%;border:none;outline:none}button.icon{display:flex;justify-content:center;align-items:center;gap:.4rem;padding:.8rem 1.2rem}button.icon ion-icon{font-size:1.4rem;color:inherit}button.icon.vertical{flex-direction:column}drawer{position:fixed;top:0;left:0;display:flex;z-index:300;height:100%;width:100%;box-sizing:border-box;justify-content:end;align-items:center;padding:1rem}drawer div.drawer-container{width:300px;max-width:70%;height:100%;background-color:var(--secondary-color-1);border-radius:var(--border-radius-large);z-index:1;overflow:hidden}drawer div.drawer-container div.user-info{background-color:var(--secondary-color-2);padding:2rem}drawer div.drawer-container div.user-info .username{margin:0;color:var(--secondary-color-9);cursor:pointer}drawer div.drawer-container div.user-info div.user-detail{display:flex;gap:.5rem;margin-top:.2rem}drawer div.drawer-container div.user-info div.user-detail span{font-size:.8rem;color:var(--primary-color-dark);display:block;cursor:pointer}drawer div.drawer-container div.user-info div.user-nav{display:grid;grid-template-columns:1fr 1fr 1fr;gap:1rem;margin-top:1rem}drawer div.drawer-container div.nav{padding:2rem;display:flex;gap:1rem;flex-direction:column}drawer div.filter{position:absolute;top:0;left:0;height:100%;width:100%;background:linear-gradient(90deg,color-mix(in srgb,var(--secondary-color-1) 50%,transparent),color-mix(in srgb,var(--secondary-color-0) 70%,transparent))}#post{padding:0;padding-top:var(--nav-height)}#post section{background-color:#2f2f45;border-radius:var(--border-radius-large);padding:20px}#post div.viewer{height:calc(100vh - 2rem - var(--nav-height));display:flex;justify-content:center;align-items:center;background-color:#000;border-radius:var(--border-radius-large);overflow:hidden;width:calc(100vw - 300px - 4rem);margin:1rem;position:relative}@media (max-width: 800px){#post div.viewer{width:100%;height:calc(100vh - var(--nav-height));border-radius:0;margin:0}}#post div.viewer img{max-width:100%;max-height:100%}#post div.viewer video{max-width:100%;max-height:100%;-webkit-user-drag:none;transition:all .3s ease}#post div.viewer div.viewer-panel{position:absolute;bottom:0;width:100%;z-index:1}#post div.viewer div.viewer-panel div.panel{width:100%;display:flex;justify-content:center;padding:1rem}#post div.viewer div.viewer-panel div.overlay{position:absolute;bottom:0;width:100%;height:200%;z-index:-1;background:linear-gradient(180deg,color-mix(in srgb,var(--secondary-color-1) 0%,transparent),color-mix(in srgb,var(--secondary-color-0) 70%,transparent))}#post div.content{width:calc(100vw - 300px - 2rem);display:flex;flex-direction:column;padding:1rem;box-sizing:border-box}@media (max-width: 800px){#post div.content{width:100%}}#post div.content::-webkit-scrollbar{background-color:#000;width:4px}#post div.content::-webkit-scrollbar-thumb{background-color:#aeaeec;border-radius:2px}#post div.content>h3{padding-left:1rem;margin-block:1rem}#post div.content section.commentary *{text-wrap:wrap;word-break:break-word}#post div.sidebar{--padding: 1rem;position:fixed;top:calc(var(--nav-height) + var(--padding));right:var(--padding);display:flex;flex-direction:column;gap:.4rem;width:300px;overflow:scroll;overflow-x:hidden;height:calc(100vh - 2rem - var(--nav-height));border-radius:var(--border-radius-large)}@media (max-width: 800px){#post div.sidebar{position:static;width:100%;overflow:visible;height:100%;padding:1rem;box-sizing:border-box}}#post div.sidebar::-webkit-scrollbar{background-color:#000;width:0px}#post div.sidebar::-webkit-scrollbar-thumb{background-color:#aeaeec}#post div.sidebar h3{padding-left:1rem;margin-block:.6rem}#post div.sidebar .post-info{background-color:#2f2f45;border-radius:var(--border-radius-large);padding:20px;display:flex;flex-direction:column;gap:.4rem}#post div.sidebar .post-info .buttons{display:grid;grid-template-columns:1fr 1fr 1fr;gap:1rem;margin-top:1rem}#post div.sidebar div.property{display:flex;gap:.6rem;align-items:center;width:100%}#post div.sidebar div.property span.property-name{flex-shrink:0}#post div.sidebar div.property div.property-values{display:flex;gap:.4rem;width:100%;overflow:hidden}#post div.sidebar div.property div.property-values span.property-value{padding:.2rem .4rem;background-color:var(--secondary-color-1);color:var(--primary-color-dark);border-radius:var(--border-radius-small);justify-content:space-between;flex-shrink:1;display:flex;align-items:center;overflow:hidden}#post div.sidebar div.property div.property-values span.property-value:has(ion-icon){flex-shrink:0}#post div.sidebar div.property div.property-values span.property-value *{display:block;overflow:hidden;text-wrap:nowrap;text-overflow:ellipsis;flex-shrink:1}#post div.sidebar div.property div.property-values span.property-value ion-icon{font-size:1rem;padding:4px;box-sizing:border-box}#post div.sidebar div.inline{display:flex;gap:1rem}#post div.sidebar div.post-tags{display:flex;flex-direction:column;gap:.2rem}#post div.sidebar div.post-tags div.tag{align-items:center}#post div.sidebar div.post-tags div.tag a.tag-name{word-break:break-word;text-decoration:none}#post div.sidebar div.post-tags div.tag span.tag-post-count{background-color:var(--secondary-color-3);color:var(--secondary-color-8);padding:0 4px;border-radius:var(--border-radius-small);font-size:12px;margin-left:.4rem}route#login{display:flex;justify-content:center;align-items:center;margin-top:5rem}route#login .login-container{padding:2rem;border:1px solid var(--secondary-color-9);border-radius:var(--border-radius-large);display:flex;flex-direction:column;justify-content:center;gap:1rem;max-width:400px;width:100%;box-sizing:border-box}route#login .login-container h1{margin:0}route#login .login-container .input-container{display:flex;flex-direction:column;gap:.5rem}route#login .login-container .input-container input{display:block}:root{--primary-color: #d1d1ee;--primary-color-dark: #9696b3;--primary-color-darker: #72728d;--secondary-color-9: #aeaeec;--secondary-color-8: #9a9ad6;--secondary-color-7: #7c7cb8;--secondary-color-6: #646497;--secondary-color-5: #545486;--secondary-color-4: #424268;--secondary-color-3: #3b3b66;--secondary-color-2: #24243b;--secondary-color-1: #1e1e2c;--secondary-color-0: #07070c;--shadow-color: #09090e50;--border-radius-small: .4rem;--border-radius-medium: .8rem;--border-radius-large: 1.2rem;--nav-height: 50px}html{overflow-x:hidden;font-size:14px}html ::-webkit-scrollbar{background-color:var(--secondary-color-1);width:8px}html ::-webkit-scrollbar-thumb{background-color:#aeaeec;border-radius:2px}body{overflow-x:hidden;background-color:var(--secondary-color-1);color:var(--primary-color);margin:0;font-family:Microsoft Yahei}nav{display:flex;width:100%;height:var(--nav-height);position:fixed;top:0;z-index:100;background-color:color-mix(in srgb,var(--secondary-color-1) 70%,transparent);justify-content:space-between;align-items:center;padding-inline:1rem;box-sizing:border-box;-webkit-backdrop-filter:blur(3px);backdrop-filter:blur(3px)}nav a.title{display:flex;align-items:center;gap:.4rem;text-decoration:none}nav a.title .booru-name{color:var(--secondary-color-9);margin:0}nav a.title .app{display:flex;align-items:center;border-radius:var(--border-radius-small);margin:0;gap:.4rem}nav a.title .app .version{color:var(--secondary-color-1);background-color:var(--secondary-color-9);padding:.2em .4em;border-radius:var(--border-radius-small);font-size:.8rem;font-weight:700}nav a.title .app .app-name{display:none;font-size:1rem;color:var(--secondary-color-9)}nav div.searchbar{padding:.4rem 10%;max-width:500px;background-color:color-mix(in srgb,var(--secondary-color-2) 30%,transparent);border:1px solid var(--primary-color-darker);border-radius:var(--border-radius-small);color:var(--primary-color-dark);transition:.3s all ease;cursor:pointer}nav div.searchbar:hover{color:var(--primary-color)}nav div.buttons{display:flex;align-items:center;gap:1rem}nav div.buttons ion-icon{transition:all .3s ease;border-radius:1rem;padding:.4rem}nav div.buttons ion-icon:hover{background-color:color-mix(in srgb,var(--secondary-color-3) 50%,transparent)}nav div.buttons ion-icon.search{display:none}nav div.buttons div.account{height:2rem;width:2rem;display:flex;justify-content:center;align-items:center;border-radius:2rem;font-weight:bolder;color:var(--secondary-color-9);background-color:var(--secondary-color-4);-webkit-user-select:none;user-select:none;cursor:pointer}@media (max-width: 800px){nav div.searchbar{display:none}nav div.buttons ion-icon.search{display:inline-block}}router{display:block;position:relative}router route{display:block;position:relative;padding-inline:1rem;padding-top:var(--nav-height)}route#posts header{margin-bottom:1rem}route#posts header h2{margin:0}route#posts header div.tags{display:flex;flex-wrap:wrap;gap:.5rem}button{background-color:var(--secondary-color-4);color:var(--secondary-color-9);padding:.8rem 1.2rem;border-radius:1rem;border:none;cursor:pointer}button:hover{background-color:var(--secondary-color-6);color:var(--primary-color)}ion-icon{font-size:24px;color:var(--primary-color);cursor:pointer}ion-icon:hover{color:var(--secondary-color-9)}a{text-decoration:none;color:var(--secondary-color-9)}input{background-color:var(--secondary-color-2);border-radius:var(--border-radius-small);border:1px solid var(--secondary-color-3);font-size:.9rem;padding:.8rem 1.2rem;color:var(--primary-color);outline:none}input:focus{border-color:var(--secondary-color-9)} diff --git a/dist/index.html b/dist/index.html index f13ca8e..0fae3b6 100644 --- a/dist/index.html +++ b/dist/index.html @@ -16,8 +16,8 @@ gtag('config', 'G-59HBGP98WR'); - - + + diff --git a/package.json b/package.json index d4d69b0..365e9a5 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "danbooru-viewer", "module": "index.ts", "type": "module", - "version": "0.5.1", + "version": "0.6.0", "devDependencies": { "@types/bun": "latest", "vite": "^5.4.8" @@ -13,7 +13,11 @@ "dependencies": { "@elexis/layout": "../elexis-ext/layout", "@elexis/router": "../elexis-ext/router", + "@elysiajs/cors": "^1.1.1", + "@elysiajs/eden": "^1.1.3", + "cheerio": "^1.0.0", "elexis": "../elexis", + "elysia": "^1.1.20", "sass": "^1.77.1" } } \ No newline at end of file diff --git a/server.ts b/server.ts new file mode 100644 index 0000000..e1d6bb0 --- /dev/null +++ b/server.ts @@ -0,0 +1,20 @@ +import cors from "@elysiajs/cors"; +import Elysia from "elysia"; +const app = new Elysia() + .use(cors()) + .get('*', async ({path}) => { + return Bun.file('./dist/index.html') + }) + .get('/assets/*', (res) => { + return Bun.file(`./dist/${res.path}`) + }) + .group('/api', app => { return app + .delete('/favorites/:id', async ({params, query}) => { + const data = await fetch(`${query.origin}/favorites/${params.id}.json?login=${query.login}&api_key=${query.api_key}`, {method: "DELETE"}).then(res => res.ok); + console.debug(data) + return data + }) + }) + .listen(3030); +console.log('Start listening: 3030') +export type Server = typeof app; \ No newline at end of file diff --git a/src/component/IonIcon/$IonIcon.ts b/src/component/IonIcon/$IonIcon.ts index 45f063e..bcd7345 100644 --- a/src/component/IonIcon/$IonIcon.ts +++ b/src/component/IonIcon/$IonIcon.ts @@ -14,4 +14,9 @@ export class $IonIcon extends $Container { this.attribute('size', size); return this; } + + link(url: string, replace = false) { + this.on('click', () => replace ? $.replace(url) : $.open(url)); + return this; + } } \ No newline at end of file diff --git a/src/route/post/$post_route.ts b/src/route/post/$post_route.ts index 394ddec..216a401 100644 --- a/src/route/post/$post_route.ts +++ b/src/route/post/$post_route.ts @@ -5,17 +5,47 @@ import { ArtistCommentary } from "../../structure/Commentary"; import { Booru } from "../../structure/Booru"; import type { $IonIcon } from "../../component/IonIcon/$IonIcon"; import { numberFormat } from "../../modules"; +import { ClientUser } from "../../structure/ClientUser"; export const post_route = $('route').path('/posts/:id').id('post').builder(({$route, params}) => { if (!Number(params.id)) return $('h1').content('404: POST NOT FOUND'); const post = Post.get(Booru.used, +params.id); + const $viewerPanel = + $('div').class('viewer-panel').content([ + $('div').class('panel').content([ + $('ion-icon').name('heart-outline').self($heart => { + ClientUser.events.on('favoriteUpdate', (user) => { + if (user.favorites.has(post.id)) $heart.name('heart'); + else $heart.name('heart-outline'); + }) + if (Booru.used.user?.favorites.has(post.id)) $heart.name('heart'); + }).on('click', () => { + if (Booru.used.user?.favorites.has(post.id)) post.deleteFavorite(); + else post.createFavorite(); + }) + ]), + $('div').class('overlay') + ]).hide(true); return [ $('div').class('viewer').content(async () => { await post.ready; - return post.isVideo + return [ + $viewerPanel, + post.isVideo ? $('video').height(post.image_height).width(post.image_width).src(post.file_ext === 'zip' ? post.large_file_url : post.file_url).controls(true).autoplay(true).loop(true).disablePictureInPicture(true) : $('img').src(post.large_file_url)//.once('load', (e, $img) => { $img.src(post.file_url)}) - }), + ] + }) + .on('pointermove', (e) => { + if (e.pointerType === 'mouse' || e.pointerType === 'pen') $viewerPanel.hide(false); + }) + .on('pointerup', (e) => { + console.debug(e.movementX) + if (e.pointerType === 'touch') $viewerPanel.hide(!$viewerPanel.hide()); + }) + .on('mouseleave', () => { + $viewerPanel.hide(true); + }), $('div').class('content').content([ $('h3').content(`Artist's Commentary`), $('section').class('commentary').content(async ($comentary) => { @@ -45,7 +75,7 @@ export const post_route = $('route').path('/posts/:id').id('post').builder(({$ro new $Property('size').name('Size').content([post.file_size$, post.dimension$]), new $Property('file-type').name('File Type').content(post.file_ext$), $('div').class('inline').content([ - new $Property('favorites').name('Favorites').content(post.favorites$), + new $Property('favorites').name('Favorites').content(post.favcount$), new $Property('score').name('Score').content(post.score$) ]), new $Property('file-url').name('File').content([ diff --git a/src/route/post/_$post_route.scss b/src/route/post/_$post_route.scss index 5880d80..a539463 100644 --- a/src/route/post/_$post_route.scss +++ b/src/route/post/_$post_route.scss @@ -17,6 +17,7 @@ overflow: hidden; width: calc(100vw - 300px - 4rem); margin: 1rem; + position: relative; @media (max-width: 800px) { width: 100%; @@ -37,6 +38,32 @@ -webkit-user-drag: none; transition: all 0.3s ease; } + + div.viewer-panel { + position: absolute; + bottom: 0; + width: 100%; + z-index: 1; + + div.panel { + width: 100%; + display: flex; + justify-content: center; + padding: 1rem; + } + + div.overlay { + position: absolute; + bottom: 0; + width: 100%; + height: 200%; + z-index: -1; + background: linear-gradient(180deg, + color-mix(in srgb, var(--secondary-color-1) 0%, transparent) 0%, + color-mix(in srgb, var(--secondary-color-0) 70%, transparent) 100% + ); + } + } } div.content { diff --git a/src/structure/Booru.ts b/src/structure/Booru.ts index f038c96..427faf8 100644 --- a/src/structure/Booru.ts +++ b/src/structure/Booru.ts @@ -3,6 +3,7 @@ import type { Post } from "./Post"; import type { Tag } from "./Tag"; import { ClientUser, type ClientUserData } from "./ClientUser"; import type { User } from "./User"; +import type { Favorite } from "./Favorite"; export interface BooruOptions { origin: string; @@ -18,6 +19,7 @@ export class Booru { posts = new Map(); tags = new Map(); users = new Map(); + favorites = new Map(); constructor(options: BooruOptions) { Object.assign(this, options); if (this.origin.endsWith('/')) this.origin = this.origin.slice(0, -1); @@ -37,16 +39,20 @@ export class Booru { static get storageAPI() { return localStorage.getItem('booru_api'); } static set storageAPI(name: string | null) { if (name) localStorage.setItem('booru_api', name); else localStorage.removeItem('booru_api') } - async fetch(endpoint: string) { + async fetch(endpoint: string, method: 'GET' | 'POST' | 'PUT' | 'DELETE' = 'GET') { const auth = this.user ? `${endpoint.includes('?') ? '&' : '?'}login=${this.user.name}&api_key=${this.user.apiKey}` : ''; - const data = await fetch(`${this.origin}${endpoint}${auth}`).then(res => res.json()) as any; + const data = await fetch(`${this.origin}${endpoint}${auth}`, { + method: method, + }).then(res => res.json()) as any; if (data.success === false) throw data.message; return data as T; } + async login(username: string, apiKey: string) { const data = await this.fetch(`/profile.json?login=${username}&api_key=${apiKey}`); this.user = new ClientUser(this, apiKey, data); + this.user.init(); Booru.events.fire('login', this.user); return this.user; } diff --git a/src/structure/ClientUser.ts b/src/structure/ClientUser.ts index 5050c96..af9e9bd 100644 --- a/src/structure/ClientUser.ts +++ b/src/structure/ClientUser.ts @@ -1,11 +1,15 @@ +import { $EventManager } from "elexis"; import type { Booru } from "./Booru"; +import { Favorite, type FavoriteData } from "./Favorite"; import { User, type UserData } from "./User"; +import type { Post } from "./Post"; export interface ClientUser extends ClientUserData {} export class ClientUser extends User { apiKey: string; favorite_count$ = $.state(0); forum_post_count$ = $.state(0); + static events = new $EventManager() constructor(booru: Booru, apiKey: string, data: ClientUserData) { super(booru, data, false); this.apiKey = apiKey; @@ -18,6 +22,19 @@ export class ClientUser extends User { this.favorite_count$?.set(this.favorite_count); } + async init() { + await this.fetchFavorites(); + + } + + async fetchFavorites() { + const oldestId = Array.from(this.favorites.keys()).at(-1); + const list = await Favorite.fetchUserFavorites(this.booru, this, ``, 1000, oldestId ? `b${oldestId}` : 1); + ClientUser.events.fire('favoriteUpdate', this); + if (list.length >= 1000) this.fetchFavorites(); + return list; + } + static get storageUserData() { const data = localStorage.getItem('user_data'); return data ? JSON.parse(data) as ClientUserStoreData : null } static set storageUserData(data: ClientUserStoreData | null) { localStorage.setItem('user_data', JSON.stringify(data)) } } @@ -68,4 +85,8 @@ export interface ClientUserData extends UserData { export interface ClientUserStoreData { username: string; apiKey: string; +} + +export interface ClientUserEventMap { + favoriteUpdate: [user: ClientUser] } \ No newline at end of file diff --git a/src/structure/Favorite.ts b/src/structure/Favorite.ts new file mode 100644 index 0000000..6ee65be --- /dev/null +++ b/src/structure/Favorite.ts @@ -0,0 +1,32 @@ +import type { Booru } from "./Booru"; +import type { ClientUser } from "./ClientUser"; +import type { Post } from "./Post"; +import type { User } from "./User"; + +export interface Favorite extends FavoriteData {} +export class Favorite { + booru: Booru; + constructor(booru: Booru, data: FavoriteData) { + Object.assign(this, data); + this.booru = booru; + } + + static async fetchUserFavorites(booru: Booru, user: User, query: string, limit: number = 100, page: number | string) { + const dataArray = await booru.fetch(`/favorites.json?${query}&${`search[user_id]=${user.id}`}&limit=${limit}&page=${page}`); + return dataArray.map(data => { + user.favorites.add(data.post_id); + return data.post_id; + }) + } + + update(data: FavoriteData) { + Object.assign(this, data) + return this; + } +} + +export interface FavoriteData { + id: id; + post_id: id; + user_id: id; +} \ No newline at end of file diff --git a/src/structure/Post.ts b/src/structure/Post.ts index b0e1390..9540759 100644 --- a/src/structure/Post.ts +++ b/src/structure/Post.ts @@ -3,6 +3,8 @@ import { Booru } from "./Booru"; import { Tag } from "./Tag"; import { User } from "./User"; import { dateFrom, digitalUnit } from "./Util"; +import { ClientUser } from "./ClientUser"; +import type { FavoriteData } from "./Favorite"; const LOADING_STRING = '...' @@ -12,7 +14,7 @@ export class Post extends $EventManager<{update: []}> { uploader$ = $.state(LOADING_STRING); approver$ = $.state(LOADING_STRING); created_date$ = $.state(LOADING_STRING); - favorites$ = $.state(0); + favcount$ = $.state(0); score$ = $.state(0); file_size$ = $.state(LOADING_STRING); file_ext$ = $.state(LOADING_STRING); @@ -75,7 +77,7 @@ export class Post extends $EventManager<{update: []}> { this.uploader$.set(this.uploader?.name$ ?? this.uploader_id?.toString()); this.approver$.set(this.approver?.name$ ?? this.approver_id?.toString() ?? 'None'); this.created_date$.set(dateFrom(+new Date(this.created_at))); - this.favorites$.set(this.fav_count); + this.favcount$.set(this.fav_count); this.score$.set(this.score); this.file_size$.set(digitalUnit(this.file_size)); this.file_ext$.set(this.file_ext as any); @@ -99,6 +101,26 @@ export class Post extends $EventManager<{update: []}> { return await Tag.fetchMultiple(this.booru, {name: {_space: this.tag_string}}); } + async createFavorite() { + if (!this.booru.user) return; + const data = await this.booru.fetch(`/favorites.json?post_id=${this.id}`, 'POST') + this.update(data); + this.booru.user.favorites.add(data.id); + ClientUser.events.fire('favoriteUpdate', this.booru.user); + return data.id; + } + + async deleteFavorite() { + if (!this.booru.user) return; + const data = await fetch(`/api/favorites/${this.id}?login=${this.booru.user.name}&api_key=${this.booru.user.apiKey}&origin=${this.booru.origin}`, {method: 'DELETE'}).then(res => res.json()) as boolean; + if (data === false) return; + this.fav_count--; + this.favcount$.set(this.fav_count); + this.booru.user.favorites.delete(this.id); + ClientUser.events.fire('favoriteUpdate', this.booru.user); + return; + } + get pathname() { return `/posts/${this.id}` } get uploader() { return this.booru.users.get(this.uploader_id); } get approver() { if (this.approver_id) return this.booru.users.get(this.approver_id); else return null } diff --git a/src/structure/User.ts b/src/structure/User.ts index 36a134c..1c79bd9 100644 --- a/src/structure/User.ts +++ b/src/structure/User.ts @@ -8,6 +8,7 @@ export class User { level$ = $.state(10); level_string$ = $.state('...'); booru: Booru; + favorites = new Set(); constructor(booru: Booru, data: UserData, update$: boolean = true) { this.booru = booru; Object.assign(this, data); diff --git a/vite.config.ts b/vite.config.ts index f0b2a75..f7f7048 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,5 +1,13 @@ import { defineConfig } from 'vite'; export default defineConfig({ + server: { + proxy: { + '/api': { + target: 'http://localhost:3030', + changeOrigin: true + }, + } + }, define: { __APP_VERSION__: JSON.stringify(process.env.npm_package_version) }