gui: native WebView host as nested module yetano.dev/yetano/core/gui

Extracted from prototypes/yetano-webview (AP1): packages assets,
document, bridge and window (macOS Cocoa/WKWebView via cgo, Windows
Win32/WebView2 pure Go). No local HTTP listener or port: assets go
through the WebView's resource handler, app routes through the native
message binding. Own go.mod and gui/vX.Y.Z tags keep cgo and the
WebView dependencies out of the main core module. Adds backend-free
tests for the window's dispatch/destroy guards and a yet-gui migration
guide.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
terminarandClaude Opus 5.5 committed 2026-10-23 14:47:26 +02:00
1 parent 90132e2d76
commit 8c63d42a27
27 files changed
+4849 -3

No files matched your search

+56
View File
@@ -0,0 +1,56 @@
package assets
import (
"bytes"
"fmt"
"net/http"
"path"
"strings"
)
// Known types by extension. The extension wins; sniffing only fills gaps.
var mimeByExt = map[string]string{
".html": "text/html; charset=utf-8",
".htm": "text/html; charset=utf-8",
".css": "text/css; charset=utf-8",
".js": "text/javascript; charset=utf-8",
".mjs": "text/javascript; charset=utf-8",
".json": "application/json",
".txt": "text/plain; charset=utf-8",
".svg": "image/svg+xml",
".png": "image/png",
".jpg": "image/jpeg",
".jpeg": "image/jpeg",
".gif": "image/gif",
".webp": "image/webp",
".ico": "image/x-icon",
".ttf": "font/ttf",
".otf": "font/otf",
".woff": "font/woff",
".woff2": "font/woff2",
".wasm": "application/wasm",
}
// strict extensions must never resolve to a generic type, and binary ones are
// checked against their magic bytes.
var wasmMagic = []byte{0x00, 'a', 's', 'm'}
// DetectMIME returns the MIME type for name/data.
func DetectMIME(name string, data []byte) (string, error) {
ext := strings.ToLower(path.Ext(name))
if m, ok := mimeByExt[ext]; ok {
if ext == ".wasm" && !bytes.HasPrefix(data, wasmMagic) {
return "", fmt.Errorf("%s: .wasm without WebAssembly magic bytes", name)
}
return m, nil
}
return http.DetectContentType(data), nil
}
// BaseMIME strips parameters ("text/css; charset=utf-8" -> "text/css").
func BaseMIME(m string) string {
if i := strings.IndexByte(m, ';'); i >= 0 {
m = m[:i]
}
return strings.TrimSpace(m)
}