@fluritheme/quote-share 0.0.0-stage → 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,5 @@
1
+ # Changelog
2
+
3
+ ## 1.0.0 — 2026-12-05
4
+
5
+ - First release.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 František Gejdoš (Fluri, https://fluri.xyz)
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,3 +1,105 @@
1
- # Temporary Holding Version
1
+ # Quote Share by Fluri
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Select a sentence, share a link straight to it. Quote Share.
4
+
5
+ **[Live demo →](https://fluri.xyz/quote-share/)** · [All Fluri themes](https://fluri.xyz/themes/) · No-code install for WordPress, Shopify, Wix & more at [fluri.xyz](https://fluri.xyz/quote-share/)
6
+
7
+ ![Quote Share by Fluri on a website](https://fluri.xyz/previews/npm/v2/quote-share.png)
8
+
9
+ - Zero dependencies, about 9 KB minified
10
+ - “Copy link” makes a text-fragment link: the page opens scrolled to the sentence, highlighted by the browser itself
11
+ - Long quotes use the start and end of the passage, so links stay short
12
+ - Works with the keyboard too (Shift + arrows), and Esc closes it
13
+ - Ignores selections in form fields
14
+ - `"share"` adds the phone's own share sheet where the browser has one
15
+ - Works with plain HTML, React, Vue, Svelte, Astro, Next.js and anything else
16
+ - TypeScript types included
17
+
18
+ ## Quick start: one line of HTML
19
+
20
+ Paste this before `</body>`:
21
+
22
+ ```html
23
+ <script src="https://cdn.jsdelivr.net/npm/@fluritheme/quote-share@1/dist/quote-share.global.js" data-auto></script>
24
+ ```
25
+
26
+ Pass options as JSON:
27
+
28
+ ```html
29
+ <script src="https://cdn.jsdelivr.net/npm/@fluritheme/quote-share@1/dist/quote-share.global.js" data-auto data-options='{"target":"article"}'></script>
30
+ ```
31
+
32
+ The running effect is available as `window.FluriQuoteShare.instance`.
33
+
34
+
35
+ ## Install with npm
36
+
37
+ ```sh
38
+ npm install @fluritheme/quote-share
39
+ ```
40
+
41
+ ```ts
42
+ import { createQuoteShare, textFragmentLink } from "@fluritheme/quote-share";
43
+
44
+ const quotes = createQuoteShare({
45
+ target: "article",
46
+ actions: ["copy", "link", "x", "linkedin", "whatsapp"],
47
+ via: "yourhandle",
48
+ });
49
+
50
+ textFragmentLink("the exact sentence");
51
+ // https://your.site/post#:~:text=the%20exact%20sentence
52
+
53
+ // When leaving the page or unmounting a component:
54
+ quotes.destroy();
55
+ ```
56
+
57
+ ### React
58
+
59
+ ```tsx
60
+ import { useEffect } from "react";
61
+ import { createQuoteShare } from "@fluritheme/quote-share";
62
+
63
+ export function QuoteShare() {
64
+ useEffect(() => {
65
+ const effect = createQuoteShare();
66
+ return () => effect.destroy();
67
+ }, []);
68
+ return null;
69
+ }
70
+ ```
71
+
72
+ ## Options
73
+
74
+ | Option | What it does | Default |
75
+ | --- | --- | --- |
76
+ | `target` | Where selecting text counts (CSS selector) | `"article, main, body"` |
77
+ | `actions` | Buttons, in order: copy, link, x, linkedin, whatsapp, share | copy, link, x, linkedin, whatsapp |
78
+ | `color` | Accent colour | `"#7c4dff"` |
79
+ | `minLength` | Shortest selection that shows the bar | `8` |
80
+ | `maxLength` | Longest quote that is shared | `280` |
81
+ | `via` | Your X handle | — |
82
+ | `root` | Limit to one element | document |
83
+ | `zIndex` | Stacking order | `2147483000` |
84
+
85
+ ## Methods
86
+
87
+ - `showAt(clientX, clientY, text)`
88
+ - `hide()`
89
+ - `update(options)`
90
+ - `getState()`
91
+ - `destroy()`
92
+
93
+ ## Great for
94
+
95
+ - Blogs, newsletters and news sites
96
+ - Reports, research and documentation
97
+ - Any writing worth quoting
98
+
99
+ ## No code? Use Fluri
100
+
101
+ Don’t want to touch code? [Fluri](https://fluri.xyz/quote-share/) installs Quote Share on WordPress, Shopify, Webflow, Wix, Squarespace and Framer with one snippet, with live settings and a dashboard. There are more than a dozen animated themes, from a pet dragon to a koi pond. [See them all →](https://fluri.xyz/themes/)
102
+
103
+ ## License
104
+
105
+ MIT © František Gejdoš · [fluri.xyz](https://fluri.xyz)
@@ -0,0 +1 @@
1
+ export declare function showFluriBadge(slug: string): void;
@@ -0,0 +1,4 @@
1
+ export * from "./quote-share.js";
2
+ import { createQuoteShare as base } from "./quote-share.js";
3
+ /** createQuoteShare from Fluri. Also shows a small "Unlock all themes on fluri.xyz" badge. */
4
+ export declare function createQuoteShare(...args: Parameters<typeof base>): ReturnType<typeof base>;
package/dist/index.js ADDED
@@ -0,0 +1,305 @@
1
+ /*! @fluritheme/quote-share v1.0.0 | MIT | https://fluri.xyz/quote-share/ */
2
+
3
+ // packages/quote-share/src/overlay.ts
4
+ var clamp = (v, a, b) => Math.max(a, Math.min(b, v));
5
+
6
+ // packages/quote-share/src/quote-share.ts
7
+ var enc = (s) => encodeURIComponent(s).replace(/-/g, "%2D");
8
+ function textFragmentLink(text, base = location.href) {
9
+ const url = base.split("#")[0];
10
+ const words = text.trim().replace(/\s+/g, " ").split(" ");
11
+ const frag = words.length <= 10 ? enc(words.join(" ")) : `${enc(words.slice(0, 5).join(" "))},${enc(words.slice(-5).join(" "))}`;
12
+ return `${url}#:~:text=${frag}`;
13
+ }
14
+ var LABEL = {
15
+ copy: "Copy",
16
+ link: "Copy link",
17
+ x: "X",
18
+ linkedin: "LinkedIn",
19
+ whatsapp: "WhatsApp",
20
+ share: "Share"
21
+ };
22
+ var CSS = `
23
+ .fluri-qs{position:fixed;display:flex;gap:2px;padding:4px;border-radius:12px;background:#17131f;box-shadow:0 8px 26px rgba(0,0,0,.28);opacity:0;transform:translateY(6px) scale(.96);transition:opacity .15s,transform .15s;pointer-events:none;font:600 13px/1 system-ui,-apple-system,"Segoe UI",sans-serif}
24
+ .fluri-qs.on{opacity:1;transform:none;pointer-events:auto}
25
+ .fluri-qs button{border:0;background:none;color:#fff;padding:8px 10px;border-radius:8px;cursor:pointer;font:inherit;white-space:nowrap}
26
+ .fluri-qs button:hover,.fluri-qs button:focus-visible{background:var(--c);outline:none}
27
+ .fluri-qs::after{content:"";position:absolute;left:var(--tip,50%);bottom:-5px;width:10px;height:10px;margin-left:-5px;background:#17131f;transform:rotate(45deg);border-radius:2px}
28
+ @media (prefers-reduced-motion:reduce){.fluri-qs{transition:none}}
29
+ `;
30
+ function createQuoteShare(options = {}) {
31
+ const o = {
32
+ target: "article, main, body",
33
+ actions: ["copy", "link", "x", "linkedin", "whatsapp"],
34
+ color: "#7c4dff",
35
+ minLength: 8,
36
+ maxLength: 280,
37
+ via: "",
38
+ zIndex: 2147483e3,
39
+ ...options
40
+ };
41
+ if (!document.getElementById("fluri-qs-css")) {
42
+ const s = document.createElement("style");
43
+ s.id = "fluri-qs-css";
44
+ s.textContent = CSS;
45
+ document.head.appendChild(s);
46
+ }
47
+ const bar = document.createElement("div");
48
+ bar.className = "fluri-qs";
49
+ bar.setAttribute("role", "toolbar");
50
+ bar.setAttribute("aria-label", "Share this quote");
51
+ if (o.root) {
52
+ bar.style.position = "absolute";
53
+ if (getComputedStyle(o.root).position === "static")
54
+ o.root.style.position = "relative";
55
+ }
56
+ (o.root ?? document.body).append(bar);
57
+ let text = "", open = false, flash = 0;
58
+ const quote = () => text.length > o.maxLength ? `${text.slice(0, o.maxLength - 1).trimEnd()}\u2026` : text;
59
+ async function copy(value, button, done) {
60
+ try {
61
+ await navigator.clipboard.writeText(value);
62
+ } catch {
63
+ const t = document.createElement("textarea");
64
+ t.value = value;
65
+ t.style.cssText = "position:fixed;opacity:0";
66
+ document.body.append(t);
67
+ t.select();
68
+ document.execCommand("copy");
69
+ t.remove();
70
+ }
71
+ const was = button.textContent;
72
+ button.textContent = done;
73
+ clearTimeout(flash);
74
+ flash = window.setTimeout(() => button.textContent = was, 1200);
75
+ }
76
+ function run(action, button) {
77
+ const link = textFragmentLink(text);
78
+ const q = `\u201C${quote()}\u201D`;
79
+ if (action === "copy") return void copy(q, button, "Copied");
80
+ if (action === "link") return void copy(link, button, "Link copied");
81
+ if (action === "share")
82
+ return void navigator.share?.({ text: q, url: link }).catch(() => {
83
+ });
84
+ const url = action === "x" ? `https://twitter.com/intent/tweet?text=${encodeURIComponent(q)}&url=${encodeURIComponent(link)}${o.via ? `&via=${encodeURIComponent(o.via.replace(/^@/, ""))}` : ""}` : action === "linkedin" ? `https://www.linkedin.com/sharing/share-offsite/?url=${encodeURIComponent(link)}` : `https://wa.me/?text=${encodeURIComponent(`${q} ${link}`)}`;
85
+ window.open(url, "_blank", "noopener,noreferrer,width=640,height=560");
86
+ }
87
+ function build() {
88
+ bar.style.zIndex = String(o.zIndex);
89
+ bar.style.setProperty("--c", o.color);
90
+ bar.innerHTML = "";
91
+ for (const a of o.actions) {
92
+ if (!(a in LABEL) || a === "share" && !navigator.share) continue;
93
+ const b = document.createElement("button");
94
+ b.type = "button";
95
+ b.textContent = LABEL[a];
96
+ b.addEventListener("click", () => run(a, b));
97
+ bar.append(b);
98
+ }
99
+ }
100
+ build();
101
+ function showAt(clientX, clientY, value) {
102
+ text = value.trim().replace(/\s+/g, " ");
103
+ const g = o.root?.getBoundingClientRect();
104
+ const w = bar.offsetWidth, h = bar.offsetHeight;
105
+ const maxX = (g ? g.width : innerWidth) - w - 8;
106
+ const x = clamp(clientX - (g?.left ?? 0) - w / 2, 8, Math.max(8, maxX));
107
+ const y = Math.max(8, clientY - (g?.top ?? 0) - h - 12);
108
+ bar.style.left = `${x}px`;
109
+ bar.style.top = `${y}px`;
110
+ bar.style.setProperty("--tip", `${clamp(clientX - (g?.left ?? 0) - x, 14, w - 14)}px`);
111
+ bar.classList.add("on");
112
+ open = true;
113
+ }
114
+ function hide() {
115
+ bar.classList.remove("on");
116
+ open = false;
117
+ }
118
+ function check() {
119
+ const sel = getSelection();
120
+ const value = sel?.toString().trim() ?? "";
121
+ if (!sel || sel.isCollapsed || value.length < o.minLength) return hide();
122
+ const node = sel.anchorNode;
123
+ const el = node instanceof Element ? node : node?.parentElement;
124
+ if (!el || el.closest("input,textarea,[contenteditable],.fluri-qs")) return hide();
125
+ let inside = false;
126
+ try {
127
+ inside = !!el.closest(o.target);
128
+ } catch {
129
+ inside = true;
130
+ }
131
+ if (!inside || o.root && !o.root.contains(el)) return hide();
132
+ const r = sel.getRangeAt(0).getBoundingClientRect();
133
+ if (!r.width && !r.height) return hide();
134
+ showAt(r.left + r.width / 2, r.top, value);
135
+ }
136
+ const up = (e) => {
137
+ if (bar.contains(e.target)) return;
138
+ setTimeout(check, 10);
139
+ };
140
+ const key = (e) => {
141
+ if (e.key === "Escape") hide();
142
+ else if (e.shiftKey || e.key.startsWith("Arrow")) setTimeout(check, 10);
143
+ };
144
+ const scroll = () => open && !o.root && check();
145
+ document.addEventListener("pointerup", up);
146
+ document.addEventListener("keyup", key);
147
+ addEventListener("scroll", scroll, { passive: true });
148
+ return {
149
+ showAt,
150
+ hide,
151
+ update(next) {
152
+ Object.assign(o, next);
153
+ build();
154
+ },
155
+ pause() {
156
+ },
157
+ resume() {
158
+ },
159
+ destroy() {
160
+ document.removeEventListener("pointerup", up);
161
+ document.removeEventListener("keyup", key);
162
+ removeEventListener("scroll", scroll);
163
+ clearTimeout(flash);
164
+ bar.remove();
165
+ },
166
+ getState() {
167
+ return { open, text };
168
+ }
169
+ };
170
+ }
171
+
172
+ // packages/quote-share/src/badge.ts
173
+ var SITE = "https://fluri.xyz/themes/";
174
+ var shown = false;
175
+ var CSS2 = `
176
+ :host{all:initial}
177
+ a{position:fixed;z-index:2147483600;display:inline-flex;align-items:center;gap:9px;padding:8px 10px 8px 9px;max-width:calc(100vw - 32px);
178
+ border-radius:999px;background:rgba(22,18,36,.88);-webkit-backdrop-filter:blur(12px) saturate(1.4);backdrop-filter:blur(12px) saturate(1.4);
179
+ border:1px solid rgba(255,255,255,.14);box-shadow:0 10px 30px rgba(10,6,30,.28),0 1px 0 rgba(255,255,255,.08) inset;
180
+ color:#fff;font:600 13px/1.2 ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;letter-spacing:.01em;text-decoration:none;
181
+ opacity:0;transform:translateY(10px) scale(.98);transition:opacity .35s ease,transform .35s cubic-bezier(.2,.8,.2,1),background .2s}
182
+ a.in{opacity:1;transform:none}
183
+ a:hover{background:rgba(32,26,52,.96)}
184
+ a:focus-visible{outline:3px solid #a78bfa;outline-offset:3px}
185
+ .star{flex:none;display:grid;place-items:center;width:22px;height:22px;border-radius:50%;background:conic-gradient(from 210deg,#8b5cf6,#ec4899,#f59e0b,#8b5cf6);box-shadow:0 0 12px rgba(167,139,250,.55)}
186
+ .star svg{width:12px;height:12px;fill:#fff}
187
+ .txt{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
188
+ .txt b{font-weight:700;background:linear-gradient(90deg,#c4b5fd,#fbcfe8);-webkit-background-clip:text;background-clip:text;color:transparent}
189
+ .arrow{flex:none;transition:transform .2s}
190
+ a:hover .arrow{transform:translateX(2px)}
191
+ button{all:unset;flex:none;display:grid;place-items:center;width:20px;height:20px;margin-left:2px;border-radius:50%;color:rgba(255,255,255,.7);font:600 14px/1 system-ui;cursor:pointer}
192
+ button:hover{background:rgba(255,255,255,.14);color:#fff}
193
+ button:focus-visible{outline:2px solid #a78bfa}
194
+ @media (max-width:480px){a{font-size:12px;padding:7px 8px 7px 7px;gap:7px}.star{width:20px;height:20px}}
195
+ @media (prefers-reduced-motion:reduce){a{transition:opacity .2s}a,a.in{transform:none}}
196
+ `;
197
+ var ORDER = ["bottom-left", "bottom-center", "bottom-right", "top-right"];
198
+ function place(a, c) {
199
+ const s = a.style;
200
+ s.top = s.bottom = s.left = s.right = s.transform = "";
201
+ if (c.startsWith("bottom")) s.bottom = "16px";
202
+ else s.top = "16px";
203
+ if (c.endsWith("left")) s.left = "16px";
204
+ else if (c.endsWith("right")) s.right = "16px";
205
+ else {
206
+ s.left = "50%";
207
+ s.marginLeft = -(a.offsetWidth / 2) + "px";
208
+ }
209
+ if (c !== "bottom-center") s.marginLeft = "";
210
+ }
211
+ function taken(host, r) {
212
+ const pts = [
213
+ [r.left + 4, r.top + 4],
214
+ [r.right - 4, r.top + 4],
215
+ [r.left + 4, r.bottom - 4],
216
+ [r.right - 4, r.bottom - 4],
217
+ [r.left + r.width / 2, r.top + r.height / 2]
218
+ ];
219
+ for (const [x, y] of pts) {
220
+ for (const el of document.elementsFromPoint(x, y)) {
221
+ if (el === host || el === document.body || el === document.documentElement) continue;
222
+ for (let e = el; e && e !== document.body; e = e.parentElement) {
223
+ const p = getComputedStyle(e).position;
224
+ if (p === "fixed" || p === "sticky") return true;
225
+ }
226
+ }
227
+ }
228
+ return false;
229
+ }
230
+ function isPreview() {
231
+ try {
232
+ const h = location.hostname;
233
+ if (/(^|\.)fluri\.xyz$/.test(h) || /(^|\.)(codepen\.io|cdpn\.io)$/.test(h)) return true;
234
+ if (navigator.webdriver) return true;
235
+ if (/HeadlessChrome|Playwright|Puppeteer/i.test(navigator.userAgent)) return true;
236
+ } catch {
237
+ }
238
+ return false;
239
+ }
240
+ function showFluriBadge(slug) {
241
+ if (shown || typeof document === "undefined" || typeof window === "undefined") return;
242
+ if (isPreview()) return;
243
+ shown = true;
244
+ const start = () => {
245
+ const host = document.createElement("fluri-badge");
246
+ host.setAttribute("style", "all:initial");
247
+ const root = host.attachShadow({ mode: "open" });
248
+ const style = document.createElement("style");
249
+ style.textContent = CSS2;
250
+ const a = document.createElement("a");
251
+ a.href = SITE + "?utm_source=npm&utm_medium=badge&utm_campaign=" + encodeURIComponent(slug);
252
+ a.target = "_blank";
253
+ a.rel = "noopener";
254
+ a.setAttribute("aria-label", "Unlock all themes on fluri.xyz (opens in a new tab)");
255
+ const star = document.createElement("span");
256
+ star.className = "star";
257
+ star.innerHTML = '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M12 2l2.4 6.6L21 11l-6.6 2.4L12 20l-2.4-6.6L3 11l6.6-2.4z"/></svg>';
258
+ const txt = document.createElement("span");
259
+ txt.className = "txt";
260
+ txt.append("Unlock all themes on ");
261
+ const b = document.createElement("b");
262
+ b.textContent = "fluri.xyz";
263
+ txt.append(b);
264
+ const arrow = document.createElement("span");
265
+ arrow.className = "arrow";
266
+ arrow.setAttribute("aria-hidden", "true");
267
+ arrow.textContent = "\u2192";
268
+ const close = document.createElement("button");
269
+ close.type = "button";
270
+ close.setAttribute("aria-label", "Hide");
271
+ close.textContent = "\xD7";
272
+ close.addEventListener("click", (e) => {
273
+ e.preventDefault();
274
+ e.stopPropagation();
275
+ a.classList.remove("in");
276
+ setTimeout(() => host.remove(), 350);
277
+ });
278
+ a.append(star, txt, arrow, close);
279
+ root.append(style, a);
280
+ document.body.appendChild(host);
281
+ let corner = ORDER[0];
282
+ for (const c of ORDER) {
283
+ place(a, c);
284
+ if (!taken(host, a.getBoundingClientRect())) {
285
+ corner = c;
286
+ break;
287
+ }
288
+ }
289
+ place(a, corner);
290
+ requestAnimationFrame(() => requestAnimationFrame(() => a.classList.add("in")));
291
+ };
292
+ const later = () => setTimeout(start, 1200);
293
+ if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", later, { once: true });
294
+ else later();
295
+ }
296
+
297
+ // packages/quote-share/src/index.ts
298
+ function createQuoteShare2(...args) {
299
+ showFluriBadge("quote-share");
300
+ return createQuoteShare(...args);
301
+ }
302
+ export {
303
+ createQuoteShare2 as createQuoteShare,
304
+ textFragmentLink
305
+ };
@@ -0,0 +1,31 @@
1
+ export interface OverlayOptions {
2
+ root?: HTMLElement | undefined;
3
+ zIndex?: number | undefined;
4
+ maxFPS?: number | undefined;
5
+ }
6
+ export interface Overlay {
7
+ canvas: HTMLCanvasElement;
8
+ ctx: CanvasRenderingContext2D;
9
+ /** CSS pixel size of the drawing area. */
10
+ width: number;
11
+ height: number;
12
+ /** Area origin in viewport coordinates (for converting client points). */
13
+ origin(): {
14
+ x: number;
15
+ y: number;
16
+ };
17
+ start(frame: (dt: number, t: number) => void): void;
18
+ pause(): void;
19
+ resume(): void;
20
+ destroy(): void;
21
+ reduced: boolean;
22
+ }
23
+ export declare function createOverlay(o?: OverlayOptions): Overlay;
24
+ export declare function surfacesIn(selector: string, root?: HTMLElement, limit?: number): HTMLElement[];
25
+ export declare const rand: (a: number, b: number) => number;
26
+ export declare const clamp: (v: number, a: number, b: number) => number;
27
+ /**
28
+ * Moves an overlay canvas behind the content of its host (the root, or the
29
+ * body) by giving the host its own stacking context. Returns an undo function.
30
+ */
31
+ export declare function sendBehind(canvas: HTMLCanvasElement, root?: HTMLElement): () => void;
@@ -0,0 +1,34 @@
1
+ export type QuoteAction = "copy" | "link" | "x" | "linkedin" | "whatsapp" | "share";
2
+ export interface QuoteShareOptions {
3
+ /** Limit it to one element (for previews). */
4
+ root?: HTMLElement;
5
+ /** Where selecting text counts (CSS selector). Default "article, main, body". */
6
+ target?: string;
7
+ /** The buttons, in order. Default copy, link, x, linkedin, whatsapp. */
8
+ actions?: QuoteAction[];
9
+ /** Accent colour. Default "#7c4dff". */
10
+ color?: string;
11
+ /** Shortest selection that shows the bar. Default 8 characters. */
12
+ minLength?: number;
13
+ /** Longest quote that is shared; longer ones are cut. Default 280. */
14
+ maxLength?: number;
15
+ /** Your X handle, added to posts as "via". */
16
+ via?: string;
17
+ /** Stacking order. Default 2147483000. */
18
+ zIndex?: number;
19
+ }
20
+ export interface QuoteShareState {
21
+ open: boolean;
22
+ text: string;
23
+ }
24
+ /** A link to this page that scrolls to the quote and highlights it. */
25
+ export declare function textFragmentLink(text: string, base?: string): string;
26
+ export declare function createQuoteShare(options?: QuoteShareOptions): {
27
+ showAt: (clientX: number, clientY: number, value: string) => void;
28
+ hide: () => void;
29
+ update(next: Partial<QuoteShareOptions>): void;
30
+ pause(): void;
31
+ resume(): void;
32
+ destroy(): void;
33
+ getState(): QuoteShareState;
34
+ };
@@ -0,0 +1,30 @@
1
+ /*! @fluritheme/quote-share v1.0.0 | MIT | https://fluri.xyz/quote-share/ */
2
+ (()=>{var w=(r,e,t)=>Math.max(e,Math.min(t,r));var E=r=>encodeURIComponent(r).replace(/-/g,"%2D");function B(r,e=location.href){let t=e.split("#")[0],i=r.trim().replace(/\s+/g," ").split(" "),p=i.length<=10?E(i.join(" ")):`${E(i.slice(0,5).join(" "))},${E(i.slice(-5).join(" "))}`;return`${t}#:~:text=${p}`}var H={copy:"Copy",link:"Copy link",x:"X",linkedin:"LinkedIn",whatsapp:"WhatsApp",share:"Share"},U=`
3
+ .fluri-qs{position:fixed;display:flex;gap:2px;padding:4px;border-radius:12px;background:#17131f;box-shadow:0 8px 26px rgba(0,0,0,.28);opacity:0;transform:translateY(6px) scale(.96);transition:opacity .15s,transform .15s;pointer-events:none;font:600 13px/1 system-ui,-apple-system,"Segoe UI",sans-serif}
4
+ .fluri-qs.on{opacity:1;transform:none;pointer-events:auto}
5
+ .fluri-qs button{border:0;background:none;color:#fff;padding:8px 10px;border-radius:8px;cursor:pointer;font:inherit;white-space:nowrap}
6
+ .fluri-qs button:hover,.fluri-qs button:focus-visible{background:var(--c);outline:none}
7
+ .fluri-qs::after{content:"";position:absolute;left:var(--tip,50%);bottom:-5px;width:10px;height:10px;margin-left:-5px;background:#17131f;transform:rotate(45deg);border-radius:2px}
8
+ @media (prefers-reduced-motion:reduce){.fluri-qs{transition:none}}
9
+ `;function Q(r={}){var M;let e={target:"article, main, body",actions:["copy","link","x","linkedin","whatsapp"],color:"#7c4dff",minLength:8,maxLength:280,via:"",zIndex:2147483e3,...r};if(!document.getElementById("fluri-qs-css")){let n=document.createElement("style");n.id="fluri-qs-css",n.textContent=U,document.head.appendChild(n)}let t=document.createElement("div");t.className="fluri-qs",t.setAttribute("role","toolbar"),t.setAttribute("aria-label","Share this quote"),e.root&&(t.style.position="absolute",getComputedStyle(e.root).position==="static"&&(e.root.style.position="relative")),((M=e.root)!=null?M:document.body).append(t);let i="",p=!1,u=0,a=()=>i.length>e.maxLength?`${i.slice(0,e.maxLength-1).trimEnd()}\u2026`:i;async function f(n,s,c){try{await navigator.clipboard.writeText(n)}catch{let l=document.createElement("textarea");l.value=n,l.style.cssText="position:fixed;opacity:0",document.body.append(l),l.select(),document.execCommand("copy"),l.remove()}let o=s.textContent;s.textContent=c,clearTimeout(u),u=window.setTimeout(()=>s.textContent=o,1200)}function g(n,s){var m;let c=B(i),o=`\u201C${a()}\u201D`;if(n==="copy")return void f(o,s,"Copied");if(n==="link")return void f(c,s,"Link copied");if(n==="share")return void((m=navigator.share)==null?void 0:m.call(navigator,{text:o,url:c}).catch(()=>{}));let l=n==="x"?`https://twitter.com/intent/tweet?text=${encodeURIComponent(o)}&url=${encodeURIComponent(c)}${e.via?`&via=${encodeURIComponent(e.via.replace(/^@/,""))}`:""}`:n==="linkedin"?`https://www.linkedin.com/sharing/share-offsite/?url=${encodeURIComponent(c)}`:`https://wa.me/?text=${encodeURIComponent(`${o} ${c}`)}`;window.open(l,"_blank","noopener,noreferrer,width=640,height=560")}function y(){t.style.zIndex=String(e.zIndex),t.style.setProperty("--c",e.color),t.innerHTML="";for(let n of e.actions){if(!(n in H)||n==="share"&&!navigator.share)continue;let s=document.createElement("button");s.type="button",s.textContent=H[n],s.addEventListener("click",()=>g(n,s)),t.append(s)}}y();function x(n,s,c){var A,I,R,z;i=c.trim().replace(/\s+/g," ");let o=(A=e.root)==null?void 0:A.getBoundingClientRect(),l=t.offsetWidth,m=t.offsetHeight,v=(o?o.width:innerWidth)-l-8,T=w(n-((I=o==null?void 0:o.left)!=null?I:0)-l/2,8,Math.max(8,v)),W=Math.max(8,s-((R=o==null?void 0:o.top)!=null?R:0)-m-12);t.style.left=`${T}px`,t.style.top=`${W}px`,t.style.setProperty("--tip",`${w(n-((z=o==null?void 0:o.left)!=null?z:0)-T,14,l-14)}px`),t.classList.add("on"),p=!0}function d(){t.classList.remove("on"),p=!1}function b(){var v;let n=getSelection(),s=(v=n==null?void 0:n.toString().trim())!=null?v:"";if(!n||n.isCollapsed||s.length<e.minLength)return d();let c=n.anchorNode,o=c instanceof Element?c:c==null?void 0:c.parentElement;if(!o||o.closest("input,textarea,[contenteditable],.fluri-qs"))return d();let l=!1;try{l=!!o.closest(e.target)}catch{l=!0}if(!l||e.root&&!e.root.contains(o))return d();let m=n.getRangeAt(0).getBoundingClientRect();if(!m.width&&!m.height)return d();x(m.left+m.width/2,m.top,s)}let h=n=>{t.contains(n.target)||setTimeout(b,10)},C=n=>{n.key==="Escape"?d():(n.shiftKey||n.key.startsWith("Arrow"))&&setTimeout(b,10)},k=()=>p&&!e.root&&b();return document.addEventListener("pointerup",h),document.addEventListener("keyup",C),addEventListener("scroll",k,{passive:!0}),{showAt:x,hide:d,update(n){Object.assign(e,n),y()},pause(){},resume(){},destroy(){document.removeEventListener("pointerup",h),document.removeEventListener("keyup",C),removeEventListener("scroll",k),clearTimeout(u),t.remove()},getState(){return{open:p,text:i}}}}var D="https://fluri.xyz/themes/",q=!1,N=`
10
+ :host{all:initial}
11
+ a{position:fixed;z-index:2147483600;display:inline-flex;align-items:center;gap:9px;padding:8px 10px 8px 9px;max-width:calc(100vw - 32px);
12
+ border-radius:999px;background:rgba(22,18,36,.88);-webkit-backdrop-filter:blur(12px) saturate(1.4);backdrop-filter:blur(12px) saturate(1.4);
13
+ border:1px solid rgba(255,255,255,.14);box-shadow:0 10px 30px rgba(10,6,30,.28),0 1px 0 rgba(255,255,255,.08) inset;
14
+ color:#fff;font:600 13px/1.2 ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;letter-spacing:.01em;text-decoration:none;
15
+ opacity:0;transform:translateY(10px) scale(.98);transition:opacity .35s ease,transform .35s cubic-bezier(.2,.8,.2,1),background .2s}
16
+ a.in{opacity:1;transform:none}
17
+ a:hover{background:rgba(32,26,52,.96)}
18
+ a:focus-visible{outline:3px solid #a78bfa;outline-offset:3px}
19
+ .star{flex:none;display:grid;place-items:center;width:22px;height:22px;border-radius:50%;background:conic-gradient(from 210deg,#8b5cf6,#ec4899,#f59e0b,#8b5cf6);box-shadow:0 0 12px rgba(167,139,250,.55)}
20
+ .star svg{width:12px;height:12px;fill:#fff}
21
+ .txt{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
22
+ .txt b{font-weight:700;background:linear-gradient(90deg,#c4b5fd,#fbcfe8);-webkit-background-clip:text;background-clip:text;color:transparent}
23
+ .arrow{flex:none;transition:transform .2s}
24
+ a:hover .arrow{transform:translateX(2px)}
25
+ button{all:unset;flex:none;display:grid;place-items:center;width:20px;height:20px;margin-left:2px;border-radius:50%;color:rgba(255,255,255,.7);font:600 14px/1 system-ui;cursor:pointer}
26
+ button:hover{background:rgba(255,255,255,.14);color:#fff}
27
+ button:focus-visible{outline:2px solid #a78bfa}
28
+ @media (max-width:480px){a{font-size:12px;padding:7px 8px 7px 7px;gap:7px}.star{width:20px;height:20px}}
29
+ @media (prefers-reduced-motion:reduce){a{transition:opacity .2s}a,a.in{transform:none}}
30
+ `,O=["bottom-left","bottom-center","bottom-right","top-right"];function $(r,e){let t=r.style;t.top=t.bottom=t.left=t.right=t.transform="",e.startsWith("bottom")?t.bottom="16px":t.top="16px",e.endsWith("left")?t.left="16px":e.endsWith("right")?t.right="16px":(t.left="50%",t.marginLeft=-(r.offsetWidth/2)+"px"),e!=="bottom-center"&&(t.marginLeft="")}function j(r,e){let t=[[e.left+4,e.top+4],[e.right-4,e.top+4],[e.left+4,e.bottom-4],[e.right-4,e.bottom-4],[e.left+e.width/2,e.top+e.height/2]];for(let[i,p]of t)for(let u of document.elementsFromPoint(i,p))if(!(u===r||u===document.body||u===document.documentElement))for(let a=u;a&&a!==document.body;a=a.parentElement){let f=getComputedStyle(a).position;if(f==="fixed"||f==="sticky")return!0}return!1}function _(){try{let r=location.hostname;if(/(^|\.)fluri\.xyz$/.test(r)||/(^|\.)(codepen\.io|cdpn\.io)$/.test(r)||navigator.webdriver||/HeadlessChrome|Playwright|Puppeteer/i.test(navigator.userAgent))return!0}catch{}return!1}function F(r){if(q||typeof document=="undefined"||typeof window=="undefined"||_())return;q=!0;let e=()=>{let i=document.createElement("fluri-badge");i.setAttribute("style","all:initial");let p=i.attachShadow({mode:"open"}),u=document.createElement("style");u.textContent=N;let a=document.createElement("a");a.href=D+"?utm_source=npm&utm_medium=badge&utm_campaign="+encodeURIComponent(r),a.target="_blank",a.rel="noopener",a.setAttribute("aria-label","Unlock all themes on fluri.xyz (opens in a new tab)");let f=document.createElement("span");f.className="star",f.innerHTML='<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M12 2l2.4 6.6L21 11l-6.6 2.4L12 20l-2.4-6.6L3 11l6.6-2.4z"/></svg>';let g=document.createElement("span");g.className="txt",g.append("Unlock all themes on ");let y=document.createElement("b");y.textContent="fluri.xyz",g.append(y);let x=document.createElement("span");x.className="arrow",x.setAttribute("aria-hidden","true"),x.textContent="\u2192";let d=document.createElement("button");d.type="button",d.setAttribute("aria-label","Hide"),d.textContent="\xD7",d.addEventListener("click",h=>{h.preventDefault(),h.stopPropagation(),a.classList.remove("in"),setTimeout(()=>i.remove(),350)}),a.append(f,g,x,d),p.append(u,a),document.body.appendChild(i);let b=O[0];for(let h of O)if($(a,h),!j(i,a.getBoundingClientRect())){b=h;break}$(a,b),requestAnimationFrame(()=>requestAnimationFrame(()=>a.classList.add("in")))},t=()=>setTimeout(e,1200);document.readyState==="loading"?document.addEventListener("DOMContentLoaded",t,{once:!0}):t()}function L(...r){return F("quote-share"),Q(...r)}var P={createQuoteShare:L};window.FluriQuoteShare=P;var S=document.currentScript;if(S&&S.hasAttribute("data-auto")){let r=()=>{let e={};try{e=JSON.parse(S.getAttribute("data-options")||"{}")}catch{}P.instance=L(e)};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",r,{once:!0}):r()}})();
package/package.json CHANGED
@@ -1,6 +1,52 @@
1
1
  {
2
2
  "name": "@fluritheme/quote-share",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "Quote Share: select a sentence and a small bar appears to copy the quote, copy a link that scrolls to and highlights that exact sentence (text fragments), or share it on X, LinkedIn and WhatsApp. Zero dependencies.",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "author": {
8
+ "name": "František Gejdoš",
9
+ "url": "https://fluri.xyz/founder/",
10
+ "email": "fluritheme@gmail.com"
11
+ },
12
+ "homepage": "https://fluri.xyz/quote-share/",
13
+ "keywords": [
14
+ "share",
15
+ "quote",
16
+ "selection",
17
+ "text-selection",
18
+ "highlight",
19
+ "share-selected-text",
20
+ "text-fragment",
21
+ "scroll-to-text",
22
+ "tweet",
23
+ "social-share",
24
+ "medium",
25
+ "blog",
26
+ "website-effects",
27
+ "fluri"
28
+ ],
29
+ "sideEffects": false,
30
+ "files": [
31
+ "dist",
32
+ "README.md",
33
+ "LICENSE",
34
+ "CHANGELOG.md"
35
+ ],
36
+ "exports": {
37
+ ".": {
38
+ "types": "./dist/index.d.ts",
39
+ "import": "./dist/index.js"
40
+ },
41
+ "./global": "./dist/quote-share.global.js",
42
+ "./package.json": "./package.json"
43
+ },
44
+ "main": "./dist/index.js",
45
+ "module": "./dist/index.js",
46
+ "types": "./dist/index.d.ts",
47
+ "unpkg": "./dist/quote-share.global.js",
48
+ "jsdelivr": "./dist/quote-share.global.js",
49
+ "publishConfig": {
50
+ "access": "public"
51
+ }
52
+ }