@attrx/role-morphic 0.1.0 → 0.2.1
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/README.md +151 -84
- package/dist/cast.d.mts +678 -0
- package/dist/cast.d.ts +678 -0
- package/dist/cast.js +3569 -0
- package/dist/cast.js.map +1 -0
- package/dist/cast.mjs +3536 -0
- package/dist/cast.mjs.map +1 -0
- package/dist/constants-BZdBwuvJ.d.mts +168 -0
- package/dist/constants-BZdBwuvJ.d.ts +168 -0
- package/dist/convert.d.mts +1157 -0
- package/dist/convert.d.ts +1157 -0
- package/dist/convert.js +2244 -0
- package/dist/convert.js.map +1 -0
- package/dist/convert.mjs +2148 -0
- package/dist/convert.mjs.map +1 -0
- package/dist/format-Be15LzfS.d.ts +668 -0
- package/dist/format-o4Y3jPH-.d.mts +668 -0
- package/dist/format.d.mts +3 -0
- package/dist/format.d.ts +3 -0
- package/dist/format.js +2303 -0
- package/dist/format.js.map +1 -0
- package/dist/format.mjs +2286 -0
- package/dist/format.mjs.map +1 -0
- package/dist/index.d.mts +200 -601
- package/dist/index.d.ts +200 -601
- package/dist/index.js +5536 -2493
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5349 -2494
- package/dist/index.mjs.map +1 -1
- package/dist/types-mbeS1e-k.d.mts +312 -0
- package/dist/types-mbeS1e-k.d.ts +312 -0
- package/dist/validate.d.mts +884 -0
- package/dist/validate.d.ts +884 -0
- package/dist/validate.js +713 -0
- package/dist/validate.js.map +1 -0
- package/dist/validate.mjs +669 -0
- package/dist/validate.mjs.map +1 -0
- package/package.json +21 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,303 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
* - Convert: Transforma entre variantes (via base)
|
|
11
|
-
* - Format: Apresenta o valor como string legível
|
|
12
|
-
*/
|
|
13
|
-
/**
|
|
14
|
-
* Função que converte um valor para o formato base da role
|
|
15
|
-
*/
|
|
16
|
-
type ToBaseFn<TValue = unknown, TBase = unknown> = (value: TValue) => TBase;
|
|
17
|
-
/**
|
|
18
|
-
* Função que converte do formato base para uma variante específica
|
|
19
|
-
*/
|
|
20
|
-
type FromBaseFn<TBase = unknown, TValue = unknown> = (base: TBase) => TValue;
|
|
21
|
-
/**
|
|
22
|
-
* Função que tenta normalizar um input desconhecido para o tipo esperado
|
|
23
|
-
* Retorna null se não conseguir fazer o cast
|
|
24
|
-
*/
|
|
25
|
-
type CastFn<TValue = unknown> = (input: unknown) => TValue | null;
|
|
26
|
-
/**
|
|
27
|
-
* Resultado de uma operação de cast
|
|
28
|
-
*/
|
|
29
|
-
type CastResult<T> = {
|
|
30
|
-
ok: true;
|
|
31
|
-
value: T;
|
|
32
|
-
} | {
|
|
33
|
-
ok: false;
|
|
34
|
-
error: string;
|
|
35
|
-
};
|
|
36
|
-
/**
|
|
37
|
-
* Regras de validação para uma variante
|
|
38
|
-
*/
|
|
39
|
-
type ValidationRule = {
|
|
40
|
-
/** Valor mínimo permitido (para números) */
|
|
41
|
-
min?: number;
|
|
42
|
-
/** Valor máximo permitido (para números) */
|
|
43
|
-
max?: number;
|
|
44
|
-
/** Deve ser inteiro (para números) */
|
|
45
|
-
integer?: boolean;
|
|
46
|
-
/** Pattern regex (para strings) */
|
|
47
|
-
pattern?: RegExp;
|
|
48
|
-
/** Função de validação customizada - retorna mensagem de erro ou null se válido */
|
|
49
|
-
custom?: (value: unknown) => string | null;
|
|
50
|
-
};
|
|
51
|
-
/**
|
|
52
|
-
* Resultado de uma validação
|
|
53
|
-
*/
|
|
54
|
-
type ValidationResult = {
|
|
55
|
-
valid: boolean;
|
|
56
|
-
errors: string[];
|
|
57
|
-
};
|
|
58
|
-
/**
|
|
59
|
-
* Opções base de formatação (compartilhadas por todas as roles)
|
|
60
|
-
*/
|
|
61
|
-
type BaseFormatOptions = {
|
|
62
|
-
/** Número de casas decimais */
|
|
63
|
-
decimals?: number;
|
|
64
|
-
/** Locale para formatação (ex: 'pt-BR', 'en-US') */
|
|
65
|
-
locale?: string;
|
|
66
|
-
/** Tipo de notação */
|
|
67
|
-
notation?: "standard" | "scientific" | "compact";
|
|
68
|
-
/** Usar nome completo ao invés de símbolo */
|
|
69
|
-
verbose?: boolean;
|
|
70
|
-
};
|
|
71
|
-
/**
|
|
72
|
-
* Opções de formatação genéricas
|
|
73
|
-
* @deprecated Use BaseFormatOptions ou tipos específicos (ColorFormatOptions, DateFormatOptions)
|
|
74
|
-
*/
|
|
75
|
-
type FormatOptions = BaseFormatOptions;
|
|
76
|
-
/**
|
|
77
|
-
* Função de formatação customizada
|
|
78
|
-
*/
|
|
79
|
-
type FormatFn<TValue = unknown> = (value: TValue, options?: BaseFormatOptions) => string;
|
|
80
|
-
/**
|
|
81
|
-
* Especificação de formatação para uma variante
|
|
82
|
-
*/
|
|
83
|
-
type FormatSpec<TValue = unknown> = {
|
|
84
|
-
/** Símbolo da unidade (ex: "m²", "ha", "°C") */
|
|
85
|
-
symbol: string;
|
|
86
|
-
/** Nome singular (ex: "meter", "hectare") */
|
|
87
|
-
singular?: string;
|
|
88
|
-
/** Nome plural (ex: "meters", "hectares") */
|
|
89
|
-
plural?: string;
|
|
90
|
-
/** Formatador customizado (override do padrão) */
|
|
91
|
-
formatter?: FormatFn<TValue>;
|
|
92
|
-
};
|
|
93
|
-
/**
|
|
94
|
-
* Definição de uma variante dentro de uma role
|
|
95
|
-
*
|
|
96
|
-
* Cada variante implementa os 4 pilares:
|
|
97
|
-
* - Convert: toBase/fromBase (obrigatório)
|
|
98
|
-
* - Cast: cast (opcional, usa default por type)
|
|
99
|
-
* - Validate: validate (opcional)
|
|
100
|
-
* - Format: format (opcional)
|
|
101
|
-
*/
|
|
102
|
-
type VariantSpec<TValue = unknown, TBase = unknown> = {
|
|
103
|
-
/** Tipo primitivo do valor nesta variante */
|
|
104
|
-
type: "string" | "number" | "boolean" | "object" | "array";
|
|
105
|
-
/** Converte o valor desta variante para o formato base */
|
|
106
|
-
toBase: ToBaseFn<TValue, TBase>;
|
|
107
|
-
/** Converte do formato base para esta variante */
|
|
108
|
-
fromBase: FromBaseFn<TBase, TValue>;
|
|
109
|
-
/** Tenta normalizar um input desconhecido para o tipo esperado */
|
|
110
|
-
cast?: CastFn<TValue>;
|
|
111
|
-
/** Regras de validação semântica */
|
|
112
|
-
validate?: ValidationRule;
|
|
113
|
-
/** Especificação de formatação */
|
|
114
|
-
format?: FormatSpec<TValue>;
|
|
115
|
-
};
|
|
116
|
-
/**
|
|
117
|
-
* Definição completa de uma Role
|
|
118
|
-
*
|
|
119
|
-
* Uma Role representa um conceito semântico (cor, área, data) que pode
|
|
120
|
-
* ser expresso em múltiplas variantes (hex, rgb, hsl para cor).
|
|
121
|
-
*/
|
|
122
|
-
type RoleSpec<TBase = unknown> = {
|
|
123
|
-
/** Nome da variante que serve como pivot para todas as conversões */
|
|
124
|
-
base: string;
|
|
125
|
-
/** Mapa de variantes disponíveis para esta role */
|
|
126
|
-
variants: Record<string, VariantSpec<unknown, TBase>>;
|
|
127
|
-
};
|
|
128
|
-
/**
|
|
129
|
-
* Identificador de variante parseado
|
|
130
|
-
*
|
|
131
|
-
* "color:rgb:object" => { role: "color", variant: "rgb:object" }
|
|
132
|
-
*/
|
|
133
|
-
type ParsedVariantId = {
|
|
134
|
-
role: string;
|
|
135
|
-
variant: string;
|
|
136
|
-
};
|
|
137
|
-
/**
|
|
138
|
-
* Resultado de uma conversão que pode falhar
|
|
139
|
-
*/
|
|
140
|
-
type ConversionResult<T> = {
|
|
141
|
-
ok: true;
|
|
142
|
-
value: T;
|
|
143
|
-
} | {
|
|
144
|
-
ok: false;
|
|
145
|
-
error: string;
|
|
146
|
-
};
|
|
147
|
-
/**
|
|
148
|
-
* Resultado de validação de reversibilidade
|
|
149
|
-
*/
|
|
150
|
-
type ReversibilityResult = {
|
|
151
|
-
reversible: boolean;
|
|
152
|
-
original: unknown;
|
|
153
|
-
converted: unknown;
|
|
154
|
-
reconverted: unknown;
|
|
155
|
-
};
|
|
156
|
-
/**
|
|
157
|
-
* Função que transforma um valor de uma role para outra
|
|
158
|
-
*/
|
|
159
|
-
type MorpherFn<TFrom = unknown, TTo = unknown> = (value: TFrom) => TTo;
|
|
160
|
-
/**
|
|
161
|
-
* Chave de um morpher: "fromRole:fromVariant->toRole:toVariant"
|
|
162
|
-
*/
|
|
163
|
-
type MorpherKey = `${string}->${string}`;
|
|
164
|
-
/**
|
|
165
|
-
* Definição de um morpher
|
|
166
|
-
*/
|
|
167
|
-
type MorpherSpec<TFrom = unknown, TTo = unknown> = {
|
|
168
|
-
from: string;
|
|
169
|
-
to: string;
|
|
170
|
-
transform: MorpherFn<TFrom, TTo>;
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* RoleMorphic
|
|
175
|
-
*
|
|
176
|
-
* Motor de conversão polimórfica de valores.
|
|
177
|
-
* Permite que um valor assuma múltiplas formas (variantes) mantendo sua identidade semântica.
|
|
178
|
-
*
|
|
179
|
-
* Arquitetura Hub-and-Spoke:
|
|
180
|
-
* - Cada role tem uma variante BASE que serve como pivot
|
|
181
|
-
* - Toda conversão passa pela base: origem -> base -> destino
|
|
182
|
-
* - Isso reduz a complexidade de N² para 2N conversões
|
|
183
|
-
*/
|
|
184
|
-
|
|
185
|
-
declare class RoleMorphic {
|
|
186
|
-
/** Registry de roles */
|
|
187
|
-
private roles;
|
|
188
|
-
/** Registry de morphers (transformações cross-role) */
|
|
189
|
-
private morphers;
|
|
190
|
-
/**
|
|
191
|
-
* Registra uma nova role
|
|
192
|
-
*/
|
|
193
|
-
register<TBase = unknown>(roleId: string, spec: RoleSpec<TBase>): this;
|
|
194
|
-
/**
|
|
195
|
-
* Remove uma role registrada
|
|
196
|
-
*/
|
|
197
|
-
unregister(roleId: string): boolean;
|
|
198
|
-
/**
|
|
199
|
-
* Verifica se uma role está registrada
|
|
200
|
-
*/
|
|
201
|
-
hasRole(roleId: string): boolean;
|
|
202
|
-
/**
|
|
203
|
-
* Obtém a spec de uma role
|
|
204
|
-
*/
|
|
205
|
-
getRole(roleId: string): RoleSpec | undefined;
|
|
206
|
-
/**
|
|
207
|
-
* Lista todas as roles registradas
|
|
208
|
-
*/
|
|
209
|
-
listRoles(): string[];
|
|
210
|
-
/**
|
|
211
|
-
* Parseia um identificador de variante
|
|
212
|
-
*
|
|
213
|
-
* "color:rgb:object" => { role: "color", variant: "rgb:object" }
|
|
214
|
-
* "area:m2" => { role: "area", variant: "m2" }
|
|
215
|
-
*/
|
|
216
|
-
parseVariantId(fullId: string): ParsedVariantId;
|
|
217
|
-
/**
|
|
218
|
-
* Verifica se uma variante existe
|
|
219
|
-
*/
|
|
220
|
-
hasVariant(fullId: string): boolean;
|
|
221
|
-
/**
|
|
222
|
-
* Obtém a spec de uma variante
|
|
223
|
-
*/
|
|
224
|
-
getVariant(fullId: string): VariantSpec | undefined;
|
|
225
|
-
/**
|
|
226
|
-
* Lista todas as variantes de uma role
|
|
227
|
-
*/
|
|
228
|
-
listVariants(roleId: string): string[];
|
|
229
|
-
/**
|
|
230
|
-
* Lista variantes para as quais uma variante pode converter
|
|
231
|
-
*/
|
|
232
|
-
getConvertibleVariants(fullId: string): string[];
|
|
233
|
-
/**
|
|
234
|
-
* Converte um valor de uma variante para outra (mesma role)
|
|
235
|
-
*
|
|
236
|
-
* @param from - Identificador da variante de origem (ex: "color:hex")
|
|
237
|
-
* @param to - Identificador da variante de destino (ex: "color:rgb:object")
|
|
238
|
-
* @param value - Valor a converter
|
|
239
|
-
* @returns Valor convertido
|
|
240
|
-
* @throws Error se a conversão não for possível
|
|
241
|
-
*/
|
|
242
|
-
convert<TFrom = unknown, TTo = unknown>(from: string, to: string, value: TFrom): TTo;
|
|
243
|
-
/**
|
|
244
|
-
* Tenta converter, retornando Result ao invés de throw
|
|
245
|
-
*/
|
|
246
|
-
tryConvert<TFrom = unknown, TTo = unknown>(from: string, to: string, value: TFrom): ConversionResult<TTo>;
|
|
247
|
-
/**
|
|
248
|
-
* Verifica se uma conversão é reversível (sem perda de dados)
|
|
249
|
-
*/
|
|
250
|
-
isReversible<T = unknown>(from: string, to: string, value: T): boolean;
|
|
251
|
-
/**
|
|
252
|
-
* Retorna detalhes sobre a reversibilidade de uma conversão
|
|
253
|
-
*/
|
|
254
|
-
checkReversibility<T = unknown>(from: string, to: string, value: T): ReversibilityResult;
|
|
255
|
-
/**
|
|
256
|
-
* Converte apenas se a conversão for reversível
|
|
257
|
-
*
|
|
258
|
-
* @throws Error se a conversão causar perda de dados
|
|
259
|
-
*/
|
|
260
|
-
convertSafe<TFrom = unknown, TTo = unknown>(from: string, to: string, value: TFrom): TTo;
|
|
261
|
-
/**
|
|
262
|
-
* Registra um morpher para transformação entre roles diferentes
|
|
263
|
-
*/
|
|
264
|
-
registerMorpher<TFrom = unknown, TTo = unknown>(spec: MorpherSpec<TFrom, TTo>): this;
|
|
265
|
-
/**
|
|
266
|
-
* Remove um morpher
|
|
267
|
-
*/
|
|
268
|
-
unregisterMorpher(from: string, to: string): boolean;
|
|
269
|
-
/**
|
|
270
|
-
* Verifica se existe um morpher para a transformação
|
|
271
|
-
*/
|
|
272
|
-
hasMorpher(from: string, to: string): boolean;
|
|
273
|
-
/**
|
|
274
|
-
* Lista morphers disponíveis a partir de uma variante
|
|
275
|
-
*/
|
|
276
|
-
getMorphersFrom(from: string): string[];
|
|
277
|
-
/**
|
|
278
|
-
* Transforma um valor de uma role para outra usando um morpher registrado
|
|
279
|
-
*/
|
|
280
|
-
morph<TFrom = unknown, TTo = unknown>(from: string, to: string, value: TFrom): TTo;
|
|
281
|
-
/**
|
|
282
|
-
* Tenta transformar, retornando Result ao invés de throw
|
|
283
|
-
*/
|
|
284
|
-
tryMorph<TFrom = unknown, TTo = unknown>(from: string, to: string, value: TFrom): ConversionResult<TTo>;
|
|
285
|
-
/**
|
|
286
|
-
* Converte ou transforma automaticamente
|
|
287
|
-
*
|
|
288
|
-
* - Se mesma role: usa convert()
|
|
289
|
-
* - Se roles diferentes: usa morph()
|
|
290
|
-
*/
|
|
291
|
-
auto<TFrom = unknown, TTo = unknown>(from: string, to: string, value: TFrom): TTo;
|
|
292
|
-
/**
|
|
293
|
-
* Converte um valor para a variante base da sua role
|
|
294
|
-
*/
|
|
295
|
-
toBase<T = unknown, TBase = unknown>(fullId: string, value: T): TBase;
|
|
296
|
-
/**
|
|
297
|
-
* Converte um valor da base para uma variante específica
|
|
298
|
-
*/
|
|
299
|
-
fromBase<TBase = unknown, T = unknown>(fullId: string, baseValue: TBase): T;
|
|
300
|
-
}
|
|
1
|
+
import { V as ValidationResult, B as BaseFormatOptions, R as RoleSpec, P as ParsedVariantId, a as VariantSpec, C as ConversionResult, b as ReversibilityResult, M as MorpherSpec, T as TemperatureUnit, D as DateTimestamp, c as DateFormatOptions, d as RGBA, e as ColorFormatOptions } from './types-mbeS1e-k.js';
|
|
2
|
+
export { m as CastFn, n as CastResult, s as ColorHex, v as ColorHslObject, w as ColorHslString, t as ColorRgbObject, u as ColorRgbString, r as ColorVariant, q as DateEpoch, p as DateIso, o as DateVariant, k as FormatFn, i as FormatOptions, j as FormatSpec, F as FromBaseFn, g as MorpherFn, h as MorpherKey, f as ToBaseFn, l as ValidationRule } from './types-mbeS1e-k.js';
|
|
3
|
+
import { CurrencyValidationConfig } from './validate.js';
|
|
4
|
+
export { AREA_VALIDATION_CONFIG, AngleValidationConfig, AreaValidationConfig, CURRENCY_VALIDATION_CONFIG, DIGITAL_VALIDATION_CONFIG, DigitalValidationConfig, ENERGY_VALIDATION_CONFIG, EnergyValidationConfig, FREQUENCY_VALIDATION_CONFIG, FrequencyValidationConfig, LENGTH_VALIDATION_CONFIG, LengthValidationConfig, MASS_VALIDATION_CONFIG, MassValidationConfig, POWER_VALIDATION_CONFIG, PRESSURE_VALIDATION_CONFIG, PowerValidationConfig, PressureValidationConfig, SpeedValidationConfig, TIME_VALIDATION_CONFIG, TemperatureValidationConfig, TimeValidationConfig, VOLUME_VALIDATION_CONFIG, VolumeValidationConfig, isValidAngle, isValidArea, isValidColorVariant, isValidCurrency, isValidDate, isValidDigital, isValidEnergy, isValidFrequency, isValidLength, isValidMass, isValidPower, isValidPressure, isValidSpeed, isValidTemperature, isValidTime, isValidVolume, validateAngle, validateArea, validateColor, validateCurrency, validateDate, validateDigital, validateEnergy, validateFrequency, validateLength, validateMass, validatePower, validatePressure, validateSpeed, validateTemperature, validateTime, validateVolume } from './validate.js';
|
|
5
|
+
export { ANGLE_BASE, AREA_BASE, DIGITAL_BASE, ENERGY_BASE, FREQUENCY_BASE, LENGTH_BASE, MASS_BASE, POWER_BASE, PRESSURE_BASE, SPEED_BASE, TEMPERATURE_BASE, TIME_BASE, VOLUME_BASE, convertAngle, convertArea, convertColor, convertDate, convertDigital, convertEnergy, convertFrequency, convertLength, convertMass, convertPower, convertPressure, convertSpeed, convertTemperature, convertTime, convertVolume, fromBaseAngle, fromBaseArea, fromBaseDigital, fromBaseEnergy, fromBaseFrequency, fromBaseLength, fromBaseMass, fromBasePower, fromBasePressure, fromBaseSpeed, fromBaseTemperature, fromBaseTime, fromBaseVolume, getAngleVariants, getAreaVariants, getDigitalVariants, getEnergyVariants, getFrequencyVariants, getLengthVariants, getMassVariants, getPowerVariants, getPressureVariants, getSpeedVariants, getTemperatureVariants, getTimeVariants, getVolumeVariants, hasAngleVariant, hasAreaVariant, hasDigitalVariant, hasEnergyVariant, hasFrequencyVariant, hasLengthVariant, hasMassVariant, hasPowerVariant, hasPressureVariant, hasSpeedVariant, hasTemperatureVariant, hasTimeVariant, hasVolumeVariant, toBaseAngle, toBaseArea, toBaseDigital, toBaseEnergy, toBaseFrequency, toBaseLength, toBaseMass, toBasePower, toBasePressure, toBaseSpeed, toBaseTemperature, toBaseTime, toBaseVolume, tryConvertAngle, tryConvertArea, tryConvertColor, tryConvertDate, tryConvertDigital, tryConvertEnergy, tryConvertFrequency, tryConvertLength, tryConvertMass, tryConvertPower, tryConvertPressure, tryConvertSpeed, tryConvertTemperature, tryConvertTime, tryConvertVolume } from './convert.js';
|
|
6
|
+
export { castAngle, castArea, castColor, castCurrency, castDate, castDigital, castEnergy, castFrequency, castLength, castMass, castPower, castPressure, castSpeed, castTemperature, castTime, castVolume, tryCastAngle, tryCastArea, tryCastColor, tryCastCurrency, tryCastDate, tryCastDigital, tryCastEnergy, tryCastFrequency, tryCastLength, tryCastMass, tryCastPower, tryCastPressure, tryCastSpeed, tryCastTemperature, tryCastTime, tryCastVolume } from './cast.js';
|
|
7
|
+
import { C as CurrencyFormatOptions, a as CurrencyCode } from './format-Be15LzfS.js';
|
|
8
|
+
export { r as CurrencyConfig, l as formatAngle, f as formatArea, o as formatColor, q as formatCurrency, p as formatDate, n as formatDigital, h as formatEnergy, k as formatFrequency, b as formatLength, c as formatMass, i as formatPower, j as formatPressure, g as formatSpeed, d as formatTemperature, m as formatTime, e as formatVolume } from './format-Be15LzfS.js';
|
|
9
|
+
import { A as AreaUnit, L as LengthUnit, M as MassUnit, a as AngleUnit, E as EnergyUnit, P as PowerUnit, S as SpeedUnit, V as VolumeUnit, T as TimeUnit, D as DigitalUnit, F as FrequencyUnit, b as PressureUnit } from './constants-BZdBwuvJ.js';
|
|
301
10
|
|
|
302
11
|
/**
|
|
303
12
|
* IRole - Interface principal que todas as Roles devem implementar
|
|
@@ -686,17 +395,133 @@ declare abstract class ComplexRole<TBase = unknown> implements IRole<TBase> {
|
|
|
686
395
|
}
|
|
687
396
|
|
|
688
397
|
/**
|
|
689
|
-
*
|
|
398
|
+
* RoleMorphic
|
|
690
399
|
*
|
|
691
|
-
*
|
|
400
|
+
* Motor de conversão polimórfica de valores.
|
|
401
|
+
* Permite que um valor assuma múltiplas formas (variantes) mantendo sua identidade semântica.
|
|
692
402
|
*
|
|
693
|
-
*
|
|
694
|
-
* -
|
|
695
|
-
* -
|
|
696
|
-
* -
|
|
403
|
+
* Arquitetura Hub-and-Spoke:
|
|
404
|
+
* - Cada role tem uma variante BASE que serve como pivot
|
|
405
|
+
* - Toda conversão passa pela base: origem -> base -> destino
|
|
406
|
+
* - Isso reduz a complexidade de N² para 2N conversões
|
|
697
407
|
*/
|
|
698
408
|
|
|
699
|
-
|
|
409
|
+
declare class RoleMorphic {
|
|
410
|
+
/** Registry de roles */
|
|
411
|
+
private roles;
|
|
412
|
+
/** Registry de morphers (transformações cross-role) */
|
|
413
|
+
private morphers;
|
|
414
|
+
/**
|
|
415
|
+
* Registra uma nova role
|
|
416
|
+
*/
|
|
417
|
+
register<TBase = unknown>(roleId: string, spec: RoleSpec<TBase>): this;
|
|
418
|
+
/**
|
|
419
|
+
* Remove uma role registrada
|
|
420
|
+
*/
|
|
421
|
+
unregister(roleId: string): boolean;
|
|
422
|
+
/**
|
|
423
|
+
* Verifica se uma role está registrada
|
|
424
|
+
*/
|
|
425
|
+
hasRole(roleId: string): boolean;
|
|
426
|
+
/**
|
|
427
|
+
* Obtém a spec de uma role
|
|
428
|
+
*/
|
|
429
|
+
getRole(roleId: string): RoleSpec | undefined;
|
|
430
|
+
/**
|
|
431
|
+
* Lista todas as roles registradas
|
|
432
|
+
*/
|
|
433
|
+
listRoles(): string[];
|
|
434
|
+
/**
|
|
435
|
+
* Parseia um identificador de variante
|
|
436
|
+
*
|
|
437
|
+
* "color:rgb:object" => { role: "color", variant: "rgb:object" }
|
|
438
|
+
* "area:m2" => { role: "area", variant: "m2" }
|
|
439
|
+
*/
|
|
440
|
+
parseVariantId(fullId: string): ParsedVariantId;
|
|
441
|
+
/**
|
|
442
|
+
* Verifica se uma variante existe
|
|
443
|
+
*/
|
|
444
|
+
hasVariant(fullId: string): boolean;
|
|
445
|
+
/**
|
|
446
|
+
* Obtém a spec de uma variante
|
|
447
|
+
*/
|
|
448
|
+
getVariant(fullId: string): VariantSpec | undefined;
|
|
449
|
+
/**
|
|
450
|
+
* Lista todas as variantes de uma role
|
|
451
|
+
*/
|
|
452
|
+
listVariants(roleId: string): string[];
|
|
453
|
+
/**
|
|
454
|
+
* Lista variantes para as quais uma variante pode converter
|
|
455
|
+
*/
|
|
456
|
+
getConvertibleVariants(fullId: string): string[];
|
|
457
|
+
/**
|
|
458
|
+
* Converte um valor de uma variante para outra (mesma role)
|
|
459
|
+
*
|
|
460
|
+
* @param from - Identificador da variante de origem (ex: "color:hex")
|
|
461
|
+
* @param to - Identificador da variante de destino (ex: "color:rgb:object")
|
|
462
|
+
* @param value - Valor a converter
|
|
463
|
+
* @returns Valor convertido
|
|
464
|
+
* @throws Error se a conversão não for possível
|
|
465
|
+
*/
|
|
466
|
+
convert<TFrom = unknown, TTo = unknown>(from: string, to: string, value: TFrom): TTo;
|
|
467
|
+
/**
|
|
468
|
+
* Tenta converter, retornando Result ao invés de throw
|
|
469
|
+
*/
|
|
470
|
+
tryConvert<TFrom = unknown, TTo = unknown>(from: string, to: string, value: TFrom): ConversionResult<TTo>;
|
|
471
|
+
/**
|
|
472
|
+
* Verifica se uma conversão é reversível (sem perda de dados)
|
|
473
|
+
*/
|
|
474
|
+
isReversible<T = unknown>(from: string, to: string, value: T): boolean;
|
|
475
|
+
/**
|
|
476
|
+
* Retorna detalhes sobre a reversibilidade de uma conversão
|
|
477
|
+
*/
|
|
478
|
+
checkReversibility<T = unknown>(from: string, to: string, value: T): ReversibilityResult;
|
|
479
|
+
/**
|
|
480
|
+
* Converte apenas se a conversão for reversível
|
|
481
|
+
*
|
|
482
|
+
* @throws Error se a conversão causar perda de dados
|
|
483
|
+
*/
|
|
484
|
+
convertSafe<TFrom = unknown, TTo = unknown>(from: string, to: string, value: TFrom): TTo;
|
|
485
|
+
/**
|
|
486
|
+
* Registra um morpher para transformação entre roles diferentes
|
|
487
|
+
*/
|
|
488
|
+
registerMorpher<TFrom = unknown, TTo = unknown>(spec: MorpherSpec<TFrom, TTo>): this;
|
|
489
|
+
/**
|
|
490
|
+
* Remove um morpher
|
|
491
|
+
*/
|
|
492
|
+
unregisterMorpher(from: string, to: string): boolean;
|
|
493
|
+
/**
|
|
494
|
+
* Verifica se existe um morpher para a transformação
|
|
495
|
+
*/
|
|
496
|
+
hasMorpher(from: string, to: string): boolean;
|
|
497
|
+
/**
|
|
498
|
+
* Lista morphers disponíveis a partir de uma variante
|
|
499
|
+
*/
|
|
500
|
+
getMorphersFrom(from: string): string[];
|
|
501
|
+
/**
|
|
502
|
+
* Transforma um valor de uma role para outra usando um morpher registrado
|
|
503
|
+
*/
|
|
504
|
+
morph<TFrom = unknown, TTo = unknown>(from: string, to: string, value: TFrom): TTo;
|
|
505
|
+
/**
|
|
506
|
+
* Tenta transformar, retornando Result ao invés de throw
|
|
507
|
+
*/
|
|
508
|
+
tryMorph<TFrom = unknown, TTo = unknown>(from: string, to: string, value: TFrom): ConversionResult<TTo>;
|
|
509
|
+
/**
|
|
510
|
+
* Converte ou transforma automaticamente
|
|
511
|
+
*
|
|
512
|
+
* - Se mesma role: usa convert()
|
|
513
|
+
* - Se roles diferentes: usa morph()
|
|
514
|
+
*/
|
|
515
|
+
auto<TFrom = unknown, TTo = unknown>(from: string, to: string, value: TFrom): TTo;
|
|
516
|
+
/**
|
|
517
|
+
* Converte um valor para a variante base da sua role
|
|
518
|
+
*/
|
|
519
|
+
toBase<T = unknown, TBase = unknown>(fullId: string, value: T): TBase;
|
|
520
|
+
/**
|
|
521
|
+
* Converte um valor da base para uma variante específica
|
|
522
|
+
*/
|
|
523
|
+
fromBase<TBase = unknown, T = unknown>(fullId: string, baseValue: TBase): T;
|
|
524
|
+
}
|
|
700
525
|
|
|
701
526
|
declare class AreaRole extends SimpleRole {
|
|
702
527
|
readonly name = "area";
|
|
@@ -708,45 +533,16 @@ declare class AreaRole extends SimpleRole {
|
|
|
708
533
|
/** Instância singleton da AreaRole */
|
|
709
534
|
declare const areaRole: AreaRole;
|
|
710
535
|
|
|
711
|
-
/**
|
|
712
|
-
* Length Role - Constants
|
|
713
|
-
*
|
|
714
|
-
* Fatores de conversão, símbolos e aliases para unidades de comprimento.
|
|
715
|
-
*
|
|
716
|
-
* Fontes:
|
|
717
|
-
* - NIST SP 811 (2008)
|
|
718
|
-
* - International Yard and Pound Agreement (1959)
|
|
719
|
-
* - SI Brochure, 9th Edition (2019)
|
|
720
|
-
*/
|
|
721
|
-
|
|
722
|
-
type LengthUnit = "kilometer" | "hectometer" | "decameter" | "meter" | "decimeter" | "centimeter" | "millimeter" | "micrometer" | "nanometer" | "inch" | "foot" | "yard" | "mile" | "nautical_mile" | "fathom" | "furlong" | "league";
|
|
723
|
-
|
|
724
536
|
declare class LengthRole extends SimpleRole {
|
|
725
537
|
readonly name = "length";
|
|
726
538
|
readonly base = "meter";
|
|
727
539
|
readonly units: Record<LengthUnit, SimpleUnitConfig>;
|
|
728
540
|
readonly aliases: UnitAliases;
|
|
541
|
+
readonly validation: SimpleValidationConfig;
|
|
729
542
|
}
|
|
730
543
|
/** Instância singleton da LengthRole */
|
|
731
544
|
declare const lengthRole: LengthRole;
|
|
732
545
|
|
|
733
|
-
/**
|
|
734
|
-
* Mass Role - Constants
|
|
735
|
-
*
|
|
736
|
-
* Fatores de conversão, símbolos e aliases para unidades de massa.
|
|
737
|
-
*
|
|
738
|
-
* Fontes:
|
|
739
|
-
* - NIST SP 811 (2008)
|
|
740
|
-
* - International Yard and Pound Agreement (1959)
|
|
741
|
-
* - SI Brochure, 9th Edition (2019)
|
|
742
|
-
*
|
|
743
|
-
* Nota: Massa ≠ Peso
|
|
744
|
-
* - Massa: quantidade de matéria (invariante)
|
|
745
|
-
* - Peso: força gravitacional (varia com localização)
|
|
746
|
-
*/
|
|
747
|
-
|
|
748
|
-
type MassUnit = "metric_ton" | "kilogram" | "hectogram" | "decagram" | "gram" | "decigram" | "centigram" | "milligram" | "microgram" | "long_ton" | "short_ton" | "stone" | "pound" | "ounce" | "dram" | "grain" | "troy_pound" | "troy_ounce" | "pennyweight";
|
|
749
|
-
|
|
750
546
|
declare class MassRole extends SimpleRole {
|
|
751
547
|
readonly name = "mass";
|
|
752
548
|
readonly base = "kilogram";
|
|
@@ -757,21 +553,6 @@ declare class MassRole extends SimpleRole {
|
|
|
757
553
|
/** Instância singleton da MassRole */
|
|
758
554
|
declare const massRole: MassRole;
|
|
759
555
|
|
|
760
|
-
/**
|
|
761
|
-
* Temperature Role - Constants
|
|
762
|
-
*
|
|
763
|
-
* Fórmulas de conversão, símbolos e aliases para unidades de temperatura.
|
|
764
|
-
*
|
|
765
|
-
* IMPORTANTE: Temperatura usa FÓRMULAS, não fatores multiplicativos.
|
|
766
|
-
* Isso porque as escalas têm offsets diferentes (0°C ≠ 0°F ≠ 0K).
|
|
767
|
-
*
|
|
768
|
-
* Fontes:
|
|
769
|
-
* - NIST SP 811 (2008)
|
|
770
|
-
* - SI Brochure, 9th Edition (2019)
|
|
771
|
-
*/
|
|
772
|
-
|
|
773
|
-
type TemperatureUnit = "celsius" | "fahrenheit" | "kelvin" | "rankine";
|
|
774
|
-
|
|
775
556
|
declare class TemperatureRole extends SimpleRole {
|
|
776
557
|
readonly name = "temperature";
|
|
777
558
|
readonly base = "celsius";
|
|
@@ -793,21 +574,6 @@ declare class TemperatureRole extends SimpleRole {
|
|
|
793
574
|
/** Instância singleton da TemperatureRole */
|
|
794
575
|
declare const temperatureRole: TemperatureRole;
|
|
795
576
|
|
|
796
|
-
/**
|
|
797
|
-
* Angle Role - Constants
|
|
798
|
-
*
|
|
799
|
-
* Fatores de conversão, símbolos e aliases para unidades de ângulo.
|
|
800
|
-
*
|
|
801
|
-
* Base: degree (grau) - mais comum em aplicações práticas.
|
|
802
|
-
* Nota: Embora radiano seja a unidade SI, grau é mais intuitivo para a maioria dos casos.
|
|
803
|
-
*
|
|
804
|
-
* Fontes:
|
|
805
|
-
* - SI Brochure, 9th Edition (2019)
|
|
806
|
-
* - NIST SP 811 (2008)
|
|
807
|
-
*/
|
|
808
|
-
|
|
809
|
-
type AngleUnit = "turn" | "degree" | "arcminute" | "arcsecond" | "milliarcsecond" | "radian" | "milliradian" | "gradian";
|
|
810
|
-
|
|
811
577
|
declare class AngleRole extends SimpleRole {
|
|
812
578
|
readonly name = "angle";
|
|
813
579
|
readonly base = "degree";
|
|
@@ -817,19 +583,6 @@ declare class AngleRole extends SimpleRole {
|
|
|
817
583
|
/** Instância singleton da AngleRole */
|
|
818
584
|
declare const angleRole: AngleRole;
|
|
819
585
|
|
|
820
|
-
/**
|
|
821
|
-
* Energy Role - Constants
|
|
822
|
-
*
|
|
823
|
-
* Fatores de conversão, símbolos e aliases para unidades de energia.
|
|
824
|
-
*
|
|
825
|
-
* Fontes:
|
|
826
|
-
* - NIST SP 811 (2008)
|
|
827
|
-
* - SI Brochure, 9th Edition (2019)
|
|
828
|
-
* - CODATA 2018 (electronvolt)
|
|
829
|
-
*/
|
|
830
|
-
|
|
831
|
-
type EnergyUnit = "gigajoule" | "megajoule" | "kilojoule" | "joule" | "millijoule" | "calorie" | "kilocalorie" | "watt_hour" | "kilowatt_hour" | "megawatt_hour" | "gigawatt_hour" | "btu" | "therm" | "electronvolt" | "kiloelectronvolt" | "megaelectronvolt" | "erg" | "foot_pound";
|
|
832
|
-
|
|
833
586
|
declare class EnergyRole extends SimpleRole {
|
|
834
587
|
readonly name = "energy";
|
|
835
588
|
readonly base = "joule";
|
|
@@ -840,18 +593,6 @@ declare class EnergyRole extends SimpleRole {
|
|
|
840
593
|
/** Instância singleton da EnergyRole */
|
|
841
594
|
declare const energyRole: EnergyRole;
|
|
842
595
|
|
|
843
|
-
/**
|
|
844
|
-
* Power Role - Constants
|
|
845
|
-
*
|
|
846
|
-
* Fatores de conversão, símbolos e aliases para unidades de potência.
|
|
847
|
-
*
|
|
848
|
-
* Fontes:
|
|
849
|
-
* - NIST SP 811 (2008)
|
|
850
|
-
* - SI Brochure, 9th Edition (2019)
|
|
851
|
-
*/
|
|
852
|
-
|
|
853
|
-
type PowerUnit = "gigawatt" | "megawatt" | "kilowatt" | "watt" | "milliwatt" | "microwatt" | "horsepower_mechanical" | "horsepower_metric" | "horsepower_electric" | "horsepower_boiler" | "btu_per_hour" | "btu_per_second" | "ton_of_refrigeration" | "foot_pound_per_second" | "calorie_per_second" | "kilocalorie_per_hour";
|
|
854
|
-
|
|
855
596
|
declare class PowerRole extends SimpleRole {
|
|
856
597
|
readonly name = "power";
|
|
857
598
|
readonly base = "watt";
|
|
@@ -862,19 +603,6 @@ declare class PowerRole extends SimpleRole {
|
|
|
862
603
|
/** Instância singleton da PowerRole */
|
|
863
604
|
declare const powerRole: PowerRole;
|
|
864
605
|
|
|
865
|
-
/**
|
|
866
|
-
* Speed Role - Constants
|
|
867
|
-
*
|
|
868
|
-
* Fatores de conversão, símbolos e aliases para unidades de velocidade.
|
|
869
|
-
*
|
|
870
|
-
* Fontes:
|
|
871
|
-
* - NIST SP 811 (2008)
|
|
872
|
-
* - SI Brochure, 9th Edition (2019)
|
|
873
|
-
* - International Yard and Pound Agreement (1959)
|
|
874
|
-
*/
|
|
875
|
-
|
|
876
|
-
type SpeedUnit = "meter_per_second" | "kilometer_per_hour" | "mile_per_hour" | "foot_per_second" | "knot" | "mach" | "speed_of_light";
|
|
877
|
-
|
|
878
606
|
declare class SpeedRole extends SimpleRole {
|
|
879
607
|
readonly name = "speed";
|
|
880
608
|
readonly base = "meter_per_second";
|
|
@@ -884,49 +612,6 @@ declare class SpeedRole extends SimpleRole {
|
|
|
884
612
|
/** Instância singleton da SpeedRole */
|
|
885
613
|
declare const speedRole: SpeedRole;
|
|
886
614
|
|
|
887
|
-
/**
|
|
888
|
-
* Date Role - Types
|
|
889
|
-
*
|
|
890
|
-
* Tipos para representação de datas nas diferentes variantes.
|
|
891
|
-
*/
|
|
892
|
-
/**
|
|
893
|
-
* Tipo base para Date: timestamp em milissegundos (como JavaScript Date.getTime())
|
|
894
|
-
*
|
|
895
|
-
* @example
|
|
896
|
-
* const ts: DateTimestamp = 1733425800000; // 2024-12-05T19:30:00.000Z
|
|
897
|
-
*/
|
|
898
|
-
type DateTimestamp = number;
|
|
899
|
-
/**
|
|
900
|
-
* Variante ISO 8601
|
|
901
|
-
*
|
|
902
|
-
* @example
|
|
903
|
-
* "2024-12-05T19:30:00.000Z"
|
|
904
|
-
* "2024-12-05T19:30:00.000-03:00"
|
|
905
|
-
* "2024-12-05"
|
|
906
|
-
*/
|
|
907
|
-
type DateIso = string;
|
|
908
|
-
/**
|
|
909
|
-
* Variante Epoch (segundos desde 1970-01-01T00:00:00Z)
|
|
910
|
-
*
|
|
911
|
-
* @example
|
|
912
|
-
* 1733425800 // 2024-12-05T19:30:00Z
|
|
913
|
-
*/
|
|
914
|
-
type DateEpoch = number;
|
|
915
|
-
type DateVariant = "iso" | "timestamp" | "epoch";
|
|
916
|
-
|
|
917
|
-
interface DateFormatOptions extends BaseFormatOptions {
|
|
918
|
-
/** Estilo de data: "full", "long", "medium", "short" */
|
|
919
|
-
dateStyle?: "full" | "long" | "medium" | "short";
|
|
920
|
-
/** Estilo de hora: "full", "long", "medium", "short" */
|
|
921
|
-
timeStyle?: "full" | "long" | "medium" | "short";
|
|
922
|
-
/** Timezone (ex: "America/Sao_Paulo", "UTC") */
|
|
923
|
-
timeZone?: string;
|
|
924
|
-
/** Se true, mostra apenas data (sem hora) */
|
|
925
|
-
dateOnly?: boolean;
|
|
926
|
-
/** Se true, mostra apenas hora (sem data) */
|
|
927
|
-
timeOnly?: boolean;
|
|
928
|
-
}
|
|
929
|
-
|
|
930
615
|
/**
|
|
931
616
|
* DateRole - Role para conversão e manipulação de datas
|
|
932
617
|
*
|
|
@@ -955,24 +640,6 @@ declare class DateRole extends ComplexRole<DateTimestamp> {
|
|
|
955
640
|
/** Instância singleton da DateRole */
|
|
956
641
|
declare const dateRole: DateRole;
|
|
957
642
|
|
|
958
|
-
/**
|
|
959
|
-
* Volume Role - Constants
|
|
960
|
-
*
|
|
961
|
-
* Fatores de conversão, símbolos e aliases para unidades de volume.
|
|
962
|
-
*
|
|
963
|
-
* Fontes:
|
|
964
|
-
* - NIST SP 811 (2008)
|
|
965
|
-
* - NIST Handbook 44 (2024)
|
|
966
|
-
* - SI Brochure, 9th Edition (2019)
|
|
967
|
-
*
|
|
968
|
-
* Notas:
|
|
969
|
-
* - Base: liter (L) - unidade aceita para uso com o SI
|
|
970
|
-
* - 1 L = 1 dm³ = 0.001 m³
|
|
971
|
-
* - Galão US vs UK: ~20% diferença (UK é maior)
|
|
972
|
-
*/
|
|
973
|
-
|
|
974
|
-
type VolumeUnit = "cubic_meter" | "cubic_decimeter" | "cubic_centimeter" | "cubic_millimeter" | "hectoliter" | "decaliter" | "liter" | "deciliter" | "centiliter" | "milliliter" | "microliter" | "gallon_us" | "quart_us" | "pint_us" | "cup_us" | "fluid_ounce_us" | "tablespoon_us" | "teaspoon_us" | "gallon_uk" | "quart_uk" | "pint_uk" | "fluid_ounce_uk" | "barrel_oil" | "cubic_inch" | "cubic_foot" | "cubic_yard";
|
|
975
|
-
|
|
976
643
|
declare class VolumeRole extends SimpleRole {
|
|
977
644
|
readonly name = "volume";
|
|
978
645
|
readonly base = "liter";
|
|
@@ -983,18 +650,6 @@ declare class VolumeRole extends SimpleRole {
|
|
|
983
650
|
/** Instância singleton da VolumeRole */
|
|
984
651
|
declare const volumeRole: VolumeRole;
|
|
985
652
|
|
|
986
|
-
/**
|
|
987
|
-
* Time Role - Constants
|
|
988
|
-
*
|
|
989
|
-
* Fatores de conversão, símbolos e aliases para unidades de tempo/duração.
|
|
990
|
-
*
|
|
991
|
-
* Fontes:
|
|
992
|
-
* - SI Brochure, 9th Edition (2019)
|
|
993
|
-
* - Gregorian calendar (365.2425 dias/ano)
|
|
994
|
-
*/
|
|
995
|
-
|
|
996
|
-
type TimeUnit = "nanosecond" | "microsecond" | "millisecond" | "second" | "minute" | "hour" | "day" | "week" | "month" | "year" | "decade" | "century" | "millennium";
|
|
997
|
-
|
|
998
653
|
declare class TimeRole extends SimpleRole {
|
|
999
654
|
readonly name = "time";
|
|
1000
655
|
readonly base = "second";
|
|
@@ -1005,22 +660,6 @@ declare class TimeRole extends SimpleRole {
|
|
|
1005
660
|
/** Instância singleton da TimeRole */
|
|
1006
661
|
declare const timeRole: TimeRole;
|
|
1007
662
|
|
|
1008
|
-
/**
|
|
1009
|
-
* Digital Storage Role - Constants
|
|
1010
|
-
*
|
|
1011
|
-
* Fatores de conversão, símbolos e aliases para unidades de armazenamento digital.
|
|
1012
|
-
*
|
|
1013
|
-
* Fontes:
|
|
1014
|
-
* - IEC 60027-2 (prefixos binários)
|
|
1015
|
-
* - SI Brochure, 9th Edition (2019)
|
|
1016
|
-
*
|
|
1017
|
-
* IMPORTANTE: Esta biblioteca suporta AMBOS os sistemas:
|
|
1018
|
-
* - SI (decimal): kB, MB, GB, TB (base 1000)
|
|
1019
|
-
* - IEC (binário): KiB, MiB, GiB, TiB (base 1024)
|
|
1020
|
-
*/
|
|
1021
|
-
|
|
1022
|
-
type DigitalUnit = "bit" | "byte" | "kibibyte" | "mebibyte" | "gibibyte" | "tebibyte" | "pebibyte" | "exbibyte" | "kilobyte" | "megabyte" | "gigabyte" | "terabyte" | "petabyte" | "exabyte";
|
|
1023
|
-
|
|
1024
663
|
declare class DigitalRole extends SimpleRole {
|
|
1025
664
|
readonly name = "digital";
|
|
1026
665
|
readonly base = "byte";
|
|
@@ -1031,18 +670,6 @@ declare class DigitalRole extends SimpleRole {
|
|
|
1031
670
|
/** Instância singleton da DigitalRole */
|
|
1032
671
|
declare const digitalRole: DigitalRole;
|
|
1033
672
|
|
|
1034
|
-
/**
|
|
1035
|
-
* Frequency Role - Constants
|
|
1036
|
-
*
|
|
1037
|
-
* Fatores de conversão, símbolos e aliases para unidades de frequência.
|
|
1038
|
-
*
|
|
1039
|
-
* Fontes:
|
|
1040
|
-
* - SI Brochure, 9th Edition (2019)
|
|
1041
|
-
* - NIST SP 811
|
|
1042
|
-
*/
|
|
1043
|
-
|
|
1044
|
-
type FrequencyUnit = "terahertz" | "gigahertz" | "megahertz" | "kilohertz" | "hertz" | "millihertz" | "microhertz" | "rpm" | "bpm" | "radians_per_second" | "cycles_per_minute";
|
|
1045
|
-
|
|
1046
673
|
declare class FrequencyRole extends SimpleRole {
|
|
1047
674
|
readonly name = "frequency";
|
|
1048
675
|
readonly base = "hertz";
|
|
@@ -1053,19 +680,6 @@ declare class FrequencyRole extends SimpleRole {
|
|
|
1053
680
|
/** Instância singleton da FrequencyRole */
|
|
1054
681
|
declare const frequencyRole: FrequencyRole;
|
|
1055
682
|
|
|
1056
|
-
/**
|
|
1057
|
-
* Pressure Role - Constants
|
|
1058
|
-
*
|
|
1059
|
-
* Fatores de conversão, símbolos e aliases para unidades de pressão.
|
|
1060
|
-
*
|
|
1061
|
-
* Fontes:
|
|
1062
|
-
* - SI Brochure, 9th Edition (2019)
|
|
1063
|
-
* - NIST SP 811
|
|
1064
|
-
* - 10th CGPM (1954) - definição da atmosfera padrão
|
|
1065
|
-
*/
|
|
1066
|
-
|
|
1067
|
-
type PressureUnit = "megapascal" | "kilopascal" | "hectopascal" | "pascal" | "bar" | "millibar" | "atmosphere" | "torr" | "mmhg" | "inhg" | "psi" | "ksi" | "cmh2o" | "inh2o";
|
|
1068
|
-
|
|
1069
683
|
declare class PressureRole extends SimpleRole {
|
|
1070
684
|
readonly name = "pressure";
|
|
1071
685
|
readonly base = "pascal";
|
|
@@ -1076,87 +690,6 @@ declare class PressureRole extends SimpleRole {
|
|
|
1076
690
|
/** Instância singleton da PressureRole */
|
|
1077
691
|
declare const pressureRole: PressureRole;
|
|
1078
692
|
|
|
1079
|
-
/**
|
|
1080
|
-
* Color Role - Types
|
|
1081
|
-
*
|
|
1082
|
-
* Tipos para representação de cores nas diferentes variantes.
|
|
1083
|
-
*/
|
|
1084
|
-
/**
|
|
1085
|
-
* Tipo base para Color: objeto RGBA com valores 0-255 e alpha 0-1
|
|
1086
|
-
*
|
|
1087
|
-
* @example
|
|
1088
|
-
* const red: RGBA = { r: 255, g: 0, b: 0, a: 1 };
|
|
1089
|
-
* const semiTransparent: RGBA = { r: 0, g: 0, b: 255, a: 0.5 };
|
|
1090
|
-
*/
|
|
1091
|
-
interface RGBA {
|
|
1092
|
-
r: number;
|
|
1093
|
-
g: number;
|
|
1094
|
-
b: number;
|
|
1095
|
-
a: number;
|
|
1096
|
-
}
|
|
1097
|
-
/**
|
|
1098
|
-
* Variante Hex
|
|
1099
|
-
*
|
|
1100
|
-
* @example
|
|
1101
|
-
* "#ff0000" // RGB (6 chars)
|
|
1102
|
-
* "#ff0000ff" // RGBA (8 chars)
|
|
1103
|
-
* "#f00" // RGB shorthand (3 chars)
|
|
1104
|
-
* "#f00f" // RGBA shorthand (4 chars)
|
|
1105
|
-
*/
|
|
1106
|
-
type ColorHex = string;
|
|
1107
|
-
/**
|
|
1108
|
-
* Variante RGB Object
|
|
1109
|
-
*
|
|
1110
|
-
* @example
|
|
1111
|
-
* { r: 255, g: 0, b: 0 }
|
|
1112
|
-
* { r: 255, g: 0, b: 0, a: 0.5 }
|
|
1113
|
-
*/
|
|
1114
|
-
interface ColorRgbObject {
|
|
1115
|
-
r: number;
|
|
1116
|
-
g: number;
|
|
1117
|
-
b: number;
|
|
1118
|
-
a?: number;
|
|
1119
|
-
}
|
|
1120
|
-
/**
|
|
1121
|
-
* Variante RGB String
|
|
1122
|
-
*
|
|
1123
|
-
* @example
|
|
1124
|
-
* "rgb(255, 0, 0)"
|
|
1125
|
-
* "rgba(255, 0, 0, 0.5)"
|
|
1126
|
-
*/
|
|
1127
|
-
type ColorRgbString = string;
|
|
1128
|
-
/**
|
|
1129
|
-
* Variante HSL Object
|
|
1130
|
-
*
|
|
1131
|
-
* @example
|
|
1132
|
-
* { h: 0, s: 100, l: 50 } // Red
|
|
1133
|
-
* { h: 0, s: 100, l: 50, a: 0.5 } // Semi-transparent red
|
|
1134
|
-
*/
|
|
1135
|
-
interface ColorHslObject {
|
|
1136
|
-
h: number;
|
|
1137
|
-
s: number;
|
|
1138
|
-
l: number;
|
|
1139
|
-
a?: number;
|
|
1140
|
-
}
|
|
1141
|
-
/**
|
|
1142
|
-
* Variante HSL String
|
|
1143
|
-
*
|
|
1144
|
-
* @example
|
|
1145
|
-
* "hsl(0, 100%, 50%)"
|
|
1146
|
-
* "hsla(0, 100%, 50%, 0.5)"
|
|
1147
|
-
*/
|
|
1148
|
-
type ColorHslString = string;
|
|
1149
|
-
type ColorVariant = "hex" | "rgb_object" | "rgb_string" | "hsl_object" | "hsl_string";
|
|
1150
|
-
|
|
1151
|
-
interface ColorFormatOptions extends BaseFormatOptions {
|
|
1152
|
-
/** Se true, usa letras maiúsculas para hex */
|
|
1153
|
-
uppercase?: boolean;
|
|
1154
|
-
/** Se true, inclui alpha mesmo quando é 1 */
|
|
1155
|
-
includeAlpha?: boolean;
|
|
1156
|
-
/** Se true, usa formato compacto (shorthand hex, sem espaços em rgb) */
|
|
1157
|
-
compact?: boolean;
|
|
1158
|
-
}
|
|
1159
|
-
|
|
1160
693
|
/**
|
|
1161
694
|
* ColorRole - Role para conversão e manipulação de cores
|
|
1162
695
|
*
|
|
@@ -1187,4 +720,70 @@ declare class ColorRole extends ComplexRole<RGBA> {
|
|
|
1187
720
|
/** Instância singleton da ColorRole */
|
|
1188
721
|
declare const colorRole: ColorRole;
|
|
1189
722
|
|
|
1190
|
-
|
|
723
|
+
/**
|
|
724
|
+
* CurrencyRole - Role para valores monetários
|
|
725
|
+
*
|
|
726
|
+
* IMPORTANTE: Currency é diferente das outras roles!
|
|
727
|
+
* - NÃO tem convert (conversão entre moedas é operação de negócio)
|
|
728
|
+
* - O tipo de moeda (BRL, USD) é METADATA, não variante
|
|
729
|
+
* - Apenas 3 pilares: validate, cast, format
|
|
730
|
+
*
|
|
731
|
+
* @example
|
|
732
|
+
* // Functional style (preferido)
|
|
733
|
+
* import { validateCurrency, castCurrency, formatCurrency } from '@attrx/role-morphic/currency';
|
|
734
|
+
*
|
|
735
|
+
* validateCurrency(100.50); // { valid: true, errors: [] }
|
|
736
|
+
* castCurrency('R$ 1.500,50'); // 1500.50
|
|
737
|
+
* formatCurrency(1500.50, { currency: 'BRL' }); // "R$ 1.500,50"
|
|
738
|
+
*/
|
|
739
|
+
|
|
740
|
+
/**
|
|
741
|
+
* CurrencyRole - classe wrapper para os 3 pilares
|
|
742
|
+
*
|
|
743
|
+
* Nota: Currency não estende SimpleRole porque não tem convert.
|
|
744
|
+
* É uma role especial com apenas validate, cast e format.
|
|
745
|
+
*/
|
|
746
|
+
declare class CurrencyRole {
|
|
747
|
+
readonly name = "currency";
|
|
748
|
+
/**
|
|
749
|
+
* Valida um valor monetário
|
|
750
|
+
*/
|
|
751
|
+
validate(value: unknown, config?: CurrencyValidationConfig): {
|
|
752
|
+
valid: boolean;
|
|
753
|
+
errors: string[];
|
|
754
|
+
};
|
|
755
|
+
/**
|
|
756
|
+
* Verifica se um valor monetário é válido
|
|
757
|
+
*/
|
|
758
|
+
isValid(value: unknown, config?: CurrencyValidationConfig): boolean;
|
|
759
|
+
/**
|
|
760
|
+
* Faz cast de input para número
|
|
761
|
+
*/
|
|
762
|
+
cast(input: unknown): number | null;
|
|
763
|
+
/**
|
|
764
|
+
* Versão safe de cast que retorna Result
|
|
765
|
+
*/
|
|
766
|
+
tryCast(input: unknown): {
|
|
767
|
+
ok: true;
|
|
768
|
+
value: number;
|
|
769
|
+
} | {
|
|
770
|
+
ok: false;
|
|
771
|
+
error: string;
|
|
772
|
+
};
|
|
773
|
+
/**
|
|
774
|
+
* Formata valor monetário
|
|
775
|
+
*/
|
|
776
|
+
format(value: number, options: CurrencyFormatOptions): string;
|
|
777
|
+
/**
|
|
778
|
+
* Lista códigos de moeda disponíveis
|
|
779
|
+
*/
|
|
780
|
+
getCurrencyCodes(): CurrencyCode[];
|
|
781
|
+
/**
|
|
782
|
+
* Verifica se um código de moeda é válido
|
|
783
|
+
*/
|
|
784
|
+
hasCurrency(code: string): code is CurrencyCode;
|
|
785
|
+
}
|
|
786
|
+
/** Instância singleton da CurrencyRole */
|
|
787
|
+
declare const currencyRole: CurrencyRole;
|
|
788
|
+
|
|
789
|
+
export { AngleRole, AngleUnit, AreaRole, AreaUnit, BaseFormatOptions, ColorRole, ConversionResult, CurrencyCode, CurrencyFormatOptions, CurrencyRole, CurrencyValidationConfig, DateRole, DateTimestamp, DigitalRole, DigitalUnit, EnergyRole, EnergyUnit, FrequencyRole, FrequencyUnit, LengthRole, LengthUnit, MassRole, MassUnit, MorpherSpec, ParsedVariantId, PowerRole, PowerUnit, PressureRole, PressureUnit, RGBA, ReversibilityResult, RoleMorphic, RoleSpec, SpeedRole, SpeedUnit, TemperatureRole, TemperatureUnit, TimeRole, TimeUnit, ValidationResult, VariantSpec, VolumeRole, VolumeUnit, angleRole, areaRole, colorRole, currencyRole, dateRole, digitalRole, energyRole, frequencyRole, lengthRole, massRole, powerRole, pressureRole, speedRole, temperatureRole, timeRole, volumeRole };
|