@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 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|or:[$element.resources.empty]]"
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|or:[$element.resources.empty]]"
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pageboard/html",
3
- "version": "0.11.26",
3
+ "version": "0.11.27",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "repository": {
package/ui/image.css CHANGED
@@ -1,10 +1,3 @@
1
- img.loading[data-src]::after {
2
- content: none;
3
- }
4
- img.error::after {
5
- width: 100%;
6
- }
7
-
8
1
  element-image {
9
2
  display:flex;
10
3
  position:relative;
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) this.placeholder();
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
- img.removeAttribute('src');
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.done();
169
+ this.promise?.done();
161
170
  this.classList.remove('loading');
162
171
  this.fix(this.image);
163
172
  }
164
173
  captureError() {
165
- this.promise.done();
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
- const { w, h } = this.dimensions;
172
- this.image.width = w;
173
- this.image.height = h;
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.done();
207
+ this.promise?.done();
195
208
  this.classList.remove('loading');
196
209
  this.fix(this.image);
197
210
  }
198
- placeholder() {
199
- const { w, h } = this.dimensions;
200
- this.width = w;
201
- this.height = h;
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
 
package/ui/loading.css CHANGED
@@ -9,6 +9,7 @@
9
9
  width: 100%;
10
10
  top: 50%;
11
11
  margin-top: -0.5rem;
12
+ line-height: 1rem;
12
13
  }
13
14
 
14
15
  @keyframes spinner {