From 8027e52cb221c432bed64517015ebf3182e6166d Mon Sep 17 00:00:00 2001 From: bptato Date: Fri, 2 Jun 2023 00:36:54 +0200 Subject: Add support for canvas and multipart Quite incomplete canvas implementation. Crucially, the layout engine can't do much with whatever is drawn because it doesn't support images yet. I've re-introduced multipart as well, with the FormData API. For the append function I've also introduced a hack to the JS binding generator that allows requesting the JSContext pointer in nim procs. Really I should just fix the union generator thing and add support for overloading. In conclusion, for now the only thing canvas can be used for is exporting it as PNG and uploading it somewhere. Also, we now have PNG encoding and decoding too. (Now if only we had sixels as well...) --- src/html/env.nim | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/html/env.nim') diff --git a/src/html/env.nim b/src/html/env.nim index 544f5083..8b558b8a 100644 --- a/src/html/env.nim +++ b/src/html/env.nim @@ -6,9 +6,12 @@ import html/htmlparser import io/loader import io/promise import io/request +import js/intl import js/javascript import js/timeout +import types/blob import types/url +import xhr/formdata as formdata_impl # NavigatorID proc appCodeName(navigator: Navigator): string {.jsfget.} = "Mozilla" @@ -73,6 +76,16 @@ proc clearTimeout(window: Window, id: int32) {.jsfunc.} = proc clearInterval(window: Window, id: int32) {.jsfunc.} = window.timeouts.clearInterval(id) +proc screenX(window: Window): int64 {.jsfget.} = 0 +proc screenY(window: Window): int64 {.jsfget.} = 0 +proc screenLeft(window: Window): int64 {.jsfget.} = 0 +proc screenTop(window: Window): int64 {.jsfget.} = 0 +#TODO outerWidth, outerHeight +proc devicePixelRatio(window: Window): float64 {.jsfget.} = 1 + +func location(window: Window): URL {.jsfget.} = + window.document.location + proc addScripting*(window: Window, selector: Selector[int]) = let rt = newJSRuntime() let ctx = rt.newJSContext() @@ -102,6 +115,10 @@ proc addScripting*(window: Window, selector: Selector[int]) = ctx.addDOMModule() ctx.addURLModule() ctx.addHTMLModule() + ctx.addIntlModule() + ctx.addBlobModule() + ctx.addFormDataModule() + ctx.addRequestModule() proc runJSJobs*(window: Window) = window.jsrt.runJSJobs(window.console.err) -- cgit 1.4.1-2-gfad0