From af1cd1a7b213a5c1e3e59d7980b3aa54db42fd20 Mon Sep 17 00:00:00 2001 From: Ben Allen Date: Wed, 15 Nov 2023 09:25:35 -0800 Subject: [PATCH] default to "auto", "always", "always" for display of hours, minutes, and seconds formatted in "numeric" style, except when the "numeric" style was _explicitly_ assigned to that unit --- index.html | 353 ++++++++++++++++++++++++++++++++++++++++++----------- spec.emu | 4 +- 2 files changed, 286 insertions(+), 71 deletions(-) diff --git a/index.html b/index.html index 120ac12..408c08b 100644 --- a/index.html +++ b/index.html @@ -808,6 +808,10 @@ this.$header.appendChild(this.$headerText); this.$headerRefId = document.createElement('a'); this.$header.appendChild(this.$headerRefId); + this.$header.addEventListener('pointerdown', e => { + this.dragStart(e); + }); + this.$closeButton = document.createElement('span'); this.$closeButton.setAttribute('id', 'references-pane-close'); this.$closeButton.addEventListener('click', () => { @@ -816,16 +820,16 @@ this.$header.appendChild(this.$closeButton); this.$pane.appendChild(this.$header); - let tableContainer = document.createElement('div'); - tableContainer.setAttribute('id', 'references-pane-table-container'); + this.$tableContainer = document.createElement('div'); + this.$tableContainer.setAttribute('id', 'references-pane-table-container'); this.$table = document.createElement('table'); this.$table.setAttribute('id', 'references-pane-table'); this.$tableBody = this.$table.createTBody(); - tableContainer.appendChild(this.$table); - this.$pane.appendChild(tableContainer); + this.$tableContainer.appendChild(this.$table); + this.$pane.appendChild(this.$tableContainer); menu.$specContainer.appendChild(this.$container); }, @@ -847,7 +851,7 @@ let previousId; let previousCell; let dupCount = 0; - this.$headerRefId.textContent = '#' + entry.id; + this.$headerRefId.innerHTML = getKey(entry); this.$headerRefId.setAttribute('href', makeLinkToId(entry.id)); this.$headerRefId.style.display = 'inline'; (entry.referencingIds || []) @@ -878,6 +882,7 @@ this.$table.removeChild(this.$tableBody); this.$tableBody = newBody; this.$table.appendChild(this.$tableBody); + this.autoSize(); }, showSDOs(sdos, alternativeId) { @@ -924,6 +929,34 @@ this.$table.removeChild(this.$tableBody); this.$tableBody = newBody; this.$table.appendChild(this.$tableBody); + this.autoSize(); + }, + + autoSize() { + this.$tableContainer.style.height = + Math.min(250, this.$table.getBoundingClientRect().height) + 'px'; + }, + + dragStart(pointerDownEvent) { + let startingMousePos = pointerDownEvent.clientY; + let startingHeight = this.$tableContainer.getBoundingClientRect().height; + let moveListener = pointerMoveEvent => { + if (pointerMoveEvent.buttons === 0) { + removeListeners(); + return; + } + let desiredHeight = startingHeight - (pointerMoveEvent.clientY - startingMousePos); + this.$tableContainer.style.height = Math.max(0, desiredHeight) + 'px'; + }; + let listenerOptions = { capture: true, passive: true }; + let removeListeners = () => { + document.removeEventListener('pointermove', moveListener, listenerOptions); + this.$header.removeEventListener('pointerup', removeListeners, listenerOptions); + this.$header.removeEventListener('pointercancel', removeListeners, listenerOptions); + }; + document.addEventListener('pointermove', moveListener, listenerOptions); + this.$header.addEventListener('pointerup', removeListeners, listenerOptions); + this.$header.addEventListener('pointercancel', removeListeners, listenerOptions); }, }; @@ -954,7 +987,9 @@ referencePane.showReferencesFor(this.entry); }); this.$container.appendChild(this.$permalink); + this.$container.appendChild(document.createTextNode(' ')); this.$container.appendChild(this.$pinLink); + this.$container.appendChild(document.createTextNode(' ')); this.$container.appendChild(this.$refsLink); document.body.appendChild(this.$outer); }, @@ -1419,14 +1454,183 @@ }); }); +'use strict'; + +// Update superscripts to not suffer misinterpretation when copied and pasted as plain text. +// For example, +// * Replace `103` with +// `103` +// so it gets pasted as `10**3` rather than `103`. +// * Replace `10-x` with +// `10-x` +// so it gets pasted as `10**-x` rather than `10-x`. +// * Replace `2a + 1` with +// `2**(a + 1)` +// so it gets pasted as `2**(a + 1)` rather than `2a + 1`. + +function makeExponentPlainTextSafe(sup) { + // Change a only if it appears to be an exponent: + // * text-only and contains only mathematical content (not e.g. `1st`) + // * contains only s and internal links (e.g. + // `2(_y_)`) + const isText = [...sup.childNodes].every(node => node.nodeType === 3); + const text = sup.textContent; + if (isText) { + if (!/^[0-9. 𝔽ℝℤ()=*×/÷±+\u2212-]+$/u.test(text)) { + return; + } + } else { + if (sup.querySelector('*:not(var, emu-xref, :scope emu-xref a)')) { + return; + } + } + + let prefix = '**'; + let suffix = ''; + + // Add wrapping parentheses unless they are already present + // or this is a simple (possibly signed) integer or single-variable exponent. + const skipParens = + /^[±+\u2212-]?(?:[0-9]+|\p{ID_Start}\p{ID_Continue}*)$/u.test(text) || + // Split on parentheses and remember them; the resulting parts must + // start and end empty (i.e., with open/close parentheses) + // and increase depth to 1 only at the first parenthesis + // to e.g. wrap `(a+1)*(b+1)` but not `((a+1)*(b+1))`. + text + .trim() + .split(/([()])/g) + .reduce((depth, s, i, parts) => { + if (s === '(') { + return depth > 0 || i === 1 ? depth + 1 : NaN; + } else if (s === ')') { + return depth > 0 ? depth - 1 : NaN; + } else if (s === '' || (i > 0 && i < parts.length - 1)) { + return depth; + } + return NaN; + }, 0) === 0; + if (!skipParens) { + prefix += '('; + suffix += ')'; + } + + sup.insertAdjacentHTML('beforebegin', ``); + if (suffix) { + sup.insertAdjacentHTML('afterend', ``); + } +} + +document.addEventListener('DOMContentLoaded', () => { + document.querySelectorAll('sup:not(.text)').forEach(sup => { + makeExponentPlainTextSafe(sup); + }); +}); + let sdoMap = JSON.parse(`{}`); let biblio = JSON.parse(`{"refsByClause":{"sec-duration-records":["_ref_0","_ref_6"],"sec-durationrecordsign":["_ref_1","_ref_21"],"sec-isvaliddurationrecord":["_ref_2","_ref_22","_ref_23"],"sec-partitiondurationformatpattern":["_ref_3","_ref_24","_ref_25","_ref_26"],"sec-Intl.DurationFormat":["_ref_4","_ref_27","_ref_28","_ref_29","_ref_30"],"sec-Intl.DurationFormat.prototype.resolvedOptions":["_ref_5"],"sec-todurationrecord":["_ref_7","_ref_8","_ref_9","_ref_10","_ref_11","_ref_12","_ref_13","_ref_14","_ref_15","_ref_16","_ref_17","_ref_18","_ref_19","_ref_20"],"sec-Intl.DurationFormat.prototype":["_ref_31"],"sec-Intl.DurationFormat.supportedLocalesOf":["_ref_32"],"sec-Intl.DurationFormat.prototype.constructor":["_ref_33"],"sec-Intl.DurationFormat.prototype.format":["_ref_34","_ref_35"],"sec-Intl.DurationFormat.prototype.formatToParts":["_ref_36","_ref_37"],"sec-properties-of-intl-durationformat-instances":["_ref_38"]},"entries":[{"type":"term","term":"Duration Record","refId":"sec-duration-records"},{"type":"table","id":"table-duration-record-fields","number":1,"caption":"Table 1: Duration Record Fields","referencingIds":["_ref_0","_ref_1","_ref_2"]},{"type":"clause","id":"sec-duration-records","titleHTML":"Duration Records","number":"1.1.1","referencingIds":["_ref_6","_ref_7","_ref_8","_ref_9","_ref_21","_ref_22","_ref_24"]},{"type":"op","aoid":"ToIntegerIfIntegral","refId":"sec-tointegerwithoutrounding"},{"type":"clause","id":"sec-tointegerwithoutrounding","title":"ToIntegerIfIntegral ( argument )","titleHTML":"ToIntegerIfIntegral ( argument )","number":"1.1.2","referencingIds":["_ref_10","_ref_11","_ref_12","_ref_13","_ref_14","_ref_15","_ref_16","_ref_17","_ref_18","_ref_19"]},{"type":"op","aoid":"ToDurationRecord","refId":"sec-todurationrecord"},{"type":"clause","id":"sec-todurationrecord","title":"ToDurationRecord ( input )","titleHTML":"ToDurationRecord ( input )","number":"1.1.3","referencingIds":["_ref_34","_ref_36"]},{"type":"op","aoid":"DurationRecordSign","refId":"sec-durationrecordsign"},{"type":"clause","id":"sec-durationrecordsign","title":"DurationRecordSign ( record )","titleHTML":"DurationRecordSign ( record )","number":"1.1.4","referencingIds":["_ref_23"]},{"type":"op","aoid":"IsValidDurationRecord","refId":"sec-isvaliddurationrecord"},{"type":"clause","id":"sec-isvaliddurationrecord","title":"IsValidDurationRecord ( record )","titleHTML":"IsValidDurationRecord ( record )","number":"1.1.5","referencingIds":["_ref_20"]},{"type":"op","aoid":"GetDurationUnitOptions","refId":"sec-getdurationunitoptions"},{"type":"clause","id":"sec-getdurationunitoptions","title":"GetDurationUnitOptions ( unit, options, baseStyle, stylesList, digitalBase, prevStyle )","titleHTML":"GetDurationUnitOptions ( unit, options, baseStyle, stylesList, digitalBase, prevStyle )","number":"1.1.6","referencingIds":["_ref_30"]},{"type":"table","id":"table-partition-duration-format-pattern","number":2,"caption":"Table 2: DurationFormat instance internal slots and properties relevant to PartitionDurationFormatPattern","referencingIds":["_ref_3"]},{"type":"op","aoid":"PartitionDurationFormatPattern","refId":"sec-partitiondurationformatpattern"},{"type":"clause","id":"sec-partitiondurationformatpattern","title":"PartitionDurationFormatPattern ( durationFormat, duration )","titleHTML":"PartitionDurationFormatPattern ( durationFormat, duration )","number":"1.1.7","referencingIds":["_ref_26","_ref_35","_ref_37"]},{"type":"clause","id":"sec-intl-durationformat-abstracts","titleHTML":"Abstract Operations for DurationFormat Objects","number":"1.1"},{"type":"term","term":"%DurationFormat%","refId":"sec-intl-durationformat-constructor"},{"type":"table","id":"table-durationformat","number":3,"caption":"Table 3: Internal slots and property names of DurationFormat instances relevant to Intl.DurationFormat constructor","referencingIds":["_ref_4"]},{"type":"clause","id":"sec-Intl.DurationFormat","title":"Intl.DurationFormat ( [ locales [ , options ] ] )","titleHTML":"Intl.DurationFormat ( [ locales [ , options ] ] )","number":"1.2.1"},{"type":"clause","id":"sec-intl-durationformat-constructor","titleHTML":"The Intl.DurationFormat Constructor","number":"1.2","referencingIds":["_ref_25","_ref_27","_ref_28","_ref_29","_ref_32","_ref_33"]},{"type":"clause","id":"sec-Intl.DurationFormat.prototype","titleHTML":"Intl.DurationFormat.prototype","number":"1.3.1"},{"type":"clause","id":"sec-Intl.DurationFormat.supportedLocalesOf","title":"Intl.DurationFormat.supportedLocalesOf ( locales [ , options ] )","titleHTML":"Intl.DurationFormat.supportedLocalesOf ( locales [ , options ] )","number":"1.3.2"},{"type":"clause","id":"sec-Intl.DurationFormat-internal-slots","titleHTML":"Internal slots","number":"1.3.3"},{"type":"clause","id":"sec-properties-of-intl-durationformat-constructor","titleHTML":"Properties of the Intl.DurationFormat Constructor","number":"1.3"},{"type":"term","term":"%DurationFormatPrototype%","refId":"sec-properties-of-intl-durationformat-prototype-object"},{"type":"clause","id":"sec-Intl.DurationFormat.prototype.constructor","titleHTML":"Intl.DurationFormat.prototype.constructor","number":"1.4.1"},{"type":"clause","id":"sec-Intl.DurationFormat.prototype-@@tostringtag","titleHTML":"Intl.DurationFormat.prototype [ @@toStringTag ]","number":"1.4.2"},{"type":"clause","id":"sec-Intl.DurationFormat.prototype.format","title":"Intl.DurationFormat.prototype.format ( duration )","titleHTML":"Intl.DurationFormat.prototype.format ( duration )","number":"1.4.3"},{"type":"clause","id":"sec-Intl.DurationFormat.prototype.formatToParts","title":"Intl.DurationFormat.prototype.formatToParts ( duration )","titleHTML":"Intl.DurationFormat.prototype.formatToParts ( duration )","number":"1.4.4"},{"type":"table","id":"table-durationformat-resolvedoptions-properties","number":4,"caption":"Table 4: Resolved Options of DurationFormat Instances","referencingIds":["_ref_5"]},{"type":"clause","id":"sec-Intl.DurationFormat.prototype.resolvedOptions","titleHTML":"Intl.DurationFormat.prototype.resolvedOptions ( )","number":"1.4.5"},{"type":"clause","id":"sec-properties-of-intl-durationformat-prototype-object","titleHTML":"Properties of the Intl.DurationFormat Prototype Object","number":"1.4","referencingIds":["_ref_31","_ref_38"]},{"type":"clause","id":"sec-properties-of-intl-durationformat-instances","titleHTML":"Properties of Intl.DurationFormat Instances","number":"1.5"},{"type":"clause","id":"durationformat-objects","titleHTML":"DurationFormat Objects","number":"1"},{"type":"clause","id":"sec-copyright-and-software-license","title":"Copyright & Software License","titleHTML":"Copyright & Software License","number":"A"}]}`); -;let usesMultipage = false