Move Web backend to winit-web

This commit is contained in:
Mads Marquart
2025-05-16 01:23:35 +02:00
committed by Kirill Chibisov
parent 2d4b9938f0
commit e542a78deb
50 changed files with 259 additions and 273 deletions

View File

@@ -0,0 +1,19 @@
{
"module": {
"type": "es6"
},
"isModule": true,
"minify": true,
"jsc": {
"parser": {
"syntax": "typescript"
},
"target": "es2022",
"minify": {
"compress": {
"unused": true
},
"mangle": true
}
}
}

View File

@@ -0,0 +1,32 @@
import eslint from '@eslint/js'
import tseslint from 'typescript-eslint'
import globals from 'globals'
export default tseslint.config(
{
ignores: ['**/*.min.js', 'eslint.config.mjs'],
},
eslint.configs.recommended,
...tseslint.configs.strictTypeChecked,
...tseslint.configs.stylisticTypeChecked,
{
languageOptions: {
parserOptions: {
ecmaVersion: 'latest',
project: ['tsconfig.json'],
sourceType: 'module',
},
globals: {
...globals.browser,
},
},
rules: {
'@typescript-eslint/no-confusing-void-expression': [
'error',
{
ignoreArrowShorthand: true,
},
],
},
}
)

View File

@@ -0,0 +1,8 @@
{
"devDependencies": {
"@eslint/js": "^9",
"eslint": "^9",
"typescript": "^5",
"typescript-eslint": "^8"
}
}

12
winit-web/src/script/scheduler.d.ts vendored Normal file
View File

@@ -0,0 +1,12 @@
declare global {
// eslint-disable-next-line no-var
var scheduler: Scheduler
}
export interface Scheduler {
postTask<T>(callback: () => T | PromiseLike<T>, options?: SchedulerPostTaskOptions): Promise<T>
}
export interface SchedulerPostTaskOptions {
delay?: number
}

View File

@@ -0,0 +1,14 @@
{
"compilerOptions": {
"target": "ESNext",
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"exactOptionalPropertyTypes": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noUncheckedIndexedAccess": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"strict": true,
}
}

1
winit-web/src/script/worker.min.js vendored Normal file
View File

@@ -0,0 +1 @@
onmessage=e=>{let[s,a]=e.data,l=()=>s.postMessage(void 0);"scheduler"in globalThis?globalThis.scheduler.postTask(l,{delay:a}):setTimeout(l,a)};

View File

@@ -0,0 +1,10 @@
onmessage = (event) => {
const [port, timeout] = event.data as [MessagePort, number]
const f = () => port.postMessage(undefined)
if ('scheduler' in globalThis) {
void globalThis.scheduler.postTask(f, { delay: timeout })
} else {
setTimeout(f, timeout)
}
}