初始化项目

master
yutent 2023-12-19 15:30:29 +08:00
commit 67bbe59f5c
52 changed files with 818 additions and 0 deletions

15
.gitignore vendored Normal file
View File

@ -0,0 +1,15 @@
node_modules
*.sublime-project
*.sublime-workspace
package-lock.json
._*
.Spotlight-V100
.Trashes
.DS_Store
.AppleDouble
.LSOverride

5
.httpserver Normal file
View File

@ -0,0 +1,5 @@
{
"enabled": true,
"port": 9090,
"root": "./dist"
}

11
.prettierrc.yaml Normal file
View File

@ -0,0 +1,11 @@
jsxBracketSameLine: true
jsxSingleQuote: true
semi: false
singleQuote: true
printWidth: 80
useTabs: false
tabWidth: 2
trailingComma: none
bracketSpacing: true
arrowParens: avoid

68
dist/app.js vendored Normal file
View File

@ -0,0 +1,68 @@
/**
* {}
* @author yutent<yutent.io@gmail.com>
* @date 2023/11/14 18:52:57
*/
import { createApp } from 'wkitd'
import { css, html } from 'wkit'
import 'es.shim'
import '@ui/base/button.js'
import '@ui/base/link.js'
import '@ui/form/input.js'
import '@ui/form/switch.js'
import '@ui/modal/layer.js'
import '@ui/nav/pager.js'
import router from './router.js'
import store from './store.js'
import fetch from '/lib/fetch.js'
import './components/header.js'
import './components/footer.js'
const app = createApp({
render() {
return html`
<wc-header></wc-header>
<div class="main-body"><router-view></router-view></div>
<wc-footer></wc-footer>
`
},
styles: css`
:host {
display: flex;
flex-direction: column;
width: 100%;
min-height: 100vh;
}
.main-body {
flex: 1;
}
`,
mounted() {
var user = localStorage.getItem('user')
var checked = sessionStorage.getItem('session_checked')
if (user) {
if (checked) {
return (this.$store.user = JSON.parse(user))
}
fetch('/login/check')
.then(r => {
localStorage.setItem('token', r.data.token)
sessionStorage.setItem('session_checked', 1)
this.$store.user = JSON.parse(user)
})
.catch(r => {
localStorage.removeItem('token')
localStorage.removeItem('user')
})
}
}
})
app.use(router).use(store).mount('.app')

0
dist/components/footer.js vendored Normal file
View File

0
dist/components/header.js vendored Normal file
View File

27
dist/index.html vendored Normal file
View File

@ -0,0 +1,27 @@
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
<title>Linux 在线应用商店</title>
<meta name="keywords" content="Linux 在线应用商店">
<meta name="description" content="Linux 在线应用商店">
<link rel="stylesheet" href="/lib/ui/css/reset-basic.css">
<link rel="stylesheet" href="/assets/app.css">
<script async src="//jscdn.ink/es-module-shims/1.6.3/es-module-shims.wasm.js"></script>
<script type="importmap">{
"imports":{
"es.shim": "//jscdn.ink/es.shim/2.1.0/index.js",
"fetch": "//jscdn.ink/@bytedo/fetch/latest/next.js",
"wkit": "//jscdn.ink/wkit/latest/index.js",
"wkitd": "//jscdn.ink/wkitd/latest/index.js",
"@ui/": "/lib/ui/"
}
}</script>
<script type="module" src="/app.js"></script>
</head>
<body>
<wc-app></wc-app>
</body>
</html>

8
dist/lib/fetch.js vendored Normal file
View File

@ -0,0 +1,8 @@
/**
* {}
* @author yutent<yutent.io@gmail.com>
* @date 2023/12/19 15:27:51
*/
import fetch from 'fetch'
export default fetch

6
dist/lib/ui/base/button.js vendored Normal file

File diff suppressed because one or more lines are too long

1
dist/lib/ui/base/fs.js vendored Normal file
View File

@ -0,0 +1 @@
function p(e){let r=e.slice(0,64),t=e.slice(-64);return Promise.all([r.arrayBuffer(),t.arrayBuffer()]).then(([n,i])=>{let l=new Uint8Array(n),a=new Uint8Array(i),o=new Uint8Array(l.length+a.length);return o.set(l),o.set(a,l.length),o})}function c(e,r){return fetch(e).then(t=>t.blob()).then(t=>URL.createObjectURL(r?new Blob([t],{type:r}):t))}function u(e){return e<1024?`${e} B`:(e=(e/1024).toFixed(2)-0,e<1024?`${e} KB`:(e=(e/1024).toFixed(2)-0,`${e} MB`))}async function y(e){return new Uint8Array(await e.arrayBuffer())}function s(e,r){let t=e.split("/"),n=r.split("/");for(t.at(-1)===""&&t.pop();n.length;){let i=n.shift();i==="."||i===""||(i===".."?t.pop():t.push(i))}return t.join("/")}function h(e){return e.split("/").pop()}async function f(e,r=""){let t=s(r,e.name);if(e.kind==="directory"){let n=await e.entries(),i,l=[];for(;(i=await n.next())&&!i.done;){let a=i.value[1];a.kind==="directory"?l=l.concat(await f(a,t)):l.push({key:s(t,a.name),file:await a.getFile()})}return l}else return{key:t,file:await e.getFile()}}async function w(e){return Promise.all([...e].map(r=>r.getAsFileSystemHandle())).then(async r=>{let t=[];for(let n of r)t=t.concat(await f(n));return t})}export{h as filename,p as getFingerprint,s as join,u as parseSize,w as resolveFiles,c as toBlobURL,y as toUint8};

5
dist/lib/ui/base/icon.js vendored Normal file
View File

@ -0,0 +1,5 @@
import{css as o,svg as t,html as r,Component as a,classMap as n}from"wkit";import l from"./svg-path.js";let e=l;window.EXT_SVG_DICT&&Object.assign(e,EXT_SVG_DICT);var p={extend(s={}){Object.assign(e,s)}};class c extends a{static props={name:{type:String,default:null,observer(i){i===""&&(this.name=null)}}};static styles=o`:host{display:inline-flex;width:var(--wc-icon-size, 32px);height:var(--wc-icon-size, 32px)}:host(:not([name])){display:none}.svg{display:block;width:100%;height:100%;color:inherit;fill:currentColor}.svg circle{stroke:currentColor;animation:circle 1.5s ease-in-out infinite}:host([name=loading]) svg{animation:load 1.5s linear infinite}:host([size=small]){width:24px;height:24px}@keyframes circle{0%{stroke-dasharray:0,3812px;stroke-dashoffset:0}50%{stroke-dasharray:1906px,3812px;stroke-dashoffset:-287px}100%{stroke-dasharray:1906px,3812px;stroke-dashoffset:-2393px}}@keyframes load{to{transform:rotate(360deg)}}`;render(){return r`
<svg class=${n({svg:!0})} viewBox="0 0 1024 1024">
${this.name==="loading"?t`<circle cx="512" cy="512" r="384" fill="none" stroke-width="80" />`:t`<path d="${e[this.name]}" />`}
</svg>
`}}c.reg("icon");export{p as default};

5
dist/lib/ui/base/link.js vendored Normal file
View File

@ -0,0 +1,5 @@
import{css as r,html as s,Component as i,bind as n,nextTick as l}from"wkit";class c extends i{static props={to:"",autofocus:!1,disabled:!1,lazy:0};static styles=[r`:host{position:relative;display:inline-flex;border-radius:2px;font-size:inherit;cursor:pointer;transition:box-shadow .15s linear}:host .link{display:flex;justify-content:center;align-items:center;width:100%;padding:var(--wc-link-padding, 0 2px);line-height:1;color:inherit;cursor:inherit;outline:none;text-decoration:none;transition:color .15s linear;-webkit-user-select:none;user-select:none}:host .link::-moz-focus-inner{border:none}:host::after{position:absolute;bottom:-2px;left:0;width:100%;height:1px;border-bottom:1px dashed var(--color-grey-1);content:"";opacity:0;transition:opacity .15s linear}`,r`:host([type=primary]){color:var(--color-teal-2)}:host([type=primary])::after{border-color:var(--color-teal-1)}:host([type=primary]:not([disabled]):hover){color:var(--color-teal-1)}:host([type=primary]:not([disabled]):active){color:var(--color-teal-3)}:host([type=primary]:not([disabled]):focus-within){box-shadow:0 0 0 2px var(--color-teal-a)}:host([type=info]){color:var(--color-blue-2)}:host([type=info])::after{border-color:var(--color-blue-1)}:host([type=info]:not([disabled]):hover){color:var(--color-blue-1)}:host([type=info]:not([disabled]):active){color:var(--color-blue-3)}:host([type=info]:not([disabled]):focus-within){box-shadow:0 0 0 2px var(--color-blue-a)}:host([type=success]){color:var(--color-green-2)}:host([type=success])::after{border-color:var(--color-green-1)}:host([type=success]:not([disabled]):hover){color:var(--color-green-1)}:host([type=success]:not([disabled]):active){color:var(--color-green-3)}:host([type=success]:not([disabled]):focus-within){box-shadow:0 0 0 2px var(--color-green-a)}:host([type=warning]){color:var(--color-orange-2)}:host([type=warning])::after{border-color:var(--color-orange-1)}:host([type=warning]:not([disabled]):hover){color:var(--color-orange-1)}:host([type=warning]:not([disabled]):active){color:var(--color-orange-3)}:host([type=warning]:not([disabled]):focus-within){box-shadow:0 0 0 2px var(--color-orange-a)}:host([type=danger]){color:var(--color-red-2)}:host([type=danger])::after{border-color:var(--color-red-1)}:host([type=danger]:not([disabled]):hover){color:var(--color-red-1)}:host([type=danger]:not([disabled]):active){color:var(--color-red-3)}:host([type=danger]:not([disabled]):focus-within){box-shadow:0 0 0 2px var(--color-red-a)}`,r`:host(:not([disabled]):hover)::after,:host([underline])::after{opacity:1}:host([disabled]){cursor:not-allowed;opacity:.6}`];#o(o){o.preventDefault(),o.stopPropagation()}mounted(){this.stamp=0,this.autofocus&&l(o=>this.$refs.a.focus()),n(this.$refs.a,"click",o=>{let{disabled:a,lazy:t}=this,e=Date.now();if(a)return this.#o(o);if(t>0&&e-this.stamp<t)return this.#o(o);this.stamp=e},!0)}render(){return s`
<a tabindex="0" ref="a" class="link" href=${this.to||"javascript:;"}>
<slot></slot>
</a>
`}}c.reg("link");

1
dist/lib/ui/base/space.js vendored Normal file
View File

@ -0,0 +1 @@
import{css as e,html as a,Component as t}from"wkit";class s extends t{static styles=e`:host{display:block}.container{--gaps: var(--wc-space-gap, 12px);display:flex;flex-wrap:wrap;align-items:center;width:100%;padding:calc(var(--gaps)/2) 0;gap:var(--gaps)}:host([vertical]) .container{flex-direction:column}:host([justify]) .container{justify-content:space-between}`;render(){return a`<div class="container"><slot></slot></div>`}}s.reg("space");

1
dist/lib/ui/base/svg-path.js vendored Normal file

File diff suppressed because one or more lines are too long

86
dist/lib/ui/css/reset-basic.css vendored Normal file
View File

@ -0,0 +1,86 @@
@charset "UTF-8";
/**
*
* @authors yutent (yutent.io@gmail.com)
* @date 2014-10-10 00:45:09
*
* CSS
*
* ,
*
*
* 1 display float position overflow z-index /
* 2 width height margin padding border
* 3 line-height font-size vertical-align text-align user-select outline ....
* 4 color background opacity cursor ...
* 5 content list-style quotes ...
*
*/
* {margin: 0;padding: 0;vertical-align: baseline;box-sizing: border-box;}
::before, ::after {box-sizing: border-box;}
/* HTML5 display-role reset for older browsers */
article,aside,details,figcaption,figure,footer,header,hgroup,menu,nav,section,content {display: block;}
img {border: 0;display: inline-block;}
ol,ul {list-style: none;}
blockquote, q {quotes: none;}
blockquote::before, blockquote::after, q::before, q::after {content: '';content: none;}
table {border-collapse: collapse;border-spacing: 0;}
a:focus,input,textarea,button:focus,input:focus,textarea:focus {outline: none;}
::-moz-focus-inner {border: none;outline: none;}
body {font-family: 'Helvetica Neue', Arial, 'WenQuanYi Micro Hei', 'PingFang SC', 'Hiragino Sans GB', 'Segoe UI', 'Microsoft Yahei', sans-serif;-webkit-font-smoothing: antialiased;text-size-adjust: 100%;-webkit-tap-highlight-color: transparent;}
code, pre, samp {font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;white-space:pre-wrap;}
.noselect {-webkit-touch-callout: none;-webkit-user-select: none;-moz-user-select: none;user-select: none;}
.noselect img, .noselect a {-webkit-user-drag: none;}
.text-ell {overflow: hidden;white-space: nowrap;text-overflow: ellipsis;}
.text-thin {-webkit-font-smoothing: antialiased;-moz-osx-font-smoothing: grayscale;}
:root {
/* primary */
--color-teal-a: rgba(72, 201, 176, 0.35);
--color-teal-1: rgb(72, 201, 176);
--color-teal-2: rgb(26, 188, 156);
--color-teal-3: rgb(22, 160, 133);
/* success */
--color-green-a: rgba(70, 221, 126, 0.35);
--color-green-1: rgb(70, 221, 126);
--color-green-2: rgb(47, 208, 105);
--color-green-3: rgb(26, 196, 88);
/* info */
--color-blue-a: rgba(100, 181, 246, 0.35);
--color-blue-1: rgb(100, 181, 246);
--color-blue-2: rgb(66, 165, 245);
--color-blue-3: rgb(33, 150, 243);
/* danger */
--color-red-a: rgba(252, 118, 97, 0.35);
--color-red-1: #fc7661;
--color-red-2: #ff5f45;
--color-red-3: #f33e22;
/* warning */
--color-orange-a: rgba(254, 174, 117, 0.35);
--color-orange-1: #feae75;
--color-orange-2: #fd964b;
--color-orange-3: #f97316;
/* default1 */
--color-plain-a: rgba(150, 204, 248, 0.35);
--color-plain-1: rgb(242, 245, 252);
--color-plain-2: rgb(232, 235, 244);
--color-plain-3: rgb(218, 225, 233);
/* default2 */
--color-grey-a: rgba(206, 214, 224, 0.35);
--color-grey-1: rgb(206, 214, 224);
--color-grey-2: rgb(164, 176, 190);
--color-grey-3: rgb(134, 144, 155);
/* inverse */
--color-dark-a: rgba(100, 116, 139, 0.35);
--color-dark-1: #64748B;
--color-dark-2: #475569;
--color-dark-3: #2c3441;
--color-drag-background: #fdf6ec;
--color-readonly-background: #f7f8fb;
--color-disabled-background: #fef0f0;
}

8
dist/lib/ui/form/checkbox.js vendored Normal file
View File

@ -0,0 +1,8 @@
import{css as t,html as a,Component as s}from"wkit";import"../base/icon.js";class i extends s{static props={value:{type:Array,default:[],observer(){this.#e()}},disabled:!1,readonly:!1};static styles=t`:host{display:inline-flex;flex-wrap:wrap;align-items:center}`;mounted(){this.$on("child-change",o=>{o.stopPropagation();let e=this.value.indexOf(o.value);e>-1?this.value.splice(e,1):this.value.push(o.value),this.$emit("input",{data:this.value}),this.$emit("change",{data:this.value})}),this.#e(!0)}#e(o){Array.from(this.children).forEach(e=>{e.tagName==="WC-CHECKBOX"?e.root&&(o&&(e.disabled=this.disabled,e.readOnly=this.readOnly),e.checked=this.value.includes(e.value)):e.remove()})}}class l extends s{static props={value:"str!",checked:!1,disabled:!1,readonly:!1};static styles=[t`:host{display:inline-flex;height:32px;cursor:pointer}:host label{display:flex;align-items:center;padding-right:16px;line-height:1;font-size:14px;white-space:nowrap;color:var(--color-dark-1);cursor:inherit;outline:none;-webkit-user-select:none;user-select:none}:host .dot{display:flex;justify-content:center;align-items:center;width:14px;height:14px;margin-right:4px;border:1px solid var(--color-dark-1);border-radius:4px;background:#fff;transition:box-shadow .15s linear}:host .dot wc-icon{display:block;visibility:hidden;width:10px;height:10px;transform:scale(0);transition:transform .15s linear}:host:host([checked]) .dot wc-icon{visibility:visible;transform:scale(1)}`,t`:host(:focus-within) .dot{box-shadow:0 0 0 2px var(--color-plain-a)}`,t`:host([size=small]){height:24px}:host([size=small]) .dot{width:12px;height:12px}`,t`:host([type=primary]) label{color:var(--color-teal-2)}:host([type=primary]) .dot{border-color:var(--color-teal-2)}:host([type=primary]):host(:focus-within) .dot{box-shadow:0 0 0 2px var(--color-teal-a)}:host([type=info]) label{color:var(--color-blue-2)}:host([type=info]) .dot{border-color:var(--color-blue-2)}:host([type=info]):host(:focus-within) .dot{box-shadow:0 0 0 2px var(--color-blue-a)}:host([type=success]) label{color:var(--color-green-2)}:host([type=success]) .dot{border-color:var(--color-green-2)}:host([type=success]):host(:focus-within) .dot{box-shadow:0 0 0 2px var(--color-green-a)}:host([type=warning]) label{color:var(--color-orange-2)}:host([type=warning]) .dot{border-color:var(--color-orange-2)}:host([type=warning]):host(:focus-within) .dot{box-shadow:0 0 0 2px var(--color-orange-a)}:host([type=danger]) label{color:var(--color-red-2)}:host([type=danger]) .dot{border-color:var(--color-red-2)}:host([type=danger]):host(:focus-within) .dot{box-shadow:0 0 0 2px var(--color-red-a)}`,t`:host([readonly]),:host([disabled]){opacity:.6}:host([disabled]){cursor:not-allowed}`];#e(o){if(this.disabled||this.readOnly)return;o.stopPropagation(),this.checked=!this.checked;let e={value:this.value,checked:this.checked};this.inGroup?this.parentNode.$emit("child-change",e):(this.$emit("input",e),this.$emit("change",e))}#o(o){(o.type==="click"||o.keyCode===32)&&this.#e(o)}mounted(){this.parentNode?.tagName==="WC-CHECKBOX-GROUP"&&(this.inGroup=!0)}render(){return a`<label
tabindex=${this.disabled||this.readOnly?"none":0}
@click=${this.#o}
@keydown=${this.#o}
>
<span class="dot"><wc-icon name="get"></wc-icon></span>
<slot></slot>
</label>`}}i.reg("checkbox-group"),l.reg("checkbox");

35
dist/lib/ui/form/input.js vendored Normal file
View File

@ -0,0 +1,35 @@
import{nextTick as r,css as l,html as s,Component as a,classMap as h,outsideClick as c}from"wkit";import"../base/icon.js";const d={duration:100,custom:[{transform:"scaleY(0)",opacity:0},{transform:"scaleY(1)",opacity:1}]};class u extends a{static props={readOnly:!1,autofocus:!1,disabled:!1,clearable:!1,icon:"",placeholder:"",maxlength:{type:Number,default:null},minlength:{type:Number,default:null},value:"str!",lazy:"num!0"};#t=[];#e=-1;#i=!1;#s=0;static styles=[l`:host{position:relative;display:inline-flex;min-width:188px;height:32px;user-select:none;-moz-user-select:none;color:var(--color-dark-1);border-radius:3px;cursor:text;transition:box-shadow .15s linear}.label{flex:1;display:flex;justify-content:center;align-items:center;height:100%;font-size:14px;border:1px solid var(--wc-input-border-color, var(--color-grey-2));border-radius:inherit;background:var(--bg-color, #fff);color:inherit;cursor:inherit}.label input{flex:1;min-width:36px;width:0;height:100%;padding:0 8px;line-height:1;border:0;border-radius:inherit;font:inherit;color:inherit;background:none;outline:none;box-shadow:none;cursor:inherit}.label input::placeholder{color:var(--color-grey-1)}.label .close{--wc-icon-size: 18px;margin:0 8px 0 4px;padding:4px;border-radius:50%;color:var(--color-grey-2);cursor:pointer;transition:background .15s linear}.label .close:hover{background:var(--color-plain-1)}.label .icon{--wc-icon-size: 16px;margin:0 8px 0 4px;color:var(--color-grey-2)}.suggestion{overflow:hidden;position:absolute;z-index:1;left:0;top:calc(100% + 4px);width:100%;padding:4px 0;border-radius:4px;box-shadow:0 2px 5px rgba(0,0,0,.15);transform-origin:top}.suggestion .list{width:100%;background:#fff}.suggestion.hide{display:none}.suggestion li{overflow:hidden;width:100%;height:30px;line-height:30px;padding:0 8px;text-overflow:ellipsis;white-space:nowrap;cursor:pointer}.suggestion li:hover,.suggestion li[focus]{background:var(--color-plain-2)}:host([round]){border-radius:26px}:host([round]) .label input{padding:0 10px}:host(:focus-within){box-shadow:0 0 0 2px var(--color-plain-a)}:host([disabled]){pointer-events:none;cursor:not-allowed}:host([disabled]) .label{border-color:var(--color-grey-1);background:var(--color-plain-1);opacity:.6}:host([readonly]){cursor:default}`,l`:host([size=m]){min-width:128px;height:24px;font-size:12px}:host([size=m]) .label{height:24px;font-size:12px}:host([size=m]) .icon{--wc-icon-size: 12px}:host([size=m][circle]){width:24px;height:24px}:host([size=xl]){min-width:224px;height:36px;font-size:14px}:host([size=xl]) .label{height:36px;font-size:14px}:host([size=xl]) .icon{--wc-icon-size: 14px}:host([size=xl][circle]){width:36px;height:36px}:host([size=xxl]){min-width:288px;height:44px;font-size:14px}:host([size=xxl]) .label{height:44px;font-size:14px}:host([size=xxl]) .icon{--wc-icon-size: 14px}:host([size=xxl][circle]){width:44px;height:44px}`];renderClear(){return s`<wc-icon class="close" name="close" @click=${this.clear} />`}render(){let e=h({suggestion:!0,hide:!this.#t.length});return s`
<div class="label">
<slot name="prepend">
<wc-icon class="icon" name=${this.icon}></wc-icon>
</slot>
<input
ref="input"
@input=${this.handleInput}
@change=${this.handleChange}
@keydown=${this.handleKeyDown}
@focus=${this.handleFocus}
placeholder=${this.placeholder}
maxlength=${this.maxlength}
minlength=${this.minlength}
disabled=${this.disabled}
readonly=${this.readOnly}
autofocus=${this.autofocus}
:value=${this.value}
/>
${this.clearable&&this.value?this.renderClear():""}
<slot name="append"></slot>
<div class=${e} ref="suggestion" #animation=${d}>
<div ref="scroller" class="scroller">
<ul class="list" @click=${this.handleClickItem} ref="list">
${this.#t.map((t,i)=>s`<li
focus=${this.#e===i?!0:null}
index=${i}
>
${t.value}
</li>`)}
</ul>
</div>
</div>
</div>
`}handleInput(e){let{lazy:t}=this;this.value=e.currentTarget.value,!(t&&Date.now()-this.#s<t)&&(this.#s=Date.now(),this.emitFetchSuggest())}handleClickItem(e){let t=e.target.getAttribute("index");this.#e=t,this.emitSelect()}clear(){this.$refs.input.value="",this.value="",this.$emit("change"),this.$emit("input")}handleChange(){this.$emit("change")}handleKeyDown(e){let{lazy:t,minlength:i,value:o}=this;if(e.keyCode===13)return e.preventDefault(),this.#e>-1&&this.#i?this.emitSelect():t&&Date.now()-this.#s<t||(this.#s=Date.now(),i&&o.length<i)?void 0:this.$emit("submit");if(e.keyCode===38||e.keyCode===40){e.preventDefault();let n=e.keyCode===38?-1:1;this.#e+=n,this.#e<0&&(this.#e=0),this.#e>this.#t.length-1&&(this.#e=this.#t.length-1),this.$requestUpdate()}}emitSelect(){let e=this.#t[this.#e];this.value=e.value,this.$refs.suggestion.$animate(!0),this.#i=!1,this.$requestUpdate(),this.$emit("change"),this.$emit("input"),this.$emit("select",{index:this.#e,value:e})}emitFetchSuggest(){this.$emit("fetch-suggest",{value:this.value,send:e=>{this.#t=e.slice(0,10),this.#e=-1,this.$requestUpdate()}})}handleFocus(){this.#i||(this.#i=!0,this.$refs.suggestion.$animate())}mounted(){this.autofocus&&r(e=>this.$refs.input.focus()),c(this,()=>{this.#i=!1,this.$refs.suggestion.$animate(!0)})}}u.reg("input");

8
dist/lib/ui/form/radio.js vendored Normal file
View File

@ -0,0 +1,8 @@
import{css as t,html as s,Component as r}from"wkit";class i extends r{static props={value:{type:String,default:"",attribute:!1,observer(){this.#o()}},disabled:!1,readonly:!1};static styles=t`:host{display:inline-flex;flex-wrap:wrap;align-items:center}`;mounted(){this.$on("child-change",o=>{o.stopPropagation(),this.value=o.value,this.$emit("input",{data:o.value}),this.$emit("change",{data:o.value})}),this.#o(!0)}#o(o){Array.from(this.children).forEach(e=>{e.tagName==="WC-RADIO"?e.root&&(o&&(e.disabled=this.disabled,e.readOnly=this.readOnly),e.value===this.value?e.checked=!0:e.checked=!1):e.remove()})}}class l extends r{static props={value:"str!",checked:!1,disabled:!1,readOnly:!1};static styles=[t`:host{display:inline-flex;height:32px;cursor:pointer}:host label{display:flex;align-items:center;padding-right:16px;line-height:1;white-space:nowrap;align-items:center;font-size:14px;cursor:inherit;outline:none;color:var(--color-dark-1);-webkit-user-select:none;user-select:none}:host .dot{display:flex;justify-content:center;align-items:center;width:14px;height:14px;margin-right:4px;border:1px solid var(--color-grey-2);border-radius:50%;background:#fff;transition:box-shadow .15s linear}:host .dot::after{display:block;visibility:hidden;width:6px;height:6px;border-radius:50%;background:var(--color-dark-1);content:"";transform:scale(0);transition:transform .15s linear}:host:host([checked]) .dot::after{visibility:visible;transform:scale(1)}`,t`:host(:focus-within) .dot{box-shadow:0 0 0 2px var(--color-plain-a)}`,t`:host([size=small]){height:24px}:host([size=small]) .dot{width:12px;height:12px}:host([size=small]) .dot::after{width:6px;height:6px}`,t`:host([type=primary]) label{color:var(--color-teal-2)}:host([type=primary]) .dot{border-color:var(--color-teal-2)}:host([type=primary]) .dot::after{background:var(--color-teal-2)}:host([type=primary]):host(:focus-within) .dot{box-shadow:0 0 0 2px var(--color-teal-a)}:host([type=info]) label{color:var(--color-blue-2)}:host([type=info]) .dot{border-color:var(--color-blue-2)}:host([type=info]) .dot::after{background:var(--color-blue-2)}:host([type=info]):host(:focus-within) .dot{box-shadow:0 0 0 2px var(--color-blue-a)}:host([type=success]) label{color:var(--color-green-2)}:host([type=success]) .dot{border-color:var(--color-green-2)}:host([type=success]) .dot::after{background:var(--color-green-2)}:host([type=success]):host(:focus-within) .dot{box-shadow:0 0 0 2px var(--color-green-a)}:host([type=warning]) label{color:var(--color-orange-2)}:host([type=warning]) .dot{border-color:var(--color-orange-2)}:host([type=warning]) .dot::after{background:var(--color-orange-2)}:host([type=warning]):host(:focus-within) .dot{box-shadow:0 0 0 2px var(--color-orange-a)}:host([type=danger]) label{color:var(--color-red-2)}:host([type=danger]) .dot{border-color:var(--color-red-2)}:host([type=danger]) .dot::after{background:var(--color-red-2)}:host([type=danger]):host(:focus-within) .dot{box-shadow:0 0 0 2px var(--color-red-a)}`,t`:host([readonly]),:host([disabled]){opacity:.6}:host([disabled]){cursor:not-allowed}`];#o(o){this.disabled||this.readOnly||this.checked||(o.stopPropagation(),this.checked=!0,this.inGroup?this.parentNode.$emit("child-change",{value:this.value}):(this.$emit("input"),this.$emit("change")))}#e(o){(o.type==="click"||o.keyCode===32)&&this.#o(o)}mounted(){this.parentNode?.tagName==="WC-RADIO-GROUP"&&(this.inGroup=!0)}render(){return s`<label
tabindex=${this.disabled||this.readOnly?"none":0}
@click=${this.#e}
@keydown=${this.#e}
>
<span class="dot"></span>
<slot></slot>
</label>`}}i.reg("radio-group"),l.reg("radio");

15
dist/lib/ui/form/star.js vendored Normal file
View File

@ -0,0 +1,15 @@
import{css as l,html as r,Component as o}from"wkit";import"../base/icon.js";class h extends o{static props={value:"num!0",text:[],allowHalf:!1,showValue:!1,disabled:!1,clearable:!1};static styles=[l`:host{display:flex;font-size:14px;cursor:pointer;-webkit-user-select:none;user-select:none}main{display:flex;align-items:center;line-height:1;cursor:inherit}main wc-icon{--wc-icon-size: var(--wc-star-size, 32px);margin:0 3px;transition:transform .15s linear,color .15s linear}main wc-icon[name=star]{color:var(--color-plain-3)}main wc-icon:nth-child(1)[name=star-full],main wc-icon:nth-child(1)[name=star-half]{color:var(--wc-star-active-1, var(--color-teal-1))}main wc-icon:nth-child(2)[name=star-full],main wc-icon:nth-child(2)[name=star-half]{color:var(--wc-star-active-2, var(--color-teal-1))}main wc-icon:nth-child(3)[name=star-full],main wc-icon:nth-child(3)[name=star-half]{color:var(--wc-star-active-3, var(--color-teal-1))}main wc-icon:nth-child(4)[name=star-full],main wc-icon:nth-child(4)[name=star-half]{color:var(--wc-star-active-4, var(--color-teal-1))}main wc-icon:nth-child(5)[name=star-full],main wc-icon:nth-child(5)[name=star-half]{color:var(--wc-star-active-5, var(--color-teal-1))}main wc-icon:hover{transform:scale(1.05)}main span{padding:2px 8px 0;margin:0 6px;color:var(--color-dark-1)}`,l`:host([size=small]){--wc-star-size: 24px;font-size:12px}`,l`:host([disabled]){cursor:not-allowed;opacity:.6}`];#i=32;#t={i:0,f:0};#a=[];#e(a,t=0){let i="star-half",e=this.value,s=this.#t;a===-1?(a=Math.floor(e),t=+(e%1).toFixed(1),a>0&&a===e&&(a--,t=1)):t=t<.5?.5:1,this.allowHalf||(t=t>0?1:0),!(a===s.i&&t===s.f)&&(t>.5&&(i="star-full"),this.#a.forEach((n,c)=>{n.name=c<a?"star-full":"star"}),t>0&&(this.#a[a].name=i),this.#t={i:a,f:t})}#l(a){if(!this.disabled&&a.target.tagName==="WC-ICON"){let t=+a.target.dataset.idx;this.#e(t,+(a.offsetX/this.#i).toFixed(1))}}#s(){this.disabled||this.#e(-1)}#n(a){let t=this.#t;this.disabled||a.target.tagName==="WC-ICON"&&(this.clearable&&this.value===t.i+t.f?(t.i=0,t.f=0,this.value=0,this.#a.forEach(i=>(i.name="star",i.style.color=""))):this.value=t.i+t.f,this.$emit("input",{value:this.value}),this.$emit("change",{value:this.value}))}mounted(){this.#a=[...this.$refs.box.children],this.#i=this.#a[0].clientWidth}render(){let a=this.value;return this.text.length===5?a=this.text[Math.ceil(a)-1]:a=a||"",r`
<main
ref="box"
@mousemove=${this.#l}
@mouseleave=${this.#s}
@click=${this.#n}
>
<wc-icon data-idx="0" name="star"></wc-icon>
<wc-icon data-idx="1" name="star"></wc-icon>
<wc-icon data-idx="2" name="star"></wc-icon>
<wc-icon data-idx="3" name="star"></wc-icon>
<wc-icon data-idx="4" name="star"></wc-icon>
<span class="text">${this.showValue?a:""}</span>
</main>
`}}h.reg("star");

12
dist/lib/ui/form/switch.js vendored Normal file
View File

@ -0,0 +1,12 @@
import{css as e,html as i,Component as o,classMap as a}from"wkit";class n extends o{static props={value:!1,inactiveText:"",activeText:"",inlineText:!1,disabled:!1,readOnly:!1};static styles=[e`:host{display:inline-flex;cursor:pointer}:host label{display:flex;align-items:center;height:32px;padding-right:8px;line-height:1;font-size:14px;white-space:nowrap;color:var(--color-dark-1);cursor:inherit;outline:none;-webkit-user-select:none;user-select:none}:host label.open .switch{flex-direction:row-reverse;background:var(--color-grey-3)}:host .switch{display:flex;align-items:center;min-width:32px;height:18px;padding:0 2px;margin-right:5px;border-radius:16px;font-family:Tahoma,Verdana,Helvetica,Arial,sans-serif;font-size:12px;background:var(--color-plain-3);transition:box-shadow .2s ease,background .2s ease}:host .dot{display:block;width:14px;height:14px;border-radius:50%;background:#fff;content:""}:host .text{padding:0 3px;background:none;color:#fff}:host(:focus-within) .switch{box-shadow:0 0 0 2px var(--color-plain-a)}`,e`:host([size=small]) label{height:24px;font-size:12px}:host([size=small]) .switch{min-width:28px;height:16px;padding:0 2px}:host([size=small]) .dot{width:12px;height:12px}`,e`:host([type=primay]) .open .switch{background:var(--color-teal-1)}:host([type=primay]):host(:focus-within) .switch{box-shadow:0 0 0 2px var(--color-teal-a)}:host([type=info]) .open .switch{background:var(--color-blue-1)}:host([type=info]):host(:focus-within) .switch{box-shadow:0 0 0 2px var(--color-blue-a)}:host([type=success]) .open .switch{background:var(--color-green-1)}:host([type=success]):host(:focus-within) .switch{box-shadow:0 0 0 2px var(--color-green-a)}:host([type=warning]) .open .switch{background:var(--color-orange-1)}:host([type=warning]):host(:focus-within) .switch{box-shadow:0 0 0 2px var(--color-orange-a)}:host([type=danger]) .open .switch{background:var(--color-red-1)}:host([type=danger]):host(:focus-within) .switch{box-shadow:0 0 0 2px var(--color-red-a)}`,e`:host([readonly]),:host([disabled]){opacity:.6}:host([disabled]){cursor:not-allowed}`];get#t(){return this.value?this.activeText:this.inactiveText}#s(t){if(this.disabled||this.readOnly)return;t.stopPropagation(),this.value=!this.value;let s={value:this.value};this.$emit("input",s),this.$emit("change",s)}#e(t){(t.type==="click"||t.keyCode===32)&&(t.preventDefault(),this.#s(t))}render(){return i` <label
class=${a({open:this.value})}
tabindex=${this.disabled||this.readOnly?"none":0}
@click=${this.#e}
@keydown=${this.#e}
>
<span class="switch">
<i class="dot"></i>
<mark class="text">${this.inlineText?this.#t:""}</mark>
</span>
<slot>${this.inlineText?"":this.#t}</slot>
</label>`}}n.reg("switch");

21
dist/lib/ui/form/textarea.js vendored Normal file
View File

@ -0,0 +1,21 @@
import{css as s,html as r,Component as h,nextTick as l}from"wkit";class n extends h{static props={value:{type:String,default:"",attribute:!1},type:"",placeholder:"",autofocus:!1,readOnly:!1,disabled:!1,autosize:!1,maxheight:{type:Number,default:null},minheight:{type:Number,default:null},maxlength:{type:Number,default:null},minlength:{type:Number,default:null},showLimit:!1,lazy:0};static styles=[s`:host{display:flex;width:100%;min-height:80px;user-select:none;-moz-user-select:none;color:var(--color-dark-1);border-radius:3px;cursor:text;transition:box-shadow .15s linear}:host([autosize]) textarea{overflow:hidden}.label{position:relative;width:100%;min-height:100%;font-size:14px;border:1px solid var(--color-grey-2);border-radius:inherit;background:var(--bg-color, #fff);color:inherit;cursor:inherit}.label textarea{flex:1;min-width:36px;width:100%;height:100%;padding:5px 8px;border:0;border-radius:inherit;color:inherit;font:inherit;background:none;outline:none;box-shadow:none;cursor:inherit;resize:none}.label textarea::placeholder{color:var(--color-grey-1)}.label .input-stat{display:none;position:absolute;right:4px;bottom:2px;line-height:1;font-size:12px;color:var(--color-grey-2)}:host([show-limit]) .label{padding-bottom:14px}:host([show-limit]) .label .input-stat{display:block}:host([disabled]){cursor:not-allowed}:host([disabled]) .label{background:var(--color-plain-1);opacity:.6}:host([readonly]){cursor:default}:host(:focus-within){box-shadow:0 0 0 2px var(--color-plain-a)}:host([type=primary]:focus-within){box-shadow:0 0 0 2px var(--color-teal-a)}:host([type=info]:focus-within){box-shadow:0 0 0 2px var(--color-blue-a)}:host([type=success]:focus-within){box-shadow:0 0 0 2px var(--color-green-a)}:host([type=danger]:focus-within){box-shadow:0 0 0 2px var(--color-red-a)}:host([type=warning]:focus-within){box-shadow:0 0 0 2px var(--color-orange-a)}:host([type=primary]) .label{border-color:var(--color-teal-2)}:host([type=info]) .label{border-color:var(--color-blue-2)}:host([type=success]) .label{border-color:var(--color-green-2)}:host([type=danger]) .label{border-color:var(--color-red-2)}:host([type=warning]) .label{border-color:var(--color-orange-2)}:host([no-border]),:host(:focus-within[no-border]){box-shadow:none}:host([no-border]) .label,:host(:focus-within[no-border]) .label{border:0}`];onInput(e){this.value=e.target.value,this.autosize&&l(()=>this.adjustTextareaSize())}adjustTextareaSize(){let{maxheight:e,minheight:a}=this;const o=this.$refs.textarea;o.style.height="auto";let t=o.scrollHeight;a&&!Number.isNaN(+a)&&(t=Math.max(a,t)),e&&!Number.isNaN(+e)&&(o.style.overflow=t>e?"auto":"hidden",t=Math.min(e,t)),o.style.height!==t&&(o.style.height=t+"px")}onKeydown(e){let{minlength:a,lazy:o}=this,t=this.value,i=Date.now();if(e.keyCode===13&&(e.ctrlKey||e.metaKey)){if(this.disabled||this.readOnly||o&&i-this.stamp<o||a&&a>0&&t.length<a)return;this.stamp=i,this.$emit("submit",{value:this.value})}}onChange(e){this.$emit(e.type)}render(){return r`
<div class="label">
<textarea
:value=${this.value}
ref="textarea"
spellcheck="false"
placeholder=${this.placeholder}
readonly=${this.readOnly}
disabled=${this.disabled}
maxlength=${this.maxlength}
minlength=${this.minlength}
autofocus=${this.autofocus}
@input=${this.onInput}
@keydown=${this.onKeydown}
@change=${this.onChange}
></textarea>
${this.showLimit?r`<div class="input-stat">
${this.value.length}/${this.maxlength||"\u221E"}
</div>`:""}
</div>
`}mounted(){this.autofocus&&l(e=>this.$refs.textarea.focus()),this.autosize&&(this.minheight=this.minheight||this.offsetHeight-2,this.adjustTextareaSize())}}n.reg("textarea");

59
dist/lib/ui/form/uploader.js vendored Normal file
View File

@ -0,0 +1,59 @@
import{css as a,html as l,Component as d,styleMap as n}from"wkit";import{resolveFiles as c,parseSize as p}from"../base/fs.js";import"../base/icon.js";function h(){return Math.random().toString(16).slice(2)}class u extends d{static props={value:[],tips:"str!",accept:"*/*",maxSize:0,limit:0,grid:!1,drag:!1,multiple:!1,disabled:!1};static styles=[a`:host{display:flex;width:100%;font-size:14px}img,a{-webkit-user-drag:none}.container{position:relative;width:100%;padding:6px 0;-webkit-user-select:none;user-select:none;--wc-icon-size: 14px}.tips,.error{display:block;line-height:1.5;font-size:12px;font-style:normal}.error{color:var(--color-red-1);background:none}.upload-button{position:relative;display:inline-flex;justify-content:center;align-items:center;width:108px;height:32px;gap:4px;border:1px solid var(--color-grey-2);border-radius:3px;cursor:pointer;transition:background .1s linear,border-color .1s linear,color .1s linear}.upload-button:hover{border-color:var(--color-grey-1)}.upload-button:active{background:var(--color-plain-1)}.upload-button.limited{background:var(--color-disabled-background);opacity:.6;cursor:not-allowed}.hidden-input{position:absolute;left:0;top:0;display:block;width:100%;height:100%;opacity:0;cursor:inherit}.hidden-input::-webkit-file-upload-button{display:none}`,a`.file-list .item{display:flex;align-items:center;padding:0 8px;line-height:24px;gap:4px;background:none no-repeat center;background-size:contain;transition:background .15s linear}.file-list .item:hover{background-color:var(--color-plain-1)}.file-list .item:hover wc-icon.del{opacity:1}.file-list .item .name{flex:1}.file-list .item wc-icon{flex-shrink:0;transition:opacity .15s linear}.file-list .item wc-icon.del{opacity:0;cursor:pointer;color:var(--color-red-1)}`,a`:host([grid]) .container{display:flex;flex-flow:row-reverse;justify-content:start;gap:12px;--size: var(--wc-uploader-size, 96px);--border-color: var(--wc-uploader-border-color, var(--color-grey-2))}:host([grid]) .tips{display:none}:host([grid]) .upload-button{width:var(--size);height:var(--size);border-radius:6px;--wc-icon-size: 18px}:host([grid]) .file-list{display:flex;gap:12px}:host([grid]) .file-list .item{justify-content:center;width:var(--size);height:var(--size);gap:6px;border:1px solid var(--border-color);border-radius:6px;--wc-icon-size: 20px}:host([grid]) .file-list .item .name{display:none}:host([grid]) .file-list .item wc-icon{padding:3px;border:1px solid rgba(255,255,255,.25);border-radius:50%;background:rgba(64,64,64,.75);color:#fff;opacity:0;cursor:pointer}:host([grid]) .file-list .item wc-icon:hover{border-color:rgba(255,255,255,.5)}:host([grid]) .file-list .item:hover wc-icon{opacity:1}`,a`:host([drag]) .container{flex-flow:column}:host([drag]) .action-area{width:100%}:host([drag]) .tips{display:block}:host([drag]) .upload-button{flex-direction:column;width:100%;height:180px;border-style:dashed;--wc-icon-size: 64px}:host([drag]) .upload-button.in{border-color:var(--color-orange-1);background:var(--color-drag-background)}:host([drag]) .upload-button:hover{color:var(--color-grey-3)}`,a`:host([disabled]){opacity:.6}:host([disabled]) .upload-button{background:var(--color-disabled-background);cursor:not-allowed}`,a`.preview{position:fixed;left:0;top:0;z-index:99;display:none;align-items:center;justify-content:center;width:100vw;height:100vh;background:rgba(0,0,0,.3)}.preview img{display:block;max-width:90%;max-height:90%;object-fit:contain;box-shadow:0 0 20px #000}`];#e=[];#i;#t(e){this.$refs.err.textContent=e,clearTimeout(this.#i),this.#i=setTimeout(()=>{this.$refs.err.textContent=""},5e3)}#s(e){let i=[...e.target.files];e.target.value="",this.#r(i)}#r(e){let{limit:i,maxSize:r}=this,o=e.length;r>0&&(e=e.filter(t=>t.size<=r),e.length<o&&(o=e.length,this.#t(`\u90E8\u5206\u6587\u4EF6\u88AB\u5FFD\u7565, \u5355\u6587\u4EF6\u6700\u5927\u5141\u8BB8 ${p(r)}`))),i>0&&(e=e.slice(0,i-this.#e.length),e.length<o&&this.#t(`\u90E8\u5206\u6587\u4EF6\u88AB\u5FFD\u7565, \u6700\u591A\u9009\u62E9 ${i} \u4E2A\u6587\u4EF6`)),e.length&&(e=e.map(t=>({file:t,id:h(),url:"",stat:0})),this.#e=this.#e.concat(e),this.$emit("upload",{files:e,send:t=>{for(let s of t)s.stat=1;this.value=this.#e.map(s=>s.url)}}),this.$requestUpdate())}#a(e,i,r){for(let o in this.#e)if(i===this.#e[o]){this.#e.splice(o,1);break}this.$requestUpdate()}#l(){this.disabled||this.$refs.button.classList.toggle("in",!0)}#n(){this.$refs.button.classList.toggle("in",!1)}async#d(e){let i;this.$refs.button.classList.toggle("in",!1),!this.disabled&&(i=await c(e.dataTransfer.items),this.#r(i.map(r=>r.file)))}#o(e,i){e.target.name!=="doc"&&(this.$refs.view.firstElementChild.src=i.url||URL.createObjectURL(i.file),this.$refs.view.style.display="flex")}#c(e){this.$refs.view.style.display=""}mounted(){}render(){let{disabled:e,grid:i,drag:r}=this,o=this.limit>0&&this.#e.length>=this.limit;return l`
<main class="container">
<header class="action-area">
<div
ref="button"
class="upload-button ${o?"limited":""}"
@dragover.prevent=${this.#l}
@dragleave.prevent=${this.#n}
@drop.prevent=${this.#d}
>
<wc-icon name=${i&&!r?"plus":"upload"}></wc-icon>
<span
>${r?"\u62D6\u62FD\u6587\u4EF6\u5230\u6B64\u5904 \u6216 \u70B9\u51FB\u9009\u62E9\u6587\u4EF6":i?"":"\u9009\u62E9\u6587\u4EF6"}</span
>
<input
class="hidden-input"
title
type="file"
accept=${this.accept}
multiple=${this.multiple}
disabled=${e||o}
@change=${this.#s}
/>
</div>
<cite class="tips">${this.tips}</cite>
<mark ref="err" class="error"></mark>
</header>
<footer
class="file-list"
style=${n({display:this.#e.length?"":"none"})}
>
${this.#e.map(t=>l`
<section
class="item"
style=${n({backgroundImage:i?`url(${t.url})`:""})}
>
<wc-icon
name=${t.stat===0?"loading":i?"search":"doc"}
@click=${s=>this.#o(s,t)}
></wc-icon>
<span class="name" @click=${s=>this.#o(s,t)}
>${t.file.name}</span
>
<wc-icon
class="del"
name="trash"
data-id=${t.id}
@click=${s=>this.#a(s,t,t.id)}
></wc-icon>
</section>
`)}
</footer>
</main>
<div class="preview" ref="view" @click.self=${this.#c}>
<img />
</div>
`}}u.reg("uploader");

16
dist/lib/ui/meditor/helper.js vendored Normal file
View File

@ -0,0 +1,16 @@
const c="\u5728\u6B64\u8F93\u5165\u6587\u672C",h={a:function(e,t,r){let l=t.match(s("href")),i=t.match(s("title")),n=t.match(s("target")),a="";return l=l&&l[1]||null,i=i&&i[1]||null,n=n&&n[1],l?(l=l.replace("viod(0)","").replaceAll("&amp;","&"),a=n?`target=${n}`:"",a+=i?`;title=${i}`:"",`[${r||l}](${l}${a?` "${a}"`:""})`):r||l},em:function(e,t,r){return r&&"_"+r+"_"||""},strong:function(e,t,r){return r&&"**"+r+"**"||""},pre:function(e,t,r){return r=r.replace(/<[/]?code>/g,""),"\n\n```\n"+r+"\n```\n"},code:function(e,t,r){return r&&"`"+r+"`"||""},blockquote:function(e,t,r){return"> "+r.trim()},img:function(e,t,r){var l=t.match(s("src")),i=t.match(s("alt"));return l=l&&l[1]||"",i=i&&i[1]||"","!["+i+"]("+l+")"},p:function(e,t,r){return r?`
`+r:""},br:`
`,"h([1-6])":function(e,t,r,l){return`
`+"#".repeat(t)+" "+l+`
`},hr:`
---
`},v=["header","quote","bold","italic","through","list","order","line","code","codeblock","table","link","image","attach","fullscreen","preview"],g=/<(ul|ol)>(?:(?!<ul|<ol)[\s\S])*?<\/\1>/gi;function p(e,t){return e.replace(new RegExp("^"+t+"|"+t+"$","g"),"")}function s(e,t="i"){return new RegExp(e+`\\s?=\\s?["']?([^"']*)["']?`,t)}function o(e,t){var r="";return["br","hr","img"].indexOf(e)>-1?r="<"+e+"([^>]*?)\\/?>":r="<"+e+"([^>]*?)>([\\s\\S]*?)<\\/"+e+">",new RegExp(r,"gi")}function m(e){try{e=decodeURIComponent(e)}catch{}e=e.replace(/\t/g," ").replace(/<\/?(meta|link|script)[^>]*?>/g,"").replace(/<!--[\w\W]*?-->/g,"").replace(/<xml[^>]*?>[\w\W]*?<\/xml>/g,"").replace(/<style>[\w\W]*?<\/style>/g,"").replace(s("class","g"),"").replace(s("style","g"),"").replace(/<a[^>]*? href\s?=\s?["']?([^"']*)["']?[^>]*?>/g,'<a href="$1">').replace(/<img[^>]*? src\s?=\s?["']?([^"']*)["']?[^>]*?>/g,'<img src="$1">').replace(/<(?!a |img )(\w+) [^>]*>/g,"<$1>").replace(/<svg[^>]*>.*?<\/svg>/g,"{svg not support}");for(let t in h){let r=h[t],l=o(t);if(t==="blockquote")for(;e.match(l);)e=e.replace(l,r);else e=e.replace(l,r);t==="p"&&(l=o("div"),e=e.replace(l,r)),t==="em"&&(l=o("i"),e=e.replace(l,r)),t==="strong"&&(l=o("b"),e=e.replace(l,r))}for(;e.match(g);)e=e.replace(g,function(t){return t=t.replace(/<(ul|ol)>([\s\S]*?)<\/\1>/gi,function(r,l,i){let n=i.split("</li>");n.pop();for(let a=0,f=n.length;a<f;a++){let d=l==="ol"?a+1+". ":"* ";n[a]=d+n[a].replace(/\s*<li>([\s\S]*)/i,function(w,u){return u=u.trim().replace(/\n/g,`
`),u}).replace(/<[\/]?[\w]*[^>]*>/g,"")}return n.join(`
`)}),`
`+t.trim()});return e=e.replace(/<[\/]?[\w]*[^>]*>/g,"").replace(/```([\w\W]*)```/g,function(t,r){return r=r.replace(/&amp;/g,"&").replace(/&lt;/g,"<").replace(/&gt;/g,">"),"```"+r+"```"}),e}const $={header(){this.$refs.header.classList.add("fadein")},h(e){var t=this.selection(!0)||c;t=t.replace(/^(#+ )?/,"#".repeat(e)+" "),this.insert(t,!0)},quote(){var e=this.selection(!0)||c;e=e.replace(/^(>+ )?/,"> "),this.insert(e,!0)},bold(){var e=this.selection()||c,t=p(e,"\\*\\*");e=e===t?`**${e}**`:t,this.insert(e,!0)},italic(){var e=this.selection()||c,t=p(e,"_");e=e===t?`_${e}_`:t,this.insert(e,!0)},through(){var e=this.selection()||c,t=p(e,"~~");e=e===t?`~~${e}~~`:t,this.insert(e,!0)},list(){var e=this.selection(!0)||c;e=e.replace(/^([+\-*] )?/,"+ "),this.insert(e,!0)},order(){var e=this.selection(!0)||c;e=e.replace(/^(\d+\. )?/,"1. "),this.insert(e,!0)},line(){this.insert(`
---
`,!1)},code(){var e=this.selection()||c,t=p(e,"`");e=e===t?`\`${e}\``:t,this.insert(e,!0)},codeblock(){this.insert("\n```language\n\n```\n")},table(){this.$refs.table.classList.add("fadein")},link(){this.$refs.link.classList.add("fadein")},fullscreen(){this.classList.toggle("fullscreen")},preview(){this.previewEnabled=!this.previewEnabled,this.$refs.view.classList.toggle("active"),this.previewEnabled&&(this.$refs.view.code=this.value)}};export{$ as Addon,v as DEFAULT_TOOLS,m as html2md};

75
dist/lib/ui/meditor/index.js vendored Normal file

File diff suppressed because one or more lines are too long

1
dist/lib/ui/meditor/svg.js vendored Normal file

File diff suppressed because one or more lines are too long

9
dist/lib/ui/modal/drawer.js vendored Normal file
View File

@ -0,0 +1,9 @@
import{css as r,html as e,Component as a}from"wkit";import"../base/icon.js";const o={left:{custom:[{transform:" translateX(-100%)"},{transform:" translateX(0)"}]},right:{custom:[{transform:" translateX(100%)"},{transform:" translateX(0)"}]},top:{custom:[{transform:" translateY(-100%)"},{transform:" translateY(0)"}]},bottom:{custom:[{transform:" translateY(100%)"},{transform:" translateY(0)"}]}};class s extends a{static animation={};static props={title:"str!",from:"right",value:{type:Boolean,default:!1,observer(t){this.$animate(!t),this.$refs.drawer.$animate(!t)}},maskClose:!1};static styles=[r`:host{position:fixed;left:0;top:0;z-index:9;width:100%;height:100%;background:rgba(0,0,0,.3)}.drawer{display:flex;flex-direction:column;position:absolute;width:var(--wc-drawer-width, 50%);height:100%;font-size:14px;background:#fff;box-shadow:0 0 24px rgba(0,0,0,.2)}.header{display:flex;align-items:center;justify-content:space-between;padding:16px;font-size:16px;color:var(--color-dark-2);user-select:none}.header wc-icon{--wc-icon-size: 16px;margin-right:8px;color:var(--color-grey-3);cursor:pointer}.wrapper{flex:1;padding:16px}`,r`:host([from=left]) .drawer,:host([from=right]) .drawer{top:0;width:var(--wc-drawer-width, 50%);height:100%}:host([from=top]) .drawer,:host([from=bottom]) .drawer{left:0;width:100%;height:var(--wc-drawer-width, 50%)}:host([from=left]) .drawer{left:0}:host([from=right]) .drawer{right:0}:host([from=top]) .drawer{top:0}:host([from=bottom]) .drawer{bottom:0}`];#t(){this.value=!1,this.$emit("input",{value:!1}),this.$emit("close",{value:!1})}mounted(){this.$on("click",t=>{t.composedPath()[0]===t.currentTarget&&this.maskClose&&this.#t()})}render(){return e`
<div class="drawer" ref="drawer" #animation=${o[this.from]}>
<header class="header">
<span class="title"><slot name="title">${this.title}</slot></span>
<wc-icon name="close" @click=${this.#t}></wc-icon>
</header>
<main class="wrapper"><slot></slot></main>
</div>
`}}s.reg("drawer");

29
dist/lib/ui/modal/layer.js vendored Normal file

File diff suppressed because one or more lines are too long

1
dist/lib/ui/modal/loading.js vendored Normal file
View File

@ -0,0 +1 @@
import{html as e,css as a,Component as o,styleMap as r}from"wkit";class n extends o{static props={progress:"num!0",duration:3e3,value:{type:Boolean,observer(t){this.duration>0?t&&requestAnimationFrame(this.#i.bind(this)):t?this.setAttribute("loading",""):this.removeAttribute("loading")}}};static styles=[a`:host{position:fixed;top:0;left:0;z-index:65535;display:flex;width:100vw;height:0}.thumb{width:0;height:var(--wc-loading-height, 2px);background:var(--wc-loading-background, var(--color-teal-1));box-shadow:0 0 5px var(--wc-loading-background, var(--color-teal-1));will-change:width;transition:width .1s linear}:host([loading]) .thumb{width:25% !important;animation:autoplay 1s infinite ease-in-out}@keyframes autoplay{from,to{transform:translateX(0)}50%{transform:translateX(calc(100vw - 100%))}}`];#t;#i(t){this.#t===void 0&&(this.#t=t);let i=t-this.#t,s=~~(i/(this.duration/100));if(s!==this.progress&&(this.progress=s),i>this.duration){this.progress=0,this.#t=void 0,this.value=!1,this.$emit("input"),this.$emit("change");return}requestAnimationFrame(this.#i.bind(this))}render(){let t=r({width:this.progress+"%"});return e` <span class="thumb" style=${t}></span> `}}n.reg("loading");

23
dist/lib/ui/modal/popconfirm.js vendored Normal file
View File

@ -0,0 +1,23 @@
import{css as p,html as c,Component as l,bind as a,unbind as d,styleMap as f,offset as h,outsideClick as m,clearOutsideClick as x}from"wkit";import"../base/button.js";const w="\u8BF7\u786E\u8BA4\u4F60\u7684\u64CD\u4F5C!";class u extends l{static props={title:"str!",confirmButtonType:"str!primary"};static styles=[p`:host{display:inline-flex}.container{position:relative}.tooltip{display:none;position:fixed;z-index:9;justify-content:center;align-items:center;max-width:260px;min-width:32px;padding:8px 12px 12px;border-radius:3px;font-size:var(--wc-popconfirm-font, 14px);background:var(--wc-popconfirm-background, #fff);color:var(--wc-popconfirm-color, var(--color-dark-1));box-shadow:0 0 3px var(--wc-popconfirm-shadow, rgba(0, 0, 0, 0.3));word-break:break-all;-webkit-user-select:none;user-select:none}.tooltip::after{position:absolute;display:block;width:8px;height:8px;border-radius:2px;background:var(--wc-popconfirm-background, #fff);content:"";transform:rotate(45deg);box-shadow:-1px -1px 0 var(--wc-popconfirm-shadow, rgba(0, 0, 0, 0.1))}.tooltip[placement=left-top]::after{right:16px;bottom:-4px;box-shadow:1px 1px 0 var(--wc-popconfirm-shadow, rgba(0, 0, 0, 0.1))}.tooltip[placement=left-bottom]::after{right:16px;top:-4px}.tooltip[placement=right-top]::after{left:16px;bottom:-4px;box-shadow:1px 1px 0 var(--wc-popconfirm-shadow, rgba(0, 0, 0, 0.1))}.tooltip[placement=right-bottom]::after{left:16px;top:-4px}`,p`.title{display:flex;align-items:center;gap:6px;padding:8px 0;--wc-icon-size: 16px}.title wc-icon{flex-shrink:0;color:var(--wc-popconfirm-icon-color, var(--color-red-1))}:host([hide-icon]) .title wc-icon{display:none}.actions{display:flex;justify-content:flex-end;gap:4px;margin-top:8px}.actions wc-button{min-width:40px;height:20px;font-size:12px}.actions wc-button:first-child{--wc-button-border-color: none}`];#t=!1;#i(s){let{left:t,top:i}=h(this),e="left",o={display:"block"},r=document.documentElement.scrollTop;if(!this.#t){if(t<260||t>260&&window.innerWidth-t>260)e="right",o.left=t+"px";else{let n=window.innerWidth-t+this.clientWidth;o.right=n+"px"}if(i<160)i+=8+this.clientHeight,e+="-bottom",o.top=i+"px";else{let n=window.innerHeight-i+8;e+="-top",o.bottom=n+"px",r>0&&(o.transform=`translateY(-${r}px)`)}this.#t=!0,this.$refs.tips.setAttribute("placement",e),this.$refs.tips.style.cssText=f(o),this.$refs.tips.$animate()}}#o(){this.#t&&(this.#t=!1,this.$refs.tips.$animate(!0))}#e(){this.$emit("confirm"),this.#o()}mounted(){this._outFn=m(this,s=>this.#o()),this._scrollFn=a(document,"scroll",s=>{if(this.#t){let t=document.documentElement.scrollTop;this.$refs.tips.style.transform=`translateY(-${t}px)`}})}unmounted(){d(document,"scroll",this._scrollFn),x(this._outFn)}render(){return c`
<main class="container">
<div class="wrapper" @click=${this.#i}>
<slot></slot>
</div>
<div class="tooltip" ref="tips" #animation=${{}}>
<header class="title">
<wc-icon name="info"></wc-icon>
${this.title||w}
</header>
<footer class="actions">
<wc-button @click=${this.#o}>取消</wc-button>
<wc-button
solid
type=${this.confirmButtonType||"primary"}
@click=${this.#e}
>确定</wc-button
>
</footer>
<i class="trigon"></i>
</div>
</main>
`}}u.reg("popconfirm");

8
dist/lib/ui/modal/tooltip.js vendored Normal file
View File

@ -0,0 +1,8 @@
import{css as a,html as n,Component as d,bind as r,styleMap as c,offset as f}from"wkit";class h extends d{static props={title:"str!"};static styles=[a`:host{display:inline-flex}.container{position:relative}.tooltip{display:none;position:fixed;z-index:9;justify-content:center;align-items:center;max-width:360px;min-width:32px;padding:6px 8px;border-radius:3px;font-size:var(--wc-tooltip-font, 14px);background:var(--wc-tooltip-background, #fff);color:var(--wc-tooltip-color, var(--color-dark-1));box-shadow:0 0 3px var(--wc-tooltip-shadow, rgba(0, 0, 0, 0.3));word-break:break-all;-webkit-user-select:none;user-select:none}.tooltip::after{position:absolute;display:block;width:8px;height:8px;border-radius:2px;background:var(--wc-tooltip-background, #fff);content:"";transform:rotate(45deg);box-shadow:-1px -1px 0 var(--wc-tooltip-shadow, rgba(0, 0, 0, 0.1))}.tooltip[placement=left-top]::after{right:16px;bottom:-4px;box-shadow:1px 1px 0 var(--wc-tooltip-shadow, rgba(0, 0, 0, 0.1))}.tooltip[placement=left-bottom]::after{right:16px;top:-4px}.tooltip[placement=right-top]::after{left:16px;bottom:-4px;box-shadow:1px 1px 0 var(--wc-tooltip-shadow, rgba(0, 0, 0, 0.1))}.tooltip[placement=right-bottom]::after{left:16px;top:-4px}`];mounted(){r(this.$refs.wrap,"mouseenter",p=>{let{left:t,top:e}=f(this),i="left",o={display:"block"},l=document.documentElement.scrollTop;if(this.title.trim()!==""){if(t<360||t>360&&window.innerWidth-t>360)i="right",o.left=t+"px";else{let s=window.innerWidth-t-this.clientWidth;o.right=s+"px"}if(e<96)e+=8+this.clientHeight,i+="-bottom",o.top=e+"px";else{let s=window.innerHeight-e+8+l;i+="-top",o.bottom=s+"px"}this.$refs.tips.setAttribute("placement",i),this.$refs.tips.style.cssText=c(o),this.$refs.tips.$animate()}}),r(this.$refs.wrap,"mouseleave",p=>{this.$refs.tips.$animate(!0)})}render(){return n`
<main class="container">
<div class="wrapper" ref="wrap"><slot></slot></div>
<div class="tooltip" ref="tips" #animation=${{}}>
<slot name="title">${this.title}</slot><i class="trigon"></i>
</div>
</main>
`}}h.reg("tooltip");

30
dist/lib/ui/nav/pager.js vendored Normal file
View File

@ -0,0 +1,30 @@
import{css as c,html as n,Component as p}from"wkit";import"../base/button.js";const r={home:a=>n`<wc-button
data-act="1"
disabled=${a}
class="item"
icon="dbl-left"
></wc-button>`,end:a=>n`<wc-button
data-act="end"
disabled=${a}
class="item"
icon="dbl-right"
></wc-button>`,prev:a=>n`<wc-button
data-act="prev"
disabled=${a}
class="item"
icon="left"
></wc-button>`,next:a=>n`<wc-button
data-act="next"
disabled=${a}
class="item"
icon="right"
></wc-button>`,curr:a=>n`<span class="curr item">${a}</span>`,info:(a,t)=>n`<span class="item"> ${a}, ${t}</span>`,jump(a){return n`<section class="item jump">
<span>Go to</span>
<input ref="input" @keydown=${this.__gotoPage} maxlength="6" value=${a} />
</section>`}};function u(a,t){let i=[],o=0,s=a<3?6-a:2;if(t<2)return i.push({to:a,txt:a}),i;if(a-s>1&&t>5){let e=a-2*s;e=e<1?1:e,i.push({to:e,txt:"..."})}t-a<s&&(o=s-t+a);for(let e=a-s-o;e<a+s+1&&e<=t;e++)e>0&&i.push({to:e,txt:e});if(a+s<t){let e=a+2*s;e=e>t?t:e,i.push({to:e,txt:"..."})}return i}class h extends p{static props={layout:"str!home, prev, pages, next, end",total:{type:Number,default:0,attribute:!1,observer(t){this.totalpage=Math.ceil(t/this.pagesize)||1}},totalpage:{type:Number,default:1,attribute:!1,observer(t){t<1&&(t=1),this.page>t&&(this.page=t)}},page:{type:Number,default:1,attribute:!1,observer(t){t>this.totalpage?this.page=this.totalpage:t<1&&(this.page=1)}},pagesize:{type:Number,default:20,attribute:!1,observer(t){this.total>0&&(this.totalpage=Math.ceil(this.total/t))}}};static styles=[c`:host{display:block;line-height:1;font-size:14px;-webkit-user-select:none;user-select:none;color:var(--color-dark-1)}:host .layout{display:flex;justify-content:center;align-items:center;margin:10px auto;--wc-button-icon-size: 10px;--wc-button-border-color: none;--wc-button-background: var(--color-plain-1);--wc-button-color-hover: var(--color-teal-1)}:host .item{min-width:32px;width:auto;margin:0 5px;border-radius:3px}:host .item.curr{display:inline-flex;align-items:center;justify-content:center;height:32px;background:var(--color-teal-1);color:#fff}:host .item.jump{display:flex;align-items:center}:host input{width:48px;height:24px;padding:0 4px;margin-left:4px;border:1px solid var(--color-grey-2);border-radius:3px;text-align:center;outline:none;transition:box-shadow .15s linear}:host input:focus{box-shadow:0 0 0 2px var(--color-plain-a)}`,c``];#t(t){let i=t.target;if(i.tagName==="WC-BUTTON"){let{page:o,totalpage:s}=this,e=i.dataset.act;if(i.disabled)return;switch(e){case"prev":e=o-1;break;case"next":console.log(e,o),e=o+1;break;case"end":e=s;break}if(+e===o)return;this.page=e,this.$refs.input&&(this.$refs.input.value=e),this.$emit("page-change",{data:e})}}__gotoPage(t){if(t.keyCode===13){let i=+t.target.value;i===i&&(this.page=i,this.$emit("page-change",{data:i})),t.target.value=this.page}}render(){let t=this.layout.split(",").map(e=>e.trim()),{page:i,total:o,totalpage:s}=this;return n`
<div class="layout" @click=${this.#t}>
${t.map(e=>{switch(e){case"pages":return u(i,s).map(l=>i===l.to?r.curr(i):n`<wc-button class="item" data-act="${l.to}"
>${l.txt}</wc-button
>`);case"home":return r.home(i===1);case"prev":return r.prev(i===1);case"next":return r.next(i>=s);case"end":return r.end(i>=s);case"curr":return r.curr(i);case"info":return r.info(o,s);case"jump":return r.jump.call(this,i);default:return""}})}
</div>
`}}h.reg("pager");

3
dist/lib/ui/other/divider.js vendored Normal file
View File

@ -0,0 +1,3 @@
import{html as e,css as t,Component as i}from"wkit";class l extends i{static styles=[t`:host{display:block;width:100%}fieldset{width:100%;height:1px;margin:16px 0;border:0;border-top:1px dashed var(--color-grey-1);user-select:none}fieldset legend{display:inline-flex;align-items:center;padding:0 8px;font-size:12px;text-align:center;color:var(--color-grey-2)}:host([align=left]) fieldset{padding-left:16px}:host([align=left]) fieldset legend{text-align:left}:host([align=right]) fieldset{padding-right:16px}:host([align=right]) fieldset legend{text-align:right}:host(:empty) fieldset legend{padding:0}`];render(){return e`<fieldset>
<legend><slot></slot></legend>
</fieldset> `}}l.reg("divider");

13
dist/lib/ui/other/scroll.js vendored Normal file
View File

@ -0,0 +1,13 @@
import{css as p,html as $,bind as a,unbind as x,Component as _}from"wkit";class z extends _{static props={axis:"xy",delay:1e3,distance:1};static styles=[p`:host{position:relative;display:block}:host .container{overflow:hidden;position:relative;width:100%;height:100%;max-height:inherit}:host .wrapper{overflow:auto;scrollbar-width:none;width:100%;height:100%;max-height:inherit;scrollbar-width:0}:host .wrapper::-webkit-scrollbar{display:none}:host .content{min-width:100%;width:fit-content;height:fit-content}`,p`.is-horizontal,.is-vertical{visibility:hidden;position:absolute;display:flex;justify-content:flex-end;opacity:0;user-select:none;transition:opacity .3s linear,visibility .3s linear}.is-horizontal .thumb,.is-vertical .thumb{display:block;border-radius:5px;background:rgba(44,47,53,.25);cursor:default;transition:width .1s linear,height .1s linear}.is-horizontal .thumb:hover,.is-vertical .thumb:hover{background:rgba(44,47,53,.5)}.is-horizontal{flex-direction:column;left:0;bottom:0;width:100%;height:10px}.is-horizontal .thumb{width:0;height:6px}.is-horizontal .thumb:hover{height:10px}.is-vertical{top:0;right:0;width:10px;height:100%}.is-vertical .thumb{width:6px;height:0}.is-vertical .thumb:hover{width:10px}`,p`:host(:hover) .is-horizontal,:host(:hover) .is-vertical{visibility:visible;opacity:1}:host([axis=x]) .wrapper{overflow-y:hidden}:host([axis=x]) .is-vertical{display:none}:host([axis=y]) .wrapper{overflow-x:hidden}:host([axis=y]) .is-horizontal{display:none}:host([disabled]) .wrapper{overflow:hidden}:host([disabled]) .is-vertical,:host([disabled]) .is-horizontal{display:none}`];stamp=0;cache={xBar:0,yBar:0,thumbX:0,thumbY:0};get scrollTop(){return this.$refs.box?.scrollTop||0}set scrollTop(t){t=+t,t===t&&(this.$refs.box.scrollTop=t)}get scrollLeft(){return this.$refs.box?.scrollLeft||0}set scrollLeft(t){t=+t,t===t&&(this.$refs.box.scrollLeft=t)}get scrollHeight(){return this.$refs.box?.scrollHeight}get scrollWidth(){return this.$refs.box?.scrollWidth}__init__(t){let e=this.offsetWidth,r=this.offsetHeight,s=this.scrollWidth,l=this.scrollHeight,h=50,i=50;h=r*(r/l)>>0,i=e*(e/s)>>0,h<50&&(h=50),i<50&&(i=50),i>=e&&(i=0),h>=r&&(h=0),this.cache.yBar=h,this.cache.xBar=i,i>0?(this.$refs.x.parentNode.style.display="flex",this.$refs.x.style.width=i+"px"):this.$refs.x.parentNode.style.display="none",h>0?(this.$refs.y.parentNode.style.display="flex",this.$refs.y.style.height=h+"px"):this.$refs.y.parentNode.style.display="none"}_fetchScrollX(t){let{xBar:e}=this.cache,{scrollWidth:r,offsetWidth:s}=this;return t<0?t=0:t>s-e&&(t=s-e),this.scrollLeft=(r-s)*(t/(s-e)),this.$refs.x.style.transform=`translateX(${t}px)`,t}_fetchScrollY(t){let{yBar:e}=this.cache,{scrollHeight:r,offsetHeight:s}=this;return t<0?t=0:t>s-e&&(t=s-e),this.scrollTop=(r-s)*(t/(s-e)),this.$refs.y.style.transform=`translateY(${t}px)`,t}_fireReachEnd(t="reach-bottom"){let e=this.delay,{scrollHeight:r,offsetHeight:s}=this,l=this.scrollTop,h=Date.now();if(h-this.stamp>e){if(t==="reach-bottom"){if(s+l<r)return}else if(l>0)return;this.stamp=h,this.$emit(t)}}mounted(){let t,e,r,s,l=i=>{let{thumbY:c,thumbX:n}=this.cache;t!==void 0&&(r=this._fetchScrollX(n+i.pageX-t)),e!==void 0&&(s=this._fetchScrollY(c+i.pageY-e))},h=i=>{Math.abs(i.pageY-e)>this.distance&&this._fireReachEnd(i.pageY>e?"reach-bottom":"reach-top"),t=void 0,e=void 0,this.cache.thumbX=r||0,this.cache.thumbY=s||0,delete this._active,x(document,"mousemove",l),x(document,"mouseup",h)};a(this.$refs.box,"scroll",i=>{if(i.stopPropagation(),this._active)return;let{xBar:c,yBar:n,thumbX:m,thumbY:f}=this.cache,{axis:d,scrollHeight:y,scrollWidth:g,offsetHeight:u,offsetWidth:b,scrollTop:v,scrollLeft:w}=this;if(!(c===0&&n===0)){if((d==="y"||d==="xy")&&n){let o=~~(v/(y-u)*(u-n));o!==f&&(this.cache.thumbY=o,this.$refs.y.style.transform=`translateY(${o}px)`,Math.abs(o-f)>this.distance&&this._fireReachEnd(o>f?"reach-bottom":"reach-top"))}if((d==="x"||d==="xy")&&c){let o=~~(w/(g-b)*(b-c));o!==m&&(this.cache.thumbX=o,this.$refs.x.style.transform=`translateX(${o}px)`)}this.$emit("scroll")}}),a(this.$refs.y,"mousedown",i=>{e=i.pageY,this._active=!0,a(document,"mousemove",l),a(document,"mouseup",h)}),a(this.$refs.x,"mousedown",i=>{t=i.pageX,this._active=!0,a(document,"mousemove",l),a(document,"mouseup",h)}),this.__observer=new ResizeObserver(this.__init__.bind(this)),this.__observer.observe(this.$refs.cont)}unmounted(){this.__observer?.disconnect()}render(){return $`
<div class="container">
<div class="wrapper" ref="box">
<div class="content" ref="cont"><slot></slot></div>
</div>
</div>
<div class="is-horizontal">
<span ref="x" class="thumb"></span>
</div>
<div class="is-vertical">
<span ref="y" class="thumb"></span>
</div>
`}}z.reg("scroll");

5
dist/lib/ui/views/avatar.js vendored Normal file
View File

@ -0,0 +1,5 @@
import{html as t,css as e,Component as i}from"wkit";import"../base/icon.js";class r extends i{static props={src:{type:String,default:null}};static styles=[e`:host{display:inline-flex;width:32px;height:32px;--wc-icon-size: 22px;font-size:14px;border-radius:3px}.avatar{display:flex;align-items:center;justify-content:center;width:100%;height:100%;padding:4px;border-radius:inherit;text-align:center;background:var(--wc-avatar-color, var(--color-grey-3));color:#fff;-webkit-user-select:none;user-select:none}.avatar img{width:100%;height:100%;border-radius:inherit;-webkit-user-drag:none}:host([src]) .avatar{padding:0}:host([circle]){border-radius:50%}`,e`:host([size=small]){width:24px;height:24px;font-size:12px;--wc-icon-size: 14px}`];mounted(){this.textContent.trim().length>4&&(this.textContent=this.textContent.trim().slice(0,4))}render(){return t`
<main class="avatar">
${this.src?t`<img src=${this.src} />`:t`<slot><wc-icon name="user"></wc-icon></slot>`}
</main>
`}}r.reg("avatar");

6
dist/lib/ui/views/badge.js vendored Normal file
View File

@ -0,0 +1,6 @@
import{css as e,html as t,Component as n}from"wkit";class o extends n{static props={value:0,max:0};static styles=[e`:host{display:inline-flex}.container{position:relative}.dot{position:absolute;z-index:9;left:calc(100% - 5px);top:-6px;display:inline-flex;justify-content:center;align-items:center;min-width:10px;min-height:10px;border-radius:10px;background:var(--color-red-1);-webkit-user-select:none;user-select:none}.num{padding:1px 3px;line-height:12px;font-size:12px;font-style:normal;text-align:center;white-space:nowrap;font-family:Tahoma,Verdana,Helvetica,Arial,sans-serif;color:#fff}.num:not(:empty){min-width:14px}:host([hidden-value]) .dot .num{display:none}`,e`:host([type=info]) .dot{background-color:var(--color-blue-1)}:host([type=success]) .dot{background-color:var(--color-green-1)}:host([type=warning]) .dot{background-color:var(--color-orange-1)}`];get#e(){return this.value>0?this.max>0&&this.value>this.max?this.max+"+":this.value:""}render(){return t`
<main class="container">
<slot></slot>
<span class="dot"><i class="num">${this.#e}</i></span>
</main>
`}}o.reg("badge");

11
dist/lib/ui/views/breadcrumb.js vendored Normal file
View File

@ -0,0 +1,11 @@
import{css as s,html as i,Component as l,styleMap as n}from"wkit";class o extends l{static styles=[s`:host{display:flex;align-items:center;width:100%;height:32px;font-size:14px}`];#e(m){let t=Array.from(this.children);t.forEach((e,r)=>{e.tagName==="WC-BREADCRUMB-ITEM"?e.last=t.length===r+1:e.remove()})}mounted(){this.#e()}}class p extends l{static props={separator:"/",last:"bool!"};static styles=[s`:host,.item{display:inline-flex;align-items:center;height:32px;font-size:14px}.pipe{margin:0 8px;user-select:none}`];render(){return i`
<label class="item">
<slot></slot>
<span
class="pipe"
style=${n({display:this.last?"none":""})}
>
<slot name="separator">${this.separator||"/"}</slot>
</span>
</label>
`}}o.reg("breadcrumb"),p.reg("breadcrumb-item");

8
dist/lib/ui/views/card.js vendored Normal file
View File

@ -0,0 +1,8 @@
import{css as e,html as r,Component as o}from"wkit";class a extends o{static props={header:""};static styles=e`:host{display:flex;border-radius:3px}.container{display:flex;flex-direction:column;position:relative;width:100%;border:1px solid var(--wc-card-border-color, var(--color-plain-2));border-radius:inherit;background:#fff;color:var(--color-dark-1);transition:box-shadow .2s ease-in-out;box-shadow:0 0 12px rgba(0,0,0,.12)}.container .header{display:flex;align-items:center;justify-content:space-between;width:100%;min-height:var(--wc-card-header-height, 52px);padding:var(--wc-card-header-padding, 8px 16px);font-size:16px;box-shadow:inset 0 -1px 0 0 var(--color-plain-2);-webkit-user-select:none;user-select:none}.container .content{flex:1;min-height:64px;padding:var(--wc-card-padding, 8px 16px);font-size:14px;color:var(--color-dark-1)}:host([shadow=never]) .container,:host([shadow=hover]) .container{box-shadow:none}:host([shadow=hover]:hover) .container{box-shadow:0 0 12px rgba(0,0,0,.12)}`;render(){return r`
<main class="container">
<header class="header">
<slot name="header">${this.header}</slot>
</header>
<div class="content"><slot></slot></div>
</main>
`}}a.reg("card");

4
dist/lib/ui/views/code/colorful.js vendored Normal file
View File

@ -0,0 +1,4 @@
const i=/<\!DOCTYPE html>/,o=/<([\w\-]+)([\w\W]*?)>/g,u=/<\/([\w\-]+)>/g,k=/[@a-zA-Z\-.:#]+=(["'])[^"]+\1|[@a-zA-Z\-.:#]+=[a-zA-Z0-9]+|[@a-zA-Z\-.:#]+=\$\{.+\}|[@a-zA-Z\-.]+/g,f=/<!--([\w\W]*?)-->/g,d=/(<script[^>]*?>)([\w\W]*?)(<\/script>)/g,_=/import (['"])([^'"]*?)\1/g,h=/import ([\w\W]*?) from (['"])([^'"]*?)\2/g,y=/import\((['"])([^'"]*?)\1\)/g,b=/\b(var|const|let|function|for|switch|with|if|else|export|import|assert|as|from|async|await|break|continue|return|class|extends|try|catch|throw|new|while|this|super|default|case|debugger|delete|do|goto|in|static|get|set|public|private|protected|package|typeof|void)\b/g,w=/\s(=|-|\+|\/|\*|<|>|%)\s/g,W=/(\+\=|-=|\/=|\*=|--|\+\+|===|==|=>|\.\.\.|\.|\?\.|\?\?|&&|\|\|)/g,A=/\b(null|undefined|true|false|NaN|Infinity)\b/g,T=/\b(Object|String|Array|Boolean|Number|Function|Promise|Map|Set|WeakMap|WeakSet|URL)\b/g,g=/(['"`])(.*?)(?<!\\)\1/g,S=/\b(\d+)\b/g,E=/([\.\s])((?!if|for)[a-zA-Z$_#][\da-zA-Z_]*)\s?(\(.*?\)?)/g,P=/(?=\s)?([ ]*\/\/.*)|(^\/\/.*)/g,z=/\/\*([\w\W]*?)\*\//g,I=/([=\(][ ]*)\/(.+?)\/([gmi]*)/g,n={code:/`([^`]*?[^`\\\s])`/g,codeBlock:/^```(.*?)$/gm,strong:[/__([\s\S]*?[^\s\\])__(?!_)/g,/\*\*([\s\S]*?[^\s\\])\*\*(?!\*)/g],em:[/_([\s\S]*?[^\s\\_])_(?!_)/g,/\*([\s\S]*?[^\s\\*])\*(?!\*)/g],del:/~~([\s\S]*?[^\s\\~])~~/g,qlinkVar:/^\[(\d+)\]: ([\S]+)\s*?((['"])[\s\S]*?\4)?\s*?$/gm,qlink:/\[([^\]]*?)\]\[(\d*?)\]/g,img:/\!\[([^\]]*?)\]\(([^)]*?)\)/g,a:/\[([^\]]*?)\]\(([^)]*?)(\s+"([\s\S]*?)")*?\)/g,head:/^(#{1,6} )(.*)$/gm,quote:/^(>{1,} )(.*)$/gm,task:/^([\-\+\*]) \[( |x)\] (.*)$/gm,list:/^([ \t]*?([\-\+\*]|\d+\.) )(.*)$/gm,br:/^([\-\*_=]{3})(.*?)$/gm};function p(r){return r.replace(_,(t,e,c)=>`import ${e}[link]${c}[/link]${e}`).replace(h,(t,e,c,a)=>(e=e.replace(/(\{|\}|,)/g,"[cm]$1[/cm]"),`import ${e} from ${c}[link]${a}[/link]${c}`)).replace(y,(t,e,c)=>`import(${e}[link]${c}[/link]${e})`).replace(I,(t,e,c,a)=>(c=c.replace(/&/g,"&amp;").replace(/(\\.)/g,"[fn]$1[/fn]"),`${e}[type]/[/type][cm]${c}[/cm][type]/[/type]${a?`[num]${a}[/num]`:""}`)).replace(E,"$1[fn]$2[/fn]$3").replace(b,"[key]$1[/key]").replace(w," [key]$1[/key] ").replace(W,"[key]$1[/key]").replace(A,"[buildin]$1[/buildin]").replace(T,"[type]$1[/type]").replace(S,"[num]$1[/num]").replace(g,(t,e,c)=>c.startsWith("[link]")&&c.endsWith("[/link]")?(c=c.slice(6,-7).replace(/\[(\w+)\](.*?)\[\/\1\]/g,"$2"),`[cm]${e}[/cm][link]${c}[/link][cm]${e}[/cm]`):(c=c.replace(/\[(\w+)\](.*?)\[\/\1\]/g,"$2").replace(/&lt;(\/?)xmp&gt;/g,"<$1xmp>").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/(\\.)/g,"[fn]$1[/fn]"),`[cm]${e}[/cm][str]${c}[/str][cm]${e}[/cm]`)).replace(P,(t,e)=>e.includes("[/link]")||e.includes("[link]")?e:(e=e.replace(/\[(\w+)\](.*?)\[\/\1\]/g,"$2").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;"),`[cm]${e}[/cm]`)).replace(z,(t,e)=>(e=e.replace(/\[(\w+)\](.*?)\[\/\1\]/g,"$2").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;"),e=`/*${e}*/`.split(`
`).map(c=>`[cm]${c}[/cm]`),e.join(`
`)))}function s(r){return r.replace(/\[(\/?)tag\]/g,(t,e)=>e?"</c>":'<c class="t-tag">').replace(/\[(\/?)attr\]/g,(t,e)=>e?"</c>":'<c class="t-attr">').replace(/\[(\/?)str\]/g,(t,e)=>e?"</c>":'<c class="t-str">').replace(/\[(\/?)key\]/g,(t,e)=>e?"</c>":'<c class="t-keyword">').replace(/\[(\/?)num\]/g,(t,e)=>e?"</c>":'<c class="t-num">').replace(/\[(\/?)fn\]/g,(t,e)=>e?"</c>":'<c class="t-fn">').replace(/\[(\/?)cm\]/g,(t,e)=>e?"</c>":'<c class="t-comment">').replace(/\[(\/?)buildin\]/g,(t,e)=>e?"</c>":'<c class="t-buildin">').replace(/\[(\/?)type\]/g,(t,e)=>e?"</c>":'<c class="t-type">').replace(/\[(\/?)link\]/g,(t,e)=>e?"</c>":'<c class="t-link">')}function O(r){return r=r.replace(n.head,"[cm]$1[/cm][tag]<strong>$2</strong>[/tag]").replace(n.br,"[cm]$1[/cm][tag]$2[/tag]").replace(n.quote,"[cm]$1[/cm]<em>$2</em>").replace(n.task,"[cm]$1 [[/cm][attr]$2[/attr][cm]][/cm] <strong>$3</strong>").replace(n.list,"[cm]$1[/cm]<strong>$3</strong>").replace(n.code,"[cm]`[/cm][tag]$1[/tag][cm]`[/cm]").replace(n.codeBlock,"[cm]```[/cm][tag]$1[/tag]").replace(n.strong[0],"[cm]__[/cm]<strong>$1</strong>[cm]__[/cm]").replace(n.strong[1],"[cm]**[/cm]<strong>$1</strong>[cm]**[/cm]").replace(n.em[0],"[cm]_[/cm]<em>$1</em>[cm]_[/cm]").replace(n.em[1],"[cm]*[/cm]<em>$1</em>[cm]*[/cm]").replace(n.del,"[cm]~~[/cm]<del>$1</del>[cm]~~[/cm]").replace(n.qlinkVar,"[[attr]$1[/attr]]: [link]$2[/link] [tag]$3[/tag]").replace(n.qlink,"[[attr]$1[/attr]][[link]$2[/link]]").replace(n.img,"![[attr]$1[/attr]]([link]$2[/link])").replace(n.a,(t,e,c,a,l="")=>(l&&(l=` "[tag]${l}[/tag]"`),`[[attr]${e}[/attr]]([link]${c}[/link]${l})`)),s(r)}function $(r){return r=r.replace(i,"[tag]&lt;!DOCTYPE [attr]html[/attr]&gt;[/tag]").replace(d,(t,e,c,a)=>e+p(c)+a).replace(o,(t,e,c)=>(c&&(c=c.replace(k,function(a){if(~a.indexOf("=")){a=a.split("=");let l=a.shift(),m=a.join("=").replace(/(\n+)/g,`[/str]
[str]`);return m.startsWith("${")&&m.endsWith("}")?`[attr]${l}[/attr]=${m}`:`[attr]${l}[/attr]=[str]${m}[/str]`}else return`[attr]${a}[/attr]`})),`[tag]&lt;${e}[/tag]${c}[tag]&gt;[/tag]`)).replace(u,(t,e)=>`[tag]&lt;/${e}&gt;[/tag]`).replace(f,"[cm]&lt;!--$1--&gt;[/cm]"),s(r)}function R(r){return r=r.replace(g,'<cc class="t-str">$1$2$1</cc>').replace(/(\$[a-zA-Z\d_\-]+)/g,'<c class="t-var">$1</c>').replace(/(\-\-[a-z\d]+\-[a-z\d]+)/g,'<c class="t-const">$1</c>').replace(/:(hover|after|active|last\-child|first\-child|nth\-child)/g,'<c class="t-buildin">:$1</c>').replace(/^((?:[ ])*)([\.#])([\w\-]+)/gm,'$1<c class="t-comment">$2</c><c class="t-keyword">$3</c>').replace(/:(root|host)/g,'<c class="t-comment">:</c><c class="t-keyword">$1</c>').replace(/([a-zA-Z\-]+):(\s?[^\n]+)/g,(t,e,c)=>(c.trim()!=="("&&!c.endsWith("</cc>;")&&(c=c.replace(/([^,;]*)([,;]?$)/,'<c class="t-num">$1</c><c class="t-comment">$2</c>')),`<c class="t-comment"><b>${e}</b>:</c>${c}`)).replace(/([,\{\}])/g,'<c class="t-comment">$1</c>').replace(/\b(in|from|to|throught)\b/g,'<c class="t-keyword">$1</c>').replace(/(&|@use|@each|@for)/g,'<c class="t-keyword">$1</c>').replace(/<cc class="t-str">(.*?)<\/cc>/g,(t,e)=>(e=e.replace(/<\/?\w+[^>]*?>/g,""),`<c class="t-str">${e}</c>`)),r}function x(r){let t={},e=160,c=a=>{for(let l in t)a.includes(l)&&(a=a.replace(l,t[l]),delete t[l]);return a};return r=r.replace(/html`(.*)`/g,(a,l)=>{let m="\uE736\uEA8B"+(e++).toString(16);return t[m]=`html\`${$(l)}\``,m}),r=r.replace(/html`([\w\W]*?)`/g,(a,l)=>{let m="\uE736\uEA8B"+(e++).toString(16);return t[m]=c(`html\`${$(l)}\``),m}),c(s(p(r)))}export{R as colorCss,$ as colorHtml,x as colorJs,O as colorMd};

18
dist/lib/ui/views/code/index.js vendored Normal file
View File

@ -0,0 +1,18 @@
import{html as t,raw as n,css as r,Component as s,nextTick as d}from"wkit";import{colorHtml as p,colorJs as h,colorCss as g,colorMd as b}from"./colorful.js";import"../../base/icon.js";import"../../modal/layer.js";function i(o){return o.trim().replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&")}class m extends s{static props={code:{type:String,default:"",attribute:!1,observer(e){this.setCode(e)}},lang:""};static styles=[r`:host{display:flex;border-radius:3px}.container{display:flex;flex-direction:column;position:relative;width:100%;margin:10px 0;padding-bottom:6px;border-radius:3px;background:#f7f8fb;color:var(--color-dark-1);box-shadow:0 1px 5px rgba(0,0,0,.1)}.container .title{flex-shrink:0;display:flex;justify-content:space-between;align-items:center;width:100%;height:32px;padding:0 12px;line-height:1;font-size:14px;user-select:none}.container .title section{display:flex;align-items:center}.container .title i{display:block;width:12px;height:12px;margin-right:6px;border-radius:50%;background:var(--color-red-1)}.container .title i:nth-child(2){background:var(--color-orange-1)}.container .title i:nth-child(3){background:var(--color-green-1)}.container .title .act{--wc-icon-size: 18px;margin:0 6px;color:var(--color-grey-2);cursor:pointer}.container .title .act:hover{color:var(--color-grey-3)}`,r`.code-block{display:flex;flex-direction:column;overflow:hidden;overflow-y:auto;line-height:20px;font-size:14px;color:var(--color-dark-1);cursor:text;counter-reset:code}.code-block>code{display:block;position:relative;min-height:20px;padding:0 8px 0 45px;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;white-space:pre-wrap;word-break:break-word}.code-block>code::before{position:absolute;left:0;width:40px;height:100%;padding-right:5px;text-align:right;color:var(--color-grey-1);content:counter(code);counter-increment:code}.code-block>code .t-tag,.code-block>code .t-keyword,.code-block>code .t-const{color:var(--color-red-2)}.code-block>code .t-attr,.code-block>code .t-fn,.code-block>code .t-var{color:var(--color-blue-2)}.code-block>code .t-str{color:var(--color-green-2)}.code-block>code .t-comment{color:var(--color-grey-2)}.code-block>code .t-type{font-weight:bold;color:var(--color-orange-1)}.code-block>code .t-num,.code-block>code .t-buildin{color:#a46ad3}.code-block>code .t-link{text-decoration:underline;color:var(--color-grey-2)}.code-block>code .t-buildin,.code-block>code .t-keyword,.code-block>code .t-type,.code-block>code .t-link,.code-block>code .t-comment{font-style:italic}`];#e=[];setCode(e,l){let a=this.lang,c=!1;switch(a){case"js":case"javascript":case"ts":case"typescript":e=h(e);break;case"html":case"xml":e=p(e);break;case"css":case"scss":case"less":c=!0,e=g(e);break;case"md":case"markdown":e=b(e);break}c===!1&&(e=e.replace(/<(\/?)(?!c)(\w+)([^>]*?)>/g,"&lt;$1$2$3>").replace(/<!(doctype)([^>]*?)>/gi,"&lt;$1$2>").replace(/<\?([^\?>]*?)\?>/g,"&lt;?$1?>").replace(/<\!\-\-([^>]*?)\-\->/g,"&lt;!--$1--&gt;")),this.#e=e.split(`
`)}copyCode(){if(navigator.clipboard)navigator.clipboard.writeText(this.code);else{let e=document.createElement("textarea");e.style.position="fixed",e.style.left="-2000px",e.value=this.code,this.root.appendChild(e),e.select(),document.execCommand("copy"),e.remove()}layer.toast("\u590D\u5236\u5230\u7C98\u8D34\u677F\u6210\u529F","success")}mounted(){var e=this.innerHTML||this.textContent;e=e.trim().replace(/^[\r\n]|\s{2,}$/g,""),e.startsWith("<xmp>")&&e.endsWith("</xmp>")?e=e.slice(6,-7):this.firstElementChild?.tagName==="TEXTAREA"?e=this.firstElementChild.value.trim():e.startsWith("<pre>")&&e.endsWith("</pre>")?e=i(e.slice(6,-7)):e=i(e),this.textContent="",e&&d(l=>{this.code=e})}render(){return t`
<main class="container">
<header class="title">
<section><i></i><i></i><i></i></section>
<section>${this.lang}</section>
<wc-icon
title="复制"
class="act"
name="doc"
@click=${this.copyCode}
></wc-icon>
</header>
<footer class="code-block">
${this.#e.map(e=>t`<code>${n(e)}</code>`)}
</footer>
</main>
`}}m.reg("code");

51
dist/lib/ui/views/markd/core.js vendored Normal file
View File

@ -0,0 +1,51 @@
const B=["=","-","_","*"],N=/^(([\+\-\*])|(\d+\.))\s/,O=/^[\+\-\*]\s\[(x|\s)\]\s/,K=/\\([-+*_`\]\[\(\)])/g,A=/^\[(\d+)\]: ([\S]+)\s*?((['"])[\s\S]*?\4)?\s*?$/,M=/<([\w\-]+)([\w\W]*?)>/g,j=/\s*?on[a-zA-Z]+="[^"]*?"\s*?/g,U=/```(.*?)([\w\W]*?)```/g,Y=/<([\w\-]+)([^>]*?)>([\w\W]*?)<\/\1>/g,Z=/<style[^>]*?>([\w\W]*?)<\/style>/g,D=/^\s*?<([\w\-]+)[^>]*?>.*?<\/\1>\s*?$/,G=/^\s*?<\/?[^>]*?>/,m={code:/`([^`]*?[^`\\\s])`/g,strong:[/__([\s\S]*?[^\s\\])__(?!_)/g,/\*\*([\s\S]*?[^\s\\])\*\*(?!\*)/g],em:[/_([\s\S]*?[^\s\\])_(?!_)/g,/\*([\s\S]*?[^\s\\*])\*(?!\*)/g],del:/~~([\s\S]*?[^\s\\~])~~/g,qlink:/\[([^\]]*?)\]\[(\d*?)\]/g,img:/\!\[([^\]]*?)\]\(([^)]*?)\)/g,a:/\[([^\]]*?)\]\(([^)]*?)(\s+"([\s\S]*?)")*?\)/g,qlist:/((<blockquote class="md\-quote">)*?)([\+\-\*]|\d+\.) (.*)/},w={isHr(s){var e=s[0];return B.includes(e)?s.trim()===e.repeat(3):!1},isList(s){var e=s.trim();if(N.test(e)){var l=+e[0];return l===l?1:0}return-1},isTodo(s){var e=s.trim();return O.test(e)?e[3]==="x"?1:0:-1},ltrim(s){return s.trimStart?s.trimStart():s.replace(/^\s+/,"")},isQLink(s){return A.test(s)?{[RegExp.$1]:{l:RegExp.$2,t:RegExp.$3}}:!1},isTable(s){return/^\|.+?\|$/.test(s)}},R={inline(s){return s.replace(m.code,(e,l)=>(l=l.replace(/([_*~])/g,"\\$1"),`<code class="inline">${l}</code>`)).replace(m.strong[0],"<strong>$1</strong>").replace(m.strong[1],"<strong>$1</strong>").replace(m.em[0],"<em>$1</em>").replace(m.em[1],"<em>$1</em>").replace(m.del,"<del>$1</del>").replace(m.img,'<img src="$2" alt="$1">').replace(m.a,(e,l,n,r,a="")=>{var h=a.split(";").filter(p=>p).map(p=>{var i=p.split("=");return i.length>1?`${i[0]}="${i[1]}"`:`title="${p}"`}).join(" ");return`<a href="${n.trim()}" ${h}>${l}</a>`}).replace(m.qlink,(e,l,n)=>{var r=this.__LINKS__[n];if(r){var a=r.t?`title=${r.t}`:"";return`<a href="${r.l}" ${a}>${l}</a>`}else return e}).replace(K,"$1")},hr(){return`
<hr>
`},head(s){return s.startsWith("#")?s.replace(/^(#{1,6}) (.*)/,(e,l,n)=>{n=n.trim();let r=l.trim().length,a=n.replace(/\s/g,"").replace(/<\/?[^>]*?>/g,"");return r===1?`<h1>${n}</h1>`:`
<h${r}><a href="#${a}" id="${a}" class="md-head-link">${n}</a></h${r}>
`}):!1},task(s){var e=w.isTodo(s);if(~e){var l=s.replace(O,"").trim(),n=e===1?"checked":"",r=e===1?`<del>${l}</del>`:l;return`
<section><wc-checkbox readonly ${n}>${r}</wc-checkbox></section>`}return!1}};function P(s){return s.replace(/\r\n|\r/g,`
`).replace(/\t/g," ").replace(/\u00a0/g," ").replace(/\u2424/g,`
`)}function T(s){return s.endsWith("<br>")?s.slice(0,-4):s}class z{constructor(e,l){this.list=e,this.__LINKS__=l}static init(e=""){let l={},n=[],r=P(e).split(`
`),a=!1,h=!1,p=0;for(let u of r){let f=u.trim();if(f)if(p=0,f.startsWith("```"))a?n.push(`
</xmp></wc-code>
`):n.push(f.replace(/^```([\w\#\-]*?)$/,`
<wc-code lang="$1"><xmp>`)),a=!a;else{var i;if(a)u=u.replace("\\`\\`\\`","```").replace(/<(\/?)xmp>/g,"&lt;$1xmp&gt;");else if(w.isTable(f)&&!h){var E=f.split("|");E.shift(),E.pop(),n.push(`
<table>
<thead><tr>${E.map($=>`<th>${$}</th>`).join("")}</tr></thead>
<tbody>`),h=!0;continue}else u=u.replace(m.code,($,b)=>`\`${b.replace(/</g,"&lt;").replace(/>/g,"&gt;")}\``).replace(/<(\/?)script[^>]*?>/g,"&lt;$1script&gt;").replace(M,($,b,k="")=>(k=k.replace(j," ").trim(),k&&(k=" "+k),`<${b}${k}>`)),i=w.isQLink(u);i?Object.assign(l,i):n.push(u)}else{if(n.length===0)continue;if(h){h=!1,n.push(`</tbody>
</table>
`);continue}(a||p<2)&&(p++,n.push(f))}}return new this(n,l)}parse(){let e="",l=!1,n=0,r=!1,a=!1,h=null,p=0,i=!1,E=!1,u=null,f=!1,$=[],b=!1,k=0,_=!1;for(let t of this.list)if(t){let I=n;if(n=0,~t.indexOf("<table>")||~t.indexOf("</table>")){f?a?e+=t+`${" ".repeat($.length)}</li>
`:e=e.replace(/<\/li>\n*?$/,"")+t:e+=t,a=!a,h=!0,_=!1;continue}if(a){let g=t.split("|").map(c=>c.trim());if(g.shift(),g.pop(),h===!0){h=g.map(c=>(c=c.split(/\-+/),c[0]===":"&&c[1]===":"?'align="center"':c[1]===":"?'align="right"':""));continue}e+=`<tr>${g.map((c,L)=>`<td ${h[L]}>${R.inline.call(this,c)}</td>`).join("")}</tr>`;continue}if(t.includes("<wc-code")||t.includes("wc-code>")){i&&(i=!1,e+=`</p>
`),f?l?e+=t+`${" ".repeat($.length)}</li>
`:e=e.replace(/<\/li>\n*?$/,"")+t:e+=t,l=!l,_=!1;continue}if(l){e+=`
`+t;continue}if(w.isHr(t)){e+=R.hr();continue}let q=D.test(t),Q=!q&&G.test(t);t=R.inline.call(this,t);let y=R.head(t);if(y){e=T(e),i&&(i=!1,e+="</p>"),f&&(e=this.#e(e,$,i),f=!1),_=!1,e+=y;continue}if(t.startsWith(">")){let g;t=t.replace(/^(>+) /,(L,S)=>{let o=S.length,d="",v=o;for(r&&(v=o-p);v>0;)v--,d+=`
<blockquote class="md-quote">`;return p=o,g=!!d,d}),i&&(i=!1,e=T(e),e+=`</p>
`),r&&g&&b&&(e+=`</${u}>
`,b=!1);let c=t.match(m.qlist);if(c){let L=c[1],S=+c[3],o=c.pop(),d=S===S?1:2;var x="";b===!1&&(b=!0,d===1?u="ol":u="ul",x+=`
<${u}>`),k=d,x+=`<li>${o}</li>`,e+=L+x,E=!0}else g===!1&&(e+="<br>"),e+=t;_=!1,i=!1,r=!0;continue}let C=R.task(t);if(C){e+=C,_=!1;continue}let H=w.isList(t);if(~H){let g=w.ltrim(t),c=t.length-g.length,L=g.replace(N,"").trim(),S=$.length-1,o=Math.floor(c/2),d=H===1?"ol":"ul";if(i&&(i=!1,e=T(e),e+=`</p>
`),f)if(o>S)$.push(d),e=e.trim().replace(/<\/li>$/,""),e+=`
${" ".repeat(o+1)}<${d}>
${" ".repeat(o+1)}<li>${L}</li>
`;else if(o===S)e+=`${" ".repeat(o+1)}<li>${L}</li>
`;else{for(let v=S-o;v>0;v--){let W=$.pop();e+=`${" ".repeat(o+v+1)}</${W}>
${" ".repeat(o+v)}</li>
`}e+=`${" ".repeat(o+1)}<li>${L}</li>
`}else $.push(d),e+=`<${d}>
<li>${L}</li>
`;f=!0,_=!1;continue}if(r){E?e=e.replace(/<\/li>\n*?$/,"")+` ${t}</li>`:e+=" "+t;continue}if(_||q)i&&(i=!1,e=T(e),e+="</p>"),e+=`${t}
`;else if(Q)i&&(i=!1,e=T(e),e+="</p>"),_=!_,e+=`${t}
`;else{if(f)if(i)if(I>0){e=T(e),e+=`<br>${t}`;continue}else e+=` ${t}`;else if(I>0)e=e.replace(/<\/li>\n*?$/,"")+`<p>${t}`;else{e=e.replace(/<\/li>\n*?$/,"")+` ${t}</li>
`;continue}else i?e+=` ${t}
`:e+=`
<p>${t}`;i=!0}}else l?e+=t+`
`:(n++,r&&(E&&(e+=`
</${u}>
`,E=!1),e=this.#t(e,p),r=!1,p=0),f&&n>1&&(e=this.#e(e,$,i),f=!1,n=0,i&&(i=!1)),i&&(n>1?(n=0,i=!1,e=T(e),e+=`</p>
`):e+="<br>"));return r&&(e=this.#t(e,p),p=0),f&&(e=this.#e(e,$,i),i&&(i=!1)),i&&(e+="</p>"),delete this.list,delete this.__LINKS__,e.trim()}#e(e,l,n){for(n&&(e=T(e),e+=`</p>
`);l.length;){let r=l.pop();e+=`${" ".repeat(l.length?l.length+1:0)}</${r}>
`,l.length&&(e+=`${" ".repeat(l.length)}</li>
`)}return e}#t(e,l){for(;l>0;)l--,e+=`</blockquote>
`;return e}}function F(s){return z.init(s).parse()}export{F as default};

1
dist/lib/ui/views/markd/index.js vendored Normal file
View File

@ -0,0 +1 @@
import{css as e,html as r,raw as l,Component as t}from"wkit";import o from"./core.js";import"../code/index.js";import"../../form/checkbox.js";var m=o;class a extends t{static props={code:{type:String,default:"",attribute:!1}};static styles=e`:host{display:block;line-height:1.5;color:var(--color-dark-1);font-size:14px}a{text-decoration:underline;color:var(--color-teal-2)}a:hover{color:var(--color-teal-1);text-decoration:none}em,del{color:var(--color-grey-2)}strong,strong em,strong{color:var(--color-dark-3)}a strong,a em{color:inherit}em,strong,del{padding:0 2px}p{margin:12px 0}img{max-width:100%}blockquote.md-quote{margin:10px 0;padding:5px 10px;line-height:1.5;border-left:5px solid var(--color-teal-1);background:#f2faf7;color:var(--color-grey-2)}blockquote.md-quote p{margin:0}blockquote.md-quote>blockquote{margin:5px 0;padding:0 10px}hr{height:1px;margin:30px 0;border:0;border-top:1px dashed var(--color-plain-3)}ol{margin-left:1em;list-style:decimal outside none}ul{margin-left:1em;list-style:disc outside none}li{margin:.5em 0}li ol{margin-left:1em}li ul{margin-left:1em;list-style-type:circle}li ol ul,li ul ul{list-style-type:square}h1,h2,h3,h4,h5,h6{margin:15px 0;line-height:2;font-weight:bold;font-size:16px}h1 code.inline,h2 code.inline,h3 code.inline,h4 code.inline,h5 code.inline,h6 code.inline{background:none}h1 a,h2 a,h3 a,h4 a,h5 a,h6 a{text-decoration:none;color:#333}h3 a::before,h4 a::before,h5 a::before,h6 a::before{content:"∮ ";color:var(--color-teal-1);font-weight:normal}h1{margin:0 0 30px;font-size:24px;text-align:center}h2{margin:20px 0;font-size:22px;border-bottom:1px solid var(--color-plain-2)}h3{margin:20px 0 15px;font-size:20px}h4{font-size:18px}table{width:100%;border-spacing:0;border-collapse:collapse}table tr{background:#fff}table thead tr{background:var(--color-plain-1)}table th,table td{padding:6px 13px;border:1px solid var(--color-plain-2);vertical-align:middle}table th{font-weight:bold}table tr:nth-child(2n){background:#fcfdff}code.inline{display:inline;margin:0 2px;padding:0 2px;color:var(--color-red-1);background:var(--color-plain-1);border-radius:2px;font-family:Menlo,Monaco,Consolas,"Courier New",monospace}`;render(){return r`<div class="container">${l(o(this.code))}</div>`}}a.reg("markd");export{m as default};

34
dist/lib/ui/views/progress.js vendored Normal file
View File

@ -0,0 +1,34 @@
import{css as o,html as a,Component as n,styleMap as i}from"wkit";const c="line",l="circle",x="dashboard",r=50,t=2*Math.PI*r,h={circle:0,dashboard:-.25*t/2+"px"},d={circle:`${t}px, ${t}px`,dashboard:`${t*.75}px, ${t}px`};class v extends n{static props={value:{type:Number,default:0,observer(e){this.value=this.#t(e)}},type:c};static styles=[o`:host{display:flex}.container{position:relative;width:100%;-webkit-user-select:none;user-select:none;--line-width: var(--wc-progress-line-width, 6px);--base-color: var(--wc-progress-inactive-color, var(--color-plain-2))}.container[step="1"]{--wc-progress-active-color: var(--wc-progress-active-color-1)}.container[step="2"]{--wc-progress-active-color: var(--wc-progress-active-color-2)}.container[step="3"]{--wc-progress-active-color: var(--wc-progress-active-color-3)}.container[step="4"]{--wc-progress-active-color: var(--wc-progress-active-color-4)}.container[step="5"]{--wc-progress-active-color: var(--wc-progress-active-color-5)}`,o`:host([type=line]){width:100%}:host([type=line]) .progress-value{display:none;position:absolute;z-index:1;top:-32px;margin-left:-24px;padding:4px 8px;border-radius:4px;font-size:14px;text-align:center;background:var(--color-dark-2);color:#fff}:host([type=line]) .progress-value::after{display:block;position:absolute;left:50%;margin-left:-3px;width:6px;height:6px;background:var(--color-dark-2);content:"";transform:rotate(45deg)}:host([type=line]):host(:hover) .progress-value{display:block}.progress-bar{display:flex;width:100%;height:var(--line-width);border-radius:32px;background:var(--base-color)}.progress-bar .thumb{width:0;height:var(--line-width);border-radius:32px;background:var(--wc-progress-active-color, var(--color-teal-1));transition:width .5s ease}`,o`:host([type=circle]),:host([type=dashboard]){width:var(--wc-progress-size, 128px);height:var(--wc-progress-size, 128px)}:host([type=circle]) svg,:host([type=dashboard]) svg{color:var(--wc-progress-active-color)}:host([type=circle]) path,:host([type=dashboard]) path{fill:none;stroke-linecap:round;stroke-width:var(--line-width);transition:stroke-dasharray .5s ease}:host([type=circle]) text,:host([type=dashboard]) text{font-size:calc(var(--line-width)*4);fill:currentColor;text-anchor:middle;alignment-baseline:middle}`];get#e(){let e=this.type===l?-1:1;return`
M 64 64
m 0 ${e*r}
a ${r} ${r} 0 1 1 0 ${-2*e*r}
a ${r} ${r} 0 1 1 0 ${2*e*r}
`}get#r(){let e=this.type===l?1:.75;return`${t*e*(this.value/100)}px, ${t}px`}#t(e){return Math.max(0,Math.min(e,100))}#s(e){let s=h[this.type],p=d[this.type];return a`
<svg viewBox="0 0 128 128">
<path
d=${this.#e}
stroke="var(--base-color)"
stroke-dashoffset=${s}
stroke-dasharray=${p}
/>
<path
d=${this.#e}
opacity=${e>0?"":0}
stroke="currentColor"
stroke-dashoffset=${s}
stroke-dasharray=${this.#r}
/>
<text x="64" y="64">${e}%</text>
</svg>
`}#o(e){let s=e<2?2:e>98?98:e;return a`
<div class="progress-bar">
<mark class="thumb" style=${i({width:e+"%"})}></mark>
</div>
<div class="progress-value" style=${i({left:s+"%"})}>
${e}%
</div>
`}render(){let e=this.value,s=~~(e/20)||1;return a`
<main class="container" step=${s}>
${this.type===c?this.#o(e):this.#s(e)}
</main>
`}}v.reg("progress");

17
dist/lib/ui/views/result.js vendored Normal file
View File

@ -0,0 +1,17 @@
import{css as t,html as e,Component as i}from"wkit";import"../base/icon.js";class o extends i{static props={title:"str!",subTitle:"",type:"success",icon:""};static styles=[t`:host{display:inline-flex}:host([type=success]) .icon{background:var(--color-teal-1)}:host([type=warning]) .icon{background:var(--color-orange-1)}:host([type=error]) .icon{background:var(--color-red-1)}:host([type=info]) .icon{background:var(--color-blue-1)}.container{display:flex;align-items:center;flex-direction:column;text-align:center;max-width:440px;padding:36px 32px;line-height:1.5;font-size:14px;color:var(--color-dark-1)}.icon{display:flex;justify-content:center;align-items:center;width:52px;height:52px;line-height:1;border-radius:50%;background:var(--wc-result-icon-color, var(--color-dark-1));color:#fff}.title{margin-top:16px;font-size:18px}.sub-title{margin-top:6px}.extra{margin-top:12px}`];get#t(){return this.icon?this.icon:this.type==="success"?"get":this.type==="error"?"deny":this.type}render(){return e`
<main class="container">
<div class="icon">
<slot name="icon"><wc-icon name=${this.#t}></wc-icon></slot>
</div>
<h3 class="title">
<slot name="title">${this.title}</slot>
</h3>
<section class="sub-title">
<slot name="sub-title">${this.subTitle}</slot>
</section>
<cite class="extra"><slot></slot></cite>
</main>
`}}o.reg("result");

8
dist/lib/ui/views/tag.js vendored Normal file
View File

@ -0,0 +1,8 @@
import{css as o,html as r,Component as e}from"wkit";import"../base/icon.js";const c={type:"scale"};class a extends e{static props={closable:!1};static styles=[o`:host{display:inline-flex}.container{display:flex;align-items:center;width:auto;height:32px;padding:0 10px;gap:3px;font-size:var(--wc-tag-font, 12px);border:1px solid var(--wc-tag-border-color, var(--color-grey-1));border-radius:3px;background:var(--wc-tag-background, var(--color-plain-1));white-space:nowrap;-webkit-user-select:none;user-select:none}.close{padding:3px;display:inline-flex;--wc-icon-size: 8px;line-height:1;border-radius:50%;cursor:pointer}.close:hover{background:var(--color-grey-2);color:#fff}`,o`:host([size=s]) .container{height:20px;padding:0 6px}:host([size=m]) .container{height:24px;padding:0 8px}`,o`:host([type=primary]) .container{border-color:var(--color-teal-a);background:#ecf5ff;color:var(--color-teal-3)}:host([type=primary]) .close:hover{color:#fff;background:var(--color-teal-1)}:host([type=info]) .container{border-color:var(--color-blue-a);background:#ecf5ff;color:var(--color-blue-3)}:host([type=info]) .close:hover{color:#fff;background:var(--color-blue-1)}:host([type=success]) .container{border-color:var(--color-green-a);background:#f0f9eb;color:var(--color-green-3)}:host([type=success]) .close:hover{color:#fff;background:var(--color-green-1)}:host([type=warning]) .container{border-color:var(--color-orange-a);background:#fdf6ec;color:var(--color-orange-3)}:host([type=warning]) .close:hover{color:#fff;background:var(--color-orange-1)}:host([type=danger]) .container{border-color:var(--color-red-a);background:#fef0f0;color:var(--color-red-3)}:host([type=danger]) .close:hover{color:#fff;background:var(--color-red-1)}`];#o(){this.$refs.tag.$animate(!0).then(t=>this.remove()),this.$emit("close")}render(){return r`
<main class="container" ref="tag" #animation=${c}>
<slot></slot>
${this.closable?r`<span class="close" @click=${this.#o}
><wc-icon name="close"></wc-icon
></span>`:""}
</main>
`}}a.reg("tag");

1
dist/lib/ui/views/time.js vendored Normal file
View File

@ -0,0 +1 @@
import{css as u,Component as c}from"wkit";const a=60*1e3,s=a*60,$=s*6,o=s*24,f=o*2,g=o*7,i=new Date().setHours(0,0,0,0),D=new Date(new Date().getFullYear(),0,1,0,0,0,0),h=new Date(new Date().getFullYear()-1,0,1,0,0,0,0);class m extends c{static props={stamp:"num!0"};get#t(){let n=new Date().setMilliseconds(0),t=this.stamp||n,e;if((t+"").length===10&&(t*=1e3),e=new Date(t),this.title=e.toLocaleString(),t>n-a)return"\u521A\u521A";if(t>n-s)return`${~~(t/a)}\u5206\u949F\u524D`;if(t>n-$)return`${~~(t/s)}\u5C0F\u65F6\u524D`;if(t>=i-f){let r=e.getHours(),l=r<6?"\u51CC\u6668":r<12?"\u4E0A\u5348":r>18?"\u665A\u4E0A":"\u4E0B\u5348";return t>=i?`${l}${r%12}\u70B9${e.getMinutes()}\u5206`:t>=i-o?`\u6628\u5929${l}${r%12}\u70B9`:`\u524D\u5929${l}`}return t>=i-g?`${~~((n-t)/o)}\u5929\u524D`:t>D?`${e.getMonth()+1}\u6708${e.getDate()}\u65E5`:t>h?`\u53BB\u5E74${e.getMonth()+1}\u6708${e.getDate()}\u65E5`:`${e.getFullYear()}\u5E74${e.getMonth()+1}\u6708`}static styles=[u`:host{display:inline-flex;font-size:12px;color:var(--color-dark-1);-webkit-user-select:none;user-select:none;cursor:default}`];render(){return this.#t}}m.reg("time");

30
dist/router.js vendored Normal file
View File

@ -0,0 +1,30 @@
import { createRouter, createWebHistory } from 'wkitd'
import './views/home.js'
import './views/detail.js'
import './views/login.js'
import './views/about.js'
const router = createRouter({
history: createWebHistory(),
routes: [
{
path: '/',
name: 'wc-home'
},
{
path: '/about',
name: 'wc-about'
},
{
path: '/view/:id',
name: 'wc-detail'
},
{
path: '/login',
name: 'wc-login'
}
]
})
export default router

13
dist/store.js vendored Normal file
View File

@ -0,0 +1,13 @@
import { createStore } from 'wkitd'
export default createStore({
user: {},
stats: {
0: '❌已删除',
1: '🕒待审核中',
2: '✅正常',
9: '🙅🏻拒绝收录'
},
searchInput: '',
result: { version: '', versions: [], id: '' } // 搜索结果
})

0
dist/views/about.js vendored Normal file
View File

0
dist/views/detail.js vendored Normal file
View File

0
dist/views/home.js vendored Normal file
View File

0
dist/views/login.js vendored Normal file
View File

6
package.json Normal file
View File

@ -0,0 +1,6 @@
{
"name": "store.lite.ink",
"type": "module",
"scripts": {},
"devDependencies": {}
}