@novely/solid-renderer 0.22.0 → 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: {
@@ -4292,6 +4307,23 @@ var createRootSetter = (getContext) => {
4292
4307
  }
4293
4308
  };
4294
4309
  };
4310
+ var vibrationPossible = /* @__PURE__ */ (() => {
4311
+ let can = false;
4312
+ const onPointerDown = () => {
4313
+ can = true;
4314
+ document.removeEventListener("pointerdown", onPointerDown);
4315
+ };
4316
+ document.addEventListener("pointerdown", onPointerDown);
4317
+ return () => can;
4318
+ })();
4319
+ var vibrate = (pattern) => {
4320
+ if (vibrationPossible() && "vibrate" in navigator) {
4321
+ try {
4322
+ navigator.vibrate(pattern);
4323
+ } catch {
4324
+ }
4325
+ }
4326
+ };
4295
4327
  var toMedia = (media) => {
4296
4328
  if (media === "portrait" || media === "landscape") {
4297
4329
  return `(orientation: ${media})`;
@@ -4490,6 +4522,7 @@ var handleInputAction = ($contextState, options, context, label, onInput, setup,
4490
4522
  });
4491
4523
  input.dispatchEvent(new InputEvent("input", { bubbles: true }));
4492
4524
  };
4525
+ var handleVibrateAction = vibrate;
4493
4526
 
4494
4527
  // src/emitter.ts
4495
4528
  var createEmitter = () => {
@@ -4579,23 +4612,6 @@ var simple = (fn) => {
4579
4612
  return result;
4580
4613
  };
4581
4614
  };
4582
- var vibrationPossible = (() => {
4583
- let can = false;
4584
- const onPointerDown = () => {
4585
- can = true;
4586
- document.removeEventListener("pointerdown", onPointerDown);
4587
- };
4588
- document.addEventListener("pointerdown", onPointerDown);
4589
- return () => can;
4590
- })();
4591
- var vibrate = (pattern) => {
4592
- if (vibrationPossible() && "vibrate" in navigator) {
4593
- try {
4594
- navigator.vibrate(pattern);
4595
- } catch {
4596
- }
4597
- }
4598
- };
4599
4615
  var getDocumentStyles = () => {
4600
4616
  let css = "";
4601
4617
  for (const styleSheet of Array.from(document.styleSheets)) {
@@ -5265,27 +5281,25 @@ var Game = (props) => {
5265
5281
  const {
5266
5282
  $contextState
5267
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));
5268
5291
  const rendererState = from(data.$rendererState);
5269
- const contextState = from($contextState);
5270
5292
  const {
5271
5293
  store,
5272
5294
  context,
5273
5295
  controls,
5274
5296
  skipTypewriterWhenGoingBack
5275
5297
  } = props;
5276
- const background = () => {
5277
- const bg = contextState().background.background;
5278
- const is = isCSSImage(bg);
5279
- return {
5280
- "background-image": is ? url(bg) : "",
5281
- "background-color": is ? void 0 : bg
5282
- };
5283
- };
5284
5298
  const [auto, setAuto] = createSignal(false);
5285
5299
  const onChoicesButtonClick = ([disabled, i]) => {
5286
5300
  if (disabled)
5287
5301
  return;
5288
- const resolve = contextState().choice.resolve;
5302
+ const resolve = choiceState().resolve;
5289
5303
  $contextState.setKey("choice", {
5290
5304
  choices: [],
5291
5305
  visible: false,
@@ -5295,12 +5309,12 @@ var Game = (props) => {
5295
5309
  resolve(i);
5296
5310
  };
5297
5311
  const onInputButtonClick = () => {
5298
- if (contextState().input.error)
5312
+ if (inputState().error)
5299
5313
  return;
5300
5314
  const {
5301
5315
  resolve,
5302
5316
  cleanup
5303
- } = contextState().input;
5317
+ } = inputState();
5304
5318
  $contextState.setKey("input", {
5305
5319
  element: null,
5306
5320
  label: "",
@@ -5312,7 +5326,9 @@ var Game = (props) => {
5312
5326
  cleanup?.();
5313
5327
  resolve?.();
5314
5328
  };
5315
- const layers = () => Object.values(contextState().custom);
5329
+ const layers = () => {
5330
+ return Object.values(customsState());
5331
+ };
5316
5332
  const speed = () => data.storageData().meta[1];
5317
5333
  const onWriterEnd = (cb) => {
5318
5334
  return (prm) => {
@@ -5328,7 +5344,7 @@ var Game = (props) => {
5328
5344
  };
5329
5345
  const TextWriter = createTypewriter({
5330
5346
  resolve() {
5331
- const resolve = contextState().text.resolve;
5347
+ const resolve = textState().resolve;
5332
5348
  $contextState.setKey("text", {
5333
5349
  content: ""
5334
5350
  });
@@ -5337,7 +5353,7 @@ var Game = (props) => {
5337
5353
  });
5338
5354
  const DialogWriter = createTypewriter({
5339
5355
  resolve() {
5340
- const resolve = contextState().dialog.resolve;
5356
+ const resolve = dialogState().resolve;
5341
5357
  $contextState.setKey("dialog", {
5342
5358
  content: "",
5343
5359
  name: "",
@@ -5355,12 +5371,28 @@ var Game = (props) => {
5355
5371
  setControlPanelMenuExpanded(false);
5356
5372
  }
5357
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
+ });
5358
5390
  return (() => {
5359
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;
5360
5392
  setAttribute(_el$2, "data-characters", true);
5361
5393
  insert(_el$2, createComponent(For, {
5362
5394
  get each() {
5363
- return Object.entries(contextState().characters);
5395
+ return Object.entries(charactersState());
5364
5396
  },
5365
5397
  children: ([character, data2]) => createComponent(Show, {
5366
5398
  get when() {
@@ -5379,10 +5411,10 @@ var Game = (props) => {
5379
5411
  }));
5380
5412
  insert(_el$3, createComponent(DialogName, {
5381
5413
  get character() {
5382
- return contextState().dialog.miniature.character;
5414
+ return dialogState().miniature.character;
5383
5415
  },
5384
5416
  get name() {
5385
- return contextState().dialog.name;
5417
+ return dialogState().name;
5386
5418
  },
5387
5419
  get characters() {
5388
5420
  return data.characters;
@@ -5393,11 +5425,11 @@ var Game = (props) => {
5393
5425
  addEventListener2(_el$4, "click", DialogWriter.clear, true);
5394
5426
  insert(_el$5, createComponent(Show, {
5395
5427
  get when() {
5396
- return contextState().dialog.miniature.emotion;
5428
+ return dialogState().miniature.emotion;
5397
5429
  },
5398
5430
  keyed: true,
5399
5431
  children: (emotion) => {
5400
- const character = contextState().dialog.miniature.character;
5432
+ const character = dialogState().miniature.character;
5401
5433
  if (!character)
5402
5434
  return null;
5403
5435
  if (!store.characters[character] || !store.characters[character].emotions[emotion]) {
@@ -5417,7 +5449,7 @@ var Game = (props) => {
5417
5449
  };
5418
5450
  },
5419
5451
  get content() {
5420
- return contextState().dialog.content;
5452
+ return dialogState().content;
5421
5453
  },
5422
5454
  get ignore() {
5423
5455
  return skipTypewriterWhenGoingBack && context.meta.goingBack || Boolean(props.isPreview);
@@ -5430,14 +5462,14 @@ var Game = (props) => {
5430
5462
  }
5431
5463
  }));
5432
5464
  insert(_el$, createComponent(Modal, {
5433
- isOpen: () => contextState().choice.visible,
5465
+ isOpen: () => choiceState().visible,
5434
5466
  trapFocus: () => !props.isPreview && !rendererState().exitPromptShown,
5435
5467
  get children() {
5436
5468
  const _el$7 = _tmpl$19(), _el$8 = _el$7.firstChild, _el$9 = _el$8.nextSibling, _el$10 = _el$9.firstChild;
5437
- insert(_el$10, () => contextState().choice.label || " ");
5469
+ insert(_el$10, () => choiceState().label || " ");
5438
5470
  insert(_el$9, createComponent(For, {
5439
5471
  get each() {
5440
- return contextState().choice.choices;
5472
+ return choiceState().choices;
5441
5473
  },
5442
5474
  children: ([text, active], i) => {
5443
5475
  const disabled = !active;
@@ -5453,7 +5485,7 @@ var Game = (props) => {
5453
5485
  }
5454
5486
  }), null);
5455
5487
  createRenderEffect((_p$) => {
5456
- const _v$ = Boolean(contextState().choice.label), _v$2 = !contextState().choice.label;
5488
+ const _v$ = Boolean(choiceState().label), _v$2 = !choiceState().label;
5457
5489
  _v$ !== _p$._v$ && setAttribute(_el$10, "data-used", _p$._v$ = _v$);
5458
5490
  _v$2 !== _p$._v$2 && setAttribute(_el$10, "aria-hidden", _p$._v$2 = _v$2);
5459
5491
  return _p$;
@@ -5465,16 +5497,16 @@ var Game = (props) => {
5465
5497
  }
5466
5498
  }), _el$26);
5467
5499
  insert(_el$, createComponent(Modal, {
5468
- isOpen: () => contextState().input.visible,
5500
+ isOpen: () => inputState().visible,
5469
5501
  trapFocus: () => !props.isPreview && !rendererState().exitPromptShown,
5470
5502
  get children() {
5471
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;
5472
- insert(_el$15, () => contextState().input.label);
5473
- insert(_el$14, () => contextState().input.element, _el$16);
5474
- 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);
5475
5507
  _el$17.$$click = onInputButtonClick;
5476
5508
  insert(_el$17, () => data.t("Sumbit"));
5477
- createRenderEffect(() => setAttribute(_el$17, "aria-disabled", Boolean(contextState().input.error)));
5509
+ createRenderEffect(() => setAttribute(_el$17, "aria-disabled", Boolean(inputState().error)));
5478
5510
  return _el$11;
5479
5511
  }
5480
5512
  }), _el$26);
@@ -5512,7 +5544,7 @@ var Game = (props) => {
5512
5544
  };
5513
5545
  },
5514
5546
  get content() {
5515
- return contextState().text.content;
5547
+ return textState().content;
5516
5548
  },
5517
5549
  get ignore() {
5518
5550
  return skipTypewriterWhenGoingBack && context.meta.goingBack || Boolean(props.isPreview);
@@ -5604,12 +5636,7 @@ var Game = (props) => {
5604
5636
  }
5605
5637
  }), null);
5606
5638
  createRenderEffect((_p$) => {
5607
- const _v$7 = background(), _v$8 = `${props.className || ""} root game`, _v$9 = Object.values(contextState().characters).reduce((acc, c) => {
5608
- if (c && c.visible) {
5609
- return acc + 1;
5610
- }
5611
- return acc;
5612
- }, 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;
5613
5640
  _p$._v$7 = style(_el$, _v$7, _p$._v$7);
5614
5641
  _v$8 !== _p$._v$8 && className(_el$, _p$._v$8 = _v$8);
5615
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"));
@@ -6136,7 +6163,7 @@ var createSolidRenderer = ({
6136
6163
  handleClearCustomAction($contextState, fn);
6137
6164
  },
6138
6165
  vibrate(pattern) {
6139
- vibrate(pattern);
6166
+ handleVibrateAction(pattern);
6140
6167
  },
6141
6168
  text(content, resolve) {
6142
6169
  handleTextAction($contextState, content, resolve);
@@ -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/dist/utils.d.ts CHANGED
@@ -13,7 +13,5 @@ declare const canvasDrawImages: (canvas: HTMLCanvasElement | undefined, ctx: Can
13
13
  declare const url: <T extends string>(str: T) => `url(${T})`;
14
14
  declare const onKey: (cb: (event: KeyboardEvent) => void, ...keys: string[]) => (e: KeyboardEvent) => void;
15
15
  declare const simple: <T extends unknown[], R>(fn: (...args: T) => R) => (...args: T) => R;
16
- declare const vibrationPossible: () => boolean;
17
- declare const vibrate: (pattern: VibratePattern) => void;
18
16
  declare const getDocumentStyles: () => string;
19
- export { isCSSImage, canvasDrawImages, url, createImage, capitalize, onKey, findLast, simple, vibrationPossible, vibrate, getDocumentStyles, };
17
+ export { isCSSImage, canvasDrawImages, url, createImage, capitalize, onKey, findLast, simple, getDocumentStyles, };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@novely/solid-renderer",
3
- "version": "0.22.0",
3
+ "version": "0.22.2",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -20,7 +20,7 @@
20
20
  },
21
21
  "dependencies": {
22
22
  "@novely/core": "*",
23
- "@novely/renderer-toolkit": "workspace:^",
23
+ "@novely/renderer-toolkit": "*",
24
24
  "@novely/typewriter": "*",
25
25
  "retrieved": "^0.1.0",
26
26
  "solid-js": "1.8.5"