@vnejs/plugins.controllers.screens.gallery.full 0.0.0-stage → 0.2.18

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.
Files changed (47) hide show
  1. package/dist/index.d.ts +2 -0
  2. package/dist/index.js +22 -0
  3. package/dist/modules/bridge.d.ts +8 -0
  4. package/dist/modules/bridge.js +13 -0
  5. package/dist/modules/controller.arrows.d.ts +12 -0
  6. package/dist/modules/controller.arrows.js +11 -0
  7. package/dist/modules/controller.d.ts +16 -0
  8. package/dist/modules/controller.js +24 -0
  9. package/dist/modules/hide.controls.d.ts +8 -0
  10. package/dist/modules/hide.controls.js +7 -0
  11. package/dist/modules/load.d.ts +9 -0
  12. package/dist/modules/load.js +17 -0
  13. package/dist/modules/load.src.d.ts +11 -0
  14. package/dist/modules/load.src.js +27 -0
  15. package/dist/modules/variation.d.ts +12 -0
  16. package/dist/modules/variation.js +12 -0
  17. package/dist/modules/view.d.ts +9 -0
  18. package/dist/modules/view.js +8 -0
  19. package/dist/types.d.ts +23 -0
  20. package/dist/types.js +1 -0
  21. package/dist/utils/gallery.full.d.ts +16 -0
  22. package/dist/utils/gallery.full.js +21 -0
  23. package/dist/view/index.d.ts +3 -0
  24. package/dist/view/index.js +10 -0
  25. package/package.json +63 -4
  26. package/src/index.ts +26 -0
  27. package/src/modules/bridge.ts +21 -0
  28. package/src/modules/controller.arrows.ts +22 -0
  29. package/src/modules/controller.ts +43 -0
  30. package/src/modules/hide.controls.ts +17 -0
  31. package/src/modules/load.src.ts +50 -0
  32. package/src/modules/load.ts +33 -0
  33. package/src/modules/variation.ts +24 -0
  34. package/src/modules/view.ts +21 -0
  35. package/src/tests/arrows.test.ts +60 -0
  36. package/src/tests/bridge.test.ts +32 -0
  37. package/src/tests/controller.test.ts +46 -0
  38. package/src/tests/hide.controls.test.ts +55 -0
  39. package/src/tests/load.src.test.ts +49 -0
  40. package/src/tests/load.test.ts +49 -0
  41. package/src/tests/setup.ts +56 -0
  42. package/src/tests/variation.test.ts +69 -0
  43. package/src/types.ts +38 -0
  44. package/src/utils/gallery.full.ts +45 -0
  45. package/src/view/index.tsx +68 -0
  46. package/tsconfig.json +10 -0
  47. package/README.md +0 -3
@@ -0,0 +1,2 @@
1
+ import "@vnejs/contracts.canvas.child.bg";
2
+ import "@vnejs/contracts.controllers.screens.gallery.full";
package/dist/index.js ADDED
@@ -0,0 +1,22 @@
1
+ import "@vnejs/contracts.canvas.child.bg";
2
+ import "@vnejs/contracts.controllers.screens.gallery.full";
3
+ import { regPlugin } from "@vnejs/registry";
4
+ import { PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/contracts.controllers.screens.gallery.full";
5
+ import { GalleryFullViewBridge } from "./modules/bridge.js";
6
+ import { GalleryFullViewControllerArrows } from "./modules/controller.arrows.js";
7
+ import { GalleryFullViewController } from "./modules/controller.js";
8
+ import { GalleryFullViewHideControls } from "./modules/hide.controls.js";
9
+ import { GalleryFullViewLoad } from "./modules/load.js";
10
+ import { GalleryFullViewLoadSrc } from "./modules/load.src.js";
11
+ import { GalleryFullViewVariation } from "./modules/variation.js";
12
+ import { GalleryFullView } from "./modules/view.js";
13
+ regPlugin(PLUGIN_NAME, { events: SUBSCRIBE_EVENTS, params: PARAMS }, [
14
+ GalleryFullViewBridge,
15
+ GalleryFullViewController,
16
+ GalleryFullViewControllerArrows,
17
+ GalleryFullViewHideControls,
18
+ GalleryFullViewLoad,
19
+ GalleryFullViewLoadSrc,
20
+ GalleryFullViewVariation,
21
+ GalleryFullView,
22
+ ]);
@@ -0,0 +1,8 @@
1
+ import { ModuleCore } from "@vnejs/module.core";
2
+ import type { GalleryFullChoosePayload } from "@vnejs/contracts.controllers.screens.gallery.full";
3
+ import type { GalleryFullPluginConstants, GalleryFullPluginEvents, GalleryFullPluginParams, GalleryFullPluginSettings } from "../types.js";
4
+ export declare class GalleryFullViewBridge extends ModuleCore<GalleryFullPluginEvents, GalleryFullPluginConstants, GalleryFullPluginSettings, GalleryFullPluginParams> {
5
+ name: string;
6
+ subscribe: () => void;
7
+ onGalleryChoose: (payload?: GalleryFullChoosePayload) => Promise<import("@vnejs/registry").EmitResults<"vne:gallery_full:show">> | undefined;
8
+ }
@@ -0,0 +1,13 @@
1
+ import { ModuleCore } from "@vnejs/module.core";
2
+ import { getItemFromPayload } from "../utils/gallery.full.js";
3
+ export class GalleryFullViewBridge extends ModuleCore {
4
+ name = "gallery.full.view.bridge";
5
+ subscribe = () => {
6
+ this.on(this.EVENTS.GALLERY.CHOOSE, this.onGalleryChoose);
7
+ };
8
+ onGalleryChoose = (payload = {}) => {
9
+ const item = getItemFromPayload(payload, this.globalState?.["gallery.controller"]);
10
+ if (item.isOpened)
11
+ return this.emit(this.EVENTS.GALLERY_FULL_VIEW.SHOW, payload);
12
+ };
13
+ }
@@ -0,0 +1,12 @@
1
+ import { ModuleControllerArrowsHorizontal } from "@vnejs/module.controller.arrows.horizontal";
2
+ import type { GalleryFullPluginConstants, GalleryFullPluginEvents, GalleryFullPluginParams, GalleryFullPluginSettings } from "../types.js";
3
+ export declare class GalleryFullViewControllerArrows extends ModuleControllerArrowsHorizontal<GalleryFullPluginEvents, GalleryFullPluginConstants, GalleryFullPluginSettings, GalleryFullPluginParams> {
4
+ name: string;
5
+ EVENT_SHOW: "vne:gallery_full:show";
6
+ EVENT_HIDE: "vne:gallery_full:hide";
7
+ EVENT_UPDATE_STATE: "vne:gallery_full:update_state";
8
+ EVENT_UPDATE_FAST: "vne:gallery_full:update_fast";
9
+ CONTROLS_ZINDEX: number;
10
+ onArrowLeft: () => undefined;
11
+ onArrowRight: () => undefined;
12
+ }
@@ -0,0 +1,11 @@
1
+ import { ModuleControllerArrowsHorizontal } from "@vnejs/module.controller.arrows.horizontal";
2
+ export class GalleryFullViewControllerArrows extends ModuleControllerArrowsHorizontal {
3
+ name = "gallery.full.view.controller.arrows";
4
+ EVENT_SHOW = this.EVENTS.GALLERY_FULL_VIEW.SHOW;
5
+ EVENT_HIDE = this.EVENTS.GALLERY_FULL_VIEW.HIDE;
6
+ EVENT_UPDATE_STATE = this.EVENTS.GALLERY_FULL_VIEW.UPDATE_STATE;
7
+ EVENT_UPDATE_FAST = this.EVENTS.GALLERY_FULL_VIEW.UPDATE_FAST;
8
+ CONTROLS_ZINDEX = this.PARAMS.GALLERY_FULL_VIEW.ZINDEX;
9
+ onArrowLeft = () => void this.emit(this.EVENTS.GALLERY_FULL_VIEW.PREV);
10
+ onArrowRight = () => void this.emit(this.EVENTS.GALLERY_FULL_VIEW.NEXT);
11
+ }
@@ -0,0 +1,16 @@
1
+ import { ModuleController } from "@vnejs/module.components";
2
+ import type { GalleryFullPluginConstants, GalleryFullPluginEvents, GalleryFullPluginParams, GalleryFullPluginSettings } from "../types.js";
3
+ import type { GalleryFullPluginState } from "../types.js";
4
+ export declare class GalleryFullViewController extends ModuleController<GalleryFullPluginEvents, GalleryFullPluginConstants, GalleryFullPluginSettings, GalleryFullPluginParams, GalleryFullPluginState> {
5
+ name: string;
6
+ EVENT_UPDATE_VIEW: "vne:gallery_full:update";
7
+ EVENT_UPDATE_STATE: "vne:gallery_full:update_state";
8
+ EVENT_UPDATE_FAST: "vne:gallery_full:update_fast";
9
+ EVENT_UPDATE_FORCE: "vne:gallery_full:update_force";
10
+ EVENT_SHOW: "vne:gallery_full:show";
11
+ EVENT_HIDE: "vne:gallery_full:hide";
12
+ CONTROLS: {};
13
+ CONTROLS_INDEX: number;
14
+ onHideAfter: () => Promise<import("@vnejs/registry").EmitResults<"vne:gallery_full:update_state">> | undefined;
15
+ onShowBefore: (args?: {}) => Promise<import("@vnejs/registry").EmitResults<"vne:gallery_full:load"> | undefined>;
16
+ }
@@ -0,0 +1,24 @@
1
+ import { ModuleController } from "@vnejs/module.components";
2
+ import { getItemFromPayload, getItemVariants } from "../utils/gallery.full.js";
3
+ export class GalleryFullViewController extends ModuleController {
4
+ name = "gallery.full.view.controller";
5
+ EVENT_UPDATE_VIEW = this.EVENTS.GALLERY_FULL_VIEW.UPDATE;
6
+ EVENT_UPDATE_STATE = this.EVENTS.GALLERY_FULL_VIEW.UPDATE_STATE;
7
+ EVENT_UPDATE_FAST = this.EVENTS.GALLERY_FULL_VIEW.UPDATE_FAST;
8
+ EVENT_UPDATE_FORCE = this.EVENTS.GALLERY_FULL_VIEW.UPDATE_FORCE;
9
+ EVENT_SHOW = this.EVENTS.GALLERY_FULL_VIEW.SHOW;
10
+ EVENT_HIDE = this.EVENTS.GALLERY_FULL_VIEW.HIDE;
11
+ CONTROLS = {};
12
+ CONTROLS_INDEX = this.PARAMS.GALLERY_FULL_VIEW.ZINDEX;
13
+ onHideAfter = () => this.emit(this.EVENT_UPDATE_STATE, { itemFullName: "", itemMediaType: "", itemLayerChildType: "", variants: [] });
14
+ onShowBefore = async (args = {}) => {
15
+ const item = getItemFromPayload(args, this.globalState?.["gallery.controller"]);
16
+ await this.emit(this.EVENT_UPDATE_STATE, {
17
+ itemFullName: item.fullName ?? "",
18
+ itemMediaType: item.mediaType ?? "",
19
+ itemLayerChildType: item.layerChildType ?? "",
20
+ variants: getItemVariants(item),
21
+ });
22
+ return this.emit(this.EVENTS.GALLERY_FULL_VIEW.LOAD, { pageIndex: 0 });
23
+ };
24
+ }
@@ -0,0 +1,8 @@
1
+ import { ModuleControllerHideOnControls } from "@vnejs/module.controller.hide.on.controls";
2
+ import type { GalleryFullPluginConstants, GalleryFullPluginEvents, GalleryFullPluginParams, GalleryFullPluginSettings } from "../types.js";
3
+ export declare class GalleryFullViewHideControls extends ModuleControllerHideOnControls<GalleryFullPluginEvents, GalleryFullPluginConstants, GalleryFullPluginSettings, GalleryFullPluginParams> {
4
+ name: string;
5
+ EVENT_SHOW: "vne:gallery_full:show";
6
+ EVENT_HIDE: "vne:gallery_full:hide";
7
+ CONTROLS_ZINDEX: number;
8
+ }
@@ -0,0 +1,7 @@
1
+ import { ModuleControllerHideOnControls } from "@vnejs/module.controller.hide.on.controls";
2
+ export class GalleryFullViewHideControls extends ModuleControllerHideOnControls {
3
+ name = "gallery.full.view.hide.controls";
4
+ EVENT_SHOW = this.EVENTS.GALLERY_FULL_VIEW.SHOW;
5
+ EVENT_HIDE = this.EVENTS.GALLERY_FULL_VIEW.HIDE;
6
+ CONTROLS_ZINDEX = this.PARAMS.GALLERY_FULL_VIEW.ZINDEX;
7
+ }
@@ -0,0 +1,9 @@
1
+ import { ModuleCore } from "@vnejs/module.core";
2
+ import type { GalleryFullLoadPayload } from "@vnejs/contracts.controllers.screens.gallery.full";
3
+ import type { GalleryFullPluginConstants, GalleryFullPluginEvents, GalleryFullPluginParams, GalleryFullPluginSettings } from "../types.js";
4
+ import type { GalleryFullPluginState } from "../types.js";
5
+ export declare class GalleryFullViewLoad extends ModuleCore<GalleryFullPluginEvents, GalleryFullPluginConstants, GalleryFullPluginSettings, GalleryFullPluginParams, GalleryFullPluginState> {
6
+ name: string;
7
+ subscribe: () => void;
8
+ onLoad: ({ pageIndex }?: GalleryFullLoadPayload) => Promise<import("@vnejs/registry").EmitResults<"vne:gallery_full:update_state"> | undefined>;
9
+ }
@@ -0,0 +1,17 @@
1
+ import { ModuleCore } from "@vnejs/module.core";
2
+ export class GalleryFullViewLoad extends ModuleCore {
3
+ name = "gallery.full.view.load";
4
+ subscribe = () => {
5
+ this.on(this.EVENTS.GALLERY_FULL_VIEW.LOAD, this.onLoad);
6
+ this.on(this.EVENTS.GALLERY_FULL_VIEW.UPDATE_STATE, this.updateState);
7
+ };
8
+ onLoad = async ({ pageIndex = 0 } = {}) => {
9
+ const variants = this.state.variants ?? [];
10
+ if (pageIndex < 0 || pageIndex >= variants.length)
11
+ return;
12
+ const variant = variants[pageIndex] ?? {};
13
+ const imageSrc = variant.isOpened ? ((await this.emitOne(this.EVENTS.GALLERY_FULL_VIEW.LOAD_SRC, variant)) ?? "") : "";
14
+ const [pagesCount, withBackgroundBlur, isAllSrcRendered] = [variants.length, !variant.isOpened, Array.isArray(imageSrc) && imageSrc.length > 1];
15
+ return this.emit(this.EVENTS.GALLERY_FULL_VIEW.UPDATE_STATE, { pageIndex, pagesCount, withBackgroundBlur, imageSrc, isAllSrcRendered });
16
+ };
17
+ }
@@ -0,0 +1,11 @@
1
+ import { ModuleCore } from "@vnejs/module.core";
2
+ import type { GalleryFullLoadSrcPayload } from "@vnejs/contracts.controllers.screens.gallery.full";
3
+ import type { GalleryFullPluginConstants, GalleryFullPluginEvents, GalleryFullPluginParams, GalleryFullPluginSettings } from "../types.js";
4
+ import type { GalleryFullPluginState } from "../types.js";
5
+ export declare class GalleryFullViewLoadSrc extends ModuleCore<GalleryFullPluginEvents, GalleryFullPluginConstants, GalleryFullPluginSettings, GalleryFullPluginParams, GalleryFullPluginState> {
6
+ name: string;
7
+ subscribe: () => void;
8
+ onLoadSrc: (payload?: GalleryFullLoadSrcPayload) => Promise<string | import("@vnejs/contracts.controllers.screens.gallery.full").GalleryFullImageSrcItem[]>;
9
+ loadImageMedia: (name: string, mediaType: string, quality: string | number) => Promise<HTMLImageElement>;
10
+ loadMediaByName: (name?: string, layerChildType?: string, mediaType?: string) => Promise<string>;
11
+ }
@@ -0,0 +1,27 @@
1
+ import { ModuleCore } from "@vnejs/module.core";
2
+ import { toGalleryMediaName, toImageSrc } from "../utils/gallery.full.js";
3
+ export class GalleryFullViewLoadSrc extends ModuleCore {
4
+ name = "gallery.full.view.load.src";
5
+ subscribe = () => {
6
+ this.on(this.EVENTS.GALLERY_FULL_VIEW.LOAD_SRC, this.onLoadSrc);
7
+ this.on(this.EVENTS.GALLERY_FULL_VIEW.UPDATE_STATE, this.updateState);
8
+ };
9
+ onLoadSrc = async (payload = {}) => {
10
+ const { name, overlays, layerChildType } = payload;
11
+ const [srcGetEvent, bgLayerChildType] = [this.EVENTS.LAYER_BG?.SRC_GET, this.CONST.LAYER_BG?.LAYER_CHILD_TYPE ?? "bg"];
12
+ if (layerChildType === bgLayerChildType && name)
13
+ return srcGetEvent ? toImageSrc(await this.emitOne(srcGetEvent, { name, args: overlays !== undefined ? { overlays } : {} })) : "";
14
+ return name ? this.loadMediaByName(name, layerChildType) : this.loadMediaByName(this.state.itemFullName ?? "", this.state.itemLayerChildType || undefined);
15
+ };
16
+ loadImageMedia = (name, mediaType, quality) => {
17
+ const [type, priority] = [this.CONST.MEDIA.TYPES.IMAGE, this.CONST.MEDIA.PRIORITIES.HIGH];
18
+ return this.emitOne(this.EVENTS.MEDIA.LOAD, { type, priority, quality, name, mediaType });
19
+ };
20
+ loadMediaByName = async (name = "", layerChildType, mediaType = this.state.itemMediaType ?? "") => {
21
+ const mediaName = toGalleryMediaName(name, layerChildType);
22
+ if (!mediaName)
23
+ return "";
24
+ const media = await this.loadImageMedia(mediaName, mediaType, this.shared.settings[this.SETTINGS.LAYER.QUALITY]);
25
+ return media?.src ?? "";
26
+ };
27
+ }
@@ -0,0 +1,12 @@
1
+ import { ModuleControllerPages } from "@vnejs/module.controller.pages";
2
+ import type { GalleryFullPluginConstants, GalleryFullPluginEvents, GalleryFullPluginParams, GalleryFullPluginSettings } from "../types.js";
3
+ import type { GalleryFullPluginState } from "../types.js";
4
+ export declare class GalleryFullViewVariation extends ModuleControllerPages<GalleryFullPluginEvents, GalleryFullPluginConstants, GalleryFullPluginSettings, GalleryFullPluginParams, GalleryFullPluginState> {
5
+ name: string;
6
+ EVENT_PAGE_SET: "vne:gallery_full:page_set";
7
+ EVENT_PAGE_NEXT: "vne:gallery_full:next";
8
+ EVENT_PAGE_PREV: "vne:gallery_full:prev";
9
+ EVENT_UPDATE_STATE: "vne:gallery_full:update_state";
10
+ EVENT_UPDATE_FAST: "vne:gallery_full:update_fast";
11
+ applyPage: () => Promise<void>;
12
+ }
@@ -0,0 +1,12 @@
1
+ import { ModuleControllerPages } from "@vnejs/module.controller.pages";
2
+ export class GalleryFullViewVariation extends ModuleControllerPages {
3
+ name = "gallery.full.view.variation";
4
+ EVENT_PAGE_SET = this.EVENTS.GALLERY_FULL_VIEW.PAGE_SET;
5
+ EVENT_PAGE_NEXT = this.EVENTS.GALLERY_FULL_VIEW.NEXT;
6
+ EVENT_PAGE_PREV = this.EVENTS.GALLERY_FULL_VIEW.PREV;
7
+ EVENT_UPDATE_STATE = this.EVENTS.GALLERY_FULL_VIEW.UPDATE_STATE;
8
+ EVENT_UPDATE_FAST = this.EVENTS.GALLERY_FULL_VIEW.UPDATE_FAST;
9
+ applyPage = async () => {
10
+ await this.emit(this.EVENTS.GALLERY_FULL_VIEW.LOAD, { pageIndex: this.state.pageIndex ?? 0 });
11
+ };
12
+ }
@@ -0,0 +1,9 @@
1
+ import { ModuleView } from "@vnejs/module.components";
2
+ import type { GalleryFullPluginConstants, GalleryFullPluginEvents, GalleryFullPluginParams, GalleryFullPluginSettings } from "../types.js";
3
+ import type { GalleryFullPluginState } from "../types.js";
4
+ export declare class GalleryFullView extends ModuleView<GalleryFullPluginEvents, GalleryFullPluginConstants, GalleryFullPluginSettings, GalleryFullPluginParams, GalleryFullPluginState> {
5
+ name: string;
6
+ EVENT_UPDATE_VIEW: "vne:gallery_full:update";
7
+ TRANSITION: number;
8
+ renderFunc: import("@vnejs/module.components").ViewRenderFunc<GalleryFullPluginState>;
9
+ }
@@ -0,0 +1,8 @@
1
+ import { ModuleView } from "@vnejs/module.components";
2
+ import { render } from "../view/index.js";
3
+ export class GalleryFullView extends ModuleView {
4
+ name = "gallery.full.view";
5
+ EVENT_UPDATE_VIEW = this.EVENTS.GALLERY_FULL_VIEW.UPDATE;
6
+ TRANSITION = this.PARAMS.GALLERY_FULL_VIEW.TRANSITION;
7
+ renderFunc = render;
8
+ }
@@ -0,0 +1,23 @@
1
+ import type { ModuleComponentsConstants, ModuleComponentsEvents, ModuleComponentsParams, ModuleComponentsSettings } from "@vnejs/module.components";
2
+ import type { Constants as LayerBgConstants, PluginName as LayerBgPluginName, SubscribeEvents as LayerBgSubscribeEvents } from "@vnejs/contracts.canvas.child.bg";
3
+ import type { SettingsKeys as LayerSettingsKeys, PluginName as LayerPluginName } from "@vnejs/contracts.canvas.layer";
4
+ import type { PluginName as GalleryPluginName, SubscribeEvents as GallerySubscribeEvents } from "@vnejs/contracts.controllers.screens.gallery";
5
+ import type { GalleryFullImageSrcItem, GalleryFullVariant, Params, PluginName, SubscribeEvents } from "@vnejs/contracts.controllers.screens.gallery.full";
6
+ import type { Constants as ControlsConstants, PluginName as ControlsPluginName } from "@vnejs/contracts.controls";
7
+ export type GalleryFullPluginEvents = ModuleComponentsEvents & Record<PluginName, SubscribeEvents> & Record<GalleryPluginName, GallerySubscribeEvents> & Record<LayerBgPluginName, LayerBgSubscribeEvents>;
8
+ export type GalleryFullPluginConstants = ModuleComponentsConstants & Record<ControlsPluginName, ControlsConstants> & Record<LayerBgPluginName, LayerBgConstants>;
9
+ export type GalleryFullPluginSettings = ModuleComponentsSettings & Record<LayerPluginName, LayerSettingsKeys>;
10
+ export type GalleryFullPluginParams = ModuleComponentsParams & Record<PluginName, Params>;
11
+ export type GalleryFullPluginState = {
12
+ isShow: boolean;
13
+ isForce: boolean;
14
+ imageSrc?: string | GalleryFullImageSrcItem[];
15
+ isAllSrcRendered?: boolean;
16
+ withBackgroundBlur?: boolean;
17
+ pageIndex?: number;
18
+ pagesCount?: number;
19
+ itemFullName?: string;
20
+ itemMediaType?: string;
21
+ itemLayerChildType?: string;
22
+ variants?: GalleryFullVariant[];
23
+ };
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,16 @@
1
+ import type { GalleryFullImageSrcItem, GalleryFullShowPayload, GalleryFullVariant } from "@vnejs/contracts.controllers.screens.gallery.full";
2
+ export type { GalleryFullImageSrcItem };
3
+ export type GalleryControllerGlobalItem = {
4
+ fullName?: string;
5
+ mediaType?: string;
6
+ layerChildType?: string;
7
+ isOpened?: boolean;
8
+ variants?: GalleryFullVariant[];
9
+ };
10
+ export type GalleryControllerGlobalState = {
11
+ currentItems?: GalleryControllerGlobalItem[];
12
+ };
13
+ export declare const toGalleryMediaName: (name?: string, layerChildType?: string) => string;
14
+ export declare const getItemFromPayload: ({ index, fullName, mediaType, layerChildType, isOpened, variants }?: GalleryFullShowPayload, galleryState?: unknown) => GalleryControllerGlobalItem;
15
+ export declare const getItemVariants: (item?: GalleryControllerGlobalItem) => GalleryFullVariant[];
16
+ export declare const toImageSrc: (src: unknown) => string | GalleryFullImageSrcItem[];
@@ -0,0 +1,21 @@
1
+ export const toGalleryMediaName = (name = "", layerChildType) => (layerChildType ? `${layerChildType}/${name}` : name);
2
+ export const getItemFromPayload = ({ index = 0, fullName, mediaType, layerChildType, isOpened, variants } = {}, galleryState) => {
3
+ if (fullName || mediaType || variants?.length)
4
+ return { fullName, mediaType, layerChildType, isOpened, variants };
5
+ return galleryState?.currentItems?.[index] ?? {};
6
+ };
7
+ export const getItemVariants = (item = {}) => {
8
+ if (item.variants?.length)
9
+ return item.variants;
10
+ const { isOpened = false, layerChildType, fullName } = item;
11
+ return fullName || item.mediaType ? [{ isOpened, layerChildType, name: fullName }] : [];
12
+ };
13
+ export const toImageSrc = (src) => {
14
+ if (typeof src === "string")
15
+ return src;
16
+ if (Array.isArray(src)) {
17
+ const items = src.map((item) => ({ url: item.url, duration: 0, transition: 0 }));
18
+ return items.length === 1 ? items[0].url : items;
19
+ }
20
+ return "";
21
+ };
@@ -0,0 +1,3 @@
1
+ import type { ViewRenderFunc } from "@vnejs/module.components";
2
+ import type { GalleryFullPluginState } from "../types.js";
3
+ export declare const render: ViewRenderFunc<GalleryFullPluginState>;
@@ -0,0 +1,10 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Image, PageSelector, PositionBox, Screen, Svg, createRenderFunc, useStoreState } from "@vnejs/uis.react";
3
+ const LOCKED_FILTER = "blur(var(--vne-screen-blur))";
4
+ const GalleryFull = ({ store, onMount, PARAMS, emit, EVENTS }) => {
5
+ const { isShow = false, imageSrc = "", isAllSrcRendered = false, withBackgroundBlur = false, pageIndex = 0, pagesCount = 0, } = useStoreState(store, onMount);
6
+ const propsView = PARAMS.GALLERY_FULL_VIEW.VIEW_PROPS;
7
+ const showPages = pagesCount > 1;
8
+ return (_jsxs(Screen, { ...propsView.screen, isShow: isShow, isDisableAutoread: isShow, children: [_jsx(Image, { ...propsView.image, src: imageSrc, isAllSrcRendered: isAllSrcRendered, isSwitchDisabled: true, transition: propsView.image.transition, filter: withBackgroundBlur ? LOCKED_FILTER : undefined }), _jsx(PositionBox, { ...propsView.close.position, children: _jsx(Svg.Cross, { ...propsView.close.props, onClick: () => void emit(EVENTS.GALLERY_FULL_VIEW.HIDE) }) }), _jsx(PositionBox, { ...propsView.pages.position, isNotRender: !showPages, children: _jsx(PageSelector, { onPrevPage: () => void emit(EVENTS.GALLERY_FULL_VIEW.PREV), onNextPage: () => void emit(EVENTS.GALLERY_FULL_VIEW.NEXT), pagesCount: pagesCount, page: pageIndex + 1, pagesMinCount: 1 }) })] }));
9
+ };
10
+ export const render = createRenderFunc(GalleryFull);
package/package.json CHANGED
@@ -1,6 +1,65 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.controllers.screens.gallery.full",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.18",
4
+ "description": "",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js",
11
+ "require": "./dist/index.js",
12
+ "default": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "src",
18
+ "tsconfig.json"
19
+ ],
20
+ "scripts": {
21
+ "test": "npx @vnejs/monorepo test",
22
+ "build": "npx @vnejs/monorepo package",
23
+ "publish:major:plugin": "npm run publish:major",
24
+ "publish:minor:plugin": "npm run publish:minor",
25
+ "publish:patch:plugin": "npm run publish:patch",
26
+ "publish:major": "npx @vnejs/monorepo publish major --access public",
27
+ "publish:minor": "npx @vnejs/monorepo publish minor --access public",
28
+ "publish:patch": "npx @vnejs/monorepo publish patch --access public"
29
+ },
30
+ "author": "",
31
+ "license": "ISC",
32
+ "dependencies": {
33
+ "@vnejs/contracts.controllers.screens.gallery.full": "~0.2.0"
34
+ },
35
+ "peerDependencies": {
36
+ "@vnejs/module.core": "~0.2.0",
37
+ "@vnejs/module.components": "~0.2.0",
38
+ "@vnejs/module.controller.arrows.horizontal": "~0.2.0",
39
+ "@vnejs/module.controller.pages": "~0.2.0",
40
+ "@vnejs/module.controller.hide.on.controls": "~0.2.0",
41
+ "@vnejs/contracts.canvas.child.bg": "~0.2.0",
42
+ "@vnejs/contracts.canvas.layer": "~0.2.0",
43
+ "@vnejs/contracts.controls": "~0.2.0",
44
+ "@vnejs/contracts.controllers.screens.gallery": "~0.2.0",
45
+ "@vnejs/registry": "~0.2.0",
46
+ "@vnejs/uis.react": "~0.2.0"
47
+ },
48
+ "devDependencies": {
49
+ "@vnejs/configs.ts-common": "~0.2.0",
50
+ "@vnejs/configs.vitest": "~0.2.0",
51
+ "@vnejs/test-utils": "~0.2.0",
52
+ "@vnejs/contracts.canvas.child.bg": "~0.2.0",
53
+ "@vnejs/contracts.canvas.layer": "~0.2.0",
54
+ "@vnejs/contracts.controls": "~0.2.0",
55
+ "@vnejs/contracts.controllers.screens.gallery": "~0.2.0",
56
+ "@vnejs/contracts.controllers.screens.gallery.full": "~0.2.0",
57
+ "@vnejs/module.core": "~0.2.0",
58
+ "@vnejs/module.components": "~0.2.0",
59
+ "@vnejs/module.controller.arrows.horizontal": "~0.2.0",
60
+ "@vnejs/module.controller.pages": "~0.2.0",
61
+ "@vnejs/module.controller.hide.on.controls": "~0.2.0",
62
+ "@vnejs/registry": "~0.2.0",
63
+ "@vnejs/uis.react": "~0.2.0"
64
+ }
65
+ }
package/src/index.ts ADDED
@@ -0,0 +1,26 @@
1
+ import "@vnejs/contracts.canvas.child.bg";
2
+ import "@vnejs/contracts.controllers.screens.gallery.full";
3
+
4
+ import { regPlugin } from "@vnejs/registry";
5
+
6
+ import { PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/contracts.controllers.screens.gallery.full";
7
+
8
+ import { GalleryFullViewBridge } from "./modules/bridge.js";
9
+ import { GalleryFullViewControllerArrows } from "./modules/controller.arrows.js";
10
+ import { GalleryFullViewController } from "./modules/controller.js";
11
+ import { GalleryFullViewHideControls } from "./modules/hide.controls.js";
12
+ import { GalleryFullViewLoad } from "./modules/load.js";
13
+ import { GalleryFullViewLoadSrc } from "./modules/load.src.js";
14
+ import { GalleryFullViewVariation } from "./modules/variation.js";
15
+ import { GalleryFullView } from "./modules/view.js";
16
+
17
+ regPlugin(PLUGIN_NAME, { events: SUBSCRIBE_EVENTS, params: PARAMS }, [
18
+ GalleryFullViewBridge,
19
+ GalleryFullViewController,
20
+ GalleryFullViewControllerArrows,
21
+ GalleryFullViewHideControls,
22
+ GalleryFullViewLoad,
23
+ GalleryFullViewLoadSrc,
24
+ GalleryFullViewVariation,
25
+ GalleryFullView,
26
+ ]);
@@ -0,0 +1,21 @@
1
+ import { ModuleCore } from "@vnejs/module.core";
2
+
3
+ import type { GalleryFullChoosePayload } from "@vnejs/contracts.controllers.screens.gallery.full";
4
+
5
+ import { getItemFromPayload } from "../utils/gallery.full.js";
6
+
7
+ import type { GalleryFullPluginConstants, GalleryFullPluginEvents, GalleryFullPluginParams, GalleryFullPluginSettings } from "../types.js";
8
+
9
+ export class GalleryFullViewBridge extends ModuleCore<GalleryFullPluginEvents, GalleryFullPluginConstants, GalleryFullPluginSettings, GalleryFullPluginParams> {
10
+ name = "gallery.full.view.bridge";
11
+
12
+ subscribe = () => {
13
+ this.on(this.EVENTS.GALLERY.CHOOSE, this.onGalleryChoose);
14
+ };
15
+
16
+ onGalleryChoose = (payload: GalleryFullChoosePayload = {}) => {
17
+ const item = getItemFromPayload(payload, this.globalState?.["gallery.controller"]);
18
+
19
+ if (item.isOpened) return this.emit(this.EVENTS.GALLERY_FULL_VIEW.SHOW, payload);
20
+ };
21
+ }
@@ -0,0 +1,22 @@
1
+ import { ModuleControllerArrowsHorizontal } from "@vnejs/module.controller.arrows.horizontal";
2
+
3
+ import type { GalleryFullPluginConstants, GalleryFullPluginEvents, GalleryFullPluginParams, GalleryFullPluginSettings } from "../types.js";
4
+
5
+ export class GalleryFullViewControllerArrows extends ModuleControllerArrowsHorizontal<
6
+ GalleryFullPluginEvents,
7
+ GalleryFullPluginConstants,
8
+ GalleryFullPluginSettings,
9
+ GalleryFullPluginParams
10
+ > {
11
+ name = "gallery.full.view.controller.arrows";
12
+
13
+ EVENT_SHOW = this.EVENTS.GALLERY_FULL_VIEW.SHOW;
14
+ EVENT_HIDE = this.EVENTS.GALLERY_FULL_VIEW.HIDE;
15
+ EVENT_UPDATE_STATE = this.EVENTS.GALLERY_FULL_VIEW.UPDATE_STATE;
16
+ EVENT_UPDATE_FAST = this.EVENTS.GALLERY_FULL_VIEW.UPDATE_FAST;
17
+
18
+ CONTROLS_ZINDEX = this.PARAMS.GALLERY_FULL_VIEW.ZINDEX;
19
+
20
+ onArrowLeft = () => void this.emit(this.EVENTS.GALLERY_FULL_VIEW.PREV);
21
+ onArrowRight = () => void this.emit(this.EVENTS.GALLERY_FULL_VIEW.NEXT);
22
+ }
@@ -0,0 +1,43 @@
1
+ import { ModuleController } from "@vnejs/module.components";
2
+
3
+ import type { GalleryFullShowPayload } from "@vnejs/contracts.controllers.screens.gallery.full";
4
+
5
+ import { getItemFromPayload, getItemVariants } from "../utils/gallery.full.js";
6
+
7
+ import type { GalleryFullPluginConstants, GalleryFullPluginEvents, GalleryFullPluginParams, GalleryFullPluginSettings } from "../types.js";
8
+ import type { GalleryFullPluginState } from "../types.js";
9
+
10
+ export class GalleryFullViewController extends ModuleController<
11
+ GalleryFullPluginEvents,
12
+ GalleryFullPluginConstants,
13
+ GalleryFullPluginSettings,
14
+ GalleryFullPluginParams,
15
+ GalleryFullPluginState
16
+ > {
17
+ name = "gallery.full.view.controller";
18
+
19
+ EVENT_UPDATE_VIEW = this.EVENTS.GALLERY_FULL_VIEW.UPDATE;
20
+ EVENT_UPDATE_STATE = this.EVENTS.GALLERY_FULL_VIEW.UPDATE_STATE;
21
+ EVENT_UPDATE_FAST = this.EVENTS.GALLERY_FULL_VIEW.UPDATE_FAST;
22
+ EVENT_UPDATE_FORCE = this.EVENTS.GALLERY_FULL_VIEW.UPDATE_FORCE;
23
+ EVENT_SHOW = this.EVENTS.GALLERY_FULL_VIEW.SHOW;
24
+ EVENT_HIDE = this.EVENTS.GALLERY_FULL_VIEW.HIDE;
25
+
26
+ CONTROLS = {};
27
+ CONTROLS_INDEX = this.PARAMS.GALLERY_FULL_VIEW.ZINDEX;
28
+
29
+ onHideAfter = () => this.emit(this.EVENT_UPDATE_STATE, { itemFullName: "", itemMediaType: "", itemLayerChildType: "", variants: [] });
30
+
31
+ onShowBefore = async (args = {}) => {
32
+ const item = getItemFromPayload(args as GalleryFullShowPayload, this.globalState?.["gallery.controller"]);
33
+
34
+ await this.emit(this.EVENT_UPDATE_STATE, {
35
+ itemFullName: item.fullName ?? "",
36
+ itemMediaType: item.mediaType ?? "",
37
+ itemLayerChildType: item.layerChildType ?? "",
38
+ variants: getItemVariants(item),
39
+ });
40
+
41
+ return this.emit(this.EVENTS.GALLERY_FULL_VIEW.LOAD, { pageIndex: 0 });
42
+ };
43
+ }
@@ -0,0 +1,17 @@
1
+ import { ModuleControllerHideOnControls } from "@vnejs/module.controller.hide.on.controls";
2
+
3
+ import type { GalleryFullPluginConstants, GalleryFullPluginEvents, GalleryFullPluginParams, GalleryFullPluginSettings } from "../types.js";
4
+
5
+ export class GalleryFullViewHideControls extends ModuleControllerHideOnControls<
6
+ GalleryFullPluginEvents,
7
+ GalleryFullPluginConstants,
8
+ GalleryFullPluginSettings,
9
+ GalleryFullPluginParams
10
+ > {
11
+ name = "gallery.full.view.hide.controls";
12
+
13
+ EVENT_SHOW = this.EVENTS.GALLERY_FULL_VIEW.SHOW;
14
+ EVENT_HIDE = this.EVENTS.GALLERY_FULL_VIEW.HIDE;
15
+
16
+ CONTROLS_ZINDEX = this.PARAMS.GALLERY_FULL_VIEW.ZINDEX;
17
+ }
@@ -0,0 +1,50 @@
1
+ import { ModuleCore } from "@vnejs/module.core";
2
+
3
+ import type { MediaLoadPayload } from "@vnejs/module.components";
4
+
5
+ import type { GalleryFullLoadSrcPayload } from "@vnejs/contracts.controllers.screens.gallery.full";
6
+
7
+ import { toGalleryMediaName, toImageSrc } from "../utils/gallery.full.js";
8
+
9
+ import type { GalleryFullPluginConstants, GalleryFullPluginEvents, GalleryFullPluginParams, GalleryFullPluginSettings } from "../types.js";
10
+ import type { GalleryFullPluginState } from "../types.js";
11
+
12
+ export class GalleryFullViewLoadSrc extends ModuleCore<
13
+ GalleryFullPluginEvents,
14
+ GalleryFullPluginConstants,
15
+ GalleryFullPluginSettings,
16
+ GalleryFullPluginParams,
17
+ GalleryFullPluginState
18
+ > {
19
+ name = "gallery.full.view.load.src";
20
+
21
+ subscribe = () => {
22
+ this.on(this.EVENTS.GALLERY_FULL_VIEW.LOAD_SRC, this.onLoadSrc);
23
+ this.on(this.EVENTS.GALLERY_FULL_VIEW.UPDATE_STATE, this.updateState);
24
+ };
25
+
26
+ onLoadSrc = async (payload: GalleryFullLoadSrcPayload = {}) => {
27
+ const { name, overlays, layerChildType } = payload;
28
+ const [srcGetEvent, bgLayerChildType] = [this.EVENTS.LAYER_BG?.SRC_GET, this.CONST.LAYER_BG?.LAYER_CHILD_TYPE ?? "bg"];
29
+
30
+ if (layerChildType === bgLayerChildType && name)
31
+ return srcGetEvent ? toImageSrc(await this.emitOne(srcGetEvent, { name, args: overlays !== undefined ? { overlays } : {} })) : "";
32
+
33
+ return name ? this.loadMediaByName(name, layerChildType) : this.loadMediaByName(this.state.itemFullName ?? "", this.state.itemLayerChildType || undefined);
34
+ };
35
+
36
+ loadImageMedia = (name: string, mediaType: string, quality: string | number): Promise<HTMLImageElement> => {
37
+ const [type, priority] = [this.CONST.MEDIA.TYPES.IMAGE, this.CONST.MEDIA.PRIORITIES.HIGH];
38
+
39
+ return this.emitOne(this.EVENTS.MEDIA.LOAD, { type, priority, quality, name, mediaType } satisfies MediaLoadPayload) as Promise<HTMLImageElement>;
40
+ };
41
+ loadMediaByName = async (name = "", layerChildType?: string, mediaType = this.state.itemMediaType ?? "") => {
42
+ const mediaName = toGalleryMediaName(name, layerChildType);
43
+
44
+ if (!mediaName) return "";
45
+
46
+ const media = await this.loadImageMedia(mediaName, mediaType, this.shared.settings[this.SETTINGS.LAYER.QUALITY]);
47
+
48
+ return media?.src ?? "";
49
+ };
50
+ }
@@ -0,0 +1,33 @@
1
+ import { ModuleCore } from "@vnejs/module.core";
2
+
3
+ import type { GalleryFullLoadPayload } from "@vnejs/contracts.controllers.screens.gallery.full";
4
+
5
+ import type { GalleryFullPluginConstants, GalleryFullPluginEvents, GalleryFullPluginParams, GalleryFullPluginSettings } from "../types.js";
6
+ import type { GalleryFullPluginState } from "../types.js";
7
+
8
+ export class GalleryFullViewLoad extends ModuleCore<
9
+ GalleryFullPluginEvents,
10
+ GalleryFullPluginConstants,
11
+ GalleryFullPluginSettings,
12
+ GalleryFullPluginParams,
13
+ GalleryFullPluginState
14
+ > {
15
+ name = "gallery.full.view.load";
16
+
17
+ subscribe = () => {
18
+ this.on(this.EVENTS.GALLERY_FULL_VIEW.LOAD, this.onLoad);
19
+ this.on(this.EVENTS.GALLERY_FULL_VIEW.UPDATE_STATE, this.updateState);
20
+ };
21
+
22
+ onLoad = async ({ pageIndex = 0 }: GalleryFullLoadPayload = {}) => {
23
+ const variants = this.state.variants ?? [];
24
+
25
+ if (pageIndex < 0 || pageIndex >= variants.length) return;
26
+
27
+ const variant = variants[pageIndex] ?? {};
28
+ const imageSrc = variant.isOpened ? ((await this.emitOne(this.EVENTS.GALLERY_FULL_VIEW.LOAD_SRC, variant)) ?? "") : "";
29
+ const [pagesCount, withBackgroundBlur, isAllSrcRendered] = [variants.length, !variant.isOpened, Array.isArray(imageSrc) && imageSrc.length > 1];
30
+
31
+ return this.emit(this.EVENTS.GALLERY_FULL_VIEW.UPDATE_STATE, { pageIndex, pagesCount, withBackgroundBlur, imageSrc, isAllSrcRendered });
32
+ };
33
+ }