@fictjs/runtime 0.0.4 → 0.0.5

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.
package/dist/index.dev.js CHANGED
@@ -790,6 +790,21 @@ function effect(fn) {
790
790
  function effectOper() {
791
791
  disposeNode(this);
792
792
  }
793
+ function effectScope(fn) {
794
+ const e = { deps: void 0, depsTail: void 0, subs: void 0, subsTail: void 0, flags: 0 };
795
+ const prevSub = activeSub;
796
+ if (prevSub !== void 0) link(e, prevSub, 0);
797
+ activeSub = e;
798
+ try {
799
+ fn();
800
+ } finally {
801
+ activeSub = prevSub;
802
+ }
803
+ return effectScopeOper.bind(e);
804
+ }
805
+ function effectScopeOper() {
806
+ disposeNode(this);
807
+ }
793
808
  function batch(fn) {
794
809
  ++batchDepth;
795
810
  try {
@@ -1038,471 +1053,190 @@ function createRenderEffect(fn) {
1038
1053
  return teardown;
1039
1054
  }
1040
1055
 
1041
- // src/hooks.ts
1042
- var ctxStack = [];
1043
- function __fictUseContext() {
1044
- if (ctxStack.length === 0) {
1045
- const ctx2 = { slots: [], cursor: 0 };
1046
- ctxStack.push(ctx2);
1047
- return ctx2;
1048
- }
1049
- const ctx = ctxStack[ctxStack.length - 1];
1050
- ctx.cursor = 0;
1051
- return ctx;
1052
- }
1053
- function __fictPushContext() {
1054
- const ctx = { slots: [], cursor: 0 };
1055
- ctxStack.push(ctx);
1056
- return ctx;
1057
- }
1058
- function __fictPopContext() {
1059
- ctxStack.pop();
1060
- }
1061
- function __fictResetContext() {
1062
- ctxStack.length = 0;
1063
- }
1064
- function __fictUseSignal(ctx, initial, slot) {
1065
- const index = slot ?? ctx.cursor++;
1066
- if (!ctx.slots[index]) {
1067
- ctx.slots[index] = signal(initial);
1068
- }
1069
- return ctx.slots[index];
1070
- }
1071
- function __fictUseMemo(ctx, fn, slot) {
1072
- const index = slot ?? ctx.cursor++;
1073
- if (!ctx.slots[index]) {
1074
- ctx.slots[index] = createMemo(fn);
1075
- }
1076
- return ctx.slots[index];
1077
- }
1078
- function __fictUseEffect(ctx, fn, slot) {
1079
- const index = slot ?? ctx.cursor++;
1080
- if (!ctx.slots[index]) {
1081
- ctx.slots[index] = createEffect(fn);
1056
+ // src/constants.ts
1057
+ var booleans = [
1058
+ "allowfullscreen",
1059
+ "async",
1060
+ "alpha",
1061
+ // HTMLInputElement
1062
+ "autofocus",
1063
+ // HTMLElement prop
1064
+ "autoplay",
1065
+ "checked",
1066
+ "controls",
1067
+ "default",
1068
+ "disabled",
1069
+ "formnovalidate",
1070
+ "hidden",
1071
+ // HTMLElement prop
1072
+ "indeterminate",
1073
+ "inert",
1074
+ // HTMLElement prop
1075
+ "ismap",
1076
+ "loop",
1077
+ "multiple",
1078
+ "muted",
1079
+ "nomodule",
1080
+ "novalidate",
1081
+ "open",
1082
+ "playsinline",
1083
+ "readonly",
1084
+ "required",
1085
+ "reversed",
1086
+ "seamless",
1087
+ // HTMLIframeElement - non-standard
1088
+ "selected",
1089
+ // Experimental attributes
1090
+ "adauctionheaders",
1091
+ "browsingtopics",
1092
+ "credentialless",
1093
+ "defaultchecked",
1094
+ "defaultmuted",
1095
+ "defaultselected",
1096
+ "defer",
1097
+ "disablepictureinpicture",
1098
+ "disableremoteplayback",
1099
+ "preservespitch",
1100
+ "shadowrootclonable",
1101
+ "shadowrootcustomelementregistry",
1102
+ "shadowrootdelegatesfocus",
1103
+ "shadowrootserializable",
1104
+ "sharedstoragewritable"
1105
+ ];
1106
+ var BooleanAttributes = new Set(booleans);
1107
+ var Properties = /* @__PURE__ */ new Set([
1108
+ // Core properties
1109
+ "className",
1110
+ "value",
1111
+ // CamelCase booleans
1112
+ "readOnly",
1113
+ "noValidate",
1114
+ "formNoValidate",
1115
+ "isMap",
1116
+ "noModule",
1117
+ "playsInline",
1118
+ // Experimental (camelCase)
1119
+ "adAuctionHeaders",
1120
+ "allowFullscreen",
1121
+ "browsingTopics",
1122
+ "defaultChecked",
1123
+ "defaultMuted",
1124
+ "defaultSelected",
1125
+ "disablePictureInPicture",
1126
+ "disableRemotePlayback",
1127
+ "preservesPitch",
1128
+ "shadowRootClonable",
1129
+ "shadowRootCustomElementRegistry",
1130
+ "shadowRootDelegatesFocus",
1131
+ "shadowRootSerializable",
1132
+ "sharedStorageWritable",
1133
+ // All lowercase booleans
1134
+ ...booleans
1135
+ ]);
1136
+ var ChildProperties = /* @__PURE__ */ new Set([
1137
+ "innerHTML",
1138
+ "textContent",
1139
+ "innerText",
1140
+ "children"
1141
+ ]);
1142
+ var Aliases = {
1143
+ className: "class",
1144
+ htmlFor: "for"
1145
+ };
1146
+ var PropAliases = {
1147
+ // Direct mapping
1148
+ class: "className",
1149
+ // Element-specific mappings
1150
+ novalidate: {
1151
+ $: "noValidate",
1152
+ FORM: 1
1153
+ },
1154
+ formnovalidate: {
1155
+ $: "formNoValidate",
1156
+ BUTTON: 1,
1157
+ INPUT: 1
1158
+ },
1159
+ ismap: {
1160
+ $: "isMap",
1161
+ IMG: 1
1162
+ },
1163
+ nomodule: {
1164
+ $: "noModule",
1165
+ SCRIPT: 1
1166
+ },
1167
+ playsinline: {
1168
+ $: "playsInline",
1169
+ VIDEO: 1
1170
+ },
1171
+ readonly: {
1172
+ $: "readOnly",
1173
+ INPUT: 1,
1174
+ TEXTAREA: 1
1175
+ },
1176
+ // Experimental element-specific
1177
+ adauctionheaders: {
1178
+ $: "adAuctionHeaders",
1179
+ IFRAME: 1
1180
+ },
1181
+ allowfullscreen: {
1182
+ $: "allowFullscreen",
1183
+ IFRAME: 1
1184
+ },
1185
+ browsingtopics: {
1186
+ $: "browsingTopics",
1187
+ IMG: 1
1188
+ },
1189
+ defaultchecked: {
1190
+ $: "defaultChecked",
1191
+ INPUT: 1
1192
+ },
1193
+ defaultmuted: {
1194
+ $: "defaultMuted",
1195
+ AUDIO: 1,
1196
+ VIDEO: 1
1197
+ },
1198
+ defaultselected: {
1199
+ $: "defaultSelected",
1200
+ OPTION: 1
1201
+ },
1202
+ disablepictureinpicture: {
1203
+ $: "disablePictureInPicture",
1204
+ VIDEO: 1
1205
+ },
1206
+ disableremoteplayback: {
1207
+ $: "disableRemotePlayback",
1208
+ AUDIO: 1,
1209
+ VIDEO: 1
1210
+ },
1211
+ preservespitch: {
1212
+ $: "preservesPitch",
1213
+ AUDIO: 1,
1214
+ VIDEO: 1
1215
+ },
1216
+ shadowrootclonable: {
1217
+ $: "shadowRootClonable",
1218
+ TEMPLATE: 1
1219
+ },
1220
+ shadowrootdelegatesfocus: {
1221
+ $: "shadowRootDelegatesFocus",
1222
+ TEMPLATE: 1
1223
+ },
1224
+ shadowrootserializable: {
1225
+ $: "shadowRootSerializable",
1226
+ TEMPLATE: 1
1227
+ },
1228
+ sharedstoragewritable: {
1229
+ $: "sharedStorageWritable",
1230
+ IFRAME: 1,
1231
+ IMG: 1
1082
1232
  }
1083
- }
1084
- function __fictRender(ctx, fn) {
1085
- ctxStack.push(ctx);
1086
- ctx.cursor = 0;
1087
- try {
1088
- return fn();
1089
- } finally {
1090
- ctxStack.pop();
1233
+ };
1234
+ function getPropAlias(prop, tagName) {
1235
+ const a = PropAliases[prop];
1236
+ if (typeof a === "object") {
1237
+ return a[tagName] ? a["$"] : void 0;
1091
1238
  }
1092
- }
1093
-
1094
- // src/versioned-signal.ts
1095
- function createVersionedSignal(initialValue, options2) {
1096
- const equals = options2?.equals ?? Object.is;
1097
- const value = signal(initialValue);
1098
- const version = signal(0);
1099
- const bumpVersion = () => {
1100
- const next = version() + 1;
1101
- version(next);
1102
- };
1103
- return {
1104
- read: () => {
1105
- version();
1106
- return value();
1107
- },
1108
- write: (next) => {
1109
- const prev = value();
1110
- if (!equals(prev, next)) {
1111
- value(next);
1112
- return;
1113
- }
1114
- bumpVersion();
1115
- },
1116
- force: () => {
1117
- bumpVersion();
1118
- },
1119
- peekVersion: () => version(),
1120
- peekValue: () => value()
1121
- };
1122
- }
1123
-
1124
- // src/props.ts
1125
- var propGetters = /* @__PURE__ */ new WeakSet();
1126
- var rawToProxy = /* @__PURE__ */ new WeakMap();
1127
- var proxyToRaw = /* @__PURE__ */ new WeakMap();
1128
- function __fictProp(getter) {
1129
- if (typeof getter === "function" && getter.length === 0) {
1130
- propGetters.add(getter);
1131
- }
1132
- return getter;
1133
- }
1134
- function isPropGetter(value) {
1135
- return typeof value === "function" && propGetters.has(value);
1136
- }
1137
- function createPropsProxy(props) {
1138
- if (!props || typeof props !== "object") {
1139
- return props;
1140
- }
1141
- if (proxyToRaw.has(props)) {
1142
- return props;
1143
- }
1144
- const cached = rawToProxy.get(props);
1145
- if (cached) {
1146
- return cached;
1147
- }
1148
- const proxy = new Proxy(props, {
1149
- get(target, prop, receiver) {
1150
- const value = Reflect.get(target, prop, receiver);
1151
- if (isPropGetter(value)) {
1152
- return value();
1153
- }
1154
- return value;
1155
- },
1156
- set(target, prop, value, receiver) {
1157
- return Reflect.set(target, prop, value, receiver);
1158
- },
1159
- has(target, prop) {
1160
- return prop in target;
1161
- },
1162
- ownKeys(target) {
1163
- return Reflect.ownKeys(target);
1164
- },
1165
- getOwnPropertyDescriptor(target, prop) {
1166
- return Object.getOwnPropertyDescriptor(target, prop);
1167
- }
1168
- });
1169
- rawToProxy.set(props, proxy);
1170
- proxyToRaw.set(proxy, props);
1171
- return proxy;
1172
- }
1173
- function unwrapProps(props) {
1174
- if (!props || typeof props !== "object") {
1175
- return props;
1176
- }
1177
- return proxyToRaw.get(props) ?? props;
1178
- }
1179
- function __fictPropsRest(props, exclude) {
1180
- const raw = unwrapProps(props);
1181
- const out = {};
1182
- const excludeSet = new Set(exclude);
1183
- for (const key of Reflect.ownKeys(raw)) {
1184
- if (excludeSet.has(key)) continue;
1185
- out[key] = raw[key];
1186
- }
1187
- return createPropsProxy(out);
1188
- }
1189
- function mergeProps(...sources) {
1190
- const validSources = sources.filter(
1191
- (s) => s != null && (typeof s === "object" || typeof s === "function")
1192
- );
1193
- if (validSources.length === 0) {
1194
- return {};
1195
- }
1196
- if (validSources.length === 1 && typeof validSources[0] === "object") {
1197
- return validSources[0];
1198
- }
1199
- const resolveSource = (src) => {
1200
- const value = typeof src === "function" ? src() : src;
1201
- if (!value || typeof value !== "object") return void 0;
1202
- return unwrapProps(value);
1203
- };
1204
- return new Proxy({}, {
1205
- get(_, prop) {
1206
- if (typeof prop === "symbol") {
1207
- return void 0;
1208
- }
1209
- for (let i = validSources.length - 1; i >= 0; i--) {
1210
- const src = validSources[i];
1211
- const raw = resolveSource(src);
1212
- if (!raw || !(prop in raw)) continue;
1213
- const value = raw[prop];
1214
- if (typeof src === "function" && !isPropGetter(value)) {
1215
- return __fictProp(() => {
1216
- const latest = resolveSource(src);
1217
- if (!latest || !(prop in latest)) return void 0;
1218
- return latest[prop];
1219
- });
1220
- }
1221
- return value;
1222
- }
1223
- return void 0;
1224
- },
1225
- has(_, prop) {
1226
- for (const src of validSources) {
1227
- const raw = resolveSource(src);
1228
- if (raw && prop in raw) {
1229
- return true;
1230
- }
1231
- }
1232
- return false;
1233
- },
1234
- ownKeys() {
1235
- const keys = /* @__PURE__ */ new Set();
1236
- for (const src of validSources) {
1237
- const raw = resolveSource(src);
1238
- if (raw) {
1239
- for (const key of Reflect.ownKeys(raw)) {
1240
- keys.add(key);
1241
- }
1242
- }
1243
- }
1244
- return Array.from(keys);
1245
- },
1246
- getOwnPropertyDescriptor(_, prop) {
1247
- for (let i = validSources.length - 1; i >= 0; i--) {
1248
- const raw = resolveSource(validSources[i]);
1249
- if (raw && prop in raw) {
1250
- return {
1251
- enumerable: true,
1252
- configurable: true,
1253
- get: () => {
1254
- const value = raw[prop];
1255
- return value;
1256
- }
1257
- };
1258
- }
1259
- }
1260
- return void 0;
1261
- }
1262
- });
1263
- }
1264
- function useProp(getter) {
1265
- return __fictProp(createMemo(getter));
1266
- }
1267
-
1268
- // src/ref.ts
1269
- function createRef() {
1270
- return { current: null };
1271
- }
1272
-
1273
- // src/transition.ts
1274
- function startTransition(fn) {
1275
- const prev = setTransitionContext(true);
1276
- try {
1277
- fn();
1278
- } finally {
1279
- setTransitionContext(prev);
1280
- scheduleFlush();
1281
- }
1282
- }
1283
- function useTransition() {
1284
- const pending = signal(false);
1285
- const start = (fn) => {
1286
- pending(true);
1287
- startTransition(() => {
1288
- try {
1289
- fn();
1290
- } finally {
1291
- pending(false);
1292
- }
1293
- });
1294
- };
1295
- return [() => pending(), start];
1296
- }
1297
- function useDeferredValue(getValue) {
1298
- const deferredValue = signal(getValue());
1299
- createEffect(() => {
1300
- const newValue = getValue();
1301
- const currentDeferred = untrack(() => deferredValue());
1302
- if (currentDeferred !== newValue) {
1303
- startTransition(() => {
1304
- deferredValue(newValue);
1305
- });
1306
- }
1307
- });
1308
- return () => deferredValue();
1309
- }
1310
-
1311
- // src/scheduler.ts
1312
- function batch2(fn) {
1313
- return batch(fn);
1314
- }
1315
- function untrack2(fn) {
1316
- return untrack(fn);
1317
- }
1318
-
1319
- // src/jsx.ts
1320
- var Fragment = Symbol("Fragment");
1321
-
1322
- // src/constants.ts
1323
- var booleans = [
1324
- "allowfullscreen",
1325
- "async",
1326
- "alpha",
1327
- // HTMLInputElement
1328
- "autofocus",
1329
- // HTMLElement prop
1330
- "autoplay",
1331
- "checked",
1332
- "controls",
1333
- "default",
1334
- "disabled",
1335
- "formnovalidate",
1336
- "hidden",
1337
- // HTMLElement prop
1338
- "indeterminate",
1339
- "inert",
1340
- // HTMLElement prop
1341
- "ismap",
1342
- "loop",
1343
- "multiple",
1344
- "muted",
1345
- "nomodule",
1346
- "novalidate",
1347
- "open",
1348
- "playsinline",
1349
- "readonly",
1350
- "required",
1351
- "reversed",
1352
- "seamless",
1353
- // HTMLIframeElement - non-standard
1354
- "selected",
1355
- // Experimental attributes
1356
- "adauctionheaders",
1357
- "browsingtopics",
1358
- "credentialless",
1359
- "defaultchecked",
1360
- "defaultmuted",
1361
- "defaultselected",
1362
- "defer",
1363
- "disablepictureinpicture",
1364
- "disableremoteplayback",
1365
- "preservespitch",
1366
- "shadowrootclonable",
1367
- "shadowrootcustomelementregistry",
1368
- "shadowrootdelegatesfocus",
1369
- "shadowrootserializable",
1370
- "sharedstoragewritable"
1371
- ];
1372
- var BooleanAttributes = new Set(booleans);
1373
- var Properties = /* @__PURE__ */ new Set([
1374
- // Core properties
1375
- "className",
1376
- "value",
1377
- // CamelCase booleans
1378
- "readOnly",
1379
- "noValidate",
1380
- "formNoValidate",
1381
- "isMap",
1382
- "noModule",
1383
- "playsInline",
1384
- // Experimental (camelCase)
1385
- "adAuctionHeaders",
1386
- "allowFullscreen",
1387
- "browsingTopics",
1388
- "defaultChecked",
1389
- "defaultMuted",
1390
- "defaultSelected",
1391
- "disablePictureInPicture",
1392
- "disableRemotePlayback",
1393
- "preservesPitch",
1394
- "shadowRootClonable",
1395
- "shadowRootCustomElementRegistry",
1396
- "shadowRootDelegatesFocus",
1397
- "shadowRootSerializable",
1398
- "sharedStorageWritable",
1399
- // All lowercase booleans
1400
- ...booleans
1401
- ]);
1402
- var ChildProperties = /* @__PURE__ */ new Set([
1403
- "innerHTML",
1404
- "textContent",
1405
- "innerText",
1406
- "children"
1407
- ]);
1408
- var Aliases = {
1409
- className: "class",
1410
- htmlFor: "for"
1411
- };
1412
- var PropAliases = {
1413
- // Direct mapping
1414
- class: "className",
1415
- // Element-specific mappings
1416
- novalidate: {
1417
- $: "noValidate",
1418
- FORM: 1
1419
- },
1420
- formnovalidate: {
1421
- $: "formNoValidate",
1422
- BUTTON: 1,
1423
- INPUT: 1
1424
- },
1425
- ismap: {
1426
- $: "isMap",
1427
- IMG: 1
1428
- },
1429
- nomodule: {
1430
- $: "noModule",
1431
- SCRIPT: 1
1432
- },
1433
- playsinline: {
1434
- $: "playsInline",
1435
- VIDEO: 1
1436
- },
1437
- readonly: {
1438
- $: "readOnly",
1439
- INPUT: 1,
1440
- TEXTAREA: 1
1441
- },
1442
- // Experimental element-specific
1443
- adauctionheaders: {
1444
- $: "adAuctionHeaders",
1445
- IFRAME: 1
1446
- },
1447
- allowfullscreen: {
1448
- $: "allowFullscreen",
1449
- IFRAME: 1
1450
- },
1451
- browsingtopics: {
1452
- $: "browsingTopics",
1453
- IMG: 1
1454
- },
1455
- defaultchecked: {
1456
- $: "defaultChecked",
1457
- INPUT: 1
1458
- },
1459
- defaultmuted: {
1460
- $: "defaultMuted",
1461
- AUDIO: 1,
1462
- VIDEO: 1
1463
- },
1464
- defaultselected: {
1465
- $: "defaultSelected",
1466
- OPTION: 1
1467
- },
1468
- disablepictureinpicture: {
1469
- $: "disablePictureInPicture",
1470
- VIDEO: 1
1471
- },
1472
- disableremoteplayback: {
1473
- $: "disableRemotePlayback",
1474
- AUDIO: 1,
1475
- VIDEO: 1
1476
- },
1477
- preservespitch: {
1478
- $: "preservesPitch",
1479
- AUDIO: 1,
1480
- VIDEO: 1
1481
- },
1482
- shadowrootclonable: {
1483
- $: "shadowRootClonable",
1484
- TEMPLATE: 1
1485
- },
1486
- shadowrootdelegatesfocus: {
1487
- $: "shadowRootDelegatesFocus",
1488
- TEMPLATE: 1
1489
- },
1490
- shadowrootserializable: {
1491
- $: "shadowRootSerializable",
1492
- TEMPLATE: 1
1493
- },
1494
- sharedstoragewritable: {
1495
- $: "sharedStorageWritable",
1496
- IFRAME: 1,
1497
- IMG: 1
1498
- }
1499
- };
1500
- function getPropAlias(prop, tagName) {
1501
- const a = PropAliases[prop];
1502
- if (typeof a === "object") {
1503
- return a[tagName] ? a["$"] : void 0;
1504
- }
1505
- return a;
1239
+ return a;
1506
1240
  }
1507
1241
  var $$EVENTS = "_$FICT_DELEGATE";
1508
1242
  var DelegatedEvents = /* @__PURE__ */ new Set([
@@ -1690,6 +1424,9 @@ var UnitlessStyles = /* @__PURE__ */ new Set([
1690
1424
  "stroke-width"
1691
1425
  ]);
1692
1426
 
1427
+ // src/jsx.ts
1428
+ var Fragment = Symbol("Fragment");
1429
+
1693
1430
  // src/node-ops.ts
1694
1431
  function toNodeArray(node) {
1695
1432
  try {
@@ -2882,257 +2619,567 @@ function createPortal(container, render2, createElementFn) {
2882
2619
  currentRoot2 = null;
2883
2620
  }
2884
2621
  }
2885
- });
2886
- const portalDispose = () => {
2887
- dispose();
2888
- if (currentRoot2) {
2889
- destroyRoot(currentRoot2);
2622
+ });
2623
+ const portalDispose = () => {
2624
+ dispose();
2625
+ if (currentRoot2) {
2626
+ destroyRoot(currentRoot2);
2627
+ }
2628
+ if (currentNodes.length > 0) {
2629
+ removeNodes(currentNodes);
2630
+ }
2631
+ marker.parentNode?.removeChild(marker);
2632
+ };
2633
+ if (parentRoot) {
2634
+ parentRoot.destroyCallbacks.push(portalDispose);
2635
+ }
2636
+ return {
2637
+ marker,
2638
+ dispose: portalDispose
2639
+ };
2640
+ }
2641
+ function mountBlock(initialValue, initialIndex, renderItem, parent, anchor, createElementFn) {
2642
+ const start = document.createComment("fict:block:start");
2643
+ const end = document.createComment("fict:block:end");
2644
+ const valueSig = signal(initialValue);
2645
+ const indexSig = signal(initialIndex);
2646
+ const versionSig = signal(0);
2647
+ const valueProxy = createValueProxy(() => {
2648
+ versionSig();
2649
+ return valueSig();
2650
+ });
2651
+ const renderCurrent = () => renderItem(valueProxy, indexSig());
2652
+ const root = createRootContext();
2653
+ const prev = pushRoot(root);
2654
+ const nodes = [start];
2655
+ let handledError = false;
2656
+ try {
2657
+ const output = renderCurrent();
2658
+ if (output != null && output !== false) {
2659
+ const el = createElementFn(output);
2660
+ const rendered = toNodeArray(el);
2661
+ nodes.push(...rendered);
2662
+ }
2663
+ nodes.push(end);
2664
+ insertNodesBefore(parent, nodes, anchor);
2665
+ } catch (err) {
2666
+ if (handleSuspend(err, root)) {
2667
+ handledError = true;
2668
+ nodes.push(end);
2669
+ insertNodesBefore(parent, nodes, anchor);
2670
+ } else if (handleError(err, { source: "renderChild" }, root)) {
2671
+ handledError = true;
2672
+ nodes.push(end);
2673
+ insertNodesBefore(parent, nodes, anchor);
2674
+ } else {
2675
+ throw err;
2676
+ }
2677
+ } finally {
2678
+ popRoot(prev);
2679
+ if (!handledError) {
2680
+ flushOnMount(root);
2681
+ } else {
2682
+ destroyRoot(root);
2683
+ }
2684
+ }
2685
+ return {
2686
+ nodes,
2687
+ root,
2688
+ value: valueSig,
2689
+ index: indexSig,
2690
+ version: versionSig,
2691
+ start,
2692
+ end,
2693
+ valueProxy,
2694
+ renderCurrent
2695
+ };
2696
+ }
2697
+ function rerenderBlock(block, createElementFn) {
2698
+ const currentContent = block.nodes.slice(1, Math.max(1, block.nodes.length - 1));
2699
+ const currentNode = currentContent.length === 1 ? currentContent[0] : null;
2700
+ clearRoot(block.root);
2701
+ const prev = pushRoot(block.root);
2702
+ let nextOutput;
2703
+ let handledError = false;
2704
+ try {
2705
+ nextOutput = block.renderCurrent();
2706
+ } catch (err) {
2707
+ if (handleSuspend(err, block.root)) {
2708
+ handledError = true;
2709
+ popRoot(prev);
2710
+ destroyRoot(block.root);
2711
+ block.nodes = [block.start, block.end];
2712
+ return block;
2713
+ }
2714
+ if (handleError(err, { source: "renderChild" }, block.root)) {
2715
+ handledError = true;
2716
+ popRoot(prev);
2717
+ destroyRoot(block.root);
2718
+ block.nodes = [block.start, block.end];
2719
+ return block;
2720
+ }
2721
+ throw err;
2722
+ } finally {
2723
+ if (!handledError) {
2724
+ popRoot(prev);
2725
+ }
2726
+ }
2727
+ if (isFragmentVNode(nextOutput) && currentContent.length > 0) {
2728
+ const patched = patchFragmentChildren(currentContent, nextOutput.props?.children);
2729
+ if (patched) {
2730
+ block.nodes = [block.start, ...currentContent, block.end];
2731
+ return block;
2732
+ }
2733
+ }
2734
+ if (currentNode && patchNode(currentNode, nextOutput)) {
2735
+ block.nodes = [block.start, currentNode, block.end];
2736
+ return block;
2737
+ }
2738
+ clearContent(block);
2739
+ if (nextOutput != null && nextOutput !== false) {
2740
+ const newNodes = toNodeArray(
2741
+ nextOutput instanceof Node ? nextOutput : createElementFn(nextOutput)
2742
+ );
2743
+ insertNodesBefore(block.start.parentNode, newNodes, block.end);
2744
+ block.nodes = [block.start, ...newNodes, block.end];
2745
+ } else {
2746
+ block.nodes = [block.start, block.end];
2747
+ }
2748
+ return block;
2749
+ }
2750
+ function patchElement(el, output) {
2751
+ if (output === null || output === void 0 || output === false || typeof output === "string" || typeof output === "number") {
2752
+ el.textContent = output === null || output === void 0 || output === false ? "" : String(output);
2753
+ return true;
2754
+ }
2755
+ if (output instanceof Text) {
2756
+ el.textContent = output.data;
2757
+ return true;
2758
+ }
2759
+ if (output && typeof output === "object" && !(output instanceof Node)) {
2760
+ const vnode = output;
2761
+ if (typeof vnode.type === "string" && vnode.type.toLowerCase() === el.tagName.toLowerCase()) {
2762
+ const children = vnode.props?.children;
2763
+ const props = vnode.props ?? {};
2764
+ for (const [key, value] of Object.entries(props)) {
2765
+ if (key === "children" || key === "key") continue;
2766
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean" || value === null || value === void 0) {
2767
+ if (key === "class" || key === "className") {
2768
+ el.setAttribute("class", value === false || value === null ? "" : String(value));
2769
+ } else if (key === "style" && typeof value === "string") {
2770
+ ;
2771
+ el.style.cssText = value;
2772
+ } else if (value === false || value === null || value === void 0) {
2773
+ el.removeAttribute(key);
2774
+ } else if (value === true) {
2775
+ el.setAttribute(key, "");
2776
+ } else {
2777
+ el.setAttribute(key, String(value));
2778
+ }
2779
+ }
2780
+ }
2781
+ if (typeof children === "string" || typeof children === "number" || children === null || children === void 0 || children === false) {
2782
+ el.textContent = children === null || children === void 0 || children === false ? "" : String(children);
2783
+ return true;
2784
+ }
2785
+ if (children && typeof children === "object" && !Array.isArray(children) && !(children instanceof Node)) {
2786
+ const childVNode = children;
2787
+ if (typeof childVNode.type === "string") {
2788
+ const childEl = el.querySelector(childVNode.type);
2789
+ if (childEl && patchElement(childEl, children)) {
2790
+ return true;
2791
+ }
2792
+ }
2793
+ }
2794
+ return false;
2795
+ }
2796
+ }
2797
+ if (output instanceof Node) {
2798
+ if (output.nodeType === Node.ELEMENT_NODE) {
2799
+ const nextEl = output;
2800
+ if (nextEl.tagName.toLowerCase() === el.tagName.toLowerCase()) {
2801
+ el.textContent = nextEl.textContent;
2802
+ return true;
2803
+ }
2804
+ } else if (output.nodeType === Node.TEXT_NODE) {
2805
+ el.textContent = output.data;
2806
+ return true;
2807
+ }
2808
+ }
2809
+ return false;
2810
+ }
2811
+ function patchNode(currentNode, nextOutput) {
2812
+ if (!currentNode) return false;
2813
+ if (currentNode instanceof Text && (nextOutput === null || nextOutput === void 0 || nextOutput === false || typeof nextOutput === "string" || typeof nextOutput === "number" || nextOutput instanceof Text)) {
2814
+ const nextText = nextOutput instanceof Text ? nextOutput.data : nextOutput === null || nextOutput === void 0 || nextOutput === false ? "" : String(nextOutput);
2815
+ currentNode.data = nextText;
2816
+ return true;
2817
+ }
2818
+ if (currentNode instanceof Element && patchElement(currentNode, nextOutput)) {
2819
+ return true;
2820
+ }
2821
+ if (nextOutput instanceof Node && currentNode === nextOutput) {
2822
+ return true;
2823
+ }
2824
+ return false;
2825
+ }
2826
+ function isFragmentVNode(value) {
2827
+ return value != null && typeof value === "object" && !(value instanceof Node) && value.type === Fragment;
2828
+ }
2829
+ function normalizeChildren(children, result = []) {
2830
+ if (children === void 0) {
2831
+ return result;
2832
+ }
2833
+ if (Array.isArray(children)) {
2834
+ for (const child of children) {
2835
+ normalizeChildren(child, result);
2836
+ }
2837
+ return result;
2838
+ }
2839
+ if (children === null || children === false) {
2840
+ return result;
2841
+ }
2842
+ result.push(children);
2843
+ return result;
2844
+ }
2845
+ function patchFragmentChildren(nodes, children) {
2846
+ const normalized = normalizeChildren(children);
2847
+ if (normalized.length !== nodes.length) {
2848
+ return false;
2849
+ }
2850
+ for (let i = 0; i < normalized.length; i++) {
2851
+ if (!patchNode(nodes[i], normalized[i])) {
2852
+ return false;
2890
2853
  }
2891
- if (currentNodes.length > 0) {
2892
- removeNodes(currentNodes);
2854
+ }
2855
+ return true;
2856
+ }
2857
+ function clearContent(block) {
2858
+ const nodes = block.nodes.slice(1, Math.max(1, block.nodes.length - 1));
2859
+ removeNodes(nodes);
2860
+ }
2861
+ function removeBlockNodes(block) {
2862
+ let cursor = block.start;
2863
+ const end = block.end;
2864
+ while (cursor) {
2865
+ const next = cursor.nextSibling;
2866
+ cursor.parentNode?.removeChild(cursor);
2867
+ if (cursor === end) break;
2868
+ cursor = next;
2869
+ }
2870
+ }
2871
+ function bumpBlockVersion(block) {
2872
+ block.version(block.version() + 1);
2873
+ }
2874
+
2875
+ // src/scope.ts
2876
+ function createScope() {
2877
+ let dispose = null;
2878
+ const stop = () => {
2879
+ if (dispose) {
2880
+ dispose();
2881
+ dispose = null;
2893
2882
  }
2894
- marker.parentNode?.removeChild(marker);
2895
2883
  };
2896
- if (parentRoot) {
2897
- parentRoot.destroyCallbacks.push(portalDispose);
2898
- }
2899
- return {
2900
- marker,
2901
- dispose: portalDispose
2884
+ const run = (fn) => {
2885
+ stop();
2886
+ const { dispose: rootDispose, value } = createRoot(fn);
2887
+ dispose = rootDispose;
2888
+ return value;
2902
2889
  };
2890
+ registerRootCleanup(stop);
2891
+ return { run, stop };
2903
2892
  }
2904
- function mountBlock(initialValue, initialIndex, renderItem, parent, anchor, createElementFn) {
2905
- const start = document.createComment("fict:block:start");
2906
- const end = document.createComment("fict:block:end");
2907
- const valueSig = signal(initialValue);
2908
- const indexSig = signal(initialIndex);
2909
- const versionSig = signal(0);
2910
- const valueProxy = createValueProxy(() => {
2911
- versionSig();
2912
- return valueSig();
2913
- });
2914
- const renderCurrent = () => renderItem(valueProxy, indexSig());
2915
- const root = createRootContext();
2916
- const prev = pushRoot(root);
2917
- const nodes = [start];
2918
- let handledError = false;
2919
- try {
2920
- const output = renderCurrent();
2921
- if (output != null && output !== false) {
2922
- const el = createElementFn(output);
2923
- const rendered = toNodeArray(el);
2924
- nodes.push(...rendered);
2925
- }
2926
- nodes.push(end);
2927
- insertNodesBefore(parent, nodes, anchor);
2928
- } catch (err) {
2929
- if (handleSuspend(err, root)) {
2930
- handledError = true;
2931
- nodes.push(end);
2932
- insertNodesBefore(parent, nodes, anchor);
2933
- } else if (handleError(err, { source: "renderChild" }, root)) {
2934
- handledError = true;
2935
- nodes.push(end);
2936
- insertNodesBefore(parent, nodes, anchor);
2893
+ function runInScope(flag, fn) {
2894
+ const scope = createScope();
2895
+ const evaluate = () => isReactive(flag) ? flag() : !!flag;
2896
+ createEffect(() => {
2897
+ const enabled = evaluate();
2898
+ if (enabled) {
2899
+ scope.run(fn);
2937
2900
  } else {
2938
- throw err;
2901
+ scope.stop();
2939
2902
  }
2903
+ });
2904
+ onCleanup(scope.stop);
2905
+ }
2906
+
2907
+ // src/hooks.ts
2908
+ var ctxStack = [];
2909
+ function __fictUseContext() {
2910
+ if (ctxStack.length === 0) {
2911
+ const ctx2 = { slots: [], cursor: 0 };
2912
+ ctxStack.push(ctx2);
2913
+ return ctx2;
2914
+ }
2915
+ const ctx = ctxStack[ctxStack.length - 1];
2916
+ ctx.cursor = 0;
2917
+ return ctx;
2918
+ }
2919
+ function __fictPushContext() {
2920
+ const ctx = { slots: [], cursor: 0 };
2921
+ ctxStack.push(ctx);
2922
+ return ctx;
2923
+ }
2924
+ function __fictPopContext() {
2925
+ ctxStack.pop();
2926
+ }
2927
+ function __fictResetContext() {
2928
+ ctxStack.length = 0;
2929
+ }
2930
+ function __fictUseSignal(ctx, initial, slot) {
2931
+ const index = slot ?? ctx.cursor++;
2932
+ if (!ctx.slots[index]) {
2933
+ ctx.slots[index] = signal(initial);
2934
+ }
2935
+ return ctx.slots[index];
2936
+ }
2937
+ function __fictUseMemo(ctx, fn, slot) {
2938
+ const index = slot ?? ctx.cursor++;
2939
+ if (!ctx.slots[index]) {
2940
+ ctx.slots[index] = createMemo(fn);
2941
+ }
2942
+ return ctx.slots[index];
2943
+ }
2944
+ function __fictUseEffect(ctx, fn, slot) {
2945
+ const index = slot ?? ctx.cursor++;
2946
+ if (!ctx.slots[index]) {
2947
+ ctx.slots[index] = createEffect(fn);
2948
+ }
2949
+ }
2950
+ function __fictRender(ctx, fn) {
2951
+ ctxStack.push(ctx);
2952
+ ctx.cursor = 0;
2953
+ try {
2954
+ return fn();
2940
2955
  } finally {
2941
- popRoot(prev);
2942
- if (!handledError) {
2943
- flushOnMount(root);
2944
- } else {
2945
- destroyRoot(root);
2946
- }
2956
+ ctxStack.pop();
2947
2957
  }
2958
+ }
2959
+
2960
+ // src/versioned-signal.ts
2961
+ function createVersionedSignal(initialValue, options2) {
2962
+ const equals = options2?.equals ?? Object.is;
2963
+ const value = signal(initialValue);
2964
+ const version = signal(0);
2965
+ const bumpVersion = () => {
2966
+ const next = version() + 1;
2967
+ version(next);
2968
+ };
2948
2969
  return {
2949
- nodes,
2950
- root,
2951
- value: valueSig,
2952
- index: indexSig,
2953
- version: versionSig,
2954
- start,
2955
- end,
2956
- valueProxy,
2957
- renderCurrent
2970
+ read: () => {
2971
+ version();
2972
+ return value();
2973
+ },
2974
+ write: (next) => {
2975
+ const prev = value();
2976
+ if (!equals(prev, next)) {
2977
+ value(next);
2978
+ return;
2979
+ }
2980
+ bumpVersion();
2981
+ },
2982
+ force: () => {
2983
+ bumpVersion();
2984
+ },
2985
+ peekVersion: () => version(),
2986
+ peekValue: () => value()
2958
2987
  };
2959
2988
  }
2960
- function rerenderBlock(block, createElementFn) {
2961
- const currentContent = block.nodes.slice(1, Math.max(1, block.nodes.length - 1));
2962
- const currentNode = currentContent.length === 1 ? currentContent[0] : null;
2963
- clearRoot(block.root);
2964
- const prev = pushRoot(block.root);
2965
- let nextOutput;
2966
- let handledError = false;
2967
- try {
2968
- nextOutput = block.renderCurrent();
2969
- } catch (err) {
2970
- if (handleSuspend(err, block.root)) {
2971
- handledError = true;
2972
- popRoot(prev);
2973
- destroyRoot(block.root);
2974
- block.nodes = [block.start, block.end];
2975
- return block;
2976
- }
2977
- if (handleError(err, { source: "renderChild" }, block.root)) {
2978
- handledError = true;
2979
- popRoot(prev);
2980
- destroyRoot(block.root);
2981
- block.nodes = [block.start, block.end];
2982
- return block;
2983
- }
2984
- throw err;
2985
- } finally {
2986
- if (!handledError) {
2987
- popRoot(prev);
2988
- }
2989
+
2990
+ // src/props.ts
2991
+ var propGetters = /* @__PURE__ */ new WeakSet();
2992
+ var rawToProxy = /* @__PURE__ */ new WeakMap();
2993
+ var proxyToRaw = /* @__PURE__ */ new WeakMap();
2994
+ function __fictProp(getter) {
2995
+ if (typeof getter === "function" && getter.length === 0) {
2996
+ propGetters.add(getter);
2989
2997
  }
2990
- if (isFragmentVNode(nextOutput) && currentContent.length > 0) {
2991
- const patched = patchFragmentChildren(currentContent, nextOutput.props?.children);
2992
- if (patched) {
2993
- block.nodes = [block.start, ...currentContent, block.end];
2994
- return block;
2998
+ return getter;
2999
+ }
3000
+ function isPropGetter(value) {
3001
+ return typeof value === "function" && propGetters.has(value);
3002
+ }
3003
+ function createPropsProxy(props) {
3004
+ if (!props || typeof props !== "object") {
3005
+ return props;
3006
+ }
3007
+ if (proxyToRaw.has(props)) {
3008
+ return props;
3009
+ }
3010
+ const cached = rawToProxy.get(props);
3011
+ if (cached) {
3012
+ return cached;
3013
+ }
3014
+ const proxy = new Proxy(props, {
3015
+ get(target, prop, receiver) {
3016
+ const value = Reflect.get(target, prop, receiver);
3017
+ if (isPropGetter(value)) {
3018
+ return value();
3019
+ }
3020
+ return value;
3021
+ },
3022
+ set(target, prop, value, receiver) {
3023
+ return Reflect.set(target, prop, value, receiver);
3024
+ },
3025
+ has(target, prop) {
3026
+ return prop in target;
3027
+ },
3028
+ ownKeys(target) {
3029
+ return Reflect.ownKeys(target);
3030
+ },
3031
+ getOwnPropertyDescriptor(target, prop) {
3032
+ return Object.getOwnPropertyDescriptor(target, prop);
2995
3033
  }
3034
+ });
3035
+ rawToProxy.set(props, proxy);
3036
+ proxyToRaw.set(proxy, props);
3037
+ return proxy;
3038
+ }
3039
+ function unwrapProps(props) {
3040
+ if (!props || typeof props !== "object") {
3041
+ return props;
2996
3042
  }
2997
- if (currentNode && patchNode(currentNode, nextOutput)) {
2998
- block.nodes = [block.start, currentNode, block.end];
2999
- return block;
3000
- }
3001
- clearContent(block);
3002
- if (nextOutput != null && nextOutput !== false) {
3003
- const newNodes = toNodeArray(
3004
- nextOutput instanceof Node ? nextOutput : createElementFn(nextOutput)
3005
- );
3006
- insertNodesBefore(block.start.parentNode, newNodes, block.end);
3007
- block.nodes = [block.start, ...newNodes, block.end];
3008
- } else {
3009
- block.nodes = [block.start, block.end];
3043
+ return proxyToRaw.get(props) ?? props;
3044
+ }
3045
+ function __fictPropsRest(props, exclude) {
3046
+ const raw = unwrapProps(props);
3047
+ const out = {};
3048
+ const excludeSet = new Set(exclude);
3049
+ for (const key of Reflect.ownKeys(raw)) {
3050
+ if (excludeSet.has(key)) continue;
3051
+ out[key] = raw[key];
3010
3052
  }
3011
- return block;
3053
+ return createPropsProxy(out);
3012
3054
  }
3013
- function patchElement(el, output) {
3014
- if (output === null || output === void 0 || output === false || typeof output === "string" || typeof output === "number") {
3015
- el.textContent = output === null || output === void 0 || output === false ? "" : String(output);
3016
- return true;
3055
+ function mergeProps(...sources) {
3056
+ const validSources = sources.filter(
3057
+ (s) => s != null && (typeof s === "object" || typeof s === "function")
3058
+ );
3059
+ if (validSources.length === 0) {
3060
+ return {};
3017
3061
  }
3018
- if (output instanceof Text) {
3019
- el.textContent = output.data;
3020
- return true;
3062
+ if (validSources.length === 1 && typeof validSources[0] === "object") {
3063
+ return validSources[0];
3021
3064
  }
3022
- if (output && typeof output === "object" && !(output instanceof Node)) {
3023
- const vnode = output;
3024
- if (typeof vnode.type === "string" && vnode.type.toLowerCase() === el.tagName.toLowerCase()) {
3025
- const children = vnode.props?.children;
3026
- const props = vnode.props ?? {};
3027
- for (const [key, value] of Object.entries(props)) {
3028
- if (key === "children" || key === "key") continue;
3029
- if (typeof value === "string" || typeof value === "number" || typeof value === "boolean" || value === null || value === void 0) {
3030
- if (key === "class" || key === "className") {
3031
- el.setAttribute("class", value === false || value === null ? "" : String(value));
3032
- } else if (key === "style" && typeof value === "string") {
3033
- ;
3034
- el.style.cssText = value;
3035
- } else if (value === false || value === null || value === void 0) {
3036
- el.removeAttribute(key);
3037
- } else if (value === true) {
3038
- el.setAttribute(key, "");
3039
- } else {
3040
- el.setAttribute(key, String(value));
3041
- }
3065
+ const resolveSource = (src) => {
3066
+ const value = typeof src === "function" ? src() : src;
3067
+ if (!value || typeof value !== "object") return void 0;
3068
+ return unwrapProps(value);
3069
+ };
3070
+ return new Proxy({}, {
3071
+ get(_, prop) {
3072
+ if (typeof prop === "symbol") {
3073
+ return void 0;
3074
+ }
3075
+ for (let i = validSources.length - 1; i >= 0; i--) {
3076
+ const src = validSources[i];
3077
+ const raw = resolveSource(src);
3078
+ if (!raw || !(prop in raw)) continue;
3079
+ const value = raw[prop];
3080
+ if (typeof src === "function" && !isPropGetter(value)) {
3081
+ return __fictProp(() => {
3082
+ const latest = resolveSource(src);
3083
+ if (!latest || !(prop in latest)) return void 0;
3084
+ return latest[prop];
3085
+ });
3042
3086
  }
3087
+ return value;
3043
3088
  }
3044
- if (typeof children === "string" || typeof children === "number" || children === null || children === void 0 || children === false) {
3045
- el.textContent = children === null || children === void 0 || children === false ? "" : String(children);
3046
- return true;
3089
+ return void 0;
3090
+ },
3091
+ has(_, prop) {
3092
+ for (const src of validSources) {
3093
+ const raw = resolveSource(src);
3094
+ if (raw && prop in raw) {
3095
+ return true;
3096
+ }
3047
3097
  }
3048
- if (children && typeof children === "object" && !Array.isArray(children) && !(children instanceof Node)) {
3049
- const childVNode = children;
3050
- if (typeof childVNode.type === "string") {
3051
- const childEl = el.querySelector(childVNode.type);
3052
- if (childEl && patchElement(childEl, children)) {
3053
- return true;
3098
+ return false;
3099
+ },
3100
+ ownKeys() {
3101
+ const keys = /* @__PURE__ */ new Set();
3102
+ for (const src of validSources) {
3103
+ const raw = resolveSource(src);
3104
+ if (raw) {
3105
+ for (const key of Reflect.ownKeys(raw)) {
3106
+ keys.add(key);
3054
3107
  }
3055
3108
  }
3056
3109
  }
3057
- return false;
3058
- }
3059
- }
3060
- if (output instanceof Node) {
3061
- if (output.nodeType === Node.ELEMENT_NODE) {
3062
- const nextEl = output;
3063
- if (nextEl.tagName.toLowerCase() === el.tagName.toLowerCase()) {
3064
- el.textContent = nextEl.textContent;
3065
- return true;
3110
+ return Array.from(keys);
3111
+ },
3112
+ getOwnPropertyDescriptor(_, prop) {
3113
+ for (let i = validSources.length - 1; i >= 0; i--) {
3114
+ const raw = resolveSource(validSources[i]);
3115
+ if (raw && prop in raw) {
3116
+ return {
3117
+ enumerable: true,
3118
+ configurable: true,
3119
+ get: () => {
3120
+ const value = raw[prop];
3121
+ return value;
3122
+ }
3123
+ };
3124
+ }
3066
3125
  }
3067
- } else if (output.nodeType === Node.TEXT_NODE) {
3068
- el.textContent = output.data;
3069
- return true;
3126
+ return void 0;
3070
3127
  }
3071
- }
3072
- return false;
3128
+ });
3073
3129
  }
3074
- function patchNode(currentNode, nextOutput) {
3075
- if (!currentNode) return false;
3076
- if (currentNode instanceof Text && (nextOutput === null || nextOutput === void 0 || nextOutput === false || typeof nextOutput === "string" || typeof nextOutput === "number" || nextOutput instanceof Text)) {
3077
- const nextText = nextOutput instanceof Text ? nextOutput.data : nextOutput === null || nextOutput === void 0 || nextOutput === false ? "" : String(nextOutput);
3078
- currentNode.data = nextText;
3079
- return true;
3080
- }
3081
- if (currentNode instanceof Element && patchElement(currentNode, nextOutput)) {
3082
- return true;
3083
- }
3084
- if (nextOutput instanceof Node && currentNode === nextOutput) {
3085
- return true;
3086
- }
3087
- return false;
3130
+ function useProp(getter) {
3131
+ return __fictProp(createMemo(getter));
3088
3132
  }
3089
- function isFragmentVNode(value) {
3090
- return value != null && typeof value === "object" && !(value instanceof Node) && value.type === Fragment;
3133
+
3134
+ // src/ref.ts
3135
+ function createRef() {
3136
+ return { current: null };
3091
3137
  }
3092
- function normalizeChildren(children, result = []) {
3093
- if (children === void 0) {
3094
- return result;
3095
- }
3096
- if (Array.isArray(children)) {
3097
- for (const child of children) {
3098
- normalizeChildren(child, result);
3099
- }
3100
- return result;
3101
- }
3102
- if (children === null || children === false) {
3103
- return result;
3138
+
3139
+ // src/transition.ts
3140
+ function startTransition(fn) {
3141
+ const prev = setTransitionContext(true);
3142
+ try {
3143
+ fn();
3144
+ } finally {
3145
+ setTransitionContext(prev);
3146
+ scheduleFlush();
3104
3147
  }
3105
- result.push(children);
3106
- return result;
3107
3148
  }
3108
- function patchFragmentChildren(nodes, children) {
3109
- const normalized = normalizeChildren(children);
3110
- if (normalized.length !== nodes.length) {
3111
- return false;
3112
- }
3113
- for (let i = 0; i < normalized.length; i++) {
3114
- if (!patchNode(nodes[i], normalized[i])) {
3115
- return false;
3116
- }
3117
- }
3118
- return true;
3149
+ function useTransition() {
3150
+ const pending = signal(false);
3151
+ const start = (fn) => {
3152
+ pending(true);
3153
+ startTransition(() => {
3154
+ try {
3155
+ fn();
3156
+ } finally {
3157
+ pending(false);
3158
+ }
3159
+ });
3160
+ };
3161
+ return [() => pending(), start];
3119
3162
  }
3120
- function clearContent(block) {
3121
- const nodes = block.nodes.slice(1, Math.max(1, block.nodes.length - 1));
3122
- removeNodes(nodes);
3163
+ function useDeferredValue(getValue) {
3164
+ const deferredValue = signal(getValue());
3165
+ createEffect(() => {
3166
+ const newValue = getValue();
3167
+ const currentDeferred = untrack(() => deferredValue());
3168
+ if (currentDeferred !== newValue) {
3169
+ startTransition(() => {
3170
+ deferredValue(newValue);
3171
+ });
3172
+ }
3173
+ });
3174
+ return () => deferredValue();
3123
3175
  }
3124
- function removeBlockNodes(block) {
3125
- let cursor = block.start;
3126
- const end = block.end;
3127
- while (cursor) {
3128
- const next = cursor.nextSibling;
3129
- cursor.parentNode?.removeChild(cursor);
3130
- if (cursor === end) break;
3131
- cursor = next;
3132
- }
3176
+
3177
+ // src/scheduler.ts
3178
+ function batch2(fn) {
3179
+ return batch(fn);
3133
3180
  }
3134
- function bumpBlockVersion(block) {
3135
- block.version(block.version() + 1);
3181
+ function untrack2(fn) {
3182
+ return untrack(fn);
3136
3183
  }
3137
3184
 
3138
3185
  // src/dom.ts
@@ -4203,6 +4250,7 @@ export {
4203
4250
  createRef,
4204
4251
  createRenderEffect,
4205
4252
  createRoot,
4253
+ createScope,
4206
4254
  createSelector,
4207
4255
  createShow,
4208
4256
  signal as createSignal,
@@ -4213,6 +4261,7 @@ export {
4213
4261
  createVersionedSignal,
4214
4262
  delegateEvents,
4215
4263
  destroyMarkerBlock,
4264
+ effectScope,
4216
4265
  getDevtoolsHook,
4217
4266
  getFirstNodeAfter,
4218
4267
  getPropAlias,
@@ -4230,6 +4279,7 @@ export {
4230
4279
  reconcileArrays,
4231
4280
  removeNodes,
4232
4281
  render,
4282
+ runInScope,
4233
4283
  setCycleProtectionOptions,
4234
4284
  spread,
4235
4285
  startTransition,