@rohal12/twee-ts 1.14.0 → 1.15.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.
- package/dist/bin/twee-ts.js +83 -45
- package/dist/bin/twee-ts.js.map +1 -1
- package/dist/{chunk-Z2CNKPVJ.js → chunk-W3SNMQO4.js} +134 -96
- package/dist/chunk-W3SNMQO4.js.map +1 -0
- package/dist/index.cjs +104 -65
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +80 -42
- package/dist/index.js.map +1 -1
- package/dist/plugins/rollup.js +1 -1
- package/dist/plugins/vite.d.ts +11 -45
- package/dist/plugins/vite.js +308 -38
- package/dist/plugins/vite.js.map +1 -1
- package/package.json +17 -3
- package/dist/chunk-Z2CNKPVJ.js.map +0 -1
|
@@ -1,3 +1,63 @@
|
|
|
1
|
+
// src/media-types.ts
|
|
2
|
+
import { extname } from "path";
|
|
3
|
+
var MEDIA_TYPE_MAP = {
|
|
4
|
+
// Audio
|
|
5
|
+
aac: "audio/aac",
|
|
6
|
+
flac: "audio/flac",
|
|
7
|
+
ogg: "audio/ogg",
|
|
8
|
+
wav: "audio/wav",
|
|
9
|
+
mp3: "audio/mpeg",
|
|
10
|
+
m4a: "audio/mp4",
|
|
11
|
+
oga: "audio/ogg",
|
|
12
|
+
opus: "audio/ogg",
|
|
13
|
+
wave: "audio/wav",
|
|
14
|
+
weba: "audio/webm",
|
|
15
|
+
// Fonts
|
|
16
|
+
otf: "font/otf",
|
|
17
|
+
ttf: "font/ttf",
|
|
18
|
+
woff: "font/woff",
|
|
19
|
+
woff2: "font/woff2",
|
|
20
|
+
// Images
|
|
21
|
+
gif: "image/gif",
|
|
22
|
+
jpeg: "image/jpeg",
|
|
23
|
+
jpg: "image/jpeg",
|
|
24
|
+
png: "image/png",
|
|
25
|
+
svg: "image/svg+xml",
|
|
26
|
+
tif: "image/tiff",
|
|
27
|
+
tiff: "image/tiff",
|
|
28
|
+
webp: "image/webp",
|
|
29
|
+
// Metadata
|
|
30
|
+
vtt: "text/vtt",
|
|
31
|
+
// Video
|
|
32
|
+
mp4: "video/mp4",
|
|
33
|
+
ogv: "video/ogg",
|
|
34
|
+
webm: "video/webm"
|
|
35
|
+
};
|
|
36
|
+
function mediaTypeFromExt(ext) {
|
|
37
|
+
return MEDIA_TYPE_MAP[ext] ?? "application/octet-stream";
|
|
38
|
+
}
|
|
39
|
+
function mediaTypeFromFilename(filename) {
|
|
40
|
+
return mediaTypeFromExt(normalizedFileExt(filename));
|
|
41
|
+
}
|
|
42
|
+
function normalizedFileExt(filename) {
|
|
43
|
+
const ext = extname(filename);
|
|
44
|
+
if (!ext) return "";
|
|
45
|
+
return ext.slice(1).toLowerCase();
|
|
46
|
+
}
|
|
47
|
+
function slugify(original) {
|
|
48
|
+
return original.replace(/[\x00-\x20!-/:-@[-^`{-\x9f]+/g, "_");
|
|
49
|
+
}
|
|
50
|
+
function fontFormatHint(ext) {
|
|
51
|
+
switch (ext) {
|
|
52
|
+
case "ttf":
|
|
53
|
+
return "truetype";
|
|
54
|
+
case "otf":
|
|
55
|
+
return "opentype";
|
|
56
|
+
default:
|
|
57
|
+
return ext;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
1
61
|
// src/compiler.ts
|
|
2
62
|
import { writeFileSync as writeFileSync2 } from "fs";
|
|
3
63
|
|
|
@@ -488,68 +548,6 @@ function getStoryStats(story, wordCountMethod = "tweego") {
|
|
|
488
548
|
// src/filesystem.ts
|
|
489
549
|
import { readdirSync, statSync, watch as fsWatch } from "fs";
|
|
490
550
|
import { resolve, relative, join } from "path";
|
|
491
|
-
|
|
492
|
-
// src/media-types.ts
|
|
493
|
-
import { extname } from "path";
|
|
494
|
-
var MEDIA_TYPE_MAP = {
|
|
495
|
-
// Audio
|
|
496
|
-
aac: "audio/aac",
|
|
497
|
-
flac: "audio/flac",
|
|
498
|
-
ogg: "audio/ogg",
|
|
499
|
-
wav: "audio/wav",
|
|
500
|
-
mp3: "audio/mpeg",
|
|
501
|
-
m4a: "audio/mp4",
|
|
502
|
-
oga: "audio/ogg",
|
|
503
|
-
opus: "audio/ogg",
|
|
504
|
-
wave: "audio/wav",
|
|
505
|
-
weba: "audio/webm",
|
|
506
|
-
// Fonts
|
|
507
|
-
otf: "font/otf",
|
|
508
|
-
ttf: "font/ttf",
|
|
509
|
-
woff: "font/woff",
|
|
510
|
-
woff2: "font/woff2",
|
|
511
|
-
// Images
|
|
512
|
-
gif: "image/gif",
|
|
513
|
-
jpeg: "image/jpeg",
|
|
514
|
-
jpg: "image/jpeg",
|
|
515
|
-
png: "image/png",
|
|
516
|
-
svg: "image/svg+xml",
|
|
517
|
-
tif: "image/tiff",
|
|
518
|
-
tiff: "image/tiff",
|
|
519
|
-
webp: "image/webp",
|
|
520
|
-
// Metadata
|
|
521
|
-
vtt: "text/vtt",
|
|
522
|
-
// Video
|
|
523
|
-
mp4: "video/mp4",
|
|
524
|
-
ogv: "video/ogg",
|
|
525
|
-
webm: "video/webm"
|
|
526
|
-
};
|
|
527
|
-
function mediaTypeFromExt(ext) {
|
|
528
|
-
return MEDIA_TYPE_MAP[ext] ?? "application/octet-stream";
|
|
529
|
-
}
|
|
530
|
-
function mediaTypeFromFilename(filename) {
|
|
531
|
-
return mediaTypeFromExt(normalizedFileExt(filename));
|
|
532
|
-
}
|
|
533
|
-
function normalizedFileExt(filename) {
|
|
534
|
-
const ext = extname(filename);
|
|
535
|
-
if (!ext) return "";
|
|
536
|
-
return ext.slice(1).toLowerCase();
|
|
537
|
-
}
|
|
538
|
-
function slugify(original) {
|
|
539
|
-
return original.replace(/[\x00-\x20!-/:-@[-^`{-\x9f]+/g, "_");
|
|
540
|
-
}
|
|
541
|
-
function fontFormatHint(ext) {
|
|
542
|
-
switch (ext) {
|
|
543
|
-
case "ttf":
|
|
544
|
-
return "truetype";
|
|
545
|
-
case "otf":
|
|
546
|
-
return "opentype";
|
|
547
|
-
default:
|
|
548
|
-
return ext;
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
// src/filesystem.ts
|
|
553
551
|
function getFilenames(pathnames, outFilename) {
|
|
554
552
|
const filenames = [];
|
|
555
553
|
const absOutFile = outFilename ? resolve(outFilename) : "";
|
|
@@ -3911,17 +3909,35 @@ function loadInlineSources(story, sources, opts, diagnostics) {
|
|
|
3911
3909
|
}
|
|
3912
3910
|
const content = typeof source.content === "string" ? source.content : source.content.toString("utf-8");
|
|
3913
3911
|
const ext = normalizedFileExt(source.filename);
|
|
3914
|
-
|
|
3915
|
-
|
|
3916
|
-
|
|
3917
|
-
|
|
3918
|
-
|
|
3919
|
-
|
|
3920
|
-
|
|
3921
|
-
|
|
3922
|
-
|
|
3923
|
-
|
|
3912
|
+
switch (ext) {
|
|
3913
|
+
case "":
|
|
3914
|
+
case "tw":
|
|
3915
|
+
case "twee":
|
|
3916
|
+
case "tw2":
|
|
3917
|
+
case "twee2": {
|
|
3918
|
+
const twee2 = ext === "tw2" || ext === "twee2" || opts.twee2Compat;
|
|
3919
|
+
const result = parseTwee(content, {
|
|
3920
|
+
filename: source.filename,
|
|
3921
|
+
trim: opts.trim ?? true,
|
|
3922
|
+
twee2Compat: twee2
|
|
3923
|
+
});
|
|
3924
|
+
diagnostics.push(...result.diagnostics);
|
|
3925
|
+
for (const p of result.passages) {
|
|
3926
|
+
storyAdd(story, p, diagnostics);
|
|
3927
|
+
}
|
|
3928
|
+
break;
|
|
3924
3929
|
}
|
|
3930
|
+
case "css":
|
|
3931
|
+
storyAdd(story, { name: basename(source.filename), tags: ["stylesheet"], text: content }, diagnostics);
|
|
3932
|
+
break;
|
|
3933
|
+
case "js":
|
|
3934
|
+
storyAdd(story, { name: basename(source.filename), tags: ["script"], text: content }, diagnostics);
|
|
3935
|
+
break;
|
|
3936
|
+
default:
|
|
3937
|
+
diagnostics.push({
|
|
3938
|
+
level: "warning",
|
|
3939
|
+
message: `load ${source.filename}: in-memory sources of type .${ext} are not supported; skipped.`
|
|
3940
|
+
});
|
|
3925
3941
|
}
|
|
3926
3942
|
}
|
|
3927
3943
|
}
|
|
@@ -4119,7 +4135,27 @@ function loadSourcesCached(story, filenames, opts, diagnostics, processedFiles,
|
|
|
4119
4135
|
}
|
|
4120
4136
|
|
|
4121
4137
|
// src/version.ts
|
|
4122
|
-
|
|
4138
|
+
import { readFileSync as readFileSync2 } from "fs";
|
|
4139
|
+
import { dirname, join as join3 } from "path";
|
|
4140
|
+
import { fileURLToPath } from "url";
|
|
4141
|
+
var PACKAGE_NAME = "@rohal12/twee-ts";
|
|
4142
|
+
function findPackageVersion(startDir) {
|
|
4143
|
+
let dir = startDir;
|
|
4144
|
+
for (; ; ) {
|
|
4145
|
+
try {
|
|
4146
|
+
const pkg = JSON.parse(readFileSync2(join3(dir, "package.json"), "utf-8"));
|
|
4147
|
+
if (pkg.name === PACKAGE_NAME && typeof pkg.version === "string") return pkg.version;
|
|
4148
|
+
} catch {
|
|
4149
|
+
}
|
|
4150
|
+
const parent = dirname(dir);
|
|
4151
|
+
if (parent === dir) return void 0;
|
|
4152
|
+
dir = parent;
|
|
4153
|
+
}
|
|
4154
|
+
}
|
|
4155
|
+
function moduleDir() {
|
|
4156
|
+
return typeof __dirname === "string" ? __dirname : dirname(fileURLToPath(import.meta.url));
|
|
4157
|
+
}
|
|
4158
|
+
var VERSION = findPackageVersion(moduleDir()) ?? "0.0.0";
|
|
4123
4159
|
|
|
4124
4160
|
// src/output-twine2.ts
|
|
4125
4161
|
var CREATOR_NAME = "Twee-ts";
|
|
@@ -4209,8 +4245,8 @@ function getTwine2DataChunk(story, startName, options) {
|
|
|
4209
4245
|
}
|
|
4210
4246
|
|
|
4211
4247
|
// src/output-twine1.ts
|
|
4212
|
-
import { readFileSync as
|
|
4213
|
-
import { join as
|
|
4248
|
+
import { readFileSync as readFileSync3 } from "fs";
|
|
4249
|
+
import { join as join4, dirname as dirname2 } from "path";
|
|
4214
4250
|
var CREATOR_NAME2 = "twee-ts";
|
|
4215
4251
|
function toTwine1Archive(story, _startName) {
|
|
4216
4252
|
const { data, count } = getTwine1PassageChunk(story);
|
|
@@ -4218,19 +4254,19 @@ function toTwine1Archive(story, _startName) {
|
|
|
4218
4254
|
`;
|
|
4219
4255
|
}
|
|
4220
4256
|
function toTwine1HTML(story, format, startName) {
|
|
4221
|
-
const formatDir =
|
|
4222
|
-
const parentDir =
|
|
4257
|
+
const formatDir = dirname2(format.filename);
|
|
4258
|
+
const parentDir = dirname2(formatDir);
|
|
4223
4259
|
let template = readFormatSource(format);
|
|
4224
4260
|
const { data, count } = getTwine1PassageChunk(story);
|
|
4225
|
-
template = tryReplaceComponent(template, '"USER_LIB"',
|
|
4226
|
-
template = tryReplaceComponent(template, '"ENGINE"',
|
|
4227
|
-
template = tryReplaceComponent(template, '"SUGARCANE"',
|
|
4228
|
-
template = tryReplaceComponent(template, '"JONAH"',
|
|
4261
|
+
template = tryReplaceComponent(template, '"USER_LIB"', join4(formatDir, "userlib.js"), false);
|
|
4262
|
+
template = tryReplaceComponent(template, '"ENGINE"', join4(parentDir, "engine.js"), true);
|
|
4263
|
+
template = tryReplaceComponent(template, '"SUGARCANE"', join4(formatDir, "code.js"), true);
|
|
4264
|
+
template = tryReplaceComponent(template, '"JONAH"', join4(formatDir, "code.js"), true);
|
|
4229
4265
|
if (story.twine1.settings.get("jquery") === "on") {
|
|
4230
|
-
template = tryReplaceComponent(template, '"JQUERY"',
|
|
4266
|
+
template = tryReplaceComponent(template, '"JQUERY"', join4(parentDir, "jquery.js"), true);
|
|
4231
4267
|
}
|
|
4232
4268
|
if (story.twine1.settings.get("modernizr") === "on") {
|
|
4233
|
-
template = tryReplaceComponent(template, '"MODERNIZR"',
|
|
4269
|
+
template = tryReplaceComponent(template, '"MODERNIZR"', join4(parentDir, "modernizr.js"), true);
|
|
4234
4270
|
}
|
|
4235
4271
|
const displayStart = startName === "Start" ? "" : startName;
|
|
4236
4272
|
template = template.replace('"VERSION"', `Compiled with ${CREATOR_NAME2}, ${VERSION}`);
|
|
@@ -4243,7 +4279,7 @@ function toTwine1HTML(story, format, startName) {
|
|
|
4243
4279
|
} else {
|
|
4244
4280
|
let footer;
|
|
4245
4281
|
try {
|
|
4246
|
-
footer =
|
|
4282
|
+
footer = readFileSync3(join4(formatDir, "footer.html"), "utf-8");
|
|
4247
4283
|
} catch {
|
|
4248
4284
|
footer = "</div>\n</body>\n</html>\n";
|
|
4249
4285
|
}
|
|
@@ -4273,7 +4309,7 @@ function getTwine1PassageChunk(story) {
|
|
|
4273
4309
|
function tryReplaceComponent(template, placeholder, componentPath, required) {
|
|
4274
4310
|
if (!template.includes(placeholder)) return template;
|
|
4275
4311
|
try {
|
|
4276
|
-
let content =
|
|
4312
|
+
let content = readFileSync3(componentPath, "utf-8");
|
|
4277
4313
|
if (content.charCodeAt(0) === 65279) content = content.slice(1);
|
|
4278
4314
|
return template.replace(placeholder, () => content);
|
|
4279
4315
|
} catch (e) {
|
|
@@ -4370,8 +4406,8 @@ function modifyHead(html, modulePaths, headFile, diagnostics) {
|
|
|
4370
4406
|
}
|
|
4371
4407
|
|
|
4372
4408
|
// src/remote-formats.ts
|
|
4373
|
-
import { mkdirSync, readFileSync as
|
|
4374
|
-
import { join as
|
|
4409
|
+
import { mkdirSync, readFileSync as readFileSync4, writeFileSync, existsSync, readdirSync as readdirSync3, statSync as statSync4, rmSync } from "fs";
|
|
4410
|
+
import { join as join5 } from "path";
|
|
4375
4411
|
import { homedir as homedir2 } from "os";
|
|
4376
4412
|
var DEFAULT_SFA_INDICES = [
|
|
4377
4413
|
"https://videlais.github.io/story-formats-archive/official/index.json",
|
|
@@ -4379,8 +4415,8 @@ var DEFAULT_SFA_INDICES = [
|
|
|
4379
4415
|
];
|
|
4380
4416
|
function getCacheDir() {
|
|
4381
4417
|
const xdg = process.env["XDG_CACHE_HOME"];
|
|
4382
|
-
const base = xdg ||
|
|
4383
|
-
return
|
|
4418
|
+
const base = xdg || join5(homedir2(), ".cache");
|
|
4419
|
+
return join5(base, "twee-ts", "storyformats");
|
|
4384
4420
|
}
|
|
4385
4421
|
var indexCache = /* @__PURE__ */ new Map();
|
|
4386
4422
|
function clearIndexCache() {
|
|
@@ -4470,9 +4506,9 @@ async function fetchAndCacheFormat(entry, downloadUrl) {
|
|
|
4470
4506
|
throw new Error(`Failed to parse format JSON from ${downloadUrl}`);
|
|
4471
4507
|
}
|
|
4472
4508
|
const cacheDir = getCacheDir();
|
|
4473
|
-
const formatDir =
|
|
4509
|
+
const formatDir = join5(cacheDir, entry.name, entry.version);
|
|
4474
4510
|
mkdirSync(formatDir, { recursive: true });
|
|
4475
|
-
const formatPath =
|
|
4511
|
+
const formatPath = join5(formatDir, "format.js");
|
|
4476
4512
|
writeFileSync(formatPath, text, "utf-8");
|
|
4477
4513
|
return {
|
|
4478
4514
|
id,
|
|
@@ -4496,9 +4532,9 @@ async function fetchDirectFormat(url) {
|
|
|
4496
4532
|
}
|
|
4497
4533
|
const id = makeFormatId(data.name, data.version);
|
|
4498
4534
|
const cacheDir = getCacheDir();
|
|
4499
|
-
const formatDir =
|
|
4535
|
+
const formatDir = join5(cacheDir, data.name, data.version);
|
|
4500
4536
|
mkdirSync(formatDir, { recursive: true });
|
|
4501
|
-
const formatPath =
|
|
4537
|
+
const formatPath = join5(formatDir, "format.js");
|
|
4502
4538
|
writeFileSync(formatPath, text, "utf-8");
|
|
4503
4539
|
return {
|
|
4504
4540
|
id,
|
|
@@ -4546,10 +4582,10 @@ async function resolveRemoteFormat(name, version, indices, urls) {
|
|
|
4546
4582
|
return void 0;
|
|
4547
4583
|
}
|
|
4548
4584
|
function getCachedFormat(name, version) {
|
|
4549
|
-
const formatPath =
|
|
4585
|
+
const formatPath = join5(getCacheDir(), name, version, "format.js");
|
|
4550
4586
|
try {
|
|
4551
4587
|
if (!existsSync(formatPath)) return void 0;
|
|
4552
|
-
const source =
|
|
4588
|
+
const source = readFileSync4(formatPath, "utf-8");
|
|
4553
4589
|
const id = makeFormatId(name, version);
|
|
4554
4590
|
const data = parseFormatJSON(source, id);
|
|
4555
4591
|
if (!data) return void 0;
|
|
@@ -4765,7 +4801,9 @@ function storyToJSON(story) {
|
|
|
4765
4801
|
}
|
|
4766
4802
|
|
|
4767
4803
|
export {
|
|
4804
|
+
mediaTypeFromFilename,
|
|
4805
|
+
TweeTsError,
|
|
4768
4806
|
compile,
|
|
4769
4807
|
compileIncremental
|
|
4770
4808
|
};
|
|
4771
|
-
//# sourceMappingURL=chunk-
|
|
4809
|
+
//# sourceMappingURL=chunk-W3SNMQO4.js.map
|