@gjsify/dom-elements 0.3.13 → 0.3.15
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/lib/esm/_virtual/_rolldown/runtime.js +18 -0
- package/lib/esm/attr.js +37 -30
- package/lib/esm/character-data.js +61 -54
- package/lib/esm/comment.js +26 -19
- package/lib/esm/document-fragment.js +116 -109
- package/lib/esm/document.js +75 -81
- package/lib/esm/dom-matrix.js +158 -123
- package/lib/esm/dom-token-list.js +114 -108
- package/lib/esm/element.js +244 -246
- package/lib/esm/font-face.js +94 -89
- package/lib/esm/gst-time.js +17 -6
- package/lib/esm/html-canvas-element.js +82 -75
- package/lib/esm/html-element.js +424 -424
- package/lib/esm/html-image-element.js +226 -225
- package/lib/esm/html-media-element.js +117 -114
- package/lib/esm/html-video-element.js +110 -108
- package/lib/esm/image.js +27 -21
- package/lib/esm/index.js +13 -45
- package/lib/esm/intersection-observer.js +22 -18
- package/lib/esm/location-stub.js +25 -23
- package/lib/esm/match-media.js +18 -19
- package/lib/esm/mutation-observer.js +18 -13
- package/lib/esm/named-node-map.js +121 -121
- package/lib/esm/namespace-uri.js +9 -8
- package/lib/esm/node-list.js +39 -33
- package/lib/esm/node-type.js +13 -12
- package/lib/esm/node.js +241 -246
- package/lib/esm/property-symbol.js +36 -30
- package/lib/esm/register/canvas.js +11 -7
- package/lib/esm/register/document.js +19 -18
- package/lib/esm/register/font-face.js +10 -6
- package/lib/esm/register/helpers.js +14 -12
- package/lib/esm/register/image.js +4 -0
- package/lib/esm/register/location.js +4 -0
- package/lib/esm/register/match-media.js +4 -0
- package/lib/esm/register/navigator.js +4 -1
- package/lib/esm/register/observers.js +5 -1
- package/lib/esm/resize-observer.js +15 -12
- package/lib/esm/text.js +56 -49
- package/lib/esm/types/index.js +3 -3
- package/package.json +11 -11
package/lib/esm/font-face.js
CHANGED
|
@@ -1,90 +1,95 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
class FontFaceSet {
|
|
36
|
-
constructor() {
|
|
37
|
-
this.status = "loaded";
|
|
38
|
-
this.ready = Promise.resolve(this);
|
|
39
|
-
this._faces = /* @__PURE__ */ new Set();
|
|
40
|
-
}
|
|
41
|
-
addEventListener(_type, _listener) {
|
|
42
|
-
}
|
|
43
|
-
removeEventListener(_type, _listener) {
|
|
44
|
-
}
|
|
45
|
-
dispatchEvent(_event) {
|
|
46
|
-
return true;
|
|
47
|
-
}
|
|
48
|
-
add(face) {
|
|
49
|
-
this._faces.add(face);
|
|
50
|
-
return this;
|
|
51
|
-
}
|
|
52
|
-
delete(face) {
|
|
53
|
-
return this._faces.delete(face);
|
|
54
|
-
}
|
|
55
|
-
clear() {
|
|
56
|
-
this._faces.clear();
|
|
57
|
-
}
|
|
58
|
-
has(face) {
|
|
59
|
-
return this._faces.has(face);
|
|
60
|
-
}
|
|
61
|
-
check(_font, _text) {
|
|
62
|
-
return false;
|
|
63
|
-
}
|
|
64
|
-
load(_font, _text) {
|
|
65
|
-
return Promise.resolve([]);
|
|
66
|
-
}
|
|
67
|
-
forEach(callback) {
|
|
68
|
-
this._faces.forEach((f) => callback(f, f, this));
|
|
69
|
-
}
|
|
70
|
-
values() {
|
|
71
|
-
return this._faces.values();
|
|
72
|
-
}
|
|
73
|
-
keys() {
|
|
74
|
-
return this._faces.values();
|
|
75
|
-
}
|
|
76
|
-
entries() {
|
|
77
|
-
const faces = Array.from(this._faces);
|
|
78
|
-
return faces.map((f) => [f, f])[Symbol.iterator]();
|
|
79
|
-
}
|
|
80
|
-
[Symbol.iterator]() {
|
|
81
|
-
return this._faces[Symbol.iterator]();
|
|
82
|
-
}
|
|
83
|
-
get size() {
|
|
84
|
-
return this._faces.size;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
export {
|
|
88
|
-
FontFace,
|
|
89
|
-
FontFaceSet
|
|
1
|
+
//#region src/font-face.ts
|
|
2
|
+
var FontFace = class {
|
|
3
|
+
constructor(family, source, _descriptors) {
|
|
4
|
+
this.status = "unloaded";
|
|
5
|
+
this.display = "auto";
|
|
6
|
+
this.style = "normal";
|
|
7
|
+
this.weight = "normal";
|
|
8
|
+
this.stretch = "normal";
|
|
9
|
+
this.unicodeRange = "U+0-10FFFF";
|
|
10
|
+
this.variant = "normal";
|
|
11
|
+
this.featureSettings = "normal";
|
|
12
|
+
this.family = family;
|
|
13
|
+
this.source = typeof source === "string" ? source : "[binary]";
|
|
14
|
+
this.loaded = Promise.resolve(this);
|
|
15
|
+
}
|
|
16
|
+
_extractFilePath() {
|
|
17
|
+
const m = this.source.match(/url\s*\(\s*["']?(file:\/\/\/[^"')]+)["']?\s*\)/i);
|
|
18
|
+
if (!m) return null;
|
|
19
|
+
return m[1].replace(/^file:\/\//, "");
|
|
20
|
+
}
|
|
21
|
+
async load() {
|
|
22
|
+
this.status = "loading";
|
|
23
|
+
const filePath = this._extractFilePath();
|
|
24
|
+
if (filePath) {
|
|
25
|
+
try {
|
|
26
|
+
const { default: PangoCairo } = await import("gi://PangoCairo?version=1.0");
|
|
27
|
+
PangoCairo.font_map_get_default().add_font_file(filePath);
|
|
28
|
+
} catch {}
|
|
29
|
+
}
|
|
30
|
+
this.status = "loaded";
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
90
33
|
};
|
|
34
|
+
/**
|
|
35
|
+
* FontFaceSet — tracks loaded FontFace objects and exposes them to consumers.
|
|
36
|
+
*
|
|
37
|
+
* Intentionally does NOT extend EventTarget. The dom-elements /register module
|
|
38
|
+
* runs before dom-events/register in the inject order, so EventTarget may not
|
|
39
|
+
* yet exist when this class is defined at module load time. All event methods
|
|
40
|
+
* are provided as no-ops; consumers that call addEventListener('loadingdone')
|
|
41
|
+
* etc. will silently receive nothing.
|
|
42
|
+
*/
|
|
43
|
+
var FontFaceSet = class {
|
|
44
|
+
constructor() {
|
|
45
|
+
this.status = "loaded";
|
|
46
|
+
this.ready = Promise.resolve(this);
|
|
47
|
+
this._faces = new Set();
|
|
48
|
+
}
|
|
49
|
+
addEventListener(_type, _listener) {}
|
|
50
|
+
removeEventListener(_type, _listener) {}
|
|
51
|
+
dispatchEvent(_event) {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
add(face) {
|
|
55
|
+
this._faces.add(face);
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
delete(face) {
|
|
59
|
+
return this._faces.delete(face);
|
|
60
|
+
}
|
|
61
|
+
clear() {
|
|
62
|
+
this._faces.clear();
|
|
63
|
+
}
|
|
64
|
+
has(face) {
|
|
65
|
+
return this._faces.has(face);
|
|
66
|
+
}
|
|
67
|
+
check(_font, _text) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
load(_font, _text) {
|
|
71
|
+
return Promise.resolve([]);
|
|
72
|
+
}
|
|
73
|
+
forEach(callback) {
|
|
74
|
+
this._faces.forEach((f) => callback(f, f, this));
|
|
75
|
+
}
|
|
76
|
+
values() {
|
|
77
|
+
return this._faces.values();
|
|
78
|
+
}
|
|
79
|
+
keys() {
|
|
80
|
+
return this._faces.values();
|
|
81
|
+
}
|
|
82
|
+
entries() {
|
|
83
|
+
const faces = Array.from(this._faces);
|
|
84
|
+
return faces.map((f) => [f, f])[Symbol.iterator]();
|
|
85
|
+
}
|
|
86
|
+
[Symbol.iterator]() {
|
|
87
|
+
return this._faces[Symbol.iterator]();
|
|
88
|
+
}
|
|
89
|
+
get size() {
|
|
90
|
+
return this._faces.size;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
//#endregion
|
|
95
|
+
export { FontFace, FontFaceSet };
|
package/lib/esm/gst-time.js
CHANGED
|
@@ -1,11 +1,22 @@
|
|
|
1
|
+
//#region src/gst-time.ts
|
|
1
2
|
const NS_PER_SECOND = 1e9;
|
|
3
|
+
/**
|
|
4
|
+
* Convert seconds (number) to GStreamer nanoseconds (bigint).
|
|
5
|
+
* Rounds to the nearest nanosecond to avoid floating-point drift over
|
|
6
|
+
* repeated back-and-forth conversions.
|
|
7
|
+
*/
|
|
2
8
|
function secondsToGstTime(seconds) {
|
|
3
|
-
|
|
9
|
+
return BigInt(Math.round(seconds * NS_PER_SECOND));
|
|
4
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Convert GStreamer nanoseconds to seconds (number).
|
|
13
|
+
* Accepts both `bigint` (the runtime type from GStreamer queries) and `number`
|
|
14
|
+
* (what the `@girs/gst-1.0` typings currently declare — a known GIR bug for
|
|
15
|
+
* `gint64` return values in `query_position` / `query_duration`).
|
|
16
|
+
*/
|
|
5
17
|
function gstTimeToSeconds(nanoseconds) {
|
|
6
|
-
|
|
18
|
+
return Number(nanoseconds) / NS_PER_SECOND;
|
|
7
19
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
};
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
export { gstTimeToSeconds, secondsToGstTime };
|
|
@@ -1,77 +1,84 @@
|
|
|
1
1
|
import { HTMLElement } from "./html-element.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
2
|
+
|
|
3
|
+
//#region src/html-canvas-element.ts
|
|
4
|
+
/**
|
|
5
|
+
* HTMLCanvasElement base class.
|
|
6
|
+
*
|
|
7
|
+
* This is a DOM-spec-compliant stub. The GTK-backed implementation lives in
|
|
8
|
+
* `@gjsify/webgl` and extends this class, overriding `getContext()`.
|
|
9
|
+
*
|
|
10
|
+
* Reference: https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement
|
|
11
|
+
*/
|
|
12
|
+
var HTMLCanvasElement = class HTMLCanvasElement extends HTMLElement {
|
|
13
|
+
constructor(..._args) {
|
|
14
|
+
super(..._args);
|
|
15
|
+
this.oncontextlost = null;
|
|
16
|
+
this.oncontextrestored = null;
|
|
17
|
+
this.onwebglcontextcreationerror = null;
|
|
18
|
+
this.onwebglcontextlost = null;
|
|
19
|
+
this.onwebglcontextrestored = null;
|
|
20
|
+
}
|
|
21
|
+
static {
|
|
22
|
+
this._contextFactories = new Map();
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Register a rendering context factory for a given context type.
|
|
26
|
+
* Called by packages like @gjsify/canvas2d and @gjsify/webgl to plug in their implementations.
|
|
27
|
+
*/
|
|
28
|
+
static registerContextFactory(contextId, factory) {
|
|
29
|
+
HTMLCanvasElement._contextFactories.set(contextId, factory);
|
|
30
|
+
}
|
|
31
|
+
/** Returns the width of the canvas element. Default: 300. */
|
|
32
|
+
get width() {
|
|
33
|
+
const w = this.getAttribute("width");
|
|
34
|
+
return w !== null ? Number(w) : 300;
|
|
35
|
+
}
|
|
36
|
+
set width(value) {
|
|
37
|
+
this.setAttribute("width", String(value));
|
|
38
|
+
}
|
|
39
|
+
/** Returns the height of the canvas element. Default: 150. */
|
|
40
|
+
get height() {
|
|
41
|
+
const h = this.getAttribute("height");
|
|
42
|
+
return h !== null ? Number(h) : 150;
|
|
43
|
+
}
|
|
44
|
+
set height(value) {
|
|
45
|
+
this.setAttribute("height", String(value));
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Returns a rendering context.
|
|
49
|
+
* Checks the static context factory registry for a matching factory.
|
|
50
|
+
* Subclasses (e.g. @gjsify/webgl) may override and fall through via super.getContext().
|
|
51
|
+
*/
|
|
52
|
+
getContext(contextId, options) {
|
|
53
|
+
const factory = HTMLCanvasElement._contextFactories.get(contextId);
|
|
54
|
+
if (factory) return factory(this, options);
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
/** Returns a data URL representing the canvas image. Delegates to the active 2D context if available. */
|
|
58
|
+
toDataURL(type, quality) {
|
|
59
|
+
const ctx = this.getContext("2d");
|
|
60
|
+
if (ctx && typeof ctx._toDataURL === "function") return ctx._toDataURL(type, quality);
|
|
61
|
+
return "";
|
|
62
|
+
}
|
|
63
|
+
/** Converts the canvas to a Blob and passes it to the callback. Delegates to the active 2D context if available. */
|
|
64
|
+
toBlob(callback, type, quality) {
|
|
65
|
+
const dataUrl = this.toDataURL(type, quality);
|
|
66
|
+
if (!dataUrl) {
|
|
67
|
+
callback(null);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const [header, b64] = dataUrl.split(",");
|
|
71
|
+
const mime = header.split(":")[1].split(";")[0];
|
|
72
|
+
const bytes = atob(b64);
|
|
73
|
+
const arr = new Uint8Array(bytes.length);
|
|
74
|
+
for (let i = 0; i < bytes.length; i++) arr[i] = bytes.charCodeAt(i);
|
|
75
|
+
callback(new Blob([arr], { type: mime }));
|
|
76
|
+
}
|
|
77
|
+
/** Returns a MediaStream capturing the canvas. Stub — returns empty object. */
|
|
78
|
+
captureStream(_frameRequestRate) {
|
|
79
|
+
return {};
|
|
80
|
+
}
|
|
77
81
|
};
|
|
82
|
+
|
|
83
|
+
//#endregion
|
|
84
|
+
export { HTMLCanvasElement };
|