Skip to content

chore(deps): update dependency ecmarkup to v16.0.1 #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 119 additions & 25 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1229,33 +1229,123 @@
});

'use strict';
let decimalBullet = Array.from({ length: 100 }, (a, i) => '' + (i + 1));
let alphaBullet = Array.from({ length: 26 }, (a, i) => String.fromCharCode('a'.charCodeAt(0) + i));

// prettier-ignore
let romanBullet = ['i', 'ii', 'iii', 'iv', 'v', 'vi', 'vii', 'viii', 'ix', 'x', 'xi', 'xii', 'xiii', 'xiv', 'xv', 'xvi', 'xvii', 'xviii', 'xix', 'xx', 'xxi', 'xxii', 'xxiii', 'xxiv', 'xxv'];
// prettier-ignore
let bullets = [decimalBullet, alphaBullet, romanBullet, decimalBullet, alphaBullet, romanBullet];

function addStepNumberText(ol, parentIndex) {
for (let i = 0; i < ol.children.length; ++i) {
let child = ol.children[i];
let index = parentIndex.concat([i]);
let applicable = bullets[Math.min(index.length - 1, 5)];
let span = document.createElement('span');
span.textContent = (applicable[i] || '?') + '. ';
span.style.fontSize = '0';
span.setAttribute('aria-hidden', 'true');
child.prepend(span);
let sublist = child.querySelector('ol');
if (sublist != null) {
addStepNumberText(sublist, index);

// Manually prefix algorithm step list items with hidden counter representations
// corresponding with their markers so they get selected and copied with content.
// We read list-style-type to avoid divergence with the style sheet, but
// for efficiency assume that all lists at the same nesting depth use the same
// style (except for those associated with replacement steps).
// We also precompute some initial items for each supported style type.
// https://w3c.github.io/csswg-drafts/css-counter-styles/

const lowerLetters = Array.from({ length: 26 }, (_, i) =>
String.fromCharCode('a'.charCodeAt(0) + i)
);
// Implement the lower-alpha 'alphabetic' algorithm,
// adjusting for indexing from 0 rather than 1.
// https://w3c.github.io/csswg-drafts/css-counter-styles/#simple-alphabetic
// https://w3c.github.io/csswg-drafts/css-counter-styles/#alphabetic-system
const lowerAlphaTextForIndex = i => {
let S = '';
for (const N = lowerLetters.length; i >= 0; i--) {
S = lowerLetters[i % N] + S;
i = Math.floor(i / N);
}
return S;
};

const weightedLowerRomanSymbols = Object.entries({
m: 1000,
cm: 900,
d: 500,
cd: 400,
c: 100,
xc: 90,
l: 50,
xl: 40,
x: 10,
ix: 9,
v: 5,
iv: 4,
i: 1,
});
// Implement the lower-roman 'additive' algorithm,
// adjusting for indexing from 0 rather than 1.
// https://w3c.github.io/csswg-drafts/css-counter-styles/#simple-numeric
// https://w3c.github.io/csswg-drafts/css-counter-styles/#additive-system
const lowerRomanTextForIndex = i => {
let value = i + 1;
let S = '';
for (const [symbol, weight] of weightedLowerRomanSymbols) {
if (!value) break;
if (weight > value) continue;
const reps = Math.floor(value / weight);
S += symbol.repeat(reps);
value -= weight * reps;
}
return S;
};

// Memoize pure index-to-text functions with an exposed cache for fast retrieval.
const makeCounter = (pureGetTextForIndex, precomputeCount = 30) => {
const cache = Array.from({ length: precomputeCount }, (_, i) => pureGetTextForIndex(i));
const getTextForIndex = i => {
if (i >= cache.length) cache[i] = pureGetTextForIndex(i);
return cache[i];
};
return { getTextForIndex, cache };
};

const counterByStyle = {
__proto__: null,
decimal: makeCounter(i => String(i + 1)),
'lower-alpha': makeCounter(lowerAlphaTextForIndex),
'upper-alpha': makeCounter(i => lowerAlphaTextForIndex(i).toUpperCase()),
'lower-roman': makeCounter(lowerRomanTextForIndex),
'upper-roman': makeCounter(i => lowerRomanTextForIndex(i).toUpperCase()),
};
const fallbackCounter = makeCounter(() => '?');
const counterByDepth = [];

function addStepNumberText(
ol,
depth = 0,
special = [...ol.classList].some(c => c.startsWith('nested-'))
) {
let counter = !special && counterByDepth[depth];
if (!counter) {
const counterStyle = getComputedStyle(ol)['list-style-type'];
counter = counterByStyle[counterStyle];
if (!counter) {
console.warn('unsupported list-style-type', {
ol,
counterStyle,
id: ol.closest('[id]')?.getAttribute('id'),
});
counterByStyle[counterStyle] = fallbackCounter;
counter = fallbackCounter;
}
if (!special) {
counterByDepth[depth] = counter;
}
}
const { cache, getTextForIndex } = counter;
let i = (Number(ol.getAttribute('start')) || 1) - 1;
for (const li of ol.children) {
const marker = document.createElement('span');
marker.textContent = `${i < cache.length ? cache[i] : getTextForIndex(i)}. `;
marker.setAttribute('aria-hidden', 'true');
li.prepend(marker);
for (const sublist of li.querySelectorAll(':scope > ol')) {
addStepNumberText(sublist, depth + 1, special);
}
i++;
}
}

document.addEventListener('DOMContentLoaded', () => {
document.querySelectorAll('emu-alg > ol').forEach(ol => {
addStepNumberText(ol, []);
addStepNumberText(ol);
});
});

Expand Down Expand Up @@ -1450,6 +1540,10 @@
list-style-type: lower-roman;
}

emu-alg [aria-hidden=true] {
font-size: 0;
}

emu-eqn {
display: block;
margin-left: 4em;
Expand Down Expand Up @@ -1501,7 +1595,7 @@
margin-bottom: 0;
}

emu-table td code {
emu-table:not(.code) td code {
white-space: normal;
}

Expand Down Expand Up @@ -2525,7 +2619,7 @@
</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">
<title>Menu</title>
<path stroke-width="10" stroke-linecap="round" d="M30,60 h60 M30,30 m0,5 h60 M30,90 m0,-5 h60"></path>
</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</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-none"></span><a href="#sec-demo-clause" title="This is an emu-clause"><span class="secnum">1</span> This is an emu-clause</a></li><li><span class="item-toggle-none"></span><a href="#sec-copyright-and-software-license" title="Copyright &amp; Software License"><span class="secnum">A</span> Copyright &amp; Software License</a></li></ol></div></div><div id="spec-container"><h1 class="version">Stage -1 Draft / November 28, 2022</h1><h1 class="title">AssertionError Proposal</h1>
</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</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-none"></span><a href="#sec-demo-clause" title="This is an emu-clause"><span class="secnum">1</span> This is an emu-clause</a></li><li><span class="item-toggle-none"></span><a href="#sec-copyright-and-software-license" title="Copyright &amp; Software License"><span class="secnum">A</span> Copyright &amp; Software License</a></li></ol></div></div><div id="spec-container"><h1 class="version">Stage -1 Draft / January 25, 2023</h1><h1 class="title">AssertionError Proposal</h1>

<emu-clause id="sec-demo-clause">
<h1><span class="secnum">1</span> This is an emu-clause</h1>
Expand All @@ -2535,7 +2629,7 @@ <h1><span class="secnum">1</span> This is an emu-clause</h1>
<h1><span class="secnum">A</span> Copyright &amp; Software License</h1>

<h2>Copyright Notice</h2>
<p>© 2022 The TC39 AssertionError Proposal Authors</p>
<p>© 2023 The TC39 AssertionError Proposal Authors</p>

<h2>Software License</h2>
<p>All Software contained in this document ("Software") is protected by copyright and is being made available under the "BSD License", included below. This Software may be subject to third party rights (rights from parties other than Ecma International), including patent rights, and no licenses under such third party rights are granted under this license even if the third party concerned is a member of Ecma International. SEE THE ECMA CODE OF CONDUCT IN PATENT MATTERS AVAILABLE AT https://ecma-international.org/memento/codeofconduct.htm FOR INFORMATION REGARDING THE LICENSING OF PATENT CLAIMS THAT ARE REQUIRED TO IMPLEMENT ECMA INTERNATIONAL STANDARDS.</p>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"repository": "github:DerekNonGeneric/proposal-assertion-error",
"license": "MIT",
"devDependencies": {
"ecmarkup": "16.0.0"
"ecmarkup": "16.0.1"
}
}