@vishu1301/script-writing 0.4.7 → 0.4.8
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 +132 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +128 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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;
|
|
@@ -1386,10 +1390,138 @@ function useScreenplayEditor() {
|
|
|
1386
1390
|
handleBlur
|
|
1387
1391
|
};
|
|
1388
1392
|
}
|
|
1393
|
+
var handleSaveAsPdf = (blocks, sceneNumbers) => {
|
|
1394
|
+
if (document.activeElement instanceof HTMLElement) {
|
|
1395
|
+
document.activeElement.blur();
|
|
1396
|
+
}
|
|
1397
|
+
const doc = new jsPDF__default.default({
|
|
1398
|
+
orientation: "portrait",
|
|
1399
|
+
unit: "mm",
|
|
1400
|
+
format: "letter"
|
|
1401
|
+
});
|
|
1402
|
+
const FONT_SIZE = 12;
|
|
1403
|
+
const LINE_HEIGHT = 4.233;
|
|
1404
|
+
const PAGE_WIDTH = doc.internal.pageSize.getWidth();
|
|
1405
|
+
const PAGE_HEIGHT = doc.internal.pageSize.getHeight();
|
|
1406
|
+
const MARGIN_LEFT = 38.1;
|
|
1407
|
+
const MARGIN_RIGHT = 25.4;
|
|
1408
|
+
const MARGIN_TOP = 25.4;
|
|
1409
|
+
const MARGIN_BOTTOM = 25.4;
|
|
1410
|
+
const blockDimensions = {
|
|
1411
|
+
SCENE_HEADING: { indent: 0, width: 152.4, upper: true, bold: true },
|
|
1412
|
+
ACTION: { indent: 0, width: 152.4, upper: false, bold: false },
|
|
1413
|
+
CHARACTER: { indent: 50.8, width: 101.6, upper: true, bold: false },
|
|
1414
|
+
PARENTHETICAL: { indent: 38.1, width: 50.8, upper: false, bold: false },
|
|
1415
|
+
DIALOGUE: { indent: 25.4, width: 88.9, upper: false, bold: false },
|
|
1416
|
+
TRANSITION: {
|
|
1417
|
+
indent: 0,
|
|
1418
|
+
width: 152.4,
|
|
1419
|
+
upper: true,
|
|
1420
|
+
bold: false,
|
|
1421
|
+
align: "right"
|
|
1422
|
+
},
|
|
1423
|
+
GENERAL: { indent: 0, width: 152.4, upper: false, bold: false }
|
|
1424
|
+
};
|
|
1425
|
+
let y = MARGIN_TOP;
|
|
1426
|
+
let pageNumber = 1;
|
|
1427
|
+
const drawPageNumber = (num) => {
|
|
1428
|
+
if (num > 1) {
|
|
1429
|
+
doc.setFont("Courier", "normal");
|
|
1430
|
+
doc.setFontSize(12);
|
|
1431
|
+
doc.text(`${num}.`, PAGE_WIDTH - MARGIN_RIGHT, 12.7, {
|
|
1432
|
+
align: "right"
|
|
1433
|
+
});
|
|
1434
|
+
}
|
|
1435
|
+
};
|
|
1436
|
+
blocks.forEach((block, index) => {
|
|
1437
|
+
const config = blockDimensions[block.type] || blockDimensions.GENERAL;
|
|
1438
|
+
let text = block.text || "";
|
|
1439
|
+
if (config.upper) text = text.toUpperCase();
|
|
1440
|
+
if (block.type === "SCENE_HEADING") {
|
|
1441
|
+
text = `${block.sceneType || "INT."} ${text} - ${block.timeOfDay || "DAY"}`.toUpperCase();
|
|
1442
|
+
}
|
|
1443
|
+
doc.setFont("Courier", config.bold ? "bold" : "normal");
|
|
1444
|
+
doc.setFontSize(FONT_SIZE);
|
|
1445
|
+
const lines = doc.splitTextToSize(text, config.width);
|
|
1446
|
+
const blockHeight = lines.length * LINE_HEIGHT;
|
|
1447
|
+
let safetyBuffer = 0;
|
|
1448
|
+
if (block.type === "CHARACTER") safetyBuffer = LINE_HEIGHT * 3;
|
|
1449
|
+
if (y + blockHeight + safetyBuffer > PAGE_HEIGHT - MARGIN_BOTTOM) {
|
|
1450
|
+
doc.addPage();
|
|
1451
|
+
pageNumber++;
|
|
1452
|
+
drawPageNumber(pageNumber);
|
|
1453
|
+
y = MARGIN_TOP;
|
|
1454
|
+
doc.setFont("Courier", config.bold ? "bold" : "normal");
|
|
1455
|
+
doc.setFontSize(FONT_SIZE);
|
|
1456
|
+
}
|
|
1457
|
+
if (y > MARGIN_TOP) {
|
|
1458
|
+
if (block.type === "SCENE_HEADING" || block.type === "ACTION" || block.type === "CHARACTER") {
|
|
1459
|
+
y += LINE_HEIGHT;
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
const xPos = MARGIN_LEFT + config.indent;
|
|
1463
|
+
if (config.align === "right") {
|
|
1464
|
+
doc.text(lines, PAGE_WIDTH - MARGIN_RIGHT, y, { align: "right" });
|
|
1465
|
+
} else {
|
|
1466
|
+
doc.text(lines, xPos, y);
|
|
1467
|
+
}
|
|
1468
|
+
if (block.type === "SCENE_HEADING" && (sceneNumbers == null ? void 0 : sceneNumbers[block.id])) {
|
|
1469
|
+
const sNum = String(sceneNumbers[block.id]);
|
|
1470
|
+
doc.setFont("Courier", "normal");
|
|
1471
|
+
doc.setFontSize(FONT_SIZE);
|
|
1472
|
+
doc.text(sNum, MARGIN_LEFT - 12, y);
|
|
1473
|
+
doc.text(sNum, PAGE_WIDTH - MARGIN_RIGHT + 5, y);
|
|
1474
|
+
doc.setFont("Courier", config.bold ? "bold" : "normal");
|
|
1475
|
+
}
|
|
1476
|
+
y += blockHeight;
|
|
1477
|
+
});
|
|
1478
|
+
doc.save("screenplay_export.pdf");
|
|
1479
|
+
};
|
|
1480
|
+
var handleSaveAsSbx = (blocks, sceneNumbers, onSaveAsSbx) => {
|
|
1481
|
+
const typeToDivClass = {
|
|
1482
|
+
SCENE_HEADING: "divtype0",
|
|
1483
|
+
ACTION: "divtype2",
|
|
1484
|
+
CHARACTER: "divtype3",
|
|
1485
|
+
PARENTHETICAL: "divtype4",
|
|
1486
|
+
DIALOGUE: "divtype5",
|
|
1487
|
+
TRANSITION: "divtype6",
|
|
1488
|
+
GENERAL: "divtype2"
|
|
1489
|
+
};
|
|
1490
|
+
const sbxData = blocks.map((block) => {
|
|
1491
|
+
const divClass = typeToDivClass[block.type] || "divtype2";
|
|
1492
|
+
let text = block.text || "";
|
|
1493
|
+
let extraAttributes = "";
|
|
1494
|
+
if (block.type === "SCENE_HEADING") {
|
|
1495
|
+
text = `${block.sceneType || "INT."} ${text} - ${block.timeOfDay || "DAY"}`.toUpperCase();
|
|
1496
|
+
const sceneNum = sceneNumbers == null ? void 0 : sceneNumbers[block.id];
|
|
1497
|
+
if (sceneNum) {
|
|
1498
|
+
extraAttributes = ` data-scene="${sceneNum}"`;
|
|
1499
|
+
}
|
|
1500
|
+
} else if (block.type === "CHARACTER" || block.type === "TRANSITION") {
|
|
1501
|
+
text = text.toUpperCase();
|
|
1502
|
+
}
|
|
1503
|
+
return `<div class="${divClass}" id="par${block.id}"${extraAttributes}>${text}</div>`;
|
|
1504
|
+
}).join("");
|
|
1505
|
+
const blob = new Blob([sbxData], { type: "text/plain" });
|
|
1506
|
+
const url = URL.createObjectURL(blob);
|
|
1507
|
+
const a = document.createElement("a");
|
|
1508
|
+
a.href = url;
|
|
1509
|
+
a.download = "screenplay.sbx";
|
|
1510
|
+
document.body.appendChild(a);
|
|
1511
|
+
a.click();
|
|
1512
|
+
document.body.removeChild(a);
|
|
1513
|
+
URL.revokeObjectURL(url);
|
|
1514
|
+
if (onSaveAsSbx) {
|
|
1515
|
+
const file = new File([blob], "screenplay.sbx", { type: "text/plain" });
|
|
1516
|
+
onSaveAsSbx(file);
|
|
1517
|
+
}
|
|
1518
|
+
};
|
|
1389
1519
|
|
|
1390
1520
|
exports.ScreenplayEditorView = ScreenplayEditorView;
|
|
1391
1521
|
exports.blockStyles = blockStyles;
|
|
1392
1522
|
exports.blockTypes = blockTypes;
|
|
1523
|
+
exports.handleSaveAsPdf = handleSaveAsPdf;
|
|
1524
|
+
exports.handleSaveAsSbx = handleSaveAsSbx;
|
|
1393
1525
|
exports.icons = icons;
|
|
1394
1526
|
exports.timeOfDayOptions = timeOfDayOptions;
|
|
1395
1527
|
exports.useScreenplayEditor = useScreenplayEditor;
|