@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,230 +1,231 @@
1
+ import { localName, namespaceURI, tagName } from "./property-symbol.js";
2
+ import { NamespaceURI } from "./namespace-uri.js";
3
+ import { HTMLElement } from "./html-element.js";
4
+ import { Event } from "@gjsify/dom-events";
1
5
  import GLib from "@girs/glib-2.0";
2
6
  import Gio from "@girs/gio-2.0";
3
7
  import GdkPixbuf from "@girs/gdkpixbuf-2.0";
4
- import { Event } from "@gjsify/dom-events";
5
- import { HTMLElement } from "./html-element.js";
6
- import * as PropertySymbol from "./property-symbol.js";
7
- import { NamespaceURI } from "./namespace-uri.js";
8
8
  import System from "system";
9
- class HTMLImageElement extends HTMLElement {
10
- constructor() {
11
- super();
12
- this._complete = false;
13
- this._naturalHeight = 0;
14
- this._naturalWidth = 0;
15
- this[PropertySymbol.tagName] = "IMG";
16
- this[PropertySymbol.localName] = "img";
17
- this[PropertySymbol.namespaceURI] = NamespaceURI.html;
18
- }
19
- // -- Read-only properties --
20
- get complete() {
21
- return this._complete;
22
- }
23
- get naturalHeight() {
24
- return this._naturalHeight;
25
- }
26
- get naturalWidth() {
27
- return this._naturalWidth;
28
- }
29
- get currentSrc() {
30
- return this.src;
31
- }
32
- get x() {
33
- return 0;
34
- }
35
- get y() {
36
- return 0;
37
- }
38
- // -- Attribute-backed string properties --
39
- get alt() {
40
- return this.getAttribute("alt") ?? "";
41
- }
42
- set alt(value) {
43
- this.setAttribute("alt", value);
44
- }
45
- get crossOrigin() {
46
- return this.getAttribute("crossorigin");
47
- }
48
- set crossOrigin(value) {
49
- if (value === null) {
50
- this.removeAttribute("crossorigin");
51
- } else {
52
- this.setAttribute("crossorigin", value);
53
- }
54
- }
55
- get decoding() {
56
- return this.getAttribute("decoding") ?? "auto";
57
- }
58
- set decoding(value) {
59
- this.setAttribute("decoding", value);
60
- }
61
- get loading() {
62
- const value = this.getAttribute("loading");
63
- if (value === "lazy" || value === "eager") return value;
64
- return "auto";
65
- }
66
- set loading(value) {
67
- this.setAttribute("loading", value);
68
- }
69
- get referrerPolicy() {
70
- return this.getAttribute("referrerpolicy") ?? "";
71
- }
72
- set referrerPolicy(value) {
73
- this.setAttribute("referrerpolicy", value);
74
- }
75
- get sizes() {
76
- return this.getAttribute("sizes") ?? "";
77
- }
78
- set sizes(value) {
79
- this.setAttribute("sizes", value);
80
- }
81
- get src() {
82
- return this.getAttribute("src") ?? "";
83
- }
84
- set src(src) {
85
- this.setAttribute("src", src);
86
- const DEBUG = globalThis.__GJSIFY_DEBUG_IMG === true;
87
- if (src.startsWith("data:")) {
88
- const commaIdx = src.indexOf(",");
89
- if (commaIdx === -1) {
90
- this._complete = true;
91
- this.dispatchEvent(new Event("error"));
92
- return;
93
- }
94
- const meta = src.slice(5, commaIdx);
95
- const data = src.slice(commaIdx + 1);
96
- const isBase64 = meta.includes(";base64");
97
- try {
98
- let bytes;
99
- if (isBase64) {
100
- bytes = GLib.base64_decode(data);
101
- } else {
102
- bytes = new TextEncoder().encode(decodeURIComponent(data));
103
- }
104
- const gbytes = GLib.Bytes.new(bytes);
105
- const stream = Gio.MemoryInputStream.new_from_bytes(gbytes);
106
- this._pixbuf = GdkPixbuf.Pixbuf.new_from_stream(stream, null);
107
- this._naturalWidth = this._pixbuf.get_width();
108
- this._naturalHeight = this._pixbuf.get_height();
109
- this._complete = true;
110
- if (DEBUG) console.log(`[img] ok data: (${this._naturalWidth}x${this._naturalHeight})`);
111
- this.dispatchEvent(new Event("load"));
112
- } catch (_error) {
113
- if (DEBUG) console.warn(`[img] error data:: ${_error?.message ?? _error}`);
114
- this._complete = true;
115
- this.dispatchEvent(new Event("error"));
116
- }
117
- return;
118
- }
119
- let filename;
120
- if (src.startsWith("file://")) {
121
- filename = GLib.filename_from_uri(src)[0];
122
- } else if (src.startsWith("http://") || src.startsWith("https://")) {
123
- this._complete = true;
124
- this.dispatchEvent(new Event("error"));
125
- return;
126
- } else {
127
- const dir = GLib.path_get_dirname(System.programInvocationName);
128
- filename = GLib.build_filenamev([dir, src]);
129
- }
130
- try {
131
- if (DEBUG) console.log(`[img] load ${filename}`);
132
- this._pixbuf = GdkPixbuf.Pixbuf.new_from_file(filename);
133
- this._naturalWidth = this._pixbuf.get_width();
134
- this._naturalHeight = this._pixbuf.get_height();
135
- this._complete = true;
136
- if (DEBUG) console.log(`[img] ok ${filename} (${this._naturalWidth}x${this._naturalHeight})`);
137
- this.dispatchEvent(new Event("load"));
138
- } catch (_error) {
139
- if (DEBUG) console.warn(`[img] error ${filename}: ${_error?.message ?? _error}`);
140
- this._complete = true;
141
- this.dispatchEvent(new Event("error"));
142
- }
143
- }
144
- get srcset() {
145
- return this.getAttribute("srcset") ?? "";
146
- }
147
- set srcset(value) {
148
- this.setAttribute("srcset", value);
149
- }
150
- get useMap() {
151
- return this.getAttribute("usemap") ?? "";
152
- }
153
- set useMap(value) {
154
- this.setAttribute("usemap", value);
155
- }
156
- // -- Attribute-backed numeric properties --
157
- get height() {
158
- if (this._pixbuf) {
159
- return this._pixbuf.get_height();
160
- }
161
- const attr = this.getAttribute("height");
162
- return attr !== null ? Number(attr) : 0;
163
- }
164
- set height(value) {
165
- this.setAttribute("height", String(value));
166
- }
167
- get width() {
168
- if (this._pixbuf) {
169
- return this._pixbuf.get_width();
170
- }
171
- const attr = this.getAttribute("width");
172
- return attr !== null ? Number(attr) : 0;
173
- }
174
- set width(value) {
175
- this.setAttribute("width", String(value));
176
- }
177
- // -- Attribute-backed boolean property --
178
- get isMap() {
179
- return this.hasAttribute("ismap");
180
- }
181
- set isMap(value) {
182
- if (value) {
183
- this.setAttribute("ismap", "");
184
- } else {
185
- this.removeAttribute("ismap");
186
- }
187
- }
188
- // -- Methods --
189
- /**
190
- * Decode the image. Returns a promise that resolves when the image is decoded.
191
- */
192
- decode() {
193
- return Promise.resolve();
194
- }
195
- /**
196
- * Clone this node.
197
- */
198
- cloneNode(deep = false) {
199
- return super.cloneNode(deep);
200
- }
201
- // -- GJS-specific extensions --
202
- /**
203
- * Get the pixels of the loaded GdkPixbuf as ImageData.
204
- * Always returns RGBA (4 channels) matches standard browser ImageData behaviour
205
- * and what WebGL expects for texSubImage2D with format=RGBA.
206
- * JPEG and other non-alpha formats are promoted to RGBA via add_alpha().
207
- */
208
- getImageData() {
209
- if (!this._pixbuf) return null;
210
- const rgba = this._pixbuf.get_has_alpha() ? this._pixbuf : this._pixbuf.add_alpha(false, 0, 0, 0) ?? this._pixbuf;
211
- return {
212
- colorSpace: "srgb",
213
- data: new Uint8ClampedArray(rgba.get_pixels()),
214
- height: rgba.get_height(),
215
- width: rgba.get_width()
216
- };
217
- }
218
- /**
219
- * Check if this image is backed by a GdkPixbuf.
220
- */
221
- isPixbuf() {
222
- return !!this._pixbuf;
223
- }
224
- get [Symbol.toStringTag]() {
225
- return "HTMLImageElement";
226
- }
227
- }
228
- export {
229
- HTMLImageElement
9
+
10
+ //#region src/html-image-element.ts
11
+ /**
12
+ * HTML Image Element.
13
+ *
14
+ * Reference: https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement
15
+ */
16
+ var HTMLImageElement = class extends HTMLElement {
17
+ constructor() {
18
+ super();
19
+ this._complete = false;
20
+ this._naturalHeight = 0;
21
+ this._naturalWidth = 0;
22
+ this[tagName] = "IMG";
23
+ this[localName] = "img";
24
+ this[namespaceURI] = NamespaceURI.html;
25
+ }
26
+ get complete() {
27
+ return this._complete;
28
+ }
29
+ get naturalHeight() {
30
+ return this._naturalHeight;
31
+ }
32
+ get naturalWidth() {
33
+ return this._naturalWidth;
34
+ }
35
+ get currentSrc() {
36
+ return this.src;
37
+ }
38
+ get x() {
39
+ return 0;
40
+ }
41
+ get y() {
42
+ return 0;
43
+ }
44
+ get alt() {
45
+ return this.getAttribute("alt") ?? "";
46
+ }
47
+ set alt(value) {
48
+ this.setAttribute("alt", value);
49
+ }
50
+ get crossOrigin() {
51
+ return this.getAttribute("crossorigin");
52
+ }
53
+ set crossOrigin(value) {
54
+ if (value === null) {
55
+ this.removeAttribute("crossorigin");
56
+ } else {
57
+ this.setAttribute("crossorigin", value);
58
+ }
59
+ }
60
+ get decoding() {
61
+ return this.getAttribute("decoding") ?? "auto";
62
+ }
63
+ set decoding(value) {
64
+ this.setAttribute("decoding", value);
65
+ }
66
+ get loading() {
67
+ const value = this.getAttribute("loading");
68
+ if (value === "lazy" || value === "eager") return value;
69
+ return "auto";
70
+ }
71
+ set loading(value) {
72
+ this.setAttribute("loading", value);
73
+ }
74
+ get referrerPolicy() {
75
+ return this.getAttribute("referrerpolicy") ?? "";
76
+ }
77
+ set referrerPolicy(value) {
78
+ this.setAttribute("referrerpolicy", value);
79
+ }
80
+ get sizes() {
81
+ return this.getAttribute("sizes") ?? "";
82
+ }
83
+ set sizes(value) {
84
+ this.setAttribute("sizes", value);
85
+ }
86
+ get src() {
87
+ return this.getAttribute("src") ?? "";
88
+ }
89
+ set src(src) {
90
+ this.setAttribute("src", src);
91
+ const DEBUG = globalThis.__GJSIFY_DEBUG_IMG === true;
92
+ if (src.startsWith("data:")) {
93
+ const commaIdx = src.indexOf(",");
94
+ if (commaIdx === -1) {
95
+ this._complete = true;
96
+ this.dispatchEvent(new Event("error"));
97
+ return;
98
+ }
99
+ const meta = src.slice(5, commaIdx);
100
+ const data = src.slice(commaIdx + 1);
101
+ const isBase64 = meta.includes(";base64");
102
+ try {
103
+ let bytes;
104
+ if (isBase64) {
105
+ bytes = GLib.base64_decode(data);
106
+ } else {
107
+ bytes = new TextEncoder().encode(decodeURIComponent(data));
108
+ }
109
+ const gbytes = GLib.Bytes.new(bytes);
110
+ const stream = Gio.MemoryInputStream.new_from_bytes(gbytes);
111
+ this._pixbuf = GdkPixbuf.Pixbuf.new_from_stream(stream, null);
112
+ this._naturalWidth = this._pixbuf.get_width();
113
+ this._naturalHeight = this._pixbuf.get_height();
114
+ this._complete = true;
115
+ if (DEBUG) console.log(`[img] ok data: (${this._naturalWidth}x${this._naturalHeight})`);
116
+ this.dispatchEvent(new Event("load"));
117
+ } catch (_error) {
118
+ if (DEBUG) console.warn(`[img] error data:: ${_error?.message ?? _error}`);
119
+ this._complete = true;
120
+ this.dispatchEvent(new Event("error"));
121
+ }
122
+ return;
123
+ }
124
+ let filename;
125
+ if (src.startsWith("file://")) {
126
+ filename = GLib.filename_from_uri(src)[0];
127
+ } else if (src.startsWith("http://") || src.startsWith("https://")) {
128
+ this._complete = true;
129
+ this.dispatchEvent(new Event("error"));
130
+ return;
131
+ } else {
132
+ const dir = GLib.path_get_dirname(System.programInvocationName);
133
+ filename = GLib.build_filenamev([dir, src]);
134
+ }
135
+ try {
136
+ if (DEBUG) console.log(`[img] load ${filename}`);
137
+ this._pixbuf = GdkPixbuf.Pixbuf.new_from_file(filename);
138
+ this._naturalWidth = this._pixbuf.get_width();
139
+ this._naturalHeight = this._pixbuf.get_height();
140
+ this._complete = true;
141
+ if (DEBUG) console.log(`[img] ok ${filename} (${this._naturalWidth}x${this._naturalHeight})`);
142
+ this.dispatchEvent(new Event("load"));
143
+ } catch (_error) {
144
+ if (DEBUG) console.warn(`[img] error ${filename}: ${_error?.message ?? _error}`);
145
+ this._complete = true;
146
+ this.dispatchEvent(new Event("error"));
147
+ }
148
+ }
149
+ get srcset() {
150
+ return this.getAttribute("srcset") ?? "";
151
+ }
152
+ set srcset(value) {
153
+ this.setAttribute("srcset", value);
154
+ }
155
+ get useMap() {
156
+ return this.getAttribute("usemap") ?? "";
157
+ }
158
+ set useMap(value) {
159
+ this.setAttribute("usemap", value);
160
+ }
161
+ get height() {
162
+ if (this._pixbuf) {
163
+ return this._pixbuf.get_height();
164
+ }
165
+ const attr = this.getAttribute("height");
166
+ return attr !== null ? Number(attr) : 0;
167
+ }
168
+ set height(value) {
169
+ this.setAttribute("height", String(value));
170
+ }
171
+ get width() {
172
+ if (this._pixbuf) {
173
+ return this._pixbuf.get_width();
174
+ }
175
+ const attr = this.getAttribute("width");
176
+ return attr !== null ? Number(attr) : 0;
177
+ }
178
+ set width(value) {
179
+ this.setAttribute("width", String(value));
180
+ }
181
+ get isMap() {
182
+ return this.hasAttribute("ismap");
183
+ }
184
+ set isMap(value) {
185
+ if (value) {
186
+ this.setAttribute("ismap", "");
187
+ } else {
188
+ this.removeAttribute("ismap");
189
+ }
190
+ }
191
+ /**
192
+ * Decode the image. Returns a promise that resolves when the image is decoded.
193
+ */
194
+ decode() {
195
+ return Promise.resolve();
196
+ }
197
+ /**
198
+ * Clone this node.
199
+ */
200
+ cloneNode(deep = false) {
201
+ return super.cloneNode(deep);
202
+ }
203
+ /**
204
+ * Get the pixels of the loaded GdkPixbuf as ImageData.
205
+ * Always returns RGBA (4 channels) matches standard browser ImageData behaviour
206
+ * and what WebGL expects for texSubImage2D with format=RGBA.
207
+ * JPEG and other non-alpha formats are promoted to RGBA via add_alpha().
208
+ */
209
+ getImageData() {
210
+ if (!this._pixbuf) return null;
211
+ const rgba = this._pixbuf.get_has_alpha() ? this._pixbuf : this._pixbuf.add_alpha(false, 0, 0, 0) ?? this._pixbuf;
212
+ return {
213
+ colorSpace: "srgb",
214
+ data: new Uint8ClampedArray(rgba.get_pixels()),
215
+ height: rgba.get_height(),
216
+ width: rgba.get_width()
217
+ };
218
+ }
219
+ /**
220
+ * Check if this image is backed by a GdkPixbuf.
221
+ */
222
+ isPixbuf() {
223
+ return !!this._pixbuf;
224
+ }
225
+ get [Symbol.toStringTag]() {
226
+ return "HTMLImageElement";
227
+ }
230
228
  };
229
+
230
+ //#endregion
231
+ export { HTMLImageElement };