@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.
Files changed (41) hide show
  1. package/lib/esm/_virtual/_rolldown/runtime.js +18 -0
  2. package/lib/esm/attr.js +37 -30
  3. package/lib/esm/character-data.js +61 -54
  4. package/lib/esm/comment.js +26 -19
  5. package/lib/esm/document-fragment.js +116 -109
  6. package/lib/esm/document.js +75 -81
  7. package/lib/esm/dom-matrix.js +158 -123
  8. package/lib/esm/dom-token-list.js +114 -108
  9. package/lib/esm/element.js +244 -246
  10. package/lib/esm/font-face.js +94 -89
  11. package/lib/esm/gst-time.js +17 -6
  12. package/lib/esm/html-canvas-element.js +82 -75
  13. package/lib/esm/html-element.js +424 -424
  14. package/lib/esm/html-image-element.js +226 -225
  15. package/lib/esm/html-media-element.js +117 -114
  16. package/lib/esm/html-video-element.js +110 -108
  17. package/lib/esm/image.js +27 -21
  18. package/lib/esm/index.js +13 -45
  19. package/lib/esm/intersection-observer.js +22 -18
  20. package/lib/esm/location-stub.js +25 -23
  21. package/lib/esm/match-media.js +18 -19
  22. package/lib/esm/mutation-observer.js +18 -13
  23. package/lib/esm/named-node-map.js +121 -121
  24. package/lib/esm/namespace-uri.js +9 -8
  25. package/lib/esm/node-list.js +39 -33
  26. package/lib/esm/node-type.js +13 -12
  27. package/lib/esm/node.js +241 -246
  28. package/lib/esm/property-symbol.js +36 -30
  29. package/lib/esm/register/canvas.js +11 -7
  30. package/lib/esm/register/document.js +19 -18
  31. package/lib/esm/register/font-face.js +10 -6
  32. package/lib/esm/register/helpers.js +14 -12
  33. package/lib/esm/register/image.js +4 -0
  34. package/lib/esm/register/location.js +4 -0
  35. package/lib/esm/register/match-media.js +4 -0
  36. package/lib/esm/register/navigator.js +4 -1
  37. package/lib/esm/register/observers.js +5 -1
  38. package/lib/esm/resize-observer.js +15 -12
  39. package/lib/esm/text.js +56 -49
  40. package/lib/esm/types/index.js +3 -3
  41. package/package.json +11 -11
@@ -1,90 +1,95 @@
1
- class FontFace {
2
- constructor(family, source, _descriptors) {
3
- this.status = "unloaded";
4
- this.display = "auto";
5
- this.style = "normal";
6
- this.weight = "normal";
7
- this.stretch = "normal";
8
- this.unicodeRange = "U+0-10FFFF";
9
- this.variant = "normal";
10
- this.featureSettings = "normal";
11
- this.family = family;
12
- this.source = typeof source === "string" ? source : "[binary]";
13
- this.loaded = Promise.resolve(this);
14
- }
15
- // Parses: url(file:///path), url("file:///path"), url('file:///path')
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
- }
31
- this.status = "loaded";
32
- return this;
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 };
@@ -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
- return BigInt(Math.round(seconds * NS_PER_SECOND));
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
- return Number(nanoseconds) / NS_PER_SECOND;
18
+ return Number(nanoseconds) / NS_PER_SECOND;
7
19
  }
8
- export {
9
- gstTimeToSeconds,
10
- secondsToGstTime
11
- };
20
+
21
+ //#endregion
22
+ export { gstTimeToSeconds, secondsToGstTime };
@@ -1,77 +1,84 @@
1
1
  import { HTMLElement } from "./html-element.js";
2
- class HTMLCanvasElement extends HTMLElement {
3
- constructor() {
4
- super(...arguments);
5
- // WebGL context event handlers
6
- this.oncontextlost = null;
7
- this.oncontextrestored = null;
8
- this.onwebglcontextcreationerror = null;
9
- this.onwebglcontextlost = null;
10
- this.onwebglcontextrestored = null;
11
- }
12
- static {
13
- // Context factory registry — packages register their context types here.
14
- // e.g. @gjsify/canvas2d registers '2d', @gjsify/webgl registers 'webgl'.
15
- this._contextFactories = /* @__PURE__ */ new Map();
16
- }
17
- /**
18
- * Register a rendering context factory for a given context type.
19
- * Called by packages like @gjsify/canvas2d and @gjsify/webgl to plug in their implementations.
20
- */
21
- static registerContextFactory(contextId, factory) {
22
- HTMLCanvasElement._contextFactories.set(contextId, factory);
23
- }
24
- /** Returns the width of the canvas element. Default: 300. */
25
- get width() {
26
- const w = this.getAttribute("width");
27
- return w !== null ? Number(w) : 300;
28
- }
29
- set width(value) {
30
- this.setAttribute("width", String(value));
31
- }
32
- /** Returns the height of the canvas element. Default: 150. */
33
- get height() {
34
- const h = this.getAttribute("height");
35
- return h !== null ? Number(h) : 150;
36
- }
37
- set height(value) {
38
- this.setAttribute("height", String(value));
39
- }
40
- /**
41
- * Returns a rendering context.
42
- * Checks the static context factory registry for a matching factory.
43
- * Subclasses (e.g. @gjsify/webgl) may override and fall through via super.getContext().
44
- */
45
- getContext(contextId, options) {
46
- const factory = HTMLCanvasElement._contextFactories.get(contextId);
47
- if (factory) return factory(this, options);
48
- return null;
49
- }
50
- /** Returns a data URL representing the canvas image. Delegates to the active 2D context if available. */
51
- toDataURL(type, quality) {
52
- const ctx = this.getContext("2d");
53
- if (ctx && typeof ctx._toDataURL === "function") return ctx._toDataURL(type, quality);
54
- return "";
55
- }
56
- /** Converts the canvas to a Blob and passes it to the callback. Delegates to the active 2D context if available. */
57
- toBlob(callback, type, quality) {
58
- const dataUrl = this.toDataURL(type, quality);
59
- if (!dataUrl) {
60
- callback(null);
61
- return;
62
- }
63
- const [header, b64] = dataUrl.split(",");
64
- const mime = header.split(":")[1].split(";")[0];
65
- const bytes = atob(b64);
66
- const arr = new Uint8Array(bytes.length);
67
- for (let i = 0; i < bytes.length; i++) arr[i] = bytes.charCodeAt(i);
68
- callback(new Blob([arr], { type: mime }));
69
- }
70
- /** Returns a MediaStream capturing the canvas. Stub — returns empty object. */
71
- captureStream(_frameRequestRate) {
72
- return {};
73
- }
74
- }
75
- export {
76
- HTMLCanvasElement
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 };