norightclick 0.0.1 → 1.0.0

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/CHANGELOG.md ADDED
@@ -0,0 +1,21 @@
1
+ # Changelog
2
+
3
+ All notable changes to norightclick are listed here. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project uses [semantic versioning](https://semver.org/).
4
+
5
+ ## [1.0.0] - 2026-12-05
6
+
7
+ First public release.
8
+
9
+ ### Added
10
+
11
+ - `protect(options?)`: blocks the right-click menu and protects images, and returns a function that turns it off. Several calls can be active at once.
12
+ - Options to block copying, cutting, text selection, dragging, Ctrl/Cmd+S and Ctrl/Cmd+P (with a blank printout).
13
+ - `credit`: copying stays allowed, and a source line with a link to the page is added to the plain-text and rich-text clipboard.
14
+ - Images: no right-click, no dragging, and no long-press "Save image" in iOS Safari.
15
+ - `target` and `allow` to protect part of a page; inputs, text areas, selects and editable areas always keep working.
16
+ - `message` (announced to screen readers) and `onBlock`.
17
+ - Classic `<script>` build for any site, configured with `data-` attributes, with `data-manual` to call it yourself.
18
+ - Safe during server-side rendering. About 1.6 kB minified and gzipped, zero dependencies, typed.
19
+ - Tests in jsdom, and in real Chromium and WebKit, including the real clipboard.
20
+
21
+ [1.0.0]: https://github.com/ckgiri/norightclick/releases/tag/v1.0.0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ckgiri
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,7 +1,203 @@
1
+ <div align="center">
2
+
3
+ <picture>
4
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/ckgiri/norightclick/main/assets/logo-dark.svg">
5
+ <img src="https://raw.githubusercontent.com/ckgiri/norightclick/main/assets/logo.svg" alt="norightclick logo" width="96" height="96">
6
+ </picture>
7
+
1
8
  # norightclick
2
9
 
3
- Reserved package name. Coming soon: stop casual copying on your site.
10
+ ### Disable right-click, copying and image saving on your site
11
+
12
+ Stop casual visitors from right-clicking, copying text or saving images, with one script tag or one import.<br>
13
+ Or let them copy, and add a link back to your page to everything they paste. Forms, keyboard and screen readers keep working.
14
+
15
+ [![npm version](https://img.shields.io/npm/v/norightclick?color=cb3837&logo=npm)](https://www.npmjs.com/package/norightclick)
16
+ ![Size](https://img.shields.io/badge/gzipped-1.6%20kB-brightgreen)
17
+ ![Zero dependencies](https://img.shields.io/badge/dependencies-0-brightgreen)
18
+ [![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
19
+
20
+ **one script tag** · **credit link on copy** · **images on iOS too** · **forms keep working** · **undo anytime** · **any framework**
21
+
22
+ [**Live demo**](https://ckgiri.github.io/norightclick/) · [Quick start](#-quick-start) · [What it does](#-what-it-does) · [Options](#%EF%B8%8F-options) · [Script tag](#-script-tag-options) · [Frameworks](#-frameworks) · [Be honest about it](#-what-it-cannot-do) · [FAQ](#-faq)
23
+
24
+ </div>
25
+
26
+ ---
27
+
28
+ ## 🚀 Quick start
29
+
30
+ **Plain HTML, WordPress, Shopify, Webflow, any site:** paste this into the `<head>`.
31
+
32
+ ```html
33
+ <script src="https://cdn.jsdelivr.net/npm/norightclick@1"></script>
34
+ ```
35
+
36
+ That's it: no right-click menu on the page, and images can't be dragged out or saved with a long press. Want more? Add [data attributes](#-script-tag-options):
37
+
38
+ ```html
39
+ <script
40
+ src="https://cdn.jsdelivr.net/npm/norightclick@1"
41
+ data-copy
42
+ data-select
43
+ data-message="Content is protected"
44
+ ></script>
45
+ ```
46
+
47
+ **With a bundler:**
48
+
49
+ ```sh
50
+ npm install norightclick
51
+ ```
52
+
53
+ ```js
54
+ import { protect } from 'norightclick';
55
+
56
+ protect(); // no right-click menu, images protected
57
+ protect({ copy: true, select: true }); // also no copying or selecting text
58
+ protect({ credit: true }); // copying works, with "Source: <your page>" added to what's pasted
59
+ ```
60
+
61
+ `protect()` returns a function that turns protection off again.
62
+
63
+ ## 🎯 What it does
64
+
65
+ | You want to | norightclick |
66
+ | ------------------------------------- | --------------------------------------------------------------------------------------------------- |
67
+ | 🖱️ Hide the right-click menu | Blocked on the page, but not in inputs, text areas or editable areas, so people can still paste |
68
+ | 🖼️ Stop people saving your photos | No right-click, no dragging to the desktop, and no "Save image" on a long press in iOS Safari |
69
+ | 📋 Stop copying, or get credit for it | Block copy and cut, or keep copying and append a credit line with a link (plain text and rich text) |
70
+ | ✂️ Stop text selection | Blocked with CSS and events; form fields stay selectable |
71
+ | 💾 Discourage Save page / Print | Ctrl+S / Cmd+S and Ctrl+P / Cmd+P blocked, and printing gives a blank page |
72
+ | 🎯 Protect only part of the page | `target: '#article'`, and `allow: '.code'` for parts people should be able to copy (code samples) |
73
+ | 💬 Tell people why | An optional short message, announced to screen readers too |
74
+
75
+ About 1.6 kB minified and gzipped, no dependencies, typed, safe during server-side rendering, and tested in real Chromium and WebKit on every change.
76
+
77
+ ## ⚙️ Options
78
+
79
+ ```js
80
+ protect({
81
+ contextmenu: true, // block the right-click menu
82
+ images: true, // protect images: no right-click, drag, or iOS long-press save
83
+ copy: false, // block copy and cut
84
+ select: false, // block text selection
85
+ drag: false, // block dragging text and links out of the page
86
+ save: false, // block Ctrl+S / Cmd+S
87
+ print: false, // block Ctrl+P / Cmd+P and print a blank page
88
+ credit: false, // true, or ({ title, url, text }) => 'your line'
89
+ creditMinLength: 20, // shorter copies get no credit line
90
+ allow: '.code, .share', // never protected (added to inputs, text areas, selects, editable areas)
91
+ target: '#article', // an element or selector; default: the whole page
92
+ message: 'Content is protected', // shown briefly when something is blocked
93
+ onBlock: (action, event) => {}, // 'contextmenu' | 'copy' | 'cut' | 'select' | 'drag' | 'save' | 'print'
94
+ });
95
+ ```
96
+
97
+ **Images only** (right-click still works on text):
98
+
99
+ ```js
100
+ protect({ contextmenu: false });
101
+ ```
102
+
103
+ **A custom credit line:**
104
+
105
+ ```js
106
+ protect({ credit: ({ title, url }) => `Read the full article "${title}" at ${url}` });
107
+ ```
108
+
109
+ Anything with the `data-norightclick-allow` attribute is never protected, without changing your options.
110
+
111
+ ## 🏷️ Script tag options
112
+
113
+ The script tag reads the same options from `data-` attributes. A flag is on when present, and off with `="false"`.
114
+
115
+ | Attribute | Same as |
116
+ | ---------------------------------------------------------------------------- | ------------------------------------- |
117
+ | `data-copy` `data-select` `data-drag` `data-save` `data-print` `data-credit` | `copy: true`, … |
118
+ | `data-contextmenu="false"` `data-images="false"` | `contextmenu: false`, `images: false` |
119
+ | `data-message="Content is protected"` | `message` |
120
+ | `data-allow=".code"` `data-target="#article"` `data-credit-min-length="50"` | `allow`, `target`, `creditMinLength` |
121
+ | `data-manual` | don't protect yet; call it yourself |
122
+
123
+ With `data-manual`, the script only defines `window.norightclick`:
124
+
125
+ ```html
126
+ <script src="https://cdn.jsdelivr.net/npm/norightclick@1" data-manual></script>
127
+ <script>
128
+ const off = norightclick.protect({ copy: true });
129
+ </script>
130
+ ```
131
+
132
+ `data-target` works in the `<head>`: the script waits for the page to load before looking for the element.
133
+
134
+ ## 🧩 Frameworks
135
+
136
+ **React**
137
+
138
+ ```jsx
139
+ import { useEffect } from 'react';
140
+ import { protect } from 'norightclick';
141
+
142
+ export function Article({ children }) {
143
+ useEffect(() => protect({ target: '#article', credit: true }), []);
144
+ return <article id="article">{children}</article>;
145
+ }
146
+ ```
147
+
148
+ **Vue**
149
+
150
+ ```js
151
+ import { onMounted, onUnmounted } from 'vue';
152
+ import { protect } from 'norightclick';
153
+
154
+ let off;
155
+ onMounted(() => (off = protect({ copy: true })));
156
+ onUnmounted(() => off());
157
+ ```
158
+
159
+ **Svelte**
160
+
161
+ ```svelte
162
+ <script>
163
+ import { onMount } from 'svelte';
164
+ import { protect } from 'norightclick';
165
+ onMount(() => protect());
166
+ </script>
167
+ ```
168
+
169
+ **Next.js / Nuxt / Astro:** call `protect()` in client code (an effect, `onMounted`, or a `<script>`). On the server it does nothing.
170
+
171
+ ## 🙏 What it cannot do
172
+
173
+ Be honest with yourself and your clients: **this is a deterrent, not security.** Anything a browser can show, a visitor can keep. View source, developer tools, screenshots, reader mode, turning off JavaScript, or a browser extension all get around it. norightclick stops the casual right-click and copy, which is most of them, and the credit option turns copying into backlinks instead of fighting it.
174
+
175
+ If content must stay private, don't send it to the browser: put it behind a login, watermark your images, or serve lower-resolution versions.
176
+
177
+ ## ♿ Accessibility
178
+
179
+ - Keyboard navigation, screen readers and browser zoom are never touched.
180
+ - Inputs, text areas, selects and editable areas always keep right-click, copy, paste and selection.
181
+ - The `message` is a `role="status"` element, so screen readers announce it.
182
+ - Blocking selection and copying makes life harder for people who use them to translate, look up words or have text read aloud. Prefer `credit: true`, or protect only part of the page with `target`.
183
+
184
+ ## ❓ FAQ
185
+
186
+ **Does it stop people saving images on phones?**
187
+ In iOS Safari, the long-press "Save image" menu is turned off with `-webkit-touch-callout: none`. On Android, Chrome's long-press menu fires a `contextmenu` event, which is blocked. Screenshots still work, of course.
188
+
189
+ **Will it break my forms or my comment box?**
190
+ No. Inputs, text areas, selects and editable areas are never protected. Add anything else with `allow` or `data-norightclick-allow`.
191
+
192
+ **Does it hurt SEO?**
193
+ No. Search engines read your HTML; the text is all still there.
194
+
195
+ **Can I protect against developer tools too?**
196
+ See [noinspect](https://www.npmjs.com/package/noinspect), the companion package. It is a deterrent too.
197
+
198
+ **Can I call `protect()` more than once?**
199
+ Yes. Each call is independent and returns its own off switch.
200
+
201
+ ## 📄 License
4
202
 
5
- - Disable the right-click menu everywhere or only on chosen elements, with an optional message
6
- - Block copying, text selection, dragging and saving images, while inputs, links and screen readers keep working
7
- - One line in plain HTML, or `import` it in any framework
203
+ [MIT](LICENSE)
@@ -0,0 +1,54 @@
1
+ /**
2
+ * norightclick: discourage casual copying on a web page.
3
+ *
4
+ * ```js
5
+ * import { protect } from 'norightclick';
6
+ *
7
+ * protect(); // no right-click menu, images can't be dragged or long-pressed
8
+ * protect({ copy: true, select: true }); // also no copying or selecting text
9
+ * protect({ credit: true }); // copying is allowed, with a link back to your page
10
+ * ```
11
+ *
12
+ * Inputs, text areas, editable areas and anything matching `allow` keep working, and so do keyboard navigation and
13
+ * screen readers. This deters casual visitors; it cannot stop someone determined (view source, screenshots).
14
+ */
15
+ /** What can be blocked. Passed to `onBlock`. */
16
+ export type Action = 'contextmenu' | 'copy' | 'cut' | 'select' | 'drag' | 'save' | 'print';
17
+ export interface Options {
18
+ /** Block the right-click (context) menu. Default `true`. */
19
+ contextmenu?: boolean;
20
+ /** Protect images: no right-click, dragging or "Save image" on long press (iOS). Default `true`. */
21
+ images?: boolean;
22
+ /** Block copying and cutting text. Default `false`. */
23
+ copy?: boolean;
24
+ /** Block selecting text. Default `false`. */
25
+ select?: boolean;
26
+ /** Block dragging text and links out of the page. Default `false`. */
27
+ drag?: boolean;
28
+ /** Block Ctrl+S / Cmd+S (save page). Default `false`. */
29
+ save?: boolean;
30
+ /** Block Ctrl+P / Cmd+P, and print a blank page. Default `false`. */
31
+ print?: boolean;
32
+ /**
33
+ * Allow copying, but add a credit line with a link to the page. `true` for the default line
34
+ * ("Source: Page title https://..."), or a function that returns the line. Ignored when `copy` is blocked.
35
+ */
36
+ credit?: boolean | ((page: {
37
+ title: string;
38
+ url: string;
39
+ text: string;
40
+ }) => string);
41
+ /** Copies shorter than this many characters get no credit line. Default `20`. */
42
+ creditMinLength?: number;
43
+ /** Elements that are never protected, as a CSS selector. Added to: inputs, text areas, selects, editable areas. */
44
+ allow?: string;
45
+ /** Where protection applies: an element or a CSS selector. Default: the whole page. */
46
+ target?: Element | string;
47
+ /** A short message shown when something is blocked, e.g. "Content is protected". */
48
+ message?: string;
49
+ /** Called when something is blocked. */
50
+ onBlock?: (action: Action, event: Event) => void;
51
+ }
52
+ /** Turns on protection. Returns a function that turns it off again. Several calls can be active at once. */
53
+ export declare function protect(options?: Options): () => void;
54
+ export default protect;
package/dist/index.js ADDED
@@ -0,0 +1,170 @@
1
+ /**
2
+ * norightclick: discourage casual copying on a web page.
3
+ *
4
+ * ```js
5
+ * import { protect } from 'norightclick';
6
+ *
7
+ * protect(); // no right-click menu, images can't be dragged or long-pressed
8
+ * protect({ copy: true, select: true }); // also no copying or selecting text
9
+ * protect({ credit: true }); // copying is allowed, with a link back to your page
10
+ * ```
11
+ *
12
+ * Inputs, text areas, editable areas and anything matching `allow` keep working, and so do keyboard navigation and
13
+ * screen readers. This deters casual visitors; it cannot stop someone determined (view source, screenshots).
14
+ */
15
+ const ALWAYS_ALLOWED = 'input,textarea,select,[contenteditable]:not([contenteditable="false"]),[data-norightclick-allow]';
16
+ let count = 0;
17
+ let toast;
18
+ let toastTimer;
19
+ function showMessage(text) {
20
+ const doc = window.document;
21
+ if (!toast) {
22
+ toast = doc.createElement('div');
23
+ toast.setAttribute('role', 'status');
24
+ toast.style.cssText =
25
+ 'position:fixed;left:50%;bottom:24px;transform:translateX(-50%);z-index:2147483647;max-width:90vw;' +
26
+ 'padding:10px 16px;border-radius:8px;background:#111;color:#fff;font:14px/1.4 system-ui,sans-serif;' +
27
+ 'box-shadow:0 4px 16px rgba(0,0,0,.25);pointer-events:none';
28
+ }
29
+ toast.textContent = text;
30
+ if (!toast.isConnected)
31
+ doc.body.appendChild(toast);
32
+ clearTimeout(toastTimer);
33
+ toastTimer = setTimeout(() => toast?.remove(), 2000);
34
+ }
35
+ function escapeHtml(text) {
36
+ return text.replace(/[&<>"]/g, (c) => `&#${c.charCodeAt(0)};`);
37
+ }
38
+ /** Turns on protection. Returns a function that turns it off again. Several calls can be active at once. */
39
+ export function protect(options = {}) {
40
+ if (typeof window === 'undefined' || !window.document)
41
+ return () => undefined;
42
+ const doc = window.document;
43
+ const { contextmenu = true, images = true, copy = false, select = false, drag = false, save = false, print = false, credit = false, creditMinLength = 20, message, onBlock, } = options;
44
+ const root = typeof options.target === 'string' ? doc.querySelector(options.target) : (options.target ?? doc.documentElement);
45
+ if (!root)
46
+ return () => undefined;
47
+ const allow = options.allow ? `${ALWAYS_ALLOWED},${options.allow}` : ALWAYS_ALLOWED;
48
+ // CSS does what events can't: no selection highlight, no iOS long-press menu on images, a blank printout.
49
+ const id = `data-norightclick-${++count}`;
50
+ const scope = `[${id}]`;
51
+ const allowed = allow
52
+ .split(',')
53
+ .map((s) => `${scope} ${s.trim()}`)
54
+ .join(',');
55
+ const rules = [];
56
+ if (select) {
57
+ rules.push(`${scope},${scope} *{-webkit-user-select:none;user-select:none}`);
58
+ rules.push(`${allowed}{-webkit-user-select:text;user-select:text}`);
59
+ }
60
+ if (images)
61
+ rules.push(`${scope} img{-webkit-touch-callout:none;-webkit-user-drag:none}`);
62
+ if (print)
63
+ rules.push(`@media print{${scope}{display:none!important}}`);
64
+ const style = doc.createElement('style');
65
+ style.textContent = rules.join('');
66
+ doc.head.appendChild(style);
67
+ root.setAttribute(id, '');
68
+ const inside = (event) => {
69
+ const el = event.target instanceof window.Element ? event.target : null;
70
+ return el && root.contains(el) ? el : null;
71
+ };
72
+ const isAllowed = (el) => el.closest(allow) !== null;
73
+ const block = (action, event) => {
74
+ event.preventDefault();
75
+ if (message)
76
+ showMessage(message);
77
+ onBlock?.(action, event);
78
+ };
79
+ const listeners = [
80
+ [
81
+ 'contextmenu',
82
+ (event) => {
83
+ const el = inside(event);
84
+ if (!el || isAllowed(el))
85
+ return;
86
+ if (contextmenu || (images && el.closest('img,picture,svg,video,canvas')))
87
+ block('contextmenu', event);
88
+ },
89
+ ],
90
+ [
91
+ 'dragstart',
92
+ (event) => {
93
+ const el = inside(event);
94
+ if (!el || isAllowed(el))
95
+ return;
96
+ if (drag || (images && el.closest('img,picture')))
97
+ block('drag', event);
98
+ },
99
+ ],
100
+ [
101
+ 'selectstart',
102
+ (event) => {
103
+ const el = inside(event) ?? event.target?.parentElement;
104
+ if (select && el && root.contains(el) && !isAllowed(el))
105
+ block('select', event);
106
+ },
107
+ ],
108
+ [
109
+ 'copy',
110
+ (event) => {
111
+ const el = selectionElement() ?? inside(event);
112
+ if (!el || !root.contains(el) || isAllowed(el))
113
+ return;
114
+ if (copy)
115
+ return block('copy', event);
116
+ if (credit)
117
+ addCredit(event);
118
+ },
119
+ ],
120
+ [
121
+ 'cut',
122
+ (event) => {
123
+ const el = selectionElement() ?? inside(event);
124
+ if (copy && el && root.contains(el) && !isAllowed(el))
125
+ block('cut', event);
126
+ },
127
+ ],
128
+ [
129
+ 'keydown',
130
+ (event) => {
131
+ const key = event;
132
+ if (!(key.ctrlKey || key.metaKey) || key.altKey)
133
+ return;
134
+ const letter = key.key.toLowerCase();
135
+ if (save && letter === 's')
136
+ block('save', event);
137
+ else if (print && letter === 'p')
138
+ block('print', event);
139
+ },
140
+ ],
141
+ ];
142
+ function selectionElement() {
143
+ const node = window.getSelection()?.anchorNode;
144
+ return node ? (node instanceof window.Element ? node : node.parentElement) : null;
145
+ }
146
+ function addCredit(event) {
147
+ // Triple-click selections end with line breaks; drop them so the credit sits one blank line below.
148
+ const text = (window.getSelection()?.toString() ?? '').replace(/\s+$/, '');
149
+ if (text.trim().length < creditMinLength || !event.clipboardData)
150
+ return;
151
+ const page = { title: doc.title, url: window.location.href, text };
152
+ const line = typeof credit === 'function' ? credit(page) : `Source: ${page.title ? `${page.title} ` : ''}${page.url}`;
153
+ event.clipboardData.setData('text/plain', `${text}\n\n${line}`);
154
+ event.clipboardData.setData('text/html', `${escapeHtml(text).replace(/\n/g, '<br>')}<br><br>${escapeHtml(line).replace(escapeHtml(page.url), `<a href="${escapeHtml(page.url)}">${escapeHtml(page.url)}</a>`)}`);
155
+ event.preventDefault();
156
+ }
157
+ for (const [type, listener] of listeners)
158
+ doc.addEventListener(type, listener, true);
159
+ let active = true;
160
+ return () => {
161
+ if (!active)
162
+ return;
163
+ active = false;
164
+ for (const [type, listener] of listeners)
165
+ doc.removeEventListener(type, listener, true);
166
+ style.remove();
167
+ root.removeAttribute(id);
168
+ };
169
+ }
170
+ export default protect;
@@ -0,0 +1,3 @@
1
+ "use strict";(()=>{var F='input,textarea,select,[contenteditable]:not([contenteditable="false"]),[data-norightclick-allow]',G=0,r,K;function R(n){let o=window.document;r||(r=o.createElement("div"),r.setAttribute("role","status"),r.style.cssText="position:fixed;left:50%;bottom:24px;transform:translateX(-50%);z-index:2147483647;max-width:90vw;padding:10px 16px;border-radius:8px;background:#111;color:#fff;font:14px/1.4 system-ui,sans-serif;box-shadow:0 4px 16px rgba(0,0,0,.25);pointer-events:none"),r.textContent=n,r.isConnected||o.body.appendChild(r),clearTimeout(K),K=setTimeout(()=>r==null?void 0:r.remove(),2e3)}function g(n){return n.replace(/[&<>"]/g,o=>`&#${o.charCodeAt(0)};`)}function E(n={}){var S;if(typeof window=="undefined"||!window.document)return()=>{};let o=window.document,{contextmenu:m=!0,images:a=!0,copy:v=!1,select:$=!1,drag:N=!1,save:j=!1,print:L=!1,credit:b=!1,creditMinLength:W=20,message:k,onBlock:y}=n,s=typeof n.target=="string"?o.querySelector(n.target):(S=n.target)!=null?S:o.documentElement;if(!s)return()=>{};let A=n.allow?`${F},${n.allow}`:F,x=`data-norightclick-${++G}`,c=`[${x}]`,q=A.split(",").map(e=>`${c} ${e.trim()}`).join(","),u=[];$&&(u.push(`${c},${c} *{-webkit-user-select:none;user-select:none}`),u.push(`${q}{-webkit-user-select:text;user-select:text}`)),a&&u.push(`${c} img{-webkit-touch-callout:none;-webkit-user-drag:none}`),L&&u.push(`@media print{${c}{display:none!important}}`);let h=o.createElement("style");h.textContent=u.join(""),o.head.appendChild(h),s.setAttribute(x,"");let d=e=>{let t=e.target instanceof window.Element?e.target:null;return t&&s.contains(t)?t:null},p=e=>e.closest(A)!==null,l=(e,t)=>{t.preventDefault(),k&&R(k),y==null||y(e,t)},C=[["contextmenu",e=>{let t=d(e);!t||p(t)||(m||a&&t.closest("img,picture,svg,video,canvas"))&&l("contextmenu",e)}],["dragstart",e=>{let t=d(e);!t||p(t)||(N||a&&t.closest("img,picture"))&&l("drag",e)}],["selectstart",e=>{var i,f;let t=(f=d(e))!=null?f:(i=e.target)==null?void 0:i.parentElement;$&&t&&s.contains(t)&&!p(t)&&l("select",e)}],["copy",e=>{var i;let t=(i=D())!=null?i:d(e);if(!(!t||!s.contains(t)||p(t))){if(v)return l("copy",e);b&&z(e)}}],["cut",e=>{var i;let t=(i=D())!=null?i:d(e);v&&t&&s.contains(t)&&!p(t)&&l("cut",e)}],["keydown",e=>{let t=e;if(!(t.ctrlKey||t.metaKey)||t.altKey)return;let i=t.key.toLowerCase();j&&i==="s"?l("save",e):L&&i==="p"&&l("print",e)}]];function D(){var t;let e=(t=window.getSelection())==null?void 0:t.anchorNode;return e?e instanceof window.Element?e:e.parentElement:null}function z(e){var O,T;let t=((T=(O=window.getSelection())==null?void 0:O.toString())!=null?T:"").replace(/\s+$/,"");if(t.trim().length<W||!e.clipboardData)return;let i={title:o.title,url:window.location.href,text:t},f=typeof b=="function"?b(i):`Source: ${i.title?`${i.title} `:""}${i.url}`;e.clipboardData.setData("text/plain",`${t}
2
+
3
+ ${f}`),e.clipboardData.setData("text/html",`${g(t).replace(/\n/g,"<br>")}<br><br>${g(f).replace(g(i.url),`<a href="${g(i.url)}">${g(i.url)}</a>`)}`),e.preventDefault()}for(let[e,t]of C)o.addEventListener(e,t,!0);let M=!0;return()=>{if(M){M=!1;for(let[e,t]of C)o.removeEventListener(e,t,!0);h.remove(),s.removeAttribute(x)}}}var X=["contextmenu","images","copy","select","drag","save","print","credit"];function H(n){let o={};for(let m of X){let a=n[m];a!==void 0&&(o[m]=a!=="false")}return n.message&&(o.message=n.message),n.allow&&(o.allow=n.allow),n.target&&(o.target=n.target),n.creditMinLength&&(o.creditMinLength=Number(n.creditMinLength)),o}var w=typeof document=="undefined"?null:document.currentScript,Y={protect:E,optionsFromDataset:H};window.norightclick=Y;if(w&&w.dataset.manual===void 0){let n=()=>E(H(w.dataset));document.readyState==="loading"&&w.dataset.target?document.addEventListener("DOMContentLoaded",n):n()}})();
package/package.json CHANGED
@@ -1,8 +1,82 @@
1
1
  {
2
2
  "name": "norightclick",
3
- "version": "0.0.1",
4
- "description": "Reserved package name. Coming soon: disable right-click, copying, text selection and image saving on a web page, with exceptions and accessibility kept.",
3
+ "version": "1.0.0",
4
+ "description": "Disable right-click, copying, text selection and image saving on a web page, or add a credit link to copied text. Keeps inputs and accessibility working. One script tag or one import; tiny, zero dependencies.",
5
+ "keywords": [
6
+ "disable-right-click",
7
+ "right-click",
8
+ "no-right-click",
9
+ "contextmenu",
10
+ "copy-protection",
11
+ "content-protection",
12
+ "disable-copy",
13
+ "no-copy",
14
+ "prevent-copy",
15
+ "image-protection",
16
+ "disable-text-selection",
17
+ "copy-attribution",
18
+ "wordpress"
19
+ ],
20
+ "homepage": "https://github.com/ckgiri/norightclick#readme",
21
+ "bugs": {
22
+ "url": "https://github.com/ckgiri/norightclick/issues"
23
+ },
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "git+https://github.com/ckgiri/norightclick.git"
27
+ },
28
+ "funding": "https://github.com/sponsors/ckgiri",
5
29
  "license": "MIT",
6
- "keywords": ["right-click", "disable-right-click", "contextmenu", "no-copy", "copy-protection", "content-protection", "image-protection"],
7
- "files": ["README.md"]
30
+ "type": "module",
31
+ "sideEffects": [
32
+ "./dist/norightclick.global.js"
33
+ ],
34
+ "exports": {
35
+ ".": {
36
+ "types": "./dist/index.d.ts",
37
+ "default": "./dist/index.js"
38
+ },
39
+ "./global": "./dist/norightclick.global.js",
40
+ "./package.json": "./package.json"
41
+ },
42
+ "main": "./dist/index.js",
43
+ "types": "./dist/index.d.ts",
44
+ "unpkg": "./dist/norightclick.global.js",
45
+ "jsdelivr": "./dist/norightclick.global.js",
46
+ "files": [
47
+ "dist",
48
+ "README.md",
49
+ "CHANGELOG.md",
50
+ "LICENSE"
51
+ ],
52
+ "scripts": {
53
+ "build": "node scripts/clean.mjs && tsc -p tsconfig.json && node scripts/build-global.mjs",
54
+ "typecheck": "tsc -p tsconfig.json --noEmit",
55
+ "lint": "eslint .",
56
+ "format": "prettier --write .",
57
+ "format:check": "prettier --check .",
58
+ "test": "npm run build && node --test \"test/*.test.js\"",
59
+ "test:coverage": "npm run build && node --test --experimental-test-coverage --test-coverage-include=\"dist/**\" --test-coverage-lines=95 --test-coverage-branches=90 --test-coverage-functions=100 \"test/*.test.js\"",
60
+ "test:browser": "npm run build && node test/browser/run.mjs",
61
+ "size": "npm run build && node scripts/size.mjs",
62
+ "check:package": "npm run build && publint --strict && attw --pack . --profile esm-only --exclude-entrypoints global",
63
+ "check": "npm run lint && npm run format:check && npm run typecheck && npm run test:coverage && npm run size && npm run check:package",
64
+ "prepublishOnly": "npm run check",
65
+ "docs": "npm run build && node scripts/docs.mjs"
66
+ },
67
+ "publishConfig": {
68
+ "access": "public"
69
+ },
70
+ "devDependencies": {
71
+ "@arethetypeswrong/cli": "^0.18.5",
72
+ "@eslint/js": "^10.0.1",
73
+ "esbuild": "^0.28.2",
74
+ "eslint": "^10.16.0",
75
+ "jsdom": "^31.0.1",
76
+ "playwright-core": "^1.65.2",
77
+ "prettier": "^3.10.2",
78
+ "publint": "^0.3.25",
79
+ "typescript": "^6.0.3",
80
+ "typescript-eslint": "^8.74.0"
81
+ }
8
82
  }