vanilla-jui 1.5.45 → 1.6.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 CHANGED
@@ -13,7 +13,7 @@ Vanilla-JUI is web UI infrastructure that decouples reactive UI, design tokens,
13
13
  - **Unified API**: The component API is simple and consistent, requiring no memorization — updating state data immediately updates the view and interaction.
14
14
  - **100% custom styling**: Supports discarding the built-in styles and using the className mechanism with CSS tools such as Tailwind to fully customize styles.
15
15
  - **Multi-dimensional themes**: A multi-dimensional theme CSS architecture based on design tokens and root-node state makes personalized theme modes easy to implement.
16
- - **Common utilities**: Includes common utilities such as ID, Events, Timer, and DOM syntax sugar.
16
+ - **Common utilities**: Includes common utilities such as ID, Events, Timer, Form Validator, Image Compression and DOM syntax sugar.
17
17
 
18
18
  ## Installation And Usage
19
19
 
package/dist/index.d.ts CHANGED
@@ -325,6 +325,128 @@ interface KeyedElementRefs<TKey, TElement extends Element> {
325
325
  }
326
326
  declare function createKeyedElementRefs<TKey, TElement extends Element>(): KeyedElementRefs<TKey, TElement>;
327
327
  //#endregion
328
+ //#region src/utilities/validator.d.ts
329
+ type ValidatorElement = HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement;
330
+ type ValidatorMessageMap = Record<string, Partial<Record<string, string>>>;
331
+ type ValidatorCustomResult = boolean | string;
332
+ type ValidatorCustomRule = (element: ValidatorElement, validator: ValidatorInstance) => ValidatorCustomResult;
333
+ interface ValidatorRule extends Record<string, unknown> {
334
+ required?: boolean;
335
+ minLength?: number;
336
+ maxLength?: number;
337
+ equalTo?: string;
338
+ email?: boolean;
339
+ checked?: boolean;
340
+ selected?: boolean;
341
+ multiple?: boolean;
342
+ min?: number;
343
+ max?: number;
344
+ noSpace?: boolean;
345
+ noChinese?: boolean;
346
+ noSpecial?: boolean;
347
+ pattern?: string | RegExp;
348
+ file?: boolean;
349
+ minSize?: number;
350
+ maxSize?: number;
351
+ accept?: string;
352
+ validate?: ValidatorCustomRule;
353
+ }
354
+ interface ValidatorProps extends Record<string, unknown> {
355
+ rules?: Record<string, ValidatorRule>;
356
+ messages?: ValidatorMessageMap;
357
+ vanilla?: boolean;
358
+ className?: ValidatorClassNameConfig;
359
+ onSubmit?: ((validator: ValidatorInstance) => void) | null;
360
+ }
361
+ interface ValidatorClassNames {
362
+ help: string;
363
+ }
364
+ type ValidatorClassNameConfig = Partial<ValidatorClassNames>;
365
+ interface ResolvedValidatorProps extends Record<string, unknown> {
366
+ rules: Record<string, ValidatorRule>;
367
+ messages: ValidatorMessageMap;
368
+ vanilla: boolean;
369
+ className: ValidatorClassNames;
370
+ onSubmit: ((validator: ValidatorInstance) => void) | null;
371
+ }
372
+ interface ValidatorRuntime {
373
+ valid: boolean;
374
+ error: boolean;
375
+ message: string;
376
+ destroyed: boolean;
377
+ }
378
+ interface ResetOptions {
379
+ native?: boolean;
380
+ }
381
+ interface ValidatorInstance {
382
+ readonly element: HTMLFormElement | null;
383
+ props: ResolvedValidatorProps | null;
384
+ runtime: ValidatorRuntime;
385
+ validate(): boolean;
386
+ reset(options?: ResetOptions): void;
387
+ destroy(): void;
388
+ }
389
+ declare function createValidator(element: DOMReference, props?: ValidatorProps, bindEvents?: boolean): ValidatorInstance;
390
+ //#endregion
391
+ //#region src/utilities/compress.d.ts
392
+ interface CompressOptions {
393
+ /** 压缩质量,范围 0-1,默认 0.7 */
394
+ quality?: number;
395
+ /** 目标宽度(像素),不指定则按原图比例缩放 */
396
+ width?: number;
397
+ /** 目标高度(像素),不指定则按原图比例缩放 */
398
+ height?: number;
399
+ }
400
+ interface ImgCompressInstance {
401
+ /**
402
+ * 将图片路径转换为压缩后的 base64 数据
403
+ * @param path - 图片文件路径或 base64 字符串
404
+ * @param callback - 压缩完成后的回调函数,接收 base64 字符串作为参数
405
+ */
406
+ canvasDataURL: (path: string, callback: (base64: string) => void) => void;
407
+ /**
408
+ * 压缩文件对象
409
+ * @param file - 文件对象(Blob 或 File)
410
+ * @param callback - 压缩完成后的回调函数,接收 base64 字符串作为参数
411
+ */
412
+ photoCompress: (file: Blob, callback: (base64: string) => void) => void;
413
+ /**
414
+ * 将 base64 字符串转换为 Blob 对象
415
+ * @param urlData - base64 数据(包含 data:image 前缀)
416
+ * @returns Blob 对象,如果解析失败则返回 undefined
417
+ */
418
+ convertBase64UrlToBlob: (urlData: string) => Blob | undefined;
419
+ }
420
+ /**
421
+ * 创建图片压缩实例
422
+ * @param options - 压缩配置选项
423
+ * @param singleton - 是否返回单例,默认 true
424
+ * @returns 图片压缩实例
425
+ * @example
426
+ * ```ts
427
+ * // 获取单例实例(默认)
428
+ * const imgzip = createImgCompress({ quality: 0.8, width: 800 });
429
+ *
430
+ * // 创建新实例
431
+ * const imgzip2 = createImgCompress({ quality: 0.9 }, false);
432
+ * ```
433
+ */
434
+ declare function createImgCompress(options?: CompressOptions, singleton?: boolean): ImgCompressInstance;
435
+ /**
436
+ * 获取单例实例(如果不存在则创建)
437
+ * @param options - 压缩配置选项(仅在首次创建时生效)
438
+ * @returns 单例实例
439
+ * @example
440
+ * ```ts
441
+ * const imgzip = getImgCompressInstance({ quality: 0.8 });
442
+ * ```
443
+ */
444
+ declare function getImgCompressInstance(options?: CompressOptions): ImgCompressInstance;
445
+ /**
446
+ * 重置单例实例(用于测试或重新配置)
447
+ */
448
+ declare function resetImgCompressInstance(): void;
449
+ //#endregion
328
450
  //#region src/core/scheduler.d.ts
329
451
  interface ScheduledTask {
330
452
  schedule: () => void;
@@ -772,69 +894,6 @@ interface StickyInstance {
772
894
  }
773
895
  declare function createSticky(props?: StickyProps): StickyInstance;
774
896
  //#endregion
775
- //#region src/validation/validator.d.ts
776
- type ValidatorElement = HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement;
777
- type ValidatorMessageMap = Record<string, Partial<Record<string, string>>>;
778
- type ValidatorCustomResult = boolean | string;
779
- type ValidatorCustomRule = (element: ValidatorElement, validator: ValidatorInstance) => ValidatorCustomResult;
780
- interface ValidatorRule extends Record<string, unknown> {
781
- required?: boolean;
782
- minLength?: number;
783
- maxLength?: number;
784
- equalTo?: string;
785
- email?: boolean;
786
- checked?: boolean;
787
- selected?: boolean;
788
- multiple?: boolean;
789
- min?: number;
790
- max?: number;
791
- noSpace?: boolean;
792
- noChinese?: boolean;
793
- noSpecial?: boolean;
794
- pattern?: string | RegExp;
795
- file?: boolean;
796
- minSize?: number;
797
- maxSize?: number;
798
- accept?: string;
799
- validate?: ValidatorCustomRule;
800
- }
801
- interface ValidatorProps extends Record<string, unknown> {
802
- rules?: Record<string, ValidatorRule>;
803
- messages?: ValidatorMessageMap;
804
- vanilla?: boolean;
805
- className?: ValidatorClassNameConfig;
806
- onSubmit?: ((validator: ValidatorInstance) => void) | null;
807
- }
808
- interface ValidatorClassNames {
809
- help: string;
810
- }
811
- type ValidatorClassNameConfig = Partial<ValidatorClassNames>;
812
- interface ResolvedValidatorProps extends Record<string, unknown> {
813
- rules: Record<string, ValidatorRule>;
814
- messages: ValidatorMessageMap;
815
- vanilla: boolean;
816
- className: ValidatorClassNames;
817
- onSubmit: ((validator: ValidatorInstance) => void) | null;
818
- }
819
- interface ValidatorRuntime {
820
- valid: boolean;
821
- error: boolean;
822
- message: string;
823
- destroyed: boolean;
824
- }
825
- interface ResetOptions {
826
- native?: boolean;
827
- }
828
- interface ValidatorInstance {
829
- readonly element: HTMLFormElement | null;
830
- props: ResolvedValidatorProps | null;
831
- runtime: ValidatorRuntime;
832
- validate(): boolean;
833
- reset(options?: ResetOptions): void;
834
- destroy(): void;
835
- }
836
- declare function createValidator(element: DOMReference, props?: ValidatorProps, bindEvents?: boolean): ValidatorInstance;
837
- //#endregion
838
897
  //#region src/core/component.d.ts
839
898
  type ComponentProps = Record<string, unknown>;
840
899
  type ComponentState = Record<string, unknown>;
@@ -1771,4 +1830,4 @@ interface MenuState extends Record<string, unknown> {
1771
1830
  type Menu = FunctionalComponent<ResolvedMenuProps, MenuState, HTMLElement>;
1772
1831
  declare function createMenu(input?: MenuProps): Menu;
1773
1832
  //#endregion
1774
- export { ClassNameToken, CleanupFunction, CollapseMotionController, CollapseTransitionDefinition, ComponentCleanup, ComponentContext, ComponentController, ComponentDefinition, ComponentLifecycleEvent, ComponentListener, ComponentPlugin, ComponentPluginOptions, ComponentProps, ComponentRuntime, ComponentState, ContainerExpect, DOMReference, DropInstance, ElementRef, FieldOption, Flow, FlowAction, FlowBusyHook, FlowBusyStrategy, FlowChangeHook, FlowClassNameConfig, FlowClassNames, FlowCleanup, FlowContext, FlowData, FlowDirection, FlowErrorHook, FlowFinishHook, FlowGoToOptions, FlowGuardHook, FlowLifecycleHook, FlowMoveHook, FlowPayload, FlowProps, FlowRenderContext, FlowSlot, FlowSlotName, FlowSnapshot, FlowState, FlowStep, FlowStepResult, FlowSubscriber, FlowTarget, FlowText, Form, FormButtons, FormClassNameConfig, FormClassNames, FormDataRecord, FormDataValue, FormField, FormItem, FormItemNext, FormItemType, FormOption, FormProps, FormText, FormTextConfig, FormValidatorConfig, FunctionalComponent, IEventManager, IconAttributeValue, IconName, IconPathMap, IconProps, KeyedElementRefs, LazyRenderCallback, LazyRenderOptions, LazyRenderTarget, Menu, MenuClassNameConfig, MenuClassNames, MenuItem, MenuItemId, MenuItemRenderType, MenuProps, MenuType, Modal, ModalClassNameConfig, ModalClassNames, ModalProps, ModalText, MotionController, NormalizeContext, Offcanvas, OffcanvasAnimate, OffcanvasClassNameConfig, OffcanvasClassNames, OffcanvasContent, OffcanvasDirection, OffcanvasProps, OwnedView, OwnedViewOptions, Pagination, PaginationClassNameConfig, PaginationClassNames, PaginationCount, PaginationPage, PaginationProps, ParabolaInstance, ParamRule, ParamRuleInput, PopupProps, PresenceController, PresenceOptions, PresencePhase, PublicFlowStep, QueryContext, RenderableContent, RequireContainerResult, ResolveContainerResult, ResolveSchema, ResolvedProps, StateSyncOptions, SupportES2022, Swiper, SwiperClassNameConfig, SwiperClassNames, SwiperDataItem, SwiperDataLoader, SwiperDataSource, SwiperProps, SwiperSlideContext, TabContent, TabItem, Tabs, TabsClassNameConfig, TabsClassNames, TabsDirection, TabsDisabled, TabsPanelContext, TabsProps, TabsValue, ThemeClassNameConfig, ThemeClassNames, ThemeConfigKey, ThemeInstance, ThemeOptions, ThemePanelGroup, ThemeResolvedOptions, Toast, ToastClassNameConfig, ToastClassNameOptions, ToastClassNames, ToastConfirmProps, ToastOptions, ToastTheme, ToastThemeOptions, TocCurrent, TocItem, TooltipInstance, TransitionDefinition, TransitionTarget, ValidateCondition, ValidatorClassNameConfig, ValidatorClassNames, ValidatorInstance, addIcons, all, asRenderable, checkModernBrowser, copy, createAccordion, createCollapseTransition, createDrop, createElementRef, createEventManager, createFlow, createForm, createKeyedElementRefs, createLoading, createMenu, createModal, createMotionGroup, createOffcanvas, createOwnedView, createPagination, createParabola, createPopup, createPresence, createScheduledTask, createStateSync, createSticky, createSwiper, createTabs, createTheme, createToc, createTooltip, createTransition, createValidator, defineComponent, flexPosition, getRegistedIconPath, getStoreVersion, getType, icon, iconHtml, iconMarkup, isDomElementValue, isDomNodeValue, isElement, isHtmlElementValue, isMobile, isModernBrowser, isNilValue, isNode, isPlainObject, isRenderableContent, isRenderablePrimitive, isRenderableValue, joinClasses, lazyRender, listen, postJson, q, randomId, removeComponentPlugin, requireContainer, resolveContainer, resolveElement, resolveNode, resolveNodeList, resolveProps, restUrl, stateSnapshot, timer, trackStoreVersion, translate, useComponentPlugin, uuid, validateParam, waitForMotion };
1833
+ export { ClassNameToken, CleanupFunction, CollapseMotionController, CollapseTransitionDefinition, ComponentCleanup, ComponentContext, ComponentController, ComponentDefinition, ComponentLifecycleEvent, ComponentListener, ComponentPlugin, ComponentPluginOptions, ComponentProps, ComponentRuntime, ComponentState, CompressOptions, ContainerExpect, DOMReference, DropInstance, ElementRef, FieldOption, Flow, FlowAction, FlowBusyHook, FlowBusyStrategy, FlowChangeHook, FlowClassNameConfig, FlowClassNames, FlowCleanup, FlowContext, FlowData, FlowDirection, FlowErrorHook, FlowFinishHook, FlowGoToOptions, FlowGuardHook, FlowLifecycleHook, FlowMoveHook, FlowPayload, FlowProps, FlowRenderContext, FlowSlot, FlowSlotName, FlowSnapshot, FlowState, FlowStep, FlowStepResult, FlowSubscriber, FlowTarget, FlowText, Form, FormButtons, FormClassNameConfig, FormClassNames, FormDataRecord, FormDataValue, FormField, FormItem, FormItemNext, FormItemType, FormOption, FormProps, FormText, FormTextConfig, FormValidatorConfig, FunctionalComponent, IEventManager, IconAttributeValue, IconName, IconPathMap, IconProps, ImgCompressInstance, KeyedElementRefs, LazyRenderCallback, LazyRenderOptions, LazyRenderTarget, Menu, MenuClassNameConfig, MenuClassNames, MenuItem, MenuItemId, MenuItemRenderType, MenuProps, MenuType, Modal, ModalClassNameConfig, ModalClassNames, ModalProps, ModalText, MotionController, NormalizeContext, Offcanvas, OffcanvasAnimate, OffcanvasClassNameConfig, OffcanvasClassNames, OffcanvasContent, OffcanvasDirection, OffcanvasProps, OwnedView, OwnedViewOptions, Pagination, PaginationClassNameConfig, PaginationClassNames, PaginationCount, PaginationPage, PaginationProps, ParabolaInstance, ParamRule, ParamRuleInput, PopupProps, PresenceController, PresenceOptions, PresencePhase, PublicFlowStep, QueryContext, RenderableContent, RequireContainerResult, ResolveContainerResult, ResolveSchema, ResolvedProps, StateSyncOptions, SupportES2022, Swiper, SwiperClassNameConfig, SwiperClassNames, SwiperDataItem, SwiperDataLoader, SwiperDataSource, SwiperProps, SwiperSlideContext, TabContent, TabItem, Tabs, TabsClassNameConfig, TabsClassNames, TabsDirection, TabsDisabled, TabsPanelContext, TabsProps, TabsValue, ThemeClassNameConfig, ThemeClassNames, ThemeConfigKey, ThemeInstance, ThemeOptions, ThemePanelGroup, ThemeResolvedOptions, Toast, ToastClassNameConfig, ToastClassNameOptions, ToastClassNames, ToastConfirmProps, ToastOptions, ToastTheme, ToastThemeOptions, TocCurrent, TocItem, TooltipInstance, TransitionDefinition, TransitionTarget, ValidateCondition, ValidatorClassNameConfig, ValidatorClassNames, ValidatorInstance, addIcons, all, asRenderable, checkModernBrowser, copy, createAccordion, createCollapseTransition, createDrop, createElementRef, createEventManager, createFlow, createForm, createImgCompress, createKeyedElementRefs, createLoading, createMenu, createModal, createMotionGroup, createOffcanvas, createOwnedView, createPagination, createParabola, createPopup, createPresence, createScheduledTask, createStateSync, createSticky, createSwiper, createTabs, createTheme, createToc, createTooltip, createTransition, createValidator, defineComponent, flexPosition, getImgCompressInstance, getRegistedIconPath, getStoreVersion, getType, icon, iconHtml, iconMarkup, isDomElementValue, isDomNodeValue, isElement, isHtmlElementValue, isMobile, isModernBrowser, isNilValue, isNode, isPlainObject, isRenderableContent, isRenderablePrimitive, isRenderableValue, joinClasses, lazyRender, listen, postJson, q, randomId, removeComponentPlugin, requireContainer, resetImgCompressInstance, resolveContainer, resolveElement, resolveNode, resolveNodeList, resolveProps, restUrl, stateSnapshot, timer, trackStoreVersion, translate, useComponentPlugin, uuid, validateParam, waitForMotion };