@novely/solid-renderer 0.22.1 → 0.22.2

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.
@@ -14,7 +14,7 @@ type CreateRootComponentOpts = {
14
14
  controls: 'inside' | 'outside';
15
15
  rendererContext: Context;
16
16
  coreOptions: RendererInit;
17
- $contextState: DeepMapStore<ContextStateStore>;
17
+ $contextState: DeepMapStore<ContextStateStore<Record<PropertyKey, unknown>>>;
18
18
  $rendererState: DeepMapStore<RendererStateStore<RendererStoreExtension>>;
19
19
  };
20
20
  declare const createRootComponent: ({ $rendererState, $contextState, coreOptions, setRoot, characters, renderer, fullscreen, emitter, controls, skipTypewriterWhenGoingBack, rendererContext }: CreateRootComponentOpts) => Component;
@@ -1,2 +1,2 @@
1
- declare const useContextState: (id: string) => import("@novely/renderer-toolkit").DeepMapStore<Omit<import("@novely/renderer-toolkit").ContextState, never> & Omit<{}, keyof import("@novely/renderer-toolkit").ContextState> & {}>, removeContextState: (id: string) => void;
1
+ declare const useContextState: (id: string) => import("@novely/renderer-toolkit").DeepMapStore<import("@novely/renderer-toolkit").ContextState>, removeContextState: (id: string) => void;
2
2
  export { useContextState, removeContextState };
package/dist/index.jsx CHANGED
@@ -2426,12 +2426,12 @@ function useContext(context) {
2426
2426
  }
2427
2427
  function children(fn) {
2428
2428
  const children2 = createMemo(fn);
2429
- const memo = createMemo(() => resolveChildren(children2()));
2430
- memo.toArray = () => {
2431
- const c = memo();
2429
+ const memo2 = createMemo(() => resolveChildren(children2()));
2430
+ memo2.toArray = () => {
2431
+ const c = memo2();
2432
2432
  return Array.isArray(c) ? c : c != null ? [c] : [];
2433
2433
  };
2434
- return memo;
2434
+ return memo2;
2435
2435
  }
2436
2436
  var SuspenseContext;
2437
2437
  function readSignal() {
@@ -3955,6 +3955,21 @@ function deepMap(initial = {}) {
3955
3955
 
3956
3956
  // ../renderer-toolkit/dist/index.js
3957
3957
  var import_howler = __toESM(require_howler(), 1);
3958
+ var memo = (input, cb) => {
3959
+ const $memoized = atom(cb(input.get()));
3960
+ const unsubscribe = input.subscribe((value) => {
3961
+ const comparable = cb(value);
3962
+ if (!Object.is($memoized.get(), comparable)) {
3963
+ $memoized.set(comparable);
3964
+ }
3965
+ });
3966
+ onMount($memoized, () => {
3967
+ return () => {
3968
+ unsubscribe();
3969
+ };
3970
+ });
3971
+ return $memoized;
3972
+ };
3958
3973
  var getDefaultContextState = () => {
3959
3974
  return {
3960
3975
  background: {
@@ -5266,27 +5281,25 @@ var Game = (props) => {
5266
5281
  const {
5267
5282
  $contextState
5268
5283
  } = props;
5284
+ const backgroundState = from(memo($contextState, (state) => state.background));
5285
+ const charactersState = from(memo($contextState, (state) => state.characters));
5286
+ const customsState = from(memo($contextState, (state) => state.custom));
5287
+ const dialogState = from(memo($contextState, (state) => state.dialog));
5288
+ const choiceState = from(memo($contextState, (state) => state.choice));
5289
+ const inputState = from(memo($contextState, (state) => state.input));
5290
+ const textState = from(memo($contextState, (state) => state.text));
5269
5291
  const rendererState = from(data.$rendererState);
5270
- const contextState = from($contextState);
5271
5292
  const {
5272
5293
  store,
5273
5294
  context,
5274
5295
  controls,
5275
5296
  skipTypewriterWhenGoingBack
5276
5297
  } = props;
5277
- const background = () => {
5278
- const bg = contextState().background.background;
5279
- const is = isCSSImage(bg);
5280
- return {
5281
- "background-image": is ? url(bg) : "",
5282
- "background-color": is ? void 0 : bg
5283
- };
5284
- };
5285
5298
  const [auto, setAuto] = createSignal(false);
5286
5299
  const onChoicesButtonClick = ([disabled, i]) => {
5287
5300
  if (disabled)
5288
5301
  return;
5289
- const resolve = contextState().choice.resolve;
5302
+ const resolve = choiceState().resolve;
5290
5303
  $contextState.setKey("choice", {
5291
5304
  choices: [],
5292
5305
  visible: false,
@@ -5296,12 +5309,12 @@ var Game = (props) => {
5296
5309
  resolve(i);
5297
5310
  };
5298
5311
  const onInputButtonClick = () => {
5299
- if (contextState().input.error)
5312
+ if (inputState().error)
5300
5313
  return;
5301
5314
  const {
5302
5315
  resolve,
5303
5316
  cleanup
5304
- } = contextState().input;
5317
+ } = inputState();
5305
5318
  $contextState.setKey("input", {
5306
5319
  element: null,
5307
5320
  label: "",
@@ -5313,7 +5326,9 @@ var Game = (props) => {
5313
5326
  cleanup?.();
5314
5327
  resolve?.();
5315
5328
  };
5316
- const layers = () => Object.values(contextState().custom);
5329
+ const layers = () => {
5330
+ return Object.values(customsState());
5331
+ };
5317
5332
  const speed = () => data.storageData().meta[1];
5318
5333
  const onWriterEnd = (cb) => {
5319
5334
  return (prm) => {
@@ -5329,7 +5344,7 @@ var Game = (props) => {
5329
5344
  };
5330
5345
  const TextWriter = createTypewriter({
5331
5346
  resolve() {
5332
- const resolve = contextState().text.resolve;
5347
+ const resolve = textState().resolve;
5333
5348
  $contextState.setKey("text", {
5334
5349
  content: ""
5335
5350
  });
@@ -5338,7 +5353,7 @@ var Game = (props) => {
5338
5353
  });
5339
5354
  const DialogWriter = createTypewriter({
5340
5355
  resolve() {
5341
- const resolve = contextState().dialog.resolve;
5356
+ const resolve = dialogState().resolve;
5342
5357
  $contextState.setKey("dialog", {
5343
5358
  content: "",
5344
5359
  name: "",
@@ -5356,12 +5371,28 @@ var Game = (props) => {
5356
5371
  setControlPanelMenuExpanded(false);
5357
5372
  }
5358
5373
  });
5374
+ const background = createMemo(() => {
5375
+ const bg = backgroundState().background;
5376
+ const is = isCSSImage(bg);
5377
+ return {
5378
+ "background-image": is ? url(bg) : "",
5379
+ "background-color": is ? void 0 : bg
5380
+ };
5381
+ });
5382
+ const charactersCount = createMemo(() => {
5383
+ return Object.values(charactersState()).reduce((acc, c) => {
5384
+ if (c && c.visible) {
5385
+ return acc + 1;
5386
+ }
5387
+ return acc;
5388
+ }, 0);
5389
+ });
5359
5390
  return (() => {
5360
5391
  const _el$ = _tmpl$82(), _el$2 = _el$.firstChild, _el$3 = _el$2.nextSibling, _el$4 = _el$3.firstChild, _el$5 = _el$4.firstChild, _el$6 = _el$5.nextSibling, _el$26 = _el$3.nextSibling, _el$27 = _el$26.nextSibling;
5361
5392
  setAttribute(_el$2, "data-characters", true);
5362
5393
  insert(_el$2, createComponent(For, {
5363
5394
  get each() {
5364
- return Object.entries(contextState().characters);
5395
+ return Object.entries(charactersState());
5365
5396
  },
5366
5397
  children: ([character, data2]) => createComponent(Show, {
5367
5398
  get when() {
@@ -5380,10 +5411,10 @@ var Game = (props) => {
5380
5411
  }));
5381
5412
  insert(_el$3, createComponent(DialogName, {
5382
5413
  get character() {
5383
- return contextState().dialog.miniature.character;
5414
+ return dialogState().miniature.character;
5384
5415
  },
5385
5416
  get name() {
5386
- return contextState().dialog.name;
5417
+ return dialogState().name;
5387
5418
  },
5388
5419
  get characters() {
5389
5420
  return data.characters;
@@ -5394,11 +5425,11 @@ var Game = (props) => {
5394
5425
  addEventListener2(_el$4, "click", DialogWriter.clear, true);
5395
5426
  insert(_el$5, createComponent(Show, {
5396
5427
  get when() {
5397
- return contextState().dialog.miniature.emotion;
5428
+ return dialogState().miniature.emotion;
5398
5429
  },
5399
5430
  keyed: true,
5400
5431
  children: (emotion) => {
5401
- const character = contextState().dialog.miniature.character;
5432
+ const character = dialogState().miniature.character;
5402
5433
  if (!character)
5403
5434
  return null;
5404
5435
  if (!store.characters[character] || !store.characters[character].emotions[emotion]) {
@@ -5418,7 +5449,7 @@ var Game = (props) => {
5418
5449
  };
5419
5450
  },
5420
5451
  get content() {
5421
- return contextState().dialog.content;
5452
+ return dialogState().content;
5422
5453
  },
5423
5454
  get ignore() {
5424
5455
  return skipTypewriterWhenGoingBack && context.meta.goingBack || Boolean(props.isPreview);
@@ -5431,14 +5462,14 @@ var Game = (props) => {
5431
5462
  }
5432
5463
  }));
5433
5464
  insert(_el$, createComponent(Modal, {
5434
- isOpen: () => contextState().choice.visible,
5465
+ isOpen: () => choiceState().visible,
5435
5466
  trapFocus: () => !props.isPreview && !rendererState().exitPromptShown,
5436
5467
  get children() {
5437
5468
  const _el$7 = _tmpl$19(), _el$8 = _el$7.firstChild, _el$9 = _el$8.nextSibling, _el$10 = _el$9.firstChild;
5438
- insert(_el$10, () => contextState().choice.label || " ");
5469
+ insert(_el$10, () => choiceState().label || " ");
5439
5470
  insert(_el$9, createComponent(For, {
5440
5471
  get each() {
5441
- return contextState().choice.choices;
5472
+ return choiceState().choices;
5442
5473
  },
5443
5474
  children: ([text, active], i) => {
5444
5475
  const disabled = !active;
@@ -5454,7 +5485,7 @@ var Game = (props) => {
5454
5485
  }
5455
5486
  }), null);
5456
5487
  createRenderEffect((_p$) => {
5457
- const _v$ = Boolean(contextState().choice.label), _v$2 = !contextState().choice.label;
5488
+ const _v$ = Boolean(choiceState().label), _v$2 = !choiceState().label;
5458
5489
  _v$ !== _p$._v$ && setAttribute(_el$10, "data-used", _p$._v$ = _v$);
5459
5490
  _v$2 !== _p$._v$2 && setAttribute(_el$10, "aria-hidden", _p$._v$2 = _v$2);
5460
5491
  return _p$;
@@ -5466,16 +5497,16 @@ var Game = (props) => {
5466
5497
  }
5467
5498
  }), _el$26);
5468
5499
  insert(_el$, createComponent(Modal, {
5469
- isOpen: () => contextState().input.visible,
5500
+ isOpen: () => inputState().visible,
5470
5501
  trapFocus: () => !props.isPreview && !rendererState().exitPromptShown,
5471
5502
  get children() {
5472
5503
  const _el$11 = _tmpl$24(), _el$12 = _el$11.firstChild, _el$13 = _el$12.nextSibling, _el$14 = _el$13.firstChild, _el$15 = _el$14.firstChild, _el$16 = _el$15.nextSibling, _el$17 = _el$14.nextSibling;
5473
- insert(_el$15, () => contextState().input.label);
5474
- insert(_el$14, () => contextState().input.element, _el$16);
5475
- insert(_el$16, () => contextState().input.error);
5504
+ insert(_el$15, () => inputState().label);
5505
+ insert(_el$14, () => inputState().element, _el$16);
5506
+ insert(_el$16, () => inputState().error);
5476
5507
  _el$17.$$click = onInputButtonClick;
5477
5508
  insert(_el$17, () => data.t("Sumbit"));
5478
- createRenderEffect(() => setAttribute(_el$17, "aria-disabled", Boolean(contextState().input.error)));
5509
+ createRenderEffect(() => setAttribute(_el$17, "aria-disabled", Boolean(inputState().error)));
5479
5510
  return _el$11;
5480
5511
  }
5481
5512
  }), _el$26);
@@ -5513,7 +5544,7 @@ var Game = (props) => {
5513
5544
  };
5514
5545
  },
5515
5546
  get content() {
5516
- return contextState().text.content;
5547
+ return textState().content;
5517
5548
  },
5518
5549
  get ignore() {
5519
5550
  return skipTypewriterWhenGoingBack && context.meta.goingBack || Boolean(props.isPreview);
@@ -5605,12 +5636,7 @@ var Game = (props) => {
5605
5636
  }
5606
5637
  }), null);
5607
5638
  createRenderEffect((_p$) => {
5608
- const _v$7 = background(), _v$8 = `${props.className || ""} root game`, _v$9 = Object.values(contextState().characters).reduce((acc, c) => {
5609
- if (c && c.visible) {
5610
- return acc + 1;
5611
- }
5612
- return acc;
5613
- }, 0), _v$10 = !!contextState().dialog.visible, _v$11 = !contextState().dialog.visible, _v$12 = !(contextState().dialog.miniature.character && contextState().dialog.miniature.emotion), _v$13 = !contextState().dialog.content, _v$14 = !!props.isPreview, _v$15 = Boolean(contextState().text.content), _v$16 = !contextState().text.content;
5639
+ const _v$7 = background(), _v$8 = `${props.className || ""} root game`, _v$9 = charactersCount(), _v$10 = !!dialogState().visible, _v$11 = !dialogState().visible, _v$12 = !(dialogState().miniature.character && dialogState().miniature.emotion), _v$13 = !dialogState().content, _v$14 = !!props.isPreview, _v$15 = Boolean(textState().content), _v$16 = !textState().content;
5614
5640
  _p$._v$7 = style(_el$, _v$7, _p$._v$7);
5615
5641
  _v$8 !== _p$._v$8 && className(_el$, _p$._v$8 = _v$8);
5616
5642
  _v$9 !== _p$._v$9 && ((_p$._v$9 = _v$9) != null ? _el$2.style.setProperty("--shown-characters-count", _v$9) : _el$2.style.removeProperty("--shown-characters-count"));
@@ -4,7 +4,7 @@ import type { SolidRendererStore } from '../renderer';
4
4
  import type { ContextStateStore, DeepMapStore } from '@novely/renderer-toolkit';
5
5
  interface GameProps {
6
6
  context: Context;
7
- $contextState: DeepMapStore<ContextStateStore>;
7
+ $contextState: DeepMapStore<ContextStateStore<Record<PropertyKey, unknown>>>;
8
8
  store: SolidRendererStore;
9
9
  controls: 'inside' | 'outside';
10
10
  skipTypewriterWhenGoingBack: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@novely/solid-renderer",
3
- "version": "0.22.1",
3
+ "version": "0.22.2",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"