Skip to content

Commit

Permalink
clean up web interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelmtimbo committed Feb 15, 2024
1 parent cfe1ee3 commit 9baffe6
Show file tree
Hide file tree
Showing 80 changed files with 301 additions and 519 deletions.
83 changes: 36 additions & 47 deletions src/API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,21 @@ import { Style } from './system/platform/Props'
import { Dict } from './types/Dict'
import { Unlisten } from './types/Unlisten'
import {
IBluetoothDevice,
IBluetoothDeviceOpt,
} from './types/global/IBluetoothDevice'
import { IChannel, IChannelOpt } from './types/global/IChannel'
import { IDeviceInfo } from './types/global/IDeviceInfo'
import { IDisplayMediaOpt } from './types/global/IDisplayMedia'
import { IDownloadDataOpt as IDownloadTextOpt } from './types/global/IDownloadData'
import { IDownloadURLOpt } from './types/global/IDownloadURL'
import { IGeoPosition } from './types/global/IGeoPosition'
import { IIntersectionObserverConstructor } from './types/global/IIntersectionObserver'
import { IMutationObserverConstructor } from './types/global/IMutationObserver'
import { IPositionObserverCostructor } from './types/global/IPositionObserver'
import { IResizeObserverConstructor } from './types/global/IResizeObserver'
BluetoothDevice,
BluetoothDeviceOpt,
} from './types/global/BluetoothDevice'
import { Channel, ChannelOpt } from './types/global/Channel'
import { DownloadDataOpt as IDownloadTextOpt } from './types/global/DownloadData'
import { DownloadURLOpt } from './types/global/DownloadURL'
import { PositionObserverCostructor } from './types/global/PositionObserver'
import {
ISpeechGrammarList,
ISpeechGrammarListOpt,
} from './types/global/ISpeechGrammarList'
SpeechGrammarList,
SpeechGrammarListOpt,
} from './types/global/SpeechGrammarList'
import {
ISpeechRecognition,
ISpeechRecognitionOpt,
} from './types/global/ISpeechRecognition'
import {
ISpeechSynthesis,
ISpeechSynthesisOpt,
} from './types/global/ISpeechSynthesis'
import {
ISpeechSynthesisUtterance,
ISpeechSynthesisUtteranceOpt,
} from './types/global/ISpeechSynthesisUtterance'
import { IUserMediaOpt } from './types/global/IUserMedia'
import { IWakeLock, IWakeLockOpt } from './types/global/IWakeLock'
SpeechRecognition,
SpeechRecognitionOpt,
} from './types/global/SpeechRecognition'
import { J } from './types/interface/J'

export type ImageCapture = any
Expand Down Expand Up @@ -84,7 +68,7 @@ export type API = {
listen: (port: number, handler: BasicHTTPHandler) => Unlisten
EventSource: typeof EventSource
}
channel: { local: (opt: IChannelOpt) => IChannel }
channel: { local: (opt: ChannelOpt) => Channel }
alert: {
alert: (message: string) => void
prompt: (message: string) => string
Expand Down Expand Up @@ -130,28 +114,28 @@ export type API = {
): LayoutNode[]
}
speech: {
SpeechGrammarList: (opt: ISpeechGrammarListOpt) => ISpeechGrammarList
SpeechRecognition: (opt: ISpeechRecognitionOpt) => ISpeechRecognition
SpeechSynthesis: (opt: ISpeechSynthesis) => ISpeechSynthesisOpt
SpeechSynthesisUtterance: (
opt: ISpeechSynthesisUtteranceOpt
) => ISpeechSynthesisUtterance
SpeechGrammarList: (opt: SpeechGrammarListOpt) => SpeechGrammarList
SpeechRecognition: (opt: SpeechRecognitionOpt) => SpeechRecognition
SpeechSynthesis: SpeechSynthesis
SpeechSynthesisUtterance: { new (text?: string): SpeechSynthesisUtterance }
}
file: {
isSaveFilePickerSupported: () => boolean
isOpenFilePickerSupported: () => boolean
showSaveFilePicker: (opt: IFilePickerOpt) => Promise<FileSystemFileHandle>
showOpenFilePicker: (opt: IFilePickerOpt) => Promise<FileSystemFileHandle[]>
fallbackShowOpenFilePicker: (opt: IFilePickerOpt) => Promise<File[]>
downloadURL: (opt: IDownloadURLOpt) => Promise<void>
downloadURL: (opt: DownloadURLOpt) => Promise<void>
downloadText: (opt: IDownloadTextOpt) => Promise<void>
}
screen: {
devicePixelRatio?: number
requestWakeLock: (type: IWakeLockOpt) => Promise<IWakeLock>
wakeLock: {
request: (type?: 'screen') => Promise<WakeLockSentinel>
}
}
bluetooth: {
requestDevice: (type: IBluetoothDeviceOpt) => Promise<IBluetoothDevice>
requestDevice: (type: BluetoothDeviceOpt) => Promise<BluetoothDevice>
}
device: {
vibrate: (opt: VibratePattern) => Promise<void>
Expand All @@ -162,7 +146,7 @@ export type API = {
writeText: (text: string) => Promise<void>
}
geolocation: {
getCurrentPosition: () => Promise<IGeoPosition>
getCurrentPosition: () => Promise<GeolocationCoordinates>
}
location: {
toString: () => Promise<string>
Expand All @@ -172,9 +156,9 @@ export type API = {
replaceState: (data: any, title: string, url: string) => void
}
media: {
getUserMedia: (opt: IUserMediaOpt) => Promise<MediaStream>
getDisplayMedia: (opt: IDisplayMediaOpt) => Promise<MediaStream>
enumerateDevices: () => Promise<IDeviceInfo[]>
getUserMedia: (opt: MediaStreamConstraints) => Promise<MediaStream>
getDisplayMedia: (opt: DisplayMediaStreamOptions) => Promise<MediaStream>
enumerateDevices: () => Promise<MediaDeviceInfo[]>
image: {
createImageBitmap: (
image: ImageBitmapSource,
Expand Down Expand Up @@ -218,10 +202,15 @@ export type API = {
getSelection(): Selection
createRange(): Range
exitPictureInPicture(): Promise<void>
MutationObserver: IMutationObserverConstructor
PositionObserver: IPositionObserverCostructor
ResizeObserver: IResizeObserverConstructor
IntersectionObserver: IIntersectionObserverConstructor
MutationObserver: { new (callback: MutationCallback): MutationObserver }
PositionObserver: PositionObserverCostructor
ResizeObserver: { new (callback: ResizeObserverCallback): ResizeObserver }
IntersectionObserver: {
new (
callback: IntersectionObserverCallback,
options?: IntersectionObserverInit
): IntersectionObserver
}
}
querystring: {
stringify: (obj: Dict<any>) => string
Expand Down
8 changes: 4 additions & 4 deletions src/RemoteClient.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { EXEC, INIT } from './constant/STRING'
import { RemotePort } from './RemotePort'
import { BundleSpec } from './types/BundleSpec'
import { IPort } from './types/global/IPort'
import { Port } from './types/global/Port'

export class RemoteClient {
private _remote_port: RemotePort
private _port: IPort
private _port: Port

constructor(port: IPort) {
constructor(port: Port) {
this._port = port

const _port: IPort = {
const _port: Port = {
send: (data) => {
const _data = this._exec_data(data)

Expand Down
8 changes: 4 additions & 4 deletions src/RemotePort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { CALL, REF, REF_EXEC, UNWATCH, WATCH } from './constant/STRING'
import { EventEmitter_, EventEmitter_EE } from './EventEmitter'
import { Callback } from './types/Callback'
import { Dict } from './types/Dict'
import { IPort } from './types/global/IPort'
import { Port } from './types/global/Port'
import { Unlisten } from './types/Unlisten'
import { randomIdNotInSet } from './util/id'

export type AnyEmitterEvents = EventEmitter_EE<Dict<any[]>> & Dict<any[]>

export class RemotePort {
private _port: IPort
private _port: Port

private _call_id: Set<string> = new Set<string>()
private _watch_id: Set<string> = new Set<string>()
Expand All @@ -22,7 +22,7 @@ export class RemotePort {

private _valid: boolean = true

constructor(port: IPort) {
constructor(port: Port) {
this._port = port

this._port.onmessage = (event) => {
Expand Down Expand Up @@ -124,7 +124,7 @@ export class RemotePort {

this._port.send(_data)

const port: IPort = {
const port: Port = {
send: (data) => {
const _data = { type: REF_EXEC, data: { id, data } }
this._port.send(_data)
Expand Down
14 changes: 7 additions & 7 deletions src/api/speech/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { EventEmitter_, EventEmitter_EE } from '../../EventEmitter'
import { APINotSupportedError } from '../../exception/APINotImplementedError'
import { System } from '../../system'
import { ISpeechGrammarList } from '../../types/global/ISpeechGrammarList'
import { SpeechGrammarList } from '../../types/global/SpeechGrammarList'
import {
ISpeechRecognition,
ISpeechRecognitionOpt,
} from '../../types/global/ISpeechRecognition'
SpeechRecognition,
SpeechRecognitionOpt,
} from '../../types/global/SpeechRecognition'
import { Unlisten } from '../../types/Unlisten'
import { callAll } from '../../util/call/callAll'

Expand All @@ -25,7 +25,7 @@ export const JSGFStrFrom = (tokens: string[]): string => {
export const grammarsFrom = (
system: System,
tokens: string[]
): ISpeechGrammarList => {
): SpeechGrammarList => {
const {
api: {
speech: { SpeechGrammarList },
Expand Down Expand Up @@ -55,11 +55,11 @@ export type SpeechRecorderEvents = EventEmitter_EE<SpeechRecorder_EE> &
SpeechRecorder_EE

export class SpeechRecorder extends EventEmitter_<SpeechRecorderEvents> {
private _recognition: ISpeechRecognition
private _recognition: SpeechRecognition

private _unlisten: Unlisten

constructor(__system: System, opt: ISpeechRecognitionOpt) {
constructor(__system: System, opt: SpeechRecognitionOpt) {
super()

const {
Expand Down
11 changes: 5 additions & 6 deletions src/boot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ import { BundleSpec } from '../types/BundleSpec'
import { Dict } from '../types/Dict'
import { GraphBundle } from '../types/GraphClass'
import { Unlisten } from '../types/Unlisten'
import { IGamepad } from '../types/global/IGamepad'
import { IKeyboard } from '../types/global/IKeyboard'
import { IPointer } from '../types/global/IPointer'
import { KeyboardState } from '../types/global/KeyboardState'
import { PointerState } from '../types/global/PointerState'
import { randomIdNotIn } from '../util/id'

export function boot(
Expand All @@ -32,12 +31,12 @@ export function boot(
flags = {},
} = opt

const keyboard: IKeyboard = {
const keyboard: KeyboardState = {
pressed: [],
repeat: false,
}
const gamepads: IGamepad[] = []
const pointers: Dict<IPointer> = {}
const gamepads: Gamepad[] = []
const pointers: Dict<PointerState> = {}

const customEvent = new Set<string>()
const context = []
Expand Down
14 changes: 7 additions & 7 deletions src/client/PositionObserver.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { System } from '../system'
import {
IPositionObserver,
IPositionCallback,
PositionObserver,
IPositionObserverEntry,
} from '../types/global/IPositionObserver'
PositionObserverCallback,
} from '../types/global/PositionObserver'
import { Unlisten } from '../types/Unlisten'
import { callAll } from '../util/call/callAll'
import { animateThrottle } from './animateThrottle'
Expand All @@ -16,14 +16,14 @@ import {
subtractVector,
} from './util/geometry'

export class PositionObserver implements IPositionObserver {
export class PositionObserver_ implements PositionObserver {
private _system: System

private _callback: IPositionCallback
private _callback: PositionObserverCallback
private _unlisten: () => void
private _abort: () => void

constructor(system: System, callback: IPositionCallback) {
constructor(system: System, callback: PositionObserverCallback) {
this._system = system
this._callback = callback
}
Expand Down Expand Up @@ -428,7 +428,7 @@ export class PositionObserver implements IPositionObserver {
update_local()
}

const parentPostionObserver = new PositionObserver(
const parentPostionObserver = new PositionObserver_(
this._system,
parentPositionCallback
)
Expand Down
4 changes: 2 additions & 2 deletions src/client/RemoteAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { _ErrorEvent } from '../events/ErrorEvent'
import { MethodNotImplementedError } from '../exception/MethodNotImplementedError'
import { Callback } from '../types/Callback'
import { Dict } from '../types/Dict'
import { IPort } from '../types/global/IPort'
import { Port } from '../types/global/Port'
import { Unlisten } from '../types/Unlisten'

type RemoteAPICall = (data: any, callback: Callback<any>) => void
Expand Down Expand Up @@ -84,7 +84,7 @@ window.onmessage = (event: MessageEvent) => {

/// process A

const channel: IPort = {
const channel: Port = {
send: function (message: any) {
throw new MethodNotImplementedError()
},
Expand Down
8 changes: 7 additions & 1 deletion src/client/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2498,7 +2498,13 @@ export class Component<
const _at = this.$mountParentRoot.indexOf(component)
const slotName = this.$parentRootSlotName[at]
this.postRemoveParentRootAt(component, slotName, at, _at)
this.domRemoveParentRootAt(component, slotName, at, _at, slotParent)
this.domRemoveParentRootAt(
component,
slotName,
at,
_at,
slotParent ?? this.$slotParent
)
this.memRemoveParentRootAt(component, slotName, at, _at)
}

Expand Down
4 changes: 2 additions & 2 deletions src/client/context.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { System } from '../system'
import { Dict } from '../types/Dict'
import { IPositionObserver } from '../types/global/IPositionObserver'
import { PositionObserver } from '../types/global/PositionObserver'
import { Unlisten } from '../types/Unlisten'
import { last, remove } from '../util/array'
import { Component } from './component'
Expand Down Expand Up @@ -30,7 +30,7 @@ export interface Context extends Listenable {
$color: string
$children: Component[]
$resizeObserver: ResizeObserver
$positionObserver: IPositionObserver
$positionObserver: PositionObserver
}

export interface Ref extends Dict<any[]> {}
Expand Down
19 changes: 10 additions & 9 deletions src/client/noop/MutationObserver.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { IMutationObserver } from '../../types/global/IMutationObserver'
import { IPositionCallback } from '../../types/global/IPositionObserver'

export class NoopMutationObserver implements IMutationObserver {
constructor(callback: IPositionCallback) {}

public observe(element: HTMLElement): void {}

disconnect() {}
export class NoopMutationObserver implements MutationObserver {
disconnect(): void {
throw new Error('Method not implemented.')
}
observe(target: Node, options?: MutationObserverInit): void {
throw new Error('Method not implemented.')
}
takeRecords(): MutationRecord[] {
throw new Error('Method not implemented.')
}
}
19 changes: 11 additions & 8 deletions src/client/noop/ResizeObserver.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { IPositionCallback } from '../../types/global/IPositionObserver'
import { IResizeObserver } from '../../types/global/IResizeObserver'
export class NoopResizeObserver implements ResizeObserver {
constructor(callback: ResizeObserverCallback) {}

export class NoopResizeObserver implements IResizeObserver {
constructor(callback: IPositionCallback) {}

public observe(element: HTMLElement): void {}

disconnect() {}
disconnect(): void {
//
}
observe(target: Element, options?: ResizeObserverOptions): void {
//
}
unobserve(target: Element): void {
//
}
}
Loading

0 comments on commit 9baffe6

Please sign in to comment.