@novely/solid-renderer 0.10.5 → 0.11.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.
Files changed (2) hide show
  1. package/dist/index.jsx +139 -84
  2. package/package.json +53 -53
package/dist/index.jsx CHANGED
@@ -1,4 +1,4 @@
1
- // ../../node_modules/.pnpm/solid-js@1.7.3/node_modules/solid-js/dist/solid.js
1
+ // ../../node_modules/.pnpm/solid-js@1.8.5/node_modules/solid-js/dist/solid.js
2
2
  var sharedConfig = {
3
3
  context: void 0,
4
4
  registry: void 0
@@ -40,11 +40,11 @@ var Effects = null;
40
40
  var ExecCount = 0;
41
41
  var [transPending, setTransPending] = /* @__PURE__ */ createSignal(false);
42
42
  function createRoot(fn, detachedOwner) {
43
- const listener = Listener, owner = Owner, unowned = fn.length === 0, root = unowned ? UNOWNED : {
43
+ const listener = Listener, owner = Owner, unowned = fn.length === 0, current = detachedOwner === void 0 ? owner : detachedOwner, root = unowned ? UNOWNED : {
44
44
  owned: null,
45
45
  cleanups: null,
46
- context: null,
47
- owner: detachedOwner === void 0 ? owner : detachedOwner
46
+ context: current ? current.context : null,
47
+ owner: current
48
48
  }, updateFn = unowned ? fn : () => fn(() => untrack(() => cleanNode(root)));
49
49
  Owner = root;
50
50
  Listener = null;
@@ -83,7 +83,7 @@ function createRenderEffect(fn, value, options) {
83
83
  }
84
84
  function createEffect(fn, value, options) {
85
85
  runEffects = runUserEffects;
86
- const c = createComputation(fn, value, false, STALE), s = SuspenseContext && lookup(Owner, SuspenseContext.id);
86
+ const c = createComputation(fn, value, false, STALE), s = SuspenseContext && useContext(SuspenseContext);
87
87
  if (s)
88
88
  c.suspense = s;
89
89
  if (!options || !options.render)
@@ -187,8 +187,7 @@ function createContext(defaultValue, options) {
187
187
  };
188
188
  }
189
189
  function useContext(context) {
190
- let ctx;
191
- return (ctx = lookup(Owner, context.id)) !== void 0 ? ctx : context.defaultValue;
190
+ return Owner && Owner.context && Owner.context[context.id] !== void 0 ? Owner.context[context.id] : context.defaultValue;
192
191
  }
193
192
  function children(fn) {
194
193
  const children2 = createMemo(fn);
@@ -338,7 +337,7 @@ function createComputation(fn, init, pure, state = STALE, options) {
338
337
  cleanups: null,
339
338
  value: init,
340
339
  owner: Owner,
341
- context: null,
340
+ context: Owner ? Owner.context : null,
342
341
  pure
343
342
  };
344
343
  if (Transition && Transition.running) {
@@ -515,8 +514,18 @@ function runUserEffects(queue) {
515
514
  else
516
515
  queue[userLength++] = e;
517
516
  }
518
- if (sharedConfig.context)
517
+ if (sharedConfig.context) {
518
+ if (sharedConfig.count) {
519
+ sharedConfig.effects || (sharedConfig.effects = []);
520
+ sharedConfig.effects.push(...queue.slice(0, userLength));
521
+ return;
522
+ } else if (sharedConfig.effects) {
523
+ queue = [...sharedConfig.effects, ...queue];
524
+ userLength += sharedConfig.effects.length;
525
+ delete sharedConfig.effects;
526
+ }
519
527
  setHydrateContext();
528
+ }
520
529
  for (i = 0; i < userLength; i++)
521
530
  runTop(queue[i]);
522
531
  }
@@ -591,7 +600,6 @@ function cleanNode(node) {
591
600
  node.tState = 0;
592
601
  else
593
602
  node.state = 0;
594
- node.context = null;
595
603
  }
596
604
  function reset(node, top) {
597
605
  if (!top) {
@@ -610,27 +618,28 @@ function castError(err) {
610
618
  cause: err
611
619
  });
612
620
  }
613
- function runErrors(fns, err) {
614
- for (const f of fns)
615
- f(err);
621
+ function runErrors(err, fns, owner) {
622
+ try {
623
+ for (const f of fns)
624
+ f(err);
625
+ } catch (e) {
626
+ handleError(e, owner && owner.owner || null);
627
+ }
616
628
  }
617
- function handleError(err) {
618
- const fns = ERROR && lookup(Owner, ERROR);
619
- if (!fns)
620
- throw err;
629
+ function handleError(err, owner = Owner) {
630
+ const fns = ERROR && owner && owner.context && owner.context[ERROR];
621
631
  const error = castError(err);
632
+ if (!fns)
633
+ throw error;
622
634
  if (Effects)
623
635
  Effects.push({
624
636
  fn() {
625
- runErrors(fns, error);
637
+ runErrors(error, fns, owner);
626
638
  },
627
639
  state: STALE
628
640
  });
629
641
  else
630
- runErrors(fns, error);
631
- }
632
- function lookup(owner, key) {
633
- return owner ? owner.context && owner.context[key] !== void 0 ? owner.context[key] : lookup(owner.owner, key) : void 0;
642
+ runErrors(error, fns, owner);
634
643
  }
635
644
  function resolveChildren(children2) {
636
645
  if (typeof children2 === "function" && !children2.length)
@@ -650,6 +659,7 @@ function createProvider(id, options) {
650
659
  let res;
651
660
  createRenderEffect(() => res = untrack(() => {
652
661
  Owner.context = {
662
+ ...Owner.context,
653
663
  [id]: props.value
654
664
  };
655
665
  return children(() => props.children);
@@ -812,6 +822,13 @@ var propTraps = {
812
822
  function resolveSource(s) {
813
823
  return !(s = typeof s === "function" ? s() : s) ? {} : s;
814
824
  }
825
+ function resolveSources() {
826
+ for (let i = 0, length = this.length; i < length; ++i) {
827
+ const v = this[i]();
828
+ if (v !== void 0)
829
+ return v;
830
+ }
831
+ }
815
832
  function mergeProps(...sources) {
816
833
  let proxy = false;
817
834
  for (let i = 0; i < sources.length; i++) {
@@ -844,22 +861,41 @@ function mergeProps(...sources) {
844
861
  }, propTraps);
845
862
  }
846
863
  const target = {};
864
+ const sourcesMap = {};
865
+ const defined = /* @__PURE__ */ new Set();
847
866
  for (let i = sources.length - 1; i >= 0; i--) {
848
- if (sources[i]) {
849
- const descriptors = Object.getOwnPropertyDescriptors(sources[i]);
850
- for (const key in descriptors) {
851
- if (key in target)
852
- continue;
853
- Object.defineProperty(target, key, {
854
- enumerable: true,
855
- get() {
856
- for (let i2 = sources.length - 1; i2 >= 0; i2--) {
857
- const v = (sources[i2] || {})[key];
858
- if (v !== void 0)
859
- return v;
860
- }
867
+ const source = sources[i];
868
+ if (!source)
869
+ continue;
870
+ const sourceKeys = Object.getOwnPropertyNames(source);
871
+ for (let i2 = 0, length = sourceKeys.length; i2 < length; i2++) {
872
+ const key = sourceKeys[i2];
873
+ if (key === "__proto__" || key === "constructor")
874
+ continue;
875
+ const desc = Object.getOwnPropertyDescriptor(source, key);
876
+ if (!defined.has(key)) {
877
+ if (desc.get) {
878
+ defined.add(key);
879
+ Object.defineProperty(target, key, {
880
+ enumerable: true,
881
+ configurable: true,
882
+ get: resolveSources.bind(sourcesMap[key] = [desc.get.bind(source)])
883
+ });
884
+ } else {
885
+ if (desc.value !== void 0)
886
+ defined.add(key);
887
+ target[key] = desc.value;
888
+ }
889
+ } else {
890
+ const sources2 = sourcesMap[key];
891
+ if (sources2) {
892
+ if (desc.get) {
893
+ sources2.push(desc.get.bind(source));
894
+ } else if (desc.value !== void 0) {
895
+ sources2.push(() => desc.value);
861
896
  }
862
- });
897
+ } else if (target[key] === void 0)
898
+ target[key] = desc.value;
863
899
  }
864
900
  }
865
901
  }
@@ -932,7 +968,7 @@ function Match(props) {
932
968
  }
933
969
  var SuspenseListContext = createContext();
934
970
 
935
- // ../../node_modules/.pnpm/solid-js@1.7.3/node_modules/solid-js/web/dist/web.js
971
+ // ../../node_modules/.pnpm/solid-js@1.8.5/node_modules/solid-js/web/dist/web.js
936
972
  var booleans = ["allowfullscreen", "async", "autofocus", "autoplay", "checked", "controls", "default", "disabled", "formnovalidate", "hidden", "indeterminate", "ismap", "loop", "multiple", "muted", "nomodule", "novalidate", "open", "playsinline", "readonly", "required", "reversed", "seamless", "selected"];
937
973
  var Properties = /* @__PURE__ */ new Set(["className", "value", "readOnly", "formNoValidate", "isMap", "noModule", "playsInline", ...booleans]);
938
974
  var ChildProperties = /* @__PURE__ */ new Set(["innerHTML", "textContent", "innerText", "children"]);
@@ -1049,7 +1085,7 @@ function template(html, isCE, isSVG) {
1049
1085
  t.innerHTML = html;
1050
1086
  return isSVG ? t.content.firstChild.firstChild : t.content.firstChild;
1051
1087
  };
1052
- const fn = isCE ? () => (node || (node = create())).cloneNode(true) : () => untrack(() => document.importNode(node || (node = create()), true));
1088
+ const fn = isCE ? () => untrack(() => document.importNode(node || (node = create()), true)) : () => (node || (node = create())).cloneNode(true);
1053
1089
  fn.cloneNode = fn;
1054
1090
  return fn;
1055
1091
  }
@@ -1064,18 +1100,24 @@ function delegateEvents(eventNames, document2 = window.document) {
1064
1100
  }
1065
1101
  }
1066
1102
  function setAttribute(node, name, value) {
1103
+ if (sharedConfig.context)
1104
+ return;
1067
1105
  if (value == null)
1068
1106
  node.removeAttribute(name);
1069
1107
  else
1070
1108
  node.setAttribute(name, value);
1071
1109
  }
1072
1110
  function setAttributeNS(node, namespace, name, value) {
1111
+ if (sharedConfig.context)
1112
+ return;
1073
1113
  if (value == null)
1074
1114
  node.removeAttributeNS(namespace, name);
1075
1115
  else
1076
1116
  node.setAttributeNS(namespace, name, value);
1077
1117
  }
1078
1118
  function className(node, value) {
1119
+ if (sharedConfig.context)
1120
+ return;
1079
1121
  if (value == null)
1080
1122
  node.removeAttribute("class");
1081
1123
  else
@@ -1218,7 +1260,8 @@ function assignProp(node, prop, value, prev, isSVG, skipRef) {
1218
1260
  if (forceProp) {
1219
1261
  prop = prop.slice(5);
1220
1262
  isProp = true;
1221
- }
1263
+ } else if (sharedConfig.context)
1264
+ return value;
1222
1265
  if (prop === "class" || prop === "className")
1223
1266
  className(node, value);
1224
1267
  else if (isCE && !isProp && !isChildProp)
@@ -1321,10 +1364,13 @@ function insertExpression(parent, value, current, marker, unwrapArray) {
1321
1364
  if (sharedConfig.context) {
1322
1365
  if (!array.length)
1323
1366
  return current;
1324
- for (let i = 0; i < array.length; i++) {
1325
- if (array[i].parentNode)
1326
- return current = array;
1327
- }
1367
+ if (marker === void 0)
1368
+ return [...parent.childNodes];
1369
+ let node = array[0];
1370
+ let nodes = [node];
1371
+ while ((node = node.nextSibling) !== marker)
1372
+ nodes.push(node);
1373
+ return current = nodes;
1328
1374
  }
1329
1375
  if (array.length === 0) {
1330
1376
  current = cleanChildren(parent, current, marker);
@@ -1340,7 +1386,7 @@ function insertExpression(parent, value, current, marker, unwrapArray) {
1340
1386
  appendNodes(parent, array);
1341
1387
  }
1342
1388
  current = array;
1343
- } else if (value instanceof Node) {
1389
+ } else if (value.nodeType) {
1344
1390
  if (sharedConfig.context && value.parentNode)
1345
1391
  return current = multi ? [value] : value;
1346
1392
  if (Array.isArray(current)) {
@@ -1353,20 +1399,20 @@ function insertExpression(parent, value, current, marker, unwrapArray) {
1353
1399
  parent.replaceChild(value, parent.firstChild);
1354
1400
  current = value;
1355
1401
  } else
1356
- console.warn(`Unrecognized value. Skipped inserting`, value);
1402
+ ;
1357
1403
  return current;
1358
1404
  }
1359
1405
  function normalizeIncomingArray(normalized, array, current, unwrap2) {
1360
1406
  let dynamic = false;
1361
1407
  for (let i = 0, len = array.length; i < len; i++) {
1362
- let item = array[i], prev = current && current[i];
1363
- if (item instanceof Node) {
1364
- normalized.push(item);
1365
- } else if (item == null || item === true || item === false)
1408
+ let item = array[i], prev = current && current[i], t;
1409
+ if (item == null || item === true || item === false)
1366
1410
  ;
1367
- else if (Array.isArray(item)) {
1411
+ else if ((t = typeof item) === "object" && item.nodeType) {
1412
+ normalized.push(item);
1413
+ } else if (Array.isArray(item)) {
1368
1414
  dynamic = normalizeIncomingArray(normalized, item, prev) || dynamic;
1369
- } else if (typeof item === "function") {
1415
+ } else if (t === "function") {
1370
1416
  if (unwrap2) {
1371
1417
  while (typeof item === "function")
1372
1418
  item = item();
@@ -1377,10 +1423,9 @@ function normalizeIncomingArray(normalized, array, current, unwrap2) {
1377
1423
  }
1378
1424
  } else {
1379
1425
  const value = String(item);
1380
- if (prev && prev.nodeType === 3) {
1381
- prev.data = value;
1426
+ if (prev && prev.nodeType === 3 && prev.data === value)
1382
1427
  normalized.push(prev);
1383
- } else
1428
+ else
1384
1429
  normalized.push(document.createTextNode(value));
1385
1430
  }
1386
1431
  }
@@ -1411,10 +1456,13 @@ function cleanChildren(parent, current, marker, replacement) {
1411
1456
  parent.insertBefore(node, marker);
1412
1457
  return [node];
1413
1458
  }
1459
+ var RequestContext = Symbol();
1414
1460
 
1415
- // ../../node_modules/.pnpm/solid-js@1.7.3/node_modules/solid-js/store/dist/store.js
1461
+ // ../../node_modules/.pnpm/solid-js@1.8.5/node_modules/solid-js/store/dist/store.js
1416
1462
  var $RAW = Symbol("store-raw");
1417
1463
  var $NODE = Symbol("store-node");
1464
+ var $HAS = Symbol("store-has");
1465
+ var $SELF = Symbol("store-self");
1418
1466
  function wrap$1(value) {
1419
1467
  let p = value[$PROXY];
1420
1468
  if (!p) {
@@ -1473,16 +1521,23 @@ function unwrap(item, set = /* @__PURE__ */ new Set()) {
1473
1521
  }
1474
1522
  return item;
1475
1523
  }
1476
- function getDataNodes(target) {
1477
- let nodes = target[$NODE];
1524
+ function getNodes(target, symbol) {
1525
+ let nodes = target[symbol];
1478
1526
  if (!nodes)
1479
- Object.defineProperty(target, $NODE, {
1527
+ Object.defineProperty(target, symbol, {
1480
1528
  value: nodes = /* @__PURE__ */ Object.create(null)
1481
1529
  });
1482
1530
  return nodes;
1483
1531
  }
1484
- function getDataNode(nodes, property, value) {
1485
- return nodes[property] || (nodes[property] = createDataNode(value));
1532
+ function getNode(nodes, property, value) {
1533
+ if (nodes[property])
1534
+ return nodes[property];
1535
+ const [s, set] = createSignal(value, {
1536
+ equals: false,
1537
+ internal: true
1538
+ });
1539
+ s.$ = set;
1540
+ return nodes[property] = s;
1486
1541
  }
1487
1542
  function proxyDescriptor$1(target, property) {
1488
1543
  const desc = Reflect.getOwnPropertyDescriptor(target, property);
@@ -1494,23 +1549,12 @@ function proxyDescriptor$1(target, property) {
1494
1549
  return desc;
1495
1550
  }
1496
1551
  function trackSelf(target) {
1497
- if (getListener()) {
1498
- const nodes = getDataNodes(target);
1499
- (nodes._ || (nodes._ = createDataNode()))();
1500
- }
1552
+ getListener() && getNode(getNodes(target, $NODE), $SELF)();
1501
1553
  }
1502
1554
  function ownKeys(target) {
1503
1555
  trackSelf(target);
1504
1556
  return Reflect.ownKeys(target);
1505
1557
  }
1506
- function createDataNode(value) {
1507
- const [s, set] = createSignal(value, {
1508
- equals: false,
1509
- internal: true
1510
- });
1511
- s.$ = set;
1512
- return s;
1513
- }
1514
1558
  var proxyTraps$1 = {
1515
1559
  get(target, property, receiver) {
1516
1560
  if (property === $RAW)
@@ -1521,22 +1565,22 @@ var proxyTraps$1 = {
1521
1565
  trackSelf(target);
1522
1566
  return receiver;
1523
1567
  }
1524
- const nodes = getDataNodes(target);
1568
+ const nodes = getNodes(target, $NODE);
1525
1569
  const tracked = nodes[property];
1526
1570
  let value = tracked ? tracked() : target[property];
1527
- if (property === $NODE || property === "__proto__")
1571
+ if (property === $NODE || property === $HAS || property === "__proto__")
1528
1572
  return value;
1529
1573
  if (!tracked) {
1530
1574
  const desc = Object.getOwnPropertyDescriptor(target, property);
1531
1575
  if (getListener() && (typeof value !== "function" || target.hasOwnProperty(property)) && !(desc && desc.get))
1532
- value = getDataNode(nodes, property, value)();
1576
+ value = getNode(nodes, property, value)();
1533
1577
  }
1534
1578
  return isWrappable(value) ? wrap$1(value) : value;
1535
1579
  },
1536
1580
  has(target, property) {
1537
- if (property === $RAW || property === $PROXY || property === $TRACK || property === $NODE || property === "__proto__")
1581
+ if (property === $RAW || property === $PROXY || property === $TRACK || property === $NODE || property === $HAS || property === "__proto__")
1538
1582
  return true;
1539
- this.get(target, property, target);
1583
+ getListener() && getNode(getNodes(target, $HAS), property)();
1540
1584
  return property in target;
1541
1585
  },
1542
1586
  set() {
@@ -1552,16 +1596,24 @@ function setProperty(state, property, value, deleting = false) {
1552
1596
  if (!deleting && state[property] === value)
1553
1597
  return;
1554
1598
  const prev = state[property], len = state.length;
1555
- if (value === void 0)
1599
+ if (value === void 0) {
1556
1600
  delete state[property];
1557
- else
1601
+ if (state[$HAS] && state[$HAS][property] && prev !== void 0)
1602
+ state[$HAS][property].$();
1603
+ } else {
1558
1604
  state[property] = value;
1559
- let nodes = getDataNodes(state), node;
1560
- if (node = getDataNode(nodes, property, prev))
1605
+ if (state[$HAS] && state[$HAS][property] && prev === void 0)
1606
+ state[$HAS][property].$();
1607
+ }
1608
+ let nodes = getNodes(state, $NODE), node;
1609
+ if (node = getNode(nodes, property, prev))
1561
1610
  node.$(() => value);
1562
- if (Array.isArray(state) && state.length !== len)
1563
- (node = getDataNode(nodes, "length", len)) && node.$(state.length);
1564
- (node = nodes._) && node.$();
1611
+ if (Array.isArray(state) && state.length !== len) {
1612
+ for (let i = state.length; i < len; i++)
1613
+ (node = nodes[i]) && node.$();
1614
+ (node = getNode(nodes, "length", len)) && node.$(state.length);
1615
+ }
1616
+ (node = nodes[$SELF]) && node.$();
1565
1617
  }
1566
1618
  function mergeStoreNode(state, value) {
1567
1619
  const keys = Object.keys(value);
@@ -3255,6 +3307,9 @@ var createSolidRenderer = ({
3255
3307
  showScreen(name) {
3256
3308
  setState("screen", name);
3257
3309
  },
3310
+ getScreen() {
3311
+ return state.screen;
3312
+ },
3258
3313
  showExitPrompt() {
3259
3314
  setState("exitPromptShown", true);
3260
3315
  },
package/package.json CHANGED
@@ -1,54 +1,54 @@
1
1
  {
2
- "name": "@novely/solid-renderer",
3
- "version": "0.10.5",
4
- "type": "module",
5
- "publishConfig": {
6
- "access": "public"
7
- },
8
- "types": "./dist/index.d.ts",
9
- "main": "./dist/index.jsx",
10
- "module": "./dist/index.jsx",
11
- "sideEffects": false,
12
- "scripts": {
13
- "dev": "node ./build.js --watch",
14
- "build": "node ./build.js && tsc"
15
- },
16
- "devDependencies": {
17
- "esbuild": "^0.19.2",
18
- "esbuild-plugin-solid": "^0.5.0",
19
- "typescript": "^5.1.6"
20
- },
21
- "dependencies": {
22
- "@novely/core": "*",
23
- "@novely/typewriter": "*",
24
- "solid-js": "1.7.3"
25
- },
26
- "peerDependencies": {
27
- "@novely/core": "*",
28
- "solid-js": "*"
29
- },
30
- "license": "ISC",
31
- "bugs": {
32
- "url": "https://github.com/yhdgms1/novely/issues"
33
- },
34
- "homepage": "https://github.com/yhdgms1/novely/tree/main/packages/solid-renderer",
35
- "keywords": [
36
- "novely",
37
- "solid-js",
38
- "solid",
39
- "renderer",
40
- "novel"
41
- ],
42
- "author": {
43
- "name": "Artemiy Schukin",
44
- "url": "https://github.com/yhdgms1"
45
- },
46
- "contributors": [],
47
- "repository": {
48
- "type": "git",
49
- "url": "git+https://github.com/yhdgms1/novely.git"
50
- },
51
- "files": [
52
- "dist/*"
53
- ]
54
- }
2
+ "name": "@novely/solid-renderer",
3
+ "version": "0.11.0",
4
+ "type": "module",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "types": "./dist/index.d.ts",
9
+ "main": "./dist/index.jsx",
10
+ "module": "./dist/index.jsx",
11
+ "sideEffects": false,
12
+ "devDependencies": {
13
+ "esbuild": "^0.19.2",
14
+ "esbuild-plugin-solid": "^0.5.0",
15
+ "typescript": "^5.2.2"
16
+ },
17
+ "dependencies": {
18
+ "@novely/core": "*",
19
+ "@novely/typewriter": "*",
20
+ "solid-js": "1.8.5"
21
+ },
22
+ "peerDependencies": {
23
+ "@novely/core": "*",
24
+ "solid-js": "*"
25
+ },
26
+ "license": "ISC",
27
+ "bugs": {
28
+ "url": "https://github.com/yhdgms1/novely/issues"
29
+ },
30
+ "homepage": "https://github.com/yhdgms1/novely/tree/main/packages/solid-renderer",
31
+ "keywords": [
32
+ "novely",
33
+ "solid-js",
34
+ "solid",
35
+ "renderer",
36
+ "novel"
37
+ ],
38
+ "author": {
39
+ "name": "Artemiy Schukin",
40
+ "url": "https://github.com/yhdgms1"
41
+ },
42
+ "contributors": [],
43
+ "repository": {
44
+ "type": "git",
45
+ "url": "git+https://github.com/yhdgms1/novely.git"
46
+ },
47
+ "files": [
48
+ "dist/*"
49
+ ],
50
+ "scripts": {
51
+ "dev": "node ./build.js --watch",
52
+ "build": "node ./build.js && tsc"
53
+ }
54
+ }