PageSourceSearch

https://cliente.kalunga.com.br/static/scripts/dist/cpfj-utilities.js

js kalunga.com.br collected 2026-10-02 02:46:55 UTC 12,237 bytes, 338 lines download raw bytes

1"use strict";
2class CpfjUtilitiesJs {
3    constructor(theName) {
4        this.appName = "cliente.kalunga.com.br";
5        this.appName = theName;
6    }
7    static disposeModais() {
8        try {
9            if (this.loadingElement == null) {
10                this.loadingElement = document.getElementById('loading-overlay-kal');
11            }
12            if (this.loadingElement !== null) {
13                if (this.loadingElement.parentNode) {
14                    this.loadingElement.parentNode.removeChild(this.loadingElement);
15                }
16                this.loadingElement.remove();
17                this.loadingElement = null;
18                document.body.style.overflow = '';
19                document.body.style.pointerEvents = '';
20            }
21        }
22        catch (err) {
23            console.error("hideLoading -> Error: ", err);
24        }
25        try {
26            if (this.errorTimeoutId !== null) {
27                clearTimeout(this.errorTimeoutId);
28                this.errorTimeoutId = null;
29            }
30            if (this.errorElement == null) {
31                this.errorElement = document.getElementById('error-overlay-kalc');
32            }
33            if (this.errorElement !== null) {
34                if (this.errorElement.parentNode) {
35                    this.errorElement.parentNode.removeChild(this.errorElement);
36                }
37                this.errorElement.remove();
38                this.errorElement = null;
39                document.body.style.overflow = '';
40                document.body.style.pointerEvents = '';
41            }
42        }
43        catch (err) {
44            console.error("hideError -> Error: ", err);
45        }
46    }
47    static hideLoading() {
48        this.disposeModais();
49    }
50    static showLoading(message) {
51        try {
52            if (this.loadingElement) {
53                this.hideLoading();
54            }
55            this.loadingElement = document.createElement('div');
56            this.loadingElement.id = 'loading-overlay-kal';
57            this.loadingElement.style.cssText = `
58            position: fixed;
59            top: 0;
60            left: 0;
61            width: 100vw;
62            height: 100vh;
63            background: rgba(0, 0, 0, 0.7);
64            display: flex;
65            flex-direction: column;
66            align-items: center;
67            justify-content: center;
68            z-index: 999999;
69            cursor: wait;
70        `;
71            this.loadingElement.innerHTML = `
72            <div style="
73                width: 50px;
74                height: 50px;
75                border: 5px solid rgba(255,255,255,0.1);
76                border-top: 5px solid #ffffff;
77                border-radius: 50%;
78                animation: spin 1s linear infinite;
79            "></div>
80            <p style="
81                color: #ffffff;
82                font-size: 18px;
83                margin-top: 20px;
84                font-family: Arial, sans-serif;
85            ">${message}</p>
86            <style>
87                @keyframes spin {
88                    0% { transform: rotate(0deg); }
89                    100% { transform: rotate(360deg); }
90                }
91            </style>
92        `;
93            document.body.appendChild(this.loadingElement);
94            document.body.style.overflow = 'hidden';
95            document.body.style.pointerEvents = 'none';
96        }
97        catch (err) {
98            console.error("showLoading -> Error: ", err);
99        }
100    }
101    static hideError() {
102        this.disposeModais();
103    }
104    static showError(message) {
105        console.error("Exception: ", message);
106        try {
107            if (this.errorElement) {
108                this.hideError();
109            }
110            this.errorElement = document.createElement('div');
111            this.errorElement.id = 'error-overlay-kalc';
112            this.errorElement.style.cssText = `
113        position: fixed;
114        top: 0;
115        left: 0;
116        width: 100vw;
117        height: 100vh;
118        background: rgba(0, 0, 0, 0.7);
119        display: flex;
120        flex-direction: column;
121        align-items: center;
122        justify-content: center;
123        z-index: 999999;
124    `;
125            this.errorElement.innerHTML = `
126        <div style="
127            position: relative;
128            background: #ffffff;
129            border-radius: 8px;
130            padding: 24px 32px;
131            max-width: 400px;
132            width: 90%;
133            display: flex;
134            flex-direction: column;
135            align-items: center;
136            box-shadow: 0 10px 40px rgba(0,0,0,0.3);
137            animation: kcpErrorFadeIn 0.25s ease-out;
138            font-family: Arial, sans-serif;
139        ">
140            <button id="kcp-error-close-btn" type="button" aria-label="Fechar" style="
141                position: absolute;
142                top: 8px;
143                right: 8px;
144                width: 28px;
145                height: 28px;
146                border: none;
147                background: transparent;
148                cursor: pointer;
149                font-size: 18px;
150                line-height: 1;
151                color: #888888;
152                display: flex;
153                align-items: center;
154                justify-content: center;
155                border-radius: 4px;
156            ">&times;</button>
157            <div style="
158                width: 48px;
159                height: 48px;
160                border-radius: 50%;
161                background: #fde8e8;
162                display: flex;
163                align-items: center;
164                justify-content: center;
165                margin-bottom: 16px;
166            ">
167                <svg width="26" height="26" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
168                    <circle cx="12" cy="12" r="10" stroke="#d9534f" stroke-width="2"/>
169                    <path d="M12 8V13" stroke="#d9534f" stroke-width="2" stroke-linecap="round"/>
170                    <circle cx="12" cy="16.5" r="1" fill="#d9534f"/>
171                </svg>
172            </div>
173            <p style="
174                color: #333333;
175                font-size: 15px;
176                text-align: center;
177                margin: 0;
178                line-height: 1.4;
179            ">${message}</p>
180        </div>
181        <style>
182            @keyframes kcpErrorFadeIn {
183                from { opacity: 0; transform: translateY(-10px); }
184                to { opacity: 1; transform: translateY(0); }
185            }
186            #kcp-error-close-btn:hover {
187                background: #f0f0f0;
188                color: #333333;
189            }
190        </style>
191    `;
192            document.body.appendChild(this.errorElement);
193            document.body.style.overflow = 'hidden';
194            document.body.style.pointerEvents = 'none';
195            this.errorElement.style.pointerEvents = 'auto';
196            const closeBtn = this.errorElement.querySelector('#kcp-error-close-btn');
197            closeBtn === null || closeBtn === void 0 ? void 0 : closeBtn.addEventListener('click', () => this.hideError());
198            this.errorTimeoutId = window.setTimeout(() => {
199                this.hideError();
200            }, 5000);
201        }
202        catch (err) {
203            console.error("showError -> Error: ", err);
204        }
205    }
206    static valorCaractereCNPJ(caractere) {
207        if (!caractere)
208            return -1;
209        const codigo = caractere.charCodeAt(0);
210        if ((codigo >= 48 && codigo <= 57) || (codigo >= 65 && codigo <= 90)) {
211            return codigo - 48;
212        }
213        return -1;
214    }
215    static calcularDVCNPJAlfanumerico(base) {
216        const pesos = base.length === 12 ? this.PESOS_12 : base.length === 13 ? this.PESOS_13 : null;
217        if (!pesos)
218            return -1;
219        let soma = 0;
220        for (let i = 0; i < base.length; i++) {
221            const valor = this.valorCaractereCNPJ(base[i]);
222            if (valor < 0)
223                return -1;
224            soma += valor * pesos[i];
225        }
226        const resto = soma % 11;
227        return resto < 2 ? 0 : 11 - resto;
228    }
229    static calcularDVCPF(base) {
230        let soma = 0;
231        for (let i = 0; i < base.length; i++) {
232            soma += parseInt(base[i], 10) * (base.length + 1 - i);
233        }
234        const resto = (soma * 10) % 11;
235        return resto === 10 ? 0 : resto;
236    }
237    static calcularDVCNPJNumerico(base) {
238        const pesos = base.length === 12
239            ? this.PESOS_12
240            : this.PESOS_13;
241        let soma = 0;
242        for (let i = 0; i < base.length; i++) {
243            soma += parseInt(base[i], 10) * pesos[i];
244        }
245        const resto = soma % 11;
246        return resto < 2 ? 0 : 11 - resto;
247    }
248    static limpar(valor) {
249        return (valor !== null && valor !== void 0 ? valor : '').toUpperCase().replace(/[^A-Z0-9]/g, '');
250    }
251    static validarCPF(valor) {
252        const limpo = valor.replace(/\D/g, '');
253        if (limpo.length !== 11)
254            return false;
255        if (/^(\d)\1{10}$/.test(limpo))
256            return false;
257        const dv1 = this.calcularDVCPF(limpo.substring(0, 9));
258        const dv2 = this.calcularDVCPF(limpo.substring(0, 9) + dv1);
259        return limpo === `${limpo.substring(0, 9)}${dv1}${dv2}`;
260    }
261    static validarCNPJNumerico(valor) {
262        const limpo = valor.replace(/\D/g, '');
263        if (limpo.length !== 14)
264            return false;
265        if (/^(\d)\1{13}$/.test(limpo))
266            return false;
267        const dv1 = this.calcularDVCNPJNumerico(limpo.substring(0, 12));
268        const dv2 = this.calcularDVCNPJNumerico(limpo.substring(0, 12) + dv1);
269        return limpo === `${limpo.substring(0, 12)}${dv1}${dv2}`;
270    }
271    static validarCNPJAlfanumerico(valor) {
272        const limpo = this.limpar(valor);
273        if (limpo.length !== 14)
274            return false;
275        const base = limpo.substring(0, 12);
276        const dvInformado = limpo.substring(12, 14);
277        if (!/^[A-Z0-9]{12}$/.test(base))
278            return false;
279        if (!/^[0-9]{2}$/.test(dvInformado))
280            return false;
281        const dv1 = this.calcularDVCNPJAlfanumerico(base);
282        if (dv1 < 0)
283            return false;
284        const dv2 = this.calcularDVCNPJAlfanumerico(base + dv1.toString());
285        if (dv2 < 0)
286            return false;
287        return dvInformado === `${dv1}${dv2}`;
288    }
289    static validar(valor) {
290        const limpo = this.limpar(valor);
291        const contemLetra = /[A-Z]/.test(limpo);
292        if (contemLetra || limpo.length === 14) {
293            return contemLetra
294                ? this.validarCNPJAlfanumerico(limpo)
295                : this.validarCNPJNumerico(limpo);
296        }
297        if (limpo.length === 11) {
298            return this.validarCPF(limpo);
299        }
300        return false;
301    }
302    static mascararCpfCnpj(valor) {
303        let limpo = this.limpar(valor);
304        const contemLetra = /[A-Z]/.test(limpo);
305        if (contemLetra || limpo.length > 11) {
306            const base = limpo.substring(0, 12).replace(/[^A-Z0-9]/g, '');
307            const dv = limpo.substring(12, 14).replace(/[^0-9]/g, '');
308            limpo = (base + dv).substring(0, 14);
309            return limpo
310                .replace(/^([A-Z0-9]{2})([A-Z0-9])/, '$1.$2')
311                .replace(/^([A-Z0-9]{2})\.([A-Z0-9]{3})([A-Z0-9])/, '$1.$2.$3')
312                .replace(/\.([A-Z0-9]{3})([A-Z0-9])/, '.$1/$2')
313                .replace(/\/([A-Z0-9]{4})([0-9]{1,2})$/, '/$1-$2');
314        }
315        limpo = limpo.substring(0, 11);
316        return limpo
317            .replace(/(\d{3})(\d)/, '$1.$2')
318            .replace(/(\d{3})(\d)/, '$1.$2')
319            .replace(/(\d{3})(\d{1,2})$/, '$1-$2');
320    }
321    static fnCheckInputDataEnter(element, event) {
322        const code = event.keyCode || event.which;
323        if (code === 13) {
324            const btn = document.getElementById('btnContinuar');
325            if (btn) {
326                btn.click();
327            }
328            return false;
329        }
330        element.value = this.mascararCpfCnpj(element.value);
331        return true;
332    }
333}
334CpfjUtilitiesJs.loadingElement = null;
335CpfjUtilitiesJs.errorElement = null;
336CpfjUtilitiesJs.errorTimeoutId = null;
337CpfjUtilitiesJs.PESOS_12 = [5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];
338CpfjUtilitiesJs.PESOS_13 = [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.