live2dapi-noa 2.4.5 → 2.4.7
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 +23 -3
- package/autoload.js +1 -1
- package/docs/en/README.md +23 -3
- 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/latest.mjs +37 -0
- package/modern/renderer.mjs +22 -22
- 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 +2 -1
- package/widget.mjs +1 -1
package/README.md
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
<a href="https://live2d-nova.vercel.app/catalog/"><img src="https://raw.githubusercontent.com/nova1751/live2d-api/main/docs/assets/live2d-banner.webp" width="100%" alt="少女前线 Live2D 网页看板娘,右侧为播放器实际渲染的 UMP9 心智升级造型"></a>
|
|
4
|
+
|
|
1
5
|
# 少女前线 Live2D 网页看板娘
|
|
2
6
|
|
|
3
|
-
|
|
7
|
+
一行脚本,把少女前线角色放进网页。点击人物播放动作、语音和台词,也可以为她切换装扮。
|
|
8
|
+
|
|
9
|
+
<a href="https://www.npmjs.com/package/live2dapi-noa"><img src="https://img.shields.io/npm/v/live2dapi-noa?logo=npm&logoColor=white&color=17695e" alt="npm 稳定版"></a> <a href="https://github.com/nova1751/live2d-api/actions/workflows/publish.yml"><img src="https://github.com/nova1751/live2d-api/actions/workflows/publish.yml/badge.svg?branch=main" alt="构建与测试"></a> <a href="#api-与兼容性"><img src="https://img.shields.io/badge/Cubism-2%E2%80%935-426578" alt="Cubism 2–5"></a> <a href="#素材与致谢"><img src="https://img.shields.io/badge/code-ISC-b89238" alt="代码许可 ISC"></a>
|
|
4
10
|
|
|
5
|
-
|
|
11
|
+
**[打开在线图鉴](https://live2d-nova.vercel.app/catalog/)** · [快速接入](#快速接入) · [模块 API](#api-与兼容性) · [English](https://github.com/nova1751/live2d-api/blob/main/docs/en/README.md)
|
|
12
|
+
|
|
13
|
+
</div>
|
|
6
14
|
|
|
7
15
|
## 快速接入
|
|
8
16
|
|
|
@@ -20,6 +28,12 @@
|
|
|
20
28
|
<script type="module" src="https://cdn.jsdelivr.net/gh/nova1751/live2d-api@widget-latest/girls-frontline.mjs"></script>
|
|
21
29
|
```
|
|
22
30
|
|
|
31
|
+
希望绕过分支缓存、自动采用已发布版本的网站,可使用下面的国内入口。固定地址标识加载脚本自身的版本。它通过国内 npm 镜像查询稳定版本号,再从国内 GitHub CDN 加载对应版本的播放器和模型。查询超时或新版入口暂不可用时,自动使用随脚本发布的版本。海外网站可将域名换成 `cdn.jsdelivr.net`。
|
|
32
|
+
|
|
33
|
+
```html
|
|
34
|
+
<script type="module" src="https://cdn.jsdmirror.com/gh/nova1751/live2d-api@widget-2.4.7/latest.mjs"></script>
|
|
35
|
+
```
|
|
36
|
+
|
|
23
37
|
快捷入口在视口宽度达到 768 CSS 像素时显示。首次访问默认展示一阶空袭妖精,后续访问恢复该站上次选择的造型。需要自定显示条件时可使用模块 API。
|
|
24
38
|
|
|
25
39
|
## 通过 npm 或 pnpm 安装
|
|
@@ -44,13 +58,15 @@ npm 包包含 JS 播放器、样式、TypeScript 声明和两套界面文案。
|
|
|
44
58
|
|
|
45
59
|
## 界面语言与人物台词
|
|
46
60
|
|
|
61
|
+
组件按需加载渲染器,按每套造型的可见轮廓取景。台词气泡位于人物上方,工具栏靠右垂直居中。在较窄的图鉴里,横向造型的工具栏会移到上方。
|
|
62
|
+
|
|
47
63
|
| 配置位置 | 简体中文(默认) | 英文 |
|
|
48
64
|
| --- | --- | --- |
|
|
49
65
|
| 快捷入口 | 省略参数或添加 `?lang=zh-CN` | 添加 `?lang=en` |
|
|
50
66
|
| 模块 API | `locale: 'zh-CN'` | `locale: 'en'` |
|
|
51
67
|
| 在线图鉴 | [中文图鉴](https://live2d-nova.vercel.app/catalog/) | [英文图鉴](https://live2d-nova.vercel.app/catalog/?lang=en) |
|
|
52
68
|
|
|
53
|
-
|
|
69
|
+
语言设置适用于工具栏、无障碍标签、问候和预设提示。图鉴切换语言时会保留当前造型。游戏台词按动作和语音事件匹配:英文优先读取事件原有字幕,中文按角色和语音编号查找译文。旧模型也支持按语音编号或内嵌原句匹配译文。互动缺少台词时显示所选语言的预设提示。字幕保留到动作和语音结束,两种语言都播放模型原有录音。新版模型会等动作和录音就绪,从动作首帧按模型配置的延迟播放语音。录音缺失或加载失败时,仍会播放动作并显示对应台词。
|
|
54
70
|
|
|
55
71
|
## API 与兼容性
|
|
56
72
|
|
|
@@ -65,6 +81,10 @@ npm 包包含 JS 播放器、样式、TypeScript 声明和两套界面文案。
|
|
|
65
81
|
|
|
66
82
|
## 模型目录与离线下载
|
|
67
83
|
|
|
84
|
+
| <a href="https://live2d-nova.vercel.app/catalog/?model=fairy/air_attack/1/default"><img src="https://raw.githubusercontent.com/nova1751/live2d-api/main/catalog/portraits/fairy--air_attack--1--default.webp" width="96" alt="空袭妖精"></a> | <a href="https://live2d-nova.vercel.app/catalog/?model=doll/ump9/mod/normal"><img src="https://raw.githubusercontent.com/nova1751/live2d-api/main/catalog/portraits/doll--ump9--mod--normal.webp" width="96" alt="UMP9 心智升级"></a> | <a href="https://live2d-nova.vercel.app/catalog/?model=squad/ags-30/base/default"><img src="https://raw.githubusercontent.com/nova1751/live2d-api/main/catalog/portraits/squad--ags-30--base--default.webp" width="96" alt="AGS-30 小队"></a> |
|
|
85
|
+
| :---: | :---: | :---: |
|
|
86
|
+
| [空袭妖精](https://live2d-nova.vercel.app/catalog/?model=fairy/air_attack/1/default) | [UMP9 心智升级](https://live2d-nova.vercel.app/catalog/?model=doll/ump9/mod/normal) | [AGS-30 小队](https://live2d-nova.vercel.app/catalog/?model=squad/ags-30/base/default) |
|
|
87
|
+
|
|
68
88
|
图鉴收录已核对的公开收藏中 129 个条目、443 个可选形态,包含妖精、人形、副官、小队和背景。标准与战损形态各有独立 ID,7 个旧档 ID 仍指向对应装扮。统计范围和上游缺件记录见核对说明。[模型目录](https://github.com/nova1751/live2d-api/blob/main/catalog/library.json) · [来源与核对记录](https://github.com/nova1751/live2d-api/blob/main/docs/model-library.zh-CN.md)
|
|
69
89
|
|
|
70
90
|
安装 Node.js 24 和 Git,在仓库根目录运行:
|
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.7";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/docs/en/README.md
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
<a href="https://live2d-nova.vercel.app/catalog/?lang=en"><img src="https://raw.githubusercontent.com/nova1751/live2d-api/main/docs/assets/live2d-banner.webp" width="100%" alt="UMP9 MOD, rendered by the Live2D widget"></a>
|
|
4
|
+
|
|
1
5
|
# Girls’ Frontline Live2D Widget
|
|
2
6
|
|
|
3
|
-
|
|
7
|
+
Add an interactive Girls’ Frontline character to your website with one script. Click a character to play its motions, voice lines and dialogue.
|
|
8
|
+
|
|
9
|
+
<a href="https://www.npmjs.com/package/live2dapi-noa"><img src="https://img.shields.io/npm/v/live2dapi-noa?logo=npm&logoColor=white&color=17695e" alt="npm version"></a> <a href="https://github.com/nova1751/live2d-api/actions/workflows/publish.yml"><img src="https://github.com/nova1751/live2d-api/actions/workflows/publish.yml/badge.svg?branch=main" alt="Build and tests"></a> <a href="#api-and-compatibility"><img src="https://img.shields.io/badge/Cubism-2%E2%80%935-426578" alt="Cubism 2–5"></a> <a href="#credits-and-licensing"><img src="https://img.shields.io/badge/code-ISC-b89238" alt="Code license: ISC"></a>
|
|
4
10
|
|
|
5
|
-
|
|
11
|
+
**[Open the gallery](https://live2d-nova.vercel.app/catalog/?lang=en)** · [Quick start](#quick-start) · [Module API](#api-and-compatibility) · [简体中文](https://github.com/nova1751/live2d-api/blob/main/README.md)
|
|
12
|
+
|
|
13
|
+
</div>
|
|
6
14
|
|
|
7
15
|
## Quick start
|
|
8
16
|
|
|
@@ -20,6 +28,12 @@ Place one module script before `</body>`. Choose the CDN closest to your audienc
|
|
|
20
28
|
<script type="module" src="https://cdn.jsdmirror.com/gh/nova1751/live2d-api@widget-latest/girls-frontline.mjs?lang=en"></script>
|
|
21
29
|
```
|
|
22
30
|
|
|
31
|
+
To follow published releases independently of Git branch caches, use the bootstrap below. Its fixed URL identifies the bootstrap itself. It looks up the stable version in the npm registry and loads that release from the GitHub CDN. If the lookup times out or the new module is unavailable, it falls back to its own release. For mainland China, use `cdn.jsdmirror.com` to select the mainland registry mirror and CDN.
|
|
32
|
+
|
|
33
|
+
```html
|
|
34
|
+
<script type="module" src="https://cdn.jsdelivr.net/gh/nova1751/live2d-api@widget-2.4.7/latest.mjs?lang=en"></script>
|
|
35
|
+
```
|
|
36
|
+
|
|
23
37
|
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.
|
|
24
38
|
|
|
25
39
|
## Install with npm or pnpm
|
|
@@ -44,13 +58,15 @@ The package includes the JS runtime, styles, TypeScript declarations and both se
|
|
|
44
58
|
|
|
45
59
|
## Languages and dialogue
|
|
46
60
|
|
|
61
|
+
The widget loads the renderer each model needs and fits the canvas to the visible figure. Captions sit above the figure and the toolbar sits to its right. In narrow gallery panels, wide formations have their tools above them.
|
|
62
|
+
|
|
47
63
|
| Setting | Simplified Chinese (default) | English |
|
|
48
64
|
| --- | --- | --- |
|
|
49
65
|
| Shortcut URL | Omit the query or use `?lang=zh-CN` | `?lang=en` |
|
|
50
66
|
| Module API | `locale: 'zh-CN'` | `locale: 'en'` |
|
|
51
67
|
| Gallery | [中文图鉴](https://live2d-nova.vercel.app/catalog/) | [English gallery](https://live2d-nova.vercel.app/catalog/?lang=en) |
|
|
52
68
|
|
|
53
|
-
The locale controls widget buttons, accessibility labels, greetings and fallback messages. The gallery language switch preserves the selected outfit. For game dialogue, English uses the subtitle attached to the original motion and voice event. Chinese uses the character and voice key to find the translated line. Older models also use matched voice keys or translations of embedded text. An interaction without a line uses a localized widget hint. Captions stay visible until the action and audio finish. Both languages play the original recording.
|
|
69
|
+
The locale controls widget buttons, accessibility labels, greetings and fallback messages. The gallery language switch preserves the selected outfit. For game dialogue, English uses the subtitle attached to the original motion and voice event. Chinese uses the character and voice key to find the translated line. Older models also use matched voice keys or translations of embedded text. An interaction without a line uses a localized widget hint. Captions stay visible until the action and audio finish. Both languages play the original recording. For modern models, the player waits for the motion and recording, then schedules the voice from the first motion frame using the configured delay. If a recording is missing or fails to load, the motion and its caption still play.
|
|
54
70
|
|
|
55
71
|
## API and compatibility
|
|
56
72
|
|
|
@@ -65,6 +81,10 @@ The locale controls widget buttons, accessibility labels, greetings and fallback
|
|
|
65
81
|
|
|
66
82
|
## Collection and offline use
|
|
67
83
|
|
|
84
|
+
| <a href="https://live2d-nova.vercel.app/catalog/?model=fairy/air_attack/1/default&lang=en"><img src="https://raw.githubusercontent.com/nova1751/live2d-api/main/catalog/portraits/fairy--air_attack--1--default.webp" width="96" alt="Airstrike Fairy"></a> | <a href="https://live2d-nova.vercel.app/catalog/?model=doll/ump9/mod/normal&lang=en"><img src="https://raw.githubusercontent.com/nova1751/live2d-api/main/catalog/portraits/doll--ump9--mod--normal.webp" width="96" alt="UMP9 MOD"></a> | <a href="https://live2d-nova.vercel.app/catalog/?model=squad/ags-30/base/default&lang=en"><img src="https://raw.githubusercontent.com/nova1751/live2d-api/main/catalog/portraits/squad--ags-30--base--default.webp" width="96" alt="AGS-30"></a> |
|
|
85
|
+
| :---: | :---: | :---: |
|
|
86
|
+
| [Airstrike Fairy](https://live2d-nova.vercel.app/catalog/?model=fairy/air_attack/1/default&lang=en) | [UMP9 MOD](https://live2d-nova.vercel.app/catalog/?model=doll/ump9/mod/normal&lang=en) | [AGS-30](https://live2d-nova.vercel.app/catalog/?model=squad/ags-30/base/default&lang=en) |
|
|
87
|
+
|
|
68
88
|
The gallery lists 443 selectable forms across 129 entries from the audited public collections. It includes fairies, dolls, adjutants, squads and backgrounds. Standard and damaged variants have distinct IDs. Seven older IDs resolve to matching outfits. These counts describe the indexed sources. [Model catalog](https://github.com/nova1751/live2d-api/blob/main/catalog/library.json) · [Source audit](https://github.com/nova1751/live2d-api/blob/main/docs/model-library.zh-CN.md)
|
|
69
89
|
|
|
70
90
|
From a repository checkout with Node.js 24 and Git, run:
|
|
@@ -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.7/";
|
|
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.7/"})();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 g(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 P,H,U;function z(){clearTimeout(H),sessionStorage.removeItem("waifu-text"),document.getElementById("waifu-tips")?.classList.remove("waifu-tips-active")}function q(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 w(o,e,t){!o||U||Number(sessionStorage.getItem("waifu-text"))>t||(q(E(o),t),H=setTimeout(z,e))}function J(o,e){if(!e){w(L(o),5e3,11);return}U=e,q(L(o),11)}function X(o){let e=document.getElementById("live2d");if(!e)return;let t=P?.find(({selector:n})=>e.closest(n)),i=t?E(t.text):P?void 0:g("指挥官,我在。","Right here, Commander.");i&&(U=o,q(i.replace("{text}",()=>L(e.textContent??"")),11))}function K(o,e){U===o&&(U=void 0,e?z():H=setTimeout(z,1200))}function ue(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=g(`欢迎阅读<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:g(`Hello!来自 <span>${L({baidu:"百度",so:"360搜索",google:"谷歌搜索"}[i.split(".")[1]]??i)}</span> 的朋友<br>${t}`,`Hello, visitor from <span>${L(i)}</span>!<br>${t}`)}function me(o){let[e,t]=o.split("/").map(Number);return e*100+t}function Q(o){P=o.click;let e=[...o.message.default],t=new Date,i=(t.getMonth()+1)*100+t.getDate();for(let{date:u,text:v}of o.seasons){let[l,m=l]=u.split("-").map(me);l<=i&&i<=m&&e.push(E(v).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")&&w(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)),w(ue(o.time),7e3,11);let d;for(let u of["mouseover","click"])window.addEventListener(u,v=>{let l=v.target;if(!(l instanceof Element)||v.live2dHandlesCaption)return;let m=u==="click"&&l.closest("#waifu .waifu-model-stage"),p=m?document.getElementById("live2d"):l.closest("#live2d"),y=o[u].find(({selector:C})=>l.closest(C)||m&&p?.closest(C));!y||u==="mouseover"&&y.selector===d||(u==="mouseover"&&(d=y.selector),w(E(y.text).replace("{text}",()=>L(l.textContent??"")),4e3,u==="click"&&p?11:8))});let h=()=>{};h.toString=()=>(w(o.message.console,6e3,9),""),console.log("%c",h),window.addEventListener("copy",()=>w(o.message.copy,6e3,9)),document.addEventListener("visibilitychange",()=>{clearTimeout(a),document.hidden||(c(),a=setTimeout(r,n),localStorage.getItem("waifu-display")||w(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,fe=/\/gh\/nova1751\/live2d-api@widget-[^/]+\/?$/,ge=/\/live2dapi-noa(?:@[^/]+)?\/?$/;function te(o){let e=new URL(o,document.baseURI);return!ge.test(e.pathname)&&!fe.test(e.pathname)||/@1\.[^/]+\/?$/.test(e.pathname)?o:(e.hostname==="cdn.jsdmirror.com"?e.origin:ee)+Z}var W=()=>g("我的新衣服好看嘛?","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 h=d[e],u=Array.isArray(h)?h:[h];u[t]||(t=0);let v=a?u[t]:E(u);t=u.indexOf(v),r=this.base+"model/"+v+"/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))),w(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,W(),!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,g(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,W(),e,t)}let{textures:s}=await T(this.base+"rand_textures/?id="+i+"-"+n);s.id===1&&n===1?w(g("我还没有其他衣服呢!","This is my only outfit so far!"),4e3,10):await this.load(i,s.id,W(),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"),t.hasAttribute("data-initial-framing")&&(t.removeAttribute("data-initial-framing"),document.activeElement?.matches("#waifu-toggle:focus-visible")&&t.querySelector("#waifu-tool button")?.focus({preventScroll:!0}))}}}};var B={scale:1,x:0,y:0},f=128;function O(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 he(o,e,t,i){let n=new Float64Array(f),s=new Float64Array(f),a=f,r=0,c=0;for(let b=0;b<o.length;b++){if(!o[b])continue;let M=Math.floor(b/f);n[b%f]+=o[b],s[M]+=o[b],c+=o[b],a=Math.min(a,M),r=Math.max(r,M+1)}if(!c)return B;a=Math.max(a,O(s,c,.001)-2);let d=O(n,c,.001),h=O(n,c,.999)+1,u=h-d,v=r-a,l=i?Math.max(.7,Math.min(1.9,u/v*.93/.94)):1;i?.(l);let m=Math.min(1,l),p=Math.min(1,1/l),y=Math.min(.93*f*p/v,.94*f*m/u,5/e.scale),C=0,A=0;if(t)for(let b=a+2;b<r;b+=4)for(let M=d+2;M<h;M+=4){if(o[b*f+M]<96)continue;t((M+.5)/f,(b+.5)/f).some(de=>/^(head|face|body|bust|torso)\d*$/i.test(de))&&(C+=M+.5,A++)}let x=A>=3?C/A:O(n,c,.5)+.5,R=.475*f*m/y,le=Math.max(h-R,Math.min(d+R,x));return{scale:e.scale*y,x:(.5-le/f)*y,y:.5-.03*p+(.5-r/f)*y}}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=new Uint8Array(n.length),a=0,r=0,c=0;return{initial:e,measure(d,h){if(!i)return B;let u=performance.now();if(!(u<c)){a++;try{i.clearRect(0,0,f,f),i.drawImage(d,0,0,f,f);let{data:v}=i.getImageData(0,0,f,f),l=0;for(let m=0;m<n.length;m++){let p=v[4*m+3];s[m]=p>=24?p:0,s[m]&&l++}l>=16&&(n.set(s),r++,c=u+80)}catch{return B}if(!(r<3&&a<10))return r?he(n,e,h,o):B}}}}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 pe(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("/")],h=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:h}});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(m=>m.manifest)),c=e?s.presentation:void 0,d=t==="en"?c?.en:c,h=l=>{let m=c?.aliases[l];return m&&r.includes(m)?m:l},u=e?pe(r.filter(l=>h(l)===l),c?.outfitOrder??{}):r;function v(l,m){if(e&&!r.includes(l))throw new Error("Model outside the selected collection: "+l);let p=s.models[l]?.find(x=>x.manifest&&(!m||x.source===m));if(!p?.manifest)throw new Error("No model manifest for "+l);let y=new URL(s.sources[p.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=x=>new URL(x.split("/").map(encodeURIComponent).join("/"),y).href,A;if(p.dialogue){let x=a.get(p.source);x||(x=new Map((s.audio?.[p.source]??[]).map(R=>[R.toUpperCase(),C(R)])),a.set(p.source,x)),A={captions:t==="en"?void 0:d?.captions,url:C(p.dialogue),audio:x}}return{captions:d?.captions,modelUrl:C(p.manifest),dialogue:A,soundAliases:p.soundAliases}}return{ids:u,visibleId:h,labels:d?.labels??{},resolve:v,legacyIds:s.legacyIds}}var F=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;try{let 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),h=1,u=this.options.collection==="girls-frontline"&&!s.startsWith("background/")?oe(l=>{h=l}):void 0,v=this.options.collection?this.transition.begin(()=>h):void 0;await window.loadlive2d("live2d",a,{start:t,locale:this.options.locale,captions:d,framing:u,onPaint:v,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})))}catch(n){throw i===this.sequence&&document.getElementById("waifu")?.removeAttribute("data-initial-framing"),n}}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 we=document.currentScript,ve=we?.dataset.asteroidsUrl??"https://cdn.jsdelivr.net/gh/nova1751/live2d-api@widget-2.4.5/asteroids.js",I=o=>document.getElementById(o);function S(o){console.error("[Live2D]",o);let e=document.getElementById("waifu-status");e&&(e.textContent=g("加载失败,请检查网络或切换模型后重试。","Could not load the model. Check your connection or try another character."),w(e.textContent,5e3,10))}async function ye(o){if(o==="en"){w(["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");w(L(e.hitokoto),6e3,9),setTimeout(()=>{w(`这句一言来自 <span>「${L(String(e.from))}」</span>,是 <span>${L(String(e.creator))}</span> 在 hitokoto.cn 投稿的。`,4e3,9)},6e3)}function be(){if(window.Asteroids)(window.ASTEROIDSPLAYERS??(window.ASTEROIDSPLAYERS=[])).push(new window.Asteroids);else{let o=document.createElement("script");o.src=ve,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="";let o=I("waifu");o.hasAttribute("data-initial-framing")?o.style.bottom="0":setTimeout(()=>{o.style.bottom="0"},0)}function V(o){return o.isTrusted&&!!window.loadlive2d.prepareInteraction?.()}function xe(){let o=I("waifu").contains(document.activeElement);window.loadlive2d.hide?.(),localStorage.setItem("waifu-display",String(Date.now())),w(g("愿你有一天能与重要的人重逢。","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"':""}${i&&e instanceof F?" data-initial-framing":""}>
|
|
2
|
+
"use strict";(()=>{var Y="zh-CN";function _(o){Y=o??"zh-CN"}function g(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 P,H,U;function z(){clearTimeout(H),sessionStorage.removeItem("waifu-text"),document.getElementById("waifu-tips")?.classList.remove("waifu-tips-active")}function q(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 w(o,e,t){!o||U||Number(sessionStorage.getItem("waifu-text"))>t||(q(E(o),t),H=setTimeout(z,e))}function J(o,e){if(!e){w(L(o),5e3,11);return}U=e,q(L(o),11)}function X(o){let e=document.getElementById("live2d");if(!e)return;let t=P?.find(({selector:n})=>e.closest(n)),i=t?E(t.text):P?void 0:g("指挥官,我在。","Right here, Commander.");i&&(U=o,q(i.replace("{text}",()=>L(e.textContent??"")),11))}function K(o,e){U===o&&(U=void 0,e?z():H=setTimeout(z,1200))}function ue(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=g(`欢迎阅读<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:g(`Hello!来自 <span>${L({baidu:"百度",so:"360搜索",google:"谷歌搜索"}[i.split(".")[1]]??i)}</span> 的朋友<br>${t}`,`Hello, visitor from <span>${L(i)}</span>!<br>${t}`)}function me(o){let[e,t]=o.split("/").map(Number);return e*100+t}function Q(o){P=o.click;let e=[...o.message.default],t=new Date,i=(t.getMonth()+1)*100+t.getDate();for(let{date:u,text:v}of o.seasons){let[l,m=l]=u.split("-").map(me);l<=i&&i<=m&&e.push(E(v).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")&&w(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)),w(ue(o.time),7e3,11);let d;for(let u of["mouseover","click"])window.addEventListener(u,v=>{let l=v.target;if(!(l instanceof Element)||v.live2dHandlesCaption)return;let m=u==="click"&&l.closest("#waifu .waifu-model-stage"),p=m?document.getElementById("live2d"):l.closest("#live2d"),y=o[u].find(({selector:C})=>l.closest(C)||m&&p?.closest(C));!y||u==="mouseover"&&y.selector===d||(u==="mouseover"&&(d=y.selector),w(E(y.text).replace("{text}",()=>L(l.textContent??"")),4e3,u==="click"&&p?11:8))});let h=()=>{};h.toString=()=>(w(o.message.console,6e3,9),""),console.log("%c",h),window.addEventListener("copy",()=>w(o.message.copy,6e3,9)),document.addEventListener("visibilitychange",()=>{clearTimeout(a),document.hidden||(c(),a=setTimeout(r,n),localStorage.getItem("waifu-display")||w(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,fe=/\/gh\/nova1751\/live2d-api@widget-[^/]+\/?$/,ge=/\/live2dapi-noa(?:@[^/]+)?\/?$/;function te(o){let e=new URL(o,document.baseURI);return!ge.test(e.pathname)&&!fe.test(e.pathname)||/@1\.[^/]+\/?$/.test(e.pathname)?o:(e.hostname==="cdn.jsdmirror.com"?e.origin:ee)+Z}var W=()=>g("我的新衣服好看嘛?","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 h=d[e],u=Array.isArray(h)?h:[h];u[t]||(t=0);let v=a?u[t]:E(u);t=u.indexOf(v),r=this.base+"model/"+v+"/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))),w(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,W(),!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,g(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,W(),e,t)}let{textures:s}=await T(this.base+"rand_textures/?id="+i+"-"+n);s.id===1&&n===1?w(g("我还没有其他衣服呢!","This is my only outfit so far!"),4e3,10):await this.load(i,s.id,W(),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"),t.hasAttribute("data-initial-framing")&&(t.removeAttribute("data-initial-framing"),document.activeElement?.matches("#waifu-toggle:focus-visible")&&t.querySelector("#waifu-tool button")?.focus({preventScroll:!0}))}}}};var B={scale:1,x:0,y:0},f=128;function O(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 he(o,e,t,i){let n=new Float64Array(f),s=new Float64Array(f),a=f,r=0,c=0;for(let b=0;b<o.length;b++){if(!o[b])continue;let M=Math.floor(b/f);n[b%f]+=o[b],s[M]+=o[b],c+=o[b],a=Math.min(a,M),r=Math.max(r,M+1)}if(!c)return B;a=Math.max(a,O(s,c,.001)-2);let d=O(n,c,.001),h=O(n,c,.999)+1,u=h-d,v=r-a,l=i?Math.max(.7,Math.min(1.9,u/v*.93/.94)):1;i?.(l);let m=Math.min(1,l),p=Math.min(1,1/l),y=Math.min(.93*f*p/v,.94*f*m/u,5/e.scale),C=0,A=0;if(t)for(let b=a+2;b<r;b+=4)for(let M=d+2;M<h;M+=4){if(o[b*f+M]<96)continue;t((M+.5)/f,(b+.5)/f).some(de=>/^(head|face|body|bust|torso)\d*$/i.test(de))&&(C+=M+.5,A++)}let x=A>=3?C/A:O(n,c,.5)+.5,R=.475*f*m/y,le=Math.max(h-R,Math.min(d+R,x));return{scale:e.scale*y,x:(.5-le/f)*y,y:.5-.03*p+(.5-r/f)*y}}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=new Uint8Array(n.length),a=0,r=0,c=0;return{initial:e,measure(d,h){if(!i)return B;let u=performance.now();if(!(u<c)){a++;try{i.clearRect(0,0,f,f),i.drawImage(d,0,0,f,f);let{data:v}=i.getImageData(0,0,f,f),l=0;for(let m=0;m<n.length;m++){let p=v[4*m+3];s[m]=p>=24?p:0,s[m]&&l++}l>=16&&(n.set(s),r++,c=u+80)}catch{return B}if(!(r<3&&a<10))return r?he(n,e,h,o):B}}}}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 pe(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("/")],h=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:h}});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(m=>m.manifest)),c=e?s.presentation:void 0,d=t==="en"?c?.en:c,h=l=>{let m=c?.aliases[l];return m&&r.includes(m)?m:l},u=e?pe(r.filter(l=>h(l)===l),c?.outfitOrder??{}):r;function v(l,m){if(e&&!r.includes(l))throw new Error("Model outside the selected collection: "+l);let p=s.models[l]?.find(x=>x.manifest&&(!m||x.source===m));if(!p?.manifest)throw new Error("No model manifest for "+l);let y=new URL(s.sources[p.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=x=>new URL(x.split("/").map(encodeURIComponent).join("/"),y).href,A;if(p.dialogue){let x=a.get(p.source);x||(x=new Map((s.audio?.[p.source]??[]).map(R=>[R.toUpperCase(),C(R)])),a.set(p.source,x)),A={captions:t==="en"?void 0:d?.captions,url:C(p.dialogue),audio:x}}return{captions:d?.captions,modelUrl:C(p.manifest),dialogue:A,soundAliases:p.soundAliases}}return{ids:u,visibleId:h,labels:d?.labels??{},resolve:v,legacyIds:s.legacyIds}}var F=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;try{let 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),h=1,u=this.options.collection==="girls-frontline"&&!s.startsWith("background/")?oe(l=>{h=l}):void 0,v=this.options.collection?this.transition.begin(()=>h):void 0;await window.loadlive2d("live2d",a,{start:t,locale:this.options.locale,captions:d,framing:u,onPaint:v,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})))}catch(n){throw i===this.sequence&&document.getElementById("waifu")?.removeAttribute("data-initial-framing"),n}}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 we=document.currentScript,ve=we?.dataset.asteroidsUrl??"https://cdn.jsdelivr.net/gh/nova1751/live2d-api@widget-2.4.7/asteroids.js",I=o=>document.getElementById(o);function S(o){console.error("[Live2D]",o);let e=document.getElementById("waifu-status");e&&(e.textContent=g("加载失败,请检查网络或切换模型后重试。","Could not load the model. Check your connection or try another character."),w(e.textContent,5e3,10))}async function ye(o){if(o==="en"){w(["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");w(L(e.hitokoto),6e3,9),setTimeout(()=>{w(`这句一言来自 <span>「${L(String(e.from))}」</span>,是 <span>${L(String(e.creator))}</span> 在 hitokoto.cn 投稿的。`,4e3,9)},6e3)}function be(){if(window.Asteroids)(window.ASTEROIDSPLAYERS??(window.ASTEROIDSPLAYERS=[])).push(new window.Asteroids);else{let o=document.createElement("script");o.src=ve,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="";let o=I("waifu");o.hasAttribute("data-initial-framing")?o.style.bottom="0":setTimeout(()=>{o.style.bottom="0"},0)}function V(o){return o.isTrusted&&!!window.loadlive2d.prepareInteraction?.()}function xe(){let o=I("waifu").contains(document.activeElement);window.loadlive2d.hide?.(),localStorage.setItem("waifu-display",String(Date.now())),w(g("愿你有一天能与重要的人重逢。","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"':""}${i&&e instanceof F?" data-initial-framing":""}>
|
|
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.7/";
|
|
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.7/"})();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 g(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 P,H,R;function z(){clearTimeout(H),sessionStorage.removeItem("waifu-text"),document.getElementById("waifu-tips")?.classList.remove("waifu-tips-active")}function q(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 w(o,e,t){!o||R||Number(sessionStorage.getItem("waifu-text"))>t||(q(U(o),t),H=setTimeout(z,e))}function J(o,e){if(!e){w(L(o),5e3,11);return}R=e,q(L(o),11)}function X(o){let e=document.getElementById("live2d");if(!e)return;let t=P?.find(({selector:n})=>e.closest(n)),i=t?U(t.text):P?void 0:g("指挥官,我在。","Right here, Commander.");i&&(R=o,q(i.replace("{text}",()=>L(e.textContent??"")),11))}function K(o,e){R===o&&(R=void 0,e?z():H=setTimeout(z,1200))}function ue(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=g(`欢迎阅读<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:g(`Hello!来自 <span>${L({baidu:"百度",so:"360搜索",google:"谷歌搜索"}[i.split(".")[1]]??i)}</span> 的朋友<br>${t}`,`Hello, visitor from <span>${L(i)}</span>!<br>${t}`)}function me(o){let[e,t]=o.split("/").map(Number);return e*100+t}function Q(o){P=o.click;let e=[...o.message.default],t=new Date,i=(t.getMonth()+1)*100+t.getDate();for(let{date:u,text:v}of o.seasons){let[l,m=l]=u.split("-").map(me);l<=i&&i<=m&&e.push(U(v).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")&&w(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)),w(ue(o.time),7e3,11);let d;for(let u of["mouseover","click"])window.addEventListener(u,v=>{let l=v.target;if(!(l instanceof Element)||v.live2dHandlesCaption)return;let m=u==="click"&&l.closest("#waifu .waifu-model-stage"),p=m?document.getElementById("live2d"):l.closest("#live2d"),y=o[u].find(({selector:C})=>l.closest(C)||m&&p?.closest(C));!y||u==="mouseover"&&y.selector===d||(u==="mouseover"&&(d=y.selector),w(U(y.text).replace("{text}",()=>L(l.textContent??"")),4e3,u==="click"&&p?11:8))});let h=()=>{};h.toString=()=>(w(o.message.console,6e3,9),""),console.log("%c",h),window.addEventListener("copy",()=>w(o.message.copy,6e3,9)),document.addEventListener("visibilitychange",()=>{clearTimeout(a),document.hidden||(c(),a=setTimeout(r,n),localStorage.getItem("waifu-display")||w(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,fe=/\/gh\/nova1751\/live2d-api@widget-[^/]+\/?$/,ge=/\/live2dapi-noa(?:@[^/]+)?\/?$/;function te(o){let e=new URL(o,document.baseURI);return!ge.test(e.pathname)&&!fe.test(e.pathname)||/@1\.[^/]+\/?$/.test(e.pathname)?o:(e.hostname==="cdn.jsdmirror.com"?e.origin:ee)+Z}var W=()=>g("我的新衣服好看嘛?","How do you like my new outfit?"),E=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=E("modelId"),t=E("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 h=d[e],u=Array.isArray(h)?h:[h];u[t]||(t=0);let v=u[t];t=u.indexOf(v),r=this.base+"model/"+v+"/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))),w(i,4e3,10),this.loaded=!0)}async costume(e){if(this.options.modelUrl||!this.useCDN)return;let t=++this.revision,i=E("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,W(),!1,t,!0)}async nextModel(e=!1){let t=++this.revision,i=E("modelId");if(this.useCDN){let{models:s,messages:a}=await this.list(),r=(i+1)%s.length;return this.load(r,0,g(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=E("modelId"),n=E("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,W(),e,t)}let{textures:s}=await T(this.base+"rand_textures/?id="+i+"-"+n);s.id===1&&n===1?w(g("我还没有其他衣服呢!","This is my only outfit so far!"),4e3,10):await this.load(i,s.id,W(),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"),t.hasAttribute("data-initial-framing")&&(t.removeAttribute("data-initial-framing"),document.activeElement?.matches("#waifu-toggle:focus-visible")&&t.querySelector("#waifu-tool button")?.focus({preventScroll:!0}))}}}};var B={scale:1,x:0,y:0},f=128;function O(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 he(o,e,t,i){let n=new Float64Array(f),s=new Float64Array(f),a=f,r=0,c=0;for(let b=0;b<o.length;b++){if(!o[b])continue;let M=Math.floor(b/f);n[b%f]+=o[b],s[M]+=o[b],c+=o[b],a=Math.min(a,M),r=Math.max(r,M+1)}if(!c)return B;a=Math.max(a,O(s,c,.001)-2);let d=O(n,c,.001),h=O(n,c,.999)+1,u=h-d,v=r-a,l=i?Math.max(.7,Math.min(1.9,u/v*.93/.94)):1;i?.(l);let m=Math.min(1,l),p=Math.min(1,1/l),y=Math.min(.93*f*p/v,.94*f*m/u,5/e.scale),C=0,A=0;if(t)for(let b=a+2;b<r;b+=4)for(let M=d+2;M<h;M+=4){if(o[b*f+M]<96)continue;t((M+.5)/f,(b+.5)/f).some(de=>/^(head|face|body|bust|torso)\d*$/i.test(de))&&(C+=M+.5,A++)}let x=A>=3?C/A:O(n,c,.5)+.5,F=.475*f*m/y,le=Math.max(h-F,Math.min(d+F,x));return{scale:e.scale*y,x:(.5-le/f)*y,y:.5-.03*p+(.5-r/f)*y}}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=new Uint8Array(n.length),a=0,r=0,c=0;return{initial:e,measure(d,h){if(!i)return B;let u=performance.now();if(!(u<c)){a++;try{i.clearRect(0,0,f,f),i.drawImage(d,0,0,f,f);let{data:v}=i.getImageData(0,0,f,f),l=0;for(let m=0;m<n.length;m++){let p=v[4*m+3];s[m]=p>=24?p:0,s[m]&&l++}l>=16&&(n.set(s),r++,c=u+80)}catch{return B}if(!(r<3&&a<10))return r?he(n,e,h,o):B}}}}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 pe(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("/")],h=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:h}});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(m=>m.manifest)),c=e?s.presentation:void 0,d=t==="en"?c?.en:c,h=l=>{let m=c?.aliases[l];return m&&r.includes(m)?m:l},u=e?pe(r.filter(l=>h(l)===l),c?.outfitOrder??{}):r;function v(l,m){if(e&&!r.includes(l))throw new Error("Model outside the selected collection: "+l);let p=s.models[l]?.find(x=>x.manifest&&(!m||x.source===m));if(!p?.manifest)throw new Error("No model manifest for "+l);let y=new URL(s.sources[p.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=x=>new URL(x.split("/").map(encodeURIComponent).join("/"),y).href,A;if(p.dialogue){let x=a.get(p.source);x||(x=new Map((s.audio?.[p.source]??[]).map(F=>[F.toUpperCase(),C(F)])),a.set(p.source,x)),A={captions:t==="en"?void 0:d?.captions,url:C(p.dialogue),audio:x}}return{captions:d?.captions,modelUrl:C(p.manifest),dialogue:A,soundAliases:p.soundAliases}}return{ids:u,visibleId:h,labels:d?.labels??{},resolve:v,legacyIds:s.legacyIds}}var k=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;try{let 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),h=1,u=this.options.collection==="girls-frontline"&&!s.startsWith("background/")?oe(l=>{h=l}):void 0,v=this.options.collection?this.transition.begin(()=>h):void 0;await window.loadlive2d("live2d",a,{start:t,locale:this.options.locale,captions:d,framing:u,onPaint:v,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})))}catch(n){throw i===this.sequence&&document.getElementById("waifu")?.removeAttribute("data-initial-framing"),n}}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 we=document.currentScript,ve=we?.dataset.asteroidsUrl??"https://cdn.jsdelivr.net/gh/nova1751/live2d-api@widget-2.4.5/asteroids.js",I=o=>document.getElementById(o);function S(o){console.error("[Live2D]",o);let e=document.getElementById("waifu-status");e&&(e.textContent=g("加载失败,请检查网络或切换模型后重试。","Could not load the model. Check your connection or try another character."),w(e.textContent,5e3,10))}async function ye(o){if(o==="en"){w(["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");w(L(e.hitokoto),6e3,9),setTimeout(()=>{w(`这句一言来自 <span>「${L(String(e.from))}」</span>,是 <span>${L(String(e.creator))}</span> 在 hitokoto.cn 投稿的。`,4e3,9)},6e3)}function be(){if(window.Asteroids)(window.ASTEROIDSPLAYERS??(window.ASTEROIDSPLAYERS=[])).push(new window.Asteroids);else{let o=document.createElement("script");o.src=ve,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="";let o=I("waifu");o.hasAttribute("data-initial-framing")?o.style.bottom="0":setTimeout(()=>{o.style.bottom="0"},0)}function V(o){return o.isTrusted&&!!window.loadlive2d.prepareInteraction?.()}function xe(){let o=I("waifu").contains(document.activeElement);window.loadlive2d.hide?.(),localStorage.setItem("waifu-display",String(Date.now())),w(g("愿你有一天能与重要的人重逢。","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"':""}${i&&e instanceof k?" data-initial-framing":""}>
|
|
2
|
+
"use strict";(()=>{var Y="zh-CN";function _(o){Y=o??"zh-CN"}function g(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 P,H,R;function z(){clearTimeout(H),sessionStorage.removeItem("waifu-text"),document.getElementById("waifu-tips")?.classList.remove("waifu-tips-active")}function q(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 w(o,e,t){!o||R||Number(sessionStorage.getItem("waifu-text"))>t||(q(U(o),t),H=setTimeout(z,e))}function J(o,e){if(!e){w(L(o),5e3,11);return}R=e,q(L(o),11)}function X(o){let e=document.getElementById("live2d");if(!e)return;let t=P?.find(({selector:n})=>e.closest(n)),i=t?U(t.text):P?void 0:g("指挥官,我在。","Right here, Commander.");i&&(R=o,q(i.replace("{text}",()=>L(e.textContent??"")),11))}function K(o,e){R===o&&(R=void 0,e?z():H=setTimeout(z,1200))}function ue(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=g(`欢迎阅读<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:g(`Hello!来自 <span>${L({baidu:"百度",so:"360搜索",google:"谷歌搜索"}[i.split(".")[1]]??i)}</span> 的朋友<br>${t}`,`Hello, visitor from <span>${L(i)}</span>!<br>${t}`)}function me(o){let[e,t]=o.split("/").map(Number);return e*100+t}function Q(o){P=o.click;let e=[...o.message.default],t=new Date,i=(t.getMonth()+1)*100+t.getDate();for(let{date:u,text:v}of o.seasons){let[l,m=l]=u.split("-").map(me);l<=i&&i<=m&&e.push(U(v).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")&&w(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)),w(ue(o.time),7e3,11);let d;for(let u of["mouseover","click"])window.addEventListener(u,v=>{let l=v.target;if(!(l instanceof Element)||v.live2dHandlesCaption)return;let m=u==="click"&&l.closest("#waifu .waifu-model-stage"),p=m?document.getElementById("live2d"):l.closest("#live2d"),y=o[u].find(({selector:C})=>l.closest(C)||m&&p?.closest(C));!y||u==="mouseover"&&y.selector===d||(u==="mouseover"&&(d=y.selector),w(U(y.text).replace("{text}",()=>L(l.textContent??"")),4e3,u==="click"&&p?11:8))});let h=()=>{};h.toString=()=>(w(o.message.console,6e3,9),""),console.log("%c",h),window.addEventListener("copy",()=>w(o.message.copy,6e3,9)),document.addEventListener("visibilitychange",()=>{clearTimeout(a),document.hidden||(c(),a=setTimeout(r,n),localStorage.getItem("waifu-display")||w(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,fe=/\/gh\/nova1751\/live2d-api@widget-[^/]+\/?$/,ge=/\/live2dapi-noa(?:@[^/]+)?\/?$/;function te(o){let e=new URL(o,document.baseURI);return!ge.test(e.pathname)&&!fe.test(e.pathname)||/@1\.[^/]+\/?$/.test(e.pathname)?o:(e.hostname==="cdn.jsdmirror.com"?e.origin:ee)+Z}var W=()=>g("我的新衣服好看嘛?","How do you like my new outfit?"),E=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=E("modelId"),t=E("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 h=d[e],u=Array.isArray(h)?h:[h];u[t]||(t=0);let v=u[t];t=u.indexOf(v),r=this.base+"model/"+v+"/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))),w(i,4e3,10),this.loaded=!0)}async costume(e){if(this.options.modelUrl||!this.useCDN)return;let t=++this.revision,i=E("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,W(),!1,t,!0)}async nextModel(e=!1){let t=++this.revision,i=E("modelId");if(this.useCDN){let{models:s,messages:a}=await this.list(),r=(i+1)%s.length;return this.load(r,0,g(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=E("modelId"),n=E("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,W(),e,t)}let{textures:s}=await T(this.base+"rand_textures/?id="+i+"-"+n);s.id===1&&n===1?w(g("我还没有其他衣服呢!","This is my only outfit so far!"),4e3,10):await this.load(i,s.id,W(),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"),t.hasAttribute("data-initial-framing")&&(t.removeAttribute("data-initial-framing"),document.activeElement?.matches("#waifu-toggle:focus-visible")&&t.querySelector("#waifu-tool button")?.focus({preventScroll:!0}))}}}};var B={scale:1,x:0,y:0},f=128;function O(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 he(o,e,t,i){let n=new Float64Array(f),s=new Float64Array(f),a=f,r=0,c=0;for(let b=0;b<o.length;b++){if(!o[b])continue;let M=Math.floor(b/f);n[b%f]+=o[b],s[M]+=o[b],c+=o[b],a=Math.min(a,M),r=Math.max(r,M+1)}if(!c)return B;a=Math.max(a,O(s,c,.001)-2);let d=O(n,c,.001),h=O(n,c,.999)+1,u=h-d,v=r-a,l=i?Math.max(.7,Math.min(1.9,u/v*.93/.94)):1;i?.(l);let m=Math.min(1,l),p=Math.min(1,1/l),y=Math.min(.93*f*p/v,.94*f*m/u,5/e.scale),C=0,A=0;if(t)for(let b=a+2;b<r;b+=4)for(let M=d+2;M<h;M+=4){if(o[b*f+M]<96)continue;t((M+.5)/f,(b+.5)/f).some(de=>/^(head|face|body|bust|torso)\d*$/i.test(de))&&(C+=M+.5,A++)}let x=A>=3?C/A:O(n,c,.5)+.5,F=.475*f*m/y,le=Math.max(h-F,Math.min(d+F,x));return{scale:e.scale*y,x:(.5-le/f)*y,y:.5-.03*p+(.5-r/f)*y}}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=new Uint8Array(n.length),a=0,r=0,c=0;return{initial:e,measure(d,h){if(!i)return B;let u=performance.now();if(!(u<c)){a++;try{i.clearRect(0,0,f,f),i.drawImage(d,0,0,f,f);let{data:v}=i.getImageData(0,0,f,f),l=0;for(let m=0;m<n.length;m++){let p=v[4*m+3];s[m]=p>=24?p:0,s[m]&&l++}l>=16&&(n.set(s),r++,c=u+80)}catch{return B}if(!(r<3&&a<10))return r?he(n,e,h,o):B}}}}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 pe(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("/")],h=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:h}});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(m=>m.manifest)),c=e?s.presentation:void 0,d=t==="en"?c?.en:c,h=l=>{let m=c?.aliases[l];return m&&r.includes(m)?m:l},u=e?pe(r.filter(l=>h(l)===l),c?.outfitOrder??{}):r;function v(l,m){if(e&&!r.includes(l))throw new Error("Model outside the selected collection: "+l);let p=s.models[l]?.find(x=>x.manifest&&(!m||x.source===m));if(!p?.manifest)throw new Error("No model manifest for "+l);let y=new URL(s.sources[p.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=x=>new URL(x.split("/").map(encodeURIComponent).join("/"),y).href,A;if(p.dialogue){let x=a.get(p.source);x||(x=new Map((s.audio?.[p.source]??[]).map(F=>[F.toUpperCase(),C(F)])),a.set(p.source,x)),A={captions:t==="en"?void 0:d?.captions,url:C(p.dialogue),audio:x}}return{captions:d?.captions,modelUrl:C(p.manifest),dialogue:A,soundAliases:p.soundAliases}}return{ids:u,visibleId:h,labels:d?.labels??{},resolve:v,legacyIds:s.legacyIds}}var k=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;try{let 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),h=1,u=this.options.collection==="girls-frontline"&&!s.startsWith("background/")?oe(l=>{h=l}):void 0,v=this.options.collection?this.transition.begin(()=>h):void 0;await window.loadlive2d("live2d",a,{start:t,locale:this.options.locale,captions:d,framing:u,onPaint:v,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})))}catch(n){throw i===this.sequence&&document.getElementById("waifu")?.removeAttribute("data-initial-framing"),n}}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 we=document.currentScript,ve=we?.dataset.asteroidsUrl??"https://cdn.jsdelivr.net/gh/nova1751/live2d-api@widget-2.4.7/asteroids.js",I=o=>document.getElementById(o);function S(o){console.error("[Live2D]",o);let e=document.getElementById("waifu-status");e&&(e.textContent=g("加载失败,请检查网络或切换模型后重试。","Could not load the model. Check your connection or try another character."),w(e.textContent,5e3,10))}async function ye(o){if(o==="en"){w(["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");w(L(e.hitokoto),6e3,9),setTimeout(()=>{w(`这句一言来自 <span>「${L(String(e.from))}」</span>,是 <span>${L(String(e.creator))}</span> 在 hitokoto.cn 投稿的。`,4e3,9)},6e3)}function be(){if(window.Asteroids)(window.ASTEROIDSPLAYERS??(window.ASTEROIDSPLAYERS=[])).push(new window.Asteroids);else{let o=document.createElement("script");o.src=ve,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="";let o=I("waifu");o.hasAttribute("data-initial-framing")?o.style.bottom="0":setTimeout(()=>{o.style.bottom="0"},0)}function V(o){return o.isTrusted&&!!window.loadlive2d.prepareInteraction?.()}function xe(){let o=I("waifu").contains(document.activeElement);window.loadlive2d.hide?.(),localStorage.setItem("waifu-display",String(Date.now())),w(g("愿你有一天能与重要的人重逢。","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"':""}${i&&e instanceof k?" data-initial-framing":""}>
|
|
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/latest.mjs
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/*! Live2D API | Generated from src/ | https://github.com/nova1751/live2d-api */
|
|
2
|
+
|
|
3
|
+
// package.json
|
|
4
|
+
var version = "2.4.7";
|
|
5
|
+
|
|
6
|
+
// src/latest.mts
|
|
7
|
+
var entry = new URL(import.meta.url);
|
|
8
|
+
var mainland = entry.hostname === "cdn.jsdmirror.com";
|
|
9
|
+
var cdn = mainland ? "https://cdn.jsdmirror.com" : "https://cdn.jsdelivr.net";
|
|
10
|
+
var registry = mainland ? "https://registry.npmmirror.com" : "https://registry.npmjs.org";
|
|
11
|
+
async function latestVersion() {
|
|
12
|
+
const request = new AbortController();
|
|
13
|
+
const timer = setTimeout(() => request.abort(), 2500);
|
|
14
|
+
try {
|
|
15
|
+
const response = await fetch(registry + "/live2dapi-noa/latest", { signal: request.signal, credentials: "omit" });
|
|
16
|
+
if (response.ok) {
|
|
17
|
+
const { version: version2 } = await response.json();
|
|
18
|
+
if (typeof version2 === "string" && /^\d+\.\d+\.\d+$/.test(version2) && version2.localeCompare(version, "en", { numeric: true }) >= 0) return version2;
|
|
19
|
+
}
|
|
20
|
+
} catch {
|
|
21
|
+
} finally {
|
|
22
|
+
clearTimeout(timer);
|
|
23
|
+
}
|
|
24
|
+
return version;
|
|
25
|
+
}
|
|
26
|
+
function mount(version2) {
|
|
27
|
+
return import(cdn + "/gh/nova1751/live2d-api@widget-" + version2 + "/girls-frontline.mjs" + entry.search);
|
|
28
|
+
}
|
|
29
|
+
if (window.innerWidth >= 768) {
|
|
30
|
+
const version2 = await latestVersion();
|
|
31
|
+
try {
|
|
32
|
+
await mount(version2);
|
|
33
|
+
} catch (error) {
|
|
34
|
+
if (version2 === version) throw error;
|
|
35
|
+
await mount(version);
|
|
36
|
+
}
|
|
37
|
+
}
|