@novely/solid-renderer 0.42.0 → 0.43.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,10 +1,8 @@
1
- import type { CharacterHandle } from '@novely/core';
2
- import type { ContextStateCharacter } from '@novely/renderer-toolkit';
3
1
  import type { VoidComponent } from 'solid-js';
4
- interface CharacterProps {
2
+ import type { CustomCharacterHandle } from '../types';
3
+ type CharacterProps = {
5
4
  character: string;
6
- characters: Record<string, CharacterHandle>;
7
- data: ContextStateCharacter;
8
- }
5
+ characters: Record<string, CustomCharacterHandle>;
6
+ };
9
7
  declare const Character: VoidComponent<CharacterProps>;
10
8
  export { Character };
@@ -0,0 +1,14 @@
1
+ import type { FlowComponent, JSX } from 'solid-js';
2
+ type NativeSelectProps = Omit<JSX.SelectHTMLAttributes<HTMLSelectElement>, 'class' | 'id'>;
3
+ type SelectProps = NativeSelectProps & {
4
+ /**
5
+ * Icon HTML string
6
+ */
7
+ icon: string;
8
+ /**
9
+ * Label
10
+ */
11
+ label: string;
12
+ };
13
+ declare const Select: FlowComponent<SelectProps>;
14
+ export { Select };
@@ -0,0 +1,3 @@
1
+ import type { FlowComponent } from 'solid-js';
2
+ declare const ShadowRoot: FlowComponent;
3
+ export { ShadowRoot };
@@ -1,3 +1,3 @@
1
- import type { ValidAction } from '@novely/core';
2
- declare const setMood: (mood: string) => ValidAction;
1
+ import type { Lang, State, TextContent, ValidAction } from '@novely/core';
2
+ declare const setMood: (mood: string | TextContent<Lang, State>) => ValidAction;
3
3
  export { setMood };
@@ -0,0 +1,10 @@
1
+ import type { Character, CharactersData, Lang, ValidAction } from "@novely/core";
2
+ type ShowArbitraryCharacterParams<$Characters extends CharactersData<Record<string, Character<Lang>>>, $Character extends keyof $Characters> = {
3
+ id: $Character & string;
4
+ emotion: $Characters[$Character]['emotions'][number] & string;
5
+ extendWith: () => string | string[];
6
+ classes?: string;
7
+ style?: string;
8
+ };
9
+ declare const createShowArbitraryCharacterAction: <$Characters extends CharactersData<Record<string, Character>>>() => <$Character extends keyof $Characters>(params: ShowArbitraryCharacterParams<$Characters, $Character>) => ValidAction;
10
+ export { createShowArbitraryCharacterAction };
@@ -1,4 +1,4 @@
1
- import type { ValidAction } from '@novely/core';
1
+ import type { ValidAction, NovelyAsset } from '@novely/core';
2
2
  type ShowImageParams = {
3
3
  z?: number;
4
4
  in?: string;
@@ -6,10 +6,10 @@ type ShowImageParams = {
6
6
  style?: string;
7
7
  await?: boolean;
8
8
  };
9
- declare const showImage: (source: string, params?: ShowImageParams) => ValidAction;
9
+ declare const showImage: (source: string | NovelyAsset, params?: ShowImageParams) => ValidAction;
10
10
  type HideImageParams = {
11
11
  out?: string;
12
12
  await?: boolean;
13
13
  };
14
- declare const hideImage: (source: string, params?: HideImageParams) => ValidAction;
14
+ declare const hideImage: (source: string | NovelyAsset, params?: HideImageParams) => ValidAction;
15
15
  export { showImage, hideImage };
@@ -0,0 +1,24 @@
1
+ import type { Character, Lang, ValidAction } from "@novely/core";
2
+ type ShowArbitraryCharacterParams<$Characters extends Record<string, Character<Lang>>, $Character extends keyof $Characters> = {
3
+ id: $Character & string;
4
+ emotion: keyof $Characters[$Character]['emotions'] & string;
5
+ extendWith: () => string | string[];
6
+ classes?: string;
7
+ style?: string;
8
+ };
9
+ declare const createShowArbitraryCharacterAction: <$Characters extends Record<string, Character>>(_: $Characters) => <$Character extends keyof $Characters>(params: ShowArbitraryCharacterParams<$Characters, $Character>) => ValidAction;
10
+ type ShowImageParams = {
11
+ z?: number;
12
+ in?: string;
13
+ class?: string;
14
+ style?: string;
15
+ position?: string;
16
+ await?: boolean;
17
+ };
18
+ declare const showImage: (source: string, params?: ShowImageParams) => ValidAction;
19
+ type HideImageParams = {
20
+ out?: string;
21
+ await?: boolean;
22
+ };
23
+ declare const hideImage: (source: string, params?: HideImageParams) => ValidAction;
24
+ export { createShowArbitraryCharacterAction, showImage, hideImage };
package/dist/index.jsx CHANGED
@@ -3070,9 +3070,7 @@ var clickOutside = (node, handler) => {
3070
3070
 
3071
3071
  // src/components/Character.tsx
3072
3072
  var Character = (props) => {
3073
- const canvas = () => props.characters[props.character].canvas;
3074
- createRenderEffect(() => setAttribute(canvas(), "style", props.data.style || ""));
3075
- return createMemo(canvas);
3073
+ return props.characters[props.character].canvas;
3076
3074
  };
3077
3075
 
3078
3076
  // src/components/Icon.tsx
@@ -4245,7 +4243,6 @@ var Game = (props) => {
4245
4243
  get children() {
4246
4244
  return createComponent(Character, {
4247
4245
  character,
4248
- data: data2,
4249
4246
  get characters() {
4250
4247
  return store.characters;
4251
4248
  }
@@ -5057,13 +5054,14 @@ var showImage = (source, params = {}) => {
5057
5054
  const ctx = useContextState(contextKey);
5058
5055
  const { promise, resolve } = Promise.withResolvers();
5059
5056
  const image = document.createElement("img");
5057
+ const src = typeof source === "object" ? source.source : source;
5060
5058
  {
5061
- image.src = source;
5059
+ image.src = src;
5062
5060
  image.className = "action-image__image " + (params.class || "");
5063
5061
  image.style.cssText = params.style || "";
5064
5062
  image.style.setProperty("--z-index", String(params.z || 1));
5065
5063
  }
5066
- ctx.mutate((s) => s.images[source], image);
5064
+ ctx.mutate((s) => s.images[src], image);
5067
5065
  const inClasses = (params.in || "").split(" ");
5068
5066
  data({
5069
5067
  image,
@@ -5093,11 +5091,9 @@ var showImage = (source, params = {}) => {
5093
5091
  return promise;
5094
5092
  };
5095
5093
  handler.id = SHOW_IMAGE;
5096
- handler.key = source;
5094
+ handler.key = typeof source === "object" ? source.id : source;
5097
5095
  handler.assets = [source];
5098
- handler.skipOnRestore = (getNext) => {
5099
- return getNext().some(([name, fn]) => name === "custom" && fn.key === source);
5100
- };
5096
+ handler.callOnlyLatest = true;
5101
5097
  return ["custom", handler];
5102
5098
  };
5103
5099
  var hideImage = (source, params = {}) => {
@@ -5105,7 +5101,7 @@ var hideImage = (source, params = {}) => {
5105
5101
  const ctx = useContextState(contextKey);
5106
5102
  const { promise, resolve } = Promise.withResolvers();
5107
5103
  const done = () => {
5108
- ctx.mutate((s) => s.images[source], void 0);
5104
+ ctx.mutate((s) => s.images[typeof source === "object" ? source.id : source], void 0);
5109
5105
  resolve();
5110
5106
  };
5111
5107
  const { image, inClasses } = data();
@@ -5134,21 +5130,19 @@ var hideImage = (source, params = {}) => {
5134
5130
  return promise;
5135
5131
  };
5136
5132
  handler.id = SHOW_IMAGE;
5137
- handler.key = source;
5133
+ handler.key = typeof source === "object" ? source.id : source;
5138
5134
  handler.assets = [];
5139
- handler.skipOnRestore = (getNext) => {
5140
- return getNext().some(([name, fn]) => name === "custom" && fn.key === source);
5141
- };
5135
+ handler.callOnlyLatest = true;
5142
5136
  return ["custom", handler];
5143
5137
  };
5144
5138
 
5145
5139
  // src/custom-actions/mood.ts
5146
5140
  var SET_MOOD = Symbol();
5147
5141
  var setMood = (mood) => {
5148
- const handler = ({ contextKey, clear }) => {
5142
+ const handler = ({ contextKey, templateReplace, state, clear }) => {
5149
5143
  const ctx = useContextState(contextKey);
5150
- if (mood === "''" || mood === '""') ctx.setKey("mood", "");
5151
- else ctx.setKey("mood", mood);
5144
+ if (mood === "''" || mood === '""' || mood === "") ctx.setKey("mood", "");
5145
+ else ctx.setKey("mood", templateReplace(mood, state()));
5152
5146
  clear(() => {
5153
5147
  ctx.setKey("mood", "");
5154
5148
  });
@@ -5260,7 +5254,6 @@ var createSolidRenderer = ({
5260
5254
  const canvasContext = canvas.getContext("2d");
5261
5255
  const characterHandle = {
5262
5256
  canvas,
5263
- ctx: canvasContext,
5264
5257
  emotions: {},
5265
5258
  emotion(emotion, shouldRender) {
5266
5259
  let stored = this.emotions[emotion];
@@ -5343,14 +5336,12 @@ var createSolidRenderer = ({
5343
5336
  });
5344
5337
  },
5345
5338
  animate(classes) {
5346
- const target2 = this.canvas;
5347
- if (!target2) return;
5348
- const classNames = classes.filter((className2) => !target2.classList.contains(className2));
5349
- target2.classList.add(...classNames);
5339
+ const classNames = classes.filter((className2) => !canvas.classList.contains(className2));
5340
+ canvas.classList.add(...classNames);
5350
5341
  const onAnimationEnd = () => {
5351
- target2.classList.remove(...classNames);
5342
+ canvas.classList.remove(...classNames);
5352
5343
  };
5353
- target2.addEventListener("animationend", onAnimationEnd, {
5344
+ canvas.addEventListener("animationend", onAnimationEnd, {
5354
5345
  once: true
5355
5346
  });
5356
5347
  }
@@ -21,18 +21,18 @@ declare const createSolidRenderer: ({ fullscreen, controls, skipTypewriterWhenGo
21
21
  preloadAudioBlocking: (source: string) => Promise<void>;
22
22
  };
23
23
  actions: {
24
- showImage: (source: string, params?: {
24
+ showImage: (source: string | import("@novely/core").NovelyAsset, params?: {
25
25
  z?: number;
26
26
  in?: string;
27
27
  class?: string;
28
28
  style?: string;
29
29
  await?: boolean;
30
30
  }) => import("@novely/core").ValidAction;
31
- hideImage: (source: string, params?: {
31
+ hideImage: (source: string | import("@novely/core").NovelyAsset, params?: {
32
32
  out?: string;
33
33
  await?: boolean;
34
34
  }) => import("@novely/core").ValidAction;
35
- setMood: (mood: string) => import("@novely/core").ValidAction;
35
+ setMood: (mood: string | import("@novely/core").TextContent<Lang, import("@novely/core").State>) => import("@novely/core").ValidAction;
36
36
  };
37
37
  };
38
38
  registerScreen(name: string, screen: StateScreen): void;
package/dist/types.d.ts CHANGED
@@ -9,8 +9,14 @@ type StateScreens = Record<string, StateScreen>;
9
9
  type PossibleScreen = NovelyScreen | (string & Record<never, never>);
10
10
  type StateMainmenuItem = (goto: (name: PossibleScreen) => void) => JSX.ButtonHTMLAttributes<HTMLButtonElement>;
11
11
  type StateMainmenuItems = StateMainmenuItem[];
12
+ type CustomCharacterHandle = CharacterHandle & {
13
+ /**
14
+ * Node in which character is rendered
15
+ */
16
+ canvas: HTMLCanvasElement;
17
+ };
12
18
  type SolidRendererStore = {
13
- characters: Record<string, CharacterHandle>;
19
+ characters: Record<string, CustomCharacterHandle>;
14
20
  };
15
21
  type CreateSolidRendererOptions = {
16
22
  /**
@@ -46,4 +52,4 @@ type RendererStoreExtension = {
46
52
  screens: Record<string, StateScreen>;
47
53
  mainmenu: StateMainmenuItems;
48
54
  };
49
- export type { EmitterEventsMap, StateScreen, StateScreens, PossibleScreen, StateMainmenuItem, StateMainmenuItems, SolidRendererStore, CreateSolidRendererOptions, RendererStoreExtension, };
55
+ export type { EmitterEventsMap, StateScreen, StateScreens, PossibleScreen, StateMainmenuItem, StateMainmenuItems, SolidRendererStore, CreateSolidRendererOptions, RendererStoreExtension, CustomCharacterHandle, };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@novely/solid-renderer",
3
- "version": "0.42.0",
3
+ "version": "0.43.0",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -20,7 +20,7 @@
20
20
  "es-toolkit": "^1.23.0",
21
21
  "solid-js": "~1.9.3",
22
22
  "solid-transition-group": "^0.2.3",
23
- "@novely/core": "0.46.0",
23
+ "@novely/core": "0.47.0",
24
24
  "@novely/renderer-toolkit": "0.12.0",
25
25
  "@novely/typewriter": "0.5.1"
26
26
  },
@@ -1,14 +0,0 @@
1
- declare const iconStore: {
2
- SkipBack: import("solid-js").JSX.Element;
3
- BookOpen: import("solid-js").JSX.Element;
4
- FloppyDisk: import("solid-js").JSX.Element;
5
- GearSix: import("solid-js").JSX.Element;
6
- SignOut: import("solid-js").JSX.Element;
7
- List: import("solid-js").JSX.Element;
8
- X: import("solid-js").JSX.Element;
9
- Play: import("solid-js").JSX.Element;
10
- Stop: import("solid-js").JSX.Element;
11
- ArrowSquareRight: import("solid-js").JSX.Element;
12
- FilePlus: import("solid-js").JSX.Element;
13
- Files: import("solid-js").JSX.Element;
14
- };
package/dist/icons.d.ts DELETED
File without changes