@oinone/kunlun-environment 6.2.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.
- package/dist/oinone-kunlun-environment.esm.js +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/src/env/constant.d.ts +2 -0
- package/dist/types/src/env/index.d.ts +4 -0
- package/dist/types/src/env/manager.d.ts +14 -0
- package/dist/types/src/env/method/getContentHTMLElement.d.ts +2 -0
- package/dist/types/src/env/method/index.d.ts +1 -0
- package/dist/types/src/env/typing.d.ts +22 -0
- package/dist/types/src/env/utils.d.ts +2 -0
- package/dist/types/src/framework/index.d.ts +1 -0
- package/dist/types/src/framework/typing.d.ts +5 -0
- package/dist/types/src/index.d.ts +4 -0
- package/dist/types/src/instance/index.d.ts +3 -0
- package/dist/types/src/instance/typing.d.ts +14 -0
- package/dist/types/src/spi/framework.d.ts +1 -0
- package/dist/types/src/spi/index.d.ts +1 -0
- package/dist/types/src/spi/instance.d.ts +4 -0
- package/index.ts +1 -0
- package/package.json +18 -0
- package/rollup.config.js +4 -0
- package/src/env/constant.ts +3 -0
- package/src/env/index.ts +4 -0
- package/src/env/manager.ts +87 -0
- package/src/env/method/getContentHTMLElement.ts +10 -0
- package/src/env/method/index.ts +1 -0
- package/src/env/typing.ts +27 -0
- package/src/env/utils.ts +41 -0
- package/src/framework/index.ts +1 -0
- package/src/framework/typing.ts +6 -0
- package/src/index.ts +4 -0
- package/src/instance/index.ts +8 -0
- package/src/instance/typing.ts +18 -0
- package/src/spi/framework.ts +1 -0
- package/src/spi/index.ts +1 -0
- package/src/spi/instance.ts +20 -0
|
@@ -0,0 +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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './src';
|
|
@@ -0,0 +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;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './getContentHTMLElement';
|
|
@@ -0,0 +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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './typing';
|
|
@@ -0,0 +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;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './instance';
|
|
@@ -0,0 +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;
|
package/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './src';
|
package/package.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@oinone/kunlun-environment",
|
|
3
|
+
"version": "6.2.0",
|
|
4
|
+
"main": "index.ts",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"prebuild": "rimraf dist",
|
|
7
|
+
"build": "rollup -c",
|
|
8
|
+
"dist": "npm run prepublishOnly",
|
|
9
|
+
"index": "npm run postpublish",
|
|
10
|
+
"x-prepublishOnly": "node ../../scripts/prepublish-only.js",
|
|
11
|
+
"x-postpublish": "node ../../scripts/postpublish.js"
|
|
12
|
+
},
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"@oinone/kunlun-shared": "6.2.0",
|
|
15
|
+
"@oinone/kunlun-spi": "6.2.0"
|
|
16
|
+
},
|
|
17
|
+
"gitHead": "b65bbf1d649da1017810c5608473d5daa1a41f94"
|
|
18
|
+
}
|
package/rollup.config.js
ADDED
package/src/env/index.ts
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { Manager, ObjectUtils } from '@oinone/kunlun-shared';
|
|
2
|
+
import { CONTENT_NULL_SELECTOR } from './constant';
|
|
3
|
+
import { getContentHTMLElement } from './method';
|
|
4
|
+
import { RuntimeEnvironment, VisibleArea } from './typing';
|
|
5
|
+
import { createVisibleArea } from './utils';
|
|
6
|
+
|
|
7
|
+
const runtimeEnvironmentMethods: Record<string, Function> = {
|
|
8
|
+
getContentHTMLElement
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
class InternalRuntimeEnvironmentManager extends Manager<RuntimeEnvironment> {
|
|
12
|
+
public constructor() {
|
|
13
|
+
super();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
protected generator(handle): RuntimeEnvironment {
|
|
17
|
+
const newEnv = {
|
|
18
|
+
contentSelector: CONTENT_NULL_SELECTOR,
|
|
19
|
+
mcx: 0,
|
|
20
|
+
mcy: 0,
|
|
21
|
+
st: 0,
|
|
22
|
+
sl: 0,
|
|
23
|
+
visibleArea: new Map<string, VisibleArea>(),
|
|
24
|
+
clickVisibleArea: [] as VisibleArea[]
|
|
25
|
+
} as RuntimeEnvironment;
|
|
26
|
+
const readonlyKeys: string[] = ['contentVisibleArea', 'visibleArea'];
|
|
27
|
+
for (const [method, fn] of Object.entries(runtimeEnvironmentMethods)) {
|
|
28
|
+
readonlyKeys.push(method);
|
|
29
|
+
newEnv[method] = fn.bind(newEnv);
|
|
30
|
+
}
|
|
31
|
+
newEnv.contentVisibleArea = createVisibleArea(handle, () => newEnv.getContentHTMLElement());
|
|
32
|
+
return ObjectUtils.readonly(newEnv, readonlyKeys);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export class RuntimeEnvironmentManager {
|
|
37
|
+
private static manager = new InternalRuntimeEnvironmentManager();
|
|
38
|
+
|
|
39
|
+
private static ROOT_HANDLE = '__ROOT_HANDLE__';
|
|
40
|
+
|
|
41
|
+
private static currentHandle: string = RuntimeEnvironmentManager.ROOT_HANDLE;
|
|
42
|
+
|
|
43
|
+
static {
|
|
44
|
+
RuntimeEnvironmentManager.manager.createOrReplace(RuntimeEnvironmentManager.ROOT_HANDLE);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public static getGlobalEnvironment(): RuntimeEnvironment {
|
|
48
|
+
return RuntimeEnvironmentManager.manager.get(RuntimeEnvironmentManager.ROOT_HANDLE)!;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public static getCurrentEnvironment(): RuntimeEnvironment {
|
|
52
|
+
const handle = RuntimeEnvironmentManager.currentHandle;
|
|
53
|
+
const environment = RuntimeEnvironmentManager.manager.get(handle);
|
|
54
|
+
if (!environment) {
|
|
55
|
+
throw new Error(`Invalid current environment. handle: ${handle}`);
|
|
56
|
+
}
|
|
57
|
+
return environment;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
public static get(handle: string) {
|
|
61
|
+
return RuntimeEnvironmentManager.manager.get(handle);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public static createOrReplace(handle: string, parent?: RuntimeEnvironment) {
|
|
65
|
+
return RuntimeEnvironmentManager.manager.createOrReplace(handle, parent);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
public static delete(handle: string, deep = true) {
|
|
69
|
+
RuntimeEnvironmentManager.manager.delete(handle, deep);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
public static select(handle: string) {
|
|
73
|
+
const environment = RuntimeEnvironmentManager.manager.get(handle);
|
|
74
|
+
if (!environment) {
|
|
75
|
+
throw new Error(`Invalid environment. ${handle}`);
|
|
76
|
+
}
|
|
77
|
+
this.currentHandle = handle;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function useGlobalEnv() {
|
|
82
|
+
return RuntimeEnvironmentManager.getGlobalEnvironment();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function useEnv() {
|
|
86
|
+
return RuntimeEnvironmentManager.getCurrentEnvironment();
|
|
87
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { RuntimeEnvironment } from '../typing';
|
|
2
|
+
|
|
3
|
+
export function getContentHTMLElement(this: RuntimeEnvironment): HTMLElement | undefined {
|
|
4
|
+
const { contentSelector } = this;
|
|
5
|
+
const el = document.querySelector<HTMLElement>(contentSelector);
|
|
6
|
+
if (!el) {
|
|
7
|
+
return undefined;
|
|
8
|
+
}
|
|
9
|
+
return el;
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './getContentHTMLElement';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ContextNode } from '@oinone/kunlun-shared';
|
|
2
|
+
|
|
3
|
+
export interface RuntimeEnvironment extends ContextNode<RuntimeEnvironment> {
|
|
4
|
+
contentSelector: string;
|
|
5
|
+
|
|
6
|
+
mcx: number;
|
|
7
|
+
mcy: number;
|
|
8
|
+
st: number;
|
|
9
|
+
sl: number;
|
|
10
|
+
|
|
11
|
+
contentVisibleArea: VisibleArea;
|
|
12
|
+
visibleArea: Map<string, VisibleArea>;
|
|
13
|
+
clickVisibleArea: VisibleArea[];
|
|
14
|
+
|
|
15
|
+
getContentHTMLElement(): HTMLElement | undefined;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface VisibleArea {
|
|
19
|
+
handle: string;
|
|
20
|
+
el?: HTMLElement;
|
|
21
|
+
h: number;
|
|
22
|
+
w: number;
|
|
23
|
+
x: number;
|
|
24
|
+
y: number;
|
|
25
|
+
ex: number;
|
|
26
|
+
ey: number;
|
|
27
|
+
}
|
package/src/env/utils.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { VisibleArea } from './typing';
|
|
2
|
+
|
|
3
|
+
export function createVisibleArea(handle: string, el?: HTMLElement | (() => HTMLElement | undefined)): VisibleArea {
|
|
4
|
+
const origin = { handle, el } as VisibleArea;
|
|
5
|
+
return new Proxy(origin, {
|
|
6
|
+
get(target, key, receiver) {
|
|
7
|
+
switch (key) {
|
|
8
|
+
case 'w':
|
|
9
|
+
return target.el?.getBoundingClientRect().width || 0;
|
|
10
|
+
case 'h':
|
|
11
|
+
return target.el?.getBoundingClientRect().height || 0;
|
|
12
|
+
case 'x':
|
|
13
|
+
return target.el?.getBoundingClientRect().x || 0;
|
|
14
|
+
case 'y':
|
|
15
|
+
return target.el?.getBoundingClientRect().y || 0;
|
|
16
|
+
case 'ex': {
|
|
17
|
+
const rect = target.el?.getBoundingClientRect();
|
|
18
|
+
if (!rect) {
|
|
19
|
+
return 0;
|
|
20
|
+
}
|
|
21
|
+
return rect.x + rect.width;
|
|
22
|
+
}
|
|
23
|
+
case 'ey': {
|
|
24
|
+
const rect = target.el?.getBoundingClientRect();
|
|
25
|
+
if (!rect) {
|
|
26
|
+
return 0;
|
|
27
|
+
}
|
|
28
|
+
return rect.y + rect.height;
|
|
29
|
+
}
|
|
30
|
+
case 'el': {
|
|
31
|
+
const el = Reflect.get(target, key, receiver);
|
|
32
|
+
if (typeof el === 'function') {
|
|
33
|
+
return el();
|
|
34
|
+
}
|
|
35
|
+
return el;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return Reflect.get(target, key, receiver);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './typing';
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface FrameworkInstance {
|
|
2
|
+
app: FrameworkApplication;
|
|
3
|
+
currentInstance?: FrameworkComponentInstance | null;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export interface FrameworkApplication {
|
|
7
|
+
id: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface FrameworkComponentInstance {
|
|
11
|
+
vNode: FrameworkVNode;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface FrameworkVNode {
|
|
15
|
+
el: HTMLElement;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type FrameworkInstanceGetter = () => FrameworkInstance;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/src/spi/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './instance';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { SPIOperator } from '@oinone/kunlun-spi';
|
|
2
|
+
import { FrameworkInitializeOptions } from '../framework';
|
|
3
|
+
import { FrameworkInstanceGetter } from '../instance/typing';
|
|
4
|
+
|
|
5
|
+
const CURRENT_INSTANCE_GETTER_KEY = Symbol('__current_instance_getter');
|
|
6
|
+
|
|
7
|
+
SPIOperator.createStorage({
|
|
8
|
+
key: CURRENT_INSTANCE_GETTER_KEY,
|
|
9
|
+
matchKeys: ['framework', 'isMobile']
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
export function registerCurrentInstanceGetter(options: FrameworkInitializeOptions, getter: FrameworkInstanceGetter) {
|
|
13
|
+
return SPIOperator.register(CURRENT_INSTANCE_GETTER_KEY, options, getter);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function selectorCurrentInstanceGetter(
|
|
17
|
+
options: FrameworkInitializeOptions
|
|
18
|
+
): FrameworkInstanceGetter | undefined {
|
|
19
|
+
return SPIOperator.selector(CURRENT_INSTANCE_GETTER_KEY, options);
|
|
20
|
+
}
|