forked from gbishop/OS-DPI
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'gbishop:main' into main
- Loading branch information
Showing
60 changed files
with
1,340 additions
and
538 deletions.
There are no files selected for viewing
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
Binary file not shown.
Binary file not shown.
Binary file not shown.
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,2 @@ | ||
thinking/* | ||
**/tracky-mouse/** |
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,84 @@ | ||
import { html as _html } from "uhtml"; | ||
|
||
export { render } from "uhtml"; | ||
|
||
const typeMap = new WeakMap(); | ||
|
||
/** @param {TemplateStringsArray} strings | ||
* @param {any[]} args | ||
*/ | ||
export function html(strings, ...args) { | ||
let types = typeMap.get(strings); | ||
if (!types) { | ||
types = args.map((arg) => getTypeOf(arg)); | ||
typeMap.set(strings, types); | ||
} | ||
|
||
if (!strings[0].match(/\s*</)) { | ||
throw new Error(`html does not begin with < ${strings[0]}`); | ||
} | ||
|
||
args.forEach((arg, index) => { | ||
const string = strings[index]; | ||
if (!string.endsWith("=") && !string.endsWith('="')) { | ||
// must be a content node | ||
if (arg === null) { | ||
throw new Error(`html arg after ${string} is null`); | ||
} | ||
if (arg === undefined) { | ||
throw new Error(`html arg after ${string} is undefined`); | ||
} | ||
const atype = getTypeOf(arg); | ||
if (atype != types[index]) { | ||
const t = types[index]; | ||
if ( | ||
!atype.startsWith("Array") || | ||
!t.startsWith("Array") || | ||
!(atype.endsWith("empty") || t.endsWith("empty")) | ||
) | ||
throw new Error( | ||
`type of arg after ${string} changed from ${types[index]} to ${atype}`, | ||
); | ||
} | ||
} else { | ||
// must be an attribute | ||
const atype = getTypeOf(arg); | ||
if ( | ||
atype != types[index] && | ||
atype != "undefined" && | ||
types[index] != "undefined" && | ||
atype != "null" && | ||
types[index] != "null" | ||
) { | ||
throw new Error( | ||
`attribute ${string} changed from ${types[index]} to ${atype}`, | ||
); | ||
} | ||
} | ||
}); | ||
return _html(strings, ...args); | ||
} | ||
|
||
/** @param {any} arg | ||
* @returns {string} */ | ||
function getTypeOf(arg) { | ||
const t = typeof arg; | ||
if (t != "object") return t; | ||
if (arg == null) return "null"; | ||
|
||
if (Array.isArray(arg)) { | ||
if (arg.length) { | ||
const ts = arg.map((a) => getTypeOf(a)); | ||
if (!ts.every((t) => t == t[0])) { | ||
return `Array of ${ts[0]}`; | ||
} else { | ||
console.error("array", ts); | ||
throw new Error("Array elements of different types"); | ||
} | ||
} else return `Array empty`; | ||
} | ||
if (arg.constructor.name == "Hole") { | ||
return "Hole"; | ||
} | ||
return "object"; | ||
} |
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
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
Oops, something went wrong.