@rohal12/twee-ts 1.2.0 → 1.3.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/README.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # twee-ts
2
2
 
3
+ [![npm](https://img.shields.io/npm/v/@rohal12/twee-ts)](https://www.npmjs.com/package/@rohal12/twee-ts)
4
+ [![CI](https://img.shields.io/github/actions/workflow/status/rohal12/twee-ts/ci.yml)](https://github.com/rohal12/twee-ts/actions)
5
+ [![bundle size](https://img.shields.io/bundlephobia/minzip/@rohal12/twee-ts)](https://bundlephobia.com/package/@rohal12/twee-ts)
6
+ [![zero dependencies](https://img.shields.io/badge/dependencies-0-brightgreen)]()
7
+ [![TypeScript](https://img.shields.io/badge/TypeScript-strict-blue)](https://www.typescriptlang.org/)
8
+ [![node](https://img.shields.io/node/v/@rohal12/twee-ts)](https://nodejs.org/)
9
+ [![last commit](https://img.shields.io/github/last-commit/rohal12/twee-ts)](https://github.com/rohal12/twee-ts/commits)
10
+ [![license](https://img.shields.io/npm/l/@rohal12/twee-ts)](./UNLICENSE)
11
+
3
12
  TypeScript reimplementation of [Tweego](https://www.motoslave.net/tweego/) — a command-line compiler for Twine/Twee interactive fiction projects.
4
13
 
5
14
  Zero runtime dependencies. Node.js 22+.
@@ -1409,23 +1409,24 @@ function getTwine2DataChunk(story, startName, diagnostics) {
1409
1409
  if (val) opts.push(opt);
1410
1410
  }
1411
1411
  const options = opts.join(" ");
1412
- const zoom = story.twine2.zoom === Math.floor(story.twine2.zoom) ? story.twine2.zoom.toString() : story.twine2.zoom.toFixed(1);
1412
+ const zoom = String(story.twine2.zoom);
1413
1413
  const wrapper = `<!-- UUID://${htmlCommentSanitize(story.ifid)}// --><tw-storydata name="${attrEscape(story.name)}" startnode="${attrEscape(startID)}" creator="${attrEscape(CREATOR_NAME)}" creator-version="${attrEscape(VERSION)}" ifid="${attrEscape(story.ifid)}" zoom="${attrEscape(zoom)}" format="${attrEscape(story.twine2.format)}" format-version="${attrEscape(story.twine2.formatVersion)}" options="${attrEscape(options)}" hidden>`;
1414
1414
  return wrapper + parts.join("") + "</tw-storydata>";
1415
1415
  }
1416
1416
  function ensureIFID(story, diagnostics) {
1417
1417
  if (story.ifid !== "") return;
1418
1418
  if (story.legacyIFID !== "") {
1419
+ story.ifid = story.legacyIFID;
1419
1420
  diagnostics.push({
1420
1421
  level: "warning",
1421
1422
  message: 'Story IFID not found; reusing "ifid" entry from the "StorySettings" special passage.'
1422
1423
  });
1423
- story.ifid = story.legacyIFID;
1424
1424
  } else {
1425
- story.ifid = generateIFID();
1425
+ const ifid = generateIFID();
1426
+ story.ifid = ifid;
1426
1427
  diagnostics.push({
1427
- level: "warning",
1428
- message: `Story IFID not found; generated ${story.ifid} for your project. Add it to a StoryData passage.`
1428
+ level: "error",
1429
+ message: `Story IFID not found. Add a StoryData passage with: {"ifid":"${ifid}"}`
1429
1430
  });
1430
1431
  }
1431
1432
  }
@@ -1822,6 +1823,7 @@ function discoverCachedFormats() {
1822
1823
  }
1823
1824
 
1824
1825
  // src/compiler.ts
1826
+ var CREATOR_NAME3 = "Twee-ts";
1825
1827
  var DEFAULT_FORMAT_ID = "sugarcube-2";
1826
1828
  var DEFAULT_START_NAME = "Start";
1827
1829
  var TweeTsError = class extends Error {
@@ -1968,28 +1970,46 @@ async function buildOutput(options) {
1968
1970
  return { output, story, format, diagnostics, stats };
1969
1971
  }
1970
1972
  function storyToJSON(story) {
1971
- return JSON.stringify(
1972
- {
1973
- name: story.name,
1974
- ifid: story.ifid,
1975
- passages: story.passages.map((p) => ({
1973
+ const scripts = [];
1974
+ const stylesheets = [];
1975
+ const storyPassages = [];
1976
+ for (const p of story.passages) {
1977
+ if (p.name === "StoryTitle" || p.name === "StoryData") continue;
1978
+ if (hasTag(p, "Twine.private")) continue;
1979
+ if (hasTag(p, "script")) {
1980
+ scripts.push(p.text);
1981
+ } else if (hasTag(p, "stylesheet")) {
1982
+ stylesheets.push(p.text);
1983
+ } else {
1984
+ const entry = {
1976
1985
  name: p.name,
1977
1986
  tags: p.tags,
1978
- text: p.text,
1979
- metadata: p.metadata ?? null
1980
- })),
1981
- twine2: {
1982
- format: story.twine2.format,
1983
- formatVersion: story.twine2.formatVersion,
1984
- start: story.twine2.start,
1985
- tagColors: Object.fromEntries(story.twine2.tagColors),
1986
- options: Object.fromEntries(story.twine2.options),
1987
- zoom: story.twine2.zoom
1987
+ text: p.text
1988
+ };
1989
+ if (p.metadata && (p.metadata.position || p.metadata.size)) {
1990
+ const meta = {};
1991
+ if (p.metadata.position) meta.position = p.metadata.position;
1992
+ if (p.metadata.size) meta.size = p.metadata.size;
1993
+ entry.metadata = meta;
1988
1994
  }
1989
- },
1990
- null,
1991
- 2
1992
- );
1995
+ storyPassages.push(entry);
1996
+ }
1997
+ }
1998
+ const obj = {
1999
+ name: story.name
2000
+ };
2001
+ if (story.ifid) obj.ifid = story.ifid;
2002
+ if (story.twine2.format) obj.format = story.twine2.format;
2003
+ if (story.twine2.formatVersion) obj["format-version"] = story.twine2.formatVersion;
2004
+ if (story.twine2.start) obj.start = story.twine2.start;
2005
+ if (story.twine2.tagColors.size > 0) obj["tag-colors"] = Object.fromEntries(story.twine2.tagColors);
2006
+ if (story.twine2.zoom !== 1) obj.zoom = story.twine2.zoom;
2007
+ obj.creator = CREATOR_NAME3;
2008
+ obj["creator-version"] = VERSION;
2009
+ obj.style = stylesheets.join("\n");
2010
+ obj.script = scripts.join("\n");
2011
+ obj.passages = storyPassages;
2012
+ return JSON.stringify(obj, null, 2);
1993
2013
  }
1994
2014
 
1995
2015
  // src/config.ts