@novely/core 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.
- package/dist/index.d.ts +5 -0
- package/dist/index.global.js +103 -81
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +103 -81
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -473,6 +473,11 @@ declare const novely: <Languages extends string, Characters extends Record<strin
|
|
|
473
473
|
* Unwraps translatable content to a string value
|
|
474
474
|
*/
|
|
475
475
|
unwrap(content: string | (() => string) | Record<Languages, string> | Exclude<Record<Languages, string | (() => string)>, Record<string, string>>): string;
|
|
476
|
+
/**
|
|
477
|
+
* Cancel data loading, hide UI, ignore page change events
|
|
478
|
+
* Data updates still will work in case Novely already was loaded
|
|
479
|
+
*/
|
|
480
|
+
destroy(): void;
|
|
476
481
|
};
|
|
477
482
|
|
|
478
483
|
export { type ActionProxyProvider, type AllowedContent, type AudioHandle, type BaseTranslationStrings, type Character, type CharacterHandle, type Context, type CoreData, type CustomHandler, type CustomHandlerFunctionGetFn, type CustomHandlerFunctionParameters, type CustomHandlerGetResult, type CustomHandlerGetResultDataFunction, type DefaultActionProxyProvider, EN, type Emotions, type FunctionableValue, type GetActionParameters, JP, KK, type Lang, type NovelyScreen, type Path, type PluralType, type Pluralization, RU, type Renderer, type RendererInit, type Save, type Storage, type StorageData, type StorageMeta, type Stored, type Story, type Thenable, type TranslationActions, type TypewriterSpeed, type Unwrappable, type ValidAction, localStorageStorage, novely };
|
package/dist/index.global.js
CHANGED
|
@@ -180,12 +180,18 @@ var Novely = (() => {
|
|
|
180
180
|
var STACK_MAP = /* @__PURE__ */ new Map();
|
|
181
181
|
|
|
182
182
|
// src/utils.ts
|
|
183
|
-
var matchAction = (getContext, values) => {
|
|
183
|
+
var matchAction = ({ getContext, push, forward }, values) => {
|
|
184
184
|
return (action, props, { ctx, data }) => {
|
|
185
185
|
const context = typeof ctx === "string" ? getContext(ctx) : ctx;
|
|
186
186
|
return values[action]({
|
|
187
187
|
ctx: context,
|
|
188
|
-
data
|
|
188
|
+
data,
|
|
189
|
+
push() {
|
|
190
|
+
push(context);
|
|
191
|
+
},
|
|
192
|
+
forward() {
|
|
193
|
+
forward(context);
|
|
194
|
+
}
|
|
189
195
|
}, props);
|
|
190
196
|
};
|
|
191
197
|
};
|
|
@@ -853,11 +859,12 @@ var Novely = (() => {
|
|
|
853
859
|
};
|
|
854
860
|
storageDelay.then(getStoredData);
|
|
855
861
|
const initial = getDefaultSave(klona(defaultState));
|
|
856
|
-
|
|
862
|
+
const onVisibilityChange = () => {
|
|
857
863
|
if (document.visibilityState === "hidden") {
|
|
858
864
|
throttledEmergencyOnStorageDataChange();
|
|
859
865
|
}
|
|
860
|
-
}
|
|
866
|
+
};
|
|
867
|
+
addEventListener("visibilitychange", onVisibilityChange);
|
|
861
868
|
addEventListener("beforeunload", throttledEmergencyOnStorageDataChange);
|
|
862
869
|
const save = (override = false, type = override ? "auto" : "manual") => {
|
|
863
870
|
if (!$$.get().dataLoaded)
|
|
@@ -946,7 +953,7 @@ var Novely = (() => {
|
|
|
946
953
|
data: latest[1]
|
|
947
954
|
});
|
|
948
955
|
});
|
|
949
|
-
context.meta.restoring = context.meta.
|
|
956
|
+
context.meta.restoring = context.meta.goingBack = false;
|
|
950
957
|
render(context);
|
|
951
958
|
};
|
|
952
959
|
const refer = (path) => {
|
|
@@ -1047,55 +1054,89 @@ var Novely = (() => {
|
|
|
1047
1054
|
});
|
|
1048
1055
|
const useStack = createUseStackFunction(renderer);
|
|
1049
1056
|
useStack(MAIN_CONTEXT_KEY).push(initial);
|
|
1050
|
-
renderer.ui.start();
|
|
1051
|
-
const
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1057
|
+
const UIInstance = renderer.ui.start();
|
|
1058
|
+
const enmemory = (ctx) => {
|
|
1059
|
+
if (ctx.meta.restoring)
|
|
1060
|
+
return;
|
|
1061
|
+
const stack = useStack(ctx);
|
|
1062
|
+
const current = klona(stack.value);
|
|
1063
|
+
current[2][1] = "auto";
|
|
1064
|
+
stack.push(current);
|
|
1065
|
+
save(true, "auto");
|
|
1066
|
+
};
|
|
1067
|
+
const next = (ctx) => {
|
|
1068
|
+
const stack = useStack(ctx);
|
|
1069
|
+
const path = stack.value[0];
|
|
1070
|
+
const last = path.at(-1);
|
|
1071
|
+
if (last && (isNull(last[0]) || last[0] === "jump") && isNumber(last[1])) {
|
|
1072
|
+
last[1]++;
|
|
1073
|
+
} else {
|
|
1074
|
+
path.push([null, 0]);
|
|
1075
|
+
}
|
|
1076
|
+
};
|
|
1077
|
+
const matchActionInit = {
|
|
1078
|
+
getContext: renderer.getContext,
|
|
1079
|
+
push(ctx) {
|
|
1080
|
+
if (ctx.meta.restoring)
|
|
1081
|
+
return;
|
|
1082
|
+
next(ctx);
|
|
1083
|
+
render(ctx);
|
|
1084
|
+
},
|
|
1085
|
+
forward(ctx) {
|
|
1086
|
+
if (!ctx.meta.preview)
|
|
1087
|
+
enmemory(ctx);
|
|
1088
|
+
matchActionInit.push(ctx);
|
|
1089
|
+
if (!ctx.meta.preview)
|
|
1090
|
+
interactivity(true);
|
|
1091
|
+
}
|
|
1092
|
+
};
|
|
1093
|
+
const match = matchAction(matchActionInit, {
|
|
1094
|
+
wait({ ctx, push }, [time]) {
|
|
1095
|
+
if (ctx.meta.restoring)
|
|
1096
|
+
return;
|
|
1097
|
+
setTimeout(push, isFunction(time) ? time() : time);
|
|
1055
1098
|
},
|
|
1056
|
-
showBackground({ ctx }, [background]) {
|
|
1099
|
+
showBackground({ ctx, push }, [background]) {
|
|
1057
1100
|
ctx.background(background);
|
|
1058
|
-
push(
|
|
1101
|
+
push();
|
|
1059
1102
|
},
|
|
1060
|
-
playMusic({ ctx }, [source]) {
|
|
1103
|
+
playMusic({ ctx, push }, [source]) {
|
|
1061
1104
|
ctx.audio.music(source, "music", true).play();
|
|
1062
|
-
push(
|
|
1105
|
+
push();
|
|
1063
1106
|
},
|
|
1064
|
-
stopMusic({ ctx }, [source]) {
|
|
1107
|
+
stopMusic({ ctx, push }, [source]) {
|
|
1065
1108
|
ctx.audio.music(source, "music").stop();
|
|
1066
|
-
push(
|
|
1109
|
+
push();
|
|
1067
1110
|
},
|
|
1068
|
-
playSound({ ctx }, [source, loop]) {
|
|
1111
|
+
playSound({ ctx, push }, [source, loop]) {
|
|
1069
1112
|
ctx.audio.music(source, "sound", loop || false).play();
|
|
1070
|
-
push(
|
|
1113
|
+
push();
|
|
1071
1114
|
},
|
|
1072
|
-
stopSound({ ctx }, [source]) {
|
|
1115
|
+
stopSound({ ctx, push }, [source]) {
|
|
1073
1116
|
ctx.audio.music(source, "sound").stop();
|
|
1074
|
-
push(
|
|
1117
|
+
push();
|
|
1075
1118
|
},
|
|
1076
|
-
voice({ ctx }, [source]) {
|
|
1119
|
+
voice({ ctx, push }, [source]) {
|
|
1077
1120
|
ctx.audio.voice(source);
|
|
1078
|
-
push(
|
|
1121
|
+
push();
|
|
1079
1122
|
},
|
|
1080
|
-
stopVoice({ ctx }) {
|
|
1123
|
+
stopVoice({ ctx, push }) {
|
|
1081
1124
|
ctx.audio.voiceStop();
|
|
1082
|
-
push(
|
|
1125
|
+
push();
|
|
1083
1126
|
},
|
|
1084
|
-
showCharacter({ ctx }, [character, emotion, className, style]) {
|
|
1127
|
+
showCharacter({ ctx, push }, [character, emotion, className, style]) {
|
|
1085
1128
|
if (DEV && !characters[character].emotions[emotion]) {
|
|
1086
1129
|
throw new Error(`Attempt to show character "${character}" with unknown emotion "${emotion}"`);
|
|
1087
1130
|
}
|
|
1088
1131
|
const handle = ctx.character(character);
|
|
1089
1132
|
handle.append(className, style, ctx.meta.restoring);
|
|
1090
1133
|
handle.emotion(emotion, true);
|
|
1091
|
-
push(
|
|
1134
|
+
push();
|
|
1092
1135
|
},
|
|
1093
|
-
hideCharacter({ ctx }, [character, className, style, duration]) {
|
|
1094
|
-
ctx.character(character).remove(className, style, duration, ctx.meta.restoring).then(
|
|
1095
|
-
push(ctx);
|
|
1096
|
-
});
|
|
1136
|
+
hideCharacter({ ctx, push }, [character, className, style, duration]) {
|
|
1137
|
+
ctx.character(character).remove(className, style, duration, ctx.meta.restoring).then(push);
|
|
1097
1138
|
},
|
|
1098
|
-
dialog({ ctx, data: data2 }, [character, content, emotion]) {
|
|
1139
|
+
dialog({ ctx, data: data2, forward }, [character, content, emotion]) {
|
|
1099
1140
|
const name = (() => {
|
|
1100
1141
|
const c = character;
|
|
1101
1142
|
const cs = characters;
|
|
@@ -1116,13 +1157,13 @@ var Novely = (() => {
|
|
|
1116
1157
|
unwrap2(name, data2),
|
|
1117
1158
|
character,
|
|
1118
1159
|
emotion,
|
|
1119
|
-
|
|
1160
|
+
forward
|
|
1120
1161
|
);
|
|
1121
1162
|
},
|
|
1122
|
-
function({ ctx }, [fn]) {
|
|
1163
|
+
function({ ctx, push }, [fn]) {
|
|
1123
1164
|
const result = fn(ctx.meta.restoring, ctx.meta.goingBack, ctx.meta.preview);
|
|
1124
1165
|
if (!ctx.meta.restoring) {
|
|
1125
|
-
result ? result.then(
|
|
1166
|
+
result ? result.then(push) : push();
|
|
1126
1167
|
}
|
|
1127
1168
|
return result;
|
|
1128
1169
|
},
|
|
@@ -1172,13 +1213,13 @@ var Novely = (() => {
|
|
|
1172
1213
|
data: data2
|
|
1173
1214
|
});
|
|
1174
1215
|
},
|
|
1175
|
-
clear({ ctx }, [keep, characters2, audio]) {
|
|
1216
|
+
clear({ ctx, push }, [keep, characters2, audio]) {
|
|
1176
1217
|
ctx.vibrate(0);
|
|
1177
1218
|
ctx.clear(
|
|
1178
1219
|
keep || EMPTY_SET,
|
|
1179
1220
|
characters2 || EMPTY_SET,
|
|
1180
1221
|
audio || { music: EMPTY_SET, sounds: EMPTY_SET },
|
|
1181
|
-
|
|
1222
|
+
push
|
|
1182
1223
|
);
|
|
1183
1224
|
},
|
|
1184
1225
|
condition({ ctx }, [condition, variants]) {
|
|
@@ -1207,15 +1248,15 @@ var Novely = (() => {
|
|
|
1207
1248
|
interactivity(false);
|
|
1208
1249
|
times.clear();
|
|
1209
1250
|
},
|
|
1210
|
-
input({ ctx, data: data2 }, [question, onInput, setup]) {
|
|
1251
|
+
input({ ctx, data: data2, forward }, [question, onInput, setup]) {
|
|
1211
1252
|
ctx.input(
|
|
1212
1253
|
unwrap2(question, data2),
|
|
1213
1254
|
onInput,
|
|
1214
1255
|
setup || noop,
|
|
1215
|
-
|
|
1256
|
+
forward
|
|
1216
1257
|
);
|
|
1217
1258
|
},
|
|
1218
|
-
custom({ ctx }, [handler]) {
|
|
1259
|
+
custom({ ctx, push }, [handler]) {
|
|
1219
1260
|
const result = ctx.custom(handler, () => {
|
|
1220
1261
|
if (ctx.meta.restoring)
|
|
1221
1262
|
return;
|
|
@@ -1223,16 +1264,16 @@ var Novely = (() => {
|
|
|
1223
1264
|
enmemory(ctx);
|
|
1224
1265
|
interactivity(true);
|
|
1225
1266
|
}
|
|
1226
|
-
push(
|
|
1267
|
+
push();
|
|
1227
1268
|
});
|
|
1228
1269
|
return result;
|
|
1229
1270
|
},
|
|
1230
|
-
vibrate({ ctx }, pattern) {
|
|
1271
|
+
vibrate({ ctx, push }, pattern) {
|
|
1231
1272
|
ctx.vibrate(pattern);
|
|
1232
|
-
push(
|
|
1273
|
+
push();
|
|
1233
1274
|
},
|
|
1234
|
-
next({ ctx }) {
|
|
1235
|
-
push(
|
|
1275
|
+
next({ ctx, push }) {
|
|
1276
|
+
push();
|
|
1236
1277
|
},
|
|
1237
1278
|
animateCharacter({ ctx, data: data2 }, [character, timeout, ...classes]) {
|
|
1238
1279
|
if (DEV && classes.length === 0) {
|
|
@@ -1253,11 +1294,12 @@ var Novely = (() => {
|
|
|
1253
1294
|
return;
|
|
1254
1295
|
const classNames = classes.filter((className) => !target.classList.contains(className));
|
|
1255
1296
|
target.classList.add(...classNames);
|
|
1256
|
-
const
|
|
1297
|
+
const removeClassNames = () => {
|
|
1257
1298
|
target.classList.remove(...classNames);
|
|
1258
|
-
}
|
|
1299
|
+
};
|
|
1300
|
+
const timeoutId = setTimeout(removeClassNames, timeout);
|
|
1259
1301
|
clear(() => {
|
|
1260
|
-
|
|
1302
|
+
removeClassNames();
|
|
1261
1303
|
clearTimeout(timeoutId);
|
|
1262
1304
|
});
|
|
1263
1305
|
};
|
|
@@ -1267,12 +1309,12 @@ var Novely = (() => {
|
|
|
1267
1309
|
data: data2
|
|
1268
1310
|
});
|
|
1269
1311
|
},
|
|
1270
|
-
text({ ctx, data: data2 }, text) {
|
|
1312
|
+
text({ ctx, data: data2, forward }, text) {
|
|
1271
1313
|
const string = text.map((content) => unwrap2(content, data2)).join(" ");
|
|
1272
1314
|
if (DEV && string.length === 0) {
|
|
1273
1315
|
throw new Error(`Action Text was called with empty string or array`);
|
|
1274
1316
|
}
|
|
1275
|
-
ctx.text(string,
|
|
1317
|
+
ctx.text(string, forward);
|
|
1276
1318
|
},
|
|
1277
1319
|
exit({ ctx, data: data2 }) {
|
|
1278
1320
|
if (ctx.meta.restoring)
|
|
@@ -1321,11 +1363,11 @@ var Novely = (() => {
|
|
|
1321
1363
|
}
|
|
1322
1364
|
render(ctx);
|
|
1323
1365
|
},
|
|
1324
|
-
preload({ ctx }, [source]) {
|
|
1366
|
+
preload({ ctx, push }, [source]) {
|
|
1325
1367
|
if (!ctx.meta.goingBack && !ctx.meta.restoring && !PRELOADED_ASSETS.has(source)) {
|
|
1326
1368
|
PRELOADED_ASSETS.add(renderer.misc.preloadImage(source));
|
|
1327
1369
|
}
|
|
1328
|
-
push(
|
|
1370
|
+
push();
|
|
1329
1371
|
},
|
|
1330
1372
|
block({ ctx }, [scene]) {
|
|
1331
1373
|
if (DEV && !story[scene]) {
|
|
@@ -1341,25 +1383,6 @@ var Novely = (() => {
|
|
|
1341
1383
|
}
|
|
1342
1384
|
}
|
|
1343
1385
|
});
|
|
1344
|
-
const enmemory = (ctx) => {
|
|
1345
|
-
if (ctx.meta.restoring)
|
|
1346
|
-
return;
|
|
1347
|
-
const stack = useStack(ctx);
|
|
1348
|
-
const current = klona(stack.value);
|
|
1349
|
-
current[2][1] = "auto";
|
|
1350
|
-
stack.push(current);
|
|
1351
|
-
save(true, "auto");
|
|
1352
|
-
};
|
|
1353
|
-
const next = (ctx) => {
|
|
1354
|
-
const stack = useStack(ctx);
|
|
1355
|
-
const path = stack.value[0];
|
|
1356
|
-
const last = path.at(-1);
|
|
1357
|
-
if (last && (isNull(last[0]) || last[0] === "jump") && isNumber(last[1])) {
|
|
1358
|
-
last[1]++;
|
|
1359
|
-
} else {
|
|
1360
|
-
path.push([null, 0]);
|
|
1361
|
-
}
|
|
1362
|
-
};
|
|
1363
1386
|
const render = (ctx) => {
|
|
1364
1387
|
const stack = useStack(ctx);
|
|
1365
1388
|
const referred = refer(stack.value[0]);
|
|
@@ -1376,17 +1399,6 @@ var Novely = (() => {
|
|
|
1376
1399
|
});
|
|
1377
1400
|
}
|
|
1378
1401
|
};
|
|
1379
|
-
const push = (ctx) => {
|
|
1380
|
-
if (!ctx.meta.restoring)
|
|
1381
|
-
next(ctx), render(ctx);
|
|
1382
|
-
};
|
|
1383
|
-
const forward = (ctx) => {
|
|
1384
|
-
if (!ctx.meta.preview)
|
|
1385
|
-
enmemory(ctx);
|
|
1386
|
-
push(ctx);
|
|
1387
|
-
if (!ctx.meta.preview)
|
|
1388
|
-
interactivity(true);
|
|
1389
|
-
};
|
|
1390
1402
|
const interactivity = (value = false) => {
|
|
1391
1403
|
interacted = value ? interacted + 1 : 0;
|
|
1392
1404
|
};
|
|
@@ -1436,6 +1448,16 @@ var Novely = (() => {
|
|
|
1436
1448
|
*/
|
|
1437
1449
|
unwrap(content) {
|
|
1438
1450
|
return unwrap2(content, $.get().data);
|
|
1451
|
+
},
|
|
1452
|
+
/**
|
|
1453
|
+
* Cancel data loading, hide UI, ignore page change events
|
|
1454
|
+
* Data updates still will work in case Novely already was loaded
|
|
1455
|
+
*/
|
|
1456
|
+
destroy() {
|
|
1457
|
+
dataLoaded.cancel();
|
|
1458
|
+
UIInstance.unmount();
|
|
1459
|
+
removeEventListener("visibilitychange", onVisibilityChange);
|
|
1460
|
+
removeEventListener("beforeunload", throttledEmergencyOnStorageDataChange);
|
|
1439
1461
|
}
|
|
1440
1462
|
};
|
|
1441
1463
|
};
|