add hw2
This commit is contained in:
31
node_modules/@iconify/utils/lib/svg/build.d.ts
generated
vendored
Normal file
31
node_modules/@iconify/utils/lib/svg/build.d.ts
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
import { IconifyIconCustomisations } from "../customisations/defaults.js";
|
||||
import { IconifyIcon } from "../icon/defaults.js";
|
||||
import { SVGViewBox } from "./viewbox.js";
|
||||
/**
|
||||
* Interface for getSVGData() result
|
||||
*/
|
||||
interface IconifyIconBuildResult {
|
||||
attributes: {
|
||||
width?: string;
|
||||
height?: string;
|
||||
viewBox: string;
|
||||
};
|
||||
viewBox: SVGViewBox;
|
||||
body: string;
|
||||
}
|
||||
/**
|
||||
* Check if value should be unset. Allows multiple keywords
|
||||
*/
|
||||
declare const isUnsetKeyword: (value: unknown) => value is "unset" | "undefined" | "none";
|
||||
/**
|
||||
* Get SVG attributes and content from icon + customisations
|
||||
*
|
||||
* Does not generate style to make it compatible with frameworks that use objects for style, such as React.
|
||||
* Instead, it generates 'inline' value. If true, rendering engine should add verticalAlign: -0.125em to icon.
|
||||
*
|
||||
* Customisations should be normalised by platform specific parser.
|
||||
* Result should be converted to <svg> by platform specific parser.
|
||||
* Use replaceIDs to generate unique IDs for body.
|
||||
*/
|
||||
declare function iconToSVG(icon: IconifyIcon, customisations?: IconifyIconCustomisations): IconifyIconBuildResult;
|
||||
export { IconifyIconBuildResult, iconToSVG, isUnsetKeyword };
|
||||
115
node_modules/@iconify/utils/lib/svg/build.js
generated
vendored
Normal file
115
node_modules/@iconify/utils/lib/svg/build.js
generated
vendored
Normal file
@@ -0,0 +1,115 @@
|
||||
import { defaultIconProps } from "../icon/defaults.js";
|
||||
import { defaultIconCustomisations } from "../customisations/defaults.js";
|
||||
import { calculateSize } from "./size.js";
|
||||
import { wrapSVGContent } from "./defs.js";
|
||||
|
||||
/**
|
||||
* Check if value should be unset. Allows multiple keywords
|
||||
*/
|
||||
const isUnsetKeyword = (value) => value === "unset" || value === "undefined" || value === "none";
|
||||
/**
|
||||
* Get SVG attributes and content from icon + customisations
|
||||
*
|
||||
* Does not generate style to make it compatible with frameworks that use objects for style, such as React.
|
||||
* Instead, it generates 'inline' value. If true, rendering engine should add verticalAlign: -0.125em to icon.
|
||||
*
|
||||
* Customisations should be normalised by platform specific parser.
|
||||
* Result should be converted to <svg> by platform specific parser.
|
||||
* Use replaceIDs to generate unique IDs for body.
|
||||
*/
|
||||
function iconToSVG(icon, customisations) {
|
||||
const fullIcon = {
|
||||
...defaultIconProps,
|
||||
...icon
|
||||
};
|
||||
const fullCustomisations = {
|
||||
...defaultIconCustomisations,
|
||||
...customisations
|
||||
};
|
||||
const box = {
|
||||
left: fullIcon.left,
|
||||
top: fullIcon.top,
|
||||
width: fullIcon.width,
|
||||
height: fullIcon.height
|
||||
};
|
||||
let body = fullIcon.body;
|
||||
[fullIcon, fullCustomisations].forEach((props) => {
|
||||
const transformations = [];
|
||||
const hFlip = props.hFlip;
|
||||
const vFlip = props.vFlip;
|
||||
let rotation = props.rotate;
|
||||
if (hFlip) if (vFlip) rotation += 2;
|
||||
else {
|
||||
transformations.push("translate(" + (box.width + box.left).toString() + " " + (0 - box.top).toString() + ")");
|
||||
transformations.push("scale(-1 1)");
|
||||
box.top = box.left = 0;
|
||||
}
|
||||
else if (vFlip) {
|
||||
transformations.push("translate(" + (0 - box.left).toString() + " " + (box.height + box.top).toString() + ")");
|
||||
transformations.push("scale(1 -1)");
|
||||
box.top = box.left = 0;
|
||||
}
|
||||
let tempValue;
|
||||
if (rotation < 0) rotation -= Math.floor(rotation / 4) * 4;
|
||||
rotation = rotation % 4;
|
||||
switch (rotation) {
|
||||
case 1:
|
||||
tempValue = box.height / 2 + box.top;
|
||||
transformations.unshift("rotate(90 " + tempValue.toString() + " " + tempValue.toString() + ")");
|
||||
break;
|
||||
case 2:
|
||||
transformations.unshift("rotate(180 " + (box.width / 2 + box.left).toString() + " " + (box.height / 2 + box.top).toString() + ")");
|
||||
break;
|
||||
case 3:
|
||||
tempValue = box.width / 2 + box.left;
|
||||
transformations.unshift("rotate(-90 " + tempValue.toString() + " " + tempValue.toString() + ")");
|
||||
break;
|
||||
}
|
||||
if (rotation % 2 === 1) {
|
||||
if (box.left !== box.top) {
|
||||
tempValue = box.left;
|
||||
box.left = box.top;
|
||||
box.top = tempValue;
|
||||
}
|
||||
if (box.width !== box.height) {
|
||||
tempValue = box.width;
|
||||
box.width = box.height;
|
||||
box.height = tempValue;
|
||||
}
|
||||
}
|
||||
if (transformations.length) body = wrapSVGContent(body, "<g transform=\"" + transformations.join(" ") + "\">", "</g>");
|
||||
});
|
||||
const customisationsWidth = fullCustomisations.width;
|
||||
const customisationsHeight = fullCustomisations.height;
|
||||
const boxWidth = box.width;
|
||||
const boxHeight = box.height;
|
||||
let width;
|
||||
let height;
|
||||
if (customisationsWidth === null) {
|
||||
height = customisationsHeight === null ? "1em" : customisationsHeight === "auto" ? boxHeight : customisationsHeight;
|
||||
width = calculateSize(height, boxWidth / boxHeight);
|
||||
} else {
|
||||
width = customisationsWidth === "auto" ? boxWidth : customisationsWidth;
|
||||
height = customisationsHeight === null ? calculateSize(width, boxHeight / boxWidth) : customisationsHeight === "auto" ? boxHeight : customisationsHeight;
|
||||
}
|
||||
const attributes = {};
|
||||
const setAttr = (prop, value) => {
|
||||
if (!isUnsetKeyword(value)) attributes[prop] = value.toString();
|
||||
};
|
||||
setAttr("width", width);
|
||||
setAttr("height", height);
|
||||
const viewBox = [
|
||||
box.left,
|
||||
box.top,
|
||||
boxWidth,
|
||||
boxHeight
|
||||
];
|
||||
attributes.viewBox = viewBox.join(" ");
|
||||
return {
|
||||
attributes,
|
||||
viewBox,
|
||||
body
|
||||
};
|
||||
}
|
||||
|
||||
export { iconToSVG, isUnsetKeyword };
|
||||
20
node_modules/@iconify/utils/lib/svg/defs.d.ts
generated
vendored
Normal file
20
node_modules/@iconify/utils/lib/svg/defs.d.ts
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Extract definitions from SVG
|
||||
*
|
||||
* Can be used with other tags, but name kept for backwards compatibility.
|
||||
* Should be used only with tags that cannot be nested, such as masks, clip paths, etc.
|
||||
*/
|
||||
interface SplitSVGDefsResult {
|
||||
defs: string;
|
||||
content: string;
|
||||
}
|
||||
declare function splitSVGDefs(content: string, tag?: string): SplitSVGDefsResult;
|
||||
/**
|
||||
* Merge defs and content
|
||||
*/
|
||||
declare function mergeDefsAndContent(defs: string, content: string): string;
|
||||
/**
|
||||
* Wrap SVG content, without wrapping definitions
|
||||
*/
|
||||
declare function wrapSVGContent(body: string, start: string, end: string): string;
|
||||
export { mergeDefsAndContent, splitSVGDefs, wrapSVGContent };
|
||||
32
node_modules/@iconify/utils/lib/svg/defs.js
generated
vendored
Normal file
32
node_modules/@iconify/utils/lib/svg/defs.js
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
function splitSVGDefs(content, tag = "defs") {
|
||||
let defs = "";
|
||||
const index = content.indexOf("<" + tag);
|
||||
while (index >= 0) {
|
||||
const start = content.indexOf(">", index);
|
||||
const end = content.indexOf("</" + tag);
|
||||
if (start === -1 || end === -1) break;
|
||||
const endEnd = content.indexOf(">", end);
|
||||
if (endEnd === -1) break;
|
||||
defs += content.slice(start + 1, end).trim();
|
||||
content = content.slice(0, index).trim() + content.slice(endEnd + 1);
|
||||
}
|
||||
return {
|
||||
defs,
|
||||
content
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Merge defs and content
|
||||
*/
|
||||
function mergeDefsAndContent(defs, content) {
|
||||
return defs ? "<defs>" + defs + "</defs>" + content : content;
|
||||
}
|
||||
/**
|
||||
* Wrap SVG content, without wrapping definitions
|
||||
*/
|
||||
function wrapSVGContent(body, start, end) {
|
||||
const split = splitSVGDefs(body);
|
||||
return mergeDefsAndContent(split.defs, start + split.content + end);
|
||||
}
|
||||
|
||||
export { mergeDefsAndContent, splitSVGDefs, wrapSVGContent };
|
||||
7
node_modules/@iconify/utils/lib/svg/encode-svg-for-css.d.ts
generated
vendored
Normal file
7
node_modules/@iconify/utils/lib/svg/encode-svg-for-css.d.ts
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
/**
|
||||
* Encode the `SVG` to be used on `CSS`: https://bl.ocks.org/jennyknuth/222825e315d45a738ed9d6e04c7a88d0.
|
||||
*
|
||||
* @param svg The `SVG` source.
|
||||
*/
|
||||
declare function encodeSvgForCss(svg: string): string;
|
||||
export { encodeSvgForCss };
|
||||
15
node_modules/@iconify/utils/lib/svg/encode-svg-for-css.js
generated
vendored
Normal file
15
node_modules/@iconify/utils/lib/svg/encode-svg-for-css.js
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
import { encodeSVGforURL } from "./url.js";
|
||||
|
||||
/**
|
||||
* Encode the `SVG` to be used on `CSS`: https://bl.ocks.org/jennyknuth/222825e315d45a738ed9d6e04c7a88d0.
|
||||
*
|
||||
* @param svg The `SVG` source.
|
||||
*/
|
||||
function encodeSvgForCss(svg) {
|
||||
let useSvg = svg.startsWith("<svg>") ? svg.replace("<svg>", "<svg >") : svg;
|
||||
if (!useSvg.includes(" xmlns:xlink=") && useSvg.includes(" xlink:")) useSvg = useSvg.replace("<svg ", "<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" ");
|
||||
if (!useSvg.includes(" xmlns=")) useSvg = useSvg.replace("<svg ", "<svg xmlns=\"http://www.w3.org/2000/svg\" ");
|
||||
return encodeSVGforURL(useSvg);
|
||||
}
|
||||
|
||||
export { encodeSvgForCss };
|
||||
5
node_modules/@iconify/utils/lib/svg/html.d.ts
generated
vendored
Normal file
5
node_modules/@iconify/utils/lib/svg/html.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* Generate <svg>
|
||||
*/
|
||||
declare function iconToHTML(body: string, attributes: Record<string, string>): string;
|
||||
export { iconToHTML };
|
||||
10
node_modules/@iconify/utils/lib/svg/html.js
generated
vendored
Normal file
10
node_modules/@iconify/utils/lib/svg/html.js
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* Generate <svg>
|
||||
*/
|
||||
function iconToHTML(body, attributes) {
|
||||
let renderAttribsHTML = body.indexOf("xlink:") === -1 ? "" : " xmlns:xlink=\"http://www.w3.org/1999/xlink\"";
|
||||
for (const attr in attributes) renderAttribsHTML += " " + attr + "=\"" + attributes[attr] + "\"";
|
||||
return "<svg xmlns=\"http://www.w3.org/2000/svg\"" + renderAttribsHTML + ">" + body + "</svg>";
|
||||
}
|
||||
|
||||
export { iconToHTML };
|
||||
18
node_modules/@iconify/utils/lib/svg/id.d.ts
generated
vendored
Normal file
18
node_modules/@iconify/utils/lib/svg/id.d.ts
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* IDs usage:
|
||||
*
|
||||
* id="{id}"
|
||||
* xlink:href="#{id}"
|
||||
* url(#{id})
|
||||
*
|
||||
* From SVG animations:
|
||||
*
|
||||
* begin="0;{id}.end"
|
||||
* begin="{id}.end"
|
||||
* begin="{id}.click"
|
||||
*/
|
||||
/**
|
||||
* Replace IDs in SVG output with unique IDs
|
||||
*/
|
||||
declare function replaceIDs(body: string, prefix?: string | ((id: string) => string)): string;
|
||||
export { replaceIDs };
|
||||
46
node_modules/@iconify/utils/lib/svg/id.js
generated
vendored
Normal file
46
node_modules/@iconify/utils/lib/svg/id.js
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* IDs usage:
|
||||
*
|
||||
* id="{id}"
|
||||
* xlink:href="#{id}"
|
||||
* url(#{id})
|
||||
*
|
||||
* From SVG animations:
|
||||
*
|
||||
* begin="0;{id}.end"
|
||||
* begin="{id}.end"
|
||||
* begin="{id}.click"
|
||||
*/
|
||||
/**
|
||||
* Regular expression for finding ids
|
||||
*/
|
||||
const regex = /\sid="(\S+)"/g;
|
||||
/**
|
||||
* New random-ish prefix for ids
|
||||
*
|
||||
* Do not use dash, it cannot be used in SVG 2 animations
|
||||
*/
|
||||
const randomPrefix = "IconifyId" + Date.now().toString(16) + (Math.random() * 16777216 | 0).toString(16);
|
||||
/**
|
||||
* Counter for ids, increasing with every replacement
|
||||
*/
|
||||
let counter = 0;
|
||||
/**
|
||||
* Replace IDs in SVG output with unique IDs
|
||||
*/
|
||||
function replaceIDs(body, prefix = randomPrefix) {
|
||||
const ids = [];
|
||||
let match;
|
||||
while (match = regex.exec(body)) ids.push(match[1]);
|
||||
if (!ids.length) return body;
|
||||
const suffix = "suffix" + (Math.random() * 16777216 | Date.now()).toString(16);
|
||||
ids.forEach((id) => {
|
||||
const newID = typeof prefix === "function" ? prefix(id) : prefix + (counter++).toString();
|
||||
const escapedID = id.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
||||
body = body.replace(new RegExp("([#;\"])(" + escapedID + ")([\")]|\\.[a-z])", "g"), "$1" + newID + suffix + "$3");
|
||||
});
|
||||
body = body.replace(new RegExp(suffix, "g"), "");
|
||||
return body;
|
||||
}
|
||||
|
||||
export { replaceIDs };
|
||||
8
node_modules/@iconify/utils/lib/svg/inner-html.d.ts
generated
vendored
Normal file
8
node_modules/@iconify/utils/lib/svg/inner-html.d.ts
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Clean up value for innerHTML assignment
|
||||
*
|
||||
* This code doesn't actually clean up anything.
|
||||
* It is intended be used with Iconify icon data, which has already been validated
|
||||
*/
|
||||
declare function cleanUpInnerHTML(html: string): string;
|
||||
export { cleanUpInnerHTML };
|
||||
23
node_modules/@iconify/utils/lib/svg/inner-html.js
generated
vendored
Normal file
23
node_modules/@iconify/utils/lib/svg/inner-html.js
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
let policy;
|
||||
/**
|
||||
* Attempt to create policy
|
||||
*/
|
||||
function createPolicy() {
|
||||
try {
|
||||
policy = window.trustedTypes.createPolicy("iconify", { createHTML: (s) => s });
|
||||
} catch (err) {
|
||||
policy = null;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Clean up value for innerHTML assignment
|
||||
*
|
||||
* This code doesn't actually clean up anything.
|
||||
* It is intended be used with Iconify icon data, which has already been validated
|
||||
*/
|
||||
function cleanUpInnerHTML(html) {
|
||||
if (policy === void 0) createPolicy();
|
||||
return policy ? policy.createHTML(html) : html;
|
||||
}
|
||||
|
||||
export { cleanUpInnerHTML };
|
||||
22
node_modules/@iconify/utils/lib/svg/parse.d.ts
generated
vendored
Normal file
22
node_modules/@iconify/utils/lib/svg/parse.d.ts
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
import { IconifyIconBuildResult } from "./build.js";
|
||||
import { IconifyIcon } from "@iconify/types";
|
||||
/**
|
||||
* Parsed SVG content
|
||||
*/
|
||||
interface ParsedSVGContent {
|
||||
attribs: Record<string, string>;
|
||||
body: string;
|
||||
}
|
||||
/**
|
||||
* Extract attributes and content from SVG
|
||||
*/
|
||||
declare function parseSVGContent(content: string): ParsedSVGContent | undefined;
|
||||
/**
|
||||
* Convert parsed SVG to IconifyIconBuildResult
|
||||
*/
|
||||
declare function buildParsedSVG(data: ParsedSVGContent): IconifyIconBuildResult | undefined;
|
||||
/**
|
||||
* Convert parsed SVG to IconifyIcon
|
||||
*/
|
||||
declare function convertParsedSVG(data: ParsedSVGContent): IconifyIcon | undefined;
|
||||
export { ParsedSVGContent, buildParsedSVG, convertParsedSVG, parseSVGContent };
|
||||
69
node_modules/@iconify/utils/lib/svg/parse.js
generated
vendored
Normal file
69
node_modules/@iconify/utils/lib/svg/parse.js
generated
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
import { wrapSVGContent } from "./defs.js";
|
||||
import { getSVGViewBox } from "./viewbox.js";
|
||||
|
||||
/**
|
||||
* Extract attributes and content from SVG
|
||||
*/
|
||||
function parseSVGContent(content) {
|
||||
const match = content.trim().match(/(?:<(?:\?xml|!DOCTYPE)[^>]+>\s*)*<svg([^>]+)>([\s\S]+)<\/svg[^>]*>/);
|
||||
if (!match) return;
|
||||
const body = match[2].trim();
|
||||
const attribsList = match[1].match(/[\w:-]+="[^"]*"/g);
|
||||
const attribs = Object.create(null);
|
||||
attribsList?.forEach((row) => {
|
||||
const match$1 = row.match(/([\w:-]+)="([^"]*)"/);
|
||||
if (match$1) attribs[match$1[1]] = match$1[2];
|
||||
});
|
||||
return {
|
||||
attribs,
|
||||
body
|
||||
};
|
||||
}
|
||||
function build(data) {
|
||||
const attribs = data.attribs;
|
||||
const viewBox = getSVGViewBox(attribs["viewBox"] ?? "");
|
||||
if (!viewBox) return;
|
||||
const groupAttributes = [];
|
||||
for (const key in attribs) if (key === "style" || key.startsWith("fill") || key.startsWith("stroke")) groupAttributes.push(`${key}="${attribs[key]}"`);
|
||||
let body = data.body;
|
||||
if (groupAttributes.length) body = wrapSVGContent(body, "<g " + groupAttributes.join(" ") + ">", "</g>");
|
||||
return {
|
||||
width: attribs.width,
|
||||
height: attribs.height,
|
||||
viewBox,
|
||||
body
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Convert parsed SVG to IconifyIconBuildResult
|
||||
*/
|
||||
function buildParsedSVG(data) {
|
||||
const result = build(data);
|
||||
if (result) return {
|
||||
attributes: {
|
||||
width: result.width,
|
||||
height: result.height,
|
||||
viewBox: result.viewBox.join(" ")
|
||||
},
|
||||
viewBox: result.viewBox,
|
||||
body: result.body
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Convert parsed SVG to IconifyIcon
|
||||
*/
|
||||
function convertParsedSVG(data) {
|
||||
const result = build(data);
|
||||
if (result) {
|
||||
const viewBox = result.viewBox;
|
||||
return {
|
||||
left: viewBox[0],
|
||||
top: viewBox[1],
|
||||
width: viewBox[2],
|
||||
height: viewBox[3],
|
||||
body: result.body
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export { buildParsedSVG, convertParsedSVG, parseSVGContent };
|
||||
5
node_modules/@iconify/utils/lib/svg/pretty.d.ts
generated
vendored
Normal file
5
node_modules/@iconify/utils/lib/svg/pretty.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* Prettify SVG
|
||||
*/
|
||||
declare function prettifySVG(content: string, tab?: string, depth?: number): string | null;
|
||||
export { prettifySVG };
|
||||
55
node_modules/@iconify/utils/lib/svg/pretty.js
generated
vendored
Normal file
55
node_modules/@iconify/utils/lib/svg/pretty.js
generated
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* Tags to skip
|
||||
*/
|
||||
const skipTags = ["script", "style"];
|
||||
/**
|
||||
* Prettify SVG
|
||||
*/
|
||||
function prettifySVG(content, tab = " ", depth = 0) {
|
||||
let result = "";
|
||||
let level = 0;
|
||||
content = content.replace(/(\s)*\/>/g, " />");
|
||||
while (content.length > 0) {
|
||||
const openIndex = content.indexOf("<");
|
||||
let closeIndex = content.indexOf(">");
|
||||
if (openIndex === -1 && closeIndex === -1) return result;
|
||||
if (openIndex === -1 || closeIndex === -1 || closeIndex < openIndex) return null;
|
||||
const text = content.slice(0, openIndex);
|
||||
const trimmedText = text.trim();
|
||||
if (trimmedText.length) if (text.trimStart() !== text && text.trimEnd() !== text) result += trimmedText + "\n" + tab.repeat(level + depth);
|
||||
else result = result.trim() + text;
|
||||
content = content.slice(openIndex);
|
||||
closeIndex -= openIndex;
|
||||
const lastChar = content.slice(closeIndex - 1, closeIndex);
|
||||
const isClosing = content.slice(0, 2) === "</";
|
||||
let isSelfClosing = lastChar === "/" || lastChar === "?";
|
||||
if (isClosing && isSelfClosing) return null;
|
||||
const tagName = content.slice(isClosing ? 2 : 1).split(/[\s>]/).shift();
|
||||
const ignoreTagContent = !isSelfClosing && !isClosing && skipTags.includes(tagName);
|
||||
if (!ignoreTagContent) {
|
||||
const nextOpenIndex = content.indexOf("<", 1);
|
||||
if (nextOpenIndex !== -1 && nextOpenIndex < closeIndex) return null;
|
||||
}
|
||||
if (isClosing && tab.length) {
|
||||
if (result.slice(0 - tab.length) === tab) result = result.slice(0, result.length - tab.length);
|
||||
}
|
||||
result += content.slice(0, closeIndex + 1);
|
||||
content = content.slice(closeIndex + 1);
|
||||
if (ignoreTagContent) {
|
||||
const closingIndex = content.indexOf("</" + tagName);
|
||||
const closingEnd = content.indexOf(">", closingIndex);
|
||||
if (closingIndex < 0 || closingEnd < 0) return null;
|
||||
result += content.slice(0, closingEnd + 1);
|
||||
content = content.slice(closingEnd + 1);
|
||||
isSelfClosing = true;
|
||||
}
|
||||
if (isClosing) {
|
||||
level--;
|
||||
if (level < 0) return null;
|
||||
} else if (!isSelfClosing) level++;
|
||||
result += "\n" + tab.repeat(level + depth);
|
||||
}
|
||||
return level === 0 ? result : null;
|
||||
}
|
||||
|
||||
export { prettifySVG };
|
||||
7
node_modules/@iconify/utils/lib/svg/size.d.ts
generated
vendored
Normal file
7
node_modules/@iconify/utils/lib/svg/size.d.ts
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
/**
|
||||
* Calculate second dimension when only 1 dimension is set
|
||||
*/
|
||||
declare function calculateSize(size: string, ratio: number, precision?: number): string;
|
||||
declare function calculateSize(size: number, ratio: number, precision?: number): number;
|
||||
declare function calculateSize(size: string | number, ratio: number, precision?: number): string | number;
|
||||
export { calculateSize };
|
||||
28
node_modules/@iconify/utils/lib/svg/size.js
generated
vendored
Normal file
28
node_modules/@iconify/utils/lib/svg/size.js
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* Regular expressions for calculating dimensions
|
||||
*/
|
||||
const unitsSplit = /(-?[0-9.]*[0-9]+[0-9.]*)/g;
|
||||
const unitsTest = /^-?[0-9.]*[0-9]+[0-9.]*$/g;
|
||||
function calculateSize(size, ratio, precision) {
|
||||
if (ratio === 1) return size;
|
||||
precision = precision || 100;
|
||||
if (typeof size === "number") return Math.ceil(size * ratio * precision) / precision;
|
||||
if (typeof size !== "string") return size;
|
||||
const oldParts = size.split(unitsSplit);
|
||||
if (oldParts === null || !oldParts.length) return size;
|
||||
const newParts = [];
|
||||
let code = oldParts.shift();
|
||||
let isNumber = unitsTest.test(code);
|
||||
while (true) {
|
||||
if (isNumber) {
|
||||
const num = parseFloat(code);
|
||||
if (isNaN(num)) newParts.push(code);
|
||||
else newParts.push(Math.ceil(num * ratio * precision) / precision);
|
||||
} else newParts.push(code);
|
||||
code = oldParts.shift();
|
||||
if (code === void 0) return newParts.join("");
|
||||
isNumber = !isNumber;
|
||||
}
|
||||
}
|
||||
|
||||
export { calculateSize };
|
||||
5
node_modules/@iconify/utils/lib/svg/trim.d.ts
generated
vendored
Normal file
5
node_modules/@iconify/utils/lib/svg/trim.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* Remove whitespace
|
||||
*/
|
||||
declare function trimSVG(str: string): string;
|
||||
export { trimSVG };
|
||||
8
node_modules/@iconify/utils/lib/svg/trim.js
generated
vendored
Normal file
8
node_modules/@iconify/utils/lib/svg/trim.js
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Remove whitespace
|
||||
*/
|
||||
function trimSVG(str) {
|
||||
return str.replace(/(['"])\s*\n\s*([^>\\/\s])/g, "$1 $2").replace(/(["';{}><])\s*\n\s*/g, "$1").replace(/\s*\n\s*/g, " ").replace(/\s+"/g, "\"").replace(/="\s+/g, "=\"").replace(/(\s)+\/>/g, "/>").trim();
|
||||
}
|
||||
|
||||
export { trimSVG };
|
||||
16
node_modules/@iconify/utils/lib/svg/url.d.ts
generated
vendored
Normal file
16
node_modules/@iconify/utils/lib/svg/url.d.ts
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* Encode SVG for use in url()
|
||||
*
|
||||
* Short alternative to encodeURIComponent() that encodes only stuff used in SVG, generating
|
||||
* smaller code.
|
||||
*/
|
||||
declare function encodeSVGforURL(svg: string): string;
|
||||
/**
|
||||
* Generate data: URL from SVG
|
||||
*/
|
||||
declare function svgToData(svg: string): string;
|
||||
/**
|
||||
* Generate url() from SVG
|
||||
*/
|
||||
declare function svgToURL(svg: string): string;
|
||||
export { encodeSVGforURL, svgToData, svgToURL };
|
||||
23
node_modules/@iconify/utils/lib/svg/url.js
generated
vendored
Normal file
23
node_modules/@iconify/utils/lib/svg/url.js
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* Encode SVG for use in url()
|
||||
*
|
||||
* Short alternative to encodeURIComponent() that encodes only stuff used in SVG, generating
|
||||
* smaller code.
|
||||
*/
|
||||
function encodeSVGforURL(svg) {
|
||||
return svg.replace(/"/g, "'").replace(/%/g, "%25").replace(/#/g, "%23").replace(/</g, "%3C").replace(/>/g, "%3E").replace(/\s+/g, " ");
|
||||
}
|
||||
/**
|
||||
* Generate data: URL from SVG
|
||||
*/
|
||||
function svgToData(svg) {
|
||||
return "data:image/svg+xml," + encodeSVGforURL(svg);
|
||||
}
|
||||
/**
|
||||
* Generate url() from SVG
|
||||
*/
|
||||
function svgToURL(svg) {
|
||||
return "url(\"" + svgToData(svg) + "\")";
|
||||
}
|
||||
|
||||
export { encodeSVGforURL, svgToData, svgToURL };
|
||||
9
node_modules/@iconify/utils/lib/svg/viewbox.d.ts
generated
vendored
Normal file
9
node_modules/@iconify/utils/lib/svg/viewbox.d.ts
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
/**
|
||||
* SVG viewBox: x, y, width, height
|
||||
*/
|
||||
type SVGViewBox = [x: number, y: number, width: number, height: number];
|
||||
/**
|
||||
* Get viewBox from string
|
||||
*/
|
||||
declare function getSVGViewBox(value: string): SVGViewBox | undefined;
|
||||
export { SVGViewBox, getSVGViewBox };
|
||||
9
node_modules/@iconify/utils/lib/svg/viewbox.js
generated
vendored
Normal file
9
node_modules/@iconify/utils/lib/svg/viewbox.js
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
/**
|
||||
* Get viewBox from string
|
||||
*/
|
||||
function getSVGViewBox(value) {
|
||||
const result = value.trim().split(/\s+/).map(Number);
|
||||
if (result.length === 4 && result.reduce((prev, value$1) => prev && !isNaN(value$1), true)) return result;
|
||||
}
|
||||
|
||||
export { getSVGViewBox };
|
||||
Reference in New Issue
Block a user