@gjsify/dom-elements 0.3.13 → 0.3.14
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
|
@@ -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
|
-
|
|
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
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
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 };
|