@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.d.cts
CHANGED
|
@@ -52,4 +52,7 @@ type ScreenplayEditorViewProps = ReturnType<typeof useScreenplayEditor> & {
|
|
|
52
52
|
};
|
|
53
53
|
declare function ScreenplayEditorView({ blocks, refs, focusedBlockId, showSuggestions, showExtensionSuggestions, characterExtensions, locations, characters, handleBlockTextChange, handleSceneTypeChange, handleTimeOfDayChange, handleBlockTypeChange, handleSelectCharacterExtension, handleKeyDown, handleFocus, handleBlur, handleScriptImport, onSave, onSaveAsPdf, onSaveAsSbx, onSyncWithCloud, handleSceneNumberChange, }: ScreenplayEditorViewProps): react_jsx_runtime.JSX.Element;
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
declare const handleSaveAsPdf: (blocks: Block[], sceneNumbers: Record<string, string>) => void;
|
|
56
|
+
declare const handleSaveAsSbx: (blocks: Block[], sceneNumbers: Record<string, string>, onSaveAsSbx?: (file: File) => void) => void;
|
|
57
|
+
|
|
58
|
+
export { type Block, type BlockType, ScreenplayEditorView, type TimeOfDay, blockStyles, blockTypes, handleSaveAsPdf, handleSaveAsSbx, icons, timeOfDayOptions, useScreenplayEditor, uuid };
|
package/dist/index.d.ts
CHANGED
|
@@ -52,4 +52,7 @@ type ScreenplayEditorViewProps = ReturnType<typeof useScreenplayEditor> & {
|
|
|
52
52
|
};
|
|
53
53
|
declare function ScreenplayEditorView({ blocks, refs, focusedBlockId, showSuggestions, showExtensionSuggestions, characterExtensions, locations, characters, handleBlockTextChange, handleSceneTypeChange, handleTimeOfDayChange, handleBlockTypeChange, handleSelectCharacterExtension, handleKeyDown, handleFocus, handleBlur, handleScriptImport, onSave, onSaveAsPdf, onSaveAsSbx, onSyncWithCloud, handleSceneNumberChange, }: ScreenplayEditorViewProps): react_jsx_runtime.JSX.Element;
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
declare const handleSaveAsPdf: (blocks: Block[], sceneNumbers: Record<string, string>) => void;
|
|
56
|
+
declare const handleSaveAsSbx: (blocks: Block[], sceneNumbers: Record<string, string>, onSaveAsSbx?: (file: File) => void) => void;
|
|
57
|
+
|
|
58
|
+
export { type Block, type BlockType, ScreenplayEditorView, type TimeOfDay, blockStyles, blockTypes, handleSaveAsPdf, handleSaveAsSbx, icons, timeOfDayOptions, useScreenplayEditor, uuid };
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import { useState, useRef, useMemo, useCallback, useEffect } from 'react';
|
|
|
2
2
|
import { ArrowRightLeft, MessageCircle, Brackets, UserRound, Sparkles, Clapperboard, ArrowRight, User, ChevronRight, Upload, Save, FileDown, RefreshCcw, Cog } from 'lucide-react';
|
|
3
3
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
4
4
|
import * as pdfjs from 'pdfjs-dist';
|
|
5
|
+
import jsPDF from 'jspdf';
|
|
5
6
|
|
|
6
7
|
var __defProp = Object.defineProperty;
|
|
7
8
|
var __defProps = Object.defineProperties;
|
|
@@ -1364,7 +1365,133 @@ function useScreenplayEditor() {
|
|
|
1364
1365
|
handleBlur
|
|
1365
1366
|
};
|
|
1366
1367
|
}
|
|
1368
|
+
var handleSaveAsPdf = (blocks, sceneNumbers) => {
|
|
1369
|
+
if (document.activeElement instanceof HTMLElement) {
|
|
1370
|
+
document.activeElement.blur();
|
|
1371
|
+
}
|
|
1372
|
+
const doc = new jsPDF({
|
|
1373
|
+
orientation: "portrait",
|
|
1374
|
+
unit: "mm",
|
|
1375
|
+
format: "letter"
|
|
1376
|
+
});
|
|
1377
|
+
const FONT_SIZE = 12;
|
|
1378
|
+
const LINE_HEIGHT = 4.233;
|
|
1379
|
+
const PAGE_WIDTH = doc.internal.pageSize.getWidth();
|
|
1380
|
+
const PAGE_HEIGHT = doc.internal.pageSize.getHeight();
|
|
1381
|
+
const MARGIN_LEFT = 38.1;
|
|
1382
|
+
const MARGIN_RIGHT = 25.4;
|
|
1383
|
+
const MARGIN_TOP = 25.4;
|
|
1384
|
+
const MARGIN_BOTTOM = 25.4;
|
|
1385
|
+
const blockDimensions = {
|
|
1386
|
+
SCENE_HEADING: { indent: 0, width: 152.4, upper: true, bold: true },
|
|
1387
|
+
ACTION: { indent: 0, width: 152.4, upper: false, bold: false },
|
|
1388
|
+
CHARACTER: { indent: 50.8, width: 101.6, upper: true, bold: false },
|
|
1389
|
+
PARENTHETICAL: { indent: 38.1, width: 50.8, upper: false, bold: false },
|
|
1390
|
+
DIALOGUE: { indent: 25.4, width: 88.9, upper: false, bold: false },
|
|
1391
|
+
TRANSITION: {
|
|
1392
|
+
indent: 0,
|
|
1393
|
+
width: 152.4,
|
|
1394
|
+
upper: true,
|
|
1395
|
+
bold: false,
|
|
1396
|
+
align: "right"
|
|
1397
|
+
},
|
|
1398
|
+
GENERAL: { indent: 0, width: 152.4, upper: false, bold: false }
|
|
1399
|
+
};
|
|
1400
|
+
let y = MARGIN_TOP;
|
|
1401
|
+
let pageNumber = 1;
|
|
1402
|
+
const drawPageNumber = (num) => {
|
|
1403
|
+
if (num > 1) {
|
|
1404
|
+
doc.setFont("Courier", "normal");
|
|
1405
|
+
doc.setFontSize(12);
|
|
1406
|
+
doc.text(`${num}.`, PAGE_WIDTH - MARGIN_RIGHT, 12.7, {
|
|
1407
|
+
align: "right"
|
|
1408
|
+
});
|
|
1409
|
+
}
|
|
1410
|
+
};
|
|
1411
|
+
blocks.forEach((block, index) => {
|
|
1412
|
+
const config = blockDimensions[block.type] || blockDimensions.GENERAL;
|
|
1413
|
+
let text = block.text || "";
|
|
1414
|
+
if (config.upper) text = text.toUpperCase();
|
|
1415
|
+
if (block.type === "SCENE_HEADING") {
|
|
1416
|
+
text = `${block.sceneType || "INT."} ${text} - ${block.timeOfDay || "DAY"}`.toUpperCase();
|
|
1417
|
+
}
|
|
1418
|
+
doc.setFont("Courier", config.bold ? "bold" : "normal");
|
|
1419
|
+
doc.setFontSize(FONT_SIZE);
|
|
1420
|
+
const lines = doc.splitTextToSize(text, config.width);
|
|
1421
|
+
const blockHeight = lines.length * LINE_HEIGHT;
|
|
1422
|
+
let safetyBuffer = 0;
|
|
1423
|
+
if (block.type === "CHARACTER") safetyBuffer = LINE_HEIGHT * 3;
|
|
1424
|
+
if (y + blockHeight + safetyBuffer > PAGE_HEIGHT - MARGIN_BOTTOM) {
|
|
1425
|
+
doc.addPage();
|
|
1426
|
+
pageNumber++;
|
|
1427
|
+
drawPageNumber(pageNumber);
|
|
1428
|
+
y = MARGIN_TOP;
|
|
1429
|
+
doc.setFont("Courier", config.bold ? "bold" : "normal");
|
|
1430
|
+
doc.setFontSize(FONT_SIZE);
|
|
1431
|
+
}
|
|
1432
|
+
if (y > MARGIN_TOP) {
|
|
1433
|
+
if (block.type === "SCENE_HEADING" || block.type === "ACTION" || block.type === "CHARACTER") {
|
|
1434
|
+
y += LINE_HEIGHT;
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
const xPos = MARGIN_LEFT + config.indent;
|
|
1438
|
+
if (config.align === "right") {
|
|
1439
|
+
doc.text(lines, PAGE_WIDTH - MARGIN_RIGHT, y, { align: "right" });
|
|
1440
|
+
} else {
|
|
1441
|
+
doc.text(lines, xPos, y);
|
|
1442
|
+
}
|
|
1443
|
+
if (block.type === "SCENE_HEADING" && (sceneNumbers == null ? void 0 : sceneNumbers[block.id])) {
|
|
1444
|
+
const sNum = String(sceneNumbers[block.id]);
|
|
1445
|
+
doc.setFont("Courier", "normal");
|
|
1446
|
+
doc.setFontSize(FONT_SIZE);
|
|
1447
|
+
doc.text(sNum, MARGIN_LEFT - 12, y);
|
|
1448
|
+
doc.text(sNum, PAGE_WIDTH - MARGIN_RIGHT + 5, y);
|
|
1449
|
+
doc.setFont("Courier", config.bold ? "bold" : "normal");
|
|
1450
|
+
}
|
|
1451
|
+
y += blockHeight;
|
|
1452
|
+
});
|
|
1453
|
+
doc.save("screenplay_export.pdf");
|
|
1454
|
+
};
|
|
1455
|
+
var handleSaveAsSbx = (blocks, sceneNumbers, onSaveAsSbx) => {
|
|
1456
|
+
const typeToDivClass = {
|
|
1457
|
+
SCENE_HEADING: "divtype0",
|
|
1458
|
+
ACTION: "divtype2",
|
|
1459
|
+
CHARACTER: "divtype3",
|
|
1460
|
+
PARENTHETICAL: "divtype4",
|
|
1461
|
+
DIALOGUE: "divtype5",
|
|
1462
|
+
TRANSITION: "divtype6",
|
|
1463
|
+
GENERAL: "divtype2"
|
|
1464
|
+
};
|
|
1465
|
+
const sbxData = blocks.map((block) => {
|
|
1466
|
+
const divClass = typeToDivClass[block.type] || "divtype2";
|
|
1467
|
+
let text = block.text || "";
|
|
1468
|
+
let extraAttributes = "";
|
|
1469
|
+
if (block.type === "SCENE_HEADING") {
|
|
1470
|
+
text = `${block.sceneType || "INT."} ${text} - ${block.timeOfDay || "DAY"}`.toUpperCase();
|
|
1471
|
+
const sceneNum = sceneNumbers == null ? void 0 : sceneNumbers[block.id];
|
|
1472
|
+
if (sceneNum) {
|
|
1473
|
+
extraAttributes = ` data-scene="${sceneNum}"`;
|
|
1474
|
+
}
|
|
1475
|
+
} else if (block.type === "CHARACTER" || block.type === "TRANSITION") {
|
|
1476
|
+
text = text.toUpperCase();
|
|
1477
|
+
}
|
|
1478
|
+
return `<div class="${divClass}" id="par${block.id}"${extraAttributes}>${text}</div>`;
|
|
1479
|
+
}).join("");
|
|
1480
|
+
const blob = new Blob([sbxData], { type: "text/plain" });
|
|
1481
|
+
const url = URL.createObjectURL(blob);
|
|
1482
|
+
const a = document.createElement("a");
|
|
1483
|
+
a.href = url;
|
|
1484
|
+
a.download = "screenplay.sbx";
|
|
1485
|
+
document.body.appendChild(a);
|
|
1486
|
+
a.click();
|
|
1487
|
+
document.body.removeChild(a);
|
|
1488
|
+
URL.revokeObjectURL(url);
|
|
1489
|
+
if (onSaveAsSbx) {
|
|
1490
|
+
const file = new File([blob], "screenplay.sbx", { type: "text/plain" });
|
|
1491
|
+
onSaveAsSbx(file);
|
|
1492
|
+
}
|
|
1493
|
+
};
|
|
1367
1494
|
|
|
1368
|
-
export { ScreenplayEditorView, blockStyles, blockTypes, icons, timeOfDayOptions, useScreenplayEditor, uuid };
|
|
1495
|
+
export { ScreenplayEditorView, blockStyles, blockTypes, handleSaveAsPdf, handleSaveAsSbx, icons, timeOfDayOptions, useScreenplayEditor, uuid };
|
|
1369
1496
|
//# sourceMappingURL=index.js.map
|
|
1370
1497
|
//# sourceMappingURL=index.js.map
|