chore: Check types and add draft full typing for x_ite. (#18)

Enabling type checking involves a full rearrangement of the
  build process, as well as supplying types for some of the
  dependencies.

  Now that (hopefully) all of the methods are typed, can call
  (for example) browser.setBrowserOption to manage the
  viewer navigation.

  Resolves #14.
  Resolves #17.

Reviewed-on: #18
Co-authored-by: Glen Whitney <glen@studioinfinity.org>
Co-committed-by: Glen Whitney <glen@studioinfinity.org>
This commit is contained in:
Glen Whitney 2023-09-11 01:52:39 +00:00 committed by Glen Whitney
parent a8707386aa
commit b5478254af
15 changed files with 2767 additions and 33 deletions

View file

@ -1,11 +1,19 @@
import https://code.jquery.com/jquery-3.7.1.js
import type {AppletObject} from ./deps/geogebra/api.ts
joyceApplets := []
type AppletDescription
html: string
children: HTMLCollection
id: string
width: number
height: number
joyceApplets: AppletDescription[] := []
$('applet[code="Geometry"]').before (i, html) ->
id := `joyceApplet${i}`
joyceApplets.push { html, this.children, id,
width: parseInt(this.getAttribute 'width'),
height: parseInt(this.getAttribute 'height') }
width: parseInt(this.getAttribute('width') ?? '200'),
height: parseInt(this.getAttribute('height') ?? '200') }
`<div id="${id}"></div>`
jQuery.getScript 'https://www.geogebra.org/apps/deployggb.js', =>
@ -14,20 +22,25 @@ jQuery.getScript 'https://www.geogebra.org/apps/deployggb.js', =>
appName: 'classic',
jApp.width,
jApp.height,
appletOnLoad: (api) =>
appletOnLoad: (api: AppletObject) =>
for child of jApp.children
dispatchJcommand api, child
api.setCoordSystem(-10, 10 + jApp.width, -10, 10 + jApp.height)
}
} as const
geoApp := new GGBApplet params
geoApp.inject jApp.id
type Cmdr
command: string
callbacks: ((api) => boolean)[]
type GeogebraCallback = (api: AppletObject) => void
type Commander
command: string
callbacks: GeogebraCallback[]
function dispatchJcommand(api, param)
type ClassHandler = (
name: string, m: string, data: string, colors: string[]) => Commander
function dispatchJcommand(api: AppletObject, param: Element): void
val := param.getAttribute 'value'
unless val return
switch param.getAttribute 'name'
'background'
api.setGraphicsOptions 1, bgColor: `#${val}`
@ -48,39 +61,39 @@ function dispatchJcommand(api, param)
else
console.log `Unkown param ${param}`
function jToG(jCom: string): Cmdr
function jToG(jCom: string): Commander
[name, klass, method, data, ...colors] := jCom.split(';')
if klass in classHandler
return classHandler[klass] name, method, data, colors
console.log `Unknown entity class ${klass}`
return ''
command: '', callbacks: []
classHandler :=
point: (name: string, m: string, data: string, colors: string[]): Cmdr =>
classHandler: Record<string, ClassHandler> :=
point: (name, method, data, colors) =>
command .= ''
callbacks .= []
switch m
callbacks: GeogebraCallback[] .= []
switch method
/free|fixed/
command += `${name} = (${data})`
if m is 'fixed'
callbacks.push (api) => api.setFixed(name, true)
if method is 'fixed'
callbacks.push (api: AppletObject) => api.setFixed(name, true)
'perpendicular'
[center, direction] := data.split(',')
command += `${name} = Rotate(${direction}, 3*pi/2, ${center})`
return {command, callbacks}
line: (name: string, m: string, data: string, colors: string[]): Cmdr =>
line: (name, method, data, colors) =>
command .= ''
callbacks .= []
switch m
callbacks: GeogebraCallback[] .= []
switch method
'connect'
command += `${name} = Segment(${data})`
return {command, callbacks}
circle: (name: string, m: string, data: string, colors: string[]): Cmdr =>
circle: (name, method, data, colors) =>
command .= ''
callbacks .= []
switch m
callbacks: GeogebraCallback[] .= []
switch method
'radius'
[center, point] := data.split(',')
command += `${name} = Circle(${center}, ${point})`

View file

@ -4,17 +4,20 @@ X3D from https://create3000.github.io/code/x_ite/latest/x_ite.mjs
certainlyHandled := '.x3d .gltf .glb .obj .stl .ply'.split ' '
canvas := X3D.createBrowser()
browser := X3D.getBrowser canvas
browser.setBrowserOption 'StraightenHorizon', false
site := $('a[href^="http"]')
url := site.attr 'href'
url := site.attr('href') ?? ''
if certainlyHandled.some((ext) => url.includes ext)
canvas.setAttribute 'src', site.attr 'href'
canvas.setAttribute 'src', url
else if url.includes '.wrl'
// Need to obtain the text and check what level it is
response := await fetch url
text .= await response.text()
if /#\s*VRML\s*V?1./i.test(text)
text = convert(text)
browser := X3D.getBrowser canvas
scene := await browser.createX3DFromString text
browser.replaceWorld(scene)
site.after(canvas)