Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'task/450-typeerror-targetownerdocumentcreaterange-is-no…
…t-a-function' of https://github.com/capricorn86/happy-dom into task/450-typeerror-targetownerdocumentcreaterange-is-not-a-function
- Loading branch information
Showing
44 changed files
with
16,753 additions
and
328 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import DOMException from '../exception/DOMException'; | ||
import DOMExceptionNameEnum from '../exception/DOMExceptionNameEnum'; | ||
|
||
const BASE64_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; | ||
|
||
/** | ||
* Base64 encoding and decoding. | ||
*/ | ||
export default class Base64 { | ||
/** | ||
* Creates a Base64-encoded ASCII string from a binary string (i.e., a string in which each character in the string is treated as a byte of binary data). | ||
* | ||
* @see https://developer.mozilla.org/en-US/docs/Web/API/btoa | ||
* @param data Binay data. | ||
* @returns Base64-encoded string. | ||
*/ | ||
public static btoa(data: unknown): string { | ||
const str = (<string>data).toString(); | ||
if (/[^\u0000-\u00ff]/.test(str)) { | ||
throw new DOMException( | ||
"Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range.", | ||
DOMExceptionNameEnum.invalidCharacterError | ||
); | ||
} | ||
|
||
let t = ''; | ||
let p = -6; | ||
let a = 0; | ||
let i = 0; | ||
let v = 0; | ||
let c; | ||
while (i < str.length || p > -6) { | ||
if (p < 0) { | ||
if (i < str.length) { | ||
c = str.charCodeAt(i++); | ||
v += 8; | ||
} else { | ||
c = 0; | ||
} | ||
a = ((a & 255) << 8) | (c & 255); | ||
p += 8; | ||
} | ||
t += BASE64_CHARS.charAt(v > 0 ? (a >> p) & 63 : 64); | ||
p -= 6; | ||
v -= 6; | ||
} | ||
return t; | ||
} | ||
|
||
/** | ||
* Decodes a string of data which has been encoded using Base64 encoding. | ||
* | ||
* @see https://developer.mozilla.org/en-US/docs/Web/API/atob | ||
* @see https://infra.spec.whatwg.org/#forgiving-base64-encode. | ||
* @see Https://html.spec.whatwg.org/multipage/webappapis.html#btoa. | ||
* @param data Binay string. | ||
* @returns An ASCII string containing decoded data from encodedData. | ||
*/ | ||
public static atob(data: unknown): string { | ||
const str = (<string>data).toString(); | ||
|
||
if (/[^\u0000-\u00ff]/.test(str)) { | ||
throw new DOMException( | ||
"Failed to execute 'atob' on 'Window': The string to be decoded contains characters outside of the Latin1 range.", | ||
DOMExceptionNameEnum.invalidCharacterError | ||
); | ||
} | ||
|
||
if (/[^A-Za-z\d+/=]/.test(str) || str.length % 4 == 1) { | ||
throw new DOMException( | ||
"Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.", | ||
DOMExceptionNameEnum.invalidCharacterError | ||
); | ||
} | ||
|
||
let t = ''; | ||
let p = -8; | ||
let a = 0; | ||
let c; | ||
let d; | ||
for (let i = 0; i < str.length; i++) { | ||
if ((c = BASE64_CHARS.indexOf(str.charAt(i))) < 0) { | ||
continue; | ||
} | ||
a = (a << 6) | (c & 63); | ||
if ((p += 6) >= 0) { | ||
d = (a >> p) & 255; | ||
if (c !== 64) { | ||
t += String.fromCharCode(d); | ||
} | ||
a &= 63; | ||
p -= 8; | ||
} | ||
} | ||
return t; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/happy-dom/src/nodes/html-input-element/HTMLInputElement.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
packages/happy-dom/src/nodes/html-opt-group-element/HTMLOptGroupElement.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import HTMLElement from '../html-element/HTMLElement'; | ||
import IHTMLOptGroupElement from './IHTMLOptGroupElement'; | ||
|
||
/** | ||
* HTML Opt Group Element. | ||
* | ||
* Reference: | ||
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLOptGroupElement. | ||
*/ | ||
export default class HTMLOptGroupElement extends HTMLElement implements IHTMLOptGroupElement { | ||
/** | ||
* Returns label. | ||
* | ||
* @returns Label. | ||
*/ | ||
public get label(): string { | ||
return this.getAttributeNS(null, 'label') || ''; | ||
} | ||
|
||
/** | ||
* Sets label. | ||
* | ||
* @param label Label. | ||
*/ | ||
public set label(label: string) { | ||
if (!label) { | ||
this.removeAttributeNS(null, 'label'); | ||
} else { | ||
this.setAttributeNS(null, 'label', label); | ||
} | ||
} | ||
|
||
/** | ||
* Returns disabled. | ||
* | ||
* @returns Disabled. | ||
*/ | ||
public get disabled(): boolean { | ||
return this.getAttributeNS(null, 'disabled') !== null; | ||
} | ||
|
||
/** | ||
* Sets disabled. | ||
* | ||
* @param disabled Disabled. | ||
*/ | ||
public set disabled(disabled: boolean) { | ||
if (!disabled) { | ||
this.removeAttributeNS(null, 'disabled'); | ||
} else { | ||
this.setAttributeNS(null, 'disabled', ''); | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
packages/happy-dom/src/nodes/html-opt-group-element/IHTMLOptGroupElement.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import IHTMLElement from '../html-element/IHTMLElement'; | ||
|
||
/** | ||
* HTML Opt Group Element. | ||
* | ||
* Reference: | ||
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLOptGroupElement. | ||
*/ | ||
export default interface IHTMLOptGroupElement extends IHTMLElement { | ||
disabled: boolean; | ||
label: string; | ||
} |
Oops, something went wrong.