@silkui/core 0.1.8 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -2
- package/package.json +5 -1
- package/src/globals.d.ts +3 -0
- package/src/globals.js +38 -0
- package/src/index.d.ts +490 -14
- package/src/index.js +2804 -137
package/README.md
CHANGED
|
@@ -59,7 +59,9 @@ mount(createBox({ position: "absolute", inset: 0, display: "flex", alignItems: "
|
|
|
59
59
|
| --- | --- |
|
|
60
60
|
| `createBox(style?, ...children)` | A box with `style` as its base look. Strings among the children become text nodes |
|
|
61
61
|
| `createText(data?)` | A text node. It takes its look from its parent |
|
|
62
|
-
| `createInput(style?)` | An editable text field. `value`, `selectionStart`, `selectionEnd` and `
|
|
62
|
+
| `createInput(style?)` | An editable text field. `value`, `selectionStart`, `selectionEnd`, `selectionDirection`, `setSelectionRange`, `select` and `setRangeText` work as on an `<input>`, in UTF-16 string indices |
|
|
63
|
+
| `createRange()`, `new Range()`, `new StaticRange(init)` | DOM Standard ranges over the app's nodes. Live ranges follow insertions, removals and text edits (`insertData`, `splitText`, `normalize` and the rest of Text's methods) |
|
|
64
|
+
| `createDocumentFragment()` | Nodes held outside the tree, as `DocumentFragment`; `cloneContents` and `extractContents` return one |
|
|
63
65
|
| `createRichInput(style?)` | A text field with marks and inline atoms (see below) |
|
|
64
66
|
| `createImage(src, style?)` | An image, as an `<img>`: `src` is a `data:` URL, a file or an `http(s):` address. An SVG file draws as an inline `<svg>` |
|
|
65
67
|
| `createSvgElement(tag)` | `document.createElementNS` for SVG: an `Svg` root for `"svg"`, else an `SvgElement` (`path`, `g`, ...) to append inside one |
|
|
@@ -72,7 +74,19 @@ An `Svg` is one node whose markup its `SvgElement` and text children make, as an
|
|
|
72
74
|
`fill`, `width` and every other attribute are markup, and React's spellings (`strokeWidth`)
|
|
73
75
|
work too. Changes are drawn once, before the host applies the batch (`flushSvg()` draws them
|
|
74
76
|
now). Without a CSS size it takes the `<svg>`'s `width` and `height`, else a square of the
|
|
75
|
-
font size.
|
|
77
|
+
font size. Listeners on its elements hear pointer events on their shapes, with
|
|
78
|
+
`pointerover`, `pointerout`, `pointerenter` and `pointerleave` as the pointer moves between
|
|
79
|
+
them; `pointer-events`, `visibility`, `display` and clip paths decide hits as on the web.
|
|
80
|
+
`getBBox()`, `getTotalLength()` and `getPointAtLength()` measure elements from their markup.
|
|
81
|
+
|
|
82
|
+
Once an `Svg` has drawn, later changes go to the tree element by element, and only the shapes
|
|
83
|
+
whose geometry changed rasterize again: a script can animate it every frame. Listeners on its
|
|
84
|
+
elements make it live from its first draw. The tree draws
|
|
85
|
+
`g`, `path`, `rect`, `circle`, `ellipse`, `line`, `polyline`, `polygon`, `clipPath` and linear
|
|
86
|
+
and radial gradients this way; anything else (text, masks, filters, `use`...) puts the `Svg`
|
|
87
|
+
back to drawing its markup whole, which is right but slower. Browser libraries that build SVG
|
|
88
|
+
with `document`, such as lottie-web, run after `import "@silkui/core/globals"`, which adds a
|
|
89
|
+
minimal `window` and `document` where the realm has none.
|
|
76
90
|
|
|
77
91
|
A node has `append`, `appendChild`, `insertBefore`, `removeChild`, `remove`, `contains`,
|
|
78
92
|
`parentNode`, `childNodes`, `firstChild`, `lastChild` and the sibling getters, as in the DOM.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@silkui/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.10",
|
|
4
4
|
"description": "The node and event API of a Silk UI tree for JavaScript applications that run on the embedded SilkJS engine",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -12,6 +12,10 @@
|
|
|
12
12
|
".": {
|
|
13
13
|
"types": "./src/index.d.ts",
|
|
14
14
|
"default": "./src/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./globals": {
|
|
17
|
+
"types": "./src/globals.d.ts",
|
|
18
|
+
"default": "./src/globals.js"
|
|
15
19
|
}
|
|
16
20
|
},
|
|
17
21
|
"files": [
|
package/src/globals.d.ts
ADDED
package/src/globals.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// A minimal `window` and `document` for libraries written for the browser that build SVG with
|
|
2
|
+
// the DOM, such as lottie-web. Import it before them; globals the realm has stay as they are.
|
|
3
|
+
import { createNode, createSvgElement, createText } from "./index.js";
|
|
4
|
+
|
|
5
|
+
const SVG_NAMESPACE = "http://www.w3.org/2000/svg";
|
|
6
|
+
const KIND_OF_TAG = { div: "box", span: "box", p: "box", a: "box", img: "image", input: "input", svg: "svg" };
|
|
7
|
+
|
|
8
|
+
// A `<canvas>` here draws nothing: libraries such as lottie-web make one at load to probe.
|
|
9
|
+
const inert = new Proxy({}, { get: (target, name) => (name in target ? target[name] : () => {}) });
|
|
10
|
+
|
|
11
|
+
function createElement(tag) {
|
|
12
|
+
tag = String(tag).toLowerCase();
|
|
13
|
+
if (tag === "canvas") return { localName: tag, width: 300, height: 150, style: {}, getContext: () => inert };
|
|
14
|
+
const node = createNode(KIND_OF_TAG[tag] ?? "box");
|
|
15
|
+
node.localName ??= tag;
|
|
16
|
+
return node;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const none = () => [];
|
|
20
|
+
|
|
21
|
+
globalThis.window ??= globalThis;
|
|
22
|
+
if (typeof globalThis.navigator !== "object" || globalThis.navigator === null) globalThis.navigator = {};
|
|
23
|
+
if (globalThis.navigator.userAgent === undefined) {
|
|
24
|
+
Object.defineProperty(globalThis.navigator, "userAgent", { value: "SilkUI", enumerable: true, configurable: true });
|
|
25
|
+
}
|
|
26
|
+
globalThis.document ??= {
|
|
27
|
+
readyState: "complete",
|
|
28
|
+
createElement,
|
|
29
|
+
createElementNS: (namespace, tag) => (namespace === SVG_NAMESPACE ? createSvgElement(tag) : createElement(tag)),
|
|
30
|
+
createTextNode: (data) => createText(data),
|
|
31
|
+
getElementsByTagName: none,
|
|
32
|
+
getElementsByClassName: none,
|
|
33
|
+
querySelectorAll: none,
|
|
34
|
+
querySelector: () => null,
|
|
35
|
+
getElementById: () => null,
|
|
36
|
+
addEventListener() {},
|
|
37
|
+
removeEventListener() {},
|
|
38
|
+
};
|