@zcomponent/core 0.0.4 → 0.0.6

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.
@@ -32,4 +32,63 @@
32
32
  background-color: white;
33
33
  height: 12px;
34
34
  border-radius: 6px;
35
+ }
36
+
37
+ #zcomponent-overlay {
38
+ position: fixed;
39
+ top: 0;
40
+ left: 0;
41
+ pointer-events: none;
42
+ overflow: hidden;
43
+ }
44
+
45
+ #zcomponent-overlay > * {
46
+ pointer-events: auto;
47
+ position: absolute;
48
+ }
49
+
50
+
51
+ .zcomponent-align {
52
+ position: absolute;
53
+ transform-origin: 0 0;
54
+ }
55
+
56
+ .zcomponent-h-left {
57
+ left: 0px;
58
+ }
59
+
60
+ .zcomponent-h-center {
61
+ left: 50%;
62
+ }
63
+
64
+ .zcomponent-h-right {
65
+ right: 0px;
66
+ }
67
+
68
+ .zcomponent-v-top {
69
+ top: 0px;
70
+ }
71
+
72
+ .zcomponent-v-center {
73
+ top: 50%;
74
+ }
75
+
76
+ .zcomponent-v-bottom {
77
+ bottom: 0px;
78
+ }
79
+
80
+ .zcomponent-hc-v {
81
+ transform: translate(-50%, 0);
82
+ }
83
+
84
+ .zcomponent-h-vc {
85
+ transform: translate(0%, -50%);
86
+ }
87
+
88
+ .zcomponent-h-v {
89
+ transform: translate(0%, 0%);
90
+ }
91
+
92
+ .zcomponent-hc-vc {
93
+ transform: translate(-50%, -50%);
35
94
  }
@@ -0,0 +1,45 @@
1
+ import { Component, ConstructorProps, ContextManager } from "..";
2
+ export interface LongLoadConstructorProps extends ConstructorProps {
3
+ /**
4
+ * The number of loading processes to simulate
5
+ * @zprop
6
+ * @zgroup LongLoad
7
+ * @zgrouppriority 10
8
+ * @zdefault 10
9
+ */
10
+ numberOfLoads: number;
11
+ /**
12
+ * The shortest time (in milliseconds) that a given load should take
13
+ * @zprop
14
+ * @zgroup LongLoad
15
+ * @zgrouppriority 10
16
+ * @zdefault 500
17
+ */
18
+ minimumLoadTime: number;
19
+ /**
20
+ * The shortest time (in milliseconds) that a given load should take
21
+ * @zprop
22
+ * @zgroup LongLoad
23
+ * @zgrouppriority 10
24
+ * @zdefault 5000
25
+ */
26
+ maximumLoadTime: number;
27
+ /**
28
+ * If the long loading process should occur in production builds (in addition to development builds)
29
+ * @zprop
30
+ * @zgroup LongLoad
31
+ * @zgrouppriority 10
32
+ * @zdefault false
33
+ */
34
+ runInProduction: boolean;
35
+ }
36
+ /**
37
+ * Simulates long random loading times to facilitate development and debugging of loading processes.
38
+ *
39
+ * @zcomponent
40
+ * @zicon settings
41
+ * @zgroup Advanced
42
+ */
43
+ export declare class LongLoad extends Component<LongLoadConstructorProps> {
44
+ constructor(props: LongLoadConstructorProps, contextManager: ContextManager);
45
+ }
@@ -0,0 +1,28 @@
1
+ import { Component, isDevelopmentBuild, registerLoadable } from "..";
2
+ /**
3
+ * Simulates long random loading times to facilitate development and debugging of loading processes.
4
+ *
5
+ * @zcomponent
6
+ * @zicon settings
7
+ * @zgroup Advanced
8
+ */
9
+ export class LongLoad extends Component {
10
+ constructor(props, contextManager) {
11
+ super(props, contextManager);
12
+ if (!props.runInProduction && !isDevelopmentBuild(contextManager))
13
+ return;
14
+ const minimumLoadTime = props.minimumLoadTime ?? 500;
15
+ const maximumLoadTime = props.maximumLoadTime ?? 5000;
16
+ for (let i = 0; i < (props.numberOfLoads ?? 10); i++) {
17
+ registerLoadable(contextManager, new Promise(resolve => {
18
+ if (this.disposed)
19
+ return;
20
+ setTimeout(() => {
21
+ if (this.disposed)
22
+ return;
23
+ resolve();
24
+ }, minimumLoadTime + Math.random() * (maximumLoadTime - minimumLoadTime));
25
+ }));
26
+ }
27
+ }
28
+ }
@@ -7,9 +7,26 @@ export interface CanvasContext {
7
7
  onAfterRender: Event<[number]>;
8
8
  size: Observable<[number, number]>;
9
9
  dispose: () => void;
10
+ overlayDefault: HTMLDivElement;
11
+ overlay: Observable<HTMLDivElement>;
12
+ }
13
+ export interface CanvasContextOptions {
14
+ overlay: HTMLDivElement;
15
+ }
16
+ export declare const CanvasContext: import("../context").ContextTypeWithDefault<CanvasContext, [canvas?: HTMLCanvasElement | undefined, options?: CanvasContextOptions | undefined]>;
17
+ export declare enum HorizontalAlignment {
18
+ 'left' = "left",
19
+ 'center' = "center",
20
+ 'right' = "right"
21
+ }
22
+ export declare enum VerticalAlignment {
23
+ 'top' = "top",
24
+ 'center' = "center",
25
+ 'bottom' = "bottom"
10
26
  }
11
- export declare const CanvasContext: import("../context").ContextTypeWithDefault<CanvasContext, [canvas?: HTMLCanvasElement | undefined]>;
12
27
  export declare function useCanvas(mgr: ContextManager): HTMLCanvasElement;
28
+ export declare function useOverlay(mgr: ContextManager): Observable<HTMLDivElement, never>;
13
29
  export declare function useCanvasSize(mgr: ContextManager): Observable<[number, number], never>;
14
30
  export declare function useOnBeforeRender(mgr: ContextManager): Event<[number]>;
15
31
  export declare function useOnAfterRender(mgr: ContextManager): Event<[number]>;
32
+ export declare function classNameForAlignment(h: HorizontalAlignment, v: VerticalAlignment): string;
@@ -1,7 +1,7 @@
1
1
  import { defineContextType } from '../context';
2
2
  import { Event } from '../event';
3
3
  import { Observable } from '../observable';
4
- export const CanvasContext = defineContextType((ctx, canvas) => {
4
+ export const CanvasContext = defineContextType((ctx, canvas, options) => {
5
5
  if (!canvas) {
6
6
  canvas = document.createElement("canvas");
7
7
  canvas.style.position = "fixed";
@@ -12,6 +12,11 @@ export const CanvasContext = defineContextType((ctx, canvas) => {
12
12
  canvas.style.touchAction = "none";
13
13
  document.body.append(canvas);
14
14
  }
15
+ const overlayDefault = options?.overlay ?? document.createElement('div');
16
+ overlayDefault.id = 'zcomponent-overlay';
17
+ if (!options?.overlay) {
18
+ document.body.append(overlayDefault);
19
+ }
15
20
  const size = new Observable([canvas.clientWidth, canvas.clientHeight]);
16
21
  const resizeObserver = new ResizeObserver(entries => {
17
22
  for (const entry of entries) {
@@ -21,19 +26,51 @@ export const CanvasContext = defineContextType((ctx, canvas) => {
21
26
  }
22
27
  });
23
28
  resizeObserver.observe(canvas);
29
+ const onBeforeRender = new Event();
30
+ let lastRect;
31
+ onBeforeRender.bindfn(() => {
32
+ const rect = canvas.getBoundingClientRect();
33
+ if (lastRect && lastRect.top === rect.top && lastRect.left === rect.left && lastRect.width === rect.width && lastRect.height === rect.height)
34
+ return;
35
+ overlayDefault.style.top = rect.top.toString() + 'px';
36
+ overlayDefault.style.left = rect.left.toString() + 'px';
37
+ overlayDefault.style.width = rect.width.toString() + 'px';
38
+ overlayDefault.style.height = rect.height.toString() + 'px';
39
+ lastRect = rect;
40
+ });
41
+ const onAfterRender = new Event();
24
42
  return {
25
43
  canvas,
26
- onBeforeRender: new Event(),
27
- onAfterRender: new Event(),
44
+ onBeforeRender,
45
+ onAfterRender,
28
46
  size,
47
+ overlayDefault,
48
+ overlay: new Observable(overlayDefault, undefined, false),
29
49
  dispose: () => {
50
+ onBeforeRender.clear();
51
+ onAfterRender.clear();
30
52
  resizeObserver.disconnect();
31
53
  }
32
54
  };
33
55
  });
56
+ export var HorizontalAlignment;
57
+ (function (HorizontalAlignment) {
58
+ HorizontalAlignment["left"] = "left";
59
+ HorizontalAlignment["center"] = "center";
60
+ HorizontalAlignment["right"] = "right";
61
+ })(HorizontalAlignment || (HorizontalAlignment = {}));
62
+ export var VerticalAlignment;
63
+ (function (VerticalAlignment) {
64
+ VerticalAlignment["top"] = "top";
65
+ VerticalAlignment["center"] = "center";
66
+ VerticalAlignment["bottom"] = "bottom";
67
+ })(VerticalAlignment || (VerticalAlignment = {}));
34
68
  export function useCanvas(mgr) {
35
69
  return mgr.get(CanvasContext).canvas;
36
70
  }
71
+ export function useOverlay(mgr) {
72
+ return mgr.get(CanvasContext).overlay;
73
+ }
37
74
  export function useCanvasSize(mgr) {
38
75
  return mgr.get(CanvasContext).size;
39
76
  }
@@ -43,3 +80,37 @@ export function useOnBeforeRender(mgr) {
43
80
  export function useOnAfterRender(mgr) {
44
81
  return mgr.get(CanvasContext).onAfterRender;
45
82
  }
83
+ export function classNameForAlignment(h, v) {
84
+ const names = ['zcomponent-align'];
85
+ switch (h) {
86
+ case HorizontalAlignment.left:
87
+ names.push('zcomponent-h-left');
88
+ break;
89
+ case HorizontalAlignment.center:
90
+ names.push('zcomponent-h-center');
91
+ break;
92
+ case HorizontalAlignment.right:
93
+ names.push('zcomponent-h-right');
94
+ break;
95
+ }
96
+ switch (v) {
97
+ case VerticalAlignment.top:
98
+ names.push('zcomponent-v-top');
99
+ break;
100
+ case VerticalAlignment.center:
101
+ names.push('zcomponent-v-center');
102
+ break;
103
+ case VerticalAlignment.bottom:
104
+ names.push('zcomponent-v-bottom');
105
+ break;
106
+ }
107
+ if (h !== HorizontalAlignment.center && v !== VerticalAlignment.center)
108
+ names.push('zcomponent-h-v');
109
+ if (h === HorizontalAlignment.center && v !== VerticalAlignment.center)
110
+ names.push('zcomponent-hc-v');
111
+ if (h === HorizontalAlignment.center && v === VerticalAlignment.center)
112
+ names.push('zcomponent-hc-vc');
113
+ if (h !== HorizontalAlignment.center && v === VerticalAlignment.center)
114
+ names.push('zcomponent-h-vc');
115
+ return names.join(' ');
116
+ }
@@ -7,3 +7,4 @@ export interface EnvirontmentContext {
7
7
  export declare const EnvironmentContext: import("../context").ContextTypeWithDefault<EnvirontmentContext, []>;
8
8
  export declare function isDesignTime(ctx: ContextManager): boolean;
9
9
  export declare function isEditTime(ctx: ContextManager): boolean;
10
+ export declare function isDevelopmentBuild(ctx: ContextManager): boolean;
@@ -12,3 +12,6 @@ export function isDesignTime(ctx) {
12
12
  export function isEditTime(ctx) {
13
13
  return ctx.get(EnvironmentContext).editTime.value;
14
14
  }
15
+ export function isDevelopmentBuild(ctx) {
16
+ return (typeof process !== 'undefined' && process?.env?.NODE_ENV === 'development');
17
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zcomponent/core",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",