Skip to content

Commit

Permalink
Use same naming for arguments as CSS clamp()
Browse files Browse the repository at this point in the history
Signed-off-by: Richie Bendall <[email protected]>
  • Loading branch information
Richienb committed Apr 22, 2023
1 parent 4258ecb commit 6d1aee5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 128 deletions.
6 changes: 3 additions & 3 deletions implementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import esAbstract from 'es-abstract';

const {ToNumber: toNumber} = esAbstract;

export default function clamp(min, number, max) {
export default function clamp(min, val, max) {
const minCoerced = toNumber(min);
const numberCoerced = toNumber(number);
const valCoerced = toNumber(val);
const maxCoerced = toNumber(max);

return Math.max(minCoerced, Math.min(numberCoerced, maxCoerced));
return Math.max(minCoerced, Math.min(valCoerced, maxCoerced));
}
128 changes: 7 additions & 121 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@
if (/^[\d.]*$/.test(searchString)) {
results = this.biblio.clauses
.filter(clause => clause.number.substring(0, searchString.length) === searchString)
.map(clause => ({ key: getKey(clause), entry: clause }));
.map(clause => ({ entry: clause }));
} else {
results = [];
Expand Down Expand Up @@ -898,7 +898,6 @@
e.preventDefault();
e.stopPropagation();
menu.togglePinEntry(this.entry.id);
this.$pinLink.textContent = menu._pinnedIds[this.entry.id] ? 'Unpin' : 'Pin';
});
this.$refsLink = document.createElement('a');
Expand All @@ -919,7 +918,6 @@
sdoBox.deactivate();
this.active = true;
this.entry = entry;
this.$pinLink.textContent = menu._pinnedIds[entry.id] ? 'Unpin' : 'Pin';
this.$outer.classList.add('active');
this.top = el.offsetTop - this.$outer.offsetHeight;
this.left = el.offsetLeft - 10;
Expand Down Expand Up @@ -1115,114 +1113,6 @@
referencePane.init();
});
// preserve state during navigation
function getTocPath(li) {
let path = [];
let pointer = li;
while (true) {
let parent = pointer.parentElement;
if (parent == null) {
return null;
}
let index = [].indexOf.call(parent.children, pointer);
if (index == -1) {
return null;
}
path.unshift(index);
pointer = parent.parentElement;
if (pointer == null) {
return null;
}
if (pointer.id === 'menu-toc') {
break;
}
if (pointer.tagName !== 'LI') {
return null;
}
}
return path;
}
function activateTocPath(path) {
try {
let pointer = document.getElementById('menu-toc');
for (let index of path) {
pointer = pointer.querySelector('ol').children[index];
}
pointer.classList.add('active');
} catch (e) {
// pass
}
}
function getActiveTocPaths() {
return [...menu.$menu.querySelectorAll('.active')].map(getTocPath).filter(p => p != null);
}
function loadStateFromSessionStorage() {
if (!window.sessionStorage || typeof menu === 'undefined' || window.navigating) {
return;
}
if (sessionStorage.referencePaneState != null) {
let state = JSON.parse(sessionStorage.referencePaneState);
if (state != null) {
if (state.type === 'ref') {
let entry = menu.search.biblio.byId[state.id];
if (entry != null) {
referencePane.showReferencesFor(entry);
}
} else if (state.type === 'sdo') {
let sdos = sdoMap[state.id];
if (sdos != null) {
referencePane.$headerText.innerHTML = state.html;
referencePane.showSDOsBody(sdos, state.id);
}
}
delete sessionStorage.referencePaneState;
}
}
if (sessionStorage.activeTocPaths != null) {
document
.getElementById('menu-toc')
.querySelectorAll('.active')
.forEach(e => {
e.classList.remove('active');
});
let active = JSON.parse(sessionStorage.activeTocPaths);
active.forEach(activateTocPath);
delete sessionStorage.activeTocPaths;
}
if (sessionStorage.searchValue != null) {
let value = JSON.parse(sessionStorage.searchValue);
menu.search.$searchBox.value = value;
menu.search.search(value);
delete sessionStorage.searchValue;
}
if (sessionStorage.tocScroll != null) {
let tocScroll = JSON.parse(sessionStorage.tocScroll);
menu.$toc.scrollTop = tocScroll;
delete sessionStorage.tocScroll;
}
}
document.addEventListener('DOMContentLoaded', loadStateFromSessionStorage);
window.addEventListener('pageshow', loadStateFromSessionStorage);
window.addEventListener('beforeunload', () => {
if (!window.sessionStorage || typeof menu === 'undefined') {
return;
}
sessionStorage.referencePaneState = JSON.stringify(referencePane.state || null);
sessionStorage.activeTocPaths = JSON.stringify(getActiveTocPaths());
sessionStorage.searchValue = JSON.stringify(menu.search.$searchBox.value);
sessionStorage.tocScroll = JSON.stringify(menu.$toc.scrollTop);
});
'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));
Expand Down Expand Up @@ -1255,7 +1145,7 @@
});
let sdoMap = JSON.parse(`{}`);
let biblio = JSON.parse(`{"refsByClause":{},"entries":[{"type":"clause","id":"intro","titleHTML":"Introduction","number":""},{"type":"clause","id":"sec-math.clamp","title":"Math.clamp ( min, number, max )","titleHTML":"Math.clamp ( <var>min</var>, <var>number</var>, <var>max</var> )","number":"1"},{"type":"clause","id":"sec-copyright-and-software-license","title":"Copyright & Software License","titleHTML":"Copyright &amp; Software License","number":"A"}]}`);
;let usesMultipage = false</script><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.0.1/styles/base16/solarized-light.min.css"><style>body {
display: flex;
font-size: 18px;
Expand Down Expand Up @@ -2517,25 +2407,22 @@
<li><span>Toggle "can call user code" annotations</span><code>u</code></li>

<li><span>Jump to search box</span><code>/</code></li>
</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"></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="#intro" title="Introduction">Introduction</a></li><li><span class="item-toggle-none"></span><a href="#sec-math.clamp" title="Math.clamp ( min, number, max )"><span class="secnum">1</span> Math.clamp ( <var>min</var>, <var>number</var>, <var>max</var> )</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 0 Draft / May 30, 2022</h1><h1 class="title">Math.clamp</h1>
</ul></div><div id="spec-container"><h1 class="version">Stage 0 Draft / April 22, 2023</h1><h1 class="title">Math.clamp</h1>

<emu-intro id="intro">
<h1>Introduction</h1>
<p><code>Math.clamp()</code> constrains a value between an upper and lower bound.</p>
</emu-intro>

<emu-clause id="sec-math.clamp">
<h1><span class="secnum">1</span> Math.clamp ( <var>min</var>, <var>number</var>, <var>max</var> )</h1>
<h1><span class="secnum">1</span> Math.clamp ( <var>min</var>, <var>val</var>, <var>max</var> )</h1>
<p>The <code>clamp</code> function returns a number that is the result of constraining <var>number</var> between the lower bound defined by <var>min</var> and the upper bound defined by <var>max</var>.</p>
<emu-alg><ol><li>Let <var>minCoerced</var> be ?&nbsp;ToNumber(<var>min</var>).</li><li>Let <var>numberCoerced</var> be ?&nbsp;ToNumber(<var>number</var>).</li><li>Let <var>maxCoerced</var> be ?&nbsp;ToNumber(<var>max</var>).</li><li>Return max(<var>minCoerced</var>, min(<var>numberCoerced</var>, <var>maxCoerced</var>)).</li></ol></emu-alg>
<emu-alg><ol><li>Let <var>minCoerced</var> be ?&nbsp;<emu-xref aoid="ToNumber" id="_ref_0"><a href="https://tc39.es/ecma262/#sec-tonumber">ToNumber</a></emu-xref>(<var>min</var>).</li><li>Let <var>valCoerced</var> be ?&nbsp;<emu-xref aoid="ToNumber" id="_ref_1"><a href="https://tc39.es/ecma262/#sec-tonumber">ToNumber</a></emu-xref>(<var>val</var>).</li><li>Let <var>maxCoerced</var> be ?&nbsp;<emu-xref aoid="ToNumber" id="_ref_2"><a href="https://tc39.es/ecma262/#sec-tonumber">ToNumber</a></emu-xref>(<var>max</var>).</li><li>Return <emu-xref aoid="max"><a href="https://tc39.es/ecma262/#eqn-max">max</a></emu-xref>(<var>minCoerced</var>, <emu-xref aoid="min"><a href="https://tc39.es/ecma262/#eqn-min">min</a></emu-xref>(<var>valCoerced</var>, <var>maxCoerced</var>)).</li></ol></emu-alg>
</emu-clause><emu-annex id="sec-copyright-and-software-license">
<h1><span class="secnum">A</span> Copyright &amp; Software License</h1>

<h2>Copyright Notice</h2>
<p2022 Richie Bendall</p>
<p2023 Richie Bendall</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 All @@ -2550,5 +2437,4 @@ <h2>Software License</h2>

<p>THIS SOFTWARE IS PROVIDED BY THE ECMA INTERNATIONAL "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ECMA INTERNATIONAL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</p>

</emu-annex>
</div></body>
</emu-annex></div></body>
8 changes: 4 additions & 4 deletions spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ <h1>Introduction</h1>
</emu-intro>

<emu-clause id="sec-math.clamp">
<h1>Math.clamp ( _min_, _number_, _max_ )</h1>
<h1>Math.clamp ( _min_, _val_, _max_ )</h1>
<p>The `clamp` function returns a number that is the result of constraining _number_ between the lower bound defined by _min_ and the upper bound defined by _max_.</p>
<emu-alg>
1. Let _minCoerced_ be ? ToNumber(_min_).
1. Let _numberCoerced_ be ? ToNumber(_number_).
1. Let _valCoerced_ be ? ToNumber(_val_).
1. Let _maxCoerced_ be ? ToNumber(_max_).
1. Return max(_minCoerced_, min(_numberCoerced_, _maxCoerced_)).
1. Return max(_minCoerced_, min(_valCoerced_, _maxCoerced_)).
</emu-alg>
</emu-clause>
</emu-clause>

0 comments on commit 6d1aee5

Please sign in to comment.