ai-2-icons
Version:
Simplified svg
1 lines • 13.4 kB
Source Map (JSON)
{"version":3,"file":"index.cjs","sources":["../src/utils/index.js","../src/components/Icon.js","../node_modules/.pnpm/style-inject@0.3.0/node_modules/style-inject/dist/style-inject.es.js"],"sourcesContent":["const ESCAPE_MAP = {\n \"<\": \"<\",\n \">\": \">\",\n '\"': \""\",\n \"'\": \"'\",\n \"&\": \"&\"\n};\n\nconst escapeHTML = (html) => {\n return html.replace(/[<>\"&]/g, (c) => ESCAPE_MAP[c] || c);\n};\n\nlet id_count = 0;\n\nconst getID = (prefix) => {\n return prefix + id_count++;\n};\n\nexport default {\n escapeHTML,\n getID\n};\n","import Vue from 'vue'\nimport utils from \"../utils\";\n\nconst icons = {};\n\nconst register = (data) => {\n const { name, paths = [], d, polygons = [], points } = data;\n\n if (d) paths.push({ d });\n if (points) polygons.push({ points });\n\n icons[name] = Object.assign({}, data, {\n paths,\n polygons\n });\n\n if (!icons[name].minX) icons[name].minX = 0;\n if (!icons[name].minY) icons[name].minY = 0;\n};\n\nconst addIcons = (...data) => {\n for (const icon of data) register(icon);\n};\n\nconst OhVueIcon = Vue.component('OhVueIcon', {\n name: 'OhVueIcon',\n props: {\n name: {\n type: String,\n validator: function (val) {\n if (val && !(val in icons)) {\n console.warn(`Invalid prop: prop \"name\" is referring to an unregistered icon \"${val}\".\\n` +\n `Please make sure you have imported this icon before using it.`);\n return false;\n }\n return true;\n }\n },\n title: String,\n fill: String,\n scale: {\n type: [Number, String],\n default: 1\n },\n animation: {\n validator: (val) => {\n return [\n \"spin\",\n \"spin-pulse\",\n \"wrench\",\n \"ring\",\n \"pulse\",\n \"flash\",\n \"float\"\n ].includes(val);\n }\n },\n hover: Boolean,\n flip: {\n validator: (val) => {\n return [\"horizontal\", \"vertical\", \"both\"].includes(val);\n }\n },\n speed: {\n validator: (val) => {\n return val === \"fast\" || val === \"slow\";\n }\n },\n label: String,\n inverse: Boolean\n },\n data() {\n return {\n children: [],\n outerScale: 1.2,\n x: null,\n y: null\n };\n },\n computed: {\n normalizedScale() {\n const scale = Number(this.scale);\n if (isNaN(scale) || scale <= 0) {\n console.warn(`Invalid prop: prop \"scale\" should be a number over 0.`);\n return this.outerScale;\n }\n return scale * this.outerScale;\n },\n icon() {\n return icons[this.name];\n },\n box() {\n const icon = this.icon;\n if (icon) {\n return `${icon.minX} ${icon.minY} ${icon.width} ${icon.height}`;\n }\n return `0 0 ${this.width} ${this.height}`;\n },\n raw() {\n // Generates unique id for each icon's SVG element with ID\n if (!this.icon || !this.icon.raw) return null;\n\n const ids = {};\n let raw = this.icon.raw;\n\n raw = raw.replace(\n /\\s(?:xml:)?id=([\"']?)([^\"')\\s]+)\\1/g,\n (match, quote, id) => {\n const uniqueId = utils.getID(\"vat-\");\n ids[id] = uniqueId;\n return ` id=\"${uniqueId}\"`;\n }\n );\n raw = raw.replace(\n /#(?:([^'\")\\s]+)|xpointer\\(id\\((['\"]?)([^')]+)\\2\\)\\))/g,\n (match, rawId, _, pointerId) => {\n const id = rawId || pointerId;\n if (!id || !ids[id]) return match;\n return `#${ids[id]}`;\n }\n );\n return raw;\n },\n ratio() {\n const icon = this.icon;\n if (!icon) return 1;\n return Math.max(icon.width, icon.height) / 16;\n },\n width() {\n return this.icon ? (this.icon.width / this.ratio) * this.normalizedScale : 0;\n },\n height() {\n return this.icon ? (this.icon.height / this.ratio) * this.normalizedScale : 0;\n },\n style() {\n if (this.normalizedScale === 1) return {};\n return {\n fontSize: this.normalizedScale + 'em'\n };\n },\n klass() {\n return {\n 'ov-icon': true,\n 'ov-inverse': this.inverse,\n 'ov-flip-horizontal': this.flip === 'horizontal',\n 'ov-flip-vertical': this.flip === 'vertical',\n 'ov-flip-both': this.flip === 'both',\n 'ov-spin': this.animation === 'spin',\n 'ov-spin-pulse': this.animation === 'spin-pulse',\n 'ov-wrench': this.animation === 'wrench',\n 'ov-ring': this.animation === 'ring',\n 'ov-pulse': this.animation === 'pulse',\n 'ov-flash': this.animation === 'flash',\n 'ov-float': this.animation === 'float',\n 'ov-hover': this.hover,\n 'ov-fast': this.speed === 'fast',\n 'ov-slow': this.speed === 'slow'\n };\n },\n attribs() {\n if (!this.icon || !this.icon.attr) return {};\n return this.icon.attr;\n }\n },\n methods: {\n updateStack() {\n if (!this.name && this.name !== null && this.children.length === 0) {\n console.warn(`Invalid prop: prop \"name\" is required.`);\n return;\n }\n\n if (this.icon) return;\n\n let width = 0, height = 0;\n this.children.forEach((child) => {\n child.outerScale = this.normalizedScale;\n width = Math.max(width, child.width);\n height = Math.max(height, child.height);\n });\n\n this.children.forEach((child) => {\n child.x = (width - child.width) / 2;\n child.y = (height - child.height) / 2;\n });\n }\n },\n mounted() {\n this.updateStack();\n },\n updated() {\n this.updateStack();\n },\n render() {\n const attrs = Object.assign(\n {\n role: this.$attrs.role || (this.label || this.title ? \"img\" : null),\n \"aria-label\": this.label || null,\n \"aria-hidden\": !(this.label || this.title),\n width: this.width,\n height: this.height,\n viewBox: this.box\n },\n this.attribs\n );\n \n if (this.attribs.stroke) {\n attrs.stroke = this.fill ? this.fill : \"currentColor\";\n } else {\n attrs.fill = this.fill ? this.fill : \"currentColor\";\n }\n \n if (this.x) attrs.x = this.x.toString();\n if (this.y) attrs.y = this.y.toString();\n \n let options = {\n class: this.klass,\n style: this.style,\n attrs: attrs\n };\n \n if (this.raw) {\n const html = this.title\n ? `<title>${this.escapeHTML(this.title)}</title>${this.raw}`\n : this.raw;\n options.domProps = { innerHTML: html };\n }\n \n const content = this.title ? [this.$createElement(\"title\", this.title)] : [];\n \n const createSVGElement = (name, value, i) => {\n return this.$createElement(name, {\n attrs: value,\n key: `${name}-${i}`\n });\n };\n \n return this.$createElement(\n \"svg\",\n options,\n this.raw\n ? undefined\n : content.concat(\n this.$slots.default || \n (this.icon ? [\n ...this.icon.paths.map((path, i) => createSVGElement(\"path\", path, i)),\n ...this.icon.polygons.map((polygon, i) => createSVGElement(\"polygon\", polygon, i))\n ] : [])\n ))\n }\n});\n\n\nexport { OhVueIcon, addIcons };","function styleInject(css, ref) {\n if ( ref === void 0 ) ref = {};\n var insertAt = ref.insertAt;\n\n if (!css || typeof document === 'undefined') { return; }\n\n var head = document.head || document.getElementsByTagName('head')[0];\n var style = document.createElement('style');\n style.type = 'text/css';\n\n if (insertAt === 'top') {\n if (head.firstChild) {\n head.insertBefore(style, head.firstChild);\n } else {\n head.appendChild(style);\n }\n } else {\n head.appendChild(style);\n }\n\n if (style.styleSheet) {\n style.styleSheet.cssText = css;\n } else {\n style.appendChild(document.createTextNode(css));\n }\n}\n\nexport default styleInject;\n"],"names":["id_count","utils","prefix","icons","register","data","name","paths","d","polygons","points","push","Object","assign","minX","minY","OhVueIcon","Vue","component","props","type","String","validator","val","title","fill","scale","Number","default","animation","includes","hover","Boolean","flip","speed","label","inverse","children","outerScale","x","y","computed","normalizedScale","this","isNaN","icon","box","width","height","raw","ids","replace","match","quote","id","uniqueId","rawId","_","pointerId","ratio","Math","max","style","fontSize","klass","attribs","attr","methods","updateStack","length","forEach","child","mounted","updated","render","attrs","role","$attrs","viewBox","stroke","toString","options","class","html","escapeHTML","domProps","innerHTML","content","$createElement","createSVGElement","value","i","key","concat","$slots","map","path","polygon","styleInject","css","ref","insertAt","document","head","getElementsByTagName","createElement","firstChild","insertBefore","appendChild","styleSheet","cssText","createTextNode"],"mappings":"iKAYA,IAAIA,EAAW,EAMf,IAAeC,EAJAC,GACNA,EAASF,ICZlB,MAAMG,EAAQ,CAAA,EAERC,EAAYC,IACV,MAAAC,KAAEA,EAAMC,MAAAA,EAAQ,GAACC,EAAGA,WAAGC,EAAW,GAAIC,OAAAA,GAAWL,EAEnDG,GAASD,EAAAI,KAAK,CAAEH,MAChBE,GAAiBD,EAAAE,KAAK,CAAED,WAE5BP,EAAMG,GAAQM,OAAOC,OAAO,CAAA,EAAIR,EAAM,CACpCE,QACAE,aAGGN,EAAMG,GAAMQ,OAAYX,EAAAG,GAAMQ,KAAO,GACrCX,EAAMG,GAAMS,OAAYZ,EAAAG,GAAMS,KA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