1454
1454
function addStepNumberText (
1455
1455
ol ,
1456
1456
depth = 0 ,
1457
+ indent = ' ' ,
1457
1458
special = [... ol .classList ].some (c => c .startsWith (' nested-' )),
1458
1459
) {
1459
1460
let counter = ! special && counterByDepth[depth];
1477
1478
let i = (Number (ol .getAttribute (' start' )) || 1 ) - 1 ;
1478
1479
for (const li of ol .children ) {
1479
1480
const marker = document .createElement (' span' );
1480
- marker .textContent = ` ${ i < cache .length ? cache[i] : getTextForIndex (i)} . ` ;
1481
+ const markerText = i < cache .length ? cache[i] : getTextForIndex (i);
1482
+ const extraIndent = ' ' .repeat (markerText .length + 2 );
1483
+ marker .textContent = ` ${ indent}${ markerText} . ` ;
1481
1484
marker .setAttribute (' aria-hidden' , ' true' );
1485
+ marker .setAttribute (' class' , ' list-marker' );
1482
1486
const attributesContainer = li .querySelector (' .attributes-tag' );
1483
1487
if (attributesContainer == null ) {
1484
1488
li .prepend (marker);
1485
1489
} else {
1486
1490
attributesContainer .insertAdjacentElement (' afterend' , marker);
1487
1491
}
1488
1492
for (const sublist of li .querySelectorAll (' :scope > ol' )) {
1489
- addStepNumberText (sublist, depth + 1 , special);
1493
+ addStepNumberText (sublist, depth + 1 , indent + extraIndent, special);
1490
1494
}
1491
1495
i++ ;
1492
1496
}
1498
1502
});
1499
1503
});
1500
1504
1505
+ // Omit indendation when copying a single algorithm step.
1506
+ document .addEventListener (' copy' , evt => {
1507
+ // Construct a DOM from the selection.
1508
+ const doc = document .implementation .createHTMLDocument (' ' );
1509
+ const domRoot = doc .createElement (' div' );
1510
+ const html = evt .clipboardData .getData (' text/html' );
1511
+ if (html) {
1512
+ domRoot .innerHTML = html;
1513
+ } else {
1514
+ const selection = getSelection ();
1515
+ const singleRange = selection? .rangeCount === 1 && selection .getRangeAt (0 );
1516
+ const container = singleRange? .commonAncestorContainer ;
1517
+ if (! container? .querySelector ? .(' .list-marker' )) {
1518
+ return ;
1519
+ }
1520
+ domRoot .append (singleRange .cloneContents ());
1521
+ }
1522
+
1523
+ // Preserve the indentation if there is no hidden list marker, or if selection
1524
+ // of more than one step is indicated by either multiple such markers or by
1525
+ // visible text before the first one.
1526
+ const listMarkers = domRoot .querySelectorAll (' .list-marker' );
1527
+ if (listMarkers .length !== 1 ) {
1528
+ return ;
1529
+ }
1530
+ const treeWalker = document .createTreeWalker (domRoot, undefined , {
1531
+ acceptNode (node ) {
1532
+ return node .nodeType === Node .TEXT_NODE || node === listMarkers[0 ]
1533
+ ? NodeFilter .FILTER_ACCEPT
1534
+ : NodeFilter .FILTER_SKIP ;
1535
+ },
1536
+ });
1537
+ while (treeWalker .nextNode ()) {
1538
+ const node = treeWalker .currentNode ;
1539
+ if (node .nodeType === Node .ELEMENT_NODE ) break ;
1540
+ if (/ \S / u .test (node .data )) return ;
1541
+ }
1542
+
1543
+ // Strip leading indentation from the plain text representation.
1544
+ evt .clipboardData .setData (' text/plain' , domRoot .textContent .trimStart ());
1545
+ if (! html) {
1546
+ evt .clipboardData .setData (' text/html' , domRoot .innerHTML );
1547
+ }
1548
+ evt .preventDefault ();
1549
+ });
1550
+
1501
1551
' use strict' ;
1502
1552
1503
1553
// Update superscripts to not suffer misinterpretation when copied and pasted as plain text.
1699
1749
1700
1750
span[aria- hidden= ' true' ] {
1701
1751
font- size: 0 ;
1752
+ white- space: pre;
1702
1753
}
1703
1754
1704
1755
a {
1796
1847
font: inherit;
1797
1848
color: inherit;
1798
1849
}
1850
+ /* suppress line break opportunities between `.` and `[[FieldName]]` */
1851
+ var .field :: before {
1852
+ content: ' \206 0'
1853
+ }
1799
1854
1800
1855
var .referenced {
1801
1856
color: inherit;
3207
3262
@media print {
3208
3263
@page : left {
3209
3264
@bottom- right {
3210
- content: ' © Ecma International 2024 ' ;
3265
+ content: ' © Ecma International 2025 ' ;
3211
3266
}
3212
3267
}
3213
3268
@page : right {
3214
3269
@bottom- left {
3215
- content: ' © Ecma International 2024 ' ;
3270
+ content: ' © Ecma International 2025 ' ;
3216
3271
}
3217
3272
}
3218
3273
@page : first {
3243
3298
< / ul>< / div>< div id= " menu-toggle" >< svg xmlns= " http://www.w3.org/2000/svg" style= " width:100%; height:100%; stroke:currentColor" viewBox= " 0 0 120 120" width= " 54" height= " 54" >
3244
3299
< title> Menu< / title>
3245
3300
< path stroke- width= " 10" stroke- linecap= " round" d= " M30,60 h60 M30,30 m0,5 h60 M30,90 m0,-5 h60" >< / path>
3246
- </svg></div><div id="menu-spacer" class="menu-spacer"></div><div id="menu"><div id="menu-search"><input type="text" id="menu-search-box" placeholder="Search..."><div id="menu-search-results" class="inactive"></div></div><div id="menu-pins"><div class="menu-pane-header">Pins<button class="unpin-all">clear</button></div><ul id="menu-pins-list"></ul></div><div class="menu-pane-header">Table of Contents</div><div id="menu-toc"><ol class="toc"><li><span class="item-toggle">+</span><a href="#sec-control-abstraction-objects" title="Control Abstraction Objects"><span class="secnum">27</span> Control Abstraction Objects</a><ol class="toc"><li><span class="item-toggle">+</span><a href="#sec-iteration" title="Iteration"><span class="secnum">27.1</span> Iteration</a><ol class="toc"><li><span class="item-toggle">+</span><a href="#sec-properties-of-the-iterator-constructor" title="Properties of the Iterator Constructor"><span class="secnum">27.1.2</span> Properties of the Iterator Constructor</a><ol class="toc"><li><span class="item-toggle-none"></span><a href="#sec-iterator.range" title="Iterator.range ( start, end, optionOrStep )"><span class="secnum">27.1.2.1</span> Iterator.range ( <var>start</var>, <var>end</var>, <var>optionOrStep</var> )</a></li></ol></li><li><span class="item-toggle">+</span><a href="#sec-numeric-range-iterator-object" title="The NumericRangeIterator Object"><span class="secnum">27.1.3</span> The <dfn tabindex="-1">NumericRangeIterator</dfn> Object</a><ol class="toc"><li><span class="item-toggle-none"></span><a href="#sec-create-numeric-range-iterator" title="CreateNumericRangeIterator ( start, end, optionOrStep, type )"><span class="secnum">27.1.3.1</span> CreateNumericRangeIterator ( <var>start</var>, <var>end</var>, <var>optionOrStep</var>, <var>type</var> )</a></li><li><span class="item-toggle">+</span><a href="#sec-%numericrangeiteratorprototype%-object" title="The %NumericRangeIteratorPrototype% Object"><span class="secnum">27.1.3.2</span> The %NumericRangeIteratorPrototype% Object</a><ol class="toc"><li><span class="item-toggle-none"></span><a href="#sec-properties-of-the-numericrangeiterator-prototype-object-next" title="%NumericRangeIterator%.next ( )"><span class="secnum">27.1.3.2.1</span> %NumericRangeIterator%.next ( )</a></li><li><span class="item-toggle-none"></span><a href="#sec-properties-of-the-numericrangeiterator-prototype-object-@@tostringtag" title="%NumericRangeIteratorPrototype%.[@@toStringTag]"><span class="secnum">27.1.3.2.2</span> %NumericRangeIteratorPrototype%.[@@toStringTag]</a></li></ol></li></ol></li></ol></li></ol></li></ol></div></div><div id="spec-container"><h1 class="version">Stage 1 Draft / December 8, 2024</h1><h1 class="title">Range proposal</h1>
3301
+ </svg></div><div id="menu-spacer" class="menu-spacer"></div><div id="menu"><div id="menu-search"><input type="text" id="menu-search-box" placeholder="Search..."><div id="menu-search-results" class="inactive"></div></div><div id="menu-pins"><div class="menu-pane-header">Pins<button class="unpin-all">clear</button></div><ul id="menu-pins-list"></ul></div><div class="menu-pane-header">Table of Contents</div><div id="menu-toc"><ol class="toc"><li><span class="item-toggle">+</span><a href="#sec-control-abstraction-objects" title="Control Abstraction Objects"><span class="secnum">27</span> Control Abstraction Objects</a><ol class="toc"><li><span class="item-toggle">+</span><a href="#sec-iteration" title="Iteration"><span class="secnum">27.1</span> Iteration</a><ol class="toc"><li><span class="item-toggle">+</span><a href="#sec-properties-of-the-iterator-constructor" title="Properties of the Iterator Constructor"><span class="secnum">27.1.2</span> Properties of the Iterator Constructor</a><ol class="toc"><li><span class="item-toggle-none"></span><a href="#sec-iterator.range" title="Iterator.range ( start, end, optionOrStep )"><span class="secnum">27.1.2.1</span> Iterator.range ( <var>start</var>, <var>end</var>, <var>optionOrStep</var> )</a></li></ol></li><li><span class="item-toggle">+</span><a href="#sec-numeric-range-iterator-object" title="The NumericRangeIterator Object"><span class="secnum">27.1.3</span> The <dfn tabindex="-1">NumericRangeIterator</dfn> Object</a><ol class="toc"><li><span class="item-toggle-none"></span><a href="#sec-create-numeric-range-iterator" title="CreateNumericRangeIterator ( start, end, optionOrStep, type )"><span class="secnum">27.1.3.1</span> CreateNumericRangeIterator ( <var>start</var>, <var>end</var>, <var>optionOrStep</var>, <var>type</var> )</a></li><li><span class="item-toggle">+</span><a href="#sec-%numericrangeiteratorprototype%-object" title="The %NumericRangeIteratorPrototype% Object"><span class="secnum">27.1.3.2</span> The %NumericRangeIteratorPrototype% Object</a><ol class="toc"><li><span class="item-toggle-none"></span><a href="#sec-properties-of-the-numericrangeiterator-prototype-object-next" title="%NumericRangeIterator%.next ( )"><span class="secnum">27.1.3.2.1</span> %NumericRangeIterator%.next ( )</a></li><li><span class="item-toggle-none"></span><a href="#sec-properties-of-the-numericrangeiterator-prototype-object-@@tostringtag" title="%NumericRangeIteratorPrototype%.[@@toStringTag]"><span class="secnum">27.1.3.2.2</span> %NumericRangeIteratorPrototype%.[@@toStringTag]</a></li></ol></li></ol></li></ol></li></ol></li></ol></div></div><div id="spec-container"><h1 class="version">Stage 1 Draft / January 27, 2025</h1><h1 class="title">Range proposal</h1>
3247
3302
3248
3303
< emu- clause id= " sec-control-abstraction-objects" number= " 27" >
3249
3304
< h1>< span class = " secnum" > 27 < / span> Control Abstraction Objects< / h1>
@@ -3262,7 +3317,7 @@ <h1><span class="secnum">27.1.2.1</span> Iterator.range ( <var>start</var>, <var
3262
3317
3263
3318
< emu- clause id= " sec-numeric-range-iterator-object" >
3264
3319
< h1>< span class = " secnum" > 27.1 .3 < / span> The < dfn tabindex= " -1" > NumericRangeIterator< / dfn> Object < / h1>
3265
- < p> A NumericRangeIterator object is an iterator that yields numbers . There is not a named < emu- xref href= " #constructor" >< a href= " https://tc39.es/ecma262/#constructor" > constructor </a></emu-xref> for NumericRangeIterator objects. Instead, NumericRangeIterator objects are created by the <emu-xref aoid="CreateNumericRangeIterator" id="_ref_2"><a href="#sec-create-numeric-range-iterator">CreateNumericRangeIterator</a></emu-xref> abstract operation as needed.</p>
3320
+ < p> A NumericRangeIterator object is an < emu - xref href = " #sec- iterator-interface " >< a href = " https://tc39.es/ecma262/#sec-iterator-interface " > iterator < / a >< / emu - xref > that yields numbers . There is not a named < emu- xref href= " #constructor" >< a href= " https://tc39.es/ecma262/#constructor" > constructor </a></emu-xref> for NumericRangeIterator objects. Instead, NumericRangeIterator objects are created by the <emu-xref aoid="CreateNumericRangeIterator" id="_ref_2"><a href="#sec-create-numeric-range-iterator">CreateNumericRangeIterator</a></emu-xref> abstract operation as needed.</p>
3266
3321
3267
3322
<emu-clause id="sec-create-numeric-range-iterator" type="abstract operation" aoid="CreateNumericRangeIterator">
3268
3323
<h1><span class="secnum">27.1.3.1</span> CreateNumericRangeIterator ( < var > start < / var > , < var > end < / var > , < var > optionOrStep < / var > , < var > type < / var > )</h1>
@@ -3277,7 +3332,7 @@ <h1><span class="secnum">27.1.3.2</span> The %NumericRangeIteratorPrototype% Obj
3277
3332
<ul>
3278
3333
<li>has properties that are inherited by all <emu-xref href="#sec-numeric-range-iterator-object" id="_ref_4"><a href="#sec-numeric-range-iterator-object">NumericRangeIterator</a></emu-xref> Objects.</li>
3279
3334
<li>is an <emu-xref href="#ordinary-object"><a href="https:// tc39.es/ecma262/#ordinary-object">ordinary object</a></emu-xref>.</li>
3280
- <li>has a <var class="field">[[Prototype]]</var> internal slot whose value is <emu-xref href="#sec-%iteratorprototype%-object"><a href="https: // tc39.es/ecma262/#sec-%iteratorprototype%-object">% IteratorPrototype%</a></emu-xref> .</li>
3335
+ <li>has a <var class="field">[[Prototype]]</var> internal slot whose value is % IteratorPrototype%.</li>
3281
3336
<li>has the following properties:</li>
3282
3337
</ul>
3283
3338
@@ -3287,7 +3342,7 @@ <h1><span class="secnum">27.1.3.2.1</span> %NumericRangeIterator%.next ( )</h1>
3287
3342
</emu-clause>
3288
3343
<emu-clause id="sec-properties-of-the-numericrangeiterator-prototype-object-@@tostringtag">
3289
3344
<h1><span class="secnum">27.1.3.2.2</span> %NumericRangeIteratorPrototype%.[@@toStringTag]</h1>
3290
- <p>The initial value of the <emu-xref href="#sec-well-known-symbols"><a href="https: // tc39.es/ecma262/#sec-well-known-symbols"> @@toStringTag</a></emu-xref> property is the String value <code>"NumericRangeIterator"</code>.</p>
3345
+ <p>The initial value of the @@toStringTag property is the String value <code>"NumericRangeIterator"</code>.</p>
3291
3346
<p>This property has the attributes { < var class = " field" > [[Writable]]< / var > : < emu- val> false < / emu- val> , < var class = " field" > [[Enumerable]]< / var > : < emu- val> false < / emu- val> , < var class = " field" > [[Configurable]]< / var > : < emu- val> true < / emu- val> }.< / p>
3292
3347
< / emu- clause>
3293
3348
< / emu- clause>
0 commit comments