@vishu1301/script-writing 0.4.7 → 0.4.9

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.cjs CHANGED
@@ -4,6 +4,9 @@ var react = require('react');
4
4
  var lucideReact = require('lucide-react');
5
5
  var jsxRuntime = require('react/jsx-runtime');
6
6
  var pdfjs = require('pdfjs-dist');
7
+ var jsPDF = require('jspdf');
8
+
9
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
7
10
 
8
11
  function _interopNamespace(e) {
9
12
  if (e && e.__esModule) return e;
@@ -24,6 +27,7 @@ function _interopNamespace(e) {
24
27
  }
25
28
 
26
29
  var pdfjs__namespace = /*#__PURE__*/_interopNamespace(pdfjs);
30
+ var jsPDF__default = /*#__PURE__*/_interopDefault(jsPDF);
27
31
 
28
32
  var __defProp = Object.defineProperty;
29
33
  var __defProps = Object.defineProperties;
@@ -369,9 +373,13 @@ function ScreenplayEditorView({
369
373
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-12 w-full items-center pb-24", children: /* @__PURE__ */ jsxRuntime.jsx(
370
374
  "div",
371
375
  {
372
- className: "relative bg-[#fdfdfc] shadow-2xl shadow-zinc-300/60 ring-1 ring-zinc-200/50 rounded-sm md:rounded-md pl-[1.5in] py-[1in] pr-[1in] flex flex-col w-[210mm] min-h-[297mm] shrink-0",
376
+ className: "relative bg-[#fdfdfc] shadow-2xl shadow-zinc-300/60 border border-zinc-100 rounded-sm md:rounded-md pl-[1.5in] py-[1in] pr-[1in] flex flex-col w-[210mm] min-h-[297mm] shrink-0",
373
377
  style: {
374
- fontFamily: "var(--font-courier-prime, 'Courier New', Courier, monospace)"
378
+ fontFamily: "var(--font-courier-prime, 'Courier Prime', 'Courier New', Courier, monospace)",
379
+ paddingLeft: "1.5in",
380
+ paddingRight: "1in",
381
+ paddingTop: "1in",
382
+ paddingBottom: "1in"
375
383
  },
376
384
  children: blocks.map((block) => {
377
385
  var _a, _b;
@@ -409,6 +417,9 @@ function ScreenplayEditorView({
409
417
  "aria-label": "Scene Type",
410
418
  value: (_a = block.sceneType) != null ? _a : "INT.",
411
419
  onChange: (e) => handleSceneTypeChange(block.id, e.target.value),
420
+ style: {
421
+ appearance: "none"
422
+ },
412
423
  children: [
413
424
  /* @__PURE__ */ jsxRuntime.jsx("option", { children: "INT." }),
414
425
  /* @__PURE__ */ jsxRuntime.jsx("option", { children: "EXT." }),
@@ -446,6 +457,9 @@ function ScreenplayEditorView({
446
457
  className: "rounded-md text-zinc-800 font-bold px-1.5 py-1 appearance-none bg-transparent hover:bg-zinc-200/50 outline-none cursor-pointer transition-colors",
447
458
  "aria-label": "Time of Day",
448
459
  value: (_b = block.timeOfDay) != null ? _b : "DAY",
460
+ style: {
461
+ appearance: "none"
462
+ },
449
463
  onChange: (e) => handleTimeOfDayChange(block.id, e.target.value),
450
464
  children: timeOfDayOptions.map((t) => /* @__PURE__ */ jsxRuntime.jsx("option", { children: t }, t))
451
465
  }
@@ -1386,10 +1400,138 @@ function useScreenplayEditor() {
1386
1400
  handleBlur
1387
1401
  };
1388
1402
  }
1403
+ var handleSaveAsPdf = (blocks, sceneNumbers) => {
1404
+ if (document.activeElement instanceof HTMLElement) {
1405
+ document.activeElement.blur();
1406
+ }
1407
+ const doc = new jsPDF__default.default({
1408
+ orientation: "portrait",
1409
+ unit: "mm",
1410
+ format: "letter"
1411
+ });
1412
+ const FONT_SIZE = 12;
1413
+ const LINE_HEIGHT = 4.233;
1414
+ const PAGE_WIDTH = doc.internal.pageSize.getWidth();
1415
+ const PAGE_HEIGHT = doc.internal.pageSize.getHeight();
1416
+ const MARGIN_LEFT = 38.1;
1417
+ const MARGIN_RIGHT = 25.4;
1418
+ const MARGIN_TOP = 25.4;
1419
+ const MARGIN_BOTTOM = 25.4;
1420
+ const blockDimensions = {
1421
+ SCENE_HEADING: { indent: 0, width: 152.4, upper: true, bold: true },
1422
+ ACTION: { indent: 0, width: 152.4, upper: false, bold: false },
1423
+ CHARACTER: { indent: 50.8, width: 101.6, upper: true, bold: false },
1424
+ PARENTHETICAL: { indent: 38.1, width: 50.8, upper: false, bold: false },
1425
+ DIALOGUE: { indent: 25.4, width: 88.9, upper: false, bold: false },
1426
+ TRANSITION: {
1427
+ indent: 0,
1428
+ width: 152.4,
1429
+ upper: true,
1430
+ bold: false,
1431
+ align: "right"
1432
+ },
1433
+ GENERAL: { indent: 0, width: 152.4, upper: false, bold: false }
1434
+ };
1435
+ let y = MARGIN_TOP;
1436
+ let pageNumber = 1;
1437
+ const drawPageNumber = (num) => {
1438
+ if (num > 1) {
1439
+ doc.setFont("Courier", "normal");
1440
+ doc.setFontSize(12);
1441
+ doc.text(`${num}.`, PAGE_WIDTH - MARGIN_RIGHT, 12.7, {
1442
+ align: "right"
1443
+ });
1444
+ }
1445
+ };
1446
+ blocks.forEach((block, index) => {
1447
+ const config = blockDimensions[block.type] || blockDimensions.GENERAL;
1448
+ let text = block.text || "";
1449
+ if (config.upper) text = text.toUpperCase();
1450
+ if (block.type === "SCENE_HEADING") {
1451
+ text = `${block.sceneType || "INT."} ${text} - ${block.timeOfDay || "DAY"}`.toUpperCase();
1452
+ }
1453
+ doc.setFont("Courier", config.bold ? "bold" : "normal");
1454
+ doc.setFontSize(FONT_SIZE);
1455
+ const lines = doc.splitTextToSize(text, config.width);
1456
+ const blockHeight = lines.length * LINE_HEIGHT;
1457
+ let safetyBuffer = 0;
1458
+ if (block.type === "CHARACTER") safetyBuffer = LINE_HEIGHT * 3;
1459
+ if (y + blockHeight + safetyBuffer > PAGE_HEIGHT - MARGIN_BOTTOM) {
1460
+ doc.addPage();
1461
+ pageNumber++;
1462
+ drawPageNumber(pageNumber);
1463
+ y = MARGIN_TOP;
1464
+ doc.setFont("Courier", config.bold ? "bold" : "normal");
1465
+ doc.setFontSize(FONT_SIZE);
1466
+ }
1467
+ if (y > MARGIN_TOP) {
1468
+ if (block.type === "SCENE_HEADING" || block.type === "ACTION" || block.type === "CHARACTER") {
1469
+ y += LINE_HEIGHT;
1470
+ }
1471
+ }
1472
+ const xPos = MARGIN_LEFT + config.indent;
1473
+ if (config.align === "right") {
1474
+ doc.text(lines, PAGE_WIDTH - MARGIN_RIGHT, y, { align: "right" });
1475
+ } else {
1476
+ doc.text(lines, xPos, y);
1477
+ }
1478
+ if (block.type === "SCENE_HEADING" && (sceneNumbers == null ? void 0 : sceneNumbers[block.id])) {
1479
+ const sNum = String(sceneNumbers[block.id]);
1480
+ doc.setFont("Courier", "normal");
1481
+ doc.setFontSize(FONT_SIZE);
1482
+ doc.text(sNum, MARGIN_LEFT - 12, y);
1483
+ doc.text(sNum, PAGE_WIDTH - MARGIN_RIGHT + 5, y);
1484
+ doc.setFont("Courier", config.bold ? "bold" : "normal");
1485
+ }
1486
+ y += blockHeight;
1487
+ });
1488
+ doc.save("screenplay_export.pdf");
1489
+ };
1490
+ var handleSaveAsSbx = (blocks, sceneNumbers, onSaveAsSbx) => {
1491
+ const typeToDivClass = {
1492
+ SCENE_HEADING: "divtype0",
1493
+ ACTION: "divtype2",
1494
+ CHARACTER: "divtype3",
1495
+ PARENTHETICAL: "divtype4",
1496
+ DIALOGUE: "divtype5",
1497
+ TRANSITION: "divtype6",
1498
+ GENERAL: "divtype2"
1499
+ };
1500
+ const sbxData = blocks.map((block) => {
1501
+ const divClass = typeToDivClass[block.type] || "divtype2";
1502
+ let text = block.text || "";
1503
+ let extraAttributes = "";
1504
+ if (block.type === "SCENE_HEADING") {
1505
+ text = `${block.sceneType || "INT."} ${text} - ${block.timeOfDay || "DAY"}`.toUpperCase();
1506
+ const sceneNum = sceneNumbers == null ? void 0 : sceneNumbers[block.id];
1507
+ if (sceneNum) {
1508
+ extraAttributes = ` data-scene="${sceneNum}"`;
1509
+ }
1510
+ } else if (block.type === "CHARACTER" || block.type === "TRANSITION") {
1511
+ text = text.toUpperCase();
1512
+ }
1513
+ return `<div class="${divClass}" id="par${block.id}"${extraAttributes}>${text}</div>`;
1514
+ }).join("");
1515
+ const blob = new Blob([sbxData], { type: "text/plain" });
1516
+ const url = URL.createObjectURL(blob);
1517
+ const a = document.createElement("a");
1518
+ a.href = url;
1519
+ a.download = "screenplay.sbx";
1520
+ document.body.appendChild(a);
1521
+ a.click();
1522
+ document.body.removeChild(a);
1523
+ URL.revokeObjectURL(url);
1524
+ if (onSaveAsSbx) {
1525
+ const file = new File([blob], "screenplay.sbx", { type: "text/plain" });
1526
+ onSaveAsSbx(file);
1527
+ }
1528
+ };
1389
1529
 
1390
1530
  exports.ScreenplayEditorView = ScreenplayEditorView;
1391
1531
  exports.blockStyles = blockStyles;
1392
1532
  exports.blockTypes = blockTypes;
1533
+ exports.handleSaveAsPdf = handleSaveAsPdf;
1534
+ exports.handleSaveAsSbx = handleSaveAsSbx;
1393
1535
  exports.icons = icons;
1394
1536
  exports.timeOfDayOptions = timeOfDayOptions;
1395
1537
  exports.useScreenplayEditor = useScreenplayEditor;