@antha/asset 0.1.3 → 0.3.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.
@@ -39,13 +39,19 @@ export type AnthaAssetModOptions = PartialWithUndefined<{
39
39
  * @default false
40
40
  */
41
41
  hideLoadingScreen: boolean;
42
+ /**
43
+ * Duration in milliseconds for the default loading screen's fade-out animation.
44
+ *
45
+ * @default defaultLoadingScreenFadeMs
46
+ */
47
+ loadingScreenFadeMs: number;
42
48
  }>;
43
49
  /**
44
50
  * Duration in milliseconds for the loading screen fade-out animation.
45
51
  *
46
52
  * @category Internal
47
53
  */
48
- export declare const loadingScreenFadeMs = 1000;
54
+ export declare const defaultLoadingScreenFadeMs = 1000;
49
55
  /**
50
56
  * Duration in milliseconds for the progress bar grow transition.
51
57
  *
@@ -62,7 +68,8 @@ export declare const AnthaAssetLoadingScreen: import("element-vir").DeclarativeE
62
68
  dotCount: number;
63
69
  completed: boolean;
64
70
  currentResourceName: string | undefined;
65
- }, {}, {}, "antha-asset-loading-screen-completed", "antha-asset-loading-screen-", readonly [], readonly []>;
71
+ loadingScreenFadeMs: number;
72
+ }, {}, {}, "antha-asset-loading-screen-completed", "antha-asset-loading-screen-fade-ms", readonly [], readonly []>;
66
73
  /**
67
74
  * The Antha Asset mod, created by {@link createAnthaAssetMod}.
68
75
  *
@@ -1,12 +1,14 @@
1
1
  import { defineAnthaMod } from '@antha/engine';
2
+ import { addSuffix } from '@augment-vir/common';
2
3
  import { css, defineElement, html } from 'element-vir';
4
+ import { setCssVarValue } from 'lit-css-vars';
3
5
  import { AssetLoader, AssetLoaderProgressUpdateEvent } from './asset-loader.js';
4
6
  /**
5
7
  * Duration in milliseconds for the loading screen fade-out animation.
6
8
  *
7
9
  * @category Internal
8
10
  */
9
- export const loadingScreenFadeMs = 1000;
11
+ export const defaultLoadingScreenFadeMs = 1000;
10
12
  /**
11
13
  * Duration in milliseconds for the progress bar grow transition.
12
14
  *
@@ -20,10 +22,16 @@ export const loadingScreenProgressGrowMs = 200;
20
22
  */
21
23
  export const AnthaAssetLoadingScreen = defineElement()({
22
24
  tagName: 'antha-asset-loading-screen',
25
+ cssVars: {
26
+ 'antha-asset-loading-screen-fade-ms': addSuffix({
27
+ value: defaultLoadingScreenFadeMs,
28
+ suffix: 'ms',
29
+ }),
30
+ },
23
31
  hostClasses: {
24
32
  'antha-asset-loading-screen-completed': ({ inputs }) => inputs.completed,
25
33
  },
26
- styles: ({ hostClasses }) => {
34
+ styles: ({ cssVars, hostClasses }) => {
27
35
  return css `
28
36
  :host {
29
37
  position: fixed;
@@ -37,7 +45,7 @@ export const AnthaAssetLoadingScreen = defineElement()({
37
45
  z-index: 9999;
38
46
  gap: 24px;
39
47
  opacity: 1;
40
- transition: opacity ${loadingScreenFadeMs}ms ease-in;
48
+ transition: opacity ${cssVars['antha-asset-loading-screen-fade-ms'].value} ease-in;
41
49
  }
42
50
 
43
51
  .loading-text {
@@ -75,7 +83,15 @@ export const AnthaAssetLoadingScreen = defineElement()({
75
83
  }
76
84
  `;
77
85
  },
78
- render({ inputs }) {
86
+ render({ host, inputs, cssVars }) {
87
+ setCssVarValue({
88
+ forCssVar: cssVars['antha-asset-loading-screen-fade-ms'],
89
+ onElement: host,
90
+ toValue: addSuffix({
91
+ value: inputs.loadingScreenFadeMs,
92
+ suffix: 'ms',
93
+ }),
94
+ });
79
95
  const dotCount = inputs.dotCount % 4;
80
96
  const dots = '.'.repeat(dotCount) + '\u00A0'.repeat(3 - dotCount);
81
97
  return html `
@@ -114,6 +130,7 @@ export const anthaAssetModName = 'antha-asset';
114
130
  * @category Pre-Built Mods
115
131
  */
116
132
  export function createAnthaAssetMod(options = {}) {
133
+ const configuredLoadingScreenFadeMs = options.loadingScreenFadeMs ?? defaultLoadingScreenFadeMs;
117
134
  return defineAnthaMod({
118
135
  modName: anthaAssetModName,
119
136
  async cleanup({ state }) {
@@ -154,7 +171,8 @@ export function createAnthaAssetMod(options = {}) {
154
171
  return;
155
172
  }
156
173
  const shouldShowLoadingScreen = state.loadingScreenState?.completedAt
157
- ? engine.totalMs <= state.loadingScreenState.completedAt + loadingScreenFadeMs
174
+ ? engine.totalMs <=
175
+ state.loadingScreenState.completedAt + configuredLoadingScreenFadeMs
158
176
  : true;
159
177
  if (state.loadingScreenState && shouldShowLoadingScreen) {
160
178
  const progressPercent = state.loadingScreenState.total > 0
@@ -166,6 +184,7 @@ export function createAnthaAssetMod(options = {}) {
166
184
  dotCount: Math.floor(engine.totalMs / 500) % 4,
167
185
  completed: !!state.loadingScreenState.completedAt,
168
186
  currentResourceName: state.loadingScreenState.currentResourceName,
187
+ loadingScreenFadeMs: configuredLoadingScreenFadeMs,
169
188
  })}></${AnthaAssetLoadingScreen}>
170
189
  `;
171
190
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antha/asset",
3
- "version": "0.1.3",
3
+ "version": "0.3.0",
4
4
  "description": "An Antha mod for handling asset loading.",
5
5
  "keywords": [
6
6
  "vir",
@@ -36,6 +36,7 @@
36
36
  "dependencies": {
37
37
  "@augment-vir/assert": "^32.2.3",
38
38
  "@augment-vir/common": "^32.2.3",
39
+ "lit-css-vars": "^3.6.3",
39
40
  "typed-event-target": "^4.3.3"
40
41
  },
41
42
  "devDependencies": {
@@ -47,7 +48,7 @@
47
48
  "pixi.js": "^8.19.0"
48
49
  },
49
50
  "peerDependencies": {
50
- "@antha/engine": "^0.1.3",
51
+ "@antha/engine": "^0.3.0",
51
52
  "element-vir": ">=26"
52
53
  },
53
54
  "engines": {