Add js web stuff to landing page + documentation
This commit is contained in:
115
go/jsruntime/runtime/solid-js/h/dist/h.cjs
vendored
Normal file
115
go/jsruntime/runtime/solid-js/h/dist/h.cjs
vendored
Normal file
@@ -0,0 +1,115 @@
|
||||
'use strict';
|
||||
|
||||
var web = require('solid-js/web');
|
||||
|
||||
const $ELEMENT = Symbol("hyper-element");
|
||||
function createHyperScript(r) {
|
||||
function h() {
|
||||
let args = [].slice.call(arguments),
|
||||
e,
|
||||
classes = [],
|
||||
multiExpression = false;
|
||||
while (Array.isArray(args[0])) args = args[0];
|
||||
if (args[0][$ELEMENT]) args.unshift(h.Fragment);
|
||||
typeof args[0] === "string" && detectMultiExpression(args);
|
||||
const ret = () => {
|
||||
while (args.length) item(args.shift());
|
||||
if (e instanceof Element && classes.length) e.classList.add(...classes);
|
||||
return e;
|
||||
};
|
||||
ret[$ELEMENT] = true;
|
||||
return ret;
|
||||
function item(l) {
|
||||
const type = typeof l;
|
||||
if (l == null) ;else if ("string" === type) {
|
||||
if (!e) parseClass(l);else e.appendChild(document.createTextNode(l));
|
||||
} else if ("number" === type || "boolean" === type || "bigint" === type || "symbol" === type || l instanceof Date || l instanceof RegExp) {
|
||||
e.appendChild(document.createTextNode(l.toString()));
|
||||
} else if (Array.isArray(l)) {
|
||||
for (let i = 0; i < l.length; i++) item(l[i]);
|
||||
} else if (l instanceof Element) {
|
||||
r.insert(e, l, multiExpression ? null : undefined);
|
||||
} else if ("object" === type) {
|
||||
let dynamic = false;
|
||||
const d = Object.getOwnPropertyDescriptors(l);
|
||||
for (const k in d) {
|
||||
if (k === "class" && classes.length !== 0) {
|
||||
const fixedClasses = classes.join(" "),
|
||||
value = typeof d["class"].value === "function" ? () => fixedClasses + " " + d["class"].value() : fixedClasses + " " + l["class"];
|
||||
Object.defineProperty(l, "class", {
|
||||
...d[k],
|
||||
value
|
||||
});
|
||||
classes = [];
|
||||
}
|
||||
if (k !== "ref" && k.slice(0, 2) !== "on" && typeof d[k].value === "function") {
|
||||
r.dynamicProperty(l, k);
|
||||
dynamic = true;
|
||||
} else if (d[k].get) dynamic = true;
|
||||
}
|
||||
dynamic ? r.spread(e, l, e instanceof SVGElement, !!args.length) : r.assign(e, l, e instanceof SVGElement, !!args.length);
|
||||
} else if ("function" === type) {
|
||||
if (!e) {
|
||||
let props,
|
||||
next = args[0];
|
||||
if (next == null || typeof next === "object" && !Array.isArray(next) && !(next instanceof Element)) props = args.shift();
|
||||
props || (props = {});
|
||||
if (args.length) {
|
||||
props.children = args.length > 1 ? args : args[0];
|
||||
}
|
||||
const d = Object.getOwnPropertyDescriptors(props);
|
||||
for (const k in d) {
|
||||
if (Array.isArray(d[k].value)) {
|
||||
const list = d[k].value;
|
||||
props[k] = () => {
|
||||
for (let i = 0; i < list.length; i++) {
|
||||
while (list[i][$ELEMENT]) list[i] = list[i]();
|
||||
}
|
||||
return list;
|
||||
};
|
||||
r.dynamicProperty(props, k);
|
||||
} else if (typeof d[k].value === "function" && !d[k].value.length) r.dynamicProperty(props, k);
|
||||
}
|
||||
e = r.createComponent(l, props);
|
||||
args = [];
|
||||
} else {
|
||||
while (l[$ELEMENT]) l = l();
|
||||
r.insert(e, l, multiExpression ? null : undefined);
|
||||
}
|
||||
}
|
||||
}
|
||||
function parseClass(string) {
|
||||
const m = string.split(/([\.#]?[^\s#.]+)/);
|
||||
if (/^\.|#/.test(m[1])) e = document.createElement("div");
|
||||
for (let i = 0; i < m.length; i++) {
|
||||
const v = m[i],
|
||||
s = v.substring(1, v.length);
|
||||
if (!v) continue;
|
||||
if (!e) e = r.SVGElements.has(v) ? document.createElementNS("http://www.w3.org/2000/svg", v) : document.createElement(v);else if (v[0] === ".") classes.push(s);else if (v[0] === "#") e.setAttribute("id", s);
|
||||
}
|
||||
}
|
||||
function detectMultiExpression(list) {
|
||||
for (let i = 1; i < list.length; i++) {
|
||||
if (typeof list[i] === "function") {
|
||||
multiExpression = true;
|
||||
return;
|
||||
} else if (Array.isArray(list[i])) {
|
||||
detectMultiExpression(list[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
h.Fragment = props => props.children;
|
||||
return h;
|
||||
}
|
||||
|
||||
const h = createHyperScript({
|
||||
spread: web.spread,
|
||||
assign: web.assign,
|
||||
insert: web.insert,
|
||||
createComponent: web.createComponent,
|
||||
dynamicProperty: web.dynamicProperty,
|
||||
SVGElements: web.SVGElements
|
||||
});
|
||||
|
||||
module.exports = h;
|
||||
113
go/jsruntime/runtime/solid-js/h/dist/h.js
vendored
Normal file
113
go/jsruntime/runtime/solid-js/h/dist/h.js
vendored
Normal file
@@ -0,0 +1,113 @@
|
||||
import { SVGElements, dynamicProperty, createComponent, insert, assign, spread } from 'solid-js/web';
|
||||
|
||||
const $ELEMENT = Symbol("hyper-element");
|
||||
function createHyperScript(r) {
|
||||
function h() {
|
||||
let args = [].slice.call(arguments),
|
||||
e,
|
||||
classes = [],
|
||||
multiExpression = false;
|
||||
while (Array.isArray(args[0])) args = args[0];
|
||||
if (args[0][$ELEMENT]) args.unshift(h.Fragment);
|
||||
typeof args[0] === "string" && detectMultiExpression(args);
|
||||
const ret = () => {
|
||||
while (args.length) item(args.shift());
|
||||
if (e instanceof Element && classes.length) e.classList.add(...classes);
|
||||
return e;
|
||||
};
|
||||
ret[$ELEMENT] = true;
|
||||
return ret;
|
||||
function item(l) {
|
||||
const type = typeof l;
|
||||
if (l == null) ;else if ("string" === type) {
|
||||
if (!e) parseClass(l);else e.appendChild(document.createTextNode(l));
|
||||
} else if ("number" === type || "boolean" === type || "bigint" === type || "symbol" === type || l instanceof Date || l instanceof RegExp) {
|
||||
e.appendChild(document.createTextNode(l.toString()));
|
||||
} else if (Array.isArray(l)) {
|
||||
for (let i = 0; i < l.length; i++) item(l[i]);
|
||||
} else if (l instanceof Element) {
|
||||
r.insert(e, l, multiExpression ? null : undefined);
|
||||
} else if ("object" === type) {
|
||||
let dynamic = false;
|
||||
const d = Object.getOwnPropertyDescriptors(l);
|
||||
for (const k in d) {
|
||||
if (k === "class" && classes.length !== 0) {
|
||||
const fixedClasses = classes.join(" "),
|
||||
value = typeof d["class"].value === "function" ? () => fixedClasses + " " + d["class"].value() : fixedClasses + " " + l["class"];
|
||||
Object.defineProperty(l, "class", {
|
||||
...d[k],
|
||||
value
|
||||
});
|
||||
classes = [];
|
||||
}
|
||||
if (k !== "ref" && k.slice(0, 2) !== "on" && typeof d[k].value === "function") {
|
||||
r.dynamicProperty(l, k);
|
||||
dynamic = true;
|
||||
} else if (d[k].get) dynamic = true;
|
||||
}
|
||||
dynamic ? r.spread(e, l, e instanceof SVGElement, !!args.length) : r.assign(e, l, e instanceof SVGElement, !!args.length);
|
||||
} else if ("function" === type) {
|
||||
if (!e) {
|
||||
let props,
|
||||
next = args[0];
|
||||
if (next == null || typeof next === "object" && !Array.isArray(next) && !(next instanceof Element)) props = args.shift();
|
||||
props || (props = {});
|
||||
if (args.length) {
|
||||
props.children = args.length > 1 ? args : args[0];
|
||||
}
|
||||
const d = Object.getOwnPropertyDescriptors(props);
|
||||
for (const k in d) {
|
||||
if (Array.isArray(d[k].value)) {
|
||||
const list = d[k].value;
|
||||
props[k] = () => {
|
||||
for (let i = 0; i < list.length; i++) {
|
||||
while (list[i][$ELEMENT]) list[i] = list[i]();
|
||||
}
|
||||
return list;
|
||||
};
|
||||
r.dynamicProperty(props, k);
|
||||
} else if (typeof d[k].value === "function" && !d[k].value.length) r.dynamicProperty(props, k);
|
||||
}
|
||||
e = r.createComponent(l, props);
|
||||
args = [];
|
||||
} else {
|
||||
while (l[$ELEMENT]) l = l();
|
||||
r.insert(e, l, multiExpression ? null : undefined);
|
||||
}
|
||||
}
|
||||
}
|
||||
function parseClass(string) {
|
||||
const m = string.split(/([\.#]?[^\s#.]+)/);
|
||||
if (/^\.|#/.test(m[1])) e = document.createElement("div");
|
||||
for (let i = 0; i < m.length; i++) {
|
||||
const v = m[i],
|
||||
s = v.substring(1, v.length);
|
||||
if (!v) continue;
|
||||
if (!e) e = r.SVGElements.has(v) ? document.createElementNS("http://www.w3.org/2000/svg", v) : document.createElement(v);else if (v[0] === ".") classes.push(s);else if (v[0] === "#") e.setAttribute("id", s);
|
||||
}
|
||||
}
|
||||
function detectMultiExpression(list) {
|
||||
for (let i = 1; i < list.length; i++) {
|
||||
if (typeof list[i] === "function") {
|
||||
multiExpression = true;
|
||||
return;
|
||||
} else if (Array.isArray(list[i])) {
|
||||
detectMultiExpression(list[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
h.Fragment = props => props.children;
|
||||
return h;
|
||||
}
|
||||
|
||||
const h = createHyperScript({
|
||||
spread,
|
||||
assign,
|
||||
insert,
|
||||
createComponent,
|
||||
dynamicProperty,
|
||||
SVGElements
|
||||
});
|
||||
|
||||
export { h as default };
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"name": "solid-js/h/jsx-dev-runtime",
|
||||
"main": "../jsx-runtime/dist/jsx.cjs",
|
||||
"module": "../jsx-runtime/dist/jsx.js",
|
||||
"types": "../jsx-runtime/types/index.d.ts",
|
||||
"type": "module",
|
||||
"sideEffects": false
|
||||
}
|
||||
15
go/jsruntime/runtime/solid-js/h/jsx-runtime/dist/jsx.cjs
vendored
Normal file
15
go/jsruntime/runtime/solid-js/h/jsx-runtime/dist/jsx.cjs
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
'use strict';
|
||||
|
||||
var h = require('solid-js/h');
|
||||
|
||||
function Fragment(props) {
|
||||
return props.children;
|
||||
}
|
||||
function jsx(type, props) {
|
||||
return h(type, props);
|
||||
}
|
||||
|
||||
exports.Fragment = Fragment;
|
||||
exports.jsx = jsx;
|
||||
exports.jsxDEV = jsx;
|
||||
exports.jsxs = jsx;
|
||||
10
go/jsruntime/runtime/solid-js/h/jsx-runtime/dist/jsx.js
vendored
Normal file
10
go/jsruntime/runtime/solid-js/h/jsx-runtime/dist/jsx.js
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
import h from 'solid-js/h';
|
||||
|
||||
function Fragment(props) {
|
||||
return props.children;
|
||||
}
|
||||
function jsx(type, props) {
|
||||
return h(type, props);
|
||||
}
|
||||
|
||||
export { Fragment, jsx, jsx as jsxDEV, jsx as jsxs };
|
||||
8
go/jsruntime/runtime/solid-js/h/jsx-runtime/package.json
Normal file
8
go/jsruntime/runtime/solid-js/h/jsx-runtime/package.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"name": "solid-js/h/jsx-runtime",
|
||||
"main": "./dist/jsx.cjs",
|
||||
"module": "./dist/jsx.js",
|
||||
"types": "./types/index.d.ts",
|
||||
"type": "module",
|
||||
"sideEffects": false
|
||||
}
|
||||
11
go/jsruntime/runtime/solid-js/h/jsx-runtime/types/index.d.ts
vendored
Normal file
11
go/jsruntime/runtime/solid-js/h/jsx-runtime/types/index.d.ts
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
export type { JSX } from "./jsx.d.ts";
|
||||
import type { JSX } from "./jsx.d.ts";
|
||||
declare function Fragment(props: {
|
||||
children: JSX.Element;
|
||||
}): JSX.Element;
|
||||
declare function jsx(type: any, props: any): () => (Node & {
|
||||
[key: string]: any;
|
||||
}) | (Node & {
|
||||
[key: string]: any;
|
||||
})[];
|
||||
export { jsx, jsx as jsxs, jsx as jsxDEV, Fragment };
|
||||
4241
go/jsruntime/runtime/solid-js/h/jsx-runtime/types/jsx.d.ts
vendored
Normal file
4241
go/jsruntime/runtime/solid-js/h/jsx-runtime/types/jsx.d.ts
vendored
Normal file
File diff suppressed because it is too large
Load Diff
8
go/jsruntime/runtime/solid-js/h/package.json
Normal file
8
go/jsruntime/runtime/solid-js/h/package.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"name": "solid-js/h",
|
||||
"main": "./dist/h.cjs",
|
||||
"module": "./dist/h.js",
|
||||
"types": "./types/index.d.ts",
|
||||
"type": "module",
|
||||
"sideEffects": false
|
||||
}
|
||||
20
go/jsruntime/runtime/solid-js/h/types/hyperscript.d.ts
vendored
Normal file
20
go/jsruntime/runtime/solid-js/h/types/hyperscript.d.ts
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
type MountableElement = Element | Document | ShadowRoot | DocumentFragment | Node;
|
||||
interface Runtime {
|
||||
insert(parent: MountableElement, accessor: any, marker?: Node | null, init?: any): any;
|
||||
spread(node: Element, accessor: any, isSVG?: Boolean, skipChildren?: Boolean): void;
|
||||
assign(node: Element, props: any, isSVG?: Boolean, skipChildren?: Boolean): void;
|
||||
createComponent(Comp: (props: any) => any, props: any): any;
|
||||
dynamicProperty(props: any, key: string): any;
|
||||
SVGElements: Set<string>;
|
||||
}
|
||||
type ExpandableNode = Node & {
|
||||
[key: string]: any;
|
||||
};
|
||||
export type HyperScript = {
|
||||
(...args: any[]): () => ExpandableNode | ExpandableNode[];
|
||||
Fragment: (props: {
|
||||
children: (() => ExpandableNode) | (() => ExpandableNode)[];
|
||||
}) => ExpandableNode[];
|
||||
};
|
||||
export declare function createHyperScript(r: Runtime): HyperScript;
|
||||
export {};
|
||||
3
go/jsruntime/runtime/solid-js/h/types/index.d.ts
vendored
Normal file
3
go/jsruntime/runtime/solid-js/h/types/index.d.ts
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import type { HyperScript } from "./hyperscript.js";
|
||||
declare const h: HyperScript;
|
||||
export default h;
|
||||
Reference in New Issue
Block a user