@plattar/plattar-qrcode 1.120.2 → 1.134.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/build/es2015/plattar-qrcode.js +87 -28
- package/build/es2015/plattar-qrcode.min.js +1 -1
- package/build/es2019/plattar-qrcode.js +76 -21
- package/build/es2019/plattar-qrcode.min.js +1 -1
- package/elements/base/base-element.js +69 -18
- package/index.js +6 -2
- package/package.json +5 -5
- package/version.js +1 -1
|
@@ -40,11 +40,12 @@ class BaseElement extends HTMLElement {
|
|
|
40
40
|
const url = this.hasAttribute("url") ? this.getAttribute("url") : undefined;
|
|
41
41
|
|
|
42
42
|
if (!url) {
|
|
43
|
-
|
|
43
|
+
console.warn("PlattarQR.renderQRCode() - required attribute \"url\" is missing or invalid, QR Code will not render");
|
|
44
|
+
return;
|
|
44
45
|
}
|
|
45
46
|
|
|
46
|
-
const width = this.hasAttribute("width") ?
|
|
47
|
-
const height = this.hasAttribute("height") ?
|
|
47
|
+
const width = this.hasAttribute("width") ? this.getAttribute("width") : "100%";
|
|
48
|
+
const height = this.hasAttribute("height") ? this.getAttribute("height") : "100%";
|
|
48
49
|
const margin = this.hasAttribute("margin") ? this.getAttribute("margin") : 0;
|
|
49
50
|
const image = this.hasAttribute("image") ? this.getAttribute("image") : undefined;
|
|
50
51
|
const color = this.hasAttribute("color") ? this.getAttribute("color") : "#000000";
|
|
@@ -125,7 +126,6 @@ class BaseElement extends HTMLElement {
|
|
|
125
126
|
type: "canvas"
|
|
126
127
|
};
|
|
127
128
|
|
|
128
|
-
this._options.data = url;
|
|
129
129
|
this._options.margin = margin;
|
|
130
130
|
this._options.image = image;
|
|
131
131
|
|
|
@@ -143,6 +143,45 @@ class BaseElement extends HTMLElement {
|
|
|
143
143
|
this._options.dotsOptions.type = "rounded";
|
|
144
144
|
}
|
|
145
145
|
|
|
146
|
+
const shortenURL = this.hasAttribute("shorten") ? this.getAttribute("shorten") : "false";
|
|
147
|
+
|
|
148
|
+
if (shortenURL && shortenURL.toLowerCase() === "true") {
|
|
149
|
+
this._ShortenURL(url).then((newURL) => {
|
|
150
|
+
this._GenerateQRCode(newURL, width, height);
|
|
151
|
+
}).catch((_err) => {
|
|
152
|
+
console.warn(_err);
|
|
153
|
+
// ignore error and just generate normal QR Code
|
|
154
|
+
this._GenerateQRCode(url, width, height);
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
this._GenerateQRCode(url, width, height);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
_UpdateCanvas(width, height) {
|
|
163
|
+
if (!this._qrCode) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const canvas = this._qrCode._canvas;
|
|
168
|
+
|
|
169
|
+
if (canvas) {
|
|
170
|
+
canvas.style.width = "100%";
|
|
171
|
+
canvas.style.height = "100%";
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (this._divContainer) {
|
|
175
|
+
const div = this._divContainer;
|
|
176
|
+
|
|
177
|
+
div.style.width = width;
|
|
178
|
+
div.style.height = height;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
_GenerateQRCode(url, width, height) {
|
|
183
|
+
this._options.data = url;
|
|
184
|
+
|
|
146
185
|
const shadow = this.shadowRoot || this.attachShadow({ mode: 'open' });
|
|
147
186
|
|
|
148
187
|
const qrCode = this._qrCode;
|
|
@@ -165,24 +204,36 @@ class BaseElement extends HTMLElement {
|
|
|
165
204
|
this._UpdateCanvas(width, height);
|
|
166
205
|
}
|
|
167
206
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
}
|
|
207
|
+
_IsFetchAPISupported() {
|
|
208
|
+
return 'fetch' in window;
|
|
209
|
+
}
|
|
172
210
|
|
|
173
|
-
|
|
211
|
+
_ShortenURL(url) {
|
|
212
|
+
return new Promise((accept, reject) => {
|
|
213
|
+
if (!this._IsFetchAPISupported()) {
|
|
214
|
+
return reject(new Error("PlattarQR._ShortenURL() - fetch api not supported, cannot proceed"));
|
|
215
|
+
}
|
|
174
216
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
}
|
|
217
|
+
try {
|
|
218
|
+
const b64 = btoa(url);
|
|
219
|
+
const endpoint = "https://c.plattar.space/api/v2/shorten?base64=" + b64;
|
|
179
220
|
|
|
180
|
-
|
|
181
|
-
|
|
221
|
+
fetch(endpoint).then((response) => {
|
|
222
|
+
if (!response.ok) {
|
|
223
|
+
throw new Error("PlattarQR._ShortenURL() - response was invalid");
|
|
224
|
+
}
|
|
182
225
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
226
|
+
return response.text();
|
|
227
|
+
}).then((text) => {
|
|
228
|
+
return accept(text);
|
|
229
|
+
}).catch(() => {
|
|
230
|
+
return reject(new Error("PlattarQR._ShortenURL() - there was an unexpected issue generating short url"));
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
catch (err) {
|
|
234
|
+
return reject(err);
|
|
235
|
+
}
|
|
236
|
+
});
|
|
186
237
|
}
|
|
187
238
|
}
|
|
188
239
|
|
package/index.js
CHANGED
|
@@ -2,9 +2,13 @@
|
|
|
2
2
|
const QRCodeElement = require("./elements/qrcode-element.js");
|
|
3
3
|
const Version = require("./version");
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
if (customElements) {
|
|
6
|
+
if (customElements.get("plattar-qrcode") === undefined) {
|
|
7
|
+
customElements.define("plattar-qrcode", QRCodeElement);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
6
10
|
|
|
7
|
-
|
|
11
|
+
console.log("using @plattar/plattar-qrcode v" + Version);
|
|
8
12
|
|
|
9
13
|
module.exports = {
|
|
10
14
|
version: Version
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plattar/plattar-qrcode",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.134.1",
|
|
4
4
|
"description": "Allows embedding Plattar-Style QR Codes for existing websites.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "index.js",
|
|
7
7
|
"types": "index.d.ts",
|
|
8
8
|
"scripts": {
|
|
9
|
-
"clean": "rm -rf build node_modules",
|
|
9
|
+
"clean": "rm -rf build node_modules package-lock.json",
|
|
10
10
|
"build": "npm run clean && npm install && npm run build-es2019 && npm run build-es2015",
|
|
11
11
|
"build-es2019": "rm -rf build/es2019 && mkdir -p build/es2019 && browserify --standalone PlattarQRCode index.js -o build/es2019/plattar-qrcode.js && uglifyjs build/es2019/plattar-qrcode.js --output build/es2019/plattar-qrcode.min.js",
|
|
12
12
|
"build-es2015": "rm -rf build/es2015 && mkdir -p build/es2015 && babel build/es2019/plattar-qrcode.js --presets=@babel/env > build/es2015/plattar-qrcode.js && uglifyjs build/es2015/plattar-qrcode.js --output build/es2015/plattar-qrcode.min.js",
|
|
@@ -42,9 +42,9 @@
|
|
|
42
42
|
"qr-code-styling": "^1.6.0-rc.1"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@babel/cli": "^7.
|
|
46
|
-
"@babel/core": "^7.
|
|
47
|
-
"@babel/preset-env": "^7.
|
|
45
|
+
"@babel/cli": "^7.18.10",
|
|
46
|
+
"@babel/core": "^7.18.13",
|
|
47
|
+
"@babel/preset-env": "^7.18.10",
|
|
48
48
|
"browserify": "^17.0.0",
|
|
49
49
|
"uglify-es": "^3.3.9"
|
|
50
50
|
},
|
package/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
module.exports = "1.
|
|
1
|
+
module.exports = "1.134.1";
|