@novely/solid-renderer 0.42.1 → 0.43.1

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,3 +1,3 @@
1
- import type { Lang, ValidAction } from '@novely/core';
2
- declare const setMood: (mood: string | Record<Lang, 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 };
@@ -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 };
package/dist/index.jsx CHANGED
@@ -5054,14 +5054,15 @@ var showImage = (source, params = {}) => {
5054
5054
  const ctx = useContextState(contextKey);
5055
5055
  const { promise, resolve } = Promise.withResolvers();
5056
5056
  const image = document.createElement("img");
5057
+ const src = typeof source === "object" ? source.source : source;
5057
5058
  {
5058
- image.src = source;
5059
+ image.src = src;
5059
5060
  image.className = "action-image__image " + (params.class || "");
5060
5061
  image.style.cssText = params.style || "";
5061
5062
  image.style.setProperty("--z-index", String(params.z || 1));
5062
5063
  }
5063
- ctx.mutate((s) => s.images[source], image);
5064
- const inClasses = (params.in || "").split(" ");
5064
+ ctx.mutate((s) => s.images[src], image);
5065
+ const inClasses = params.in ? params.in.split(" ") : [];
5065
5066
  data({
5066
5067
  image,
5067
5068
  inClasses
@@ -5090,11 +5091,9 @@ var showImage = (source, params = {}) => {
5090
5091
  return promise;
5091
5092
  };
5092
5093
  handler.id = SHOW_IMAGE;
5093
- handler.key = source;
5094
+ handler.key = typeof source === "object" ? source.id : source;
5094
5095
  handler.assets = [source];
5095
- handler.skipOnRestore = (getNext) => {
5096
- return getNext().some(([name, fn]) => name === "custom" && fn.key === source);
5097
- };
5096
+ handler.callOnlyLatest = true;
5098
5097
  return ["custom", handler];
5099
5098
  };
5100
5099
  var hideImage = (source, params = {}) => {
@@ -5102,7 +5101,7 @@ var hideImage = (source, params = {}) => {
5102
5101
  const ctx = useContextState(contextKey);
5103
5102
  const { promise, resolve } = Promise.withResolvers();
5104
5103
  const done = () => {
5105
- ctx.mutate((s) => s.images[source], void 0);
5104
+ ctx.mutate((s) => s.images[typeof source === "object" ? source.id : source], void 0);
5106
5105
  resolve();
5107
5106
  };
5108
5107
  const { image, inClasses } = data();
@@ -5131,21 +5130,19 @@ var hideImage = (source, params = {}) => {
5131
5130
  return promise;
5132
5131
  };
5133
5132
  handler.id = SHOW_IMAGE;
5134
- handler.key = source;
5133
+ handler.key = typeof source === "object" ? source.id : source;
5135
5134
  handler.assets = [];
5136
- handler.skipOnRestore = (getNext) => {
5137
- return getNext().some(([name, fn]) => name === "custom" && fn.key === source);
5138
- };
5135
+ handler.callOnlyLatest = true;
5139
5136
  return ["custom", handler];
5140
5137
  };
5141
5138
 
5142
5139
  // src/custom-actions/mood.ts
5143
5140
  var SET_MOOD = Symbol();
5144
5141
  var setMood = (mood) => {
5145
- const handler = ({ contextKey, lang, clear }) => {
5142
+ const handler = ({ contextKey, templateReplace, state, clear }) => {
5146
5143
  const ctx = useContextState(contextKey);
5147
- if (mood === "''" || mood === '""') ctx.setKey("mood", "");
5148
- else ctx.setKey("mood", typeof mood === "object" ? mood[lang] : mood);
5144
+ if (mood === "''" || mood === '""' || mood === "") ctx.setKey("mood", "");
5145
+ else ctx.setKey("mood", templateReplace(mood, state()));
5149
5146
  clear(() => {
5150
5147
  ctx.setKey("mood", "");
5151
5148
  });
@@ -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 | Record<Lang, 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@novely/solid-renderer",
3
- "version": "0.42.1",
3
+ "version": "0.43.1",
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.2",
23
+ "@novely/core": "0.47.0",
24
24
  "@novely/renderer-toolkit": "0.12.0",
25
25
  "@novely/typewriter": "0.5.1"
26
26
  },