@edusites/bancos-brasil 1.0.5 → 1.0.6
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/package.json +1 -1
- package/src/core.js +29 -11
package/package.json
CHANGED
package/src/core.js
CHANGED
|
@@ -82,15 +82,25 @@ function criarFundo(formato, tamanho, corFundo) {
|
|
|
82
82
|
return ''
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
function
|
|
86
|
-
|
|
85
|
+
function extrairConteudo(svgCompleto) {
|
|
86
|
+
// Extrai só o conteúdo interno do SVG (paths, circles, etc)
|
|
87
|
+
const match = svgCompleto.match(/<svg[^>]*>([\s\S]*)<\/svg>/)
|
|
88
|
+
return match ? match[1].trim() : ''
|
|
87
89
|
}
|
|
88
90
|
|
|
89
|
-
function
|
|
90
|
-
|
|
91
|
-
const
|
|
91
|
+
function extrairViewBox(svgCompleto) {
|
|
92
|
+
// Extrai o viewBox original
|
|
93
|
+
const match = svgCompleto.match(/viewBox=["']([^"']+)["']/)
|
|
94
|
+
return match ? match[1] : '0 0 108 108'
|
|
95
|
+
}
|
|
92
96
|
|
|
93
|
-
|
|
97
|
+
function aplicarCor(conteudo, cor) {
|
|
98
|
+
// Aplica a cor aos paths
|
|
99
|
+
return conteudo.replace(/<(path|circle|rect|polygon)([^>]*)(\/?>)/g, (match, tag, attrs, close) => {
|
|
100
|
+
// Remove fill existente e adiciona o novo
|
|
101
|
+
const attrsLimpos = attrs.replace(/\s*fill=["'][^"']*["']/g, '')
|
|
102
|
+
return `<${tag}${attrsLimpos} fill="${cor}"${close}`
|
|
103
|
+
})
|
|
94
104
|
}
|
|
95
105
|
|
|
96
106
|
export function svgBanco(options) {
|
|
@@ -112,16 +122,24 @@ export function svgBanco(options) {
|
|
|
112
122
|
tamanho: tamanho || preset.tamanho
|
|
113
123
|
}
|
|
114
124
|
|
|
115
|
-
const
|
|
116
|
-
if (!
|
|
125
|
+
const svgOriginal = obterIcone(nomeNormalizado)
|
|
126
|
+
if (!svgOriginal) return null
|
|
127
|
+
|
|
128
|
+
const viewBoxOriginal = extrairViewBox(svgOriginal)
|
|
129
|
+
const conteudoOriginal = extrairConteudo(svgOriginal)
|
|
130
|
+
const conteudoColorido = aplicarCor(conteudoOriginal, config.cor)
|
|
117
131
|
|
|
118
|
-
|
|
119
|
-
|
|
132
|
+
// Calcula padding e escala para centralizar o ícone
|
|
133
|
+
const padding = config.tamanho * 0.15
|
|
134
|
+
const tamanhoIcone = config.tamanho - padding * 2
|
|
135
|
+
const [, , vbWidth, vbHeight] = viewBoxOriginal.split(' ').map(Number)
|
|
136
|
+
const escala = tamanhoIcone / Math.max(vbWidth, vbHeight)
|
|
120
137
|
|
|
121
138
|
const elementoFundo = config.formato !== 'sem' ? criarFundo(config.formato, config.tamanho, config.fundo) : ''
|
|
122
139
|
|
|
123
140
|
const classAttr = className ? ` class="${className}"` : ''
|
|
124
|
-
|
|
141
|
+
|
|
142
|
+
return `<svg width="${config.tamanho}" height="${config.tamanho}" viewBox="0 0 ${config.tamanho} ${config.tamanho}" fill="none" xmlns="http://www.w3.org/2000/svg"${classAttr}>${elementoFundo}<g transform="translate(${padding}, ${padding}) scale(${escala})">${conteudoColorido}</g></svg>`
|
|
125
143
|
}
|
|
126
144
|
|
|
127
145
|
export function listarBancos() {
|