- web/: Vue 3 + Vite + UnoCSS + Pinia, dark tactical theme (amber/#0d1117) - AppNav, ListingCard, SearchView with filters/sort, composables (useSnipeMode, useKonamiCode, useMotion), Pinia search store - Steal shimmer, auction countdown, Snipe Mode easter egg all native in Vue - docker/web/: nginx + multi-stage Dockerfile (node build → nginx serve) - compose.yml: api (8510) + web (8509) services - Dockerfile CMD updated to uvicorn for upcoming FastAPI layer - Clean build: 0 TS errors, 380 modules
55 lines
1.8 KiB
JavaScript
55 lines
1.8 KiB
JavaScript
import { getBOMEncoding } from './fallback/encoding.api.js'
|
|
|
|
// Lite-weight version which re-exports existing implementations on browsers,
|
|
// while still being aliased to the full impl in RN and Node.js
|
|
|
|
// WARNING: Note that browsers have bugs (which hopefully will get fixed soon)
|
|
|
|
const { TextDecoder, TextEncoder, TextDecoderStream, TextEncoderStream } = globalThis
|
|
|
|
export { getBOMEncoding } from './fallback/encoding.api.js'
|
|
export { TextDecoder, TextEncoder, TextDecoderStream, TextEncoderStream }
|
|
|
|
export function normalizeEncoding(label) {
|
|
if (label === 'utf-8' || label === 'utf8' || label === 'UTF-8' || label === 'UTF8') return 'utf-8'
|
|
if (label === 'windows-1252' || label === 'ascii' || label === 'latin1') return 'windows-1252'
|
|
if (/[^\w\t\n\f\r .:-]/i.test(label)) return null
|
|
const l = `${label}`.trim().toLowerCase()
|
|
try {
|
|
return new TextDecoder(l).encoding
|
|
} catch {}
|
|
|
|
if (l === 'x-user-defined') return l
|
|
if (
|
|
l === 'replacement' ||
|
|
l === 'csiso2022kr' ||
|
|
l === 'hz-gb-2312' ||
|
|
l === 'iso-2022-cn' ||
|
|
l === 'iso-2022-cn-ext' ||
|
|
l === 'iso-2022-kr'
|
|
) {
|
|
return 'replacement'
|
|
}
|
|
|
|
return null
|
|
}
|
|
|
|
export function legacyHookDecode(input, fallbackEncoding = 'utf-8') {
|
|
const enc = getBOMEncoding(input) ?? normalizeEncoding(fallbackEncoding)
|
|
if (enc === 'replacement') return input.byteLength > 0 ? '\uFFFD' : ''
|
|
return new TextDecoder(enc).decode(input)
|
|
}
|
|
|
|
export function labelToName(label) {
|
|
const enc = normalizeEncoding(label)
|
|
if (enc === 'utf-8') return 'UTF-8'
|
|
if (!enc) return enc
|
|
const p = enc.slice(0, 3)
|
|
if (p === 'utf' || p === 'iso' || p === 'koi' || p === 'euc' || p === 'ibm' || p === 'gbk') {
|
|
return enc.toUpperCase()
|
|
}
|
|
|
|
if (enc === 'big5') return 'Big5'
|
|
if (enc === 'shift_jis') return 'Shift_JIS'
|
|
return enc
|
|
}
|