highlighter-pen 1.0.2 → 1.0.4
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/README.md +1 -1
- package/dist/highlighter-pen.js +30 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -34,7 +34,7 @@ It behaves like a real highlighter: drag your mouse over text and see a custom o
|
|
|
34
34
|
### CDN (recommended)
|
|
35
35
|
|
|
36
36
|
```html
|
|
37
|
-
<script src="https://cdn.jsdelivr.net/gh/mimoklef/highlighter-pen@v1.0.
|
|
37
|
+
<script src="https://cdn.jsdelivr.net/gh/mimoklef/highlighter-pen@v1.0.4/dist/highlighter-pen.js"></script>
|
|
38
38
|
<script>
|
|
39
39
|
HighlighterPen().init();
|
|
40
40
|
</script>
|
package/dist/highlighter-pen.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* Highlighter pen v1.0.
|
|
2
|
+
* Highlighter pen v1.0.4
|
|
3
3
|
* Marker-like selection overlay using <marker> + optional native input selection yellow.
|
|
4
4
|
* https://github.com/mimoklef/highlighter-pen/
|
|
5
5
|
* © 2026 Morgan Bouyakhlef
|
|
@@ -9,12 +9,12 @@
|
|
|
9
9
|
"use strict";
|
|
10
10
|
|
|
11
11
|
const DEFAULTS = {
|
|
12
|
-
markerImage: "https://cdn.jsdelivr.net/gh/mimoklef/highlighter-pen@v1.0.
|
|
13
|
-
markerZIndex: 10,
|
|
14
|
-
hideNativeSelection: true,
|
|
15
|
-
inputSelectionYellow: true,
|
|
12
|
+
markerImage: "https://cdn.jsdelivr.net/gh/mimoklef/highlighter-pen@v1.0.4/assets/marker.png",
|
|
13
|
+
markerZIndex: 10,
|
|
14
|
+
hideNativeSelection: true,
|
|
15
|
+
inputSelectionYellow: true,
|
|
16
16
|
inputSelectionColor: "rgba(255,235,59,0.95)",
|
|
17
|
-
exclude: "input, textarea, select, button, label"
|
|
17
|
+
exclude: "input, textarea, select, button, label"
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
function createStyle(id, cssText) {
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
let padBottom = 0;
|
|
47
47
|
let destroyed = false;
|
|
48
48
|
|
|
49
|
-
let onSelectionChange, onScroll, onResize, onPointerDown;
|
|
49
|
+
let onSelectionChange, onScroll, onResize, onPointerDown, onKeyDown;
|
|
50
50
|
|
|
51
51
|
function injectStyles() {
|
|
52
52
|
createStyle(
|
|
@@ -120,7 +120,6 @@ input::-moz-selection, textarea::-moz-selection { background: ${opt.inputSelecti
|
|
|
120
120
|
return;
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
// Keep native selection (yellow) inside text inputs/textarea
|
|
124
123
|
const ae = document.activeElement;
|
|
125
124
|
if (isTextLikeInput(ae)) {
|
|
126
125
|
clearOverlays();
|
|
@@ -129,7 +128,6 @@ input::-moz-selection, textarea::-moz-selection { background: ${opt.inputSelecti
|
|
|
129
128
|
|
|
130
129
|
const range = sel.getRangeAt(0);
|
|
131
130
|
|
|
132
|
-
// avoid nesting markers
|
|
133
131
|
const sp = range.startContainer.parentElement;
|
|
134
132
|
const ep = range.endContainer.parentElement;
|
|
135
133
|
if ((sp && sp.closest("marker")) || (ep && ep.closest("marker"))) return;
|
|
@@ -152,8 +150,6 @@ input::-moz-selection, textarea::-moz-selection { background: ${opt.inputSelecti
|
|
|
152
150
|
m.style.display = "block";
|
|
153
151
|
m.style.pointerEvents = "none";
|
|
154
152
|
m.style.margin = "0";
|
|
155
|
-
|
|
156
|
-
// avoid double-padding (already included in top/height)
|
|
157
153
|
m.style.padding = "0";
|
|
158
154
|
|
|
159
155
|
document.body.appendChild(m);
|
|
@@ -184,12 +180,33 @@ input::-moz-selection, textarea::-moz-selection { background: ${opt.inputSelecti
|
|
|
184
180
|
const el = e.target && e.target.closest(opt.exclude);
|
|
185
181
|
if (!el) return;
|
|
186
182
|
|
|
187
|
-
// keep native selection inside text-like inputs/textarea
|
|
188
183
|
if (isTextLikeInput(el)) return;
|
|
189
184
|
|
|
190
185
|
cancelSelection();
|
|
191
186
|
};
|
|
192
187
|
|
|
188
|
+
// Ensure a clean selection state before browser "select all"
|
|
189
|
+
onKeyDown = (e) => {
|
|
190
|
+
const key = (e.key || "").toLowerCase();
|
|
191
|
+
const isSelectAll = (e.ctrlKey || e.metaKey) && !e.shiftKey && key === "a";
|
|
192
|
+
if (!isSelectAll) return;
|
|
193
|
+
|
|
194
|
+
const ae = document.activeElement;
|
|
195
|
+
|
|
196
|
+
if (isTextLikeInput(ae)) {
|
|
197
|
+
clearOverlays();
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
clearOverlays();
|
|
202
|
+
|
|
203
|
+
const sel = window.getSelection();
|
|
204
|
+
if (sel && sel.rangeCount) {
|
|
205
|
+
sel.removeAllRanges();
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
document.addEventListener("keydown", onKeyDown, true);
|
|
193
210
|
document.addEventListener("selectionchange", onSelectionChange);
|
|
194
211
|
window.addEventListener("scroll", onScroll, { passive: true });
|
|
195
212
|
window.addEventListener("resize", onResize);
|
|
@@ -206,6 +223,7 @@ input::-moz-selection, textarea::-moz-selection { background: ${opt.inputSelecti
|
|
|
206
223
|
window.removeEventListener("scroll", onScroll);
|
|
207
224
|
window.removeEventListener("resize", onResize);
|
|
208
225
|
document.removeEventListener("pointerdown", onPointerDown, true);
|
|
226
|
+
document.removeEventListener("keydown", onKeyDown, true);
|
|
209
227
|
}
|
|
210
228
|
|
|
211
229
|
const api = { init, draw, clear: clearOverlays, cancelSelection, destroy, options: opt };
|
|
@@ -215,7 +233,6 @@ input::-moz-selection, textarea::-moz-selection { background: ${opt.inputSelecti
|
|
|
215
233
|
global.HighlighterPen = HighlighterPen;
|
|
216
234
|
})(typeof window !== "undefined" ? window : this);
|
|
217
235
|
|
|
218
|
-
// --- npm / node export (CommonJS) ---
|
|
219
236
|
if (typeof module !== "undefined" && typeof module.exports !== "undefined") {
|
|
220
237
|
module.exports = globalThis.HighlighterPen;
|
|
221
238
|
}
|