-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.html
417 lines (417 loc) · 14.1 KB
/
index.html
1
2
3
4
5
6
7
8
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>
Image Resource
</title>
<script src="https://www.w3.org/Tools/respec/respec-w3c" class=
"remove"></script>
<script class="remove">
const respecConfig = {
mdn: false,
specStatus: "ED",
group: "webapps",
editors: [
{
name: "Aaron Gustafson",
company: "Microsoft Corporation",
companyURL: "https://microsoft.com/",
w3cid: 43672,
},
{
name: "Rayan Kanso",
company: "Google Inc.",
companyURL: "https://google.com/",
w3cid: 115452,
},
{
name: "Marcos Cáceres",
company: "W3C",
companyURL: "https://w3c.org/",
w3cid: 39125,
},
],
github: {
repoURL: "w3c/image-resource/",
branch: "main",
},
xref: "web-platform",
};
</script>
</head>
<body data-cite="ENCODING MIMESNIFF APPMANIFEST">
<h1 id="title">
Image Resource
</h1>
<section id="abstract">
<p>
This document defines the concept of an "image resource" and a
corresponding WebIDL {{ImageResource}} dictionary. Web APIs can use the
{{ImageResource}} dictionary to represent an image resource in contexts
where an `HTMLImageElement` is not suitable or available (e.g., in a
Worker).
</p>
</section>
<section id="sotd">
<p class="warning">
<strong>This specification is not stable.</strong> Implementors who are
not taking part in the discussions will find the specification changing
out from under them in incompatible ways.
</p>
</section>
<section>
<h2>
Introduction
</h2>
<p>
Web applications often accept developer-provided image resources to be
displayed outside of a HTML document (e.g., in the OS, in the browser
UI, etc.). This specification defines a WebIDL dictionary that
describes an image, and where that image resource can be fetched from.
The user agent can then use this extra information to choose an image
that is best suited to display on the end-user's device or most closely
matches the end-user's preferences or environment.
</p>
</section>
<section>
<h2>
Privacy and security considerations
</h2>
<p>
[=Fetching an image resource=] can reveal the user's IP address. It is
RECOMMENDED that user agents fetch the chosen [=image resources=] when
provided by the developer, and store them for re-use if needed. This
limits tracking the user's location over time.
</p>
</section>
<section>
<h2>
Image resource
</h2>
<p>
An <dfn data-export="">image resource</dfn> consists of:
</p>
<dl>
<dt>
<dfn data-dfn-for="image resource">src</dfn>
</dt>
<dd>
A [=URL=] from where to obtain the image data.
</dd>
<dt>
<dfn data-dfn-for="image resource">sizes</dfn>
</dt>
<dd>
An optional [=string=] representing the sizes of the image, expressed
using the same syntax as [^link^]'s [^link/sizes^] attribute.
</dd>
<dt>
<dfn data-dfn-for="image resource">type</dfn>
</dt>
<dd>
An optional [=image MIME type=].
</dd>
<dt>
<dfn data-dfn-for="image resource">label</dfn>
</dt>
<dd>
A [=string=] representing the accessible name of the image.
</dd>
</dl>
<p>
In an API, an [=image resource=] is represented as an {{ImageResource}}
dictionary.
</p>
<p>
In [[JSON]], [=image resource=] is represented as an object.
</p>
</section>
<section data-dfn-for="ImageResource">
<h2>
<dfn>ImageResource</dfn> dictionary
</h2>
<pre class="idl">
dictionary ImageResource {
required USVString src;
DOMString sizes;
DOMString type;
DOMString label;
};
</pre>
<section>
<h3>
<dfn>src</dfn> member
</h3>
<p>
The {{ImageResource/src}} of an {{ImageResource}} is a [=URL=] from
which a user agent can [=fetch=] image data.
</p>
</section>
<section data-cite="html">
<h3>
<dfn>sizes</dfn> member
</h3>
<p>
The {{ImageResource/sizes}} member is equivalent to a [^link^]
element's [^link/sizes^] attribute, and is processed in the same
manner.
</p>
<p>
When multiple {{ImageResource}} dictionaries are available, a user
agent MAY use the {{ImageResource/sizes}} value to decide which image
is most suitable for a display context (and ignore any that are
inappropriate).
</p>
<aside class="note">
When multiple {{ImageResource}} dictionaries are being used by an API
(e.g., in a WebIDL [=sequence=]), the specifications should indicate
if the order in which the dictionaries are passed is significant. As
a general rule, order is significant and "first match wins".
</aside>
<div class="example">
The {{ImageResource/sizes}} member allows for multiple
space-separated size values in order to accommodate image formats
(such as ICO) that can act as a container for multiple images of
varying dimensions.
<pre class="js">
const image = {
src: "path/to/image.ico",
sizes: "16x16 32x32 64x64",
type: "image/vnd.microsoft.icon",
};
some.api.doSomething(image);
</pre>
</div>
</section>
<section>
<h3>
<dfn>type</dfn> member
</h3>
<p>
The {{ImageResource/type}} member represents an [=image MIME Type=]
for the image resource. A user agent MAY ignore media types it does
not support.
</p>
<p>
There is no default [=MIME type=] for an {{ImageResource}}. The
{{ImageResource/type}} is purely advisory. User agents MUST use the
[=rules for sniffing images specifically=] to determine the
[=computed MIME type=] of an [=image resource=].
</p>
</section>
<section data-cite="WAI-ARIA">
<h3>
<dfn>label</dfn> member
</h3>
<p>
The {{ImageResource/label}} of an {{ImageResource}} is a [=string=]
that provides the <a data-cite=
"accname-1.2#dfn-accessible-name">accessible name</a> for the
associated image.
</p>
<p>
Implementors MUST [=derive the accessible name=] for every
{{ImageResource}} they expose to users.
</p>
<p>
Authors are strongly encouraged to add a {{ImageResource/label}}
unless the {{ImageResource}}’s [=accessible name=] can be inferred
from an <dfn>external label</dfn> in its context. For example, in the
context of a [=manifest=], the [=manifest/`name`=] (or
[=manifest/`short_name`=]) provides an [=external label=] for all
members of the [=manifest/`icons`=] array that don’t have a
{{ImageResource/label}} defined.
</p>
<p>
If neither an explicit {{ImageResource/label}} nor an [=external
label=] is provided, but the {{ImageResource/type}} supports
providing an [=embedded accessible name=], implementors MAY choose to
defer assigning the {{ImageResource/label}} until the
{{ImageResource/src}} has been fetched and processed. If the
{{ImageResource/src}} is found to provide an [=embedded accessible
name=], implementors MUST update the {{ImageResource/label}} to match
that value.
</p>
</section>
</section>
<section>
<h2>
Processing an `ImageResource` from an API
</h2>
<p>
The steps to <dfn data-export="">process an `ImageResource` from an
API</dfn> are given by the following algorithm. The algorithm takes an
{{ImageResource}} |input:ImageResource|. It returns an [=image
resource=].
</p>
<ol>
<li>Let |base URL| be the [=relevant settings object=]’s [=environment
settings object/api base url=] from where this dictionary is being
used.
</li>
<li>Let |image| be a new [=image resource=].
</li>
<li>Set |image|'s [=image resource/src=] to the result of [=URL
parser|URL parsing=] |input|.{{ImageResource/src}} and |base URL|. If
parsing the URL fails, throw a {{TypeError}}.
</li>
<li>If |input|'s {{ImageResource/sizes}} member is present:
<ol>
<li data-cite="html">Set |image|'s [=image resource/sizes=] to the
result of parsing |input|.{{ImageResource/sizes}} as if it was a
[^link/sizes^] attribute of a [^link^] element whose [^link/rel^]
attribute contains the token `icon`. If parsing fails, throw a
{{TypeError}}.
</li>
</ol>
</li>
<li>If |input|'s {{ImageResource/type}} member is present and not the
empty string:
<ol>
<li>If {{ImageResource/type}} is not an [=image MIME Type=], throw
a {{TypeError}}.
</li>
<li>Set |image|'s [=image resource/type=] to
|input|.{{ImageResource/type}}.
</li>
</ol>
</li>
<li>Set |image|'s [=image resource/label=] to the result of [=deriving
the accessible name=].
</li>
<li>Return |image|.
</li>
</ol>
</section>
<section>
<h2>
Processing an image resource from JSON
</h2>
<p>
To <dfn data-export="">process an image resource from JSON</dfn>, given
a JSON Object |input:object| and a [=URL=] |base:URL|. It returns an
[=ordered map=].
</p>
<ol>
<li>If |input| is not of type [=object=], return failure.
</li>
<li>If |input|["src"] is not of type [=string=], return failure.
</li>
<li>Let |src:URL| be the result of [=URL parser|parsing=]
|input|["src"] with |base| as the base URL.
</li>
<li>If |src| is failure, return failure.
</li>
<li>Let |image| be an new [=ordered map=].
</li>
<li>Set |image|["src"] to |src|.
</li>
<li>If type of |input|["sizes"] is a [=string=], and its length is
greater than zero:
<ol>
<li>Set |sizes:string| to the result of parsing |input|["sizes"] as
if it was a [^link/sizes^] attribute of a [^link^] element whose
[^link/rel^] attribute contains the token `icon`.
</li>
<li>If |sizes| is failure, return failure.
</li>
<li>Set |image|["sizes"] to |sizes|.
</li>
</ol>
</li>
<li>If |input|["type"] is a [=string=], and it has a length greater
than zero:
<ol>
<li>Let |mime| be the result of [=parse a mime type|parsing=]
|input|["type"].
</li>
<li>If |mime| is failure, return failure.
</li>
<li>Set |image|["type"] to the [=MIME type/essence=] of |mime|.
</li>
</ol>
</li>
<li>Set |image|["label"] to the result of [=deriving the accessible
name=].
</li>
<li>Return |image|.
</li>
</ol>
</section>
<section>
<h2>
Fetching an image resource
</h2>
<p>
The steps for <dfn data-export="">fetching an image resource</dfn> are
given by the following algorithm. The algorithm takes an [=image
resource=] |image|, and an optional [=Request=] |request|. It returns a
[=Response=].
</p>
<ol>
<li>If |request| is `undefined`:
<ol>
<li>Set |request| to a new [=Request=].
</li>
<li>Set [=request/URL=] to |image|'s [=image resource/src=].
</li>
<li>Set [=request/Destination=] to "image".
</li>
<li>Set [=request/Client=] to the context object's [=relevant
settings object=].
</li>
</ol>
</li>
<li>If |request|'s [=request/Client=] is null, throw a {{TypeError}}.
</li>
<li>Perform a [=fetch=] using |request| and return the [=Response=].
</li>
</ol>
<aside class="note">
[=request/Client=] is required here so the appropriate CSP can be
applied.
</aside>
</section>
<section>
<h2>
Deriving the accessible name
</h2>
<p>
The steps to <dfn data-lt="deriving the accessible name">derive the
accessible name</dfn> for an [=image resource=] |resource| are as
follows. It returns a [=string=].
</p>
<ol>
<li>If |resource|["label"] is a [=string=], return |input|["label"].
</li>
<li>Otherwise, if |image| provides an [=embedded accessible name=],
return the [=embedded accessible name=].
</li>
<li>Otherwise, if an [=external label=] can be substituted, return the
relevant [=external label=].
</li>
<li>Return "".
</li>
</ol>
</section>
<section>
<h2>
Examples of graphics formats supporting embedded accessible names
</h2>
<p>
Certain graphics formats support the inclusion of an <dfn>embedded
accessible name</dfn> as part of the image’s contents. Examples
include:
</p>
<ul>
<li data-cite="SVG">The [^title^] element in [=SVG=].
</li>
<li>Metadata in raster images (e.g., tiff:ImageDescription,
XMP:Description).
</li>
</ul>
</section>
<section id="conformance"></section>
</body>
</html>