@pageboard/html 0.11.26 → 0.11.27
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/elements/image.js +2 -8
- package/package.json +1 -1
- package/ui/image.css +0 -7
- package/ui/image.js +35 -15
- package/ui/loading.css +1 -0
package/elements/image.js
CHANGED
|
@@ -131,14 +131,11 @@ exports.image = {
|
|
|
131
131
|
html: `<element-image
|
|
132
132
|
class="[display.fit|or:none] [display.horizontal|or:] [display.vertical|or:]"
|
|
133
133
|
alt="[alt]"
|
|
134
|
-
data-src="[url
|
|
134
|
+
data-src="[url]"
|
|
135
135
|
data-crop="[crop.x|or:50];[crop.y|or:50];[crop.width|or:100];[crop.height|or:100];[crop.zoom|or:100]"
|
|
136
136
|
>
|
|
137
137
|
<div block-content="legend"></div>
|
|
138
138
|
</element-image>`,
|
|
139
|
-
resources: {
|
|
140
|
-
empty: '../ui/empty.png'
|
|
141
|
-
},
|
|
142
139
|
stylesheets: [
|
|
143
140
|
'../ui/loading.css',
|
|
144
141
|
'../ui/image.css'
|
|
@@ -281,7 +278,7 @@ exports.inlineImage = {
|
|
|
281
278
|
group: "inline",
|
|
282
279
|
tag: "img",
|
|
283
280
|
html: `<img is="element-img"
|
|
284
|
-
data-src="[url
|
|
281
|
+
data-src="[url]"
|
|
285
282
|
data-crop="[crop.x];[crop.y];[crop.width];[crop.height];[crop.zoom]"
|
|
286
283
|
alt="" class="ui inline image
|
|
287
284
|
[display.avatar|?]
|
|
@@ -290,9 +287,6 @@ exports.inlineImage = {
|
|
|
290
287
|
[display.spaced|?]
|
|
291
288
|
[display.floated|pre:floated ]
|
|
292
289
|
[display.align|post: aligned]" />`,
|
|
293
|
-
resources: {
|
|
294
|
-
empty: '../ui/empty.png'
|
|
295
|
-
},
|
|
296
290
|
stylesheets: [
|
|
297
291
|
'../lib/components/image.css'
|
|
298
292
|
],
|
package/package.json
CHANGED
package/ui/image.css
CHANGED
package/ui/image.js
CHANGED
|
@@ -98,12 +98,21 @@ class HTMLElementImage extends VirtualHTMLElement {
|
|
|
98
98
|
if (!meta || !meta.width || !meta.height) return;
|
|
99
99
|
this.dataset.width = meta.width;
|
|
100
100
|
this.dataset.height = meta.height;
|
|
101
|
-
if (!this.currentSrc)
|
|
101
|
+
if (!this.currentSrc) {
|
|
102
|
+
this.placeholder();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
get currentSrc() {
|
|
107
|
+
const cur = super.currentSrc;
|
|
108
|
+
if (!cur && this.src?.startsWith('data:')) return this.src;
|
|
109
|
+
else return cur;
|
|
102
110
|
}
|
|
111
|
+
|
|
103
112
|
reveal(state) {
|
|
104
113
|
const img = this.image;
|
|
105
114
|
if (!this.options.src) {
|
|
106
|
-
|
|
115
|
+
this.placeholder(true);
|
|
107
116
|
return;
|
|
108
117
|
}
|
|
109
118
|
const fit = this.fit;
|
|
@@ -157,23 +166,22 @@ class HTMLElementImage extends VirtualHTMLElement {
|
|
|
157
166
|
return this.promise;
|
|
158
167
|
}
|
|
159
168
|
captureLoad() {
|
|
160
|
-
this.promise
|
|
169
|
+
this.promise?.done();
|
|
161
170
|
this.classList.remove('loading');
|
|
162
171
|
this.fix(this.image);
|
|
163
172
|
}
|
|
164
173
|
captureError() {
|
|
165
|
-
this.promise
|
|
174
|
+
this.promise?.done();
|
|
166
175
|
this.classList.remove('loading');
|
|
167
176
|
this.classList.add('error');
|
|
168
177
|
this.placeholder();
|
|
169
178
|
}
|
|
170
|
-
placeholder() {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
179
|
+
placeholder(error) {
|
|
180
|
+
let { w, h } = this.dimensions;
|
|
181
|
+
if (Number.isNaN(w)) w = 320;
|
|
182
|
+
if (Number.isNaN(h)) h = 240;
|
|
174
183
|
this.image.src = "data:image/svg+xml," + encodeURIComponent(
|
|
175
|
-
`<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 ${w} ${h}"></svg>`
|
|
176
|
-
);
|
|
184
|
+
`<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 ${w} ${h}"><text text-anchor="middle" dominant-baseline="central" x="50%" y="50%" fill="#aaa">${error ? '∅' : ''}</text></svg>`);
|
|
177
185
|
}
|
|
178
186
|
}
|
|
179
187
|
|
|
@@ -190,15 +198,27 @@ class HTMLElementInlineImage extends HTMLImageElement {
|
|
|
190
198
|
get image() {
|
|
191
199
|
return this;
|
|
192
200
|
}
|
|
201
|
+
get currentSrc() {
|
|
202
|
+
const cur = super.currentSrc;
|
|
203
|
+
if (!cur && this.src?.startsWith('data:')) return this.src;
|
|
204
|
+
else return cur;
|
|
205
|
+
}
|
|
193
206
|
captureLoad() {
|
|
194
|
-
this.promise
|
|
207
|
+
this.promise?.done();
|
|
195
208
|
this.classList.remove('loading');
|
|
196
209
|
this.fix(this.image);
|
|
197
210
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
this.
|
|
201
|
-
this.
|
|
211
|
+
captureError() {
|
|
212
|
+
this.promise?.done();
|
|
213
|
+
this.classList.remove('loading');
|
|
214
|
+
this.placeholder(true);
|
|
215
|
+
}
|
|
216
|
+
placeholder(error) {
|
|
217
|
+
let { w, h } = this.dimensions;
|
|
218
|
+
w = Number.isNaN(w) ? 40 : w;
|
|
219
|
+
h = Number.isNaN(h) ? 30 : h;
|
|
220
|
+
this.setAttribute('src', "data:image/svg+xml," + encodeURIComponent(
|
|
221
|
+
`<svg xmlns="http://www.w3.org/2000/svg" width="${w}px" height="${h}px" viewBox="0 0 ${w} ${h}"><text text-anchor="middle" dominant-baseline="central" x="50%" y="50%" fill="#aaa">${error ? '∅' : ''}</text></svg>`));
|
|
202
222
|
}
|
|
203
223
|
}
|
|
204
224
|
|