@plattar/plattar-qrcode 1.119.2 → 1.122.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 +89 -27
- package/build/es2015/plattar-qrcode.min.js +1 -1
- package/build/es2019/plattar-qrcode.js +83 -25
- package/build/es2019/plattar-qrcode.min.js +1 -1
- package/elements/base/base-element.js +76 -22
- package/index.js +6 -2
- package/package.json +5 -5
- package/version.js +1 -1
|
@@ -13,7 +13,9 @@ class BaseElement extends HTMLElement {
|
|
|
13
13
|
const observer = new MutationObserver((mutations) => {
|
|
14
14
|
mutations.forEach((mutation) => {
|
|
15
15
|
if (mutation.type === "attributes") {
|
|
16
|
-
this.
|
|
16
|
+
if (this.hasAttribute("url")) {
|
|
17
|
+
this.renderQRCode();
|
|
18
|
+
}
|
|
17
19
|
}
|
|
18
20
|
});
|
|
19
21
|
});
|
|
@@ -38,7 +40,8 @@ class BaseElement extends HTMLElement {
|
|
|
38
40
|
const url = this.hasAttribute("url") ? this.getAttribute("url") : undefined;
|
|
39
41
|
|
|
40
42
|
if (!url) {
|
|
41
|
-
|
|
43
|
+
console.warn("PlattarQR.renderQRCode() - required attribute \"url\" is missing or invalid, QR Code will not render");
|
|
44
|
+
return;
|
|
42
45
|
}
|
|
43
46
|
|
|
44
47
|
const width = this.hasAttribute("width") ? parseInt(this.getAttribute("width")) : 512;
|
|
@@ -117,12 +120,12 @@ class BaseElement extends HTMLElement {
|
|
|
117
120
|
color2: "#ffffff",
|
|
118
121
|
rotation: "0"
|
|
119
122
|
}
|
|
120
|
-
}
|
|
123
|
+
},
|
|
124
|
+
width: 1024,
|
|
125
|
+
height: 1024,
|
|
126
|
+
type: "canvas"
|
|
121
127
|
};
|
|
122
128
|
|
|
123
|
-
this._options.width = 2048;
|
|
124
|
-
this._options.height = 2048;
|
|
125
|
-
this._options.data = url;
|
|
126
129
|
this._options.margin = margin;
|
|
127
130
|
this._options.image = image;
|
|
128
131
|
|
|
@@ -140,6 +143,45 @@ class BaseElement extends HTMLElement {
|
|
|
140
143
|
this._options.dotsOptions.type = "rounded";
|
|
141
144
|
}
|
|
142
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 + "px";
|
|
178
|
+
div.style.height = height + "px";
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
_GenerateQRCode(url, width, height) {
|
|
183
|
+
this._options.data = url;
|
|
184
|
+
|
|
143
185
|
const shadow = this.shadowRoot || this.attachShadow({ mode: 'open' });
|
|
144
186
|
|
|
145
187
|
const qrCode = this._qrCode;
|
|
@@ -162,24 +204,36 @@ class BaseElement extends HTMLElement {
|
|
|
162
204
|
this._UpdateCanvas(width, height);
|
|
163
205
|
}
|
|
164
206
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
const canvas = this._qrCode._canvas;
|
|
171
|
-
|
|
172
|
-
if (canvas) {
|
|
173
|
-
canvas.style.width = "100%";
|
|
174
|
-
canvas.style.height = "100%";
|
|
175
|
-
}
|
|
207
|
+
_IsFetchAPISupported() {
|
|
208
|
+
return 'fetch' in window;
|
|
209
|
+
}
|
|
176
210
|
|
|
177
|
-
|
|
178
|
-
|
|
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
|
+
}
|
|
179
216
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
217
|
+
try {
|
|
218
|
+
const b64 = btoa(url);
|
|
219
|
+
const endpoint = "https://c.plattar.space/api/v2/shorten?base64=" + b64;
|
|
220
|
+
|
|
221
|
+
fetch(endpoint).then((response) => {
|
|
222
|
+
if (!response.ok) {
|
|
223
|
+
throw new Error("PlattarQR._ShortenURL() - response was invalid");
|
|
224
|
+
}
|
|
225
|
+
|
|
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
|
+
});
|
|
183
237
|
}
|
|
184
238
|
}
|
|
185
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.122.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.16.
|
|
45
|
+
"@babel/cli": "^7.17.0",
|
|
46
|
+
"@babel/core": "^7.17.0",
|
|
47
|
+
"@babel/preset-env": "^7.16.11",
|
|
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.122.1";
|