diff --git a/README.md b/README.md index 7a7db56e..d7bf2089 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,8 @@ Lightweight social sharing component for web applications. Zero dependencies, fr ## Features - 🌐 Multiple platforms: WhatsApp, Facebook, X, LinkedIn, Telegram, Reddit, Email, Pinterest, Discord -- 🎯 Zero dependencies - pure vanilla JavaScript +- 📷 QR Code sharing (optional — requires the `social-share-button-qr.js` extension, which loads `qrcode-generator` at runtime) +- 🎯 Zero dependencies for the core library — pure vanilla JavaScript (QR extension loads `qrcode-generator` from jsDelivr CDN at runtime) - ⚛️ Framework support: React, Preact, Next.js, Qwik, Vue, Angular, or plain HTML - 🔄 Auto-detects current URL and page title - 📱 Fully responsive and mobile-ready @@ -529,6 +530,8 @@ new SocialShareButton({ **Available Platforms:** `whatsapp`, `facebook`, `twitter`, `linkedin`, `telegram`, `reddit`, `email`, `pinterest`, `discord` +> **QR Code** (`qrcode`) is available as an optional platform. It requires the separate `social-share-button-qr.js` extension — see [Using the QR Code Extension](#using-the-qr-code-extension). + ### Customize Share Message/Post Text Control the text that appears when users share to social platforms: @@ -659,6 +662,42 @@ new SocialShareButton({ ## Advanced Usage +### Using the QR Code Extension + +The QR code feature is an **optional extension**. The core library has zero runtime dependencies; this extension loads `qrcode-generator` from jsDelivr at runtime. + +#### Via CDN (HTML) + +```html + + + + + + +``` + +#### Via npm / bundler + +```javascript +import "@aossie-org/social-share-button/src/social-share-button-qr.js"; +``` + +The extension will dynamically inject `qrcode-generator` from jsDelivr the first time a user clicks the QR platform. + +#### Self-hosting under a strict CSP + +If your Content Security Policy (CSP) blocks `cdn.jsdelivr.net`, download `qrcode-generator` locally and load it **before** the extension: + +```html + + + + +``` + +When you pass `qrcode` in the `platforms` array, a QR code panel will be rendered inline inside the share modal with a canvas preview and a **Download QR** button. + ### Using npm Package ```javascript diff --git a/package.json b/package.json index 972ad17e..3c2a76ce 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "src/social-share-button.js", "src/social-share-button.css", "src/social-share-button-react.jsx", + "src/social-share-button-qr.js", "src/social-share-analytics.js", "README.md", "LICENSE" diff --git a/src/social-share-button-qr.js b/src/social-share-button-qr.js new file mode 100644 index 00000000..dcff3fa6 --- /dev/null +++ b/src/social-share-button-qr.js @@ -0,0 +1,243 @@ +/** + * SocialShareButton QR Code Extension + * Dynamically loads Kazuhiko Arase's qrcode-generator from CDN + */ + +(function () { + // Shared bootstrap error helper for the QR extension. + // Keeps all console output in one place for easy logger swapping. + function _qrWarn(message) { + /* eslint-disable no-console */ + if (typeof console !== "undefined" && typeof console.warn === "function") { + console.warn("[SocialShareButton QR] " + message); + } + /* eslint-enable no-console */ + } + + // Cached Promise for the qrcode-generator CDN load. + // Guarantees only one