-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOverview.html
680 lines (622 loc) · 25 KB
/
Overview.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
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
<!DOCTYPE html><html lang="en"><head>
<meta charset="utf-8">
<meta name="generator" content="ReSpec 35.1.0">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<style>
dfn{cursor:pointer}
.dfn-panel{position:absolute;z-index:35;min-width:300px;max-width:500px;padding:.5em .75em;margin-top:.6em;font-family:"Helvetica Neue",sans-serif;font-size:small;background:#fff;background:var(--indextable-hover-bg,#fff);color:#000;color:var(--text,#000);box-shadow:0 1em 3em -.4em rgba(0,0,0,.3),0 0 1px 1px rgba(0,0,0,.05);box-shadow:0 1em 3em -.4em var(--tocsidebar-shadow,rgba(0,0,0,.3)),0 0 1px 1px var(--tocsidebar-shadow,rgba(0,0,0,.05));border-radius:2px}
.dfn-panel:not(.docked)>.caret{position:absolute;top:-9px}
.dfn-panel:not(.docked)>.caret::after,.dfn-panel:not(.docked)>.caret::before{content:"";position:absolute;border:10px solid transparent;border-top:0;border-bottom:10px solid #fff;border-bottom-color:var(--indextable-hover-bg,#fff);top:0}
.dfn-panel:not(.docked)>.caret::before{border-bottom:9px solid #a2a9b1;border-bottom-color:var(--indextable-hover-bg,#a2a9b1)}
.dfn-panel *{margin:0}
.dfn-panel b{display:block;color:#000;color:var(--text,#000);margin-top:.25em}
.dfn-panel ul a[href]{color:#333;color:var(--text,#333)}
.dfn-panel>div{display:flex}
.dfn-panel a.self-link{font-weight:700;margin-right:auto}
.dfn-panel .marker{padding:.1em;margin-left:.5em;border-radius:.2em;text-align:center;white-space:nowrap;font-size:90%;color:#040b1c}
.dfn-panel .marker.dfn-exported{background:#d1edfd;box-shadow:0 0 0 .125em #1ca5f940}
.dfn-panel .marker.idl-block{background:#8ccbf2;box-shadow:0 0 0 .125em #0670b161}
.dfn-panel a:not(:hover){text-decoration:none!important;border-bottom:none!important}
.dfn-panel a[href]:hover{border-bottom-width:1px}
.dfn-panel ul{padding:0}
.dfn-panel li{margin-left:1em}
.dfn-panel.docked{position:fixed;left:.5em;top:unset;bottom:2em;margin:0 auto;max-width:calc(100vw - .75em * 2 - .5em - .2em * 2);max-height:30vh;overflow:auto}
</style>
<title>IIFAA 分布式可信认证技术规范</title>
<style id="respec-mainstyle">
@keyframes pop{
0%{transform:scale(1,1)}
25%{transform:scale(1.25,1.25);opacity:.75}
100%{transform:scale(1,1)}
}
a.internalDFN{color:inherit;border-bottom:1px solid #99c;text-decoration:none}
a.externalDFN{color:inherit;border-bottom:1px dotted #ccc;text-decoration:none}
a.bibref{text-decoration:none}
.respec-offending-element:target{animation:pop .25s ease-in-out 0s 1}
.respec-offending-element,a[href].respec-offending-element{text-decoration:red wavy underline}
@supports not (text-decoration:red wavy underline){
.respec-offending-element:not(pre){display:inline-block}
.respec-offending-element{background:url(data:image/gif;base64,R0lGODdhBAADAPEAANv///8AAP///wAAACwAAAAABAADAEACBZQjmIAFADs=) bottom repeat-x}
}
#references :target{background:#eaf3ff;animation:pop .4s ease-in-out 0s 1}
cite .bibref{font-style:normal}
a[href].orcid{padding-left:4px;padding-right:4px}
a[href].orcid>svg{margin-bottom:-2px}
ol.tof,ul.tof{list-style:none outside none}
.caption{margin-top:.5em;font-style:italic}
#issue-summary>ul{column-count:2}
#issue-summary li{list-style:none;display:inline-block}
details.respec-tests-details{margin-left:1em;display:inline-block;vertical-align:top}
details.respec-tests-details>*{padding-right:2em}
details.respec-tests-details[open]{z-index:999999;position:absolute;border:thin solid #cad3e2;border-radius:.3em;background-color:#fff;padding-bottom:.5em}
details.respec-tests-details[open]>summary{border-bottom:thin solid #cad3e2;padding-left:1em;margin-bottom:1em;line-height:2em}
details.respec-tests-details>ul{width:100%;margin-top:-.3em}
details.respec-tests-details>li{padding-left:1em}
.self-link:hover{opacity:1;text-decoration:none;background-color:transparent}
aside.example .marker>a.self-link{color:inherit}
.header-wrapper{display:flex;align-items:baseline}
:is(h2,h3,h4,h5,h6):not(#toc>h2,#abstract>h2,#sotd>h2,.head>h2){position:relative;left:-.5em}
:is(h2,h3,h4,h5,h6):not(#toch2)+a.self-link{color:inherit;order:-1;position:relative;left:-1.1em;font-size:1rem;opacity:.5}
:is(h2,h3,h4,h5,h6)+a.self-link::before{content:"§";text-decoration:none;color:var(--heading-text)}
:is(h2,h3)+a.self-link{top:-.2em}
:is(h4,h5,h6)+a.self-link::before{color:#000}
@media (max-width:767px){
dd{margin-left:0}
}
@media print{
.removeOnSave{display:none}
}
.logo{
text-align: right;
right: 0;
width: 30px; /* or any other width you want */
height: 20px; /* or any other height you want */
}
.logo-container {
display: flex;
justify-content: flex-end; /* or flex-start if you want them aligned left */
}
.logo-1, .logo-2 {
float: right;
margin-left: 10px;
}
</style>
<meta name="color-scheme" content="light">
<meta name="description" content="本文件规定了IIFAA分布式可信认证参考模型、技术架构和功能、业务流程、安全要求和个人信息保护要求。">
<style>
var{position:relative;cursor:pointer}
var[data-type]::after,var[data-type]::before{position:absolute;left:50%;top:-6px;opacity:0;transition:opacity .4s;pointer-events:none}
var[data-type]::before{content:"";transform:translateX(-50%);border-width:4px 6px 0 6px;border-style:solid;border-color:transparent;border-top-color:#222}
var[data-type]::after{content:attr(data-type);transform:translateX(-50%) translateY(-100%);background:#222;text-align:center;font-family:"Dank Mono","Fira Code",monospace;font-style:normal;padding:6px;border-radius:3px;color:#daca88;text-indent:0;font-weight:400}
var[data-type]:hover::after,var[data-type]:hover::before{opacity:1}
</style>
<div class="head">
<div class="logo-container">
<a class="logo" href="https://www.iifaa.org.cn/index"><img class="logo-1" alt="IIFAA" height="88"
src="img/iifaa-logo.jpg" width="auto"></a>
<a class="logo" href="https://www.w3.org/community"><img class="logo-2" alt="W3C Community Group" height="68"
src="img/cgbg-logo.svg" width="auto" text-align: “right;></a>
</div>
<script id="initialUserConfig" type="application/json">{
"specStatus": "CG-DRAFT",
"shortName": "iifaa-did",
"editors": [
{
"name": "Wang Yongtao",
"company": "Ant Group",
"companyURL": "https://www.antgroup.com/"
},
{
"name": "Zhang Wu",
"company": "Ant Group",
"companyURL": "https://www.antgroup.com/"
},
{
"name": "Sun Weichao",
"company": "Ant Group",
"companyURL": "https://www.antgroup.com/"
},
{
"name": "Peng Jin",
"company": "Ant Group",
"companyURL": "https://www.antgroup.com/"
},
{
"name": "Lin Guanchen",
"company": "Ant Group",
"companyURL": "https://www.antgroup.com/"
},
{
"name": "Huang Lin",
"company": "Ant Group",
"companyURL": "https://www.antgroup.com/"
},
{
"name": "Wu Sijie",
"company": "Ant Group",
"companyURL": "https://www.antgroup.com/"
},
{
"name": "Xu Yijia",
"company": "Ant Group",
"companyURL": "https://www.antgroup.com/"
},
{
"name": "Lyu Lei",
"company": "National Engineering Research Center for Cryptography",
"companyURL": ""
},
{
"name": "Yin Yihua",
"company": "National Engineering Research Center for Cryptography",
"companyURL": ""
},
{
"name": "Lai Tao",
"company": "National Engineering Research Center for Cryptography",
"companyURL": ""
},
{
"name": "Fu Shan",
"company": "China Academy of Information and Communications Technology (CAICT)",
"companyURL": "http://www.catr.cn/"
},
{
"name": "Wei Fanxing",
"company": "China Academy of Information and Communications Technology (CAICT)",
"companyURL": "http://www.catr.cn/"
},
{
"name": "Yang Bo",
"company": "Beijing UnionPay Gold Card Technology Co., Ltd.",
"companyURL": "http://www.bctest.com/"
},
{
"name": "Zhang Yanchao",
"company": "Beijing UnionPay Gold Card Technology Co., Ltd.",
"companyURL": ""
},
{
"name": "Zhuang Huaiyu",
"company": "China Mobile Fintech Co. Ltd.",
"companyURL": ""
},
{
"name": "Guo Yanhong",
"company": "China Mobile Fintech Co. Ltd.",
"companyURL": ""
},
{
"name": "Li Zhichao",
"company": "Honor Terminal Co., Ltd.",
"companyURL": "https://www.honor.com/global/"
},
{
"name": "Luo Guangwen",
"company": "Honor Terminal Co., Ltd.",
"companyURL": "https://www.honor.com/global/"
},
{
"name": "Zhao Xiaona",
"company": "Honor Terminal Co., Ltd.",
"companyURL": "https://www.honor.com/global/"
},
{
"name": "Shi Xinling",
"company": "Ruift Co., Ltd.",
"companyURL": ""
},
{
"name": "Ju Mingqi",
"company": "Ruift Co., Ltd.",
"companyURL": ""
},
{
"name": "Wu Huacheng",
"company": "Vivo Communication Co., Ltd.",
"companyURL": ""
},
{
"name": "Liu Weihua",
"company": "Zhengzhou XindaJiean Information Technology Co., Ltd.",
"companyURL": "www.xdja.com"
},
{
"name": "Huang Xiaoni",
"company": "Beijing d-Ear Technologies Co., Ltd.",
"companyURL": "http://www.d-ear.com/"
},
{
"name": "Zheng Fang",
"company": "Beijing d-Ear Technologies Co., Ltd.",
"companyURL": "http://www.d-ear.com/"
},
{
"name": "Lyu Fang",
"company": "Cilent Service International, Inc.",
"companyURL": ""
},
{
"name": "Wu Yue",
"company": "Beijing Samsung Communication Technology Research Institute Co., Ltd.",
"companyURL": ""
},
{
"name": "Yang Chunlin",
"company": "Beijing Eyecool Technology Co, Ltd.",
"companyURL": "http://www.eyecool.cn/"
},
{
"name": "Wang Jun",
"company": "Beijing eSand Information Technology Co., Ltd.",
"companyURL": "https://www.esandinfo.com/"
},
{
"name": "Lu Ruyi",
"company": "Beijing eSand Information Technology Co., Ltd.",
"companyURL": "https://www.esandinfo.com/"
},
{
"name": "Zhang Shengyi",
"company": "Beijing eSand Information Technology Co., Ltd.",
"companyURL": "https://www.esandinfo.com/"
},
{
"name": "Li Angyang",
"company": "Beijing Allhopes Trusted Link Technology Co., Ltd.",
"companyURL": "www.allhopes.com"
},
{
"name": "Zhu Pengfei",
"company": "Feitian Technologies Co., Ltd.",
"companyURL": "https://www.ftsafe.com"
},
{
"name": "Meng Ru",
"company": "Koal Software, Inc.",
"companyURL": "http://www.koal.com/"
},
{
"name": "Cao Haihong",
"company": "Shanghai Paraview Software Co., Ltd.",
"companyURL": ""
},
{
"name": "Ping Zhenghai",
"company": "ZTE Corporation",
"companyURL": ""
},
{
"name": "Huang Xixin",
"company": "Meizu Technology Co., Ltd.",
"companyURL": ""
},
{
"name": "Wang Xiang",
"company": "Henan Province Information Group Co., Ltd.",
"companyURL": "https://www.hnxaca.com/"
},
{
"name": "Wu Huacheng",
"company": "Vivo Communication Co., Ltd.",
"companyURL": ""
}
],
"group": "cndid",
"publishISODate": "2024-12-19T00:00:00.000Z",
"generatedSubtitle": "Draft Community Group Report 19 December 2024"
}</script>
<link rel="stylesheet" href="https://www.w3.org/StyleSheets/TR/2021/cg-draft"></head>
<body data-new-gr-c-s-check-loaded="14.1179.0" data-gr-ext-installed="" class="h-entry informative">
<h1 id="title" class="title">IIFAA 分布式可信认证技术规范</h1>
<p id="w3c-state">
<a href="https://www.w3.org/standards/types#reports">Draft Community Group Report</a>
<time class="dt-published" datetime="2024-06-07">07 June 2024</time>
</p>
<dl>
<dt>Latest published version:</dt><dd>
<a href="https://www.w3.org/iifaa-did/">https://www.w3.org/iifaa-did/</a>
</dd>
<dt>Editor:</dt><dd class="editor p-author h-card vcard">
<span class="p-name fn">null</span>
</dd>
</dl>
<p class="copyright">
<a href="https://www.w3.org/policies/#copyright">Copyright</a>
©
2024
the Contributors to the IIFAA 分布式可信认证技术规范
Specification, published by <a href="https://www.iifaa.org.cn/index">IIFAA</a> and
<a href="https://www.w3.org/groups/cg/cndid">Chinese DID & VC Community Group</a> under the
<a href="https://www.w3.org/community/about/agreements/cla/">W3C Community Contributor License Agreement (CLA)</a>. A human-readable
<a href="https://www.w3.org/community/about/agreements/cla-deed/">summary</a>
is available.
</p>
<hr title="Separator for header">
</div>
<section id="abstract" class="introductory"><h2>Abstract</h2>
<p>本文件规定了IIFAA分布式可信认证参考模型、技术架构和功能、业务流程、安全要求和个人信息保护要求。</p>
<p>本文件适用于IIFAA分布式可信认证研发设计、部署应用和测试认证等相关活动。
</p>
</section>
<section id="sotd" class="introductory"><h2>Status of This Document</h2><p>
This specification was published by the <a href="https://www.iifaa.org.cn/index">IIFAA</a> and
<a href="https://www.w3.org/groups/cg/cndid">Chinese DID & VC Community Group</a>. It is not a W3C Standard nor is it
on the W3C Standards Track.
Please note that under the
<a href="https://www.w3.org/community/about/agreements/cla/">W3C Community Contributor License Agreement (CLA)</a>
there is a limited opt-out and other conditions apply.
Learn more about
<a href="https://www.w3.org/community/">W3C Community and Business Groups</a>.
</p>
</section><nav id="toc"><h2 class="introductory" id="table-of-contents">Table of Contents</h2><ol class="toc"><li class="tocline"><a class="tocxref" href="#abstract">Abstract</a></li><li class="tocline"><a class="tocxref" href="#sotd">Status of This Document</a></li><li class="tocline"><a class="tocxref" href="#introduction"><bdi class="secno">1. </bdi>Introduction</a></li><li class="tocline"><a class="tocxref" href="#generatedID"><bdi class="secno">2. </bdi>总体框架</a><ol class="toc"><li class="tocline"><a class="tocxref" href="#generatedID-0"><bdi class="secno">2.1 </bdi>参考模型</a></li><li class="tocline"><a class="tocxref" href="#generatedID-1"><bdi class="secno">2.2 </bdi>凭证颁发方</a></li></ol></li></ol></nav>
<section id="introduction"><div class="header-wrapper"><h2 id="x1-introduction"><bdi class="secno">1. </bdi>Introduction</h2><a class="self-link" href="#introduction" aria-label="Permalink for Section 1."></a></div>
<p>本文件规定了IIFAA分布式可信认证参考模型、技术架构和功能、业务流程、安全要求和个人信息保护要求。</p>
<p>本文件适用于IIFAA分布式可信认证研发设计、部署应用和测试认证等相关活动。
</p>
</section>
<section id="generatedID"><div class="header-wrapper"><h2 id="x2"><bdi class="secno">2. </bdi>总体框架</h2><a class="self-link" href="#generatedID" aria-label="Permalink for Section 2."></a></div>
<section id="generatedID-0"><div class="header-wrapper"><h3 id="x2-1"><bdi class="secno">2.1 </bdi>参考模型</h3><a class="self-link" href="#generatedID-0" aria-label="Permalink for Section 2.1"></a></div>
<p>IIFAA分布式可信认证服务参考模型如图1所示,有四个关键角色:凭证颁发方、业务服务提供方、
身份服务提供方、DID持有方,两类关键数据:可验证凭证、可验证表达,一个关键基础设施:IIFAA分
布式可信认证基础设施(云链)。</p>
<div><img src=""><p>图 1 参考模型</p></div>
<p>IIFAA分布式可信认证服务具体包括:</p>
<ul>
<li>
分布式可信认证体系中的机构或者个人都需要通过身份服务提供方注册 DID 并将含身份公钥的分布式身份文档上链存证;
</li>
<li>
经过用户主动申请,凭证颁发方为用户签发可验证凭证到用户端侧加密存储;
</li>
<li>
当用户需要在特定业务场景出示相关凭证时,经由用户授权后在用户端侧将可验证表达组装签发成可验证表达并提交给业务服务提供方;
</li>
<li>
业务服务提供方通过基础设施获取用户和凭证颁发方的身份公钥,依次进行可验证表达的用户授权验证和凭证颁发方身份验证,验证通过后进一步判断声明内容满足业务场景要求后即可提供场景服务。
</li>
</ul>
</section>
<section id="generatedID-1"><div class="header-wrapper"><h3 id="x2-2"><bdi class="secno">2.2 </bdi>凭证颁发方</h3><a class="self-link" href="#generatedID-1" aria-label="Permalink for Section 2.2"></a></div>
<p>凭证颁发方要求如下:</p>
</section>
</section>
<script>
// <![CDATA[ <-- For SVG support
if ('WebSocket' in window) {
(function () {
function refreshCSS() {
var sheets = [].slice.call(document.getElementsByTagName("link"));
var head = document.getElementsByTagName("head")[0];
for (var i = 0; i < sheets.length; ++i) {
var elem = sheets[i];
var parent = elem.parentElement || head;
parent.removeChild(elem);
var rel = elem.rel;
if (elem.href && typeof rel != "string" || rel.length == 0 || rel.toLowerCase() == "stylesheet") {
var url = elem.href.replace(/(&|\?)_cacheOverride=\d+/, '');
elem.href = url + (url.indexOf('?') >= 0 ? '&' : '?') + '_cacheOverride=' + (new Date().valueOf());
}
parent.appendChild(elem);
}
}
var protocol = window.location.protocol === 'http:' ? 'ws://' : 'wss://';
var address = protocol + window.location.host + window.location.pathname + '/ws';
var socket = new WebSocket(address);
socket.onmessage = function (msg) {
if (msg.data == 'reload') window.location.reload();
else if (msg.data == 'refreshcss') refreshCSS();
};
if (sessionStorage && !sessionStorage.getItem('IsThisFirstTime_Log_From_LiveServer')) {
console.log('Live reload enabled.');
sessionStorage.setItem('IsThisFirstTime_Log_From_LiveServer', true);
}
})();
}
else {
console.error('Upgrade your browser. This Browser is NOT supported WebSocket for Live-Reloading.');
}
// ]]>
</script>
<p role="navigation" id="back-to-top">
<a href="#title"><abbr title="Back to Top">↑</abbr></a>
</p><script id="respec-dfn-panel">(() => {
// @ts-check
if (document.respec) {
document.respec.ready.then(setupPanel);
} else {
setupPanel();
}
function setupPanel() {
const listener = panelListener();
document.body.addEventListener("keydown", listener);
document.body.addEventListener("click", listener);
}
function panelListener() {
/** @type {HTMLElement} */
let panel = null;
return event => {
const { target, type } = event;
if (!(target instanceof HTMLElement)) return;
// For keys, we only care about Enter key to activate the panel
// otherwise it's activated via a click.
if (type === "keydown" && event.key !== "Enter") return;
const action = deriveAction(event);
switch (action) {
case "show": {
hidePanel(panel);
/** @type {HTMLElement} */
const dfn = target.closest("dfn, .index-term");
panel = document.getElementById(`dfn-panel-for-${dfn.id}`);
const coords = deriveCoordinates(event);
displayPanel(dfn, panel, coords);
break;
}
case "dock": {
panel.style.left = null;
panel.style.top = null;
panel.classList.add("docked");
break;
}
case "hide": {
hidePanel(panel);
panel = null;
break;
}
}
};
}
/**
* @param {MouseEvent|KeyboardEvent} event
*/
function deriveCoordinates(event) {
const target = /** @type HTMLElement */ (event.target);
// We prevent synthetic AT clicks from putting
// the dialog in a weird place. The AT events sometimes
// lack coordinates, so they have clientX/Y = 0
const rect = target.getBoundingClientRect();
if (
event instanceof MouseEvent &&
event.clientX >= rect.left &&
event.clientY >= rect.top
) {
// The event probably happened inside the bounding rect...
return { x: event.clientX, y: event.clientY };
}
// Offset to the middle of the element
const x = rect.x + rect.width / 2;
// Placed at the bottom of the element
const y = rect.y + rect.height;
return { x, y };
}
/**
* @param {Event} event
*/
function deriveAction(event) {
const target = /** @type {HTMLElement} */ (event.target);
const hitALink = !!target.closest("a");
if (target.closest("dfn:not([data-cite]), .index-term")) {
return hitALink ? "none" : "show";
}
if (target.closest(".dfn-panel")) {
if (hitALink) {
return target.classList.contains("self-link") ? "hide" : "dock";
}
const panel = target.closest(".dfn-panel");
return panel.classList.contains("docked") ? "hide" : "none";
}
if (document.querySelector(".dfn-panel:not([hidden])")) {
return "hide";
}
return "none";
}
/**
* @param {HTMLElement} dfn
* @param {HTMLElement} panel
* @param {{ x: number, y: number }} clickPosition
*/
function displayPanel(dfn, panel, { x, y }) {
panel.hidden = false;
// distance (px) between edge of panel and the pointing triangle (caret)
const MARGIN = 20;
const dfnRects = dfn.getClientRects();
// Find the `top` offset when the `dfn` can be spread across multiple lines
let closestTop = 0;
let minDiff = Infinity;
for (const rect of dfnRects) {
const { top, bottom } = rect;
const diffFromClickY = Math.abs((top + bottom) / 2 - y);
if (diffFromClickY < minDiff) {
minDiff = diffFromClickY;
closestTop = top;
}
}
const top = window.scrollY + closestTop + dfnRects[0].height;
const left = x - MARGIN;
panel.style.left = `${left}px`;
panel.style.top = `${top}px`;
// Find if the panel is flowing out of the window
const panelRect = panel.getBoundingClientRect();
const SCREEN_WIDTH = Math.min(window.innerWidth, window.screen.width);
if (panelRect.right > SCREEN_WIDTH) {
const newLeft = Math.max(MARGIN, x + MARGIN - panelRect.width);
const newCaretOffset = left - newLeft;
panel.style.left = `${newLeft}px`;
/** @type {HTMLElement} */
const caret = panel.querySelector(".caret");
caret.style.left = `${newCaretOffset}px`;
}
// As it's a dialog, we trap focus.
// TODO: when <dialog> becomes a implemented, we should really
// use that.
trapFocus(panel, dfn);
}
/**
* @param {HTMLElement} panel
* @param {HTMLElement} dfn
* @returns
*/
function trapFocus(panel, dfn) {
/** @type NodeListOf<HTMLAnchorElement> elements */
const anchors = panel.querySelectorAll("a[href]");
// No need to trap focus
if (!anchors.length) return;
// Move focus to first anchor element
const first = anchors.item(0);
first.focus();
const trapListener = createTrapListener(anchors, panel, dfn);
panel.addEventListener("keydown", trapListener);
// Hiding the panel releases the trap
const mo = new MutationObserver(records => {
const [record] = records;
const target = /** @type HTMLElement */ (record.target);
if (target.hidden) {
panel.removeEventListener("keydown", trapListener);
mo.disconnect();
}
});
mo.observe(panel, { attributes: true, attributeFilter: ["hidden"] });
}
/**
*
* @param {NodeListOf<HTMLAnchorElement>} anchors
* @param {HTMLElement} panel
* @param {HTMLElement} dfn
* @returns
*/
function createTrapListener(anchors, panel, dfn) {
const lastIndex = anchors.length - 1;
let currentIndex = 0;
return event => {
switch (event.key) {
// Hitting "Tab" traps us in a nice loop around elements.
case "Tab": {
event.preventDefault();
currentIndex += event.shiftKey ? -1 : +1;
if (currentIndex < 0) {
currentIndex = lastIndex;
} else if (currentIndex > lastIndex) {
currentIndex = 0;
}
anchors.item(currentIndex).focus();
break;
}
// Hitting "Enter" on an anchor releases the trap.
case "Enter":
hidePanel(panel);
break;
// Hitting "Escape" returns focus to dfn.
case "Escape":
hidePanel(panel);
dfn.focus();
return;
}
};
}
/** @param {HTMLElement} panel */
function hidePanel(panel) {
if (!panel) return;
panel.hidden = true;
panel.classList.remove("docked");
}
})()</script><script src="https://www.w3.org/scripts/TR/2021/fixup.js"></script></body><grammarly-desktop-integration data-grammarly-shadow-root="true"></grammarly-desktop-integration></html>