@gjsify/dom-elements 0.1.0
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 +31 -0
- package/lib/esm/attr.js +31 -0
- package/lib/esm/character-data.js +56 -0
- package/lib/esm/comment.js +21 -0
- package/lib/esm/document-fragment.js +112 -0
- package/lib/esm/document.js +83 -0
- package/lib/esm/dom-token-list.js +109 -0
- package/lib/esm/element.js +237 -0
- package/lib/esm/html-canvas-element.js +65 -0
- package/lib/esm/html-element.js +346 -0
- package/lib/esm/html-image-element.js +184 -0
- package/lib/esm/image.js +23 -0
- package/lib/esm/index.js +112 -0
- package/lib/esm/intersection-observer.js +19 -0
- package/lib/esm/mutation-observer.js +14 -0
- package/lib/esm/named-node-map.js +124 -0
- package/lib/esm/namespace-uri.js +10 -0
- package/lib/esm/node-list.js +34 -0
- package/lib/esm/node-type.js +14 -0
- package/lib/esm/node.js +227 -0
- package/lib/esm/property-symbol.js +30 -0
- package/lib/esm/resize-observer.js +13 -0
- package/lib/esm/text.js +51 -0
- package/lib/esm/types/i-html-image-element.js +0 -0
- package/lib/esm/types/image-data.js +0 -0
- package/lib/esm/types/index.js +3 -0
- package/lib/esm/types/predefined-color-space.js +0 -0
- package/lib/types/attr.d.ts +22 -0
- package/lib/types/character-data.d.ts +24 -0
- package/lib/types/comment.d.ts +12 -0
- package/lib/types/document-fragment.d.ts +37 -0
- package/lib/types/document.d.ts +39 -0
- package/lib/types/dom-token-list.d.ts +30 -0
- package/lib/types/element.d.ts +58 -0
- package/lib/types/html-canvas-element.d.ts +40 -0
- package/lib/types/html-element.d.ts +119 -0
- package/lib/types/html-image-element.d.ts +65 -0
- package/lib/types/image.d.ts +17 -0
- package/lib/types/index.d.ts +21 -0
- package/lib/types/intersection-observer.d.ts +21 -0
- package/lib/types/mutation-observer.d.ts +24 -0
- package/lib/types/named-node-map.d.ts +31 -0
- package/lib/types/namespace-uri.d.ts +7 -0
- package/lib/types/node-list.d.ts +18 -0
- package/lib/types/node-type.d.ts +11 -0
- package/lib/types/node.d.ts +63 -0
- package/lib/types/property-symbol.d.ts +14 -0
- package/lib/types/resize-observer.d.ts +13 -0
- package/lib/types/text.d.ts +21 -0
- package/lib/types/types/i-html-image-element.d.ts +41 -0
- package/lib/types/types/image-data.d.ts +11 -0
- package/lib/types/types/index.d.ts +3 -0
- package/lib/types/types/predefined-color-space.d.ts +1 -0
- package/package.json +43 -0
- package/src/attr.ts +61 -0
- package/src/character-data.ts +79 -0
- package/src/comment.ts +31 -0
- package/src/document-fragment.ts +137 -0
- package/src/document.ts +93 -0
- package/src/dom-token-list.ts +140 -0
- package/src/element.ts +299 -0
- package/src/html-canvas-element.ts +81 -0
- package/src/html-element.ts +422 -0
- package/src/html-image-element.ts +242 -0
- package/src/image.ts +31 -0
- package/src/index.spec.ts +897 -0
- package/src/index.ts +95 -0
- package/src/intersection-observer.ts +42 -0
- package/src/mutation-observer.ts +39 -0
- package/src/named-node-map.ts +159 -0
- package/src/namespace-uri.ts +11 -0
- package/src/node-list.ts +52 -0
- package/src/node-type.ts +14 -0
- package/src/node.ts +250 -0
- package/src/property-symbol.ts +23 -0
- package/src/resize-observer.ts +28 -0
- package/src/test.mts +6 -0
- package/src/text.ts +67 -0
- package/src/types/i-html-image-element.ts +44 -0
- package/src/types/image-data.ts +12 -0
- package/src/types/index.ts +3 -0
- package/src/types/predefined-color-space.ts +1 -0
- package/tsconfig.json +37 -0
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1,65 @@
|
|
|
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. Stub — returns empty string. */
|
|
51
|
+
toDataURL(_type, _quality) {
|
|
52
|
+
return "";
|
|
53
|
+
}
|
|
54
|
+
/** Converts the canvas to a Blob and passes it to the callback. Stub — returns empty Blob. */
|
|
55
|
+
toBlob(callback, _type, _quality) {
|
|
56
|
+
callback(new Blob([]));
|
|
57
|
+
}
|
|
58
|
+
/** Returns a MediaStream capturing the canvas. Stub — returns empty object. */
|
|
59
|
+
captureStream(_frameRequestRate) {
|
|
60
|
+
return {};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
export {
|
|
64
|
+
HTMLCanvasElement
|
|
65
|
+
};
|
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
import { Event } from "@gjsify/dom-events";
|
|
2
|
+
import { Element } from "./element.js";
|
|
3
|
+
import * as PS from "./property-symbol.js";
|
|
4
|
+
class CSSStyleDeclaration {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.cssText = "";
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
class HTMLElement extends Element {
|
|
10
|
+
constructor() {
|
|
11
|
+
super(...arguments);
|
|
12
|
+
// -- Style stub (no layout engine — assignments are no-ops) --
|
|
13
|
+
this.style = new CSSStyleDeclaration();
|
|
14
|
+
}
|
|
15
|
+
// -- Attribute-backed string properties --
|
|
16
|
+
get title() {
|
|
17
|
+
return this.getAttribute("title") ?? "";
|
|
18
|
+
}
|
|
19
|
+
set title(value) {
|
|
20
|
+
this.setAttribute("title", value);
|
|
21
|
+
}
|
|
22
|
+
get lang() {
|
|
23
|
+
return this.getAttribute("lang") ?? "";
|
|
24
|
+
}
|
|
25
|
+
set lang(value) {
|
|
26
|
+
this.setAttribute("lang", value);
|
|
27
|
+
}
|
|
28
|
+
get dir() {
|
|
29
|
+
return this.getAttribute("dir") ?? "";
|
|
30
|
+
}
|
|
31
|
+
set dir(value) {
|
|
32
|
+
this.setAttribute("dir", value);
|
|
33
|
+
}
|
|
34
|
+
get accessKey() {
|
|
35
|
+
return this.getAttribute("accesskey") ?? "";
|
|
36
|
+
}
|
|
37
|
+
set accessKey(value) {
|
|
38
|
+
this.setAttribute("accesskey", value);
|
|
39
|
+
}
|
|
40
|
+
get accessKeyLabel() {
|
|
41
|
+
return this.getAttribute("accesskey") ?? "";
|
|
42
|
+
}
|
|
43
|
+
// -- Attribute-backed boolean properties --
|
|
44
|
+
get hidden() {
|
|
45
|
+
return this.hasAttribute("hidden");
|
|
46
|
+
}
|
|
47
|
+
set hidden(value) {
|
|
48
|
+
if (value) {
|
|
49
|
+
this.setAttribute("hidden", "");
|
|
50
|
+
} else {
|
|
51
|
+
this.removeAttribute("hidden");
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
get draggable() {
|
|
55
|
+
return this.getAttribute("draggable") === "true";
|
|
56
|
+
}
|
|
57
|
+
set draggable(value) {
|
|
58
|
+
this.setAttribute("draggable", String(value));
|
|
59
|
+
}
|
|
60
|
+
get spellcheck() {
|
|
61
|
+
const attr = this.getAttribute("spellcheck");
|
|
62
|
+
if (attr === "false") return false;
|
|
63
|
+
return attr !== null;
|
|
64
|
+
}
|
|
65
|
+
set spellcheck(value) {
|
|
66
|
+
this.setAttribute("spellcheck", String(value));
|
|
67
|
+
}
|
|
68
|
+
get translate() {
|
|
69
|
+
const attr = this.getAttribute("translate");
|
|
70
|
+
return attr !== "no";
|
|
71
|
+
}
|
|
72
|
+
set translate(value) {
|
|
73
|
+
this.setAttribute("translate", value ? "yes" : "no");
|
|
74
|
+
}
|
|
75
|
+
// -- Attribute-backed numeric properties --
|
|
76
|
+
get tabIndex() {
|
|
77
|
+
const attr = this.getAttribute("tabindex");
|
|
78
|
+
return attr !== null ? Number(attr) : -1;
|
|
79
|
+
}
|
|
80
|
+
set tabIndex(value) {
|
|
81
|
+
this.setAttribute("tabindex", String(value));
|
|
82
|
+
}
|
|
83
|
+
// -- Content editable --
|
|
84
|
+
get contentEditable() {
|
|
85
|
+
const attr = this.getAttribute("contenteditable");
|
|
86
|
+
if (attr === "" || attr === "true") return "true";
|
|
87
|
+
if (attr === "false") return "false";
|
|
88
|
+
return "inherit";
|
|
89
|
+
}
|
|
90
|
+
set contentEditable(value) {
|
|
91
|
+
if (value === "inherit") {
|
|
92
|
+
this.removeAttribute("contenteditable");
|
|
93
|
+
} else {
|
|
94
|
+
this.setAttribute("contenteditable", value);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
get isContentEditable() {
|
|
98
|
+
return this.contentEditable === "true";
|
|
99
|
+
}
|
|
100
|
+
// -- Layout stubs (return 0 — no layout engine) --
|
|
101
|
+
get offsetHeight() {
|
|
102
|
+
return 0;
|
|
103
|
+
}
|
|
104
|
+
get offsetWidth() {
|
|
105
|
+
return 0;
|
|
106
|
+
}
|
|
107
|
+
get offsetLeft() {
|
|
108
|
+
return 0;
|
|
109
|
+
}
|
|
110
|
+
get offsetTop() {
|
|
111
|
+
return 0;
|
|
112
|
+
}
|
|
113
|
+
get offsetParent() {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
get clientHeight() {
|
|
117
|
+
return 0;
|
|
118
|
+
}
|
|
119
|
+
get clientWidth() {
|
|
120
|
+
return 0;
|
|
121
|
+
}
|
|
122
|
+
get clientLeft() {
|
|
123
|
+
return 0;
|
|
124
|
+
}
|
|
125
|
+
get clientTop() {
|
|
126
|
+
return 0;
|
|
127
|
+
}
|
|
128
|
+
get scrollHeight() {
|
|
129
|
+
return 0;
|
|
130
|
+
}
|
|
131
|
+
get scrollWidth() {
|
|
132
|
+
return 0;
|
|
133
|
+
}
|
|
134
|
+
get scrollTop() {
|
|
135
|
+
return 0;
|
|
136
|
+
}
|
|
137
|
+
set scrollTop(_value) {
|
|
138
|
+
}
|
|
139
|
+
get scrollLeft() {
|
|
140
|
+
return 0;
|
|
141
|
+
}
|
|
142
|
+
set scrollLeft(_value) {
|
|
143
|
+
}
|
|
144
|
+
// -- Interaction methods --
|
|
145
|
+
click() {
|
|
146
|
+
this.dispatchEvent(new Event("click", { bubbles: true, cancelable: true }));
|
|
147
|
+
}
|
|
148
|
+
blur() {
|
|
149
|
+
this.dispatchEvent(new Event("blur"));
|
|
150
|
+
}
|
|
151
|
+
focus() {
|
|
152
|
+
this.dispatchEvent(new Event("focus"));
|
|
153
|
+
}
|
|
154
|
+
// -- on* event handler properties --
|
|
155
|
+
// Following happy-dom pattern: stored in propertyEventListeners Map,
|
|
156
|
+
// dispatched automatically by Element.dispatchEvent override
|
|
157
|
+
get onclick() {
|
|
158
|
+
return this[PS.propertyEventListeners].get("onclick") ?? null;
|
|
159
|
+
}
|
|
160
|
+
set onclick(value) {
|
|
161
|
+
this[PS.propertyEventListeners].set("onclick", value);
|
|
162
|
+
}
|
|
163
|
+
get ondblclick() {
|
|
164
|
+
return this[PS.propertyEventListeners].get("ondblclick") ?? null;
|
|
165
|
+
}
|
|
166
|
+
set ondblclick(value) {
|
|
167
|
+
this[PS.propertyEventListeners].set("ondblclick", value);
|
|
168
|
+
}
|
|
169
|
+
get onload() {
|
|
170
|
+
return this[PS.propertyEventListeners].get("onload") ?? null;
|
|
171
|
+
}
|
|
172
|
+
set onload(value) {
|
|
173
|
+
this[PS.propertyEventListeners].set("onload", value);
|
|
174
|
+
}
|
|
175
|
+
get onerror() {
|
|
176
|
+
return this[PS.propertyEventListeners].get("onerror") ?? null;
|
|
177
|
+
}
|
|
178
|
+
set onerror(value) {
|
|
179
|
+
this[PS.propertyEventListeners].set("onerror", value);
|
|
180
|
+
}
|
|
181
|
+
get onabort() {
|
|
182
|
+
return this[PS.propertyEventListeners].get("onabort") ?? null;
|
|
183
|
+
}
|
|
184
|
+
set onabort(value) {
|
|
185
|
+
this[PS.propertyEventListeners].set("onabort", value);
|
|
186
|
+
}
|
|
187
|
+
get onfocus() {
|
|
188
|
+
return this[PS.propertyEventListeners].get("onfocus") ?? null;
|
|
189
|
+
}
|
|
190
|
+
set onfocus(value) {
|
|
191
|
+
this[PS.propertyEventListeners].set("onfocus", value);
|
|
192
|
+
}
|
|
193
|
+
get onblur() {
|
|
194
|
+
return this[PS.propertyEventListeners].get("onblur") ?? null;
|
|
195
|
+
}
|
|
196
|
+
set onblur(value) {
|
|
197
|
+
this[PS.propertyEventListeners].set("onblur", value);
|
|
198
|
+
}
|
|
199
|
+
get onchange() {
|
|
200
|
+
return this[PS.propertyEventListeners].get("onchange") ?? null;
|
|
201
|
+
}
|
|
202
|
+
set onchange(value) {
|
|
203
|
+
this[PS.propertyEventListeners].set("onchange", value);
|
|
204
|
+
}
|
|
205
|
+
get oninput() {
|
|
206
|
+
return this[PS.propertyEventListeners].get("oninput") ?? null;
|
|
207
|
+
}
|
|
208
|
+
set oninput(value) {
|
|
209
|
+
this[PS.propertyEventListeners].set("oninput", value);
|
|
210
|
+
}
|
|
211
|
+
get onsubmit() {
|
|
212
|
+
return this[PS.propertyEventListeners].get("onsubmit") ?? null;
|
|
213
|
+
}
|
|
214
|
+
set onsubmit(value) {
|
|
215
|
+
this[PS.propertyEventListeners].set("onsubmit", value);
|
|
216
|
+
}
|
|
217
|
+
get onreset() {
|
|
218
|
+
return this[PS.propertyEventListeners].get("onreset") ?? null;
|
|
219
|
+
}
|
|
220
|
+
set onreset(value) {
|
|
221
|
+
this[PS.propertyEventListeners].set("onreset", value);
|
|
222
|
+
}
|
|
223
|
+
get onscroll() {
|
|
224
|
+
return this[PS.propertyEventListeners].get("onscroll") ?? null;
|
|
225
|
+
}
|
|
226
|
+
set onscroll(value) {
|
|
227
|
+
this[PS.propertyEventListeners].set("onscroll", value);
|
|
228
|
+
}
|
|
229
|
+
get onresize() {
|
|
230
|
+
return this[PS.propertyEventListeners].get("onresize") ?? null;
|
|
231
|
+
}
|
|
232
|
+
set onresize(value) {
|
|
233
|
+
this[PS.propertyEventListeners].set("onresize", value);
|
|
234
|
+
}
|
|
235
|
+
// Mouse events
|
|
236
|
+
get onmousedown() {
|
|
237
|
+
return this[PS.propertyEventListeners].get("onmousedown") ?? null;
|
|
238
|
+
}
|
|
239
|
+
set onmousedown(value) {
|
|
240
|
+
this[PS.propertyEventListeners].set("onmousedown", value);
|
|
241
|
+
}
|
|
242
|
+
get onmouseup() {
|
|
243
|
+
return this[PS.propertyEventListeners].get("onmouseup") ?? null;
|
|
244
|
+
}
|
|
245
|
+
set onmouseup(value) {
|
|
246
|
+
this[PS.propertyEventListeners].set("onmouseup", value);
|
|
247
|
+
}
|
|
248
|
+
get onmousemove() {
|
|
249
|
+
return this[PS.propertyEventListeners].get("onmousemove") ?? null;
|
|
250
|
+
}
|
|
251
|
+
set onmousemove(value) {
|
|
252
|
+
this[PS.propertyEventListeners].set("onmousemove", value);
|
|
253
|
+
}
|
|
254
|
+
get onmouseover() {
|
|
255
|
+
return this[PS.propertyEventListeners].get("onmouseover") ?? null;
|
|
256
|
+
}
|
|
257
|
+
set onmouseover(value) {
|
|
258
|
+
this[PS.propertyEventListeners].set("onmouseover", value);
|
|
259
|
+
}
|
|
260
|
+
get onmouseout() {
|
|
261
|
+
return this[PS.propertyEventListeners].get("onmouseout") ?? null;
|
|
262
|
+
}
|
|
263
|
+
set onmouseout(value) {
|
|
264
|
+
this[PS.propertyEventListeners].set("onmouseout", value);
|
|
265
|
+
}
|
|
266
|
+
get onmouseenter() {
|
|
267
|
+
return this[PS.propertyEventListeners].get("onmouseenter") ?? null;
|
|
268
|
+
}
|
|
269
|
+
set onmouseenter(value) {
|
|
270
|
+
this[PS.propertyEventListeners].set("onmouseenter", value);
|
|
271
|
+
}
|
|
272
|
+
get onmouseleave() {
|
|
273
|
+
return this[PS.propertyEventListeners].get("onmouseleave") ?? null;
|
|
274
|
+
}
|
|
275
|
+
set onmouseleave(value) {
|
|
276
|
+
this[PS.propertyEventListeners].set("onmouseleave", value);
|
|
277
|
+
}
|
|
278
|
+
get oncontextmenu() {
|
|
279
|
+
return this[PS.propertyEventListeners].get("oncontextmenu") ?? null;
|
|
280
|
+
}
|
|
281
|
+
set oncontextmenu(value) {
|
|
282
|
+
this[PS.propertyEventListeners].set("oncontextmenu", value);
|
|
283
|
+
}
|
|
284
|
+
// Keyboard events
|
|
285
|
+
get onkeydown() {
|
|
286
|
+
return this[PS.propertyEventListeners].get("onkeydown") ?? null;
|
|
287
|
+
}
|
|
288
|
+
set onkeydown(value) {
|
|
289
|
+
this[PS.propertyEventListeners].set("onkeydown", value);
|
|
290
|
+
}
|
|
291
|
+
get onkeyup() {
|
|
292
|
+
return this[PS.propertyEventListeners].get("onkeyup") ?? null;
|
|
293
|
+
}
|
|
294
|
+
set onkeyup(value) {
|
|
295
|
+
this[PS.propertyEventListeners].set("onkeyup", value);
|
|
296
|
+
}
|
|
297
|
+
// Touch events
|
|
298
|
+
get ontouchstart() {
|
|
299
|
+
return this[PS.propertyEventListeners].get("ontouchstart") ?? null;
|
|
300
|
+
}
|
|
301
|
+
set ontouchstart(value) {
|
|
302
|
+
this[PS.propertyEventListeners].set("ontouchstart", value);
|
|
303
|
+
}
|
|
304
|
+
get ontouchend() {
|
|
305
|
+
return this[PS.propertyEventListeners].get("ontouchend") ?? null;
|
|
306
|
+
}
|
|
307
|
+
set ontouchend(value) {
|
|
308
|
+
this[PS.propertyEventListeners].set("ontouchend", value);
|
|
309
|
+
}
|
|
310
|
+
get ontouchmove() {
|
|
311
|
+
return this[PS.propertyEventListeners].get("ontouchmove") ?? null;
|
|
312
|
+
}
|
|
313
|
+
set ontouchmove(value) {
|
|
314
|
+
this[PS.propertyEventListeners].set("ontouchmove", value);
|
|
315
|
+
}
|
|
316
|
+
// Pointer events
|
|
317
|
+
get onpointerdown() {
|
|
318
|
+
return this[PS.propertyEventListeners].get("onpointerdown") ?? null;
|
|
319
|
+
}
|
|
320
|
+
set onpointerdown(value) {
|
|
321
|
+
this[PS.propertyEventListeners].set("onpointerdown", value);
|
|
322
|
+
}
|
|
323
|
+
get onpointerup() {
|
|
324
|
+
return this[PS.propertyEventListeners].get("onpointerup") ?? null;
|
|
325
|
+
}
|
|
326
|
+
set onpointerup(value) {
|
|
327
|
+
this[PS.propertyEventListeners].set("onpointerup", value);
|
|
328
|
+
}
|
|
329
|
+
get onpointermove() {
|
|
330
|
+
return this[PS.propertyEventListeners].get("onpointermove") ?? null;
|
|
331
|
+
}
|
|
332
|
+
set onpointermove(value) {
|
|
333
|
+
this[PS.propertyEventListeners].set("onpointermove", value);
|
|
334
|
+
}
|
|
335
|
+
// -- Clone --
|
|
336
|
+
cloneNode(deep = false) {
|
|
337
|
+
return super.cloneNode(deep);
|
|
338
|
+
}
|
|
339
|
+
get [Symbol.toStringTag]() {
|
|
340
|
+
return "HTMLElement";
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
export {
|
|
344
|
+
CSSStyleDeclaration,
|
|
345
|
+
HTMLElement
|
|
346
|
+
};
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import GLib from "@girs/glib-2.0";
|
|
2
|
+
import GdkPixbuf from "@girs/gdkpixbuf-2.0";
|
|
3
|
+
import { Event } from "@gjsify/dom-events";
|
|
4
|
+
import { HTMLElement } from "./html-element.js";
|
|
5
|
+
import * as PropertySymbol from "./property-symbol.js";
|
|
6
|
+
import { NamespaceURI } from "./namespace-uri.js";
|
|
7
|
+
import System from "system";
|
|
8
|
+
class HTMLImageElement extends HTMLElement {
|
|
9
|
+
constructor() {
|
|
10
|
+
super();
|
|
11
|
+
this._complete = false;
|
|
12
|
+
this._naturalHeight = 0;
|
|
13
|
+
this._naturalWidth = 0;
|
|
14
|
+
this[PropertySymbol.tagName] = "IMG";
|
|
15
|
+
this[PropertySymbol.localName] = "img";
|
|
16
|
+
this[PropertySymbol.namespaceURI] = NamespaceURI.html;
|
|
17
|
+
}
|
|
18
|
+
// -- Read-only properties --
|
|
19
|
+
get complete() {
|
|
20
|
+
return this._complete;
|
|
21
|
+
}
|
|
22
|
+
get naturalHeight() {
|
|
23
|
+
return this._naturalHeight;
|
|
24
|
+
}
|
|
25
|
+
get naturalWidth() {
|
|
26
|
+
return this._naturalWidth;
|
|
27
|
+
}
|
|
28
|
+
get currentSrc() {
|
|
29
|
+
return this.src;
|
|
30
|
+
}
|
|
31
|
+
get x() {
|
|
32
|
+
return 0;
|
|
33
|
+
}
|
|
34
|
+
get y() {
|
|
35
|
+
return 0;
|
|
36
|
+
}
|
|
37
|
+
// -- Attribute-backed string properties --
|
|
38
|
+
get alt() {
|
|
39
|
+
return this.getAttribute("alt") ?? "";
|
|
40
|
+
}
|
|
41
|
+
set alt(value) {
|
|
42
|
+
this.setAttribute("alt", value);
|
|
43
|
+
}
|
|
44
|
+
get crossOrigin() {
|
|
45
|
+
return this.getAttribute("crossorigin");
|
|
46
|
+
}
|
|
47
|
+
set crossOrigin(value) {
|
|
48
|
+
if (value === null) {
|
|
49
|
+
this.removeAttribute("crossorigin");
|
|
50
|
+
} else {
|
|
51
|
+
this.setAttribute("crossorigin", value);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
get decoding() {
|
|
55
|
+
return this.getAttribute("decoding") ?? "auto";
|
|
56
|
+
}
|
|
57
|
+
set decoding(value) {
|
|
58
|
+
this.setAttribute("decoding", value);
|
|
59
|
+
}
|
|
60
|
+
get loading() {
|
|
61
|
+
const value = this.getAttribute("loading");
|
|
62
|
+
if (value === "lazy" || value === "eager") return value;
|
|
63
|
+
return "auto";
|
|
64
|
+
}
|
|
65
|
+
set loading(value) {
|
|
66
|
+
this.setAttribute("loading", value);
|
|
67
|
+
}
|
|
68
|
+
get referrerPolicy() {
|
|
69
|
+
return this.getAttribute("referrerpolicy") ?? "";
|
|
70
|
+
}
|
|
71
|
+
set referrerPolicy(value) {
|
|
72
|
+
this.setAttribute("referrerpolicy", value);
|
|
73
|
+
}
|
|
74
|
+
get sizes() {
|
|
75
|
+
return this.getAttribute("sizes") ?? "";
|
|
76
|
+
}
|
|
77
|
+
set sizes(value) {
|
|
78
|
+
this.setAttribute("sizes", value);
|
|
79
|
+
}
|
|
80
|
+
get src() {
|
|
81
|
+
return this.getAttribute("src") ?? "";
|
|
82
|
+
}
|
|
83
|
+
set src(src) {
|
|
84
|
+
this.setAttribute("src", src);
|
|
85
|
+
const dir = GLib.path_get_dirname(System.programInvocationName);
|
|
86
|
+
const filename = GLib.build_filenamev([dir, src]);
|
|
87
|
+
try {
|
|
88
|
+
this._pixbuf = GdkPixbuf.Pixbuf.new_from_file(filename);
|
|
89
|
+
this._naturalWidth = this._pixbuf.get_width();
|
|
90
|
+
this._naturalHeight = this._pixbuf.get_height();
|
|
91
|
+
this._complete = true;
|
|
92
|
+
this.dispatchEvent(new Event("load"));
|
|
93
|
+
} catch (_error) {
|
|
94
|
+
this._complete = true;
|
|
95
|
+
this.dispatchEvent(new Event("error"));
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
get srcset() {
|
|
99
|
+
return this.getAttribute("srcset") ?? "";
|
|
100
|
+
}
|
|
101
|
+
set srcset(value) {
|
|
102
|
+
this.setAttribute("srcset", value);
|
|
103
|
+
}
|
|
104
|
+
get useMap() {
|
|
105
|
+
return this.getAttribute("usemap") ?? "";
|
|
106
|
+
}
|
|
107
|
+
set useMap(value) {
|
|
108
|
+
this.setAttribute("usemap", value);
|
|
109
|
+
}
|
|
110
|
+
// -- Attribute-backed numeric properties --
|
|
111
|
+
get height() {
|
|
112
|
+
if (this._pixbuf) {
|
|
113
|
+
return this._pixbuf.get_height();
|
|
114
|
+
}
|
|
115
|
+
const attr = this.getAttribute("height");
|
|
116
|
+
return attr !== null ? Number(attr) : 0;
|
|
117
|
+
}
|
|
118
|
+
set height(value) {
|
|
119
|
+
this.setAttribute("height", String(value));
|
|
120
|
+
}
|
|
121
|
+
get width() {
|
|
122
|
+
if (this._pixbuf) {
|
|
123
|
+
return this._pixbuf.get_width();
|
|
124
|
+
}
|
|
125
|
+
const attr = this.getAttribute("width");
|
|
126
|
+
return attr !== null ? Number(attr) : 0;
|
|
127
|
+
}
|
|
128
|
+
set width(value) {
|
|
129
|
+
this.setAttribute("width", String(value));
|
|
130
|
+
}
|
|
131
|
+
// -- Attribute-backed boolean property --
|
|
132
|
+
get isMap() {
|
|
133
|
+
return this.hasAttribute("ismap");
|
|
134
|
+
}
|
|
135
|
+
set isMap(value) {
|
|
136
|
+
if (value) {
|
|
137
|
+
this.setAttribute("ismap", "");
|
|
138
|
+
} else {
|
|
139
|
+
this.removeAttribute("ismap");
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
// -- Methods --
|
|
143
|
+
/**
|
|
144
|
+
* Decode the image. Returns a promise that resolves when the image is decoded.
|
|
145
|
+
*/
|
|
146
|
+
decode() {
|
|
147
|
+
return Promise.resolve();
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Clone this node.
|
|
151
|
+
*/
|
|
152
|
+
cloneNode(deep = false) {
|
|
153
|
+
return super.cloneNode(deep);
|
|
154
|
+
}
|
|
155
|
+
// -- GJS-specific extensions --
|
|
156
|
+
/**
|
|
157
|
+
* Get the pixels of the loaded GdkPixbuf as ImageData.
|
|
158
|
+
* Always returns RGBA (4 channels) — matches standard browser ImageData behaviour
|
|
159
|
+
* and what WebGL expects for texSubImage2D with format=RGBA.
|
|
160
|
+
* JPEG and other non-alpha formats are promoted to RGBA via add_alpha().
|
|
161
|
+
*/
|
|
162
|
+
getImageData() {
|
|
163
|
+
if (!this._pixbuf) return null;
|
|
164
|
+
const rgba = this._pixbuf.get_has_alpha() ? this._pixbuf : this._pixbuf.add_alpha(false, 0, 0, 0) ?? this._pixbuf;
|
|
165
|
+
return {
|
|
166
|
+
colorSpace: "srgb",
|
|
167
|
+
data: new Uint8ClampedArray(rgba.get_pixels()),
|
|
168
|
+
height: rgba.get_height(),
|
|
169
|
+
width: rgba.get_width()
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Check if this image is backed by a GdkPixbuf.
|
|
174
|
+
*/
|
|
175
|
+
isPixbuf() {
|
|
176
|
+
return !!this._pixbuf;
|
|
177
|
+
}
|
|
178
|
+
get [Symbol.toStringTag]() {
|
|
179
|
+
return "HTMLImageElement";
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
export {
|
|
183
|
+
HTMLImageElement
|
|
184
|
+
};
|
package/lib/esm/image.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { HTMLImageElement } from "./html-image-element.js";
|
|
2
|
+
class Image extends HTMLImageElement {
|
|
3
|
+
/**
|
|
4
|
+
* Constructor.
|
|
5
|
+
*
|
|
6
|
+
* @param [width] Width.
|
|
7
|
+
* @param [height] Height.
|
|
8
|
+
*/
|
|
9
|
+
constructor(width = null, height = null) {
|
|
10
|
+
super();
|
|
11
|
+
if (width !== null) {
|
|
12
|
+
this.width = width;
|
|
13
|
+
}
|
|
14
|
+
if (height !== null) {
|
|
15
|
+
this.height = height;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export {
|
|
20
|
+
HTMLImageElement,
|
|
21
|
+
Image,
|
|
22
|
+
Image as default
|
|
23
|
+
};
|