types-nora-api 0.0.468 → 0.0.472

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.
@@ -0,0 +1,175 @@
1
+ import type { CapacidadeDef } from '../dominio';
2
+ import type { AtributoCompletaDto, ClasseDto, DificuldadeSessaoCompletaDto, EstatisticaDanificavelCompletaDto, FichaEmProcessoDeEvolucaoDto, GanhoNivelClasseCompletaDto, NivelDto, PatentePericiaCompletaDto, PericiaCompletaDto, TipoGanhoNivelCompletaDto, TipoSessaoDto, UsuarioParaObjetoAutenticacaoDto, VariavelAmbienteCompletaDto } from '../dtos';
3
+ interface PaletaCores {
4
+ corPrimaria: string;
5
+ corSecundaria?: string;
6
+ corTerciaria?: string;
7
+ }
8
+ type EstruturaPaginaDefinicao = {
9
+ titulo: string;
10
+ subtitulo?: string;
11
+ listaConteudo: {
12
+ itens: ConteudoItem[];
13
+ };
14
+ listaItensDefinicoesConectadas?: {
15
+ etiqueta: string;
16
+ subPaginaDefinicao: string;
17
+ }[];
18
+ };
19
+ type ConteudoItem = {
20
+ tipo: 'Definicao';
21
+ elementos: DefinicaoElemento[];
22
+ } | {
23
+ tipo: 'Lista';
24
+ itensLista: ListaItem[];
25
+ };
26
+ type DefinicaoElemento = {
27
+ tipo: 'Paragrafo';
28
+ conteudo: string;
29
+ } | {
30
+ tipo: 'ParagrafoSecreto';
31
+ };
32
+ type ListaItem = {
33
+ tipo: 'ItemLista';
34
+ etiqueta: string;
35
+ subPaginaDefinicao: string;
36
+ } | {
37
+ tipo: 'ItemListaSecreto';
38
+ };
39
+ declare enum AventuraEstado {
40
+ EM_PREPARO = "Em Preparo",
41
+ EM_ANDAMENTO = "Em Andamento",
42
+ FINALIZADA = "Finalizada"
43
+ }
44
+ declare enum EstadoPendenciaPersonagem {
45
+ RESUMO_AVENTURA_PENDENTE = "Informa\u00E7\u00F5es sobre Aventura Pendentes",
46
+ FICHA_NAO_CRIADA = "Cria\u00E7\u00E3o da Ficha Pendente",
47
+ FICHA_PENDENTE = "Atualiza\u00E7\u00E3o de Ficha Pendente",
48
+ SEM_PENDENCIAS = ""
49
+ }
50
+ declare enum EstadoPendenciaAdministrativaPersonagem {
51
+ SEM_AVATAR = "O Administrador ainda n\u00E3o vinculou o avatar do personagem",
52
+ SEM_PENDENCIAS = ""
53
+ }
54
+ declare enum EstadoOcupacaoPersonagem {
55
+ SE_PREPARANDO_AVENTURA = 0,
56
+ EM_AVENTURA = 1,
57
+ EM_ESPERA = 2
58
+ }
59
+ declare enum EstadoSessao {
60
+ MARCADA = "A Sess\u00E3o est\u00E1 marcada",
61
+ EM_ANDAMENTO = "A Sess\u00E3o est\u00E1 em andamento nesse momento",
62
+ FINALIZADA = "A Sess\u00E3o j\u00E1 foi realizada"
63
+ }
64
+ declare enum DiaDaSemana {
65
+ DOMINGO = 0,
66
+ SEGUNDA = 1,
67
+ TERCA = 2,
68
+ QUARTA = 3,
69
+ QUINTA = 4,
70
+ SEXTA = 5,
71
+ SABADO = 6
72
+ }
73
+ declare function obtemDiaDaSemanaPorExtensoPorDDS(dds: DiaDaSemana, plural?: boolean): string;
74
+ type NumeroHora24 = `0${0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9}` | `1${0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9}` | `2${0 | 1 | 2 | 3}`;
75
+ type NumeroMomento = `0${0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9}` | `${1 | 2 | 3 | 4 | 5}${0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9}`;
76
+ type MomentoFormatado24 = `${NumeroHora24}:${NumeroMomento}`;
77
+ type MomentoFormatado = `${NumeroMomento}:${NumeroMomento}`;
78
+ declare enum CargoExibicaoUsuario {
79
+ ADMIN = 0,
80
+ MESTRE = 1,
81
+ JOGADOR = 2,
82
+ ESPECTADOR = 3
83
+ }
84
+ type CargosUsuario = {
85
+ cargoExibicaoUsuario: CargoExibicaoUsuario;
86
+ hierarquiaNoCargo: number;
87
+ hierarquiaTotal: number;
88
+ cargos: string[];
89
+ };
90
+ type ObjetoAutenticacao = {
91
+ usuarioLogado: UsuarioParaObjetoAutenticacaoDto | null;
92
+ variaveisAmbiente: VariavelAmbienteCompletaDto[];
93
+ capacidadesConcedidas: Record<string, true>;
94
+ cadastroPermitido: boolean;
95
+ };
96
+ type ObjetoCache = {
97
+ atributos: AtributoCompletaDto[];
98
+ pericias: PericiaCompletaDto[];
99
+ patentesPericia: PatentePericiaCompletaDto[];
100
+ estatisticasDanificaveis: EstatisticaDanificavelCompletaDto[];
101
+ classes: ClasseDto[];
102
+ tiposGanho: TipoGanhoNivelCompletaDto[];
103
+ niveis: NivelDto[];
104
+ dificuldadesSessao: DificuldadeSessaoCompletaDto[];
105
+ tiposSessao: TipoSessaoDto[];
106
+ };
107
+ type ObjetoPendeciaPersonagem = {
108
+ pendeciaUsuario: EstadoPendenciaPersonagem;
109
+ pendenciaAdmin: EstadoPendenciaAdministrativaPersonagem;
110
+ };
111
+ type TipoVariavelAmbiente = 'boolean' | 'string' | 'number';
112
+ type ObjetoEvolucaoCompleto = ObjetoEvolucao & ObjetoGanhosEvolucao;
113
+ type ObjetoEvolucao = {
114
+ fichaEmProcessoDeEvolucao: FichaEmProcessoDeEvolucaoDto;
115
+ listaReferenciaTodosAtributos: AtributoCompletaDto[];
116
+ listaReferenciaPericiasDisponiveis: PericiaCompletaDto[];
117
+ listaReferenciaTodasPatentes: PatentePericiaCompletaDto[];
118
+ listaReferenciaTodasEstatisticasDanificaveis: EstatisticaDanificavelCompletaDto[];
119
+ listaReferenciaTodasClasses: ClasseDto[];
120
+ listaReferenciaTodosTiposGanho: TipoGanhoNivelCompletaDto[];
121
+ };
122
+ type ObjetoGanhosEvolucao = {
123
+ listaGanhos: GanhoNivelClasseCompletaDto[];
124
+ listaGanhosEstatisticasPorAtributos: GanhoEstatistica[];
125
+ };
126
+ type GanhoEstatistica = {
127
+ estatisticaDanificavel: EstatisticaDanificavelCompletaDto;
128
+ ganhosPorAtributo: {
129
+ atributo: AtributoCompletaDto;
130
+ valorPorUnidade: number;
131
+ }[];
132
+ };
133
+ declare enum FormatoMomento {
134
+ HMS = 0,
135
+ EXTENSO = 1,
136
+ EXTENSO_APROXIMADO = 2
137
+ }
138
+ type DetalheUtilizacaoRascunho = {
139
+ disponivel: boolean;
140
+ detalhe: string;
141
+ };
142
+ declare const PathAvatarPadrao: import("../dtos").CaminhoArquivoAvatar;
143
+ declare const PathArteCapaPadrao: import("../dtos").CaminhoArquivoArte;
144
+ type TituloSessaoInteligente = {
145
+ tituloCompleto: string;
146
+ titulo: string;
147
+ subtitulo?: string;
148
+ };
149
+ type PermissaoItemMinimo = {
150
+ id: number;
151
+ codigo: string;
152
+ itemPai?: {
153
+ id: number;
154
+ } | null;
155
+ };
156
+ type ListaCapacidadesNecessarias = readonly [CapacidadeDef, ...CapacidadeDef[]];
157
+ type AcessoPagina = {
158
+ autenticado: true;
159
+ listaDeCapacidadesNecessarias?: never;
160
+ cadastroPermitido?: never;
161
+ } | {
162
+ autenticado?: never;
163
+ listaDeCapacidadesNecessarias: ListaCapacidadesNecessarias;
164
+ cadastroPermitido?: never;
165
+ } | {
166
+ autenticado?: never;
167
+ listaDeCapacidadesNecessarias?: never;
168
+ cadastroPermitido: true;
169
+ };
170
+ declare function momentoParaMinutos(momento: string): number;
171
+ declare function concatenarDataEHoraEmNovaData(data: Date | string, hora: string, utcOffsetMinutes?: number): Date;
172
+ declare const pluralize: (count: number, singular: string, plural?: string) => string;
173
+ declare function minutosParaMs(minutos: number): number;
174
+ declare function formataDataCompacta(data?: Date): string;
175
+ export { AcessoPagina, AventuraEstado, CargoExibicaoUsuario, CargosUsuario, ConteudoItem, DefinicaoElemento, DetalheUtilizacaoRascunho, DiaDaSemana, EstadoOcupacaoPersonagem, EstadoPendenciaAdministrativaPersonagem, EstadoPendenciaPersonagem, EstadoSessao, EstruturaPaginaDefinicao, FormatoMomento, GanhoEstatistica, ListaCapacidadesNecessarias, ListaItem, MomentoFormatado, MomentoFormatado24, NumeroHora24, NumeroMomento, ObjetoAutenticacao, ObjetoCache, ObjetoEvolucao, ObjetoEvolucaoCompleto, ObjetoGanhosEvolucao, ObjetoPendeciaPersonagem, PaletaCores, PathArteCapaPadrao, PathAvatarPadrao, PermissaoItemMinimo, TipoVariavelAmbiente, TituloSessaoInteligente, concatenarDataEHoraEmNovaData, formataDataCompacta, minutosParaMs, momentoParaMinutos, obtemDiaDaSemanaPorExtensoPorDDS, pluralize };
@@ -0,0 +1,138 @@
1
+ // AUTO-GENERATED FILE - DO NOT EDIT
2
+ // Contratos compartilhados base
3
+ import { ARQUIVOS_INTERNOS } from '../dominio';
4
+ import { criaCaminhoArquivoArte, criaCaminhoArquivoAvatar } from '../dtos';
5
+ // @tipoCompartilhadoFront
6
+ var AventuraEstado;
7
+ (function (AventuraEstado) {
8
+ AventuraEstado["EM_PREPARO"] = "Em Preparo";
9
+ AventuraEstado["EM_ANDAMENTO"] = "Em Andamento";
10
+ AventuraEstado["FINALIZADA"] = "Finalizada";
11
+ })(AventuraEstado || (AventuraEstado = {}));
12
+ // @tipoCompartilhadoFront
13
+ var EstadoPendenciaPersonagem;
14
+ (function (EstadoPendenciaPersonagem) {
15
+ EstadoPendenciaPersonagem["RESUMO_AVENTURA_PENDENTE"] = "Informa\u00E7\u00F5es sobre Aventura Pendentes";
16
+ EstadoPendenciaPersonagem["FICHA_NAO_CRIADA"] = "Cria\u00E7\u00E3o da Ficha Pendente";
17
+ EstadoPendenciaPersonagem["FICHA_PENDENTE"] = "Atualiza\u00E7\u00E3o de Ficha Pendente";
18
+ EstadoPendenciaPersonagem["SEM_PENDENCIAS"] = "";
19
+ })(EstadoPendenciaPersonagem || (EstadoPendenciaPersonagem = {}));
20
+ // @tipoCompartilhadoFront
21
+ var EstadoPendenciaAdministrativaPersonagem;
22
+ (function (EstadoPendenciaAdministrativaPersonagem) {
23
+ EstadoPendenciaAdministrativaPersonagem["SEM_AVATAR"] = "O Administrador ainda n\u00E3o vinculou o avatar do personagem";
24
+ EstadoPendenciaAdministrativaPersonagem["SEM_PENDENCIAS"] = "";
25
+ })(EstadoPendenciaAdministrativaPersonagem || (EstadoPendenciaAdministrativaPersonagem = {}));
26
+ // @tipoCompartilhadoFront
27
+ var EstadoOcupacaoPersonagem;
28
+ (function (EstadoOcupacaoPersonagem) {
29
+ EstadoOcupacaoPersonagem[EstadoOcupacaoPersonagem["SE_PREPARANDO_AVENTURA"] = 0] = "SE_PREPARANDO_AVENTURA";
30
+ EstadoOcupacaoPersonagem[EstadoOcupacaoPersonagem["EM_AVENTURA"] = 1] = "EM_AVENTURA";
31
+ EstadoOcupacaoPersonagem[EstadoOcupacaoPersonagem["EM_ESPERA"] = 2] = "EM_ESPERA";
32
+ })(EstadoOcupacaoPersonagem || (EstadoOcupacaoPersonagem = {}));
33
+ // @tipoCompartilhadoFront
34
+ var EstadoSessao;
35
+ (function (EstadoSessao) {
36
+ EstadoSessao["MARCADA"] = "A Sess\u00E3o est\u00E1 marcada";
37
+ EstadoSessao["EM_ANDAMENTO"] = "A Sess\u00E3o est\u00E1 em andamento nesse momento";
38
+ EstadoSessao["FINALIZADA"] = "A Sess\u00E3o j\u00E1 foi realizada";
39
+ })(EstadoSessao || (EstadoSessao = {}));
40
+ // @tipoCompartilhadoFront
41
+ var DiaDaSemana;
42
+ (function (DiaDaSemana) {
43
+ DiaDaSemana[DiaDaSemana["DOMINGO"] = 0] = "DOMINGO";
44
+ DiaDaSemana[DiaDaSemana["SEGUNDA"] = 1] = "SEGUNDA";
45
+ DiaDaSemana[DiaDaSemana["TERCA"] = 2] = "TERCA";
46
+ DiaDaSemana[DiaDaSemana["QUARTA"] = 3] = "QUARTA";
47
+ DiaDaSemana[DiaDaSemana["QUINTA"] = 4] = "QUINTA";
48
+ DiaDaSemana[DiaDaSemana["SEXTA"] = 5] = "SEXTA";
49
+ DiaDaSemana[DiaDaSemana["SABADO"] = 6] = "SABADO";
50
+ })(DiaDaSemana || (DiaDaSemana = {}));
51
+ // @tipoCompartilhadoFront
52
+ function obtemDiaDaSemanaPorExtensoPorDDS(dds, plural = false) {
53
+ const diasDaSemanaSingular = [
54
+ 'Domingo',
55
+ 'Segunda-feira',
56
+ 'Terça-feira',
57
+ 'Quarta-feira',
58
+ 'Quinta-feira',
59
+ 'Sexta-feira',
60
+ 'Sábado',
61
+ ];
62
+ const diasDaSemanaPlural = [
63
+ 'Domingos',
64
+ 'Segundas-feiras',
65
+ 'Terças-feiras',
66
+ 'Quartas-feiras',
67
+ 'Quintas-feiras',
68
+ 'Sextas-feiras',
69
+ 'Sábados',
70
+ ];
71
+ return plural ? diasDaSemanaPlural[dds] : diasDaSemanaSingular[dds];
72
+ }
73
+ // @tipoCompartilhadoFront
74
+ var CargoExibicaoUsuario;
75
+ (function (CargoExibicaoUsuario) {
76
+ CargoExibicaoUsuario[CargoExibicaoUsuario["ADMIN"] = 0] = "ADMIN";
77
+ CargoExibicaoUsuario[CargoExibicaoUsuario["MESTRE"] = 1] = "MESTRE";
78
+ CargoExibicaoUsuario[CargoExibicaoUsuario["JOGADOR"] = 2] = "JOGADOR";
79
+ CargoExibicaoUsuario[CargoExibicaoUsuario["ESPECTADOR"] = 3] = "ESPECTADOR";
80
+ })(CargoExibicaoUsuario || (CargoExibicaoUsuario = {}));
81
+ // @tipoCompartilhadoFront
82
+ var FormatoMomento;
83
+ (function (FormatoMomento) {
84
+ FormatoMomento[FormatoMomento["HMS"] = 0] = "HMS";
85
+ FormatoMomento[FormatoMomento["EXTENSO"] = 1] = "EXTENSO";
86
+ FormatoMomento[FormatoMomento["EXTENSO_APROXIMADO"] = 2] = "EXTENSO_APROXIMADO";
87
+ })(FormatoMomento || (FormatoMomento = {}));
88
+ // @tipoCompartilhadoFront
89
+ const PathAvatarPadrao = criaCaminhoArquivoAvatar(ARQUIVOS_INTERNOS.AVATAR_PADRAO.caminhoArquivo);
90
+ const PathArteCapaPadrao = criaCaminhoArquivoArte('RecursosPublicos/imagem_especial_artista/e1e4973b-d681-4387-8028-2cce061939c6.webp');
91
+ // @tipoCompartilhadoFront
92
+ function momentoParaMinutos(momento) {
93
+ const partes = momento.split(':');
94
+ const hh = Number(partes[0]);
95
+ const mm = Number(partes[1]);
96
+ if (!Number.isFinite(hh) || !Number.isFinite(mm))
97
+ throw new Error(`Momento inválido: ${momento}`);
98
+ return (hh * 60) + mm;
99
+ }
100
+ // @tipoCompartilhadoFront
101
+ function concatenarDataEHoraEmNovaData(data, hora, utcOffsetMinutes = -180) {
102
+ const base = typeof data === 'string' ? new Date(data) : new Date(data);
103
+ if (Number.isNaN(base.getTime()))
104
+ throw new Error('Data inválida');
105
+ const partes = hora.split(':');
106
+ if (partes.length !== 2)
107
+ throw new Error('Hora inválida, esperado HH:mm');
108
+ const h = Number(partes[0]);
109
+ const m = Number(partes[1]);
110
+ if (!Number.isInteger(h) || !Number.isInteger(m) || h < 0 || h > 23 || m < 0 || m > 59)
111
+ throw new Error('Hora inválida, esperado HH:mm');
112
+ const y = base.getUTCFullYear();
113
+ const mo = base.getUTCMonth();
114
+ const d = base.getUTCDate();
115
+ const localMinutes = (h * 60) + m;
116
+ const utcMinutes = localMinutes - utcOffsetMinutes;
117
+ const inicioDoDiaUtcMs = Date.UTC(y, mo, d, 0, 0, 0, 0);
118
+ return new Date(inicioDoDiaUtcMs + (utcMinutes * 60_000));
119
+ }
120
+ // @tipoCompartilhadoFront
121
+ const pluralize = (count, singular, plural) => {
122
+ const pluralForm = plural || `${singular}s`;
123
+ return count === 1 ? singular : pluralForm;
124
+ };
125
+ // @tipoCompartilhadoFront
126
+ function minutosParaMs(minutos) { return minutos * 60 * 1000; }
127
+ // @tipoCompartilhadoFront
128
+ function formataDataCompacta(data = new Date()) {
129
+ const ano = data.getFullYear();
130
+ const mes = String(data.getMonth() + 1).padStart(2, '0');
131
+ const dia = String(data.getDate()).padStart(2, '0');
132
+ const hora = String(data.getHours()).padStart(2, '0');
133
+ const minuto = String(data.getMinutes()).padStart(2, '0');
134
+ const segundo = String(data.getSeconds()).padStart(2, '0');
135
+ const milesimo = String(data.getMilliseconds()).padStart(3, '0');
136
+ return `${ano}${mes}${dia}_${hora}${minuto}${segundo}${milesimo}`;
137
+ }
138
+ export { AventuraEstado, CargoExibicaoUsuario, DiaDaSemana, EstadoOcupacaoPersonagem, EstadoPendenciaAdministrativaPersonagem, EstadoPendenciaPersonagem, EstadoSessao, FormatoMomento, PathArteCapaPadrao, PathAvatarPadrao, concatenarDataEHoraEmNovaData, formataDataCompacta, minutosParaMs, momentoParaMinutos, obtemDiaDaSemanaPorExtensoPorDDS, pluralize };
@@ -0,0 +1,47 @@
1
+ import type { FormatoUploadArquivo, RegrasUploadArquivo } from '../dtos';
2
+ type ResultadoValidacao = {
3
+ ok: true;
4
+ } | {
5
+ ok: false;
6
+ erros: string[];
7
+ };
8
+ declare function isNumeroInteiroPositivo(n: number): boolean;
9
+ declare function isNumeroPositivo(n: number): boolean;
10
+ declare function pushErro(erros: string[], msg: string): void;
11
+ declare function validarFormatos(formatos: FormatoUploadArquivo[], erros: string[]): void;
12
+ declare function validarTamanho(regras: RegrasUploadArquivo, erros: string[]): void;
13
+ declare function validarDimensoesDim(d: {
14
+ largura: number;
15
+ altura: number;
16
+ }, path: string, erros: string[]): void;
17
+ declare function validarDimensoesRegra(regra: {
18
+ modo: 'exato';
19
+ exato: {
20
+ largura: number;
21
+ altura: number;
22
+ };
23
+ } | ({
24
+ modo: 'intervalo';
25
+ } & {
26
+ min?: {
27
+ largura: number;
28
+ altura: number;
29
+ };
30
+ max?: {
31
+ largura: number;
32
+ altura: number;
33
+ };
34
+ }), erros: string[]): void;
35
+ declare function validarProporcao(regra: {
36
+ largura: number;
37
+ altura: number;
38
+ toleranciaPercentual?: number;
39
+ }, erros: string[]): void;
40
+ declare function validarMaxPixels(maxPixels: number | undefined, erros: string[]): void;
41
+ declare function validarImagem(regras: RegrasUploadArquivo, erros: string[]): void;
42
+ declare function validarRegrasUploadArquivo(regras: RegrasUploadArquivo): ResultadoValidacao;
43
+ declare function isRegrasUploadArquivoValidas(regras: RegrasUploadArquivo): regras is RegrasUploadArquivo;
44
+ declare function mimeFromFormato(formato: FormatoUploadArquivo): string | null;
45
+ declare function acceptFromFormatos(formatos: FormatoUploadArquivo[]): string;
46
+ declare function isFormatoImagemBitmap(formato: FormatoUploadArquivo): formato is "png" | "webp";
47
+ export { ResultadoValidacao, acceptFromFormatos, isFormatoImagemBitmap, isNumeroInteiroPositivo, isNumeroPositivo, isRegrasUploadArquivoValidas, mimeFromFormato, pushErro, validarDimensoesDim, validarDimensoesRegra, validarFormatos, validarImagem, validarMaxPixels, validarProporcao, validarRegrasUploadArquivo, validarTamanho };
@@ -0,0 +1,112 @@
1
+ // AUTO-GENERATED FILE - DO NOT EDIT
2
+ // Contratos de uploads
3
+ function isNumeroInteiroPositivo(n) { return Number.isInteger(n) && n > 0; }
4
+ function isNumeroPositivo(n) { return typeof n === 'number' && Number.isFinite(n) && n > 0; }
5
+ function pushErro(erros, msg) { erros.push(msg); }
6
+ function validarFormatos(formatos, erros) {
7
+ if (!Array.isArray(formatos) || formatos.length === 0) {
8
+ pushErro(erros, 'formatosPermitidos deve ter pelo menos 1 formato.');
9
+ return;
10
+ }
11
+ const set = new Set();
12
+ for (const f of formatos) {
13
+ if (f !== 'png' && f !== 'webp' && f !== 'svg')
14
+ pushErro(erros, `Formato inválido em formatosPermitidos: ${String(f)}`);
15
+ if (set.has(f))
16
+ pushErro(erros, `Formato duplicado em formatosPermitidos: ${f}`);
17
+ set.add(f);
18
+ }
19
+ }
20
+ function validarTamanho(regras, erros) {
21
+ if (!('tamanho' in regras) || !regras.tamanho)
22
+ return;
23
+ const { minBytes, maxBytes } = regras.tamanho;
24
+ if (minBytes === undefined && maxBytes === undefined)
25
+ pushErro(erros, 'tamanho não pode ser {}: informe minBytes e/ou maxBytes.');
26
+ if (minBytes !== undefined && (!isNumeroInteiroPositivo(minBytes) || minBytes < 1))
27
+ pushErro(erros, 'tamanho.minBytes deve ser inteiro positivo.');
28
+ if (maxBytes !== undefined && (!isNumeroInteiroPositivo(maxBytes) || maxBytes < 1))
29
+ pushErro(erros, 'tamanho.maxBytes deve ser inteiro positivo.');
30
+ if (minBytes !== undefined && maxBytes !== undefined && minBytes > maxBytes)
31
+ pushErro(erros, 'tamanho.minBytes não pode ser maior que tamanho.maxBytes.');
32
+ }
33
+ function validarDimensoesDim(d, path, erros) {
34
+ if (!isNumeroInteiroPositivo(d.largura))
35
+ pushErro(erros, `${path}.largura deve ser inteiro positivo.`);
36
+ if (!isNumeroInteiroPositivo(d.altura))
37
+ pushErro(erros, `${path}.altura deve ser inteiro positivo.`);
38
+ }
39
+ function validarDimensoesRegra(regra, erros) {
40
+ if (regra.modo === 'exato') {
41
+ validarDimensoesDim(regra.exato, 'imagem.dimensoes.exato', erros);
42
+ return;
43
+ }
44
+ const min = regra.min;
45
+ const max = regra.max;
46
+ if (!min && !max)
47
+ pushErro(erros, 'imagem.dimensoes (intervalo) exige min e/ou max.');
48
+ if (min)
49
+ validarDimensoesDim(min, 'imagem.dimensoes.min', erros);
50
+ if (max)
51
+ validarDimensoesDim(max, 'imagem.dimensoes.max', erros);
52
+ if (min && max) {
53
+ if (min.largura > max.largura)
54
+ pushErro(erros, 'imagem.dimensoes.min.largura não pode ser maior que imagem.dimensoes.max.largura.');
55
+ if (min.altura > max.altura)
56
+ pushErro(erros, 'imagem.dimensoes.min.altura não pode ser maior que imagem.dimensoes.max.altura.');
57
+ }
58
+ }
59
+ function validarProporcao(regra, erros) {
60
+ if (!isNumeroInteiroPositivo(regra.largura))
61
+ pushErro(erros, 'imagem.proporcao.largura deve ser inteiro positivo.');
62
+ if (!isNumeroInteiroPositivo(regra.altura))
63
+ pushErro(erros, 'imagem.proporcao.altura deve ser inteiro positivo.');
64
+ if (regra.toleranciaPercentual !== undefined && (!isNumeroPositivo(regra.toleranciaPercentual) || regra.toleranciaPercentual > 50))
65
+ pushErro(erros, 'imagem.proporcao.toleranciaPercentual deve ser > 0 e <= 50.');
66
+ }
67
+ function validarMaxPixels(maxPixels, erros) {
68
+ if (maxPixels === undefined)
69
+ return;
70
+ if (!isNumeroInteiroPositivo(maxPixels))
71
+ pushErro(erros, 'imagem.maxPixels deve ser inteiro positivo.');
72
+ }
73
+ function validarImagem(regras, erros) {
74
+ if (!('imagem' in regras) || !regras.imagem)
75
+ return;
76
+ const imagem = regras.imagem;
77
+ if (imagem.tipoValidacao === 'dimensoes') {
78
+ validarDimensoesRegra(imagem.dimensoes, erros);
79
+ validarMaxPixels(imagem.maxPixels, erros);
80
+ return;
81
+ }
82
+ if (imagem.tipoValidacao === 'proporcao') {
83
+ validarProporcao(imagem.proporcao, erros);
84
+ validarMaxPixels(imagem.maxPixels, erros);
85
+ return;
86
+ }
87
+ if (imagem.tipoValidacao === 'nenhuma') {
88
+ validarMaxPixels(imagem.maxPixels, erros);
89
+ return;
90
+ }
91
+ pushErro(erros, 'imagem.tipoValidacao inválido.');
92
+ }
93
+ function validarRegrasUploadArquivo(regras) {
94
+ const erros = [];
95
+ validarFormatos(regras.formatosPermitidos, erros);
96
+ validarTamanho(regras, erros);
97
+ validarImagem(regras, erros);
98
+ return erros.length === 0 ? { ok: true } : { ok: false, erros };
99
+ }
100
+ function isRegrasUploadArquivoValidas(regras) { return validarRegrasUploadArquivo(regras).ok; }
101
+ function mimeFromFormato(formato) {
102
+ if (formato === 'webp')
103
+ return 'image/webp';
104
+ if (formato === 'svg')
105
+ return 'image/svg+xml';
106
+ if (formato === 'png')
107
+ return 'image/png';
108
+ return null;
109
+ }
110
+ function acceptFromFormatos(formatos) { return Array.from(new Set(formatos.map(mimeFromFormato).filter((v) => v !== null))).join(','); }
111
+ function isFormatoImagemBitmap(formato) { return formato === 'webp' || formato === 'png'; }
112
+ export { acceptFromFormatos, isFormatoImagemBitmap, isNumeroInteiroPositivo, isNumeroPositivo, isRegrasUploadArquivoValidas, mimeFromFormato, pushErro, validarDimensoesDim, validarDimensoesRegra, validarFormatos, validarImagem, validarMaxPixels, validarProporcao, validarRegrasUploadArquivo, validarTamanho };