Skip to content

Commit e8ad561

Browse files
committed
remove unused dependencies
1 parent f0fa86d commit e8ad561

5 files changed

Lines changed: 110 additions & 10 deletions

File tree

bun.lock

Lines changed: 2 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tex2typst-webapp",
3-
"version": "1.4.10",
3+
"version": "1.4.11",
44
"type": "module",
55
"scripts": {
66
"make:katex": "cp node_modules/katex/dist/katex.min.css public/ && cp -r node_modules/katex/dist/fonts public/",
@@ -13,7 +13,6 @@
1313
},
1414
"dependencies": {
1515
"@myriaddreamin/typst.ts": "0.7.0-rc2",
16-
"@qwinsi/utilities-js": "^0.5.0",
1716
"butteruptoasts": "^2.0.1",
1817
"katex": "^0.16.21",
1918
"tex2typst": "^0.6.0"

src/App.svelte

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import { onMount } from 'svelte';
33
import katex from 'katex'
44
import { convertTex2Typst, convertTypst2Tex, customTexMacros } from './converter'
5-
import { copyTextToClipboard } from '@qwinsi/utilities-js/clipboard'
65
import CopiedToast from './components/CopiedToast.svelte'
76
import SettingsDialog from './components/SettingsDialog.svelte'
87
import { getRandomFormula } from './random'
@@ -100,7 +99,7 @@ function sendToClipboard() {
10099
if(inputStr === '') {
101100
return;
102101
}
103-
copyTextToClipboard(output.target).then(() => {
102+
navigator.clipboard.writeText(output.target).then(() => {
104103
copiedToast.trigger();
105104
});
106105
}

src/setup-sw.ts

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
* Last Modified: 2026-04-08
3+
* Resources:
4+
* - Progressive Web Apps: Going Offline https://developers.google.com/codelabs/pwa-training/pwa03--going-offline
5+
*/
6+
7+
// return Promise<Response>
8+
function cleanResponse(response: Response): Promise<Response> {
9+
const clonedResponse = response.clone();
10+
11+
// Not all browsers support the Response.body stream, so fall back to reading
12+
// the entire body into memory as a blob.
13+
const bodyPromise = clonedResponse.body ?
14+
Promise.resolve(clonedResponse.body) :
15+
clonedResponse.blob();
16+
17+
return bodyPromise.then((body) => {
18+
// new Response() is happy when passed either a stream or a Blob.
19+
return new Response(body, {
20+
headers: clonedResponse.headers,
21+
status: clonedResponse.status,
22+
statusText: clonedResponse.statusText,
23+
});
24+
});
25+
}
26+
27+
const LAZY_CACHE_RESOURCES: string[] = [];
28+
29+
// precacheResources: string[]
30+
export function setup(version: string, precacheResources: string[], lazyCacheResources: string[] = []) {
31+
const cacheName = "cache-v" + version;
32+
33+
LAZY_CACHE_RESOURCES.push(...lazyCacheResources);
34+
35+
self.addEventListener("install", (event: any) => {
36+
// Cache all resources for current version.
37+
// Note that {cache: "reload"} is important here,
38+
// otherwise we may end up with setting old cached resources as new cache.
39+
// Ref https://stackoverflow.com/a/64880880
40+
console.info(`[Service Worker v${version}] Caching resources...`);
41+
const requests = precacheResources.map((resource) => new Request(resource, {cache: "reload"}) );
42+
event.waitUntil(
43+
caches.open(cacheName)
44+
.then((cache) => cache.addAll(requests))
45+
.then(() => {
46+
// Note that this time of loading still uses the old cache.
47+
// So it's better to propmt the user to update the app.
48+
/* e.g. display a message like:
49+
New version x.y.z is available.
50+
To update, close all active tabs of this website and open again.
51+
(Simply refreshing this page won't take effect.)
52+
*/
53+
const channel = new BroadcastChannel("SW_MESSAGES");
54+
channel.postMessage({title: "APP_UPDATE", version: version});
55+
})
56+
);
57+
});
58+
59+
self.addEventListener("activate", (event: any) => {
60+
console.info(`[Service Worker v${version}] Activated.`);
61+
62+
// Delete old caches
63+
event.waitUntil(
64+
caches.keys().then(keyList => {
65+
return Promise.all(
66+
keyList.map(key => {
67+
if (key !== cacheName) {
68+
console.info(`[Service Worker v${version}] Deleting old cache: ${key}`);
69+
return caches.delete(key);
70+
}
71+
})
72+
);
73+
})
74+
);
75+
});
76+
77+
self.addEventListener("fetch", (event: any) => {
78+
event.respondWith(
79+
/*
80+
Make sure to write `caches.open(cacheName).then(...)` instead of simple `caches.match(event.request)`.
81+
It may somehow fail to delete old cache so that the user will get stuck in old cache.
82+
Maybe it's because the tab is closed during the execution of the listener function of "activate" event?
83+
*/
84+
caches.open(cacheName).then(async function(cache) {
85+
const cachedResponse = await cache.match(event.request);
86+
if (cachedResponse) {
87+
// A cached response of **/index.html may contain a mark of redirected=true,
88+
// which will cause browser to block the response due to security concerns.
89+
// So we need to somehow remove this mark from the response.
90+
// https://stackoverflow.com/questions/45434470/only-in-chrome-service-worker-a-redirected-response-was-used-for-a-reque
91+
if (cachedResponse.redirected === true && event.request.url.endsWith("/index.html")) {
92+
return cleanResponse(cachedResponse);
93+
}
94+
return cachedResponse;
95+
} else {
96+
const response = await fetch(event.request);
97+
if (LAZY_CACHE_RESOURCES.includes(event.request.url)) {
98+
cache.put(event.request.url, response.clone());
99+
}
100+
return response;
101+
}
102+
})
103+
);
104+
});
105+
}

src/sw.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { setup } from "@qwinsi/utilities-js/sw";
1+
import { setup } from "./setup-sw";
22
import { version as APP_VERSION } from "../package.json";
33

44
const SUBDIRECTORY = "/tex2typst-webapp/";

0 commit comments

Comments
 (0)