forked from speced/bikeshed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalgorithm001.html
309 lines (292 loc) · 10.9 KB
/
algorithm001.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
<!doctype html><html lang="en">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<meta content="width=device-width, initial-scale=1, shrink-to-fit=no" name="viewport">
<title>Foo</title>
<link href="http://example.com/foo" rel="canonical">
<style>/* style-autolinks */
.css.css, .property.property, .descriptor.descriptor {
color: #005a9c;
font-size: inherit;
font-family: inherit;
}
.css::before, .property::before, .descriptor::before {
content: "‘";
}
.css::after, .property::after, .descriptor::after {
content: "’";
}
.property, .descriptor {
/* Don't wrap property and descriptor names */
white-space: nowrap;
}
.type { /* CSS value <type> */
font-style: italic;
}
pre .property::before, pre .property::after {
content: "";
}
[data-link-type="property"]::before,
[data-link-type="propdesc"]::before,
[data-link-type="descriptor"]::before,
[data-link-type="value"]::before,
[data-link-type="function"]::before,
[data-link-type="at-rule"]::before,
[data-link-type="selector"]::before,
[data-link-type="maybe"]::before {
content: "‘";
}
[data-link-type="property"]::after,
[data-link-type="propdesc"]::after,
[data-link-type="descriptor"]::after,
[data-link-type="value"]::after,
[data-link-type="function"]::after,
[data-link-type="at-rule"]::after,
[data-link-type="selector"]::after,
[data-link-type="maybe"]::after {
content: "’";
}
[data-link-type].production::before,
[data-link-type].production::after,
.prod [data-link-type]::before,
.prod [data-link-type]::after {
content: "";
}
[data-link-type=element],
[data-link-type=element-attr] {
font-family: Menlo, Consolas, "DejaVu Sans Mono", monospace;
font-size: .9em;
}
[data-link-type=element]::before { content: "<" }
[data-link-type=element]::after { content: ">" }
[data-link-type=biblio] {
white-space: pre;
}</style>
<style>/* style-counters */
body {
counter-reset: example figure issue;
}
.issue {
counter-increment: issue;
}
.issue:not(.no-marker)::before {
content: "Issue " counter(issue);
}
.example {
counter-increment: example;
}
.example:not(.no-marker)::before {
content: "Example " counter(example);
}
.invalid.example:not(.no-marker)::before,
.illegal.example:not(.no-marker)::before {
content: "Invalid Example" counter(example);
}
figcaption {
counter-increment: figure;
}
figcaption:not(.no-marker)::before {
content: "Figure " counter(figure) " ";
}</style>
<style>/* style-md-lists */
/* This is a weird hack for me not yet following the commonmark spec
regarding paragraph and lists. */
[data-md] > :first-child {
margin-top: 0;
}
[data-md] > :last-child {
margin-bottom: 0;
}</style>
<style>/* style-selflinks */
.heading, .issue, .note, .example, li, dt {
position: relative;
}
a.self-link {
position: absolute;
top: 0;
left: calc(-1 * (3.5rem - 26px));
width: calc(3.5rem - 26px);
height: 2em;
text-align: center;
border: none;
transition: opacity .2s;
opacity: .5;
}
a.self-link:hover {
opacity: 1;
}
.heading > a.self-link {
font-size: 83%;
}
li > a.self-link {
left: calc(-1 * (3.5rem - 26px) - 2em);
}
dfn > a.self-link {
top: auto;
left: auto;
opacity: 0;
width: 1.5em;
height: 1.5em;
background: gray;
color: white;
font-style: normal;
transition: opacity .2s, background-color .2s, color .2s;
}
dfn:hover > a.self-link {
opacity: 1;
}
dfn > a.self-link:hover {
color: black;
}
a.self-link::before { content: "¶"; }
.heading > a.self-link::before { content: "§"; }
dfn > a.self-link::before { content: "#"; }</style>
<style>/* style-var-click-highlighting */
var { cursor: pointer; }
var.selected0 { background-color: #F4D200; box-shadow: 0 0 0 2px #F4D200; }
var.selected1 { background-color: #FF87A2; box-shadow: 0 0 0 2px #FF87A2; }
var.selected2 { background-color: #96E885; box-shadow: 0 0 0 2px #96E885; }
var.selected3 { background-color: #3EEED2; box-shadow: 0 0 0 2px #3EEED2; }
var.selected4 { background-color: #EACFB6; box-shadow: 0 0 0 2px #EACFB6; }
var.selected5 { background-color: #82DDFF; box-shadow: 0 0 0 2px #82DDFF; }
var.selected6 { background-color: #FFBCF2; box-shadow: 0 0 0 2px #FFBCF2; }
</style>
<body class="h-entry">
<div class="head">
<p data-fill-with="logo"></p>
<h1 class="p-name no-ref" id="title">Foo</h1>
<h2 class="no-num no-toc no-ref heading settled" id="subtitle"><span class="content">Living Standard, <time class="dt-updated" datetime="1970-01-01">1 January 1970</time></span></h2>
<div data-fill-with="spec-metadata">
<dl>
<dt>This version:
<dd><a class="u-url" href="http://example.com/foo">http://example.com/foo</a>
<dt class="editor">Editor:
<dd class="editor p-author h-card vcard"><span class="p-name fn">Example Editor</span>
</dl>
</div>
<div data-fill-with="warning"></div>
<p class="copyright" data-fill-with="copyright">COPYRIGHT GOES HERE </p>
<hr title="Separator for header">
</div>
<div class="p-summary" data-fill-with="abstract">
<h2 class="no-num no-toc no-ref heading settled" id="abstract"><span class="content">Abstract</span></h2>
<p>Test algorithm auto-naming.</p>
</div>
<div data-fill-with="at-risk"></div>
<nav data-fill-with="table-of-contents" id="toc">
<h2 class="no-num no-toc no-ref" id="contents">Table of Contents</h2>
<ol class="toc" role="directory">
<li>
<a href="#foo"><span class="secno">1</span> <span class="content">Find a Foo</span></a>
<ol class="toc">
<li><a href="#bar"><span class="secno">1.1</span> <span class="content">bar</span></a>
</ol>
<li><a href="#foo2"><span class="secno">2</span> <span class="content">More Stuff</span></a>
<li>
<a href="#index"><span class="secno"></span> <span class="content">Index</span></a>
<ol class="toc">
<li><a href="#index-defined-here"><span class="secno"></span> <span class="content">Terms defined by this specification</span></a>
</ol>
</ol>
</nav>
<main>
<h2 class="heading settled algorithm" data-algorithm="Find a Foo" data-level="1" id="foo"><span class="secno">1. </span><span class="content">Find a Foo</span><a class="self-link" href="#foo"></a></h2>
<p>Blah blah blah, <var>foo</var></p>
<h3 class="heading settled" data-level="1.1" id="bar"><span class="secno">1.1. </span><span class="content">bar</span><a class="self-link" href="#bar"></a></h3>
<p><var>foo</var></p>
<h2 class="heading settled" data-level="2" id="foo2"><span class="secno">2. </span><span class="content">More Stuff</span><a class="self-link" href="#foo2"></a></h2>
<div class="algorithm" data-algorithm="find more foo">
<dfn data-dfn-type="dfn" data-noexport id="find-more-foo">find more foo<a class="self-link" href="#find-more-foo"></a></dfn>
<p><var>foo</var></p>
</div>
<div class="algorithm" data-algorithm> <var>foo</var> </div>
<div class="algorithm" data-algorithm>
<dfn data-dfn-type="dfn" data-noexport id="find-even-more-foo">find even more foo<a class="self-link" href="#find-even-more-foo"></a></dfn> but also <dfn data-dfn-type="dfn" data-noexport id="find-some-bar">find some bar<a class="self-link" href="#find-some-bar"></a></dfn>
<p><var>foo</var></p>
</div>
</main>
<h2 class="no-num no-ref heading settled" id="index"><span class="content">Index</span><a class="self-link" href="#index"></a></h2>
<h3 class="no-num no-ref heading settled" id="index-defined-here"><span class="content">Terms defined by this specification</span><a class="self-link" href="#index-defined-here"></a></h3>
<ul class="index">
<li><a href="#find-even-more-foo">find even more foo</a><span>, in §2</span>
<li><a href="#find-more-foo">find more foo</a><span>, in §2</span>
<li><a href="#find-some-bar">find some bar</a><span>, in §2</span>
</ul>
<script>/* script-var-click-highlighting */
document.addEventListener("click", e=>{
if(e.target.nodeName == "VAR") {
highlightSameAlgoVars(e.target);
}
});
{
const indexCounts = new Map();
const indexNames = new Map();
function highlightSameAlgoVars(v) {
// Find the algorithm container.
let algoContainer = null;
let searchEl = v;
while(algoContainer == null && searchEl != document.body) {
searchEl = searchEl.parentNode;
if(searchEl.hasAttribute("data-algorithm")) {
algoContainer = searchEl;
}
}
// Not highlighting document-global vars,
// too likely to be unrelated.
if(algoContainer == null) return;
const algoName = algoContainer.getAttribute("data-algorithm");
const varName = getVarName(v);
const addClass = !v.classList.contains("selected");
let highlightClass = null;
if(addClass) {
const index = chooseHighlightIndex(algoName, varName);
indexCounts.get(algoName)[index] += 1;
indexNames.set(algoName+"///"+varName, index);
highlightClass = nameFromIndex(index);
} else {
const index = previousHighlightIndex(algoName, varName);
indexCounts.get(algoName)[index] -= 1;
highlightClass = nameFromIndex(index);
}
// Find all same-name vars, and toggle their class appropriately.
for(const el of algoContainer.querySelectorAll("var")) {
if(getVarName(el) == varName) {
el.classList.toggle("selected", addClass);
el.classList.toggle(highlightClass, addClass);
}
}
}
function getVarName(el) {
return el.textContent.replace(/(\s| )+/, " ").trim();
}
function chooseHighlightIndex(algoName, varName) {
let indexes = null;
if(indexCounts.has(algoName)) {
indexes = indexCounts.get(algoName);
} else {
// 7 classes right now
indexes = [0,0,0,0,0,0,0];
indexCounts.set(algoName, indexes);
}
// If the element was recently unclicked,
// *and* that color is still unclaimed,
// give it back the same color.
const lastIndex = previousHighlightIndex(algoName, varName);
if(indexes[lastIndex] === 0) return lastIndex;
// Find the earliest index with the lowest count.
const minCount = Math.min.apply(null, indexes);
let index = null;
for(var i = 0; i < indexes.length; i++) {
if(indexes[i] == minCount) {
return i;
}
}
}
function previousHighlightIndex(algoName, varName) {
return indexNames.get(algoName+"///"+varName);
}
function nameFromIndex(index) {
return "selected" + index;
}
}
</script>