@oinone/kunlun-environment 6.4.1 → 7.1.0

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.
@@ -1 +1 @@
1
- import{Manager as e,ObjectUtils as t}from"@oinone/kunlun-shared";import{SPIOperator as n}from"@oinone/kunlun-spi";const r="oio-click-activated",o="__null__";function i(e,t){return new Proxy({handle:e,el:t},{get(e,t,n){var r,o,i,c,l,a;switch(t){case"w":return(null===(r=e.el)||void 0===r?void 0:r.getBoundingClientRect().width)||0;case"h":return(null===(o=e.el)||void 0===o?void 0:o.getBoundingClientRect().height)||0;case"x":return(null===(i=e.el)||void 0===i?void 0:i.getBoundingClientRect().x)||0;case"y":return(null===(c=e.el)||void 0===c?void 0:c.getBoundingClientRect().y)||0;case"ex":{const t=null===(l=e.el)||void 0===l?void 0:l.getBoundingClientRect();return t?t.x+t.width:0}case"ey":{const t=null===(a=e.el)||void 0===a?void 0:a.getBoundingClientRect();return t?t.y+t.height:0}case"el":{const r=Reflect.get(e,t,n);return"function"==typeof r?r():r}}return Reflect.get(e,t,n)}})}const c={getContentHTMLElement:function(){const{contentSelector:e}=this,t=document.querySelector(e);if(t)return t}};class l{static getGlobalEnvironment(){return l.manager.get(l.ROOT_HANDLE)}static getCurrentEnvironment(){const e=l.currentHandle,t=l.manager.get(e);if(!t)throw new Error(`Invalid current environment. handle: ${e}`);return t}static get(e){return l.manager.get(e)}static createOrReplace(e,t){return l.manager.createOrReplace(e,t)}static delete(e,t=!0){l.manager.delete(e,t)}static select(e){if(!l.manager.get(e))throw new Error(`Invalid environment. ${e}`);this.currentHandle=e}}function a(){return l.getGlobalEnvironment()}function u(){return l.getCurrentEnvironment()}l.manager=new class extends e{constructor(){super()}generator(e){const n={contentSelector:o,mcx:0,mcy:0,st:0,sl:0,visibleArea:new Map,clickVisibleArea:[]},r=["contentVisibleArea","visibleArea"];for(const[e,t]of Object.entries(c))r.push(e),n[e]=t.bind(n);return n.contentVisibleArea=i(e,()=>n.getContentHTMLElement()),t.readonly(n,r)}},l.ROOT_HANDLE="__ROOT_HANDLE__",l.currentHandle=l.ROOT_HANDLE,l.manager.createOrReplace(l.ROOT_HANDLE);const s=Symbol("__current_instance_getter");function g(e,t){return n.register(s,e,t)}function d(e){return n.selector(s,e)}function m(){return d({framework:"vue"})()}n.createStorage({key:s,matchKeys:["framework","isMobile"]});export{r as CLICK_ACTIVATED_CLASS,o as CONTENT_NULL_SELECTOR,l as RuntimeEnvironmentManager,i as createVisibleArea,g as registerCurrentInstanceGetter,d as selectorCurrentInstanceGetter,m as useCurrentInstance,u as useEnv,a as useGlobalEnv};
1
+ import{Manager as n,ObjectUtils as e}from"@oinone/kunlun-shared";import{SPIOperator as t}from"@oinone/kunlun-spi";const r="oio-click-activated",i="__null__";function a(n,e){return new Proxy({handle:n,el:e},{get(n,t,r){let i;switch(i="function"==typeof e?e():e,t){case"w":return(null==i?void 0:i.getBoundingClientRect().width)||0;case"h":return(null==i?void 0:i.getBoundingClientRect().height)||0;case"x":return(null==i?void 0:i.getBoundingClientRect().x)||0;case"y":return(null==i?void 0:i.getBoundingClientRect().y)||0;case"ex":{const n=null==i?void 0:i.getBoundingClientRect();return n?n.x+n.width:0}case"ey":{const n=null==i?void 0:i.getBoundingClientRect();return n?n.y+n.height:0}case"el":return i}return Reflect.get(n,t,r)}})}const o={getContentHTMLElement:function(){const{contentSelector:n}=this,e=document.querySelector(n);if(e)return e}};class RuntimeEnvironmentManager{static getGlobalEnvironment(){return RuntimeEnvironmentManager.manager.get(RuntimeEnvironmentManager.ROOT_HANDLE)}static getCurrentEnvironment(){const n=RuntimeEnvironmentManager.currentHandle,e=RuntimeEnvironmentManager.manager.get(n);if(!e)throw new Error(`Invalid current environment. handle: ${n}`);return e}static get(n){return RuntimeEnvironmentManager.manager.get(n)}static createOrReplace(n,e){return RuntimeEnvironmentManager.manager.createOrReplace(n,e)}static delete(n,e=!0){RuntimeEnvironmentManager.manager.delete(n,e)}static select(n){if(!RuntimeEnvironmentManager.manager.get(n))throw new Error(`Invalid environment. ${n}`);this.currentHandle=n}}function u(){return RuntimeEnvironmentManager.getGlobalEnvironment()}function c(){return RuntimeEnvironmentManager.getCurrentEnvironment()}RuntimeEnvironmentManager.manager=new class InternalRuntimeEnvironmentManager extends n{constructor(){super()}generator(n){const t={contentSelector:i,mcx:0,mcy:0,st:0,sl:0,visibleArea:new Map,clickVisibleArea:[]},r=["contentVisibleArea","visibleArea"];for(const[n,e]of Object.entries(o))r.push(n),t[n]=e.bind(t);return t.contentVisibleArea=a(n,()=>t.getContentHTMLElement()),e.readonly(t,r)}},RuntimeEnvironmentManager.ROOT_HANDLE="__ROOT_HANDLE__",RuntimeEnvironmentManager.currentHandle=RuntimeEnvironmentManager.ROOT_HANDLE,RuntimeEnvironmentManager.manager.createOrReplace(RuntimeEnvironmentManager.ROOT_HANDLE);const m=Symbol("__current_instance_getter");function l(n,e){return t.register(m,n,e)}function g(n){return t.selector(m,n)}function s(){return g({framework:"vue"})()}t.createStorage({key:m,matchKeys:["framework","isMobile"]});export{r as CLICK_ACTIVATED_CLASS,i as CONTENT_NULL_SELECTOR,RuntimeEnvironmentManager,a as createVisibleArea,l as registerCurrentInstanceGetter,g as selectorCurrentInstanceGetter,s as useCurrentInstance,c as useEnv,u as useGlobalEnv};
@@ -1 +1 @@
1
- export * from './src';
1
+ export * from './src';
@@ -1,2 +1,2 @@
1
- export declare const CLICK_ACTIVATED_CLASS = "oio-click-activated";
2
- export declare const CONTENT_NULL_SELECTOR = "__null__";
1
+ export declare const CLICK_ACTIVATED_CLASS = "oio-click-activated";
2
+ export declare const CONTENT_NULL_SELECTOR = "__null__";
@@ -1,4 +1,4 @@
1
- export * from './constant';
2
- export * from './typing';
3
- export * from './manager';
4
- export * from './utils';
1
+ export * from './constant';
2
+ export * from './typing';
3
+ export * from './manager';
4
+ export * from './utils';
@@ -1,14 +1,14 @@
1
- import { RuntimeEnvironment } from './typing';
2
- export declare class RuntimeEnvironmentManager {
3
- private static manager;
4
- private static ROOT_HANDLE;
5
- private static currentHandle;
6
- static getGlobalEnvironment(): RuntimeEnvironment;
7
- static getCurrentEnvironment(): RuntimeEnvironment;
8
- static get(handle: string): RuntimeEnvironment | undefined;
9
- static createOrReplace(handle: string, parent?: RuntimeEnvironment): RuntimeEnvironment;
10
- static delete(handle: string, deep?: boolean): void;
11
- static select(handle: string): void;
12
- }
13
- export declare function useGlobalEnv(): RuntimeEnvironment;
14
- export declare function useEnv(): RuntimeEnvironment;
1
+ import type { RuntimeEnvironment } from './typing';
2
+ export declare class RuntimeEnvironmentManager {
3
+ private static manager;
4
+ private static ROOT_HANDLE;
5
+ private static currentHandle;
6
+ static getGlobalEnvironment(): RuntimeEnvironment;
7
+ static getCurrentEnvironment(): RuntimeEnvironment;
8
+ static get(handle: string): RuntimeEnvironment | undefined;
9
+ static createOrReplace(handle: string, parent?: RuntimeEnvironment): RuntimeEnvironment;
10
+ static delete(handle: string, deep?: boolean): void;
11
+ static select(handle: string): void;
12
+ }
13
+ export declare function useGlobalEnv(): RuntimeEnvironment;
14
+ export declare function useEnv(): RuntimeEnvironment;
@@ -1,2 +1,2 @@
1
- import { RuntimeEnvironment } from '../typing';
2
- export declare function getContentHTMLElement(this: RuntimeEnvironment): HTMLElement | undefined;
1
+ import type { RuntimeEnvironment } from '../typing';
2
+ export declare function getContentHTMLElement(this: RuntimeEnvironment): HTMLElement | undefined;
@@ -1 +1 @@
1
- export * from './getContentHTMLElement';
1
+ export * from './getContentHTMLElement';
@@ -1,22 +1,22 @@
1
- import { ContextNode } from '@oinone/kunlun-shared';
2
- export interface RuntimeEnvironment extends ContextNode<RuntimeEnvironment> {
3
- contentSelector: string;
4
- mcx: number;
5
- mcy: number;
6
- st: number;
7
- sl: number;
8
- contentVisibleArea: VisibleArea;
9
- visibleArea: Map<string, VisibleArea>;
10
- clickVisibleArea: VisibleArea[];
11
- getContentHTMLElement(): HTMLElement | undefined;
12
- }
13
- export interface VisibleArea {
14
- handle: string;
15
- el?: HTMLElement;
16
- h: number;
17
- w: number;
18
- x: number;
19
- y: number;
20
- ex: number;
21
- ey: number;
22
- }
1
+ import type { ContextNode } from '@oinone/kunlun-shared';
2
+ export interface RuntimeEnvironment extends ContextNode<RuntimeEnvironment> {
3
+ contentSelector: string;
4
+ mcx: number;
5
+ mcy: number;
6
+ st: number;
7
+ sl: number;
8
+ contentVisibleArea: VisibleArea;
9
+ visibleArea: Map<string, VisibleArea>;
10
+ clickVisibleArea: VisibleArea[];
11
+ getContentHTMLElement(): HTMLElement | undefined;
12
+ }
13
+ export interface VisibleArea {
14
+ handle: string;
15
+ el?: HTMLElement;
16
+ h: number;
17
+ w: number;
18
+ x: number;
19
+ y: number;
20
+ ex: number;
21
+ ey: number;
22
+ }
@@ -1,2 +1,2 @@
1
- import { VisibleArea } from './typing';
2
- export declare function createVisibleArea(handle: string, el?: HTMLElement | (() => HTMLElement | undefined)): VisibleArea;
1
+ import type { VisibleArea } from './typing';
2
+ export declare function createVisibleArea(handle: string, el?: HTMLElement | (() => HTMLElement | undefined)): VisibleArea;
@@ -1 +1 @@
1
- export * from './typing';
1
+ export * from './typing';
@@ -1,5 +1,5 @@
1
- import { SPIOptions } from '@oinone/kunlun-spi';
2
- export interface FrameworkInitializeOptions extends SPIOptions {
3
- framework: string;
4
- isMobile?: boolean;
5
- }
1
+ import type { SPIOptions } from '@oinone/kunlun-spi';
2
+ export interface FrameworkInitializeOptions extends SPIOptions {
3
+ framework: string;
4
+ isMobile?: boolean;
5
+ }
@@ -1,4 +1,4 @@
1
- export * from './env';
2
- export * from './framework';
3
- export * from './instance';
4
- export * from './spi';
1
+ export * from './env';
2
+ export * from './framework';
3
+ export * from './instance';
4
+ export * from './spi';
@@ -1,3 +1,3 @@
1
- import { FrameworkInstance } from './typing';
2
- export declare function useCurrentInstance(): FrameworkInstance;
3
- export * from './typing';
1
+ import type { FrameworkInstance } from './typing';
2
+ export declare function useCurrentInstance(): FrameworkInstance;
3
+ export * from './typing';
@@ -1,14 +1,14 @@
1
- export interface FrameworkInstance {
2
- app: FrameworkApplication;
3
- currentInstance?: FrameworkComponentInstance | null;
4
- }
5
- export interface FrameworkApplication {
6
- id: string;
7
- }
8
- export interface FrameworkComponentInstance {
9
- vNode: FrameworkVNode;
10
- }
11
- export interface FrameworkVNode {
12
- el: HTMLElement;
13
- }
14
- export declare type FrameworkInstanceGetter = () => FrameworkInstance;
1
+ export interface FrameworkInstance {
2
+ app: FrameworkApplication;
3
+ currentInstance?: FrameworkComponentInstance | null;
4
+ }
5
+ export interface FrameworkApplication {
6
+ id: string;
7
+ }
8
+ export interface FrameworkComponentInstance {
9
+ vNode: FrameworkVNode;
10
+ }
11
+ export interface FrameworkVNode {
12
+ el: HTMLElement;
13
+ }
14
+ export type FrameworkInstanceGetter = () => FrameworkInstance;
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1 +1 @@
1
- export * from './instance';
1
+ export * from './instance';
@@ -1,4 +1,4 @@
1
- import { FrameworkInitializeOptions } from '../framework';
2
- import { FrameworkInstanceGetter } from '../instance/typing';
3
- export declare function registerCurrentInstanceGetter(options: FrameworkInitializeOptions, getter: FrameworkInstanceGetter): boolean;
4
- export declare function selectorCurrentInstanceGetter(options: FrameworkInitializeOptions): FrameworkInstanceGetter | undefined;
1
+ import type { FrameworkInitializeOptions } from '../framework';
2
+ import type { FrameworkInstanceGetter } from '../instance/typing';
3
+ export declare function registerCurrentInstanceGetter(options: FrameworkInitializeOptions, getter: FrameworkInstanceGetter): boolean;
4
+ export declare function selectorCurrentInstanceGetter(options: FrameworkInitializeOptions): FrameworkInstanceGetter | undefined;
package/package.json CHANGED
@@ -1,18 +1,29 @@
1
1
  {
2
2
  "name": "@oinone/kunlun-environment",
3
- "version": "6.4.1",
4
- "main": "index.ts",
3
+ "version": "7.1.0",
4
+ "type": "module",
5
+ "main": "dist/oinone-kunlun-environment.esm.js",
5
6
  "scripts": {
6
7
  "prebuild": "rimraf dist",
7
8
  "build": "rollup -c",
8
9
  "dist": "npm run prepublishOnly",
9
10
  "index": "npm run postpublish",
10
- "x-prepublishOnly": "node ../../scripts/prepublish-only.js",
11
- "x-postpublish": "node ../../scripts/postpublish.js"
11
+ "format": "prettier --write --experimental-cli src/",
12
+ "test": "jest",
13
+ "prepublishOnly": "node ../../../../scripts/prepublish-only.cjs",
14
+ "deploy": "npm publish --exact",
15
+ "postpublish": "node ../../../../scripts/postpublish.cjs"
12
16
  },
13
17
  "devDependencies": {
14
- "@oinone/kunlun-shared": "6.4.1",
15
- "@oinone/kunlun-spi": "6.4.1"
18
+ "@oinone/kunlun-shared": "7.1.0",
19
+ "@oinone/kunlun-spi": "7.1.0"
16
20
  },
17
- "gitHead": "2b4c0c7911626c105ca71c2d41e54af470e2e079"
18
- }
21
+ "gitHead": "2b4c0c7911626c105ca71c2d41e54af470e2e079",
22
+ "module": "dist/oinone-kunlun-environment.esm.js",
23
+ "typings": "dist/types/index.d.ts",
24
+ "files": [
25
+ "dist",
26
+ "index.ts",
27
+ "src"
28
+ ]
29
+ }
@@ -1,7 +1,7 @@
1
1
  import { Manager, ObjectUtils } from '@oinone/kunlun-shared';
2
2
  import { CONTENT_NULL_SELECTOR } from './constant';
3
3
  import { getContentHTMLElement } from './method';
4
- import { RuntimeEnvironment, VisibleArea } from './typing';
4
+ import type { RuntimeEnvironment, VisibleArea } from './typing';
5
5
  import { createVisibleArea } from './utils';
6
6
 
7
7
  const runtimeEnvironmentMethods: Record<string, Function> = {
@@ -1,4 +1,4 @@
1
- import { RuntimeEnvironment } from '../typing';
1
+ import type { RuntimeEnvironment } from '../typing';
2
2
 
3
3
  export function getContentHTMLElement(this: RuntimeEnvironment): HTMLElement | undefined {
4
4
  const { contentSelector } = this;
package/src/env/typing.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ContextNode } from '@oinone/kunlun-shared';
1
+ import type { ContextNode } from '@oinone/kunlun-shared';
2
2
 
3
3
  export interface RuntimeEnvironment extends ContextNode<RuntimeEnvironment> {
4
4
  contentSelector: string;
package/src/env/utils.ts CHANGED
@@ -1,38 +1,40 @@
1
- import { VisibleArea } from './typing';
1
+ import type { VisibleArea } from './typing';
2
2
 
3
3
  export function createVisibleArea(handle: string, el?: HTMLElement | (() => HTMLElement | undefined)): VisibleArea {
4
4
  const origin = { handle, el } as VisibleArea;
5
5
  return new Proxy(origin, {
6
6
  get(target, key, receiver) {
7
+ let tel: HTMLElement | undefined;
8
+ if (typeof el === 'function') {
9
+ tel = el();
10
+ } else {
11
+ tel = el;
12
+ }
7
13
  switch (key) {
8
14
  case 'w':
9
- return target.el?.getBoundingClientRect().width || 0;
15
+ return tel?.getBoundingClientRect().width || 0;
10
16
  case 'h':
11
- return target.el?.getBoundingClientRect().height || 0;
17
+ return tel?.getBoundingClientRect().height || 0;
12
18
  case 'x':
13
- return target.el?.getBoundingClientRect().x || 0;
19
+ return tel?.getBoundingClientRect().x || 0;
14
20
  case 'y':
15
- return target.el?.getBoundingClientRect().y || 0;
21
+ return tel?.getBoundingClientRect().y || 0;
16
22
  case 'ex': {
17
- const rect = target.el?.getBoundingClientRect();
23
+ const rect = tel?.getBoundingClientRect();
18
24
  if (!rect) {
19
25
  return 0;
20
26
  }
21
27
  return rect.x + rect.width;
22
28
  }
23
29
  case 'ey': {
24
- const rect = target.el?.getBoundingClientRect();
30
+ const rect = tel?.getBoundingClientRect();
25
31
  if (!rect) {
26
32
  return 0;
27
33
  }
28
34
  return rect.y + rect.height;
29
35
  }
30
36
  case 'el': {
31
- const el = Reflect.get(target, key, receiver);
32
- if (typeof el === 'function') {
33
- return el();
34
- }
35
- return el;
37
+ return tel;
36
38
  }
37
39
  }
38
40
  return Reflect.get(target, key, receiver);
@@ -1,4 +1,4 @@
1
- import { SPIOptions } from '@oinone/kunlun-spi';
1
+ import type { SPIOptions } from '@oinone/kunlun-spi';
2
2
 
3
3
  export interface FrameworkInitializeOptions extends SPIOptions {
4
4
  framework: string;
@@ -1,5 +1,5 @@
1
1
  import { selectorCurrentInstanceGetter } from '../spi';
2
- import { FrameworkInstance } from './typing';
2
+ import type { FrameworkInstance } from './typing';
3
3
 
4
4
  export function useCurrentInstance(): FrameworkInstance {
5
5
  return selectorCurrentInstanceGetter({ framework: 'vue' })!();
@@ -1,6 +1,6 @@
1
1
  import { SPIOperator } from '@oinone/kunlun-spi';
2
- import { FrameworkInitializeOptions } from '../framework';
3
- import { FrameworkInstanceGetter } from '../instance/typing';
2
+ import type { FrameworkInitializeOptions } from '../framework';
3
+ import type { FrameworkInstanceGetter } from '../instance/typing';
4
4
 
5
5
  const CURRENT_INSTANCE_GETTER_KEY = Symbol('__current_instance_getter');
6
6
 
package/rollup.config.js DELETED
@@ -1,4 +0,0 @@
1
- import pkg from './package.json';
2
- import rollupConfig from '../../scripts/build.config.js';
3
-
4
- export default rollupConfig(pkg.name, ['@oinone/kunlun-shared', '@oinone/kunlun-spi']);