@samuelbradshaw/highlight-helper-js 0.7.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/publish.yml +20 -8
- package/README.md +19 -1
- package/highlight-helper.js +14 -6
- package/highlight-helper.mjs +3 -0
- package/package.json +3 -2
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
# From https://docs.github.com/en/actions/tutorials/publish-packages/publish-nodejs-packages#publishing-packages-to-the-npm-registry
|
|
2
|
-
|
|
3
1
|
name: Publish Package to npmjs
|
|
4
2
|
on:
|
|
5
3
|
release:
|
|
@@ -8,15 +6,29 @@ jobs:
|
|
|
8
6
|
build:
|
|
9
7
|
runs-on: ubuntu-latest
|
|
10
8
|
permissions:
|
|
11
|
-
contents:
|
|
9
|
+
contents: write
|
|
12
10
|
id-token: write
|
|
13
11
|
steps:
|
|
14
|
-
-
|
|
15
|
-
|
|
12
|
+
- name: Checkout code
|
|
13
|
+
uses: actions/checkout@v5
|
|
14
|
+
- name: Get release version
|
|
15
|
+
id: get_version
|
|
16
|
+
run: echo "RELEASE_VERSION=${{ github.event.release.tag_name }}" >> $GITHUB_OUTPUT
|
|
17
|
+
- name: Update package.json
|
|
18
|
+
run: npm version "${{ steps.get_version.outputs.RELEASE_VERSION }}" --no-git-tag-version
|
|
19
|
+
- name: Commit package.json changes
|
|
20
|
+
uses: stefanzweifel/git-auto-commit-action@v6
|
|
21
|
+
with:
|
|
22
|
+
commit_message: "Update package.json version to ${{ steps.get_version.outputs.RELEASE_VERSION }}"
|
|
23
|
+
branch: main
|
|
24
|
+
- name: Set up Node.js
|
|
25
|
+
uses: actions/setup-node@v4
|
|
16
26
|
with:
|
|
17
27
|
node-version: '20.x'
|
|
18
28
|
registry-url: 'https://registry.npmjs.org'
|
|
19
|
-
-
|
|
20
|
-
|
|
29
|
+
- name: Install dependencies
|
|
30
|
+
run: npm ci
|
|
31
|
+
- name: Push to npmjs
|
|
32
|
+
run: npm publish --provenance --access public
|
|
21
33
|
env:
|
|
22
|
-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
34
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
package/README.md
CHANGED
|
@@ -15,6 +15,7 @@ An HTML demo page that shows basic functionality can be found here: [Highlight H
|
|
|
15
15
|
### Documentation:
|
|
16
16
|
- [Known issues](#known-issues)
|
|
17
17
|
- [Getting started](#getting-started)
|
|
18
|
+
- [Installation options](#installation-options)
|
|
18
19
|
- [Methods, options, and custom events](#methods-options-and-custom-events)
|
|
19
20
|
- [Methods](#methods)
|
|
20
21
|
- [Options](#options)
|
|
@@ -42,7 +43,24 @@ In the source of demo.html, you’ll see CSS styles, followed by the HTML body,
|
|
|
42
43
|
3. Sets up logic to call Highlight Helper methods when buttons on the demo page are tapped, and
|
|
43
44
|
4. Sets up listeners to respond to custom event messages that come back from Highlight Helper.
|
|
44
45
|
|
|
45
|
-
|
|
46
|
+
|
|
47
|
+
### <a name="installation-options"></a>Installation options
|
|
48
|
+
|
|
49
|
+
You can download highlight-helper.js from GitHub and reference it from your HTML file:
|
|
50
|
+
```html
|
|
51
|
+
<script src="scripts/highlight-helper.js"></script>
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Or you can load it from [jsDelivr](https://www.jsdelivr.com/package/gh/samuelbradshaw/highlight-helper-js):
|
|
55
|
+
```html
|
|
56
|
+
<script src="https://cdn.jsdelivr.net/gh/samuelbradshaw/highlight-helper-js@main/highlight-helper.min.js"></script>
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Or you can install it using [npm](https://www.npmjs.com/package/@samuelbradshaw/highlight-helper-js):
|
|
60
|
+
```bash
|
|
61
|
+
% cd /your/project/folder
|
|
62
|
+
% npm i @samuelbradshaw/highlight-helper-js
|
|
63
|
+
```
|
|
46
64
|
|
|
47
65
|
|
|
48
66
|
## <a name="methods-options-and-custom-events"></a>Methods, options, and custom events
|
package/highlight-helper.js
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
* https://github.com/samuelbradshaw/highlight-helper-js
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
'use strict';
|
|
7
|
+
|
|
6
8
|
function Highlighter(options = hhDefaultOptions) {
|
|
7
9
|
for (const key of Object.keys(hhDefaultOptions)) {
|
|
8
10
|
options[key] = options[key] ?? hhDefaultOptions[key];
|
|
@@ -231,6 +233,7 @@ function Highlighter(options = hhDefaultOptions) {
|
|
|
231
233
|
range.endContainer.splitText(range.endOffset);
|
|
232
234
|
const textNodeIter = document.createNodeIterator(range.commonAncestorContainer, NodeFilter.SHOW_TEXT);
|
|
233
235
|
const relevantTextNodes = [];
|
|
236
|
+
let node;
|
|
234
237
|
while (node = textNodeIter.nextNode()) {
|
|
235
238
|
if (range.intersectsNode(node) && node !== range.startContainer && node.textContent !== '' && !node.parentElement.closest('rt') && node.parentElement.closest(options.paragraphSelector)) relevantTextNodes.push(node);
|
|
236
239
|
if (node === range.endContainer) break;
|
|
@@ -239,7 +242,7 @@ function Highlighter(options = hhDefaultOptions) {
|
|
|
239
242
|
for (let tn = 0; tn < relevantTextNodes.length; tn++) {
|
|
240
243
|
const textNode = relevantTextNodes[tn];
|
|
241
244
|
if (textNode.parentElement.dataset.highlightId) {
|
|
242
|
-
overlappingHighlightIds.add(textNode.parentElement.dataset.highlightId)
|
|
245
|
+
overlappingHighlightIds.add(textNode.parentElement.dataset.highlightId);
|
|
243
246
|
}
|
|
244
247
|
const styledMark = document.createElement('mark');
|
|
245
248
|
styledMark.dataset.highlightId = highlightId;
|
|
@@ -302,6 +305,7 @@ function Highlighter(options = hhDefaultOptions) {
|
|
|
302
305
|
template.innerHTML = htmlString;
|
|
303
306
|
let htmlElement = template.content.firstChild;
|
|
304
307
|
|
|
308
|
+
let node;
|
|
305
309
|
const textNodeIter = document.createNodeIterator(htmlElement, NodeFilter.SHOW_TEXT);
|
|
306
310
|
while (node = textNodeIter.nextNode()) node.parentNode.removeChild(node);
|
|
307
311
|
range.insertNode(htmlElement);
|
|
@@ -323,8 +327,8 @@ function Highlighter(options = hhDefaultOptions) {
|
|
|
323
327
|
// Create a new highlight, or update an existing highlight when it changes
|
|
324
328
|
this.createOrUpdateHighlight = (attributes = {}, triggeredByUserAction = true) => {
|
|
325
329
|
let highlightId = attributes.highlightId ?? activeHighlightId ?? options.highlightIdFunction();
|
|
326
|
-
appearanceChanges = [];
|
|
327
|
-
boundsChanges = [];
|
|
330
|
+
const appearanceChanges = [];
|
|
331
|
+
const boundsChanges = [];
|
|
328
332
|
|
|
329
333
|
let isNewHighlight, oldHighlightInfo;
|
|
330
334
|
if (highlightsById.hasOwnProperty(highlightId)) {
|
|
@@ -541,7 +545,7 @@ function Highlighter(options = hhDefaultOptions) {
|
|
|
541
545
|
// Get info for specified highlights, or all highlights on the page
|
|
542
546
|
this.getHighlightInfo = (highlightIds = Object.keys(highlightsById), paragraphId = null) => {
|
|
543
547
|
let filteredHighlights = []
|
|
544
|
-
for (highlightId of highlightIds) {
|
|
548
|
+
for (const highlightId of highlightIds) {
|
|
545
549
|
const highlightInfo = highlightsById[highlightId];
|
|
546
550
|
if (!paragraphId || paragraphId === highlightInfo.startParagraphId) {
|
|
547
551
|
filteredHighlights.push(highlightInfo);
|
|
@@ -1272,6 +1276,7 @@ function Highlighter(options = hhDefaultOptions) {
|
|
|
1272
1276
|
// Get line positions (bottom edge of each line)
|
|
1273
1277
|
let linePositions = new Set();
|
|
1274
1278
|
let lineWalker = document.createTreeWalker(paragraph, NodeFilter.SHOW_TEXT);
|
|
1279
|
+
let textNode;
|
|
1275
1280
|
while (textNode = lineWalker.nextNode()) {
|
|
1276
1281
|
const computedStyle = window.getComputedStyle(textNode.parentElement);
|
|
1277
1282
|
const lineHeight = parseInt((computedStyle.lineHeight === 'normal' ? computedStyle.fontSize : computedStyle.lineHeight).replace('px', ''));
|
|
@@ -1302,8 +1307,8 @@ function Highlighter(options = hhDefaultOptions) {
|
|
|
1302
1307
|
mergedRect.width = rect.width;
|
|
1303
1308
|
}
|
|
1304
1309
|
// Process then remove rects that apply to the current line
|
|
1305
|
-
minLeft = Math.min(mergedRect.x, rect.x);
|
|
1306
|
-
maxRight = Math.max(mergedRect.right, rect.right);
|
|
1310
|
+
const minLeft = Math.min(mergedRect.x, rect.x);
|
|
1311
|
+
const maxRight = Math.max(mergedRect.right, rect.right);
|
|
1307
1312
|
mergedRect.width = maxRight - minLeft;
|
|
1308
1313
|
mergedRect.x = minLeft;
|
|
1309
1314
|
unmergedRects.splice(r, 1); r--;
|
|
@@ -1447,3 +1452,6 @@ let hhDefaultOptions = {
|
|
|
1447
1452
|
}
|
|
1448
1453
|
|
|
1449
1454
|
console.info('Highlighter loaded');
|
|
1455
|
+
|
|
1456
|
+
// Make Highlighter available to ES module (highlight-helper.mjs)
|
|
1457
|
+
window.Highlighter = Highlighter;
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@samuelbradshaw/highlight-helper-js",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "JavaScript tool that enables highlighting or underlining text in an HTML page.",
|
|
5
|
-
"
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "highlight-helper.mjs",
|
|
6
7
|
"repository": {
|
|
7
8
|
"type": "git",
|
|
8
9
|
"url": "git+https://github.com/samuelbradshaw/highlight-helper-js.git"
|