Skip to content

Commit 6dfb07f

Browse files
Patch icon import
1 parent 42e80a5 commit 6dfb07f

File tree

5 files changed

+62
-65
lines changed

5 files changed

+62
-65
lines changed

demo/login.html

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ <h1 class="h3 mb-3 fw-normal">看板娘登陆平台</h1>
150150
</div>
151151
<p class="mt-5 mb-3 text-muted">Copyleft &copy; Mimi 2019</p>
152152
</form>
153-
<script>
153+
<script type="module">
154154
/*
155155
* _(:з」∠)_
156156
* Created by Shuqiao Zhang in 2019.
@@ -168,49 +168,43 @@ <h1 class="h3 mb-3 fw-normal">看板娘登陆平台</h1>
168168
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
169169
* GNU General Public License for more details.
170170
*/
171+
import { Model } from "../build/index.js";
171172
window.addEventListener("load", () => {
172-
"use strict";
173-
174173
if (!CSS.supports("clip-path", "circle(120px at center)")) {
175174
document.getElementById("stage").innerHTML = '<img src="./screenshots/screenshot-1.png">';
176175
return;
177176
}
178177

179178
const apiPath = "https://live2d.fghrsh.net/api";
180-
let state = 0, loading = false,
181-
modelId = localStorage.getItem("modelId"),
182-
modelTexturesId = localStorage.getItem("modelTexturesId");
183-
if (modelId === null) {
184-
modelId = 1;
185-
modelTexturesId = 53;
186-
}
187-
loadModel(modelId, modelTexturesId);
179+
let state = 0, loading = false, modelInitialized = false;
180+
const model = new Model();
181+
const modelId = 1;
182+
let modelTexturesId = 0;
183+
loadModel();
188184

189-
function loadModel(modelId, modelTexturesId) {
190-
localStorage.setItem("modelId", modelId);
191-
if (modelTexturesId === undefined) modelTexturesId = 0;
192-
localStorage.setItem("modelTexturesId", modelTexturesId);
193-
loadlive2d("live2d", `${apiPath}/get/?id=${modelId}-${modelTexturesId}`, null);
185+
async function loadModel() {
186+
const modelSettingPath = `${apiPath}/get/?id=${modelId}-${modelTexturesId}`;
187+
const response = await fetch(modelSettingPath);
188+
const modelSetting = await response.json();
189+
if (!modelInitialized) {
190+
modelInitialized = true;
191+
await model.init('live2d', modelSettingPath, modelSetting);
192+
} else {
193+
await model.changeModelWithJSON(modelSettingPath, modelSetting);
194+
}
194195
console.log("live2d", `模型 ${modelId}-${modelTexturesId} 加载完成`);
195-
setTimeout(() => {
196-
coverPosition("80%");
197-
state = 2;
198-
}, 2000);
196+
coverPosition("80%");
197+
state = 2;
199198
}
200199

201-
function loadRandModel() {
202-
const modelId = localStorage.getItem("modelId"),
203-
modelTexturesId = localStorage.getItem("modelTexturesId");
204-
fetch(`${apiPath}/rand_textures/?id=${modelId}-${modelTexturesId}`)
205-
.then(response => response.json())
206-
.then(result => {
207-
loadModel(modelId, result.textures.id);
208-
setTimeout(() => {
209-
state = 2;
210-
coverPosition("80%");
211-
loading = false;
212-
}, 1000);
213-
});
200+
async function loadRandModel() {
201+
const response = await fetch(`${apiPath}/rand_textures/?id=${modelId}-${modelTexturesId}`);
202+
const result = await response.json();
203+
modelTexturesId = result.textures.id;
204+
await loadModel();
205+
state = 2;
206+
coverPosition("80%");
207+
loading = false;
214208
}
215209

216210
function coverPosition(pos) {

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@
3535
},
3636
"devDependencies": {
3737
"@eslint/js": "9.26.0",
38-
"@rollup/plugin-node-resolve": "16.0.1",
3938
"@rollup/plugin-terser": "0.4.4",
40-
"@rollup/pluginutils": "5.1.4",
4139
"@types/node": "22.15.14",
4240
"eslint": "9.26.0",
4341
"rollup": "4.40.2",

rollup.config.js

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,9 @@
1-
import { nodeResolve } from '@rollup/plugin-node-resolve';
2-
import { createFilter } from '@rollup/pluginutils';
31
import terser from '@rollup/plugin-terser';
42

5-
function string(opts = {}) {
6-
if (!opts.include) {
7-
throw Error('include option should be specified');
8-
}
9-
10-
const filter = createFilter(opts.include, opts.exclude);
3+
function banner() {
114

125
return {
13-
name: 'string',
14-
15-
transform(code, id) {
16-
if (filter(id)) {
17-
return {
18-
code: `export default ${JSON.stringify(code)};`,
19-
map: { mappings: '' },
20-
};
21-
}
22-
},
6+
name: 'banner',
237

248
renderChunk(code, chunk, outputOptions = {}) {
259
return (
@@ -41,10 +25,7 @@ export default {
4125
format: 'iife',
4226
},
4327
plugins: [
44-
nodeResolve(),
45-
string({
46-
include: '**/*.svg',
47-
}),
28+
banner(),
4829
terser(),
4930
],
5031
context: 'this',

src/icons.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const fa_comment = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.7.2 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 2024 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.4c0 0 0 0 0 0s0 0 0 0s0 0 0 0c0 0 0 0 0 0l.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"/>';
2+
3+
const fa_paper_plane = ' xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.7.2 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 2024 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 480l0-83.6c0-4 1.5-7.8 4.2-10.8L331.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"/>';
4+
5+
const fa_user_circle = ' xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.7.2 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 2024 Fonticons, Inc. --><path d="M399 384.2C376.9 345.8 335.4 320 288 320l-64 0c-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"/>';
6+
7+
const fa_street_view = ' xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.7.2 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 2024 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 64l0 48c0 17.7 14.3 32 32 32l1.8 0 11.1 99.5c1.8 16.2 15.5 28.5 31.8 28.5l38.7 0c16.3 0 30-12.3 31.8-28.5L318.2 304l1.8 0c17.7 0 32-14.3 32-32l0-48c0-35.3-28.7-64-64-64l-64 0zM132.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"/>';
8+
9+
const fa_camera_retro = ' xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.7.2 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 2024 Fonticons, Inc. --><path d="M220.6 121.2L271.1 96 448 96l0 96-114.8 0c-21.9-15.1-48.5-24-77.2-24s-55.2 8.9-77.2 24L64 192l0-64 128 0c9.9 0 19.7-2.3 28.6-6.8zM0 128L0 416c0 35.3 28.7 64 64 64l384 0c35.3 0 64-28.7 64-64l0-320c0-35.3-28.7-64-64-64L271.1 32c-9.9 0-19.7 2.3-28.6 6.8L192 64l-32 0 0-16c0-8.8-7.2-16-16-16L80 32c-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"/>';
10+
11+
const fa_info_circle = ' xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.7.2 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 2024 Fonticons, Inc. --><path d="M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512zM216 336l24 0 0-64-24 0c-13.3 0-24-10.7-24-24s10.7-24 24-24l48 0c13.3 0 24 10.7 24 24l0 88 8 0c13.3 0 24 10.7 24 24s-10.7 24-24 24l-80 0c-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"/>';
12+
13+
const fa_xmark = ' xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><!--! Font Awesome Free 6.7.2 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 2024 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>';
14+
15+
export {
16+
fa_comment,
17+
fa_paper_plane,
18+
fa_user_circle,
19+
fa_street_view,
20+
fa_camera_retro,
21+
fa_info_circle,
22+
fa_xmark
23+
}

src/tools.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
* @module tools
44
*/
55

6-
import fa_comment from '@fortawesome/fontawesome-free/svgs/solid/comment.svg';
7-
import fa_paper_plane from '@fortawesome/fontawesome-free/svgs/solid/paper-plane.svg';
8-
import fa_user_circle from '@fortawesome/fontawesome-free/svgs/solid/circle-user.svg';
9-
import fa_street_view from '@fortawesome/fontawesome-free/svgs/solid/street-view.svg';
10-
import fa_camera_retro from '@fortawesome/fontawesome-free/svgs/solid/camera-retro.svg';
11-
import fa_info_circle from '@fortawesome/fontawesome-free/svgs/solid/circle-info.svg';
12-
import fa_xmark from '@fortawesome/fontawesome-free/svgs/solid/xmark.svg';
13-
6+
import {
7+
fa_comment,
8+
fa_paper_plane,
9+
fa_user_circle,
10+
fa_street_view,
11+
fa_camera_retro,
12+
fa_info_circle,
13+
fa_xmark
14+
} from './icons.js';
1415
import { showMessage } from './message.js';
1516

1617
/**

0 commit comments

Comments
 (0)