Skip to content

Commit 96599c6

Browse files
authored
feat: Add more document methods for bindings/dom.ts (#2336)
1 parent 4b73edb commit 96599c6

File tree

1 file changed

+129
-0
lines changed

1 file changed

+129
-0
lines changed

Diff for: std/assembly/bindings/dom.ts

+129
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,23 @@ export declare namespace String {
115115
export function fromCodePoints(codepoints: i32[]): externref;
116116
}
117117

118+
export declare namespace Object {
119+
@external("env", "Object.is")
120+
export function is(a: externref, b: externref): bool;
121+
@external("env", "Object.hasOwn")
122+
export function hasOwn(target: externref, propertyKey: string): bool;
123+
@external("env", "Object.assign")
124+
export function assign(target: externref, source: externref): externref;
125+
@external("env", "Object.keys")
126+
export function keys(target: externref): externref;
127+
@external("env", "Object.values")
128+
export function values(target: externref): externref;
129+
@external("env", "Object.entries")
130+
export function entries(target: externref): externref;
131+
@external("env", "Object.getOwnPropertyNames")
132+
export function getOwnPropertyNames(target: externref): externref;
133+
}
134+
118135
export declare namespace Date {
119136
@external("env", "Date.now")
120137
export function now(): f64;
@@ -142,8 +159,120 @@ export declare namespace console {
142159
}
143160

144161
export declare namespace document {
162+
/** Returns document's encoding. */
163+
@external("env", "document.characterSet")
164+
export const characterSet: string;
165+
/** Returns a value that indicates whether standards-compliant mode is switched on for the object. */
166+
@external("env", "document.compatMode")
167+
export const compatMode: string;
168+
/** Returns document's content type. */
169+
@external("env", "document.contentType")
170+
export const contentType: string;
171+
/** Returns a reference to the root node of the document. */
172+
@external("env", "document.documentElement")
173+
export const documentElement: externref;
174+
/** Returns document's URL. */
175+
@external("env", "document.documentURI")
176+
export const documentURI: string;
177+
/** Returns the URL of the location that referred the user to the current page. */
178+
@external("env", "document.referrer")
179+
export const referrer: string;
180+
/** Returns true if document has the ability of fullscreen mode, or false otherwise. */
181+
@external("env", "document.pictureInPictureEnabled")
182+
export const fullscreenEnabled: bool;
183+
/** Returns true if document has the ability of picture-in-picture mode, or false otherwise. */
184+
@external("env", "document.pictureInPictureEnabled")
185+
export const pictureInPictureEnabled: bool;
186+
187+
/** Returns the number of child elements. */
188+
@external("env", "document.childElementCount")
189+
export const childElementCount: i32;
190+
/** Returns the child elements. */
191+
@external("env", "document.children")
192+
export const children: externref;
193+
/** Returns the first child that is an element, and null otherwise. */
194+
@external("env", "document.firstElementChild")
195+
export const firstElementChild: externref;
196+
/** Returns the last child that is an element, and null otherwise. */
197+
@external("env", "document.lastElementChild")
198+
export const lastElementChild: externref;
199+
200+
/**
201+
* Returns the HTTP cookies that apply to the Document. If there are no cookies or cookies can't be applied
202+
* to this resource, the empty string will be returned.
203+
*
204+
* Can be set, to add a new cookie to the element's set of HTTP cookies.
205+
*
206+
* If the contents are sandboxed into a unique origin (e.g. in an iframe with the sandbox attribute),
207+
* a "SecurityError" DOMException will be thrown on getting and setting.
208+
*/
209+
@external("env", "document.cookie")
210+
export let cookie: string;
211+
/** Represents the <body> or <frameset> node of the current document, or null if no such element exists. */
212+
@external("env", "document.body")
213+
export let body: externref;
214+
/** Sets or gets the security domain of the document. */
215+
@external("env", "document.domain")
216+
export let domain: string;
217+
/** Sets or gets the title of the document. */
218+
@external("env", "document.title")
219+
export let title: string;
220+
/** Sets or gets information about the current Location. */
221+
@external("env", "document.location")
222+
export let location: externref;
223+
/** Sets or gets the URL for the current document. */
224+
@external("env", "document.URL")
225+
export let URL: string;
226+
227+
/**
228+
* Creates an instance of the element for the specified tag.
229+
* @param tagName The name of an element.
230+
*/
231+
@external("env", "document.createElement")
232+
export function createElement(tagName: string /* , options?: ElementCreationOptions */): externref;
233+
/**
234+
* Returns a reference to the first HTMLElement object with the specified value of the ID attribute.
235+
* @param id String that specifies the ID value.
236+
*/
145237
@external("env", "document.getElementById")
146238
export function getElementById(id: string): externref;
239+
/**
240+
* Returns a HTMLCollection of the elements in the object on which the method was invoked that have all the classes
241+
* given by classNames. The classNames argument is interpreted as a space-separated list of classes.
242+
* @param classNames Gets a collection of objects based on the value of the CLASS attribute.
243+
*/
244+
@external("env", "document.getElementsByClassName")
245+
export function getElementsByClassName(classNames: string): externref;
246+
/**
247+
* Gets a collection of HTMLElement objects based on the value of the NAME or ID attribute.
248+
* @param elementName Gets a collection of objects based on the value of the NAME or ID attribute.
249+
*/
250+
@external("env", "document.getElementsByName")
251+
export function getElementsByName(elementName: string): externref;
252+
/** Gets a value indicating whether the object currently has focus. */
253+
@external("env", "document.hasFocus")
254+
export function hasFocus(): bool;
255+
/** Inserts nodes after the last child of node, while replacing strings in nodes with equivalent Text nodes. */
256+
@external("env", "document.append")
257+
export function append(node: externref): void;
258+
/** Inserts nodes before the first child of node, while replacing strings in nodes with equivalent Text nodes. */
259+
@external("env", "document.prepend")
260+
export function prepend(node: externref): void;
261+
/** Replace all children of node with nodes, while replacing strings in nodes with equivalent Text nodes. */
262+
@external("env", "document.replaceChildren")
263+
export function replaceChildren(node: externref): void;
264+
/**
265+
* Writes one or more HTML expressions to a document in the specified window.
266+
* @param content Specifies the text and HTML tags to write.
267+
*/
268+
@external("env", "document.write")
269+
export function write(content: string): void;
270+
/**
271+
* Writes one or more HTML expressions, followed by a carriage return, to a document in the specified window.
272+
* @param content Specifies the text and HTML tags to write.
273+
*/
274+
@external("env", "document.writeln")
275+
export function writeln(content: string): void;
147276
}
148277

149278
export declare namespace performance {

0 commit comments

Comments
 (0)