live2dapi-noa 2.4.1 → 2.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/autoload.js +1 -1
- package/css/left.css +30 -5
- package/css/left.min.css +1 -1
- package/css/right.css +30 -5
- package/css/right.min.css +1 -1
- package/docs/en/README.md +4 -4
- package/jsdelivr/random/autoload.js +1 -1
- package/jsdelivr/random/autoload.min.js +1 -1
- package/jsdelivr/random/waifu-tips.js +1 -1
- package/jsdelivr/sequential/autoload.js +1 -1
- package/jsdelivr/sequential/autoload.min.js +1 -1
- package/jsdelivr/sequential/waifu-tips.js +1 -1
- package/npm/random/autoload.js +1 -1
- package/npm/random/waifu-tips.js +1 -1
- package/npm/sequential/autoload.js +1 -1
- package/npm/sequential/waifu-tips.js +1 -1
- package/package.json +1 -1
- package/widget.mjs +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[English](https://github.com/nova1751/live2d-api/blob/main/docs/en/README.md) · **简体中文** · [在线图鉴](https://live2d-nova.vercel.app/catalog/) · [npm](https://www.npmjs.com/package/live2dapi-noa)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
在网页中加入可互动的少女前线角色。访客可以切换人物和装扮,点击角色时按模型配置播放动作、语音并显示台词。组件按需加载对应渲染器,根据每套造型的可见轮廓调整取景。台词气泡跟随人物上缘,工具栏靠人物右侧排列。图鉴较窄时,横向造型的工具栏移到人物上方靠右,给小队留出完整宽度。
|
|
6
6
|
|
|
7
7
|
## 快速接入
|
|
8
8
|
|
|
@@ -11,13 +11,13 @@
|
|
|
11
11
|
**中国大陆**
|
|
12
12
|
|
|
13
13
|
```html
|
|
14
|
-
<script type="module" src="https://cdn.jsdmirror.com/gh/nova1751/live2d-api@widget-2.4.
|
|
14
|
+
<script type="module" src="https://cdn.jsdmirror.com/gh/nova1751/live2d-api@widget-2.4.2/girls-frontline.mjs"></script>
|
|
15
15
|
```
|
|
16
16
|
|
|
17
17
|
**海外**
|
|
18
18
|
|
|
19
19
|
```html
|
|
20
|
-
<script type="module" src="https://cdn.jsdelivr.net/gh/nova1751/live2d-api@widget-2.4.
|
|
20
|
+
<script type="module" src="https://cdn.jsdelivr.net/gh/nova1751/live2d-api@widget-2.4.2/girls-frontline.mjs"></script>
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
快捷入口在视口宽度达到 768 CSS 像素时显示。首次访问默认展示一阶空袭妖精,后续访问恢复该站上次选择的造型。需要自定显示条件时可使用模块 API。
|
|
@@ -79,7 +79,7 @@ python -m http.server 8765 --bind 127.0.0.1 --directory ./models-offline
|
|
|
79
79
|
|
|
80
80
|
## 原版网页示例
|
|
81
81
|
|
|
82
|
-
<img src="https://raw.githubusercontent.com/nova1751/live2d-api/v2.4.
|
|
82
|
+
<img src="https://raw.githubusercontent.com/nova1751/live2d-api/v2.4.2/img/01.png" height="200" alt="红裙看板娘与台词气泡"> <img src="https://raw.githubusercontent.com/nova1751/live2d-api/v2.4.2/img/02.png" height="200" alt="黑裙看板娘与互动提示">
|
|
83
83
|
|
|
84
84
|
## 开发与发布
|
|
85
85
|
|
package/autoload.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/*! Live2D API | Generated from src/ | https://github.com/nova1751/live2d-api */
|
|
2
|
-
"use strict";(()=>{function v(e){return e.pathname.toLowerCase().endsWith(".model3.json")}function j(e,t){let s,o,i,c=0,a=!1;function p(){return s??(s=new Promise((n,d)=>{let r=document.createElement("script");r.src=e+"live2d.min.js",r.acceptCubism2=u=>{t=u,n(u)},r.onerror=()=>d(new Error("Failed to load "+r.src)),document.head.appendChild(r)}).catch(n=>{throw s=void 0,n}))}let l=(n,d,r)=>{let u=++c;o?.abort(),o=void 0,i=void 0,a=!1;let h=new URL(d,document.baseURI);if(!v(h))return t?t(n,d,r):p().then(g=>{if(c!==u)return;let R=g(n,d,r);return a&&g.hide?.(),R});t?.hide?.(),o=new AbortController;let{signal:w}=o;return import(e+"modern/renderer.mjs").then(async g=>{if(w.aborted)return;let R=await g.mountModern(document.getElementById(n),h.href,r?.coreUrl,w,r?.dialogue,r?.framing,r?.onPaint);w.aborted||(i=R,a&&i.pause())}).catch(g=>{if(!w.aborted)throw o=void 0,g})};return l.hide=()=>{a=!0,o?i?.pause():t?.hide?.()},l.show=n=>{a=!1,o?i?.resume():t?.show?.(n)},l.prepareInteraction=()=>!o&&!!t?.prepareInteraction?.(),l.capture=()=>(o&&i?.capture(),!!o),l}var M="2.4.
|
|
2
|
+
"use strict";(()=>{function v(e){return e.pathname.toLowerCase().endsWith(".model3.json")}function j(e,t){let s,o,i,c=0,a=!1;function p(){return s??(s=new Promise((n,d)=>{let r=document.createElement("script");r.src=e+"live2d.min.js",r.acceptCubism2=u=>{t=u,n(u)},r.onerror=()=>d(new Error("Failed to load "+r.src)),document.head.appendChild(r)}).catch(n=>{throw s=void 0,n}))}let l=(n,d,r)=>{let u=++c;o?.abort(),o=void 0,i=void 0,a=!1;let h=new URL(d,document.baseURI);if(!v(h))return t?t(n,d,r):p().then(g=>{if(c!==u)return;let R=g(n,d,r);return a&&g.hide?.(),R});t?.hide?.(),o=new AbortController;let{signal:w}=o;return import(e+"modern/renderer.mjs").then(async g=>{if(w.aborted)return;let R=await g.mountModern(document.getElementById(n),h.href,r?.coreUrl,w,r?.dialogue,r?.framing,r?.onPaint);w.aborted||(i=R,a&&i.pause())}).catch(g=>{if(!w.aborted)throw o=void 0,g})};return l.hide=()=>{a=!0,o?i?.pause():t?.hide?.()},l.show=n=>{a=!1,o?i?.resume():t?.show?.(n)},l.prepareInteraction=()=>!o&&!!t?.prepareInteraction?.(),l.capture=()=>(o&&i?.capture(),!!o),l}var M="2.4.2";var D="/gh/nova1751/live2d-api@cdn-b3ac5ae545e2/",U="https://cdn.jsdelivr.net",N=U+D,k=/\/gh\/nova1751\/live2d-api@widget-[^/]+\/?$/,W=/\/live2dapi-noa(?:@[^/]+)?\/?$/;function b(e){let t=new URL(e,document.baseURI);return W.test(t.pathname)?(t.pathname.endsWith("/")||(t.pathname+="/"),t.search=t.hash="",t):new URL(".",t)}function E(e){return/^https?:\/\//.test(e)&&/\/widget\.mjs(?:[?#]|$)/.test(e)?b(e):new URL(U+"/gh/nova1751/live2d-api@widget-"+M+"/")}function L(e){return(e.hostname==="cdn.jsdmirror.com"?e.origin:U)+"/gh/nova1751/live2d-api@catalog-0cb4f982723bf0f0/catalog/library.json"}function I(e){if(!(!W.test(e.pathname)&&!k.test(e.pathname)))return L(e)}var f=Symbol.for("live2dapi-noa.mounting"),y=new Map;function x(e,t){return new Promise((s,o)=>{e.onload=()=>s(),e.onerror=()=>{e.remove(),o(new Error(`Failed to load ${t}`))},document.head.appendChild(e)})}function C(e,t,s){if(!y.has(e)){let o=document.createElement("script");o.src=e,s&&(o.dataset.asteroidsUrl=s);let i=x(o,e).then(()=>{let c=window[t];if(typeof c!="function")throw new Error(`Missing export from ${e}`);return c}).catch(c=>{throw y.delete(e),c});y.set(e,i)}return y.get(e)}async function T(e,t,s,o){let{modelUrl:i,coreUrl:c,modelBaseUrl:a,catalogUrl:p,modelId:l,collection:n,locale:d}=t,r=document.createElement("link");r.rel="stylesheet",r.href=e+`css/${o}.css`;try{let[,,u]=await Promise.all([x(r,r.href),p||i&&v(new URL(i,document.baseURI))?window.loadlive2d=j(e):C(e+"live2d.min.js","loadlive2d"),C(e+`jsdelivr/${s}/waifu-tips.js`,"initWidget",e+"asteroids.js")]);document.body||await new Promise(h=>document.addEventListener("DOMContentLoaded",()=>h(),{once:!0})),document.getElementById("waifu-toggle")||u({cdnPath:e,collection:n,locale:d,catalogUrl:p&&new URL(p,document.baseURI).href,modelId:l,modelBaseUrl:a&&new URL(a,document.baseURI).href,waifuPath:e+(d==="en"?"waifu-tips.en.json":"waifu-tips.json"),modelUrl:i&&new URL(i,document.baseURI).href,coreUrl:c&&new URL(c,document.baseURI).href})}catch(u){throw r.remove(),u}}async function P({mode:e="sequential",position:t="left",baseUrl:s,modelUrl:o,coreUrl:i,modelBaseUrl:c,catalogUrl:a,modelId:p,collection:l,locale:n}={}){if(n&&n!=="en"&&n!=="zh-CN")throw new TypeError("Unsupported widget locale");if(!["random","sequential"].includes(e))throw new TypeError("Invalid Live2D mode");if(!["left","right"].includes(t))throw new TypeError("Invalid Live2D position");if(a&&o)throw new TypeError("Choose catalogUrl or modelUrl");let d=document;if(d[f])return d[f];if(document.getElementById("waifu-toggle"))return;let r=s===void 0?E(document.currentScript.src):new URL(s,document.baseURI);if(r.pathname.endsWith("/")||(r.pathname+="/"),r.search="",r.hash="",!a&&!o&&!c&&(a=l?L(r):I(r)),p&&!a)throw new TypeError("modelId requires a catalog");return d[f]=T(r.href,{modelUrl:o,coreUrl:i,modelBaseUrl:c,catalogUrl:a,modelId:p,collection:l,locale:n},e,t).catch(u=>{throw delete d[f],u}),d[f]}var m=document.currentScript;if(m&&window.innerWidth>=768){let{mode:e,position:t}=m.dataset;P({locale:m.dataset.locale==="en"?"en":"zh-CN",baseUrl:b(m.src),catalogUrl:m.dataset.catalogUrl,modelId:m.dataset.modelId,modelBaseUrl:m.dataset.modelBaseUrl,modelUrl:m.dataset.modelUrl,coreUrl:m.dataset.coreUrl,mode:e,position:t}).catch(s=>console.error("[Live2D]",s))}})();
|
package/css/left.css
CHANGED
|
@@ -32,14 +32,19 @@
|
|
|
32
32
|
z-index: 1;
|
|
33
33
|
}
|
|
34
34
|
#waifu.waifu-adaptive {
|
|
35
|
-
--waifu-
|
|
35
|
+
--waifu-rail: 44px;
|
|
36
|
+
--waifu-gap: 6px;
|
|
37
|
+
--waifu-side-space: calc(var(--waifu-rail) + var(--waifu-gap));
|
|
38
|
+
--waifu-top-tools: 0px;
|
|
39
|
+
--waifu-max-width: min(480px, calc(96vw - var(--waifu-side-space)));
|
|
36
40
|
--waifu-max-height: min(410px, 60vh);
|
|
37
|
-
width: min(var(--waifu-max-width), calc(var(--waifu-max-height) * var(--waifu-aspect, 1)));
|
|
38
|
-
|
|
41
|
+
--waifu-model-width: min(var(--waifu-max-width), calc(var(--waifu-max-height) * var(--waifu-aspect, 1)));
|
|
42
|
+
width: calc(var(--waifu-model-width) + var(--waifu-side-space));
|
|
43
|
+
height: calc(var(--waifu-model-width) / var(--waifu-aspect, 1));
|
|
39
44
|
}
|
|
40
45
|
.waifu-viewport {
|
|
41
46
|
position: absolute;
|
|
42
|
-
inset: 0;
|
|
47
|
+
inset: 0 var(--waifu-side-space) 0 0;
|
|
43
48
|
overflow: hidden;
|
|
44
49
|
}
|
|
45
50
|
.waifu-surface {
|
|
@@ -59,15 +64,35 @@
|
|
|
59
64
|
#waifu.waifu-adaptive #waifu-tips {
|
|
60
65
|
box-sizing: border-box;
|
|
61
66
|
z-index: 1;
|
|
62
|
-
|
|
67
|
+
top: auto;
|
|
68
|
+
bottom: calc(100% + var(--waifu-gap) + var(--waifu-top-tools));
|
|
69
|
+
left: 0;
|
|
70
|
+
right: var(--waifu-side-space);
|
|
71
|
+
width: min(320px, var(--waifu-model-width));
|
|
72
|
+
min-height: 0;
|
|
73
|
+
max-height: min(30vh, 160px);
|
|
74
|
+
margin: 0 auto;
|
|
75
|
+
overflow: auto;
|
|
76
|
+
overflow-wrap: anywhere;
|
|
77
|
+
word-break: normal;
|
|
78
|
+
}
|
|
79
|
+
#waifu.waifu-adaptive #waifu-tips.waifu-tips-active {
|
|
80
|
+
pointer-events: auto;
|
|
63
81
|
}
|
|
64
82
|
#waifu.waifu-adaptive #waifu-tool {
|
|
65
83
|
z-index: 2;
|
|
66
84
|
top: 0;
|
|
85
|
+
right: 0;
|
|
86
|
+
left: auto;
|
|
87
|
+
width: var(--waifu-rail);
|
|
67
88
|
max-height: 100%;
|
|
68
89
|
overflow-y: auto;
|
|
69
90
|
scrollbar-width: thin;
|
|
70
91
|
}
|
|
92
|
+
#waifu.waifu-adaptive #waifu-tool button {
|
|
93
|
+
width: 100%;
|
|
94
|
+
text-align: center;
|
|
95
|
+
}
|
|
71
96
|
#waifu:hover {
|
|
72
97
|
transform: translateY(0);
|
|
73
98
|
}
|
package/css/left.min.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
#waifu-toggle{border:0;background-color:#fa0;border-radius:5px;bottom:66px;color:#fff;cursor:pointer;font-size:12px;left:0;margin-left:-100px;padding:5px 2px 5px 5px;position:fixed;transition:margin-left 1s;width:60px;writing-mode:vertical-rl}#waifu-toggle.waifu-toggle-active{margin-left:-50px}#waifu-toggle.waifu-toggle-active:hover,#waifu-toggle:focus-visible{margin-left:-30px}#waifu{bottom:-1000px;line-height:0;margin-bottom:0;position:fixed;transform:translateY(3px);transition:transform .3s ease-in-out,bottom 3s ease-in-out;z-index:1}#waifu.waifu-adaptive{--waifu-max-width: min(480px, 96vw);--waifu-max-height: min(410px, 60vh)
|
|
1
|
+
#waifu-toggle{border:0;background-color:#fa0;border-radius:5px;bottom:66px;color:#fff;cursor:pointer;font-size:12px;left:0;margin-left:-100px;padding:5px 2px 5px 5px;position:fixed;transition:margin-left 1s;width:60px;writing-mode:vertical-rl}#waifu-toggle.waifu-toggle-active{margin-left:-50px}#waifu-toggle.waifu-toggle-active:hover,#waifu-toggle:focus-visible{margin-left:-30px}#waifu{bottom:-1000px;line-height:0;margin-bottom:0;position:fixed;transform:translateY(3px);transition:transform .3s ease-in-out,bottom 3s ease-in-out;z-index:1}#waifu.waifu-adaptive{--waifu-rail: 44px;--waifu-gap: 6px;--waifu-side-space: calc(var(--waifu-rail) + var(--waifu-gap));--waifu-top-tools: 0px;--waifu-max-width: min(480px, calc(96vw - var(--waifu-side-space)));--waifu-max-height: min(410px, 60vh);--waifu-model-width: min(var(--waifu-max-width), calc(var(--waifu-max-height) * var(--waifu-aspect, 1)));width:calc(var(--waifu-model-width) + var(--waifu-side-space));height:calc(var(--waifu-model-width) / var(--waifu-aspect, 1))}.waifu-viewport{position:absolute;inset:0 var(--waifu-side-space) 0 0;overflow:hidden}.waifu-surface{position:absolute;left:50%;bottom:0;transform:translate(-50%);width:max(100%,calc(100% / var(--waifu-aspect, 1)));aspect-ratio:1}.waifu-surface>div,.waifu-surface #live2d{display:block;width:100%;height:100%}#waifu.waifu-adaptive #waifu-tips{box-sizing:border-box;z-index:1;top:auto;bottom:calc(100% + var(--waifu-gap) + var(--waifu-top-tools));left:0;right:var(--waifu-side-space);width:min(320px,var(--waifu-model-width));min-height:0;max-height:min(30vh,160px);margin:0 auto;overflow:auto;overflow-wrap:anywhere;word-break:normal}#waifu.waifu-adaptive #waifu-tips.waifu-tips-active{pointer-events:auto}#waifu.waifu-adaptive #waifu-tool{z-index:2;top:0;right:0;left:auto;width:var(--waifu-rail);max-height:100%;overflow-y:auto;scrollbar-width:thin}#waifu.waifu-adaptive #waifu-tool button{width:100%;text-align:center}#waifu:hover{transform:translateY(0)}#waifu-tips{pointer-events:none;animation:shake 50s ease-in-out 5s infinite;background-color:#ecd9bc80;border:1px solid rgba(224,186,140,.62);border-radius:12px;box-shadow:0 3px 15px 2px #bf9e7633;font-size:14px;line-height:24px;margin:-30px 30px;min-height:75px;opacity:0;overflow:hidden;padding:5px 10px;position:absolute;text-overflow:ellipsis;transition:opacity 1s;width:280px;word-break:break-all;top:-60px}#waifu-tips.waifu-tips-active{opacity:1;transition:opacity .2s}#waifu-tips span{color:#09c}#live2d{cursor:grab;height:350px;position:relative;width:350px}#waifu canvas,#waifu-tool button,#waifu-toggle{user-select:none;-webkit-tap-highlight-color:transparent}#waifu canvas:focus:not(:focus-visible),#waifu-tool button:focus:not(:focus-visible),#waifu-toggle:focus:not(:focus-visible){outline:none;box-shadow:none}#waifu[data-model-loading] #live2d,#waifu[data-model-loading] .waifu-model-stage{opacity:0;pointer-events:none}#waifu .waifu-model-still{position:absolute;inset:0;width:100%;height:100%;pointer-events:none}#live2d:active{cursor:grabbing}#waifu-tool{color:#aaa;opacity:0;position:absolute;top:50px;transition:opacity 1s}#waifu:hover #waifu-tool,#waifu:focus-within #waifu-tool{opacity:1}#waifu-tool button{appearance:none;border:0;background:transparent;padding:0 4px;cursor:pointer;display:block;height:40px;text-align:center}#waifu-tool svg{fill:#7b8c9d;cursor:pointer;height:22px;transition:fill .3s}#waifu-tool svg:hover{fill:#0684bd}@keyframes shake{2%{transform:translate(.5px,-1.5px) rotate(-.5deg)}4%{transform:translate(.5px,1.5px) rotate(1.5deg)}6%{transform:translate(1.5px,1.5px) rotate(1.5deg)}8%{transform:translate(2.5px,1.5px) rotate(.5deg)}10%{transform:translate(.5px,2.5px) rotate(.5deg)}12%{transform:translate(1.5px,1.5px) rotate(.5deg)}14%{transform:translate(.5px,.5px) rotate(.5deg)}16%{transform:translate(-1.5px,-.5px) rotate(1.5deg)}18%{transform:translate(.5px,.5px) rotate(1.5deg)}20%{transform:translate(2.5px,2.5px) rotate(1.5deg)}22%{transform:translate(.5px,-1.5px) rotate(1.5deg)}24%{transform:translate(-1.5px,1.5px) rotate(-.5deg)}26%{transform:translate(1.5px,.5px) rotate(1.5deg)}28%{transform:translate(-.5px,-.5px) rotate(-.5deg)}30%{transform:translate(1.5px,-.5px) rotate(-.5deg)}32%{transform:translate(2.5px,-1.5px) rotate(1.5deg)}34%{transform:translate(2.5px,2.5px) rotate(-.5deg)}36%{transform:translate(.5px,-1.5px) rotate(.5deg)}38%{transform:translate(2.5px,-.5px) rotate(-.5deg)}40%{transform:translate(-.5px,2.5px) rotate(.5deg)}42%{transform:translate(-1.5px,2.5px) rotate(.5deg)}44%{transform:translate(-1.5px,1.5px) rotate(.5deg)}46%{transform:translate(1.5px,-.5px) rotate(-.5deg)}48%{transform:translate(2.5px,-.5px) rotate(.5deg)}50%{transform:translate(-1.5px,1.5px) rotate(.5deg)}52%{transform:translate(-.5px,1.5px) rotate(.5deg)}54%{transform:translate(-1.5px,1.5px) rotate(.5deg)}56%{transform:translate(.5px,2.5px) rotate(1.5deg)}58%{transform:translate(2.5px,2.5px) rotate(.5deg)}60%{transform:translate(2.5px,-1.5px) rotate(1.5deg)}62%{transform:translate(-1.5px,.5px) rotate(1.5deg)}64%{transform:translate(-1.5px,1.5px) rotate(1.5deg)}66%{transform:translate(.5px,2.5px) rotate(1.5deg)}68%{transform:translate(2.5px,-1.5px) rotate(1.5deg)}70%{transform:translate(2.5px,2.5px) rotate(.5deg)}72%{transform:translate(-.5px,-1.5px) rotate(1.5deg)}74%{transform:translate(-1.5px,2.5px) rotate(1.5deg)}76%{transform:translate(-1.5px,2.5px) rotate(1.5deg)}78%{transform:translate(-1.5px,2.5px) rotate(.5deg)}80%{transform:translate(-1.5px,.5px) rotate(-.5deg)}82%{transform:translate(-1.5px,.5px) rotate(-.5deg)}84%{transform:translate(-.5px,.5px) rotate(1.5deg)}86%{transform:translate(2.5px,1.5px) rotate(.5deg)}88%{transform:translate(-1.5px,.5px) rotate(1.5deg)}90%{transform:translate(-1.5px,-.5px) rotate(-.5deg)}92%{transform:translate(-1.5px,-1.5px) rotate(1.5deg)}94%{transform:translate(.5px,.5px) rotate(-.5deg)}96%{transform:translate(2.5px,-.5px) rotate(-.5deg)}98%{transform:translate(-1.5px,-1.5px) rotate(-.5deg)}0%,to{transform:translate(0) rotate(0)}}.waifu-sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%)}#waifu-tool button:focus-visible,#waifu-toggle:focus-visible{outline:2px solid #126381;outline-offset:2px}@media(hover:none){#waifu-tool{opacity:1}#waifu-tool button{min-width:44px;min-height:44px}}@media(prefers-reduced-motion:reduce){#waifu,#waifu-toggle,#waifu-tool,#waifu-tips,#waifu-tips.waifu-tips-active{animation:none;transition:none}}#waifu{left:0}#waifu-tool{right:10px}
|
package/css/right.css
CHANGED
|
@@ -32,14 +32,19 @@
|
|
|
32
32
|
z-index: 1;
|
|
33
33
|
}
|
|
34
34
|
#waifu.waifu-adaptive {
|
|
35
|
-
--waifu-
|
|
35
|
+
--waifu-rail: 44px;
|
|
36
|
+
--waifu-gap: 6px;
|
|
37
|
+
--waifu-side-space: calc(var(--waifu-rail) + var(--waifu-gap));
|
|
38
|
+
--waifu-top-tools: 0px;
|
|
39
|
+
--waifu-max-width: min(480px, calc(96vw - var(--waifu-side-space)));
|
|
36
40
|
--waifu-max-height: min(410px, 60vh);
|
|
37
|
-
width: min(var(--waifu-max-width), calc(var(--waifu-max-height) * var(--waifu-aspect, 1)));
|
|
38
|
-
|
|
41
|
+
--waifu-model-width: min(var(--waifu-max-width), calc(var(--waifu-max-height) * var(--waifu-aspect, 1)));
|
|
42
|
+
width: calc(var(--waifu-model-width) + var(--waifu-side-space));
|
|
43
|
+
height: calc(var(--waifu-model-width) / var(--waifu-aspect, 1));
|
|
39
44
|
}
|
|
40
45
|
.waifu-viewport {
|
|
41
46
|
position: absolute;
|
|
42
|
-
inset: 0;
|
|
47
|
+
inset: 0 var(--waifu-side-space) 0 0;
|
|
43
48
|
overflow: hidden;
|
|
44
49
|
}
|
|
45
50
|
.waifu-surface {
|
|
@@ -59,15 +64,35 @@
|
|
|
59
64
|
#waifu.waifu-adaptive #waifu-tips {
|
|
60
65
|
box-sizing: border-box;
|
|
61
66
|
z-index: 1;
|
|
62
|
-
|
|
67
|
+
top: auto;
|
|
68
|
+
bottom: calc(100% + var(--waifu-gap) + var(--waifu-top-tools));
|
|
69
|
+
left: 0;
|
|
70
|
+
right: var(--waifu-side-space);
|
|
71
|
+
width: min(320px, var(--waifu-model-width));
|
|
72
|
+
min-height: 0;
|
|
73
|
+
max-height: min(30vh, 160px);
|
|
74
|
+
margin: 0 auto;
|
|
75
|
+
overflow: auto;
|
|
76
|
+
overflow-wrap: anywhere;
|
|
77
|
+
word-break: normal;
|
|
78
|
+
}
|
|
79
|
+
#waifu.waifu-adaptive #waifu-tips.waifu-tips-active {
|
|
80
|
+
pointer-events: auto;
|
|
63
81
|
}
|
|
64
82
|
#waifu.waifu-adaptive #waifu-tool {
|
|
65
83
|
z-index: 2;
|
|
66
84
|
top: 0;
|
|
85
|
+
right: 0;
|
|
86
|
+
left: auto;
|
|
87
|
+
width: var(--waifu-rail);
|
|
67
88
|
max-height: 100%;
|
|
68
89
|
overflow-y: auto;
|
|
69
90
|
scrollbar-width: thin;
|
|
70
91
|
}
|
|
92
|
+
#waifu.waifu-adaptive #waifu-tool button {
|
|
93
|
+
width: 100%;
|
|
94
|
+
text-align: center;
|
|
95
|
+
}
|
|
71
96
|
#waifu:hover {
|
|
72
97
|
transform: translateY(0);
|
|
73
98
|
}
|
package/css/right.min.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
#waifu-toggle{border:0;background-color:#fa0;border-radius:5px;bottom:66px;color:#fff;cursor:pointer;font-size:12px;left:0;margin-left:-100px;padding:5px 2px 5px 5px;position:fixed;transition:margin-left 1s;width:60px;writing-mode:vertical-rl}#waifu-toggle.waifu-toggle-active{margin-left:-50px}#waifu-toggle.waifu-toggle-active:hover,#waifu-toggle:focus-visible{margin-left:-30px}#waifu{bottom:-1000px;line-height:0;margin-bottom:0;position:fixed;transform:translateY(3px);transition:transform .3s ease-in-out,bottom 3s ease-in-out;z-index:1}#waifu.waifu-adaptive{--waifu-max-width: min(480px, 96vw);--waifu-max-height: min(410px, 60vh)
|
|
1
|
+
#waifu-toggle{border:0;background-color:#fa0;border-radius:5px;bottom:66px;color:#fff;cursor:pointer;font-size:12px;left:0;margin-left:-100px;padding:5px 2px 5px 5px;position:fixed;transition:margin-left 1s;width:60px;writing-mode:vertical-rl}#waifu-toggle.waifu-toggle-active{margin-left:-50px}#waifu-toggle.waifu-toggle-active:hover,#waifu-toggle:focus-visible{margin-left:-30px}#waifu{bottom:-1000px;line-height:0;margin-bottom:0;position:fixed;transform:translateY(3px);transition:transform .3s ease-in-out,bottom 3s ease-in-out;z-index:1}#waifu.waifu-adaptive{--waifu-rail: 44px;--waifu-gap: 6px;--waifu-side-space: calc(var(--waifu-rail) + var(--waifu-gap));--waifu-top-tools: 0px;--waifu-max-width: min(480px, calc(96vw - var(--waifu-side-space)));--waifu-max-height: min(410px, 60vh);--waifu-model-width: min(var(--waifu-max-width), calc(var(--waifu-max-height) * var(--waifu-aspect, 1)));width:calc(var(--waifu-model-width) + var(--waifu-side-space));height:calc(var(--waifu-model-width) / var(--waifu-aspect, 1))}.waifu-viewport{position:absolute;inset:0 var(--waifu-side-space) 0 0;overflow:hidden}.waifu-surface{position:absolute;left:50%;bottom:0;transform:translate(-50%);width:max(100%,calc(100% / var(--waifu-aspect, 1)));aspect-ratio:1}.waifu-surface>div,.waifu-surface #live2d{display:block;width:100%;height:100%}#waifu.waifu-adaptive #waifu-tips{box-sizing:border-box;z-index:1;top:auto;bottom:calc(100% + var(--waifu-gap) + var(--waifu-top-tools));left:0;right:var(--waifu-side-space);width:min(320px,var(--waifu-model-width));min-height:0;max-height:min(30vh,160px);margin:0 auto;overflow:auto;overflow-wrap:anywhere;word-break:normal}#waifu.waifu-adaptive #waifu-tips.waifu-tips-active{pointer-events:auto}#waifu.waifu-adaptive #waifu-tool{z-index:2;top:0;right:0;left:auto;width:var(--waifu-rail);max-height:100%;overflow-y:auto;scrollbar-width:thin}#waifu.waifu-adaptive #waifu-tool button{width:100%;text-align:center}#waifu:hover{transform:translateY(0)}#waifu-tips{pointer-events:none;animation:shake 50s ease-in-out 5s infinite;background-color:#ecd9bc80;border:1px solid rgba(224,186,140,.62);border-radius:12px;box-shadow:0 3px 15px 2px #bf9e7633;font-size:14px;line-height:24px;margin:-30px 30px;min-height:75px;opacity:0;overflow:hidden;padding:5px 10px;position:absolute;text-overflow:ellipsis;transition:opacity 1s;width:280px;word-break:break-all;top:-60px}#waifu-tips.waifu-tips-active{opacity:1;transition:opacity .2s}#waifu-tips span{color:#09c}#live2d{cursor:grab;height:350px;position:relative;width:350px}#waifu canvas,#waifu-tool button,#waifu-toggle{user-select:none;-webkit-tap-highlight-color:transparent}#waifu canvas:focus:not(:focus-visible),#waifu-tool button:focus:not(:focus-visible),#waifu-toggle:focus:not(:focus-visible){outline:none;box-shadow:none}#waifu[data-model-loading] #live2d,#waifu[data-model-loading] .waifu-model-stage{opacity:0;pointer-events:none}#waifu .waifu-model-still{position:absolute;inset:0;width:100%;height:100%;pointer-events:none}#live2d:active{cursor:grabbing}#waifu-tool{color:#aaa;opacity:0;position:absolute;top:50px;transition:opacity 1s}#waifu:hover #waifu-tool,#waifu:focus-within #waifu-tool{opacity:1}#waifu-tool button{appearance:none;border:0;background:transparent;padding:0 4px;cursor:pointer;display:block;height:40px;text-align:center}#waifu-tool svg{fill:#7b8c9d;cursor:pointer;height:22px;transition:fill .3s}#waifu-tool svg:hover{fill:#0684bd}@keyframes shake{2%{transform:translate(.5px,-1.5px) rotate(-.5deg)}4%{transform:translate(.5px,1.5px) rotate(1.5deg)}6%{transform:translate(1.5px,1.5px) rotate(1.5deg)}8%{transform:translate(2.5px,1.5px) rotate(.5deg)}10%{transform:translate(.5px,2.5px) rotate(.5deg)}12%{transform:translate(1.5px,1.5px) rotate(.5deg)}14%{transform:translate(.5px,.5px) rotate(.5deg)}16%{transform:translate(-1.5px,-.5px) rotate(1.5deg)}18%{transform:translate(.5px,.5px) rotate(1.5deg)}20%{transform:translate(2.5px,2.5px) rotate(1.5deg)}22%{transform:translate(.5px,-1.5px) rotate(1.5deg)}24%{transform:translate(-1.5px,1.5px) rotate(-.5deg)}26%{transform:translate(1.5px,.5px) rotate(1.5deg)}28%{transform:translate(-.5px,-.5px) rotate(-.5deg)}30%{transform:translate(1.5px,-.5px) rotate(-.5deg)}32%{transform:translate(2.5px,-1.5px) rotate(1.5deg)}34%{transform:translate(2.5px,2.5px) rotate(-.5deg)}36%{transform:translate(.5px,-1.5px) rotate(.5deg)}38%{transform:translate(2.5px,-.5px) rotate(-.5deg)}40%{transform:translate(-.5px,2.5px) rotate(.5deg)}42%{transform:translate(-1.5px,2.5px) rotate(.5deg)}44%{transform:translate(-1.5px,1.5px) rotate(.5deg)}46%{transform:translate(1.5px,-.5px) rotate(-.5deg)}48%{transform:translate(2.5px,-.5px) rotate(.5deg)}50%{transform:translate(-1.5px,1.5px) rotate(.5deg)}52%{transform:translate(-.5px,1.5px) rotate(.5deg)}54%{transform:translate(-1.5px,1.5px) rotate(.5deg)}56%{transform:translate(.5px,2.5px) rotate(1.5deg)}58%{transform:translate(2.5px,2.5px) rotate(.5deg)}60%{transform:translate(2.5px,-1.5px) rotate(1.5deg)}62%{transform:translate(-1.5px,.5px) rotate(1.5deg)}64%{transform:translate(-1.5px,1.5px) rotate(1.5deg)}66%{transform:translate(.5px,2.5px) rotate(1.5deg)}68%{transform:translate(2.5px,-1.5px) rotate(1.5deg)}70%{transform:translate(2.5px,2.5px) rotate(.5deg)}72%{transform:translate(-.5px,-1.5px) rotate(1.5deg)}74%{transform:translate(-1.5px,2.5px) rotate(1.5deg)}76%{transform:translate(-1.5px,2.5px) rotate(1.5deg)}78%{transform:translate(-1.5px,2.5px) rotate(.5deg)}80%{transform:translate(-1.5px,.5px) rotate(-.5deg)}82%{transform:translate(-1.5px,.5px) rotate(-.5deg)}84%{transform:translate(-.5px,.5px) rotate(1.5deg)}86%{transform:translate(2.5px,1.5px) rotate(.5deg)}88%{transform:translate(-1.5px,.5px) rotate(1.5deg)}90%{transform:translate(-1.5px,-.5px) rotate(-.5deg)}92%{transform:translate(-1.5px,-1.5px) rotate(1.5deg)}94%{transform:translate(.5px,.5px) rotate(-.5deg)}96%{transform:translate(2.5px,-.5px) rotate(-.5deg)}98%{transform:translate(-1.5px,-1.5px) rotate(-.5deg)}0%,to{transform:translate(0) rotate(0)}}.waifu-sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%)}#waifu-tool button:focus-visible,#waifu-toggle:focus-visible{outline:2px solid #126381;outline-offset:2px}@media(hover:none){#waifu-tool{opacity:1}#waifu-tool button{min-width:44px;min-height:44px}}@media(prefers-reduced-motion:reduce){#waifu,#waifu-toggle,#waifu-tool,#waifu-tips,#waifu-tips.waifu-tips-active{animation:none;transition:none}}#waifu{right:0}#waifu-tool{left:10px}
|
package/docs/en/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
**English** · [简体中文](https://github.com/nova1751/live2d-api/blob/main/README.md) · [Live gallery](https://live2d-nova.vercel.app/catalog/?lang=en) · [npm](https://www.npmjs.com/package/live2dapi-noa)
|
|
4
4
|
|
|
5
|
-
Add an interactive Girls’ Frontline character to a website. Visitors can change outfits and click characters to play their authored motions, voice lines and subtitles. The widget loads the renderer required by the selected model and frames each outfit to its visible silhouette.
|
|
5
|
+
Add an interactive Girls’ Frontline character to a website. Visitors can change outfits and click characters to play their authored motions, voice lines and subtitles. The widget loads the renderer required by the selected model and frames each outfit to its visible silhouette. Captions sit above the model and controls sit beside it. On narrow gallery panels, wide groups keep the full preview width, with controls in a row above them.
|
|
6
6
|
|
|
7
7
|
## Quick start
|
|
8
8
|
|
|
@@ -11,13 +11,13 @@ Place one module script before `</body>`. Choose the CDN closest to your audienc
|
|
|
11
11
|
**Global**
|
|
12
12
|
|
|
13
13
|
```html
|
|
14
|
-
<script type="module" src="https://cdn.jsdelivr.net/gh/nova1751/live2d-api@widget-2.4.
|
|
14
|
+
<script type="module" src="https://cdn.jsdelivr.net/gh/nova1751/live2d-api@widget-2.4.2/girls-frontline.mjs?lang=en"></script>
|
|
15
15
|
```
|
|
16
16
|
|
|
17
17
|
**Mainland China**
|
|
18
18
|
|
|
19
19
|
```html
|
|
20
|
-
<script type="module" src="https://cdn.jsdmirror.com/gh/nova1751/live2d-api@widget-2.4.
|
|
20
|
+
<script type="module" src="https://cdn.jsdmirror.com/gh/nova1751/live2d-api@widget-2.4.2/girls-frontline.mjs?lang=en"></script>
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
The shortcut displays the widget on viewports at least 768 CSS pixels wide. A first visit starts with the tier-one Airstrike Fairy. Subsequent visits restore the last outfit on that site. Use the module API to set your own display rules.
|
|
@@ -79,7 +79,7 @@ Open `http://127.0.0.1:8765/viewer/catalog/?lang=en`. Use `--list` to inspect so
|
|
|
79
79
|
|
|
80
80
|
## Original widget examples
|
|
81
81
|
|
|
82
|
-
<img src="https://raw.githubusercontent.com/nova1751/live2d-api/v2.4.
|
|
82
|
+
<img src="https://raw.githubusercontent.com/nova1751/live2d-api/v2.4.2/img/01.png" height="200" alt="Original red-dress companion with a speech bubble"> <img src="https://raw.githubusercontent.com/nova1751/live2d-api/v2.4.2/img/02.png" height="200" alt="Original black-dress companion with interaction tips">
|
|
83
83
|
|
|
84
84
|
## Development and releases
|
|
85
85
|
|
|
@@ -8,7 +8,7 @@ const live2d_path = (() => {
|
|
|
8
8
|
return new URL("../../", url).href;
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
-
return "https://cdn.jsdelivr.net/gh/nova1751/live2d-api@widget-2.4.
|
|
11
|
+
return "https://cdn.jsdelivr.net/gh/nova1751/live2d-api@widget-2.4.2/";
|
|
12
12
|
})();
|
|
13
13
|
function loadExternalResource(url, type) {
|
|
14
14
|
let tag;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/*! Live2D API | Generated from src/ | https://github.com/nova1751/live2d-api */
|
|
2
|
-
"use strict";const live2d_path=(()=>{const e=document.currentScript;if(e?.src){const i=new URL(e.src);if(/\/(?:live2dapi-noa|gh\/nova1751\/live2d-api)(?:@[^/]+)?\/(?:npm|jsdelivr)\/(?:random|sequential)\/autoload(?:\.min)?\.js$/.test(i.pathname))return new URL("../../",i).href}return"https://cdn.jsdelivr.net/gh/nova1751/live2d-api@widget-2.4.
|
|
2
|
+
"use strict";const live2d_path=(()=>{const e=document.currentScript;if(e?.src){const i=new URL(e.src);if(/\/(?:live2dapi-noa|gh\/nova1751\/live2d-api)(?:@[^/]+)?\/(?:npm|jsdelivr)\/(?:random|sequential)\/autoload(?:\.min)?\.js$/.test(i.pathname))return new URL("../../",i).href}return"https://cdn.jsdelivr.net/gh/nova1751/live2d-api@widget-2.4.2/"})();function loadExternalResource(e,i){let n;if(i==="css"){const t=document.createElement("link");t.href=e,t.rel="stylesheet",n=t}else{const t=document.createElement("script");t.src=e,e===live2d_path+"jsdelivr/random/waifu-tips.js"&&(t.dataset.asteroidsUrl=live2d_path+"asteroids.js"),n=t}return new Promise((t,s)=>{n.onload=()=>t(e),n.onerror=()=>s(e),document.head.appendChild(n)})}screen.width>=768&&Promise.all([loadExternalResource(live2d_path+"live2d.min.js","js"),loadExternalResource(live2d_path+"jsdelivr/random/waifu-tips.js","js")]).then(async()=>{document.body||await new Promise(e=>document.addEventListener("DOMContentLoaded",()=>e(),{once:!0})),window.initWidget({tools:["hitokoto","asteroids","switch-model","switch-texture","photo","info","quit"],cdnPath:live2d_path,waifuPath:live2d_path+"waifu-tips.json"})}).catch(e=>console.error("[Live2D]",e));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*! Live2D API | Generated from src/ | https://github.com/nova1751/live2d-api */
|
|
2
|
-
"use strict";(()=>{var Y="zh-CN";function _(o){Y=o??"zh-CN"}function m(o,e){return Y==="en"?e:o}var G={hitokoto:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --><path d="M512 240c0 114.9-114.6 208-256 208c-37.1 0-72.3-6.4-104.1-17.9c-11.9 8.7-31.3 20.6-54.3 30.6C73.6 471.1 44.7 480 16 480c-6.5 0-12.3-3.9-14.8-9.9c-2.5-6-1.1-12.8 3.4-17.4l0 0 0 0 0 0 0 0 .3-.3c.3-.3 .7-.7 1.3-1.4c1.1-1.2 2.8-3.1 4.9-5.7c4.1-5 9.6-12.4 15.2-21.6c10-16.6 19.5-38.4 21.4-62.9C17.7 326.8 0 285.1 0 240C0 125.1 114.6 32 256 32s256 93.1 256 208z"/></svg>',asteroids:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --><path d="M498.1 5.6c10.1 7 15.4 19.1 13.5 31.2l-64 416c-1.5 9.7-7.4 18.2-16 23s-18.9 5.4-28 1.6L284 427.7l-68.5 74.1c-8.9 9.7-22.9 12.9-35.2 8.1S160 493.2 160 480V396.4c0-4 1.5-7.8 4.2-10.7L331.8 202.8c5.8-6.3 5.6-16-.4-22s-15.7-6.4-22-.7L106 360.8 17.7 316.6C7.1 311.3 .3 300.7 0 288.9s5.9-22.8 16.1-28.7l448-256c10.7-6.1 23.9-5.5 34 1.4z"/></svg>',"switch-model":'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --><path d="M399 384.2C376.9 345.8 335.4 320 288 320H224c-47.4 0-88.9 25.8-111 64.2c35.2 39.2 86.2 63.8 143 63.8s107.8-24.7 143-63.8zM0 256a256 256 0 1 1 512 0A256 256 0 1 1 0 256zm256 16a72 72 0 1 0 0-144 72 72 0 1 0 0 144z"/></svg>',"switch-texture":'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --><path d="M320 64A64 64 0 1 0 192 64a64 64 0 1 0 128 0zm-96 96c-35.3 0-64 28.7-64 64v48c0 17.7 14.3 32 32 32h1.8l11.1 99.5c1.8 16.2 15.5 28.5 31.8 28.5h38.7c16.3 0 30-12.3 31.8-28.5L318.2 304H320c17.7 0 32-14.3 32-32V224c0-35.3-28.7-64-64-64H224zM132.3 394.2c13-2.4 21.7-14.9 19.3-27.9s-14.9-21.7-27.9-19.3c-32.4 5.9-60.9 14.2-82 24.8c-10.5 5.3-20.3 11.7-27.8 19.6C6.4 399.5 0 410.5 0 424c0 21.4 15.5 36.1 29.1 45c14.7 9.6 34.3 17.3 56.4 23.4C130.2 504.7 190.4 512 256 512s125.8-7.3 170.4-19.6c22.1-6.1 41.8-13.8 56.4-23.4c13.7-8.9 29.1-23.6 29.1-45c0-13.5-6.4-24.5-14-32.6c-7.5-7.9-17.3-14.3-27.8-19.6c-21-10.6-49.5-18.9-82-24.8c-13-2.4-25.5 6.3-27.9 19.3s6.3 25.5 19.3 27.9c30.2 5.5 53.7 12.8 69 20.5c3.2 1.6 5.8 3.1 7.9 4.5c3.6 2.4 3.6 7.2 0 9.6c-8.8 5.7-23.1 11.8-43 17.3C374.3 457 318.5 464 256 464s-118.3-7-157.7-17.9c-19.9-5.5-34.2-11.6-43-17.3c-3.6-2.4-3.6-7.2 0-9.6c2.1-1.4 4.8-2.9 7.9-4.5c15.3-7.7 38.8-14.9 69-20.5z"/></svg>',photo:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --><path d="M220.6 121.2L271.1 96 448 96v96H333.2c-21.9-15.1-48.5-24-77.2-24s-55.2 8.9-77.2 24H64V128H192c9.9 0 19.7-2.3 28.6-6.8zM0 128V416c0 35.3 28.7 64 64 64H448c35.3 0 64-28.7 64-64V96c0-35.3-28.7-64-64-64H271.1c-9.9 0-19.7 2.3-28.6 6.8L192 64H160V48c0-8.8-7.2-16-16-16H80c-8.8 0-16 7.2-16 16l0 16C28.7 64 0 92.7 0 128zM168 304a88 88 0 1 1 176 0 88 88 0 1 1 -176 0z"/></svg>',info:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --><path d="M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512zM216 336h24V272H216c-13.3 0-24-10.7-24-24s10.7-24 24-24h48c13.3 0 24 10.7 24 24v88h8c13.3 0 24 10.7 24 24s-10.7 24-24 24H216c-13.3 0-24-10.7-24-24s10.7-24 24-24zm40-208a32 32 0 1 1 0 64 32 32 0 1 1 0-64z"/></svg>',quit:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --><path d="M342.6 150.6c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L192 210.7 86.6 105.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L146.7 256 41.4 361.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0L192 301.3 297.4 406.6c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L237.3 256 342.6 150.6z"/></svg>'};function E(o){return Array.isArray(o)?o[Math.floor(Math.random()*o.length)]:o}function L(o){return o.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}var B,H,A;function P(){clearTimeout(H),sessionStorage.removeItem("waifu-text"),document.getElementById("waifu-tips")?.classList.remove("waifu-tips-active")}function z(o,e){clearTimeout(H),sessionStorage.setItem("waifu-text",String(e));let t=document.getElementById("waifu-tips");t.innerHTML=o,t.classList.add("waifu-tips-active")}function v(o,e,t){!o||A||Number(sessionStorage.getItem("waifu-text"))>t||(z(E(o),t),H=setTimeout(P,e))}function J(o,e){if(!e){v(L(o),5e3,11);return}A=e,z(L(o),11)}function X(o){let e=document.getElementById("live2d");if(!e)return;let t=B?.find(({selector:n})=>e.closest(n)),i=t?E(t.text):B?void 0:m("指挥官,我在。","Right here, Commander.");i&&(A=o,z(i.replace("{text}",()=>L(e.textContent??"")),11))}function K(o,e){A===o&&(A=void 0,e?P():H=setTimeout(P,1200))}function de(o){if(location.pathname==="/"){let s=new Date().getHours();for(let{hour:a,text:r}of o){let[c,d=c]=a.split("-").map(Number);if(c<=s&&s<=d)return r}}let e=L(document.title.split(" - ")[0]),t=m(`欢迎阅读<span>「${e}」</span>`,`Welcome to <span>${e}</span>!`);if(!document.referrer)return t;let{hostname:i}=new URL(document.referrer);return i===location.hostname?t:m(`Hello!来自 <span>${L({baidu:"百度",so:"360搜索",google:"谷歌搜索"}[i.split(".")[1]]??i)}</span> 的朋友<br>${t}`,`Hello, visitor from <span>${L(i)}</span>!<br>${t}`)}function ue(o){let[e,t]=o.split("/").map(Number);return e*100+t}function Q(o){B=o.click;let e=[...o.message.default],t=new Date,i=(t.getMonth()+1)*100+t.getDate();for(let{date:u,text:p}of o.seasons){let[l,h=l]=u.split("-").map(ue);l<=i&&i<=h&&e.push(E(p).replace("{year}",String(t.getFullYear())))}let n=2e4,s=Date.now(),a;function r(){if(document.hidden)return;let u=n-(Date.now()-s);u<=0&&!localStorage.getItem("waifu-display")&&v(e,6e3,9),a=setTimeout(r,u>0?u:n)}let c=()=>{s=Date.now()};window.addEventListener("pointermove",c,{passive:!0}),window.addEventListener("pointerdown",c,{passive:!0}),window.addEventListener("keydown",c),document.hidden||(a=setTimeout(r,n)),v(de(o.time),7e3,11);let d;for(let u of["mouseover","click"])window.addEventListener(u,p=>{let l=p.target;if(!(l instanceof Element)||p.live2dHandlesCaption)return;let h=u==="click"&&l.closest("#waifu .waifu-model-stage"),w=h?document.getElementById("live2d"):l.closest("#live2d"),y=o[u].find(({selector:C})=>l.closest(C)||h&&w?.closest(C));!y||u==="mouseover"&&y.selector===d||(u==="mouseover"&&(d=y.selector),v(E(y.text).replace("{text}",()=>L(l.textContent??"")),4e3,u==="click"&&w?11:8))});let f=()=>{};f.toString=()=>(v(o.message.console,6e3,9),""),console.log("%c",f),window.addEventListener("copy",()=>v(o.message.copy,6e3,9)),document.addEventListener("visibilitychange",()=>{clearTimeout(a),document.hidden||(c(),a=setTimeout(r,n),localStorage.getItem("waifu-display")||v(o.message.visibilitychange,6e3,9))})}async function T(o){let e=await fetch(o);if(!e.ok)throw new Error(`Failed to load ${o} (HTTP ${e.status})`);return e.json()}var Z="/gh/nova1751/live2d-api@cdn-b3ac5ae545e2/",ee="https://cdn.jsdelivr.net",j=ee+Z,me=/\/gh\/nova1751\/live2d-api@widget-[^/]+\/?$/,ge=/\/live2dapi-noa(?:@[^/]+)?\/?$/;function te(o){let e=new URL(o,document.baseURI);return!ge.test(e.pathname)&&!me.test(e.pathname)||/@1\.[^/]+\/?$/.test(e.pathname)?o:(e.hostname==="cdn.jsdmirror.com"?e.origin:ee)+Z}var q=()=>m("我的新衣服好看嘛?","How do you like my new outfit?"),k=o=>Number(localStorage.getItem(o))||0,D=class{constructor(e){this.options=e;this.revision=0;this.loaded=!1;this.useCDN=typeof e.cdnPath=="string";let t=e.modelBaseUrl??(e.cdnPath&&te(e.cdnPath))??e.apiPath;if(typeof t!="string")throw new TypeError("Invalid initWidget argument");this.base=t.endsWith("/")?t:t+"/"}reopen(e){if(this.loaded)window.loadlive2d.show?.(e);else return this.load(void 0,void 0,void 0,e)}cancel(){this.revision++}async fetchCatalog(){let e=this.base+"model_list.json",t=await fetch(e);if(t.status===404&&!this.options.modelBaseUrl&&this.base!==j){let i=await T(j+"model_list.json");return this.base=j,i}if(!t.ok)throw new Error(`Failed to load ${e} (HTTP ${t.status})`);return t.json()}list(){return this.catalog??(this.catalog=this.fetchCatalog().catch(e=>{throw this.catalog=void 0,e}))}async load(e=k("modelId"),t=k("modelTexturesId"),i,n=!1,s=++this.revision,a=!1){let r;if(this.options.modelUrl)r=this.options.modelUrl;else if(this.useCDN){let{models:d}=await this.list();d[e]||(e=0);let f=d[e],u=Array.isArray(f)?f:[f];u[t]||(t=0);let p=a?u[t]:E(u);t=u.indexOf(p),r=this.base+"model/"+p+"/index.json"}else r=this.base+"get/?id="+e+"-"+t;if(s!==this.revision)return;let c=window.loadlive2d("live2d",r,{start:n,locale:this.options.locale,coreUrl:this.options.coreUrl});c&&await c,s===this.revision&&(this.options.modelUrl||(localStorage.setItem("modelId",String(e)),localStorage.setItem("modelTexturesId",String(t))),v(i,4e3,10),this.loaded=!0)}async costume(e){if(this.options.modelUrl||!this.useCDN)return;let t=++this.revision,i=k("modelId"),n=(await this.list()).models[i],a=(Array.isArray(n)?n:[n]).findIndex(r=>new URL(this.base+"model/"+r+"/index.json",document.baseURI).href===e);a>=0&&await this.load(i,a,q(),!1,t,!0)}async nextModel(e=!1){let t=++this.revision,i=k("modelId");if(this.useCDN){let{models:s,messages:a}=await this.list(),r=(i+1)%s.length;return this.load(r,0,m(a[r],"Ready for duty!"),e,t)}let{model:n}=await T(this.base+"switch/?id="+i);return this.load(n.id,0,n.message,e,t)}async nextTexture(e=!1){let t=++this.revision,i=k("modelId"),n=k("modelTexturesId");if(this.useCDN){let a=(await this.list()).models[i],r=Array.isArray(a)?a.length:1;return this.load(i,n,q(),e,t)}let{textures:s}=await T(this.base+"rand_textures/?id="+i+"-"+n);s.id===1&&n===1?v(m("我还没有其他衣服呢!","This is my only outfit so far!"),4e3,10):await this.load(i,s.id,q(),e,t)}};var $=class{constructor(){this.revision=0}begin(e){let t=document.getElementById("waifu"),i=t?.querySelector(".waifu-surface"),n=++this.revision;return t&&(this.still&&!this.still.isConnected&&(i??t).prepend(this.still),t.setAttribute("data-model-loading","")),s=>{if(this.revision!==n||!t)return;let a=document.createElement("canvas");a.className="waifu-model-still",a.setAttribute("aria-hidden","true"),a.width=s.width,a.height=s.height;try{let r=a.getContext("2d");r&&r.drawImage(s,0,0),this.still?.remove(),this.still=r?a:void 0}finally{i&&t.style.setProperty("--waifu-aspect",String(e())),t.removeAttribute("data-model-loading")}}}};var O={scale:1,x:0,y:0},g=128;function W(o,e,t){let i=0;for(let n=0;n<o.length;n++)if(i+=o[n],i>e*t)return n;return o.length-1}function fe(o,e,t,i){let n=new Float64Array(g),s=g,a=0,r=0;for(let x=0;x<o.length;x++){if(!o[x])continue;let M=Math.floor(x/g);n[x%g]+=o[x],r+=o[x],s=Math.min(s,M),a=Math.max(a,M+1)}if(!r)return O;let c=W(n,r,.001),d=W(n,r,.999)+1,f=d-c,u=a-s,p=i?Math.max(.7,Math.min(1.9,f/u*.93/.94)):1;i?.(p);let l=Math.min(1,p),h=Math.min(1,1/p),w=Math.min(.93*g*h/u,.94*g*l/f,5/e.scale),y=0,C=0;if(t)for(let x=s+2;x<a;x+=4)for(let M=c+2;M<d;M+=4){if(o[x*g+M]<96)continue;t((M+.5)/g,(x+.5)/g).some(le=>/^(head|face|body|bust|torso)\d*$/i.test(le))&&(y+=M+.5,C++)}let F=C>=3?y/C:W(n,r,.5)+.5,b=.475*g*l/w,U=Math.max(d-b,Math.min(c+b,F));return{scale:e.scale*w,x:(.5-U/g)*w,y:.5-.03*h+(.5-a/g)*w}}function oe(o){let e={scale:.65,x:0,y:0},t=document.createElement("canvas");t.width=t.height=g;let i=t.getContext("2d",{willReadFrequently:!0}),n=new Uint8Array(g*g),s=0,a=0,r=0;return{initial:e,measure(c,d){if(!i)return O;let f=performance.now();if(!(f<r)){s++;try{i.clearRect(0,0,g,g),i.drawImage(c,0,0,g,g);let{data:u}=i.getImageData(0,0,g,g),p=0;for(let l=0;l<n.length;l++){let h=u[4*l+3];h<24||(n[l]=Math.max(n[l],h),p++)}p>=16&&(a++,r=f+80)}catch{return O}if(!(a<3&&s<10))return a?fe(n,e,d,o):O}}}}var ne=["fairy","doll","adjutant","npc","squad","background"],ie=["default","normal","destroy"];function N(o,e){let t=o.indexOf(e);return t<0?o.length:t}function he(o,e){let t=new Intl.Collator("en",{numeric:!0}),i=o.map(n=>{let[s,a,r,c]=n.split("/"),d=e[[s,a,r].join("/")],f=r==="base"?-1:d??(s==="fairy"&&/^\d+$/.test(r)?Number(r):Number.MAX_SAFE_INTEGER);return{id:n,category:s,character:a,version:r,form:c,order:f}});return i.sort((n,s)=>N(ne,n.category)-N(ne,s.category)||t.compare(n.category,s.category)||t.compare(n.character,s.character)||n.order-s.order||t.compare(n.version,s.version)||N(ie,n.form)-N(ie,s.form)||t.compare(n.form,s.form)),i.map(n=>n.id)}async function se(o,e,t="zh-CN"){let i=new URL(o,document.baseURI),n=await fetch(i);if(!n.ok)throw new Error("Cannot load catalog: HTTP "+n.status);let s=await n.json();if(s.schemaVersion!==1||!s.models||!s.sources)throw new Error("Unsupported model catalog");let a=new Map,r=Object.keys(s.models).filter(l=>(!e||!l.startsWith("other/"))&&s.models[l].some(h=>h.manifest)),c=e?s.presentation:void 0,d=t==="en"?c?.en:c,f=l=>{let h=c?.aliases[l];return h&&r.includes(h)?h:l},u=e?he(r.filter(l=>f(l)===l),c?.outfitOrder??{}):r;function p(l,h){if(e&&!r.includes(l))throw new Error("Model outside the selected collection: "+l);let w=s.models[l]?.find(b=>b.manifest&&(!h||b.source===h));if(!w?.manifest)throw new Error("No model manifest for "+l);let y=new URL(s.sources[w.source].baseUrl,n.url||i);i.hostname==="cdn.jsdmirror.com"&&y.hostname==="cdn.jsdelivr.net"&&y.pathname.startsWith("/gh/nova1751/live2d-api@cdn-")&&(y.hostname=i.hostname);let C=b=>new URL(b.split("/").map(encodeURIComponent).join("/"),y).href,F;if(w.dialogue){let b=a.get(w.source);b||(b=new Map((s.audio?.[w.source]??[]).map(U=>[U.toUpperCase(),C(U)])),a.set(w.source,b)),F={captions:t==="en"?void 0:d?.captions,url:C(w.dialogue),audio:b}}return{captions:d?.captions,modelUrl:C(w.manifest),dialogue:F,soundAliases:w.soundAliases}}return{ids:u,visibleId:f,labels:d?.labels??{},resolve:p,legacyIds:s.legacyIds}}var R=class{constructor(e,t){this.url=e;this.options=t;this.sequence=0;this.transition=new $;let i=t.collection?":"+t.collection:"",n="live2d:model:"+e+i,s=a=>a.replace(/(\/gh\/nova1751\/live2d-api)@catalog-[a-f0-9]{16}(\/catalog\/library\.json:girls-frontline)$/,"$1$2");if(this.key=s(n),this.key!==n&&!localStorage.getItem(this.key)){let a=[n,...Object.keys(localStorage)].find(r=>s(r)===this.key&&localStorage.getItem(r));a&&localStorage.setItem(this.key,localStorage.getItem(a))}}open(){return this.library??(this.library=se(this.url,this.options.collection,this.options.locale).catch(e=>{throw this.library=void 0,e}))}async select(e,t){let i=++this.sequence,n=await this.open();if(i!==this.sequence)return;let s=e(n.ids,n.legacyIds,n.visibleId),{modelUrl:a,dialogue:r,soundAliases:c,captions:d}=n.resolve(s),f=1,u=this.options.collection==="girls-frontline"&&!s.startsWith("background/")?oe(l=>{f=l}):void 0,p=this.options.collection?this.transition.begin(()=>f):void 0;await window.loadlive2d("live2d",a,{start:t,locale:this.options.locale,captions:d,framing:u,onPaint:p,coreUrl:this.options.coreUrl,dialogue:r,soundAliases:c}),i===this.sequence&&(this.active=n.visibleId(s),localStorage.setItem(this.key,s),window.dispatchEvent(new CustomEvent("live2d:model",{detail:s})))}load(e,t,i,n=!1){return this.select((s,a,r)=>{let c=localStorage.getItem(this.key);if(this.options.collection)return this.options.modelId??(c&&s.includes(r(c))?c:s[0]);let d=a?.[Number(localStorage.getItem("modelId"))]?.[Number(localStorage.getItem("modelTexturesId"))];return this.options.modelId??(c&&s.includes(r(c))?c:d&&s.includes(d)?d:s[0])},n)}choose(e){return this.select(()=>e,!1)}cancel(){this.sequence++}reopen(e){if(this.active)window.loadlive2d.show?.(e);else return this.load(void 0,void 0,void 0,e)}character(e){return e.split("/").slice(0,2).join("/")}nextModel(e=!1){return this.select(t=>{let i=[...new Set(t.map(s=>this.character(s)))],n=i[(i.indexOf(this.character(this.active??""))+1)%i.length];return t.find(s=>this.character(s)===n)},e)}nextTexture(e=!1){return this.select(t=>{let i=t.filter(n=>this.character(n)===this.character(this.active??t[0]));{let n=i.filter(s=>s!==this.active);return n.length?n[Math.floor(Math.random()*n.length)]:i[0]}return i[(i.indexOf(this.active??"")+1)%i.length]},e)}async costume(e){let t=await this.open(),i=t.ids.find(n=>t.resolve(n).modelUrl===e);i&&await this.select(()=>i,!1)}};var pe=document.currentScript,we=pe?.dataset.asteroidsUrl??"https://cdn.jsdelivr.net/gh/nova1751/live2d-api@widget-2.4.1/asteroids.js",I=o=>document.getElementById(o);function S(o){console.error("[Live2D]",o);let e=document.getElementById("waifu-status");e&&(e.textContent=m("加载失败,请检查网络或切换模型后重试。","Could not load the model. Check your connection or try another character."),v(e.textContent,5e3,10))}async function ve(o){if(o==="en"){v(["One step at a time, Commander.","Even on a quiet day, there is something worth noticing."],6e3,9);return}let e=await T("https://v1.hitokoto.cn");v(L(e.hitokoto),6e3,9),setTimeout(()=>{v(`这句一言来自 <span>「${L(String(e.from))}」</span>,是 <span>${L(String(e.creator))}</span> 在 hitokoto.cn 投稿的。`,4e3,9)},6e3)}function ye(){if(window.Asteroids)(window.ASTEROIDSPLAYERS??(window.ASTEROIDSPLAYERS=[])).push(new window.Asteroids);else{let o=document.createElement("script");o.src=we,document.head.appendChild(o)}}var ae;function ce(){clearTimeout(ae),localStorage.removeItem("waifu-display"),I("waifu-toggle").setAttribute("tabindex","-1"),I("waifu-toggle").setAttribute("aria-expanded","true"),I("waifu").style.display="",setTimeout(()=>{I("waifu").style.bottom="0"},0)}function V(o){return o.isTrusted&&!!window.loadlive2d.prepareInteraction?.()}function be(){let o=I("waifu").contains(document.activeElement);window.loadlive2d.hide?.(),localStorage.setItem("waifu-display",String(Date.now())),v(m("愿你有一天能与重要的人重逢。","I hope you meet the people you miss again."),2e3,11),I("waifu").style.bottom="-500px",ae=setTimeout(()=>{I("waifu").style.display="none";let e=I("waifu-toggle");e.removeAttribute("tabindex"),e.setAttribute("aria-expanded","false"),e.classList.add("waifu-toggle-active"),o&&e.focus()},window.matchMedia("(prefers-reduced-motion: reduce)").matches?0:3e3)}function re(o,e,t=!1){sessionStorage.removeItem("waifu-text");let i=o.collection==="girls-frontline",n='<canvas id="live2d" width="800" height="800"></canvas>';document.body.insertAdjacentHTML("beforeend",`<div id="waifu" lang="${o.locale==="en"?"en":"zh-CN"}"${i?' class="waifu-adaptive"':""}>
|
|
2
|
+
"use strict";(()=>{var Y="zh-CN";function _(o){Y=o??"zh-CN"}function m(o,e){return Y==="en"?e:o}var G={hitokoto:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --><path d="M512 240c0 114.9-114.6 208-256 208c-37.1 0-72.3-6.4-104.1-17.9c-11.9 8.7-31.3 20.6-54.3 30.6C73.6 471.1 44.7 480 16 480c-6.5 0-12.3-3.9-14.8-9.9c-2.5-6-1.1-12.8 3.4-17.4l0 0 0 0 0 0 0 0 .3-.3c.3-.3 .7-.7 1.3-1.4c1.1-1.2 2.8-3.1 4.9-5.7c4.1-5 9.6-12.4 15.2-21.6c10-16.6 19.5-38.4 21.4-62.9C17.7 326.8 0 285.1 0 240C0 125.1 114.6 32 256 32s256 93.1 256 208z"/></svg>',asteroids:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --><path d="M498.1 5.6c10.1 7 15.4 19.1 13.5 31.2l-64 416c-1.5 9.7-7.4 18.2-16 23s-18.9 5.4-28 1.6L284 427.7l-68.5 74.1c-8.9 9.7-22.9 12.9-35.2 8.1S160 493.2 160 480V396.4c0-4 1.5-7.8 4.2-10.7L331.8 202.8c5.8-6.3 5.6-16-.4-22s-15.7-6.4-22-.7L106 360.8 17.7 316.6C7.1 311.3 .3 300.7 0 288.9s5.9-22.8 16.1-28.7l448-256c10.7-6.1 23.9-5.5 34 1.4z"/></svg>',"switch-model":'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --><path d="M399 384.2C376.9 345.8 335.4 320 288 320H224c-47.4 0-88.9 25.8-111 64.2c35.2 39.2 86.2 63.8 143 63.8s107.8-24.7 143-63.8zM0 256a256 256 0 1 1 512 0A256 256 0 1 1 0 256zm256 16a72 72 0 1 0 0-144 72 72 0 1 0 0 144z"/></svg>',"switch-texture":'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --><path d="M320 64A64 64 0 1 0 192 64a64 64 0 1 0 128 0zm-96 96c-35.3 0-64 28.7-64 64v48c0 17.7 14.3 32 32 32h1.8l11.1 99.5c1.8 16.2 15.5 28.5 31.8 28.5h38.7c16.3 0 30-12.3 31.8-28.5L318.2 304H320c17.7 0 32-14.3 32-32V224c0-35.3-28.7-64-64-64H224zM132.3 394.2c13-2.4 21.7-14.9 19.3-27.9s-14.9-21.7-27.9-19.3c-32.4 5.9-60.9 14.2-82 24.8c-10.5 5.3-20.3 11.7-27.8 19.6C6.4 399.5 0 410.5 0 424c0 21.4 15.5 36.1 29.1 45c14.7 9.6 34.3 17.3 56.4 23.4C130.2 504.7 190.4 512 256 512s125.8-7.3 170.4-19.6c22.1-6.1 41.8-13.8 56.4-23.4c13.7-8.9 29.1-23.6 29.1-45c0-13.5-6.4-24.5-14-32.6c-7.5-7.9-17.3-14.3-27.8-19.6c-21-10.6-49.5-18.9-82-24.8c-13-2.4-25.5 6.3-27.9 19.3s6.3 25.5 19.3 27.9c30.2 5.5 53.7 12.8 69 20.5c3.2 1.6 5.8 3.1 7.9 4.5c3.6 2.4 3.6 7.2 0 9.6c-8.8 5.7-23.1 11.8-43 17.3C374.3 457 318.5 464 256 464s-118.3-7-157.7-17.9c-19.9-5.5-34.2-11.6-43-17.3c-3.6-2.4-3.6-7.2 0-9.6c2.1-1.4 4.8-2.9 7.9-4.5c15.3-7.7 38.8-14.9 69-20.5z"/></svg>',photo:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --><path d="M220.6 121.2L271.1 96 448 96v96H333.2c-21.9-15.1-48.5-24-77.2-24s-55.2 8.9-77.2 24H64V128H192c9.9 0 19.7-2.3 28.6-6.8zM0 128V416c0 35.3 28.7 64 64 64H448c35.3 0 64-28.7 64-64V96c0-35.3-28.7-64-64-64H271.1c-9.9 0-19.7 2.3-28.6 6.8L192 64H160V48c0-8.8-7.2-16-16-16H80c-8.8 0-16 7.2-16 16l0 16C28.7 64 0 92.7 0 128zM168 304a88 88 0 1 1 176 0 88 88 0 1 1 -176 0z"/></svg>',info:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --><path d="M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512zM216 336h24V272H216c-13.3 0-24-10.7-24-24s10.7-24 24-24h48c13.3 0 24 10.7 24 24v88h8c13.3 0 24 10.7 24 24s-10.7 24-24 24H216c-13.3 0-24-10.7-24-24s10.7-24 24-24zm40-208a32 32 0 1 1 0 64 32 32 0 1 1 0-64z"/></svg>',quit:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --><path d="M342.6 150.6c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L192 210.7 86.6 105.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L146.7 256 41.4 361.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0L192 301.3 297.4 406.6c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L237.3 256 342.6 150.6z"/></svg>'};function E(o){return Array.isArray(o)?o[Math.floor(Math.random()*o.length)]:o}function L(o){return o.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}var B,H,k;function P(){clearTimeout(H),sessionStorage.removeItem("waifu-text"),document.getElementById("waifu-tips")?.classList.remove("waifu-tips-active")}function z(o,e){clearTimeout(H),sessionStorage.setItem("waifu-text",String(e));let t=document.getElementById("waifu-tips");t.innerHTML=o,t.classList.add("waifu-tips-active")}function v(o,e,t){!o||k||Number(sessionStorage.getItem("waifu-text"))>t||(z(E(o),t),H=setTimeout(P,e))}function J(o,e){if(!e){v(L(o),5e3,11);return}k=e,z(L(o),11)}function X(o){let e=document.getElementById("live2d");if(!e)return;let t=B?.find(({selector:n})=>e.closest(n)),i=t?E(t.text):B?void 0:m("指挥官,我在。","Right here, Commander.");i&&(k=o,z(i.replace("{text}",()=>L(e.textContent??"")),11))}function K(o,e){k===o&&(k=void 0,e?P():H=setTimeout(P,1200))}function de(o){if(location.pathname==="/"){let s=new Date().getHours();for(let{hour:a,text:r}of o){let[c,d=c]=a.split("-").map(Number);if(c<=s&&s<=d)return r}}let e=L(document.title.split(" - ")[0]),t=m(`欢迎阅读<span>「${e}」</span>`,`Welcome to <span>${e}</span>!`);if(!document.referrer)return t;let{hostname:i}=new URL(document.referrer);return i===location.hostname?t:m(`Hello!来自 <span>${L({baidu:"百度",so:"360搜索",google:"谷歌搜索"}[i.split(".")[1]]??i)}</span> 的朋友<br>${t}`,`Hello, visitor from <span>${L(i)}</span>!<br>${t}`)}function ue(o){let[e,t]=o.split("/").map(Number);return e*100+t}function Q(o){B=o.click;let e=[...o.message.default],t=new Date,i=(t.getMonth()+1)*100+t.getDate();for(let{date:u,text:p}of o.seasons){let[l,h=l]=u.split("-").map(ue);l<=i&&i<=h&&e.push(E(p).replace("{year}",String(t.getFullYear())))}let n=2e4,s=Date.now(),a;function r(){if(document.hidden)return;let u=n-(Date.now()-s);u<=0&&!localStorage.getItem("waifu-display")&&v(e,6e3,9),a=setTimeout(r,u>0?u:n)}let c=()=>{s=Date.now()};window.addEventListener("pointermove",c,{passive:!0}),window.addEventListener("pointerdown",c,{passive:!0}),window.addEventListener("keydown",c),document.hidden||(a=setTimeout(r,n)),v(de(o.time),7e3,11);let d;for(let u of["mouseover","click"])window.addEventListener(u,p=>{let l=p.target;if(!(l instanceof Element)||p.live2dHandlesCaption)return;let h=u==="click"&&l.closest("#waifu .waifu-model-stage"),w=h?document.getElementById("live2d"):l.closest("#live2d"),y=o[u].find(({selector:C})=>l.closest(C)||h&&w?.closest(C));!y||u==="mouseover"&&y.selector===d||(u==="mouseover"&&(d=y.selector),v(E(y.text).replace("{text}",()=>L(l.textContent??"")),4e3,u==="click"&&w?11:8))});let f=()=>{};f.toString=()=>(v(o.message.console,6e3,9),""),console.log("%c",f),window.addEventListener("copy",()=>v(o.message.copy,6e3,9)),document.addEventListener("visibilitychange",()=>{clearTimeout(a),document.hidden||(c(),a=setTimeout(r,n),localStorage.getItem("waifu-display")||v(o.message.visibilitychange,6e3,9))})}async function T(o){let e=await fetch(o);if(!e.ok)throw new Error(`Failed to load ${o} (HTTP ${e.status})`);return e.json()}var Z="/gh/nova1751/live2d-api@cdn-b3ac5ae545e2/",ee="https://cdn.jsdelivr.net",j=ee+Z,me=/\/gh\/nova1751\/live2d-api@widget-[^/]+\/?$/,ge=/\/live2dapi-noa(?:@[^/]+)?\/?$/;function te(o){let e=new URL(o,document.baseURI);return!ge.test(e.pathname)&&!me.test(e.pathname)||/@1\.[^/]+\/?$/.test(e.pathname)?o:(e.hostname==="cdn.jsdmirror.com"?e.origin:ee)+Z}var q=()=>m("我的新衣服好看嘛?","How do you like my new outfit?"),A=o=>Number(localStorage.getItem(o))||0,D=class{constructor(e){this.options=e;this.revision=0;this.loaded=!1;this.useCDN=typeof e.cdnPath=="string";let t=e.modelBaseUrl??(e.cdnPath&&te(e.cdnPath))??e.apiPath;if(typeof t!="string")throw new TypeError("Invalid initWidget argument");this.base=t.endsWith("/")?t:t+"/"}reopen(e){if(this.loaded)window.loadlive2d.show?.(e);else return this.load(void 0,void 0,void 0,e)}cancel(){this.revision++}async fetchCatalog(){let e=this.base+"model_list.json",t=await fetch(e);if(t.status===404&&!this.options.modelBaseUrl&&this.base!==j){let i=await T(j+"model_list.json");return this.base=j,i}if(!t.ok)throw new Error(`Failed to load ${e} (HTTP ${t.status})`);return t.json()}list(){return this.catalog??(this.catalog=this.fetchCatalog().catch(e=>{throw this.catalog=void 0,e}))}async load(e=A("modelId"),t=A("modelTexturesId"),i,n=!1,s=++this.revision,a=!1){let r;if(this.options.modelUrl)r=this.options.modelUrl;else if(this.useCDN){let{models:d}=await this.list();d[e]||(e=0);let f=d[e],u=Array.isArray(f)?f:[f];u[t]||(t=0);let p=a?u[t]:E(u);t=u.indexOf(p),r=this.base+"model/"+p+"/index.json"}else r=this.base+"get/?id="+e+"-"+t;if(s!==this.revision)return;let c=window.loadlive2d("live2d",r,{start:n,locale:this.options.locale,coreUrl:this.options.coreUrl});c&&await c,s===this.revision&&(this.options.modelUrl||(localStorage.setItem("modelId",String(e)),localStorage.setItem("modelTexturesId",String(t))),v(i,4e3,10),this.loaded=!0)}async costume(e){if(this.options.modelUrl||!this.useCDN)return;let t=++this.revision,i=A("modelId"),n=(await this.list()).models[i],a=(Array.isArray(n)?n:[n]).findIndex(r=>new URL(this.base+"model/"+r+"/index.json",document.baseURI).href===e);a>=0&&await this.load(i,a,q(),!1,t,!0)}async nextModel(e=!1){let t=++this.revision,i=A("modelId");if(this.useCDN){let{models:s,messages:a}=await this.list(),r=(i+1)%s.length;return this.load(r,0,m(a[r],"Ready for duty!"),e,t)}let{model:n}=await T(this.base+"switch/?id="+i);return this.load(n.id,0,n.message,e,t)}async nextTexture(e=!1){let t=++this.revision,i=A("modelId"),n=A("modelTexturesId");if(this.useCDN){let a=(await this.list()).models[i],r=Array.isArray(a)?a.length:1;return this.load(i,n,q(),e,t)}let{textures:s}=await T(this.base+"rand_textures/?id="+i+"-"+n);s.id===1&&n===1?v(m("我还没有其他衣服呢!","This is my only outfit so far!"),4e3,10):await this.load(i,s.id,q(),e,t)}};var $=class{constructor(){this.revision=0}begin(e){let t=document.getElementById("waifu"),i=t?.querySelector(".waifu-surface"),n=++this.revision;return t&&(this.still&&!this.still.isConnected&&(i??t).prepend(this.still),t.setAttribute("data-model-loading","")),s=>{if(this.revision!==n||!t)return;let a=document.createElement("canvas");a.className="waifu-model-still",a.setAttribute("aria-hidden","true"),a.width=s.width,a.height=s.height;try{let r=a.getContext("2d");r&&r.drawImage(s,0,0),this.still?.remove(),this.still=r?a:void 0}finally{if(i){let r=e();t.style.setProperty("--waifu-aspect",String(r)),t.toggleAttribute("data-wide-model",r>=1.35)}t.removeAttribute("data-model-loading")}}}};var O={scale:1,x:0,y:0},g=128;function W(o,e,t){let i=0;for(let n=0;n<o.length;n++)if(i+=o[n],i>e*t)return n;return o.length-1}function fe(o,e,t,i){let n=new Float64Array(g),s=g,a=0,r=0;for(let x=0;x<o.length;x++){if(!o[x])continue;let M=Math.floor(x/g);n[x%g]+=o[x],r+=o[x],s=Math.min(s,M),a=Math.max(a,M+1)}if(!r)return O;let c=W(n,r,.001),d=W(n,r,.999)+1,f=d-c,u=a-s,p=i?Math.max(.7,Math.min(1.9,f/u*.93/.94)):1;i?.(p);let l=Math.min(1,p),h=Math.min(1,1/p),w=Math.min(.93*g*h/u,.94*g*l/f,5/e.scale),y=0,C=0;if(t)for(let x=s+2;x<a;x+=4)for(let M=c+2;M<d;M+=4){if(o[x*g+M]<96)continue;t((M+.5)/g,(x+.5)/g).some(le=>/^(head|face|body|bust|torso)\d*$/i.test(le))&&(y+=M+.5,C++)}let F=C>=3?y/C:W(n,r,.5)+.5,b=.475*g*l/w,U=Math.max(d-b,Math.min(c+b,F));return{scale:e.scale*w,x:(.5-U/g)*w,y:.5-.03*h+(.5-a/g)*w}}function oe(o){let e={scale:.65,x:0,y:0},t=document.createElement("canvas");t.width=t.height=g;let i=t.getContext("2d",{willReadFrequently:!0}),n=new Uint8Array(g*g),s=0,a=0,r=0;return{initial:e,measure(c,d){if(!i)return O;let f=performance.now();if(!(f<r)){s++;try{i.clearRect(0,0,g,g),i.drawImage(c,0,0,g,g);let{data:u}=i.getImageData(0,0,g,g),p=0;for(let l=0;l<n.length;l++){let h=u[4*l+3];h<24||(n[l]=Math.max(n[l],h),p++)}p>=16&&(a++,r=f+80)}catch{return O}if(!(a<3&&s<10))return a?fe(n,e,d,o):O}}}}var ne=["fairy","doll","adjutant","npc","squad","background"],ie=["default","normal","destroy"];function N(o,e){let t=o.indexOf(e);return t<0?o.length:t}function he(o,e){let t=new Intl.Collator("en",{numeric:!0}),i=o.map(n=>{let[s,a,r,c]=n.split("/"),d=e[[s,a,r].join("/")],f=r==="base"?-1:d??(s==="fairy"&&/^\d+$/.test(r)?Number(r):Number.MAX_SAFE_INTEGER);return{id:n,category:s,character:a,version:r,form:c,order:f}});return i.sort((n,s)=>N(ne,n.category)-N(ne,s.category)||t.compare(n.category,s.category)||t.compare(n.character,s.character)||n.order-s.order||t.compare(n.version,s.version)||N(ie,n.form)-N(ie,s.form)||t.compare(n.form,s.form)),i.map(n=>n.id)}async function se(o,e,t="zh-CN"){let i=new URL(o,document.baseURI),n=await fetch(i);if(!n.ok)throw new Error("Cannot load catalog: HTTP "+n.status);let s=await n.json();if(s.schemaVersion!==1||!s.models||!s.sources)throw new Error("Unsupported model catalog");let a=new Map,r=Object.keys(s.models).filter(l=>(!e||!l.startsWith("other/"))&&s.models[l].some(h=>h.manifest)),c=e?s.presentation:void 0,d=t==="en"?c?.en:c,f=l=>{let h=c?.aliases[l];return h&&r.includes(h)?h:l},u=e?he(r.filter(l=>f(l)===l),c?.outfitOrder??{}):r;function p(l,h){if(e&&!r.includes(l))throw new Error("Model outside the selected collection: "+l);let w=s.models[l]?.find(b=>b.manifest&&(!h||b.source===h));if(!w?.manifest)throw new Error("No model manifest for "+l);let y=new URL(s.sources[w.source].baseUrl,n.url||i);i.hostname==="cdn.jsdmirror.com"&&y.hostname==="cdn.jsdelivr.net"&&y.pathname.startsWith("/gh/nova1751/live2d-api@cdn-")&&(y.hostname=i.hostname);let C=b=>new URL(b.split("/").map(encodeURIComponent).join("/"),y).href,F;if(w.dialogue){let b=a.get(w.source);b||(b=new Map((s.audio?.[w.source]??[]).map(U=>[U.toUpperCase(),C(U)])),a.set(w.source,b)),F={captions:t==="en"?void 0:d?.captions,url:C(w.dialogue),audio:b}}return{captions:d?.captions,modelUrl:C(w.manifest),dialogue:F,soundAliases:w.soundAliases}}return{ids:u,visibleId:f,labels:d?.labels??{},resolve:p,legacyIds:s.legacyIds}}var R=class{constructor(e,t){this.url=e;this.options=t;this.sequence=0;this.transition=new $;let i=t.collection?":"+t.collection:"",n="live2d:model:"+e+i,s=a=>a.replace(/(\/gh\/nova1751\/live2d-api)@catalog-[a-f0-9]{16}(\/catalog\/library\.json:girls-frontline)$/,"$1$2");if(this.key=s(n),this.key!==n&&!localStorage.getItem(this.key)){let a=[n,...Object.keys(localStorage)].find(r=>s(r)===this.key&&localStorage.getItem(r));a&&localStorage.setItem(this.key,localStorage.getItem(a))}}open(){return this.library??(this.library=se(this.url,this.options.collection,this.options.locale).catch(e=>{throw this.library=void 0,e}))}async select(e,t){let i=++this.sequence,n=await this.open();if(i!==this.sequence)return;let s=e(n.ids,n.legacyIds,n.visibleId),{modelUrl:a,dialogue:r,soundAliases:c,captions:d}=n.resolve(s),f=1,u=this.options.collection==="girls-frontline"&&!s.startsWith("background/")?oe(l=>{f=l}):void 0,p=this.options.collection?this.transition.begin(()=>f):void 0;await window.loadlive2d("live2d",a,{start:t,locale:this.options.locale,captions:d,framing:u,onPaint:p,coreUrl:this.options.coreUrl,dialogue:r,soundAliases:c}),i===this.sequence&&(this.active=n.visibleId(s),localStorage.setItem(this.key,s),window.dispatchEvent(new CustomEvent("live2d:model",{detail:s})))}load(e,t,i,n=!1){return this.select((s,a,r)=>{let c=localStorage.getItem(this.key);if(this.options.collection)return this.options.modelId??(c&&s.includes(r(c))?c:s[0]);let d=a?.[Number(localStorage.getItem("modelId"))]?.[Number(localStorage.getItem("modelTexturesId"))];return this.options.modelId??(c&&s.includes(r(c))?c:d&&s.includes(d)?d:s[0])},n)}choose(e){return this.select(()=>e,!1)}cancel(){this.sequence++}reopen(e){if(this.active)window.loadlive2d.show?.(e);else return this.load(void 0,void 0,void 0,e)}character(e){return e.split("/").slice(0,2).join("/")}nextModel(e=!1){return this.select(t=>{let i=[...new Set(t.map(s=>this.character(s)))],n=i[(i.indexOf(this.character(this.active??""))+1)%i.length];return t.find(s=>this.character(s)===n)},e)}nextTexture(e=!1){return this.select(t=>{let i=t.filter(n=>this.character(n)===this.character(this.active??t[0]));{let n=i.filter(s=>s!==this.active);return n.length?n[Math.floor(Math.random()*n.length)]:i[0]}return i[(i.indexOf(this.active??"")+1)%i.length]},e)}async costume(e){let t=await this.open(),i=t.ids.find(n=>t.resolve(n).modelUrl===e);i&&await this.select(()=>i,!1)}};var pe=document.currentScript,we=pe?.dataset.asteroidsUrl??"https://cdn.jsdelivr.net/gh/nova1751/live2d-api@widget-2.4.2/asteroids.js",I=o=>document.getElementById(o);function S(o){console.error("[Live2D]",o);let e=document.getElementById("waifu-status");e&&(e.textContent=m("加载失败,请检查网络或切换模型后重试。","Could not load the model. Check your connection or try another character."),v(e.textContent,5e3,10))}async function ve(o){if(o==="en"){v(["One step at a time, Commander.","Even on a quiet day, there is something worth noticing."],6e3,9);return}let e=await T("https://v1.hitokoto.cn");v(L(e.hitokoto),6e3,9),setTimeout(()=>{v(`这句一言来自 <span>「${L(String(e.from))}」</span>,是 <span>${L(String(e.creator))}</span> 在 hitokoto.cn 投稿的。`,4e3,9)},6e3)}function ye(){if(window.Asteroids)(window.ASTEROIDSPLAYERS??(window.ASTEROIDSPLAYERS=[])).push(new window.Asteroids);else{let o=document.createElement("script");o.src=we,document.head.appendChild(o)}}var ae;function ce(){clearTimeout(ae),localStorage.removeItem("waifu-display"),I("waifu-toggle").setAttribute("tabindex","-1"),I("waifu-toggle").setAttribute("aria-expanded","true"),I("waifu").style.display="",setTimeout(()=>{I("waifu").style.bottom="0"},0)}function V(o){return o.isTrusted&&!!window.loadlive2d.prepareInteraction?.()}function be(){let o=I("waifu").contains(document.activeElement);window.loadlive2d.hide?.(),localStorage.setItem("waifu-display",String(Date.now())),v(m("愿你有一天能与重要的人重逢。","I hope you meet the people you miss again."),2e3,11),I("waifu").style.bottom="-500px",ae=setTimeout(()=>{I("waifu").style.display="none";let e=I("waifu-toggle");e.removeAttribute("tabindex"),e.setAttribute("aria-expanded","false"),e.classList.add("waifu-toggle-active"),o&&e.focus()},window.matchMedia("(prefers-reduced-motion: reduce)").matches?0:3e3)}function re(o,e,t=!1){sessionStorage.removeItem("waifu-text");let i=o.collection==="girls-frontline",n='<canvas id="live2d" width="800" height="800"></canvas>';document.body.insertAdjacentHTML("beforeend",`<div id="waifu" lang="${o.locale==="en"?"en":"zh-CN"}"${i?' class="waifu-adaptive"':""}>
|
|
3
3
|
<div id="waifu-status" role="status" class="waifu-sr-only"></div>
|
|
4
4
|
<div id="waifu-tips"></div>
|
|
5
5
|
${i?`<div class="waifu-viewport"><div class="waifu-surface">${n}</div></div>`:n}
|
|
@@ -8,7 +8,7 @@ const live2d_path = (() => {
|
|
|
8
8
|
return new URL("../../", url).href;
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
-
return "https://cdn.jsdelivr.net/gh/nova1751/live2d-api@widget-2.4.
|
|
11
|
+
return "https://cdn.jsdelivr.net/gh/nova1751/live2d-api@widget-2.4.2/";
|
|
12
12
|
})();
|
|
13
13
|
function loadExternalResource(url, type) {
|
|
14
14
|
let tag;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/*! Live2D API | Generated from src/ | https://github.com/nova1751/live2d-api */
|
|
2
|
-
"use strict";const live2d_path=(()=>{const e=document.currentScript;if(e?.src){const i=new URL(e.src);if(/\/(?:live2dapi-noa|gh\/nova1751\/live2d-api)(?:@[^/]+)?\/(?:npm|jsdelivr)\/(?:random|sequential)\/autoload(?:\.min)?\.js$/.test(i.pathname))return new URL("../../",i).href}return"https://cdn.jsdelivr.net/gh/nova1751/live2d-api@widget-2.4.
|
|
2
|
+
"use strict";const live2d_path=(()=>{const e=document.currentScript;if(e?.src){const i=new URL(e.src);if(/\/(?:live2dapi-noa|gh\/nova1751\/live2d-api)(?:@[^/]+)?\/(?:npm|jsdelivr)\/(?:random|sequential)\/autoload(?:\.min)?\.js$/.test(i.pathname))return new URL("../../",i).href}return"https://cdn.jsdelivr.net/gh/nova1751/live2d-api@widget-2.4.2/"})();function loadExternalResource(e,i){let n;if(i==="css"){const t=document.createElement("link");t.href=e,t.rel="stylesheet",n=t}else{const t=document.createElement("script");t.src=e,e===live2d_path+"jsdelivr/sequential/waifu-tips.js"&&(t.dataset.asteroidsUrl=live2d_path+"asteroids.js"),n=t}return new Promise((t,s)=>{n.onload=()=>t(e),n.onerror=()=>s(e),document.head.appendChild(n)})}screen.width>=768&&Promise.all([loadExternalResource(live2d_path+"live2d.min.js","js"),loadExternalResource(live2d_path+"jsdelivr/sequential/waifu-tips.js","js")]).then(async()=>{document.body||await new Promise(e=>document.addEventListener("DOMContentLoaded",()=>e(),{once:!0})),window.initWidget({tools:["hitokoto","asteroids","switch-model","switch-texture","photo","info","quit"],cdnPath:live2d_path,waifuPath:live2d_path+"waifu-tips.json"})}).catch(e=>console.error("[Live2D]",e));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*! Live2D API | Generated from src/ | https://github.com/nova1751/live2d-api */
|
|
2
|
-
"use strict";(()=>{var Y="zh-CN";function _(o){Y=o??"zh-CN"}function m(o,e){return Y==="en"?e:o}var G={hitokoto:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --><path d="M512 240c0 114.9-114.6 208-256 208c-37.1 0-72.3-6.4-104.1-17.9c-11.9 8.7-31.3 20.6-54.3 30.6C73.6 471.1 44.7 480 16 480c-6.5 0-12.3-3.9-14.8-9.9c-2.5-6-1.1-12.8 3.4-17.4l0 0 0 0 0 0 0 0 .3-.3c.3-.3 .7-.7 1.3-1.4c1.1-1.2 2.8-3.1 4.9-5.7c4.1-5 9.6-12.4 15.2-21.6c10-16.6 19.5-38.4 21.4-62.9C17.7 326.8 0 285.1 0 240C0 125.1 114.6 32 256 32s256 93.1 256 208z"/></svg>',asteroids:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --><path d="M498.1 5.6c10.1 7 15.4 19.1 13.5 31.2l-64 416c-1.5 9.7-7.4 18.2-16 23s-18.9 5.4-28 1.6L284 427.7l-68.5 74.1c-8.9 9.7-22.9 12.9-35.2 8.1S160 493.2 160 480V396.4c0-4 1.5-7.8 4.2-10.7L331.8 202.8c5.8-6.3 5.6-16-.4-22s-15.7-6.4-22-.7L106 360.8 17.7 316.6C7.1 311.3 .3 300.7 0 288.9s5.9-22.8 16.1-28.7l448-256c10.7-6.1 23.9-5.5 34 1.4z"/></svg>',"switch-model":'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --><path d="M399 384.2C376.9 345.8 335.4 320 288 320H224c-47.4 0-88.9 25.8-111 64.2c35.2 39.2 86.2 63.8 143 63.8s107.8-24.7 143-63.8zM0 256a256 256 0 1 1 512 0A256 256 0 1 1 0 256zm256 16a72 72 0 1 0 0-144 72 72 0 1 0 0 144z"/></svg>',"switch-texture":'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --><path d="M320 64A64 64 0 1 0 192 64a64 64 0 1 0 128 0zm-96 96c-35.3 0-64 28.7-64 64v48c0 17.7 14.3 32 32 32h1.8l11.1 99.5c1.8 16.2 15.5 28.5 31.8 28.5h38.7c16.3 0 30-12.3 31.8-28.5L318.2 304H320c17.7 0 32-14.3 32-32V224c0-35.3-28.7-64-64-64H224zM132.3 394.2c13-2.4 21.7-14.9 19.3-27.9s-14.9-21.7-27.9-19.3c-32.4 5.9-60.9 14.2-82 24.8c-10.5 5.3-20.3 11.7-27.8 19.6C6.4 399.5 0 410.5 0 424c0 21.4 15.5 36.1 29.1 45c14.7 9.6 34.3 17.3 56.4 23.4C130.2 504.7 190.4 512 256 512s125.8-7.3 170.4-19.6c22.1-6.1 41.8-13.8 56.4-23.4c13.7-8.9 29.1-23.6 29.1-45c0-13.5-6.4-24.5-14-32.6c-7.5-7.9-17.3-14.3-27.8-19.6c-21-10.6-49.5-18.9-82-24.8c-13-2.4-25.5 6.3-27.9 19.3s6.3 25.5 19.3 27.9c30.2 5.5 53.7 12.8 69 20.5c3.2 1.6 5.8 3.1 7.9 4.5c3.6 2.4 3.6 7.2 0 9.6c-8.8 5.7-23.1 11.8-43 17.3C374.3 457 318.5 464 256 464s-118.3-7-157.7-17.9c-19.9-5.5-34.2-11.6-43-17.3c-3.6-2.4-3.6-7.2 0-9.6c2.1-1.4 4.8-2.9 7.9-4.5c15.3-7.7 38.8-14.9 69-20.5z"/></svg>',photo:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --><path d="M220.6 121.2L271.1 96 448 96v96H333.2c-21.9-15.1-48.5-24-77.2-24s-55.2 8.9-77.2 24H64V128H192c9.9 0 19.7-2.3 28.6-6.8zM0 128V416c0 35.3 28.7 64 64 64H448c35.3 0 64-28.7 64-64V96c0-35.3-28.7-64-64-64H271.1c-9.9 0-19.7 2.3-28.6 6.8L192 64H160V48c0-8.8-7.2-16-16-16H80c-8.8 0-16 7.2-16 16l0 16C28.7 64 0 92.7 0 128zM168 304a88 88 0 1 1 176 0 88 88 0 1 1 -176 0z"/></svg>',info:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --><path d="M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512zM216 336h24V272H216c-13.3 0-24-10.7-24-24s10.7-24 24-24h48c13.3 0 24 10.7 24 24v88h8c13.3 0 24 10.7 24 24s-10.7 24-24 24H216c-13.3 0-24-10.7-24-24s10.7-24 24-24zm40-208a32 32 0 1 1 0 64 32 32 0 1 1 0-64z"/></svg>',quit:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --><path d="M342.6 150.6c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L192 210.7 86.6 105.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L146.7 256 41.4 361.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0L192 301.3 297.4 406.6c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L237.3 256 342.6 150.6z"/></svg>'};function U(o){return Array.isArray(o)?o[Math.floor(Math.random()*o.length)]:o}function L(o){return o.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}var B,H,E;function P(){clearTimeout(H),sessionStorage.removeItem("waifu-text"),document.getElementById("waifu-tips")?.classList.remove("waifu-tips-active")}function z(o,e){clearTimeout(H),sessionStorage.setItem("waifu-text",String(e));let t=document.getElementById("waifu-tips");t.innerHTML=o,t.classList.add("waifu-tips-active")}function v(o,e,t){!o||E||Number(sessionStorage.getItem("waifu-text"))>t||(z(U(o),t),H=setTimeout(P,e))}function J(o,e){if(!e){v(L(o),5e3,11);return}E=e,z(L(o),11)}function X(o){let e=document.getElementById("live2d");if(!e)return;let t=B?.find(({selector:n})=>e.closest(n)),i=t?U(t.text):B?void 0:m("指挥官,我在。","Right here, Commander.");i&&(E=o,z(i.replace("{text}",()=>L(e.textContent??"")),11))}function K(o,e){E===o&&(E=void 0,e?P():H=setTimeout(P,1200))}function de(o){if(location.pathname==="/"){let s=new Date().getHours();for(let{hour:a,text:r}of o){let[c,d=c]=a.split("-").map(Number);if(c<=s&&s<=d)return r}}let e=L(document.title.split(" - ")[0]),t=m(`欢迎阅读<span>「${e}」</span>`,`Welcome to <span>${e}</span>!`);if(!document.referrer)return t;let{hostname:i}=new URL(document.referrer);return i===location.hostname?t:m(`Hello!来自 <span>${L({baidu:"百度",so:"360搜索",google:"谷歌搜索"}[i.split(".")[1]]??i)}</span> 的朋友<br>${t}`,`Hello, visitor from <span>${L(i)}</span>!<br>${t}`)}function ue(o){let[e,t]=o.split("/").map(Number);return e*100+t}function Q(o){B=o.click;let e=[...o.message.default],t=new Date,i=(t.getMonth()+1)*100+t.getDate();for(let{date:u,text:p}of o.seasons){let[l,h=l]=u.split("-").map(ue);l<=i&&i<=h&&e.push(U(p).replace("{year}",String(t.getFullYear())))}let n=2e4,s=Date.now(),a;function r(){if(document.hidden)return;let u=n-(Date.now()-s);u<=0&&!localStorage.getItem("waifu-display")&&v(e,6e3,9),a=setTimeout(r,u>0?u:n)}let c=()=>{s=Date.now()};window.addEventListener("pointermove",c,{passive:!0}),window.addEventListener("pointerdown",c,{passive:!0}),window.addEventListener("keydown",c),document.hidden||(a=setTimeout(r,n)),v(de(o.time),7e3,11);let d;for(let u of["mouseover","click"])window.addEventListener(u,p=>{let l=p.target;if(!(l instanceof Element)||p.live2dHandlesCaption)return;let h=u==="click"&&l.closest("#waifu .waifu-model-stage"),w=h?document.getElementById("live2d"):l.closest("#live2d"),y=o[u].find(({selector:C})=>l.closest(C)||h&&w?.closest(C));!y||u==="mouseover"&&y.selector===d||(u==="mouseover"&&(d=y.selector),v(U(y.text).replace("{text}",()=>L(l.textContent??"")),4e3,u==="click"&&w?11:8))});let g=()=>{};g.toString=()=>(v(o.message.console,6e3,9),""),console.log("%c",g),window.addEventListener("copy",()=>v(o.message.copy,6e3,9)),document.addEventListener("visibilitychange",()=>{clearTimeout(a),document.hidden||(c(),a=setTimeout(r,n),localStorage.getItem("waifu-display")||v(o.message.visibilitychange,6e3,9))})}async function T(o){let e=await fetch(o);if(!e.ok)throw new Error(`Failed to load ${o} (HTTP ${e.status})`);return e.json()}var Z="/gh/nova1751/live2d-api@cdn-b3ac5ae545e2/",ee="https://cdn.jsdelivr.net",j=ee+Z,me=/\/gh\/nova1751\/live2d-api@widget-[^/]+\/?$/,fe=/\/live2dapi-noa(?:@[^/]+)?\/?$/;function te(o){let e=new URL(o,document.baseURI);return!fe.test(e.pathname)&&!me.test(e.pathname)||/@1\.[^/]+\/?$/.test(e.pathname)?o:(e.hostname==="cdn.jsdmirror.com"?e.origin:ee)+Z}var q=()=>m("我的新衣服好看嘛?","How do you like my new outfit?"),k=o=>Number(localStorage.getItem(o))||0,D=class{constructor(e){this.options=e;this.revision=0;this.loaded=!1;this.useCDN=typeof e.cdnPath=="string";let t=e.modelBaseUrl??(e.cdnPath&&te(e.cdnPath))??e.apiPath;if(typeof t!="string")throw new TypeError("Invalid initWidget argument");this.base=t.endsWith("/")?t:t+"/"}reopen(e){if(this.loaded)window.loadlive2d.show?.(e);else return this.load(void 0,void 0,void 0,e)}cancel(){this.revision++}async fetchCatalog(){let e=this.base+"model_list.json",t=await fetch(e);if(t.status===404&&!this.options.modelBaseUrl&&this.base!==j){let i=await T(j+"model_list.json");return this.base=j,i}if(!t.ok)throw new Error(`Failed to load ${e} (HTTP ${t.status})`);return t.json()}list(){return this.catalog??(this.catalog=this.fetchCatalog().catch(e=>{throw this.catalog=void 0,e}))}async load(e=k("modelId"),t=k("modelTexturesId"),i,n=!1,s=++this.revision,a=!1){let r;if(this.options.modelUrl)r=this.options.modelUrl;else if(this.useCDN){let{models:d}=await this.list();d[e]||(e=0);let g=d[e],u=Array.isArray(g)?g:[g];u[t]||(t=0);let p=u[t];t=u.indexOf(p),r=this.base+"model/"+p+"/index.json"}else r=this.base+"get/?id="+e+"-"+t;if(s!==this.revision)return;let c=window.loadlive2d("live2d",r,{start:n,locale:this.options.locale,coreUrl:this.options.coreUrl});c&&await c,s===this.revision&&(this.options.modelUrl||(localStorage.setItem("modelId",String(e)),localStorage.setItem("modelTexturesId",String(t))),v(i,4e3,10),this.loaded=!0)}async costume(e){if(this.options.modelUrl||!this.useCDN)return;let t=++this.revision,i=k("modelId"),n=(await this.list()).models[i],a=(Array.isArray(n)?n:[n]).findIndex(r=>new URL(this.base+"model/"+r+"/index.json",document.baseURI).href===e);a>=0&&await this.load(i,a,q(),!1,t,!0)}async nextModel(e=!1){let t=++this.revision,i=k("modelId");if(this.useCDN){let{models:s,messages:a}=await this.list(),r=(i+1)%s.length;return this.load(r,0,m(a[r],"Ready for duty!"),e,t)}let{model:n}=await T(this.base+"switch/?id="+i);return this.load(n.id,0,n.message,e,t)}async nextTexture(e=!1){let t=++this.revision,i=k("modelId"),n=k("modelTexturesId");if(this.useCDN){let a=(await this.list()).models[i],r=Array.isArray(a)?a.length:1;return this.load(i,(n+1)%r,q(),e,t)}let{textures:s}=await T(this.base+"rand_textures/?id="+i+"-"+n);s.id===1&&n===1?v(m("我还没有其他衣服呢!","This is my only outfit so far!"),4e3,10):await this.load(i,s.id,q(),e,t)}};var $=class{constructor(){this.revision=0}begin(e){let t=document.getElementById("waifu"),i=t?.querySelector(".waifu-surface"),n=++this.revision;return t&&(this.still&&!this.still.isConnected&&(i??t).prepend(this.still),t.setAttribute("data-model-loading","")),s=>{if(this.revision!==n||!t)return;let a=document.createElement("canvas");a.className="waifu-model-still",a.setAttribute("aria-hidden","true"),a.width=s.width,a.height=s.height;try{let r=a.getContext("2d");r&&r.drawImage(s,0,0),this.still?.remove(),this.still=r?a:void 0}finally{i&&t.style.setProperty("--waifu-aspect",String(e())),t.removeAttribute("data-model-loading")}}}};var O={scale:1,x:0,y:0},f=128;function W(o,e,t){let i=0;for(let n=0;n<o.length;n++)if(i+=o[n],i>e*t)return n;return o.length-1}function ge(o,e,t,i){let n=new Float64Array(f),s=f,a=0,r=0;for(let x=0;x<o.length;x++){if(!o[x])continue;let M=Math.floor(x/f);n[x%f]+=o[x],r+=o[x],s=Math.min(s,M),a=Math.max(a,M+1)}if(!r)return O;let c=W(n,r,.001),d=W(n,r,.999)+1,g=d-c,u=a-s,p=i?Math.max(.7,Math.min(1.9,g/u*.93/.94)):1;i?.(p);let l=Math.min(1,p),h=Math.min(1,1/p),w=Math.min(.93*f*h/u,.94*f*l/g,5/e.scale),y=0,C=0;if(t)for(let x=s+2;x<a;x+=4)for(let M=c+2;M<d;M+=4){if(o[x*f+M]<96)continue;t((M+.5)/f,(x+.5)/f).some(le=>/^(head|face|body|bust|torso)\d*$/i.test(le))&&(y+=M+.5,C++)}let R=C>=3?y/C:W(n,r,.5)+.5,b=.475*f*l/w,F=Math.max(d-b,Math.min(c+b,R));return{scale:e.scale*w,x:(.5-F/f)*w,y:.5-.03*h+(.5-a/f)*w}}function oe(o){let e={scale:.65,x:0,y:0},t=document.createElement("canvas");t.width=t.height=f;let i=t.getContext("2d",{willReadFrequently:!0}),n=new Uint8Array(f*f),s=0,a=0,r=0;return{initial:e,measure(c,d){if(!i)return O;let g=performance.now();if(!(g<r)){s++;try{i.clearRect(0,0,f,f),i.drawImage(c,0,0,f,f);let{data:u}=i.getImageData(0,0,f,f),p=0;for(let l=0;l<n.length;l++){let h=u[4*l+3];h<24||(n[l]=Math.max(n[l],h),p++)}p>=16&&(a++,r=g+80)}catch{return O}if(!(a<3&&s<10))return a?ge(n,e,d,o):O}}}}var ne=["fairy","doll","adjutant","npc","squad","background"],ie=["default","normal","destroy"];function N(o,e){let t=o.indexOf(e);return t<0?o.length:t}function he(o,e){let t=new Intl.Collator("en",{numeric:!0}),i=o.map(n=>{let[s,a,r,c]=n.split("/"),d=e[[s,a,r].join("/")],g=r==="base"?-1:d??(s==="fairy"&&/^\d+$/.test(r)?Number(r):Number.MAX_SAFE_INTEGER);return{id:n,category:s,character:a,version:r,form:c,order:g}});return i.sort((n,s)=>N(ne,n.category)-N(ne,s.category)||t.compare(n.category,s.category)||t.compare(n.character,s.character)||n.order-s.order||t.compare(n.version,s.version)||N(ie,n.form)-N(ie,s.form)||t.compare(n.form,s.form)),i.map(n=>n.id)}async function se(o,e,t="zh-CN"){let i=new URL(o,document.baseURI),n=await fetch(i);if(!n.ok)throw new Error("Cannot load catalog: HTTP "+n.status);let s=await n.json();if(s.schemaVersion!==1||!s.models||!s.sources)throw new Error("Unsupported model catalog");let a=new Map,r=Object.keys(s.models).filter(l=>(!e||!l.startsWith("other/"))&&s.models[l].some(h=>h.manifest)),c=e?s.presentation:void 0,d=t==="en"?c?.en:c,g=l=>{let h=c?.aliases[l];return h&&r.includes(h)?h:l},u=e?he(r.filter(l=>g(l)===l),c?.outfitOrder??{}):r;function p(l,h){if(e&&!r.includes(l))throw new Error("Model outside the selected collection: "+l);let w=s.models[l]?.find(b=>b.manifest&&(!h||b.source===h));if(!w?.manifest)throw new Error("No model manifest for "+l);let y=new URL(s.sources[w.source].baseUrl,n.url||i);i.hostname==="cdn.jsdmirror.com"&&y.hostname==="cdn.jsdelivr.net"&&y.pathname.startsWith("/gh/nova1751/live2d-api@cdn-")&&(y.hostname=i.hostname);let C=b=>new URL(b.split("/").map(encodeURIComponent).join("/"),y).href,R;if(w.dialogue){let b=a.get(w.source);b||(b=new Map((s.audio?.[w.source]??[]).map(F=>[F.toUpperCase(),C(F)])),a.set(w.source,b)),R={captions:t==="en"?void 0:d?.captions,url:C(w.dialogue),audio:b}}return{captions:d?.captions,modelUrl:C(w.manifest),dialogue:R,soundAliases:w.soundAliases}}return{ids:u,visibleId:g,labels:d?.labels??{},resolve:p,legacyIds:s.legacyIds}}var A=class{constructor(e,t){this.url=e;this.options=t;this.sequence=0;this.transition=new $;let i=t.collection?":"+t.collection:"",n="live2d:model:"+e+i,s=a=>a.replace(/(\/gh\/nova1751\/live2d-api)@catalog-[a-f0-9]{16}(\/catalog\/library\.json:girls-frontline)$/,"$1$2");if(this.key=s(n),this.key!==n&&!localStorage.getItem(this.key)){let a=[n,...Object.keys(localStorage)].find(r=>s(r)===this.key&&localStorage.getItem(r));a&&localStorage.setItem(this.key,localStorage.getItem(a))}}open(){return this.library??(this.library=se(this.url,this.options.collection,this.options.locale).catch(e=>{throw this.library=void 0,e}))}async select(e,t){let i=++this.sequence,n=await this.open();if(i!==this.sequence)return;let s=e(n.ids,n.legacyIds,n.visibleId),{modelUrl:a,dialogue:r,soundAliases:c,captions:d}=n.resolve(s),g=1,u=this.options.collection==="girls-frontline"&&!s.startsWith("background/")?oe(l=>{g=l}):void 0,p=this.options.collection?this.transition.begin(()=>g):void 0;await window.loadlive2d("live2d",a,{start:t,locale:this.options.locale,captions:d,framing:u,onPaint:p,coreUrl:this.options.coreUrl,dialogue:r,soundAliases:c}),i===this.sequence&&(this.active=n.visibleId(s),localStorage.setItem(this.key,s),window.dispatchEvent(new CustomEvent("live2d:model",{detail:s})))}load(e,t,i,n=!1){return this.select((s,a,r)=>{let c=localStorage.getItem(this.key);if(this.options.collection)return this.options.modelId??(c&&s.includes(r(c))?c:s[0]);let d=a?.[Number(localStorage.getItem("modelId"))]?.[Number(localStorage.getItem("modelTexturesId"))];return this.options.modelId??(c&&s.includes(r(c))?c:d&&s.includes(d)?d:s[0])},n)}choose(e){return this.select(()=>e,!1)}cancel(){this.sequence++}reopen(e){if(this.active)window.loadlive2d.show?.(e);else return this.load(void 0,void 0,void 0,e)}character(e){return e.split("/").slice(0,2).join("/")}nextModel(e=!1){return this.select(t=>{let i=[...new Set(t.map(s=>this.character(s)))],n=i[(i.indexOf(this.character(this.active??""))+1)%i.length];return t.find(s=>this.character(s)===n)},e)}nextTexture(e=!1){return this.select(t=>{let i=t.filter(n=>this.character(n)===this.character(this.active??t[0]));return i[(i.indexOf(this.active??"")+1)%i.length]},e)}async costume(e){let t=await this.open(),i=t.ids.find(n=>t.resolve(n).modelUrl===e);i&&await this.select(()=>i,!1)}};var pe=document.currentScript,we=pe?.dataset.asteroidsUrl??"https://cdn.jsdelivr.net/gh/nova1751/live2d-api@widget-2.4.1/asteroids.js",I=o=>document.getElementById(o);function S(o){console.error("[Live2D]",o);let e=document.getElementById("waifu-status");e&&(e.textContent=m("加载失败,请检查网络或切换模型后重试。","Could not load the model. Check your connection or try another character."),v(e.textContent,5e3,10))}async function ve(o){if(o==="en"){v(["One step at a time, Commander.","Even on a quiet day, there is something worth noticing."],6e3,9);return}let e=await T("https://v1.hitokoto.cn");v(L(e.hitokoto),6e3,9),setTimeout(()=>{v(`这句一言来自 <span>「${L(String(e.from))}」</span>,是 <span>${L(String(e.creator))}</span> 在 hitokoto.cn 投稿的。`,4e3,9)},6e3)}function ye(){if(window.Asteroids)(window.ASTEROIDSPLAYERS??(window.ASTEROIDSPLAYERS=[])).push(new window.Asteroids);else{let o=document.createElement("script");o.src=we,document.head.appendChild(o)}}var ae;function ce(){clearTimeout(ae),localStorage.removeItem("waifu-display"),I("waifu-toggle").setAttribute("tabindex","-1"),I("waifu-toggle").setAttribute("aria-expanded","true"),I("waifu").style.display="",setTimeout(()=>{I("waifu").style.bottom="0"},0)}function V(o){return o.isTrusted&&!!window.loadlive2d.prepareInteraction?.()}function be(){let o=I("waifu").contains(document.activeElement);window.loadlive2d.hide?.(),localStorage.setItem("waifu-display",String(Date.now())),v(m("愿你有一天能与重要的人重逢。","I hope you meet the people you miss again."),2e3,11),I("waifu").style.bottom="-500px",ae=setTimeout(()=>{I("waifu").style.display="none";let e=I("waifu-toggle");e.removeAttribute("tabindex"),e.setAttribute("aria-expanded","false"),e.classList.add("waifu-toggle-active"),o&&e.focus()},window.matchMedia("(prefers-reduced-motion: reduce)").matches?0:3e3)}function re(o,e,t=!1){sessionStorage.removeItem("waifu-text");let i=o.collection==="girls-frontline",n='<canvas id="live2d" width="800" height="800"></canvas>';document.body.insertAdjacentHTML("beforeend",`<div id="waifu" lang="${o.locale==="en"?"en":"zh-CN"}"${i?' class="waifu-adaptive"':""}>
|
|
2
|
+
"use strict";(()=>{var Y="zh-CN";function _(o){Y=o??"zh-CN"}function m(o,e){return Y==="en"?e:o}var G={hitokoto:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --><path d="M512 240c0 114.9-114.6 208-256 208c-37.1 0-72.3-6.4-104.1-17.9c-11.9 8.7-31.3 20.6-54.3 30.6C73.6 471.1 44.7 480 16 480c-6.5 0-12.3-3.9-14.8-9.9c-2.5-6-1.1-12.8 3.4-17.4l0 0 0 0 0 0 0 0 .3-.3c.3-.3 .7-.7 1.3-1.4c1.1-1.2 2.8-3.1 4.9-5.7c4.1-5 9.6-12.4 15.2-21.6c10-16.6 19.5-38.4 21.4-62.9C17.7 326.8 0 285.1 0 240C0 125.1 114.6 32 256 32s256 93.1 256 208z"/></svg>',asteroids:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --><path d="M498.1 5.6c10.1 7 15.4 19.1 13.5 31.2l-64 416c-1.5 9.7-7.4 18.2-16 23s-18.9 5.4-28 1.6L284 427.7l-68.5 74.1c-8.9 9.7-22.9 12.9-35.2 8.1S160 493.2 160 480V396.4c0-4 1.5-7.8 4.2-10.7L331.8 202.8c5.8-6.3 5.6-16-.4-22s-15.7-6.4-22-.7L106 360.8 17.7 316.6C7.1 311.3 .3 300.7 0 288.9s5.9-22.8 16.1-28.7l448-256c10.7-6.1 23.9-5.5 34 1.4z"/></svg>',"switch-model":'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --><path d="M399 384.2C376.9 345.8 335.4 320 288 320H224c-47.4 0-88.9 25.8-111 64.2c35.2 39.2 86.2 63.8 143 63.8s107.8-24.7 143-63.8zM0 256a256 256 0 1 1 512 0A256 256 0 1 1 0 256zm256 16a72 72 0 1 0 0-144 72 72 0 1 0 0 144z"/></svg>',"switch-texture":'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --><path d="M320 64A64 64 0 1 0 192 64a64 64 0 1 0 128 0zm-96 96c-35.3 0-64 28.7-64 64v48c0 17.7 14.3 32 32 32h1.8l11.1 99.5c1.8 16.2 15.5 28.5 31.8 28.5h38.7c16.3 0 30-12.3 31.8-28.5L318.2 304H320c17.7 0 32-14.3 32-32V224c0-35.3-28.7-64-64-64H224zM132.3 394.2c13-2.4 21.7-14.9 19.3-27.9s-14.9-21.7-27.9-19.3c-32.4 5.9-60.9 14.2-82 24.8c-10.5 5.3-20.3 11.7-27.8 19.6C6.4 399.5 0 410.5 0 424c0 21.4 15.5 36.1 29.1 45c14.7 9.6 34.3 17.3 56.4 23.4C130.2 504.7 190.4 512 256 512s125.8-7.3 170.4-19.6c22.1-6.1 41.8-13.8 56.4-23.4c13.7-8.9 29.1-23.6 29.1-45c0-13.5-6.4-24.5-14-32.6c-7.5-7.9-17.3-14.3-27.8-19.6c-21-10.6-49.5-18.9-82-24.8c-13-2.4-25.5 6.3-27.9 19.3s6.3 25.5 19.3 27.9c30.2 5.5 53.7 12.8 69 20.5c3.2 1.6 5.8 3.1 7.9 4.5c3.6 2.4 3.6 7.2 0 9.6c-8.8 5.7-23.1 11.8-43 17.3C374.3 457 318.5 464 256 464s-118.3-7-157.7-17.9c-19.9-5.5-34.2-11.6-43-17.3c-3.6-2.4-3.6-7.2 0-9.6c2.1-1.4 4.8-2.9 7.9-4.5c15.3-7.7 38.8-14.9 69-20.5z"/></svg>',photo:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --><path d="M220.6 121.2L271.1 96 448 96v96H333.2c-21.9-15.1-48.5-24-77.2-24s-55.2 8.9-77.2 24H64V128H192c9.9 0 19.7-2.3 28.6-6.8zM0 128V416c0 35.3 28.7 64 64 64H448c35.3 0 64-28.7 64-64V96c0-35.3-28.7-64-64-64H271.1c-9.9 0-19.7 2.3-28.6 6.8L192 64H160V48c0-8.8-7.2-16-16-16H80c-8.8 0-16 7.2-16 16l0 16C28.7 64 0 92.7 0 128zM168 304a88 88 0 1 1 176 0 88 88 0 1 1 -176 0z"/></svg>',info:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --><path d="M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512zM216 336h24V272H216c-13.3 0-24-10.7-24-24s10.7-24 24-24h48c13.3 0 24 10.7 24 24v88h8c13.3 0 24 10.7 24 24s-10.7 24-24 24H216c-13.3 0-24-10.7-24-24s10.7-24 24-24zm40-208a32 32 0 1 1 0 64 32 32 0 1 1 0-64z"/></svg>',quit:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --><path d="M342.6 150.6c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L192 210.7 86.6 105.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L146.7 256 41.4 361.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0L192 301.3 297.4 406.6c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L237.3 256 342.6 150.6z"/></svg>'};function U(o){return Array.isArray(o)?o[Math.floor(Math.random()*o.length)]:o}function L(o){return o.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}var B,H,E;function P(){clearTimeout(H),sessionStorage.removeItem("waifu-text"),document.getElementById("waifu-tips")?.classList.remove("waifu-tips-active")}function z(o,e){clearTimeout(H),sessionStorage.setItem("waifu-text",String(e));let t=document.getElementById("waifu-tips");t.innerHTML=o,t.classList.add("waifu-tips-active")}function v(o,e,t){!o||E||Number(sessionStorage.getItem("waifu-text"))>t||(z(U(o),t),H=setTimeout(P,e))}function J(o,e){if(!e){v(L(o),5e3,11);return}E=e,z(L(o),11)}function X(o){let e=document.getElementById("live2d");if(!e)return;let t=B?.find(({selector:n})=>e.closest(n)),i=t?U(t.text):B?void 0:m("指挥官,我在。","Right here, Commander.");i&&(E=o,z(i.replace("{text}",()=>L(e.textContent??"")),11))}function K(o,e){E===o&&(E=void 0,e?P():H=setTimeout(P,1200))}function de(o){if(location.pathname==="/"){let s=new Date().getHours();for(let{hour:a,text:r}of o){let[c,d=c]=a.split("-").map(Number);if(c<=s&&s<=d)return r}}let e=L(document.title.split(" - ")[0]),t=m(`欢迎阅读<span>「${e}」</span>`,`Welcome to <span>${e}</span>!`);if(!document.referrer)return t;let{hostname:i}=new URL(document.referrer);return i===location.hostname?t:m(`Hello!来自 <span>${L({baidu:"百度",so:"360搜索",google:"谷歌搜索"}[i.split(".")[1]]??i)}</span> 的朋友<br>${t}`,`Hello, visitor from <span>${L(i)}</span>!<br>${t}`)}function ue(o){let[e,t]=o.split("/").map(Number);return e*100+t}function Q(o){B=o.click;let e=[...o.message.default],t=new Date,i=(t.getMonth()+1)*100+t.getDate();for(let{date:u,text:p}of o.seasons){let[l,h=l]=u.split("-").map(ue);l<=i&&i<=h&&e.push(U(p).replace("{year}",String(t.getFullYear())))}let n=2e4,s=Date.now(),a;function r(){if(document.hidden)return;let u=n-(Date.now()-s);u<=0&&!localStorage.getItem("waifu-display")&&v(e,6e3,9),a=setTimeout(r,u>0?u:n)}let c=()=>{s=Date.now()};window.addEventListener("pointermove",c,{passive:!0}),window.addEventListener("pointerdown",c,{passive:!0}),window.addEventListener("keydown",c),document.hidden||(a=setTimeout(r,n)),v(de(o.time),7e3,11);let d;for(let u of["mouseover","click"])window.addEventListener(u,p=>{let l=p.target;if(!(l instanceof Element)||p.live2dHandlesCaption)return;let h=u==="click"&&l.closest("#waifu .waifu-model-stage"),w=h?document.getElementById("live2d"):l.closest("#live2d"),y=o[u].find(({selector:C})=>l.closest(C)||h&&w?.closest(C));!y||u==="mouseover"&&y.selector===d||(u==="mouseover"&&(d=y.selector),v(U(y.text).replace("{text}",()=>L(l.textContent??"")),4e3,u==="click"&&w?11:8))});let f=()=>{};f.toString=()=>(v(o.message.console,6e3,9),""),console.log("%c",f),window.addEventListener("copy",()=>v(o.message.copy,6e3,9)),document.addEventListener("visibilitychange",()=>{clearTimeout(a),document.hidden||(c(),a=setTimeout(r,n),localStorage.getItem("waifu-display")||v(o.message.visibilitychange,6e3,9))})}async function T(o){let e=await fetch(o);if(!e.ok)throw new Error(`Failed to load ${o} (HTTP ${e.status})`);return e.json()}var Z="/gh/nova1751/live2d-api@cdn-b3ac5ae545e2/",ee="https://cdn.jsdelivr.net",j=ee+Z,me=/\/gh\/nova1751\/live2d-api@widget-[^/]+\/?$/,ge=/\/live2dapi-noa(?:@[^/]+)?\/?$/;function te(o){let e=new URL(o,document.baseURI);return!ge.test(e.pathname)&&!me.test(e.pathname)||/@1\.[^/]+\/?$/.test(e.pathname)?o:(e.hostname==="cdn.jsdmirror.com"?e.origin:ee)+Z}var q=()=>m("我的新衣服好看嘛?","How do you like my new outfit?"),k=o=>Number(localStorage.getItem(o))||0,D=class{constructor(e){this.options=e;this.revision=0;this.loaded=!1;this.useCDN=typeof e.cdnPath=="string";let t=e.modelBaseUrl??(e.cdnPath&&te(e.cdnPath))??e.apiPath;if(typeof t!="string")throw new TypeError("Invalid initWidget argument");this.base=t.endsWith("/")?t:t+"/"}reopen(e){if(this.loaded)window.loadlive2d.show?.(e);else return this.load(void 0,void 0,void 0,e)}cancel(){this.revision++}async fetchCatalog(){let e=this.base+"model_list.json",t=await fetch(e);if(t.status===404&&!this.options.modelBaseUrl&&this.base!==j){let i=await T(j+"model_list.json");return this.base=j,i}if(!t.ok)throw new Error(`Failed to load ${e} (HTTP ${t.status})`);return t.json()}list(){return this.catalog??(this.catalog=this.fetchCatalog().catch(e=>{throw this.catalog=void 0,e}))}async load(e=k("modelId"),t=k("modelTexturesId"),i,n=!1,s=++this.revision,a=!1){let r;if(this.options.modelUrl)r=this.options.modelUrl;else if(this.useCDN){let{models:d}=await this.list();d[e]||(e=0);let f=d[e],u=Array.isArray(f)?f:[f];u[t]||(t=0);let p=u[t];t=u.indexOf(p),r=this.base+"model/"+p+"/index.json"}else r=this.base+"get/?id="+e+"-"+t;if(s!==this.revision)return;let c=window.loadlive2d("live2d",r,{start:n,locale:this.options.locale,coreUrl:this.options.coreUrl});c&&await c,s===this.revision&&(this.options.modelUrl||(localStorage.setItem("modelId",String(e)),localStorage.setItem("modelTexturesId",String(t))),v(i,4e3,10),this.loaded=!0)}async costume(e){if(this.options.modelUrl||!this.useCDN)return;let t=++this.revision,i=k("modelId"),n=(await this.list()).models[i],a=(Array.isArray(n)?n:[n]).findIndex(r=>new URL(this.base+"model/"+r+"/index.json",document.baseURI).href===e);a>=0&&await this.load(i,a,q(),!1,t,!0)}async nextModel(e=!1){let t=++this.revision,i=k("modelId");if(this.useCDN){let{models:s,messages:a}=await this.list(),r=(i+1)%s.length;return this.load(r,0,m(a[r],"Ready for duty!"),e,t)}let{model:n}=await T(this.base+"switch/?id="+i);return this.load(n.id,0,n.message,e,t)}async nextTexture(e=!1){let t=++this.revision,i=k("modelId"),n=k("modelTexturesId");if(this.useCDN){let a=(await this.list()).models[i],r=Array.isArray(a)?a.length:1;return this.load(i,(n+1)%r,q(),e,t)}let{textures:s}=await T(this.base+"rand_textures/?id="+i+"-"+n);s.id===1&&n===1?v(m("我还没有其他衣服呢!","This is my only outfit so far!"),4e3,10):await this.load(i,s.id,q(),e,t)}};var $=class{constructor(){this.revision=0}begin(e){let t=document.getElementById("waifu"),i=t?.querySelector(".waifu-surface"),n=++this.revision;return t&&(this.still&&!this.still.isConnected&&(i??t).prepend(this.still),t.setAttribute("data-model-loading","")),s=>{if(this.revision!==n||!t)return;let a=document.createElement("canvas");a.className="waifu-model-still",a.setAttribute("aria-hidden","true"),a.width=s.width,a.height=s.height;try{let r=a.getContext("2d");r&&r.drawImage(s,0,0),this.still?.remove(),this.still=r?a:void 0}finally{if(i){let r=e();t.style.setProperty("--waifu-aspect",String(r)),t.toggleAttribute("data-wide-model",r>=1.35)}t.removeAttribute("data-model-loading")}}}};var O={scale:1,x:0,y:0},g=128;function W(o,e,t){let i=0;for(let n=0;n<o.length;n++)if(i+=o[n],i>e*t)return n;return o.length-1}function fe(o,e,t,i){let n=new Float64Array(g),s=g,a=0,r=0;for(let x=0;x<o.length;x++){if(!o[x])continue;let M=Math.floor(x/g);n[x%g]+=o[x],r+=o[x],s=Math.min(s,M),a=Math.max(a,M+1)}if(!r)return O;let c=W(n,r,.001),d=W(n,r,.999)+1,f=d-c,u=a-s,p=i?Math.max(.7,Math.min(1.9,f/u*.93/.94)):1;i?.(p);let l=Math.min(1,p),h=Math.min(1,1/p),w=Math.min(.93*g*h/u,.94*g*l/f,5/e.scale),y=0,C=0;if(t)for(let x=s+2;x<a;x+=4)for(let M=c+2;M<d;M+=4){if(o[x*g+M]<96)continue;t((M+.5)/g,(x+.5)/g).some(le=>/^(head|face|body|bust|torso)\d*$/i.test(le))&&(y+=M+.5,C++)}let R=C>=3?y/C:W(n,r,.5)+.5,b=.475*g*l/w,F=Math.max(d-b,Math.min(c+b,R));return{scale:e.scale*w,x:(.5-F/g)*w,y:.5-.03*h+(.5-a/g)*w}}function oe(o){let e={scale:.65,x:0,y:0},t=document.createElement("canvas");t.width=t.height=g;let i=t.getContext("2d",{willReadFrequently:!0}),n=new Uint8Array(g*g),s=0,a=0,r=0;return{initial:e,measure(c,d){if(!i)return O;let f=performance.now();if(!(f<r)){s++;try{i.clearRect(0,0,g,g),i.drawImage(c,0,0,g,g);let{data:u}=i.getImageData(0,0,g,g),p=0;for(let l=0;l<n.length;l++){let h=u[4*l+3];h<24||(n[l]=Math.max(n[l],h),p++)}p>=16&&(a++,r=f+80)}catch{return O}if(!(a<3&&s<10))return a?fe(n,e,d,o):O}}}}var ne=["fairy","doll","adjutant","npc","squad","background"],ie=["default","normal","destroy"];function N(o,e){let t=o.indexOf(e);return t<0?o.length:t}function he(o,e){let t=new Intl.Collator("en",{numeric:!0}),i=o.map(n=>{let[s,a,r,c]=n.split("/"),d=e[[s,a,r].join("/")],f=r==="base"?-1:d??(s==="fairy"&&/^\d+$/.test(r)?Number(r):Number.MAX_SAFE_INTEGER);return{id:n,category:s,character:a,version:r,form:c,order:f}});return i.sort((n,s)=>N(ne,n.category)-N(ne,s.category)||t.compare(n.category,s.category)||t.compare(n.character,s.character)||n.order-s.order||t.compare(n.version,s.version)||N(ie,n.form)-N(ie,s.form)||t.compare(n.form,s.form)),i.map(n=>n.id)}async function se(o,e,t="zh-CN"){let i=new URL(o,document.baseURI),n=await fetch(i);if(!n.ok)throw new Error("Cannot load catalog: HTTP "+n.status);let s=await n.json();if(s.schemaVersion!==1||!s.models||!s.sources)throw new Error("Unsupported model catalog");let a=new Map,r=Object.keys(s.models).filter(l=>(!e||!l.startsWith("other/"))&&s.models[l].some(h=>h.manifest)),c=e?s.presentation:void 0,d=t==="en"?c?.en:c,f=l=>{let h=c?.aliases[l];return h&&r.includes(h)?h:l},u=e?he(r.filter(l=>f(l)===l),c?.outfitOrder??{}):r;function p(l,h){if(e&&!r.includes(l))throw new Error("Model outside the selected collection: "+l);let w=s.models[l]?.find(b=>b.manifest&&(!h||b.source===h));if(!w?.manifest)throw new Error("No model manifest for "+l);let y=new URL(s.sources[w.source].baseUrl,n.url||i);i.hostname==="cdn.jsdmirror.com"&&y.hostname==="cdn.jsdelivr.net"&&y.pathname.startsWith("/gh/nova1751/live2d-api@cdn-")&&(y.hostname=i.hostname);let C=b=>new URL(b.split("/").map(encodeURIComponent).join("/"),y).href,R;if(w.dialogue){let b=a.get(w.source);b||(b=new Map((s.audio?.[w.source]??[]).map(F=>[F.toUpperCase(),C(F)])),a.set(w.source,b)),R={captions:t==="en"?void 0:d?.captions,url:C(w.dialogue),audio:b}}return{captions:d?.captions,modelUrl:C(w.manifest),dialogue:R,soundAliases:w.soundAliases}}return{ids:u,visibleId:f,labels:d?.labels??{},resolve:p,legacyIds:s.legacyIds}}var A=class{constructor(e,t){this.url=e;this.options=t;this.sequence=0;this.transition=new $;let i=t.collection?":"+t.collection:"",n="live2d:model:"+e+i,s=a=>a.replace(/(\/gh\/nova1751\/live2d-api)@catalog-[a-f0-9]{16}(\/catalog\/library\.json:girls-frontline)$/,"$1$2");if(this.key=s(n),this.key!==n&&!localStorage.getItem(this.key)){let a=[n,...Object.keys(localStorage)].find(r=>s(r)===this.key&&localStorage.getItem(r));a&&localStorage.setItem(this.key,localStorage.getItem(a))}}open(){return this.library??(this.library=se(this.url,this.options.collection,this.options.locale).catch(e=>{throw this.library=void 0,e}))}async select(e,t){let i=++this.sequence,n=await this.open();if(i!==this.sequence)return;let s=e(n.ids,n.legacyIds,n.visibleId),{modelUrl:a,dialogue:r,soundAliases:c,captions:d}=n.resolve(s),f=1,u=this.options.collection==="girls-frontline"&&!s.startsWith("background/")?oe(l=>{f=l}):void 0,p=this.options.collection?this.transition.begin(()=>f):void 0;await window.loadlive2d("live2d",a,{start:t,locale:this.options.locale,captions:d,framing:u,onPaint:p,coreUrl:this.options.coreUrl,dialogue:r,soundAliases:c}),i===this.sequence&&(this.active=n.visibleId(s),localStorage.setItem(this.key,s),window.dispatchEvent(new CustomEvent("live2d:model",{detail:s})))}load(e,t,i,n=!1){return this.select((s,a,r)=>{let c=localStorage.getItem(this.key);if(this.options.collection)return this.options.modelId??(c&&s.includes(r(c))?c:s[0]);let d=a?.[Number(localStorage.getItem("modelId"))]?.[Number(localStorage.getItem("modelTexturesId"))];return this.options.modelId??(c&&s.includes(r(c))?c:d&&s.includes(d)?d:s[0])},n)}choose(e){return this.select(()=>e,!1)}cancel(){this.sequence++}reopen(e){if(this.active)window.loadlive2d.show?.(e);else return this.load(void 0,void 0,void 0,e)}character(e){return e.split("/").slice(0,2).join("/")}nextModel(e=!1){return this.select(t=>{let i=[...new Set(t.map(s=>this.character(s)))],n=i[(i.indexOf(this.character(this.active??""))+1)%i.length];return t.find(s=>this.character(s)===n)},e)}nextTexture(e=!1){return this.select(t=>{let i=t.filter(n=>this.character(n)===this.character(this.active??t[0]));return i[(i.indexOf(this.active??"")+1)%i.length]},e)}async costume(e){let t=await this.open(),i=t.ids.find(n=>t.resolve(n).modelUrl===e);i&&await this.select(()=>i,!1)}};var pe=document.currentScript,we=pe?.dataset.asteroidsUrl??"https://cdn.jsdelivr.net/gh/nova1751/live2d-api@widget-2.4.2/asteroids.js",I=o=>document.getElementById(o);function S(o){console.error("[Live2D]",o);let e=document.getElementById("waifu-status");e&&(e.textContent=m("加载失败,请检查网络或切换模型后重试。","Could not load the model. Check your connection or try another character."),v(e.textContent,5e3,10))}async function ve(o){if(o==="en"){v(["One step at a time, Commander.","Even on a quiet day, there is something worth noticing."],6e3,9);return}let e=await T("https://v1.hitokoto.cn");v(L(e.hitokoto),6e3,9),setTimeout(()=>{v(`这句一言来自 <span>「${L(String(e.from))}」</span>,是 <span>${L(String(e.creator))}</span> 在 hitokoto.cn 投稿的。`,4e3,9)},6e3)}function ye(){if(window.Asteroids)(window.ASTEROIDSPLAYERS??(window.ASTEROIDSPLAYERS=[])).push(new window.Asteroids);else{let o=document.createElement("script");o.src=we,document.head.appendChild(o)}}var ae;function ce(){clearTimeout(ae),localStorage.removeItem("waifu-display"),I("waifu-toggle").setAttribute("tabindex","-1"),I("waifu-toggle").setAttribute("aria-expanded","true"),I("waifu").style.display="",setTimeout(()=>{I("waifu").style.bottom="0"},0)}function V(o){return o.isTrusted&&!!window.loadlive2d.prepareInteraction?.()}function be(){let o=I("waifu").contains(document.activeElement);window.loadlive2d.hide?.(),localStorage.setItem("waifu-display",String(Date.now())),v(m("愿你有一天能与重要的人重逢。","I hope you meet the people you miss again."),2e3,11),I("waifu").style.bottom="-500px",ae=setTimeout(()=>{I("waifu").style.display="none";let e=I("waifu-toggle");e.removeAttribute("tabindex"),e.setAttribute("aria-expanded","false"),e.classList.add("waifu-toggle-active"),o&&e.focus()},window.matchMedia("(prefers-reduced-motion: reduce)").matches?0:3e3)}function re(o,e,t=!1){sessionStorage.removeItem("waifu-text");let i=o.collection==="girls-frontline",n='<canvas id="live2d" width="800" height="800"></canvas>';document.body.insertAdjacentHTML("beforeend",`<div id="waifu" lang="${o.locale==="en"?"en":"zh-CN"}"${i?' class="waifu-adaptive"':""}>
|
|
3
3
|
<div id="waifu-status" role="status" class="waifu-sr-only"></div>
|
|
4
4
|
<div id="waifu-tips"></div>
|
|
5
5
|
${i?`<div class="waifu-viewport"><div class="waifu-surface">${n}</div></div>`:n}
|
package/npm/random/autoload.js
CHANGED
|
@@ -8,7 +8,7 @@ const live2d_path = (() => {
|
|
|
8
8
|
return new URL("../../", url).href;
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
-
return "https://cdn.jsdelivr.net/gh/nova1751/live2d-api@widget-2.4.
|
|
11
|
+
return "https://cdn.jsdelivr.net/gh/nova1751/live2d-api@widget-2.4.2/";
|
|
12
12
|
})();
|
|
13
13
|
function loadExternalResource(url, type) {
|
|
14
14
|
let tag;
|
package/npm/random/waifu-tips.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*! Live2D API | Generated from src/ | https://github.com/nova1751/live2d-api */
|
|
2
|
-
"use strict";(()=>{var Y="zh-CN";function _(o){Y=o??"zh-CN"}function m(o,e){return Y==="en"?e:o}var G={hitokoto:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --><path d="M512 240c0 114.9-114.6 208-256 208c-37.1 0-72.3-6.4-104.1-17.9c-11.9 8.7-31.3 20.6-54.3 30.6C73.6 471.1 44.7 480 16 480c-6.5 0-12.3-3.9-14.8-9.9c-2.5-6-1.1-12.8 3.4-17.4l0 0 0 0 0 0 0 0 .3-.3c.3-.3 .7-.7 1.3-1.4c1.1-1.2 2.8-3.1 4.9-5.7c4.1-5 9.6-12.4 15.2-21.6c10-16.6 19.5-38.4 21.4-62.9C17.7 326.8 0 285.1 0 240C0 125.1 114.6 32 256 32s256 93.1 256 208z"/></svg>',asteroids:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --><path d="M498.1 5.6c10.1 7 15.4 19.1 13.5 31.2l-64 416c-1.5 9.7-7.4 18.2-16 23s-18.9 5.4-28 1.6L284 427.7l-68.5 74.1c-8.9 9.7-22.9 12.9-35.2 8.1S160 493.2 160 480V396.4c0-4 1.5-7.8 4.2-10.7L331.8 202.8c5.8-6.3 5.6-16-.4-22s-15.7-6.4-22-.7L106 360.8 17.7 316.6C7.1 311.3 .3 300.7 0 288.9s5.9-22.8 16.1-28.7l448-256c10.7-6.1 23.9-5.5 34 1.4z"/></svg>',"switch-model":'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --><path d="M399 384.2C376.9 345.8 335.4 320 288 320H224c-47.4 0-88.9 25.8-111 64.2c35.2 39.2 86.2 63.8 143 63.8s107.8-24.7 143-63.8zM0 256a256 256 0 1 1 512 0A256 256 0 1 1 0 256zm256 16a72 72 0 1 0 0-144 72 72 0 1 0 0 144z"/></svg>',"switch-texture":'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --><path d="M320 64A64 64 0 1 0 192 64a64 64 0 1 0 128 0zm-96 96c-35.3 0-64 28.7-64 64v48c0 17.7 14.3 32 32 32h1.8l11.1 99.5c1.8 16.2 15.5 28.5 31.8 28.5h38.7c16.3 0 30-12.3 31.8-28.5L318.2 304H320c17.7 0 32-14.3 32-32V224c0-35.3-28.7-64-64-64H224zM132.3 394.2c13-2.4 21.7-14.9 19.3-27.9s-14.9-21.7-27.9-19.3c-32.4 5.9-60.9 14.2-82 24.8c-10.5 5.3-20.3 11.7-27.8 19.6C6.4 399.5 0 410.5 0 424c0 21.4 15.5 36.1 29.1 45c14.7 9.6 34.3 17.3 56.4 23.4C130.2 504.7 190.4 512 256 512s125.8-7.3 170.4-19.6c22.1-6.1 41.8-13.8 56.4-23.4c13.7-8.9 29.1-23.6 29.1-45c0-13.5-6.4-24.5-14-32.6c-7.5-7.9-17.3-14.3-27.8-19.6c-21-10.6-49.5-18.9-82-24.8c-13-2.4-25.5 6.3-27.9 19.3s6.3 25.5 19.3 27.9c30.2 5.5 53.7 12.8 69 20.5c3.2 1.6 5.8 3.1 7.9 4.5c3.6 2.4 3.6 7.2 0 9.6c-8.8 5.7-23.1 11.8-43 17.3C374.3 457 318.5 464 256 464s-118.3-7-157.7-17.9c-19.9-5.5-34.2-11.6-43-17.3c-3.6-2.4-3.6-7.2 0-9.6c2.1-1.4 4.8-2.9 7.9-4.5c15.3-7.7 38.8-14.9 69-20.5z"/></svg>',photo:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --><path d="M220.6 121.2L271.1 96 448 96v96H333.2c-21.9-15.1-48.5-24-77.2-24s-55.2 8.9-77.2 24H64V128H192c9.9 0 19.7-2.3 28.6-6.8zM0 128V416c0 35.3 28.7 64 64 64H448c35.3 0 64-28.7 64-64V96c0-35.3-28.7-64-64-64H271.1c-9.9 0-19.7 2.3-28.6 6.8L192 64H160V48c0-8.8-7.2-16-16-16H80c-8.8 0-16 7.2-16 16l0 16C28.7 64 0 92.7 0 128zM168 304a88 88 0 1 1 176 0 88 88 0 1 1 -176 0z"/></svg>',info:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --><path d="M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512zM216 336h24V272H216c-13.3 0-24-10.7-24-24s10.7-24 24-24h48c13.3 0 24 10.7 24 24v88h8c13.3 0 24 10.7 24 24s-10.7 24-24 24H216c-13.3 0-24-10.7-24-24s10.7-24 24-24zm40-208a32 32 0 1 1 0 64 32 32 0 1 1 0-64z"/></svg>',quit:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --><path d="M342.6 150.6c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L192 210.7 86.6 105.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L146.7 256 41.4 361.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0L192 301.3 297.4 406.6c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L237.3 256 342.6 150.6z"/></svg>'};function E(o){return Array.isArray(o)?o[Math.floor(Math.random()*o.length)]:o}function L(o){return o.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}var B,H,A;function P(){clearTimeout(H),sessionStorage.removeItem("waifu-text"),document.getElementById("waifu-tips")?.classList.remove("waifu-tips-active")}function z(o,e){clearTimeout(H),sessionStorage.setItem("waifu-text",String(e));let t=document.getElementById("waifu-tips");t.innerHTML=o,t.classList.add("waifu-tips-active")}function v(o,e,t){!o||A||Number(sessionStorage.getItem("waifu-text"))>t||(z(E(o),t),H=setTimeout(P,e))}function J(o,e){if(!e){v(L(o),5e3,11);return}A=e,z(L(o),11)}function X(o){let e=document.getElementById("live2d");if(!e)return;let t=B?.find(({selector:n})=>e.closest(n)),i=t?E(t.text):B?void 0:m("指挥官,我在。","Right here, Commander.");i&&(A=o,z(i.replace("{text}",()=>L(e.textContent??"")),11))}function K(o,e){A===o&&(A=void 0,e?P():H=setTimeout(P,1200))}function de(o){if(location.pathname==="/"){let s=new Date().getHours();for(let{hour:a,text:r}of o){let[c,d=c]=a.split("-").map(Number);if(c<=s&&s<=d)return r}}let e=L(document.title.split(" - ")[0]),t=m(`欢迎阅读<span>「${e}」</span>`,`Welcome to <span>${e}</span>!`);if(!document.referrer)return t;let{hostname:i}=new URL(document.referrer);return i===location.hostname?t:m(`Hello!来自 <span>${L({baidu:"百度",so:"360搜索",google:"谷歌搜索"}[i.split(".")[1]]??i)}</span> 的朋友<br>${t}`,`Hello, visitor from <span>${L(i)}</span>!<br>${t}`)}function ue(o){let[e,t]=o.split("/").map(Number);return e*100+t}function Q(o){B=o.click;let e=[...o.message.default],t=new Date,i=(t.getMonth()+1)*100+t.getDate();for(let{date:u,text:p}of o.seasons){let[l,h=l]=u.split("-").map(ue);l<=i&&i<=h&&e.push(E(p).replace("{year}",String(t.getFullYear())))}let n=2e4,s=Date.now(),a;function r(){if(document.hidden)return;let u=n-(Date.now()-s);u<=0&&!localStorage.getItem("waifu-display")&&v(e,6e3,9),a=setTimeout(r,u>0?u:n)}let c=()=>{s=Date.now()};window.addEventListener("pointermove",c,{passive:!0}),window.addEventListener("pointerdown",c,{passive:!0}),window.addEventListener("keydown",c),document.hidden||(a=setTimeout(r,n)),v(de(o.time),7e3,11);let d;for(let u of["mouseover","click"])window.addEventListener(u,p=>{let l=p.target;if(!(l instanceof Element)||p.live2dHandlesCaption)return;let h=u==="click"&&l.closest("#waifu .waifu-model-stage"),w=h?document.getElementById("live2d"):l.closest("#live2d"),y=o[u].find(({selector:C})=>l.closest(C)||h&&w?.closest(C));!y||u==="mouseover"&&y.selector===d||(u==="mouseover"&&(d=y.selector),v(E(y.text).replace("{text}",()=>L(l.textContent??"")),4e3,u==="click"&&w?11:8))});let f=()=>{};f.toString=()=>(v(o.message.console,6e3,9),""),console.log("%c",f),window.addEventListener("copy",()=>v(o.message.copy,6e3,9)),document.addEventListener("visibilitychange",()=>{clearTimeout(a),document.hidden||(c(),a=setTimeout(r,n),localStorage.getItem("waifu-display")||v(o.message.visibilitychange,6e3,9))})}async function T(o){let e=await fetch(o);if(!e.ok)throw new Error(`Failed to load ${o} (HTTP ${e.status})`);return e.json()}var Z="/gh/nova1751/live2d-api@cdn-b3ac5ae545e2/",ee="https://cdn.jsdelivr.net",j=ee+Z,me=/\/gh\/nova1751\/live2d-api@widget-[^/]+\/?$/,ge=/\/live2dapi-noa(?:@[^/]+)?\/?$/;function te(o){let e=new URL(o,document.baseURI);return!ge.test(e.pathname)&&!me.test(e.pathname)||/@1\.[^/]+\/?$/.test(e.pathname)?o:(e.hostname==="cdn.jsdmirror.com"?e.origin:ee)+Z}var q=()=>m("我的新衣服好看嘛?","How do you like my new outfit?"),k=o=>Number(localStorage.getItem(o))||0,D=class{constructor(e){this.options=e;this.revision=0;this.loaded=!1;this.useCDN=typeof e.cdnPath=="string";let t=e.modelBaseUrl??(e.cdnPath&&te(e.cdnPath))??e.apiPath;if(typeof t!="string")throw new TypeError("Invalid initWidget argument");this.base=t.endsWith("/")?t:t+"/"}reopen(e){if(this.loaded)window.loadlive2d.show?.(e);else return this.load(void 0,void 0,void 0,e)}cancel(){this.revision++}async fetchCatalog(){let e=this.base+"model_list.json",t=await fetch(e);if(t.status===404&&!this.options.modelBaseUrl&&this.base!==j){let i=await T(j+"model_list.json");return this.base=j,i}if(!t.ok)throw new Error(`Failed to load ${e} (HTTP ${t.status})`);return t.json()}list(){return this.catalog??(this.catalog=this.fetchCatalog().catch(e=>{throw this.catalog=void 0,e}))}async load(e=k("modelId"),t=k("modelTexturesId"),i,n=!1,s=++this.revision,a=!1){let r;if(this.options.modelUrl)r=this.options.modelUrl;else if(this.useCDN){let{models:d}=await this.list();d[e]||(e=0);let f=d[e],u=Array.isArray(f)?f:[f];u[t]||(t=0);let p=a?u[t]:E(u);t=u.indexOf(p),r=this.base+"model/"+p+"/index.json"}else r=this.base+"get/?id="+e+"-"+t;if(s!==this.revision)return;let c=window.loadlive2d("live2d",r,{start:n,locale:this.options.locale,coreUrl:this.options.coreUrl});c&&await c,s===this.revision&&(this.options.modelUrl||(localStorage.setItem("modelId",String(e)),localStorage.setItem("modelTexturesId",String(t))),v(i,4e3,10),this.loaded=!0)}async costume(e){if(this.options.modelUrl||!this.useCDN)return;let t=++this.revision,i=k("modelId"),n=(await this.list()).models[i],a=(Array.isArray(n)?n:[n]).findIndex(r=>new URL(this.base+"model/"+r+"/index.json",document.baseURI).href===e);a>=0&&await this.load(i,a,q(),!1,t,!0)}async nextModel(e=!1){let t=++this.revision,i=k("modelId");if(this.useCDN){let{models:s,messages:a}=await this.list(),r=(i+1)%s.length;return this.load(r,0,m(a[r],"Ready for duty!"),e,t)}let{model:n}=await T(this.base+"switch/?id="+i);return this.load(n.id,0,n.message,e,t)}async nextTexture(e=!1){let t=++this.revision,i=k("modelId"),n=k("modelTexturesId");if(this.useCDN){let a=(await this.list()).models[i],r=Array.isArray(a)?a.length:1;return this.load(i,n,q(),e,t)}let{textures:s}=await T(this.base+"rand_textures/?id="+i+"-"+n);s.id===1&&n===1?v(m("我还没有其他衣服呢!","This is my only outfit so far!"),4e3,10):await this.load(i,s.id,q(),e,t)}};var $=class{constructor(){this.revision=0}begin(e){let t=document.getElementById("waifu"),i=t?.querySelector(".waifu-surface"),n=++this.revision;return t&&(this.still&&!this.still.isConnected&&(i??t).prepend(this.still),t.setAttribute("data-model-loading","")),s=>{if(this.revision!==n||!t)return;let a=document.createElement("canvas");a.className="waifu-model-still",a.setAttribute("aria-hidden","true"),a.width=s.width,a.height=s.height;try{let r=a.getContext("2d");r&&r.drawImage(s,0,0),this.still?.remove(),this.still=r?a:void 0}finally{i&&t.style.setProperty("--waifu-aspect",String(e())),t.removeAttribute("data-model-loading")}}}};var O={scale:1,x:0,y:0},g=128;function W(o,e,t){let i=0;for(let n=0;n<o.length;n++)if(i+=o[n],i>e*t)return n;return o.length-1}function fe(o,e,t,i){let n=new Float64Array(g),s=g,a=0,r=0;for(let x=0;x<o.length;x++){if(!o[x])continue;let M=Math.floor(x/g);n[x%g]+=o[x],r+=o[x],s=Math.min(s,M),a=Math.max(a,M+1)}if(!r)return O;let c=W(n,r,.001),d=W(n,r,.999)+1,f=d-c,u=a-s,p=i?Math.max(.7,Math.min(1.9,f/u*.93/.94)):1;i?.(p);let l=Math.min(1,p),h=Math.min(1,1/p),w=Math.min(.93*g*h/u,.94*g*l/f,5/e.scale),y=0,C=0;if(t)for(let x=s+2;x<a;x+=4)for(let M=c+2;M<d;M+=4){if(o[x*g+M]<96)continue;t((M+.5)/g,(x+.5)/g).some(le=>/^(head|face|body|bust|torso)\d*$/i.test(le))&&(y+=M+.5,C++)}let F=C>=3?y/C:W(n,r,.5)+.5,b=.475*g*l/w,U=Math.max(d-b,Math.min(c+b,F));return{scale:e.scale*w,x:(.5-U/g)*w,y:.5-.03*h+(.5-a/g)*w}}function oe(o){let e={scale:.65,x:0,y:0},t=document.createElement("canvas");t.width=t.height=g;let i=t.getContext("2d",{willReadFrequently:!0}),n=new Uint8Array(g*g),s=0,a=0,r=0;return{initial:e,measure(c,d){if(!i)return O;let f=performance.now();if(!(f<r)){s++;try{i.clearRect(0,0,g,g),i.drawImage(c,0,0,g,g);let{data:u}=i.getImageData(0,0,g,g),p=0;for(let l=0;l<n.length;l++){let h=u[4*l+3];h<24||(n[l]=Math.max(n[l],h),p++)}p>=16&&(a++,r=f+80)}catch{return O}if(!(a<3&&s<10))return a?fe(n,e,d,o):O}}}}var ne=["fairy","doll","adjutant","npc","squad","background"],ie=["default","normal","destroy"];function N(o,e){let t=o.indexOf(e);return t<0?o.length:t}function he(o,e){let t=new Intl.Collator("en",{numeric:!0}),i=o.map(n=>{let[s,a,r,c]=n.split("/"),d=e[[s,a,r].join("/")],f=r==="base"?-1:d??(s==="fairy"&&/^\d+$/.test(r)?Number(r):Number.MAX_SAFE_INTEGER);return{id:n,category:s,character:a,version:r,form:c,order:f}});return i.sort((n,s)=>N(ne,n.category)-N(ne,s.category)||t.compare(n.category,s.category)||t.compare(n.character,s.character)||n.order-s.order||t.compare(n.version,s.version)||N(ie,n.form)-N(ie,s.form)||t.compare(n.form,s.form)),i.map(n=>n.id)}async function se(o,e,t="zh-CN"){let i=new URL(o,document.baseURI),n=await fetch(i);if(!n.ok)throw new Error("Cannot load catalog: HTTP "+n.status);let s=await n.json();if(s.schemaVersion!==1||!s.models||!s.sources)throw new Error("Unsupported model catalog");let a=new Map,r=Object.keys(s.models).filter(l=>(!e||!l.startsWith("other/"))&&s.models[l].some(h=>h.manifest)),c=e?s.presentation:void 0,d=t==="en"?c?.en:c,f=l=>{let h=c?.aliases[l];return h&&r.includes(h)?h:l},u=e?he(r.filter(l=>f(l)===l),c?.outfitOrder??{}):r;function p(l,h){if(e&&!r.includes(l))throw new Error("Model outside the selected collection: "+l);let w=s.models[l]?.find(b=>b.manifest&&(!h||b.source===h));if(!w?.manifest)throw new Error("No model manifest for "+l);let y=new URL(s.sources[w.source].baseUrl,n.url||i);i.hostname==="cdn.jsdmirror.com"&&y.hostname==="cdn.jsdelivr.net"&&y.pathname.startsWith("/gh/nova1751/live2d-api@cdn-")&&(y.hostname=i.hostname);let C=b=>new URL(b.split("/").map(encodeURIComponent).join("/"),y).href,F;if(w.dialogue){let b=a.get(w.source);b||(b=new Map((s.audio?.[w.source]??[]).map(U=>[U.toUpperCase(),C(U)])),a.set(w.source,b)),F={captions:t==="en"?void 0:d?.captions,url:C(w.dialogue),audio:b}}return{captions:d?.captions,modelUrl:C(w.manifest),dialogue:F,soundAliases:w.soundAliases}}return{ids:u,visibleId:f,labels:d?.labels??{},resolve:p,legacyIds:s.legacyIds}}var R=class{constructor(e,t){this.url=e;this.options=t;this.sequence=0;this.transition=new $;let i=t.collection?":"+t.collection:"",n="live2d:model:"+e+i,s=a=>a.replace(/(\/gh\/nova1751\/live2d-api)@catalog-[a-f0-9]{16}(\/catalog\/library\.json:girls-frontline)$/,"$1$2");if(this.key=s(n),this.key!==n&&!localStorage.getItem(this.key)){let a=[n,...Object.keys(localStorage)].find(r=>s(r)===this.key&&localStorage.getItem(r));a&&localStorage.setItem(this.key,localStorage.getItem(a))}}open(){return this.library??(this.library=se(this.url,this.options.collection,this.options.locale).catch(e=>{throw this.library=void 0,e}))}async select(e,t){let i=++this.sequence,n=await this.open();if(i!==this.sequence)return;let s=e(n.ids,n.legacyIds,n.visibleId),{modelUrl:a,dialogue:r,soundAliases:c,captions:d}=n.resolve(s),f=1,u=this.options.collection==="girls-frontline"&&!s.startsWith("background/")?oe(l=>{f=l}):void 0,p=this.options.collection?this.transition.begin(()=>f):void 0;await window.loadlive2d("live2d",a,{start:t,locale:this.options.locale,captions:d,framing:u,onPaint:p,coreUrl:this.options.coreUrl,dialogue:r,soundAliases:c}),i===this.sequence&&(this.active=n.visibleId(s),localStorage.setItem(this.key,s),window.dispatchEvent(new CustomEvent("live2d:model",{detail:s})))}load(e,t,i,n=!1){return this.select((s,a,r)=>{let c=localStorage.getItem(this.key);if(this.options.collection)return this.options.modelId??(c&&s.includes(r(c))?c:s[0]);let d=a?.[Number(localStorage.getItem("modelId"))]?.[Number(localStorage.getItem("modelTexturesId"))];return this.options.modelId??(c&&s.includes(r(c))?c:d&&s.includes(d)?d:s[0])},n)}choose(e){return this.select(()=>e,!1)}cancel(){this.sequence++}reopen(e){if(this.active)window.loadlive2d.show?.(e);else return this.load(void 0,void 0,void 0,e)}character(e){return e.split("/").slice(0,2).join("/")}nextModel(e=!1){return this.select(t=>{let i=[...new Set(t.map(s=>this.character(s)))],n=i[(i.indexOf(this.character(this.active??""))+1)%i.length];return t.find(s=>this.character(s)===n)},e)}nextTexture(e=!1){return this.select(t=>{let i=t.filter(n=>this.character(n)===this.character(this.active??t[0]));{let n=i.filter(s=>s!==this.active);return n.length?n[Math.floor(Math.random()*n.length)]:i[0]}return i[(i.indexOf(this.active??"")+1)%i.length]},e)}async costume(e){let t=await this.open(),i=t.ids.find(n=>t.resolve(n).modelUrl===e);i&&await this.select(()=>i,!1)}};var pe=document.currentScript,we=pe?.dataset.asteroidsUrl??"https://cdn.jsdelivr.net/gh/nova1751/live2d-api@widget-2.4.1/asteroids.js",I=o=>document.getElementById(o);function S(o){console.error("[Live2D]",o);let e=document.getElementById("waifu-status");e&&(e.textContent=m("加载失败,请检查网络或切换模型后重试。","Could not load the model. Check your connection or try another character."),v(e.textContent,5e3,10))}async function ve(o){if(o==="en"){v(["One step at a time, Commander.","Even on a quiet day, there is something worth noticing."],6e3,9);return}let e=await T("https://v1.hitokoto.cn");v(L(e.hitokoto),6e3,9),setTimeout(()=>{v(`这句一言来自 <span>「${L(String(e.from))}」</span>,是 <span>${L(String(e.creator))}</span> 在 hitokoto.cn 投稿的。`,4e3,9)},6e3)}function ye(){if(window.Asteroids)(window.ASTEROIDSPLAYERS??(window.ASTEROIDSPLAYERS=[])).push(new window.Asteroids);else{let o=document.createElement("script");o.src=we,document.head.appendChild(o)}}var ae;function ce(){clearTimeout(ae),localStorage.removeItem("waifu-display"),I("waifu-toggle").setAttribute("tabindex","-1"),I("waifu-toggle").setAttribute("aria-expanded","true"),I("waifu").style.display="",setTimeout(()=>{I("waifu").style.bottom="0"},0)}function V(o){return o.isTrusted&&!!window.loadlive2d.prepareInteraction?.()}function be(){let o=I("waifu").contains(document.activeElement);window.loadlive2d.hide?.(),localStorage.setItem("waifu-display",String(Date.now())),v(m("愿你有一天能与重要的人重逢。","I hope you meet the people you miss again."),2e3,11),I("waifu").style.bottom="-500px",ae=setTimeout(()=>{I("waifu").style.display="none";let e=I("waifu-toggle");e.removeAttribute("tabindex"),e.setAttribute("aria-expanded","false"),e.classList.add("waifu-toggle-active"),o&&e.focus()},window.matchMedia("(prefers-reduced-motion: reduce)").matches?0:3e3)}function re(o,e,t=!1){sessionStorage.removeItem("waifu-text");let i=o.collection==="girls-frontline",n='<canvas id="live2d" width="800" height="800"></canvas>';document.body.insertAdjacentHTML("beforeend",`<div id="waifu" lang="${o.locale==="en"?"en":"zh-CN"}"${i?' class="waifu-adaptive"':""}>
|
|
2
|
+
"use strict";(()=>{var Y="zh-CN";function _(o){Y=o??"zh-CN"}function m(o,e){return Y==="en"?e:o}var G={hitokoto:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --><path d="M512 240c0 114.9-114.6 208-256 208c-37.1 0-72.3-6.4-104.1-17.9c-11.9 8.7-31.3 20.6-54.3 30.6C73.6 471.1 44.7 480 16 480c-6.5 0-12.3-3.9-14.8-9.9c-2.5-6-1.1-12.8 3.4-17.4l0 0 0 0 0 0 0 0 .3-.3c.3-.3 .7-.7 1.3-1.4c1.1-1.2 2.8-3.1 4.9-5.7c4.1-5 9.6-12.4 15.2-21.6c10-16.6 19.5-38.4 21.4-62.9C17.7 326.8 0 285.1 0 240C0 125.1 114.6 32 256 32s256 93.1 256 208z"/></svg>',asteroids:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --><path d="M498.1 5.6c10.1 7 15.4 19.1 13.5 31.2l-64 416c-1.5 9.7-7.4 18.2-16 23s-18.9 5.4-28 1.6L284 427.7l-68.5 74.1c-8.9 9.7-22.9 12.9-35.2 8.1S160 493.2 160 480V396.4c0-4 1.5-7.8 4.2-10.7L331.8 202.8c5.8-6.3 5.6-16-.4-22s-15.7-6.4-22-.7L106 360.8 17.7 316.6C7.1 311.3 .3 300.7 0 288.9s5.9-22.8 16.1-28.7l448-256c10.7-6.1 23.9-5.5 34 1.4z"/></svg>',"switch-model":'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --><path d="M399 384.2C376.9 345.8 335.4 320 288 320H224c-47.4 0-88.9 25.8-111 64.2c35.2 39.2 86.2 63.8 143 63.8s107.8-24.7 143-63.8zM0 256a256 256 0 1 1 512 0A256 256 0 1 1 0 256zm256 16a72 72 0 1 0 0-144 72 72 0 1 0 0 144z"/></svg>',"switch-texture":'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --><path d="M320 64A64 64 0 1 0 192 64a64 64 0 1 0 128 0zm-96 96c-35.3 0-64 28.7-64 64v48c0 17.7 14.3 32 32 32h1.8l11.1 99.5c1.8 16.2 15.5 28.5 31.8 28.5h38.7c16.3 0 30-12.3 31.8-28.5L318.2 304H320c17.7 0 32-14.3 32-32V224c0-35.3-28.7-64-64-64H224zM132.3 394.2c13-2.4 21.7-14.9 19.3-27.9s-14.9-21.7-27.9-19.3c-32.4 5.9-60.9 14.2-82 24.8c-10.5 5.3-20.3 11.7-27.8 19.6C6.4 399.5 0 410.5 0 424c0 21.4 15.5 36.1 29.1 45c14.7 9.6 34.3 17.3 56.4 23.4C130.2 504.7 190.4 512 256 512s125.8-7.3 170.4-19.6c22.1-6.1 41.8-13.8 56.4-23.4c13.7-8.9 29.1-23.6 29.1-45c0-13.5-6.4-24.5-14-32.6c-7.5-7.9-17.3-14.3-27.8-19.6c-21-10.6-49.5-18.9-82-24.8c-13-2.4-25.5 6.3-27.9 19.3s6.3 25.5 19.3 27.9c30.2 5.5 53.7 12.8 69 20.5c3.2 1.6 5.8 3.1 7.9 4.5c3.6 2.4 3.6 7.2 0 9.6c-8.8 5.7-23.1 11.8-43 17.3C374.3 457 318.5 464 256 464s-118.3-7-157.7-17.9c-19.9-5.5-34.2-11.6-43-17.3c-3.6-2.4-3.6-7.2 0-9.6c2.1-1.4 4.8-2.9 7.9-4.5c15.3-7.7 38.8-14.9 69-20.5z"/></svg>',photo:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --><path d="M220.6 121.2L271.1 96 448 96v96H333.2c-21.9-15.1-48.5-24-77.2-24s-55.2 8.9-77.2 24H64V128H192c9.9 0 19.7-2.3 28.6-6.8zM0 128V416c0 35.3 28.7 64 64 64H448c35.3 0 64-28.7 64-64V96c0-35.3-28.7-64-64-64H271.1c-9.9 0-19.7 2.3-28.6 6.8L192 64H160V48c0-8.8-7.2-16-16-16H80c-8.8 0-16 7.2-16 16l0 16C28.7 64 0 92.7 0 128zM168 304a88 88 0 1 1 176 0 88 88 0 1 1 -176 0z"/></svg>',info:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --><path d="M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512zM216 336h24V272H216c-13.3 0-24-10.7-24-24s10.7-24 24-24h48c13.3 0 24 10.7 24 24v88h8c13.3 0 24 10.7 24 24s-10.7 24-24 24H216c-13.3 0-24-10.7-24-24s10.7-24 24-24zm40-208a32 32 0 1 1 0 64 32 32 0 1 1 0-64z"/></svg>',quit:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --><path d="M342.6 150.6c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L192 210.7 86.6 105.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L146.7 256 41.4 361.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0L192 301.3 297.4 406.6c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L237.3 256 342.6 150.6z"/></svg>'};function E(o){return Array.isArray(o)?o[Math.floor(Math.random()*o.length)]:o}function L(o){return o.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}var B,H,k;function P(){clearTimeout(H),sessionStorage.removeItem("waifu-text"),document.getElementById("waifu-tips")?.classList.remove("waifu-tips-active")}function z(o,e){clearTimeout(H),sessionStorage.setItem("waifu-text",String(e));let t=document.getElementById("waifu-tips");t.innerHTML=o,t.classList.add("waifu-tips-active")}function v(o,e,t){!o||k||Number(sessionStorage.getItem("waifu-text"))>t||(z(E(o),t),H=setTimeout(P,e))}function J(o,e){if(!e){v(L(o),5e3,11);return}k=e,z(L(o),11)}function X(o){let e=document.getElementById("live2d");if(!e)return;let t=B?.find(({selector:n})=>e.closest(n)),i=t?E(t.text):B?void 0:m("指挥官,我在。","Right here, Commander.");i&&(k=o,z(i.replace("{text}",()=>L(e.textContent??"")),11))}function K(o,e){k===o&&(k=void 0,e?P():H=setTimeout(P,1200))}function de(o){if(location.pathname==="/"){let s=new Date().getHours();for(let{hour:a,text:r}of o){let[c,d=c]=a.split("-").map(Number);if(c<=s&&s<=d)return r}}let e=L(document.title.split(" - ")[0]),t=m(`欢迎阅读<span>「${e}」</span>`,`Welcome to <span>${e}</span>!`);if(!document.referrer)return t;let{hostname:i}=new URL(document.referrer);return i===location.hostname?t:m(`Hello!来自 <span>${L({baidu:"百度",so:"360搜索",google:"谷歌搜索"}[i.split(".")[1]]??i)}</span> 的朋友<br>${t}`,`Hello, visitor from <span>${L(i)}</span>!<br>${t}`)}function ue(o){let[e,t]=o.split("/").map(Number);return e*100+t}function Q(o){B=o.click;let e=[...o.message.default],t=new Date,i=(t.getMonth()+1)*100+t.getDate();for(let{date:u,text:p}of o.seasons){let[l,h=l]=u.split("-").map(ue);l<=i&&i<=h&&e.push(E(p).replace("{year}",String(t.getFullYear())))}let n=2e4,s=Date.now(),a;function r(){if(document.hidden)return;let u=n-(Date.now()-s);u<=0&&!localStorage.getItem("waifu-display")&&v(e,6e3,9),a=setTimeout(r,u>0?u:n)}let c=()=>{s=Date.now()};window.addEventListener("pointermove",c,{passive:!0}),window.addEventListener("pointerdown",c,{passive:!0}),window.addEventListener("keydown",c),document.hidden||(a=setTimeout(r,n)),v(de(o.time),7e3,11);let d;for(let u of["mouseover","click"])window.addEventListener(u,p=>{let l=p.target;if(!(l instanceof Element)||p.live2dHandlesCaption)return;let h=u==="click"&&l.closest("#waifu .waifu-model-stage"),w=h?document.getElementById("live2d"):l.closest("#live2d"),y=o[u].find(({selector:C})=>l.closest(C)||h&&w?.closest(C));!y||u==="mouseover"&&y.selector===d||(u==="mouseover"&&(d=y.selector),v(E(y.text).replace("{text}",()=>L(l.textContent??"")),4e3,u==="click"&&w?11:8))});let f=()=>{};f.toString=()=>(v(o.message.console,6e3,9),""),console.log("%c",f),window.addEventListener("copy",()=>v(o.message.copy,6e3,9)),document.addEventListener("visibilitychange",()=>{clearTimeout(a),document.hidden||(c(),a=setTimeout(r,n),localStorage.getItem("waifu-display")||v(o.message.visibilitychange,6e3,9))})}async function T(o){let e=await fetch(o);if(!e.ok)throw new Error(`Failed to load ${o} (HTTP ${e.status})`);return e.json()}var Z="/gh/nova1751/live2d-api@cdn-b3ac5ae545e2/",ee="https://cdn.jsdelivr.net",j=ee+Z,me=/\/gh\/nova1751\/live2d-api@widget-[^/]+\/?$/,ge=/\/live2dapi-noa(?:@[^/]+)?\/?$/;function te(o){let e=new URL(o,document.baseURI);return!ge.test(e.pathname)&&!me.test(e.pathname)||/@1\.[^/]+\/?$/.test(e.pathname)?o:(e.hostname==="cdn.jsdmirror.com"?e.origin:ee)+Z}var q=()=>m("我的新衣服好看嘛?","How do you like my new outfit?"),A=o=>Number(localStorage.getItem(o))||0,D=class{constructor(e){this.options=e;this.revision=0;this.loaded=!1;this.useCDN=typeof e.cdnPath=="string";let t=e.modelBaseUrl??(e.cdnPath&&te(e.cdnPath))??e.apiPath;if(typeof t!="string")throw new TypeError("Invalid initWidget argument");this.base=t.endsWith("/")?t:t+"/"}reopen(e){if(this.loaded)window.loadlive2d.show?.(e);else return this.load(void 0,void 0,void 0,e)}cancel(){this.revision++}async fetchCatalog(){let e=this.base+"model_list.json",t=await fetch(e);if(t.status===404&&!this.options.modelBaseUrl&&this.base!==j){let i=await T(j+"model_list.json");return this.base=j,i}if(!t.ok)throw new Error(`Failed to load ${e} (HTTP ${t.status})`);return t.json()}list(){return this.catalog??(this.catalog=this.fetchCatalog().catch(e=>{throw this.catalog=void 0,e}))}async load(e=A("modelId"),t=A("modelTexturesId"),i,n=!1,s=++this.revision,a=!1){let r;if(this.options.modelUrl)r=this.options.modelUrl;else if(this.useCDN){let{models:d}=await this.list();d[e]||(e=0);let f=d[e],u=Array.isArray(f)?f:[f];u[t]||(t=0);let p=a?u[t]:E(u);t=u.indexOf(p),r=this.base+"model/"+p+"/index.json"}else r=this.base+"get/?id="+e+"-"+t;if(s!==this.revision)return;let c=window.loadlive2d("live2d",r,{start:n,locale:this.options.locale,coreUrl:this.options.coreUrl});c&&await c,s===this.revision&&(this.options.modelUrl||(localStorage.setItem("modelId",String(e)),localStorage.setItem("modelTexturesId",String(t))),v(i,4e3,10),this.loaded=!0)}async costume(e){if(this.options.modelUrl||!this.useCDN)return;let t=++this.revision,i=A("modelId"),n=(await this.list()).models[i],a=(Array.isArray(n)?n:[n]).findIndex(r=>new URL(this.base+"model/"+r+"/index.json",document.baseURI).href===e);a>=0&&await this.load(i,a,q(),!1,t,!0)}async nextModel(e=!1){let t=++this.revision,i=A("modelId");if(this.useCDN){let{models:s,messages:a}=await this.list(),r=(i+1)%s.length;return this.load(r,0,m(a[r],"Ready for duty!"),e,t)}let{model:n}=await T(this.base+"switch/?id="+i);return this.load(n.id,0,n.message,e,t)}async nextTexture(e=!1){let t=++this.revision,i=A("modelId"),n=A("modelTexturesId");if(this.useCDN){let a=(await this.list()).models[i],r=Array.isArray(a)?a.length:1;return this.load(i,n,q(),e,t)}let{textures:s}=await T(this.base+"rand_textures/?id="+i+"-"+n);s.id===1&&n===1?v(m("我还没有其他衣服呢!","This is my only outfit so far!"),4e3,10):await this.load(i,s.id,q(),e,t)}};var $=class{constructor(){this.revision=0}begin(e){let t=document.getElementById("waifu"),i=t?.querySelector(".waifu-surface"),n=++this.revision;return t&&(this.still&&!this.still.isConnected&&(i??t).prepend(this.still),t.setAttribute("data-model-loading","")),s=>{if(this.revision!==n||!t)return;let a=document.createElement("canvas");a.className="waifu-model-still",a.setAttribute("aria-hidden","true"),a.width=s.width,a.height=s.height;try{let r=a.getContext("2d");r&&r.drawImage(s,0,0),this.still?.remove(),this.still=r?a:void 0}finally{if(i){let r=e();t.style.setProperty("--waifu-aspect",String(r)),t.toggleAttribute("data-wide-model",r>=1.35)}t.removeAttribute("data-model-loading")}}}};var O={scale:1,x:0,y:0},g=128;function W(o,e,t){let i=0;for(let n=0;n<o.length;n++)if(i+=o[n],i>e*t)return n;return o.length-1}function fe(o,e,t,i){let n=new Float64Array(g),s=g,a=0,r=0;for(let x=0;x<o.length;x++){if(!o[x])continue;let M=Math.floor(x/g);n[x%g]+=o[x],r+=o[x],s=Math.min(s,M),a=Math.max(a,M+1)}if(!r)return O;let c=W(n,r,.001),d=W(n,r,.999)+1,f=d-c,u=a-s,p=i?Math.max(.7,Math.min(1.9,f/u*.93/.94)):1;i?.(p);let l=Math.min(1,p),h=Math.min(1,1/p),w=Math.min(.93*g*h/u,.94*g*l/f,5/e.scale),y=0,C=0;if(t)for(let x=s+2;x<a;x+=4)for(let M=c+2;M<d;M+=4){if(o[x*g+M]<96)continue;t((M+.5)/g,(x+.5)/g).some(le=>/^(head|face|body|bust|torso)\d*$/i.test(le))&&(y+=M+.5,C++)}let F=C>=3?y/C:W(n,r,.5)+.5,b=.475*g*l/w,U=Math.max(d-b,Math.min(c+b,F));return{scale:e.scale*w,x:(.5-U/g)*w,y:.5-.03*h+(.5-a/g)*w}}function oe(o){let e={scale:.65,x:0,y:0},t=document.createElement("canvas");t.width=t.height=g;let i=t.getContext("2d",{willReadFrequently:!0}),n=new Uint8Array(g*g),s=0,a=0,r=0;return{initial:e,measure(c,d){if(!i)return O;let f=performance.now();if(!(f<r)){s++;try{i.clearRect(0,0,g,g),i.drawImage(c,0,0,g,g);let{data:u}=i.getImageData(0,0,g,g),p=0;for(let l=0;l<n.length;l++){let h=u[4*l+3];h<24||(n[l]=Math.max(n[l],h),p++)}p>=16&&(a++,r=f+80)}catch{return O}if(!(a<3&&s<10))return a?fe(n,e,d,o):O}}}}var ne=["fairy","doll","adjutant","npc","squad","background"],ie=["default","normal","destroy"];function N(o,e){let t=o.indexOf(e);return t<0?o.length:t}function he(o,e){let t=new Intl.Collator("en",{numeric:!0}),i=o.map(n=>{let[s,a,r,c]=n.split("/"),d=e[[s,a,r].join("/")],f=r==="base"?-1:d??(s==="fairy"&&/^\d+$/.test(r)?Number(r):Number.MAX_SAFE_INTEGER);return{id:n,category:s,character:a,version:r,form:c,order:f}});return i.sort((n,s)=>N(ne,n.category)-N(ne,s.category)||t.compare(n.category,s.category)||t.compare(n.character,s.character)||n.order-s.order||t.compare(n.version,s.version)||N(ie,n.form)-N(ie,s.form)||t.compare(n.form,s.form)),i.map(n=>n.id)}async function se(o,e,t="zh-CN"){let i=new URL(o,document.baseURI),n=await fetch(i);if(!n.ok)throw new Error("Cannot load catalog: HTTP "+n.status);let s=await n.json();if(s.schemaVersion!==1||!s.models||!s.sources)throw new Error("Unsupported model catalog");let a=new Map,r=Object.keys(s.models).filter(l=>(!e||!l.startsWith("other/"))&&s.models[l].some(h=>h.manifest)),c=e?s.presentation:void 0,d=t==="en"?c?.en:c,f=l=>{let h=c?.aliases[l];return h&&r.includes(h)?h:l},u=e?he(r.filter(l=>f(l)===l),c?.outfitOrder??{}):r;function p(l,h){if(e&&!r.includes(l))throw new Error("Model outside the selected collection: "+l);let w=s.models[l]?.find(b=>b.manifest&&(!h||b.source===h));if(!w?.manifest)throw new Error("No model manifest for "+l);let y=new URL(s.sources[w.source].baseUrl,n.url||i);i.hostname==="cdn.jsdmirror.com"&&y.hostname==="cdn.jsdelivr.net"&&y.pathname.startsWith("/gh/nova1751/live2d-api@cdn-")&&(y.hostname=i.hostname);let C=b=>new URL(b.split("/").map(encodeURIComponent).join("/"),y).href,F;if(w.dialogue){let b=a.get(w.source);b||(b=new Map((s.audio?.[w.source]??[]).map(U=>[U.toUpperCase(),C(U)])),a.set(w.source,b)),F={captions:t==="en"?void 0:d?.captions,url:C(w.dialogue),audio:b}}return{captions:d?.captions,modelUrl:C(w.manifest),dialogue:F,soundAliases:w.soundAliases}}return{ids:u,visibleId:f,labels:d?.labels??{},resolve:p,legacyIds:s.legacyIds}}var R=class{constructor(e,t){this.url=e;this.options=t;this.sequence=0;this.transition=new $;let i=t.collection?":"+t.collection:"",n="live2d:model:"+e+i,s=a=>a.replace(/(\/gh\/nova1751\/live2d-api)@catalog-[a-f0-9]{16}(\/catalog\/library\.json:girls-frontline)$/,"$1$2");if(this.key=s(n),this.key!==n&&!localStorage.getItem(this.key)){let a=[n,...Object.keys(localStorage)].find(r=>s(r)===this.key&&localStorage.getItem(r));a&&localStorage.setItem(this.key,localStorage.getItem(a))}}open(){return this.library??(this.library=se(this.url,this.options.collection,this.options.locale).catch(e=>{throw this.library=void 0,e}))}async select(e,t){let i=++this.sequence,n=await this.open();if(i!==this.sequence)return;let s=e(n.ids,n.legacyIds,n.visibleId),{modelUrl:a,dialogue:r,soundAliases:c,captions:d}=n.resolve(s),f=1,u=this.options.collection==="girls-frontline"&&!s.startsWith("background/")?oe(l=>{f=l}):void 0,p=this.options.collection?this.transition.begin(()=>f):void 0;await window.loadlive2d("live2d",a,{start:t,locale:this.options.locale,captions:d,framing:u,onPaint:p,coreUrl:this.options.coreUrl,dialogue:r,soundAliases:c}),i===this.sequence&&(this.active=n.visibleId(s),localStorage.setItem(this.key,s),window.dispatchEvent(new CustomEvent("live2d:model",{detail:s})))}load(e,t,i,n=!1){return this.select((s,a,r)=>{let c=localStorage.getItem(this.key);if(this.options.collection)return this.options.modelId??(c&&s.includes(r(c))?c:s[0]);let d=a?.[Number(localStorage.getItem("modelId"))]?.[Number(localStorage.getItem("modelTexturesId"))];return this.options.modelId??(c&&s.includes(r(c))?c:d&&s.includes(d)?d:s[0])},n)}choose(e){return this.select(()=>e,!1)}cancel(){this.sequence++}reopen(e){if(this.active)window.loadlive2d.show?.(e);else return this.load(void 0,void 0,void 0,e)}character(e){return e.split("/").slice(0,2).join("/")}nextModel(e=!1){return this.select(t=>{let i=[...new Set(t.map(s=>this.character(s)))],n=i[(i.indexOf(this.character(this.active??""))+1)%i.length];return t.find(s=>this.character(s)===n)},e)}nextTexture(e=!1){return this.select(t=>{let i=t.filter(n=>this.character(n)===this.character(this.active??t[0]));{let n=i.filter(s=>s!==this.active);return n.length?n[Math.floor(Math.random()*n.length)]:i[0]}return i[(i.indexOf(this.active??"")+1)%i.length]},e)}async costume(e){let t=await this.open(),i=t.ids.find(n=>t.resolve(n).modelUrl===e);i&&await this.select(()=>i,!1)}};var pe=document.currentScript,we=pe?.dataset.asteroidsUrl??"https://cdn.jsdelivr.net/gh/nova1751/live2d-api@widget-2.4.2/asteroids.js",I=o=>document.getElementById(o);function S(o){console.error("[Live2D]",o);let e=document.getElementById("waifu-status");e&&(e.textContent=m("加载失败,请检查网络或切换模型后重试。","Could not load the model. Check your connection or try another character."),v(e.textContent,5e3,10))}async function ve(o){if(o==="en"){v(["One step at a time, Commander.","Even on a quiet day, there is something worth noticing."],6e3,9);return}let e=await T("https://v1.hitokoto.cn");v(L(e.hitokoto),6e3,9),setTimeout(()=>{v(`这句一言来自 <span>「${L(String(e.from))}」</span>,是 <span>${L(String(e.creator))}</span> 在 hitokoto.cn 投稿的。`,4e3,9)},6e3)}function ye(){if(window.Asteroids)(window.ASTEROIDSPLAYERS??(window.ASTEROIDSPLAYERS=[])).push(new window.Asteroids);else{let o=document.createElement("script");o.src=we,document.head.appendChild(o)}}var ae;function ce(){clearTimeout(ae),localStorage.removeItem("waifu-display"),I("waifu-toggle").setAttribute("tabindex","-1"),I("waifu-toggle").setAttribute("aria-expanded","true"),I("waifu").style.display="",setTimeout(()=>{I("waifu").style.bottom="0"},0)}function V(o){return o.isTrusted&&!!window.loadlive2d.prepareInteraction?.()}function be(){let o=I("waifu").contains(document.activeElement);window.loadlive2d.hide?.(),localStorage.setItem("waifu-display",String(Date.now())),v(m("愿你有一天能与重要的人重逢。","I hope you meet the people you miss again."),2e3,11),I("waifu").style.bottom="-500px",ae=setTimeout(()=>{I("waifu").style.display="none";let e=I("waifu-toggle");e.removeAttribute("tabindex"),e.setAttribute("aria-expanded","false"),e.classList.add("waifu-toggle-active"),o&&e.focus()},window.matchMedia("(prefers-reduced-motion: reduce)").matches?0:3e3)}function re(o,e,t=!1){sessionStorage.removeItem("waifu-text");let i=o.collection==="girls-frontline",n='<canvas id="live2d" width="800" height="800"></canvas>';document.body.insertAdjacentHTML("beforeend",`<div id="waifu" lang="${o.locale==="en"?"en":"zh-CN"}"${i?' class="waifu-adaptive"':""}>
|
|
3
3
|
<div id="waifu-status" role="status" class="waifu-sr-only"></div>
|
|
4
4
|
<div id="waifu-tips"></div>
|
|
5
5
|
${i?`<div class="waifu-viewport"><div class="waifu-surface">${n}</div></div>`:n}
|
|
@@ -8,7 +8,7 @@ const live2d_path = (() => {
|
|
|
8
8
|
return new URL("../../", url).href;
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
-
return "https://cdn.jsdelivr.net/gh/nova1751/live2d-api@widget-2.4.
|
|
11
|
+
return "https://cdn.jsdelivr.net/gh/nova1751/live2d-api@widget-2.4.2/";
|
|
12
12
|
})();
|
|
13
13
|
function loadExternalResource(url, type) {
|
|
14
14
|
let tag;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*! Live2D API | Generated from src/ | https://github.com/nova1751/live2d-api */
|
|
2
|
-
"use strict";(()=>{var Y="zh-CN";function _(o){Y=o??"zh-CN"}function m(o,e){return Y==="en"?e:o}var G={hitokoto:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --><path d="M512 240c0 114.9-114.6 208-256 208c-37.1 0-72.3-6.4-104.1-17.9c-11.9 8.7-31.3 20.6-54.3 30.6C73.6 471.1 44.7 480 16 480c-6.5 0-12.3-3.9-14.8-9.9c-2.5-6-1.1-12.8 3.4-17.4l0 0 0 0 0 0 0 0 .3-.3c.3-.3 .7-.7 1.3-1.4c1.1-1.2 2.8-3.1 4.9-5.7c4.1-5 9.6-12.4 15.2-21.6c10-16.6 19.5-38.4 21.4-62.9C17.7 326.8 0 285.1 0 240C0 125.1 114.6 32 256 32s256 93.1 256 208z"/></svg>',asteroids:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --><path d="M498.1 5.6c10.1 7 15.4 19.1 13.5 31.2l-64 416c-1.5 9.7-7.4 18.2-16 23s-18.9 5.4-28 1.6L284 427.7l-68.5 74.1c-8.9 9.7-22.9 12.9-35.2 8.1S160 493.2 160 480V396.4c0-4 1.5-7.8 4.2-10.7L331.8 202.8c5.8-6.3 5.6-16-.4-22s-15.7-6.4-22-.7L106 360.8 17.7 316.6C7.1 311.3 .3 300.7 0 288.9s5.9-22.8 16.1-28.7l448-256c10.7-6.1 23.9-5.5 34 1.4z"/></svg>',"switch-model":'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --><path d="M399 384.2C376.9 345.8 335.4 320 288 320H224c-47.4 0-88.9 25.8-111 64.2c35.2 39.2 86.2 63.8 143 63.8s107.8-24.7 143-63.8zM0 256a256 256 0 1 1 512 0A256 256 0 1 1 0 256zm256 16a72 72 0 1 0 0-144 72 72 0 1 0 0 144z"/></svg>',"switch-texture":'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --><path d="M320 64A64 64 0 1 0 192 64a64 64 0 1 0 128 0zm-96 96c-35.3 0-64 28.7-64 64v48c0 17.7 14.3 32 32 32h1.8l11.1 99.5c1.8 16.2 15.5 28.5 31.8 28.5h38.7c16.3 0 30-12.3 31.8-28.5L318.2 304H320c17.7 0 32-14.3 32-32V224c0-35.3-28.7-64-64-64H224zM132.3 394.2c13-2.4 21.7-14.9 19.3-27.9s-14.9-21.7-27.9-19.3c-32.4 5.9-60.9 14.2-82 24.8c-10.5 5.3-20.3 11.7-27.8 19.6C6.4 399.5 0 410.5 0 424c0 21.4 15.5 36.1 29.1 45c14.7 9.6 34.3 17.3 56.4 23.4C130.2 504.7 190.4 512 256 512s125.8-7.3 170.4-19.6c22.1-6.1 41.8-13.8 56.4-23.4c13.7-8.9 29.1-23.6 29.1-45c0-13.5-6.4-24.5-14-32.6c-7.5-7.9-17.3-14.3-27.8-19.6c-21-10.6-49.5-18.9-82-24.8c-13-2.4-25.5 6.3-27.9 19.3s6.3 25.5 19.3 27.9c30.2 5.5 53.7 12.8 69 20.5c3.2 1.6 5.8 3.1 7.9 4.5c3.6 2.4 3.6 7.2 0 9.6c-8.8 5.7-23.1 11.8-43 17.3C374.3 457 318.5 464 256 464s-118.3-7-157.7-17.9c-19.9-5.5-34.2-11.6-43-17.3c-3.6-2.4-3.6-7.2 0-9.6c2.1-1.4 4.8-2.9 7.9-4.5c15.3-7.7 38.8-14.9 69-20.5z"/></svg>',photo:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --><path d="M220.6 121.2L271.1 96 448 96v96H333.2c-21.9-15.1-48.5-24-77.2-24s-55.2 8.9-77.2 24H64V128H192c9.9 0 19.7-2.3 28.6-6.8zM0 128V416c0 35.3 28.7 64 64 64H448c35.3 0 64-28.7 64-64V96c0-35.3-28.7-64-64-64H271.1c-9.9 0-19.7 2.3-28.6 6.8L192 64H160V48c0-8.8-7.2-16-16-16H80c-8.8 0-16 7.2-16 16l0 16C28.7 64 0 92.7 0 128zM168 304a88 88 0 1 1 176 0 88 88 0 1 1 -176 0z"/></svg>',info:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --><path d="M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512zM216 336h24V272H216c-13.3 0-24-10.7-24-24s10.7-24 24-24h48c13.3 0 24 10.7 24 24v88h8c13.3 0 24 10.7 24 24s-10.7 24-24 24H216c-13.3 0-24-10.7-24-24s10.7-24 24-24zm40-208a32 32 0 1 1 0 64 32 32 0 1 1 0-64z"/></svg>',quit:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --><path d="M342.6 150.6c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L192 210.7 86.6 105.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L146.7 256 41.4 361.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0L192 301.3 297.4 406.6c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L237.3 256 342.6 150.6z"/></svg>'};function U(o){return Array.isArray(o)?o[Math.floor(Math.random()*o.length)]:o}function L(o){return o.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}var B,H,E;function P(){clearTimeout(H),sessionStorage.removeItem("waifu-text"),document.getElementById("waifu-tips")?.classList.remove("waifu-tips-active")}function z(o,e){clearTimeout(H),sessionStorage.setItem("waifu-text",String(e));let t=document.getElementById("waifu-tips");t.innerHTML=o,t.classList.add("waifu-tips-active")}function v(o,e,t){!o||E||Number(sessionStorage.getItem("waifu-text"))>t||(z(U(o),t),H=setTimeout(P,e))}function J(o,e){if(!e){v(L(o),5e3,11);return}E=e,z(L(o),11)}function X(o){let e=document.getElementById("live2d");if(!e)return;let t=B?.find(({selector:n})=>e.closest(n)),i=t?U(t.text):B?void 0:m("指挥官,我在。","Right here, Commander.");i&&(E=o,z(i.replace("{text}",()=>L(e.textContent??"")),11))}function K(o,e){E===o&&(E=void 0,e?P():H=setTimeout(P,1200))}function de(o){if(location.pathname==="/"){let s=new Date().getHours();for(let{hour:a,text:r}of o){let[c,d=c]=a.split("-").map(Number);if(c<=s&&s<=d)return r}}let e=L(document.title.split(" - ")[0]),t=m(`欢迎阅读<span>「${e}」</span>`,`Welcome to <span>${e}</span>!`);if(!document.referrer)return t;let{hostname:i}=new URL(document.referrer);return i===location.hostname?t:m(`Hello!来自 <span>${L({baidu:"百度",so:"360搜索",google:"谷歌搜索"}[i.split(".")[1]]??i)}</span> 的朋友<br>${t}`,`Hello, visitor from <span>${L(i)}</span>!<br>${t}`)}function ue(o){let[e,t]=o.split("/").map(Number);return e*100+t}function Q(o){B=o.click;let e=[...o.message.default],t=new Date,i=(t.getMonth()+1)*100+t.getDate();for(let{date:u,text:p}of o.seasons){let[l,h=l]=u.split("-").map(ue);l<=i&&i<=h&&e.push(U(p).replace("{year}",String(t.getFullYear())))}let n=2e4,s=Date.now(),a;function r(){if(document.hidden)return;let u=n-(Date.now()-s);u<=0&&!localStorage.getItem("waifu-display")&&v(e,6e3,9),a=setTimeout(r,u>0?u:n)}let c=()=>{s=Date.now()};window.addEventListener("pointermove",c,{passive:!0}),window.addEventListener("pointerdown",c,{passive:!0}),window.addEventListener("keydown",c),document.hidden||(a=setTimeout(r,n)),v(de(o.time),7e3,11);let d;for(let u of["mouseover","click"])window.addEventListener(u,p=>{let l=p.target;if(!(l instanceof Element)||p.live2dHandlesCaption)return;let h=u==="click"&&l.closest("#waifu .waifu-model-stage"),w=h?document.getElementById("live2d"):l.closest("#live2d"),y=o[u].find(({selector:C})=>l.closest(C)||h&&w?.closest(C));!y||u==="mouseover"&&y.selector===d||(u==="mouseover"&&(d=y.selector),v(U(y.text).replace("{text}",()=>L(l.textContent??"")),4e3,u==="click"&&w?11:8))});let g=()=>{};g.toString=()=>(v(o.message.console,6e3,9),""),console.log("%c",g),window.addEventListener("copy",()=>v(o.message.copy,6e3,9)),document.addEventListener("visibilitychange",()=>{clearTimeout(a),document.hidden||(c(),a=setTimeout(r,n),localStorage.getItem("waifu-display")||v(o.message.visibilitychange,6e3,9))})}async function T(o){let e=await fetch(o);if(!e.ok)throw new Error(`Failed to load ${o} (HTTP ${e.status})`);return e.json()}var Z="/gh/nova1751/live2d-api@cdn-b3ac5ae545e2/",ee="https://cdn.jsdelivr.net",j=ee+Z,me=/\/gh\/nova1751\/live2d-api@widget-[^/]+\/?$/,fe=/\/live2dapi-noa(?:@[^/]+)?\/?$/;function te(o){let e=new URL(o,document.baseURI);return!fe.test(e.pathname)&&!me.test(e.pathname)||/@1\.[^/]+\/?$/.test(e.pathname)?o:(e.hostname==="cdn.jsdmirror.com"?e.origin:ee)+Z}var q=()=>m("我的新衣服好看嘛?","How do you like my new outfit?"),k=o=>Number(localStorage.getItem(o))||0,D=class{constructor(e){this.options=e;this.revision=0;this.loaded=!1;this.useCDN=typeof e.cdnPath=="string";let t=e.modelBaseUrl??(e.cdnPath&&te(e.cdnPath))??e.apiPath;if(typeof t!="string")throw new TypeError("Invalid initWidget argument");this.base=t.endsWith("/")?t:t+"/"}reopen(e){if(this.loaded)window.loadlive2d.show?.(e);else return this.load(void 0,void 0,void 0,e)}cancel(){this.revision++}async fetchCatalog(){let e=this.base+"model_list.json",t=await fetch(e);if(t.status===404&&!this.options.modelBaseUrl&&this.base!==j){let i=await T(j+"model_list.json");return this.base=j,i}if(!t.ok)throw new Error(`Failed to load ${e} (HTTP ${t.status})`);return t.json()}list(){return this.catalog??(this.catalog=this.fetchCatalog().catch(e=>{throw this.catalog=void 0,e}))}async load(e=k("modelId"),t=k("modelTexturesId"),i,n=!1,s=++this.revision,a=!1){let r;if(this.options.modelUrl)r=this.options.modelUrl;else if(this.useCDN){let{models:d}=await this.list();d[e]||(e=0);let g=d[e],u=Array.isArray(g)?g:[g];u[t]||(t=0);let p=u[t];t=u.indexOf(p),r=this.base+"model/"+p+"/index.json"}else r=this.base+"get/?id="+e+"-"+t;if(s!==this.revision)return;let c=window.loadlive2d("live2d",r,{start:n,locale:this.options.locale,coreUrl:this.options.coreUrl});c&&await c,s===this.revision&&(this.options.modelUrl||(localStorage.setItem("modelId",String(e)),localStorage.setItem("modelTexturesId",String(t))),v(i,4e3,10),this.loaded=!0)}async costume(e){if(this.options.modelUrl||!this.useCDN)return;let t=++this.revision,i=k("modelId"),n=(await this.list()).models[i],a=(Array.isArray(n)?n:[n]).findIndex(r=>new URL(this.base+"model/"+r+"/index.json",document.baseURI).href===e);a>=0&&await this.load(i,a,q(),!1,t,!0)}async nextModel(e=!1){let t=++this.revision,i=k("modelId");if(this.useCDN){let{models:s,messages:a}=await this.list(),r=(i+1)%s.length;return this.load(r,0,m(a[r],"Ready for duty!"),e,t)}let{model:n}=await T(this.base+"switch/?id="+i);return this.load(n.id,0,n.message,e,t)}async nextTexture(e=!1){let t=++this.revision,i=k("modelId"),n=k("modelTexturesId");if(this.useCDN){let a=(await this.list()).models[i],r=Array.isArray(a)?a.length:1;return this.load(i,(n+1)%r,q(),e,t)}let{textures:s}=await T(this.base+"rand_textures/?id="+i+"-"+n);s.id===1&&n===1?v(m("我还没有其他衣服呢!","This is my only outfit so far!"),4e3,10):await this.load(i,s.id,q(),e,t)}};var $=class{constructor(){this.revision=0}begin(e){let t=document.getElementById("waifu"),i=t?.querySelector(".waifu-surface"),n=++this.revision;return t&&(this.still&&!this.still.isConnected&&(i??t).prepend(this.still),t.setAttribute("data-model-loading","")),s=>{if(this.revision!==n||!t)return;let a=document.createElement("canvas");a.className="waifu-model-still",a.setAttribute("aria-hidden","true"),a.width=s.width,a.height=s.height;try{let r=a.getContext("2d");r&&r.drawImage(s,0,0),this.still?.remove(),this.still=r?a:void 0}finally{i&&t.style.setProperty("--waifu-aspect",String(e())),t.removeAttribute("data-model-loading")}}}};var O={scale:1,x:0,y:0},f=128;function W(o,e,t){let i=0;for(let n=0;n<o.length;n++)if(i+=o[n],i>e*t)return n;return o.length-1}function ge(o,e,t,i){let n=new Float64Array(f),s=f,a=0,r=0;for(let x=0;x<o.length;x++){if(!o[x])continue;let M=Math.floor(x/f);n[x%f]+=o[x],r+=o[x],s=Math.min(s,M),a=Math.max(a,M+1)}if(!r)return O;let c=W(n,r,.001),d=W(n,r,.999)+1,g=d-c,u=a-s,p=i?Math.max(.7,Math.min(1.9,g/u*.93/.94)):1;i?.(p);let l=Math.min(1,p),h=Math.min(1,1/p),w=Math.min(.93*f*h/u,.94*f*l/g,5/e.scale),y=0,C=0;if(t)for(let x=s+2;x<a;x+=4)for(let M=c+2;M<d;M+=4){if(o[x*f+M]<96)continue;t((M+.5)/f,(x+.5)/f).some(le=>/^(head|face|body|bust|torso)\d*$/i.test(le))&&(y+=M+.5,C++)}let R=C>=3?y/C:W(n,r,.5)+.5,b=.475*f*l/w,F=Math.max(d-b,Math.min(c+b,R));return{scale:e.scale*w,x:(.5-F/f)*w,y:.5-.03*h+(.5-a/f)*w}}function oe(o){let e={scale:.65,x:0,y:0},t=document.createElement("canvas");t.width=t.height=f;let i=t.getContext("2d",{willReadFrequently:!0}),n=new Uint8Array(f*f),s=0,a=0,r=0;return{initial:e,measure(c,d){if(!i)return O;let g=performance.now();if(!(g<r)){s++;try{i.clearRect(0,0,f,f),i.drawImage(c,0,0,f,f);let{data:u}=i.getImageData(0,0,f,f),p=0;for(let l=0;l<n.length;l++){let h=u[4*l+3];h<24||(n[l]=Math.max(n[l],h),p++)}p>=16&&(a++,r=g+80)}catch{return O}if(!(a<3&&s<10))return a?ge(n,e,d,o):O}}}}var ne=["fairy","doll","adjutant","npc","squad","background"],ie=["default","normal","destroy"];function N(o,e){let t=o.indexOf(e);return t<0?o.length:t}function he(o,e){let t=new Intl.Collator("en",{numeric:!0}),i=o.map(n=>{let[s,a,r,c]=n.split("/"),d=e[[s,a,r].join("/")],g=r==="base"?-1:d??(s==="fairy"&&/^\d+$/.test(r)?Number(r):Number.MAX_SAFE_INTEGER);return{id:n,category:s,character:a,version:r,form:c,order:g}});return i.sort((n,s)=>N(ne,n.category)-N(ne,s.category)||t.compare(n.category,s.category)||t.compare(n.character,s.character)||n.order-s.order||t.compare(n.version,s.version)||N(ie,n.form)-N(ie,s.form)||t.compare(n.form,s.form)),i.map(n=>n.id)}async function se(o,e,t="zh-CN"){let i=new URL(o,document.baseURI),n=await fetch(i);if(!n.ok)throw new Error("Cannot load catalog: HTTP "+n.status);let s=await n.json();if(s.schemaVersion!==1||!s.models||!s.sources)throw new Error("Unsupported model catalog");let a=new Map,r=Object.keys(s.models).filter(l=>(!e||!l.startsWith("other/"))&&s.models[l].some(h=>h.manifest)),c=e?s.presentation:void 0,d=t==="en"?c?.en:c,g=l=>{let h=c?.aliases[l];return h&&r.includes(h)?h:l},u=e?he(r.filter(l=>g(l)===l),c?.outfitOrder??{}):r;function p(l,h){if(e&&!r.includes(l))throw new Error("Model outside the selected collection: "+l);let w=s.models[l]?.find(b=>b.manifest&&(!h||b.source===h));if(!w?.manifest)throw new Error("No model manifest for "+l);let y=new URL(s.sources[w.source].baseUrl,n.url||i);i.hostname==="cdn.jsdmirror.com"&&y.hostname==="cdn.jsdelivr.net"&&y.pathname.startsWith("/gh/nova1751/live2d-api@cdn-")&&(y.hostname=i.hostname);let C=b=>new URL(b.split("/").map(encodeURIComponent).join("/"),y).href,R;if(w.dialogue){let b=a.get(w.source);b||(b=new Map((s.audio?.[w.source]??[]).map(F=>[F.toUpperCase(),C(F)])),a.set(w.source,b)),R={captions:t==="en"?void 0:d?.captions,url:C(w.dialogue),audio:b}}return{captions:d?.captions,modelUrl:C(w.manifest),dialogue:R,soundAliases:w.soundAliases}}return{ids:u,visibleId:g,labels:d?.labels??{},resolve:p,legacyIds:s.legacyIds}}var A=class{constructor(e,t){this.url=e;this.options=t;this.sequence=0;this.transition=new $;let i=t.collection?":"+t.collection:"",n="live2d:model:"+e+i,s=a=>a.replace(/(\/gh\/nova1751\/live2d-api)@catalog-[a-f0-9]{16}(\/catalog\/library\.json:girls-frontline)$/,"$1$2");if(this.key=s(n),this.key!==n&&!localStorage.getItem(this.key)){let a=[n,...Object.keys(localStorage)].find(r=>s(r)===this.key&&localStorage.getItem(r));a&&localStorage.setItem(this.key,localStorage.getItem(a))}}open(){return this.library??(this.library=se(this.url,this.options.collection,this.options.locale).catch(e=>{throw this.library=void 0,e}))}async select(e,t){let i=++this.sequence,n=await this.open();if(i!==this.sequence)return;let s=e(n.ids,n.legacyIds,n.visibleId),{modelUrl:a,dialogue:r,soundAliases:c,captions:d}=n.resolve(s),g=1,u=this.options.collection==="girls-frontline"&&!s.startsWith("background/")?oe(l=>{g=l}):void 0,p=this.options.collection?this.transition.begin(()=>g):void 0;await window.loadlive2d("live2d",a,{start:t,locale:this.options.locale,captions:d,framing:u,onPaint:p,coreUrl:this.options.coreUrl,dialogue:r,soundAliases:c}),i===this.sequence&&(this.active=n.visibleId(s),localStorage.setItem(this.key,s),window.dispatchEvent(new CustomEvent("live2d:model",{detail:s})))}load(e,t,i,n=!1){return this.select((s,a,r)=>{let c=localStorage.getItem(this.key);if(this.options.collection)return this.options.modelId??(c&&s.includes(r(c))?c:s[0]);let d=a?.[Number(localStorage.getItem("modelId"))]?.[Number(localStorage.getItem("modelTexturesId"))];return this.options.modelId??(c&&s.includes(r(c))?c:d&&s.includes(d)?d:s[0])},n)}choose(e){return this.select(()=>e,!1)}cancel(){this.sequence++}reopen(e){if(this.active)window.loadlive2d.show?.(e);else return this.load(void 0,void 0,void 0,e)}character(e){return e.split("/").slice(0,2).join("/")}nextModel(e=!1){return this.select(t=>{let i=[...new Set(t.map(s=>this.character(s)))],n=i[(i.indexOf(this.character(this.active??""))+1)%i.length];return t.find(s=>this.character(s)===n)},e)}nextTexture(e=!1){return this.select(t=>{let i=t.filter(n=>this.character(n)===this.character(this.active??t[0]));return i[(i.indexOf(this.active??"")+1)%i.length]},e)}async costume(e){let t=await this.open(),i=t.ids.find(n=>t.resolve(n).modelUrl===e);i&&await this.select(()=>i,!1)}};var pe=document.currentScript,we=pe?.dataset.asteroidsUrl??"https://cdn.jsdelivr.net/gh/nova1751/live2d-api@widget-2.4.1/asteroids.js",I=o=>document.getElementById(o);function S(o){console.error("[Live2D]",o);let e=document.getElementById("waifu-status");e&&(e.textContent=m("加载失败,请检查网络或切换模型后重试。","Could not load the model. Check your connection or try another character."),v(e.textContent,5e3,10))}async function ve(o){if(o==="en"){v(["One step at a time, Commander.","Even on a quiet day, there is something worth noticing."],6e3,9);return}let e=await T("https://v1.hitokoto.cn");v(L(e.hitokoto),6e3,9),setTimeout(()=>{v(`这句一言来自 <span>「${L(String(e.from))}」</span>,是 <span>${L(String(e.creator))}</span> 在 hitokoto.cn 投稿的。`,4e3,9)},6e3)}function ye(){if(window.Asteroids)(window.ASTEROIDSPLAYERS??(window.ASTEROIDSPLAYERS=[])).push(new window.Asteroids);else{let o=document.createElement("script");o.src=we,document.head.appendChild(o)}}var ae;function ce(){clearTimeout(ae),localStorage.removeItem("waifu-display"),I("waifu-toggle").setAttribute("tabindex","-1"),I("waifu-toggle").setAttribute("aria-expanded","true"),I("waifu").style.display="",setTimeout(()=>{I("waifu").style.bottom="0"},0)}function V(o){return o.isTrusted&&!!window.loadlive2d.prepareInteraction?.()}function be(){let o=I("waifu").contains(document.activeElement);window.loadlive2d.hide?.(),localStorage.setItem("waifu-display",String(Date.now())),v(m("愿你有一天能与重要的人重逢。","I hope you meet the people you miss again."),2e3,11),I("waifu").style.bottom="-500px",ae=setTimeout(()=>{I("waifu").style.display="none";let e=I("waifu-toggle");e.removeAttribute("tabindex"),e.setAttribute("aria-expanded","false"),e.classList.add("waifu-toggle-active"),o&&e.focus()},window.matchMedia("(prefers-reduced-motion: reduce)").matches?0:3e3)}function re(o,e,t=!1){sessionStorage.removeItem("waifu-text");let i=o.collection==="girls-frontline",n='<canvas id="live2d" width="800" height="800"></canvas>';document.body.insertAdjacentHTML("beforeend",`<div id="waifu" lang="${o.locale==="en"?"en":"zh-CN"}"${i?' class="waifu-adaptive"':""}>
|
|
2
|
+
"use strict";(()=>{var Y="zh-CN";function _(o){Y=o??"zh-CN"}function m(o,e){return Y==="en"?e:o}var G={hitokoto:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --><path d="M512 240c0 114.9-114.6 208-256 208c-37.1 0-72.3-6.4-104.1-17.9c-11.9 8.7-31.3 20.6-54.3 30.6C73.6 471.1 44.7 480 16 480c-6.5 0-12.3-3.9-14.8-9.9c-2.5-6-1.1-12.8 3.4-17.4l0 0 0 0 0 0 0 0 .3-.3c.3-.3 .7-.7 1.3-1.4c1.1-1.2 2.8-3.1 4.9-5.7c4.1-5 9.6-12.4 15.2-21.6c10-16.6 19.5-38.4 21.4-62.9C17.7 326.8 0 285.1 0 240C0 125.1 114.6 32 256 32s256 93.1 256 208z"/></svg>',asteroids:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --><path d="M498.1 5.6c10.1 7 15.4 19.1 13.5 31.2l-64 416c-1.5 9.7-7.4 18.2-16 23s-18.9 5.4-28 1.6L284 427.7l-68.5 74.1c-8.9 9.7-22.9 12.9-35.2 8.1S160 493.2 160 480V396.4c0-4 1.5-7.8 4.2-10.7L331.8 202.8c5.8-6.3 5.6-16-.4-22s-15.7-6.4-22-.7L106 360.8 17.7 316.6C7.1 311.3 .3 300.7 0 288.9s5.9-22.8 16.1-28.7l448-256c10.7-6.1 23.9-5.5 34 1.4z"/></svg>',"switch-model":'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --><path d="M399 384.2C376.9 345.8 335.4 320 288 320H224c-47.4 0-88.9 25.8-111 64.2c35.2 39.2 86.2 63.8 143 63.8s107.8-24.7 143-63.8zM0 256a256 256 0 1 1 512 0A256 256 0 1 1 0 256zm256 16a72 72 0 1 0 0-144 72 72 0 1 0 0 144z"/></svg>',"switch-texture":'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --><path d="M320 64A64 64 0 1 0 192 64a64 64 0 1 0 128 0zm-96 96c-35.3 0-64 28.7-64 64v48c0 17.7 14.3 32 32 32h1.8l11.1 99.5c1.8 16.2 15.5 28.5 31.8 28.5h38.7c16.3 0 30-12.3 31.8-28.5L318.2 304H320c17.7 0 32-14.3 32-32V224c0-35.3-28.7-64-64-64H224zM132.3 394.2c13-2.4 21.7-14.9 19.3-27.9s-14.9-21.7-27.9-19.3c-32.4 5.9-60.9 14.2-82 24.8c-10.5 5.3-20.3 11.7-27.8 19.6C6.4 399.5 0 410.5 0 424c0 21.4 15.5 36.1 29.1 45c14.7 9.6 34.3 17.3 56.4 23.4C130.2 504.7 190.4 512 256 512s125.8-7.3 170.4-19.6c22.1-6.1 41.8-13.8 56.4-23.4c13.7-8.9 29.1-23.6 29.1-45c0-13.5-6.4-24.5-14-32.6c-7.5-7.9-17.3-14.3-27.8-19.6c-21-10.6-49.5-18.9-82-24.8c-13-2.4-25.5 6.3-27.9 19.3s6.3 25.5 19.3 27.9c30.2 5.5 53.7 12.8 69 20.5c3.2 1.6 5.8 3.1 7.9 4.5c3.6 2.4 3.6 7.2 0 9.6c-8.8 5.7-23.1 11.8-43 17.3C374.3 457 318.5 464 256 464s-118.3-7-157.7-17.9c-19.9-5.5-34.2-11.6-43-17.3c-3.6-2.4-3.6-7.2 0-9.6c2.1-1.4 4.8-2.9 7.9-4.5c15.3-7.7 38.8-14.9 69-20.5z"/></svg>',photo:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --><path d="M220.6 121.2L271.1 96 448 96v96H333.2c-21.9-15.1-48.5-24-77.2-24s-55.2 8.9-77.2 24H64V128H192c9.9 0 19.7-2.3 28.6-6.8zM0 128V416c0 35.3 28.7 64 64 64H448c35.3 0 64-28.7 64-64V96c0-35.3-28.7-64-64-64H271.1c-9.9 0-19.7 2.3-28.6 6.8L192 64H160V48c0-8.8-7.2-16-16-16H80c-8.8 0-16 7.2-16 16l0 16C28.7 64 0 92.7 0 128zM168 304a88 88 0 1 1 176 0 88 88 0 1 1 -176 0z"/></svg>',info:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --><path d="M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512zM216 336h24V272H216c-13.3 0-24-10.7-24-24s10.7-24 24-24h48c13.3 0 24 10.7 24 24v88h8c13.3 0 24 10.7 24 24s-10.7 24-24 24H216c-13.3 0-24-10.7-24-24s10.7-24 24-24zm40-208a32 32 0 1 1 0 64 32 32 0 1 1 0-64z"/></svg>',quit:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --><path d="M342.6 150.6c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L192 210.7 86.6 105.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L146.7 256 41.4 361.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0L192 301.3 297.4 406.6c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L237.3 256 342.6 150.6z"/></svg>'};function U(o){return Array.isArray(o)?o[Math.floor(Math.random()*o.length)]:o}function L(o){return o.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}var B,H,E;function P(){clearTimeout(H),sessionStorage.removeItem("waifu-text"),document.getElementById("waifu-tips")?.classList.remove("waifu-tips-active")}function z(o,e){clearTimeout(H),sessionStorage.setItem("waifu-text",String(e));let t=document.getElementById("waifu-tips");t.innerHTML=o,t.classList.add("waifu-tips-active")}function v(o,e,t){!o||E||Number(sessionStorage.getItem("waifu-text"))>t||(z(U(o),t),H=setTimeout(P,e))}function J(o,e){if(!e){v(L(o),5e3,11);return}E=e,z(L(o),11)}function X(o){let e=document.getElementById("live2d");if(!e)return;let t=B?.find(({selector:n})=>e.closest(n)),i=t?U(t.text):B?void 0:m("指挥官,我在。","Right here, Commander.");i&&(E=o,z(i.replace("{text}",()=>L(e.textContent??"")),11))}function K(o,e){E===o&&(E=void 0,e?P():H=setTimeout(P,1200))}function de(o){if(location.pathname==="/"){let s=new Date().getHours();for(let{hour:a,text:r}of o){let[c,d=c]=a.split("-").map(Number);if(c<=s&&s<=d)return r}}let e=L(document.title.split(" - ")[0]),t=m(`欢迎阅读<span>「${e}」</span>`,`Welcome to <span>${e}</span>!`);if(!document.referrer)return t;let{hostname:i}=new URL(document.referrer);return i===location.hostname?t:m(`Hello!来自 <span>${L({baidu:"百度",so:"360搜索",google:"谷歌搜索"}[i.split(".")[1]]??i)}</span> 的朋友<br>${t}`,`Hello, visitor from <span>${L(i)}</span>!<br>${t}`)}function ue(o){let[e,t]=o.split("/").map(Number);return e*100+t}function Q(o){B=o.click;let e=[...o.message.default],t=new Date,i=(t.getMonth()+1)*100+t.getDate();for(let{date:u,text:p}of o.seasons){let[l,h=l]=u.split("-").map(ue);l<=i&&i<=h&&e.push(U(p).replace("{year}",String(t.getFullYear())))}let n=2e4,s=Date.now(),a;function r(){if(document.hidden)return;let u=n-(Date.now()-s);u<=0&&!localStorage.getItem("waifu-display")&&v(e,6e3,9),a=setTimeout(r,u>0?u:n)}let c=()=>{s=Date.now()};window.addEventListener("pointermove",c,{passive:!0}),window.addEventListener("pointerdown",c,{passive:!0}),window.addEventListener("keydown",c),document.hidden||(a=setTimeout(r,n)),v(de(o.time),7e3,11);let d;for(let u of["mouseover","click"])window.addEventListener(u,p=>{let l=p.target;if(!(l instanceof Element)||p.live2dHandlesCaption)return;let h=u==="click"&&l.closest("#waifu .waifu-model-stage"),w=h?document.getElementById("live2d"):l.closest("#live2d"),y=o[u].find(({selector:C})=>l.closest(C)||h&&w?.closest(C));!y||u==="mouseover"&&y.selector===d||(u==="mouseover"&&(d=y.selector),v(U(y.text).replace("{text}",()=>L(l.textContent??"")),4e3,u==="click"&&w?11:8))});let f=()=>{};f.toString=()=>(v(o.message.console,6e3,9),""),console.log("%c",f),window.addEventListener("copy",()=>v(o.message.copy,6e3,9)),document.addEventListener("visibilitychange",()=>{clearTimeout(a),document.hidden||(c(),a=setTimeout(r,n),localStorage.getItem("waifu-display")||v(o.message.visibilitychange,6e3,9))})}async function T(o){let e=await fetch(o);if(!e.ok)throw new Error(`Failed to load ${o} (HTTP ${e.status})`);return e.json()}var Z="/gh/nova1751/live2d-api@cdn-b3ac5ae545e2/",ee="https://cdn.jsdelivr.net",j=ee+Z,me=/\/gh\/nova1751\/live2d-api@widget-[^/]+\/?$/,ge=/\/live2dapi-noa(?:@[^/]+)?\/?$/;function te(o){let e=new URL(o,document.baseURI);return!ge.test(e.pathname)&&!me.test(e.pathname)||/@1\.[^/]+\/?$/.test(e.pathname)?o:(e.hostname==="cdn.jsdmirror.com"?e.origin:ee)+Z}var q=()=>m("我的新衣服好看嘛?","How do you like my new outfit?"),k=o=>Number(localStorage.getItem(o))||0,D=class{constructor(e){this.options=e;this.revision=0;this.loaded=!1;this.useCDN=typeof e.cdnPath=="string";let t=e.modelBaseUrl??(e.cdnPath&&te(e.cdnPath))??e.apiPath;if(typeof t!="string")throw new TypeError("Invalid initWidget argument");this.base=t.endsWith("/")?t:t+"/"}reopen(e){if(this.loaded)window.loadlive2d.show?.(e);else return this.load(void 0,void 0,void 0,e)}cancel(){this.revision++}async fetchCatalog(){let e=this.base+"model_list.json",t=await fetch(e);if(t.status===404&&!this.options.modelBaseUrl&&this.base!==j){let i=await T(j+"model_list.json");return this.base=j,i}if(!t.ok)throw new Error(`Failed to load ${e} (HTTP ${t.status})`);return t.json()}list(){return this.catalog??(this.catalog=this.fetchCatalog().catch(e=>{throw this.catalog=void 0,e}))}async load(e=k("modelId"),t=k("modelTexturesId"),i,n=!1,s=++this.revision,a=!1){let r;if(this.options.modelUrl)r=this.options.modelUrl;else if(this.useCDN){let{models:d}=await this.list();d[e]||(e=0);let f=d[e],u=Array.isArray(f)?f:[f];u[t]||(t=0);let p=u[t];t=u.indexOf(p),r=this.base+"model/"+p+"/index.json"}else r=this.base+"get/?id="+e+"-"+t;if(s!==this.revision)return;let c=window.loadlive2d("live2d",r,{start:n,locale:this.options.locale,coreUrl:this.options.coreUrl});c&&await c,s===this.revision&&(this.options.modelUrl||(localStorage.setItem("modelId",String(e)),localStorage.setItem("modelTexturesId",String(t))),v(i,4e3,10),this.loaded=!0)}async costume(e){if(this.options.modelUrl||!this.useCDN)return;let t=++this.revision,i=k("modelId"),n=(await this.list()).models[i],a=(Array.isArray(n)?n:[n]).findIndex(r=>new URL(this.base+"model/"+r+"/index.json",document.baseURI).href===e);a>=0&&await this.load(i,a,q(),!1,t,!0)}async nextModel(e=!1){let t=++this.revision,i=k("modelId");if(this.useCDN){let{models:s,messages:a}=await this.list(),r=(i+1)%s.length;return this.load(r,0,m(a[r],"Ready for duty!"),e,t)}let{model:n}=await T(this.base+"switch/?id="+i);return this.load(n.id,0,n.message,e,t)}async nextTexture(e=!1){let t=++this.revision,i=k("modelId"),n=k("modelTexturesId");if(this.useCDN){let a=(await this.list()).models[i],r=Array.isArray(a)?a.length:1;return this.load(i,(n+1)%r,q(),e,t)}let{textures:s}=await T(this.base+"rand_textures/?id="+i+"-"+n);s.id===1&&n===1?v(m("我还没有其他衣服呢!","This is my only outfit so far!"),4e3,10):await this.load(i,s.id,q(),e,t)}};var $=class{constructor(){this.revision=0}begin(e){let t=document.getElementById("waifu"),i=t?.querySelector(".waifu-surface"),n=++this.revision;return t&&(this.still&&!this.still.isConnected&&(i??t).prepend(this.still),t.setAttribute("data-model-loading","")),s=>{if(this.revision!==n||!t)return;let a=document.createElement("canvas");a.className="waifu-model-still",a.setAttribute("aria-hidden","true"),a.width=s.width,a.height=s.height;try{let r=a.getContext("2d");r&&r.drawImage(s,0,0),this.still?.remove(),this.still=r?a:void 0}finally{if(i){let r=e();t.style.setProperty("--waifu-aspect",String(r)),t.toggleAttribute("data-wide-model",r>=1.35)}t.removeAttribute("data-model-loading")}}}};var O={scale:1,x:0,y:0},g=128;function W(o,e,t){let i=0;for(let n=0;n<o.length;n++)if(i+=o[n],i>e*t)return n;return o.length-1}function fe(o,e,t,i){let n=new Float64Array(g),s=g,a=0,r=0;for(let x=0;x<o.length;x++){if(!o[x])continue;let M=Math.floor(x/g);n[x%g]+=o[x],r+=o[x],s=Math.min(s,M),a=Math.max(a,M+1)}if(!r)return O;let c=W(n,r,.001),d=W(n,r,.999)+1,f=d-c,u=a-s,p=i?Math.max(.7,Math.min(1.9,f/u*.93/.94)):1;i?.(p);let l=Math.min(1,p),h=Math.min(1,1/p),w=Math.min(.93*g*h/u,.94*g*l/f,5/e.scale),y=0,C=0;if(t)for(let x=s+2;x<a;x+=4)for(let M=c+2;M<d;M+=4){if(o[x*g+M]<96)continue;t((M+.5)/g,(x+.5)/g).some(le=>/^(head|face|body|bust|torso)\d*$/i.test(le))&&(y+=M+.5,C++)}let R=C>=3?y/C:W(n,r,.5)+.5,b=.475*g*l/w,F=Math.max(d-b,Math.min(c+b,R));return{scale:e.scale*w,x:(.5-F/g)*w,y:.5-.03*h+(.5-a/g)*w}}function oe(o){let e={scale:.65,x:0,y:0},t=document.createElement("canvas");t.width=t.height=g;let i=t.getContext("2d",{willReadFrequently:!0}),n=new Uint8Array(g*g),s=0,a=0,r=0;return{initial:e,measure(c,d){if(!i)return O;let f=performance.now();if(!(f<r)){s++;try{i.clearRect(0,0,g,g),i.drawImage(c,0,0,g,g);let{data:u}=i.getImageData(0,0,g,g),p=0;for(let l=0;l<n.length;l++){let h=u[4*l+3];h<24||(n[l]=Math.max(n[l],h),p++)}p>=16&&(a++,r=f+80)}catch{return O}if(!(a<3&&s<10))return a?fe(n,e,d,o):O}}}}var ne=["fairy","doll","adjutant","npc","squad","background"],ie=["default","normal","destroy"];function N(o,e){let t=o.indexOf(e);return t<0?o.length:t}function he(o,e){let t=new Intl.Collator("en",{numeric:!0}),i=o.map(n=>{let[s,a,r,c]=n.split("/"),d=e[[s,a,r].join("/")],f=r==="base"?-1:d??(s==="fairy"&&/^\d+$/.test(r)?Number(r):Number.MAX_SAFE_INTEGER);return{id:n,category:s,character:a,version:r,form:c,order:f}});return i.sort((n,s)=>N(ne,n.category)-N(ne,s.category)||t.compare(n.category,s.category)||t.compare(n.character,s.character)||n.order-s.order||t.compare(n.version,s.version)||N(ie,n.form)-N(ie,s.form)||t.compare(n.form,s.form)),i.map(n=>n.id)}async function se(o,e,t="zh-CN"){let i=new URL(o,document.baseURI),n=await fetch(i);if(!n.ok)throw new Error("Cannot load catalog: HTTP "+n.status);let s=await n.json();if(s.schemaVersion!==1||!s.models||!s.sources)throw new Error("Unsupported model catalog");let a=new Map,r=Object.keys(s.models).filter(l=>(!e||!l.startsWith("other/"))&&s.models[l].some(h=>h.manifest)),c=e?s.presentation:void 0,d=t==="en"?c?.en:c,f=l=>{let h=c?.aliases[l];return h&&r.includes(h)?h:l},u=e?he(r.filter(l=>f(l)===l),c?.outfitOrder??{}):r;function p(l,h){if(e&&!r.includes(l))throw new Error("Model outside the selected collection: "+l);let w=s.models[l]?.find(b=>b.manifest&&(!h||b.source===h));if(!w?.manifest)throw new Error("No model manifest for "+l);let y=new URL(s.sources[w.source].baseUrl,n.url||i);i.hostname==="cdn.jsdmirror.com"&&y.hostname==="cdn.jsdelivr.net"&&y.pathname.startsWith("/gh/nova1751/live2d-api@cdn-")&&(y.hostname=i.hostname);let C=b=>new URL(b.split("/").map(encodeURIComponent).join("/"),y).href,R;if(w.dialogue){let b=a.get(w.source);b||(b=new Map((s.audio?.[w.source]??[]).map(F=>[F.toUpperCase(),C(F)])),a.set(w.source,b)),R={captions:t==="en"?void 0:d?.captions,url:C(w.dialogue),audio:b}}return{captions:d?.captions,modelUrl:C(w.manifest),dialogue:R,soundAliases:w.soundAliases}}return{ids:u,visibleId:f,labels:d?.labels??{},resolve:p,legacyIds:s.legacyIds}}var A=class{constructor(e,t){this.url=e;this.options=t;this.sequence=0;this.transition=new $;let i=t.collection?":"+t.collection:"",n="live2d:model:"+e+i,s=a=>a.replace(/(\/gh\/nova1751\/live2d-api)@catalog-[a-f0-9]{16}(\/catalog\/library\.json:girls-frontline)$/,"$1$2");if(this.key=s(n),this.key!==n&&!localStorage.getItem(this.key)){let a=[n,...Object.keys(localStorage)].find(r=>s(r)===this.key&&localStorage.getItem(r));a&&localStorage.setItem(this.key,localStorage.getItem(a))}}open(){return this.library??(this.library=se(this.url,this.options.collection,this.options.locale).catch(e=>{throw this.library=void 0,e}))}async select(e,t){let i=++this.sequence,n=await this.open();if(i!==this.sequence)return;let s=e(n.ids,n.legacyIds,n.visibleId),{modelUrl:a,dialogue:r,soundAliases:c,captions:d}=n.resolve(s),f=1,u=this.options.collection==="girls-frontline"&&!s.startsWith("background/")?oe(l=>{f=l}):void 0,p=this.options.collection?this.transition.begin(()=>f):void 0;await window.loadlive2d("live2d",a,{start:t,locale:this.options.locale,captions:d,framing:u,onPaint:p,coreUrl:this.options.coreUrl,dialogue:r,soundAliases:c}),i===this.sequence&&(this.active=n.visibleId(s),localStorage.setItem(this.key,s),window.dispatchEvent(new CustomEvent("live2d:model",{detail:s})))}load(e,t,i,n=!1){return this.select((s,a,r)=>{let c=localStorage.getItem(this.key);if(this.options.collection)return this.options.modelId??(c&&s.includes(r(c))?c:s[0]);let d=a?.[Number(localStorage.getItem("modelId"))]?.[Number(localStorage.getItem("modelTexturesId"))];return this.options.modelId??(c&&s.includes(r(c))?c:d&&s.includes(d)?d:s[0])},n)}choose(e){return this.select(()=>e,!1)}cancel(){this.sequence++}reopen(e){if(this.active)window.loadlive2d.show?.(e);else return this.load(void 0,void 0,void 0,e)}character(e){return e.split("/").slice(0,2).join("/")}nextModel(e=!1){return this.select(t=>{let i=[...new Set(t.map(s=>this.character(s)))],n=i[(i.indexOf(this.character(this.active??""))+1)%i.length];return t.find(s=>this.character(s)===n)},e)}nextTexture(e=!1){return this.select(t=>{let i=t.filter(n=>this.character(n)===this.character(this.active??t[0]));return i[(i.indexOf(this.active??"")+1)%i.length]},e)}async costume(e){let t=await this.open(),i=t.ids.find(n=>t.resolve(n).modelUrl===e);i&&await this.select(()=>i,!1)}};var pe=document.currentScript,we=pe?.dataset.asteroidsUrl??"https://cdn.jsdelivr.net/gh/nova1751/live2d-api@widget-2.4.2/asteroids.js",I=o=>document.getElementById(o);function S(o){console.error("[Live2D]",o);let e=document.getElementById("waifu-status");e&&(e.textContent=m("加载失败,请检查网络或切换模型后重试。","Could not load the model. Check your connection or try another character."),v(e.textContent,5e3,10))}async function ve(o){if(o==="en"){v(["One step at a time, Commander.","Even on a quiet day, there is something worth noticing."],6e3,9);return}let e=await T("https://v1.hitokoto.cn");v(L(e.hitokoto),6e3,9),setTimeout(()=>{v(`这句一言来自 <span>「${L(String(e.from))}」</span>,是 <span>${L(String(e.creator))}</span> 在 hitokoto.cn 投稿的。`,4e3,9)},6e3)}function ye(){if(window.Asteroids)(window.ASTEROIDSPLAYERS??(window.ASTEROIDSPLAYERS=[])).push(new window.Asteroids);else{let o=document.createElement("script");o.src=we,document.head.appendChild(o)}}var ae;function ce(){clearTimeout(ae),localStorage.removeItem("waifu-display"),I("waifu-toggle").setAttribute("tabindex","-1"),I("waifu-toggle").setAttribute("aria-expanded","true"),I("waifu").style.display="",setTimeout(()=>{I("waifu").style.bottom="0"},0)}function V(o){return o.isTrusted&&!!window.loadlive2d.prepareInteraction?.()}function be(){let o=I("waifu").contains(document.activeElement);window.loadlive2d.hide?.(),localStorage.setItem("waifu-display",String(Date.now())),v(m("愿你有一天能与重要的人重逢。","I hope you meet the people you miss again."),2e3,11),I("waifu").style.bottom="-500px",ae=setTimeout(()=>{I("waifu").style.display="none";let e=I("waifu-toggle");e.removeAttribute("tabindex"),e.setAttribute("aria-expanded","false"),e.classList.add("waifu-toggle-active"),o&&e.focus()},window.matchMedia("(prefers-reduced-motion: reduce)").matches?0:3e3)}function re(o,e,t=!1){sessionStorage.removeItem("waifu-text");let i=o.collection==="girls-frontline",n='<canvas id="live2d" width="800" height="800"></canvas>';document.body.insertAdjacentHTML("beforeend",`<div id="waifu" lang="${o.locale==="en"?"en":"zh-CN"}"${i?' class="waifu-adaptive"':""}>
|
|
3
3
|
<div id="waifu-status" role="status" class="waifu-sr-only"></div>
|
|
4
4
|
<div id="waifu-tips"></div>
|
|
5
5
|
${i?`<div class="waifu-viewport"><div class="waifu-surface">${n}</div></div>`:n}
|
package/package.json
CHANGED
package/widget.mjs
CHANGED