@novely/solid-renderer 0.39.0 → 0.40.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,9 +1,10 @@
1
1
  import type { Component } from 'solid-js';
2
2
  import type { Renderer, RendererInit } from '@novely/core';
3
3
  import type { Emitter } from '../emitter';
4
- import type { RendererStateStore, ContextStateStore, DeepAtom } from '@novely/renderer-toolkit';
4
+ import type { RendererStateStore, DeepAtom } from '@novely/renderer-toolkit';
5
5
  import type { EmitterEventsMap, RendererStoreExtension, SettingsIcons } from '../types';
6
6
  import type { Context } from '@novely/core';
7
+ import type { IContextState } from '../context-state';
7
8
  type CreateRootComponentOpts = {
8
9
  setRoot: (root: HTMLDivElement) => void;
9
10
  renderer: Renderer;
@@ -15,7 +16,7 @@ type CreateRootComponentOpts = {
15
16
  showAudioSettings: boolean;
16
17
  rendererContext: Context;
17
18
  coreOptions: RendererInit<any, any>;
18
- $contextState: DeepAtom<ContextStateStore<Record<PropertyKey, unknown>>>;
19
+ $contextState: IContextState;
19
20
  $rendererState: DeepAtom<RendererStateStore<RendererStoreExtension>>;
20
21
  };
21
22
  declare const createRootComponent: ({ $rendererState, $contextState, coreOptions, setRoot, renderer, showAudioSettings, fullscreen, emitter, controls, skipTypewriterWhenGoingBack, settingsIcons, rendererContext }: CreateRootComponentOpts) => Component;
@@ -1,2 +1,6 @@
1
- declare const useContextState: (id: string) => import("@novely/renderer-toolkit").DeepAtom<import("@novely/renderer-toolkit").ContextState>, removeContextState: (id: string) => void;
1
+ declare const useContextState: (id: string) => import("@novely/renderer-toolkit").DeepAtom<import("@novely/renderer-toolkit").ContextStateStore<{
2
+ images: Record<string, HTMLImageElement | undefined>;
3
+ }>>, removeContextState: (id: string) => void;
4
+ type IContextState = ReturnType<typeof useContextState>;
2
5
  export { useContextState, removeContextState };
6
+ export type { IContextState };
@@ -4,7 +4,6 @@ type ShowImageParams = {
4
4
  in?: string;
5
5
  class?: string;
6
6
  style?: string;
7
- position?: string;
8
7
  await?: boolean;
9
8
  };
10
9
  declare const showImage: (source: string, params?: ShowImageParams) => ValidAction;
package/dist/index.jsx CHANGED
@@ -2923,7 +2923,11 @@ var createEmitter = () => {
2923
2923
  };
2924
2924
 
2925
2925
  // src/context-state.ts
2926
- var { useContextState, removeContextState } = createContextStateRoot();
2926
+ var { useContextState, removeContextState } = createContextStateRoot(() => {
2927
+ return {
2928
+ images: {}
2929
+ };
2930
+ });
2927
2931
 
2928
2932
  // src/shared.ts
2929
2933
  var PRELOADED_IMAGE_MAP = /* @__PURE__ */ new Map();
@@ -4149,7 +4153,7 @@ var _tmpl$82 = /* @__PURE__ */ template(`<button type="button" class="button con
4149
4153
  var _tmpl$92 = /* @__PURE__ */ template(`<span class="control-panel-container-fix" aria-hidden="true">&#8203;`);
4150
4154
  var _tmpl$102 = /* @__PURE__ */ template(`<div class="control-panel-container-backdrop">`);
4151
4155
  var _tmpl$112 = /* @__PURE__ */ template(`<div class="control-panel"><div role="menubar" class="control-panel-container">`);
4152
- var _tmpl$122 = /* @__PURE__ */ template(`<div><div class="characters"></div><div class="action-dialog"><div class="action-dialog-container" role="button" tabindex="0"><div class="action-dialog-content"></div></div></div><div></div><div class="action-text" role="button" tabindex="0">`);
4156
+ var _tmpl$122 = /* @__PURE__ */ template(`<div><div class="characters"></div><div class="action-dialog"><div class="action-dialog-container" role="button" tabindex="0"><div class="action-dialog-content"></div></div></div><div></div><div class="action-text" role="button" tabindex="0"></div><div class="action-image">`);
4153
4157
  var _tmpl$132 = /* @__PURE__ */ template(`<button type="button" class="button choice-dialog__choice"><span>`);
4154
4158
  var Game = (props) => {
4155
4159
  const data = useData();
@@ -4160,7 +4164,8 @@ var Game = (props) => {
4160
4164
  choice,
4161
4165
  input,
4162
4166
  background,
4163
- custom
4167
+ custom,
4168
+ images
4164
4169
  } = destructure(from(props.$contextState));
4165
4170
  const rendererState = from(data.$rendererState);
4166
4171
  const exitPromptShown = () => rendererState().exitPromptShown;
@@ -4224,8 +4229,11 @@ var Game = (props) => {
4224
4229
  return acc;
4225
4230
  }, 0);
4226
4231
  });
4232
+ createEffect(() => {
4233
+ console.log(images());
4234
+ });
4227
4235
  return (() => {
4228
- const _el$ = _tmpl$122(), _el$2 = _el$.firstChild, _el$3 = _el$2.nextSibling, _el$4 = _el$3.firstChild, _el$6 = _el$4.firstChild, _el$16 = _el$3.nextSibling, _el$17 = _el$16.nextSibling;
4236
+ const _el$ = _tmpl$122(), _el$2 = _el$.firstChild, _el$3 = _el$2.nextSibling, _el$4 = _el$3.firstChild, _el$6 = _el$4.firstChild, _el$16 = _el$3.nextSibling, _el$17 = _el$16.nextSibling, _el$23 = _el$17.nextSibling;
4229
4237
  insert(_el$, createComponent(Canvas, {
4230
4238
  "class": "background",
4231
4239
  resize: false,
@@ -4362,12 +4370,12 @@ var Game = (props) => {
4362
4370
  return createComponent(Show, {
4363
4371
  when: visible,
4364
4372
  get children() {
4365
- const _el$23 = _tmpl$132(), _el$24 = _el$23.firstChild;
4366
- _el$23.$$click = onChoicesButtonClick;
4367
- _el$23.$$clickData = [disabled, index];
4368
- setAttribute(_el$23, "aria-disabled", disabled);
4369
- insert(_el$24, text2);
4370
- insert(_el$23, createComponent(Show, {
4373
+ const _el$24 = _tmpl$132(), _el$25 = _el$24.firstChild;
4374
+ _el$24.$$click = onChoicesButtonClick;
4375
+ _el$24.$$clickData = [disabled, index];
4376
+ setAttribute(_el$24, "aria-disabled", disabled);
4377
+ insert(_el$25, text2);
4378
+ insert(_el$24, createComponent(Show, {
4371
4379
  when: image !== "",
4372
4380
  get children() {
4373
4381
  return createComponent(Canvas, {
@@ -4382,7 +4390,7 @@ var Game = (props) => {
4382
4390
  });
4383
4391
  }
4384
4392
  }), null);
4385
- return _el$23;
4393
+ return _el$24;
4386
4394
  }
4387
4395
  });
4388
4396
  }
@@ -4548,7 +4556,13 @@ var Game = (props) => {
4548
4556
  });
4549
4557
  return _el$18;
4550
4558
  }
4551
- }), null);
4559
+ }), _el$23);
4560
+ insert(_el$23, createComponent(For, {
4561
+ get each() {
4562
+ return Object.values(images());
4563
+ },
4564
+ children: (image) => image
4565
+ }));
4552
4566
  createRenderEffect((_p$) => {
4553
4567
  const _v$7 = `${props.className || ""} game`, _v$8 = !!props.isPreview, _v$9 = charactersCount(), _v$10 = !!dialog().visible, _v$11 = !dialog().visible, _v$12 = !(dialog().miniature.character && dialog().miniature.emotion), _v$13 = !dialog().content, _v$14 = !!props.isPreview, _v$15 = !!Boolean(text().content), _v$16 = !text().content;
4554
4568
  _v$7 !== _p$._v$7 && className(_el$, _p$._v$7 = _v$7);
@@ -5057,42 +5071,39 @@ var createRootComponent = ({
5057
5071
  // src/custom-actions/show-hide-image.ts
5058
5072
  var SHOW_IMAGE = Symbol();
5059
5073
  var showImage = (source, params = {}) => {
5060
- const handler = ({ getDomNodes, clear, flags, data, rendererContext }) => {
5074
+ const handler = ({ contextKey, clear, flags, data, rendererContext }) => {
5075
+ const ctx = useContextState(contextKey);
5061
5076
  const { promise, resolve } = Promise.withResolvers();
5062
- const { element } = getDomNodes(true);
5063
- {
5064
- element.style.cssText += `position: fixed; inset: 0;`;
5065
- element.style.zIndex = String(params.z || 1);
5066
- }
5067
5077
  const image = document.createElement("img");
5068
5078
  {
5069
5079
  image.src = source;
5070
- image.className = params.class || "";
5080
+ image.className = "action-image__image " + (params.class || "");
5071
5081
  image.style.cssText = params.style || "";
5072
- image.style.cssText += `object-fit: cover; object-position: ${params.position || "50% 50%"}; width: 100vw; height: 100vh;`;
5082
+ image.style.setProperty("--z-index", String(params.z || 1));
5073
5083
  }
5074
- element.appendChild(image);
5084
+ ctx.mutate((s) => s.images[source], image);
5085
+ const inClasses = (params.in || "").split(" ");
5075
5086
  data({
5076
5087
  image,
5077
- in: params.in
5088
+ inClasses
5078
5089
  });
5079
5090
  let clearAnimation = noop;
5080
5091
  if (params.in && !flags.preview) {
5081
- const classes = params.in.split(" ");
5082
- image.classList.add(...classes);
5092
+ image.classList.add(...inClasses);
5093
+ if (params.await) {
5094
+ rendererContext.clearBlockingActions(void 0);
5095
+ }
5083
5096
  clearAnimation = () => {
5084
- image.classList.remove(...classes);
5085
- if (params.await) {
5086
- rendererContext.clearBlockingActions(void 0);
5087
- resolve();
5088
- }
5097
+ image.classList.remove(...inClasses);
5098
+ resolve();
5089
5099
  };
5090
5100
  image.addEventListener("animationend", clearAnimation, { once: true });
5101
+ } else {
5102
+ resolve();
5091
5103
  }
5092
5104
  clear(() => {
5093
5105
  data({});
5094
5106
  clearAnimation();
5095
- image.remove();
5096
5107
  });
5097
5108
  if (!params.await) {
5098
5109
  resolve();
@@ -5108,39 +5119,41 @@ var showImage = (source, params = {}) => {
5108
5119
  return ["custom", handler];
5109
5120
  };
5110
5121
  var hideImage = (source, params = {}) => {
5111
- const handler = async ({ data, rendererContext }) => {
5122
+ const handler = async ({ data, rendererContext, contextKey, flags }) => {
5123
+ const ctx = useContextState(contextKey);
5112
5124
  const { promise, resolve } = Promise.withResolvers();
5113
- const { image, in: inClasses } = data();
5125
+ const done = () => {
5126
+ ctx.mutate((s) => s.images[source], void 0);
5127
+ resolve();
5128
+ };
5129
+ const { image, inClasses } = data();
5114
5130
  if (!image) {
5115
5131
  resolve();
5116
5132
  return promise;
5117
5133
  }
5118
5134
  if (inClasses) {
5119
- const classes = inClasses.split(" ");
5120
- image.classList.remove(...classes);
5135
+ image.classList.remove(...inClasses);
5121
5136
  }
5122
- if (params.out) {
5137
+ if (params.out && !flags.preview) {
5123
5138
  const classes = params.out.split(" ");
5124
5139
  image.classList.add(...classes);
5140
+ rendererContext.clearBlockingActions(void 0);
5125
5141
  const onAnimationEnd = () => {
5126
5142
  image.classList.remove(...classes);
5127
- if (params.await) {
5128
- rendererContext.clearBlockingActions(void 0);
5129
- resolve();
5130
- }
5143
+ done();
5131
5144
  };
5132
5145
  image.addEventListener("animationend", onAnimationEnd, { once: true });
5133
5146
  if (!params.await) {
5134
- resolve();
5147
+ done();
5135
5148
  }
5136
5149
  } else {
5137
- resolve();
5150
+ done();
5138
5151
  }
5139
5152
  return promise;
5140
5153
  };
5141
5154
  handler.id = SHOW_IMAGE;
5142
5155
  handler.key = source;
5143
- handler.assets = [source];
5156
+ handler.assets = [];
5144
5157
  handler.skipOnRestore = (getNext) => {
5145
5158
  return getNext().some(([name, fn]) => name === "custom" && fn.key === source);
5146
5159
  };
@@ -26,7 +26,6 @@ declare const createSolidRenderer: ({ fullscreen, controls, skipTypewriterWhenGo
26
26
  in?: string;
27
27
  class?: string;
28
28
  style?: string;
29
- position?: string;
30
29
  await?: boolean;
31
30
  }) => import("@novely/core").ValidAction;
32
31
  hideImage: (source: string, params?: {
@@ -1,10 +1,10 @@
1
1
  import type { Context } from '@novely/core';
2
2
  import type { VoidComponent } from 'solid-js';
3
3
  import type { SolidRendererStore } from '../renderer';
4
- import type { ContextStateStore, DeepAtom } from '@novely/renderer-toolkit';
4
+ import type { IContextState } from '../context-state';
5
5
  interface GameProps {
6
6
  context: Context;
7
- $contextState: DeepAtom<ContextStateStore<Record<PropertyKey, unknown>>>;
7
+ $contextState: IContextState;
8
8
  store: SolidRendererStore;
9
9
  controls: 'inside' | 'outside';
10
10
  skipTypewriterWhenGoingBack: boolean;
@@ -566,6 +566,28 @@
566
566
 
567
567
  /* src/styles/action-dialog/index.css */
568
568
 
569
+ /* src/styles/custom-actions/image/image.css */
570
+ .action-image {
571
+ z-index: 1;
572
+ position: fixed;
573
+ top: 0;
574
+ bottom: 0;
575
+ left: 0;
576
+ right: 0;
577
+ }
578
+ .action-image__image {
579
+ z-index: var(--z-index, 1);
580
+ object-fit: cover;
581
+ object-position: 50% 50%;
582
+ width: 100vw;
583
+ height: 100vh;
584
+ position: absolute;
585
+ }
586
+
587
+ /* src/styles/custom-actions/image/index.css */
588
+
589
+ /* src/styles/custom-actions/index.css */
590
+
569
591
  /* src/styles/dialog/dialog.css */
570
592
  .dialog {
571
593
  z-index: 25;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@novely/solid-renderer",
3
- "version": "0.39.0",
3
+ "version": "0.40.0",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -19,7 +19,7 @@
19
19
  "clsx": "^2.1.1",
20
20
  "solid-js": "1.8.21",
21
21
  "solid-transition-group": "^0.2.3",
22
- "@novely/core": "0.42.0",
22
+ "@novely/core": "0.44.0",
23
23
  "@novely/renderer-toolkit": "0.10.0",
24
24
  "@novely/typewriter": "0.5.1"
25
25
  },