Release v2.5.6
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
// Shared QR SVG helpers for browser renderers.
|
||||
|
||||
(function () {
|
||||
function normalizeSvgMarkup(svg) {
|
||||
var markup = String(svg || '').trim();
|
||||
if (!markup) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return markup.replace(/^<\?xml[^>]*>\s*/i, '');
|
||||
}
|
||||
|
||||
function stripBackground(svg) {
|
||||
var markup = String(svg || '').trim();
|
||||
if (!markup) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return markup
|
||||
.replace(/<path\b[^>]*fill="#ffffff"[^>]*d="M0 0h[^\"]*"[^>]*\s*\/>/i, '')
|
||||
.replace(/<path\b[^>]*fill="#ffffff"[^>]*d="M0 0h[^\"]*"[^>]*><\/path>/i, '')
|
||||
.replace(/<rect\b[^>]*fill="#ffffff"[^>]*x="0"[^>]*y="0"[^>]*width="\d+"[^>]*height="\d+"[^>]*\s*\/?>(?:<\/rect>)?/i, '');
|
||||
}
|
||||
|
||||
function normalizePreviewSvg(svg) {
|
||||
var markup = normalizeSvgMarkup(stripBackground(svg));
|
||||
if (!markup || markup.charAt(0) !== '<') {
|
||||
return markup;
|
||||
}
|
||||
|
||||
return markup.replace(/^<svg\b([^>]*)>/i, function (_match, attrText) {
|
||||
var attrs = String(attrText || '');
|
||||
if (!/\bwidth\s*=\s*/i.test(attrs)) {
|
||||
attrs += ' width="95%"';
|
||||
}
|
||||
if (!/\bheight\s*=\s*/i.test(attrs)) {
|
||||
attrs += ' height="95%"';
|
||||
}
|
||||
if (!/\bpreserveAspectRatio\s*=\s*/i.test(attrs)) {
|
||||
attrs += ' preserveAspectRatio="xMidYMid meet"';
|
||||
}
|
||||
if (!/\bstyle\s*=\s*/i.test(attrs)) {
|
||||
attrs += ' style="display:block;width:95%;height:95%;"';
|
||||
}
|
||||
return '<svg' + attrs + '>';
|
||||
});
|
||||
}
|
||||
|
||||
window.pulseQrSvgUtils = {
|
||||
normalizeSvgMarkup: normalizeSvgMarkup,
|
||||
stripBackground: stripBackground,
|
||||
normalizePreviewSvg: normalizePreviewSvg
|
||||
};
|
||||
}());
|
||||
Reference in New Issue
Block a user